XOOPS  2.6.0
censor.php
Go to the documentation of this file.
1 <?php
2 /*
3  You may not change or alter any portion of this comment or credits
4  of supporting developers from this source code or any supporting source code
5  which is considered copyrighted (c) material of the original comment or credit authors.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 */
11 
32 {
38  public function load(MyTextSanitizer &$ts, $text, array $paramsConf=null)
39  {
40  static $censorConf;
41 
43 
44  if (!empty($paramsConf))
45  $censorConf = $paramsConf;
46 
47  if (!isset($censorConf)) {
48  $censorConf = $xoops->getConfigs();
49  $config = parent::loadConfig(__DIR__);
50  //merge and allow config override
51  $censorConf = array_merge($censorConf, $config);
52  }
53 
54  if (empty($censorConf['censor_enable'])) {
55  return $text;
56  }
57 
58  if (empty($censorConf['censor_words'])) {
59  return $text;
60  }
61 
62  if (!empty($censorConf['censor_admin']) && !$xoops->userIsAdmin) {
63  return $text;
64  }
65 
66  $replacement = empty($censorConf['censor_replace']) ? '!!censured!!' : $censorConf['censor_replace'];
67  if (is_array($censorConf['censor_words'])) foreach ($censorConf['censor_words'] as $bad) {
68  $bad = trim($bad);
69  if (!empty($bad)) {
70  if (false === strpos($text, $bad)) {
71  continue;
72  }
73  if (!empty($censorConf['censor_terminate'])) {
74  trigger_error("Censor words found", E_USER_ERROR);
75  $text = '';
76  return $text;
77  }
78  $patterns[] = "/(^|[^0-9a-z_]){$bad}([^0-9a-z_]|$)/siU";
79  $replacements[] = "\\1{$replacement}\\2";
80  $text = preg_replace($patterns, $replacements, $text);
81  }
82  }
83  return $text;
84  }
85 }
static getInstance()
Definition: Xoops.php:160
$text
Definition: qrrender.php:27
load(MyTextSanitizer &$ts, $text, array $paramsConf=null)
Definition: censor.php:38
$xoops
Definition: admin.php:25