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:
12: namespace Xoops\Core\Text\Sanitizer\Extensions;
13:
14: use Xoops\Core\Text\Sanitizer;
15: use Xoops\Core\Text\Sanitizer\FilterAbstract;
16:
17: /**
18: * TextSanitizer filter to Replace banned words in a string with their replacements
19: * or terminate current request
20: *
21: * @category Sanitizer
22: * @package Xoops\Core\Text
23: * @author Taiwen Jiang <phppp@users.sourceforge.net>
24: * @copyright 2000-2015 XOOPS Project (http://xoops.org)
25: * @license GNU GPL 2 (http://www.gnu.org/licenses/gpl-2.0.html)
26: * @link http://xoops.org
27: */
28: class Quote extends FilterAbstract
29: {
30: /**
31: * @var array default configuration values
32: */
33: protected static $defaultConfiguration = [
34: 'enabled' => true,
35: ];
36:
37: /**
38: * Convert quote codes to blockquote tags
39: *
40: * This seems to work for well matched sets, but is actually crisscrossing nested tags
41: *
42: * @param string $text text to censor
43: *
44: * @return string
45: */
46: public function applyFilter($text)
47: {
48: if (!$this->config['enabled']) {
49: return $text;
50: }
51:
52: //look for both open and closing tags in the correct order
53: $pattern = "/\[quote](.*)\[\/quote\]/sU";
54: $replacement = \XoopsLocale::C_QUOTE . '<div class="xoopsQuote"><blockquote>\\1</blockquote></div>';
55:
56: $text = preg_replace($pattern, $replacement, $text, -1, $count);
57: //no more matches, return now
58: if (!$count) {
59: return $text;
60: }
61: //new matches could have been created, keep doing it until we have no matches
62: return $this->applyFilter($text);
63: }
64: }
65: