vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=251)
-   -   How do I change words in post texts? (https://vborg.vbsupport.ru/showthread.php?t=277456)

kh99 02-04-2012 01:43 PM

Strange. The above works for me, so I'm not sure what to try.

DonosOdD 02-04-2012 02:28 PM

Quote:

Originally Posted by kh99 (Post 2296098)
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!

DonosOdD 02-08-2012 01:19 AM

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!

kh99 02-08-2012 01:34 AM

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

Anyway, thanks for posting that.

Emeralda 02-25-2012 11:10 PM

Uhm... which hook should I chose to limit it to things in postbit?

kh99 02-25-2012 11:13 PM

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

Emeralda 02-26-2012 10:25 AM

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']); 


kh99 02-26-2012 12:02 PM

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']); 


Emeralda 02-26-2012 12:46 PM

None of the two seemed to work >.<

kh99 02-26-2012 12:54 PM

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.


All times are GMT. The time now is 02:03 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01090 seconds
  • Memory Usage 1,758KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_html_printable
  • (4)bbcode_php_printable
  • (2)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (2)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.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
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete