TinyPortal

Development => Block Codes => Topic started by: IchBin on February 22, 2010, 07:53:26 PM

Title: Recent topics for SMF2
Post by: IchBin on February 22, 2010, 07:53:26 PM
Let me know if there are any errors as I haven't tested any of this. :)

global $context, $settings, $scripturl, $txt, $db_prefix, $user_info, $modSettings, $user_profile, $smcFunc;

//////////////////////////////////////////// ---------- Unconditional Exclude
//   
   $exclude_boards = array();   // KEEP (to preserve variable declaration)
//   $exclude_boards = array(5);   //  Exclude single board
//     $exclude_boards = array(55,69);   //  Exclude multiple boards
   $ex_board_clause = !empty($exclude_boards) ? ' AND b.id_board NOT IN (' . implode(', ', $exclude_boards) . ')' : '';
//   
//   

//////////////////////////////////////////// ---------- Use in TP PHP Article (no title or frame from theme)
//   This will give most recent XX posted to topics -OR-
//   most recent XX unreplied to topics -OR-
//   topics posted to in last XX hours -OR-
//   most recent XX topics on topic notify list
//   
//   Sorts by most recent reply (descending; most recent first) -OR-
//            creation order (descending; most recent first)
//   
//   All in the detailed topic format
//   
//   
//   Default
//   index.php?page=##
//   most recent posted to topics - will list
//   number equal to  $settings['number_recent_posts']
//   
//   index.php?page=##;count=50 or index.php?page=##;type=last;count=50
//   50 most recently posted to topics
//   
//   index.php?page=##;type=unreplied or index.php?page=##;type=unreplied;count=50
//   Most recent unreplied to topics - will
//   list number specified in 'count' or default to
//   number equal to  $settings['number_recent_posts']
//   
//   index.php?page=##;type=hours or index.php?page=##;type=hours;count=12
//   Topics posted to in last number of hours
//   specified in 'count' or default to 24.
//   
//   index.php?page=##;type=notify or index.php?page=##;type=notify;count=50
//   Topics in topic notifcation list up to number
//   specified in 'count' or a maximum of 100 topics.
//   
//   *** Admins Only ***
//   index.php?page=##;type=notify;user=XXX or index.php?page=##;type=notify;user=XXX;count=50
//   Topics in topic notifcation list of specified user up to number
//   specified in 'count' or a maximum of 100 topics.
//   
//   index.php?page=##;type=started or index.php?page=##;type=started;count=50
//   Topics started by current user list up to number
//   specified in 'count' or a maximum of 100 topics.
//   
//   *** Admins Only ***
//   index.php?page=##;type=notify;user=XXX or index.php?page=##;type=started;user=XXX;count=50
//   Topics started by specified user up to number
//   specified in 'count' or a maximum of 100 topics.
//   
//   Add argument order=create to sort by topic creation sequence (most recent first)
//   rather than by last reply sequence

   $do_query = 1;

//////////////////////////////////////////// ---------- Poor Man's Global Announcements Block (center block - no Title/Frame)
//   Delete documentation comments above and marked section below
//
//   $announce_topics = array(254, 568, 675, 678); // Topic ID's to be 'Announced'
//
//   $heading = '<center>Announcements<center>';
//   $where_clause = 't.ID_TOPIC IN (' . implode(', ', $announce_topics) . ')';
//   $limit_clause = '';
//   $order_clause = 't.ID_LAST_MSG DESC';
////////////////////////////////////////////   

//////////////////////////////////////////// ---------- Last 5 Topics Started by User Block (center block - no Title/Frame)
//   Delete documentation comments above and marked section below
//
//   $heading = 'Most Recent Topics You Started';
//   $where_clause = 'ms.ID_MEMBER = '.$ID_MEMBER;
//   $limit_clause = 'LIMIT 5';
//   $order_clause = 't.ID_FIRST_MSG DESC';
////////////////////////////////////////////   

//////////////////////////////////////////// ---------- Boardindex Most Recent Topics Arguments
//
//   Comment out the Info Center's Most Recent Posts Code and Insert this
//   to show Most Recent Topics in full detail style instead
//
//   $list_count = $settings['number_recent_posts'];
//   $heading = 'Most Recently Posted To Topics';
//   $where_clause = 't.ID_LAST_MSG >= ' . ($modSettings['maxMsgID'] - 50 * min($list_count, 5));
//   $limit_clause = 'LIMIT ' . $list_count;
//   $order_clause = 't.ID_LAST_MSG DESC';
////////////////////////////////////////////   

////////////////////////////////////////////  ------ Remove down to next mark to use in block/boardindex ------
//
   if (empty($settings['number_recent_posts']))
      $number_recent_posts = 20;
   else
      $number_recent_posts = $settings['number_recent_posts'];

        if( isset($_GET['type']) )
      $list_type = $_GET['type'];
   else
      $list_type = 'last';

        if( isset($_GET['count']) )
      $list_count = $_GET['count'];
   else
   {
      $list_count = $number_recent_posts;
      if ($list_type == 'notify')
         $list_count = 100;
      elseif ($list_type == 'hours')
         $list_count = 24;
   }

   if ($list_count <= 0)
   {
      $list_count = $number_recent_posts;
      if ($list_type == 'hours')
         $list_count = 24;
   }

   if ($list_count > 100)
      $list_count = 100;

        if( isset($_GET['order']) )
      $list_order = $_GET['order'];
   else
      $list_order = 'lastpost';

        if( $list_order == 'create' )
      $order_clause = 't.id_first_msg DESC';
   else
      $order_clause = 't.id_last_msg DESC';

   if ($list_type == 'hours')
   {
      $list_from = strtotime($list_count.' hours ago');
      $where_clause = 'ml.poster_time >= ' . $list_from;
      $limit_clause = ' ';
      $heading = 'Topics Posted To In Last '. $list_count . ' Hours';
   }
   elseif ($list_type == 'unreplied')
   {
      $where_clause = 't.num_replies = 0';
      if ($list_count == 0)
      {
         $limit_clause = ' ';
         $heading = 'Unreplied To Topics';
      }
      else
      {
      $limit_clause = 'LIMIT ' . $list_count;
      $heading = $list_count . ' Most Recent Unreplied To Topics';
      }
   }
   elseif ($list_type == 'notify')
   {
      if (isset($_GET['user']) && $user_info['is_admin'])
      {
         $watched_topics = array();
         $request = $smcFunc['db_query']("", "SELECT id_topic FROM ".$db_prefix."log_notify
                                 WHERE id_member = {int:user_id}
                                 AND id_board = 0",
                                 array('user_id' => $_GET['user']));
         while ($row = $smcFunc['db_fetch_assoc']($request))
            $watched_topics[] = $row['id_topic'];
         $smcFunc['db_free_result']($request);
         $heading = $list_count . ' Most Recent Topics Being Watched by User # '.$_GET['user'];
         $where_clause = 't.id_topic IN (' . implode(', ', $watched_topics) . ')';
         $limit_clause = 'LIMIT ' . $list_count;
         if (empty($watched_topics))
            $do_query = 0;
      }
      else
      {
         $watched_topics = array();
         $request = $smcFunc['db_query']("", "SELECT id_topic FROM ".$db_prefix."log_notify
                                 WHERE id_member = {int:id_member}
                                 AND id_board = 0",
                                 array('id_member' => $user_info['id']));
         while ($row = $smcFunc['db_fetch_assoc']($request))
            $watched_topics[] = $row['id_topic'];
         $smcFunc['db_free_result']($request);
         $heading = $list_count . ' Most Recent Topics Being Watched';
         $where_clause = 't.id_topic IN (' . implode(', ', $watched_topics) . ')';
         $limit_clause = 'LIMIT ' . $list_count;
         if (empty($watched_topics))
            $do_query = 0;
      }
   }
   elseif ($list_type == 'started')
   {
      if (isset($_GET['user']) && $user_info['is_admin'])
      {
         $where_clause = 'ms.id_member = '.$_GET['user'];
         $limit_clause = 'LIMIT ' . $list_count;
              if( $list_order == 'create' )
         {
            $order_clause = 't.id_first_msg DESC';
            $heading = 'Most Recent Topics Started by User '.$_GET['user'];
         }
         else
         {
            $order_clause = 't.id_last_msg DESC';
            $heading = 'Most Recently Posted To Topics Started by User '.$_GET['user'];
         }
      }
      else
      {
         $where_clause = 'ms.id_member = '.$user_info['id'];
         $limit_clause = 'LIMIT ' . $list_count;
              if( $list_order == 'create' )
         {
            $order_clause = 't.id_first_msg DESC';
            $heading = 'Most Recent Topics You Started';
         }
         else
         {
            $order_clause = 't.id_last_msg DESC';
            $heading = 'Most Recently Posted To Topics You Started';
         }
      }
   }
   else
   {
      $where_clause = 't.id_last_msg >= ' . ($modSettings['maxMsgID'] - 90 * min($list_count, 5));
      $limit_clause = 'LIMIT ' . $list_count;
      $heading = $list_count . ' Most Recently Posted To Topics';
   }
//
////////////////////////////////////////////  ------ Remove up to first mark to use in block/boardindex ------

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

   $groupcolors = array();
   $request = $smcFunc['db_query']("", "SELECT id_group, online_color FROM ".$db_prefix."membergroups",array());
   while ($row = $smcFunc['db_fetch_assoc']($request))
      $groupcolors[$row['id_group']] = $row['online_color'];
   $smcFunc['db_free_result']($request);

   $topics = array();

   if ($do_query == 1)
   {
      $request = $smcFunc['db_query']("", "
      SELECT
            ms.subject AS firstSubject, ms.poster_time AS firstPosterTime, ms.id_topic, t.id_last_msg, t.id_board, b.name AS bname,
            t.num_replies, t.num_views, ms.id_member AS ID_FIRST_MEMBER, ml.id_member AS ID_LAST_MEMBER,
            ml.poster_time AS lastPosterTime, IFNULL(mems.real_name, ms.poster_name) AS firstPosterName,
            IFNULL(meml.real_name, ml.poster_name) AS lastPosterName,
            mems.id_group as mems_group, meml.id_group as meml_group,
            ml.subject AS lastSubject, b.member_groups,
            ml.icon AS lastIcon, ms.icon AS firstIcon, t.id_poll, t.is_sticky, t.locked, ml.modified_time AS lastModifiedTime,
            LEFT(ml.body, 384) AS lastBody, LEFT(ms.body, 384) AS firstBody,
            ml.smileys_enabled AS lastSmileys, ms.smileys_enabled AS firstSmileys, t.id_first_msg,"
            . ($user_info['is_guest'] ? '1 AS isRead, 0 AS new_from' : '
            IFNULL(lt.id_msg, IFNULL(lmr.id_msg, 0)) >= ml.id_msg_modified AS isRead,
            IFNULL(lt.id_msg, IFNULL(lmr.id_msg, -1)) + 1 AS new_from') . "
         FROM (".$db_prefix."messages AS ms, ".$db_prefix."messages AS ml, ".$db_prefix."topics AS t, ".$db_prefix."boards AS b)
            LEFT JOIN ".$db_prefix."members AS mems ON (mems.id_member = ms.id_member)
            LEFT JOIN ".$db_prefix."members AS meml ON (meml.id_member = ml.id_member)
            LEFT JOIN ".$db_prefix."log_topics AS lt ON (lt.id_topic = t.id_topic AND lt.id_member = ".$user_info['id'].")
            LEFT JOIN ".$db_prefix."log_mark_read AS lmr ON (lmr.id_board = t.id_board AND lmr.id_member = ".$user_info['id'].")
         WHERE " . $where_clause . $ex_board_clause . "
            AND t.id_topic = ms.id_topic
            AND b.id_board = t.id_board" . (!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0 ? " AND b.id_board != ".$modSettings['recycle_board'] : "") . "
            AND ms.id_msg = t.id_first_msg
            AND ml.id_msg = t.id_last_msg
            AND " . $user_info['query_see_board'] . "
         ORDER BY " . $order_clause . " " . $limit_clause,
       array());


   $topic_ids = array();
   while ($row = $smcFunc['db_fetch_assoc']($request))
   {
      if ($row['id_poll'] > 0 && $modSettings['pollMode'] == '0')
         continue;

      $topic_ids[] = $row['id_topic'];

      // Clip the strings first because censoring is slow :/. (for some reason?)
      $row['firstBody'] = strip_tags(strtr(parse_bbc($row['firstBody'], $row['firstSmileys'], $row['id_first_msg']), array('<br />' => '
')));
      if (strlen($row['firstBody']) > 128)
         $row['firstBody'] = substr($row['firstBody'], 0, 128) . '...';
      $row['lastBody'] = strip_tags(strtr(parse_bbc($row['lastBody'], $row['lastSmileys'], $row['id_last_msg']), array('<br />' => '
')));
      if (strlen($row['lastBody']) > 128)
         $row['lastBody'] = substr($row['lastBody'], 0, 128) . '...';

         $row['lastSubject'] = $row['firstSubject'];
         $row['lastBody'] = $row['firstBody'];

      // Decide how many pages the topic should have.
      $topic_length = $row['num_replies'] + 1;
      if ($topic_length > $modSettings['defaultMaxMessages'])
      {
         $tmppages = array();
         $tmpa = 1;
         for ($tmpb = 0; $tmpb < $topic_length; $tmpb += $modSettings['defaultMaxMessages'])
         {
            $tmppages[] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.' . $tmpb . ';topicseen">' . $tmpa . '</a>';
            $tmpa++;
         }
         // Show links to all the pages?
         if (count($tmppages) <= 5)
            $pages = 'Ã,« ' . implode(' ', $tmppages);
         // Or skip a few?
         else
            $pages = 'Ã,« ' . $tmppages[0] . ' ' . $tmppages[1] . ' ... ' . $tmppages[count($tmppages) - 2] . ' ' . $tmppages[count($tmppages) - 1];

         if (!empty($modSettings['enableAllMessages']) && $topic_length < $modSettings['enableAllMessages'])
            $pages .= '  <a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0;all">' . $txt['all'] . '</a>';
         $pages .= ' Ã,»';
      }
      else
         $pages = '';

      // We need to check the topic icons exist... you can never be too sure!
      if (empty($modSettings['messageIconChecks_disable']))
      {
         // First icon first... as you'd expect.
         if (!isset($icon_sources[$row['firstIcon']]))
            $icon_sources[$row['firstIcon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['firstIcon'] . '.gif') ? 'images_url' : 'default_images_url';
         // Last icon... last... duh.
         if (!isset($icon_sources[$row['lastIcon']]))
            $icon_sources[$row['lastIcon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['lastIcon'] . '.gif') ? 'images_url' : 'default_images_url';
      }

      $color_start = !empty($groupcolors[$row['mems_group']]) ? $groupcolors[$row['mems_group']] : '';
      $color_last = !empty($groupcolors[$row['meml_group']]) ? $groupcolors[$row['meml_group']] : '';

      // And build the array.
      $topics[$row['id_topic']] = array(
         'id' => $row['id_topic'],
         'first_post' => array(
            'id' => $row['id_first_msg'],
            'member' => array(
               'name' => $row['firstPosterName'],
               'id' => $row['ID_FIRST_MEMBER'],
               'href' => $scripturl . '?action=profile;u=' . $row['ID_FIRST_MEMBER'],
               'link' => !empty($row['ID_FIRST_MEMBER']) ? '<a href="' . $scripturl . '?action=profile;u=' . $row['ID_FIRST_MEMBER'] . '" title="' . $txt['profile_of'] . ' ' . $row['firstPosterName'] . '">' . '<font color="' . $color_start . '">' . $row['firstPosterName'] . '</font>' . '</a>' : $row['firstPosterName']
            ),
            'time' => timeformat($row['firstPosterTime']),
            'timestamp' => forum_time(true, $row['firstPosterTime']),
            'subject' => $row['firstSubject'],
            'preview' => $row['firstBody'],
            'icon' => $row['firstIcon'],
            'icon_url' => $settings[$icon_sources[$row['firstIcon']]] . '/post/' . $row['firstIcon'] . '.gif',
            'href' => $scripturl . '?topic=' . $row['id_topic'] . '.0;topicseen',
            'link' => '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0;topicseen">' . $row['firstSubject'] . '</a>'
         ),
         'last_post' => array(
            'id' => $row['id_last_msg'],
            'member' => array(
               'name' => $row['lastPosterName'],
               'id' => $row['ID_LAST_MEMBER'],
               'href' => $scripturl . '?action=profile;u=' . $row['ID_LAST_MEMBER'],
               'link' => !empty($row['ID_LAST_MEMBER']) ? '<a href="' . $scripturl . '?action=profile;u=' . $row['ID_LAST_MEMBER'] . '">' . '<font color="' . $color_last . '">' . $row['lastPosterName'] . '</font>' . '</a>' : $row['lastPosterName']
            ),
            'time' => timeformat($row['lastPosterTime']),
            'timestamp' => forum_time(true, $row['lastPosterTime']),
            'subject' => $row['lastSubject'],
            'preview' => $row['lastBody'],
            'icon' => $row['lastIcon'],
            'icon_url' => $settings[$icon_sources[$row['lastIcon']]] . '/post/' . $row['lastIcon'] . '.gif',
            'href' => $scripturl . '?topic=' . $row['id_topic'] . ($row['num_replies'] == 0 ? '.0' : '.msg' . $row['id_last_msg']) . ';topicseen#msg' . $row['id_last_msg'],
            'link' => '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . ($row['num_replies'] == 0 ? '.0' : '.msg' . $row['id_last_msg']) . ';topicseen#msg' . $row['id_last_msg'] . '">' . $row['lastSubject'] . '</a>'
         ),
         'new' => $row['isRead'],
         'new_from' => $row['new_from'],
         'new_href' => $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['new_from'] . ';topicseen#new',
         'href' => $scripturl . '?topic=' . $row['id_topic'] . ($row['num_replies'] == 0 ? '.0' : '.msg' . $row['new_from']) . ';topicseen' . ($row['num_replies'] == 0 ? '' : 'new'),
         'link' => '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . ($row['num_replies'] == 0 ? '.0' : '.msg' . $row['new_from']) . ';topicseen#msg' . $row['new_from'] . '">' . $row['firstSubject'] . '</a>',
         'is_sticky' => !empty($modSettings['enableStickyTopics']) && !empty($row['isSticky']),
         'is_locked' => !empty($row['locked']),
         'is_poll' => $modSettings['pollMode'] == '1' && $row['id_poll'] > 0,
         'is_hot' => $row['num_replies'] >= $modSettings['hotTopicPosts'],
         'is_very_hot' => $row['num_replies'] >= $modSettings['hotTopicVeryPosts'],
         'is_posted_in' => false,
         'icon' => $row['firstIcon'],
         'icon_url' => $settings[$icon_sources[$row['firstIcon']]] . '/post/' . $row['firstIcon'] . '.gif',
         'subject' => $row['firstSubject'],
         'pages' => $pages,
         'replies' => $row['num_replies'],
         'views' => $row['num_views'],
         '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>'
         )
      );

      determineTopicClass($topics[$row['id_topic']]);
   }
   $smcFunc['db_free_result']($request);

   if (!empty($modSettings['enableParticipation']) && !empty($topic_ids))
   {
      $result = $smcFunc['db_query']("", "
         SELECT id_topic
         FROM ".$db_prefix."messages
         WHERE id_topic IN (" . implode(', ', $topic_ids) . ")
            AND id_member = {int:id_member}",
         array('id_member' => $user_info['id']));
      while ($row = $smcFunc['db_fetch_assoc']($result))
      {
         if (empty($topics[$row['id_topic']]['is_posted_in']))
         {
            $topics[$row['id_topic']]['is_posted_in'] = true;
            $topics[$row['id_topic']]['class'] = 'my_' . $topics[$row['id_topic']]['class'];
         }
      }
      $smcFunc['db_free_result']($result);
   }

   }

if (!empty($topics))
    {
    echo '
        <div class="tborder" ', $context['browser']['needs_size_fix'] && !$context['browser']['is_ie6'] ? 'style="width: 100%;margin:0px;"' : 'style="margin:0px;"', '>
            <table border="0" width="100%" cellspacing="1" cellpadding="1" class="bordercolor">
                <tr>';

    echo '
                    <td class="titlebg" colspan="7">', $heading, '</td>';
    echo '
                </tr>';

    echo '
            <tr class="titlebg">
               <td width="10%" colspan="2"> </td>
               <td>', $txt['subject'], '
               </td><td width="14%">', $txt['posted_by'], '
               </td><td width="4%" align="center">', $txt['replies'], '
               </td><td width="4%" align="center">', $txt['views'], '
               </td><td width="24%">', $txt['last_post'], '
               </td>
            </tr>';

   foreach ($topics as $topic)
   {
      // Do we want to seperate the sticky and lock status out?
      if (!empty($settings['seperate_sticky_lock']) && strpos($topic['class'], 'sticky') !== false)
         $topic['class'] = substr($topic['class'], 0, strrpos($topic['class'], '_sticky'));
      if (!empty($settings['seperate_sticky_lock']) && strpos($topic['class'], 'locked') !== false)
         $topic['class'] = substr($topic['class'], 0, strrpos($topic['class'], '_locked'));

      echo '
            <tr>
               <td class="windowbg2" valign="middle" align="center" width="6%">
                  <img src="' . $settings['images_url'] . '/topic/' . $topic['class'] . '.gif" alt="" />
               </td><td class="windowbg2" valign="middle" align="center" width="4%">
                  <img src="' . $topic['first_post']['icon_url'] . '" alt="" align="middle" />
               </td><td class="windowbg' , $topic['is_sticky'] && !empty($settings['seperate_sticky_lock']) ? '3' : '' , '" width="48%" valign="middle">' , $topic['is_locked'] && !empty($settings['seperate_sticky_lock']) ? '
                  <img src="' . $settings['images_url'] . '/icons/quick_lock.gif" align="right" alt="" style="margin: 0;" />' : '' , $topic['is_sticky'] && !empty($settings['seperate_sticky_lock']) ? '
                  <img src="' . $settings['images_url'] . '/icons/show_sticky.gif" align="right" alt="" style="margin: 0;" />' : '', $topic['first_post']['link'];
               if ($topic['new'] == 0)
                  {
                  echo '<a href="', $topic['new_href'], '"> <img src="', $settings['images_url'], '/', $context['user']['language'], '/new.gif" alt="', $txt['seconds_with'], '" /></a>';
                  }
                echo '
               <span class="smalltext">', $topic['pages'], '<br>', $txt['in'], ' ', $topic['board']['link'], '</span></td>
               <td class="windowbg2" valign="middle" width="14%">
                  ', $topic['first_post']['member']['link'], '</td>
               <td class="windowbg" valign="middle" width="4%" align="center">
                  ', $topic['replies'], '</td>
               <td class="windowbg" valign="middle" width="4%" align="center">
                  ', $topic['views'], '</td>
               <td class="windowbg2" valign="middle" width="22%">
                  <a href="', $topic['last_post']['href'], '"><img src="', $settings['images_url'], '/icons/last_post.gif" alt="', $txt['last_post'], '" title="', $txt['last_post'], '" style="float: right;" /></a>
                  <span class="smalltext">
                     ', $topic['last_post']['time'], '<br />
                     ', $txt['by'], ' ', $topic['last_post']['member']['link'], '
                  </span>
               </td>
            </tr>';
   }

    echo '</table></div>';

    }
   else
       echo '<b><u>'.$heading.'<br><br>No Topics Match Search Criteria</u></b>';
Title: Re: Recent topics for SMF2
Post by: Ken. on February 22, 2010, 09:12:32 PM
Tried it on my test site and live site and on both it gives this error when trying to save the code to the block:
QuoteThe database value you're trying to insert does not exist: user_id
Title: Re: Recent topics for SMF2
Post by: Mick on February 22, 2010, 10:36:10 PM
Oh wow, thanx for trying ;)


As Ken said, there is an error :o
Title: Re: Recent topics for SMF2
Post by: IchBin on February 23, 2010, 04:24:11 PM
Aren't you using another portal bluedevil? Does this happen in that portal too?

I don't know why it's throwing that error when it tries to save the block code. It shouldn't be trying to execute the statement when it saves the code. I'll try to figure it out later today or during a work break.
Title: Re: Recent topics for SMF2
Post by: Mick on February 23, 2010, 04:51:35 PM
Yes i use another portal.

...but also i have tp98 in my old test site and the following shows after saving.

Fatal error: Function name must be a string in /home/********/public_html/devsite/Sources/Load.php(1742) : eval()'d code(209) : eval()'d code on line 243
Title: Re: Recent topics for SMF2
Post by: Mick on February 23, 2010, 04:54:07 PM
Nevermind my previous post.  I just realized is smf 1.1.x


Anywho,  in my other portal with rc2,   it shows "nothing" after saving.   It cuts out the page, meaning it has an error but no indication what kind of error. :o


Unless im doing it wrong...... i added the entire code in a php block and tried in a php page too.
Title: Re: Recent topics for SMF2
Post by: ZarPrime on February 23, 2010, 05:06:36 PM
Ichbin,

Also, $ID_MEMBER in your global declaration is no longer a valid variable but I don't think that has anything to do with the error.  I'm pretty sure that it can just be removed.  I see where the error is coming from but it is confusing me too.

ZarPrime
Title: Re: Recent topics for SMF2
Post by: bloc on February 23, 2010, 09:45:19 PM
$ID_MEMBER is longer filled in SMF2. So you need to set that somewhere, on top maybe?

Like:

$ID_MEMBER = $context['user']['id'];
Title: Re: Recent topics for SMF2
Post by: IchBin on February 24, 2010, 02:56:50 PM
Yeah, I just changed it to user_info['id'] instead. Thanks for the heads up guys. I think this code is working for me now. Updating my first post.

--edit--

oops... It would seem there's quite a few variables that need to be changed for the $txt language strings. I'll have to look at those later.
Title: Re: Recent topics for SMF2
Post by: ZarPrime on February 25, 2010, 03:33:33 PM
Yeah, it's a pretty complicated bit of code.  I'm going to look at it again this weekend if I can find the time but no promises. ;)

ZarPrime
Title: Re: Recent topics for SMF2
Post by: Mick on April 07, 2010, 12:46:04 AM
I just tried this on RC3 and got a parse error.  At least it worked somewhat in RC2.

Not sure what changed tho'
Title: Re: Recent topics for SMF2
Post by: IchBin on April 07, 2010, 05:50:14 PM
Is this with the fixed issues for the alpha? It works for me with the issues that Bloc just fixed.
Title: Re: Recent topics for SMF2
Post by: stormlrd on April 07, 2010, 05:54:31 PM
That code worked perfect in php block in the revision just released Brad just tried it
Title: Re: Recent topics for SMF2
Post by: Mick on April 07, 2010, 06:34:51 PM
Ah ok,.... i should try the new files then. ;)
Title: Re: Recent topics for SMF2
Post by: shane is my name on April 12, 2010, 08:48:24 AM
Works on mine. I Really like this.
Missing category topics on mine though (Views, posts, subject, etc).

2.0RC3
TP 1 beta 5.1
Title: Re: Recent topics for SMF2
Post by: Mick on April 12, 2010, 01:48:27 PM
Yes it does...

Yep it works.  I use it just for last 24 hour posts ;)

Thanx for updating this :smitten:
Title: Re: Recent topics for SMF2
Post by: Mick on April 12, 2010, 02:16:52 PM
To add views, posted by, subject, etc....

In the code,...... find near the bottom:

    echo '
            <tr class="titlebg">
               <td width="10%" colspan="2"> </td>
               <td>', $txt[70], '
               </td><td width="14%">', $txt[109], '
               </td><td width="4%" align="center">', $txt['110'], '
               </td><td width="4%" align="center">', $txt[301], '
               </td><td width="24%">', $txt[111], '
               </td>
            </tr>';


Replace with:
    echo '
            <tr class="titlebg">
               <td width="10%" colspan="2"> </td>
               <td>', $txt[subject], '
               </td><td width="14%">', $txt[posted_by], '
               </td><td width="4%" align="center">', $txt['replies'], '
               </td><td width="4%" align="center">', $txt[views], '
               </td><td width="24%">', $txt[last_post], '
               </td>
            </tr>';
Title: Re: Recent topics for SMF2
Post by: shane is my name on April 13, 2010, 07:19:55 AM
hey Thanks, it looks much better with the column headers!    :up:

By the way, how did you get it to display last 24 hours posts? I was using it just for recent posts so I could put it on front page, but I tried experimenting with the other features just now and maybe Im not understanding what exactly to uncomment, because I uncomment the part I want... for example, for the "last 5 topics started by user", I uncomment the following:
$heading = 'Most Recent Topics You Started';
$where_clause = 'ms.ID_MEMBER = '.$ID_MEMBER;
$limit_clause = 'LIMIT 5';
$order_clause = 't.ID_FIRST_MSG DESC';


I really only want it for recent posts, but since you did last 24 hours, i was curious to see the other features.  :)
Title: Re: Recent topics for SMF2
Post by: RoarinRow on April 13, 2010, 06:15:28 PM
Quote from: bluedevil on April 12, 2010, 02:16:52 PM
To add views, posted by, subject, etc....

In the code,...... find near the bottom:

    echo '
            <tr class="titlebg">
               <td width="10%" colspan="2"> </td>
               <td>', $txt[70], '
               </td><td width="14%">', $txt[109], '
               </td><td width="4%" align="center">', $txt['110'], '
               </td><td width="4%" align="center">', $txt[301], '
               </td><td width="24%">', $txt[111], '
               </td>
            </tr>';


Replace with:
    echo '
            <tr class="titlebg">
               <td width="10%" colspan="2"> </td>
               <td>', $txt[subject], '
               </td><td width="14%">', $txt[posted_by], '
               </td><td width="4%" align="center">', $txt['replies'], '
               </td><td width="4%" align="center">', $txt[views], '
               </td><td width="24%">', $txt[last_post], '
               </td>
            </tr>';


Excellent, thanks Ich and BD!   O0
Title: Re: Recent topics for SMF2
Post by: Mick on April 13, 2010, 06:41:09 PM
Hey Ro!  long time no see bud...

I updated the language texts...

global $context, $settings, $scripturl, $txt, $db_prefix, $user_info, $modSettings, $user_profile, $smcFunc;

//////////////////////////////////////////// ---------- Unconditional Exclude
//   
   $exclude_boards = array();   // KEEP (to preserve variable declaration)
//   $exclude_boards = array(5);   //  Exclude single board
//     $exclude_boards = array(55,69);   //  Exclude multiple boards
   $ex_board_clause = !empty($exclude_boards) ? ' AND b.id_board NOT IN (' . implode(', ', $exclude_boards) . ')' : '';
//   
//   

//////////////////////////////////////////// ---------- Use in TP PHP Article (no title or frame from theme)
//   This will give most recent XX posted to topics -OR-
//   most recent XX unreplied to topics -OR-
//   topics posted to in last XX hours -OR-
//   most recent XX topics on topic notify list
//   
//   Sorts by most recent reply (descending; most recent first) -OR-
//            creation order (descending; most recent first)
//   
//   All in the detailed topic format
//   
//   
//   Default
//   index.php?page=##
//   most recent posted to topics - will list
//   number equal to  $settings['number_recent_posts']
//   
//   index.php?page=##;count=50 or index.php?page=##;type=last;count=50
//   50 most recently posted to topics
//   
//   index.php?page=##;type=unreplied or index.php?page=##;type=unreplied;count=50
//   Most recent unreplied to topics - will
//   list number specified in 'count' or default to
//   number equal to  $settings['number_recent_posts']
//   
//   index.php?page=##;type=hours or index.php?page=##;type=hours;count=12
//   Topics posted to in last number of hours
//   specified in 'count' or default to 24.
//   
//   index.php?page=##;type=notify or index.php?page=##;type=notify;count=50
//   Topics in topic notifcation list up to number
//   specified in 'count' or a maximum of 100 topics.
//   
//   *** Admins Only ***
//   index.php?page=##;type=notify;user=XXX or index.php?page=##;type=notify;user=XXX;count=50
//   Topics in topic notifcation list of specified user up to number
//   specified in 'count' or a maximum of 100 topics.
//   
//   index.php?page=##;type=started or index.php?page=##;type=started;count=50
//   Topics started by current user list up to number
//   specified in 'count' or a maximum of 100 topics.
//   
//   *** Admins Only ***
//   index.php?page=##;type=notify;user=XXX or index.php?page=##;type=started;user=XXX;count=50
//   Topics started by specified user up to number
//   specified in 'count' or a maximum of 100 topics.
//   
//   Add argument order=create to sort by topic creation sequence (most recent first)
//   rather than by last reply sequence

   $do_query = 1;

//////////////////////////////////////////// ---------- Poor Man's Global Announcements Block (center block - no Title/Frame)
//   Delete documentation comments above and marked section below
//
//   $announce_topics = array(254, 568, 675, 678); // Topic ID's to be 'Announced'
//
//   $heading = '<center>Announcements<center>';
//   $where_clause = 't.ID_TOPIC IN (' . implode(', ', $announce_topics) . ')';
//   $limit_clause = '';
//   $order_clause = 't.ID_LAST_MSG DESC';
////////////////////////////////////////////   

//////////////////////////////////////////// ---------- Last 5 Topics Started by User Block (center block - no Title/Frame)
//   Delete documentation comments above and marked section below
//
//   $heading = 'Most Recent Topics You Started';
//   $where_clause = 'ms.ID_MEMBER = '.$ID_MEMBER;
//   $limit_clause = 'LIMIT 5';
//   $order_clause = 't.ID_FIRST_MSG DESC';
////////////////////////////////////////////   

//////////////////////////////////////////// ---------- Boardindex Most Recent Topics Arguments
//
//   Comment out the Info Center's Most Recent Posts Code and Insert this
//   to show Most Recent Topics in full detail style instead
//
//   $list_count = $settings['number_recent_posts'];
//   $heading = 'Most Recently Posted To Topics';
//   $where_clause = 't.ID_LAST_MSG >= ' . ($modSettings['maxMsgID'] - 50 * min($list_count, 5));
//   $limit_clause = 'LIMIT ' . $list_count;
//   $order_clause = 't.ID_LAST_MSG DESC';
////////////////////////////////////////////   

////////////////////////////////////////////  ------ Remove down to next mark to use in block/boardindex ------
//
   if (empty($settings['number_recent_posts']))
      $number_recent_posts = 20;
   else
      $number_recent_posts = $settings['number_recent_posts'];

        if( isset($_GET['type']) )
      $list_type = $_GET['type'];
   else
      $list_type = 'last';

        if( isset($_GET['count']) )
      $list_count = $_GET['count'];
   else
   {
      $list_count = $number_recent_posts;
      if ($list_type == 'notify')
         $list_count = 100;
      elseif ($list_type == 'hours')
         $list_count = 24;
   }

   if ($list_count <= 0)
   {
      $list_count = $number_recent_posts;
      if ($list_type == 'hours')
         $list_count = 24;
   }

   if ($list_count > 100)
      $list_count = 100;

        if( isset($_GET['order']) )
      $list_order = $_GET['order'];
   else
      $list_order = 'lastpost';

        if( $list_order == 'create' )
      $order_clause = 't.id_first_msg DESC';
   else
      $order_clause = 't.id_last_msg DESC';

   if ($list_type == 'hours')
   {
      $list_from = strtotime($list_count.' hours ago');
      $where_clause = 'ml.poster_time >= ' . $list_from;
      $limit_clause = ' ';
      $heading = 'Topics Posted To In Last '. $list_count . ' Hours';
   }
   elseif ($list_type == 'unreplied')
   {
      $where_clause = 't.num_replies = 0';
      if ($list_count == 0)
      {
         $limit_clause = ' ';
         $heading = 'Unreplied To Topics';
      }
      else
      {
      $limit_clause = 'LIMIT ' . $list_count;
      $heading = $list_count . ' Most Recent Unreplied To Topics';
      }
   }
   elseif ($list_type == 'notify')
   {
      if (isset($_GET['user']) && $user_info['is_admin'])
      {
         $watched_topics = array();
         $request = $smcFunc['db_query']("", "SELECT id_topic FROM ".$db_prefix."log_notify
                                 WHERE id_member = {int:user_id}
                                 AND id_board = 0",
                                 array('user_id' => $_GET['user']));
         while ($row = $smcFunc['db_fetch_assoc']($request))
            $watched_topics[] = $row['id_topic'];
         $smcFunc['db_free_result']($request);
         $heading = $list_count . ' Most Recent Topics Being Watched by User # '.$_GET['user'];
         $where_clause = 't.id_topic IN (' . implode(', ', $watched_topics) . ')';
         $limit_clause = 'LIMIT ' . $list_count;
         if (empty($watched_topics))
            $do_query = 0;
      }
      else
      {
         $watched_topics = array();
         $request = $smcFunc['db_query']("", "SELECT id_topic FROM ".$db_prefix."log_notify
                                 WHERE id_member = {int:id_member}
                                 AND id_board = 0",
                                 array('id_member' => $user_info['id']));
         while ($row = $smcFunc['db_fetch_assoc']($request))
            $watched_topics[] = $row['id_topic'];
         $smcFunc['db_free_result']($request);
         $heading = $list_count . ' Most Recent Topics Being Watched';
         $where_clause = 't.id_topic IN (' . implode(', ', $watched_topics) . ')';
         $limit_clause = 'LIMIT ' . $list_count;
         if (empty($watched_topics))
            $do_query = 0;
      }
   }
   elseif ($list_type == 'started')
   {
      if (isset($_GET['user']) && $user_info['is_admin'])
      {
         $where_clause = 'ms.id_member = '.$_GET['user'];
         $limit_clause = 'LIMIT ' . $list_count;
              if( $list_order == 'create' )
         {
            $order_clause = 't.id_first_msg DESC';
            $heading = 'Most Recent Topics Started by User '.$_GET['user'];
         }
         else
         {
            $order_clause = 't.id_last_msg DESC';
            $heading = 'Most Recently Posted To Topics Started by User '.$_GET['user'];
         }
      }
      else
      {
         $where_clause = 'ms.id_member = '.$user_info['id'];
         $limit_clause = 'LIMIT ' . $list_count;
              if( $list_order == 'create' )
         {
            $order_clause = 't.id_first_msg DESC';
            $heading = 'Most Recent Topics You Started';
         }
         else
         {
            $order_clause = 't.id_last_msg DESC';
            $heading = 'Most Recently Posted To Topics You Started';
         }
      }
   }
   else
   {
      $where_clause = 't.id_last_msg >= ' . ($modSettings['maxMsgID'] - 90 * min($list_count, 5));
      $limit_clause = 'LIMIT ' . $list_count;
      $heading = $list_count . ' Most Recently Posted To Topics';
   }
//
////////////////////////////////////////////  ------ Remove up to first mark to use in block/boardindex ------

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

   $groupcolors = array();
   $request = $smcFunc['db_query']("", "SELECT id_group, online_color FROM ".$db_prefix."membergroups",array());
   while ($row = $smcFunc['db_fetch_assoc']($request))
      $groupcolors[$row['id_group']] = $row['online_color'];
   $smcFunc['db_free_result']($request);

   $topics = array();

   if ($do_query == 1)
   {
      $request = $smcFunc['db_query']("", "
      SELECT
            ms.subject AS firstSubject, ms.poster_time AS firstPosterTime, ms.id_topic, t.id_board, b.name AS bname,
            t.num_replies, t.num_views, ms.id_member AS ID_FIRST_MEMBER, ml.id_member AS ID_LAST_MEMBER,
            ml.poster_time AS lastPosterTime, IFNULL(mems.real_name, ms.poster_name) AS firstPosterName,
            IFNULL(meml.real_name, ml.poster_name) AS lastPosterName,
            mems.id_group as mems_group, meml.id_group as meml_group,
            ml.subject AS lastSubject, b.member_groups,
            ml.icon AS lastIcon, ms.icon AS firstIcon, t.id_poll, t.is_sticky, t.locked, ml.modified_time AS lastModifiedTime,
            LEFT(ml.body, 384) AS lastBody, LEFT(ms.body, 384) AS firstBody,
            ml.smileys_enabled AS lastSmileys, ms.smileys_enabled AS firstSmileys, t.id_first_msg, t.id_first_msg,"
            . ($user_info['is_guest'] ? '1 AS isRead, 0 AS new_from' : '
            IFNULL(lt.id_msg, IFNULL(lmr.id_msg, 0)) >= ml.id_msg_modified AS isRead,
            IFNULL(lt.id_msg, IFNULL(lmr.id_msg, -1)) + 1 AS new_from') . "
         FROM (".$db_prefix."messages AS ms, ".$db_prefix."messages AS ml, ".$db_prefix."topics AS t, ".$db_prefix."boards AS b)
            LEFT JOIN ".$db_prefix."members AS mems ON (mems.id_member = ms.id_member)
            LEFT JOIN ".$db_prefix."members AS meml ON (meml.id_member = ml.id_member)
            LEFT JOIN ".$db_prefix."log_topics AS lt ON (lt.id_topic = t.id_topic AND lt.id_member = ".$user_info['id'].")
            LEFT JOIN ".$db_prefix."log_mark_read AS lmr ON (lmr.id_board = t.id_board AND lmr.id_member = ".$user_info['id'].")
         WHERE " . $where_clause . $ex_board_clause . "
            AND t.id_topic = ms.id_topic
            AND b.id_board = t.id_board" . (!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0 ? " AND b.id_board != ".$modSettings['recycle_board'] : "") . "
            AND ms.id_msg = t.id_first_msg
            AND ml.id_msg = t.id_last_msg
            AND " . $user_info['query_see_board'] . "
         ORDER BY " . $order_clause . " " . $limit_clause,
       array());


   $topic_ids = array();
   while ($row = $smcFunc['db_fetch_assoc']($request))
   {
      if ($row['id_poll'] > 0 && $modSettings['pollMode'] == '0')
         continue;

      $topic_ids[] = $row['id_topic'];

      // Clip the strings first because censoring is slow :/. (for some reason?)
      $row['firstBody'] = strip_tags(strtr(parse_bbc($row['firstBody'], $row['firstSmileys'], $row['id_first_msg']), array('<br />' => '
')));
      if (strlen($row['firstBody']) > 128)
         $row['firstBody'] = substr($row['firstBody'], 0, 128) . '...';
      $row['lastBody'] = strip_tags(strtr(parse_bbc($row['lastBody'], $row['lastSmileys'], $row['id_last_msg']), array('<br />' => '
')));
      if (strlen($row['lastBody']) > 128)
         $row['lastBody'] = substr($row['lastBody'], 0, 128) . '...';

         $row['lastSubject'] = $row['firstSubject'];
         $row['lastBody'] = $row['firstBody'];

      // Decide how many pages the topic should have.
      $topic_length = $row['num_replies'] + 1;
      if ($topic_length > $modSettings['defaultMaxMessages'])
      {
         $tmppages = array();
         $tmpa = 1;
         for ($tmpb = 0; $tmpb < $topic_length; $tmpb += $modSettings['defaultMaxMessages'])
         {
            $tmppages[] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.' . $tmpb . ';topicseen">' . $tmpa . '</a>';
            $tmpa++;
         }
         // Show links to all the pages?
         if (count($tmppages) <= 5)
            $pages = 'Ã,« ' . implode(' ', $tmppages);
         // Or skip a few?
         else
            $pages = 'Ã,« ' . $tmppages[0] . ' ' . $tmppages[1] . ' ... ' . $tmppages[count($tmppages) - 2] . ' ' . $tmppages[count($tmppages) - 1];

         if (!empty($modSettings['enableAllMessages']) && $topic_length < $modSettings['enableAllMessages'])
            $pages .= '  <a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0;all">' . $txt['all'] . '</a>';
         $pages .= ' Ã,»';
      }
      else
         $pages = '';

      // We need to check the topic icons exist... you can never be too sure!
      if (empty($modSettings['messageIconChecks_disable']))
      {
         // First icon first... as you'd expect.
         if (!isset($icon_sources[$row['firstIcon']]))
            $icon_sources[$row['firstIcon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['firstIcon'] . '.gif') ? 'images_url' : 'default_images_url';
         // Last icon... last... duh.
         if (!isset($icon_sources[$row['lastIcon']]))
            $icon_sources[$row['lastIcon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['lastIcon'] . '.gif') ? 'images_url' : 'default_images_url';
      }

      $color_start = !empty($groupcolors[$row['mems_group']]) ? $groupcolors[$row['mems_group']] : '';
      $color_last = !empty($groupcolors[$row['meml_group']]) ? $groupcolors[$row['meml_group']] : '';

      // And build the array.
      $topics[$row['id_topic']] = array(
         'id' => $row['id_topic'],
         'first_post' => array(
            'id' => $row['ID_FIRST_MSG'],
            'member' => array(
               'name' => $row['firstPosterName'],
               'id' => $row['ID_FIRST_MEMBER'],
               'href' => $scripturl . '?action=profile;u=' . $row['ID_FIRST_MEMBER'],
               'link' => !empty($row['ID_FIRST_MEMBER']) ? '<a href="' . $scripturl . '?action=profile;u=' . $row['ID_FIRST_MEMBER'] . '" title="' . $txt[92] . ' ' . $row['firstPosterName'] . '">' . '<font color="' . $color_start . '">' . $row['firstPosterName'] . '</font>' . '</a>' : $row['firstPosterName']
            ),
            'time' => timeformat($row['firstPosterTime']),
            'timestamp' => forum_time(true, $row['firstPosterTime']),
            'subject' => $row['firstSubject'],
            'preview' => $row['firstBody'],
            'icon' => $row['firstIcon'],
            'icon_url' => $settings[$icon_sources[$row['firstIcon']]] . '/post/' . $row['firstIcon'] . '.gif',
            'href' => $scripturl . '?topic=' . $row['id_topic'] . '.0;topicseen',
            'link' => '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0;topicseen">' . $row['firstSubject'] . '</a>'
         ),
         'last_post' => array(
            'id' => $row['id_last_msg'],
            'member' => array(
               'name' => $row['lastPosterName'],
               'id' => $row['ID_LAST_MEMBER'],
               'href' => $scripturl . '?action=profile;u=' . $row['ID_LAST_MEMBER'],
               'link' => !empty($row['ID_LAST_MEMBER']) ? '<a href="' . $scripturl . '?action=profile;u=' . $row['ID_LAST_MEMBER'] . '">' . '<font color="' . $color_last . '">' . $row['lastPosterName'] . '</font>' . '</a>' : $row['lastPosterName']
            ),
            'time' => timeformat($row['lastPosterTime']),
            'timestamp' => forum_time(true, $row['lastPosterTime']),
            'subject' => $row['lastSubject'],
            'preview' => $row['lastBody'],
            'icon' => $row['lastIcon'],
            'icon_url' => $settings[$icon_sources[$row['lastIcon']]] . '/post/' . $row['lastIcon'] . '.gif',
            'href' => $scripturl . '?topic=' . $row['id_topic'] . ($row['num_replies'] == 0 ? '.0' : '.msg' . $row['ID_LAST_MSG']) . ';topicseen#msg' . $row['id_last_msg'],
            'link' => '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . ($row['num_replies'] == 0 ? '.0' : '.msg' . $row['id_last_msg']) . ';topicseen#msg' . $row['id_last_msg'] . '">' . $row['lastSubject'] . '</a>'
         ),
         'new' => $row['isRead'],
         'new_from' => $row['new_from'],
         'new_href' => $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['new_from'] . ';topicseen#new',
         'href' => $scripturl . '?topic=' . $row['id_topic'] . ($row['num_replies'] == 0 ? '.0' : '.msg' . $row['new_from']) . ';topicseen' . ($row['num_replies'] == 0 ? '' : 'new'),
         'link' => '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . ($row['num_replies'] == 0 ? '.0' : '.msg' . $row['new_from']) . ';topicseen#msg' . $row['new_from'] . '">' . $row['firstSubject'] . '</a>',
         'is_sticky' => !empty($modSettings['enableStickyTopics']) && !empty($row['isSticky']),
         'is_locked' => !empty($row['locked']),
         'is_poll' => $modSettings['pollMode'] == '1' && $row['id_poll'] > 0,
         'is_hot' => $row['num_replies'] >= $modSettings['hotTopicPosts'],
         'is_very_hot' => $row['num_replies'] >= $modSettings['hotTopicVeryPosts'],
         'is_posted_in' => false,
         'icon' => $row['firstIcon'],
         'icon_url' => $settings[$icon_sources[$row['firstIcon']]] . '/post/' . $row['firstIcon'] . '.gif',
         'subject' => $row['firstSubject'],
         'pages' => $pages,
         'replies' => $row['num_replies'],
         'views' => $row['num_views'],
         '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>'
         )
      );

      determineTopicClass($topics[$row['id_topic']]);
   }
   $smcFunc['db_free_result']($request);

   if (!empty($modSettings['enableParticipation']) && !empty($topic_ids))
   {
      $result = $smcFunc['db_query']("", "
         SELECT id_topic
         FROM ".$db_prefix."messages
         WHERE id_topic IN (" . implode(', ', $topic_ids) . ")
            AND id_member = {int:id_member}",
         array('id_member' => $user_info['id']));
      while ($row = $smcFunc['db_fetch_assoc']($result))
      {
         if (empty($topics[$row['id_topic']]['is_posted_in']))
         {
            $topics[$row['id_topic']]['is_posted_in'] = true;
            $topics[$row['id_topic']]['class'] = 'my_' . $topics[$row['id_topic']]['class'];
         }
      }
      $smcFunc['db_free_result']($result);
   }

   }

if (!empty($topics))
    {
    echo '
        <div class="tborder" ', $context['browser']['needs_size_fix'] && !$context['browser']['is_ie6'] ? 'style="width: 100%;margin:0px;"' : 'style="margin:0px;"', '>
            <table border="0" width="100%" cellspacing="1" cellpadding="1" class="bordercolor">
                <tr>';

    echo '
                    <td class="titlebg" colspan="7">', $heading, '</td>';
    echo '
                </tr>';

    echo '
            <tr class="titlebg">
               <td width="10%" colspan="2"> </td>
               <td>', $txt[subject], '
               </td><td width="14%">', $txt[posted_by], '
               </td><td width="4%" align="center">', $txt['replies'], '
               </td><td width="4%" align="center">', $txt[views], '
               </td><td width="24%">', $txt[last_post], '
               </td>
            </tr>';

   foreach ($topics as $topic)
   {
      // Do we want to seperate the sticky and lock status out?
      if (!empty($settings['seperate_sticky_lock']) && strpos($topic['class'], 'sticky') !== false)
         $topic['class'] = substr($topic['class'], 0, strrpos($topic['class'], '_sticky'));
      if (!empty($settings['seperate_sticky_lock']) && strpos($topic['class'], 'locked') !== false)
         $topic['class'] = substr($topic['class'], 0, strrpos($topic['class'], '_locked'));

      echo '
            <tr>
               <td class="windowbg2" valign="middle" align="center" width="6%">
                  <img src="' . $settings['images_url'] . '/topic/' . $topic['class'] . '.gif" alt="" />
               </td><td class="windowbg2" valign="middle" align="center" width="4%">
                  <img src="' . $topic['first_post']['icon_url'] . '" alt="" align="middle" />
               </td><td class="windowbg' , $topic['is_sticky'] && !empty($settings['seperate_sticky_lock']) ? '3' : '' , '" width="48%" valign="middle">' , $topic['is_locked'] && !empty($settings['seperate_sticky_lock']) ? '
                  <img src="' . $settings['images_url'] . '/icons/quick_lock.gif" align="right" alt="" style="margin: 0;" />' : '' , $topic['is_sticky'] && !empty($settings['seperate_sticky_lock']) ? '
                  <img src="' . $settings['images_url'] . '/icons/show_sticky.gif" align="right" alt="" style="margin: 0;" />' : '', $topic['first_post']['link'];
               if ($topic['new'] == 0)
                  {
                  echo '<a href="', $topic['new_href'], '"> <img src="', $settings['images_url'], '/', $context['user']['language'], '/new.gif" alt="', $txt['seconds_with'], '" /></a>';
                  }
                echo '
               <span class="smalltext">', $topic['pages'], '<br>', $txt['in'], ' ', $topic['board']['link'], '</span></td>
               <td class="windowbg2" valign="middle" width="14%">
                  ', $topic['first_post']['member']['link'], '</td>
               <td class="windowbg" valign="middle" width="4%" align="center">
                  ', $topic['replies'], '</td>
               <td class="windowbg" valign="middle" width="4%" align="center">
                  ', $topic['views'], '</td>
               <td class="windowbg2" valign="middle" width="22%">
                  <a href="', $topic['last_post']['href'], '"><img src="', $settings['images_url'], '/icons/last_post.gif" alt="', $txt['last_post'], '" title="', $txt[last_post], '" style="float: right;" /></a>
                  <span class="smalltext">
                     ', $topic['last_post']['time'], '<br />
                     ', $txt['by'], ' ', $topic['last_post']['member']['link'], '
                  </span>
               </td>
            </tr>';
   }

    echo '</table></div>';

    }
   else
       echo '<b><u>'.$heading.'<br><br>No Topics Match Search Criteria</u></b>';
Title: Re: Recent topics for SMF2
Post by: RoarinRow on April 13, 2010, 07:51:59 PM
Cool, thanks Mick!  I updated my code.   :up:
Title: Re: Recent topics for SMF2
Post by: shane is my name on April 13, 2010, 08:09:16 PM
I am seriosuly stumped. lets say you wanted to use the feature written in this code that would show "last 5 topics started by user"... What would the code look like now?  I have uncommented, and deleted things, but can not get it to do anything but last 20 posts...

Im just trying to learn, so thats why im asking...
:)
Title: Re: Recent topics for SMF2
Post by: shane is my name on April 13, 2010, 11:32:15 PM
There may be something wrong with the code...
I love the RECENT TOPICS part of this code,
So I'm only posting as an FYI...  Every since I used this in a block on my front page, I would randomly get an Internal Server Error page show up when i try to go to front page. I didn't think it had anything to do with this code at first.. until just now when i decided i wanted to show 10 recent and not 20 recent... So I changed the 20 to 10 like below... 
if (empty($settings['number_recent_posts']))
      $number_recent_posts = 10;


But once i did that, then I got the Internal Server Error page 100% of the time instead of randomly...  that doesnt seem logical to me, that just a number change would cause such an error, and maybe Im wrong... but I turned the block on and off, testing , and each time it was on, i got the error code... and when its off, evreything is normal again.

Just an FYI..

Title: Re: Recent topics for SMF2
Post by: IchBin on April 14, 2010, 01:22:45 AM
I don't have any problem like that when running it on my site. Have you checked your server log to see what the error was when you get this?
Title: Re: Recent topics for SMF2
Post by: shane is my name on April 14, 2010, 04:05:02 AM
Im learning more and more everyday.  :)
Ok so I never knew about a server log, but I just logged onto CPanel and found it... and I found this error:

Quote[Tue Apr 13 19:56:38 2010] [error] [client 74.101.59.3] File does not exist: /public_html/hiphopforums/500.shtml
[Tue Apr 13 19:56:38 2010] [error] [client 74.101.59.3] Premature end of script headers: /public_html/hiphopforums/index.php

Any clue on what that means? I guess the first one means that i need a 500.shtml error file, right? Im guessing.. im not that good at this,,.  lol.
but what about premature end of script headers? that sounds more complicated. lol
Title: Re: Recent topics for SMF2
Post by: IchBin on April 14, 2010, 04:38:15 PM
You must have something else going on. Premature end of script headers means that SMF is sending it's output to the browser before it sends the content-type. I'm not sure what to tell you at this point.
Title: Re: Recent topics for SMF2
Post by: shane is my name on April 14, 2010, 04:45:43 PM
OK thanks, I'll try and ask this over at SMF forum, since it seems nothing to do with tinyportal. 
Title: Re: Recent topics for SMF2
Post by: IchBin on April 14, 2010, 04:50:21 PM
Well I suppose it could be something that was done with TP when it installed or something, but I wouldn't know without looking myself. Even then, I've never really dealt with this problem much.
Title: Re: Recent topics for SMF2
Post by: shane is my name on April 14, 2010, 04:54:32 PM
thats true it might be TP,...  Ive already posted in SMF.. shoudl I just wait and see if they can help, or should i post a topic here too?  I just dont know if people will think im double posting...
Title: Re: Recent topics for SMF2
Post by: IchBin on April 14, 2010, 04:57:33 PM
I don't see a problem with posting here to start a different topic here for your issue. Don't think too many people here know much about your problem though. :)
Title: Re: Recent topics for SMF2
Post by: shane is my name on April 14, 2010, 05:03:57 PM
let me ask you one quick question before i post a new topic...

do you get alot of errors in your error log in admin section?
just curious, because even when i was using 1.1.10, I looked in the error log and saw alot of errors,  but it never caused no issues.  Im just wondering are some errors just normal to get due to complexity of smf / tp?  and they are accepted, but just ahv eto work on critical errors?

Title: Re: Recent topics for SMF2
Post by: IchBin on April 14, 2010, 05:15:45 PM
Sure. I get a ton of errors just from bots trying to hack the site. Not to mention other errors that happen. Just don't let the error log get to big as that can cause some slowness to my recollection.

One thing you should test before posting, is to remove the block that you using for this to see if you still get the premature script end error.
Title: Re: Recent topics for SMF2
Post by: shane is my name on April 14, 2010, 09:41:02 PM
Oh ok, just wanted to make sure it wasnt just me getting so many errors. lol.
Yeah i removed the block and i dont get the error no more. i put it back, and i get it. I repeated it a bunch of times and it same results, but it must be something in combination with it cause i just used same block on another test forum, and it never hgave me that error... so Its my forum.  :( sobb sobb. lol. 

Im sorry for taking this 'Recent Topics' thread so far in another direction. 
sincerely.  And I appreciate your help you gave.
Title: Re: Recent topics for SMF2
Post by: Svaha on May 14, 2010, 02:36:32 PM
Thanks for the revival of the recent topics script  :up:

I've a little problem with this (don't know if it's a script error or has something to do with utf-8)

I'm using SMF 2.0-rc3 and Tiny Portal 1.0 beta 5-1.

When I click on the link (on the right) it leads me to the beginning of a topic, not to the end.

This is the error message I receive :


http://www.mysite/index.php?page=02;type=hours

8: Use of undefined constant last_post - assumed 'last_post'

Bestand: /home/domains/mysite/cache/lang_Aeva_dutch-utf8_default.php (main sub template - eval?)
Regel: 481
Title: Re: Recent topics for SMF2
Post by: IchBin on May 14, 2010, 03:26:10 PM
The code in the first post has been updated. The "last_post" error should be gone.
Title: Re: Recent topics for SMF2
Post by: Svaha on May 14, 2010, 03:48:59 PM
I'm sorry, to be absolutely sure I copied the php script of the first post into the article once again, but the error remains.
Could it be that this is cached?
Title: Re: Recent topics for SMF2
Post by: IchBin on May 17, 2010, 02:51:34 PM
Sorry, I missed one other spot. Code in first post updated again. :)
Title: Re: Recent topics for SMF2
Post by: Svaha on May 21, 2010, 10:25:18 AM
Thanks for your efforts.
I tried the new code but still get errors and no link to the last message.


Undefined index: id_last_msg
Undefined index: ID_LAST_MSG
Undefined offset: 92
Undefined index: ID_FIRST_MSG
Title: Re: Recent topics for SMF2
Post by: IchBin on May 21, 2010, 03:02:55 PM
Ok, there's no errors on my side now. Let me know if there are for you.
Title: Re: Recent topics for SMF2
Post by: Svaha on May 21, 2010, 03:18:27 PM
YES, YES you did it !!!
No errors, thanks very much  :up:
Title: Re: Recent topics for SMF2
Post by: BaghdadGhost on January 28, 2012, 06:58:32 PM
Hi all,

this is a great code. thanks for sharing it.

I need a little changes in the style of it.

how to remover "20 Most Recently Posted To Topics" field? nm I got that

how to combine the views/replies together?

and last when a topic has more than one page, I see "?" characters near the pages number?

btw, I use simple portal. does this have to do with the last question.

the reason why I want to make these changes because I want to make it identical with the regular message index and also to save some space as I am going to use it in a top block between left and right sides.

please see these images for better understanding.

(https://www.tinyportal.net/proxy.php?request=http%3A%2F%2Fi40.tinypic.com%2F35n2er8.jpg&hash=a3130bf37430104e3cc7acbbf02a3cda0a18aa54)


(https://www.tinyportal.net/proxy.php?request=http%3A%2F%2Fi44.tinypic.com%2F11uvips.jpg&hash=33baf29031eaaedcc40632556c499195d1abe82f)

thanks
Title: Re: Recent topics for SMF2
Post by: Lesmond on January 29, 2012, 03:20:56 PM
Quote from: BaghdadGhost on January 28, 2012, 06:58:32 PMI use simple portal. does this have to do with the last question.

Sorry but we only support TinyPortal here, you would be best to ask over at simple portal ::)


Title: Re: Recent topics for SMF2
Post by: BaghdadGhost on January 29, 2012, 04:15:02 PM
I just wanted to be honest and not lie.

well thanks anyways for helping others
Title: Re: Recent topics for SMF2
Post by: thechamp on January 30, 2012, 05:58:10 PM
Hi,

Thanks for this, is there a way I can get rid of Most Recently Posted To Topics at the top? I want to use the frame title instead which just says Recent Topics.

Thanks
Title: Re: Recent topics for SMF2
Post by: daveb47 on February 29, 2012, 04:05:31 PM


QuoteThanks for this, is there a way I can get rid of Most Recently Posted To Topics at the top? I want to use the frame title instead which just says Recent Topics.

Would like to know this as well please
Title: Re: Recent topics for SMF2
Post by: IchBin on February 29, 2012, 04:43:40 PM
Remove this section.
    echo '
                    <td class="titlebg" colspan="7">', $heading, '</td>';
Title: Re: Recent topics for SMF2
Post by: lparker on May 24, 2012, 06:28:18 PM
installed this with NO errors, after trying many different ones with all kinds of issues, this one worked like a charm, THANK YOU VERY MUCH was so hating the default one haha
Title: Re: Recent topics for SMF2
Post by: leftezi on July 28, 2012, 12:12:24 AM
SMF 2.0.2
TP 1.107

I just tried in a Greek utf-8 forum (default language).
When a topic has more than one page, I see " Ã,« " for "Prev" and " Ã,» " for "Next". This characters are just plain text (not clickable as link).

If this is not easy to fix, it does not bother me if this will be only in English, as "Prev" and "Next", or if this will be not there at all.
Title: Re: Recent topics for SMF2
Post by: IchBin on July 28, 2012, 12:27:33 AM
If you look at the code you can see that those characters have been messed up in this section.
         // Show links to all the pages?
         if (count($tmppages) <= 5)
            $pages = 'Ã,« ' . implode(' ', $tmppages);
         // Or skip a few?
         else
            $pages = 'Ã,« ' . $tmppages[0] . ' ' . $tmppages[1] . ' ... ' . $tmppages[count($tmppages) - 2] . ' ' . $tmppages[count($tmppages) - 1];

         if (!empty($modSettings['enableAllMessages']) && $topic_length < $modSettings['enableAllMessages'])
            $pages .= '  <a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0;all">' . $txt['all'] . '</a>';
         $pages .= ' Ã,»';


You can change them to be whatever you'd like.
Title: Re: Recent topics for SMF2
Post by: leftezi on July 28, 2012, 01:00:11 AM
I changed this way but they still plain text (not link)

// Show links to all the pages?
         if (count($tmppages) <= 5)
            $pages = 'Prev« ' . implode(' ', $tmppages);
         // Or skip a few?
         else
            $pages = 'Prev« ' . $tmppages[0] . ' ' . $tmppages[1] . ' ... ' . $tmppages[count($tmppages) - 2] . ' ' . $tmppages[count($tmppages) - 1];

         if (!empty($modSettings['enableAllMessages']) && $topic_length < $modSettings['enableAllMessages'])
            $pages .= '  <a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0;all">' . $txt['all'] . '</a>';
         $pages .= ' Next»';
      }
      else
         $pages = '';
Title: Re: Recent topics for SMF2
Post by: leftezi on July 28, 2012, 01:28:01 PM
The page numbers links did not working properly. They redirect to wrong topics.
I tried to remove the page number section by deleting some code, with success, but i get this error in forum errors log:

Undefined variable: pages
File: ....Themes/default/TPsubs.template.php(127) : eval()'d code
Line: 385


The change i have tried is this:

// Show links to all the pages?
         if (count($tmppages) <= 0)
            $pages = '« ' . implode(' ', $tmppages);
      }
      else
         $pages = '';


Sure it' is the wrong way. Can someone tel me the right way to remove the page numbers?  :)
Title: Re: Recent topics for SMF2
Post by: IchBin on July 29, 2012, 01:46:50 AM
You need to post the code you are using so we can see what is going on. So you just want to remove the page number section?
Title: Re: Recent topics for SMF2
Post by: leftezi on July 29, 2012, 02:48:57 AM
Yes  :) The page numbers and ths "Prev" - "Next"
Thanks

global $context, $settings, $scripturl, $txt, $db_prefix, $user_info, $modSettings, $user_profile, $smcFunc;

//////////////////////////////////////////// ---------- Unconditional Exclude
//   
   $exclude_boards = array(28,87,137,85,138,83,32,24,27,44,117,128);   // KEEP (to preserve variable declaration)
//   $exclude_boards = array(5);   //  Exclude single board
//     $exclude_boards = array(55,69);   //  Exclude multiple boards
   $ex_board_clause = !empty($exclude_boards) ? ' AND b.id_board NOT IN (' . implode(', ', $exclude_boards) . ')' : '';
//   
//   

//////////////////////////////////////////// ---------- Use in TP PHP Article (no title or frame from theme)
//   This will give most recent XX posted to topics -OR-
//   most recent XX unreplied to topics -OR-
//   topics posted to in last XX hours -OR-
//   most recent XX topics on topic notify list
//   
//   Sorts by most recent reply (descending; most recent first) -OR-
//            creation order (descending; most recent first)
//   
//   All in the detailed topic format
//   
//   
//   Default
//   index.php?page=##
//   most recent posted to topics - will list
//   number equal to  $settings['number_recent_posts']
//   
//   index.php?page=##;count=50 or index.php?page=##;type=last;count=50
//   50 most recently posted to topics
//   
//   index.php?page=##;type=unreplied or index.php?page=##;type=unreplied;count=50
//   Most recent unreplied to topics - will
//   list number specified in 'count' or default to
//   number equal to  $settings['number_recent_posts']
//   
//   index.php?page=##;type=hours or index.php?page=##;type=hours;count=12
//   Topics posted to in last number of hours
//   specified in 'count' or default to 24.
//   
//   index.php?page=##;type=notify or index.php?page=##;type=notify;count=50
//   Topics in topic notifcation list up to number
//   specified in 'count' or a maximum of 100 topics.
//   
//   *** Admins Only ***
//   index.php?page=##;type=notify;user=XXX or index.php?page=##;type=notify;user=XXX;count=50
//   Topics in topic notifcation list of specified user up to number
//   specified in 'count' or a maximum of 100 topics.
//   
//   index.php?page=##;type=started or index.php?page=##;type=started;count=50
//   Topics started by current user list up to number
//   specified in 'count' or a maximum of 100 topics.
//   
//   *** Admins Only ***
//   index.php?page=##;type=notify;user=XXX or index.php?page=##;type=started;user=XXX;count=50
//   Topics started by specified user up to number
//   specified in 'count' or a maximum of 100 topics.
//   
//   Add argument order=create to sort by topic creation sequence (most recent first)
//   rather than by last reply sequence

   $do_query = 1;

//////////////////////////////////////////// ---------- Poor Man's Global Announcements Block (center block - no Title/Frame)
//   Delete documentation comments above and marked section below
//
//   $announce_topics = array(254, 568, 675, 678); // Topic ID's to be 'Announced'
//
//   $heading = '<center>Announcements<center>';
//   $where_clause = 't.ID_TOPIC IN (' . implode(', ', $announce_topics) . ')';
//   $limit_clause = '';
//   $order_clause = 't.ID_LAST_MSG DESC';
////////////////////////////////////////////   

//////////////////////////////////////////// ---------- Last 5 Topics Started by User Block (center block - no Title/Frame)
//   Delete documentation comments above and marked section below
//
//   $heading = 'Most Recent Topics You Started';
//   $where_clause = 'ms.ID_MEMBER = '.$ID_MEMBER;
//   $limit_clause = 'LIMIT 5';
//   $order_clause = 't.ID_FIRST_MSG DESC';
////////////////////////////////////////////   

//////////////////////////////////////////// ---------- Boardindex Most Recent Topics Arguments
//
//   Comment out the Info Center's Most Recent Posts Code and Insert this
//   to show Most Recent Topics in full detail style instead
//
//   $list_count = $settings['number_recent_posts'];
//   $heading = 'Most Recently Posted To Topics';
//   $where_clause = 't.ID_LAST_MSG >= ' . ($modSettings['maxMsgID'] - 50 * min($list_count, 5));
//   $limit_clause = 'LIMIT ' . $list_count;
//   $order_clause = 't.ID_LAST_MSG DESC';
////////////////////////////////////////////   

////////////////////////////////////////////  ------ Remove down to next mark to use in block/boardindex ------
//
   if (empty($settings['number_recent_posts']))
      $number_recent_posts = 12;
   else
      $number_recent_posts = $settings['number_recent_posts'];

        if( isset($_GET['type']) )
      $list_type = $_GET['type'];
   else
      $list_type = 'last';

        if( isset($_GET['count']) )
      $list_count = $_GET['count'];
   else
   {
      $list_count = $number_recent_posts;
      if ($list_type == 'notify')
         $list_count = 100;
      elseif ($list_type == 'hours')
         $list_count = 24;
   }

   if ($list_count <= 0)
   {
      $list_count = $number_recent_posts;
      if ($list_type == 'hours')
         $list_count = 24;
   }

   if ($list_count > 100)
      $list_count = 100;

        if( isset($_GET['order']) )
      $list_order = $_GET['order'];
   else
      $list_order = 'lastpost';

        if( $list_order == 'create' )
      $order_clause = 't.id_first_msg DESC';
   else
      $order_clause = 't.id_last_msg DESC';

   if ($list_type == 'hours')
   {
      $list_from = strtotime($list_count.' hours ago');
      $where_clause = 'ml.poster_time >= ' . $list_from;
      $limit_clause = ' ';
      $heading = 'Topics Posted To In Last '. $list_count . ' Hours';
   }
   elseif ($list_type == 'unreplied')
   {
      $where_clause = 't.num_replies = 0';
      if ($list_count == 0)
      {
         $limit_clause = ' ';
         $heading = 'Unreplied To Topics';
      }
      else
      {
      $limit_clause = 'LIMIT ' . $list_count;
      $heading = $list_count . ' Most Recent Unreplied To Topics';
      }
   }
   elseif ($list_type == 'notify')
   {
      if (isset($_GET['user']) && $user_info['is_admin'])
      {
         $watched_topics = array();
         $request = $smcFunc['db_query']("", "SELECT id_topic FROM ".$db_prefix."log_notify
                                 WHERE id_member = {int:user_id}
                                 AND id_board = 0",
                                 array('user_id' => $_GET['user']));
         while ($row = $smcFunc['db_fetch_assoc']($request))
            $watched_topics[] = $row['id_topic'];
         $smcFunc['db_free_result']($request);
         $heading = $list_count . ' Most Recent Topics Being Watched by User # '.$_GET['user'];
         $where_clause = 't.id_topic IN (' . implode(', ', $watched_topics) . ')';
         $limit_clause = 'LIMIT ' . $list_count;
         if (empty($watched_topics))
            $do_query = 0;
      }
      else
      {
         $watched_topics = array();
         $request = $smcFunc['db_query']("", "SELECT id_topic FROM ".$db_prefix."log_notify
                                 WHERE id_member = {int:id_member}
                                 AND id_board = 0",
                                 array('id_member' => $user_info['id']));
         while ($row = $smcFunc['db_fetch_assoc']($request))
            $watched_topics[] = $row['id_topic'];
         $smcFunc['db_free_result']($request);
         $heading = $list_count . ' Most Recent Topics Being Watched';
         $where_clause = 't.id_topic IN (' . implode(', ', $watched_topics) . ')';
         $limit_clause = 'LIMIT ' . $list_count;
         if (empty($watched_topics))
            $do_query = 0;
      }
   }
   elseif ($list_type == 'started')
   {
      if (isset($_GET['user']) && $user_info['is_admin'])
      {
         $where_clause = 'ms.id_member = '.$_GET['user'];
         $limit_clause = 'LIMIT ' . $list_count;
              if( $list_order == 'create' )
         {
            $order_clause = 't.id_first_msg DESC';
            $heading = 'Most Recent Topics Started by User '.$_GET['user'];
         }
         else
         {
            $order_clause = 't.id_last_msg DESC';
            $heading = 'Most Recently Posted To Topics Started by User '.$_GET['user'];
         }
      }
      else
      {
         $where_clause = 'ms.id_member = '.$user_info['id'];
         $limit_clause = 'LIMIT ' . $list_count;
              if( $list_order == 'create' )
         {
            $order_clause = 't.id_first_msg DESC';
            $heading = 'Most Recent Topics You Started';
         }
         else
         {
            $order_clause = 't.id_last_msg DESC';
            $heading = 'Most Recently Posted To Topics You Started';
         }
      }
   }
   else
   {
      $where_clause = 't.id_last_msg >= ' . ($modSettings['maxMsgID'] - 90 * min($list_count, 5));
      $limit_clause = 'LIMIT ' . $list_count;
      $heading = $list_count . ' Most Recently Posted To Topics';
   }
//
////////////////////////////////////////////  ------ Remove up to first mark to use in block/boardindex ------

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

   $groupcolors = array();
   $request = $smcFunc['db_query']("", "SELECT id_group, online_color FROM ".$db_prefix."membergroups",array());
   while ($row = $smcFunc['db_fetch_assoc']($request))
      $groupcolors[$row['id_group']] = $row['online_color'];
   $smcFunc['db_free_result']($request);

   $topics = array();

   if ($do_query == 1)
   {
      $request = $smcFunc['db_query']("", "
      SELECT
            ms.subject AS firstSubject, ms.poster_time AS firstPosterTime, ms.id_topic, t.id_last_msg, t.id_board, b.name AS bname,
            t.num_replies, t.num_views, ms.id_member AS ID_FIRST_MEMBER, ml.id_member AS ID_LAST_MEMBER,
            ml.poster_time AS lastPosterTime, IFNULL(mems.real_name, ms.poster_name) AS firstPosterName,
            IFNULL(meml.real_name, ml.poster_name) AS lastPosterName,
            mems.id_group as mems_group, meml.id_group as meml_group,
            ml.subject AS lastSubject, b.member_groups,
            ml.icon AS lastIcon, ms.icon AS firstIcon, t.id_poll, t.is_sticky, t.locked, ml.modified_time AS lastModifiedTime,
            LEFT(ml.body, 384) AS lastBody, LEFT(ms.body, 384) AS firstBody,
            ml.smileys_enabled AS lastSmileys, ms.smileys_enabled AS firstSmileys, t.id_first_msg,"
            . ($user_info['is_guest'] ? '1 AS isRead, 0 AS new_from' : '
            IFNULL(lt.id_msg, IFNULL(lmr.id_msg, 0)) >= ml.id_msg_modified AS isRead,
            IFNULL(lt.id_msg, IFNULL(lmr.id_msg, -1)) + 1 AS new_from') . "
         FROM (".$db_prefix."messages AS ms, ".$db_prefix."messages AS ml, ".$db_prefix."topics AS t, ".$db_prefix."boards AS b)
            LEFT JOIN ".$db_prefix."members AS mems ON (mems.id_member = ms.id_member)
            LEFT JOIN ".$db_prefix."members AS meml ON (meml.id_member = ml.id_member)
            LEFT JOIN ".$db_prefix."log_topics AS lt ON (lt.id_topic = t.id_topic AND lt.id_member = ".$user_info['id'].")
            LEFT JOIN ".$db_prefix."log_mark_read AS lmr ON (lmr.id_board = t.id_board AND lmr.id_member = ".$user_info['id'].")
         WHERE " . $where_clause . $ex_board_clause . "
            AND t.id_topic = ms.id_topic
            AND b.id_board = t.id_board" . (!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0 ? " AND b.id_board != ".$modSettings['recycle_board'] : "") . "
            AND ms.id_msg = t.id_first_msg
            AND ml.id_msg = t.id_last_msg
            AND " . $user_info['query_see_board'] . "
         ORDER BY " . $order_clause . " " . $limit_clause,
       array());


   $topic_ids = array();
   while ($row = $smcFunc['db_fetch_assoc']($request))
   {
      if ($row['id_poll'] > 0 && $modSettings['pollMode'] == '0')
         continue;

      $topic_ids[] = $row['id_topic'];

      // Clip the strings first because censoring is slow :/. (for some reason?)
      $row['firstBody'] = strip_tags(strtr(parse_bbc($row['firstBody'], $row['firstSmileys'], $row['id_first_msg']), array('<br />' => '
')));
      if (strlen($row['firstBody']) > 128)
         $row['firstBody'] = substr($row['firstBody'], 0, 128) . '...';
      $row['lastBody'] = strip_tags(strtr(parse_bbc($row['lastBody'], $row['lastSmileys'], $row['id_last_msg']), array('<br />' => '
')));
      if (strlen($row['lastBody']) > 128)
         $row['lastBody'] = substr($row['lastBody'], 0, 128) . '...';

         $row['lastSubject'] = $row['firstSubject'];
         $row['lastBody'] = $row['firstBody'];

      // Decide how many pages the topic should have.
      $topic_length = $row['num_replies'] + 1;
      if ($topic_length > $modSettings['defaultMaxMessages'])
      {
         $tmppages = array();
         $tmpa = 1;
         for ($tmpb = 0; $tmpb < $topic_length; $tmpb += $modSettings['defaultMaxMessages'])
         {
            $tmppages[] = '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.' . $tmpb . ';topicseen">' . $tmpa . '</a>';
            $tmpa++;
         }
// Show links to all the pages?
         if (count($tmppages) <= 0)
            $pages = '« ' . implode(' ', $tmppages);
      }
      else
         $pages = '';

      // We need to check the topic icons exist... you can never be too sure!
      if (empty($modSettings['messageIconChecks_disable']))
      {
         // First icon first... as you'd expect.
         if (!isset($icon_sources[$row['firstIcon']]))
            $icon_sources[$row['firstIcon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['firstIcon'] . '.gif') ? 'images_url' : 'default_images_url';
         // Last icon... last... duh.
         if (!isset($icon_sources[$row['lastIcon']]))
            $icon_sources[$row['lastIcon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['lastIcon'] . '.gif') ? 'images_url' : 'default_images_url';
      }

      $color_start = !empty($groupcolors[$row['mems_group']]) ? $groupcolors[$row['mems_group']] : '';
      $color_last = !empty($groupcolors[$row['meml_group']]) ? $groupcolors[$row['meml_group']] : '';

      // And build the array.
      $topics[$row['id_topic']] = array(
         'id' => $row['id_topic'],
         'first_post' => array(
            'id' => $row['id_first_msg'],
            'member' => array(
               'name' => $row['firstPosterName'],
               'id' => $row['ID_FIRST_MEMBER'],
               'href' => $scripturl . '?action=profile;u=' . $row['ID_FIRST_MEMBER'],
               'link' => !empty($row['ID_FIRST_MEMBER']) ? '<a href="' . $scripturl . '?action=profile;u=' . $row['ID_FIRST_MEMBER'] . '" title="' . $txt['profile_of'] . ' ' . $row['firstPosterName'] . '">' . '<font color="' . $color_start . '">' . $row['firstPosterName'] . '</font>' . '</a>' : $row['firstPosterName']
            ),
            'time' => timeformat($row['firstPosterTime']),
            'timestamp' => forum_time(true, $row['firstPosterTime']),
            'subject' => $row['firstSubject'],
            'preview' => $row['firstBody'],
            'icon' => $row['firstIcon'],
            'icon_url' => $settings[$icon_sources[$row['firstIcon']]] . '/post/' . $row['firstIcon'] . '.gif',
            'href' => $scripturl . '?topic=' . $row['id_topic'] . '.0;topicseen',
            'link' => '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0;topicseen">' . $row['firstSubject'] . '</a>'
         ),
         'last_post' => array(
            'id' => $row['id_last_msg'],
            'member' => array(
               'name' => $row['lastPosterName'],
               'id' => $row['ID_LAST_MEMBER'],
               'href' => $scripturl . '?action=profile;u=' . $row['ID_LAST_MEMBER'],
               'link' => !empty($row['ID_LAST_MEMBER']) ? '<a href="' . $scripturl . '?action=profile;u=' . $row['ID_LAST_MEMBER'] . '">' . '<font color="' . $color_last . '">' . $row['lastPosterName'] . '</font>' . '</a>' : $row['lastPosterName']
            ),
            'time' => timeformat($row['lastPosterTime']),
            'timestamp' => forum_time(true, $row['lastPosterTime']),
            'subject' => $row['lastSubject'],
            'preview' => $row['lastBody'],
            'icon' => $row['lastIcon'],
            'icon_url' => $settings[$icon_sources[$row['lastIcon']]] . '/post/' . $row['lastIcon'] . '.gif',
            'href' => $scripturl . '?topic=' . $row['id_topic'] . ($row['num_replies'] == 0 ? '.0' : '.msg' . $row['id_last_msg']) . ';topicseen#msg' . $row['id_last_msg'],
            'link' => '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . ($row['num_replies'] == 0 ? '.0' : '.msg' . $row['id_last_msg']) . ';topicseen#msg' . $row['id_last_msg'] . '">' . $row['lastSubject'] . '</a>'
         ),
         'new' => $row['isRead'],
         'new_from' => $row['new_from'],
         'new_href' => $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['new_from'] . ';topicseen#new',
         'href' => $scripturl . '?topic=' . $row['id_topic'] . ($row['num_replies'] == 0 ? '.0' : '.msg' . $row['new_from']) . ';topicseen' . ($row['num_replies'] == 0 ? '' : 'new'),
         'link' => '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . ($row['num_replies'] == 0 ? '.0' : '.msg' . $row['new_from']) . ';topicseen#msg' . $row['new_from'] . '">' . $row['firstSubject'] . '</a>',
         'is_sticky' => !empty($modSettings['enableStickyTopics']) && !empty($row['isSticky']),
         'is_locked' => !empty($row['locked']),
         'is_poll' => $modSettings['pollMode'] == '1' && $row['id_poll'] > 0,
         'is_hot' => $row['num_replies'] >= $modSettings['hotTopicPosts'],
         'is_very_hot' => $row['num_replies'] >= $modSettings['hotTopicVeryPosts'],
         'is_posted_in' => false,
         'icon' => $row['firstIcon'],
         'icon_url' => $settings[$icon_sources[$row['firstIcon']]] . '/post/' . $row['firstIcon'] . '.gif',
         'subject' => $row['firstSubject'],
         'pages' => $pages,
         'replies' => $row['num_replies'],
         'views' => $row['num_views'],
         '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>'
         )
      );

      determineTopicClass($topics[$row['id_topic']]);
   }
   $smcFunc['db_free_result']($request);

   if (!empty($modSettings['enableParticipation']) && !empty($topic_ids))
   {
      $result = $smcFunc['db_query']("", "
         SELECT id_topic
         FROM ".$db_prefix."messages
         WHERE id_topic IN (" . implode(', ', $topic_ids) . ")
            AND id_member = {int:id_member}",
         array('id_member' => $user_info['id']));
      while ($row = $smcFunc['db_fetch_assoc']($result))
      {
         if (empty($topics[$row['id_topic']]['is_posted_in']))
         {
            $topics[$row['id_topic']]['is_posted_in'] = true;
            $topics[$row['id_topic']]['class'] = 'my_' . $topics[$row['id_topic']]['class'];
         }
      }
      $smcFunc['db_free_result']($result);
   }

   }

if (!empty($topics))
    {
    echo '
        <div class="tborder" ', $context['browser']['needs_size_fix'] && !$context['browser']['is_ie6'] ? 'style="width: 100%;margin:0px;"' : 'style="margin:0px;"', '>
            <table border="0" width="100%" cellspacing="1" cellpadding="1" class="bordercolor">
                <tr>';


    echo '
                </tr>';

    echo '
            <tr class="titlebg">
               <td width="10%" colspan="2"> </td>
               <td>', $txt['subject'], '
               </td><td width="14%">', $txt['posted_by'], '
               </td><td width="4%" align="center">', $txt['replies'], '
               </td><td width="4%" align="center">', $txt['views'], '
               </td><td width="24%">', $txt['last_post'], '
               </td>
            </tr>';

   foreach ($topics as $topic)
   {
      // Do we want to seperate the sticky and lock status out?
      if (!empty($settings['seperate_sticky_lock']) && strpos($topic['class'], 'sticky') !== false)
         $topic['class'] = substr($topic['class'], 0, strrpos($topic['class'], '_sticky'));
      if (!empty($settings['seperate_sticky_lock']) && strpos($topic['class'], 'locked') !== false)
         $topic['class'] = substr($topic['class'], 0, strrpos($topic['class'], '_locked'));

      echo '
            <tr>
               <td class="windowbg2" valign="middle" align="center" width="6%">
                  <img src="' . $settings['images_url'] . '/topic/' . $topic['class'] . '.gif" alt="" />
               </td><td class="windowbg2" valign="middle" align="center" width="4%">
                  <img src="' . $topic['first_post']['icon_url'] . '" alt="" align="middle" />
               </td><td class="windowbg' , $topic['is_sticky'] && !empty($settings['seperate_sticky_lock']) ? '3' : '' , '" width="48%" valign="middle">' , $topic['is_locked'] && !empty($settings['seperate_sticky_lock']) ? '
                  <img src="' . $settings['images_url'] . '/icons/quick_lock.gif" align="right" alt="" style="margin: 0;" />' : '' , $topic['is_sticky'] && !empty($settings['seperate_sticky_lock']) ? '
                  <img src="' . $settings['images_url'] . '/icons/show_sticky.gif" align="right" alt="" style="margin: 0;" />' : '', $topic['first_post']['link'];
               if ($topic['new'] == 0)
                  {
                  echo '<a href="', $topic['new_href'], '"> <img src="', $settings['images_url'], '/', $context['user']['language'], '/new.gif" alt="', $txt['seconds_with'], '" /></a>';
                  }
                echo '
               <span class="smalltext">', $topic['pages'], '<br>', $txt['in'], ' ', $topic['board']['link'], '</span></td>
               <td class="windowbg2" valign="middle" width="14%">
                  ', $topic['first_post']['member']['link'], '</td>
               <td class="windowbg" valign="middle" width="4%" align="center">
                  ', $topic['replies'], '</td>
               <td class="windowbg" valign="middle" width="4%" align="center">
                  ', $topic['views'], '</td>
               <td class="windowbg2" valign="middle" width="22%">
                  <a href="', $topic['last_post']['href'], '"><img src="', $settings['images_url'], '/icons/last_post.gif" alt="', $txt['last_post'], '" title="', $txt['last_post'], '" style="float: right;" /></a>
                  <span class="smalltext">
                     ', $topic['last_post']['time'], '<br />
                     ', $txt['by'], ' ', $topic['last_post']['member']['link'], '
                  </span>
               </td>
            </tr>';
   }

    echo '</table></div>';

    }
   else
       echo '<b><u>'.$heading.'<br><br>No Topics Match Search Criteria</u></b>';



Title: Re: Recent topics for SMF2
Post by: IchBin on July 29, 2012, 04:19:31 AM
Think this should do it. Let me know if I missed something.

global $context, $settings, $scripturl, $txt, $db_prefix, $user_info, $modSettings, $user_profile, $smcFunc;

//////////////////////////////////////////// ---------- Unconditional Exclude
//   
   $exclude_boards = array(28,87,137,85,138,83,32,24,27,44,117,128);   // KEEP (to preserve variable declaration)
//   $exclude_boards = array(5);   //  Exclude single board
//     $exclude_boards = array(55,69);   //  Exclude multiple boards
   $ex_board_clause = !empty($exclude_boards) ? ' AND b.id_board NOT IN (' . implode(', ', $exclude_boards) . ')' : '';
//   
//   

//////////////////////////////////////////// ---------- Use in TP PHP Article (no title or frame from theme)
//   This will give most recent XX posted to topics -OR-
//   most recent XX unreplied to topics -OR-
//   topics posted to in last XX hours -OR-
//   most recent XX topics on topic notify list
//   
//   Sorts by most recent reply (descending; most recent first) -OR-
//            creation order (descending; most recent first)
//   
//   All in the detailed topic format
//   
//   
//   Default
//   index.php?page=##
//   most recent posted to topics - will list
//   number equal to  $settings['number_recent_posts']
//   
//   index.php?page=##;count=50 or index.php?page=##;type=last;count=50
//   50 most recently posted to topics
//   
//   index.php?page=##;type=unreplied or index.php?page=##;type=unreplied;count=50
//   Most recent unreplied to topics - will
//   list number specified in 'count' or default to
//   number equal to  $settings['number_recent_posts']
//   
//   index.php?page=##;type=hours or index.php?page=##;type=hours;count=12
//   Topics posted to in last number of hours
//   specified in 'count' or default to 24.
//   
//   index.php?page=##;type=notify or index.php?page=##;type=notify;count=50
//   Topics in topic notifcation list up to number
//   specified in 'count' or a maximum of 100 topics.
//   
//   *** Admins Only ***
//   index.php?page=##;type=notify;user=XXX or index.php?page=##;type=notify;user=XXX;count=50
//   Topics in topic notifcation list of specified user up to number
//   specified in 'count' or a maximum of 100 topics.
//   
//   index.php?page=##;type=started or index.php?page=##;type=started;count=50
//   Topics started by current user list up to number
//   specified in 'count' or a maximum of 100 topics.
//   
//   *** Admins Only ***
//   index.php?page=##;type=notify;user=XXX or index.php?page=##;type=started;user=XXX;count=50
//   Topics started by specified user up to number
//   specified in 'count' or a maximum of 100 topics.
//   
//   Add argument order=create to sort by topic creation sequence (most recent first)
//   rather than by last reply sequence

   $do_query = 1;

//////////////////////////////////////////// ---------- Poor Man's Global Announcements Block (center block - no Title/Frame)
//   Delete documentation comments above and marked section below
//
//   $announce_topics = array(254, 568, 675, 678); // Topic ID's to be 'Announced'
//
//   $heading = '<center>Announcements<center>';
//   $where_clause = 't.ID_TOPIC IN (' . implode(', ', $announce_topics) . ')';
//   $limit_clause = '';
//   $order_clause = 't.ID_LAST_MSG DESC';
////////////////////////////////////////////   

//////////////////////////////////////////// ---------- Last 5 Topics Started by User Block (center block - no Title/Frame)
//   Delete documentation comments above and marked section below
//
//   $heading = 'Most Recent Topics You Started';
//   $where_clause = 'ms.ID_MEMBER = '.$ID_MEMBER;
//   $limit_clause = 'LIMIT 5';
//   $order_clause = 't.ID_FIRST_MSG DESC';
////////////////////////////////////////////   

//////////////////////////////////////////// ---------- Boardindex Most Recent Topics Arguments
//
//   Comment out the Info Center's Most Recent Posts Code and Insert this
//   to show Most Recent Topics in full detail style instead
//
//   $list_count = $settings['number_recent_posts'];
//   $heading = 'Most Recently Posted To Topics';
//   $where_clause = 't.ID_LAST_MSG >= ' . ($modSettings['maxMsgID'] - 50 * min($list_count, 5));
//   $limit_clause = 'LIMIT ' . $list_count;
//   $order_clause = 't.ID_LAST_MSG DESC';
////////////////////////////////////////////   

////////////////////////////////////////////  ------ Remove down to next mark to use in block/boardindex ------
//
   if (empty($settings['number_recent_posts']))
      $number_recent_posts = 12;
   else
      $number_recent_posts = $settings['number_recent_posts'];

        if( isset($_GET['type']) )
      $list_type = $_GET['type'];
   else
      $list_type = 'last';

        if( isset($_GET['count']) )
      $list_count = $_GET['count'];
   else
   {
      $list_count = $number_recent_posts;
      if ($list_type == 'notify')
         $list_count = 100;
      elseif ($list_type == 'hours')
         $list_count = 24;
   }

   if ($list_count <= 0)
   {
      $list_count = $number_recent_posts;
      if ($list_type == 'hours')
         $list_count = 24;
   }

   if ($list_count > 100)
      $list_count = 100;

        if( isset($_GET['order']) )
      $list_order = $_GET['order'];
   else
      $list_order = 'lastpost';

        if( $list_order == 'create' )
      $order_clause = 't.id_first_msg DESC';
   else
      $order_clause = 't.id_last_msg DESC';

   if ($list_type == 'hours')
   {
      $list_from = strtotime($list_count.' hours ago');
      $where_clause = 'ml.poster_time >= ' . $list_from;
      $limit_clause = ' ';
      $heading = 'Topics Posted To In Last '. $list_count . ' Hours';
   }
   elseif ($list_type == 'unreplied')
   {
      $where_clause = 't.num_replies = 0';
      if ($list_count == 0)
      {
         $limit_clause = ' ';
         $heading = 'Unreplied To Topics';
      }
      else
      {
      $limit_clause = 'LIMIT ' . $list_count;
      $heading = $list_count . ' Most Recent Unreplied To Topics';
      }
   }
   elseif ($list_type == 'notify')
   {
      if (isset($_GET['user']) && $user_info['is_admin'])
      {
         $watched_topics = array();
         $request = $smcFunc['db_query']("", "SELECT id_topic FROM ".$db_prefix."log_notify
                                 WHERE id_member = {int:user_id}
                                 AND id_board = 0",
                                 array('user_id' => $_GET['user']));
         while ($row = $smcFunc['db_fetch_assoc']($request))
            $watched_topics[] = $row['id_topic'];
         $smcFunc['db_free_result']($request);
         $heading = $list_count . ' Most Recent Topics Being Watched by User # '.$_GET['user'];
         $where_clause = 't.id_topic IN (' . implode(', ', $watched_topics) . ')';
         $limit_clause = 'LIMIT ' . $list_count;
         if (empty($watched_topics))
            $do_query = 0;
      }
      else
      {
         $watched_topics = array();
         $request = $smcFunc['db_query']("", "SELECT id_topic FROM ".$db_prefix."log_notify
                                 WHERE id_member = {int:id_member}
                                 AND id_board = 0",
                                 array('id_member' => $user_info['id']));
         while ($row = $smcFunc['db_fetch_assoc']($request))
            $watched_topics[] = $row['id_topic'];
         $smcFunc['db_free_result']($request);
         $heading = $list_count . ' Most Recent Topics Being Watched';
         $where_clause = 't.id_topic IN (' . implode(', ', $watched_topics) . ')';
         $limit_clause = 'LIMIT ' . $list_count;
         if (empty($watched_topics))
            $do_query = 0;
      }
   }
   elseif ($list_type == 'started')
   {
      if (isset($_GET['user']) && $user_info['is_admin'])
      {
         $where_clause = 'ms.id_member = '.$_GET['user'];
         $limit_clause = 'LIMIT ' . $list_count;
              if( $list_order == 'create' )
         {
            $order_clause = 't.id_first_msg DESC';
            $heading = 'Most Recent Topics Started by User '.$_GET['user'];
         }
         else
         {
            $order_clause = 't.id_last_msg DESC';
            $heading = 'Most Recently Posted To Topics Started by User '.$_GET['user'];
         }
      }
      else
      {
         $where_clause = 'ms.id_member = '.$user_info['id'];
         $limit_clause = 'LIMIT ' . $list_count;
              if( $list_order == 'create' )
         {
            $order_clause = 't.id_first_msg DESC';
            $heading = 'Most Recent Topics You Started';
         }
         else
         {
            $order_clause = 't.id_last_msg DESC';
            $heading = 'Most Recently Posted To Topics You Started';
         }
      }
   }
   else
   {
      $where_clause = 't.id_last_msg >= ' . ($modSettings['maxMsgID'] - 90 * min($list_count, 5));
      $limit_clause = 'LIMIT ' . $list_count;
      $heading = $list_count . ' Most Recently Posted To Topics';
   }
//
////////////////////////////////////////////  ------ Remove up to first mark to use in block/boardindex ------

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

   $groupcolors = array();
   $request = $smcFunc['db_query']("", "SELECT id_group, online_color FROM ".$db_prefix."membergroups",array());
   while ($row = $smcFunc['db_fetch_assoc']($request))
      $groupcolors[$row['id_group']] = $row['online_color'];
   $smcFunc['db_free_result']($request);

   $topics = array();

   if ($do_query == 1)
   {
      $request = $smcFunc['db_query']("", "
      SELECT
            ms.subject AS firstSubject, ms.poster_time AS firstPosterTime, ms.id_topic, t.id_last_msg, t.id_board, b.name AS bname,
            t.num_replies, t.num_views, ms.id_member AS ID_FIRST_MEMBER, ml.id_member AS ID_LAST_MEMBER,
            ml.poster_time AS lastPosterTime, IFNULL(mems.real_name, ms.poster_name) AS firstPosterName,
            IFNULL(meml.real_name, ml.poster_name) AS lastPosterName,
            mems.id_group as mems_group, meml.id_group as meml_group,
            ml.subject AS lastSubject, b.member_groups,
            ml.icon AS lastIcon, ms.icon AS firstIcon, t.id_poll, t.is_sticky, t.locked, ml.modified_time AS lastModifiedTime,
            LEFT(ml.body, 384) AS lastBody, LEFT(ms.body, 384) AS firstBody,
            ml.smileys_enabled AS lastSmileys, ms.smileys_enabled AS firstSmileys, t.id_first_msg,"
            . ($user_info['is_guest'] ? '1 AS isRead, 0 AS new_from' : '
            IFNULL(lt.id_msg, IFNULL(lmr.id_msg, 0)) >= ml.id_msg_modified AS isRead,
            IFNULL(lt.id_msg, IFNULL(lmr.id_msg, -1)) + 1 AS new_from') . "
         FROM (".$db_prefix."messages AS ms, ".$db_prefix."messages AS ml, ".$db_prefix."topics AS t, ".$db_prefix."boards AS b)
            LEFT JOIN ".$db_prefix."members AS mems ON (mems.id_member = ms.id_member)
            LEFT JOIN ".$db_prefix."members AS meml ON (meml.id_member = ml.id_member)
            LEFT JOIN ".$db_prefix."log_topics AS lt ON (lt.id_topic = t.id_topic AND lt.id_member = ".$user_info['id'].")
            LEFT JOIN ".$db_prefix."log_mark_read AS lmr ON (lmr.id_board = t.id_board AND lmr.id_member = ".$user_info['id'].")
         WHERE " . $where_clause . $ex_board_clause . "
            AND t.id_topic = ms.id_topic
            AND b.id_board = t.id_board" . (!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0 ? " AND b.id_board != ".$modSettings['recycle_board'] : "") . "
            AND ms.id_msg = t.id_first_msg
            AND ml.id_msg = t.id_last_msg
            AND " . $user_info['query_see_board'] . "
         ORDER BY " . $order_clause . " " . $limit_clause,
       array());


   $topic_ids = array();
   while ($row = $smcFunc['db_fetch_assoc']($request))
   {
      if ($row['id_poll'] > 0 && $modSettings['pollMode'] == '0')
         continue;

      $topic_ids[] = $row['id_topic'];

      // Clip the strings first because censoring is slow :/. (for some reason?)
      $row['firstBody'] = strip_tags(strtr(parse_bbc($row['firstBody'], $row['firstSmileys'], $row['id_first_msg']), array('<br />' => '
')));
      if (strlen($row['firstBody']) > 128)
         $row['firstBody'] = substr($row['firstBody'], 0, 128) . '...';
      $row['lastBody'] = strip_tags(strtr(parse_bbc($row['lastBody'], $row['lastSmileys'], $row['id_last_msg']), array('<br />' => '
')));
      if (strlen($row['lastBody']) > 128)
         $row['lastBody'] = substr($row['lastBody'], 0, 128) . '...';

         $row['lastSubject'] = $row['firstSubject'];
         $row['lastBody'] = $row['firstBody'];

      // We need to check the topic icons exist... you can never be too sure!
      if (empty($modSettings['messageIconChecks_disable']))
      {
         // First icon first... as you'd expect.
         if (!isset($icon_sources[$row['firstIcon']]))
            $icon_sources[$row['firstIcon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['firstIcon'] . '.gif') ? 'images_url' : 'default_images_url';
         // Last icon... last... duh.
         if (!isset($icon_sources[$row['lastIcon']]))
            $icon_sources[$row['lastIcon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['lastIcon'] . '.gif') ? 'images_url' : 'default_images_url';
      }

      $color_start = !empty($groupcolors[$row['mems_group']]) ? $groupcolors[$row['mems_group']] : '';
      $color_last = !empty($groupcolors[$row['meml_group']]) ? $groupcolors[$row['meml_group']] : '';

      // And build the array.
      $topics[$row['id_topic']] = array(
         'id' => $row['id_topic'],
         'first_post' => array(
            'id' => $row['id_first_msg'],
            'member' => array(
               'name' => $row['firstPosterName'],
               'id' => $row['ID_FIRST_MEMBER'],
               'href' => $scripturl . '?action=profile;u=' . $row['ID_FIRST_MEMBER'],
               'link' => !empty($row['ID_FIRST_MEMBER']) ? '<a href="' . $scripturl . '?action=profile;u=' . $row['ID_FIRST_MEMBER'] . '" title="' . $txt['profile_of'] . ' ' . $row['firstPosterName'] . '">' . '<font color="' . $color_start . '">' . $row['firstPosterName'] . '</font>' . '</a>' : $row['firstPosterName']
            ),
            'time' => timeformat($row['firstPosterTime']),
            'timestamp' => forum_time(true, $row['firstPosterTime']),
            'subject' => $row['firstSubject'],
            'preview' => $row['firstBody'],
            'icon' => $row['firstIcon'],
            'icon_url' => $settings[$icon_sources[$row['firstIcon']]] . '/post/' . $row['firstIcon'] . '.gif',
            'href' => $scripturl . '?topic=' . $row['id_topic'] . '.0;topicseen',
            'link' => '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0;topicseen">' . $row['firstSubject'] . '</a>'
         ),
         'last_post' => array(
            'id' => $row['id_last_msg'],
            'member' => array(
               'name' => $row['lastPosterName'],
               'id' => $row['ID_LAST_MEMBER'],
               'href' => $scripturl . '?action=profile;u=' . $row['ID_LAST_MEMBER'],
               'link' => !empty($row['ID_LAST_MEMBER']) ? '<a href="' . $scripturl . '?action=profile;u=' . $row['ID_LAST_MEMBER'] . '">' . '<font color="' . $color_last . '">' . $row['lastPosterName'] . '</font>' . '</a>' : $row['lastPosterName']
            ),
            'time' => timeformat($row['lastPosterTime']),
            'timestamp' => forum_time(true, $row['lastPosterTime']),
            'subject' => $row['lastSubject'],
            'preview' => $row['lastBody'],
            'icon' => $row['lastIcon'],
            'icon_url' => $settings[$icon_sources[$row['lastIcon']]] . '/post/' . $row['lastIcon'] . '.gif',
            'href' => $scripturl . '?topic=' . $row['id_topic'] . ($row['num_replies'] == 0 ? '.0' : '.msg' . $row['id_last_msg']) . ';topicseen#msg' . $row['id_last_msg'],
            'link' => '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . ($row['num_replies'] == 0 ? '.0' : '.msg' . $row['id_last_msg']) . ';topicseen#msg' . $row['id_last_msg'] . '">' . $row['lastSubject'] . '</a>'
         ),
         'new' => $row['isRead'],
         'new_from' => $row['new_from'],
         'new_href' => $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['new_from'] . ';topicseen#new',
         'href' => $scripturl . '?topic=' . $row['id_topic'] . ($row['num_replies'] == 0 ? '.0' : '.msg' . $row['new_from']) . ';topicseen' . ($row['num_replies'] == 0 ? '' : 'new'),
         'link' => '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . ($row['num_replies'] == 0 ? '.0' : '.msg' . $row['new_from']) . ';topicseen#msg' . $row['new_from'] . '">' . $row['firstSubject'] . '</a>',
         'is_sticky' => !empty($modSettings['enableStickyTopics']) && !empty($row['isSticky']),
         'is_locked' => !empty($row['locked']),
         'is_poll' => $modSettings['pollMode'] == '1' && $row['id_poll'] > 0,
         'is_hot' => $row['num_replies'] >= $modSettings['hotTopicPosts'],
         'is_very_hot' => $row['num_replies'] >= $modSettings['hotTopicVeryPosts'],
         'is_posted_in' => false,
         'icon' => $row['firstIcon'],
         'icon_url' => $settings[$icon_sources[$row['firstIcon']]] . '/post/' . $row['firstIcon'] . '.gif',
         'subject' => $row['firstSubject'],
         'replies' => $row['num_replies'],
         'views' => $row['num_views'],
         '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>'
         )
      );

      determineTopicClass($topics[$row['id_topic']]);
   }
   $smcFunc['db_free_result']($request);

   if (!empty($modSettings['enableParticipation']) && !empty($topic_ids))
   {
      $result = $smcFunc['db_query']("", "
         SELECT id_topic
         FROM ".$db_prefix."messages
         WHERE id_topic IN (" . implode(', ', $topic_ids) . ")
            AND id_member = {int:id_member}",
         array('id_member' => $user_info['id']));
      while ($row = $smcFunc['db_fetch_assoc']($result))
      {
         if (empty($topics[$row['id_topic']]['is_posted_in']))
         {
            $topics[$row['id_topic']]['is_posted_in'] = true;
            $topics[$row['id_topic']]['class'] = 'my_' . $topics[$row['id_topic']]['class'];
         }
      }
      $smcFunc['db_free_result']($result);
   }

   }

if (!empty($topics))
    {
    echo '
        <div class="tborder" ', $context['browser']['needs_size_fix'] && !$context['browser']['is_ie6'] ? 'style="width: 100%;margin:0px;"' : 'style="margin:0px;"', '>
            <table border="0" width="100%" cellspacing="1" cellpadding="1" class="bordercolor">
                <tr>';


    echo '
                </tr>';

    echo '
            <tr class="titlebg">
               <td width="10%" colspan="2"> </td>
               <td>', $txt['subject'], '
               </td><td width="14%">', $txt['posted_by'], '
               </td><td width="4%" align="center">', $txt['replies'], '
               </td><td width="4%" align="center">', $txt['views'], '
               </td><td width="24%">', $txt['last_post'], '
               </td>
            </tr>';

   foreach ($topics as $topic)
   {
      // Do we want to seperate the sticky and lock status out?
      if (!empty($settings['seperate_sticky_lock']) && strpos($topic['class'], 'sticky') !== false)
         $topic['class'] = substr($topic['class'], 0, strrpos($topic['class'], '_sticky'));
      if (!empty($settings['seperate_sticky_lock']) && strpos($topic['class'], 'locked') !== false)
         $topic['class'] = substr($topic['class'], 0, strrpos($topic['class'], '_locked'));

      echo '
            <tr>
               <td class="windowbg2" valign="middle" align="center" width="6%">
                  <img src="' . $settings['images_url'] . '/topic/' . $topic['class'] . '.gif" alt="" />
               </td><td class="windowbg2" valign="middle" align="center" width="4%">
                  <img src="' . $topic['first_post']['icon_url'] . '" alt="" align="middle" />
               </td><td class="windowbg' , $topic['is_sticky'] && !empty($settings['seperate_sticky_lock']) ? '3' : '' , '" width="48%" valign="middle">' , $topic['is_locked'] && !empty($settings['seperate_sticky_lock']) ? '
                  <img src="' . $settings['images_url'] . '/icons/quick_lock.gif" align="right" alt="" style="margin: 0;" />' : '' , $topic['is_sticky'] && !empty($settings['seperate_sticky_lock']) ? '
                  <img src="' . $settings['images_url'] . '/icons/show_sticky.gif" align="right" alt="" style="margin: 0;" />' : '', $topic['first_post']['link'];
               if ($topic['new'] == 0)
                  {
                  echo '<a href="', $topic['new_href'], '"> <img src="', $settings['images_url'], '/', $context['user']['language'], '/new.gif" alt="', $txt['seconds_with'], '" /></a>';
                  }
                echo '
               <span class="smalltext">', $topic['board']['link'], '</span></td>
               <td class="windowbg2" valign="middle" width="14%">
                  ', $topic['first_post']['member']['link'], '</td>
               <td class="windowbg" valign="middle" width="4%" align="center">
                  ', $topic['replies'], '</td>
               <td class="windowbg" valign="middle" width="4%" align="center">
                  ', $topic['views'], '</td>
               <td class="windowbg2" valign="middle" width="22%">
                  <a href="', $topic['last_post']['href'], '"><img src="', $settings['images_url'], '/icons/last_post.gif" alt="', $txt['last_post'], '" title="', $txt['last_post'], '" style="float: right;" /></a>
                  <span class="smalltext">
                     ', $topic['last_post']['time'], '<br />
                     ', $txt['by'], ' ', $topic['last_post']['member']['link'], '
                  </span>
               </td>
            </tr>';
   }

    echo '</table></div>';

    }
   else
       echo '<b><u>'.$heading.'<br><br>No Topics Match Search Criteria</u></b>';

Title: Re: Recent topics for SMF2
Post by: leftezi on July 29, 2012, 09:56:04 AM
I think you miss nothing.
It works perfect without errors in the log.  O0 O0
Thank you!  :)




A request from many members for more space and easier reading in mobile devices: If it is possible to have Replies/Views together in the same column like in the board index.




And in the future the option to have small avatars in the last post column maybe?
Title: Re: Recent topics for SMF2
Post by: leftezi on July 30, 2012, 04:17:24 PM
A question:

The string for the Topic title is

$txt['subject']

With is the string for the Board title?
I have a friend who have separated the board titles in another column but he don't know the string and the column has no title in the top.
Title: Re: Recent topics for SMF2
Post by: WillyP on July 30, 2012, 05:27:08 PM
Its easy to find any string just open the string file in your editor and do a search for the text displayed.
Title: Re: Recent topics for SMF2
Post by: leftezi on July 30, 2012, 09:56:49 PM
Witch file do you mean? If you mean the courent block code, there was no Boards column in the layout to find the title.
Title: Re: Recent topics for SMF2
Post by: WillyP on July 30, 2012, 10:40:12 PM
Eh... I think I misunderstood your question. Sorry.
Title: Re: Recent topics for SMF2
Post by: leftezi on July 30, 2012, 10:51:01 PM
I could make my own string but I am not sure from witch file the strings reading the source to put it in there. Are they in the modifications.php?

Edit: I found it. The strings are readed from the Modifications.greek-utf8.php file (in my language). I put my own string there and now i have a title in the Boards column.

EDIT again: This way a had errors. I found the original source file for the string. This is in index.greek-utf8.php and the string for the Board title is $txt['board']
So simple!!  :2funny:
Title: Re: Recent topics for SMF2
Post by: leftezi on July 31, 2012, 01:02:18 AM
Ok, there is a version without the first icons column and without the first poster column and with separate Board column, for anyone that would need it.
Note: I am not a developer. A friend of my have done this.


global $context, $settings, $scripturl, $txt, $db_prefix, $user_info, $modSettings, $user_profile, $smcFunc;

//////////////////////////////////////////// ---------- Unconditional Exclude
//   
   $exclude_boards = array();   // KEEP (to preserve variable declaration)
//   $exclude_boards = array(5);   //  Exclude single board
//     $exclude_boards = array(55,69);   //  Exclude multiple boards
   $ex_board_clause = !empty($exclude_boards) ? ' AND b.id_board NOT IN (' . implode(', ', $exclude_boards) . ')' : '';
//   
//   

//////////////////////////////////////////// ---------- Use in TP PHP Article (no title or frame from theme)
//   This will give most recent XX posted to topics -OR-
//   most recent XX unreplied to topics -OR-
//   topics posted to in last XX hours -OR-
//   most recent XX topics on topic notify list
//   
//   Sorts by most recent reply (descending; most recent first) -OR-
//            creation order (descending; most recent first)
//   
//   All in the detailed topic format
//   
//   
//   Default
//   index.php?page=##
//   most recent posted to topics - will list
//   number equal to  $settings['number_recent_posts']
//   
//   index.php?page=##;count=50 or index.php?page=##;type=last;count=50
//   50 most recently posted to topics
//   
//   index.php?page=##;type=unreplied or index.php?page=##;type=unreplied;count=50
//   Most recent unreplied to topics - will
//   list number specified in 'count' or default to
//   number equal to  $settings['number_recent_posts']
//   
//   index.php?page=##;type=hours or index.php?page=##;type=hours;count=12
//   Topics posted to in last number of hours
//   specified in 'count' or default to 24.
//   
//   index.php?page=##;type=notify or index.php?page=##;type=notify;count=50
//   Topics in topic notifcation list up to number
//   specified in 'count' or a maximum of 100 topics.
//   
//   *** Admins Only ***
//   index.php?page=##;type=notify;user=XXX or index.php?page=##;type=notify;user=XXX;count=50
//   Topics in topic notifcation list of specified user up to number
//   specified in 'count' or a maximum of 100 topics.
//   
//   index.php?page=##;type=started or index.php?page=##;type=started;count=50
//   Topics started by current user list up to number
//   specified in 'count' or a maximum of 100 topics.
//   
//   *** Admins Only ***
//   index.php?page=##;type=notify;user=XXX or index.php?page=##;type=started;user=XXX;count=50
//   Topics started by specified user up to number
//   specified in 'count' or a maximum of 100 topics.
//   
//   Add argument order=create to sort by topic creation sequence (most recent first)
//   rather than by last reply sequence

   $do_query = 1;

//////////////////////////////////////////// ---------- Poor Man's Global Announcements Block (center block - no Title/Frame)
//   Delete documentation comments above and marked section below
//
//   $announce_topics = array(254, 568, 675, 678); // Topic ID's to be 'Announced'
//
//   $heading = '<center>Announcements<center>';
//   $where_clause = 't.ID_TOPIC IN (' . implode(', ', $announce_topics) . ')';
//   $limit_clause = '';
//   $order_clause = 't.ID_LAST_MSG DESC';
////////////////////////////////////////////   

//////////////////////////////////////////// ---------- Last 5 Topics Started by User Block (center block - no Title/Frame)
//   Delete documentation comments above and marked section below
//
//   $heading = 'Most Recent Topics You Started';
//   $where_clause = 'ms.ID_MEMBER = '.$ID_MEMBER;
//   $limit_clause = 'LIMIT 5';
//   $order_clause = 't.ID_FIRST_MSG DESC';
////////////////////////////////////////////   

//////////////////////////////////////////// ---------- Boardindex Most Recent Topics Arguments
//
//   Comment out the Info Center's Most Recent Posts Code and Insert this
//   to show Most Recent Topics in full detail style instead
//
//   $list_count = $settings['number_recent_posts'];
//   $heading = 'Most Recently Posted To Topics';
//   $where_clause = 't.ID_LAST_MSG >= ' . ($modSettings['maxMsgID'] - 50 * min($list_count, 5));
//   $limit_clause = 'LIMIT ' . $list_count;
//   $order_clause = 't.ID_LAST_MSG DESC';
////////////////////////////////////////////   

////////////////////////////////////////////  ------ Remove down to next mark to use in block/boardindex ------
//
   if (empty($settings['number_recent_posts']))
      $number_recent_posts = 12;
   else
      $number_recent_posts = $settings['number_recent_posts'];

        if( isset($_GET['type']) )
      $list_type = $_GET['type'];
   else
      $list_type = 'last';

        if( isset($_GET['count']) )
      $list_count = $_GET['count'];
   else
   {
      $list_count = $number_recent_posts;
      if ($list_type == 'notify')
         $list_count = 100;
      elseif ($list_type == 'hours')
         $list_count = 24;
   }

   if ($list_count <= 0)
   {
      $list_count = $number_recent_posts;
      if ($list_type == 'hours')
         $list_count = 24;
   }

   if ($list_count > 100)
      $list_count = 100;

        if( isset($_GET['order']) )
      $list_order = $_GET['order'];
   else
      $list_order = 'lastpost';

        if( $list_order == 'create' )
      $order_clause = 't.id_first_msg DESC';
   else
      $order_clause = 't.id_last_msg DESC';

   if ($list_type == 'hours')
   {
      $list_from = strtotime($list_count.' hours ago');
      $where_clause = 'ml.poster_time >= ' . $list_from;
      $limit_clause = ' ';
      $heading = 'Topics Posted To In Last '. $list_count . ' Hours';
   }
   elseif ($list_type == 'unreplied')
   {
      $where_clause = 't.num_replies = 0';
      if ($list_count == 0)
      {
         $limit_clause = ' ';
         $heading = 'Unreplied To Topics';
      }
      else
      {
      $limit_clause = 'LIMIT ' . $list_count;
      $heading = $list_count . ' Most Recent Unreplied To Topics';
      }
   }
   elseif ($list_type == 'notify')
   {
      if (isset($_GET['user']) && $user_info['is_admin'])
      {
         $watched_topics = array();
         $request = $smcFunc['db_query']("", "SELECT id_topic FROM ".$db_prefix."log_notify
                                 WHERE id_member = {int:user_id}
                                 AND id_board = 0",
                                 array('user_id' => $_GET['user']));
         while ($row = $smcFunc['db_fetch_assoc']($request))
            $watched_topics[] = $row['id_topic'];
         $smcFunc['db_free_result']($request);
         $heading = $list_count . ' Most Recent Topics Being Watched by User # '.$_GET['user'];
         $where_clause = 't.id_topic IN (' . implode(', ', $watched_topics) . ')';
         $limit_clause = 'LIMIT ' . $list_count;
         if (empty($watched_topics))
            $do_query = 0;
      }
      else
      {
         $watched_topics = array();
         $request = $smcFunc['db_query']("", "SELECT id_topic FROM ".$db_prefix."log_notify
                                 WHERE id_member = {int:id_member}
                                 AND id_board = 0",
                                 array('id_member' => $user_info['id']));
         while ($row = $smcFunc['db_fetch_assoc']($request))
            $watched_topics[] = $row['id_topic'];
         $smcFunc['db_free_result']($request);
         $heading = $list_count . ' Most Recent Topics Being Watched';
         $where_clause = 't.id_topic IN (' . implode(', ', $watched_topics) . ')';
         $limit_clause = 'LIMIT ' . $list_count;
         if (empty($watched_topics))
            $do_query = 0;
      }
   }
   elseif ($list_type == 'started')
   {
      if (isset($_GET['user']) && $user_info['is_admin'])
      {
         $where_clause = 'ms.id_member = '.$_GET['user'];
         $limit_clause = 'LIMIT ' . $list_count;
              if( $list_order == 'create' )
         {
            $order_clause = 't.id_first_msg DESC';
            $heading = 'Most Recent Topics Started by User '.$_GET['user'];
         }
         else
         {
            $order_clause = 't.id_last_msg DESC';
            $heading = 'Most Recently Posted To Topics Started by User '.$_GET['user'];
         }
      }
      else
      {
         $where_clause = 'ms.id_member = '.$user_info['id'];
         $limit_clause = 'LIMIT ' . $list_count;
              if( $list_order == 'create' )
         {
            $order_clause = 't.id_first_msg DESC';
            $heading = 'Most Recent Topics You Started';
         }
         else
         {
            $order_clause = 't.id_last_msg DESC';
            $heading = 'Most Recently Posted To Topics You Started';
         }
      }
   }
   else
   {
      $where_clause = 't.id_last_msg >= ' . ($modSettings['maxMsgID'] - 90 * min($list_count, 5));
      $limit_clause = 'LIMIT ' . $list_count;
      $heading = $list_count . ' Most Recently Posted To Topics';
   }
//
////////////////////////////////////////////  ------ Remove up to first mark to use in block/boardindex ------

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

   $groupcolors = array();
   $request = $smcFunc['db_query']("", "SELECT id_group, online_color FROM ".$db_prefix."membergroups",array());
   while ($row = $smcFunc['db_fetch_assoc']($request))
      $groupcolors[$row['id_group']] = $row['online_color'];
   $smcFunc['db_free_result']($request);

   $topics = array();

   if ($do_query == 1)
   {
      $request = $smcFunc['db_query']("", "
      SELECT
            ms.subject AS firstSubject, ms.poster_time AS firstPosterTime, ms.id_topic, t.id_last_msg, t.id_board, b.name AS bname,
            t.num_replies, t.num_views, ms.id_member AS ID_FIRST_MEMBER, ml.id_member AS ID_LAST_MEMBER,
            ml.poster_time AS lastPosterTime, IFNULL(mems.real_name, ms.poster_name) AS firstPosterName,
            IFNULL(meml.real_name, ml.poster_name) AS lastPosterName,
            mems.id_group as mems_group, meml.id_group as meml_group,
            ml.subject AS lastSubject, b.member_groups,
            ml.icon AS lastIcon, ms.icon AS firstIcon, t.id_poll, t.is_sticky, t.locked, ml.modified_time AS lastModifiedTime,
            LEFT(ml.body, 384) AS lastBody, LEFT(ms.body, 384) AS firstBody,
            ml.smileys_enabled AS lastSmileys, ms.smileys_enabled AS firstSmileys, t.id_first_msg,"
            . ($user_info['is_guest'] ? '1 AS isRead, 0 AS new_from' : '
            IFNULL(lt.id_msg, IFNULL(lmr.id_msg, 0)) >= ml.id_msg_modified AS isRead,
            IFNULL(lt.id_msg, IFNULL(lmr.id_msg, -1)) + 1 AS new_from') . "
         FROM (".$db_prefix."messages AS ms, ".$db_prefix."messages AS ml, ".$db_prefix."topics AS t, ".$db_prefix."boards AS b)
            LEFT JOIN ".$db_prefix."members AS mems ON (mems.id_member = ms.id_member)
            LEFT JOIN ".$db_prefix."members AS meml ON (meml.id_member = ml.id_member)
            LEFT JOIN ".$db_prefix."log_topics AS lt ON (lt.id_topic = t.id_topic AND lt.id_member = ".$user_info['id'].")
            LEFT JOIN ".$db_prefix."log_mark_read AS lmr ON (lmr.id_board = t.id_board AND lmr.id_member = ".$user_info['id'].")
         WHERE " . $where_clause . $ex_board_clause . "
            AND t.id_topic = ms.id_topic
            AND b.id_board = t.id_board" . (!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0 ? " AND b.id_board != ".$modSettings['recycle_board'] : "") . "
            AND ms.id_msg = t.id_first_msg
            AND ml.id_msg = t.id_last_msg
            AND " . $user_info['query_see_board'] . "
         ORDER BY " . $order_clause . " " . $limit_clause,
       array());


   $topic_ids = array();
   while ($row = $smcFunc['db_fetch_assoc']($request))
   {
      if ($row['id_poll'] > 0 && $modSettings['pollMode'] == '0')
         continue;

      $topic_ids[] = $row['id_topic'];

      // Clip the strings first because censoring is slow :/. (for some reason?)
      $row['firstBody'] = strip_tags(strtr(parse_bbc($row['firstBody'], $row['firstSmileys'], $row['id_first_msg']), array('[br /]' => '
')));
      if (strlen($row['firstBody']) > 128)
         $row['firstBody'] = substr($row['firstBody'], 0, 128) . '...';
      $row['lastBody'] = strip_tags(strtr(parse_bbc($row['lastBody'], $row['lastSmileys'], $row['id_last_msg']), array('[br /]' => '
')));
      if (strlen($row['lastBody']) > 128)
         $row['lastBody'] = substr($row['lastBody'], 0, 128) . '...';

         $row['lastSubject'] = $row['firstSubject'];
         $row['lastBody'] = $row['firstBody'];

      // We need to check the topic icons exist... you can never be too sure!
      if (empty($modSettings['messageIconChecks_disable']))
      {
         // First icon first... as you'd expect.
         if (!isset($icon_sources[$row['firstIcon']]))
            $icon_sources[$row['firstIcon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['firstIcon'] . '.gif') ? 'images_url' : 'default_images_url';
         // Last icon... last... duh.
         if (!isset($icon_sources[$row['lastIcon']]))
            $icon_sources[$row['lastIcon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['lastIcon'] . '.gif') ? 'images_url' : 'default_images_url';
      }

      $color_start = !empty($groupcolors[$row['mems_group']]) ? $groupcolors[$row['mems_group']] : '';
      $color_last = !empty($groupcolors[$row['meml_group']]) ? $groupcolors[$row['meml_group']] : '';

      // And build the array.
      $topics[$row['id_topic']] = array(
         'id' => $row['id_topic'],
         'first_post' => array(
            'id' => $row['id_first_msg'],
            'member' => array(
               'name' => $row['firstPosterName'],
               'id' => $row['ID_FIRST_MEMBER'],
               'href' => $scripturl . '?action=profile;u=' . $row['ID_FIRST_MEMBER'],
               'link' => !empty($row['ID_FIRST_MEMBER']) ? '<a href="' . $scripturl . '?action=profile;u=' . $row['ID_FIRST_MEMBER'] . '" title="' . $txt['profile_of'] . ' ' . $row['firstPosterName'] . '">' . '<font color="' . $color_start . '">' . $row['firstPosterName'] . '</font>' . '[/url]' : $row['firstPosterName']
            ),
            'time' => timeformat($row['firstPosterTime']),
            'timestamp' => forum_time(true, $row['firstPosterTime']),
            'subject' => $row['firstSubject'],
            'preview' => $row['firstBody'],
            'icon' => $row['firstIcon'],
            'icon_url' => $settings[$icon_sources[$row['firstIcon']]] . '/post/' . $row['firstIcon'] . '.gif',
            'href' => $scripturl . '?topic=' . $row['id_topic'] . '.0;topicseen',
            'link' => '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0;topicseen">' . $row['firstSubject'] . '[/url]'
         ),
         'last_post' => array(
            'id' => $row['id_last_msg'],
            'member' => array(
               'name' => $row['lastPosterName'],
               'id' => $row['ID_LAST_MEMBER'],
               'href' => $scripturl . '?action=profile;u=' . $row['ID_LAST_MEMBER'],
               'link' => !empty($row['ID_LAST_MEMBER']) ? '<a href="' . $scripturl . '?action=profile;u=' . $row['ID_LAST_MEMBER'] . '">' . '<font color="' . $color_last . '">' . $row['lastPosterName'] . '</font>' . '[/url]' : $row['lastPosterName']
            ),
            'time' => timeformat($row['lastPosterTime']),
            'timestamp' => forum_time(true, $row['lastPosterTime']),
            'subject' => $row['lastSubject'],
            'preview' => $row['lastBody'],
            'icon' => $row['lastIcon'],
            'icon_url' => $settings[$icon_sources[$row['lastIcon']]] . '/post/' . $row['lastIcon'] . '.gif',
            'href' => $scripturl . '?topic=' . $row['id_topic'] . ($row['num_replies'] == 0 ? '.0' : '.msg' . $row['id_last_msg']) . ';topicseen#msg' . $row['id_last_msg'],
            'link' => '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . ($row['num_replies'] == 0 ? '.0' : '.msg' . $row['id_last_msg']) . ';topicseen#msg' . $row['id_last_msg'] . '">' . $row['lastSubject'] . '[/url]'
         ),
         'new' => $row['isRead'],
         'new_from' => $row['new_from'],
         'new_href' => $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['new_from'] . ';topicseen#new',
         'href' => $scripturl . '?topic=' . $row['id_topic'] . ($row['num_replies'] == 0 ? '.0' : '.msg' . $row['new_from']) . ';topicseen' . ($row['num_replies'] == 0 ? '' : 'new'),
         'link' => '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . ($row['num_replies'] == 0 ? '.0' : '.msg' . $row['new_from']) . ';topicseen#msg' . $row['new_from'] . '">' . $row['firstSubject'] . '[/url]',
         'is_sticky' => !empty($modSettings['enableStickyTopics']) && !empty($row['isSticky']),
         'is_locked' => !empty($row['locked']),
         'is_poll' => $modSettings['pollMode'] == '1' && $row['id_poll'] > 0,
         'is_hot' => $row['num_replies'] >= $modSettings['hotTopicPosts'],
         'is_very_hot' => $row['num_replies'] >= $modSettings['hotTopicVeryPosts'],
         'is_posted_in' => false,
         'icon' => $row['firstIcon'],
         'icon_url' => $settings[$icon_sources[$row['firstIcon']]] . '/post/' . $row['firstIcon'] . '.gif',
         'subject' => $row['firstSubject'],
         'replies' => $row['num_replies'],
         'views' => $row['num_views'],
         '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'] . '[/url]'
         )
      );

      determineTopicClass($topics[$row['id_topic']]);
   }
   $smcFunc['db_free_result']($request);

   if (!empty($modSettings['enableParticipation']) && !empty($topic_ids))
   {
      $result = $smcFunc['db_query']("", "
         SELECT id_topic
         FROM ".$db_prefix."messages
         WHERE id_topic IN (" . implode(', ', $topic_ids) . ")
            AND id_member = {int:id_member}",
         array('id_member' => $user_info['id']));
      while ($row = $smcFunc['db_fetch_assoc']($result))
      {
         if (empty($topics[$row['id_topic']]['is_posted_in']))
         {
            $topics[$row['id_topic']]['is_posted_in'] = true;
            $topics[$row['id_topic']]['class'] = 'my_' . $topics[$row['id_topic']]['class'];
         }
      }
      $smcFunc['db_free_result']($result);
   }

   }

if (!empty($topics))
    {
    echo '
        <div class="tborder" ', $context['browser']['needs_size_fix'] && !$context['browser']['is_ie6'] ? 'style="width: 100%;margin:0px;"' : 'style="margin:0px;"', '>
            <table border="0" width="100%" cellspacing="1" cellpadding="1" class="bordercolor">
                <tr>';


    echo '
                </tr>';

    echo '
            <tr class="titlebg">
               <td width="4%"> </td>
               <td>', $txt['subject'], '
            </td><td width="10%" align="center">', $txt['board'], '
               </td><td width="4%" align="center">', $txt['replies'], '
               </td><td width="4%" align="center">', $txt['views'], '
               </td><td width="18%">', $txt['last_post'], '
               </td>
            </tr>';

   foreach ($topics as $topic)
   {
      // Do we want to seperate the sticky and lock status out?
      if (!empty($settings['seperate_sticky_lock']) && strpos($topic['class'], 'sticky') !== false)
         $topic['class'] = substr($topic['class'], 0, strrpos($topic['class'], '_sticky'));
      if (!empty($settings['seperate_sticky_lock']) && strpos($topic['class'], 'locked') !== false)
         $topic['class'] = substr($topic['class'], 0, strrpos($topic['class'], '_locked'));

      echo '
            <tr>
               <td class="windowbg2" valign="middle" align="center" width="4%">
                  <img src="' . $topic['first_post']['icon_url'] . '" alt="" align="middle" />
               </td>
           

           
            <td class="windowbg' , $topic['is_sticky'] && !empty($settings['seperate_sticky_lock']) ? '3' : '' , '" width="48%" valign="middle">' , $topic['is_locked'] && !empty($settings['seperate_sticky_lock']) ? '
                  <img src="' . $settings['images_url'] . '/icons/quick_lock.gif" align="right" alt="" style="margin: 0;" />' : '' , $topic['is_sticky'] && !empty($settings['seperate_sticky_lock']) ? '
                  <img src="' . $settings['images_url'] . '/icons/show_sticky.gif" align="right" alt="" style="margin: 0;" />' : '', $topic['first_post']['link'];
               if ($topic['new'] == 0)
                  {
                  echo '<a href="', $topic['new_href'], '"> <img src="', $settings['images_url'], '/', $context['user']['language'], '/new.gif" alt="', $txt['seconds_with'], '" />[/url]';
                  }
                echo '

               <td class="windowbg2" width="18%" align="center">
            <span class="smalltext">', $topic['board']['link'], '</span></td>
               </td>

               <td class="windowbg" valign="middle" width="4%" align="center">
                  ', $topic['replies'], '</td>
               <td class="windowbg" valign="middle" width="4%" align="center">
                  ', $topic['views'], '</td>
               <td class="windowbg2" valign="middle" width="14%">
                  <a href="', $topic['last_post']['href'], '"><img src="', $settings['images_url'], '/icons/last_post.gif" alt="', $txt['last_post'], '" title="', $txt['last_post'], '" style="float: right;" />[/url]
                  <span class="smalltext">
                     ', $topic['last_post']['time'], '[br /]
                     ', $txt['by'], ' ', $topic['last_post']['member']['link'], '
                  </span>
               </td>
            </tr>';
   }

    echo '</table></div>';

    }
   else
       echo ''.$heading.'[br /][br /]No Topics Match Search Criteria';

Title: Re: Recent topics for SMF2
Post by: leftezi on July 31, 2012, 01:56:12 AM
If someone can help me to find in witch file the the query strings for the avatars from the original "Recent topics" are located, then maybe we can have a version with avatars too.  :)
Title: Re: Recent topics for SMF2
Post by: IchBin on July 31, 2012, 04:59:04 PM
TPsubs.template.php file is where all the block functions are.
Title: Re: Recent topics for SMF2
Post by: NeoX on November 11, 2012, 10:57:05 AM
Thank you great block code!
Only a question, How can I insert first post member Avatar instead first post Icon?

Thank you!  :)