1: <?php
2: 3: 4:
5: function smarty_outputfilter_shortcodes($output, Smarty_Internal_Template $template)
6: {
7: $shortcodes = \Xoops\Core\Text\Sanitizer::getInstance()->getShortCodes();
8: $shortcodes->addShortcode(
9: 'nosc42',
10: function ($attributes, $content, $tagName) {
11: return $content;
12: }
13: );
14:
15:
16: $bodyPattern = '/<body[^>]*>(.*?)<\/body>/is';
17:
18:
19: $scPattern = '/((<textarea[\S\s]*\/textarea>)|(<input[\S\s]*>)|(<select[\S\s]*\/select>)|(<script[\S\s]*\/script>)|(<style[\S\s]*\/style>))/U';
20:
21: $text = preg_replace_callback(
22: $bodyPattern,
23: function ($matches) use ($scPattern, $shortcodes) {
24: $element = preg_replace_callback(
25: $scPattern,
26: function ($innerMatches) {
27: return '[nosc42]' . $innerMatches[0] . '[/nosc42]';
28: },
29: $matches[1]
30: );
31: if ($element===null) {
32: trigger_error('preg_last_error=' . preg_last_error(), E_USER_WARNING);
33: return $matches[1];
34: }
35: return $element;
36: },
37: $output
38: );
39:
40: if ($text===null) {
41: trigger_error('preg_last_error=' . preg_last_error(), E_USER_WARNING);
42: return $output;
43: }
44: $text = $shortcodes->process($text);
45: return $text;
46: }
47: