00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
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
00074
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 global $ilCtrl;
00127
00128 $this->tpl = new ilTemplate("tpl.wysiwyg_popup_footnote.html",false,false,true);
00129 $this->tpl->setVariable("LOCATION_STYLESHEET", ilUtil::getStyleSheetLocation() );
00130 $this->tpl->setVariable("LOCATION_CONTENT_STYLESHEET_HTMLAREA", ILIAS_HTTP_PATH."/content/content.css" );
00131 $this->tpl->setVariable("REF_ID", $_GET["ref_id"]);
00132 $ilCtrl->setParameterByClass("ilpcparagraphgui", "ptype", "footnote");
00133 $this->tpl->setVariable("FOOTNOTE_TARGET",
00134 $ilCtrl->getLinkTargetByClass("ilpcparagraphgui", "popup"));
00135
00136
00137 $this->tpl->setVariable("TXT_FOOTNOTES", $this->lng->txt("cont_title_footnotes"));
00138 $this->tpl->setVariable("TXT_INSERT_NEW_FOOTNOTES", $this->lng->txt("cont_insert_new_footnote"));
00139 $this->tpl->setVariable("BTN_SUBMIT", $this->lng->txt("save"));
00140 $this->tpl->setVariable("BTN_CANCEL", $this->lng->txt("cancel"));
00141
00142 $this->tpl->setVariable("DELETE_QUESTION", $this->lng->txt("cont_confirm_delete"));
00143 $this->tpl->setVariable("BTN_DELETE", $this->lng->txt("delete"));
00144
00145 }
00146
00147
00148
00149 function showHeader()
00150 {
00151
00152 }
00153
00154
00155 var $struct = array();
00156 var $depth;
00157 var $newXml;
00158 function convertFromPost($content)
00159 {
00160
00161
00162 $content = str_replace(" "," ",$content);
00163
00164
00165 $content = str_replace(" </span>","</span> ",$content);
00166 $content = str_replace("<span class=\"ilc_Strong\"></span>","",$content);
00167 $content = str_replace("<span class=\"ilc_Emph\"></span>","",$content);
00168 $content = str_replace("<span class=\"ilc_Quotation\"></span>","",$content);
00169 $content = str_replace("<span class=\"ilc_Comment\"></span>","",$content);
00170
00171 $content = rawurlencode($content);
00172 $content = str_replace("%3Cspan%20class%3D%22ilc_Strong%22%3E%20%3C%2Fspan%3E","%20",$content);
00173 $content = str_replace("%3Cspan%20class%3D%22ilc_Emph%22%3E%20%3C%2Fspan%3E","%20",$content);
00174 $content = str_replace("%3Cspan%20class%3D%22ilc_Quotation%22%3E%20%3C%2Fspan%3E","%20",$content);
00175 $content = str_replace("%3Cspan%20class%3D%22ilc_Comment%22%3E%20%3C%2Fspan%3E","%20",$content);
00176 $content = rawurldecode($content);
00177
00178
00179
00180
00181
00182
00183 $content = str_replace("&","&",$content);
00184
00185 for($k=0;$k<2;$k++) {
00186 $xml_parser = xml_parser_create("UTF-8");
00187 xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, false);
00188 xml_set_object($xml_parser,$this);
00189 xml_set_element_handler($xml_parser, "startElement", "endElement");
00190 xml_set_character_data_handler($xml_parser, "characterData");
00191
00192 $xml_data = "<xml>".$content."</xml>";
00193
00194 $this->depth = 0;
00195 $this->struct = array();
00196 $this->newXml = "";
00197
00198 if (!xml_parse($xml_parser, $xml_data))
00199 {
00200 die(sprintf("XML error: %s at line %d", xml_error_string(xml_get_error_code($xml_parser)),xml_get_current_line_number($xml_parser)));
00201 }
00202 xml_parser_free($xml_parser);
00203
00204 $this->newXml = str_replace("<xml>","",$this->newXml);
00205 $this->newXml = str_replace("</xml>","",$this->newXml);
00206
00207 $content = $this->newXml;
00208
00209
00210
00211 }
00212
00213
00214
00215 $this->newXml = str_replace("[com][/com]","",$this->newXml);
00216 $this->newXml = str_replace("[emp][/emp]","",$this->newXml);
00217 $this->newXml = str_replace("[str][/str]","",$this->newXml);
00218 $this->newXml = str_replace("[code][/code]","",$this->newXml);
00219 $this->newXml = str_replace("[quot][/quot]","",$this->newXml);
00220
00221 $this->newXml = str_replace("</p><p>","\n",$this->newXml);
00222 $this->newXml = str_replace("<p>","",$this->newXml);
00223 $this->newXml = str_replace("</p>","",$this->newXml);
00224
00225 $this->newXml = str_replace("<p class=\"MsoNormal\">","\n",$this->newXml);
00226 $this->newXml = str_replace("<p class=\"MsoNormal\" style=\"MARGIN: 0cm 0cm 0pt\">","\n",$this->newXml);
00227
00228
00229 $this->newXml = str_replace("<Strong/>","",$this->newXml);
00230 $this->newXml = str_replace("<Emph/>","",$this->newXml);
00231
00232 $this->newXml = str_replace("<span>","",$this->newXml);
00233 $this->newXml = str_replace("</span>","",$this->newXml);
00234
00235
00236
00237 return($this->newXml);
00238 }
00239
00240
00241
00242
00243
00244 function startElement($parser, $name, $attrs)
00245 {
00246 $new = array("name" => $name,
00247 "attrs" => $attrs,
00248 "convert" => "",
00249 "convert2" => ""
00250 );
00251
00252 $new["convert"] = "<".$name;
00253 if (is_array($attrs))
00254 {
00255 reset ($attrs);
00256 while (list ($key, $val) = each ($attrs))
00257 {
00258 $new["convert"] .= " ".$key."=\"".$val."\"";
00259 }
00260 }
00261 $new["convert"] .= ">";
00262 $new["convert2"] = "</".$name.">";
00263
00264
00265 if ($attrs["style"] == "font-style: italic;" || $name == "em")
00266 {
00267 $new["convert"] = "[emp]";
00268 $new["convert2"] = "[/emp]";
00269 }
00270 if ($attrs["style"] == "font-weight: bold;" || $name == "strong")
00271 {
00272 $new["convert"] = "[str]";
00273 $new["convert2"] = "[/str]";
00274 }
00275
00276
00277 if ($attrs["class"] == "ilc_ExtLink")
00278 {
00279 $new["convert"] = "[xln url=\"".str_replace("&","&",$attrs[url])."\"]";
00280 $new["convert2"] = "[/xln]";
00281 }
00282
00283 if ($attrs["class"] == "ilc_IntLink")
00284 {
00285 reset ($attrs);
00286 $N = "";
00287 while (list ($key, $val) = each ($attrs))
00288 {
00289 if ($key!="class")
00290 {
00291 $N .= " ".$key."=\"".$val."\"";
00292 }
00293 }
00294 $new["convert"] = "[iln".$N."]";
00295 $new["convert2"] = "[/iln]";
00296 }
00297
00298 if ($attrs["class"] == "ilc_Strong")
00299 {
00300 $new["convert"] = "[str]";
00301 $new["convert2"] = "[/str]";
00302 }
00303 if ($attrs["class"] == "ilc_Comment")
00304 {
00305 $new["convert"] = "[com]";
00306 $new["convert2"] = "[/com]";
00307 }
00308 if ($attrs["class"] == "ilc_Emph")
00309 {
00310 $new["convert"] = "[emp]";
00311 $new["convert2"] = "[/emp]";
00312 }
00313
00314 if ($attrs["class"] == "ilc_Quotation")
00315 {
00316 $new["convert"] = "[quot]";
00317 $new["convert2"] = "[/quot]";
00318 }
00319
00320 if ($attrs["class"] == "footnote")
00321 {
00322
00323
00324 $fn1 = explode("|**#",stripslashes($_POST["footnotelist"]));
00325 for ($i=0;$i<count($fn1);$i++)
00326 {
00327
00328 $fn2 = explode("|*#",$fn1[$i]);
00329
00330
00331
00332 if($fn2[0] == $attrs["value"])
00333 {
00334 $new["convert"] = "[fn]".$fn2[1];
00335 $new["convert2"] = "[/fn]";
00336 break;
00337 }
00338
00339
00340 }
00341
00342 }
00343
00344 if ($name == "code") {
00345 $new["convert"] = "[code]";
00346 $new["convert2"] = "[/code]";
00347 }
00348
00349
00350
00351 $this->struct[$this->depth] = $new;
00352 $this->depth++;
00353
00354 if ($name!="br")
00355 {
00356 $this->newXml .= $new[convert];
00357 }
00358 else
00359 {
00360 $this->newXml .= "\n";
00361 }
00362
00363
00364
00365 }
00366
00367 function characterData($parser, $data)
00368 {
00369
00370
00371 if (!stristr( $this->struct[$this->depth-1]["convert"], "[fn]" ))
00372 {
00373 $this->newXml .= $data;
00374 }
00375
00376 }
00377
00378 function endElement($parser, $name)
00379 {
00380 $this->depth--;
00381
00382
00383 if ($name!="br")
00384 {
00385 $this->newXml .= $this->struct[$this->depth]["convert2"];
00386 }
00387
00388
00389 }
00390
00391
00392 }
00393
00394 ?>