SimplePortal

Customization => Blocks and Modifications => Mod Requests => Topic started by: techprince on December 29, 2008, 06:44:56 AM

Title: Board News Tabular Block
Post by: techprince on December 29, 2008, 06:44:56 AM
The tabular block of board news which was in Simple Portal 2.0.5 was discontinued. So is there any way to add tabular board news block with parameters in version 2.1.1?
Title: Re: Board News Tabular Block
Post by: [SiNaN] on January 01, 2009, 09:13:35 AM
SPortal1-1.php

Find:

Code: [Select]
foreach ($return as $news)
{
echo '
<div class="tborder">
<table class="bordercolor" cellspacing="0" width="100%">
<tr class="catbg">
<td valign="middle">', $news['icon'], '</td>
<td valign="middle" width="100%" style="padding: 5px;"><a href="', $news['href'], '">', $news['subject'], '</a> | ', $news['timeyear'], '</td>
</tr>
<tr class="windowbg">
<td style="padding: 5px;" colspan="2">';

if($avatars && $news['avatar']['name'] !== null && !empty($news['avatar']['href']))
echo '
<img src="' . $news['avatar']['href'] . '" alt="' . $news['poster']['name'] . '" width="30" style="float: right;" />
<div style="font-size: 11px;">', $news['timeday'], ' ', $txt[525], ' ', $news['poster']['link'], '<br />', $txt['sp-articlesViews'], ': ', $news['views'], ' | ', $txt['sp-articlesComments'], ': ', $news['replies'], '</div>';
else
echo '
<div style="font-size: 11px;">', $news['timeday'], ' ', $txt[525], ' ', $news['poster']['link'], ' | ', $txt['sp-articlesViews'], ': ', $news['views'], ' | ', $txt['sp-articlesComments'], ': ', $news['replies'], '</div>';

echo '
<hr />
<div class="post">', $news['body'], '<br/><br/>
</div>
</td>
</tr>
<tr>
<td class="windowbg2" colspan="2">
<div style="float: right; padding: 5px;" >', $news['link'], ' | ',  $news['new_comment'], '</div>
</td>
</tr>
</table>
</div>
<br />';
}

Replace:

Code: [Select]
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 && $news['avatar']['name'] !== null && !empty($news['avatar']['href']))
echo '
<td>
<img src="' . $news['avatar']['href'] . '" alt="' . $news['poster']['name'] . '" width="30" style="float: right;" />
</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 ? ' colspan="2"' : '', '>
<hr style="margin: 2ex 0;" width="100%" />
</td>
</tr>';
}

echo '
</table>';

SPortalBlocks1-1.template.php

Find and Remove:

Code: [Select]
if ($block['type'] == 'sp_boardNews')
{
$parameters = explode(',', $block['parameters']);
$block['type']($parameters);

echo '
<br />';

return;
}
Title: Re: Board News Tabular Block
Post by: techprince on January 04, 2009, 03:02:36 AM
This will replace the existing style. I wanted a new block with tabular style.
Title: Re: Board News Tabular Block
Post by: techprince on January 21, 2009, 06:32:46 PM
Urgently needed.. plz
Title: Re: Board News Tabular Block
Post by: [SiNaN] on February 02, 2009, 10:57:34 AM
Sorry for delayed response. Try these codes in a PHP block:

Code: [Select]
global $scripturl, $db_prefix, $txt, $settings, $modSettings, $context;
global $smcFunc, $return, $color_profile, $func;

loadLanguage('Stats');

$board = 1;
$limit = 5;
$start = 0;
$length = 250;
$avatars = 1;

$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 " . ($board === null ? '' : "ID_BOARD = $board
AND ") . "FIND_IN_SET(-1, memberGroups)
LIMIT 1", __FILE__, __LINE__);
if (mysql_num_rows($request) == 0)
{
echo $txt['smf_news_error2'];
return false;
}
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 = $board
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.numViews, 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))
{
//on html replace the length... to prevent style errors... normal only admin can use this so this is the admin fault! Boardnews
$oldlength = $length;
if(stripos($row['body'], '[html]') !== false) {
$length = strrpos(strtolower($row['body']), '[/html]')+7;
}

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

//So is there a unclosed bbc near the end try to truncate them
if(strrpos($row['body'], '[') > strrpos($row['body'], ']')) {
$row['body'] = $func['substr']($row['body'], 0, strrpos($row['body'], '['));
$row['body'] .= '...';
}

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

//Fix the the html fix for admins back to an normal way =).
if($oldlength != $length)
$length = $oldlength;

// 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 :)
if(!empty($row['ID_MEMBER']))
$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']),
'timeyear' => timeformat($row['posterTime'], '%d %b %y'),
'timeday' => timeformat($row['posterTime'], '%H:%M:%S'),
'timestamp' => forum_time(true, $row['posterTime']),
'views' => $row['numViews'],
'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;

//Give some colors to the nice poster links :)
if(!empty($colorids) && sp_loadColors($colorids) !== false)
foreach($return as $k => $p)
if(!empty($color_profile[$p['poster']['id']]['link']))
$return[$k]['poster']['link'] = $color_profile[$p['poster']['id']]['link'];

   echo '
      <table cellpadding="0" cellspacing="0" border="0" width="100%">';

   foreach ($return as $news)
   {
      echo '
         <tr>
            <td>', $avatars && $news['avatar']['name'] !== null && !empty($news['avatar']['href']) ? '
               <img src="' . $news['avatar']['href'] . '" alt="' . $news['poster']['name'] . '" width="30" style="float: right;" />' : '', '
               <div>
                  <div style="float: left; padding-right: 5px;"><a href="', $news['href'], '">', $news['icon'], '</a></div><b>', $news['subject'], '</b>
                  <div class="smalltext">', $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>
               <hr style="margin: 2ex 0;" width="100%" />
            </td>
         </tr>';
      }

      echo '
      </table>';
Title: Re: Board News Tabular Block
Post by: raasaa on March 02, 2009, 02:55:42 PM
i put the above code into a new php block on SP 2.1.1

This is the error message i get

Quote
Fatal error: Call to undefined function db_query() in /home/konoha/konoha/smf/Sources/SPortal2.php(1863) : eval()'d code on line 16
SimplePortal 2.3.8 © 2008-2024, SimplePortal