ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilRTE.php
Go to the documentation of this file.
1 <?php
2  /*
3  +----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +----------------------------------------------------------------------------+
22 */
23 
34 class ilRTE
35 {
36  const ILIAS_IMG_MANAGER_PLUGIN = 'ilias_image_manager_plugin';
37 
45  var $plugins;
46  var $buttons;
47  var $tpl;
48  var $ctrl;
49  var $lng;
50 
54  protected $initialWidth = null;
55 
56 
57  function ilRTE($a_version = "")
58  {
59  global $tpl, $ilCtrl, $lng;
60  $this->tpl =& $tpl;
61  $this->ctrl =& $ilCtrl;
62  $this->lng =& $lng;
63  $this->plugins = array();
64  $this->buttons = array();
65  }
66 
75  function addPlugin($a_plugin_name)
76  {
77  array_push($this->plugins, $a_plugin_name);
78  }
79 
88  function addButton($a_button_name)
89  {
90  array_push($this->buttons, $a_button_name);
91  }
92 
101  function removePlugin($a_plugin_name)
102  {
103  $key = array_search($a_plugin_name, $this->plugins);
104  if ($key !== FALSE)
105  {
106  unset($this->plugins[$key]);
107  }
108  }
109 
110  public function removeAllPlugins()
111  {
112  foreach($this->plugins as $plugin)
113  {
114  $this->removePlugin($plugin);
115  }
116  }
117 
126  function removeButton($a_button_name)
127  {
128  $key = array_search($a_button_name, $this->buttons);
129  if ($key !== FALSE)
130  {
131  unset($this->buttons[$key]);
132  }
133  }
134 
142  function addRTESupport()
143  {
144  // must be overwritten in parent classes
145  }
146 
152  function addUserTextEditor($editor_selector)
153  {
154  // must be overwritten in parent classes
155  }
156 
164  function addCustomRTESupport($obj_id, $obj_type, $tags)
165  {
166  // must be overwritten in parent classes
167  }
168 
169 
170  public static function _getRTEClassname()
171  {
172  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
174  switch ($editor)
175  {
176  case "tinymce":
177  return "ilTinyMCE";
178  break;
179  default:
180  return "ilRTE";
181  break;
182  }
183  }
184 
193  function _cleanupMediaObjectUsage($a_text, $a_usage_type, $a_usage_id)
194  {
195  // get current stored mobs
196  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
198  $a_usage_id);
199  while (eregi("data\/".CLIENT_ID."\/mobs\/mm_([0-9]+)", $a_text, $found))
200  {
201  $a_text = str_replace($found[0], "", $a_text);
202  if (!in_array($found[1], $mobs))
203  {
204  // save usage if missing
205  ilObjMediaObject::_saveUsage($found[1], $a_usage_type,
206  $a_usage_id);
207  }
208  else
209  {
210  // if already saved everything ok -> take mob out of mobs array
211  unset($mobs[$found[1]]);
212  }
213  }
214  // remaining usages are not in text anymore -> delete them
215  // and media objects (note: delete method of ilObjMediaObject
216  // checks whether object is used in another context; if yes,
217  // the object is not deleted!)
218  foreach($mobs as $mob)
219  {
220  ilObjMediaObject::_removeUsage($mob, $a_usage_type,
221  $a_usage_id);
222  $mob_obj =& new ilObjMediaObject($mob);
223  $mob_obj->delete();
224  }
225  }
226 
236  public static function _replaceMediaObjectImageSrc($a_text, $a_direction = 0, $nic = IL_INST_ID)
237  {
238  if (!strlen($a_text)) return "";
239  switch ($a_direction)
240  {
241  case 0:
242  $a_text = preg_replace('/src="([^"]*?\/mobs\/mm_([0-9]+)\/.*?)\"/', 'src="il_' . IL_INST_ID . '_mob_\\2"', $a_text);
243  break;
244  default:
245  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
246  $resulttext = $a_text;
247  if(preg_match_all('/src="il_([0-9]+)_mob_([0-9]+)"/', $a_text, $matches))
248  {
249  foreach ($matches[2] as $idx => $mob)
250  {
251  if (ilObjMediaObject::_exists($mob))
252  {
253  $mob_obj = new ilObjMediaObject($mob);
254  $replace = "il_" . $matches[1][$idx] . "_mob_" . $mob;
255 
256  require_once('./Services/WebAccessChecker/classes/class.ilWACSignedPath.php');
257  $path_to_file = ilWACSignedPath::signFile(ILIAS_HTTP_PATH . "/data/" . CLIENT_ID . "/mobs/mm_" . $mob . "/" . $mob_obj->getTitle());
258  $resulttext = str_replace("src=\"$replace\"", "src=\"" . $path_to_file . "\"", $resulttext);
259  }
260  }
261  }
262  $a_text = $resulttext;
263  break;
264  }
265  return $a_text;
266  }
267 
275  public static function _getMediaObjects($a_text, $a_direction = 0)
276  {
277  if (!strlen($a_text)) return array();
278  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
279 
280  $mediaObjects = array();
281  switch ($a_direction)
282  {
283  case 0:
284  if(preg_match_all('/src="([^"]*?\/mobs\/mm_([0-9]+)\/.*?)\"/', $a_text, $matches))
285  {
286  foreach ($matches[2] as $idx => $mob)
287  {
288  if (ilObjMediaObject::_exists($mob) && !in_array($mob, $mediaObjects))
289  {
290  $mediaObjects[] = $mob;
291  }
292  }
293  }
294  break;
295  default:
296  if(preg_match_all('/src="il_([0-9]+)_mob_([0-9]+)"/', $a_text, $matches))
297  {
298  foreach ($matches[2] as $idx => $mob)
299  {
300  if (ilObjMediaObject::_exists($mob) && !in_array($mob, $mediaObjects))
301  {
302  $mediaObjects[] = $mob;
303  }
304  }
305  }
306  break;
307  }
308  return $mediaObjects;
309  }
310 
311  public function setRTERootBlockElement()
312  {
313  // must be overwritten in sub classes
314  }
315 
316  public function getRTERootBlockElement()
317  {
318  // must be overwritten in sub classes
319  }
320 
321  public function disableButtons()
322  {
323  // must be overwritten in sub classes
324  }
325 
326  public function getDisabledButtons()
327  {
328  // must be overwritten in sub classes
329  }
330 
334  public function getInitialWidth()
335  {
336  return $this->initialWidth;
337  }
338 
343  {
344  $this->initialWidth = $initialWidth;
345  }
346 }
347 
348 ?>
static _getMediaObjects($a_text, $a_direction=0)
Returns all media objects found in the passed string.
static _getRTEClassname()
addRTESupport()
Adds support for an RTE in an ILIAS form.
addButton($a_button_name)
Adds a button to the button list.
Definition: class.ilRTE.php:88
removeAllPlugins()
_getRichTextEditor()
Returns the identifier for the Rich Text Editor.
getDisabledButtons()
_cleanupMediaObjectUsage($a_text, $a_usage_type, $a_usage_id)
synchronises appearances of media objects in $a_text with media object usage table ...
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...
getInitialWidth()
setInitialWidth($initialWidth)
_removeUsage($a_mob_id, $a_type, $a_id, $a_usage_hist_nr=0, $a_lang="-")
Remove usage of mob in another container.
removeButton($a_button_name)
Removes a button from the button list.
global $ilCtrl
Definition: ilias.php:18
addUserTextEditor($editor_selector)
Adds support for an user text editor.
Rich Text Editor base class.
Definition: class.ilRTE.php:34
_saveUsage($a_mob_id, $a_type, $a_id, $a_usage_hist_nr=0, $a_lang="-")
Save usage of mob within another container (e.g.
$mobs
static _exists($a_id)
checks wether a lm content object with specified id exists or not
const ILIAS_IMG_MANAGER_PLUGIN
Definition: class.ilRTE.php:36
ilRTE($a_version="")
Definition: class.ilRTE.php:57
addCustomRTESupport($obj_id, $obj_type, $tags)
Adds custom support for an RTE in an ILIAS form.
Class ilObjMediaObject.
static signFile($path_to_file)
_getMobsOfObject($a_type, $a_id, $a_usage_hist_nr=0, $a_lang="-")
get mobs of object
addPlugin($a_plugin_name)
Adds a plugin to the plugin list.
Definition: class.ilRTE.php:75
disableButtons()
removePlugin($a_plugin_name)
Removes a plugin from the plugin list.
getRTERootBlockElement()
setRTERootBlockElement()
$initialWidth
Definition: class.ilRTE.php:54