News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

Grab a single message with SSI.php

Started by Cccddd, March 09, 2004, 01:22:41 PM

Previous topic - Next topic

Mastiff

I guess I'll just keep posting until maybe someone decides to have mercy on me.  :(

I can get the function to work like this:

http://www.mysite.com/Forum/SSI.php?ssi_function=grabPost&message_id=3776

But that doesn't really do me much good since I want to embed everything into my own formatting.  I need to use it in array mode.

If I do this:

<?php ssi_grabPost(3776?>

or any similar variation, it ignores the arguments and just gives back the most recent post on the forum.  I can get ssi_boardNews to work fine that way.  Has anyone ever used this function like this??  It seems that it's getting hung up here:

if (isset($_REQUEST['message_id']))

Won't this only come back positive if stuff is sent in on the command line or something?  ssi_boardNews has no such if statement and just uses $message_id straight out.

It would be so cool if someone could rescue me from this.  I didn't think I'd have to spend 6 hours grabbing the text of a message.  My site is languishing right now with busted links.  :(
"If you're an ugly chick, you're basically the same as a dude... I mean, you're gonna have to work."

Mastiff

Well, I've edited SSI.php to get what I want.  I realize this is a no-no, but I must be the first person ever who has wanted to display a single message using my own formatting.  That kind of weirds me out; what are others using this mod for?  Anyway, here's the modified version, new stuff bolded:

Quotefunction ssi_grabPost($message_id = null, $message_length = null, $output_method = 'echo')
{
  global $scripturl, $db_prefix, $txt, $settings, $modSettings, $context;

if (isset($message_id) == FALSE)
  {

  if (isset($_REQUEST['message_id']))
  {
    $message_id = $_REQUEST['message_id'];
    if ($message_id !== null) $message_id = (int) $message_id;
    elseif (isset($_GET['ID_MSG'])) $message_id = (int) $_GET['ID_MSG'];
  }
  else
  {
    $request = db_query("SELECT ID_MSG FROM {$db_prefix}messages ORDER BY ID_MSG DESC LIMIT 1", __FILE__, __LINE__);
    if ($hash = mysql_fetch_array($request)) $message_id = $hash['ID_MSG'];
    else die ("Can't even get a message ID!");
  }
  }

  $request = db_query("
    SELECT m.icon, m.subject, m.body, IFNULL(mem.realName, m.posterName) AS posterName, m.posterTime, m.ID_MSG, t.ID_TOPIC, m.ID_MEMBER, m.smileysEnabled, b.name
    FROM {$db_prefix}topics AS t, {$db_prefix}messages AS m, {$db_prefix}boards as b
    LEFT JOIN {$db_prefix}members AS mem ON (mem.ID_MEMBER = m.ID_MEMBER)
    WHERE m.ID_MSG = $message_id
    AND m.ID_TOPIC = t.ID_TOPIC
    AND t.ID_BOARD = b.ID_BOARD
    AND FIND_IN_SET(-1, b.memberGroups)", __FILE__, __LINE__);

  $return = array();
                                                                                                       
  if (mysql_num_rows($request) == 0)                                                                               
  {
    if ($output_method == 'echo') die('Query returned no response. Perhaps you don\'t have permission to view this board?');
    else return('Query returned no response. Perhaps you don\'t have permission to view this board?');
  }

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

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

  if ($message_length > 0)
    $row['body'] = substr($row['body'], 0, $message_length) . '...';

  $return[] = array(
    'icon' => '<img src="' . $settings['images_url'] . '/post/' . $row['icon'] . '.gif" align="middle" alt="' . $row['icon'] . '" />',
    'subject' => $row['subject'],
    'time' => timeformat($row['posterTime']),
    'body' => $row['body'],
    'href' => $scripturl . '?topic=' . $row['ID_TOPIC'] . '.0',
    'link' => '<a href="' . $scripturl . '?topic=' . $row['ID_TOPIC'] . '.msg' . $row['ID_MSG'] . '#msg' . $row['ID_MSG'] . '">Read More...',
    'new_comment' => '<a href="' . $scripturl . '?action=post;topic=' . $row['ID_TOPIC'] . '.0">Reply</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']
    ),
  );
  mysql_free_result($request);

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


  foreach ($return as $news)
    echo '
      <table border="0" width="100%" align="center" class="smfNews">
        <tr><td>', $news['icon'], ' <b>', $news['subject'], '</b><span class="smaller"><br />', $news['time'], ' ', $txt[525], ' ', $news['poster']['link'], '<br /><br /></span></td></tr>
        <tr><td>', $news['body'], '<br /><br /></td></tr>
        <tr><td>', $news['link'], ' | ', $news['new_comment'], '</td></tr>
      </table>
';

}

These changes make it so you can call it like a function in "array" mode, have the values returned and have no echo to the screen.

Here's me test PHP file:

<?php require("/home/libertar/public_html/Forum/SSI.php"); ?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>LU Article</TITLE>
<link rel="stylesheet" type="text/css" href="./Forum/LU.css" />

</HEAD>

<BODY text=#000000 link=#0033ff bgcolor=#666699>

<?

$array = ssi_grabPost($id_msg, null, 'array');

foreach ($array as $post){
echo
$post['body'],'<br><br>',
$post['time'],'<br><br>',
$post['href'],'<br><br>',
$post['subject'],'<br><br>',
$post['poster']['link'];

}

?>

</html>


If I did something dumb, someone please let me know.  But it seems to work.
"If you're an ugly chick, you're basically the same as a dude... I mean, you're gonna have to work."

Cccddd

I'm not ignoring your issues, but I am definitely putting them off right now. I have two other major mods which are taking a lot of my time, and this old package worked well enough for most other people, so... yeah. keep posting and I will eventually get around to helping.

trust me though, this was a really basic mod. if you just take the time on your own to edit it, you should learn at least a little about SMF.

Mastiff

Thanks for the reply.  I hope I don't sound like a jerk or anything...  I'm well aware that I'm getting all this good stuff for free.   ;D  It seems to be working now.  I'm only concerned that I might get into trouble later for installing a package and then changing it...  I'm also a little confused since someone else posted on this thread that they could get it to work like <?php sse_grabPost(1234) ?> and it never worked for me until I made the edits.  ???
"If you're an ugly chick, you're basically the same as a dude... I mean, you're gonna have to work."

Cccddd

possible that it was an older version they were using? i dunno. it's been half a year since i even glanced at the code for this mod, let alone actively used it.

Trekkie101

Is it planned to be updated for the current relese of 1.1?

I tried it but it just told me the query came back empty.

Ben_S

It should work fine, although I'm still using the old version.
Liverpool FC Forum with 14 million+ posts.

Mastiff

I sure hope 1.1 doesn't mess up the way SSI stuff works.  :o  Does SSI.php itself change with 1.1?
"If you're an ugly chick, you're basically the same as a dude... I mean, you're gonna have to work."

Trekkie101

Quote from: Mastiff on July 24, 2005, 10:02:18 AM
I sure hope 1.1 doesn't mess up the way SSI stuff works.  :o  Does SSI.php itself change with 1.1?
All the things that worked in 1.0.X by default in SSI should work just the same.

Quote from: Ben_S on July 24, 2005, 09:55:24 AM
It should work fine, although I'm still using the old version.
Its working now, I manually applied it, but I had to remove ssi_boardNews, it kept throwing me an error but the grabMessage function is now working :)

drhamad

Am I the only one still totally confused here?  SMF always makes me feel like a little newbie idiot ;)

OK lets back up to just the very BASIC way of running this:

<?php 
include("http://development.fmvperformance.com/SSI.php?ssi_function=grabPost&message_id=2");
?>



That shows absolutely nothing:
http://development.fmvperformance.com/newstest.php

What am I missing here?
FMVperformance:  3.51m posts, 63k members, 11 boards, 1 database

Mazda3Forums - SmallVolvos - MazdaSpeeders Mazda Club - FordFusionClubMazda CX-7 Club - MyMazda6
Now introducing: MKSdrivers.com - FocusDrivers - TaurusDrivers

Trekkie101

<?php require("SSI.php"); 
ssi_grabMessage(2);
?>


Will work ;)

drhamad

Quote from: Trekkie101 on July 28, 2005, 03:21:25 PM
<?php require("SSI.php"); 
ssi_grabMessage(2);
?>


Will work ;)


Ahhh... I was trying to interpret the jumble of ideas in this thread, knew I was missing something - that was it ;)

Thanks.  It works now.

A long way to go until it's something useable for my site, of course, but at least now I know it works :)
FMVperformance:  3.51m posts, 63k members, 11 boards, 1 database

Mazda3Forums - SmallVolvos - MazdaSpeeders Mazda Club - FordFusionClubMazda CX-7 Club - MyMazda6
Now introducing: MKSdrivers.com - FocusDrivers - TaurusDrivers

drhamad

No wonder I'm having such a hard time here... where's this v1.3?
http://mods.simplemachines.org/index.php?mod=18
That lists just v1.0, and it is definitely some different code.
FMVperformance:  3.51m posts, 63k members, 11 boards, 1 database

Mazda3Forums - SmallVolvos - MazdaSpeeders Mazda Club - FordFusionClubMazda CX-7 Club - MyMazda6
Now introducing: MKSdrivers.com - FocusDrivers - TaurusDrivers

perplexed

Is there more info to be had for this mod, and maybe some examples?

also I clicked on the link on the first page but its not there

thanks

rekarde

Quote from: Ben_S on December 01, 2004, 07:39:13 PM
I'm using it as follows, the ssi_boardNews function to grab a chunk of the message

$news = ssi_boardNews(17,15,0,350,"array");

And my read more link looks like

<a href="./article.php?id=', $news['message_id'], '">Read More</a>


I did that... but the variable $news['message_id'] is empty...
Adding this code to ssi_boardNews function:

'message_id' => $row['ID_MSG'],

don´t resolve the problem...
what i´m doing wrong?

rekarde

even better... something like topic grabber... using the topic id instead the message id...
and even better was to pull all the posts of a topic. to do something like:
the first topic was a news and the others were coments...

anyone have seen something like that?

Advertisement: