News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

RecentPosts - Count of posts shown if some boards excluded

Started by bryan_49ers, March 21, 2006, 01:34:57 AM

Previous topic - Next topic

bryan_49ers

<?php
include_once('SSI.php');

$mystuff = ssi_recentPosts(5,array(1,2,3,8,5,6,4,9));

{
  echo '<a href="', $post['href'], '">',$post['short_subject'],'</a> -', $post['time'], '<BR>';
}

?>

And the issue I have is that I only get 1 post listed... how can I get the most recent 5 posts even if they are say a year old?

bryan_49ers

[quote]<?php
include_once('SSI.php');
// Recent post list:   [board] Subject by Poster Date
function ssi_recentPosts($num_recent 40$exclude_boards = array(), $output_method 'echo')
{
global $context$settings$scripturl$txt$db_prefix$ID_MEMBER$user_info$modSettings;

// Find all the posts.  Newer ones will have higher IDs.
$request db_query("
SELECT
m.posterTime, m.subject, m.ID_TOPIC, m.ID_MEMBER, m.ID_MSG, m.ID_BOARD, b.name AS bName,
IFNULL(mem.realName, m.posterName) AS posterName, " 
. ($user_info['is_guest'] ? '1 AS isRead, 0 AS logTime' '
IFNULL(lt.logTime, IFNULL(lmr.logTime, 0)) >= GREATEST(m.posterTime, m.modifiedTime) AS isRead,
IFNULL(lt.logTime, IFNULL(lmr.logTime, 0)) AS logTime'
) . "
FROM (
{$db_prefix}messages AS m, {$db_prefix}boards AS b)
LEFT JOIN 
{$db_prefix}members AS mem ON (mem.ID_MEMBER = m.ID_MEMBER)" . (!$user_info['is_guest'] ? "
LEFT JOIN 
{$db_prefix}log_topics AS lt ON (lt.ID_TOPIC = m.ID_TOPIC AND lt.ID_MEMBER = $ID_MEMBER)
LEFT JOIN 
{$db_prefix}log_mark_read AS lmr ON (lmr.ID_BOARD = m.ID_BOARD AND lmr.ID_MEMBER = $ID_MEMBER)" '') . "
WHERE m.ID_MSG >= " 
. ($modSettings['maxMsgID'] - 50 $num_recent) . "
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]
ORDER BY m.ID_MSG DESC
LIMIT 
$num_recent"__FILE____LINE__);
$posts = array();
while ($row mysql_fetch_assoc($request))
{
// Censor the subject.
censorText($row['subject']);

// Build the array.
$posts[] = array(
'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>'
),
'topic' => $row['ID_TOPIC'],
'poster' => array(
'id' => $row['ID_MEMBER'],
'name' => $row['posterName'],
'href' => empty($row['ID_MEMBER']) ? '' $scripturl '?action=profile;u=' $row['ID_MEMBER'],
'link' => empty($row['ID_MEMBER']) ? $row['posterName'] : '<a href="' $scripturl '?action=profile;u=' $row['ID_MEMBER'] . '">' $row['posterName'] . '</a>'
),
'subject' => $row['subject'],
'short_subject' => strlen(un_htmlspecialchars($row['subject'])) > 50 htmlspecialchars(substr(un_htmlspecialchars($row['subject']), 045) . '...') : $row['subject'],
'time' => timeformat($row['posterTime']),
'timestamp' => $row['posterTime'],
'href' => $scripturl '?topic=' $row['ID_TOPIC'] . '.msg' $row['ID_MSG'] . ';topicseen#msg' $row['ID_MSG'],
'link' => '<a href="' $scripturl '?topic=' $row['ID_TOPIC'] . '.msg' $row['ID_MSG'] . '#msg' $row['ID_MSG'] . '">' $row['subject'] . '</a>',
'new' => !empty($row['isRead']),
'newtime' => $row['logTime']
);
}
mysql_free_result($request);

// Just return it.
if ($output_method != 'echo' || empty($posts))
return $posts;

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'] . '.from' $post['newtime'] . ';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>'
;
}
?>
[/quote]


Is there any way to change the above code so that it pulls the most recent posts even if they are months old?

Kindred

first of all, what does this have to do with the previous posts in this thread?
Second, why are you including SSI.php, if you are defining the function right there?
third, this function does list all the most recent (40) posts, without regard to time period... (if you only had 10 posts from this YEAR, the other 30 posts would go back however long it was, in order to list the most recent 40 posts)
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

bryan_49ers

Wow, I appreciate the support, but I don't really need the attitude with it.

1) the recentposts is what these two topics have in common
2) I am including ssi.php because otherwise it doesn't work
3) and no it does not go all the way back in time.  You can tell this because if you exclude all but one of my forums when you do the include into a page of the site you'll get 1 or 2 listings.

