ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilRTE Class Reference

Rich Text Editor base class This class provides access methods to a Rich Text Editor (RTE) integrated in ILIAS. More...

+ Inheritance diagram for ilRTE:
+ Collaboration diagram for ilRTE:

Public Member Functions

 __construct ()
 
 addPlugin (string $a_plugin_name)
 
 addButton (string $a_button_name)
 
 removePlugin (string $a_plugin_name)
 
 removeAllPlugins ()
 
 removeButton (string $a_button_name)
 
 addRTESupport (Language $lng, ilObjUser $user, int $obj_id, string $obj_type, string $a_module='', bool $allowFormElements=false, ?string $cfg_template=null)
 
 addUserTextEditor (string $editor_selector)
 
 addCustomRTESupport (int $obj_id, string $obj_type, array $tags)
 Adds custom support for an RTE in an ILIAS form. More...
 
 setRTERootBlockElement (?string $a_root_block_element)
 
 getRTERootBlockElement ()
 
 disableButtons ($a_button)
 Sets buttons which should be disabled in the RTE. More...
 
 getDisabledButtons (bool $as_list=true)
 Returns the disabled RTE buttons. More...
 
 getInitialWidth ()
 
 setInitialWidth (?int $initialWidth)
 

Static Public Member Functions

static _getRTEClassname ()
 
static _cleanupMediaObjectUsage (string $a_text, string $a_usage_type, int $a_usage_id)
 Synchronises appearances of media objects in $a_text with media object usage table. More...
 
static replaceLatexSpan (string $text)
 Replace the latex delimiters used by the rich text editor Unfortunately these can't be processed by MathJax: "Note that the delimiters can’t look like HTML tags (i.e., can’t include the less-than sign), as these would be turned into tags by the browser before MathJax has the chance to run. More...
 
static _replaceMediaObjectImageSrc (string $a_text, int $a_direction=0, string $nic='')
 Replaces image source from mob image urls with the mob id or replaces mob id with the correct image source. More...
 
static _getMediaObjects (string $a_text, int $a_direction=0)
 Returns all media objects found in the passed string. More...
 

Protected Attributes

ilGlobalTemplateInterface $tpl
 
ilCtrlInterface $ctrl
 
ilObjUser $user
 
ilLanguage $lng
 
AgentDetermination $browser
 
ilIniFile $client_init
 
int $initialWidth = null
 
string $root_block_element = null
 
array $plugins = []
 
array $buttons = []
 
array $disabled_buttons = []
 

Detailed Description

Rich Text Editor base class This class provides access methods to a Rich Text Editor (RTE) integrated in ILIAS.

Author
Helmut Schottmüller helmu.nosp@m.t.sc.nosp@m.hottm.nosp@m.uell.nosp@m.er@ma.nosp@m.c.co.nosp@m.m

Definition at line 30 of file class.ilRTE.php.

Constructor & Destructor Documentation

◆ __construct()

ilRTE::__construct ( )

Reimplemented in ilTinyMCE.

Definition at line 58 of file class.ilRTE.php.

59 {
60 global $DIC;
61
62 $this->tpl = $DIC['tpl'];
63 $this->ctrl = $DIC['ilCtrl'];
64 $this->lng = $DIC['lng'];
65 $this->browser = $DIC->http()->agent();
66 $this->client_init = $DIC['ilClientIniFile'];
67 $this->user = $DIC['ilUser'];
68 }
global $DIC
Definition: shib_login.php:26

References $DIC, ILIAS\Repository\ctrl(), ILIAS\Repository\lng(), and ILIAS\Repository\user().

+ Here is the call graph for this function:

Member Function Documentation

◆ _cleanupMediaObjectUsage()

static ilRTE::_cleanupMediaObjectUsage ( string  $a_text,
string  $a_usage_type,
int  $a_usage_id 
)
static

Synchronises appearances of media objects in $a_text with media object usage table.

Parameters
string$a_texttext, including media object tags
string$a_usage_typetype of context of usage, e.g. cat:html
int$a_usage_idif of context of usage, e.g. category id

Definition at line 145 of file class.ilRTE.php.

145 : void
146 {
147 $mobs = ilObjMediaObject::_getMobsOfObject($a_usage_type, $a_usage_id);
148 while (preg_match('/src=".*" data-id="([0-9]+)"/', $a_text, $found)) {
149 $a_text = str_replace($found[0], '', $a_text);
150 $found_mob_id = (int) $found[1];
151
152 if (!in_array($found_mob_id, $mobs, true) && ilObjMediaObject::_exists($found_mob_id)) {
153 // save usage if missing
154 ilObjMediaObject::_saveUsage($found_mob_id, $a_usage_type, $a_usage_id);
155 } else {
156 // if already saved everything ok -> take mob out of mobs array
157 unset($mobs[$found_mob_id]);
158 }
159 }
160 // remaining usages are not in text anymore -> delete them
161 // and media objects (note: delete method of ilObjMediaObject
162 // checks whether object is used in another context; if yes,
163 // the object is not deleted!)
164 foreach ($mobs as $mob) {
165 ilObjMediaObject::_removeUsage($mob, $a_usage_type, $a_usage_id);
166 $mob_obj = new ilObjMediaObject($mob);
167 $mob_obj->delete();
168 }
169 }
static _exists(int $id, bool $reference=false, ?string $type=null)
checks if an object exists in object_data
static _getMobsOfObject(string $a_type, int $a_id, int $a_usage_hist_nr=0, string $a_lang="-")
static _removeUsage(int $a_mob_id, string $a_type, int $a_id, int $a_usage_hist_nr=0, string $a_lang="-")
Remove usage of mob in another container.
static _saveUsage(int $a_mob_id, string $a_type, int $a_id, int $a_usage_hist_nr=0, string $a_lang="-")
Save usage of mob within another container (e.g.

References ilObjMediaObject\_exists(), ilObjMediaObject\_getMobsOfObject(), ilObjMediaObject\_removeUsage(), ilObjMediaObject\_saveUsage(), and ILIAS\Repository\int().

Referenced by assQuestion\cleanupMediaObjectUsage(), and SurveyQuestion\saveToDb().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _getMediaObjects()

static ilRTE::_getMediaObjects ( string  $a_text,
int  $a_direction = 0 
)
static

Returns all media objects found in the passed string.

Parameters
string$a_texttext, including media object tags
integer$a_direction0 to find image src, 1 to find mob id
Returns
int[] Array of media object ids

Definition at line 270 of file class.ilRTE.php.

270 : array
271 {
272 if ($a_text === '') {
273 return [];
274 }
275
276 $mediaObjects = [];
277 if ($a_direction === 0) {
278 $is_matching = preg_match_all('/src=".*" data-id="([0-9]+)"/', $a_text, $matches);
279 } else {
280 $is_matching = preg_match_all('/src="il_[0-9]+_mob_([0-9]+)"/', $a_text, $matches);
281 }
282
283 if ($is_matching) {
284 foreach ($matches[1] as $mob) {
285 $mob = (int) $mob;
286
287 if (ilObjMediaObject::_exists($mob) && !in_array($mob, $mediaObjects, true)) {
288 $mediaObjects[] = $mob;
289 }
290 }
291 }
292
293 return $mediaObjects;
294 }

References ilObjMediaObject\_exists(), and ILIAS\Repository\int().

Referenced by ilObjForumGUI\createThread(), ilObjForumGUI\deleteMobsOfDraft(), ilForumAutoSaveAsyncDraftAction\executeAndGetResponseObject(), and ilObjForumGUI\savePostObject().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _getRTEClassname()

static ilRTE::_getRTEClassname ( )
static

Definition at line 128 of file class.ilRTE.php.

128 : string
129 {
130 global $DIC;
131 $editor = (new ilRTESettings($DIC['lng'], $DIC['ilUser']))->getRichTextEditor();
132 if (strtolower($editor) === 'tinymce') {
133 return ilTinyMCE::class;
134 }
135
136 return self::class;
137 }

References $DIC.

Referenced by ilTextAreaInputGUI\insert(), and assTextQuestionGUI\magicAfterTestOutput().

+ Here is the caller graph for this function:

◆ _replaceMediaObjectImageSrc()

static ilRTE::_replaceMediaObjectImageSrc ( string  $a_text,
int  $a_direction = 0,
string  $nic = '' 
)
static

Replaces image source from mob image urls with the mob id or replaces mob id with the correct image source.

Parameters
string$a_texttext, including media object tags
integer$a_direction0 to replace image src => mob id, 1 to replace mob id => image src
string$nic
Returns
string The text containing the replaced media object src

Definition at line 228 of file class.ilRTE.php.

232 : string {
233 if ($a_text === '') {
234 return '';
235 }
236
237 if ($nic === '' && defined('IL_INST_ID')) {
238 $nic = (string) IL_INST_ID;
239 }
240
241 if ($a_direction === 0) {
242 $a_text = preg_replace(
243 '/src=".*" data-id="([0-9]+)"/',
244 'src="il_' . $nic . '_mob_\\1"',
245 $a_text
246 );
247 } else {
248 $resulttext = $a_text;
249 if (preg_match_all('/src="(il_[0-9]+_mob_([0-9]+))"/', $a_text, $matches)) {
250 foreach ($matches[2] as $idx => $mob) {
251 if (ilObject::_lookupType((int) $mob) === 'mob') {
252 $mob_obj = new ilObjMediaObject((int) $mob);
253 $path_to_file = $mob_obj->getStandardSrc();
254 $resulttext = str_replace("src=\"{$matches[1][$idx]}\"", "src=\"{$path_to_file}\" data-id=\"{$matches[2][$idx]}\"", $resulttext);
255 }
256 }
257 }
258 $a_text = $resulttext;
259 }
260
261 return $a_text;
262 }
static _lookupType(int $id, bool $reference=false)
const IL_INST_ID
Definition: constants.php:40

Referenced by assQuestionExport\addQTIMaterial(), ilObjForumGUI\createThread(), ilObjForumGUI\doHistoryCheck(), ilObjForumGUI\editThreadDraftObject(), ilForumAutoSaveAsyncDraftAction\executeAndGetResponseObject(), ilAssSelfAssessmentQuestionFormatter\format(), ilAssMultiOptionQuestionFeedback\getAllSpecificAnswerFeedbackContents(), ilObjTest\getCompleteManualFeedback(), ilObjTest\getFinalStatement(), ilAssQuestionFeedback\getGenericFeedbackContent(), ilObjTest\getIntroduction(), ilObjTest\getSingleManualFeedback(), ilAssMultiOptionQuestionFeedback\getSpecificAnswerFeedbackContent(), assKprimChoice\loadAnswerData(), assErrorText\loadFromDb(), assLongMenu\loadFromDb(), assMatchingQuestion\loadFromDb(), assOrderingHorizontal\loadFromDb(), assOrderingQuestion\loadFromDb(), assKprimChoice\loadFromDb(), ilObjSurvey\loadFromDb(), SurveyMatrixQuestion\loadFromDb(), SurveyMetricQuestion\loadFromDb(), SurveyMultipleChoiceQuestion\loadFromDb(), SurveySingleChoiceQuestion\loadFromDb(), SurveyTextQuestion\loadFromDb(), assClozeTest\loadFromDb(), assFileUpload\loadFromDb(), assFormulaQuestion\loadFromDb(), assImagemapQuestion\loadFromDb(), assMultipleChoice\loadFromDb(), assNumeric\loadFromDb(), assSingleChoice\loadFromDb(), assTextQuestion\loadFromDb(), assTextSubset\loadFromDb(), ilExAssignmentListTextTableGUI\parse(), assQuestionImport\processNonAbstractedImageReferences(), ilObjForumGUI\publishDraftObject(), ilForumExportGUI\renderPostHtml(), ilObjForumGUI\renderPostingForm(), ilObjTest\retrieveMobsFromLegacyImports(), assClozeTest\saveAdditionalQuestionDataToDb(), assMultipleChoice\saveAnswerSpecificDataToDb(), ilObjForumGUI\saveAsDraftObject(), ilAssQuestionFeedback\saveGenericFeedbackContent(), ilObjForumGUI\savePostObject(), assQuestion\saveQuestionDataToDb(), ilAssMultiOptionQuestionFeedback\saveSpecificAnswerFeedbackContent(), ilObjForumGUI\saveThreadAsDraftObject(), ilObjSurvey\saveToDb(), SurveyQuestion\saveToDb(), ilExSubmissionTextGUI\showAssignmentTextObject(), ILIAS\Test\Settings\MainSettings\SettingsMainGUI\showOldConcludingRemarks(), ILIAS\Test\Settings\MainSettings\SettingsMainGUI\showOldIntroduction(), ilForumXMLWriter\start(), assErrorText\toJSON(), assErrorText\toLog(), ilObjTest\toXML(), ilObjForumGUI\updateDraftObject(), and ilObjForumGUI\updateThreadDraftObject().

+ Here is the caller graph for this function:

◆ addButton()

ilRTE::addButton ( string  $a_button_name)

Definition at line 75 of file class.ilRTE.php.

75 : void
76 {
77 $this->buttons[] = $a_button_name;
78 }

◆ addCustomRTESupport()

ilRTE::addCustomRTESupport ( int  $obj_id,
string  $obj_type,
array  $tags 
)

Adds custom support for an RTE in an ILIAS form.

Parameters
int$obj_id
string$obj_type
string[]$tags

Reimplemented in ilTinyMCE.

Definition at line 124 of file class.ilRTE.php.

124 : void
125 {
126 }

◆ addPlugin()

ilRTE::addPlugin ( string  $a_plugin_name)

Definition at line 70 of file class.ilRTE.php.

70 : void
71 {
72 $this->plugins[] = $a_plugin_name;
73 }

◆ addRTESupport()

ilRTE::addRTESupport ( Language  $lng,
ilObjUser  $user,
int  $obj_id,
string  $obj_type,
string  $a_module = '',
bool  $allowFormElements = false,
?string  $cfg_template = null 
)

Reimplemented in ilTinyMCE.

Definition at line 103 of file class.ilRTE.php.

111 : void {
112 }

◆ addUserTextEditor()

ilRTE::addUserTextEditor ( string  $editor_selector)

Reimplemented in ilTinyMCE.

Definition at line 114 of file class.ilRTE.php.

114 : void
115 {
116 }

◆ disableButtons()

ilRTE::disableButtons (   $a_button)

Sets buttons which should be disabled in the RTE.

Parameters
string[] | string$a_buttonEither a button string or an array of button strings
Returns
self

Definition at line 312 of file class.ilRTE.php.

312 : self
313 {
314 if (is_array($a_button)) {
315 $this->disabled_buttons = array_unique(array_merge($this->disabled_buttons, $a_button));
316 } else {
317 $this->disabled_buttons = array_unique(array_merge($this->disabled_buttons, [$a_button]));
318 }
319
320 return $this;
321 }

◆ getDisabledButtons()

ilRTE::getDisabledButtons ( bool  $as_list = true)

Returns the disabled RTE buttons.

Parameters
bool$as_listShould the disabled buttons be returned as a string or as an array
Returns
string[]|string

Definition at line 328 of file class.ilRTE.php.

329 {
330 if (!$as_list) {
331 return implode(',', $this->disabled_buttons);
332 }
333
335 }
array $disabled_buttons
Definition: class.ilRTE.php:56

◆ getInitialWidth()

ilRTE::getInitialWidth ( )

Definition at line 337 of file class.ilRTE.php.

337 : ?int
338 {
339 return $this->initialWidth;
340 }
int $initialWidth
Definition: class.ilRTE.php:38

◆ getRTERootBlockElement()

ilRTE::getRTERootBlockElement ( )

Definition at line 302 of file class.ilRTE.php.

302 : ?string
303 {
305 }
string $root_block_element
Definition: class.ilRTE.php:44

◆ removeAllPlugins()

ilRTE::removeAllPlugins ( )

Definition at line 88 of file class.ilRTE.php.

88 : void
89 {
90 foreach ($this->plugins as $plugin) {
91 $this->removePlugin($plugin);
92 }
93 }
removePlugin(string $a_plugin_name)
Definition: class.ilRTE.php:80

References XapiProxy\$plugin, and removePlugin().

+ Here is the call graph for this function:

◆ removeButton()

ilRTE::removeButton ( string  $a_button_name)

Definition at line 95 of file class.ilRTE.php.

95 : void
96 {
97 $key = array_search($a_button_name, $this->buttons, true);
98 if ($key !== false) {
99 unset($this->buttons[$key]);
100 }
101 }

◆ removePlugin()

ilRTE::removePlugin ( string  $a_plugin_name)

Definition at line 80 of file class.ilRTE.php.

80 : void
81 {
82 $key = array_search($a_plugin_name, $this->plugins, true);
83 if ($key !== false) {
84 unset($this->plugins[$key]);
85 }
86 }

Referenced by removeAllPlugins().

+ Here is the caller graph for this function:

◆ replaceLatexSpan()

static ilRTE::replaceLatexSpan ( string  $text)
static

Replace the latex delimiters used by the rich text editor Unfortunately these can't be processed by MathJax: "Note that the delimiters can’t look like HTML tags (i.e., can’t include the less-than sign), as these would be turned into tags by the browser before MathJax has the chance to run.

You can only include text, not tags, as your math delimiters."

See also
https://docs.mathjax.org/en/latest/options/input/tex.html#option-descriptions

This function should called by components that display RTE content.

Definition at line 181 of file class.ilRTE.php.

181 : string
182 {
183 $start = '<span class="latex">';
184 $end = '</span>';
185 $start_len = ilStr::strLen($start);
186 $end_len = ilStr::strLen($end);
187
188 // current position to start the search for delimiters
189 $cpos = 0;
190
191 // find position of start delimiter
192 while (is_int($spos = ilStr::strIPos($text, $start, $cpos))) {
193
194 // find position of end delimiter
195 $epos = ilStr::strIPos($text, $end, $spos + $start_len);
196 if (!is_int($epos)) {
197 break;
198 }
199
200 // extract the tex code inside the delimiters
201 $tex = ilStr::subStr($text, $spos + $start_len, $epos - $spos - $start_len);
202
203 // wrap the tex code in new delimiters
204 $replace = '[tex]' . $tex . '[/tex]';
205
206 // replace the span
207 $text = ilStr::subStr($text, 0, $spos) . $replace . ilStr::subStr($text, $epos + $end_len);
208
209 // continue search behind the replacement
210 $cpos = $spos + ilStr::strLen($replace);
211
212 if ($cpos >= ilStr::strlen($text)) {
213 // current position at the end => stop search
214 break;
215 }
216 }
217
218 return $text;
219 }
static subStr(string $a_str, int $a_start, ?int $a_length=null)
Definition: class.ilStr.php:21
static strLen(string $a_string)
Definition: class.ilStr.php:60
static strIPos(string $a_haystack, string $a_needle, int $a_offset=0)
Definition: class.ilStr.php:51

References ilStr\strIPos(), ilStr\strLen(), and ilStr\subStr().

Referenced by ilAssSelfAssessmentQuestionFormatter\format(), ilAssSelfAssessmentQuestionFormatter\migrateToLmContent(), ilForum\prepareText(), and ilLegacyFormElementsUtil\prepareTextareaOutput().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setInitialWidth()

ilRTE::setInitialWidth ( ?int  $initialWidth)

Definition at line 342 of file class.ilRTE.php.

342 : void
343 {
344 $this->initialWidth = $initialWidth;
345 }

◆ setRTERootBlockElement()

ilRTE::setRTERootBlockElement ( ?string  $a_root_block_element)

Definition at line 296 of file class.ilRTE.php.

296 : self
297 {
298 $this->root_block_element = $a_root_block_element;
299 return $this;
300 }

Field Documentation

◆ $browser

AgentDetermination ilRTE::$browser
protected

Definition at line 36 of file class.ilRTE.php.

◆ $buttons

array ilRTE::$buttons = []
protected

Definition at line 50 of file class.ilRTE.php.

◆ $client_init

ilIniFile ilRTE::$client_init
protected

Definition at line 37 of file class.ilRTE.php.

◆ $ctrl

ilCtrlInterface ilRTE::$ctrl
protected

Definition at line 33 of file class.ilRTE.php.

◆ $disabled_buttons

array ilRTE::$disabled_buttons = []
protected

Definition at line 56 of file class.ilRTE.php.

◆ $initialWidth

int ilRTE::$initialWidth = null
protected

Definition at line 38 of file class.ilRTE.php.

◆ $lng

ilLanguage ilRTE::$lng
protected

Definition at line 35 of file class.ilRTE.php.

◆ $plugins

array ilRTE::$plugins = []
protected

Definition at line 47 of file class.ilRTE.php.

Referenced by ilTinyMCE\getPlugins().

◆ $root_block_element

string ilRTE::$root_block_element = null
protected

Definition at line 44 of file class.ilRTE.php.

◆ $tpl

ilGlobalTemplateInterface ilRTE::$tpl
protected

Definition at line 32 of file class.ilRTE.php.

◆ $user

ilObjUser ilRTE::$user
protected

Definition at line 34 of file class.ilRTE.php.


The documentation for this class was generated from the following file: