SimplePortal

Customization => Custom Coding => Topic started by: efil on April 11, 2009, 07:26:29 AM

Title: sticky Posts
Post by: efil on April 11, 2009, 07:26:29 AM
Hi,
Is there a way to show in the block "Recent Posts" , a sticky Posts?

Thanks,
Efil.
Title: Re: sticky Posts
Post by: Nathaniel on April 11, 2009, 09:38:13 AM
Not sure I exactly understood what you meant.

Do you want the block to show only the most recent stickies posts?
Title: Re: sticky Posts
Post by: efil on April 11, 2009, 10:01:08 AM
No.
what I mean is that if I make a sticky Topic in one of my forums, it will display in the "Recent Topics " block at the first position, untill i remove the sticky from the forum.
Title: Re: sticky Posts
Post by: efil on April 29, 2009, 09:38:45 AM
Here how it looks in "vBadvanced CMPS" the vb portal.

Efil.
Title: Re: sticky Posts
Post by: Nathaniel on May 03, 2009, 05:44:24 AM
Sorry about the wait:
This should be fairly easy to do with a custom edit to the database query for that block.

Which versions of SMF/SP are you using?
Title: Re: sticky Posts
Post by: efil on May 03, 2009, 09:55:14 AM
Hi,
Now i'm using smf 1.18 & SimplePortal Version 2.2, but in the near future i will use smf 2.

Thanks,
Efil.

Title: Re: sticky Posts
Post by: Nathaniel on May 03, 2009, 05:32:47 PM
Unfortunately we have to edit some database queries for this. :(

For SMF 1.1.x (SPortal1-1.php):
Replace this code:
Code: [Select]
$posts = ssi_recentPosts($limit, null, null, 'array');
With this code:
Code: [Select]
global $context, $settings, $scripturl, $txt, $db_prefix, $ID_MEMBER;
global $user_info, $modSettings, $func;

// 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 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
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'] - 25 * min($limit, 5)) . "
AND b.ID_BOARD = m.ID_BOARD
AND $user_info[query_see_board]
ORDER BY t.isSticky, m.ID_MSG DESC
LIMIT $limit", __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 it!
censorText($row['subject']);
censorText($row['body']);

// 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' => 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'] . '#msg' . $row['ID_MSG'] . '">' . $row['subject'] . '</a>',
'new' => !empty($row['isRead']),
'new_from' => $row['new_from'],
);
}
mysql_free_result($request);

For SMF 2 (SPortal2.php):
I can post this later if you need it.
Title: Re: sticky Posts
Post by: efil on May 04, 2009, 12:16:12 AM
Hi,
I tried it and it seems to be not working.
I use "Compact Recent" with Recent Topics. and i tried "Recent Topics" too.

Thanks,
Efil.
Title: Re: sticky Posts
Post by: Nathaniel on May 04, 2009, 01:09:02 AM
Ah, whoops. Use the edit above, but replace 't.isSticky' with 't.isSticky DESC'.

Its for the non compact version, although the edit should be the same or similar for the other function.
Title: Re: sticky Posts
Post by: efil on May 04, 2009, 10:17:48 AM
Ah, whoops. Use the edit above, but replace 't.isSticky' with 't.isSticky DESC'.

Its for the non compact version, although the edit should be the same or similar for the other function.
I changed, but still not working.
Title: Re: sticky Posts
Post by: Nathaniel on May 16, 2009, 10:55:24 PM
Sorry about the wait, I forgot about this topic. ;)

Try this code (instead of the replace part of my earlier post):
Code: [Select]
   global $context, $settings, $scripturl, $txt, $db_prefix, $ID_MEMBER;
   global $user_info, $modSettings, $func;

   // 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 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
      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)" : '') . "
LEFT JOIN {$db_prefix}topics AS t ON (t.ID_TOPIC = m.ID_TOPIC)
      WHERE m.ID_MSG >= " . ($modSettings['maxMsgID'] - 25 * min($limit, 5)) . "
         AND b.ID_BOARD = m.ID_BOARD
         AND $user_info[query_see_board]
      ORDER BY t.isSticky DESC, m.ID_MSG DESC
      LIMIT $limit", __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 it!
      censorText($row['subject']);
      censorText($row['body']);

      // 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' => 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'] . '#msg' . $row['ID_MSG'] . '">' . $row['subject'] . '</a>',
         'new' => !empty($row['isRead']),
         'new_from' => $row['new_from'],
      );
   }
   mysql_free_result($request);
Title: Re: sticky Posts
Post by: efil on May 17, 2009, 12:28:45 AM
Hi,
Where should I put the code? If you mean in "SPortal2.php", please tell me the exact location in the file.

Thanks,
Efil.
Title: Re: sticky Posts
Post by: Nathaniel on May 17, 2009, 02:23:46 AM
That edit was for SMF 1.1.8. The edit below will work for SMF 2 RC1, for your SPortal2.php file.

Find this code:
Code: [Select]
$posts = ssi_recentPosts($limit, null, null, 'array');

Replace with this code:
Code: [Select]
global $modSettings, $smcFunc, $user_info;

// Find all the posts. Newer ones will have higher IDs.
$request = $smcFunc['db_query']('substring', '
SELECT
m.poster_time, m.subject, m.id_topic, m.id_member, m.id_msg, m.id_board, b.name AS board_name,
IFNULL(mem.real_name, m.poster_name) AS poster_name, ' . ($user_info['is_guest'] ? '1 AS is_read, 0 AS new_from' : '
IFNULL(lt.id_msg, IFNULL(lmr.id_msg, 0)) >= m.id_msg_modified AS is_read,
IFNULL(lt.id_msg, IFNULL(lmr.id_msg, -1)) + 1 AS new_from') . ', ' . ($limit_body ? 'SUBSTRING(m.body, 1, 384) AS body' : 'm.body') . ', m.smileys_enabled
FROM {db_prefix}messages AS m
INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board)
LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)
LEFT JOIN {db_prefix}topics AS t ON (t.id_topic = m.id_topic)' . (!$user_info['is_guest'] ? '
LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = m.id_topic AND lt.id_member = {int:current_member})
LEFT JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = m.id_board AND lmr.id_member = {int:current_member})' : '') . '
WHERE m.id_msg >= {int:min_message_id}
AND {query_wanna_see_board}' . ($modSettings['postmod_active'] ? '
AND m.approved = {int:is_approved}' : '') . '
ORDER BY t.is_sticky DESC, m.id_msg DESC
LIMIT ' . $limit,
array(
'is_approved' => 1,
'min_message_id' => $modSettings['maxMsgID'] - 25 * min($limit, 5),
'current_member' => $user_info['id'],
)
);
$posts = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
{
$row['body'] = parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']);
$preview = strip_tags(strtr($row['body'], array('<br />' => '&#10;')));

// Censor it!
censorText($row['subject']);
censorText($row['body']);

// 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']),
'new_from' => $row['new_from'],
);
}
$smcFunc['db_free_result']($request);
Title: Re: sticky Posts
Post by: efil on May 17, 2009, 11:39:12 AM
Hi,
sorry but it still not working for me.

Efil.
Title: Re: sticky Posts
Post by: efil on June 12, 2009, 01:49:28 PM
Hi,
Do this mod works for someone?

It's not working for me.


Thanks,
Efil.
Title: Re: sticky Posts
Post by: Nathaniel on June 12, 2009, 07:49:53 PM
Ah, sorry about the wait. I must have missed this topic.

Could you please attach your SPortal2.php file?
Title: Re: sticky Posts
Post by: efil on June 13, 2009, 12:14:42 PM
Thank you Nathaniel!

 I use for now smf 1.19...

Do you want me to attach  SPortal1-1.php? (it's the last version. i didn't edit it).

Title: Re: sticky Posts
Post by: Nathaniel on June 13, 2009, 07:27:10 PM
Yeah, that is the correct file for SMF 1.1.x. If you could attach it then that would be good.
Title: Re: sticky Posts
Post by: efil on June 13, 2009, 11:09:55 PM
Here is the file.
Title: Re: sticky Posts
Post by: Nathaniel on June 14, 2009, 12:46:07 AM
Okay, the attached file will work for the 'Topic' mode, with the 'Compact Recent' block. I will have to make more changes if you want to show a sticky icon for the stickies, or if you want to change the type/block.
Title: Re: sticky Posts
Post by: efil on June 14, 2009, 01:02:01 AM
Hi,
Yes it's working.
It takes the sticky posts from two board only. (there are more).
Is there a way to choose from what board it will take it?
surely sticky icon for the stickies posts will be great.

Thanks,
Efil.

SimplePortal 2.3.8 © 2008-2024, SimplePortal