ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 {
117 unset($this->plugins[$key]);
118 }
119 }
120
124 public function removeAllPlugins()
125 {
126 foreach($this->plugins as $plugin)
127 {
128 $this->removePlugin($plugin);
129 }
130 }
131
136 public function removeButton($a_button_name)
137 {
138 $key = array_search($a_button_name, $this->buttons);
139 if($key !== FALSE)
140 {
141 unset($this->buttons[$key]);
142 }
143 }
144
154 public function addRTESupport($obj_id, $obj_type, $a_module = "", $allowFormElements = FALSE, $cfg_template = null, $hide_switch = false)
155 {
156 }
157
162 public function addUserTextEditor($editor_selector)
163 {
164 }
165
172 public function addCustomRTESupport($obj_id, $obj_type, array $tags)
173 {
174 }
175
179 public static function _getRTEClassname()
180 {
181 require_once 'Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php';
183 {
184 case 'tinymce':
185 return 'ilTinyMCE';
186 break;
187
188 default:
189 return 'ilRTE';
190 break;
191 }
192 }
193
200 public static function _cleanupMediaObjectUsage($a_text, $a_usage_type, $a_usage_id)
201 {
202 require_once 'Services/MediaObjects/classes/class.ilObjMediaObject.php';
203
204 $mobs = ilObjMediaObject::_getMobsOfObject($a_usage_type, $a_usage_id);
205 while(preg_match("/data\/" . CLIENT_ID . "\/mobs\/mm_([0-9]+)/i", $a_text, $found))
206 {
207 $a_text = str_replace($found[0], "", $a_text);
208 if(!in_array($found[1], $mobs))
209 {
210 // save usage if missing
211 ilObjMediaObject::_saveUsage($found[1], $a_usage_type, $a_usage_id);
212 }
213 else
214 {
215 // if already saved everything ok -> take mob out of mobs array
216 unset($mobs[$found[1]]);
217 }
218 }
219 // remaining usages are not in text anymore -> delete them
220 // and media objects (note: delete method of ilObjMediaObject
221 // checks whether object is used in another context; if yes,
222 // the object is not deleted!)
223 foreach($mobs as $mob)
224 {
225 ilObjMediaObject::_removeUsage($mob, $a_usage_type, $a_usage_id);
226 $mob_obj = new ilObjMediaObject($mob);
227 $mob_obj->delete();
228 }
229 }
230
237 public static function _replaceMediaObjectImageSrc($a_text, $a_direction = 0, $nic = IL_INST_ID)
238 {
239 if(!strlen($a_text)) return '';
240
241 switch($a_direction)
242 {
243 case 0:
244 $a_text = preg_replace('/src="([^"]*?\/mobs\/mm_([0-9]+)\/.*?)\"/', 'src="il_' . IL_INST_ID . '_mob_\\2"', $a_text);
245 break;
246
247 default:
248 require_once 'Services/MediaObjects/classes/class.ilObjMediaObject.php';
249 $resulttext = $a_text;
250 if(preg_match_all('/src="il_([0-9]+)_mob_([0-9]+)"/', $a_text, $matches))
251 {
252 foreach($matches[2] as $idx => $mob)
253 {
254 if(ilObject::_lookupType($mob) == "mob")
255 {
256 $mob_obj = new ilObjMediaObject($mob);
257 $replace = "il_" . $matches[1][$idx] . "_mob_" . $mob;
258 require_once('./Services/WebAccessChecker/classes/class.ilWACSignedPath.php');
259 $path_to_file = ilWACSignedPath::signFile(ILIAS_HTTP_PATH . "/data/" . CLIENT_ID . "/mobs/mm_" . $mob . "/" . $mob_obj->getTitle());
260 $resulttext = str_replace("src=\"$replace\"", "src=\"" . $path_to_file . "\"", $resulttext);
261 }
262 }
263 }
264 $a_text = $resulttext;
265 break;
266 }
267
268 return $a_text;
269 }
270
277 public static function _getMediaObjects($a_text, $a_direction = 0)
278 {
279 if(!strlen($a_text)) return array();
280
281 require_once 'Services/MediaObjects/classes/class.ilObjMediaObject.php';
282
283 $mediaObjects = array();
284 switch($a_direction)
285 {
286 case 0:
287 if(preg_match_all('/src="([^"]*?\/mobs\/mm_([0-9]+)\/.*?)\"/', $a_text, $matches))
288 {
289 foreach($matches[2] as $idx => $mob)
290 {
291 if(ilObjMediaObject::_exists($mob) && !in_array($mob, $mediaObjects))
292 {
293 $mediaObjects[] = $mob;
294 }
295 }
296 }
297 break;
298
299 default:
300 if(preg_match_all('/src="il_([0-9]+)_mob_([0-9]+)"/', $a_text, $matches))
301 {
302 foreach($matches[2] as $idx => $mob)
303 {
304 if(ilObjMediaObject::_exists($mob) && !in_array($mob, $mediaObjects))
305 {
306 $mediaObjects[] = $mob;
307 }
308 }
309 }
310 break;
311 }
312
313 return $mediaObjects;
314 }
315
321 public function setRTERootBlockElement($a_root_block_element)
322 {
323 $this->root_block_element = $a_root_block_element;
324 return $this;
325 }
326
331 public function getRTERootBlockElement()
332 {
334 }
335
341 public function disableButtons($a_button)
342 {
343 if(is_array($a_button))
344 {
345 $this->disabled_buttons = array_unique(array_merge($this->disabled_buttons, $a_button));
346 }
347 else
348 {
349 $this->disabled_buttons = array_unique(array_merge($this->disabled_buttons, array($a_button)));
350 }
351
352 return $this;
353 }
354
360 public function getDisabledButtons($as_array = true)
361 {
362 if(!$as_array)
363 {
364 return implode(',', $this->disabled_buttons);
365 }
366 else
367 {
369 }
370 }
371
375 public function getInitialWidth()
376 {
377 return $this->initialWidth;
378 }
379
384 {
385 $this->initialWidth = $initialWidth;
386 }
387}
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
removeButton($a_button_name)
Removes a button from the button list.
addRTESupport($obj_id, $obj_type, $a_module="", $allowFormElements=FALSE, $cfg_template=null, $hide_switch=false)
Adds support for an RTE in an ILIAS form.
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)
global $DIC
$mobs