News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

ssi_boardNews() to fetch attachment images

Started by robembra, December 06, 2009, 04:22:55 PM

Previous topic - Next topic

robembra

Hi,

I have recently upgraded from 1.1.11 to 2.0 RC2. I edited the SSI.php in my old forum so I could see attachments with ssi_boardNews(). See code below

function ssi_boardNews2($board = null, $limit = null, $start = null, $length = null, $output_method = 'echo')
{
   
global $scripturl, $db_prefix, $txt;
global $settings, $modSettings, $context;
   
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;

if ($board !== null)$board = (int) $board;
elseif (isset($_GET['board']))
$board = (int) $_GET['board'];

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

// 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)
{
if ($output_method == 'echo')
die($txt['smf_news_error2']);
else
return array();
}
list ($board) = mysql_fetch_row($request);
mysql_free_result($request);

// 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
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_BOARD = $board
AND m.ID_MSG = t.ID_FIRST_MSG
ORDER BY m.ID_MSG DESC
LIMIT $start, $limit", __FILE__, __LINE__);
$return = array();
$message_ids = array();
while ($row = mysql_fetch_assoc($request))
{
$message_ids[] = $row['ID_MSG'];
// If we want to limit the length of the post.
if (!empty($length) && strlen($row['body']) > $length)
{
$row['body'] = 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'] = substr($row['body'], 0, $cutoff);
$row['body'] .= '...';
}

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

censorText($row['subject']);
censorText($row['body']);

$return[$row['ID_MSG']] = array(
'attachments' => array(),
'id' => $row['ID_TOPIC'],
'icon' => '<img src="' . $settings['images_url'] . '/post/' . $row['icon'] . '.gif" align="middle" alt="' . $row['icon'] . '" />',
'subject' => $row['subject'],
'time' => timeformat($row['posterTime']),
'timestamp' => $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'],'new_comment' => '<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']                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                ),
'is_last' => false
);
}
mysql_free_result($request);


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

// Find their attachments.

$request = db_query("
SELECT ID_ATTACH, ID_MSG, filename, size, downloads
FROM {$db_prefix}attachments
WHERE ID_MSG IN (" . implode(', ', $message_ids) . ")", __FILE__, __LINE__);
while ($row = mysql_fetch_assoc($request))
{

$return[$row['ID_MSG']]['attachments'][] = array(
'name' => $row['filename'],
'downloads' => $row['downloads'],
'size' => round($row['size'] / 1024, 2) . ' ' . $txt['smf211'],
'byte_size' => $row['size'],
'href' => $scripturl . '?action=dlattach;topic=' . $return[$row['ID_MSG']]['id'] . '.0;id=' . $row['ID_ATTACH'],
'link' => '<a href="' . $scripturl . '?action=dlattach;topic=' . $return[$row['ID_MSG']]['id'] . '.0;id=' . $row['ID_ATTACH'] . '">' . $row['filename'] . '</a>'
);
}
mysql_free_result($request);
return $return;
}


How do i make ssi_boardNews() show the attachment image with 2.0 RC2

Thanks

Advertisement: