ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 
51  function ilRTE($a_version = "")
52  {
53  global $tpl, $ilCtrl, $lng;
54  $this->tpl =& $tpl;
55  $this->ctrl =& $ilCtrl;
56  $this->lng =& $lng;
57  $this->plugins = array();
58  $this->buttons = array();
59  }
60 
69  function addPlugin($a_plugin_name)
70  {
71  array_push($this->plugins, $a_plugin_name);
72  }
73 
82  function addButton($a_button_name)
83  {
84  array_push($this->buttons, $a_button_name);
85  }
86 
95  function removePlugin($a_plugin_name)
96  {
97  $key = array_search($a_plugin_name, $this->plugins);
98  if ($key !== FALSE)
99  {
100  unset($this->plugins[$key]);
101  }
102  }
103 
112  function removeButton($a_button_name)
113  {
114  $key = array_search($a_button_name, $this->buttons);
115  if ($key !== FALSE)
116  {
117  unset($this->buttons[$key]);
118  }
119  }
120 
128  function addRTESupport()
129  {
130  // must be overwritten in parent classes
131  }
132 
138  function addUserTextEditor($editor_selector)
139  {
140  // must be overwritten in parent classes
141  }
142 
150  function addCustomRTESupport($obj_id, $obj_type, $tags)
151  {
152  // must be overwritten in parent classes
153  }
154 
155 
156  public static function _getRTEClassname()
157  {
158  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
160  switch ($editor)
161  {
162  case "tinymce":
163  return "ilTinyMCE";
164  break;
165  default:
166  return "ilRTE";
167  break;
168  }
169  }
170 
179  function _cleanupMediaObjectUsage($a_text, $a_usage_type, $a_usage_id)
180  {
181  // get current stored mobs
182  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
184  $a_usage_id);
185  while (eregi("data\/".CLIENT_ID."\/mobs\/mm_([0-9]+)", $a_text, $found))
186  {
187  $a_text = str_replace($found[0], "", $a_text);
188  if (!in_array($found[1], $mobs))
189  {
190  // save usage if missing
191  ilObjMediaObject::_saveUsage($found[1], $a_usage_type,
192  $a_usage_id);
193  }
194  else
195  {
196  // if already saved everything ok -> take mob out of mobs array
197  unset($mobs[$found[1]]);
198  }
199  }
200  // remaining usages are not in text anymore -> delete them
201  // and media objects (note: delete method of ilObjMediaObject
202  // checks whether object is used in another context; if yes,
203  // the object is not deleted!)
204  foreach($mobs as $mob)
205  {
206  ilObjMediaObject::_removeUsage($mob, $a_usage_type,
207  $a_usage_id);
208  $mob_obj =& new ilObjMediaObject($mob);
209  $mob_obj->delete();
210  }
211  }
212 
222  public static function _replaceMediaObjectImageSrc($a_text, $a_direction = 0)
223  {
224  if (!strlen($a_text)) return "";
225  switch ($a_direction)
226  {
227  case 0:
228  $a_text = preg_replace("/src\=\"(.*?\/mobs\/mm_([0-9]+)\/.*?)\"/", "src=\"il_" . IL_INST_ID . "_mob_" . "\\2" . "\"", $a_text);
229  break;
230  default:
231  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
232  $resulttext = $a_text;
233  if (preg_match_all("/src\=\"il_([0-9]+)_mob_([0-9]+)\"/", $a_text, $matches))
234  {
235  foreach ($matches[2] as $idx => $mob)
236  {
237  if (ilObjMediaObject::_exists($mob))
238  {
239  $mob_obj =& new ilObjMediaObject($mob);
240  $replace = "il_" . $matches[1][$idx] . "_mob_" . $mob;
241  $resulttext = str_replace("src=\"$replace\"", "src=\"" . ILIAS_HTTP_PATH . "/data/" . CLIENT_ID . "/mobs/mm_" . $mob . "/" . $mob_obj->getTitle() . "\"", $resulttext);
242  }
243  }
244  }
245  $a_text = $resulttext;
246  break;
247  }
248  return $a_text;
249  }
250 
258  public static function _getMediaObjects($a_text, $a_direction = 0)
259  {
260  if (!strlen($a_text)) return array();
261  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
262 
263  $mediaObjects = array();
264  switch ($a_direction)
265  {
266  case 0:
267  if(preg_match_all("/src\=\"(.*?\/mobs\/mm_([0-9]+)\/.*?)\"/", $a_text, $matches))
268  {
269  foreach ($matches[2] as $idx => $mob)
270  {
271  if (ilObjMediaObject::_exists($mob) && !in_array($mob, $mediaObjects))
272  {
273  $mediaObjects[] = $mob;
274  }
275  }
276  }
277  break;
278  default:
279 
280  if(preg_match_all("/src\=\"il_([0-9]+)_mob_([0-9]+)\"/", $a_text, $matches))
281  {
282  foreach ($matches[2] as $idx => $mob)
283  {
284  if (ilObjMediaObject::_exists($mob) && !in_array($mob, $mediaObjects))
285  {
286  $mediaObjects[] = $mob;
287  }
288  }
289  }
290  break;
291  }
292  return $mediaObjects;
293  }
294 
295  public function setRTERootBlockElement()
296  {
297  // must be overwritten in sub classes
298  }
299 
300  public function getRTERootBlockElement()
301  {
302  // must be overwritten in sub classes
303  }
304 
305  public function disableButtons()
306  {
307  // must be overwritten in sub classes
308  }
309 
310  public function getDisabledButtons()
311  {
312  // must be overwritten in sub classes
313  }
314 }
315 
316 ?>