Main Menu
collapse

Simple Portal Archived Forum

This is an Archive Forum.

The content in this forum may be out-of-date or have been superseded by newer information, and links in forum pages to other sites may not work.
This forum contains archives for future reference.

Visit our thread at Simple Machines Forum for current support.

SMF 2.1 users: EhPortal is a ported version of Simple Portal specifically designed for the SMF 2.1 branch.
Please visit web-develop.ca to download EhPortal and for its support.

User Info

Welcome Guest.
Please log in.

Who's Online

  • Dot Guests: 838
  • Dot Hidden: 0
  • Dot Users: 0

There aren't any users online.

Recent Posts

Adding Forums Button to Nav bar by jirapon
[August 01, 2019, 09:07:12 AM]


Re: Board Icons by ♦ Ninja ZX-10RR ♦
[July 30, 2019, 04:03:41 PM]


MOVED: Czech translation???? by ♦ Ninja ZX-10RR ♦
[July 30, 2019, 03:04:51 PM]


Board Icons by jirapon
[July 30, 2019, 07:28:44 AM]


Re: Thankyou Simpleportal, by ♦ Ninja ZX-10RR ♦
[July 29, 2019, 09:41:29 AM]


NEED HELP? If you're looking for support with Simple Portal, look no further than the Support Board!

sp_recent displaying topic author instead of last poster?

Started by Adjacent, October 12, 2011, 10:14:40 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Adjacent

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

Click the banner above to see what all television-watching cats are talking about!

AngelinaBelle

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?
Please to keep this website running, if you like SimplePortal, make a
one-time subscription. Thank you for your support.

Have you tried the SimplePortal documentation?

ccbtimewiz

Haven't tested this, but it might work the way you want it to.

Open ./Sources/PortalBlocks.php

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


Replace with:
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.

AngelinaBelle

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

'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.
Please to keep this website running, if you like SimplePortal, make a
one-time subscription. Thank you for your support.

Have you tried the SimplePortal documentation?

ccbtimewiz

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.

Adjacent

Quote from: Veridis Quo 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:
else
$items[count($items) - 1]['is_last'] = true;


Replace with:
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?

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>';

Click the banner above to see what all television-watching cats are talking about!

Adjacent


Click the banner above to see what all television-watching cats are talking about!

AngelinaBelle

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.
Please to keep this website running, if you like SimplePortal, make a
one-time subscription. Thank you for your support.

Have you tried the SimplePortal documentation?

Adjacent


Click the banner above to see what all television-watching cats are talking about!

AngelinaBelle

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.
Please to keep this website running, if you like SimplePortal, make a
one-time subscription. Thank you for your support.

Have you tried the SimplePortal documentation?

Adjacent

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

Click the banner above to see what all television-watching cats are talking about!

AngelinaBelle

OK.  Thanks for that explanation.  That makes more sense to me.

The Recent Topics block doesn't do what you want?
Please to keep this website running, if you like SimplePortal, make a
one-time subscription. Thank you for your support.

Have you tried the SimplePortal documentation?

Adjacent

Quote from: 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?

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?

Click the banner above to see what all television-watching cats are talking about!

AngelinaBelle

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'];
   }

Please to keep this website running, if you like SimplePortal, make a
one-time subscription. Thank you for your support.

Have you tried the SimplePortal documentation?

Adjacent

#14
Thank you for efforts and time AngelinaBelle. I do believe this code could work.


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:

'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'],
      )

Click the banner above to see what all television-watching cats are talking about!

AngelinaBelle

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)
            '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'],
      )

Please to keep this website running, if you like SimplePortal, make a
one-time subscription. Thank you for your support.

Have you tried the SimplePortal documentation?

Adjacent

#16
----
Edited by AngelinaBelle
I'm sorry.  I accidentally modified your message instead of quoting it.

Click the banner above to see what all television-watching cats are talking about!

AngelinaBelle

I looked up foreach in the php manual to correct my typo:
http://www.google.com/search?q=foreach+php.net
http://php.net/manual/en/control-structures.foreach.php

   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.
Please to keep this website running, if you like SimplePortal, make a
one-time subscription. Thank you for your support.

Have you tried the SimplePortal documentation?

Adjacent

Quote from: 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://php.net/manual/en/control-structures.foreach.php

   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":
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

Click the banner above to see what all television-watching cats are talking about!

AngelinaBelle

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

Please to keep this website running, if you like SimplePortal, make a
one-time subscription. Thank you for your support.

Have you tried the SimplePortal documentation?