MyBB Community Forums

Full Version: display recent posts
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I think it would be useful for new and low volume boards to monitor new posts through a feed instead of all that drilling.  So, I've created a recentpost.php from the syndication.php file.  Here are the changes with context below:

$ diff -c syndication.php recentposts.php
*** syndication.php	2015-07-20 13:56:41.946689932 +0000
--- recentposts.php	2015-07-20 15:17:29.076654114 +0000
***************
*** 174,180 ****
  
  if(!empty($firstposts))
  {
! 	$firstpostlist = "pid IN(".$db->escape_string(implode(',', $firstposts)).")";
  
  	if($mybb->settings['enableattachments'] == 1)
  	{
--- 174,180 ----
  
  if(!empty($firstposts))
  {
! 	$firstpostlist = '';
  
  	if($mybb->settings['enableattachments'] == 1)
  	{
***************
*** 190,196 ****
  		}
  	}
  
! 	$query = $db->simple_select("posts", "message, edittime, tid, fid, pid", $firstpostlist, array('order_by' => 'dateline', 'order_dir' => 'desc'));
  	while($post = $db->fetch_array($query))
  	{
  		$parser_options = array(
--- 190,196 ----
  		}
  	}
  
! 	$query = $db->simple_select("posts", "subject, message, edittime, tid, fid, pid, greatest(dateline, edittime) as lastsaved", $firstpostlist, array('order_by' => 'lastsaved', 'order_dir' => 'desc', 'limit' => $thread_limit));
  	while($post = $db->fetch_array($query))
  	{
  		$parser_options = array(
***************
*** 225,230 ****
--- 225,234 ----
  			}
  		}
  
+ 		$items[$post['tid']]['title'] = $parser->parse_badwords($post['subject']);
+ 		if( !$items[$post['tid']]['link'] ) {
+ 			$items[$post['tid']]['link'] = $channel['link'].get_post_link($post['pid'] . "#pid" . $post['pid'], $post['tid']);
+ 		}
  		$items[$post['tid']]['description'] = $parsed_message;
  		$items[$post['tid']]['updated'] = $post['edittime'];
  		$feedgenerator->add_item($items[$post['tid']]);

Hope that helps.

UPDATE: I thought the "Portal" button in the top menu of the default installation (left of search) would make recentposts.php redundant and unnecessary... unless you specifically want to set up a feed for rss readers. However, "Portal" doesn't give the latest posts, only the latest threads, so this remains useful... to me anyway.
Would be nice if you listed each change separately in [php] BBCode, many people here don't know how to apply diffs.
(2015-07-20, 07:38 PM)Destroy666 Wrote: [ -> ]Would be nice if you listed each change separately in [php] BBCode, many people here don't know how to apply diffs.

Looks like the thread was moved.  I thought only developers would be reading it. 

Not sure the most efficient way to post info here.  I'd upload the file, but doesn't look like the forum supports whole php files, and it's too much to paste.  Here's a diff without context, perhaps between the two it will be easier to follow.

$ diff syndication.php recentposts.php 
177c177
< 	$firstpostlist = "pid IN(".$db->escape_string(implode(',', $firstposts)).")";
---
> 	$firstpostlist = '';
193c193
< 	$query = $db->simple_select("posts", "message, edittime, tid, fid, pid", $firstpostlist, array('order_by' => 'dateline', 'order_dir' => 'desc'));
---
> 	$query = $db->simple_select("posts", "subject, message, edittime, tid, fid, pid, greatest(dateline, edittime) as lastsaved", $firstpostlist, array('order_by' => 'lastsaved', 'order_dir' => 'desc', 'limit' => $thread_limit));
227a228,231
> 		$items[$post['tid']]['title'] = $parser->parse_badwords($post['subject']);
> 		if( !$items[$post['tid']]['link'] ) {
> 			$items[$post['tid']]['link'] = $channel['link'].get_post_link($post['pid'] . "#pid" . $post['pid'], $post['tid']);
> 		}


What this says, is that
- at line 177, I cleared the assignment of $firstpostlist so it wouldn't limit the query.
- at line 193, I modified the query to include subject, and lastsaved which is the result of the mysql greatest() function, and sorted descending by the lastsaved value.
- at line 227, I inserted 4 lines.  The first sets the title, and the next three set the link to a pid anchored url if link is not already set.

Hope this helps.

Oh, found the attach button.  Didn't like the 6.8k php file, zipped to 2.4k file.
I thought the "Portal" button in the top menu of the default installation (left of search) would make recentposts.php redundant and unnecessary... unless you specifically want to set up a feed for rss readers. However, "Portal" doesn't give the latest posts, only the latest threads, so this remains useful... to me anyway.
is this more taxing for a heavy board? I would like polls and other contenttypes...

so this is for the portal?

How do you activate it?
(2015-09-18, 11:19 PM)expat Wrote: [ -> ]is this more taxing for a heavy board? I would like polls and other contenttypes...

so this is for the portal?

How do you activate it?

I don''t think it would be anymore taxing than the syndication.php

The portal.php gives a good overview of activity, but again, like syndication.php, it shows threads, not recent posts.  I'm watching my board for spam and new contributions, and recentposts.php helps me to do that in a way that watching threads does not.

There is no "activation" because it doesn't rely on any hooks.  I copied syndication.php to recentposts.php and made my changes.  If you get the whole recentposts.php file, you can just  put it  in the mybb webroot next to the syndication.php, and then point your browser to it.
so how do i add it to the portal, and have list of recent threads and posts?

is there no cutoff for number of words or characters?

and images are not parsed?
(2015-09-20, 11:18 PM)expat Wrote: [ -> ]so how do i add it to the portal, and have list of recent threads and posts?

is there no cutoff for number of words or characters?

and images are not parsed?

You don't "add" it to the portal.php page.  You reference it through directly the http://yoursite.com/recentposts.php url as an "alternative" to the http://yoursite.com/syndication.php feed.

If you want to modify what it displays, it is php source after all and you can make any changes you like.

Enjoy.