TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

October 12, 2024, 01:27:56 PM

Login with username, password and session length
Members
Stats
  • Total Posts: 195,395
  • Total Topics: 21,244
  • Online today: 215
  • Online ever: 3,540 (September 03, 2022, 01:38:54 AM)
Users Online
  • Users: 0
  • Guests: 51
  • Total: 51

[Discussion] Random topic

Started by JPDeni, May 05, 2009, 04:33:13 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Freddy

Quote from: illori on October 14, 2015, 04:24:37 PM
then i guess the script will only work with 1 category or all categories.
Yes that is correct. I just adapted it so you can exclude categories. Try this...

Just set this to zero...

$category = 0;

Then set $exclude to an array of cat ids. For example...

$exclude = array(12, 5, 3);

and it will ignore those.

global $txt, $user_info, $settings, $memberContext, $scripturl, $boardurl, $smcFunc;

// Configuration...

// Percentage width of avatar area
$avatararea = 30;
// Colour of border around avatar
$avbordercol= '#fff';
// Default width and height of avatar
$avwidth = 35;
$avheight= 35;
// Path to 'no avatar' image.
$noavatarurl = $boardurl . '/Themes/default/images/noavatar.jpg';

// If you want to limit it to one category, enter the category number here
// If you want to use all categories, set it to 0. If you want to exclude cats below set this to zero too.
$category = 0 ;

// Exclude categories ? Use the category ids eg. $exclude = array(3,6);
// Also set $category above to 0 (zero) for this to work.
$exclude = array();

// Set how many posts you want to display
$limit = 5;

// If you want to limit the number of characters displayed, enter the length here
// If you want the whole post to be displayed, no matter what the length, set it to 0
$maxlength = 1000;

loadLanguage('Stats');

$result = $smcFunc['db_query']('', "
SELECT m.id_board, m.icon, m.subject, m.body, IFNULL(mem.real_name, m.poster_name) AS poster_name, m.poster_time,
t.num_replies, t.id_topic, m.id_member, m.smileys_enabled, m.id_msg, t.locked
FROM ({db_prefix}topics AS t, {db_prefix}messages AS m, {db_prefix}boards as b)
LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)
WHERE m.id_msg = t.id_first_msg
AND b.id_board = m.id_board
AND $user_info[query_see_board]" .
($category > 0 ? " AND id_cat = {int:cat}" : "")
.
(!empty($exclude) ? " AND id_cat NOT IN ({array_int:exclude})" : "")
. "
ORDER BY RAND() LIMIT {int:limit}",
array(
'exclude' => $exclude,
'cat' => $category,
'limit' => $limit)
);

