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