SimplePortal

Customization => Blocks and Modifications => Block Requests => Topic started by: Elyes on June 06, 2009, 08:36:09 AM

Title: Collapsible block news !
Post by: Elyes on June 06, 2009, 08:36:09 AM
Hi everyone!

I've used this code to have a "news block" on my portal

Code: [Select]

        // Limit the number of articles to show.
        $limit = 10;
$start = 0;
        // An array of board ids to show.
$boards = array(8,35,36,37,25);
        // 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'], '<b>', $news['subject'], '</b></a>

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

But I need an upgrade !  >:-D

To be very cool, this block must display collapsible news! Each news must be collapsible one by one, a user can see only news interesting himself  :)

Thanks for your helps, and sorry for my bad english !

Title: Re: Collapsible block news !
Post by: Elyes on June 10, 2009, 04:15:54 AM
Bump ?! :)
Title: Re: Collapsible block news !
Post by: ianus on June 10, 2009, 06:06:11 AM
This can be done with some scripts.
Example:
http://dynamicdrive.com/dynamicindex17/animatedcollapse.htm

I have done this some time ago, well and deleted it again. So I can't offer you an example.

This part should be included into the index_template
Code: [Select]
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript" src="animatedcollapse.js">

/***********************************************
* Animated Collapsible DIV v2.2- (c) Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for this script and 100s more
***********************************************/

</script>

For my page, I have written an "stand alone" page with the rest of Step 1 and the code of Step2.
Your costom code (in my case some of the ssi_recent topics), can be put into the <b>Content inside DIV!</b><br /> part.

To include the "stand alone page", you can use a php-block and include('link to file')';

You can choose another script of course. This will work also (http://dynamicdrive.com/dynamicindex17/tabcontent.htm)
SimplePortal 2.3.8 © 2008-2024, SimplePortal