• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

Services/RTE/classes/class.ilRTE.php

Go to the documentation of this file.
00001 <?php
00002  /*
00003    +----------------------------------------------------------------------------+
00004    | ILIAS open source                                                          |
00005    +----------------------------------------------------------------------------+
00006    | Copyright (c) 1998-2001 ILIAS open source, University of Cologne           |
00007    |                                                                            |
00008    | This program is free software; you can redistribute it and/or              |
00009    | modify it under the terms of the GNU General Public License                |
00010    | as published by the Free Software Foundation; either version 2             |
00011    | of the License, or (at your option) any later version.                     |
00012    |                                                                            |
00013    | This program is distributed in the hope that it will be useful,            |
00014    | but WITHOUT ANY WARRANTY; without even the implied warranty of             |
00015    | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              |
00016    | GNU General Public License for more details.                               |
00017    |                                                                            |
00018    | You should have received a copy of the GNU General Public License          |
00019    | along with this program; if not, write to the Free Software                |
00020    | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
00021    +----------------------------------------------------------------------------+
00022 */
00023 
00034 class ilRTE
00035 {
00043         var $plugins;
00044         var $buttons;
00045         var $tpl;
00046         var $ctrl;
00047         var $lng;
00048         
00049         function ilRTE()
00050         {
00051                 global $tpl, $ilCtrl, $lng;
00052                 $this->tpl =& $tpl;
00053                 $this->ctrl =& $ilCtrl;
00054                 $this->lng =& $lng;
00055                 $this->plugins = array();
00056                 $this->buttons = array();
00057         }
00058         
00067         function addPlugin($a_plugin_name)
00068         {
00069                 array_push($this->plugins, $a_plugin_name);
00070         }
00071         
00080         function addButton($a_button_name)
00081         {
00082                 array_push($this->buttons, $a_button_name);
00083         }
00084         
00093         function removePlugin($a_plugin_name)
00094         {
00095                 $key = array_search($a_plugin_name, $this->plugins);
00096                 if ($key !== FALSE)
00097                 {
00098                         unset($this->plugins[$key]);
00099                 }
00100         }
00101         
00110         function removeButton($a_button_name)
00111         {
00112                 $key = array_search($a_button_name, $this->buttons);
00113                 if ($key !== FALSE)
00114                 {
00115                         unset($this->buttons[$key]);
00116                 }
00117         }
00118         
00126         function addRTESupport()
00127         {
00128                 // must be overwritten in parent classes
00129         }
00130 
00138         function addCustomRTESupport($obj_id, $obj_type, $tags)
00139         {
00140                 // must be overwritten in parent classes
00141         }
00142         
00143         
00144         function _getRTEClassname()
00145         {
00146                 include_once "./classes/class.ilObjAdvancedEditing.php";
00147                 $editor = ilObjAdvancedEditing::_getRichTextEditor();
00148                 switch ($editor)
00149                 {
00150                         case "tinymce":
00151                                 return "ilTinyMCE";
00152                                 break;
00153                         default:
00154                                 return "ilRTE";
00155                                 break;
00156                 }
00157         }
00158 
00167         function _cleanupMediaObjectUsage($a_text, $a_usage_type, $a_usage_id)
00168         {
00169                 // get current stored mobs
00170                 include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
00171                 $mobs = ilObjMediaObject::_getMobsOfObject($a_usage_type,
00172                         $a_usage_id);
00173                 while (eregi("data\/".CLIENT_ID."\/mobs\/mm_([0-9]+)", $a_text, $found))
00174                 {
00175                         $a_text = str_replace($found[0], "", $a_text);
00176                         if (!in_array($found[1], $mobs))
00177                         {
00178                                 // save usage if missing
00179                                 ilObjMediaObject::_saveUsage($found[1], $a_usage_type,
00180                                         $a_usage_id);
00181                         }
00182                         else
00183                         {
00184                                 // if already saved everything ok -> take mob out of mobs array
00185                                 unset($mobs[$found[1]]);
00186                         }
00187                 }
00188                 // remaining usages are not in text anymore -> delete them
00189                 // and media objects (note: delete method of ilObjMediaObject
00190                 // checks whether object is used in another context; if yes,
00191                 // the object is not deleted!)
00192                 foreach($mobs as $mob)
00193                 {
00194                         ilObjMediaObject::_removeUsage($mob, $a_usage_type,
00195                                 $a_usage_id);
00196                         $mob_obj =& new ilObjMediaObject($mob);
00197                         $mob_obj->delete();
00198                 }
00199         }
00200         
00209         function _replaceMediaObjectImageSrc($a_text, $a_direction = 0)
00210         {
00211                 switch ($a_direction)
00212                 {
00213                         case 0:
00214                                 $a_text = preg_replace("/src\=\"(.*?\/mobs\/mm_([0-9]+)\/.*?)\"/", "src=\"il_" . IL_INST_ID . "_mob_" . "\\2" . "\"", $a_text);
00215                                 break;
00216                         default:
00217                                 include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
00218                                 $resulttext = $a_text;
00219                                 if (preg_match_all("/src\=\"il_([0-9]+)_mob_([0-9]+)\"/", $a_text, $matches))
00220                                 {
00221                                         foreach ($matches[2] as $idx => $mob)
00222                                         {
00223                                                 $mob_obj =& new ilObjMediaObject($mob);
00224                                                 $replace = "il_" . $matches[1][$idx] . "_mob_" . $mob;
00225                                                 $resulttext = str_replace("src=\"$replace\"", "src=\"" . ILIAS_HTTP_PATH . "/data/" . CLIENT_ID . "/mobs/mm_" . $mob . "/" . $mob_obj->getTitle() . "\"", $resulttext);
00226                                         }
00227                                 }
00228                                 $a_text = $resulttext;
00229                                 break;
00230                 }
00231                 return $a_text;
00232         }
00233 }
00234 
00235 ?>

Generated on Fri Dec 13 2013 17:57:00 for ILIAS Release_3_9_x_branch .rev 46835 by  doxygen 1.7.1