The only way around this is to call 500 or so your min instead of 5

So either 1) it doesn't not go on all the way back in time
or
2) it pools the 5 most recent topics and then does in the include which is the exact opposite order of how I want this to work.

Kindred

why does everyone assume that my posts have "attitude"?   I answered straight up...

This is not related to the original topic and as such, I have split the post out to its own topic.
(it is about a rather different implementation of ssi_recentPosts)

hmmm....   The order that the filters are applied might have some effect...
What you are saying is that it applies

Find # most recent posts
remove any that are part of and excluded board
display the remaining set

(although, if, in my joomla module, I choose to show the 10 most recent posts, and exclue 3 boards, I still get 10 posts, regardless of whether the excluded boards have newer posts...   so something is wrong with that suggestion as well)


Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

bryan_49ers

Evidentally that is what is happening.  It pools the latest posts and then applies the filter. 

My php isn't great, but I've experimented with some different loops to try and establish a counter so that I can pool more posts to choose from apply the filter, but rather than use foreach it would stop at count = 5 problem with this is it constantly reposts only the absolute latest post .. .that might be my PHP issues.

I don't know what a joomla module is, but can I adopt that to put on a regular .shtml page somehow?  It sounds like that's what I am looking for... unless of course by only excluding 3 boards you still have enough in the pool to reach 10.

sorry if you didn't mean to have an attitude.. .where I come from when you begin a statement with "first of all" its recognized as pompous.

Kindred

hmmm... nope... not pompous at all. First of all, indicates the first item in a numbered list. :)

You can take a look at the joomla module here

but, if I recall, it essentially calls the ssi function...

My suggestion in your case... re-write the ssi function (as a different name) to use
AND b.ID_BOARD = specific boards
rather than a where AND b.ID_BOARD = NOT (in exclude list)

although..   now that I look at it a little closer...  yuo are right...

      WHERE m.ID_MSG >= " . ($modSettings['maxMsgID'] - 50 * $num_recent) . "

this line is going to kill you every time...  it's looking in the most recent messages and then applying the exclude.


So, you could increase the pool here...
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

bryan_49ers

Interesting though, you might be on to something.  If I can call the 50 latest posts of a certain board than that would be ok...

Can you think of another way to apply the filter? or a way to terminate a foreach loop? (would you rather chat over msn?)

Kindred

I'll have to think on it and play around a bit... (can't use IM at work)

I'll try to post something tomorrow, if I can.
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

bryan_49ers

I would appreciate that.  Thank you for your help so far.

JayBachatero

Follow me on Twitter

"HELP!!! I've fallen and I can't get up"
This moment has been brought to you by LifeAlert

bryan_49ers

I've read through that, and if you notice the "5" indiates that I should have 5 posts returning, but I don't.

I think what's happening is that SMF goes to find the 5 latest posts, and then runs the exclude rather than the other way around.  Hence if only 1 of the 5 is not excluded only 1 gets posted.  Is there a way I can reverse this process?

JayBachatero

Well you have two conflicts there.  First you are using $mystuff but the other part is using $post.  Also you need to add foreach ($variables as $variable) after the $mystuff var.  $variable needs to be the same in all three places.  In this case you should use $posts.
Follow me on Twitter

"HELP!!! I've fallen and I can't get up"
This moment has been brought to you by LifeAlert

bryan_49ers

<?php
include_once('ssi_newfeed.php');
$posts ssi_recentTopics(5,array(1,2,3,4,5,6,8,9), $output_method 'array');

foreach (
$posts as $post)

{

echo 
$counter;
  echo 
'<a href="'$post['href'], '">',$post['short_subject'],'</a> -'$post['time'], '<BR>';

}
?>



But that doesn't change matters for me at all.  The sort still seems to be in the wrong order

JayBachatero

Follow me on Twitter

"HELP!!! I've fallen and I can't get up"
This moment has been brought to you by LifeAlert

bryan_49ers

so I don't have to alter ssi.php if I need to make changes to that file to get this to work

JayBachatero

Can you please provide a link to the page that yu have this in?
Follow me on Twitter

"HELP!!! I've fallen and I can't get up"
This moment has been brought to you by LifeAlert

kegobeer

"The truth of the matter is that you always know the right thing to do. The hard part is doing it." - Norman Schwarzkopf
Posting and you (Click "WATCH THIS MOVIE")

bryan_49ers

I'm running 1.06
my url is www.49ersparadise.com/0white.shtml

the script I am closest to get working is on the bottom right under "Front office / Coaching"

Thanks

kegobeer

Post a screenshot of your problem.  There are 13 topics shown when I visit the page.
"The truth of the matter is that you always know the right thing to do. The hard part is doing it." - Norman Schwarzkopf
Posting and you (Click "WATCH THIS MOVIE")

Advertisement: