Customizing SMF > Mod Requests

[Paid] News Site SSI

<< < (3/3)

Motorhed:
I unmarked this as 'solved' because while I found a solution, it simply floats the first attachment IN the post to the left... meaning the person posting has to attach the image at the top of their post - and if they don't, it doesn't show at all.

Soooo... ugh.

Motorhed:
Got it. Finally managed to dig up the ONE very old post here that noted how to do it. It's in the advanced SSI FAQ thread, IIRC.

Closed.

mane16:
Hey Motorhed, would you mind sharing a little explanation on how you did it (if you actually managed to do it), I want to do the same thing on simpleportal, but can't really think on how to actually do it, and my knowledge is also a little limited on this field.
Thanks in advance :)

Motorhed:
Sorry for the late reply. I assumed nobody else cared about the feature.

Here is the edited boardNews code. I renamed it and added it in so that I could still have the OLD boardNews in place. It is now called squareNews and must be called by that name when adding the portal block...

You can see it in use here:

http://herohour.com (The front page news area and the header news w/edit to make it horizontal.)
http://incomics.com (The front page news area, this is not a forum portal.)

Put this in SSI.php, near the end but not outside the php code.


--- Code: ---// Square news, assembled/stolen by Motorhed from various forum posts.
function ssi_squareNews($board = null, $limit = null, $start = null, $length = null, $output_method = 'echo')
{
global $scripturl, $db_prefix, $txt, $settings, $modSettings, $context;
global $smcFunc;

loadLanguage('Stats');

// Must be integers....
if ($limit === null)
$limit = isset($_GET['limit']) ? (int) $_GET['limit'] : 5;
else
$limit = (int) $limit;

if ($start === null)
$start = isset($_GET['start']) ? (int) $_GET['start'] : 0;
else
$start = (int) $start;

/*
if ($board !== null)
$board = (int) $board;
elseif (isset($_GET['board']))
$board = (int) $_GET['board'];
*/

if (empty($board))
return;
elseif (!is_array($board))
$board = array($board);

if ($length === null)
$length = isset($_GET['length']) ? (int) $_GET['length'] : 0;
else
$length = (int) $length;

$limit = max(0, $limit);
$start = max(0, $start);

/*
// Make sure guests can see this board.
$request = $smcFunc['db_query']('', '
SELECT id_board
FROM {db_prefix}boards
WHERE ' . ($board === null ? '' : 'id_board = {int:current_board}
AND ') . 'FIND_IN_SET(-1, member_groups)
LIMIT 1',
array(
'current_board' => $board,
)
);
if ($smcFunc['db_num_rows']($request) == 0)
{
if ($output_method == 'echo')
die($txt['ssi_no_guests']);
else
return array();
}
list ($board) = $smcFunc['db_fetch_row']($request);
$smcFunc['db_free_result']($request);
*/

// Load the message icons - the usual suspects.
$stable_icons = array('xx', 'thumbup', 'thumbdown', 'exclamation', 'question', 'lamp', 'smiley', 'angry', 'cheesy', 'grin', 'sad', 'wink', 'moved', 'recycled', 'wireless');
$icon_sources = array();
foreach ($stable_icons as $icon)
$icon_sources[$icon] = 'images_url';

// Find the post ids.
$request = $smcFunc['db_query']('', '
SELECT id_first_msg
FROM {db_prefix}topics
WHERE id_board IN ({array_int:current_board})' . ($modSettings['postmod_active'] ? '
AND approved = {int:is_approved}' : '') . '
ORDER BY id_first_msg DESC
LIMIT ' . $start . ', ' . $limit,
array(
'current_board' => $board,
'is_approved' => 1,
)
);
$posts = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
$posts[] = $row['id_first_msg'];
$smcFunc['db_free_result']($request);

if (empty($posts))
return array();

global $sourcedir, $attachments, $topic;
require_once($sourcedir . '/Display.php');

$attachments = array();
$request = $smcFunc['db_query']('', '
SELECT
a.id_attach, a.id_folder, a.id_msg, a.filename, IFNULL(a.size, 0) AS filesize, a.downloads, a.approved,
a.width, a.height' . (empty($modSettings['attachmentShowImages']) || empty($modSettings['attachmentThumbnails']) ? '' : ',
IFNULL(thumb.id_attach, 0) AS id_thumb, thumb.width AS thumb_width, thumb.height AS thumb_height') . '
FROM {db_prefix}attachments AS a' . (empty($modSettings['attachmentShowImages']) || empty($modSettings['attachmentThumbnails']) ? '' : '
LEFT JOIN {db_prefix}attachments AS thumb ON (thumb.id_attach = a.id_thumb)') . '
WHERE a.id_msg IN ({array_int:message_list})
AND a.attachment_type = {int:attachment_type}' . (!$modSettings['postmod_active'] || allowedTo('approve_posts') ? '' : '
AND a.approved = {int:is_approved}'),
array(
'message_list' => $posts,
'attachment_type' => 0,
'is_approved' => 1,
)
);
$temp = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
{
$temp[$row['id_attach']] = $row;

if (!isset($attachments[$row['id_msg']]))
$attachments[$row['id_msg']] = array();
}
$smcFunc['db_free_result']($request);

ksort($temp);

foreach ($temp as $row)
$attachments[$row['id_msg']][] = $row;

// Find the posts.
$request = $smcFunc['db_query']('', '
SELECT
m.icon, m.subject, m.body, IFNULL(mem.real_name, m.poster_name) AS poster_name, m.poster_time,
t.num_replies, t.num_views, t.id_topic, m.id_member, m.smileys_enabled, m.id_msg, t.locked, t.id_last_msg
FROM {db_prefix}topics AS t
INNER JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_first_msg)
LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)
WHERE t.id_first_msg IN ({array_int:post_list})
ORDER BY t.id_first_msg DESC
LIMIT ' . count($posts),
array(
'post_list' => $posts,
)
);
$return = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
{
// If we want to limit the length of the post.
if (!empty($length) && $smcFunc['strlen']($row['body']) > $length)
{
$row['body'] = $smcFunc['substr']($row['body'], 0, $length);

// The first space or line break. (<br />, etc.)
$cutoff = max(strrpos($row['body'], ' '), strrpos($row['body'], '<'));

if ($cutoff !== false)
$row['body'] = $smcFunc['substr']($row['body'], 0, $cutoff);
$row['body'] .= '...';
}

$row['body'] = parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']);

// Check that this message icon is there...
if (empty($modSettings['messageIconChecks_disable']) && !isset($icon_sources[$row['icon']]))
$icon_sources[$row['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['icon'] . '.gif') ? 'images_url' : 'default_images_url';

censorText($row['subject']);
censorText($row['body']);

$topic = $row['id_topic'];
$return[] = array(
'attachments' => loadAttachmentContext($row['id_msg']),
'id' => $row['id_topic'],
'views' => $row['num_views'],
'message_id' => $row['id_msg'],
'icon' => '<img src="' . $settings[$icon_sources[$row['icon']]] . '/post/' . $row['icon'] . '.gif" alt="' . $row['icon'] . '" />',
'subject' => $row['subject'],
'time' => timeformat($row['poster_time']),
'timestamp' => forum_time(true, $row['poster_time']),
'body' => $row['body'],
'href' => $scripturl . '?topic=' . $row['id_topic'] . '.0',
'link' => '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $row['num_replies'] . ' ' . ($row['num_replies'] == 1 ? $txt['ssi_comment'] : $txt['ssi_comments']) . '</a>',
'replies' => $row['num_replies'],
'comment_href' => !empty($row['locked']) ? '' : $scripturl . '?action=post;topic=' . $row['id_topic'] . '.' . $row['num_replies'] . ';last_msg=' . $row['id_last_msg'],
'comment_link' => !empty($row['locked']) ? '' : '<a href="' . $scripturl . '?action=post;topic=' . $row['id_topic'] . '.' . $row['num_replies'] . ';last_msg=' . $row['id_last_msg'] . '">' . $txt['ssi_write_comment'] . '</a>',
'new_comment' => !empty($row['locked']) ? '' : '<a href="' . $scripturl . '?action=post;topic=' . $row['id_topic'] . '.' . $row['num_replies'] . '">' . $txt['ssi_write_comment'] . '</a>',
'poster' => array(
'id' => $row['id_member'],
'name' => $row['poster_name'],
'href' => !empty($row['id_member']) ? $scripturl . '?action=profile;u=' . $row['id_member'] : '',
'link' => !empty($row['id_member']) ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['poster_name'] . '</a>' : $row['poster_name']
),
'locked' => !empty($row['locked']),
'is_last' => false
);
}
$smcFunc['db_free_result']($request);

if (empty($return))
return $return;

$return[count($return) - 1]['is_last'] = true;

if ($output_method != 'echo')
return $return;

foreach ($return as $news)
{
$attachment = array();
if (!empty($news['attachments'][0]))
{
$attachment = $news['attachments'][0];

if ($attachment['is_image'])
{
if ($attachment['thumbnail']['has_thumb'])
echo '
<div class="floatsquare"><a href="', $news['href'], '"><img src="', $attachment['thumbnail']['href'], '" alt="' . $news['subject'] . '" border="0" /></a><br /></div>';
else
echo '
<div class="floatsquare"><a href="', $news['href'], '"><img src="' . $attachment['href'] . ';image" alt="' . $news['subject'] . '" width="' . $attachment['width'] . '" height="' . $attachment['height'] . '" border="0" /></a><br /></div>';
}
}
else
echo '
<div class="floatsquare"> &nbsp; </div>';

echo '
<div class="newsblock">
<div class="headline"><a href="', $news['href'], '">', $news['subject'], '</a></div>
<div class="details"><span style="display: none;">', $news['time'], '</span>', $txt['by'], ' ', $news['poster']['link'], ' | <i>' , $news['views'], ' views</i></div>
<div class="text">', $news['link'], $news['locked'] ? '' : ' | ' . $news['comment_link'], '</div>

</div>';

if (!$news['is_last'])
echo '
<hr />';
}
}

--- End code ---

Note I removed some things you might want and that I call images and CSS that I made myself. You'll have to be clever and either remove those bits or make your own CSS entries to fit what I put, etc.

I cannot possibly properly credit all the code I used to make this - it came from multiple people in multiple places... so instead I have to credit "The SMF Community" for everything here that I didn't do myself.

Here is the CSS I used for some of this:


--- Code: ---
.headline {
display: block;
font-family: book antiqua;
font-style: italic;
font-size: 18px;
}

.headline a:link, .headline a:visited {
font-weight: bold;
text-decoration: none;
color: red;
}

.headline a:hover {
color: #CD0000;
}

.text, .text a:link, .text a:visited {
color: #888;
font-size: 12px;
line-height: 12px;
}

.text a:hover {
text-decoration: underline;
}

.text img {
display: none;
}

.text hr {
color: #eee;
}

.details, .details a:link, .details a:visited, .details a:hover {
font-size: 11px;
color: #bbb;
margin-bottom: 4px;
}

.floatsquare {
float: left;
width: 100px;
height: 100px;
display: block;
overflow: hidden;
border: 1px solid #eee;
background: #fff url(../images/off.png) no-repeat center center;
}

.floatsquare img {
width: 100px;
max-width: 100px;
min-height: 100px;
min-width: 100px;
}

.newsblock {
margin-left: 110px;
height: 102px;
display: block;
overflow: hidden;
}

--- End code ---


Forgive all the mess!

I'm not a programmer, so needless to say I cannot supply support.

Navigation

[0] Message Index

[*] Previous page

Go to full version