News:

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

Main Menu

ssi_grabPost stopped working - please help!

Started by Mastiff, July 09, 2006, 09:09:37 AM

Previous topic - Next topic

Mastiff

Not sure how many people use this (very useful) function, but suddenly today it stopped working.  I haven't changed anything.  I use it like this:

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

foreach ($array as $post){
$body=$post['body'];
$time=$post['time'];
$href=$post['href'];
$subject=$post['subject'];
$poster=$post['poster']['link'];

}


But now, no matter what I put for message ID, it always grabs the most recent post from the forum.  I'm stumped, because the SSI code hasn't been touched in probably years, so something must have changed in the database just from regular posting and messed it up somehow  ???.  I'd really appreciate any help because I have bogus links on my main page now.
"If you're an ugly chick, you're basically the same as a dude... I mean, you're gonna have to work."

kegobeer

That function isn't in SSI.php, so I can't help you.  Can you post this custom function?
"The truth of the matter is that you always know the right thing to do. The hard part is doing it." - Norman Schwarzkopf
Posting and you (Click "WATCH THIS MOVIE")

Mastiff

Quote from: kegobeer on July 09, 2006, 09:17:15 AM
That function isn't in SSI.php, so I can't help you.  Can you post this custom function?

I didn't write it, I got it here:  http://www.simplemachines.org/community/index.php?topic=6883.0

But here it is anyway:
function 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>
';

}


Thanks for the help. Maybe a new version of PHP came on-line and broke this?
"If you're an ugly chick, you're basically the same as a dude... I mean, you're gonna have to work."

kegobeer

How about a link to the page that uses this code?  You should also post this question on the mod's thread.  The mod author needs to provide support.
"The truth of the matter is that you always know the right thing to do. The hard part is doing it." - Norman Schwarzkopf
Posting and you (Click "WATCH THIS MOVIE")

Mastiff

Here's the top of the file I use it in.  I call it like "...script.php?id_msg=17"

<?php

$ssi_theme
=3;

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

echo 
'IM',$id_msg;

$array ssi_grabPost($id_msgnull'array'); 

foreach (
$array as $post){ 
$body=$post['body'];
$time=$post['time'];
$href=$post['href'];
$subject=$post['subject'];
$poster=$post['poster']['link'];

}

?>


The echo is debug code I just added, and I get no message ID at that point.  It's like my command line argument isn't even getting in for some reason.  Any ideas?

I tried to reply to the original thread, but it's been closed (no reply button).  This does appear to be an inappropriate forum though.  If a moderator wants to move the thread, that would be fine.

Thanks.
"If you're an ugly chick, you're basically the same as a dude... I mean, you're gonna have to work."

Mastiff

PHP must have changed so that command line query strings don't automatically turn into variables.  I fixed it by using this:

$argument=$_GET['argument'];
"If you're an ugly chick, you're basically the same as a dude... I mean, you're gonna have to work."

Advertisement: