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

Recent

Welcome to TinyPortal. Please login or sign up.

Members
  • Total Members: 3,973
  • Latest: NonStop
Stats
  • Total Posts: 196,236
  • Total Topics: 21,353
  • Online today: 739
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online
  • Users: 0
  • Guests: 536
  • Total: 536

Last X User posts & Topics - how?

Started by akulion, November 24, 2006, 11:38:23 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

akulion

hi,

I need to know how I could call up a users last X posts and also Last X topics

Basically its gona be like the 'Recent Topics' block only difference is this:

Last X Topics (started by user Z)

Last X threads participated in by user Z

What I am trying to do is create an extension for the user CP so that on the same page the user can see which last x topics they started and the last x threads they were active in.

Thanks

aku

JPDeni

You want this as a link in the User CP, yes? Sort of like the "Show own posts" link? That would require creating a secondary action (or two) in the Profile.php file.

Or... you could do blocks that would only appear when looking at the profile that would list those things automatically. That would mean that it could be done in a php block without having to change the Profile.php file.

akulion

the 2nd one is what im aiming for

Basically here is the idea....

The user CP thingie - with some smaller icons this time around...and instead of having the descriptions under them I will add a small script which shows a popup description on mouse over on the icons

Under that the user will be able to see some info relevant to them like

Last 5 Topics they started (listed the same way as in the Recent topics block)
Last 5 Threads/Posts they participated in

so that way the user CP kind looks a bit more personal and useful for the person

hopefully this could also be used in a centr block for sites which wana give the user their CP on the front page once they login - so its usability would kinda increase

JPDeni

That shouldn't be too hard. I should be able to give you something tomorrow.

akulion


Techdomain


JPDeni

I think this'll work for you.

The most recent posts for the user. Set the number you want to show in the $num_recent variable:


global $scripturl, $db_prefix, $ID_MEMBER;
global $user_info, $modSettings, $func;
       
$num_recent = 5;

if (!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0)
  $exclude_boards = array($modSettings['recycle_board']);
else
  $exclude_boards = array();

// Find all the posts.  Newer ones will have higher IDs.
$request = db_query("
           SELECT
                 m.posterTime, m.subject, m.ID_TOPIC, m.ID_MSG, m.ID_BOARD, b.name AS bName,
                 LEFT(m.body, 384) AS body, m.smileysEnabled
           FROM ({$db_prefix}messages AS m, {$db_prefix}boards AS b)
           WHERE m.ID_MSG >= " . ($modSettings['maxMsgID'] - 25 * min($num_recent, 5)) . "
                 AND b.ID_BOARD = m.ID_BOARD" . (empty($exclude_boards) ? '' : "
                 AND b.ID_BOARD NOT IN (" . implode(', ', $exclude_boards) . ")") . "
                 AND $user_info[query_see_board]
                 AND m.ID_MEMBER = $ID_MEMBER
          ORDER BY m.ID_MSG DESC
          LIMIT $num_recent", __FILE__, __LINE__);
$posts = array();
while ($row = mysql_fetch_assoc($request))
{
  $row['body'] = strip_tags(strtr(parse_bbc($row['body'], $row['smileysEnabled'], $row['ID_MSG']), array('<br />' => '')));
  if ($func['strlen']($row['body']) > 128)
    $row['body'] = $func['substr']($row['body'], 0, 128) . '...';

  // Censor it!
  censorText($row['subject']);
  censorText($row['body']);

  // Build the array.
  $posts[] = array(
                   'board' => array(
                                'link' => '<a href="' . $scripturl . '?board=' . $row['ID_BOARD'] . '.0">' . $row['bName'] . '</a>'
      ),
                   'subject' => $row['subject'],
                   'preview' => $row['body'],
                   'time' => timeformat($row['posterTime']),
                   'link' => '<a href="' . $scripturl . '?topic=' . $row['ID_TOPIC'] . '.msg' . $row['ID_MSG'] . '#msg' . $row['ID_MSG'] . '">' . $row['subject'] . '</a>',
             );
}
mysql_free_result($request);

foreach ($posts as $post)
  echo $post['link'], '<br />
       ', $post['time'], '<br />
       [', $post['board']['link'], ']<br /><br />
  ';


The most recent topics started by the user. Again, use the $num_recent variable to set how many you want to display:


global $settings, $scripturl, $db_prefix, $ID_MEMBER;
global $user_info, $modSettings, $func;

$num_recent= 5;

if (!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0)
  $exclude_boards = array($modSettings['recycle_board']);
else
  $exclude_boards = array();

$stable_icons = array('xx', 'thumbup', 'thumbdown', 'exclamation', 'question', 'lamp', 'smiley', 'angry', 'cheesy', 'grin', 'sad', 'wink', 'moved', 'recycled', 'wireless');
$icon_sources = array();
foreach ($stable_icons as $icon)
  $icon_sources[$icon] = 'images_url';

// Find all the posts in distinct topics.  Newer ones will have higher IDs.
$request = db_query("
           SELECT
                 m.posterTime, ms.subject, m.ID_TOPIC, m.ID_MSG, b.ID_BOARD, b.name AS bName,
                 LEFT(m.body, 384) AS body, m.smileysEnabled, m.icon
           FROM ({$db_prefix}messages AS m, {$db_prefix}topics AS t, {$db_prefix}boards AS b, {$db_prefix}messages AS ms)
           WHERE t.ID_LAST_MSG >= " . ($modSettings['maxMsgID'] - 35 * min($num_recent, 5)) . "
                 AND t.ID_LAST_MSG = m.ID_MSG
                 AND b.ID_BOARD = t.ID_BOARD" . (empty($exclude_boards) ? '' : "
                 AND b.ID_BOARD NOT IN (" . implode(', ', $exclude_boards) . ")") . "
                 AND $user_info[query_see_board]
                 AND m.subject NOT LIKE 'MOVED:%'
                 AND ms.ID_MSG = t.ID_FIRST_MSG
                 AND t.ID_MEMBER_STARTED = $ID_MEMBER
           ORDER BY t.ID_LAST_MSG DESC
           LIMIT $num_recent", __FILE__, __LINE__);
$posts = array();
while ($row = mysql_fetch_assoc($request))
{
  $row['body'] = strip_tags(strtr(parse_bbc($row['body'], $row['smileysEnabled'], $row['ID_MSG']), array('<br />' => '')));
  if ($func['strlen']($row['body']) > 128)
    $row['body'] = $func['substr']($row['body'], 0, 128) . '...';

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

  if (empty($modSettings['messageIconChecks_disable']) && !isset($icon_sources[$row['icon']]))
    $icon_sources[$row['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['icon'] . '.gif') ? 'images_url' : 'default_images_url';

// Build the array.
  $posts[] = array(
                   'board' => array(
                                'link' => '<a href="' . $scripturl . '?board=' . $row['ID_BOARD'] . '.0">' . $row['bName'] . '</a>'
      ),
                   'subject' => $row['subject'],
                   'preview' => $row['body'],
                   'time' => timeformat($row['posterTime']),
                   'link' => '<a href="' . $scripturl . '?topic=' . $row['ID_TOPIC'] . '.msg' . $row['ID_MSG'] . '#new">' . $row['subject'] . '</a>',
                   'icon' => '<img src="' . $settings[$icon_sources[$row['icon']]] . '/post/' . $row['icon'] . '.gif" align="middle" alt="' . $row['icon'] . '" border="0" />',
             );
}
mysql_free_result($request);

foreach ($posts as $post)
    echo $post['link'] , '<br />
         ', $post['time'] , '<br />
         [', $post['board']['link'], ']<br /><br />';


All I did with these was to take functions from SSI.php, add one line and delete a whole lot of stuff that wasn't needed, like whether the message has been read or not (presumably if the person wrote it, he read it :) ) and the name of the poster (we already know who the poster is).

The structure of the output on these is

post name with link
time the post was made
[board where the post was added]

You can set up any structure you want, but this makes it easy for a side block. If you want something different, let me know and I'll set it up for you.

knat

#7
Works very well.. thanks  ;)


Here is a screenshot of how it looks in my forum  ;)


Edit: Only thing is that it probably looks pretty weird if the user has zero topics and zero posts  :o


edit: link removed.

akulion

Thanks JP - ill give it a go tonight :up:

thanks so much :D

knat

#9
Is it possible to make the script echo out some sort of message if the user has 0 posts or 0 topics... so it dont show empty box.. maybe a text that will motivate the user to go to the forum and make his/hers first post ..

I know im always asking for to much but i just cant help myself  :laugh:

Edit: I think i found a bug in this script .. sorry  :-\ but if you log in as a normal user (i tested on two test accounts) it shows nothing in the blocks  :'( Aku can you test if the scripts act the same way on your forum please  ::)

Another Edit: Is there somekind of time limit on this thing.. i just posted with one of my test account, and that showed up in the last posts block... but the older posts dont .. hmm   ???

This website is proudly hosted on Crocweb Cloud Website Hosting.