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

content/classes/Pages/class.ilWysiwygUtil.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 
00024 require_once("content/classes/class.ilLMObjectFactory.php");
00025 
00026 class ilWysiwygUtil
00027 {
00028     
00029         var $tpl;
00030         var $lng;
00031         
00032         function ilWysiwygUtil() 
00033         {
00034                 global $lng;
00035                 $this->lng =& $lng;
00036                 $this->lng->loadLanguageModule("content");
00037         }
00038         
00039         function show($ptype) 
00040         {
00041                 $this->showHeader();
00042                 switch ($ptype) {
00043                         case "xtl" : {
00044                                                         $this->showXtl();
00045                                                         break;
00046                                                 }
00047                         case "itl" : {
00048                                                         $this->showItl();
00049                                                         break;
00050                                                 }
00051                         case "footnote" : {
00052                                                         $this->showFootnote();
00053                                                         break;
00054                                                 }
00055                         case "movecopytreenode" : {
00056                                                         $this->showMoveCopyQuestion();
00057                                                         break;
00058                                                 }
00059                 }
00060                 
00061                 $this->tpl->show();
00062                 
00063         }
00064         
00065         function showMoveCopyQuestion() {
00066                 
00067                 $tempobj = ilObjectFactory::getInstanceByRefId($_GET["ref_id"]);
00068                 $source_obj = ilLMObjectFactory::getInstance($tempobj, $_GET["sourceId"], true);
00069                 $source_obj->setLMId($tempobj->getId());
00070                 $target_obj = ilLMObjectFactory::getInstance($tempobj, $_GET["targetId"], true);
00071                 $target_obj->setLMId($tempobj->getId());
00072                 
00073                 //vd($source_obj->getType());
00074                 //vd($target_obj->getType());
00075                 
00076                 $this->tpl = new ilTemplate("tpl.wysiwyg_popup_movecopyquestion.html",false,true,true);
00077                 $this->tpl->setVariable("LOCATION_STYLESHEET", ilUtil::getStyleSheetLocation() );
00078                 
00079                 if ($source_obj->getType() == "st" && $target_obj->getType() == "pg") {
00080                         $this->tpl->setVariable("TXT_ST_ON_PG",$this->lng->txt("cont_st_on_pg"));
00081                         $this->tpl->setVariable("BTN_CLOSE2", $this->lng->txt("close"));
00082                 } else {
00083                 
00084                         if (($source_obj->getType() == "pg" && $target_obj->getType() == "pg") || ($source_obj->getType() == "st" && $target_obj->getType() == "st")) {
00085                                 $this->tpl->setVariable("TXT_SET_AFTER", $this->lng->txt("cont_set_after"));
00086                                 $this->tpl->setVariable("TXT_SET_BEFORE", $this->lng->txt("cont_set_before"));
00087                         }
00088                         if ($source_obj->getType() == "st" && $target_obj->getType() == "st") {
00089                                 $this->tpl->setVariable("TXT_SET_INTO", $this->lng->txt("cont_set_into"));
00090                         }
00091                         
00092                         $this->tpl->setVariable("TXT_MOVE_OBJECT", $this->lng->txt("cont_move_object"));
00093                         $this->tpl->setVariable("TXT_COPY_OBJECT", $this->lng->txt("cont_copy_object"));
00094                         
00095                         $this->tpl->setVariable("BTN_SUBMIT", $this->lng->txt("save"));
00096                         $this->tpl->setVariable("BTN_CLOSE", $this->lng->txt("close"));
00097                 }
00098         }
00099         
00100         function showXtl() 
00101         {
00102                 $this->tpl = new ilTemplate("tpl.wysiwyg_popup_xtl.html",false,false,true);
00103                 $this->tpl->setVariable("LOCATION_STYLESHEET", ilUtil::getStyleSheetLocation() );
00104                 
00105                 
00106                 $this->tpl->setVariable("TXT_EXTERNAL_URL", $this->lng->txt("cont_external_url"));
00107                 $this->tpl->setVariable("TXT_TITLE", $this->lng->txt("cont_title"));
00108                 $this->tpl->setVariable("BTN_SUBMIT", $this->lng->txt("save"));
00109                 $this->tpl->setVariable("BTN_DELETE", $this->lng->txt("delete"));
00110                 $this->tpl->setVariable("BTN_CLOSE", $this->lng->txt("close"));
00111                 
00112                 $this->tpl->setVariable("TXT_OR", $this->lng->txt("cont_or"));
00113                 $this->tpl->setVariable("TXT_EXAMPLE", $this->lng->txt("cont_example"));
00114                 
00115                 $this->tpl->setVariable("DELETE_QUESTION", $this->lng->txt("cont_confirm_delete"));
00116         }
00117         
00118         function showItl() 
00119         {
00120                 $this->tpl = new ilTemplate("tpl.wysiwyg_popup_itl.html",false,false,true);
00121                 $this->tpl->setVariable("LOCATION_STYLESHEET", ilUtil::getStyleSheetLocation() );
00122         }
00123         
00124         function showFootnote() 
00125         {
00126                 $this->tpl = new ilTemplate("tpl.wysiwyg_popup_footnote.html",false,false,true);
00127                 $this->tpl->setVariable("LOCATION_STYLESHEET", ilUtil::getStyleSheetLocation() );
00128                 $this->tpl->setVariable("LOCATION_CONTENT_STYLESHEET_HTMLAREA", "../content/content.css" );
00129                 $this->tpl->setVariable("REF_ID", $_GET["ref_id"]);
00130 
00131                 
00132                 $this->tpl->setVariable("TXT_FOOTNOTES", $this->lng->txt("cont_title_footnotes"));
00133                 $this->tpl->setVariable("TXT_INSERT_NEW_FOOTNOTES", $this->lng->txt("cont_insert_new_footnote"));
00134                 $this->tpl->setVariable("BTN_SUBMIT", $this->lng->txt("save"));
00135                 $this->tpl->setVariable("BTN_CANCEL", $this->lng->txt("cancel"));
00136                 
00137                 $this->tpl->setVariable("DELETE_QUESTION", $this->lng->txt("cont_confirm_delete"));
00138                 $this->tpl->setVariable("BTN_DELETE", $this->lng->txt("delete"));
00139                 
00140         }
00141         
00142         
00143         
00144         function showHeader() 
00145         {
00146                 
00147         }
00148         
00149         
00150     var $struct = array();
00151     var $depth;
00152     var $newXml;
00153     function convertFromPost($content) 
00154         {
00155         
00156                 
00157                 $content = str_replace("&nbsp;"," ",$content);
00158                 //vd(htmlspecialchars($content));
00159                 
00160                 $content = str_replace(" </span>","</span> ",$content);
00161                 $content = str_replace("<span class=\"ilc_Strong\"></span>","",$content);
00162                 $content = str_replace("<span class=\"ilc_Emph\"></span>","",$content);
00163                 $content = str_replace("<span class=\"ilc_Quotation\"></span>","",$content);
00164                 $content = str_replace("<span class=\"ilc_Comment\"></span>","",$content);
00165                 
00166                 $content = rawurlencode($content);
00167                 $content = str_replace("%3Cspan%20class%3D%22ilc_Strong%22%3E%20%3C%2Fspan%3E","%20",$content);
00168                 $content = str_replace("%3Cspan%20class%3D%22ilc_Emph%22%3E%20%3C%2Fspan%3E","%20",$content);
00169                 $content = str_replace("%3Cspan%20class%3D%22ilc_Quotation%22%3E%20%3C%2Fspan%3E","%20",$content);
00170                 $content = str_replace("%3Cspan%20class%3D%22ilc_Comment%22%3E%20%3C%2Fspan%3E","%20",$content);
00171                 $content = rawurldecode($content);
00172                 
00173 
00174                 //echo(htmlspecialchars($content));
00175 //              echo "<p>";
00176 //              echo(rawurlencode($content));
00177                 
00178                 $content = str_replace("&","&amp;",$content);
00179 
00180                 for($k=0;$k<2;$k++) {
00181                         $xml_parser = xml_parser_create("UTF-8");
00182                         xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, false);
00183                         xml_set_object($xml_parser,$this);
00184                         xml_set_element_handler($xml_parser, "startElement", "endElement");
00185                         xml_set_character_data_handler($xml_parser, "characterData");
00186         
00187                         $xml_data = "<xml>".$content."</xml>";
00188                         
00189                         $this->depth = 0;
00190                         $this->struct = array();
00191                         $this->newXml = "";
00192                         
00193                         if (!xml_parse($xml_parser, $xml_data)) 
00194                         {
00195                                 die(sprintf("XML error: %s at line %d", xml_error_string(xml_get_error_code($xml_parser)),xml_get_current_line_number($xml_parser)));
00196                         }
00197                         xml_parser_free($xml_parser);
00198                         
00199                         $this->newXml = str_replace("<xml>","",$this->newXml);
00200                         $this->newXml = str_replace("</xml>","",$this->newXml);
00201                         
00202                         $content = $this->newXml;
00203 
00204                         
00205                         //echo htmlspecialchars($content)."<p>";
00206                 }        
00207                 //echo htmlspecialchars($this->newXml);
00208                 //exit;
00209                 
00210                 $this->newXml = str_replace("[com][/com]","",$this->newXml);
00211                 $this->newXml = str_replace("[emp][/emp]","",$this->newXml);
00212                 $this->newXml = str_replace("[str][/str]","",$this->newXml);
00213                 $this->newXml = str_replace("[code][/code]","",$this->newXml);
00214                 $this->newXml = str_replace("[quot][/quot]","",$this->newXml);
00215                 
00216                 $this->newXml = str_replace("</p><p>","\n",$this->newXml);
00217                 $this->newXml = str_replace("<p>","",$this->newXml);
00218                 $this->newXml = str_replace("</p>","",$this->newXml);
00219                 
00220                 
00221                 $this->newXml = str_replace("<Strong/>","",$this->newXml);
00222                 $this->newXml = str_replace("<Emph/>","",$this->newXml);
00223                 
00224                 $this->newXml = str_replace("<span>","",$this->newXml);
00225                 $this->newXml = str_replace("</span>","",$this->newXml);
00226                 
00227                 //vd(htmlspecialchars($this->newXml));
00228                 
00229         return($this->newXml);
00230     }
00231 
00232     
00233     
00234 
00235     //{{{
00236     function startElement($parser, $name, $attrs) 
00237         {
00238         $new = array("name" => $name,
00239                                 "attrs" => $attrs,
00240                                 "convert" => "",
00241                                 "convert2" => ""
00242                                 );
00243 
00244         $new["convert"] = "<".$name;                
00245         if (is_array($attrs)) 
00246                 {
00247             reset ($attrs);
00248             while (list ($key, $val) = each ($attrs)) 
00249                         {
00250                 $new["convert"] .= " ".$key."=\"".$val."\"";
00251             }
00252         }
00253         $new["convert"] .= ">";
00254         $new["convert2"] = "</".$name.">";
00255         
00256                 
00257                 if ($attrs["style"] == "font-style: italic;" || $name == "em") 
00258                 {
00259             $new["convert"] = "[emp]";
00260             $new["convert2"] = "[/emp]";
00261                 }
00262                 if ($attrs["style"] == "font-weight: bold;" || $name == "strong") 
00263                 {
00264             $new["convert"] = "[str]";
00265             $new["convert2"] = "[/str]";
00266                 }
00267                 
00268                 // alex changed
00269                 if ($attrs["class"] == "ilc_ExtLink") 
00270                 {
00271                         $new["convert"] = "[xln url=\"".$attrs[url]."\"]";
00272             $new["convert2"] = "[/xln]";
00273                 }
00274                 
00275                 if ($attrs["class"] == "ilc_IntLink") 
00276                 {
00277                         reset ($attrs);
00278                         $N = "";
00279                         while (list ($key, $val) = each ($attrs)) 
00280                         {
00281                                 if ($key!="class") 
00282                                 {
00283                                         $N .= " ".$key."=\"".$val."\"";
00284                                 }
00285                         }
00286                         $new["convert"] = "[iln".$N."]";
00287             $new["convert2"] = "[/iln]";
00288                 }
00289                 
00290         if ($attrs["class"] == "ilc_Strong") 
00291                 {
00292             $new["convert"] = "[str]";
00293             $new["convert2"] = "[/str]";
00294         }
00295         if ($attrs["class"] == "ilc_Comment") 
00296                 {
00297             $new["convert"] = "[com]";
00298             $new["convert2"] = "[/com]";
00299         }
00300         if ($attrs["class"] == "ilc_Emph") 
00301                 {
00302             $new["convert"] = "[emp]";
00303             $new["convert2"] = "[/emp]";
00304         }
00305         
00306         if ($attrs["class"] == "ilc_Quotation") 
00307                 {
00308             $new["convert"] = "[quot]";
00309             $new["convert2"] = "[/quot]";
00310         }
00311         
00312                 if ($attrs["class"] == "footnote") 
00313                 {
00314                         //vd($attrs);
00315 
00316                         $fn1 = explode("|**#",stripslashes($_POST["footnotelist"]));
00317                         for ($i=0;$i<count($fn1);$i++) 
00318                         {
00319                                 // {{{
00320                                 $fn2 = explode("|*#",$fn1[$i]);
00321                                 
00322                                 //echo htmlspecialchars(serialize($fn2[1]))."<p>";
00323                                 
00324                                 if($fn2[0] == $attrs["value"]) 
00325                                 {
00326                                         $new["convert"] = "[fn]".$fn2[1];
00327                                         $new["convert2"] = "[/fn]";
00328                                         break;
00329                                 }
00330                                 
00331                                 // }}}
00332                         }
00333                         
00334                 }
00335                 
00336         if ($name == "code") {
00337             $new["convert"] = "[code]";
00338             $new["convert2"] = "[/code]";
00339         }
00340         
00341         //echo htmlspecialchars($new[convert]);
00342                                 
00343         $this->struct[$this->depth] = $new;
00344         $this->depth++;
00345         
00346         if ($name!="br") 
00347                 {
00348             $this->newXml .= $new[convert];
00349         } 
00350                 else 
00351                 {
00352             $this->newXml .= "\n";
00353         }
00354         
00355 //        vd($name);
00356 //        vd($attrs);
00357     }
00358     
00359     function characterData($parser, $data) 
00360         {
00361 //        vd($data);
00362                 //if ($data == "[1]") $data = "";
00363                 if (!stristr( $this->struct[$this->depth-1]["convert"], "[fn]" )) 
00364                 { 
00365                         $this->newXml .= $data;
00366                 }
00367                 
00368     }
00369     
00370     function endElement($parser, $name)
00371     {
00372         $this->depth--;
00373         
00374         //$this->newXml .= "</".$name.">";
00375         if ($name!="br") 
00376                 {
00377             $this->newXml .= $this->struct[$this->depth]["convert2"];
00378         }
00379         
00380 //        vd($name);
00381     }
00382     // }}}  
00383     
00384 }
00385 
00386 ?>

Generated on Fri Dec 13 2013 09:06:36 for ILIAS Release_3_4_x_branch .rev 46804 by  doxygen 1.7.1