ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
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 (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 _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 29 of file class.ilRTE.php.

Constructor & Destructor Documentation

◆ __construct()

ilRTE::__construct ( )

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

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

58  {
59  global $DIC;
60 
61  $this->tpl = $DIC['tpl'];
62  $this->ctrl = $DIC['ilCtrl'];
63  $this->lng = $DIC['lng'];
64  $this->browser = $DIC->http()->agent();
65  $this->client_init = $DIC['ilClientIniFile'];
66  $this->user = $DIC['ilUser'];
67  }
global $DIC
Definition: shib_login.php:25
+ 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 141 of file class.ilRTE.php.

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

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

141  : void
142  {
143  $mobs = ilObjMediaObject::_getMobsOfObject($a_usage_type, $a_usage_id);
144  while (preg_match('/src=".*" data-id="([0-9]+)"/', $a_text, $found)) {
145  $a_text = str_replace($found[0], '', $a_text);
146  $found_mob_id = (int) $found[1];
147 
148  if (!in_array($found_mob_id, $mobs, true) && ilObjMediaObject::_exists($found_mob_id)) {
149  // save usage if missing
150  ilObjMediaObject::_saveUsage($found_mob_id, $a_usage_type, $a_usage_id);
151  } else {
152  // if already saved everything ok -> take mob out of mobs array
153  unset($mobs[$found_mob_id]);
154  }
155  }
156  // remaining usages are not in text anymore -> delete them
157  // and media objects (note: delete method of ilObjMediaObject
158  // checks whether object is used in another context; if yes,
159  // the object is not deleted!)
160  foreach ($mobs as $mob) {
161  ilObjMediaObject::_removeUsage($mob, $a_usage_type, $a_usage_id);
162  $mob_obj = new ilObjMediaObject($mob);
163  $mob_obj->delete();
164  }
165  }
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.
static _exists(int $id, bool $reference=false, ?string $type=null)
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.
+ 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 216 of file class.ilRTE.php.

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

Referenced by ilObjForumGUI\createThread(), ilObjForumGUI\deleteMobsOfDraft(), ilForumAutoSaveAsyncDraftAction\executeAndGetResponseObject(), ilForumUtil\moveMediaObjects(), ilForumUtil\saveMediaObjects(), ilObjForumGUI\savePostObject(), and ilExSubmissionTextGUI\updateAssignmentTextObject().

216  : array
217  {
218  if ($a_text === '') {
219  return [];
220  }
221 
222  $mediaObjects = [];
223  if ($a_direction === 0) {
224  $is_matching = preg_match_all('/src=".*" data-id="([0-9]+)"/', $a_text, $matches);
225  } else {
226  $is_matching = preg_match_all('/src="il_[0-9]+_mob_([0-9]+)"/', $a_text, $matches);
227  }
228 
229  if ($is_matching) {
230  foreach ($matches[1] as $mob) {
231  $mob = (int) $mob;
232 
233  if (ilObjMediaObject::_exists($mob) && !in_array($mob, $mediaObjects, true)) {
234  $mediaObjects[] = $mob;
235  }
236  }
237  }
238 
239  return $mediaObjects;
240  }
static _exists(int $id, bool $reference=false, ?string $type=null)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _getRTEClassname()

static ilRTE::_getRTEClassname ( )
static

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

References ilObjAdvancedEditing\_getRichTextEditor().

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

125  : string
126  {
128  if (strtolower($editor) === 'tinymce') {
129  return ilTinyMCE::class;
130  }
131 
132  return self::class;
133  }
static _getRichTextEditor()
Returns the identifier for the Rich Text Editor.
+ Here is the call graph for this function:
+ 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 174 of file class.ilRTE.php.

References ilObject\_lookupType(), and IL_INST_ID.

Referenced by SurveyQuestion\addMaterialTag(), ilObjSurvey\addMaterialTag(), assQuestionExport\addQTIMaterial(), ilExerciseManagementGUI\collectFeedbackDataFromPeer(), ilObjForumGUI\createThread(), ilObjForumGUI\doHistoryCheck(), ilExSubmissionTextGUI\editAssignmentTextObject(), ilObjForumGUI\editThreadDraftObject(), ilForumAutoSaveAsyncDraftAction\executeAndGetResponseObject(), ilAssSelfAssessmentQuestionFormatter\format(), assErrorTextImport\fromXML(), assFileUploadImport\fromXML(), assFormulaQuestionImport\fromXML(), assImagemapQuestionImport\fromXML(), assMultipleChoiceImport\fromXML(), assNumericImport\fromXML(), assOrderingHorizontalImport\fromXML(), assSingleChoiceImport\fromXML(), assTextSubsetImport\fromXML(), assKprimChoiceImport\fromXML(), assOrderingQuestionImport\fromXML(), assTextQuestionImport\fromXML(), assLongMenuImport\fromXML(), assMatchingQuestionImport\fromXML(), assClozeTestImport\fromXML(), ilAssMultiOptionQuestionFeedback\getAllSpecificAnswerFeedbackContents(), ilObjTest\getCompleteManualFeedback(), ilAssQuestionFeedback\getGenericFeedbackContent(), ilForum\getOneThread(), ilObjTest\getSingleManualFeedback(), ilAssMultiOptionQuestionFeedback\getSpecificAnswerFeedbackContent(), ilExPeerReviewGUI\getSubmissionContent(), ilObjTest\insertManualFeedback(), assKprimChoice\loadAnswerData(), SurveyTextQuestion\loadFromDb(), SurveyMultipleChoiceQuestion\loadFromDb(), assNumeric\loadFromDb(), SurveySingleChoiceQuestion\loadFromDb(), assTextSubset\loadFromDb(), assSingleChoice\loadFromDb(), SurveyMetricQuestion\loadFromDb(), assOrderingHorizontal\loadFromDb(), assMultipleChoice\loadFromDb(), assTextQuestion\loadFromDb(), assOrderingQuestion\loadFromDb(), assFileUpload\loadFromDb(), assClozeTest\loadFromDb(), assErrorText\loadFromDb(), assKprimChoice\loadFromDb(), assImagemapQuestion\loadFromDb(), SurveyMatrixQuestion\loadFromDb(), assMatchingQuestion\loadFromDb(), assLongMenu\loadFromDb(), assFormulaQuestion\loadFromDb(), ilObjSurvey\loadFromDb(), ilExAssignmentListTextTableGUI\parse(), assQuestionImport\processNonAbstractedImageReferences(), ilObjForumGUI\publishDraftObject(), ilObjForumGUI\renderDraftContent(), ilObjForumGUI\renderPostContent(), ilForumExportGUI\renderPostHtml(), ilObjForumGUI\renderPostingForm(), ilObjTest\retrieveMobsFromLegacyImports(), assClozeTest\saveAdditionalQuestionDataToDb(), assSingleChoice\saveAdditionalQuestionDataToDb(), assMultipleChoice\saveAnswerSpecificDataToDb(), ilObjForumGUI\saveAsDraftObject(), ilAssQuestionFeedback\saveGenericFeedbackContent(), ilObjForumGUI\savePostObject(), assQuestion\saveQuestionDataToDb(), ilAssMultiOptionQuestionFeedback\saveSpecificAnswerFeedbackContent(), ilObjForumGUI\saveThreadAsDraftObject(), SurveyQuestion\saveToDb(), ilObjSurvey\saveToDb(), ilExSubmissionTextGUI\showAssignmentTextObject(), ilForumXMLWriter\start(), assErrorText\toJSON(), assErrorText\toLog(), ilObjTest\toXML(), ilExSubmissionTextGUI\updateAssignmentTextObject(), ilObjForumGUI\updateDraftObject(), and ilObjForumGUI\updateThreadDraftObject().

178  : string {
179  if ($a_text === '') {
180  return '';
181  }
182 
183  if ($nic === '' && defined('IL_INST_ID')) {
184  $nic = (string) IL_INST_ID;
185  }
186 
187  if ($a_direction === 0) {
188  $a_text = preg_replace(
189  '/src=".*" data-id="([0-9]+)"/',
190  'src="il_' . $nic . '_mob_\\1"',
191  $a_text
192  );
193  } else {
194  $resulttext = $a_text;
195  if (preg_match_all('/src="(il_[0-9]+_mob_([0-9]+))"/', $a_text, $matches)) {
196  foreach ($matches[2] as $idx => $mob) {
197  if (ilObject::_lookupType((int) $mob) === 'mob') {
198  $mob_obj = new ilObjMediaObject((int) $mob);
199  $path_to_file = $mob_obj->getStandardSrc();
200  $resulttext = str_replace("src=\"{$matches[1][$idx]}\"", "src=\"{$path_to_file}\" data-id=\"{$matches[2][$idx]}\"", $resulttext);
201  }
202  }
203  }
204  $a_text = $resulttext;
205  }
206 
207  return $a_text;
208  }
const IL_INST_ID
Definition: constants.php:40
static _lookupType(int $id, bool $reference=false)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addButton()

ilRTE::addButton ( string  $a_button_name)

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

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

◆ 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

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

121  : void
122  {
123  }

◆ addPlugin()

ilRTE::addPlugin ( string  $a_plugin_name)

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

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

◆ addRTESupport()

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

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

108  : void {
109  }

◆ addUserTextEditor()

ilRTE::addUserTextEditor ( string  $editor_selector)

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

111  : void
112  {
113  }

◆ disableButtons()

ilRTE::disableButtons (   $a_button)

Sets buttons which should be disabled in the RTE.

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

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

Referenced by ilTinyMCE\addCustomRTESupport().

258  : self
259  {
260  if (is_array($a_button)) {
261  $this->disabled_buttons = array_unique(array_merge($this->disabled_buttons, $a_button));
262  } else {
263  $this->disabled_buttons = array_unique(array_merge($this->disabled_buttons, [$a_button]));
264  }
265 
266  return $this;
267  }
+ Here is the caller graph for this function:

◆ 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 274 of file class.ilRTE.php.

References $disabled_buttons.

Referenced by ilTinyMCE\_buildAdvancedButtonsFromHTMLTags(), ilTinyMCE\_buildAdvancedTableButtonsFromHTMLTags(), and ilTinyMCE\_buildButtonsFromHTMLTags().

275  {
276  if (!$as_list) {
277  return implode(',', $this->disabled_buttons);
278  }
279 
281  }
array $disabled_buttons
Definition: class.ilRTE.php:55
+ Here is the caller graph for this function:

◆ getInitialWidth()

ilRTE::getInitialWidth ( )

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

References $initialWidth.

Referenced by ilTinyMCE\addRTESupport().

283  : ?int
284  {
285  return $this->initialWidth;
286  }
int $initialWidth
Definition: class.ilRTE.php:37
+ Here is the caller graph for this function:

◆ getRTERootBlockElement()

ilRTE::getRTERootBlockElement ( )

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

References $root_block_element.

Referenced by ilTinyMCE\addCustomRTESupport(), and ilTinyMCE\addRTESupport().

248  : ?string
249  {
251  }
string $root_block_element
Definition: class.ilRTE.php:43
+ Here is the caller graph for this function:

◆ removeAllPlugins()

ilRTE::removeAllPlugins ( )

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

References XapiProxy\$plugin, and removePlugin().

87  : void
88  {
89  foreach ($this->plugins as $plugin) {
90  $this->removePlugin($plugin);
91  }
92  }
removePlugin(string $a_plugin_name)
Definition: class.ilRTE.php:79
+ Here is the call graph for this function:

◆ removeButton()

ilRTE::removeButton ( string  $a_button_name)

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

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

◆ removePlugin()

ilRTE::removePlugin ( string  $a_plugin_name)

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

Referenced by removeAllPlugins().

79  : void
80  {
81  $key = array_search($a_plugin_name, $this->plugins, true);
82  if ($key !== false) {
83  unset($this->plugins[$key]);
84  }
85  }
+ Here is the caller graph for this function:

◆ setInitialWidth()

ilRTE::setInitialWidth ( ?int  $initialWidth)

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

References $initialWidth.

288  : void
289  {
290  $this->initialWidth = $initialWidth;
291  }
int $initialWidth
Definition: class.ilRTE.php:37

◆ setRTERootBlockElement()

ilRTE::setRTERootBlockElement ( ?string  $a_root_block_element)

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

242  : self
243  {
244  $this->root_block_element = $a_root_block_element;
245  return $this;
246  }

Field Documentation

◆ $browser

AgentDetermination ilRTE::$browser
protected

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

◆ $buttons

array ilRTE::$buttons = []
protected

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

◆ $client_init

ilIniFile ilRTE::$client_init
protected

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

◆ $ctrl

ilCtrlInterface ilRTE::$ctrl
protected

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

◆ $disabled_buttons

array ilRTE::$disabled_buttons = []
protected

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

Referenced by getDisabledButtons().

◆ $initialWidth

int ilRTE::$initialWidth = null
protected

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

Referenced by getInitialWidth(), and setInitialWidth().

◆ $lng

ilLanguage ilRTE::$lng
protected

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

◆ $plugins

array ilRTE::$plugins = []
protected

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

Referenced by ilTinyMCE\getPlugins().

◆ $root_block_element

string ilRTE::$root_block_element = null
protected

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

Referenced by getRTERootBlockElement().

◆ $tpl

ilGlobalTemplateInterface ilRTE::$tpl
protected

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

Referenced by ilTinyMCE\addCustomRTESupport(), and ilTinyMCE\addRTESupport().

◆ $user

ilObjUser ilRTE::$user
protected

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


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