News:

Wondering if this will always be free?  See why free is better.

Main Menu

Breaking Up ssi_boardNews, Possible?

Started by Mathijs88, February 27, 2008, 05:12:27 AM

Previous topic - Next topic

Mathijs88

Hello Again!

I am building a webpage for my world of warcraft guild, and I am using SMF as our main forum. I want to use;

QuoteBoard News Function: <?php ssi_boardNews(); ?>

but not in the way how it displays it on default. I want the topic title & posted by & the actual post etc. in different tables. Yet again, I had been searching on how to do this but couldn't find it.

~Math

p.s. - Yes, my coding skills are horrible.

Angelotus

Gezien je username ga ik ervan uit dat je nederlands spreekt?

Mathijs88

I do, but are we allowed to speak dutch? ;)

Angelotus

Only in the Dutchforums I guess...

If you go into the ssi.php file and search for this function, at the and of the function you can see the output (in html). You only have to edit that piece of code using tables or listings and the strings that you want to use (topic title, topic icon, topic description, summary, poster etc).

I have an example, but not right now (at work now :P)...

Mathijs88

I'll wait for your example. Hope you haven't forgot about me.

Sarge

Are you trying to display board news on a SMF page or on a main (non-SMF) page?

The way they are coded, most SSI functions can return the output -- instead of display it -- if you pass a parameter other than 'echo' (which is the default). It's normally the last parameter, so you have to make sure that you put the correct amount of values and in the correct order.

Here's an example of how to use ssi_boardNews:

$board_array = ssi_boardNews(1, 5, null, 250, 'array');


The code above will return an array with the first 250 characters for each of the 5 latest posts from board 1. The null above is for the start topic, i.e. if you put 11 instead of null, you'll get the latest posts from topics 11-15 in the list of the newest topics.

All you have to do after that is display the info contained inside $board_array. If you're not sure about it, do this:

echo '<pre>';
print_r($board_array);
echo '</pre>';


to have the structure of the whole array displayed on the screen.

If ssi_boardNews() is not called with 'array', it displays the info instead of returning it. The PHP/HTML code used in this case is located in lines 1356-1371 of SSI.php (from the SMF 1.1.4 package). You can use that in your own code and modify to your taste.

    Please do not PM me with support requests unless I invite you to.

http://www.zeriyt.com/   ~   http://www.galeriashqiptare.net/


Quote
<H> I had zero posts when I started posting

Angelotus

I use this in my SSI.php file


// Show the latest news, with a template... by board.
function ssi_Nieuwsssss($board = null, $limit = null, $start = null, $length = null, $output_method = 'echo')
{
global $scripturl, $db_prefix, $txt, $settings, $modSettings, $context;
global $func;

loadLanguage('Stats');

// Must be integers....
if ($limit === null)
$limit = isset($_GET['limit']) ? (int) $_GET['limit'] : 5;
else
$limit = (int) $limit;

if ($start === null)
$start = isset($_GET['start']) ? (int) $_GET['start'] : 0;
else
$start = (int) $start;

// Was a board passed?
if ($board !== null)
{
// Are we using an array?
if (is_array($board))
{
// Make sure all values are numeric.
foreach ($board as $key => $board_id)
$board[$key] = (int) $board_id;
}
// Otherwise, it's probably a number.
else
{
$board = (int) $board;
}
}
// No board? Check GET variable.
elseif (isset($_REQUEST['board']))
{
// Could it be an array?
// You can pass a comma seperated list of boards, and they'll all be
// used (eg. ?board=1,2,3,4,5).
if (strpos($_REQUEST['board'], ',') !== false)
{
// Split up the string.
$board = explode(',', $_REQUEST['board']);
// Make sure all values are numeric.
foreach ($board as $key => $board_id)
$board[$key] = (int) $board_id;
}
// Probably a number (backwards-compatibility).
else
{
$board = (int) $_REQUEST['board'];
}
}

// WHERE clause in the queries.
$boardQuery = 'ID_BOARD ' . (is_array($board) ? ('IN (' . implode(',', $board) . ')') : ('= ' . $board));

if ($length === null)
$length = isset($_GET['length']) ? (int) $_GET['length'] : 0;
else
$length = (int) $length;

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

// If no boards were passed, get the first board guests can view
// Otherwise, check if all the passed boards are valid.
$request = db_query("
SELECT ID_BOARD, name
FROM {$db_prefix}boards
WHERE " . ($board === null ? '' : $boardQuery . '
AND ') . 'FIND_IN_SET(-1, memberGroups)
ORDER BY ID_BOARD ASC' . ($board === null ? '
LIMIT 1' : ''), __FILE__, __LINE__);

// No boards? That's bad.
if (mysql_num_rows($request) == 0)
{
if ($output_method == 'echo')
die($txt['smf_news_error2']);
else
return array();
}

$boardInfo = array();
// Empty the board ID array - We're grabbing the IDs from scratch.
unset($board);
$board = array();

// Loop through all returned boards.
while ($row = mysql_fetch_assoc($request))
{
// Add this board to the arrays.
// Board info - Used later on (in the stuff returned)
$boardInfo[$row['ID_BOARD']] = $row;
$board[] = $row['ID_BOARD'];
}
mysql_free_result($request);

// Let's get the new WHERE clause
// Note: The $board array does not need to be sanitised, its data has been
// returned from the database (and is safe).
$boardQuery = 'ID_BOARD IN (' . implode(',', $board) . ')';


// 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 $boardQuery
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, t.ID_BOARD
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))
{
// 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 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[] = array(
'id' => $row['ID_TOPIC'],
'message_id' => $row['ID_MSG'],
'icon' => '<img height="11" 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' => '(' . $row['numReplies'] . '' . ($row['numReplies'] == 1 ? $txt['smf_news_1'] : $txt['smf_news_5']) . ')',
'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_4'] . '</a>',
'new_comment' => !empty($row['locked']) ? '' : '(<a href="' . $scripturl . '?action=post;topic=' . $row['ID_TOPIC'] . '.' . $row['numReplies'] . '">reageren</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']),

'board' => array(
'id' => $row['ID_BOARD'],
'name' => $boardInfo[$row['ID_BOARD']]['name'],
'href' => $scripturl . '?board=' . $row['ID_BOARD'],
'link' => '<a href="' . $scripturl . '?board=' . $row['ID_BOARD'] . '">' . $boardInfo[$row['ID_BOARD']]['name'] . '</a>'
),
'is_last' => false
);
}
mysql_free_result($request);

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

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

if ($output_method != 'echo')
return $return;

foreach ($return as $news)
{
echo '

<li><a href="', $news['href'], '">', $news['icon'], ' ', $news['subject'], ' ', $news['link'], $news['locked'] ? '' : '</a></li>
';

if (!$news['is_last'])
echo '
';
}
}


Please add to your language/stats.english.php (or dutch.php):

$txt['smf_news_4'] = 'reageren';
$txt['smf_news_5'] = '';


Than call in your custom page the function ssi_Nieuwsssss(boardid, nr of posts, nr of characters, 0);

Output should be like:

[an image] Title of your post (nr of replies)

Finale Idols (24)

Sarge

Mathijs88, let us know if the suggestions above have helped. :)

    Please do not PM me with support requests unless I invite you to.

http://www.zeriyt.com/   ~   http://www.galeriashqiptare.net/


Quote
<H> I had zero posts when I started posting

Advertisement: