SimplePortal

Customization => Blocks and Modifications => Block Requests => Topic started by: cedrict on February 15, 2011, 10:15:01 AM

Title: sp_recent modification to show the post owner
Post by: cedrict on February 15, 2011, 10:15:01 AM
Hello,

It's my firt post, so I try the search fonction before ask your help. Sorry for my english.

I use your simple portal 2.3.3 on my smf 1.1.12 and it's so wonderfull but i'd like to add one modification to sp_recent in PortalBlocks.php to show the post owner. I'm neewbie in php and I don't find hox to to that. Can you help me ?

So the code is :

Code: [Select]
if ($display == 'compact')

{

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

echo '

<a href="', $item['href'], '">', $item['subject'], '</a> <span class="smalltext">', $txt[525], ' ', $item['poster']['link'], $item['new'] ? '' : ' <a href="' . $scripturl . '?topic=' . $item['topic'] . '.msg' . $item['new_from'] . ';topicseen#new" rel="nofollow"><img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/new.gif" alt="' . $txt[302] . '" border="0" /></a>', '<br />[', $item['time'], ']</span><br />', empty($item['is_last']) ? '<hr />' : '';

}

i try to do this :

Code: [Select]
if ($display == 'compact')

{

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

echo '

<a href="', $item['href'], '">', $item['subject'], '</a> <span class="smalltext">, $txt[525],',item['owner']['link']'', $txt[525a], ' ', $item['poster']['link'], $item['new'] ? '' : ' <a href="' . $scripturl . '?topic=' . $item['topic'] . '.msg' . $item['new_from'] . ';topicseen#new" rel="nofollow"><img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/new.gif" alt="' . $txt[302] . '" border="0" /></a>', '<br />[', $item['time'], ']</span><br />', empty($item['is_last']) ? '<hr />' : '';

}

$txt[525a] is a text I add in index.french_uft8.php to say "last answer by"

But I don't know how and where define the $item['owner']

I hope you understand me and you'll can help me.

Thanks a lot.

Cedrict
Title: Re: sp_recent modification to show the post owner
Post by: AngelinaBelle on February 15, 2011, 11:14:21 AM
I think I understand you perfectly, Cedric.
 
I will try to write in simple English, since I know you are a French speaker.
Thank you for searching for some answers first. You know so much now, I can easily explain the rest.
I will show you how I found out the answer. I hope to make it easy for you to do many more customizations in the future.
 
* 1: What is in $item? Where does $item come from?
Code: (in sp_recent, in PortalBlocks.php) [Select]
$type = 'ssi_recent' . (empty($parameters['type']) ? 'Posts' : 'Topics');
 $items = $type($limit, null, $boards, 'array');
So $items = ssi_recentPosts or else $items = ssi_recentTopics.
Code: (in ssi_recentPosts, in SSI.php) [Select]
return ssi_queryPosts($query_where, $query_where_params, $num_recent, 'm.id_msg DESC', $output_method, $limit_body);
Code: (in ssi_queryPosts, in SSI.php) [Select]
  // Build the array.
  $posts[] = array(
   'id' => $row['id_msg'],
   'board' => array(
    'id' => $row['id_board'],
    'name' => $row['board_name'],
    'href' => $scripturl . '?board=' . $row['id_board'] . '.0',
    'link' => '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['board_name'] . '</a>'
   ),
   'topic' => $row['id_topic'],
   '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>'
   ),
   'subject' => $row['subject'],
   'short_subject' => shorten_subject($row['subject'], 25),
   'preview' => $smcFunc['strlen']($preview) > 128 ? $smcFunc['substr']($preview, 0, 128) . '...' : $preview,
   'body' => $row['body'],
   'time' => timeformat($row['poster_time']),
   'timestamp' => forum_time(true, $row['poster_time']),
   'href' => $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . ';topicseen#new',
   'link' => '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#msg' . $row['id_msg'] . '" rel="nofollow">' . $row['subject'] . '</a>',
   'new' => !empty($row['is_read']),
   'is_new' => empty($row['is_read']),
   'new_from' => $row['new_from'],
  );
 }
 $smcFunc['db_free_result']($request);
 // Just return it.
 if ($output_method != 'echo' || empty($posts))
  return $posts;

* 2: What do you want from $item?
       You can now see that $item holds everything from $posts (ssi_queryPosts put it there)
       So you can choose from

Now, you choose what to put in youc code.
Title: Re: sp_recent modification to show the post owner
Post by: cedrict on February 16, 2011, 06:09:01 AM
Thanks so much for your help AngelinaBelle, I understand now what is $item and what I could do with it. I think it is not the good solution to do what I want.

Indeed, $item could'nt have function to declare the name of the owner or first writer of the post.

So, I read SSI.php but I don't find any more solution to resolve my problem. However, in MessageIndex.template.php (a smf file) I found this : ', $topic['first_post']['member']['link'], '  that display the owner of a last topic in a tab.

I don't if I go in the right or wrong way  :0

Title: Re: sp_recent modification to show the post owner
Post by: AngelinaBelle on February 16, 2011, 12:19:33 PM
$item['poster']['link'] should give you the name and link to the profile of the person who posted the post.
 
What is it you want?
Title: Re: sp_recent modification to show the post owner
Post by: cedrict on February 16, 2011, 01:39:09 PM
$item['poster']['link'] give me the name and the link  to the personn who writed the last post of the topic. I would like to show the name of the person who write the firt post of the topic.

Exemple : sp_recent modification to show the post owner initiated (http://simpleportal.net/index.php?topic=7752.0) by Cedrict, last reponse by AngelinaBelle (http://simpleportal.net/index.php?action=profile;u=1730) on: Today at 11:19:33 AM
Title: Re: sp_recent modification to show the post owner
Post by: AngelinaBelle on February 16, 2011, 02:41:37 PM
Yes. This is true. You get the poster of the message, not the poster of the topic.
For that, you would need a new SQL statement -- you would have to write a replacement for one of those SSI functions. It could be done, but not quickly by either one of us.
Title: Re: sp_recent modification to show the post owner
Post by: cedrict on February 16, 2011, 06:15:00 PM
Well, thanks you for your help :)

I'll try to resolve my problem with lots of test of coding. I'll continue to post that I 'll find or try.

If anybody else have a part of the solution ...  :D
Title: Re: sp_recent modification to show the post owner
Post by: cedrict on February 17, 2011, 09:10:31 AM
Hi,

After some search, i try to modify ssi_recentTopics in SSI.php, but it seems to not work, the result is a blank page. I don't know where is my mistake.

Code: [Select]
// Recent topic list:   [board] Subject by Poster Date
function ssi_recentTopics($num_recent = 8, $exclude_boards = null, $output_method = 'echo')
{
global $context, $settings, $scripturl, $txt, $db_prefix, $ID_MEMBER, $ID_MEMBER_STARTED;
global $user_info, $modSettings, $func;

if ($exclude_boards === null && !empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0)
$exclude_boards = array($modSettings['recycle_board']);
else
$exclude_boards = empty($exclude_boards) ? array() : $exclude_boards;

$stable_icons = array('xx', 'thumbup', 'thumbdown', 'exclamation', 'question', 'lamp', 'smiley', 'angry', 'cheesy', 'grin', 'sad', 'wink', 'moved', 'recycled', 'wireless');
$icon_sources = array();
foreach ($stable_icons as $icon)
$icon_sources[$icon] = 'images_url';

// Find all the posts in distinct topics.  Newer ones will have higher IDs.
$request = db_query("
SELECT
m.posterTime, ms.subject, m.ID_TOPIC, m.ID_MEMBER, m.ID_MSG, b.ID_BOARD, b.name AS bName,
IFNULL(mem.realName, m.posterName) AS posterName, " . ($user_info['is_guest'] ? '1 AS isRead, 0 AS new_from' : '
IFNULL(lt.ID_MSG, IFNULL(lmr.ID_MSG, 0)) >= m.ID_MSG_MODIFIED AS isRead,
IFNULL(lt.ID_MSG, IFNULL(lmr.ID_MSG, -1)) + 1 AS new_from') . ", LEFT(m.body, 384) AS body, m.smileysEnabled, m.icon
IFNULL(ml.realName, m.posterName) AS starterName,
FROM ({$db_prefix}messages AS m, {$db_prefix}topics AS t, {$db_prefix}boards AS b, {$db_prefix}messages AS ms)
[b]LEFT JOIN {$db_prefix}members AS ml ON (ml.ID_MEMBER = t.ID_MEMBER_STARTED) [/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 = t.ID_TOPIC AND lt.ID_MEMBER = $ID_MEMBER)
LEFT JOIN {$db_prefix}log_mark_read AS lmr ON (lmr.ID_BOARD = b.ID_BOARD AND lmr.ID_MEMBER = $ID_MEMBER)" : '') . "


WHERE t.ID_LAST_MSG >= " . ($modSettings['maxMsgID'] - 35 * min($num_recent, 5)) . "
AND t.ID_LAST_MSG = m.ID_MSG
AND b.ID_BOARD = t.ID_BOARD" . (empty($exclude_boards) ? '' : "
AND b.ID_BOARD NOT IN (" . implode(', ', $exclude_boards) . ")") . "
AND $user_info[query_see_board]
AND ms.ID_MSG = t.ID_FIRST_MSG
ORDER BY t.ID_LAST_MSG DESC
LIMIT $num_recent", __FILE__, __LINE__);

$posts = array();
while ($row = mysql_fetch_assoc($request))
{
$row['body'] = strip_tags(strtr(parse_bbc($row['body'], $row['smileysEnabled'], $row['ID_MSG']), array('<br />' => '&#10;')));
if ($func['strlen']($row['body']) > 128)
$row['body'] = $func['substr']($row['body'], 0, 128) . '...';


// Censor the subject.
censorText($row['subject']);
censorText($row['body']);

if (empty($modSettings['messageIconChecks_disable']) && !isset($icon_sources[$row['icon']]))
$icon_sources[$row['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['icon'] . '.gif') ? 'images_url' : 'default_images_url';

// 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>'
),
'starter' => array(
'id' => $row['ID_MEMBER_STARTED'],
'name' => $row['starterName'],
'href' => empty($row['ID_MEMBER_STARTED']) ? '' : $scripturl . '?action=profile;u=' . $row['ID_MEMBER_STARTED'],
'link' => empty($row['ID_MEMBER_STARTED']) ? $row['starterName'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['ID_MEMBER_STARTED'] . '">' . $row['starterName'] . '</a>'
),
'subject' => $row['subject'],
'short_subject' => shorten_subject($row['subject'], 25),
'preview' => $row['body'],
'time' => timeformat($row['posterTime']),
'timestamp' => forum_time(true, $row['posterTime']),
'href' => $scripturl . '?topic=' . $row['ID_TOPIC'] . '.msg' . $row['ID_MSG'] . ';topicseen#new',
'link' => '<a href="' . $scripturl . '?topic=' . $row['ID_TOPIC'] . '.msg' . $row['ID_MSG'] . '#new">' . $row['subject'] . '</a>',
'new' => !empty($row['isRead']),
'new_from' => $row['new_from'],
'icon' => '<img src="' . $settings[$icon_sources[$row['icon']]] . '/post/' . $row['icon'] . '.gif" align="middle" alt="' . $row['icon'] . '" border="0" />',
);
}
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'] . '.msg' . $post['new_from'] . ';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: sp_recent modification to show the post owner
Post by: AngelinaBelle on February 17, 2011, 10:53:35 AM
I would normally test the SQL statement alone before trying to insert it into a complicated page.
Sometimes, it is convenient to just put it in a SimplePortal php page or block, to see what the outcome is, and how long it takes to run.
And whether it just throws a SQL area.
It looks to me like you have a SQL error from leaving out a comma.
Also, you used m.posterName where you wanted ml.posterName (which wouldn't cause an error)
I have not tested your SQL statement. You should give it a good test, to see if you have any other SQL errors.
 

Code: [Select]
   $request = db_query("
      SELECT
         m.posterTime, ms.subject, m.ID_TOPIC, m.ID_MEMBER, m.ID_MSG, b.ID_BOARD, b.name AS bName,
         IFNULL(mem.realName, m.posterName) AS posterName, " . ($user_info['is_guest'] ? '1 AS isRead, 0 AS new_from' : '
         IFNULL(lt.ID_MSG, IFNULL(lmr.ID_MSG, 0)) >= m.ID_MSG_MODIFIED AS isRead,
         IFNULL(lt.ID_MSG, IFNULL(lmr.ID_MSG, -1)) + 1 AS new_from') . ", LEFT(m.body, 384) AS body, m.smileysEnabled, m.icon
 
         ,
         IFNULL(ml.realName, ml.posterName) AS starterName,

      FROM ({$db_prefix}messages AS m, {$db_prefix}topics AS t, {$db_prefix}boards AS b, {$db_prefix}messages AS ms)
 
         LEFT JOIN {$db_prefix}members AS ml ON (ml.ID_MEMBER = t.ID_MEMBER_STARTED)

         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 = t.ID_TOPIC AND lt.ID_MEMBER = $ID_MEMBER)
         LEFT JOIN {$db_prefix}log_mark_read AS lmr ON (lmr.ID_BOARD = b.ID_BOARD AND lmr.ID_MEMBER = $ID_MEMBER)" : '') . "
         
     
      WHERE t.ID_LAST_MSG >= " . ($modSettings['maxMsgID'] - 35 * min($num_recent, 5)) . "
         AND t.ID_LAST_MSG = m.ID_MSG
         AND b.ID_BOARD = t.ID_BOARD" . (empty($exclude_boards) ? '' : "
         AND b.ID_BOARD NOT IN (" . implode(', ', $exclude_boards) . ")") . "
         AND $user_info[query_see_board]
         AND ms.ID_MSG = t.ID_FIRST_MSG
      ORDER BY t.ID_LAST_MSG DESC
      LIMIT $num_recent", __FILE__, __LINE__);
         
Title: Re: sp_recent modification to show the post owner
Post by: grafitus on May 22, 2011, 01:52:29 PM
Hey, cedrict! Could you do it?
SimplePortal 2.3.8 © 2008-2024, SimplePortal