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: 407
  • 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]

Installation errors? Mod incompatibilities? Upgrade problems? Make your way over to the Install and Upgrade Support board for all your solutions!

Author Topic: custom ssi code need some help with  (Read 3177 times)

0 Members and 1 Guest are viewing this topic.

Offline Ares

  • Jr. Member
  • **
  • Posts: 50
  • Gender: Male
  • World Of Mass Distruction
    • [SoW] Spoils of War
  • SMF Version: 2.0.5
  • SP Version: 2.3.5
custom ssi code need some help with
« on: March 05, 2011, 01:54:35 AM »
added to ssi.php
Code: [Select]
// Arantor: ssi_multiBoardNews
function ssi_multiBoardNews($parameters)
{
global $scripturl, $db_prefix, $txt, $settings, $modSettings, $context, $smcFunc, $user_profile;

loadLanguage('Stats');

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

$feed_types = array('rss', 'rdf', 'atom', 'none');
$attach_types = array('none', 'linkonly', 'thumbnail', 'inline');
$avatar_types = array('none', 'left', 'right');

// Checking off the parameters first
$parameters['limit'] = isset($parameters['limit']) ? max(1, (int) $parameters['limit']) : 5;
$parameters['start'] = isset($parameters['start']) ? max(0, (int) $parameters['start']) : 0;
$parameters['length'] = isset($parameters['length']) ? (int) $parameters['length'] : 0;
$parameters['perms_override'] = isset($parameters['perms_override']) ? (bool) $parameters['perms_override'] : false;
$parameters['attachments'] = isset($parameters['attachments']) ? (in_array($parameters['attachments'], $attach_types) ? $parameters['attachments'] : 'none') : 'none';
$parameters['avatar'] = isset($parameters['avatar']) ? (in_array($parameters['avatar'], $avatar_types) ? $parameters['avatar'] : 'none') : 'none';

$parameters['feed'] = isset($parameters['feed']) ? (array) $parameters['feed'] : array('none');
$parameters['feed'] = array_intersect($parameters['feed'], $feed_types);
if (count($parameters['feed']) == 0)
$parameters['feed'] = array('none');

$parameters['board'] = isset($parameters['board']) ? (array) $parameters['board'] : array(0);
$parameters['category'] = isset($parameters['category']) ? (array) $parameters['category'] : array(0);
$parameters['board_disp'] = isset($parameters['board_disp']) ? (bool) $parameters['board_disp'] : true;
$parameters['category_disp'] = isset($parameters['category_disp']) ? (bool) $parameters['category_disp'] : false;

$parameters['icon'] = isset($parameters['icon']) ? (array) $parameters['icon'] : array();
$parameters['icon'] = array_intersect(array_unique($parameters['icon']), $stable_icons);

$parameters['output_type'] = isset($parameters['output_type']) ? ($parameters['output_type'] == 'echo' ? 'echo' : 'array') : 'echo';

foreach ($parameters['board'] as $key => $value)
{
$value = (int) $value;
if ($value < 1)
unset ($parameters['board'][$key]);
else
$parameters['board'][$key] = (int) $value;
}

if (!empty($parameters['category']))
{
$parameters['category'] = array_unique((array) $parameters['category']);
foreach ($parameters['category'] as $key => $value)
{
$value = (int) $value;
if ($value < 1)
unset ($parameters['category'][$key]);
else
$parameters['category'][$key] = (int) $value;
}

if (count($parameters['category']) > 0)
{
$query = $smcFunc['db_query']('', '
SELECT id_board FROM {db_prefix}boards WHERE id_cat IN ({array_int:cat_list})',
array(
'cat_list' => $parameters['category'],
)
);
while($row = $smcFunc['db_fetch_row']($query))
$parameters['board'][] = $row[0];

$smcFunc['db_free_result']($query);
}
}

$parameters['board'] = array_unique($parameters['board']);

if (count($parameters['board']) == 0)
$parameters['board'] = array(0);

if (!$parameters['perms_override'])
{
// So we're checking the guest perms here. Note this can only be done from a PHP call.
// You can't do this from an external SSI type include (via $_GET) for obvious reasons!

$board_count = count($parameters['board']);

$board_limit = 1;
$where = 'FIND_IN_SET(-1, member_groups)';
if ($board_count > 1)
{
$where = 'id_board IN ({array_int:board_list}) AND ' . $where;
$board_limit = $board_count;
}

// So, either get all boards we asked for and check their membergroups,
// or we asked for nothing, so get the first board you find that is guest safe

$request = $smcFunc['db_query']('', '
SELECT id_board
FROM {db_prefix}boards
WHERE ' . $where . '
LIMIT {int:limit}',
array(
'board_list' => $parameters['board'],
'limit' => $board_limit,
)
);
if ($smcFunc['db_num_rows']($request) == 0)
{
if ($output_method == 'echo')
die($txt['ssi_no_guests']);
else
return array();
}

$allowed_boards = array();
while($row = $smcFunc['db_fetch_row']($request))
$allowed_boards[] = $row[0];
$smcFunc['db_free_result']($request);

if ($board_count > 0)
$parameters['board'] = array_intersect($parameters['board'], $allowed_boards);
else
$parameters['board'] = $allowed_boards;

if (count($parameters['board']) == 0)
$parameters['board'] = array(0);
}

// Find the post ids.
$request = $smcFunc['db_query']('', '
SELECT id_first_msg, icon
FROM {db_prefix}topics AS t INNER JOIN {db_prefix}messages AS m ON (t.id_first_msg = m.id_msg)
WHERE t.id_board IN ({array_int:board_list})' . (count($parameters['icon']) > 0 ? '
AND m.icon IN ({array_string:icon})' : '') . ($modSettings['postmod_active'] ? '
AND t.approved = {int:is_approved}' : '') . '
ORDER BY id_first_msg DESC
LIMIT ' . $parameters['start'] . ', ' . $parameters['limit'],
array(
'board_list' => $parameters['board'],
'is_approved' => 1,
'icon' => $parameters['icon'],
)
);

$posts = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
$posts[] = $row['id_first_msg'];
$smcFunc['db_free_result']($request);

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

// Find the posts.
$request = $smcFunc['db_query']('', '
SELECT
m.icon, m.subject, m.body, IFNULL(mem.real_name, m.poster_name) AS poster_name, m.poster_time,
t.num_replies, t.id_topic, m.id_member, m.smileys_enabled, m.id_msg, t.locked, t.id_board, b.name AS board_name, c.id_cat, c.name AS cat_name
FROM {db_prefix}topics AS t
INNER JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_first_msg)
LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)
INNER JOIN {db_prefix}boards AS b ON (t.id_board = b.id_board)
INNER JOIN {db_prefix}categories AS c ON (b.id_cat = c.id_cat)
WHERE t.id_first_msg IN ({array_int:post_list})
ORDER BY t.id_first_msg DESC
LIMIT ' . count($posts),
array(
'post_list' => $posts,
)
);
$return = array();
$posters = array();
$messages = array();
$last = 0;
while ($row = $smcFunc['db_fetch_assoc']($request))
{
// If we want to limit the length of the post.
if ($parameters['length'] > 0 && $smcFunc['strlen']($row['body']) > $parameters['length'])
{
$row['body'] = $smcFunc['substr']($row['body'], 0, $parameters['length']);

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

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

$row['body'] = parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']);

// 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']);

$return['topics'][$row['id_topic']] = array(
'id' => $row['id_topic'],
'board' => array(
'id' => $row['id_board'],
'name' => $row['board_name'],
'href' => $scripturl . '?board=' . $row['id_board'] . '.0',
'link' => '<a href="' . $scripturl . '?topic=' . $row['id_board'] . '.0">' . $row['board_name'] . '</a>',
),
'category' => array(
'id' => $row['id_cat'],
'name' => $row['cat_name'],
'href' => $scripturl . '#c' . $row['id_cat'],
'link' => '<a href="' . $scripturl . '#c' . $row['id_cat'] . '">' . $row['cat_name'] . '</a>',
),
'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['poster_time']),
'timestamp' => forum_time(true, $row['poster_time']),
'body' => $row['body'],
'href' => $scripturl . '?topic=' . $row['id_topic'] . '.0',
'link' => '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $row['num_replies'] . ' ' . ($row['num_replies'] == 1 ? $txt['ssi_comment'] : $txt['ssi_comments']) . '</a>',
'replies' => $row['num_replies'],
'comment_href' => !empty($row['locked']) ? '' : $scripturl . '?action=post;topic=' . $row['id_topic'] . '.' . $row['num_replies'] . ';num_replies=' . $row['num_replies'],
'comment_link' => !empty($row['locked']) ? '' : '<a href="' . $scripturl . '?action=post;topic=' . $row['id_topic'] . '.' . $row['num_replies'] . ';num_replies=' . $row['num_replies'] . '">' . $txt['ssi_write_comment'] . '</a>',
'new_comment' => !empty($row['locked']) ? '' : '<a href="' . $scripturl . '?action=post;topic=' . $row['id_topic'] . '.' . $row['num_replies'] . '">' . $txt['ssi_write_comment'] . '</a>',
'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']) ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['poster_name'] . '</a>' : $row['poster_name']
),
'locked' => !empty($row['locked']),
'is_last' => false,
);
$posters[$row['id_member']][] = $row['id_topic'];
$messages[] = $row['id_msg'];
$last = $row['id_topic'];
}

$smcFunc['db_free_result']($request);

// Get all the attachments, but only if we actually want them
if ($parameters['attachments'] != 'none' && !empty($modSettings['attachmentEnable']) && count(array_intersect($parameters['board'], boardsAllowedTo('view_attachments'))) > 0)
{
$request = $smcFunc['db_query']('', '
SELECT
a.id_attach, a.id_folder, a.id_msg, a.filename, IFNULL(a.size, 0) AS filesize, a.downloads, a.approved,
a.width, a.height, IFNULL(thumb.id_attach, 0) AS id_thumb, thumb.width AS thumb_width, thumb.height AS thumb_height, m.id_topic
FROM {db_prefix}attachments AS a
LEFT JOIN {db_prefix}attachments AS thumb ON (thumb.id_attach = a.id_thumb)
INNER JOIN {db_prefix}messages AS m ON (a.id_msg = m.id_msg)
WHERE a.id_msg IN ({array_int:message_list})
AND a.attachment_type = {int:attachment_type}' . (!$modSettings['postmod_active'] || allowedTo('approve_posts') ? '' : '
AND a.approved = {int:is_approved}'),
array(
'message_list' => $messages,
'attachment_type' => 0,
'is_approved' => 1,
)
);
$temp = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
{
$temp[$row['id_attach']] = $row;
if (!isset($attachments[$row['id_msg']]))
$attachments[$row['id_msg']] = array();
}
$smcFunc['db_free_result']($request);

// This is better than sorting it with the query...
ksort($temp);

foreach ($temp as $attach_single)
{
$attachment = array(
'href' => $scripturl . '?action=dlattach;topic=' . $attach_single['id_topic'] . '.0;attach=' . $attach_single['id_attach'],
'filename' => htmlspecialchars($attach_single['filename']),
'filesize' => round($attach_single['filesize'] / 1024, 2) . ' ' . $txt['kilobyte'],
'width' => $attach_single['width'],
'height' => $attach_single['height'],
'imgsize' => $attach_single['width'] > 0 ? $attach_single['width'] . 'x' . $attach_single['height'] : '',
'downloads' => $txt['attach_viewed'] . ' ' . $attach_single['downloads'] . ' ' . $txt['attach_times'],
);
$attachment['thumbnail'] = $attach_single['id_thumb'] == 0 ? false : array(
'href' => $scripturl . '?action=dlattach;topic=' . $attach_single['id_topic'] . '.0;attach=' . $attach_single['id_thumb'] . ';image',
'width' => $attach_single['thumb_width'],
'height' => $attach_single['thumb_height'],
);
$return['topics'][$attach_single['id_topic']]['attachments'][] = $attachment;
}
}

// Get all the avatars, but only if we actually want them, then attach to the posts!
if ($parameters['avatar'] != 'none')
{
if ($modSettings['avatar_action_too_large'] == 'option_html_resize' || $modSettings['avatar_action_too_large'] == 'option_js_resize')
{
$avatar_width = !empty($modSettings['avatar_max_width_external']) ? ' width="' . $modSettings['avatar_max_width_external'] . '"' : '';
$avatar_height = !empty($modSettings['avatar_max_height_external']) ? ' height="' . $modSettings['avatar_max_height_external'] . '"' : '';
}
else
{
$avatar_width = '';
$avatar_height = '';
}

$poster_ids = loadMemberData(array_keys($posters));
foreach ($poster_ids as $member)
{
$topic = $posters[$member]; // to get back to $return
$profile = $user_profile[$member];
$avatar = array(
'image' => $profile['avatar'] == '' ? ($profile['id_attach'] > 0 ? '<img src="' . (empty($profile['attachment_type']) ? $scripturl . '?action=dlattach;attach=' . $profile['id_attach'] . ';type=avatar' : $modSettings['custom_avatar_url'] . '/' . $profile['filename']) . '" alt="" class="avatar" border="0" />' : '') : (stristr($profile['avatar'], 'http://') ? '<img src="' . $profile['avatar'] . '"' . $avatar_width . $avatar_height . ' alt="" class="avatar" border="0" />' : '<img src="' . $modSettings['avatar_url'] . '/' . htmlspecialchars($profile['avatar']) . '" alt="" class="avatar" border="0" />'),
'href' => $profile['avatar'] == '' ? ($profile['id_attach'] > 0 ? (empty($profile['attachment_type']) ? $scripturl . '?action=dlattach;attach=' . $profile['id_attach'] . ';type=avatar' : $modSettings['custom_avatar_url'] . '/' . $profile['filename']) : '') : (stristr($profile['avatar'], 'http://') ? $profile['avatar'] : $modSettings['avatar_url'] . '/' . $profile['avatar']),
);

if ($avatar['href'] > '')
foreach ($topic as $tid)
$return['topics'][$tid]['poster']['avatar'] = $avatar;

}
}

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

$return['topics'][$last]['is_last'] = true;

$return['feed'] = array();

if (in_array('rss', $parameters['feed']))
$return['feed']['RSS'] = array(
'href' => $scripturl . '?action=.xml;sa=news;type=rss;boards=' . implode(',', $parameters['board']),
'link' => '<a href="' . $scripturl . '?action=.xml;sa=news;type=rss;boards=' . implode(',', $parameters['board']) . '">RSS</a>',
);

if (in_array('rdf', $parameters['feed']))
$return['feed']['RDF'] = array(
'href' => $scripturl . '?action=.xml;sa=news;type=rdf;boards=' . implode(',', $parameters['board']),
'link' => '<a href="' . $scripturl . '?action=.xml;sa=news;type=rdf;boards=' . implode(',', $parameters['board']) . '">RDF</a>',
);

if (in_array('rdf', $parameters['feed']))
$return['feed']['Atom'] = array(
'href' => $scripturl . '?action=.xml;sa=news;type=atom;boards=' . implode(',', $parameters['board']),
'link' => '<a href="' . $scripturl . '?action=.xml;sa=news;type=atom;boards=' . implode(',', $parameters['board']) . '">Atom</a>',
);

if ($parameters['output_type'] != 'echo')
return $return;

foreach ($return['topics'] as $news)
{
if ($parameters['avatar'] != 'none' && isset($news['poster']['avatar']))
$news['body'] = '<img class="ssi_avatar" src="' . $news['poster']['avatar']['href'] . '" style="margin:0 1em 1em 1em; float: ' . $parameters['avatar'] . '" />' . $news['body'];

echo '
<div>
', ($parameters['category_disp'] ? '[' . $news['category']['link'] . ']' : ''), ($parameters['board_disp'] ? ' [' . $news['board']['link'] . ']' : ''), ' <a href="', $news['href'], '">', $news['icon'], '</a> <strong>', $news['subject'], '</strong>
<div class="smaller">', $news['time'], ' ', $txt['by'], ' ', $news['poster']['link'], '</div>

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

', ($parameters['perms_override'] ? '' : $news['link'] . ($news['locked'] ? '' : ' | ' . $news['comment_link'])), '
</div>';

if (!empty($news['attachments']))
{
$count = count($news['attachments']);
if ($count > 0) {
switch($parameters['attachments'])
{
case 'linkonly':
echo ' <ul>';
foreach ($news['attachments'] as $attach)
echo '
<li><a target="_blank" href="', $attach['href'], '">', $attach['filename'], '</a> (', ($attach['imgsize'] != '' ? $attach['imgsize'] . ', ' : ''), $attach['filesize'], ')</li>';
echo '
</ul>';
break;
case 'thumbnail':
foreach ($news['attachments'] as $attach)
{
echo '
<div class="ssi_attach" style="margin-top:0.3em;">';
if ($attach['thumbnail'])
echo '
<img src="', $attach['thumbnail']['href'], '" width="', $attach['thumbnail']['width'], '" height="', $attach['thumbnail']['height'], '" />';
echo '
<div class="ssi_attach_filename"><a target="_blank" href="', $attach['href'], '">', $attach['filename'], '</a></div>
<div class="ssi_attach_filesize">', $attach['filesize'], ($attach['imgsize'] != '' ? ', ' . $attach['imgsize'] : ''), '</div>';
echo '
</div>';
}
break;
case 'inline':
foreach ($news['attachments'] as $attach)
{
echo '
<div class="ssi_attach" style="margin-top:0.3em;">';
if ($attach['width'] > 0)
echo '
<img src="', $attach['href'], '" width="', $attach['width'], '" height="', $attach['height'], '" />';
echo '
<div class="ssi_attach_filename"><a target="_blank" href="', $attach['href'], '">', $attach['filename'], '</a></div>
<div class="ssi_attach_filesize">', ($attach['imgsize'] != '' ? $attach['imgsize'] . ', ' : ''), $attach['filesize'], '</div>
</div>';
}
break;
}
}
}

if (!$news['is_last'])
echo '
<hr style="margin: 2ex 0; clear:left;" width="100%" />';
}

// Now, what about feeds

if (count($return['feed']) > 0)
{
$feeds = array();
foreach ($return['feed'] as $feed)
$feeds[] = $feed['link'];
echo '
<hr style="margin: 2ex 0;" width="100%" />
<div class="smalltext">', implode(' | ', $feeds), '</div>';
}
}

php code to call some functions and displays posts from 5 boards
Code: [Select]
$parameters = array(
  'limit' => 6,
  'board' => array(6,8,9,10,11),
  'board_disp' => false,
  'thumbnail' => 'left',
  'avatar' => 'false',
  'category_disp' => false,
);
ssi_multiBoardNews($parameters);
this works with 2.0 RC4 but I can not get it to show attached images i this possible with this code
« Last Edit: March 05, 2011, 02:22:03 AM by Ares »

Offline Ares

  • Jr. Member
  • **
  • Posts: 50
  • Gender: Male
  • World Of Mass Distruction
    • [SoW] Spoils of War
  • SMF Version: 2.0.5
  • SP Version: 2.3.5
Re: custom ssi code need some help with
« Reply #1 on: March 06, 2011, 03:52:45 AM »
any one