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
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.
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
That shouldn't be too hard. I should be able to give you something tomorrow.
sure no problem and thanks :D
Thats a great idea Aku!
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.
Works very well.. thanks ;)
Here is a screenshot of how it looks in my forum ;)
(https://www.tinyportal.net/proxy.php?request=http%3A%2F%2Fwww.dumparump.com%2Fthumb%2F267%2Fdc8k93b.jpg&hash=1803cf7a9ea3336c1cbf1af6957dfffc578a1f9b)
Edit: Only thing is that it probably looks pretty weird if the user has zero topics and zero posts :o
edit: link removed.
Thanks JP - ill give it a go tonight :up:
thanks so much :D
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 ???
works wonderfully - thanks so much JP - ur the best! :D
Glad it's working for you. That wasn't a very hard one to do, fortunately. :)
I get:
You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'ORDER BY m.ID_MSG DESC
LIMIT 5' at line 10
File: /home/xxxxxxxxx/public_html/Sources/Load.php(1714) : eval()'d code(225) : eval()'d code
Line: 22
when I put it in a php article or custom actions
php block or article would do fine
Quote from: Aku on November 25, 2006, 10:53:34 PM
works wonderfully - thanks so much JP - ur the best! :D
So did you check it out with other accounts ? Look back a few post to see that i found a problem.. i want to know if its only me who has this problem :)
I put it into a block and that's what it was designed for. I don't know what difference it would make in an article or a custom action. I would suggest that you try it in a block first and see if it works the way it's supposed to before you try to make changes.
Ok - will do.
Is it possible to make this show all the posts from a single board. It tried to set $num_recent= 200; but is won`t show that many.
What i would like to do i show all of the members topics from board X. Not just the recent ones, but all from that board.
Possible? I tried somthing from another snippet, but could not make it work. ( http://www.tinyportal.net/smf/index.php?topic=596.msg89646#msg89646 )
Regards
The desperate one :)
To show posts from a specific board, you can try changing
AND b.ID_BOARD = m.ID_BOARD" . (empty($exclude_boards) ? '' : "
AND b.ID_BOARD NOT IN (" . implode(', ', $exclude_boards) . ")") . "
to
AND b.ID_BOARD = the-board-number-you-want-to-show
As for showing them all, you could try deleting
LIMIT $num_recent
so there's no limit at all. I don't know how many will actually display, though.