while ($row = $smcFunc['db_fetch_assoc']($result))
{
if ($maxlength > 0 && strlen($row['body']) > $maxlength)
{
$row['body'] = substr($row['body'], 0, $maxlength);
while (substr($row['body'],-1) <> ' ')
$row['body'] = substr($row['body'],0,-1);
$row['body'] .= ' ...';
}

// Get the avatar and build the image link for it, if it exists...
$memberID = $row['id_member'];
loadMemberData($memberID);
loadMemberContext($memberID);

if (!empty($memberContext[$memberID]['avatar']['href']))
{
$news['avatar'] = '<img width="' . $avwidth . '" height="' . $avheight . '" style="border:1px solid ' . $avbordercol . ' ;padding: 2px" alt="' . $row['poster_name'] . '" title="' . $row['poster_name'] . '" src="' . $memberContext[$memberID]['avatar']['href'] . '" />';
}
else
{
$news['avatar'] = '<img width="' . $avwidth . '" height="' . $avheight . '" style="border:1px solid ' . $avbordercol . ' ;padding: 2px" alt="' . $row['poster_name'] . '" title="' . $row['poster_name'] . '" src="' . $noavatarurl . '" />';
}

$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']);

$news['icon'] = '<img src="' . $settings[$icon_sources[$row['icon']]] . '/post/' . $row['icon'] . '.gif" align="middle" alt="' . $row['icon'] . '" border="0" />';
$news['subject'] = $row['subject'];
$news['time'] = timeformat($row['poster_time']);
$news['body'] = $row['body'];
$news['href'] = $scripturl . '?topic=' . $row['id_topic'] . '.0';
$news['link'] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $row['num_replies'] . ' ' . ($row['num_replies'] == 1 ? $txt['ssi_comment'] : $txt['ssi_comments']) . '</a>';
$news['comment_link'] = !empty($row['locked']) ? '' : '<a href="' . $scripturl . '?action=post;topic=' . $row['id_topic'] . '.' . $row['num_replies'] . ';num_replies=' . $row['num_replies'] . '">' . $txt['ssi_write_comment'] . '</a>';
$news['poster'] = !empty($row['id_member']) ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['poster_name'] . '</a>' : $row['poster_name'];
$news['locked'] = !empty($row['locked']);

// Display it all...try your own styling. Might be better in a table.
echo '
<div style="width:100%;display:table">
<div style="width: ' , $avatararea , '%;float:left;text-align:center">
                ' , $news['avatar'] , '
</div>
<div style="width: ' , 99 - $avatararea ,  '%;float:right">
<a href="', $news['href'], '">', $news['icon'], '</a> <strong>', $news['subject'], '</strong>
<div class="smaller">', $news['time'], '<br />' , $txt['by'] , ' ' , $news['poster'], '</div>
</div>
<div class="post" style="padding: 2ex 0;clear:both">', $news['body'], '</div>
    ', $news['link'], $news['locked'] ? '' : ' | ' . $news['comment_link'], '<hr />
</div>';
}

$smcFunc['db_free_result']($result);

ayozeve

Thanks a lot but i have just insert it and it doesnt't work for me :-[. I wrote this:

global $txt, $user_info, $settings, $memberContext, $scripturl, $boardurl, $smcFunc;

// Configuration...

// Percentage width of avatar area
$avatararea = 8;
// Colour of border around avatar
$avbordercol= '#fff';
// Default width and height of avatar
$avwidth = 35;
$avheight= 35;
// Path to 'no avatar' image.
$noavatarurl = $boardurl . '/Themes/default/images/noavatar.jpg';

// If you want to limit it to one category, enter the category number here
// If you want to use all categories, set it to 0. If you want to exclude cats below set this to zero too.
$category = 0 ;

// Exclude categories ? Use the category ids eg. $exclude = array(3,6);
// Also set $category above to 0 (zero) for this to work.
$exclude = array(54,40,13,43,47,14,38,86,19,83,61,30,34,16,32,17,28,53,41,8,44,48,9,39,45,85,18,82,60,29,35,11,31,10,26,64,59,65,66,77,78,67,68,84,69,81,70,71,72,73,74,75,76);

// Set how many posts you want to display
$limit = 1;

// If you want to limit the number of characters displayed, enter the length here
// If you want the whole post to be displayed, no matter what the length, set it to 0
$maxlength = 1000;

loadLanguage('Stats');

$result = $smcFunc['db_query']('', "
SELECT m.id_board, m.icon, m.subject, m.body, IFNULL(mem.real_name, m.poster_name) AS poster_name, m.poster_time,
t.num_replies, t.id_topic, m.id_member, m.smileys_enabled, m.id_msg, t.locked
FROM ({db_prefix}topics AS t, {db_prefix}messages AS m, {db_prefix}boards as b)
LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)
WHERE m.id_msg = t.id_first_msg
AND b.id_board = m.id_board
AND $user_info[query_see_board]" .
($category > 0 ? " AND id_cat = {int:cat}" : "")
.
(!empty($exclude) ? " AND id_cat NOT IN ({array_int:exclude})" : "")
. "
ORDER BY RAND() LIMIT {int:limit}",
array(
'exclude' => $exclude,
'cat' => $category,
'limit' => $limit)
);

