Oh no! Where's the JavaScript?
Your Web browser does not have JavaScript enabled or does not support JavaScript. Please enable JavaScript on your Web browser to properly view this Web site, or upgrade to a Web browser that does support JavaScript.
Not a member yet? Click here to register.
Forgot Password?

Need fix function censorwords($text) in maincore.php

Asked Modified Viewed 921 times
W
Wanabo
W
Wanabo 10
www.probemyip.com/probe-my-ip-80x15.png
pHp-Fusion.Asia & pHp-Fusion.Fr & pHp-Fusion.Cn are available for a localized support community. Send PB for info.
  • Senior Member, joined since
  • Contributed 598 posts on the community forums.
  • Started 94 threads in the forums
  • Started this discussions
asked
Senior Member

maincore.php
// Replace offensive words with the defined replacement word
function censorwords($text) {
 global $settings;
 if ($settings['bad_words_enabled'] == "1" && $settings['bad_words'] != "") {
 $word_list = explode("rn", $settings['bad_words']);
 for ($i = 0; $i < count($word_list); $i++) {
 if ($word_list[$i] != "")
 $text = preg_replace("/".$word_list[$i]."/si", $settings['bad_word_replace'], $text);
 }
 }
 return $text;
}


Database:
bad_words_enabled = 1
bad_words = test
bad_word_replace = ***


Problem: the bad words do not get replaced in forum/viewthread.php
0 replies

3 posts

C
Chan
C
Chan 0
Lead Developer of PHP-Fusion
  • Super Admin, joined since
  • Contributed 3,841 posts on the community forums.
  • Started 232 threads in the forums
  • Answered 6 questions
answered
Super Admin

This code does not work?

/**
 * Replace offensive words with the defined replacement word.
 * The list of offensive words and the replacement word are both defined in the Security Settings.
 *
 * @param string $text Text that should be censored.
 *
 * @return string Censored text.
 */
function censorwords($text) {

 $settings = fusion_get_settings();

 if ($settings['bad_words_enabled'] && !empty($settings['bad_words'])) {
 $words = preg_quote(trim($settings['bad_words']), "/");
 $words = preg_replace("/s+/", "|", $words);
 $text = preg_replace("/".$words."/si", $settings['bad_word_replace'], $text);
 }

 return $text;
}
0 replies
W
Wanabo
W
Wanabo 10
www.probemyip.com/probe-my-ip-80x15.png
pHp-Fusion.Asia & pHp-Fusion.Fr & pHp-Fusion.Cn are available for a localized support community. Send PB for info.
  • Senior Member, joined since
  • Contributed 598 posts on the community forums.
  • Started 94 threads in the forums
  • Started this discussions
answered
Senior Member

No the code from maincore v9 does not work, I had tried that all ready.

But I see now my viewing angle is wrong.
function censorwords is used when posting and not when viewing.

I presumed that function censorwords was used when viewing a post or comment. That would make more sense to me. Because this way you can all ways block unwanted words or links after the evil is done. It might take some time before you realize some one is posting words or links you do not want. Then it would be quite an effort to remove this afterwards.

I added this code to viewthread.php to get the behavior I want.
// Replace offensive words with the defined replacement word
 if ($settings['bad_words_enabled'] == "1" && $settings['bad_words'] != "") {
 $word_list = explode("rn", $settings['bad_words']);
 for ($i = 0; $i < count($word_list); $i++) {
 if ($word_list[$i] != "")
 $message = preg_replace("/".$word_list[$i]."/si", $settings['bad_word_replace'], $message);
 }
 }
 return $message;
0 replies
C
Chan
C
Chan 0
Lead Developer of PHP-Fusion
  • Super Admin, joined since
  • Contributed 3,841 posts on the community forums.
  • Started 232 threads in the forums
  • Answered 6 questions
answered
Super Admin

We try to consume resources as few as possible during optimization. Having it at POST was done by the sanitizer function to ensure values are entirely safe to be viewed by audience or be recorded as needed. That is the purpose of sanitization - If it is prevented from happening, there will be no cure required. But there could be times, of course that we are unable to curb it successfully, and that requires direct action from system admin.

You could direct edit that post containing the censored words and mark it *** manually.
0 replies

Category Forum

Settings - 8

Labels

None yet

Statistics

  • Views 0 views
  • Posts 3 posts
  • Votes 0 votes
  • Topic users 2 members

0 participants

Notifications

Track thread

You are not receiving notifications from this thread.

Related Questions

Not yet