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 login or register.

* Who's Online

  • Dot Guests: 238
  • Dot Hidden: 0
  • Dot Users: 0

There aren't any users online.

* Shoutbox

Refresh History
  • Shoutbox is not for support!
  • {OCS}MasterSeal: Yup, Still adore SP
    April 21, 2019, 07:08:06 PM
  • {OCS}MasterSeal: STILL love SP :)
    November 24, 2018, 05:05:50 AM
  • ♦ Ninja ZX-10RR ♦: <3 aegersz
    September 13, 2018, 03:36:09 PM
  • aegersz: I STILL <3 LOVE SimplePortal
    September 13, 2018, 07:11:39 AM
  • aegersz: o LOVE you guys - Simple Portal rocks !
    May 09, 2018, 05:18:59 AM
  • Chen Zhen: our apologies for the site being down.. please read server issues topic
    March 22, 2018, 05:32:38 AM
  • {OCS}MasterSeal: LOL PLEASE forget I just posted that. I found the answer in my own dang post back in 2015. lol sorry!
    July 04, 2017, 10:47:55 PM
  • {OCS}MasterSeal: I know this SB isnt' for support, but I just have a general question. Who would I contact to find out where SP stores its block info? Is it DB driven or files? I searched the site but came up with nothing. probably my fault any insight is appreciated.
    July 04, 2017, 10:43:36 PM
  • ♦ Ninja ZX-10RR ♦: Excuse me but what does Simpleportal have to deal with that?
    February 05, 2017, 08:21:14 PM
  • WhiteEagle: of course IMHO that site appears to be dead :(
    February 04, 2017, 01:08:05 PM
  • WhiteEagle: If I can get that, then I'll use it for that site...
    February 04, 2017, 01:07:35 PM
  • WhiteEagle: decided to not use SMF for any projects, unless I can get a copy of the premium version of the fanfiction archive plugin
    February 04, 2017, 01:06:54 PM
  • expertdecisions: cloudflare
    January 28, 2017, 08:01:47 AM
  • aegersz: SM release 2.0.13 !
    January 12, 2017, 06:00:13 AM
  • raffo: Tks Emanuele, even if I didn't understand the fix :D
    November 07, 2016, 02:01:20 AM
  • emanuele: [link]
    November 01, 2016, 12:43:50 PM
  • emanuele: raffo: the English support board is a good place. ;)
    November 01, 2016, 12:43:38 PM
  • raffo: Where can I find the fix for the shoutbox?
    November 01, 2016, 05:06:09 AM
  • {OCS}MasterSeal: To the SP team, I make a point to come here and thank you as much as possible for your work.  so again, THANK YOU!
    October 28, 2016, 10:38:05 AM
  • emanuele: That's indeed funny, the limit is present only in the patch and not the full install.
    October 22, 2016, 06:14:58 PM

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

Blocks speak! Do you have an interest in getting more blocks - or even making your own? The Blocks Board is for you!

Author Topic: Custom Block Creation and Block Customization  (Read 9151 times)

0 Members and 1 Guest are viewing this topic.

Offline bizref

  • Semi Newbie
  • *
  • Posts: 27
Custom Block Creation and Block Customization
« 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.

Offline ccbtimewiz

  • Hero Member
  • *****
  • Posts: 2185
  • Gender: Male
  • $("div.content:dd").hide();
  • SMF Version: None
  • SP Version: None
  • Elkarte Version: None
  • EhPortal Version: None
Re: Custom Block Creation and Block Customization
« Reply #1 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. :)

Offline Nathaniel

  • Comrade
  • *
  • Posts: 5203
  • Gender: Male
    • Verbtest.com
  • SMF Version: 2 RC4
  • SP Version: 2.3.3
Re: Custom Block Creation and Block Customization
« Reply #2 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'.
SMF Friend (Former Support Specialist) | SimplePortal DeveloperMy SMF Mods | SimplePortal"Quis custodiet ipsos custodes?" - Who will Guard the Guards?Please don't send me ANY support related PMs. I will just delete them.

Offline bizref

  • Semi Newbie
  • *
  • Posts: 27
Re: Custom Block Creation and Block Customization
« Reply #3 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 ....!!!

Offline bizref

  • Semi Newbie
  • *
  • Posts: 27
Re: Custom Block Creation and Block Customization
« Reply #4 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?

Offline Nathaniel

  • Comrade
  • *
  • Posts: 5203
  • Gender: Male
    • Verbtest.com
  • SMF Version: 2 RC4
  • SP Version: 2.3.3
Re: Custom Block Creation and Block Customization
« Reply #5 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?
SMF Friend (Former Support Specialist) | SimplePortal DeveloperMy SMF Mods | SimplePortal"Quis custodiet ipsos custodes?" - Who will Guard the Guards?Please don't send me ANY support related PMs. I will just delete them.

Offline bizref

  • Semi Newbie
  • *
  • Posts: 27
Re: Custom Block Creation and Block Customization
« Reply #6 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!

Offline Nathaniel

  • Comrade
  • *
  • Posts: 5203
  • Gender: Male
    • Verbtest.com
  • SMF Version: 2 RC4
  • SP Version: 2.3.3
Re: Custom Block Creation and Block Customization
« Reply #7 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?
« Last Edit: September 19, 2008, 04:21:29 AM by LHVWB »
SMF Friend (Former Support Specialist) | SimplePortal DeveloperMy SMF Mods | SimplePortal"Quis custodiet ipsos custodes?" - Who will Guard the Guards?Please don't send me ANY support related PMs. I will just delete them.

Offline bizref

  • Semi Newbie
  • *
  • Posts: 27
Re: Custom Block Creation and Block Customization
« Reply #8 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!!

Offline Nathaniel

  • Comrade
  • *
  • Posts: 5203
  • Gender: Male
    • Verbtest.com
  • SMF Version: 2 RC4
  • SP Version: 2.3.3
Re: Custom Block Creation and Block Customization
« Reply #9 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.
SMF Friend (Former Support Specialist) | SimplePortal DeveloperMy SMF Mods | SimplePortal"Quis custodiet ipsos custodes?" - Who will Guard the Guards?Please don't send me ANY support related PMs. I will just delete them.

Offline bizref

  • Semi Newbie
  • *
  • Posts: 27
Re: Custom Block Creation and Block Customization
« Reply #10 on: September 21, 2008, 08:05:30 PM »
Don't think I need these ..
Quote
Time of topic post.
Message icon.
Poster link.

Offline Nathaniel

  • Comrade
  • *
  • Posts: 5203
  • Gender: Male
    • Verbtest.com
  • SMF Version: 2 RC4
  • SP Version: 2.3.3
Re: Custom Block Creation and Block Customization
« Reply #11 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>';
SMF Friend (Former Support Specialist) | SimplePortal DeveloperMy SMF Mods | SimplePortal"Quis custodiet ipsos custodes?" - Who will Guard the Guards?Please don't send me ANY support related PMs. I will just delete them.

Offline bizref

  • Semi Newbie
  • *
  • Posts: 27
Re: Custom Block Creation and Block Customization
« Reply #12 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!

Offline Nathaniel

  • Comrade
  • *
  • Posts: 5203
  • Gender: Male
    • Verbtest.com
  • SMF Version: 2 RC4
  • SP Version: 2.3.3
Re: Custom Block Creation and Block Customization
« Reply #13 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>';
SMF Friend (Former Support Specialist) | SimplePortal DeveloperMy SMF Mods | SimplePortal"Quis custodiet ipsos custodes?" - Who will Guard the Guards?Please don't send me ANY support related PMs. I will just delete them.

Offline bizref

  • Semi Newbie
  • *
  • Posts: 27
Re: Custom Block Creation and Block Customization
« Reply #14 on: September 28, 2008, 09:33:37 PM »
Perfect, thank you!!!!

Offline Tonino

  • Semi Newbie
  • *
  • Posts: 10
Re: Custom Block Creation and Block Customization
« Reply #15 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)

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