ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilPCParagraph.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 require_once("./Services/COPage/classes/class.ilPageContent.php");
5 require_once("./Services/COPage/classes/class.ilWysiwygUtil.php");
6 
18 {
19  var $dom;
20  var $par_node; // node of Paragraph element
21 
25  function init()
26  {
27  $this->setType("par");
28  }
29 
35  function setNode(&$a_node)
36  {
37  parent::setNode($a_node); // this is the PageContent node
38 
39  $childs = $a_node->child_nodes();
40  for ($i=0; $i<count($childs); $i++)
41  {
42  if ($childs[$i]->node_name() == "Paragraph")
43  {
44  $this->par_node = $childs[$i]; //... and this the Paragraph node
45  }
46  }
47  }
48 
49 
55  function createAtNode(&$node)
56  {
57  $this->node = $this->createPageContentNode();
58  $this->par_node =& $this->dom->create_element("Paragraph");
59  $this->par_node =& $this->node->append_child($this->par_node);
60  $this->par_node->set_attribute("Language", "");
61  $node->append_child ($this->node);
62  }
63 
70  {
71  $this->node = $this->createPageContentNode();
72  $this->par_node =& $this->dom->create_element("Paragraph");
73  $this->par_node =& $this->node->append_child($this->par_node);
74  $this->par_node->set_attribute("Language", "");
75  $node->insert_before($this->node, $node);
76  }
77 
84  function createAfter($node)
85  {
86  $this->node = $this->createPageContentNode(false);
87  if($succ_node = $node->next_sibling())
88  {
89  $this->node = $succ_node->insert_before($this->node, $succ_node);
90  }
91  else
92  {
93  $parent_node = $node->parent_node();
94  $this->node = $parent_node->append_child($this->node);
95  }
96  $this->par_node = $this->dom->create_element("Paragraph");
97  $this->par_node = $this->node->append_child($this->par_node);
98  $this->par_node->set_attribute("Language", "");
99  }
100 
108  function create(&$a_pg_obj, $a_hier_id, $a_pc_id = "")
109  {
110 //echo "-$a_pc_id-";
111 //echo "<br>-".htmlentities($a_pg_obj->getXMLFromDom())."-<br><br>"; mk();
112  $this->node =& $this->dom->create_element("PageContent");
113 
114  // this next line kicks out placeholders, if something is inserted
115  $a_pg_obj->insertContent($this, $a_hier_id, IL_INSERT_AFTER, $a_pc_id);
116 
117  $this->par_node =& $this->dom->create_element("Paragraph");
118  $this->par_node =& $this->node->append_child($this->par_node);
119  $this->par_node->set_attribute("Language", "");
120  }
121 
128  function setText($a_text, $a_auto_split = false)
129  {
130 
131 //var_dump($a_text);
132  if (!is_array($a_text))
133  {
134  $text = array(array("level" => 0, "text" => $a_text));
135  }
136  else
137  {
138  $text = $a_text;
139  }
140 
141  if ($a_auto_split)
142  {
143  $text = $this->autoSplit($a_text);
144  }
145 
146  // DOMXML_LOAD_PARSING, DOMXML_LOAD_VALIDATING, DOMXML_LOAD_RECOVERING
147  $check = "";
148  foreach ($text as $t)
149  {
150  $check.= "<Paragraph>".$t["text"]."</Paragraph>";
151  }
152  /*$temp_dom = domxml_open_mem('<?xml version="1.0" encoding="UTF-8"?><Paragraph>'.$text[0]["text"].'</Paragraph>',
153  DOMXML_LOAD_PARSING, $error);*/
154  $temp_dom = domxml_open_mem('<?xml version="1.0" encoding="UTF-8"?><Paragraph>'.$check.'</Paragraph>',
155  DOMXML_LOAD_PARSING, $error);
156 
157  //$this->text = $a_text;
158  // remove all childs
159  if(empty($error))
160  {
161  $temp_dom = domxml_open_mem('<?xml version="1.0" encoding="UTF-8"?><Paragraph>'.$text[0]["text"].'</Paragraph>',
162  DOMXML_LOAD_PARSING, $error);
163 
164  // delete children of paragraph node
165  $children = $this->par_node->child_nodes();
166  for($i=0; $i<count($children); $i++)
167  {
168  $this->par_node->remove_child($children[$i]);
169  }
170 
171  // copy new content children in paragraph node
172  $xpc = xpath_new_context($temp_dom);
173  $path = "//Paragraph";
174  $res =& xpath_eval($xpc, $path);
175  if (count($res->nodeset) == 1)
176  {
177  $new_par_node =& $res->nodeset[0];
178  $new_childs = $new_par_node->child_nodes();
179 
180  for($i=0; $i<count($new_childs); $i++)
181  {
182  $cloned_child =& $new_childs[$i]->clone_node(true);
183  $this->par_node->append_child($cloned_child);
184  }
185  $orig_characteristic = $this->getCharacteristic();
186 
187  // if headlines are entered and current characteristic is a headline
188  // use no characteristic as standard
189  if ((count($text) > 1) && (substr($orig_characteristic, 0, 8) == "Headline"))
190  {
191  $orig_characteristic = "";
192  }
193  if ($text[0]["level"] > 0)
194  {
195  $this->par_node->set_attribute("Characteristic", 'Headline'.$text[0]["level"]);
196  }
197  }
198 
199  $ok = true;
200 
201  $c_node = $this->node;
202  // add other chunks afterwards
203  for ($i=1; $i<count($text); $i++)
204  {
205  if ($ok)
206  {
207  $next_par = new ilPCParagraph($this->dom);
208  $next_par->createAfter($c_node);
209  $next_par->setLanguage($this->getLanguage());
210  if ($text[$i]["level"] > 0)
211  {
212  $next_par->setCharacteristic("Headline".$text[$i]["level"]);
213  }
214  else
215  {
216  $next_par->setCharacteristic($orig_characteristic);
217  }
218  $ok = $next_par->setText($text[$i]["text"], false);
219  $c_node = $next_par->node;
220  }
221  }
222 
223  return true;
224  }
225  else
226  {
227  // We want the correct number of \n here to have the real lines numbers
228  $text = str_replace("<br>", "\n", $check); // replace <br> with \n to get correct line
229  $text = str_replace("<br/>", "\n", $text);
230  $text = str_replace("<br />", "\n", $text);
231  $text = str_replace("</SimpleListItem>", "</SimpleListItem>\n", $text);
232  $text = str_replace("<SimpleBulletList>", "\n<SimpleBulletList>", $text);
233  $text = str_replace("<SimpleNumberedList>", "\n<SimpleNumberedList>", $text);
234  $text = str_replace("<Paragraph>\n", "<Paragraph>", $text);
235  $text = str_replace("</Paragraph>", "</Paragraph>\n", $text);
236  include_once("./Services/Dom/classes/class.ilDomDocument.php");
237  $doc = new ilDOMDocument();
238  $text = '<?xml version="1.0" encoding="UTF-8"?><Paragraph>'.$text.'</Paragraph>';
239 //echo htmlentities($text);
240  $this->success = $doc->loadXML($text);
241  $error = $doc->errors;
242  $estr = "";
243  foreach ($error as $e)
244  {
245  $e = str_replace(" in Entity", "", $e);
246  $estr.= $e."<br />";
247  }
248  return $estr;
249  }
250  }
251 
257  function getText($a_short_mode = false)
258  {
259  if (is_object($this->par_node))
260  {
261  $content = "";
262  $childs = $this->par_node->child_nodes();
263  for($i=0; $i<count($childs); $i++)
264  {
265  $content .= $this->dom->dump_node($childs[$i]);
266  }
267  return $content;
268  }
269  else
270  {
271  return "";
272  }
273  }
274 
278  function getParagraphSequenceContent($a_pg_obj)
279  {
280  $childs = $this->par_node->parent_node()->parent_node()->child_nodes();
281  $seq = array();
282  $cur_seq = array();
283  $found = false;
284  $pc_id = $this->readPCId();
285  $hier_id = $this->readHierId();
286  for($i=0; $i<count($childs); $i++)
287  {
288  $pchilds = $childs[$i]->child_nodes();
289  if ($pchilds[0]->node_name() == "Paragraph" &&
290  $pchilds[0]->get_attribute("Characteristic") != "Code")
291  {
292  $cur_seq[] = $childs[$i];
293 
294  // check whether this is the sequence of the current paragraph
295  if ($childs[$i]->get_attribute("PCID") == $pc_id &&
296  $childs[$i]->get_attribute("HierId") == $hier_id)
297  {
298  $found = true;
299  }
300 
301  // if this is the current sequenc, get it
302  if ($found)
303  {
304  $seq = $cur_seq;
305  }
306  }
307  else
308  {
309  // non-paragraph element found -> init the current sequence
310  $cur_seq = array();
311  $found = false;
312  }
313  }
314 
315  $content = "";
316  $ids = "###";
317  $id_sep = "";
318  foreach ($seq as $p_node)
319  {
320  $ids.= $id_sep.$p_node->get_attribute("HierId").":".$p_node->get_attribute("PCID");
321  $po = $a_pg_obj->getContentObject($p_node->get_attribute("HierId"),
322  $p_node->get_attribute("PCID"));
323  $s_text = $po->getText();
324  $s_text = $po->xml2output($s_text, true, false);
325  $char = $po->getCharacteristic();
326  if ($char == "")
327  {
328  $char = "Standard";
329  }
330  $s_text = ilPCParagraphGUI::xml2outputJS($s_text, $char, $po->readPCId());
331  $content.= $s_text;
332  $id_sep = ";";
333  }
334  $ids.= "###";
335 
336  return $ids.$content;
337  }
338 
344  function setCharacteristic($a_char)
345  {
346  if (!empty($a_char))
347  {
348  $this->par_node->set_attribute("Characteristic", $a_char);
349  }
350  else
351  {
352  if ($this->par_node->has_attribute("Characteristic"))
353  {
354  $this->par_node->remove_attribute("Characteristic");
355  }
356  }
357  }
358 
364  function getCharacteristic()
365  {
366  if (is_object($this->par_node))
367  {
368  return $this->par_node->get_attribute("Characteristic");
369  }
370  }
371 
372 
376  function setSubCharacteristic($a_char)
377  {
378  if (!empty($a_char))
379  {
380  $this->par_node->set_attribute("SubCharacteristic", $a_char);
381  }
382  else
383  {
384  if ($this->par_node->has_attribute("SubCharacteristic"))
385  {
386  $this->par_node->remove_attribute("SubCharacteristic");
387  }
388  }
389  }
390 
396  function getAutoIndent()
397  {
398  return $this->par_node->get_attribute("AutoIndent");
399  }
400 
401  function setAutoIndent($a_char)
402  {
403  if (!empty($a_char))
404  {
405  $this->par_node->set_attribute("AutoIndent", $a_char);
406  }
407  else
408  {
409  if ($this->par_node->has_attribute("AutoIndent"))
410  {
411  $this->par_node->remove_attribute("AutoIndent");
412  }
413  }
414  }
415 
420  {
421  return $this->par_node->get_attribute("SubCharacteristic");
422  }
423 
428  function setDownloadTitle($a_char)
429  {
430  if (!empty($a_char))
431  {
432  $this->par_node->set_attribute("DownloadTitle", $a_char);
433  }
434  else
435  {
436  if ($this->par_node->has_attribute("DownloadTitle"))
437  {
438  $this->par_node->remove_attribute("DownloadTitle");
439  }
440  }
441  }
442 
446  function getDownloadTitle()
447  {
448  return $this->par_node->get_attribute("DownloadTitle");
449  }
450 
455  function setShowLineNumbers($a_char)
456  {
457  $a_char = empty($a_char)?"n":$a_char;
458 
459  $this->par_node->set_attribute("ShowLineNumbers", $a_char);
460  }
461 
467  {
468  return $this->par_node->get_attribute("ShowLineNumbers");
469  }
470 
474  function setLanguage($a_lang)
475  {
476  $this->par_node->set_attribute("Language", $a_lang);
477  }
478 
482  function getLanguage()
483  {
484  return $this->par_node->get_attribute("Language");
485  }
486 
487  function input2xml($a_text, $a_wysiwyg = 0, $a_handle_lists = true)
488  {
489  return $this->_input2xml($a_text, $this->getLanguage(), $a_wysiwyg, $a_handle_lists);
490  }
491 
495  static function _input2xml($a_text, $a_lang, $a_wysiwyg = 0, $a_handle_lists = true)
496  {
497  if (!$a_wysiwyg)
498  {
499  $a_text = ilUtil::stripSlashes($a_text, false);
500  }
501 
502  if ($a_wysiwyg)
503  {
504  $a_text = str_replace("<br />", chr(10), $a_text);
505  }
506 
507  // note: the order of the processing steps is crucial
508  // and should be the same as in xml2output() in REVERSE order!
509  $a_text = trim($a_text);
510 
511 //echo "<br>between:".htmlentities($a_text);
512 
513  // mask html
514 if (!$a_wysiwyg)
515 {
516  $a_text = str_replace("&","&amp;",$a_text);
517 }
518  $a_text = str_replace("<","&lt;",$a_text);
519  $a_text = str_replace(">","&gt;",$a_text);
520 
521  // Reconvert PageTurn and BibItemIdentifier
522  $a_text = preg_replace('/&lt;([\s\/]*?PageTurn.*?)&gt;/i',"<$1>",$a_text);
523  $a_text = preg_replace('/&lt;([\s\/]*?BibItemIdentifier.*?)&gt;/i',"<$1>",$a_text);
524 
525 //echo "<br>second:".htmlentities($a_text);
526 
527  // mask curly brackets
528 /*
529 echo htmlentities($a_text);
530  $a_text = str_replace("{", "&#123;", $a_text);
531  $a_text = str_replace("}", "&#125;", $a_text);
532 echo htmlentities($a_text);*/
533  // linefeed to br
534  $a_text = str_replace(chr(13).chr(10),"<br />",$a_text);
535  $a_text = str_replace(chr(13),"<br />", $a_text);
536  $a_text = str_replace(chr(10),"<br />", $a_text);
537 
538  if ($a_handle_lists)
539  {
540  $a_text = ilPCParagraph::input2xmlReplaceLists($a_text);
541  }
542 
543  // remove empty tags
544  $atags = array("com", "emp", "str", "fn", "quot", "code", "acc", "imp", "kw");
545  foreach ($atags as $at)
546  {
547  $a_text = str_replace("[".$at."][/".$at."]", "", $a_text);
548  }
549 
550  // bb code to xml
551  $a_text = eregi_replace("\[com\]","<Comment Language=\"".$a_lang."\">",$a_text);
552  $a_text = eregi_replace("\[\/com\]","</Comment>",$a_text);
553  $a_text = eregi_replace("\[emp\]","<Emph>",$a_text);
554  $a_text = eregi_replace("\[\/emp\]","</Emph>",$a_text);
555  $a_text = eregi_replace("\[str\]","<Strong>",$a_text);
556  $a_text = eregi_replace("\[\/str\]","</Strong>",$a_text);
557  $a_text = eregi_replace("\[fn\]","<Footnote>",$a_text);
558  $a_text = eregi_replace("\[\/fn\]","</Footnote>",$a_text);
559  $a_text = eregi_replace("\[quot\]","<Quotation Language=\"".$a_lang."\">",$a_text);
560  $a_text = eregi_replace("\[\/quot\]","</Quotation>",$a_text);
561  $a_text = eregi_replace("\[code\]","<Code>",$a_text);
562  $a_text = eregi_replace("\[\/code\]","</Code>",$a_text);
563  $a_text = eregi_replace("\[acc\]","<Accent>",$a_text);
564  $a_text = eregi_replace("\[\/acc\]","</Accent>",$a_text);
565  $a_text = eregi_replace("\[imp\]","<Important>",$a_text);
566  $a_text = eregi_replace("\[\/imp\]","</Important>",$a_text);
567  $a_text = eregi_replace("\[kw\]","<Keyw>",$a_text);
568  $a_text = eregi_replace("\[\/kw\]","</Keyw>",$a_text);
569 
570  // internal links
571  //$any = "[^\]]*"; // this doesn't work :-(
572  $ws= "[ \t\r\f\v\n]*";
573  $ltypes = "page|chap|term|media|htlm|lm|dbk|glo|frm|exc|tst|svy|webr|chat|cat|crs|grp|file|fold|mep|wiki|sahs|mcst|obj|dfile";
574  // empty internal links
575  while (eregi("\[(iln$ws((inst$ws=$ws([\"0-9])*)?$ws".
576  "((".$ltypes.")$ws=$ws([\"0-9])*)$ws".
577  "(target$ws=$ws(\"(New|FAQ|Media)\"))?$ws(anchor$ws=$ws(\"([^\"])*\"))?$ws))\]\[\/iln\]", $a_text, $found))
578  {
579  $a_text = str_replace($found[0], "",$a_text);
580  }
581 
582  while (eregi("\[(iln$ws((inst$ws=$ws([\"0-9])*)?$ws".
583  "((".$ltypes.")$ws=$ws([\"0-9])*)$ws".
584  "(target$ws=$ws(\"(New|FAQ|Media)\"))?$ws(anchor$ws=$ws(\"([^\"])*\"))?$ws))\]", $a_text, $found))
585  {
586  $attribs = ilUtil::attribsToArray($found[2]);
587  $inst_str = $attribs["inst"];
588  // pages
589  if (isset($attribs["page"]))
590  {
591  $tframestr = "";
592  if (!empty($found[10]))
593  {
594  $tframestr = " TargetFrame=\"".$found[10]."\" ";
595  }
596  $ancstr = "";
597  if ($attribs["anchor"] != "")
598  {
599  $ancstr = ' Anchor="'.$attribs["anchor"].'" ';
600  }
601  $a_text = eregi_replace("\[".$found[1]."\]",
602  "<IntLink Target=\"il_".$inst_str."_pg_".$attribs[page]."\" Type=\"PageObject\"".$tframestr.$ancstr.">", $a_text);
603  }
604  // chapters
605  else if (isset($attribs["chap"]))
606  {
607  if (!empty($found[10]))
608  {
609  $tframestr = " TargetFrame=\"".$found[10]."\" ";
610  }
611  else
612  {
613  $tframestr = "";
614  }
615  $a_text = eregi_replace("\[".$found[1]."\]",
616  "<IntLink Target=\"il_".$inst_str."_st_".$attribs[chap]."\" Type=\"StructureObject\"".$tframestr.">", $a_text);
617  }
618  // glossary terms
619  else if (isset($attribs["term"]))
620  {
621  switch ($found[10])
622  {
623  case "New":
624  $tframestr = " TargetFrame=\"New\" ";
625  break;
626 
627  default:
628  $tframestr = " TargetFrame=\"Glossary\" ";
629  break;
630  }
631  $a_text = eregi_replace("\[".$found[1]."\]",
632  "<IntLink Target=\"il_".$inst_str."_git_".$attribs[term]."\" Type=\"GlossaryItem\" $tframestr>", $a_text);
633  }
634  // media object
635  else if (isset($attribs["media"]))
636  {
637  if (!empty($found[10]))
638  {
639  $tframestr = " TargetFrame=\"".$found[10]."\" ";
640  $a_text = eregi_replace("\[".$found[1]."\]",
641  "<IntLink Target=\"il_".$inst_str."_mob_".$attribs[media]."\" Type=\"MediaObject\"".$tframestr.">", $a_text);
642  }
643  else
644  {
645  $a_text = eregi_replace("\[".$found[1]."\]",
646  "<IntLink Target=\"il_".$inst_str."_mob_".$attribs[media]."\" Type=\"MediaObject\"/>", $a_text);
647  }
648  }
649  // direct download file (no repository object)
650  else if (isset($attribs["dfile"]))
651  {
652  $a_text = eregi_replace("\[".$found[1]."\]",
653  "<IntLink Target=\"il_".$inst_str."_dfile_".$attribs[dfile]."\" Type=\"File\">", $a_text);
654  }
655  // repository items (id is ref_id (will be used internally but will
656  // be replaced by object id for export purposes)
657  else if (isset($attribs["lm"]) || isset($attribs["dbk"]) || isset($attribs["glo"])
658  || isset($attribs["frm"]) || isset($attribs["exc"]) || isset($attribs["tst"])
659  || isset($attribs["svy"]) || isset($attribs["obj"]) || isset($attribs['webr'])
660  || isset($attribs["htlm"]) || isset($attribs["chat"]) || isset($attribs["grp"])
661  || isset($attribs["fold"]) || isset($attribs["sahs"]) || isset($attribs["mcst"])
662  || isset($attribs["mep"]) || isset($attribs["wiki"])
663  || isset($attribs["cat"]) || isset($attribs["crs"]) || isset($attribs["file"]))
664  {
665  $obj_id = (isset($attribs["lm"])) ? $attribs["lm"] : $obj_id;
666  $obj_id = (isset($attribs["dbk"])) ? $attribs["dbk"] : $obj_id;
667  $obj_id = (isset($attribs["chat"])) ? $attribs["chat"] : $obj_id;
668  $obj_id = (isset($attribs["glo"])) ? $attribs["glo"] : $obj_id;
669  $obj_id = (isset($attribs["frm"])) ? $attribs["frm"] : $obj_id;
670  $obj_id = (isset($attribs["exc"])) ? $attribs["exc"] : $obj_id;
671  $obj_id = (isset($attribs["htlm"])) ? $attribs["htlm"] : $obj_id;
672  $obj_id = (isset($attribs["tst"])) ? $attribs["tst"] : $obj_id;
673  $obj_id = (isset($attribs["svy"])) ? $attribs["svy"] : $obj_id;
674  $obj_id = (isset($attribs["obj"])) ? $attribs["obj"] : $obj_id;
675  $obj_id = (isset($attribs["webr"])) ? $attribs["webr"] : $obj_id;
676  $obj_id = (isset($attribs["fold"])) ? $attribs["fold"] : $obj_id;
677  $obj_id = (isset($attribs["cat"])) ? $attribs["cat"] : $obj_id;
678  $obj_id = (isset($attribs["crs"])) ? $attribs["crs"] : $obj_id;
679  $obj_id = (isset($attribs["grp"])) ? $attribs["grp"] : $obj_id;
680  $obj_id = (isset($attribs["file"])) ? $attribs["file"] : $obj_id;
681  $obj_id = (isset($attribs["sahs"])) ? $attribs["sahs"] : $obj_id;
682  $obj_id = (isset($attribs["mcst"])) ? $attribs["mcst"] : $obj_id;
683  $obj_id = (isset($attribs["mep"])) ? $attribs["mep"] : $obj_id;
684  $obj_id = (isset($attribs["wiki"])) ? $attribs["wiki"] : $obj_id;
685  //$obj_id = (isset($attribs["obj"])) ? $attribs["obj"] : $obj_id;
686 
687  if ($inst_str == "")
688  {
689  $a_text = eregi_replace("\[".$found[1]."\]",
690  "<IntLink Target=\"il_".$inst_str."_obj_".$obj_id."\" Type=\"RepositoryItem\">", $a_text);
691  }
692  else
693  {
694  $a_text = eregi_replace("\[".$found[1]."\]",
695  "<IntLink Target=\"il_".$inst_str."_".$found[6]."_".$obj_id."\" Type=\"RepositoryItem\">", $a_text);
696  }
697  }
698  else
699  {
700  $a_text = eregi_replace("\[".$found[1]."\]", "[error: iln".$found[1]."]",$a_text);
701  }
702  }
703  while (eregi("\[(iln$ws((inst$ws=$ws([\"0-9])*)?".$ws."media$ws=$ws([\"0-9])*)$ws)/\]", $a_text, $found))
704  {
705  $attribs = ilUtil::attribsToArray($found[2]);
706  $inst_str = $attribs["inst"];
707  $a_text = eregi_replace("\[".$found[1]."/\]",
708  "<IntLink Target=\"il_".$inst_str."_mob_".$attribs[media]."\" Type=\"MediaObject\"/>", $a_text);
709  }
710  $a_text = eregi_replace("\[\/iln\]","</IntLink>",$a_text);
711 
712  // external link
713  $ws= "[ \t\r\f\v\n]*";
714  // remove empty external links
715  while (eregi("\[(xln$ws(url$ws=$ws\"([^\"])*\")$ws(target$ws=$ws(\"(Glossary|FAQ|Media)\"))?$ws)\]\[\/xln\]", $a_text, $found))
716  {
717  $a_text = str_replace($found[0], "",$a_text);
718  }
719  while (eregi("\[(xln$ws(url$ws=$ws(([^]])*)))$ws\]\[\/xln\]", $a_text, $found))
720  {
721  $a_text = str_replace($found[0], "",$a_text);
722  }
723  // external links
724  while (eregi("\[(xln$ws(url$ws=$ws\"([^\"])*\")$ws(target$ws=$ws(\"(Glossary|FAQ|Media)\"))?$ws)\]", $a_text, $found))
725  {
726  $attribs = ilUtil::attribsToArray($found[2]);
727  if (isset($attribs["url"]))
728  {
729  $a2 = ilUtil::attribsToArray($found[4]);
730  $tstr = "";
731  if (in_array($a2["target"], array("FAQ", "Glossary", "Media")))
732  {
733  $tstr = ' TargetFrame="'.$a2["target"].'"';
734  }
735  $a_text = str_replace("[".$found[1]."]", "<ExtLink Href=\"".$attribs["url"]."\"$tstr>", $a_text);
736  }
737  else
738  {
739  $a_text = str_replace("[".$found[1]."]", "[error: xln".$found[1]."]",$a_text);
740  }
741  }
742 
743  // ie/tinymce fix for links without "", see bug #8391
744  while (eregi("\[(xln$ws(url$ws=$ws(([^]])*)))$ws\]", $a_text, $found))
745  {
746  if ($found[3] != "")
747  {
748  $a_text = str_replace("[".$found[1]."]", "<ExtLink Href=\"".$found[3]."\">", $a_text);
749  }
750  else
751  {
752  $a_text = str_replace("[".$found[1]."]", "[error: xln".$found[1]."]",$a_text);
753  }
754  }
755  $a_text = eregi_replace("\[\/xln\]","</ExtLink>",$a_text);
756 
757  // anchor
758  $ws= "[ \t\r\f\v\n]*";
759  while (eregi("\[(anc$ws(name$ws=$ws\"([^\"])*\")$ws)\]", $a_text, $found))
760  {
761  $attribs = ilUtil::attribsToArray($found[2]);
762  $a_text = str_replace("[".$found[1]."]", "<Anchor Name=\"".$attribs["name"]."\">", $a_text);
763  }
764  $a_text = eregi_replace("\[\/anc\]","</Anchor>",$a_text);
765 //echo htmlentities($a_text); exit;
766  return $a_text;
767  }
768 
776  static function input2xmlReplaceLists($a_text)
777  {
778  $rows = explode("<br />", $a_text."<br />");
779 //var_dump($a_text);
780 
781  $old_level = 0;
782 
783  $text = "";
784 
785  foreach ($rows as $row)
786  {
787  $level = 0;
788  if (str_replace("#", "*", substr($row, 0, 3)) == "***")
789  {
790  $level = 3;
791  }
792  else if (str_replace("#", "*", substr($row, 0, 2)) == "**")
793  {
794  $level = 2;
795  }
796  else if (str_replace("#", "*", substr($row, 0, 1)) == "*")
797  {
798  $level = 1;
799  }
800 
801  // end previous line
802  if ($level < $old_level)
803  {
804  for ($i = $old_level; $i > $level; $i--)
805  {
806  $text.= "</SimpleListItem></".$clist[$i].">";
807  }
808  if ($level > 0)
809  {
810  $text.= "</SimpleListItem>";
811  }
812  }
813  else if ($old_level > 0 && $level > 0 && ($level == $old_level))
814  {
815  $text.= "</SimpleListItem>";
816  }
817  else if (($level == $old_level) && $text != "")
818  {
819  $text.= "<br />";
820  }
821 
822  // start next line
823  if ($level > $old_level)
824  {
825  for($i = $old_level + 1; $i <= $level; $i++)
826  {
827  if (substr($row, $i - 1, 1) == "*")
828  {
829  $clist[$i] = "SimpleBulletList";
830  }
831  else
832  {
833  $clist[$i] = "SimpleNumberedList";
834  }
835  $text.= "<".$clist[$i]."><SimpleListItem>";
836  }
837  }
838  else if ($old_level > 0 && $level > 0)
839  {
840  $text.= "<SimpleListItem>";
841  }
842  $text.= substr($row, $level);
843 
844  $old_level = $level;
845  }
846 
847  // remove "<br />" at the end
848  if (substr($text, strlen($text) - 6) == "<br />")
849  {
850  $text = substr($text, 0, strlen($text) - 6);
851  }
852 
853  return $text;
854  }
855 
863  static function xml2outputReplaceLists($a_text)
864  {
865  $segments = ilPCParagraph::segmentString($a_text, array("<SimpleBulletList>", "</SimpleBulletList>",
866  "</SimpleListItem>", "<SimpleListItem>", "<SimpleListItem/>", "<SimpleNumberedList>", "</SimpleNumberedList>"));
867 
868  $current_list = array();
869  $text = "";
870  for ($i=0; $i<= count($segments); $i++)
871  {
872  if ($segments[$i] == "<SimpleBulletList>")
873  {
874  if (count($current_list) == 0)
875  {
876  $list_start = true;
877  }
878  array_push($current_list, "*");
879  $li = false;
880  }
881  else if ($segments[$i] == "<SimpleNumberedList>")
882  {
883  if (count($current_list) == 0)
884  {
885  $list_start = true;
886  }
887  array_push($current_list, "#");
888  $li = false;
889  }
890  else if ($segments[$i] == "</SimpleBulletList>")
891  {
892  array_pop($current_list);
893  $li = false;
894  }
895  else if ($segments[$i] == "</SimpleNumberedList>")
896  {
897  array_pop($current_list);
898  $li = false;
899  }
900  else if ($segments[$i] == "<SimpleListItem>")
901  {
902  $li = true;
903  }
904  else if ($segments[$i] == "</SimpleListItem>")
905  {
906  $li = false;
907  }
908  else if ($segments[$i] == "<SimpleListItem/>")
909  {
910  if ($list_start)
911  {
912  $text.= "<br />";
913  $list_start = false;
914  }
915  foreach($current_list as $list)
916  {
917  $text.= $list;
918  }
919  $text.= "<br />";
920  $li = false;
921  }
922  else
923  {
924  if ($li)
925  {
926  if ($list_start)
927  {
928  $text.= "<br />";
929  $list_start = false;
930  }
931  foreach($current_list as $list)
932  {
933  $text.= $list;
934  }
935  }
936  $text.= $segments[$i];
937  if ($li)
938  {
939  $text.= "<br />";
940  }
941  $li = false;
942  }
943  }
944 
945  // remove trailing <br />, if text ends with list
946  if ($segments[count($segments) - 1] == "</SimpleBulletList>" ||
947  $segments[count($segments) - 1] == "</SimpleNumberedList>" &&
948  substr($text, strlen($text) - 6) == "<br />")
949  {
950  $text = substr($text, 0, strlen($text) - 6);
951  }
952 
953  return $text;
954  }
955 
959  static function segmentString($a_haystack, $a_needles)
960  {
961  $segments = array();
962 
963  $nothing_found = false;
964  while (!$nothing_found)
965  {
966  $nothing_found = true;
967  $found = -1;
968  foreach($a_needles as $needle)
969  {
970  $pos = stripos($a_haystack, $needle);
971  if (is_int($pos) && ($pos < $found || $found == -1))
972  {
973  $found = $pos;
974  $found_needle = $needle;
975  $nothing_found = false;
976  }
977  }
978  if ($found > 0)
979  {
980  $segments[] = substr($a_haystack, 0, $found);
981  $a_haystack = substr($a_haystack, $found);
982  }
983  if ($found > -1)
984  {
985  $segments[] = substr($a_haystack, 0, strlen($found_needle));
986  $a_haystack = substr($a_haystack, strlen($found_needle));
987  }
988  }
989  if ($a_haystack != "")
990  {
991  $segments[] = $a_haystack;
992  }
993 
994  return $segments;
995  }
996 
1004  static function xml2output($a_text, $a_wysiwyg = false, $a_replace_lists = true)
1005  {
1006  // note: the order of the processing steps is crucial
1007  // and should be the same as in input2xml() in REVERSE order!
1008 
1009  // xml to bb code
1010  $any = "[^>]*";
1011  $a_text = eregi_replace("<Comment[^>]*>","[com]",$a_text);
1012  $a_text = eregi_replace("</Comment>","[/com]",$a_text);
1013  $a_text = eregi_replace("<Comment/>","[com][/com]",$a_text);
1014  $a_text = eregi_replace("<Emph>","[emp]",$a_text);
1015  $a_text = eregi_replace("</Emph>","[/emp]",$a_text);
1016  $a_text = eregi_replace("<Emph/>","[emp][/emp]",$a_text);
1017  $a_text = eregi_replace("<Strong>","[str]",$a_text);
1018  $a_text = eregi_replace("</Strong>","[/str]",$a_text);
1019  $a_text = eregi_replace("<Strong/>","[str][/str]",$a_text);
1020  $a_text = eregi_replace("<Footnote[^>]*>","[fn]",$a_text);
1021  $a_text = eregi_replace("</Footnote>","[/fn]",$a_text);
1022  $a_text = eregi_replace("<Footnote/>","[fn][/fn]",$a_text);
1023  $a_text = eregi_replace("<Quotation[^>]*>","[quot]",$a_text);
1024  $a_text = eregi_replace("</Quotation>","[/quot]",$a_text);
1025  $a_text = eregi_replace("<Quotation/>","[quot][/quot]",$a_text);
1026  $a_text = eregi_replace("<Code[^>]*>","[code]",$a_text);
1027  $a_text = eregi_replace("</Code>","[/code]",$a_text);
1028  $a_text = eregi_replace("<Code/>","[code][/code]",$a_text);
1029  $a_text = eregi_replace("<Accent>","[acc]",$a_text);
1030  $a_text = eregi_replace("</Accent>","[/acc]",$a_text);
1031  $a_text = eregi_replace("<Important>","[imp]",$a_text);
1032  $a_text = eregi_replace("</Important>","[/imp]",$a_text);
1033  $a_text = eregi_replace("<Keyw>","[kw]",$a_text);
1034  $a_text = eregi_replace("</Keyw>","[/kw]",$a_text);
1035 
1036  // replace lists
1037  if ($a_replace_lists)
1038  {
1039 //echo "<br>".htmlentities($a_text);
1040  $a_text = ilPCParagraph::xml2outputReplaceLists($a_text);
1041 //echo "<br>".htmlentities($a_text);
1042  }
1043 
1044  // internal links
1045  while (eregi("<IntLink($any)>", $a_text, $found))
1046  {
1047  $found[0];
1048  $attribs = ilUtil::attribsToArray($found[1]);
1049  $target = explode("_", $attribs["Target"]);
1050  $target_id = $target[count($target) - 1];
1051  $inst_str = (!is_int(strpos($attribs["Target"], "__")))
1052  ? $inst_str = "inst=\"".$target[1]."\" "
1053  : $inst_str = "";
1054  switch($attribs["Type"])
1055  {
1056  case "PageObject":
1057  $tframestr = (!empty($attribs["TargetFrame"]))
1058  ? " target=\"".$attribs["TargetFrame"]."\""
1059  : "";
1060  $ancstr = (!empty($attribs["Anchor"]))
1061  ? ' anchor="'.$attribs["Anchor"].'"'
1062  : "";
1063  $a_text = eregi_replace("<IntLink".$found[1].">","[iln ".$inst_str."page=\"".$target_id."\"$tframestr$ancstr]",$a_text);
1064  break;
1065 
1066  case "StructureObject":
1067  $tframestr = (!empty($attribs["TargetFrame"]))
1068  ? " target=\"".$attribs["TargetFrame"]."\""
1069  : "";
1070  $a_text = eregi_replace("<IntLink".$found[1].">","[iln ".$inst_str."chap=\"".$target_id."\"$tframestr]",$a_text);
1071  break;
1072 
1073  case "GlossaryItem":
1074  $tframestr = (empty($attribs["TargetFrame"]) || $attribs["TargetFrame"] == "Glossary")
1075  ? ""
1076  : " target=\"".$attribs["TargetFrame"]."\"";
1077  $a_text = eregi_replace("<IntLink".$found[1].">","[iln ".$inst_str."term=\"".$target_id."\"".$tframestr."]",$a_text);
1078  break;
1079 
1080  case "MediaObject":
1081  if (empty($attribs["TargetFrame"]))
1082  {
1083  $a_text = eregi_replace("<IntLink".$found[1].">","[iln ".$inst_str."media=\"".$target_id."\"/]",$a_text);
1084  }
1085  else
1086  {
1087  $a_text = eregi_replace("<IntLink".$found[1].">","[iln media=\"".$target_id."\"".
1088  " target=\"".$attribs["TargetFrame"]."\"]",$a_text);
1089  }
1090  break;
1091 
1092  // Repository Item (using ref id)
1093  case "RepositoryItem":
1094  if ($inst_str == "")
1095  {
1097  }
1098  else
1099  {
1100  $rtype = $target[count($target) - 2];
1101  $target_type = $rtype;
1102  }
1103  $a_text = eregi_replace("<IntLink".$found[1].">","[iln ".$inst_str."$target_type=\"".$target_id."\"".$tframestr."]",$a_text);
1104  break;
1105 
1106  // Download File (not in repository, Object ID)
1107  case "File":
1108  $a_text = eregi_replace("<IntLink".$found[1].">","[iln ".$inst_str."dfile=\"".$target_id."\"".$tframestr."]",$a_text);
1109  break;
1110 
1111  default:
1112  $a_text = eregi_replace("<IntLink".$found[1].">","[iln]",$a_text);
1113  break;
1114  }
1115  }
1116  $a_text = eregi_replace("</IntLink>","[/iln]",$a_text);
1117 
1118  // external links
1119  while (eregi("<ExtLink($any)>", $a_text, $found))
1120  {
1121  $found[0];
1122  $attribs = ilUtil::attribsToArray($found[1]);
1123  //$found[1] = str_replace("?", "\?", $found[1]);
1124  $tstr = "";
1125  if (in_array($attribs["TargetFrame"], array("FAQ", "Glossary", "Media")))
1126  {
1127  $tstr = ' target="'.$attribs["TargetFrame"].'"';
1128  }
1129  $a_text = str_replace("<ExtLink".$found[1].">","[xln url=\"".$attribs["Href"]."\"$tstr]",$a_text);
1130  }
1131  $a_text = eregi_replace("</ExtLink>","[/xln]",$a_text);
1132 
1133  // anchor
1134  while (eregi("<Anchor($any)>", $a_text, $found))
1135  {
1136  $found[0];
1137  $attribs = ilUtil::attribsToArray($found[1]);
1138  $a_text = str_replace("<Anchor".$found[1].">","[anc name=\"".$attribs["Name"]."\"]",$a_text);
1139  }
1140  $a_text = eregi_replace("</Anchor>","[/anc]",$a_text);
1141 
1142 
1143  // br to linefeed
1144  if (!$a_wysiwyg)
1145  {
1146  $a_text = str_replace("<br />", "\n", $a_text);
1147  $a_text = str_replace("<br/>", "\n", $a_text);
1148  }
1149 
1150 if (!$a_wysiwyg)
1151 {
1152  // prevent curly brackets from being swallowed up by template engine
1153  $a_text = str_replace("{", "&#123;", $a_text);
1154  $a_text = str_replace("}", "&#125;", $a_text);
1155 
1156  // unmask html
1157  $a_text = str_replace("&lt;", "<", $a_text);
1158  $a_text = str_replace("&gt;", ">",$a_text);
1159 
1160  // this is needed to allow html like <tag attribute="value">... in paragraphs
1161  $a_text = str_replace("&quot;", "\"", $a_text);
1162 
1163  // make ampersands in (enabled) html attributes work
1164  // e.g. <a href="foo.php?n=4&t=5">hhh</a>
1165  $a_text = str_replace("&amp;", "&", $a_text);
1166 
1167  // make &gt; and $lt; work to allow (disabled) html descriptions
1168  $a_text = str_replace("&lt;", "&amp;lt;", $a_text);
1169  $a_text = str_replace("&gt;", "&amp;gt;", $a_text);
1170 }
1171  return $a_text;
1172  //return str_replace("<br />", chr(13).chr(10), $a_text);
1173  }
1174 
1181  function autoSplit($a_text)
1182  {
1183  $a_text = str_replace ("=<SimpleBulletList>", "=<br /><SimpleBulletList>", $a_text);
1184  $a_text = str_replace ("=<SimpleNumberedList>", "=<br /><SimpleNumberedList>", $a_text);
1185  $a_text = str_replace ("</SimpleBulletList>=", "</SimpleBulletList><br />=", $a_text);
1186  $a_text = str_replace ("</SimpleNumberedList>=", "</SimpleNumberedList><br />=", $a_text);
1187  $a_text = "<br />".$a_text."<br />"; // add preceding and trailing br
1188 
1189  $chunks = array();
1190  $c_text = $a_text;
1191 //echo "0";
1192  while ($c_text != "")
1193  {
1194 //var_dump($c_text); flush();
1195 //echo "1";
1196  $s1 = strpos($c_text, "<br />=");
1197  if (is_int($s1))
1198  {
1199 //echo "2";
1200  $s2 = strpos($c_text, "<br />==");
1201  if (is_int($s2) && $s2 <= $s1)
1202  {
1203 //echo "3";
1204  $s3 = strpos($c_text, "<br />===");
1205  if (is_int($s3) && $s3 <= $s2) // possible level three header
1206  {
1207 //echo "4";
1208  $n = strpos($c_text, "<br />", $s3 + 1);
1209  if ($n > ($s3+9) && substr($c_text, $n-3, 9) == "===<br />")
1210  {
1211 //echo "5";
1212  // found level three header
1213  if ($s3 > 0 || $head != "")
1214  {
1215 //echo "6";
1216  $chunks[] = array("level" => 0,
1217  "text" => $this->removeTrailingBr($head.substr($c_text, 0, $s3)));
1218  $head = "";
1219  }
1220  $chunks[] = array("level" => 3,
1221  "text" => trim(substr($c_text, $s3+9, $n-$s3-12)));
1222  $c_text = $this->handleNextBr(substr($c_text, $n+6));
1223  }
1224  else
1225  {
1226 //echo "7";
1227  $head.= substr($c_text, 0, $n);
1228  $c_text = substr($c_text, $n);
1229  }
1230  }
1231  else // possible level two header
1232  {
1233 //echo "8";
1234  $n = strpos($c_text, "<br />", $s2 + 1);
1235  if ($n > ($s2+8) && substr($c_text, $n-2, 8) == "==<br />")
1236  {
1237 //echo "9";
1238  // found level two header
1239  if ($s2 > 0 || $head != "")
1240  {
1241 //echo "A";
1242  $chunks[] = array("level" => 0,
1243  "text" => $this->removeTrailingBr($head.substr($c_text, 0, $s2)));
1244  $head = "";
1245  }
1246  $chunks[] = array("level" => 2, "text" => trim(substr($c_text, $s2+8, $n-$s2-10)));
1247  $c_text = $this->handleNextBr(substr($c_text, $n+6));
1248  }
1249  else
1250  {
1251 //echo "B";
1252  $head.= substr($c_text, 0, $n);
1253  $c_text = substr($c_text, $n);
1254  }
1255  }
1256  }
1257  else // possible level one header
1258  {
1259 //echo "C";
1260  $n = strpos($c_text, "<br />", $s1 + 1);
1261  if ($n > ($s1+7) && substr($c_text, $n-1, 7) == "=<br />")
1262  {
1263 //echo "D";
1264  // found level one header
1265  if ($s1 > 0 || $head != "")
1266  {
1267 //echo "E";
1268  $chunks[] = array("level" => 0,
1269  "text" => $this->removeTrailingBr($head.substr($c_text, 0, $s1)));
1270  $head = "";
1271  }
1272  $chunks[] = array("level" => 1, "text" => trim(substr($c_text, $s1+7, $n-$s1-8)));
1273  $c_text = $this->handleNextBr(substr($c_text, $n+6));
1274 //echo "<br>ctext:".htmlentities($c_text)."<br>";
1275  }
1276  else
1277  {
1278  $head.= substr($c_text, 0, $n);
1279  $c_text = substr($c_text, $n);
1280 //echo "<br>head:".$head."c_text:".$c_text."<br>";
1281  }
1282  }
1283  }
1284  else
1285  {
1286 //echo "G";
1287  $chunks[] = array("level" => 0, "text" => $head.$c_text);
1288  $head = "";
1289  $c_text = "";
1290  }
1291  }
1292  if (count($chunks) == 0)
1293  {
1294  $chunks[] = array("level" => 0, "text" => "");
1295  }
1296 
1297 
1298  // remove preceding br
1299  if (substr($chunks[0]["text"], 0, 6) == "<br />")
1300  {
1301  $chunks[0]["text"] = substr($chunks[0]["text"], 6);
1302  }
1303 
1304  // remove trailing br
1305  if (substr($chunks[count($chunks) - 1]["text"],
1306  strlen($chunks[count($chunks) - 1]["text"]) - 6, 6) == "<br />")
1307  {
1308  $chunks[count($chunks) - 1]["text"] =
1309  substr($chunks[count($chunks) - 1]["text"], 0, strlen($chunks[count($chunks) - 1]["text"]) - 6);
1310  if ($chunks[count($chunks) - 1]["text"] == "")
1311  {
1312  unset($chunks[count($chunks) - 1]);
1313  }
1314  }
1315  return $chunks;
1316  }
1317 
1321  function handleNextBr($a_str)
1322  {
1323  // do not remove, if next line starts with a "=", otherwise two
1324  // headlines in a row will not be recognized
1325  if (substr($a_str, 0, 6) == "<br />" && substr($a_str, 6, 1) != "=")
1326  {
1327  $a_str = substr($a_str, 6);
1328  }
1329  else
1330  {
1331  // if next line starts with a "=" we need to reinsert the <br />
1332  // otherwise it will not be recognized
1333  if (substr($a_str, 0, 1) == "=")
1334  {
1335  $a_str = "<br />".$a_str;
1336  }
1337  }
1338  return $a_str;
1339  }
1340 
1344  function removeTrailingBr($a_str)
1345  {
1346  if (substr($a_str, strlen($a_str) - 6) == "<br />")
1347  {
1348  $a_str = substr($a_str, 0, strlen($a_str) - 6);
1349  }
1350  return $a_str;
1351  }
1352 
1356  function getType()
1357  {
1358  return ($this->getCharacteristic() == "Code")?"src":parent::getType();
1359  }
1360 
1364 
1371  function saveJS($a_pg_obj, $a_content, $a_char, $a_pc_id, $a_insert_at = "")
1372  {
1373  global $ilUser;
1374 
1375  $t = self::handleAjaxContent($a_content);
1376  if ($text === false)
1377  {
1378  return false;
1379  }
1380 
1381  $pc_id = explode(":", $a_pc_id);
1382  $insert_at = explode(":", $a_insert_at);
1383  $t_id = explode(":", $t["id"]);
1384 
1385  // insert new paragraph
1386  if ($a_insert_at != "")
1387  {
1388  $par = new ilPCParagraph($this->dom);
1389  $par->create($a_pg_obj, $insert_at[0], $insert_at[1]);
1390  }
1391  else
1392  {
1393  $par = $a_pg_obj->getContentObject($pc_id[0], $pc_id[1]);
1394  }
1395 
1396  if ($a_insert_at != "")
1397  {
1398  $pc_id = $a_pg_obj->generatePCId();
1399  $par->writePCId($pc_id);
1400  $this->inserted_pc_id = $pc_id;
1401  }
1402  else
1403  {
1404  $this->inserted_pc_id = $pc_id[1];
1405  }
1406 
1407  $par->setLanguage($ilUser->getLanguage());
1408  $par->setCharacteristic($t["class"]);
1409 
1410  $t2 = $par->input2xml($t["text"], true, false);
1412  $updated = $par->setText($t2, true);
1413 
1414  if ($updated !== true)
1415  {
1416  echo $updated; exit;
1417  return false;
1418  }
1419  $updated = $a_pg_obj->update();
1420  return $updated;
1421  }
1422 
1429  function getLastSavedPCId($a_pg_obj, $a_as_ajax_str = false)
1430  {
1431  if ($a_as_ajax_str)
1432  {
1433  $a_pg_obj->stripHierIDs();
1434  $a_pg_obj->addHierIds();
1435  $ids = "###";
1436 //var_dump($this->inserted_pc_ids);
1437  $combined = $a_pg_obj->getHierIdsForPCIds(
1438  array($this->inserted_pc_id));
1439  foreach ($combined as $pc_id => $hier_id)
1440  {
1441 //echo "1";
1442  $ids.= $sep.$hier_id.":".$pc_id;
1443  $sep = ";";
1444  }
1445  $ids.= "###";
1446  return $ids;
1447  }
1448 
1449  return $this->inserted_pc_id;
1450  }
1451 
1452 
1456  static function handleAjaxContent($a_content)
1457  {
1458  $a_content = "<dummy>".$a_content."</dummy>";
1459 
1460  $doc = new DOMDocument();
1461 
1462  $content = ilUtil::stripSlashes($a_content, false);
1463 
1464 // $content = str_replace("&lt;", "<", $content);
1465 // $content = str_replace("&gt;", ">", $content);
1466 //echo "<br><br>".htmlentities($content); mk();
1467  $res = $doc->loadXML($content);
1468 
1469  if (!$res)
1470  {
1471  return false;
1472  }
1473 
1474  // convert tags
1475  $xpath = new DOMXpath($doc);
1476 
1477  $elements = $xpath->query("//span");
1478  include_once("./Services/Utilities/classes/class.ilDOM2Util.php");
1479  while (!is_null($elements) && !is_null($element = $elements->item(0)))
1480  {
1481  //$element = $elements->item(0);
1482  $class = $element->getAttribute("class");
1483  if (substr($class, 0, 16) == "ilc_text_inline_")
1484  {
1485  $class_arr = explode(" ", $class);
1486  $cnode = ilDOM2Util::changeName($element, "il".substr($class_arr[0], 16), false);
1487  for ($i = 1; $i < count($class_arr); $i++)
1488  {
1489  $cnode = ilDOM2Util::addParent($cnode, "il".substr($class_arr[$i], 16));
1490  }
1491  }
1492  else
1493  {
1494  ilDOM2Util::replaceByChilds($element);
1495  }
1496 
1497  $elements = $xpath->query("//span");
1498  }
1499 
1500  // convert tags
1501  $xpath = new DOMXpath($doc);
1502  $elements = $xpath->query("/dummy/div");
1503 
1504  $ret = array();
1505  if (!is_null($elements))
1506  {
1507  foreach ($elements as $element)
1508  {
1509  $id = $element->getAttribute("id");
1510  $class = $element->getAttribute("class");
1511  $class = substr($class, 15);
1512  if (trim($class) == "")
1513  {
1514  $class = "Standard";
1515  }
1516 
1517  $text = $doc->saveXML($element);
1518  $text = str_replace("<br/>", "\n", $text);
1519 
1520  // remove wrapping div
1521  $pos = strpos($text, ">");
1522  $text = substr($text, $pos + 1);
1523  $pos = strrpos($text, "<");
1524  $text = substr($text, 0, $pos);
1525 
1526  // todo: remove empty spans <span ...> </span>
1527 
1528  // replace tags by bbcode
1529  foreach (ilPageContentGUI::_getCommonBBButtons() as $bb => $cl)
1530  {
1531  if (!in_array($bb, array("code", "tex", "fn", "xln")))
1532  {
1533  $text = str_replace("<il".$cl.">",
1534  "[".$bb."]", $text);
1535  $text = str_replace("</il".$cl.">",
1536  "[/".$bb."]", $text);
1537  $text = str_replace("<il".$cl."/>", "", $text);
1538  }
1539  }
1540  $text = str_replace(array("<code>", "</code>"),
1541  array("[code]", "[/code]"), $text);
1542 
1543  $text = str_replace("<code/>", "", $text);
1544  $text = str_replace('<ul class="ilc_list_u_BulletedList"/>', "", $text);
1545  $text = str_replace('<ul class="ilc_list_o_NumberedList"/>', "", $text);
1546 
1547  $ret[] = array("text" => $text, "id" => $id, "class" => $class);
1548  }
1549  }
1550 
1551  // we should only have one here!
1552  return $ret[0];
1553  }
1554 
1558  static function handleAjaxContentPost($text)
1559  {
1560  $text = str_replace(array("&lt;ul&gt;", "&lt;/ul&gt;"),
1561  array("<SimpleBulletList>", "</SimpleBulletList>"), $text);
1562  $text = str_replace(array("&lt;ul class='ilc_list_u_BulletedList'&gt;", "&lt;/ul&gt;"),
1563  array("<SimpleBulletList>", "</SimpleBulletList>"), $text);
1564  $text = str_replace(array("&lt;ul class=\"ilc_list_u_BulletedList\"&gt;", "&lt;/ul&gt;"),
1565  array("<SimpleBulletList>", "</SimpleBulletList>"), $text);
1566  $text = str_replace(array("&lt;ol&gt;", "&lt;/ol&gt;"),
1567  array("<SimpleNumberedList>", "</SimpleNumberedList>"), $text);
1568  $text = str_replace(array("&lt;ol class='ilc_list_o_NumberedList'&gt;", "&lt;/ol&gt;"),
1569  array("<SimpleNumberedList>", "</SimpleNumberedList>"), $text);
1570  $text = str_replace(array("&lt;ol class=\"ilc_list_o_NumberedList\"&gt;", "&lt;/ol&gt;"),
1571  array("<SimpleNumberedList>", "</SimpleNumberedList>"), $text);
1572  $text = str_replace(array("&lt;li&gt;", "&lt;/li&gt;"),
1573  array("<SimpleListItem>", "</SimpleListItem>"), $text);
1574  $text = str_replace(array("&lt;li class='ilc_list_item_StandardListItem'&gt;", "&lt;/li&gt;"),
1575  array("<SimpleListItem>", "</SimpleListItem>"), $text);
1576  $text = str_replace(array("&lt;li class=\"ilc_list_item_StandardListItem\"&gt;", "&lt;/li&gt;"),
1577  array("<SimpleListItem>", "</SimpleListItem>"), $text);
1578 
1579  $text = str_replace(array("&lt;li class=\"ilc_list_item_StandardListItem\"/&gt;"),
1580  array("<SimpleListItem></SimpleListItem>"), $text);
1581 
1582  $text = str_replace("<SimpleBulletList><br />", "<SimpleBulletList>", $text);
1583  $text = str_replace("<SimpleNumberedList><br />", "<SimpleNumberedList>", $text);
1584  $text = str_replace("<br /><SimpleBulletList>", "<SimpleBulletList>", $text);
1585  $text = str_replace("<br /><SimpleNumberedList>", "<SimpleNumberedList>", $text);
1586  $text = str_replace("</SimpleBulletList><br />", "</SimpleBulletList>", $text);
1587  $text = str_replace("</SimpleNumberedList><br />", "</SimpleNumberedList>", $text);
1588  $text = str_replace("</SimpleListItem><br />", "</SimpleListItem>", $text);
1589 
1590  return $text;
1591  }
1592 
1593 }
1594 ?>