ILIAS  Release_3_10_x_branch Revision 61812
 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()
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  switch ($a_direction)
222  {
223  case 0:
224  $a_text = preg_replace("/src\=\"(.*?\/mobs\/mm_([0-9]+)\/.*?)\"/", "src=\"il_" . IL_INST_ID . "_mob_" . "\\2" . "\"", $a_text);
225  break;
226  default:
227  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
228  $resulttext = $a_text;
229  if (preg_match_all("/src\=\"il_([0-9]+)_mob_([0-9]+)\"/", $a_text, $matches))
230  {
231  foreach ($matches[2] as $idx => $mob)
232  {
233  if (ilObjMediaObject::_exists($mob))
234  {
235  $mob_obj =& new ilObjMediaObject($mob);
236  $replace = "il_" . $matches[1][$idx] . "_mob_" . $mob;
237  $resulttext = str_replace("src=\"$replace\"", "src=\"" . ILIAS_HTTP_PATH . "/data/" . CLIENT_ID . "/mobs/mm_" . $mob . "/" . $mob_obj->getTitle() . "\"", $resulttext);
238  }
239  }
240  }
241  $a_text = $resulttext;
242  break;
243  }
244  return $a_text;
245  }
246 }
247 
248 ?>