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