At this moment my forum has over 150.000 messages. Because we like the discussion taking place at the right topic new news messages regarding a discussion are placed within the topic. This creates the problem that new news items won't show up by the function recenttopics of ssi.php. This function is used to display the latest news items on the frontpage of my website.
Is there a way to display this new news items within a topic using a prefix in the title of the message, or is it possible to alter the function resenttopics that it selects messages based on a prefix in the title?
I am using version 1.1.10 at this moment....
Regards,
Peter
That could be possible.
What I've done for something similar is to create a special post icon and then check for that in a modified BoardNews function.
That would likely have a higher performance; filtering based on a topic prefix (especially taking into account Re: replies) is actually computationally expensive.
@Kays: Could you share the way you made this, so I can get an idea how to change the ssi to display the right messages?
Regards,
Hi this is the modifided ssi_boardNews I'm using
// News worthy posts, with a template
function ssi_recentNews($limit = null, $exclude_boards = null, $length = null, $output_method = 'echo')
{
global $context, $settings, $scripturl, $txt, $db_prefix, $ID_MEMBER;
global $user_info, $modSettings, $func;
loadLanguage('Stats');
if ($exclude_boards === null && !empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0)
$exclude_boards = array($modSettings['recycle_board']);
else
$exclude_boards = empty($exclude_boards) ? array() : $exclude_boards;
// Must be integers....
if ($limit === null)
$limit = isset($_GET['limit']) ? (int) $_GET['limit'] : 5;
else
$limit = (int) $limit;
if ($length === null || $length == 0)
$length = 65000;
else
$length = (int) $length;
// Find all the posts. Newer ones will have higher IDs.
$request = db_query("
SELECT
t.numReplies, t.locked, m.icon, m.posterTime, m.subject, m.ID_TOPIC, m.ID_MEMBER, m.ID_MSG, m.ID_BOARD, b.name AS bName,
IFNULL(mem.realName, m.posterName) AS posterName, " . ($user_info['is_guest'] ? '1 AS isRead, 0 AS new_from' : '
IFNULL(lt.ID_MSG, IFNULL(lmr.ID_MSG, 0)) >= m.ID_MSG_MODIFIED AS isRead,
IFNULL(lt.ID_MSG, IFNULL(lmr.ID_MSG, -1)) + 1 AS new_from') . ", m.body, m.smileysEnabled
FROM ({$db_prefix}messages AS m, {$db_prefix}boards AS b)
LEFT JOIN {$db_prefix}topics AS t ON (t.ID_TOPIC = m.ID_TOPIC)
LEFT JOIN {$db_prefix}members AS mem ON (mem.ID_MEMBER = m.ID_MEMBER)" . (!$user_info['is_guest'] ? "
LEFT JOIN {$db_prefix}log_topics AS lt ON (lt.ID_TOPIC = m.ID_TOPIC AND lt.ID_MEMBER = $ID_MEMBER)
LEFT JOIN {$db_prefix}log_mark_read AS lmr ON (lmr.ID_BOARD = m.ID_BOARD AND lmr.ID_MEMBER = $ID_MEMBER)" : '') . "
WHERE b.ID_BOARD = m.ID_BOARD" . (empty($exclude_boards) ? '' : "
AND b.ID_BOARD NOT IN (" . implode(', ', $exclude_boards) . ")") . "
AND $user_info[query_see_board] AND m.icon = 'news'
ORDER BY m.ID_MSG DESC
LIMIT $limit", __FILE__, __LINE__);
$return = array();
while ($row = mysql_fetch_assoc($request))
{
if ($length != 6500)
$row['body'] = shorten_subject($row['body'], $length);
$row['body'] = parse_bbc($row['body'], $row['smileysEnabled'], $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']);
$return[] = array(
'id' => $row['ID_TOPIC'],
'board' => $row['bName'],
'message_id' => $row['ID_MSG'],
'icon' => '<img src="' . $settings[$icon_sources[$row['icon']]] . '/post/' . $row['icon'] . '.gif" align="middle" alt="' . $row['icon'] . '" border="0" />',
'subject' => $row['subject'],
'time' => timeformat($row['posterTime']),
'timestamp' => forum_time(true, $row['posterTime']),
'body' => $row['body'],
'href' => $scripturl . '?topic=' . $row['ID_TOPIC'] . '.0',
'link' => '<a href="' . $scripturl . '?topic=' . $row['ID_TOPIC'] . '#msg'. $row['ID_MSG']. '">View Post</a>',
'replies' => $row['numReplies'],
'comment_href' => !empty($row['locked']) ? '' : $scripturl . '?action=post;topic=' . $row['ID_TOPIC'] . '.' . $row['numReplies'] . ';num_replies=' . $row['numReplies'],
'comment_link' => !empty($row['locked']) ? '' : '<a href="' . $scripturl . '?action=post;topic=' . $row['ID_TOPIC'] . '.' . $row['numReplies'] . ';num_replies=' . $row['numReplies'] . '">' . $txt['smf_news_3'] . '</a>',
'new_comment' => !empty($row['locked']) ? '' : '<a href="' . $scripturl . '?action=post;topic=' . $row['ID_TOPIC'] . '.' . $row['numReplies'] . '">' . $txt['smf_news_3'] . '</a>',
'poster' => array(
'id' => $row['ID_MEMBER'],
'name' => $row['posterName'],
'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['posterName'] . '</a>' : $row['posterName']
),
'locked' => !empty($row['locked']),
'is_last' => false
);
}
mysql_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)
{
echo '
<div style="float:right;" align="right">', $txt[525], ': <b>', $news['poster']['name'], '</b><br />', $news['time'], '</div>
<div>
<a href="', $news['href'], '">', $news['icon'], '</a> <b>', $news['subject'], '</b>
<div class="smaller">In: ', $news['board'], '</div><br /><hr class="hrcolor" />
<div class="post" style="padding: 2ex 0;">', $news['body'], '</div>
', $news['link'], $news['locked'] ? '' : ' | ' . $news['comment_link'], '
</div>';
if (!$news['is_last'])
echo '
<hr style="margin: 2ex 0;" width="100%" />';
}
}
What I did was to create an icon named news.gif and to check for it in the query. So this will display the last posts where this icon is used.
AND $user_info[query_see_board] AND m.icon = 'news'
Now I'm a little sketchy on the details of adding the icon and don't know if any addional steps are needed. This should make it so that it is only veiwed by admins and global moderators
In Post.php look for:
if (!empty($context['icons']))
$context['icons'][count($context['icons']) - 1]['is_last'] = true;
And above it add:
$staff_groups = array(1,2);
if (in_array($user_info['groups'][0], $staff_groups))
{
$context['icons'][] = array(
'value' => 'news',
'name' => 'For news items only',
'url' => $settings['images_url'] . '/post/news.gif',
'is_last' => false,
);
}
In the first line you can add any additional groups. Also you do need to upload an icon named news.gif to the images/post folder of the theme you are using.
I hope that this is enough to get you started.
Thanks! I will implement it this weekend..
I have implemented the changes and it works with the function recenttopics :)
Only problem now is how to implement the same function to the ssi_boardnews,
because I would like to show the complete message on the frontpage, not only the title.
Also the link directs the viewer to the start of the topic, in stead of linking to the news message itself...
Use the function I posted. The display is similar to ssi_boardNews but it only shows the posts where that icon is used.
For the link back to the post.
<a href="', $scripturl, '?;topic=' , $news['id'],. '.msg', $news['message_id'], '#msg', $news['message_id'], '">View Entire Post</a>
Thanks! that works like a charm :D
Good, if you have it working to your satisfaction, please mark the topic as being solved by clicking on the green "Mark Topic Solved link under this post
Can someone convert it to version 2.0 because I have a problem with db_query and I need something like this.
I have changed db_query ( "
for $ smcFunc [ 'db_query']('','
because I had an error
Fatal error: Call to undefined function db_query() in .../SSItest.php on line 1620
And now i have
Parse error: syntax error, unexpected T_STRING in .../SSItest.php on line 1623
Thanks
Hi, it's not quite as easy as that since there are quite a few differences between 1.1 and 2.0.
I did take a stab at it but can't get the query to work. When I get time later I'll take another look at it since I do need this for whenever I decide to upgrade my forums to 2.0
Hmm, I wonder if I should add this to the already massive ssi_multiBoardNews I'm doing, as an option.
LOL, isn't it bloated enough. :P
It might be an good idea though since there seems to be a few requests for it. Shouldn't be that difficult to do either.
Bloated? It's 400 lines of pure efficiency :P
I think I might just add it, actually. It's not a huge change. Also add support for multiple icons too.
Quote from: Arantor on November 23, 2009, 01:57:57 PM
Bloated? It's 400 lines of pure efficiency :P
I think I might just add it, actually. It's not a huge change. Also add support for multiple icons too.
Do you have an eta on this mod ?
I just added it to the mod just now, it's just waiting for approval as it's done otherwise (including the bugfix for non standard avatar directories in 1.1.10)
Quote from: Arantor on November 23, 2009, 04:36:27 PM
I just added it to the mod just now, it's just waiting for approval as it's done otherwise (including the bugfix for non standard avatar directories in 1.1.10)
Woop ! :D