| 1: | <?php
|
| 2: | |
| 3: | |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: | |
| 9: | |
| 10: | |
| 11: | |
| 12: | |
| 13: | |
| 14: | |
| 15: | |
| 16: | |
| 17: | |
| 18: |
|
| 19: | defined('XOOPS_ROOT_PATH') || exit('Restricted access');
|
| 20: |
|
| 21: | |
| 22: | |
| 23: | |
| 24: | |
| 25: | |
| 26: | |
| 27: |
|
| 28: | class MytsCensor extends MyTextSanitizerExtension
|
| 29: | {
|
| 30: | |
| 31: | |
| 32: | |
| 33: | |
| 34: | |
| 35: |
|
| 36: | public function load($myts, $text)
|
| 37: | {
|
| 38: | static $censorConf;
|
| 39: | if (!isset($censorConf)) {
|
| 40: |
|
| 41: | $config_handler = xoops_getHandler('config');
|
| 42: | $censorConf = $config_handler->getConfigsByCat(XOOPS_CONF_CENSOR);
|
| 43: | $config = parent::loadConfig(__DIR__);
|
| 44: |
|
| 45: | $censorConf = array_merge($censorConf, $config);
|
| 46: | }
|
| 47: |
|
| 48: | if (empty($censorConf['censor_enable'])) {
|
| 49: | return $text;
|
| 50: | }
|
| 51: |
|
| 52: | if (empty($censorConf['censor_words'])) {
|
| 53: | return $text;
|
| 54: | }
|
| 55: |
|
| 56: | if (empty($censorConf['censor_admin']) && $GLOBALS['xoopsUserIsAdmin']) {
|
| 57: | return $text;
|
| 58: | }
|
| 59: |
|
| 60: | $replacement = $censorConf['censor_replace'];
|
| 61: | foreach ($censorConf['censor_words'] as $bad) {
|
| 62: | $bad = trim($bad);
|
| 63: | if (!empty($bad)) {
|
| 64: | if (false === strpos($text, $bad)) {
|
| 65: | continue;
|
| 66: | }
|
| 67: | if (!empty($censorConf['censor_terminate'])) {
|
| 68: | trigger_error('Censor words found', E_USER_ERROR);
|
| 69: | $text = '';
|
| 70: |
|
| 71: | return $text;
|
| 72: | }
|
| 73: | $patterns[] = "/(^|[^0-9a-z_]){$bad}([^0-9a-z_]|$)/siU";
|
| 74: | $replacements[] = "\\1{$replacement}\\2";
|
| 75: | $text = preg_replace($patterns, $replacements, $text);
|
| 76: | }
|
| 77: | }
|
| 78: |
|
| 79: | return $text;
|
| 80: | }
|
| 81: | }
|
| 82: | |