Login  |  Register
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome, Guest. Please login or register.
Did you miss your activation email?

October 20, 2021, 01:13:07 AM

Login with username, password and session length
Members
  • Total Members: 3825
  • Latest: JLavau
Stats
  • Total Posts: 192534
  • Total Topics: 21007
  • Online Today: 59
  • Online Ever: 1035
  • (November 26, 2020, 04:45:12 AM)
Users Online
Users: 0
Guests: 41
Total: 41

Author Topic: [block] Recent Topics for Frontpage (with board selection)  (Read 6181 times)

0 Members and 1 Guest are viewing this topic.

obarriel

  • Guest
[block] Recent Topics for Frontpage (with board selection)
« on: August 14, 2008, 08:33:17 AM »
I post here the code I am using in my website to show a recent topics list in the frontpage of tinyportal.

I tried a lot of codes but none of them were suitable a central position in the frontpage.  Finally I modified one, and nows it goes pretty well.

Code: [Select]
global $context, $settings, $scripturl, $txt, $db_prefix, $ID_MEMBER;
global $user_info, $modSettings, $func;

$num_recent = 5;
$include_boards = array(1,2,3,4,5,6,7,8);

$bullet = '<img src="'.$settings['images_url'].'/TPdivider.gif" alt="" border="0" style="margin:0 2px 0 0;" />';

  $include_boards = empty($include_boards) ? array() : $include_boards;

  $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 all the posts in distinct topics.  Newer ones will have higher IDs.
  $request = db_query("
SELECT
m.posterTime, ms.subject, m.ID_TOPIC, t.numReplies, m.ID_MEMBER, m.ID_MSG, b.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') . ", LEFT(m.body, 384) AS body, m.smileysEnabled, m.icon
FROM ({$db_prefix}messages AS m, {$db_prefix}topics AS t, {$db_prefix}boards AS b, {$db_prefix}messages AS ms)
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 = $ID_MEMBER)
LEFT JOIN {$db_prefix}log_mark_read AS lmr ON (lmr.ID_BOARD = b.ID_BOARD AND lmr.ID_MEMBER = $ID_MEMBER)" : '') . "
WHERE t.ID_LAST_MSG >= " . ($modSettings['maxMsgID'] - 35 * min($num_recent, 5)) . "
AND t.ID_LAST_MSG = m.ID_MSG
                        AND b.ID_BOARD = t.ID_BOARD" . (empty($include_boards) ? '' : "
AND b.ID_BOARD IN (" . implode(', ', $include_boards) . ")") . "
" . ((!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0) ? "
AND b.ID_BOARD != '$modSettings[recycle_board]'" : '') . "
AND $user_info[query_see_board]
AND ms.ID_MSG = t.ID_FIRST_MSG
ORDER BY t.ID_LAST_MSG DESC
LIMIT $num_recent", __FILE__, __LINE__);
  $posts = array();
  while ($row = mysql_fetch_assoc($request))
  {
    $row['body'] = strip_tags(strtr(parse_bbc($row['body'], $row['smileysEnabled'], $row['ID_MSG']), array('<br />' => '
')));
    if ($func['strlen']($row['body']) > 128)
      $row['body'] = $func['substr']($row['body'], 0, 128) . '...';

// Censor the subject.
      censorText($row['subject']);
      censorText($row['body']);

      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';

// Build the array.
$result[] = array(
                        'board' => array(
                                                'id' => $row['ID_BOARD'],
                                                'name' => $row['bName'],
                                                'href' => $scripturl . '?board=' . $row['ID_BOARD'] . '.0',
                                                'link' => '<a href="' . $scripturl . '?board=' . $row['ID_BOARD'] . '.0">' . $row['bName'] . '</a>'
),
                        'topic' => array(
'id' => $row['ID_TOPIC'],
'views' => $row['numViews'],
'replies' => $row['numReplies'],
),
                                                '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']) ? $row['posterName'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['ID_MEMBER'] . '">' . $row['posterName'] . '</a>'
       ),
                        'subject' => $row['subject'],
                        'short_subject' => shorten_subject($row['subject'], 25),
                        'preview' => $row['body'],
                        'time' => timeformat($row['posterTime']),
                        'timestamp' => forum_time(true, $row['posterTime']),
                        'href' => $scripturl . '?topic=' . $row['ID_TOPIC'] . '.msg' . $row['ID_MSG'] . ';topicseen#new',
                        'link' => '<a href="' . $scripturl . '?topic=' . $row['ID_TOPIC'] . '.msg' . $row['ID_MSG'] . '#new">' . $row['subject'] . '</a>',
                        'new' => !empty($row['isRead']),
                        'new_from' => $row['new_from'],
                        'icon' => '<img src="' . $settings[$icon_sources[$row['icon']]] . '/post/' . $row['icon'] . '.gif" align="middle" alt="' . $row['icon'] . '" border="0" />',
);
}

mysql_free_result($request);

// Print out the results
  echo '<span class="smallertext">','<br>';
foreach($result as $my){
  echo "$bullet";
  echo ' ', '<span class="normaltext">'.$my['board']['link'],': ';
  echo '<span class="normaltext">'.$my['link'],' ';
  echo 'por ', '<span class="normaltext">'.$my['poster']['link'],' ';
  echo '(', '<span class="normaltext">'.$my['topic']['replies'],') ';
  // is this topic new? (assume they are logged in)
  if (!$my['new'] && $context['user']['is_logged'])
  echo '
    <a href="', $scripturl, '?topic=', $my['topic'], '.from', $my['newtime'], '#new">
    <img src="', $settings['images_url'], '/', $context['user']['language'], '/new.gif" alt="', $txt[302], '" border="0" /></a>';
  echo '</span>';
  echo '<span class="largetext">','<br>';
}

Put it in a phpbox

These two lines are for configuration:

Code: [Select]
$num_recent = 5;
$include_boards = array(1,2,3,4,5,6,7,8);

You can see an example in www.reproductormp3.net
« Last Edit: September 17, 2008, 12:11:28 AM by Bloc »

shengton

  • Guest
Re: [block] Recent Topics for Frontpage (with board selection)
« Reply #1 on: September 26, 2008, 11:12:01 PM »
How about Unanswered Topics instead of Recent Topics is displayed in the Frontpage block or left/right block.

spider1es

  • Guest
Re: [block] Recent Topics for Frontpage (with board selection)
« Reply #2 on: May 24, 2009, 02:35:07 AM »
Hello, since I can do in order that in this code THE NEW POST turn out to be alone, not the ANSWERS?


Graces(Thanks) and pardon for my Englishman

Offline IchBin

  • Developer
  • *
  • Posts: 16231
Re: [block] Recent Topics for Frontpage (with board selection)
« Reply #3 on: May 24, 2009, 05:54:05 PM »
Being that you're asking for a totally different snippet, you should perhaps post in the request board and see if anyone would like to make the code for you.

spider1es

  • Guest
Re: [block] Recent Topics for Frontpage (with board selection)
« Reply #4 on: May 25, 2009, 06:45:17 AM »
Ok, he(she) was thinking that alone serious to change some lines into the code, then it(he,she) will create a post to see if they help me.

THANK YOU.

NCSurfer

  • Guest
Re: [block] Recent Topics for Frontpage (with board selection)
« Reply #5 on: September 10, 2009, 06:13:10 PM »
Nice, only thing I saw was that you need to change "por" to "by" (or something other than "por") in your code.

Thanks for sharing