Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Topic started by: bryan_49ers on March 21, 2006, 01:34:57 AM

Title: RecentPosts - Count of posts shown if some boards excluded
Post by: bryan_49ers on March 21, 2006, 01:34:57 AM
<?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?
Title: RecentPosts - Count of posts shown if some boards excluded
Post by: bryan_49ers on March 21, 2006, 12:03:28 PM
[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']), 0, 45) . '...') : $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?
Title: RecentPosts - Count of posts shown if some boards excluded
Post by: Kindred on March 21, 2006, 12:26:45 PM
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)
Title: RecentPosts - Count of posts shown if some boards excluded
Post by: bryan_49ers on March 21, 2006, 04:18:57 PM
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.
Title: Re: RecentPosts - Count of posts shown if some boards excluded
Post by: Kindred on March 21, 2006, 04:43:59 PM
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)


Title: Re: RecentPosts - Count of posts shown if some boards excluded
Post by: bryan_49ers on March 21, 2006, 05:02:55 PM
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.
Title: Re: RecentPosts - Count of posts shown if some boards excluded
Post by: Kindred on March 21, 2006, 05:13:19 PM
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 (http://www.simplemachines.org/community/index.php?topic=25718.msg470792#msg470792)

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...
Title: Re: RecentPosts - Count of posts shown if some boards excluded
Post by: bryan_49ers on March 21, 2006, 05:16:22 PM
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?)
Title: Re: RecentPosts - Count of posts shown if some boards excluded
Post by: Kindred on March 21, 2006, 05:26:42 PM
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.
Title: Re: RecentPosts - Count of posts shown if some boards excluded
Post by: bryan_49ers on March 21, 2006, 05:28:22 PM
I would appreciate that.  Thank you for your help so far.
Title: How can I display the latest posted to topics from the latest post list
Post by: JayBachatero on March 21, 2006, 06:49:45 PM
Advanced SSI FAQ (http://www.simplemachines.org/community/index.php?topic=13016.0)
Title: How can I display the latest posted to topics from the latest post list
Post by: bryan_49ers on March 21, 2006, 07:25:24 PM
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?
Title: How can I display the latest posted to topics from the latest post list
Post by: JayBachatero on March 21, 2006, 07:45:44 PM
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.
Title: How can I display the latest posted to topics from the latest post list
Post by: bryan_49ers on March 21, 2006, 08:07:03 PM
<?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
Title: How can I display the latest posted to topics from the latest post list
Post by: JayBachatero on March 21, 2006, 08:10:20 PM
Why are you using ssi_newfeed.php instead of SSI.php?
Title: How can I display the latest posted to topics from the latest post list
Post by: bryan_49ers on March 21, 2006, 08:28:57 PM
so I don't have to alter ssi.php if I need to make changes to that file to get this to work
Title: How can I display the latest posted to topics from the latest post list
Post by: JayBachatero on March 21, 2006, 08:32:48 PM
Can you please provide a link to the page that yu have this in?
Title: How can I display the latest posted to topics from the latest post list
Post by: kegobeer on March 21, 2006, 08:41:35 PM
What version of SMF are you using?
Title: How can I display the latest posted to topics from the latest post list
Post by: bryan_49ers on March 21, 2006, 08:53:03 PM
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
Title: How can I display the latest posted to topics from the latest post list
Post by: kegobeer on March 21, 2006, 08:55:10 PM
Post a screenshot of your problem.  There are 13 topics shown when I visit the page.
Title: How can I display the latest posted to topics from the latest post list
Post by: kegobeer on March 21, 2006, 08:58:16 PM
What are your settings for sessions and local storage of cookies (Admin -> Features and Options)?  Also, if you create a php script (not shtml), do you still have this issue?
Title: How can I display the latest posted to topics from the latest post list
Post by: JayBachatero on March 21, 2006, 09:01:48 PM
I see 5 recent topics.

Abraham a Falcon in 3-way deal- Today at 02:00:43 PM
Peterson is a Seahawk- March 20, 2006, 06:56:59 PM
Rashaun Woods Last Chance- March 20, 2006, 07:24:01 AM
Peter Boulware released- March 17, 2006, 04:51:11 AM
Aaron Shea and Jeb Putzier- March 16, 2006, 06:26:05 AM
Title: How can I display the latest posted to topics from the latest post list
Post by: bryan_49ers on March 21, 2006, 09:03:11 PM
I have three different scripts running there.. the one I'm talking about has a "1" next to it

it looks like
Front Office / Coaching

1YOU fill in the captio... -Today at 10:53:53 AM

http://49ersparadise.com/forum/feed2b.php has the same issue

cookie length is 60 mins
local storage is on (what happens if I turn it off?) what do I miss out on?
Title: How can I display the latest posted to topics from the latest post list
Post by: JayBachatero on March 21, 2006, 09:06:06 PM
Can you post EVERYTHING that you have in feed2b.php?
Title: How can I display the latest posted to topics from the latest post list
Post by: kegobeer on March 21, 2006, 09:08:46 PM
SSI doesn't work well if you use local storage of cookies.  Turn it off.
Title: How can I display the latest posted to topics from the latest post list
Post by: bryan_49ers on March 21, 2006, 09:16:14 PM
what do you mean by everything I have in feed2b.php?

what is the value of local stoarge of cookies ... what does it do.  Before I turn it off, I want to make sure that the benefit out weighs the cost.
Title: How can I display the latest posted to topics from the latest post list
Post by: JayBachatero on March 21, 2006, 09:17:57 PM
It stores the cookies in your PC instead of the database.  Storing it on the DB give you the ability to take with you the contents of the cookie from PC to PC.

I mean to copy and paste everything in that file. feed2b.php.
Title: How can I display the latest posted to topics from the latest post list
Post by: bryan_49ers on March 21, 2006, 09:20:41 PM
OK I turned it off

this is feed2b.php

<?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)

{

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

}
?>


this is the ssi file that is included in it

<?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'] - 5 * $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']), 0, 45) . '...') : $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>'
;
}
?>
Title: How can I display the latest posted to topics from the latest post list
Post by: kegobeer on March 21, 2006, 09:51:11 PM
Try this instead:


<?php

require ('SSI.php');

$posts = ssi_recentTopics(5, array(1,2,3,4,5,6,8,9), 'array');

foreach (
$posts as $post)
{
 
$counter = $counter+1;
 echo
$counter;
 echo
' <a href="', $post['href'], '">', $post['short_subject'], '</a> -', $post['time'], '<br>';
}
?>


I don't understand why you included SSI.php and then immediately redeclared function ssi_recentPosts.  Can you explain why you did that?
Title: How can I display the latest posted to topics from the latest post list
Post by: JayBachatero on March 21, 2006, 09:55:28 PM
also use Scounter = 1; before the foreach statement and remove $counter = $counter+1;.  Change echo $counter; to echo $counter++;
Title: How can I display the latest posted to topics from the latest post list
Post by: bryan_49ers on March 21, 2006, 09:59:44 PM
This is the current code

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

$counter = 1;

foreach (
$posts as $post)

{


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

}
?>


Now I don't have any being output
Title: How can I display the latest posted to topics from the latest post list
Post by: JayBachatero on March 21, 2006, 10:04:03 PM
You still including ssi_newfeed.php.  Include SSI.php and use the full path.
$counter = 1; should be $counter = 0;
Title: How can I display the latest posted to topics from the latest post list
Post by: bryan_49ers on March 21, 2006, 10:15:18 PM
same result...
ssi.php is in the same folder, I shouldn't need to post the full directory name with it

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

$counter = 0;

foreach (
$posts as $post)

{


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

}
?>
Title: How can I display the latest posted to topics from the latest post list
Post by: kegobeer on March 21, 2006, 10:44:03 PM
What didn't you understand about my post?  Do as I instructed.


<?php

require ('SSI.php');

$posts = ssi_recentTopics(5, array(1,2,3,4,5,6,8,9), 'array');

foreach (
$posts as $post)
{
 
$counter = $counter+1;
 echo
$counter;
 echo
' <a href="', $post['href'], '">', $post['short_subject'], '</a> -', $post['time'], '<br>';
}
?>
Title: How can I display the latest posted to topics from the latest post list
Post by: bryan_49ers on March 22, 2006, 11:47:22 AM
same result with that code

The probelm is clearly in relation to the order the filter is applied. How can I either change this order, or break out of the foreach cycle after 5 turns
Title: How can I display the latest posted to topics from the latest post list
Post by: kegobeer on March 22, 2006, 12:06:07 PM
Send me a link to your forum, with an admin username and password.  Also send me the link to the code I posted.
Title: Re: RecentPosts - Count of posts shown if some boards excluded
Post by: bryan_49ers on March 22, 2006, 12:19:51 PM
Kindred, did you come up with anything yesterday by any chance?
Title: How can I display the latest posted to topics from the latest post list
Post by: bryan_49ers on March 22, 2006, 12:20:49 PM
What for? This is a coding issue.
Title: Re: RecentPosts - Count of posts shown if some boards excluded
Post by: Kindred on March 22, 2006, 12:52:47 PM
Bryan,

Sorry... things got busy at work and I have not had a chance to do anything with this yet...
Title: Re: RecentPosts - Count of posts shown if some boards excluded
Post by: bryan_49ers on March 22, 2006, 12:58:48 PM
ok.. I'll be around for most of the day if you do get a chance...
Title: How can I display the latest posted to topics from the latest post list
Post by: kegobeer on March 22, 2006, 03:00:04 PM
Because this code works perfectly on my forum, so I want to see how you have things organized.
Title: How can I display the latest posted to topics from the latest post list
Post by: bryan_49ers on March 22, 2006, 03:10:23 PM
How I have things organized?  You don't need an admin pass for that
here's my url www.49ersparadise.com/forum

You probably think the code is working perfectly on your forum ... but try excluding all but your least popular category from the code and see what happens...
Title: How can I display the latest posted to topics from the latest post list
Post by: kegobeer on March 22, 2006, 03:24:06 PM
You mean exclude the least popular board.  I did, it works fine.
Title: How can I display the latest posted to topics from the latest post list
Post by: kegobeer on March 22, 2006, 03:27:28 PM
If you don't want to provide an admin account (or FTP access so I can look at your code) I can't help.
Title: How can I display the latest posted to topics from the latest post list
Post by: bryan_49ers on March 22, 2006, 03:30:00 PM
I've already provided you the code that is involved with the issue.  It is exactly as I've provided it.  I'm sorry, but I do not feel comfortable giving out Admin status .. if you try what I've said on the exclusions on your board I'm sure you'll notice the exact same thing.  The filter is provided after the top 5 recents have been pulled, it should be applied before.
Title: How can I display the latest posted to topics from the latest post list
Post by: bryan_49ers on March 22, 2006, 03:55:28 PM
Kego - and no I mean exclude all but your least popular board.  In other words try and get the 5 most recent topics from your least popular board.  It won't work.
Title: How can I display the latest posted to topics from the latest post list
Post by: kegobeer on March 22, 2006, 04:56:57 PM
I did.  It works.
Title: How can I display the latest posted to topics from the latest post list
Post by: bryan_49ers on March 22, 2006, 05:05:37 PM
can I see it in action?
Title: How can I display the latest posted to topics from the latest post list
Post by: JayBachatero on March 22, 2006, 05:07:26 PM
I found an interesting issue.  What are you trying to pull posts or topics?  On your custom file you are looking for posts BUT in the actually call you are calling for topics.  That's why we told you to use SSI.php.  It seems like you are still using the call to the custom file.
Title: How can I display the latest posted to topics from the latest post list
Post by: bryan_49ers on March 22, 2006, 05:16:02 PM
I am trying to pull the title of the topics which have the most recent post, I want this sorted by the date of the most recent post.  I want to do this on a per board basis.  SSI.php does not allow for this.
Title: How can I display the latest posted to topics from the latest post list
Post by: JayBachatero on March 22, 2006, 05:20:13 PM
Well you are calling the wrong function buddy.  SSi pulls the latest one by date so I'm not sure what exactly you are trying to do.  At this point it's not a problem with SMF it's a problem with the custom code that you are using.
Title: How can I display the latest posted to topics from the latest post list
Post by: Kindred on March 22, 2006, 05:24:24 PM
ok, bryan...
(I have not had a chance to try the alternative code I was thinking about, but it would have the same problemn, in this case)
this may explain the problems you've been having.
you're using the function incorrectly.

ssi_RecentPosts gets the latest posts. period... nothing to do with topics.
ssi_RecentTopics gets the latest topics. period... nothing to do with posts.

What you appear to be trying to do (and correct me if I am wrong) is:

1) Find the most recent posts in X boards.
2) display the a link to the TOPIC of any topics that contain posts listed in step 1

This is not what either of the above ssi functions are intended to do, and to do this, you (or someone) would have to write a fairly involved set of queries...
Title: How can I display the latest posted to topics from the latest post list
Post by: kegobeer on March 22, 2006, 05:24:51 PM
This has nothing to do with the topic ("Can I exclude a board or category from recentTopics").

::)
Title: How can I display the latest posted to topics from the latest post list
Post by: bryan_49ers on March 22, 2006, 05:26:09 PM
I don't think you are understanding what I want to do.

SMF has an SSI function called recent posts.

If I use the recent post function I can get the x amount of recent posts from all of my different boards.  This function correctly posts the subject of the topic in which the most recent post was made, and lists the date of the most recent post.  It does this for EVERY board of my forum.

What I would like to do is the exact same thing but for a SPECIFIC board of my forum.  So I tried to EXCLUDE all the boards but the one I wanted to do this for.  I was left with no results.  The reason is that first the script looks for the 5 most recent posts, then it applies a filter to exclude any of those posts which have been excluded by the board.  If the board you are trying to post the recent posts for does not have a recent post in the top 5 recent posts on the board then nothing gets posted.  The exclude filter is applied too late, it should be applied before the script looks for the recent posts.  All I want to do is know how to change this order.

AND this has EVERYTHIng to dow ith this topic
Title: Re: How can I display the latest posted to topics from the latest post list
Post by: Kindred on March 22, 2006, 05:28:30 PM
I have split this off from the original topic...

Bryan, you posted an identical question to a completely different thread.
This is the second time I have had to split a thread of your off...
Please start your own threads rather than hijacking other people's threads (especially ones that have alreayd been resolved)
Title: Re: RecentPosts - Count of posts shown if some boards excluded
Post by: bryan_49ers on March 22, 2006, 05:39:15 PM
sorry kindred..

I see what you are saying, but no.. the link I want posted is to the post not to the topic.  I want the topic name to be what is in the link, but that happens automaticaly because the subject of each post is automatically the subject of the whole topic unless someone changes it ... which they don't on my board.

so I want to use the recent post function to get all the 5 latests posts from ONE specific baord.

So
1) find board 1
2) find the 5 most recent posts in board 1
2b) ideally if two of these posts are from the same topic only take the most recent one
3) post the most recent post from board 1
Title: Re: RecentPosts - Count of posts shown if some boards excluded
Post by: Kindred on March 22, 2006, 05:43:45 PM
So, try this...


<?php
include_once('SSI.php');
// Recent post list:   [board] Subject by Poster Date
function show_recentPosts($num_recent = 40, $include_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($include_boards) ? '' : "
AND b.ID_BOARD IN ("
. implode(', ', $include_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']), 0, 45) . '...') : $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>'
;
}
?>
Title: Re: RecentPosts - Count of posts shown if some boards excluded
Post by: bryan_49ers on March 22, 2006, 05:51:01 PM
I replaced my ssi_newfeed.php with that and added the <?php at the top and got no results

It's working exactly the same way as the other one which I find very odd, because it should now be including all the boards that were being excluded right?
Title: Re: RecentPosts - Count of posts shown if some boards excluded
Post by: bryan_49ers on March 22, 2006, 05:59:43 PM
is there a way to not use the foreach for this ?  or to break out of foreach?  Because if I simply increase the pool size of the latests posts I can get the desired result


Another way of thinking about it, is I want to post a very condensed version of what appears in each board.  So if I click on board 1, the 5 first topics that I see are what I want to "port" onto the main page.  Is that easier to understand?  Easier to do?
Title: Re: RecentPosts - Count of posts shown if some boards excluded
Post by: bryan_49ers on March 23, 2006, 06:41:43 PM
It might be an ugly solution but I got it to work... if anyone needs this let me know