News:

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

Main Menu

SSI Pulling a Single Post

Started by Innocent, March 27, 2006, 08:43:15 PM

Previous topic - Next topic

Innocent

I searched but was unable to find it, I know it'd be simple to write but I'm unfamiliar with SMF.

I want an SSI function like ssi_showPost(postid, showPosterInfo);

Where postID is the post key ( int )
and showPosterInfo toggles: post author, attachments, etc etc ( bool )


Just a function I can add to the end of my ssi.php, if anyone could write this, or tell me how to pull a post, that would be cool.

If the showPosterInfo is too much, can just do the post key, also a simple template so I know how to modify how it displays would be cool :P


Sting

ya, I've basically been forced to create multiple boards when wanting to post seperate topics away from each other.

Innocent

Quote from: Sting on March 27, 2006, 09:48:25 PM
ya, I've basically been forced to create multiple boards when wanting to post seperate topics away from each other.

I'm pretty sure you can do it, it's simply a matter of how to do it... teach me, or give me the silver platter :P I'm competent in php...

fwitt

probly copy a function like ssi_Boardnews and change the database query so it looks by topic number rather than board number

Sting

it's alot more involved than that.

You will have to basically add something to it that will leave it to check and see if guests are allowed to view to board that the topic is in while pointing to a specific topic number.  :-\

H

Standard SSI cannot pull a single post.

However search this forum for the grabmessage function which does just what you want with SSI ;)
-H
Former Support Team Lead
                              I recommend:
Namecheap (domains)
Fastmail (e-mail)
Linode (VPS)
                             

Sting

#6
or I just messed around and did this.

Add to SSI.php

// Show the latest news, with a template... by topic.
function ssi_topicNews($topic = 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'] : 10;
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
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_TOPIC = $topic
AND m.ID_MSG = t.ID_FIRST_MSG
ORDER BY m.ID_MSG DESC
LIMIT $start, $limit", __FILE__, __LINE__);
$return = array();
while ($row = mysql_fetch_assoc($request))
{
// 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[] = 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;

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

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

foreach ($return as $news)
{
echo '
<table border="0" width="100%" align="center" class="ssi_table">
<tr>
<td>', $news['icon'], ' <b><font color=white>', $news['subject'], '</b><br /><br /></font></td>
</tr>
<tr>
<td><b><font color=white>', $news['body'], '<br /><br /></font></b></td>
</tr>
<tr>
<td Align=Center><b><font color=white style="font-size: 11px">', $news['link'], ' | ', $news['new_comment'], '</font><font color=white style="font-size: 11px"> | </font><font color=#8585A9 style="font-size: 11px">', $news['time'], '</font><font color=white style="font-size: 11px"> | </font>', $news['poster']['link'], '</b></td>
</tr>
</table>';

if (!$news['is_last'])
echo '
<hr width="100%" />
<br />';
}
}


when you call it do ssi_topicnews(#);

this overlooks the must be viewable by guests issue though, which in itself can be a good thing and a bad thing.

# is the topic number

I know there is code in there not being used, but someone else can remove that  :P

Innocent

#7
Thanks!

I wanted to allow guests to view it whether they're registered or not. However does this allow them to post? Or just view. Because if they can post then that's bad >.>

[edit]

Works great, thanks for the help, Sting!

Sting

Quote from: Innocent on March 29, 2006, 11:40:45 PM
Thanks!

I wanted to allow guests to view it whether they're registered or not. However does this allow them to post? Or just view. Because if they can post then that's bad >.>

[edit]

Works great, thanks for the help, Sting!

not a problem. This solved my problem too  ;)

Flogging My Log

hi i install your mod it is any configuration in admin panel for this becouse i cannot find it.

Arantor

Quote from: Flogging My Log on February 16, 2011, 02:00:52 PM
hi i install your mod it is any configuration in admin panel for this becouse i cannot find it.

What mod, exactly? If you followed the steps above and added code to SSI.php, that's designed specifically for adding to your own non-forum pages. There's no admin panel because there's no admin options for it... it's all done in your own non-forum code.

Sting

Ya, this is not integrating anything to your forum, simply pulling individual topics from the forum and displaying them on a page away from the forum.

Advertisement: