ILIAS  Release_5_0_x_branch Revision 61816
 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 
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_" . $nic . "_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  $resulttext = str_replace("src=\"$replace\"", "src=\"" . ILIAS_HTTP_PATH . "/data/" . CLIENT_ID . "/mobs/mm_" . $mob . "/" . $mob_obj->getTitle() . "\"", $resulttext);
256  }
257  }
258  }
259  $a_text = $resulttext;
260  break;
261  }
262  return $a_text;
263  }
264 
272  public static function _getMediaObjects($a_text, $a_direction = 0)
273  {
274  if (!strlen($a_text)) return array();
275  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
276 
277  $mediaObjects = array();
278  switch ($a_direction)
279  {
280  case 0:
281  if(preg_match_all("/src\=\"(.*?\/mobs\/mm_([0-9]+)\/.*?)\"/", $a_text, $matches))
282  {
283  foreach ($matches[2] as $idx => $mob)
284  {
285  if (ilObjMediaObject::_exists($mob) && !in_array($mob, $mediaObjects))
286  {
287  $mediaObjects[] = $mob;
288  }
289  }
290  }
291  break;
292  default:
293 
294  if(preg_match_all("/src\=\"il_([0-9]+)_mob_([0-9]+)\"/", $a_text, $matches))
295  {
296  foreach ($matches[2] as $idx => $mob)
297  {
298  if (ilObjMediaObject::_exists($mob) && !in_array($mob, $mediaObjects))
299  {
300  $mediaObjects[] = $mob;
301  }
302  }
303  }
304  break;
305  }
306  return $mediaObjects;
307  }
308 
309  public function setRTERootBlockElement()
310  {
311  // must be overwritten in sub classes
312  }
313 
314  public function getRTERootBlockElement()
315  {
316  // must be overwritten in sub classes
317  }
318 
319  public function disableButtons()
320  {
321  // must be overwritten in sub classes
322  }
323 
324  public function getDisabledButtons()
325  {
326  // must be overwritten in sub classes
327  }
328 
332  public function getInitialWidth()
333  {
334  return $this->initialWidth;
335  }
336 
341  {
342  $this->initialWidth = $initialWidth;
343  }
344 }
345 
346 ?>