ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilWysiwygUtil.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 require_once("./Modules/LearningModule/classes/class.ilLMObjectFactory.php");
25 
34 {
35 
36  var $tpl;
37  var $lng;
38 
39  function ilWysiwygUtil()
40  {
41  global $lng;
42  $this->lng =& $lng;
43  $this->lng->loadLanguageModule("content");
44  }
45 
46  function show($ptype)
47  {
48  $this->showHeader();
49  switch ($ptype) {
50  case "xtl" : {
51  $this->showXtl();
52  break;
53  }
54  case "itl" : {
55  $this->showItl();
56  break;
57  }
58  case "footnote" : {
59  $this->showFootnote();
60  break;
61  }
62  case "movecopytreenode" : {
63  $this->showMoveCopyQuestion();
64  break;
65  }
66  }
67 
68  $this->tpl->show();
69 
70  }
71 
72  function showMoveCopyQuestion() {
73 
74  $tempobj = ilObjectFactory::getInstanceByRefId($_GET["ref_id"]);
75  $source_obj = ilLMObjectFactory::getInstance($tempobj, $_GET["sourceId"], true);
76  $source_obj->setLMId($tempobj->getId());
77  $target_obj = ilLMObjectFactory::getInstance($tempobj, $_GET["targetId"], true);
78  $target_obj->setLMId($tempobj->getId());
79 
80  //vd($source_obj->getType());
81  //vd($target_obj->getType());
82 
83  $this->tpl = new ilTemplate("tpl.wysiwyg_popup_movecopyquestion.html",false,true,"Services/COPage");
84  $this->tpl->setVariable("LOCATION_STYLESHEET", ilUtil::getStyleSheetLocation() );
85 
86  if ($source_obj->getType() == "st" && $target_obj->getType() == "pg") {
87  $this->tpl->setVariable("TXT_ST_ON_PG",$this->lng->txt("cont_st_on_pg"));
88  $this->tpl->setVariable("BTN_CLOSE2", $this->lng->txt("close"));
89  } else {
90 
91  if (($source_obj->getType() == "pg" && $target_obj->getType() == "pg") || ($source_obj->getType() == "st" && $target_obj->getType() == "st")) {
92  $this->tpl->setVariable("TXT_SET_AFTER", $this->lng->txt("cont_set_after"));
93  $this->tpl->setVariable("TXT_SET_BEFORE", $this->lng->txt("cont_set_before"));
94  }
95  if ($source_obj->getType() == "st" && $target_obj->getType() == "st") {
96  $this->tpl->setVariable("TXT_SET_INTO", $this->lng->txt("cont_set_into"));
97  }
98 
99  $this->tpl->setVariable("TXT_MOVE_OBJECT", $this->lng->txt("cont_move_object"));
100  $this->tpl->setVariable("TXT_COPY_OBJECT", $this->lng->txt("cont_copy_object"));
101 
102  $this->tpl->setVariable("BTN_SUBMIT", $this->lng->txt("save"));
103  $this->tpl->setVariable("BTN_CLOSE", $this->lng->txt("close"));
104  }
105  }
106 
107  function showXtl()
108  {
109  $this->tpl = new ilTemplate("tpl.wysiwyg_popup_xtl.html",false,false,"Services/COPage");
110  $this->tpl->setVariable("LOCATION_STYLESHEET", ilUtil::getStyleSheetLocation() );
111 
112 
113  $this->tpl->setVariable("TXT_EXTERNAL_URL", $this->lng->txt("cont_external_url"));
114  $this->tpl->setVariable("TXT_TITLE", $this->lng->txt("cont_title"));
115  $this->tpl->setVariable("BTN_SUBMIT", $this->lng->txt("save"));
116  $this->tpl->setVariable("BTN_DELETE", $this->lng->txt("delete"));
117  $this->tpl->setVariable("BTN_CLOSE", $this->lng->txt("close"));
118 
119  $this->tpl->setVariable("TXT_OR", $this->lng->txt("cont_or"));
120  $this->tpl->setVariable("TXT_EXAMPLE", $this->lng->txt("cont_e_g_example"));
121 
122  $this->tpl->setVariable("DELETE_QUESTION", $this->lng->txt("cont_confirm_delete"));
123  }
124 
125  function showItl()
126  {
127  $this->tpl = new ilTemplate("tpl.wysiwyg_popup_itl.html",false,false,"Services/COPage");
128  $this->tpl->setVariable("LOCATION_STYLESHEET", ilUtil::getStyleSheetLocation() );
129  }
130 
131  function showFootnote()
132  {
133  global $ilCtrl;
134 
135  $this->tpl = new ilTemplate("tpl.wysiwyg_popup_footnote.html",false,false,"Services/COPage");
136  $this->tpl->setVariable("LOCATION_STYLESHEET", ilUtil::getStyleSheetLocation() );
137  $this->tpl->setVariable("LOCATION_CONTENT_STYLESHEET_HTMLAREA", ILIAS_HTTP_PATH."/Services/COPage/css/content.css" );
138  $this->tpl->setVariable("REF_ID", $_GET["ref_id"]);
139  $ilCtrl->setParameterByClass("ilpcparagraphgui", "ptype", "footnote");
140  $this->tpl->setVariable("FOOTNOTE_TARGET",
141  $ilCtrl->getLinkTargetByClass("ilpcparagraphgui", "popup"));
142 
143 
144  $this->tpl->setVariable("TXT_FOOTNOTES", $this->lng->txt("cont_title_footnotes"));
145  $this->tpl->setVariable("TXT_INSERT_NEW_FOOTNOTES", $this->lng->txt("cont_insert_new_footnote"));
146  $this->tpl->setVariable("BTN_SUBMIT", $this->lng->txt("save"));
147  $this->tpl->setVariable("BTN_CANCEL", $this->lng->txt("cancel"));
148 
149  $this->tpl->setVariable("DELETE_QUESTION", $this->lng->txt("cont_confirm_delete"));
150  $this->tpl->setVariable("BTN_DELETE", $this->lng->txt("delete"));
151 
152  }
153 
154 
155 
156  function showHeader()
157  {
158 
159  }
160 
161 
162  var $struct = array();
163  var $depth;
164  var $newXml;
165  function convertFromPost($content)
166  {
167 
168 
169  $content = str_replace("&nbsp;"," ",$content);
170  //vd(htmlspecialchars($content));
171 
172  $content = str_replace(" </span>","</span> ",$content);
173  $content = str_replace("<span class=\"ilc_Strong\"></span>","",$content);
174  $content = str_replace("<span class=\"ilc_Emph\"></span>","",$content);
175  $content = str_replace("<span class=\"ilc_Quotation\"></span>","",$content);
176  $content = str_replace("<span class=\"ilc_Comment\"></span>","",$content);
177 
178  $content = rawurlencode($content);
179  $content = str_replace("%3Cspan%20class%3D%22ilc_Strong%22%3E%20%3C%2Fspan%3E","%20",$content);
180  $content = str_replace("%3Cspan%20class%3D%22ilc_Emph%22%3E%20%3C%2Fspan%3E","%20",$content);
181  $content = str_replace("%3Cspan%20class%3D%22ilc_Quotation%22%3E%20%3C%2Fspan%3E","%20",$content);
182  $content = str_replace("%3Cspan%20class%3D%22ilc_Comment%22%3E%20%3C%2Fspan%3E","%20",$content);
183  $content = rawurldecode($content);
184 
185 
186  //echo(htmlspecialchars($content));
187 // echo "<p>";
188 // echo(rawurlencode($content));
189 
190  $content = str_replace("&","&amp;",$content);
191 
192  for($k=0;$k<2;$k++) {
193  $xml_parser = xml_parser_create("UTF-8");
194  xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, false);
195  xml_set_object($xml_parser,$this);
196  xml_set_element_handler($xml_parser, "startElement", "endElement");
197  xml_set_character_data_handler($xml_parser, "characterData");
198 
199  $xml_data = "<xml>".$content."</xml>";
200 
201  $this->depth = 0;
202  $this->struct = array();
203  $this->newXml = "";
204 
205  if (!xml_parse($xml_parser, $xml_data))
206  {
207  die(sprintf("XML error: %s at line %d", xml_error_string(xml_get_error_code($xml_parser)),xml_get_current_line_number($xml_parser)));
208  }
209  xml_parser_free($xml_parser);
210 
211  $this->newXml = str_replace("<xml>","",$this->newXml);
212  $this->newXml = str_replace("</xml>","",$this->newXml);
213 
214  $content = $this->newXml;
215 
216 
217  //echo htmlspecialchars($content)."<p>";
218  }
219  //echo htmlspecialchars($this->newXml);
220  //exit;
221 
222  $this->newXml = str_replace("[com][/com]","",$this->newXml);
223  $this->newXml = str_replace("[emp][/emp]","",$this->newXml);
224  $this->newXml = str_replace("[str][/str]","",$this->newXml);
225  $this->newXml = str_replace("[code][/code]","",$this->newXml);
226  $this->newXml = str_replace("[quot][/quot]","",$this->newXml);
227 
228  $this->newXml = str_replace("</p><p>","\n",$this->newXml);
229  $this->newXml = str_replace("<p>","",$this->newXml);
230  $this->newXml = str_replace("</p>","",$this->newXml);
231 
232  $this->newXml = str_replace("<p class=\"MsoNormal\">","\n",$this->newXml);
233  $this->newXml = str_replace("<p class=\"MsoNormal\" style=\"MARGIN: 0cm 0cm 0pt\">","\n",$this->newXml);
234 
235 
236  $this->newXml = str_replace("<Strong/>","",$this->newXml);
237  $this->newXml = str_replace("<Emph/>","",$this->newXml);
238 
239  $this->newXml = str_replace("<span>","",$this->newXml);
240  $this->newXml = str_replace("</span>","",$this->newXml);
241 
242  //vd(htmlspecialchars($this->newXml));
243 
244  return($this->newXml);
245  }
246 
247 
248 
249 
250  //{{{
251  function startElement($parser, $name, $attrs)
252  {
253  $new = array("name" => $name,
254  "attrs" => $attrs,
255  "convert" => "",
256  "convert2" => ""
257  );
258 
259  $new["convert"] = "<".$name;
260  if (is_array($attrs))
261  {
262  reset ($attrs);
263  while (list ($key, $val) = each ($attrs))
264  {
265  $new["convert"] .= " ".$key."=\"".$val."\"";
266  }
267  }
268  $new["convert"] .= ">";
269  $new["convert2"] = "</".$name.">";
270 
271 
272  if ($attrs["style"] == "font-style: italic;" || $name == "em")
273  {
274  $new["convert"] = "[emp]";
275  $new["convert2"] = "[/emp]";
276  }
277  if ($attrs["style"] == "font-weight: bold;" || $name == "strong")
278  {
279  $new["convert"] = "[str]";
280  $new["convert2"] = "[/str]";
281  }
282 
283  // alex changed
284  if ($attrs["class"] == "ilc_ExtLink")
285  {
286  $new["convert"] = "[xln url=\"".str_replace("&","&amp;",$attrs[url])."\"]";
287  $new["convert2"] = "[/xln]";
288  }
289 
290  if ($attrs["class"] == "ilc_IntLink")
291  {
292  reset ($attrs);
293  $N = "";
294  while (list ($key, $val) = each ($attrs))
295  {
296  if ($key!="class")
297  {
298  $N .= " ".$key."=\"".$val."\"";
299  }
300  }
301  $new["convert"] = "[iln".$N."]";
302  $new["convert2"] = "[/iln]";
303  }
304 
305  if ($attrs["class"] == "ilc_Strong")
306  {
307  $new["convert"] = "[str]";
308  $new["convert2"] = "[/str]";
309  }
310  if ($attrs["class"] == "ilc_Comment")
311  {
312  $new["convert"] = "[com]";
313  $new["convert2"] = "[/com]";
314  }
315  if ($attrs["class"] == "ilc_Emph")
316  {
317  $new["convert"] = "[emp]";
318  $new["convert2"] = "[/emp]";
319  }
320 
321  if ($attrs["class"] == "ilc_Quotation")
322  {
323  $new["convert"] = "[quot]";
324  $new["convert2"] = "[/quot]";
325  }
326 
327  if ($attrs["class"] == "footnote")
328  {
329  //vd($attrs);
330 
331  $fn1 = explode("|**#",stripslashes($_POST["footnotelist"]));
332  for ($i=0;$i<count($fn1);$i++)
333  {
334  // {{{
335  $fn2 = explode("|*#",$fn1[$i]);
336 
337  //echo htmlspecialchars(serialize($fn2[1]))."<p>";
338 
339  if($fn2[0] == $attrs["value"])
340  {
341  $new["convert"] = "[fn]".$fn2[1];
342  $new["convert2"] = "[/fn]";
343  break;
344  }
345 
346  // }}}
347  }
348 
349  }
350 
351  if ($name == "code") {
352  $new["convert"] = "[code]";
353  $new["convert2"] = "[/code]";
354  }
355 
356  //echo htmlspecialchars($new[convert]);
357 
358  $this->struct[$this->depth] = $new;
359  $this->depth++;
360 
361  if ($name!="br")
362  {
363  $this->newXml .= $new[convert];
364  }
365  else
366  {
367  $this->newXml .= "\n";
368  }
369 
370 // vd($name);
371 // vd($attrs);
372  }
373 
374  function characterData($parser, $data)
375  {
376 // vd($data);
377  //if ($data == "[1]") $data = "";
378  if (!stristr( $this->struct[$this->depth-1]["convert"], "[fn]" ))
379  {
380  $this->newXml .= $data;
381  }
382 
383  }
384 
385  function endElement($parser, $name)
386  {
387  $this->depth--;
388 
389  //$this->newXml .= "</".$name.">";
390  if ($name!="br")
391  {
392  $this->newXml .= $this->struct[$this->depth]["convert2"];
393  }
394 
395 // vd($name);
396  }
397  // }}}
398 
399 }
400 
401 ?>