while ($row = $smcFunc['db_fetch_assoc']($result))
{
if ($maxlength > 0 && strlen($row['body']) > $maxlength)
{
$row['body'] = substr($row['body'], 0, $maxlength);
while (substr($row['body'],-1) <> ' ')
$row['body'] = substr($row['body'],0,-1);
$row['body'] .= ' ...';
}

// Get the avatar and build the image link for it, if it exists...
$memberID = $row['id_member'];
loadMemberData($memberID);
loadMemberContext($memberID);

if (!empty($memberContext[$memberID]['avatar']['href']))
{
$news['avatar'] = '<img width="' . $avwidth . '" height="' . $avheight . '" style="border:1px solid ' . $avbordercol . ' ;padding: 2px" alt="' . $row['poster_name'] . '" title="' . $row['poster_name'] . '" src="' . $memberContext[$memberID]['avatar']['href'] . '" />';
}
else
{
$news['avatar'] = '<img width="' . $avwidth . '" height="' . $avheight . '" style="border:1px solid ' . $avbordercol . ' ;padding: 2px" alt="' . $row['poster_name'] . '" title="' . $row['poster_name'] . '" src="' . $noavatarurl . '" />';
}

$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']);

$news['icon'] = '<img src="' . $settings[$icon_sources[$row['icon']]] . '/post/' . $row['icon'] . '.gif" align="middle" alt="' . $row['icon'] . '" border="0" />';
$news['subject'] = $row['subject'];
$news['time'] = timeformat($row['poster_time']);
$news['body'] = $row['body'];
$news['href'] = $scripturl . '?topic=' . $row['id_topic'] . '.0';
$news['link'] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $row['num_replies'] . ' ' . ($row['num_replies'] == 1 ? $txt['ssi_comment'] : $txt['ssi_comments']) . '</a>';
$news['comment_link'] = !empty($row['locked']) ? '' : '<a href="' . $scripturl . '?action=post;topic=' . $row['id_topic'] . '.' . $row['num_replies'] . ';num_replies=' . $row['num_replies'] . '">' . $txt['ssi_write_comment'] . '</a>';
$news['poster'] = !empty($row['id_member']) ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['poster_name'] . '</a>' : $row['poster_name'];
$news['locked'] = !empty($row['locked']);

// Display it all...try your own styling. Might be better in a table.
echo '
<div style="width:100%;display:table">
<div style="width: ' , $avatararea , '%;float:left;text-align:center">
                ' , $news['avatar'] , '
</div>
<div style="width: ' , 99 - $avatararea ,  '%;float:right">
<a href="', $news['href'], '">', $news['icon'], '</a> <strong>', $news['subject'], '</strong>
<div class="smaller">', $news['time'], '<br />' , $txt['by'] , ' ' , $news['poster'], '</div>
</div>
<div class="post" style="padding: 2ex 0;clear:both">', $news['body'], '</div>
    ', $news['link'], $news['locked'] ? '' : ' | ' . $news['comment_link'], '<hr />
</div>';
}

$smcFunc['db_free_result']($result);



I only let 2 board to show (to see it is correct), but it doesn't work. Are there any bad????
The problem with this script is that can show private content from boards, i guess.

Thanks so much.

Freddy

$exclude needs to be the cats you want left out.

ayozeve

Yes, i understood but it didn't work for me. It show all the boards and the exlude boards too.

illori

are you entering the numbers for the CATEGORIES or the numbers for the BOARDS. you need to make sure they are the id numbers for the CATEGORIES, if you have a category with both public and private boards in it, then you need to exclude that CATEGORY.

ayozeve

Quote from: illori on October 16, 2015, 12:47:25 PM
are you entering the numbers for the CATEGORIES or the numbers for the BOARDS. you need to make sure they are the id numbers for the CATEGORIES, if you have a category with both public and private boards in it, then you need to exclude that CATEGORY.

You have rights, I was put id boards instead id cats. Thanks a lot men!!

Ken.

" If everything seems under control, you're not going fast enough." - Mario Andretti
Yesterday When I was Young.

VladTepes

How can I get this to display in exactly the same manner / format as the 'Recent Topics' block?

(So just avatar, title, author, date/time)

I don't want any preview etc.

Thanks