SimplePortal

Customization => Custom Coding => Topic started by: bizref on September 07, 2008, 11:26:27 AM

Title: Custom Block Creation and Block Customization
Post by: bizref on September 07, 2008, 11:26:27 AM
Hi -- there seems to be a problem with the Manual (it's not loading) so I thought I would post this here ...

In answering the question, if you could explain as if to a first grader and/or rpovide any links to further instructions, that would be great: I don't know how to "create php blocks" or ANYTHING like that; I work completely from the Admin panel :-)

Question1: How can I create a custom block (i.e. a block that announces newly-created BOARDS ...?)

Question2: How can I modify a News Block (which is SO cool by the way) to pull the most recent topics across all of the Categories within a single Board? -- if you'd even like to provide the code in a reply I would be SO GRATEFUL :-)

Thanks very much, this is a REALLY exciting mod.
Title: Re: Custom Block Creation and Block Customization
Post by: ccbtimewiz on September 07, 2008, 12:16:18 PM
In regards to the manual-- http://simpleportal.net/index.php?topic=102.0

But anyways, the blocks you're requesting require PHP work. I'm sure someone whom is familar with PHP enough to create a block for you will do such. :)
Title: Re: Custom Block Creation and Block Customization
Post by: Nathaniel on September 07, 2008, 05:34:12 PM
Basically if uou have the php skills then you can use the 'PHP' block to create 'your own custom blocks'.
Title: Re: Custom Block Creation and Block Customization
Post by: bizref on September 07, 2008, 07:54:22 PM
Quote
But anyways, the blocks you're requesting require PHP work. I'm sure someone whom is familar with PHP enough to create a block for you will do such. Smiley

Whoever that might be would be my VERY VERY best friend ....!!!
Title: Re: Custom Block Creation and Block Customization
Post by: bizref on September 07, 2008, 07:55:13 PM
Quote
Question2: How can I modify a News Block (which is SO cool by the way) to pull the most recent topics across all of the Categories within a single Board? --

Does this require custom PHP as well?
Title: Re: Custom Block Creation and Block Customization
Post by: Nathaniel on September 14, 2008, 07:26:00 AM
Yep, although you could do it either of two ways:
1) Copy the relevant 'sp_boardNews()' function/code from your 'SPortal.php' file into a new php block and then edit it there.
2) Edit the code in your SPortal.php file.

It will require quite a bit of editing, if you like then one of us can give it a go?
Title: Re: Custom Block Creation and Block Customization
Post by: bizref on September 18, 2008, 08:32:47 PM
Yes please!

I'd also like to create a custom block that announces newly-created BOARDS, could you help?

Many thanks!
Title: Re: Custom Block Creation and Block Customization
Post by: Nathaniel on September 19, 2008, 04:19:35 AM
For the board news block that can show new from multiple boards:
Put the code below into a new "PHP" block:
Code: [Select]

        // Limit the number of articles to show.
        $limit = 5;
$start = 0;
        // An array of board ids to show.
$boards = array(1, 4);
        // The length limit of each message shown.
$length = 0;
        // 0 = don't show avatars, 1= show.
        $avatars = 0;

        global $scripturl, $db_prefix, $txt, $settings, $modSettings, $context;
global $func, $return;

loadLanguage('Stats');

$limit = max(0, $limit);
$start = max(0, $start);

// Make sure guests can see this board.
$request = db_query("
SELECT ID_BOARD
FROM {$db_prefix}boards
WHERE ID_BOARD IN (".implode(',',$boards).")
        AND FIND_IN_SET(-1, memberGroups)
LIMIT 1", __FILE__, __LINE__);
if (mysql_num_rows($request) == 0)
{
die($txt['smf_news_error2']);
}
list ($board) = mysql_fetch_row($request);
mysql_free_result($request);

// Load the message icons - the usual suspects.
$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 the post ids.
$request = db_query("
SELECT ID_FIRST_MSG
FROM {$db_prefix}topics
WHERE ID_BOARD IN (".implode(',',$boards).")
ORDER BY ID_FIRST_MSG DESC
LIMIT $start, $limit", __FILE__, __LINE__);
$posts = array();
while ($row = mysql_fetch_assoc($request))
$posts[] = $row['ID_FIRST_MSG'];
mysql_free_result($request);

if (empty($posts))
return array();

// Find the posts.
$request = db_query("
SELECT
m.icon, m.subject, m.body, IFNULL(mem.realName, m.posterName) AS posterName, m.posterTime,
t.numReplies, t.ID_TOPIC, m.ID_MEMBER, m.smileysEnabled, m.ID_MSG, t.locked, mem.avatar, a.ID_ATTACH, a.attachmentType, a.filename
FROM ({$db_prefix}topics AS t, {$db_prefix}messages AS m)
LEFT JOIN {$db_prefix}members AS mem ON (mem.ID_MEMBER = m.ID_MEMBER)
LEFT JOIN {$db_prefix}attachments AS a ON (a.ID_MEMBER = m.ID_MEMBER)
WHERE t.ID_FIRST_MSG IN (" . implode(', ', $posts) . ")
AND m.ID_MSG = t.ID_FIRST_MSG
ORDER BY t.ID_FIRST_MSG DESC
LIMIT " . count($posts), __FILE__, __LINE__);
$return = array();
$colorids = array();
while ($row = mysql_fetch_assoc($request))
{
// If we want to limit the length of the post.
if (!empty($length) && $func['strlen']($row['body']) > $length)
{
$row['body'] = $func['substr']($row['body'], 0, $length);

// The first space or line break. (<br />, etc.)
$cutoff = max(strrpos($row['body'], ' '), strrpos($row['body'], '<'));

if ($cutoff !== false)
$row['body'] = $func['substr']($row['body'], 0, $cutoff);
$row['body'] .= '...';
}

$row['body'] = parse_bbc($row['body'], $row['smileysEnabled'], $row['ID_MSG']);

// Check if the topic icon exists.
if (!isset($icon_sources[$row['icon']]))
$icon_sources[$row['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['icon'] . '.gif') ? 'images_url' : 'default_images_url';

if (stristr($row['avatar'], 'http://') && !empty($modSettings['avatar_check_size']))
{
$sizes = url_image_size($row['avatar']);

// Does your avatar still fit the maximum size?
if ($modSettings['avatar_action_too_large'] == 'option_refuse' && is_array($sizes) && (($sizes[0] > $modSettings['avatar_max_width_external'] && !empty($modSettings['avatar_max_width_external'])) || ($sizes[1] > $modSettings['avatar_max_height_external'] && !empty($modSettings['avatar_max_height_external']))))
{
// Fix it permanently!
$row['avatar'] = '';
updateMemberData($row['ID_MEMBER'], array('avatar' => '\'\''));
}
}

// Check that this message icon is there...
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';

censorText($row['subject']);
censorText($row['body']);

//Collect the color ids :)
$colorids[$row['ID_MEMBER']] = $row['ID_MEMBER'];

$return[] = array(
'id' => $row['ID_TOPIC'],
'message_id' => $row['ID_MSG'],
'icon' => '<img src="' . $settings[$icon_sources[$row['icon']]] . '/post/' . $row['icon'] . '.gif" align="middle" alt="' . $row['icon'] . '" border="0" />',
'subject' => $row['subject'],
'time' => timeformat($row['posterTime']),
'timestamp' => forum_time(true, $row['posterTime']),
'body' => $row['body'],
'href' => $scripturl . '?topic=' . $row['ID_TOPIC'] . '.0',
'link' => '<a href="' . $scripturl . '?topic=' . $row['ID_TOPIC'] . '.0">' . $row['numReplies'] . ' ' . ($row['numReplies'] == 1 ? $txt['smf_news_1'] : $txt['smf_news_2']) . '</a>',
'replies' => $row['numReplies'],
'comment_href' => !empty($row['locked']) ? '' : $scripturl . '?action=post;topic=' . $row['ID_TOPIC'] . '.' . $row['numReplies'] . ';num_replies=' . $row['numReplies'],
'comment_link' => !empty($row['locked']) ? '' : '<a href="' . $scripturl . '?action=post;topic=' . $row['ID_TOPIC'] . '.' . $row['numReplies'] . ';num_replies=' . $row['numReplies'] . '">' . $txt['smf_news_3'] . '</a>',
'new_comment' => !empty($row['locked']) ? '' : '<a href="' . $scripturl . '?action=post;topic=' . $row['ID_TOPIC'] . '.' . $row['numReplies'] . '">' . $txt['smf_news_3'] . '</a>',
'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']) ? '<a href="' . $scripturl . '?action=profile;u=' . $row['ID_MEMBER'] . '">' . $row['posterName'] . '</a>' : $row['posterName']
),
'locked' => !empty($row['locked']),
'is_last' => false,
'avatar' => array(
'name' => $row['avatar'],
'image' => $row['avatar'] == '' ? ($row['ID_ATTACH'] > 0 ? '<img src="' . (empty($row['attachmentType']) ? $scripturl . '?action=dlattach;attach=' . $row['ID_ATTACH'] . ';type=avatar' : $modSettings['custom_avatar_url'] . '/' . $row['filename']) . '" alt="" class="avatar" border="0" />' : '') : (stristr($row['avatar'], 'http://') ? '<img src="' . $row['avatar'] . '" alt="" class="avatar" border="0" />' : '<img src="' . $modSettings['avatar_url'] . '/' . htmlspecialchars($row['avatar']) . '" alt="" class="avatar" border="0" />'),
'href' => $row['avatar'] == '' ? ($row['ID_ATTACH'] > 0 ? (empty($row['attachmentType']) ? $scripturl . '?action=dlattach;attach=' . $row['ID_ATTACH'] . ';type=avatar' : $modSettings['custom_avatar_url'] . '/' . $row['filename']) : '') : (stristr($row['avatar'], 'http://') ? $row['avatar'] : $modSettings['avatar_url'] . '/' . $row['avatar']),
'url' => $row['avatar'] == '' ? '' : (stristr($row['avatar'], 'http://') ? $row['avatar'] : $modSettings['avatar_url'] . '/' . $row['avatar']),
),
);
}
mysql_free_result($request);

if (empty($return))
return $return;

$return[count($return) - 1]['is_last'] = true;

if(!empty($colorids)) {
$color_profile = sp_loadColors($colorids);
foreach($return as $k => $p) {
if(!empty($color_profile[$p['poster']['id']])) {
$profile = $color_profile[$p['poster']['id']];
if(!empty($profile)) {
$return[$k]['poster']['link'] = $profile['link'];
}
}
}
}

echo '<br />
<table cellpadding="0" cellspacing="0" border="0" width="100%" style="clear: both; table-layout: fixed;">';

foreach ($return as $news)
{
echo '
<tr>';
if($avatars == 1) {
$avatar_max_table_width = max($modSettings['avatar_max_width_upload'], $modSettings['avatar_max_width_external']) + 10;
echo'
<td width="', $avatar_max_table_width, 'px">', $news['avatar']['image'], '</td>';
}
echo '
<td>
<div>
<a href="', $news['href'], '">', $news['icon'], '</a> <b>', $news['subject'], '</b>
<div class="smaller">', $news['time'], ' ', $txt[525], ' ', $news['poster']['link'], '</div>

<div class="post" style="padding: 2ex 0;">', $news['body'], '</div>

', $news['link'], $news['locked'] ? '' : ' | ' . $news['comment_link'], '
</div>
</td>
</tr>';

if (!$news['is_last'])
echo '
<tr>
<td', $avatars == 1 ? ' colspan="2"' : '', '>
<hr style="margin: 2ex 0;" width="100%" />
</td>
</tr>';
}
echo '</table>';

For the second request, I should be possible with a database query. But why don't you just make a html or bbc block which you can update?
Title: Re: Custom Block Creation and Block Customization
Post by: bizref on September 20, 2008, 09:33:00 AM
Thank you for the first PHP code: could I request that instead of showing the actual post i just show the topic titles?

As for item #2, sure, I could do a PHP block and just update it myself ... would you be able to provide me the code?

Thanks so much!!
Title: Re: Custom Block Creation and Block Customization
Post by: Nathaniel on September 21, 2008, 07:41:25 PM
Well there are also some other parts for each topic in that block, here is a list. Can you please tell me which ones you want/don't want?

"x comments | Write Comment" links.
Time of topic post.
Message icon.
Poster link.
Title: Re: Custom Block Creation and Block Customization
Post by: bizref on September 21, 2008, 08:05:30 PM
Don't think I need these ..
Quote
Time of topic post.
Message icon.
Poster link.
Title: Re: Custom Block Creation and Block Customization
Post by: Nathaniel on September 21, 2008, 08:11:59 PM
Okay, try this code:
Code: [Select]
$limit = 5;
$start = 0;
$boards = array(1, 4);
$length = 0;

    global $scripturl, $db_prefix, $txt, $settings, $modSettings, $context;
global $func, $return;

loadLanguage('Stats');

$limit = max(0, $limit);
$start = max(0, $start);

// Make sure guests can see this board.
$request = db_query("
SELECT ID_BOARD
FROM {$db_prefix}boards
WHERE ID_BOARD IN (".implode(',',$boards).")
        AND FIND_IN_SET(-1, memberGroups)
LIMIT 1", __FILE__, __LINE__);
if (mysql_num_rows($request) == 0)
{
die($txt['smf_news_error2']);
}
list ($board) = mysql_fetch_row($request);
mysql_free_result($request);

// Find the post ids.
$request = db_query("
SELECT ID_FIRST_MSG
FROM {$db_prefix}topics
WHERE ID_BOARD IN (".implode(',',$boards).")
ORDER BY ID_FIRST_MSG DESC
LIMIT $start, $limit", __FILE__, __LINE__);
$posts = array();
while ($row = mysql_fetch_assoc($request))
$posts[] = $row['ID_FIRST_MSG'];
mysql_free_result($request);

if (empty($posts))
return array();

// Find the posts.
$request = db_query("
SELECT
m.subject, t.numReplies, t.ID_TOPIC, m.ID_MEMBER, m.ID_MSG, t.locked
FROM ({$db_prefix}topics AS t, {$db_prefix}messages AS m)
LEFT JOIN {$db_prefix}members AS mem ON (mem.ID_MEMBER = m.ID_MEMBER)
WHERE t.ID_FIRST_MSG IN (" . implode(', ', $posts) . ")
AND m.ID_MSG = t.ID_FIRST_MSG
ORDER BY t.ID_FIRST_MSG DESC
LIMIT " . count($posts), __FILE__, __LINE__);
$return = array();
while ($row = mysql_fetch_assoc($request))
{
censorText($row['subject']);

$return[] = array(
'subject' => $row['subject'],
'link' => '<a href="' . $scripturl . '?topic=' . $row['ID_TOPIC'] . '.0">' . $row['numReplies'] . ' ' . ($row['numReplies'] == 1 ? $txt['smf_news_1'] : $txt['smf_news_2']) . '</a>',
'comment_link' => !empty($row['locked']) ? '' : '<a href="' . $scripturl . '?action=post;topic=' . $row['ID_TOPIC'] . '.' . $row['numReplies'] . ';num_replies=' . $row['numReplies'] . '">' . $txt['smf_news_3'] . '</a>',
'locked' => !empty($row['locked']),
'is_last' => false,
);
}
mysql_free_result($request);

if (empty($return))
return $return;

$return[count($return) - 1]['is_last'] = true;

echo '<br />
<table cellpadding="0" cellspacing="0" border="0" width="100%" style="clear: both; table-layout: fixed;">';

foreach ($return as $news)
{
echo '
<tr>
<td>
<div>
<b>', $news['subject'], '</b><br />
', $news['link'], $news['locked'] ? '' : ' | ' . $news['comment_link'], '
</div>
</td>
</tr>';

if (!$news['is_last'])
echo '
<tr>
<td', $avatars == 1 ? ' colspan="2"' : '', '>
<hr style="margin: 2ex 0;" width="100%" />
</td>
</tr>';
}
echo '</table>';
Title: Re: Custom Block Creation and Block Customization
Post by: bizref on September 27, 2008, 09:51:56 AM
Thanks very much, works great ... but I don't think I understood your earlier question and would perfer to have these
Time of topic post.
Message icon.
Poster link.

rather than comments links ... but if it's too much trouble don't worry about it!
Title: Re: Custom Block Creation and Block Customization
Post by: Nathaniel on September 28, 2008, 07:33:16 AM
Okay, try the code below then:
Code: [Select]

// Limit the number of articles to show.
$limit = 5;
$start = 0;
// An array of board ids to show.
$boards = array(1, 4);
    // The length limit of each message shown.
$length = 0;
    // 0 = don't show avatars, 1= show.
$avatars = 0;

    global $scripturl, $db_prefix, $txt, $settings, $modSettings, $context;
global $func, $return;

loadLanguage('Stats');

$limit = max(0, $limit);
$start = max(0, $start);

// Load the message icons - the usual suspects.
$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 the post ids.
$request = db_query("
SELECT ID_FIRST_MSG
FROM {$db_prefix}topics
WHERE ID_BOARD IN (".implode(',',$boards).")
ORDER BY ID_FIRST_MSG DESC
LIMIT $start, $limit", __FILE__, __LINE__);
$posts = array();
while ($row = mysql_fetch_assoc($request))
$posts[] = $row['ID_FIRST_MSG'];
mysql_free_result($request);

if (empty($posts))
return array();

// Find the posts.
$request = db_query("
SELECT
m.icon, m.subject, IFNULL(mem.realName, m.posterName) AS posterName, m.posterTime,
t.ID_TOPIC, m.ID_MEMBER, m.ID_MSG
FROM ({$db_prefix}topics AS t, {$db_prefix}messages AS m)
LEFT JOIN {$db_prefix}members AS mem ON (mem.ID_MEMBER = m.ID_MEMBER)
WHERE t.ID_FIRST_MSG IN (" . implode(', ', $posts) . ")
AND m.ID_MSG = t.ID_FIRST_MSG
ORDER BY t.ID_FIRST_MSG DESC
LIMIT " . count($posts), __FILE__, __LINE__);
$return = array();
$colorids = array();
while ($row = mysql_fetch_assoc($request))
{

$row['body'] = parse_bbc($row['body'], $row['smileysEnabled'], $row['ID_MSG']);

// Check if the topic icon exists.
if (!isset($icon_sources[$row['icon']]))
$icon_sources[$row['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['icon'] . '.gif') ? 'images_url' : 'default_images_url';

// Check that this message icon is there...
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';

censorText($row['subject']);

//Collect the color ids :)
$colorids[$row['ID_MEMBER']] = $row['ID_MEMBER'];

$return[] = array(
'icon' => '<img src="' . $settings[$icon_sources[$row['icon']]] . '/post/' . $row['icon'] . '.gif" align="middle" alt="' . $row['icon'] . '" border="0" />',
'subject' => $row['subject'],
'time' => timeformat($row['posterTime']),
'href' => $scripturl . '?topic=' . $row['ID_TOPIC'] . '.0',
'poster' => array(
'link' => !empty($row['ID_MEMBER']) ? '<a href="' . $scripturl . '?action=profile;u=' . $row['ID_MEMBER'] . '">' . $row['posterName'] . '</a>' : $row['posterName']
),
'is_last' => false,
);
}
mysql_free_result($request);

if (empty($return))
return $return;

$return[count($return) - 1]['is_last'] = true;

if(!empty($colorids)) {
$color_profile = sp_loadColors($colorids);
foreach($return as $k => $p) {
if(!empty($color_profile[$p['poster']['id']])) {
$profile = $color_profile[$p['poster']['id']];
if(!empty($profile)) {
$return[$k]['poster']['link'] = $profile['link'];
}
}
}
}

echo '
<br />
<table cellpadding="0" cellspacing="0" border="0" width="100%" style="clear: both; table-layout: fixed;">';

foreach ($return as $news)
{
echo '
<tr>
<td>
<div>
<a href="', $news['href'], '">', $news['icon'], '</a> <b>', $news['subject'], '</b>
<div class="smaller">', $news['time'], ' ', $txt[525], ' ', $news['poster']['link'], '</div>
</div>
</td>
</tr>';

if (!$news['is_last'])
echo '
<tr>
<td', $avatars == 1 ? ' colspan="2"' : '', '>
<hr style="margin: 2ex 0;" width="100%" />
</td>
</tr>';
}
echo '
</table>';
Title: Re: Custom Block Creation and Block Customization
Post by: bizref on September 28, 2008, 09:33:37 PM
Perfect, thank you!!!!
Title: Re: Custom Block Creation and Block Customization
Post by: Tonino on December 23, 2008, 12:33:38 PM
Hi to all,
I'm trying to create a NEWS BLOCK (central top version) were I can display the latest topics
FROM EVERY FORUM (4 in total):

PS: I use SMF 2.04 + Latest SimplePortal

I copied the code below in the block (as reported from this topic http://simpleportal.net/index.php?topic=248.msg2329#msg2329 (http://simpleportal.net/index.php?topic=248.msg2329#msg2329))

BUT WHEN DISPLAYING THE BLOCK I HAVE THIS ERROR:
/home/xxxxxxxxxx/public_html/Sources/SPortal2.php(1874) : eval()'d code on line 20

I looked on line 20 and is indicating:
$request = db_query("  (Is this request used for the SMF previous versions ?)

I'm not familiar with PHP and neither with the newest request as below
$request = $smcFunc['db_query']('', '

I would appreciate if this block COULD BE USED for SMF 2.04 + Latest SimplePortal

MANY MANY THANKS IN ADVANCE
___________________________________________________________ __
 
   // Limit the number of articles to show.
    $limit = 5;
   $start = 0;
    // An array of board ids to show.
   $boards = array(1, 4);
   // The length limit of each message shown.
   $length = 0;
        // 0 = don't show avatars, 1= show.
        $avatars = 0;   

        global $scripturl, $db_prefix, $txt, $settings, $modSettings, $context;
   global $func, $return;

   loadLanguage('Stats');

   $limit = max(0, $limit);
   $start = max(0, $start);

   // Make sure guests can see this board.
   $request = db_query("
      SELECT ID_BOARD
      FROM {$db_prefix}boards
      WHERE ID_BOARD IN (".implode(',',$boards).")
        AND FIND_IN_SET(-1, memberGroups)
      LIMIT 1", __FILE__, __LINE__);
   if (mysql_num_rows($request) == 0)
   {
      die($txt['smf_news_error2']);
   }
   list ($board) = mysql_fetch_row($request);
   mysql_free_result($request);

   // Load the message icons - the usual suspects.
   $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 the post ids.
   $request = db_query("
      SELECT ID_FIRST_MSG
      FROM {$db_prefix}topics
      WHERE ID_BOARD IN (".implode(',',$boards).")
      ORDER BY ID_FIRST_MSG DESC
      LIMIT $start, $limit", __FILE__, __LINE__);
   $posts = array();
   while ($row = mysql_fetch_assoc($request))
      $posts[] = $row['ID_FIRST_MSG'];
   mysql_free_result($request);

   if (empty($posts))
      return array();

   // Find the posts.
   $request = db_query("
      SELECT
         m.icon, m.subject, m.body, IFNULL(mem.realName, m.posterName) AS posterName, m.posterTime,
         t.numReplies, t.ID_TOPIC, m.ID_MEMBER, m.smileysEnabled, m.ID_MSG, t.locked, mem.avatar, a.ID_ATTACH, a.attachmentType, a.filename
      FROM ({$db_prefix}topics AS t, {$db_prefix}messages AS m)
         LEFT JOIN {$db_prefix}members AS mem ON (mem.ID_MEMBER = m.ID_MEMBER)
         LEFT JOIN {$db_prefix}attachments AS a ON (a.ID_MEMBER = m.ID_MEMBER)
      WHERE t.ID_FIRST_MSG IN (" . implode(', ', $posts) . ")
         AND m.ID_MSG = t.ID_FIRST_MSG
      ORDER BY t.ID_FIRST_MSG DESC
      LIMIT " . count($posts), __FILE__, __LINE__);
   $return = array();
   $colorids = array();
   while ($row = mysql_fetch_assoc($request))
   {
      // If we want to limit the length of the post.
      if (!empty($length) && $func['strlen']($row['body']) > $length)
      {
         $row['body'] = $func['substr']($row['body'], 0, $length);

         // The first space or line break. (<br />, etc.)
         $cutoff = max(strrpos($row['body'], ' '), strrpos($row['body'], '<'));

         if ($cutoff !== false)
            $row['body'] = $func['substr']($row['body'], 0, $cutoff);
         $row['body'] .= '...';
      }

      $row['body'] = parse_bbc($row['body'], $row['smileysEnabled'], $row['ID_MSG']);

      // Check if the topic icon exists.
      if (!isset($icon_sources[$row['icon']]))
         $icon_sources[$row['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['icon'] . '.gif') ? 'images_url' : 'default_images_url';
     
      if (stristr($row['avatar'], 'http://') && !empty($modSettings['avatar_check_size']))
      {
         $sizes = url_image_size($row['avatar']);

         // Does your avatar still fit the maximum size?
         if ($modSettings['avatar_action_too_large'] == 'option_refuse' && is_array($sizes) && (($sizes[0] > $modSettings['avatar_max_width_external'] && !empty($modSettings['avatar_max_width_external'])) || ($sizes[1] > $modSettings['avatar_max_height_external'] && !empty($modSettings['avatar_max_height_external']))))
         {
            // Fix it permanently!
            $row['avatar'] = '';
            updateMemberData($row['ID_MEMBER'], array('avatar' => '\'\''));
         }
      }

      // Check that this message icon is there...
      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';

      censorText($row['subject']);
      censorText($row['body']);
     
      $colorids[$row['ID_MEMBER']] = $row['ID_MEMBER'];

      $return[] = array(
         'id' => $row['ID_TOPIC'],
         'message_id' => $row['ID_MSG'],
         'icon' => '<img src="' . $settings[$icon_sources[$row['icon']]] . '/post/' . $row['icon'] . '.gif" align="middle" alt="' . $row['icon'] . '" border="0" />',
         'subject' => $row['subject'],
         'time' => timeformat($row['posterTime']),
         'timestamp' => forum_time(true, $row['posterTime']),
         'body' => $row['body'],
         'href' => $scripturl . '?topic=' . $row['ID_TOPIC'] . '.0',
         'link' => '<a href="' . $scripturl . '?topic=' . $row['ID_TOPIC'] . '.0">' . $row['numReplies'] . ' ' . ($row['numReplies'] == 1 ? $txt['smf_news_1'] : $txt['smf_news_2']) . '</a>',
         'replies' => $row['numReplies'],
         'comment_href' => !empty($row['locked']) ? '' : $scripturl . '?action=post;topic=' . $row['ID_TOPIC'] . '.' . $row['numReplies'] . ';num_replies=' . $row['numReplies'],
         'comment_link' => !empty($row['locked']) ? '' : '<a href="' . $scripturl . '?action=post;topic=' . $row['ID_TOPIC'] . '.' . $row['numReplies'] . ';num_replies=' . $row['numReplies'] . '">' . $txt['smf_news_3'] . '</a>',
         'new_comment' => !empty($row['locked']) ? '' : '<a href="' . $scripturl . '?action=post;topic=' . $row['ID_TOPIC'] . '.' . $row['numReplies'] . '">' . $txt['smf_news_3'] . '</a>',
         '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']) ? '<a href="' . $scripturl . '?action=profile;u=' . $row['ID_MEMBER'] . '">' . $row['posterName'] . '</a>' : $row['posterName']
         ),
         'locked' => !empty($row['locked']),
         'is_last' => false,
         'avatar' => array(
            'name' => $row['avatar'],
            'image' => $row['avatar'] == '' ? ($row['ID_ATTACH'] > 0 ? '<img src="' . (empty($row['attachmentType']) ? $scripturl . '?action=dlattach;attach=' . $row['ID_ATTACH'] . ';type=avatar' : $modSettings['custom_avatar_url'] . '/' . $row['filename']) . '" alt="" class="avatar" border="0" />' : '') : (stristr($row['avatar'], 'http://') ? '<img src="' . $row['avatar'] . '" alt="" class="avatar" border="0" />' : '<img src="' . $modSettings['avatar_url'] . '/' . htmlspecialchars($row['avatar']) . '" alt="" class="avatar" border="0" />'),
            'href' => $row['avatar'] == '' ? ($row['ID_ATTACH'] > 0 ? (empty($row['attachmentType']) ? $scripturl . '?action=dlattach;attach=' . $row['ID_ATTACH'] . ';type=avatar' : $modSettings['custom_avatar_url'] . '/' . $row['filename']) : '') : (stristr($row['avatar'], 'http://') ? $row['avatar'] : $modSettings['avatar_url'] . '/' . $row['avatar']),
            'url' => $row['avatar'] == '' ? '' : (stristr($row['avatar'], 'http://') ? $row['avatar'] : $modSettings['avatar_url'] . '/' . $row['avatar']),
         ),
      );
   }
   mysql_free_result($request);

   if (empty($return))
      return $return;

   $return[count($return) - 1]['is_last'] = true;
   
   if(!empty($colorids)) {
      $color_profile = sp_loadColors($colorids);
      foreach($return as $k => $p) {
         if(!empty($color_profile[$p['poster']['id']])) {
            $profile = $color_profile[$p['poster']['id']];
            if(!empty($profile)) {
               $return[$k]['poster']['link'] = $profile['link'];
            }
         }
      }
   }

      echo '<br />
      <table cellpadding="0" cellspacing="0" border="0" width="100%" style="clear: both; table-layout: fixed;">';

      foreach ($return as $news)
      {
      echo '
         <tr>';
         if($avatars == 1) {
            $avatar_max_table_width = max($modSettings['avatar_max_width_upload'], $modSettings['avatar_max_width_external']) + 10;
            echo'
               <td width="', $avatar_max_table_width, 'px">', $news['avatar']['image'], '</td>';
         }
         echo '
            <td>
         <div>
            <a href="', $news['href'], '">', $news['icon'], '</a> <b>', $news['subject'], '</b>
            <div class="smaller">', $news['time'], ' ', $txt[525], ' ', $news['poster']['link'], '</div>

            <div class="post" style="padding: 2ex 0;">', $news['body'], '</div>

            ', $news['link'], $news['locked'] ? '' : ' | ' . $news['comment_link'], '
         </div>
            </td>
         </tr>';

      if (!$news['is_last'])
         echo '
         <tr>
            <td', $avatars == 1 ? ' colspan="2"' : '', '>
               <hr style="margin: 2ex 0;" width="100%" />
            </td>
         </tr>';
      }
      echo '</table>';
___________________________________________________________ _________________



SimplePortal 2.3.8 © 2008-2024, SimplePortal