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

Reply
 
Thread Tools Display Modes
  #11  
Old 02-04-2012, 01:43 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Strange. The above works for me, so I'm not sure what to try.
Reply With Quote
  #12  
Old 02-04-2012, 02:28 PM
DonosOdD DonosOdD is offline
 
Join Date: Mar 2011
Posts: 121
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by kh99 View Post
Strange. The above works for me, so I'm not sure what to try.
Yes, it is very strange.

I deleted the plugin, created another one, copied the same code above, and tested. Doesn't work at all.

EDIT: Changed the preg_replace to str_replace, and it worked (however, without the boundaries). preg_replace is indeed returning null here, and I can't understand why.

--------------- Added [DATE]1328410811[/DATE] at [TIME]1328410811[/TIME] ---------------

Ok, here we have some news:

I was wondering why preg_replace remains returning NULL, even with silly/obvious examples. I changed it to str_replace and it worked. However, I need to manipulate strings in such a way that str_replace can't.

I've searched for the preg_replace returning NULL issue, and found this link:
http://www.pelagodesign.com/blog/200...-returns-null/


Quote:
In PHP 5.2, Perl Compatible Regular Expressions (PCRE) introduced with little fanfare a PHP setting called backtrack_limit, which, for the first time, set a limit on the number of backtracks a regular expression could perform before it stops operating and reports an error. Unfortunately, when PCRE encounters an error of this type, it doesn?t report a notice or warning or error. All it does is return NULL (...)
Then I went to my php.init file, to set a higher backtrack_limit.

After that, in the admincp->maintenance-> PHP Info, I've found this:

Directive Local Value Master Value
pcre.backtrack_limit -1 20000000
pcre.recursion_limit 20000000 20000000


So, what I need now is to change the local value to the master value, which I don't know how to :S

Any ideas?



Thanks in advance!
Reply With Quote
  #13  
Old 02-08-2012, 01:19 AM
DonosOdD DonosOdD is offline
 
Join Date: Mar 2011
Posts: 121
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Update: it's ok now, I've solved it and it works perfectly.

The problem was indeed that variable, pcre.backtrack_limit. I changed my php.ini file to raise its value, but its local value was still at -1. Then I've found that there's a config file in the vbulletin installation called init.php, which has this line:

@ini_set('pcre.backtrack_limit', -1);

That was keeping the variable so low, and this is why code was always returning NULL.

I commented this line, and it began to work.

Well, guess that's it, hope I'm also able to help someone with this.

Cya!
Reply With Quote
Благодарность от:
kh99
  #14  
Old 02-08-2012, 01:34 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I guess it worked for me because I don't have 5.3.

Anyway, thanks for posting that.
Reply With Quote
  #15  
Old 02-25-2012, 11:10 PM
Emeralda's Avatar
Emeralda Emeralda is offline
 
Join Date: Oct 2011
Posts: 202
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Uhm... which hook should I chose to limit it to things in postbit?
Reply With Quote
  #16  
Old 02-25-2012, 11:13 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

The above uses hook postbit_display_complete. I should probably have directed you to the thread mentioned in the first post, which is here: https://vborg.vbsupport.ru/showthread.php?t=219968
Reply With Quote
  #17  
Old 02-26-2012, 10:25 AM
Emeralda's Avatar
Emeralda Emeralda is offline
 
Join Date: Oct 2011
Posts: 202
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

HTML Code:
$censoredword = array(
'word1',
'word2'
);

$changedword = array(
'word3',
'word4'
);

$this->post['message'] = str_ireplace($censoredword, $changedword, $this->post['message']);
And how do the replacement work exactly? Is it something like

PHP Code:
$censoredword = array(
'swear word1',
'swear word2'
);

$changedword = array(
'swear word1 change',
'swear word2 change'
);

$this->post['message'] = str_ireplace($censoredword$changedword$this->post['message']); 
Or

PHP Code:
$censoredword = array(
'swear word1',
'swear word2'
);

$changedword = array(
'new word for all swears'
);

$this->post['message'] = str_ireplace($censoredword$changedword$this->post['message']); 
Reply With Quote
  #18  
Old 02-26-2012, 12:02 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You can have either one replacement for all words or a separate replacement for each word. But if you only want one replacement I think it might have to be a string instead of an array, like:

PHP Code:
$censoredword = array( 
'swear word1'
'swear word2' 
); 

$changedword 'new word for all swears'

$this->post['message'] = str_ireplace($censoredword$changedword$this->post['message']); 
Reply With Quote
  #19  
Old 02-26-2012, 12:46 PM
Emeralda's Avatar
Emeralda Emeralda is offline
 
Join Date: Oct 2011
Posts: 202
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

None of the two seemed to work >.<
Reply With Quote
  #20  
Old 02-26-2012, 12:54 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Well, I tried it with exactly the code above and it works, so maybe you have a typo somewhere? I'd suggest you post your code but I suppose it contains bad language.

ETA: or maybe it's just not working like you expected? Like Lynne mentioned in the other thread, this only changes it just before a post is displayed, so there are probably some situations where the swear word would be seen (like an RSS feed maybe?). If you want to change it permanently when the post is saved (which is the way the build-in censoring works), I think you could use hook newpost_process and code like this:

PHP Code:
$censoredword = array(  
'swear word1',  
'swear word2'  
);  

$changedword 'new word for all swears';  

$post['message'] = str_ireplace($censoredword$changedword$post['message']); 

I suppose a disadvantage to this way is that it won't change any existing swear words.
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 01:49 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.07162 seconds
  • Memory Usage 2,272KB
  • 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
  • (1)bbcode_html
  • (4)bbcode_php
  • (2)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (2)pagenav_pagelink
  • (10)post_thanks_box
  • (1)post_thanks_box_bit
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)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
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete