Simple Machines Community Forum

General Community => Scripting Help => Aiheen aloitti: sonicslp - kesäkuu 10, 2008, 03:58:41 AP

Otsikko: SSI Single Message Mod problems
Kirjoitti: sonicslp - kesäkuu 10, 2008, 03:58:41 AP
I'm having trouble with the SSI Single Message (http://custom.simplemachines.org/mods/index.php?mod=357) mod.

All quotes/apostrophes are coming out as question marks and I can't figure out where/how to fix it. Are the forum posts not being inserted properly into MySQL by SMF? Does it not use addslashes?

MySQL 4.23
PHP 4.3.11
SMF 1.1.4
Otsikko: Re: SSI Single Message Mod problems
Kirjoitti: IchBin™ - kesäkuu 10, 2008, 08:19:11 IP
What is your forum language set to, and what is your database language set to?

Make sure if you are using a UTF8 language, that you have the utf8 language files in your default theme. I'm not sure how the languages work much, but you should probably make sure your database is saving as UTF8 if youre using UTF8 as well.
Otsikko: Re: SSI Single Message Mod problems
Kirjoitti: IchBin™ - kesäkuu 10, 2008, 08:28:47 IP
Another question, are you seeing this only through the grabMessage function? Or do you see it in other places on your board?
Otsikko: Re: SSI Single Message Mod problems
Kirjoitti: sonicslp - kesäkuu 10, 2008, 08:34:42 IP
Only the grabMessage function, the board displays the messages correctly. I'll check out the UTF8 stuff and get back to you.
Otsikko: Re: SSI Single Message Mod problems
Kirjoitti: sonicslp - kesäkuu 10, 2008, 08:42:22 IP
The MySQL db is set to Collation utf8_general_ci but if I go into the SMF tables I see that a lot of them are either unset or say "latin1_swedish_ci"

I'm just using English for the forum, have no idea what SMF does outside of that.
Otsikko: Re: SSI Single Message Mod problems
Kirjoitti: IchBin™ - kesäkuu 11, 2008, 10:14:02 AP
Going to see if I can get some input from someone that knows language/character issues.
Otsikko: Re: SSI Single Message Mod problems
Kirjoitti: Sarge - kesäkuu 11, 2008, 10:25:33 AP
Lainaus käyttäjältä: sonicslp - kesäkuu 10, 2008, 03:58:41 AP
MySQL 4.23

I don't recognize this MySQL version... Can you copy/paste it from SMF Admin > Support and Credits > Version Information section?
Otsikko: Re: SSI Single Message Mod problems
Kirjoitti: sonicslp - kesäkuu 11, 2008, 12:27:08 IP
Sorry about that, brain fart on my part. The MySQL version is actually 3.23.49 according to phpinfo(). Oddly, if I look at "Support and Credits" in SMF it says "MySQL version: 4.1.7-nt"
Otsikko: Re: SSI Single Message Mod problems
Kirjoitti: sonicslp - kesäkuu 12, 2008, 12:10:10 AP
I'm still stumped on this one. Any updates?
Otsikko: Re: SSI Single Message Mod problems
Kirjoitti: Sarge - kesäkuu 13, 2008, 08:50:12 AP
I assume you are displaying single messages on the homepage, or some other page outside SMF?

What are the selected page encodings (View menu > Character Encoding in Firefox, View > Encoding in IE) for SMF and the page where single messages are displayed?
Otsikko: Re: SSI Single Message Mod problems
Kirjoitti: sonicslp - kesäkuu 13, 2008, 02:14:23 IP
Unicode UTF-8
Otsikko: Re: SSI Single Message Mod problems
Kirjoitti: Sarge - kesäkuu 13, 2008, 03:05:11 IP
Lainaus käyttäjältä: sonicslp - kesäkuu 13, 2008, 02:14:23 IP
Unicode UTF-8

Both for SMF and the outside page?
Otsikko: Re: SSI Single Message Mod problems
Kirjoitti: sonicslp - kesäkuu 13, 2008, 04:30:20 IP
Ah! I assumed both were UTF-8 but the forum is Western. That's what I get for assuming. Thanks a bunch man!

One other quick question...

Can I set your mod to only display a certain length of the post and have a link to the full forum post?
Otsikko: Re: SSI Single Message Mod problems
Kirjoitti: IchBin™ - kesäkuu 14, 2008, 12:22:11 AP
You can limit the output of the body by changing a couple of things.

First add $func to the global list at the beginning of the function in SSI.php. Second, change this line:
'body' => $row['body'],

To this:
'body' => $func['substr']($row['body'], 0, 120),

120 being the amount of characters you want it to have.

To change the link to the post to link to the topic, change this line:
'link' => '<a href="' . $scripturl . '?topic=' . $row['ID_TOPIC'] . '.msg' . $row['ID_MSG'] . '#msg' . $row['ID_MSG'] . '">'.$txt['gsm_read_more'].'</a>',

To this:
'link' => '<a href="' . $scripturl . '?topic=' . $row['ID_TOPIC'] . '">'.$txt['gsm_read_more'].'</a>',
Otsikko: Re: SSI Single Message Mod problems
Kirjoitti: sonicslp - kesäkuu 16, 2008, 09:56:23 IP
Thanks a bunch for the help, it's working perfect!
Otsikko: Re: SSI Single Message Mod problems
Kirjoitti: kai920 - kesäkuu 22, 2008, 03:06:02 IP
hey IchBin - how do I modify this code to fetch the first attachment of the single message?

I used this code successfully with ssi_boardNews() but would appreciate some help with the SQL:


// Find their attachments.
       $request = db_query("
          SELECT ID_ATTACH, ID_THUMB, 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'],
             'thumb' => ($row['ID_THUMB']==0 ? ($scripturl . '?action=dlattach;topic=' . $return[$row['ID_MSG']]['id'] . '.0;id=' . $row['ID_ATTACH']) : ($scripturl . '?action=dlattach;topic=' . $return[$row['ID_MSG']]['id'] . '.0;id=' . $row['ID_THUMB'])),
             '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;
Otsikko: Re: SSI Single Message Mod problems
Kirjoitti: kai920 - kesäkuu 23, 2008, 02:58:13 AP
I think I got the SQL statement correct, but when I try to return the attachment array it somehow overwrites the earlier result in green?  I get an Undefined index:  body error as long as the statement in red exists.

Any help please?

Lainaa
        $return[] = array(
        'body' => $row['body']
        );

Lainaa
// Find their attachments.
       $request = db_query("
          SELECT ID_ATTACH, ID_THUMB, ID_MSG, filename, size, downloads
          FROM {$db_prefix}attachments
          WHERE ID_MSG = (" . ($message_id) . ")", __FILE__, __LINE__);
        $row = mysql_fetch_assoc($request);
        $return['attachment'][] = array(
                'name' => $row['filename']
            );
    mysql_free_result($request);
      return $return;