ILIAS  Release_4_4_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 
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 
104  public function removeAllPlugins()
105  {
106  foreach($this->plugins as $plugin)
107  {
108  $this->removePlugin($plugin);
109  }
110  }
111 
120  function removeButton($a_button_name)
121  {
122  $key = array_search($a_button_name, $this->buttons);
123  if ($key !== FALSE)
124  {
125  unset($this->buttons[$key]);
126  }
127  }
128 
136  function addRTESupport()
137  {
138  // must be overwritten in parent classes
139  }
140 
146  function addUserTextEditor($editor_selector)
147  {
148  // must be overwritten in parent classes
149  }
150 
158  function addCustomRTESupport($obj_id, $obj_type, $tags)
159  {
160  // must be overwritten in parent classes
161  }
162 
163 
164  public static function _getRTEClassname()
165  {
166  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
168  switch ($editor)
169  {
170  case "tinymce":
171  return "ilTinyMCE";
172  break;
173  default:
174  return "ilRTE";
175  break;
176  }
177  }
178 
187  function _cleanupMediaObjectUsage($a_text, $a_usage_type, $a_usage_id)
188  {
189  // get current stored mobs
190  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
192  $a_usage_id);
193  while (eregi("data\/".CLIENT_ID."\/mobs\/mm_([0-9]+)", $a_text, $found))
194  {
195  $a_text = str_replace($found[0], "", $a_text);
196  if (!in_array($found[1], $mobs))
197  {
198  // save usage if missing
199  ilObjMediaObject::_saveUsage($found[1], $a_usage_type,
200  $a_usage_id);
201  }
202  else
203  {
204  // if already saved everything ok -> take mob out of mobs array
205  unset($mobs[$found[1]]);
206  }
207  }
208  // remaining usages are not in text anymore -> delete them
209  // and media objects (note: delete method of ilObjMediaObject
210  // checks whether object is used in another context; if yes,
211  // the object is not deleted!)
212  foreach($mobs as $mob)
213  {
214  ilObjMediaObject::_removeUsage($mob, $a_usage_type,
215  $a_usage_id);
216  $mob_obj =& new ilObjMediaObject($mob);
217  $mob_obj->delete();
218  }
219  }
220 
230  public static function _replaceMediaObjectImageSrc($a_text, $a_direction = 0)
231  {
232  if (!strlen($a_text)) return "";
233  switch ($a_direction)
234  {
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  default:
239  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
240  $resulttext = $a_text;
241  if (preg_match_all("/src\=\"il_([0-9]+)_mob_([0-9]+)\"/", $a_text, $matches))
242  {
243  foreach ($matches[2] as $idx => $mob)
244  {
245  if (ilObjMediaObject::_exists($mob))
246  {
247  $mob_obj =& new ilObjMediaObject($mob);
248  $replace = "il_" . $matches[1][$idx] . "_mob_" . $mob;
249  $resulttext = str_replace("src=\"$replace\"", "src=\"" . ILIAS_HTTP_PATH . "/data/" . CLIENT_ID . "/mobs/mm_" . $mob . "/" . $mob_obj->getTitle() . "\"", $resulttext);
250  }
251  }
252  }
253  $a_text = $resulttext;
254  break;
255  }
256  return $a_text;
257  }
258 
266  public static function _getMediaObjects($a_text, $a_direction = 0)
267  {
268  if (!strlen($a_text)) return array();
269  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
270 
271  $mediaObjects = array();
272  switch ($a_direction)
273  {
274  case 0:
275  if(preg_match_all("/src\=\"(.*?\/mobs\/mm_([0-9]+)\/.*?)\"/", $a_text, $matches))
276  {
277  foreach ($matches[2] as $idx => $mob)
278  {
279  if (ilObjMediaObject::_exists($mob) && !in_array($mob, $mediaObjects))
280  {
281  $mediaObjects[] = $mob;
282  }
283  }
284  }
285  break;
286  default:
287 
288  if(preg_match_all("/src\=\"il_([0-9]+)_mob_([0-9]+)\"/", $a_text, $matches))
289  {
290  foreach ($matches[2] as $idx => $mob)
291  {
292  if (ilObjMediaObject::_exists($mob) && !in_array($mob, $mediaObjects))
293  {
294  $mediaObjects[] = $mob;
295  }
296  }
297  }
298  break;
299  }
300  return $mediaObjects;
301  }
302 
303  public function setRTERootBlockElement()
304  {
305  // must be overwritten in sub classes
306  }
307 
308  public function getRTERootBlockElement()
309  {
310  // must be overwritten in sub classes
311  }
312 
313  public function disableButtons()
314  {
315  // must be overwritten in sub classes
316  }
317 
318  public function getDisabledButtons()
319  {
320  // must be overwritten in sub classes
321  }
322 }
323 
324 ?>