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