ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilRTESettings.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
24{
25 private const ALL_AVAILABLE_TAGS = [
26 'a',
27 'blockquote',
28 'br',
29 'cite',
30 'code',
31 'dd',
32 'div',
33 'dl',
34 'dt',
35 'em',
36 'h1',
37 'h2',
38 'h3',
39 'h4',
40 'h5',
41 'h6',
42 'hr',
43 'img',
44 'li',
45 'object',
46 'ol',
47 'p',
48 'param',
49 'pre',
50 'span',
51 'strike',
52 'strong',
53 'sub',
54 'sup',
55 'table',
56 'td',
57 'tr',
58 'u',
59 'ul',
60 'ruby', // Ruby Annotation XHTML module
61 'rbc',
62 'rtc',
63 'rb',
64 'rt',
65 'rp'
66 ];
67
68 private const DEFAULT_TAGS = [
69 'a',
70 'blockquote',
71 'br',
72 'cite',
73 'code',
74 'dd',
75 'div',
76 'dl',
77 'dt',
78 'em',
79 'h1',
80 'h2',
81 'h3',
82 'h4',
83 'h5',
84 'h6',
85 'hr',
86 'img',
87 'li',
88 'ol',
89 'p',
90 'pre',
91 'span',
92 'strike',
93 'strong',
94 'sub',
95 'sup',
96 'u',
97 'ul'
98 ];
99
101 'a',
102 'blockquote',
103 'br',
104 'code',
105 'div',
106 'em',
107 'img',
108 'li',
109 'ol',
110 'p',
111 'strong',
112 'u',
113 'ul',
114 'span'
115 ];
116
118
119 public function __construct(
120 private readonly Language $lng,
121 private readonly ?ilObjUser $current_user = null
122 ) {
123 $this->advanced_editing = new ilSetting('advanced_editing');
124 }
125
126 public static function _getUsedHTMLTags(string $module = ''): array
127 {
128 $tags = (new ilSetting('advanced_editing'))->get('advanced_editing_used_html_tags_' . $module, '');
129
130 if ($tags === '') {
131 if ($module === 'frm_post' || $module === 'exc_ass') {
133 }
134 return self::DEFAULT_TAGS;
135 }
136
137 $usedtags = unserialize($tags, ['allowed_classes' => false]);
138 if ($module !== 'frm_post') {
139 return $usedtags;
140 }
141
142 if (!in_array('div', $usedtags, true)) {
143 $usedtags[] = 'div';
144 }
145
146 if (!in_array('blockquote', $usedtags, true)) {
147 $usedtags[] = 'blockquote';
148 }
149
150 return $usedtags;
151 }
152
153 public static function _getUsedHTMLTagsAsString(string $module = ''): string
154 {
155 return array_reduce(
156 self::_getUsedHTMLTags(),
157 static fn(string $c, string $v): string => $c . '<$v>',
158 ''
159 );
160 }
161
162 public function getRichTextEditor(): string
163 {
164 return $this->advanced_editing->get('advanced_editing_javascript_editor', '0');
165 }
166
167 public function setRichTextEditor(string $js_editor): void
168 {
169 $this->advanced_editing->set('advanced_editing_javascript_editor', $js_editor);
170 }
171
172 public function setUsedHTMLTags(
173 array $html_tags,
174 string $module
175 ): void {
176 if ($module === '') {
177 return;
178 }
179
180 $auto_added_tags = [];
181 if ($module === 'frm_post') {
182 if (!in_array('div', $html_tags, true)) {
183 $auto_added_tags[] = 'div';
184 }
185
186 if (!in_array('blockquote', $html_tags, true)) {
187 $auto_added_tags[] = 'blockquote';
188 }
189 }
190
191 $this->advanced_editing->set(
192 'advanced_editing_used_html_tags_' . $module,
193 serialize(array_merge($html_tags, $auto_added_tags))
194 );
195
196 if ($auto_added_tags !== []) {
198 sprintf(
199 $this->lng->txt('advanced_editing_required_tags'),
200 implode(', ', $auto_added_tags)
201 )
202 );
203 }
204 }
205
206 public function getAllAvailableHTMLTags(): array
207 {
208 return self::ALL_AVAILABLE_TAGS;
209 }
210
211 public function setRichTextEditorUserState(int $state): void
212 {
213 $this->current_user->writePref('show_rte', (string) $state);
214 }
215
217 {
218
219 if ($this->current_user->getPref('show_rte') !== '') {
220 return (int) $this->current_user->getPref('show_rte');
221 }
222 return 1;
223 }
224}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
User class.
setUsedHTMLTags(array $html_tags, string $module)
static _getUsedHTMLTags(string $module='')
setRichTextEditor(string $js_editor)
const ALL_AVAILABLE_TAGS
__construct(private readonly Language $lng, private readonly ?ilObjUser $current_user=null)
static _getUsedHTMLTagsAsString(string $module='')
ilSetting $advanced_editing
setRichTextEditorUserState(int $state)
const DEFAULT_FORUM_AND_EXERCISE_TAGS
ILIAS Setting Class.
$c
Definition: deliver.php:25
global $lng
Definition: privfeed.php:31
if(!file_exists('../ilias.ini.php'))