News:

SMF 2.0.19 has been released! Please update. Read more.

Main Menu

Recent posts user preference

Started by miseryshining, March 19, 2007, 05:37:32 PM

Previous topic - Next topic

miseryshining

Link to Mod

recent topics page example
http://www.yourforum.com/index.php?action=recenttopics;boards=2,4;limit=1
(will show a list of recent topics from boards 2 and 4, limited to the last day)

supported filters:
boards=all; (all boards, overrides user preference)
boards=2,4; (board filter, overrides user preference)
limit=3; (days)
warning: this can cause performance issues. Admins can define a maximum timeframe to search in.
start=20; (pagination)

sorting:
sort=starter (etc);
desc (sorting)

configuration
[forum users]
"edit profile -> Recent posts preferences"
  • setup which boards to monitor
  • choose between showing all recent posts or only the last one in a topic (this is only applied to recent post blocks and can be disabled by admins)
  • choose how many posts to display in a block (same as above)
[admins]
SMF2: "configuration -> modifications -> Recent posts/topics"
SMF1: "features and options -> Recent posts/topics"

  • enable extra user settings for users (only relevant for blocks)
  • Use recent topics mode instead on board index
  • Nr of posts to whow in blocks by default
  • Timeframe in which to search for recent posts/topics (in days)

instructions to setup a recent posts/topics block
The recent posts block that is already embedded in most of the themes (on the board index) is automatically enhanced to reflect the user preferences. You can enable it from the theme's settings page. 

More flexible example: insert the following code where you want to display the block


require_once('location/to/SSI.php');
if (function_exists('ssi_recentPostsPref')) ssi_recentPostsPref();


hacks
add a dropdown box on the recent topics page for selection of nr of days

Variables:
ssi_recentPostsPref( int $nrofPosts, string,array $boards, string $returnMode, int $mode, int $limit_days, int $member_id )

$nrofPosts:     
  • override user preference,
  • default: null
$boards:           
  • override board selection
  • possible values: board numbers seperated by commas, array for SMF 2
  • default: null
$returnMode:
  • how the list is returned
  • possible values:       
------  'echo' (print the result on the page)
------  'extended' (creates a detailed array with recent topics, ala vBulletin. puts it in $context['topics'])
------  [anything else] (return an array with post/topic info)
  • default: 'echo'
  • peculiarities:  applies only for recent topics, for recent posts, it will fallback to 'echo' mode
$mode:           
  • override posts/topics mode
  • possible values:
------  1 (show all posts)
------  2 (show topics)
  • default: 2                     
$limit_days
  • will search for all posts in the specified timeframe untill the (user) defined nr of posts are found
  • default: null
  • peculiarities: if it surpasses the timeframe defined in admin settings (under "features and options -> Recent posts/topics") it will not display posts out of that range)
$member_id   
  • show only posts by one member
  • default: null
blue only applies to SMF 1.x

NEMINI

is there something I need to do other then to call ssi_recentPostsPref() ?  Doing that I find the number of posts displayed does change depending what I have set in my profile, but no matter what I set for boards they all show (even if I unselect all boards).
signatures are boring.

miseryshining

#2
Quote from: NEMINI on March 19, 2007, 07:18:34 PM
is there something I need to do other then to call ssi_recentPostsPref() ?  Doing that I find the number of posts displayed does change depending what I have set in my profile, but no matter what I set for boards they all show (even if I unselect all boards).

No, it should work by just calling that function. I think it has to do with the the user array being cached for an X amount of time. It should refresh automatically. If you select no boards at all, it will display content from all boards by default.

Yio

Hi! miseryshining,

I installed your mod but it doesn't has any effect it self, without modifying some code lines.

You said that we must call the ssi_recentPostsPref() function. I wonder if I must call that function instead of getLastPosts(), by changing the folowing code line in Sources/BoardIndex.php:

$context['latest_posts'] = getLastPosts($settings['number_recent_posts']);


The mod may need to be edited so as to that lines be modified by the mod.

;)

Yio

I called the ssi_recentPostsPref() function instead of getLastPosts() and include the require_once('SSI.php');

The mod shows the RecentPosts but at the top of the index.

I guess that´s because of the ssi_recentPostsPref() function doesn't give the same format that getLastPosts() function.

miseryshining

The mod shows preformatted list of topics wherever you call ssi_recentPostsPref(). You can call it everywhere in your templates. It doesn't make much sense to both ssi_recentPostsPref() and getLatestPosts() at the same time.

My implementation uses the functions provided in SSI.php for added flexibility. When you want it to return an array of values, you should use this code:


global $context;
if ($context['user']['recentPosts']['lastOnly'] == 1)
$topicArray = ssi_recentTopics($context['user']['recentPosts']['nrofPosts'], null, 'array', $context['user']['recentPosts']['boards']);
else
$topicArray = ssi_recentPosts($context['user']['recentPosts']['nrofPosts'], null, 'array', $context['user']['recentPosts']['boards']);

Yio

Because I don´t want users take control of the last threads preferences, I just have pasted the ssi_recentTopics function at the Recent.php file and called it from Recent/BoardIndex.php, instead of using getLastPosts().

// this line was removed: $context['latest_posts'] = getLastPosts($settings['number_recent_posts']);
      $context['latest_posts'] = ssi_recentTopics();

I have removed the echo lines of the results and the line   if ($output_method != 'echo' || empty($posts)).
Just have leaved the return line.

I have modified the $num_recent limit to 30

function ssi_recentTopics($num_recent = 30, $exclude_boards = null, $output_method = 'echo', $include_boards = null)


I also removed the link from profile.

HOWEVER, I wish to thank you a lot for help me resolving a dilemma I had, by giving us your mod!

miseryshining

Quote from: Yio on April 05, 2007, 02:08:20 PM
HOWEVER, I wish to thank you a lot for help me resolving a dilemma I had, by giving us your mod!
Glad to help, but i still don't understand how this mod helped you?

Yio

Your mod was the better tool I found to accelerate the development of the feature I needed at my site, an easy way to face it, instead of wasting too much time into it because of I don´t have too much time to do it. Moreover, I´m not the Great Programmer!!
Thanks again!
;)

S1L1C0N

Is there any way to edit recent.php to show a list of THREAD TITLES only?

Yio

If you use the echo lines of the ssi_recentTopics function, take a look at this lines:

echo '
<table border="0" class="ssi_table">';
foreach ($posts as $post)
echo '
<tr>
<td align="right" valign="top" nowrap="nowrap">
[', $post['board']['link'], ']
</td>
<td valign="top">
<a href="', $post['href'], '">', $post['subject'], '</a>
', $txt[525], ' ', $post['poster']['link'], '
', $post['new'] ? '' : '<a href="' . $scripturl . '?topic=' . $post['topic'] . '.msg' . $post['new_from'] . ';topicseen#new"><img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/new.gif" alt="' . $txt[302] . '" border="0" /></a>', '
</td>
<td align="right" nowrap="nowrap">
', $post['time'], '
</td>
</tr>';
echo '
</table>';


and delete columns that you don´t want, like
<td align="right" valign="top" nowrap="nowrap">
[', $post['board']['link'], ']
</td>

if you don´t want to show board´s name

and

', $txt[525], ' ', $post['poster']['link'], '
', $post['new'] ? '' : '<a href="' . $scripturl . '?topic=' . $post['topic'] . '.msg' . $post['new_from'] . ';topicseen#new"><img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/new.gif" alt="' . $txt[302] . '" border="0" /></a>', '
</td>
<td align="right" nowrap="nowrap">
', $post['time'], '


so you will have only this:

echo '
<table border="0" class="ssi_table">';
foreach ($posts as $post)
echo '
<tr>

<td valign="top">
<a href="', $post['href'], '">', $post['subject'], '</a></td>
</tr>';
echo '
</table>';




If you use the function return you must edit the template that uses the array returned, at Themes/.../BoardIndex.template.php , below // Show lots of posts,
edit the lines:

<td class="middletext" valign="top" width=380><b>', $post['link'], '</td><td width=120 class="smalltext"></b> ', $txt[525], ' ', $post['poster']['link'], ' </td><td width=220 class="smalltext">(', $post['board']['link'], ')</td>
<td class="smalltext" align="right" nowrap="nowrap">', $post['time'], '</td>


so they look like this:

<td class="middletext" valign="top" width=380><b>', $post['link'], '</td>


Good luck!  ;)

S1L1C0N

Is there any way of achieving this by just editing Recent.php ?

miseryshining

Quote from: S1L1C0N on April 12, 2007, 11:52:54 AM
Is there any way of achieving this by just editing Recent.php ?

What exactly do you want to achieve? You could use a modified RecentPosts function (with modified query) to get the posts. There's no support for recent topics in Recent.php. 

S1L1C0N

I'd love a list that looks EXACTLY like action=unread  that instead shows recent TOPICS in X number of days.

that would = heaven for a million users here in this community if anyone could figure it out.

hvyhitter

man I am searching for the SAME thing.. not getting any response.. Sure the whole new posts since your last login is cool.. but i want to see that list with unread items too.
been searching these forums for now 3 days.. still nothing. although this SSI thing looks promising

miseryshining

You could get something similar by requesting the result as an array, then formatting it the way you want to. Create a new action+page, include the formatted array, and you're done.

An option to select the maximum nr of days that users want to go back could be useful, so I'm willing to implement that.

S1L1C0N

Quote from: miseryshining on April 23, 2007, 07:59:02 PM
You could get something similar by requesting the result as an array, then formatting it the way you want to. Create a new action+page, include the formatted array, and you're done.

An option to select the maximum nr of days that users want to go back could be useful, so I'm willing to implement that.




You DO know that if you really did this, youd be like GOD around here right? Its what everyone wants so bad and every other forum software has! Search and you will see... Oh IM GETTING EXCITED!

hvyhitter


miseryshining

Ha, you guys seem really desperate, i can't let you down. I'll do the following:

-add a user definable option for nr of days to go back (is that a requirement? we could also use pagination, just like the unread posts listing).
-make it only display topics that have replies you haven't seen yet (right?).
-maybe create a template page that looks like the unread posts listing.

S1L1C0N

#19
Quote from: miseryshining on April 24, 2007, 09:46:18 AM
-add a user definable option for nr of days to go back (is that a requirement? we could also use pagination, just like the unread posts listing).

Correct, I'd say if you did it its the cherry ontop, my suggestion, GO FOR IT!

Quote
-make it only display topics that have replies you haven't seen yet (right?).

IF it can be made optional via a checkbox or something it would truely be incredible, however the default way its handled is just recent, not really ones you havent seen yet, even if you've seen it, it would show up there.  USUALLY, the ones with new replies are bolded, the ones where your username is the last posted is NOT bolded.

Quote
-maybe create a template page that looks like the unread posts listing.

WINNER.

Advertisement: