News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

ssi_boardNews(); for all boards

Started by dodos26, March 28, 2021, 08:51:52 AM

Previous topic - Next topic

dodos26

ssi_boardNews(); for all boards.
I wanted to modify this feature to display topics from all categories, and not the specified ID...
But I don't want it to display 5 of each. I have a lot of these categories over 100 ... I want all of them to be displayed to me by the latest 15.
I am using a simple portal 2.3.7 And it would be good to write it under the php block.
There is a nice block there "Latest news / threads" But it seems that selecting the option show topic.
It does not work because if there is a reply to this topic, the topic is shown in the most recent.

So what do I want to achieve a hybrid ssi_boardNews and ssi_recentPosts.

Kindred

Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

dodos26

I wrote that I want to avoid it....
If the topic receives a comment.. This will be displayed in the news..
ssi_boardNews only displays topics sorted from the date the topic was created.
ssi_recentTopics(); only shows topics sorted from the date of the last post.

And I want a function ssi_recentTopics(); which is sorted by the topic creation date.

Kindred

 Well, no, you said not ssi_recentPosts,not recentTopics...

However,  you are correct....  but doing what you suggest is going to be an EXPENSIVE routine (in terms of server resources)
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

live627


dodos26

Quote from: Kindred on March 28, 2021, 06:55:47 PM
Well, no, you said not ssi_recentPosts,not recentTopics...

However,  you are correct....  but doing what you suggest is going to be an EXPENSIVE routine (in terms of server resources)

Why should it be less efficient than ssi_recentTopics ? It would do the same thing, it would only sort differently. Unfortunately, this tangle of database queries is magic for me and I will not do it myself.

Quote from: live627 on March 29, 2021, 08:37:33 AM
there's a mod that may work for you

[SSI Multiple Board News (ssi_multiBoardNews)

YeaH I saw it BUUUUT apply it for these categories :) with as many subcategories see screens:

dodos26

Hey I did it like this,
I wonder if it can be done better or more efficiently
Is there any variable that specifies the maximum ID board? I don't know if it is optimal to use range()
global $smcFunc, $scripturl, $modSettings;

$id_board = range(1,200);
$list_limit = 10;

$request = $smcFunc['db_query']('', '
SELECT t.id_topic, m.subject
FROM {db_prefix}topics AS t
INNER JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_first_msg)
WHERE t.id_board IN ({array_int:board})' . ($modSettings['postmod_active'] ? '
AND t.approved = {int:approved}
AND m.approved = {int:approved}' : '') . '
ORDER BY t.id_topic DESC
LIMIT {int:limit}',
array(
'board' => $id_board,
'approved' => 1,
'limit' => $list_limit,
)
);
$topics = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
$topics[$row['id_topic']] = $row['subject'];
$smcFunc['db_free_result']($request);

echo '
<ul>';

if (empty($topics))
{
echo '
<li>There aren\'t any topics.</li>';
}
else
{
foreach ($topics as $id => $subject)
echo '
<li><a href="', $scripturl, '?topic=', $id, '.0">', $subject, '</a></li>';
}

echo '
</ul>';

vbgamer45

You could change
t.id_board IN ({array_int:board})
To
t.id_board != 0

And would do all boards...
Community Suite for SMF - Take your forum to the next level built for SMF, Gallery,Store,Classifieds,Downloads,more!

SMFHacks.com -  Paid Modifications for SMF

Mods:
EzPortal - Portal System for SMF
SMF Gallery Pro
SMF Store SMF Classifieds Ad Seller Pro

dodos26

So now I've made a clean nice block for simple portal 2.3.7 testing. I do not know if it can be done better, but probably if so, write it. And let this code serve you well :)



