ILIAS  release_8 Revision v8.23
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, bool $hide_switch=false)
 
 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...
 

Data Fields

const ILIAS_IMG_MANAGER_PLUGIN = 'ilias_image_manager_plugin'
 

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

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

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

References $mobs, ilObjMediaObject\_getMobsOfObject(), ilObjMediaObject\_removeUsage(), ilObjMediaObject\_saveUsage(), CLIENT_ID, and ILIAS\Repository\int().

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

144  : void
145  {
146  $mobs = ilObjMediaObject::_getMobsOfObject($a_usage_type, $a_usage_id);
147  while (preg_match("/data\/" . CLIENT_ID . "\/mobs\/mm_([0-9]+)/i", $a_text, $found)) {
148  $a_text = str_replace($found[0], '', $a_text);
149  $found_mob_id = (int) $found[1];
150 
151  if (!in_array($found_mob_id, $mobs, true)) {
152  // save usage if missing
153  ilObjMediaObject::_saveUsage($found_mob_id, $a_usage_type, $a_usage_id);
154  } else {
155  // if already saved everything ok -> take mob out of mobs array
156  unset($mobs[$found_mob_id]);
157  }
158  }
159  // remaining usages are not in text anymore -> delete them
160  // and media objects (note: delete method of ilObjMediaObject
161  // checks whether object is used in another context; if yes,
162  // the object is not deleted!)
163  foreach ($mobs as $mob) {
164  ilObjMediaObject::_removeUsage($mob, $a_usage_type, $a_usage_id);
165  $mob_obj = new ilObjMediaObject($mob);
166  $mob_obj->delete();
167  }
168  }
$mobs
Definition: imgupload.php:70
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.
const CLIENT_ID
Definition: constants.php:41
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 222 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().

222  : array
223  {
224  if ($a_text === '') {
225  return [];
226  }
227 
228  $mediaObjects = [];
229  if ($a_direction === 0) {
230  $is_matching = preg_match_all('/src="([^"]*?\/mobs\/mm_([0-9]+)\/.*?)\"/', $a_text, $matches);
231  } else {
232  $is_matching = preg_match_all('/src="il_([0-9]+)_mob_([0-9]+)"/', $a_text, $matches);
233  }
234 
235  if ($is_matching) {
236  foreach ($matches[2] as $idx => $mob) {
237  $mob = (int) $mob;
238 
239  if (ilObjMediaObject::_exists($mob) && !in_array($mob, $mediaObjects, true)) {
240  $mediaObjects[] = $mob;
241  }
242  }
243  }
244 
245  return $mediaObjects;
246  }
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 128 of file class.ilRTE.php.

References ilObjAdvancedEditing\_getRichTextEditor().

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

128  : string
129  {
131  if (strtolower($editor) === 'tinymce') {
132  return ilTinyMCE::class;
133  }
134 
135  return self::class;
136  }
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 177 of file class.ilRTE.php.

References ilObject\_lookupType(), CLIENT_ID, IL_INST_ID, and ilWACSignedPath\signFile().

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

181  : string {
182  if ($a_text === '') {
183  return '';
184  }
185 
186  if ($nic === '' && defined('IL_INST_ID')) {
187  $nic = (string) IL_INST_ID;
188  }
189 
190  if ($a_direction === 0) {
191  $a_text = preg_replace(
192  '/src="([^"]*?\/mobs\/mm_([0-9]+)\/.*?)\"/',
193  'src="il_' . $nic . '_mob_\\2"',
194  $a_text
195  );
196  } else {
197  $resulttext = $a_text;
198  if (preg_match_all('/src="il_([0-9]+)_mob_([0-9]+)"/', $a_text, $matches)) {
199  foreach ($matches[2] as $idx => $mob) {
200  if (ilObject::_lookupType((int) $mob) === 'mob') {
201  $mob_obj = new ilObjMediaObject((int) $mob);
202  $replace = 'il_' . $matches[1][$idx] . '_mob_' . $mob;
203  $path_to_file = ilWACSignedPath::signFile(
204  ILIAS_HTTP_PATH . '/data/' . CLIENT_ID . '/mobs/mm_' . $mob . '/' . $mob_obj->getTitle()
205  );
206  $resulttext = str_replace("src=\"$replace\"", "src=\"" . $path_to_file . "\"", $resulttext);
207  }
208  }
209  }
210  $a_text = $resulttext;
211  }
212 
213  return $a_text;
214  }
const IL_INST_ID
Definition: constants.php:40
const CLIENT_ID
Definition: constants.php:41
static signFile(string $path_to_file)
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 76 of file class.ilRTE.php.

Referenced by ilTinyMCE\addInternalTinyMCEImageManager().

76  : void
77  {
78  $this->buttons[] = $a_button_name;
79  }
+ Here is the caller graph for this function:

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

124  : void
125  {
126  }

◆ addPlugin()

ilRTE::addPlugin ( string  $a_plugin_name)

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

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

◆ addRTESupport()

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

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

111  : void {
112  }

◆ addUserTextEditor()

ilRTE::addUserTextEditor ( string  $editor_selector)

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_button Either a button string or an array of button strings
Returns
self

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

Referenced by ilTinyMCE\addCustomRTESupport(), ilTinyMCE\addInternalTinyMCEImageManager(), ilTinyMCE\handleIliasImageManagerRemoved(), and ilTinyMCE\handleImagePluginsBeforeRendering().

264  : self
265  {
266  if (is_array($a_button)) {
267  $this->disabled_buttons = array_unique(array_merge($this->disabled_buttons, $a_button));
268  } else {
269  $this->disabled_buttons = array_unique(array_merge($this->disabled_buttons, [$a_button]));
270  }
271 
272  return $this;
273  }
+ 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 280 of file class.ilRTE.php.

References $disabled_buttons.

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

281  {
282  if (!$as_list) {
283  return implode(',', $this->disabled_buttons);
284  }
285 
287  }
array $disabled_buttons
Definition: class.ilRTE.php:57
+ Here is the caller graph for this function:

◆ getInitialWidth()

ilRTE::getInitialWidth ( )

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

References $initialWidth.

Referenced by ilTinyMCE\addRTESupport().

289  : ?int
290  {
291  return $this->initialWidth;
292  }
int $initialWidth
Definition: class.ilRTE.php:39
+ Here is the caller graph for this function:

◆ getRTERootBlockElement()

ilRTE::getRTERootBlockElement ( )

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

References $root_block_element.

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

254  : ?string
255  {
257  }
string $root_block_element
Definition: class.ilRTE.php:45
+ Here is the caller graph for this function:

◆ removeAllPlugins()

ilRTE::removeAllPlugins ( )

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

References XapiProxy\$plugin, and removePlugin().

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

◆ removeButton()

ilRTE::removeButton ( string  $a_button_name)

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

References ILIAS\LTI\ToolProvider\$key.

96  : void
97  {
98  $key = array_search($a_button_name, $this->buttons, true);
99  if ($key !== false) {
100  unset($this->buttons[$key]);
101  }
102  }
string $key
Consumer key/client ID value.
Definition: System.php:193

◆ removePlugin()

ilRTE::removePlugin ( string  $a_plugin_name)

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

References ILIAS\LTI\ToolProvider\$key.

Referenced by removeAllPlugins().

81  : void
82  {
83  $key = array_search($a_plugin_name, $this->plugins, true);
84  if ($key !== false) {
85  unset($this->plugins[$key]);
86  }
87  }
string $key
Consumer key/client ID value.
Definition: System.php:193
+ Here is the caller graph for this function:

◆ setInitialWidth()

ilRTE::setInitialWidth ( ?int  $initialWidth)

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

References $initialWidth.

294  : void
295  {
296  $this->initialWidth = $initialWidth;
297  }
int $initialWidth
Definition: class.ilRTE.php:39

◆ setRTERootBlockElement()

ilRTE::setRTERootBlockElement ( ?string  $a_root_block_element)

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

248  : self
249  {
250  $this->root_block_element = $a_root_block_element;
251  return $this;
252  }

Field Documentation

◆ $browser

AgentDetermination ilRTE::$browser
protected

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

◆ $buttons

array ilRTE::$buttons = []
protected

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

◆ $client_init

ilIniFile ilRTE::$client_init
protected

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

◆ $ctrl

ilCtrlInterface ilRTE::$ctrl
protected

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

◆ $disabled_buttons

array ilRTE::$disabled_buttons = []
protected

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

Referenced by getDisabledButtons().

◆ $initialWidth

int ilRTE::$initialWidth = null
protected

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

Referenced by getInitialWidth(), and setInitialWidth().

◆ $lng

ilLanguage ilRTE::$lng
protected

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

Referenced by ilTinyMCE\addRTESupport().

◆ $plugins

array ilRTE::$plugins = []
protected

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

Referenced by ilTinyMCE\getPlugins().

◆ $root_block_element

string ilRTE::$root_block_element = null
protected

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

Referenced by getRTERootBlockElement().

◆ $tpl

ilGlobalTemplateInterface ilRTE::$tpl
protected

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

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

◆ $user

ilObjUser ilRTE::$user
protected

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

◆ ILIAS_IMG_MANAGER_PLUGIN

const ilRTE::ILIAS_IMG_MANAGER_PLUGIN = 'ilias_image_manager_plugin'

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

Referenced by ilSurveyEditorGUI\initHeadingForm().


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