The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
|||
|
|||
hook for posting data?
I have coded alot in my days but I am new to VB and PHP.. Anyways I want a simple peice of code that will go through a users post right before they post it or preview it and replace string 'x' with string 'y'..
Lets say for the sake of exmaple it will detect the word "infinity" and replace it with the character "∞" This is what I have so far (for the main part of the plugin) and I have no clue where to go? any guiding hands?? Code:
<plugin active="1" executionorder="5"> <title>Math</title> <hookname>newpost_process</hookname> <phpcode><![CDATA[if (THIS_SCRIPT == "index" and $vbulletin->options['math_onoff']) { $mathpost .= ''; $template_hook['postbit_messagearea_start'] .= 'mathpost'; }]]></phpcode> </plugin> |
#2
|
|||
|
|||
I think you have the correct hook location, you'd want to do something like:
PHP Code:
or if you have more than one potential replacement: PHP Code:
and if you want it to be case insensitive, use str_ireplace() instead (same parameters). BTW, I see what you posted is from an install xml file. If you're working on it that way you're probably finding it annoying. What you really should do is work on a test site in debug mode, then export the install xml when you're done. |
#3
|
|||
|
|||
Thanks! But how do I let it know not to post the original message then my message (with replacements) but only post the replacement message?
Here is my main section of the code for the product: Code:
<plugins> <plugin active="1" executionorder="5"> <title>Math</title> <hookname>newpost_process</hookname> <phpcode><![CDATA[if (THIS_SCRIPT == "index" and $vbulletin->options['math_onoff']) { $find = array("infinty", "pi"); $replace = array("∞", "π"); $post['message'] = str_replace($find, $replace, $post['message']; }]]></phpcode> </plugin> </plugins> |
#4
|
|||
|
|||
It should post only the replacement, because what it does is changes the post text before it's saved.
By the way, I tried it out and found a couple typos in what I posted: infinity is spelled wrong and I left off a close paren at the end of the str_replace line. |
#5
|
|||
|
|||
[S]Haha! good deal! Alright thanks! [/S]
Edit: just installed the product and when I went to make a post it didn't seem to work? Do I have the right hooks? |
#6
|
|||
|
|||
You have 1 problem with your code.
You're checking if the script name is 'index'. New posts are never posted via the index page. |
#7
|
|||
|
|||
ahh! Thanks! Silly me, Don't know why I left that in there! I got the section from another users product.xml file..
So now 1 last question.. It was supposed to replace the "infinity" with "∞" but instead it put a "?" I had to use HTML code "&#*8734;" (without the *asterix) Does that have to do with how I'm compiling the xml file or is it just how the forum reads it? |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|