<?php
{

global $smcFunc$scripturl$modSettings$user_info$txt$context$color_profile$settings$db_prefix;

$list_limit 10;
$display_type 'full';

$request $smcFunc['db_query']('''
SELECT
m.poster_time, ms.subject, m.id_topic, m.id_member, m.id_msg, b.id_board, b.name AS board_name, t.num_replies, t.num_views,
. ($user_info['is_guest'] ? '1 AS is_read, 0 AS new_from' '
IFNULL(lt.id_msg, IFNULL(lmr.id_msg, 0)) >= m.id_msg_modified AS is_read,
IFNULL(lt.id_msg, IFNULL(lmr.id_msg, -1)) + 1 AS new_from'
) . '
FROM {db_prefix}topics AS t
INNER JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_last_msg)
INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board)
INNER JOIN {db_prefix}messages AS ms ON (ms.id_msg = t.id_first_msg)
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 = t.id_topic AND lt.id_member = {int:current_member})
LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = b.id_board AND lmr.id_member = {int:current_member})' 
'') . '
WHERE t.id_board != 0' 
. ($modSettings['postmod_active'] ? '
AND t.approved = {int:approved}
AND m.approved = {int:approved}' 
'') . '
ORDER BY t.id_topic DESC
LIMIT {int:limit}'
,
array(
'approved' => 1,
'limit' => $list_limit,
'current_member' => $user_info['id'],
)
);


$topics = array();
while ($row $smcFunc['db_fetch_assoc']($request))
{
censorText($row['subject']);
$topics[] = $row;
}
$smcFunc['db_free_result']($request);


if (empty($topics))
{
echo $txt['error_sp_no_posts_found'];
return;
}
else
$topics[count($topics) - 1]['is_last'] = true;


$colorids = array();
foreach ($topics as $item)
$colorids[] = $item['id_member'];
sp_loadColors($colorids);


if ($display_type == 'compact')
{
foreach ($topics as $key => $item)
echo '<a href="'$scripturl '?topic=' $item['id_topic'] . '.msg' $item['id_msg'] . ';topicseen#new''">'$item['subject'], '</a> <span class="smalltext">'$txt['by'], ' '$color_profile[$item['id_member']]['link'], !empty($item['is_read']) ? '' ' <a href="' $scripturl '?topic=' $item['id_topic'] . '.msg' $item['new_from'] . ';topicseen#new" rel="nofollow"><img src="' $settings['lang_images_url'] . '/new.gif" alt="' $txt['new'] . '" border="0" /></a>','<br />['timeformat($item['poster_time']), ']</span><br />', empty($item['is_last']) ? '<hr />' '';
}
elseif ($display_type == 'full')
{
echo '<table class="sp_fullwidth">';

foreach ($topics as $item)
echo '
<tr>
<td class="sp_recent_icon sp_center">
'
sp_embed_image(empty($display_type) ? 'post' 'topic'), '
</td>
<td class="sp_recent_subject">
<a href="'
$scripturl '?topic=' $item['id_topic'] . '.msg' $item['id_msg'] . ';topicseen#new''">'$item['subject'], '</a> 
'
, !empty($item['is_read']) ? '' '<a href="' $scripturl '?topic=' $item['id_topic'] . '.msg' $item['new_from'] . ';topicseen#new"><img src="' $settings['images_url'] . '/' $context['user']['language'] . '/new.gif" alt="' $txt['new'] . '" border="0" /></a>''<br />[''<a href="' $scripturl '?board=' $item['id_board'] . '.0">' $item['board_name'] . '</a>'']
</td>
<td class="sp_recent_info sp_right">
'
$color_profile[$item['id_member']]['link'], ' | '$txt['sp-articlesViews'], ': '$item['num_views'], ' | '$txt['sp-articlesComments'], ': '$item['num_replies'], '<br />'timeformat($item['poster_time']), '
</td>
</tr>'
;

echo '</table>';
}


}
?>

dodos26

So now I've made a clean nice block for simple portal 2.3.7 testing. I do not know if it can be done better, but probably if so, write it. And let this code serve you well :)

FIX
Fixed topic date display. Now displays the date of the first topic instead of the date of the last reply in it.



<?php
{

global $smcFunc$scripturl$modSettings$user_info$txt$context$color_profile$settings$db_prefix;

$list_limit 10;  //Count number of messages to display
$display_type 'full'// full or compact

$request $smcFunc['db_query']('''
SELECT
m.poster_time, ms.subject, m.id_topic, m.id_member, m.id_msg, b.id_board, b.name AS board_name, t.num_replies, t.num_views,
. ($user_info['is_guest'] ? '1 AS is_read, 0 AS new_from' '
IFNULL(lt.id_msg, IFNULL(lmr.id_msg, 0)) >= m.id_msg_modified AS is_read,
IFNULL(lt.id_msg, IFNULL(lmr.id_msg, -1)) + 1 AS new_from'
) . '
FROM {db_prefix}topics AS t
INNER JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_first_msg)
INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board)
INNER JOIN {db_prefix}messages AS ms ON (ms.id_msg = t.id_first_msg)
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 = t.id_topic AND lt.id_member = {int:current_member})
LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = b.id_board AND lmr.id_member = {int:current_member})' 
'') . '
WHERE t.id_board != 0' 
. ($modSettings['postmod_active'] ? '
AND t.approved = {int:approved}
AND m.approved = {int:approved}' 
'') . '
ORDER BY t.id_topic DESC
LIMIT {int:limit}'
,
array(
'approved' => 1,
'limit' => $list_limit,
'current_member' => $user_info['id'],
)
);


$topics = array();
while ($row $smcFunc['db_fetch_assoc']($request))
{
censorText($row['subject']);
$topics[] = $row;
}
$smcFunc['db_free_result']($request);


if (empty($topics))
{
echo $txt['error_sp_no_posts_found'];
return;
}
else
$topics[count($topics) - 1]['is_last'] = true;


$colorids = array();
foreach ($topics as $item)
$colorids[] = $item['id_member'];
sp_loadColors($colorids);


if ($display_type == 'compact')
{
foreach ($topics as $key => $item)
echo '<a href="'$scripturl '?topic=' $item['id_topic'] . '.msg' $item['id_msg'] . ';topicseen#new''">'$item['subject'], '</a> <span class="smalltext">'$txt['by'], ' '$color_profile[$item['id_member']]['link'], !empty($item['is_read']) ? '' ' <a href="' $scripturl '?topic=' $item['id_topic'] . '.msg' $item['new_from'] . ';topicseen#new" rel="nofollow"><img src="' $settings['lang_images_url'] . '/new.gif" alt="' $txt['new'] . '" border="0" /></a>','<br />['timeformat($item['poster_time']), ']</span><br />', empty($item['is_last']) ? '<hr />' '';
}
elseif ($display_type == 'full')
{
echo '<table class="sp_fullwidth">';

foreach ($topics as $item)
echo '
<tr>
<td class="sp_recent_icon sp_center">
'
sp_embed_image(empty($display_type) ? 'post' 'topic'), '
</td>
<td class="sp_recent_subject">
<a href="'
$scripturl '?topic=' $item['id_topic'] . '.msg' $item['id_msg'] . ';topicseen#new''">'$item['subject'], '</a> 
'
, !empty($item['is_read']) ? '' '<a href="' $scripturl '?topic=' $item['id_topic'] . '.msg' $item['new_from'] . ';topicseen#new"><img src="' $settings['images_url'] . '/' $context['user']['language'] . '/new.gif" alt="' $txt['new'] . '" border="0" /></a>''<br />[''<a href="' $scripturl '?board=' $item['id_board'] . '.0">' $item['board_name'] . '</a>'']
</td>
<td class="sp_recent_info sp_right">
'
$color_profile[$item['id_member']]['link'], ' | '$txt['sp-articlesViews'], ': '$item['num_views'], ' | '$txt['sp-articlesComments'], ': '$item['num_replies'], '<br />'timeformat($item['poster_time']), '
</td>
</tr>'
;

echo '</table>';
}

}
?>


Advertisement: