The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
|||
|
|||
How do I change words in post texts?
Hi everyone,
I wanted to have a wordfilter, to replace a censored word for a word I want, in all forum sections but one specific. when I was looking online for how to solve this, I've found this link: https://vborg.vbsupport.ru/showthread.php?t=219968 which contained this code: PHP Code:
So I changed it to: PHP Code:
I wonder if this code is right, where should I put it, and how would I make it work for all subforums but one. Sorry for this silly question, but I don't know PHP. Thanks in advance! |
#2
|
|||
|
|||
That code looks right - it will of course replace all occurences of 'word1' and 'word2' even if they are part of another word (or a bbcode, or a link, etc), so you have to be a little careful how it's used.
The linked post says you should create a new plugin using hook location postbit_display_complete and that code. |
#3
|
|||
|
|||
Thank you, however, it still tricks me in those 3 points:
1- how do I create a new plugin (and using this hook location)? 2-where is postbit_display_complete? (I haven't found it, so I thought it exists only in previous versions, not vb4) 3-how do I make it work for all forum sections but one? I thought using a simple if statement: PHP Code:
Again, thanks in advance! |
#4
|
|||
|
|||
Create a new plugin by going to Add New Plugin under Plugins & Products in the adminCP. Choose the hook location from the dropdown menu, enter a title so you'll remember what it does later, and paste the code in the large text area. Click the "Yes" radio button to enable it, and press "Save".
To have one forum be exempt, put this around the code: Code:
if ($forum['forumid'] != X) { // insert code here } and of course replace X with the forum id. |
#5
|
|||
|
|||
I've done it, it was very simple indeed, and worked without problems.
Thank you! Hope this question helps out other people too. |
#6
|
|||
|
|||
Hello again
I've tried it and it was fine - until I decided to use the function preg_replace instead of str_replace. And what happened was, all the posts went blank (all characters removed). I wanted to use preg_replace because it's better for general word replacing. Any thoughts? Thanks! |
#7
|
|||
|
|||
preg_replace returns NULL if there's an error, so my guess would be that you're passing it something that's not a valid pattern.
You could try something like this (for testing only): Code:
$ret = preg_replace($pat, $rep, $this->post['message']); if ($ret !== NULL) $this->post['message'] = $ret; else $this->post['message'] .= '<BR /><BR />Pattern error: ' . preg_last_error(); |
#8
|
|||
|
|||
Yeah, tried it and got Pattern Error 0.
This is the code I'm using, trying to simply change "foo" to "boo". PHP Code:
Thanks again! |
#9
|
|||
|
|||
Well, slightly bad choice of error message wording on my part - 0 is actually 'no error', so it's apparently not a pattern error. [S]But what I don't understand is why you seem to be getting NULL returned if there's no error.[/S] (See below)
I tried your code in a test script and it works for me: PHP Code:
Code:
new text : boo ETA: OK, further testing, that error code returned from preg_last_error isn't very useful - I purposely put in a bad pattern and I got NULL as a return, but 0 from preg_last_error(), just like you did. So I guess you *do* have an error in one of your patterns. I assume what you posted is a simplified version of what you're actually using, so I guess you'll have to look them over carefully to check for bad pattern string syntax. |
Благодарность от: | ||
DonosOdD |
#10
|
|||
|
|||
Hello again, and sorry for the late response (I haven't worked on the forum for some time).
Your answers were great, and I was able to do this: PHP Code:
And it worked fine. However, my forum is in portuguese, and when I change something to a word with any accentuation, like ? or ?, the code changes nothing at all (I guess ret == null). I'm bypassing it by writing the words without accentuation. Any thoughts? Thanks! EDIT: It doesn't work. Well, it worked for a while, but after two tests and two F5s, it stopped working. I can't understand why. And I was using this exact code, with this silly words. |
Thread Tools | |
Display Modes | |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|