Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 07-15-2011, 10:26 PM
orange gold orange gold is offline
 
Join Date: Dec 2007
Posts: 94
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default 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>
Reply With Quote
  #2  
Old 07-15-2011, 10:53 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I think you have the correct hook location, you'd want to do something like:

PHP Code:
$post['message'] = str_replace("infinity""∞"$post['message']); 

or if you have more than one potential replacement:


PHP Code:
$find = array("infinity""pi");
$replace  = array("∞""pi symbol");
$post['message'] = str_replace($find$replace$post['message']); 

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.
Reply With Quote
  #3  
Old 07-15-2011, 11:02 PM
orange gold orange gold is offline
 
Join Date: Dec 2007
Posts: 94
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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>
Reply With Quote
  #4  
Old 07-15-2011, 11:08 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #5  
Old 07-15-2011, 11:44 PM
orange gold orange gold is offline
 
Join Date: Dec 2007
Posts: 94
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

[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?
Reply With Quote
  #6  
Old 07-16-2011, 12:24 PM
nhawk nhawk is offline
 
Join Date: Jan 2011
Posts: 1,604
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #7  
Old 07-16-2011, 08:10 PM
orange gold orange gold is offline
 
Join Date: Dec 2007
Posts: 94
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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?
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 10:13 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04785 seconds
  • Memory Usage 2,223KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (2)bbcode_code
  • (2)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (7)post_thanks_box
  • (7)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (7)post_thanks_postbit_info
  • (7)postbit
  • (7)postbit_onlinestatus
  • (7)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete