XOOPS 2.5.6  Final
 All Classes Namespaces Files Functions Variables Pages
censor.php
Go to the documentation of this file.
1 <?php
20 defined('XOOPS_ROOT_PATH') or die('Restricted access');
21 
30 {
31  function load(&$ts, $text)
32  {
33  static $censorConf;
34  if (!isset($censorConf)) {
35  $config_handler = & xoops_gethandler('config');
36  $censorConf = $config_handler->getConfigsByCat(XOOPS_CONF_CENSOR);
37  $config = parent::loadConfig(dirname(__FILE__));
38  //merge and allow config override
39  $censorConf = array_merge($censorConf, $config);
40  }
41 
42  if (empty($censorConf['censor_enable'])) {
43  return $text;
44  }
45 
46  if (empty($censorConf['censor_words'])) {
47  return $text;
48  }
49 
50  if (empty($censorConf['censor_admin']) && $GLOBALS['xoopsUserIsAdmin']) {
51  return $text;
52  }
53 
54  $replacement = $censorConf['censor_replace'];
55  foreach ($censorConf['censor_words'] as $bad) {
56  $bad = trim($bad);
57  if (!empty($bad)) {
58  if (false === strpos($text, $bad)) {
59  continue;
60  }
61  if (!empty($censorConf['censor_terminate'])) {
62  trigger_error("Censor words found", E_USER_ERROR);
63  $text = '';
64  return $text;
65  }
66  $patterns[] = "/(^|[^0-9a-z_]){$bad}([^0-9a-z_]|$)/siU";
67  $replacements[] = "\\1{$replacement}\\2";
68  $text = preg_replace($patterns, $replacements, $text);
69  }
70  }
71  return $text;
72  }
73 }
74 
75 ?>