Advertisement:

Author Topic: SSI Pulling a Single Post  (Read 8260 times)

Offline Innocent

  • Semi-Newbie
  • *
  • Posts: 12
SSI Pulling a Single Post
« on: March 27, 2006, 08:43:15 PM »
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


Offline Sting

  • Semi-Newbie
  • *
  • Posts: 61
  • Gender: Male
    • Subspace/Continuum Info & Tutorials
Re: SSI Pulling a Single Post
« Reply #1 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.

Offline Innocent

  • Semi-Newbie
  • *
  • Posts: 12
Re: SSI Pulling a Single Post
« Reply #2 on: March 27, 2006, 09:52:41 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...

Offline fwitt

  • Full Member
  • ***
  • Posts: 479
  • Gender: Male
Re: SSI Pulling a Single Post
« Reply #3 on: March 28, 2006, 02:33:30 PM »
probly copy a function like ssi_Boardnews and change the database query so it looks by topic number rather than board number

Offline Sting

  • Semi-Newbie
  • *
  • Posts: 61
  • Gender: Male
    • Subspace/Continuum Info & Tutorials
Re: SSI Pulling a Single Post
« Reply #4 on: March 29, 2006, 02:55:20 PM »
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.  :-\

Offline H

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 21,660
  • Gender: Male
Re: SSI Pulling a Single Post
« Reply #5 on: March 29, 2006, 03:00:17 PM »
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)
                             

Offline Sting

  • Semi-Newbie
  • *
  • Posts: 61
  • Gender: Male
    • Subspace/Continuum Info & Tutorials
Re: SSI Pulling a Single Post
« Reply #6 on: March 29, 2006, 03:09:44 PM »
or I just messed around and did this.

Add to SSI.php
Code: [Select]
// 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
« Last Edit: March 29, 2006, 03:11:48 PM by Sting »

Offline Innocent

  • Semi-Newbie
  • *
  • Posts: 12
Re: SSI Pulling a Single Post
« Reply #7 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!
« Last Edit: March 30, 2006, 12:01:04 AM by Innocent »

Offline Sting

  • Semi-Newbie
  • *
  • Posts: 61
  • Gender: Male
    • Subspace/Continuum Info & Tutorials
Re: SSI Pulling a Single Post
« Reply #8 on: March 30, 2006, 10:00:04 AM »
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  ;)

Offline Flogging My Log

  • Jr. Member
  • **
  • Posts: 162
Re: SSI Pulling a Single Post
« Reply #9 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.

Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 67,877
    • Arantor on GitHub
Re: SSI Pulling a Single Post
« Reply #10 on: February 16, 2011, 02:02:54 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.
To assume is to hope that those who came before had the presence of mind and capacity to implement the dreams of those who would come after.

You either die a hero or live long enough to see yourself become the villain. It seems you have chosen which, and now I must do the same.

Offline Sting

  • Semi-Newbie
  • *
  • Posts: 61
  • Gender: Male
    • Subspace/Continuum Info & Tutorials
Re: SSI Pulling a Single Post
« Reply #11 on: March 10, 2011, 02:18:33 PM »
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.