1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10:
11:
12: namespace Xoops\Core\Text\Sanitizer\Extensions;
13:
14: use Xoops\Core\Text\Sanitizer;
15: use Xoops\Core\Text\Sanitizer\ExtensionAbstract;
16:
17: 18: 19: 20: 21: 22: 23: 24: 25: 26:
27: class XoopsCode extends ExtensionAbstract
28: {
29: 30: 31:
32: protected static $defaultConfiguration = ['enabled' => true];
33:
34: 35: 36: 37: 38:
39: public function registerExtensionProcessing()
40: {
41: $shortcodes = $this->shortcodes;
42:
43: $shortcodes->addShortcode(
44: 'siteurl',
45: function ($attributes, $content, $tagName) use ($shortcodes) {
46: $url = ltrim($attributes[0], '=');
47: $url = \Xoops::getInstance()->url($url);
48: $newcontent = '<a href="' .$url. '">' . $shortcodes->process($content) . '</a>';
49: return $newcontent;
50: }
51: );
52:
53: $shortcodes->addShortcode(
54: 'url',
55: function ($attributes, $content, $tagName) use ($shortcodes) {
56: $url = ltrim($attributes[0], '=');
57: $url = \Xoops::getInstance()->url($url);
58: $newcontent = '<a href="' .$url. '">' . $shortcodes->process($content) . '</a>';
59: return $newcontent;
60: }
61: );
62:
63: $shortcodes->addShortcode(
64: 'color',
65: function ($attributes, $content, $tagName) use ($shortcodes) {
66: $color = ltrim($attributes[0], '=');
67: $color = preg_match('/^[a-f0-9]{3}$|^[a-f0-9]{6}$/i', $color) ? '#' . $color : $color;
68: $newcontent = '<span style="color: ' .$color. '">' . $shortcodes->process($content) . '</span>';
69: return $newcontent;
70: }
71: );
72:
73: $shortcodes->addShortcode(
74: 'size',
75: function ($attributes, $content, $tagName) use ($shortcodes) {
76: $size = ltrim($attributes[0], '=');
77: $newcontent = '<span style="font-size: ' .$size. '">' . $shortcodes->process($content) . '</span>';
78: return $newcontent;
79: }
80: );
81:
82: $shortcodes->addShortcode(
83: 'font',
84: function ($attributes, $content, $tagName) use ($shortcodes) {
85: $font = ltrim($attributes[0], '=');
86: $newcontent = '<span style="font-family: ' .$font. '">' . $shortcodes->process($content) . '</span>';
87: return $newcontent;
88: }
89: );
90:
91: $shortcodes->addShortcode(
92: 'email',
93: function ($attributes, $content, $tagName) {
94: $newcontent = '<a href="mailto:' . trim($content) . '</a>';
95: return $newcontent;
96: }
97: );
98:
99: $shortcodes->addShortcode(
100: 'b',
101: function ($attributes, $content, $tagName) use ($shortcodes) {
102: $newcontent = '<strong>' . $shortcodes->process($content) . '</strong>';
103: return $newcontent;
104: }
105: );
106:
107: $shortcodes->addShortcode(
108: 'i',
109: function ($attributes, $content, $tagName) use ($shortcodes) {
110: $newcontent = '<em>' . $shortcodes->process($content) . '</em>';
111: return $newcontent;
112: }
113: );
114:
115: $shortcodes->addShortcode(
116: 'u',
117: function ($attributes, $content, $tagName) use ($shortcodes) {
118: $newcontent = '<u>' . $shortcodes->process($content) . '</u>';
119: return $newcontent;
120: }
121: );
122:
123: $shortcodes->addShortcode(
124: 'd',
125: function ($attributes, $content, $tagName) use ($shortcodes) {
126: $newcontent = '<del>' . $shortcodes->process($content) . '</del>';
127: return $newcontent;
128: }
129: );
130:
131: $shortcodes->addShortcode(
132: 'center',
133: function ($attributes, $content, $tagName) use ($shortcodes) {
134: $newcontent = '<div style="text-align: center;">' . $shortcodes->process($content) . '</div>';
135: return $newcontent;
136: }
137: );
138:
139: $shortcodes->addShortcode(
140: 'left',
141: function ($attributes, $content, $tagName) use ($shortcodes) {
142: $newcontent = '<div style="text-align: left;">' . $shortcodes->process($content) . '</div>';
143: return $newcontent;
144: }
145: );
146:
147: $shortcodes->addShortcode(
148: 'right',
149: function ($attributes, $content, $tagName) use ($shortcodes) {
150: $newcontent = '<div style="text-align: right;">' . $shortcodes->process($content) . '</div>';
151: return $newcontent;
152: }
153: );
154: }
155: }
156: