Firefox PHP

Best way to parse smileys outside of phorum?

Posted by sheik 
Best way to parse smileys outside of phorum?
January 10, 2007 12:10PM
I'm trying to format Phorum messages outside of Phorum.
I bbcode them simply by hacking the bbcode() function out of Phorum and placing it in my own script.
Smileys are proving more problematic though.
This is what I'm including at the moment:

chdir("/www/vhtdocs/moviedeaths/phorum/");
include_once("./common.php");
include_once("./mods/smileys/smileys.php");
include_once ("./include/quick_auth.php");

...but I get errors as soon as I try and include smileys.php (at the foreach() call on line 35)

Can anybody suggest what other include files I need, or perhaps a better way of doing this altogether?

Thanks,

/\dam

--
My notable Phorum sites:
Movie Deaths Database - "review comments" system mostly powered by Phorum
Learn Chinese! - integrated forum quiz
Re: Best way to parse smileys outside of phorum?
January 10, 2007 12:17PM
What error do you get for line 35? For me, that line is inside a function, so when including it shouldn't really give errors. Are you already calling the format hook function somwhere?


Maurice Makaay
Phorum Development Team
my blog linkedin profile secret sauce
Re: Best way to parse smileys outside of phorum?
January 10, 2007 12:29PM
I have more info. The error was caused by me calling:

phorum_mod_smileys_format($message["body"])
instead of:
phorum_mod_smileys_format($message)

I still don't have the function working, but I'm making progress now thanks.

Do I need to include format_functions.php to run the smileys mod?

/\dam

--
My notable Phorum sites:
Movie Deaths Database - "review comments" system mostly powered by Phorum
Learn Chinese! - integrated forum quiz
Re: Best way to parse smileys outside of phorum?
January 10, 2007 12:45PM
It's all a bit tricky, as I'm not too sure how to call phorum_mod_smileys_format().

I've hacked it to output the body text within the function, and I can't see any smiley replacement going on.

I assume the return $data; line of phorum_mod_smileys_format() is supposed to return me the same message object I pass in, but with smiley code in the body part?


Outside of Phorum, this is my call:
$message = phorum_mod_smileys_format($message);

Within smileys.php->phorum_mod_smileys_format(), if I do:
print_r($PHORUM["mod_smileys"]["replacements"]);
...then I can see a large array dump of all my smiley substitutions, but for some reason they're not being carried out by the function.

/\dam

--
My notable Phorum sites:
Movie Deaths Database - "review comments" system mostly powered by Phorum
Learn Chinese! - integrated forum quiz
Re: Best way to parse smileys outside of phorum?
January 10, 2007 12:48PM
I can rule out that the replacements are being made by calling:
 echo $data['body'] . "<br/>";
in smileys.php and then looking at my page source. The <img src> tags are definitely not there.


/\dam

--
My notable Phorum sites:
Movie Deaths Database - "review comments" system mostly powered by Phorum
Learn Chinese! - integrated forum quiz
Re: Best way to parse smileys outside of phorum?
January 10, 2007 01:02PM
SUCCESS! (sort of)

I gave up trying to get the included function to work, and copy/pasted a hacked version as:

function phorum_mod_smileys_format2($body)
{
    $PHORUM = $GLOBALS["PHORUM"];

    // Return immediately if we have no active smiley replacements.
    if (!isset($PHORUM["mod_smileys"])||!$PHORUM["mod_smileys"]["do_smileys"]){
        return $data;
    }

    // Run smiley replacements.
    $replace = $PHORUM["mod_smileys"]["replacements"];

	// Do body replacements.
	if (isset($replace["body"])) {
		$body = str_replace ($replace["body"][0] , $replace["body"][1], $body );
	}

	//echo $data['body'] . "<br/>";
	return $body;
}

(I only need it to parse a string, not a whole message structure of subject and body)

Running this directly from my script seems to work a treat.

One problem is that the image paths are all wrong, but I think I've fixed that with a mod_rewrite call...

/\dam

--
My notable Phorum sites:
Movie Deaths Database - "review comments" system mostly powered by Phorum
Learn Chinese! - integrated forum quiz
Re: Best way to parse smileys outside of phorum?
January 10, 2007 05:52PM
The path problem is something that I was suffering from in the embedding module too. There I fixed it with rewrite code in the embedding module. Using mod_rewrite is a good work-around too. I still want to look into this to make it work correctly from the smileys module.

To make the hook function from the smileys.php work, you'll have to pass the correct type of data. This is an array, where each element is an array containing the message data. The format hook function allows for missing subject data, so you'll only have to provide the body element to make it work. Here's an example:
$body = ...the body variable to format...;
$messages = array( 1 => array('body' => $body) );
$messages = phorum_mod_smileys_format($messages);
$body = $messages[1]['body'];


Maurice Makaay
Phorum Development Team
my blog linkedin profile secret sauce
Sorry, only registered users may post in this forum.

Click here to login