ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilRTE.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2016 ILIAS open source, Extended GPL, see docs/LICENSE */
3
12class ilRTE
13{
14 const ILIAS_IMG_MANAGER_PLUGIN = 'ilias_image_manager_plugin';
15
20 protected $plugins = array();
21
25 protected $buttons = array();
26
30 protected $tpl;
31
35 protected $ctrl;
36
40 protected $user;
41
45 protected $lng;
46
50 protected $browser;
51
55 protected $client_init;
56
60 protected $initialWidth = null;
61
66 protected $root_block_element = null;
67
72 protected $disabled_buttons = array();
73
78 public function __construct($a_version = '')
79 {
80 global $DIC;
81
82 $this->tpl = $DIC['tpl'];
83 $this->ctrl = $DIC['ilCtrl'];
84 $this->lng = $DIC['lng'];
85 $this->browser = $DIC['ilBrowser'];
86 $this->client_init = $DIC['ilClientIniFile'];
87 $this->user = $DIC['ilUser'];
88 }
89
94 public function addPlugin($a_plugin_name)
95 {
96 array_push($this->plugins, $a_plugin_name);
97 }
98
103 public function addButton($a_button_name)
104 {
105 array_push($this->buttons, $a_button_name);
106 }
107
112 public function removePlugin($a_plugin_name)
113 {
114 $key = array_search($a_plugin_name, $this->plugins);
115 if ($key !== false) {
116 unset($this->plugins[$key]);
117 }
118 }
119
123 public function removeAllPlugins()
124 {
125 foreach ($this->plugins as $plugin) {
126 $this->removePlugin($plugin);
127 }
128 }
129
134 public function removeButton($a_button_name)
135 {
136 $key = array_search($a_button_name, $this->buttons);
137 if ($key !== false) {
138 unset($this->buttons[$key]);
139 }
140 }
141
151 public function addRTESupport($obj_id, $obj_type, $a_module = "", $allowFormElements = false, $cfg_template = null, $hide_switch = false)
152 {
153 }
154
159 public function addUserTextEditor($editor_selector)
160 {
161 }
162
169 public function addCustomRTESupport($obj_id, $obj_type, array $tags)
170 {
171 }
172
176 public static function _getRTEClassname()
177 {
178 require_once 'Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php';
180 case 'tinymce':
181 return 'ilTinyMCE';
182 break;
183
184 default:
185 return 'ilRTE';
186 break;
187 }
188 }
189
196 public static function _cleanupMediaObjectUsage($a_text, $a_usage_type, $a_usage_id)
197 {
198 require_once 'Services/MediaObjects/classes/class.ilObjMediaObject.php';
199
200 $mobs = ilObjMediaObject::_getMobsOfObject($a_usage_type, $a_usage_id);
201 while (preg_match("/data\/" . CLIENT_ID . "\/mobs\/mm_([0-9]+)/i", $a_text, $found)) {
202 $a_text = str_replace($found[0], "", $a_text);
203 if (!in_array($found[1], $mobs)) {
204 // save usage if missing
205 ilObjMediaObject::_saveUsage($found[1], $a_usage_type, $a_usage_id);
206 } else {
207 // if already saved everything ok -> take mob out of mobs array
208 unset($mobs[$found[1]]);
209 }
210 }
211 // remaining usages are not in text anymore -> delete them
212 // and media objects (note: delete method of ilObjMediaObject
213 // checks whether object is used in another context; if yes,
214 // the object is not deleted!)
215 foreach ($mobs as $mob) {
216 ilObjMediaObject::_removeUsage($mob, $a_usage_type, $a_usage_id);
217 $mob_obj = new ilObjMediaObject($mob);
218 $mob_obj->delete();
219 }
220 }
221
228 public static function _replaceMediaObjectImageSrc($a_text, $a_direction = 0, $nic = IL_INST_ID)
229 {
230 if (!strlen($a_text)) {
231 return '';
232 }
233
234 switch ($a_direction) {
235 case 0:
236 $a_text = preg_replace('/src="([^"]*?\/mobs\/mm_([0-9]+)\/.*?)\"/', 'src="il_' . IL_INST_ID . '_mob_\\2"', $a_text);
237 break;
238
239 default:
240 require_once 'Services/MediaObjects/classes/class.ilObjMediaObject.php';
241 $resulttext = $a_text;
242 if (preg_match_all('/src="il_([0-9]+)_mob_([0-9]+)"/', $a_text, $matches)) {
243 foreach ($matches[2] as $idx => $mob) {
244 if (ilObject::_lookupType($mob) == "mob") {
245 $mob_obj = new ilObjMediaObject($mob);
246 $replace = "il_" . $matches[1][$idx] . "_mob_" . $mob;
247 require_once('./Services/WebAccessChecker/classes/class.ilWACSignedPath.php');
248 $path_to_file = ilWACSignedPath::signFile(ILIAS_HTTP_PATH . "/data/" . CLIENT_ID . "/mobs/mm_" . $mob . "/" . $mob_obj->getTitle());
249 $resulttext = str_replace("src=\"$replace\"", "src=\"" . $path_to_file . "\"", $resulttext);
250 }
251 }
252 }
253 $a_text = $resulttext;
254 break;
255 }
256
257 return $a_text;
258 }
259
266 public static function _getMediaObjects($a_text, $a_direction = 0)
267 {
268 if (!strlen($a_text)) {
269 return array();
270 }
271
272 require_once 'Services/MediaObjects/classes/class.ilObjMediaObject.php';
273
274 $mediaObjects = array();
275 switch ($a_direction) {
276 case 0:
277 if (preg_match_all('/src="([^"]*?\/mobs\/mm_([0-9]+)\/.*?)\"/', $a_text, $matches)) {
278 foreach ($matches[2] as $idx => $mob) {
279 if (ilObjMediaObject::_exists($mob) && !in_array($mob, $mediaObjects)) {
280 $mediaObjects[] = $mob;
281 }
282 }
283 }
284 break;
285
286 default:
287 if (preg_match_all('/src="il_([0-9]+)_mob_([0-9]+)"/', $a_text, $matches)) {
288 foreach ($matches[2] as $idx => $mob) {
289 if (ilObjMediaObject::_exists($mob) && !in_array($mob, $mediaObjects)) {
290 $mediaObjects[] = $mob;
291 }
292 }
293 }
294 break;
295 }
296
297 return $mediaObjects;
298 }
299
305 public function setRTERootBlockElement($a_root_block_element)
306 {
307 $this->root_block_element = $a_root_block_element;
308 return $this;
309 }
310
315 public function getRTERootBlockElement()
316 {
318 }
319
325 public function disableButtons($a_button)
326 {
327 if (is_array($a_button)) {
328 $this->disabled_buttons = array_unique(array_merge($this->disabled_buttons, $a_button));
329 } else {
330 $this->disabled_buttons = array_unique(array_merge($this->disabled_buttons, array($a_button)));
331 }
332
333 return $this;
334 }
335
341 public function getDisabledButtons($as_array = true)
342 {
343 if (!$as_array) {
344 return implode(',', $this->disabled_buttons);
345 } else {
347 }
348 }
349
353 public function getInitialWidth()
354 {
355 return $this->initialWidth;
356 }
357
362 {
363 $this->initialWidth = $initialWidth;
364 }
365}
user()
Definition: user.php:4
An exception for terminatinating execution or to throw for unit testing.
static _getRichTextEditor()
Returns the identifier for the Rich Text Editor.
Class ilObjMediaObject.
static _saveUsage($a_mob_id, $a_type, $a_id, $a_usage_hist_nr=0, $a_lang="-")
Save usage of mob within another container (e.g.
static _getMobsOfObject($a_type, $a_id, $a_usage_hist_nr=0, $a_lang="-")
get mobs of object
static _removeUsage($a_mob_id, $a_type, $a_id, $a_usage_hist_nr=0, $a_lang="-")
Remove usage of mob in another container.
static _exists($a_id, $a_reference=false, $a_type=null)
checks wether a lm content object with specified id exists or not
static _lookupType($a_id, $a_reference=false)
lookup object type
Rich Text Editor base class This class provides access methods to a Rich Text Editor (RTE) integrated...
Definition: class.ilRTE.php:13
static _replaceMediaObjectImageSrc($a_text, $a_direction=0, $nic=IL_INST_ID)
Replaces image source from mob image urls with the mob id or replaces mob id with the correct image s...
$root_block_element
Definition: class.ilRTE.php:66
getDisabledButtons($as_array=true)
Returns the disabled RTE buttons.
$initialWidth
Definition: class.ilRTE.php:60
removePlugin($a_plugin_name)
Removes a plugin from the plugin list.
static _getMediaObjects($a_text, $a_direction=0)
Returns all media objects found in the passed string.
$disabled_buttons
Definition: class.ilRTE.php:72
static _getRTEClassname()
addPlugin($a_plugin_name)
Adds a plugin to the plugin list.
Definition: class.ilRTE.php:94
setInitialWidth($initialWidth)
addCustomRTESupport($obj_id, $obj_type, array $tags)
Adds custom support for an RTE in an ILIAS form.
setRTERootBlockElement($a_root_block_element)
Setter for the RTE root block element.
getRTERootBlockElement()
Getter for the RTE root block element.
$client_init
Definition: class.ilRTE.php:55
const ILIAS_IMG_MANAGER_PLUGIN
Definition: class.ilRTE.php:14
addRTESupport($obj_id, $obj_type, $a_module="", $allowFormElements=false, $cfg_template=null, $hide_switch=false)
Adds support for an RTE in an ILIAS form.
removeButton($a_button_name)
Removes a button from the button list.
static _cleanupMediaObjectUsage($a_text, $a_usage_type, $a_usage_id)
Synchronises appearances of media objects in $a_text with media object usage table.
removeAllPlugins()
Removes all plugins from instance.
addButton($a_button_name)
Adds a button to the button list.
disableButtons($a_button)
Sets buttons which should be disabled in the RTE.
getInitialWidth()
__construct($a_version='')
ilRTE constructor.
Definition: class.ilRTE.php:78
addUserTextEditor($editor_selector)
Adds support for an user text editor.
static signFile($path_to_file)
$mobs
$DIC
Definition: xapitoken.php:46