SimplePortal

Customization => Custom Coding => Topic started by: Adjacent on October 12, 2011, 10:14:40 PM

Title: sp_recent displaying topic author instead of last poster?
Post by: Adjacent on October 12, 2011, 10:14:40 PM
Hi, I opened up PortalBlocks.php in Sources and tried modifying it. Currently the Recent Topics block shows:

The topic name
[Board Name]
By Last poster on date/time

I want it to show:

The topic name
[Board Name]
By Topic Author on date/time


I was told by the great AngelinaBelle on SMF support that this function uses 'ssi_recent' . $type in SSI.php.

So basically my question is how can I edit the sql query to return author of the topic in ssi_recentTopics rather than the latest poster?  :)

Thanks,
Jason
Title: Re: sp_recent displaying topic author instead of last poster?
Post by: AngelinaBelle on October 13, 2011, 10:47:31 AM
I'm going to ask you another silly question now.
1) You want to show a link to the most recent post on the topic but
2) You want to show the author's name of the first post on the topic?
Title: Re: sp_recent displaying topic author instead of last poster?
Post by: ccbtimewiz on October 13, 2011, 12:47:21 PM
Haven't tested this, but it might work the way you want it to.

Open ./Sources/PortalBlocks.php

Find:
Code: [Select]
else
$items[count($items) - 1]['is_last'] = true;

Replace with:
Code: [Select]
else
$items[count($items) - 1]['is_last'] = true;

foreach ($items as $k => $v)
if (!isset($items[$k]['first_poster']))
$items[$k]['first_poster'] = isset($v['poster'][0]) ? $v['poster'][0] : '';

And then you can use the key 'first_poster' $item['poster'] array.
Title: Re: sp_recent displaying topic author instead of last poster?
Post by: AngelinaBelle on October 13, 2011, 02:18:25 PM
Chris, I'm confused.

Where does ['poster'][0] come from?
in ssi_recentTopics, we have for each $posts[] (which is passed to the block as $items[$k])
Code: [Select]
'poster' => array(
'id' => $row['id_member'],
'name' => $row['poster_name'],
'href' => empty($row['id_member']) ? '' : $scripturl . '?action=profile;u=' . $row['id_member'],
'link' => empty($row['id_member']) ? $row['poster_name'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['poster_name'] . '</a>'
),
I cannot figure out where this ['poster'][0] element would come from, or how it would get loaded with the name or user id of the first poster of the topic.
Where would this information come from?

I would think this would require changes to SSI.php, to add another join to the SQL query.
Title: Re: sp_recent displaying topic author instead of last poster?
Post by: ccbtimewiz on October 13, 2011, 06:46:08 PM
Weird, I thought every poster was loaded in that array as opposed to each individual post themselves being loaded with topic info.

A join isn't needed, as you only need to pop off the first element of the array that designates it as the topic.
Title: Re: sp_recent displaying topic author instead of last poster?
Post by: Adjacent on October 15, 2011, 10:49:50 PM
Haven't tested this, but it might work the way you want it to.

Open ./Sources/PortalBlocks.php

Find:
Code: [Select]
else
$items[count($items) - 1]['is_last'] = true;

Replace with:
Code: [Select]
else
$items[count($items) - 1]['is_last'] = true;

foreach ($items as $k => $v)
if (!isset($items[$k]['first_poster']))
$items[$k]['first_poster'] = isset($v['poster'][0]) ? $v['poster'][0] : '';

And then you can use the key 'first_poster' $item['poster'] array.

I found two instances of the code you said to replace, so I replaced them both.

Still, it displays the last poster instead of topic author.

Did I do something wrong? Am I suppose to modify this part?

Code: [Select]
echo '
<tr>
<td class="sp_recent_icon sp_center">
', sp_embed_image(empty($parameters['type']) ? 'post' : 'topic'), '
</td>
<td class="sp_recent_subject">
<a href="', $item['href'], '">', $item['subject'], '</a>
', $item['new'] ? '' : '<a href="' . $scripturl . '?topic=' . $item['topic'] . '.msg' . $item['new_from'] . ';topicseen#new"><img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/new.gif" alt="' . $txt['new'] . '" border="0" /></a>', '<br />[', $item['board']['link'], ']', '<br />by&nbsp;', $item['poster']['link'], ',&nbsp;', $item['time'], '
</td>
</tr>';
Title: Re: sp_recent displaying topic author instead of last poster?
Post by: Adjacent on October 19, 2011, 05:04:55 PM
Bumper cars.
Title: Re: sp_recent displaying topic author instead of last poster?
Post by: AngelinaBelle on October 20, 2011, 10:29:33 AM
I am not so sure this approach is going to work, as the query brings back the poster of the CURRENT post, but not the poster of the FIRST post in the topic.
Title: Re: sp_recent displaying topic author instead of last poster?
Post by: Adjacent on October 21, 2011, 07:24:47 PM
So is it even in any known way, possible?
Title: Re: sp_recent displaying topic author instead of last poster?
Post by: AngelinaBelle on October 24, 2011, 01:32:46 AM
Yes.  You would need to write a new function to call instead of ssi_recentTopics.

Let me ask again, though
1) You want to show a post
2) But you don't want to show the post's author
3) Instead, you want to show the author of the first post in the topic, along with the contents of the current post, but not the author of the current post.

This just seems very confusing and misleading to me, which is why I keep asking.
Title: Re: sp_recent displaying topic author instead of last poster?
Post by: Adjacent on October 26, 2011, 02:57:09 PM
I want the "Recent Topics" to show a list a list of recent topics, but instead of linking to the latest post in each topic by the last poster, I want it to link to the topic start. By the topic's author.

Example: http://www.thisisbigbrother.com/forums/ (See the "Latest Threads" box on right? Like this..)
Title: Re: sp_recent displaying topic author instead of last poster?
Post by: AngelinaBelle on October 27, 2011, 02:42:15 PM
OK.  Thanks for that explanation.  That makes more sense to me.

The Recent Topics block doesn't do what you want?
Title: Re: sp_recent displaying topic author instead of last poster?
Post by: Adjacent on October 27, 2011, 03:18:55 PM
OK.  Thanks for that explanation.  That makes more sense to me.

The Recent Topics block doesn't do what you want?

Eh.. no. That's kind of why I'm here... lol. It displays the last post of each topic, made by the last poster.

I just want recent topics to display the a link to the first post/topic start like vBulletin and other forums do. Is it possible?
Title: Re: sp_recent displaying topic author instead of last poster?
Post by: AngelinaBelle on October 28, 2011, 10:25:15 AM
I'm sorry I keep asking these basic questions. I can tell you want to do something different. I just wanted to make sure I understand what you want.

Here's what I think:
1) ssi_recentTopics already has the correct joins in it to pull back the information about the first topic. Veridis Quo, you were correct about that.
All it needs is to pull back the correct fields and stuff them in the return array in some logical way. That's easy.
2) And then the block can use that information stuffed in the return array.  That's easy, too.

Are you ready? here are some untested suggestions. Use at your own risk.
Keep backup copies of the files before you start in on them.
Code: (find in SSI.php) [Select]
// Find all the posts in distinct topics. Newer ones will have higher IDs.
$request = $smcFunc['db_query']('substring', '
SELECT
m.poster_time, ms.subject, m.id_topic, m.id_member, m.id_msg, b.id_board, b.name AS board_name, t.num_replies, t.num_views,
Code: (replace) [Select]
// Find all the posts in distinct topics. Newer ones will have higher IDs.
$request = $smcFunc['db_query']('substring', '
SELECT
m.poster_time, ms.subject, m.id_topic, m.id_member, m.id_msg, b.id_board, b.name AS board_name, t.num_replies, t.num_views,
ms.poster_name AS first_poster_name, ms.id_member AS first_id_member, ms.id_msg AS first_id_msg,

Code: (find in SSI.php, just below the above -- the second time you find this string in the file) [Select]
'topic' => $row['id_topic'],
Code: (replace) [Select]
'topic' => $row['id_topic'],
   'first' => array(
      'href' => $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['first_id_msg'] . ';topicseen#new',
      'poster' => array(
         'name' => $row['first_poster_name'],
         'link' => empty($row['first_poster_id']) ? $row['first_poster_name'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['first_poster_id'] . '">' .
'first_msg_id' => $row['first_msg_id'],
      )
   ),
Check for any syntax errors in those lines, please. When you are sure this is working OK, move on to PortalBlocks.php.



Here is a suggestion for something you can try. I haven't changed the part where the stuff gets written out.
Instead, I just replaced the information about the last-message with the information about the first-message in the topic.
I left the "new" link (which will take a logged-in user to the last place they left off in the thread) alone.
This code is also completely off the top of my head and untested.

Code: (find in PortalBlocks.php) [Select]
else
$items[count($items) - 1]['is_last'] = true;
Code: (replace) [Select]
else
$items[count($items) - 1]['is_last'] = true;
if ( $parameters['type'] = 'Topics' )
   foreach ($items as $key $item) {
      $items[$key]['poster']['link'] = $item['first']['poster']['link'];
      $items[$key]['href'] = $item['first']['href'];
   }
Title: Re: sp_recent displaying topic author instead of last poster?
Post by: Adjacent on October 28, 2011, 03:03:30 PM
Thank you for efforts and time AngelinaBelle. I do believe this code could work.

Code: [Select]
Parse error: syntax error, unexpected T_DOUBLE_ARROW, expecting ')' in /web/users/xxxxx/SSI.php on line 382
For starters, I receive the error above.

Lines 380-383:

Code: [Select]
'name' => $row['first_poster_name'],
'link' => empty($row['first_poster_id']) ? $row['first_poster_name'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['first_poster_id'] . '">' .
'first_msg_id' => $row['first_msg_id'],
      )
Title: Re: sp_recent displaying topic author instead of last poster?
Post by: AngelinaBelle on October 31, 2011, 12:40:45 PM
Hmmm -- well, looks like I put a "." at the end of the array element in line 381 instead of a ",", and the parser reasonably assumed I simply wanted to append the string 'first_msg_id' to the string I was building in line 381. Then it couldn't make any sense at all of the '=>' in line 382.
 
This should work better (though I am not guaranteeing it)
Code: [Select]
            'name' => $row['first_poster_name'],
            'link' => empty($row['first_poster_id']) ? $row['first_poster_name'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['first_poster_id'] . '">' ,
            'first_msg_id' => $row['first_msg_id'],
      )
Title: Re: sp_recent displaying topic author instead of last poster?
Post by: Adjacent on October 31, 2011, 03:37:00 PM
----
Edited by AngelinaBelle
I'm sorry.  I accidentally modified your message instead of quoting it.
Title: Re: sp_recent displaying topic author instead of last poster?
Post by: AngelinaBelle on November 02, 2011, 02:47:56 PM
I looked up foreach in the php manual to correct my typo:
http://www.google.com/search?q=foreach+php.net (http://www.google.com/search?q=foreach+php.net)
http://php.net/manual/en/control-structures.foreach.php (http://php.net/manual/en/control-structures.foreach.php)
Code: [Select]

   foreach ($items as $key => $item) {

Do you like this kind of project? I recommend that you start with a php tutorial (like the one at w3schools.com) and become comfortable with the manual at php.net. These are great resources, and will help you understand the SMF code.
Of course, since SMF uses php to emit XHTML, you'll want to learn about HTML as well.
And CSS. And SQL.  It'll be fun.  I promise.
Title: Re: sp_recent displaying topic author instead of last poster?
Post by: Adjacent on November 03, 2011, 01:51:02 AM
I looked up foreach in the php manual to correct my typo:
http://www.google.com/search?q=foreach+php.net (http://www.google.com/search?q=foreach+php.net)
http://php.net/manual/en/control-structures.foreach.php (http://php.net/manual/en/control-structures.foreach.php)
Code: [Select]

   foreach ($items as $key => $item) {

Do you like this kind of project? I recommend that you start with a php tutorial (like the one at w3schools.com) and become comfortable with the manual at php.net. These are great resources, and will help you understand the SMF code.
Of course, since SMF uses php to emit XHTML, you'll want to learn about HTML as well.
And CSS. And SQL.  It'll be fun.  I promise.


Thanks, that fixed the error (yes, I would be able to fix it myself if I were more experienced). And I know you're probably tired of dealing with this issue I have but I feel we're nearly there so please bare with me.

There are no more errors except for this one in one of my recent topics boxes called "Entertainment Forum":
Code: [Select]
Unknown column 'ms.subject' in 'field list'
File: /web/users/xxxxxx/SSI.php
Line: 305
Code: (Line 305, although I don't see why this is a problem...) [Select]
return ssi_queryPosts($query_where, $query_where_params, $num_recent, 'm.id_msg DESC', $output_method, $limit_body);
Also, the box that works still shows the name of the last poster.  :( When you click on the topic name, it is null. Any thoughts?

Thank you for your time and patience with my ignorance,
Jason
Title: Re: sp_recent displaying topic author instead of last poster?
Post by: AngelinaBelle on November 03, 2011, 11:57:55 AM
Yes, when you do a little reading and coding on your own, you will very quickly learn to track down syntax errors.

The changes you just made in SSI.php -- did you make them in
function ssi_queryPosts, or in ssi_recentTopics?

All the SSI.php changes should be in function ssi_recentTopics

Title: Re: sp_recent displaying topic author instead of last poster?
Post by: Adjacent on November 06, 2011, 12:44:52 AM
Yes, when you do a little reading and coding on your own, you will very quickly learn to track down syntax errors.

The changes you just made in SSI.php -- did you make them in
function ssi_queryPosts, or in ssi_recentTopics?

All the SSI.php changes should be in function ssi_recentTopics

Sorry. my mistake. Heh, made the changes in ssi_queryPosts. I corrected it now and that error is gone, however the Recent Topics block still displays the last poster... :(

Maybe I've made another error? I looked through it and it all looks right. If you could be so kind as to have a quick look for me?
Title: Re: sp_recent displaying topic author instead of last poster?
Post by: Adjacent on November 14, 2011, 03:14:47 PM
Bump, any ideas please? :(
Title: Re: sp_recent displaying topic author instead of last poster?
Post by: AngelinaBelle on November 15, 2011, 11:29:57 AM
Here's how I would approach a problem like this.
1) I would create a new custom php block, because it is an easy way to test the SSI file right inside my forum
2) In that custom php block, I would call ssi_recentTopics. Use the same kind of parameters you would be using from your recent topics block -- number of posts, included or excluded boards, if any, and 'array' output.

3) Using the returned array from  ssi_recentTopics, print out just the stuff you care about -- the stuff you added.
* subject, all the ['topic']['poster'] stuff you just added, id_msg.

Remember, there is a differencee between $posts[$i]['topic]['poster']['link'] and $posts[$i]['poster']['link'] -- merely because different information is stored in those two different locations.
Title: Re: sp_recent displaying topic author instead of last poster?
Post by: ccbtimewiz on November 15, 2011, 12:04:11 PM
In your PortalBlocks.php file,

Find:
Code: [Select]
if ( $parameters['type'] = 'Topics' )
Replace:
Code: [Select]
if ($parameters['type'] == 'topics')
Title: Re: sp_recent displaying topic author instead of last poster?
Post by: Adjacent on November 15, 2011, 10:17:27 PM
In your PortalBlocks.php file,

Find:
Code: [Select]
if ( $parameters['type'] = 'Topics' )
Replace:
Code: [Select]
if ($parameters['type'] == 'topics')


Thanks for your time and response, it was an honest effort too. However it seems this did not fix the box, its still displaying the last poster.

Box here: http://www.blastbox.co.uk/forum/

Also, I thank you for all your help AngelinaBelle but I'm just about done with all of this trouble. What a headache over a little box...   :-[
Title: Re: sp_recent displaying topic author instead of last poster?
Post by: ayekuf on December 01, 2011, 10:38:13 PM
Shame there is no fix for this, really wanted the same feature :(
Title: Re: sp_recent displaying topic author instead of last poster?
Post by: Adjacent on December 09, 2011, 11:47:17 AM
Shame there is no fix for this, really wanted the same feature :(

You're telling me...
SimplePortal 2.3.8 © 2008-2024, SimplePortal