ILIAS  Release_4_2_x_branch Revision 61807
 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  // bb code to xml
544  $a_text = eregi_replace("\[com\]","<Comment Language=\"".$a_lang."\">",$a_text);
545  $a_text = eregi_replace("\[\/com\]","</Comment>",$a_text);
546  $a_text = eregi_replace("\[emp\]","<Emph>",$a_text);
547  $a_text = eregi_replace("\[\/emp\]","</Emph>",$a_text);
548  $a_text = eregi_replace("\[str\]","<Strong>",$a_text);
549  $a_text = eregi_replace("\[\/str\]","</Strong>",$a_text);
550  $a_text = eregi_replace("\[fn\]","<Footnote>",$a_text);
551  $a_text = eregi_replace("\[\/fn\]","</Footnote>",$a_text);
552  $a_text = eregi_replace("\[quot\]","<Quotation Language=\"".$a_lang."\">",$a_text);
553  $a_text = eregi_replace("\[\/quot\]","</Quotation>",$a_text);
554  $a_text = eregi_replace("\[code\]","<Code>",$a_text);
555  $a_text = eregi_replace("\[\/code\]","</Code>",$a_text);
556  $a_text = eregi_replace("\[acc\]","<Accent>",$a_text);
557  $a_text = eregi_replace("\[\/acc\]","</Accent>",$a_text);
558  $a_text = eregi_replace("\[imp\]","<Important>",$a_text);
559  $a_text = eregi_replace("\[\/imp\]","</Important>",$a_text);
560  $a_text = eregi_replace("\[kw\]","<Keyw>",$a_text);
561  $a_text = eregi_replace("\[\/kw\]","</Keyw>",$a_text);
562 
563  // internal links
564  //$any = "[^\]]*"; // this doesn't work :-(
565  $ws= "[ \t\r\f\v\n]*";
566 
567  while (eregi("\[(iln$ws((inst$ws=$ws([\"0-9])*)?$ws".
568  "((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)$ws=$ws([\"0-9])*)$ws".
569  "(target$ws=$ws(\"(New|FAQ|Media)\"))?$ws(anchor$ws=$ws(\"([^\"])*\"))?$ws))\]", $a_text, $found))
570  {
571  $attribs = ilUtil::attribsToArray($found[2]);
572  $inst_str = $attribs["inst"];
573  // pages
574  if (isset($attribs["page"]))
575  {
576  $tframestr = "";
577  if (!empty($found[10]))
578  {
579  $tframestr = " TargetFrame=\"".$found[10]."\" ";
580  }
581  $ancstr = "";
582  if ($attribs["anchor"] != "")
583  {
584  $ancstr = ' Anchor="'.$attribs["anchor"].'" ';
585  }
586  $a_text = eregi_replace("\[".$found[1]."\]",
587  "<IntLink Target=\"il_".$inst_str."_pg_".$attribs[page]."\" Type=\"PageObject\"".$tframestr.$ancstr.">", $a_text);
588  }
589  // chapters
590  else if (isset($attribs["chap"]))
591  {
592  if (!empty($found[10]))
593  {
594  $tframestr = " TargetFrame=\"".$found[10]."\" ";
595  }
596  else
597  {
598  $tframestr = "";
599  }
600  $a_text = eregi_replace("\[".$found[1]."\]",
601  "<IntLink Target=\"il_".$inst_str."_st_".$attribs[chap]."\" Type=\"StructureObject\"".$tframestr.">", $a_text);
602  }
603  // glossary terms
604  else if (isset($attribs["term"]))
605  {
606  switch ($found[10])
607  {
608  case "New":
609  $tframestr = " TargetFrame=\"New\" ";
610  break;
611 
612  default:
613  $tframestr = " TargetFrame=\"Glossary\" ";
614  break;
615  }
616  $a_text = eregi_replace("\[".$found[1]."\]",
617  "<IntLink Target=\"il_".$inst_str."_git_".$attribs[term]."\" Type=\"GlossaryItem\" $tframestr>", $a_text);
618  }
619  // media object
620  else if (isset($attribs["media"]))
621  {
622  if (!empty($found[10]))
623  {
624  $tframestr = " TargetFrame=\"".$found[10]."\" ";
625  $a_text = eregi_replace("\[".$found[1]."\]",
626  "<IntLink Target=\"il_".$inst_str."_mob_".$attribs[media]."\" Type=\"MediaObject\"".$tframestr.">", $a_text);
627  }
628  else
629  {
630  $a_text = eregi_replace("\[".$found[1]."\]",
631  "<IntLink Target=\"il_".$inst_str."_mob_".$attribs[media]."\" Type=\"MediaObject\"/>", $a_text);
632  }
633  }
634  // direct download file (no repository object)
635  else if (isset($attribs["dfile"]))
636  {
637  $a_text = eregi_replace("\[".$found[1]."\]",
638  "<IntLink Target=\"il_".$inst_str."_dfile_".$attribs[dfile]."\" Type=\"File\">", $a_text);
639  }
640  // repository items (id is ref_id (will be used internally but will
641  // be replaced by object id for export purposes)
642  else if (isset($attribs["lm"]) || isset($attribs["dbk"]) || isset($attribs["glo"])
643  || isset($attribs["frm"]) || isset($attribs["exc"]) || isset($attribs["tst"])
644  || isset($attribs["svy"]) || isset($attribs["obj"]) || isset($attribs['webr'])
645  || isset($attribs["htlm"]) || isset($attribs["chat"]) || isset($attribs["grp"])
646  || isset($attribs["fold"]) || isset($attribs["sahs"]) || isset($attribs["mcst"])
647  || isset($attribs["mep"]) || isset($attribs["wiki"])
648  || isset($attribs["cat"]) || isset($attribs["crs"]) || isset($attribs["file"]))
649  {
650  $obj_id = (isset($attribs["lm"])) ? $attribs["lm"] : $obj_id;
651  $obj_id = (isset($attribs["dbk"])) ? $attribs["dbk"] : $obj_id;
652  $obj_id = (isset($attribs["chat"])) ? $attribs["chat"] : $obj_id;
653  $obj_id = (isset($attribs["glo"])) ? $attribs["glo"] : $obj_id;
654  $obj_id = (isset($attribs["frm"])) ? $attribs["frm"] : $obj_id;
655  $obj_id = (isset($attribs["exc"])) ? $attribs["exc"] : $obj_id;
656  $obj_id = (isset($attribs["htlm"])) ? $attribs["htlm"] : $obj_id;
657  $obj_id = (isset($attribs["tst"])) ? $attribs["tst"] : $obj_id;
658  $obj_id = (isset($attribs["svy"])) ? $attribs["svy"] : $obj_id;
659  $obj_id = (isset($attribs["obj"])) ? $attribs["obj"] : $obj_id;
660  $obj_id = (isset($attribs["webr"])) ? $attribs["webr"] : $obj_id;
661  $obj_id = (isset($attribs["fold"])) ? $attribs["fold"] : $obj_id;
662  $obj_id = (isset($attribs["cat"])) ? $attribs["cat"] : $obj_id;
663  $obj_id = (isset($attribs["crs"])) ? $attribs["crs"] : $obj_id;
664  $obj_id = (isset($attribs["grp"])) ? $attribs["grp"] : $obj_id;
665  $obj_id = (isset($attribs["file"])) ? $attribs["file"] : $obj_id;
666  $obj_id = (isset($attribs["sahs"])) ? $attribs["sahs"] : $obj_id;
667  $obj_id = (isset($attribs["mcst"])) ? $attribs["mcst"] : $obj_id;
668  $obj_id = (isset($attribs["mep"])) ? $attribs["mep"] : $obj_id;
669  $obj_id = (isset($attribs["wiki"])) ? $attribs["wiki"] : $obj_id;
670  //$obj_id = (isset($attribs["obj"])) ? $attribs["obj"] : $obj_id;
671 
672  if ($inst_str == "")
673  {
674  $a_text = eregi_replace("\[".$found[1]."\]",
675  "<IntLink Target=\"il_".$inst_str."_obj_".$obj_id."\" Type=\"RepositoryItem\">", $a_text);
676  }
677  else
678  {
679  $a_text = eregi_replace("\[".$found[1]."\]",
680  "<IntLink Target=\"il_".$inst_str."_".$found[6]."_".$obj_id."\" Type=\"RepositoryItem\">", $a_text);
681  }
682  }
683  else
684  {
685  $a_text = eregi_replace("\[".$found[1]."\]", "[error: iln".$found[1]."]",$a_text);
686  }
687  }
688  while (eregi("\[(iln$ws((inst$ws=$ws([\"0-9])*)?".$ws."media$ws=$ws([\"0-9])*)$ws)/\]", $a_text, $found))
689  {
690  $attribs = ilUtil::attribsToArray($found[2]);
691  $inst_str = $attribs["inst"];
692  $a_text = eregi_replace("\[".$found[1]."/\]",
693  "<IntLink Target=\"il_".$inst_str."_mob_".$attribs[media]."\" Type=\"MediaObject\"/>", $a_text);
694  }
695  $a_text = eregi_replace("\[\/iln\]","</IntLink>",$a_text);
696 
697  // external link
698  $ws= "[ \t\r\f\v\n]*";
699  while (eregi("\[(xln$ws(url$ws=$ws\"([^\"])*\")$ws(target$ws=$ws(\"(Glossary|FAQ|Media)\"))?$ws)\]", $a_text, $found))
700  {
701  $attribs = ilUtil::attribsToArray($found[2]);
702  if (isset($attribs["url"]))
703  {
704  $a2 = ilUtil::attribsToArray($found[4]);
705  $tstr = "";
706  if (in_array($a2["target"], array("FAQ", "Glossary", "Media")))
707  {
708  $tstr = ' TargetFrame="'.$a2["target"].'"';
709  }
710  $a_text = str_replace("[".$found[1]."]", "<ExtLink Href=\"".$attribs["url"]."\"$tstr>", $a_text);
711  }
712  else
713  {
714  $a_text = str_replace("[".$found[1]."]", "[error: xln".$found[1]."]",$a_text);
715  }
716  }
717 
718  // ie/tinymce fix for links without "", see bug #8391
719  while (eregi("\[(xln$ws(url$ws=$ws(([^]])*)))$ws\]", $a_text, $found))
720  {
721  if ($found[3] != "")
722  {
723  $a_text = str_replace("[".$found[1]."]", "<ExtLink Href=\"".$found[3]."\">", $a_text);
724  }
725  else
726  {
727  $a_text = str_replace("[".$found[1]."]", "[error: xln".$found[1]."]",$a_text);
728  }
729  }
730  $a_text = eregi_replace("\[\/xln\]","</ExtLink>",$a_text);
731 
732  // anchor
733  $ws= "[ \t\r\f\v\n]*";
734  while (eregi("\[(anc$ws(name$ws=$ws\"([^\"])*\")$ws)\]", $a_text, $found))
735  {
736  $attribs = ilUtil::attribsToArray($found[2]);
737  $a_text = str_replace("[".$found[1]."]", "<Anchor Name=\"".$attribs["name"]."\">", $a_text);
738  }
739  $a_text = eregi_replace("\[\/anc\]","</Anchor>",$a_text);
740 //echo htmlentities($a_text);
741  return $a_text;
742  }
743 
751  static function input2xmlReplaceLists($a_text)
752  {
753  $rows = explode("<br />", $a_text."<br />");
754 //var_dump($a_text);
755 
756  $old_level = 0;
757 
758  $text = "";
759 
760  foreach ($rows as $row)
761  {
762  $level = 0;
763  if (str_replace("#", "*", substr($row, 0, 3)) == "***")
764  {
765  $level = 3;
766  }
767  else if (str_replace("#", "*", substr($row, 0, 2)) == "**")
768  {
769  $level = 2;
770  }
771  else if (str_replace("#", "*", substr($row, 0, 1)) == "*")
772  {
773  $level = 1;
774  }
775 
776  // end previous line
777  if ($level < $old_level)
778  {
779  for ($i = $old_level; $i > $level; $i--)
780  {
781  $text.= "</SimpleListItem></".$clist[$i].">";
782  }
783  if ($level > 0)
784  {
785  $text.= "</SimpleListItem>";
786  }
787  }
788  else if ($old_level > 0 && $level > 0 && ($level == $old_level))
789  {
790  $text.= "</SimpleListItem>";
791  }
792  else if (($level == $old_level) && $text != "")
793  {
794  $text.= "<br />";
795  }
796 
797  // start next line
798  if ($level > $old_level)
799  {
800  for($i = $old_level + 1; $i <= $level; $i++)
801  {
802  if (substr($row, $i - 1, 1) == "*")
803  {
804  $clist[$i] = "SimpleBulletList";
805  }
806  else
807  {
808  $clist[$i] = "SimpleNumberedList";
809  }
810  $text.= "<".$clist[$i]."><SimpleListItem>";
811  }
812  }
813  else if ($old_level > 0 && $level > 0)
814  {
815  $text.= "<SimpleListItem>";
816  }
817  $text.= substr($row, $level);
818 
819  $old_level = $level;
820  }
821 
822  // remove "<br />" at the end
823  if (substr($text, strlen($text) - 6) == "<br />")
824  {
825  $text = substr($text, 0, strlen($text) - 6);
826  }
827 
828  return $text;
829  }
830 
838  static function xml2outputReplaceLists($a_text)
839  {
840  $segments = ilPCParagraph::segmentString($a_text, array("<SimpleBulletList>", "</SimpleBulletList>",
841  "</SimpleListItem>", "<SimpleListItem>", "<SimpleListItem/>", "<SimpleNumberedList>", "</SimpleNumberedList>"));
842 
843  $current_list = array();
844  $text = "";
845  for ($i=0; $i<= count($segments); $i++)
846  {
847  if ($segments[$i] == "<SimpleBulletList>")
848  {
849  if (count($current_list) == 0)
850  {
851  $list_start = true;
852  }
853  array_push($current_list, "*");
854  $li = false;
855  }
856  else if ($segments[$i] == "<SimpleNumberedList>")
857  {
858  if (count($current_list) == 0)
859  {
860  $list_start = true;
861  }
862  array_push($current_list, "#");
863  $li = false;
864  }
865  else if ($segments[$i] == "</SimpleBulletList>")
866  {
867  array_pop($current_list);
868  $li = false;
869  }
870  else if ($segments[$i] == "</SimpleNumberedList>")
871  {
872  array_pop($current_list);
873  $li = false;
874  }
875  else if ($segments[$i] == "<SimpleListItem>")
876  {
877  $li = true;
878  }
879  else if ($segments[$i] == "</SimpleListItem>")
880  {
881  $li = false;
882  }
883  else if ($segments[$i] == "<SimpleListItem/>")
884  {
885  if ($list_start)
886  {
887  $text.= "<br />";
888  $list_start = false;
889  }
890  foreach($current_list as $list)
891  {
892  $text.= $list;
893  }
894  $text.= "<br />";
895  $li = false;
896  }
897  else
898  {
899  if ($li)
900  {
901  if ($list_start)
902  {
903  $text.= "<br />";
904  $list_start = false;
905  }
906  foreach($current_list as $list)
907  {
908  $text.= $list;
909  }
910  }
911  $text.= $segments[$i];
912  if ($li)
913  {
914  $text.= "<br />";
915  }
916  $li = false;
917  }
918  }
919 
920  // remove trailing <br />, if text ends with list
921  if ($segments[count($segments) - 1] == "</SimpleBulletList>" ||
922  $segments[count($segments) - 1] == "</SimpleNumberedList>" &&
923  substr($text, strlen($text) - 6) == "<br />")
924  {
925  $text = substr($text, 0, strlen($text) - 6);
926  }
927 
928  return $text;
929  }
930 
934  static function segmentString($a_haystack, $a_needles)
935  {
936  $segments = array();
937 
938  $nothing_found = false;
939  while (!$nothing_found)
940  {
941  $nothing_found = true;
942  $found = -1;
943  foreach($a_needles as $needle)
944  {
945  $pos = stripos($a_haystack, $needle);
946  if (is_int($pos) && ($pos < $found || $found == -1))
947  {
948  $found = $pos;
949  $found_needle = $needle;
950  $nothing_found = false;
951  }
952  }
953  if ($found > 0)
954  {
955  $segments[] = substr($a_haystack, 0, $found);
956  $a_haystack = substr($a_haystack, $found);
957  }
958  if ($found > -1)
959  {
960  $segments[] = substr($a_haystack, 0, strlen($found_needle));
961  $a_haystack = substr($a_haystack, strlen($found_needle));
962  }
963  }
964  if ($a_haystack != "")
965  {
966  $segments[] = $a_haystack;
967  }
968 
969  return $segments;
970  }
971 
979  static function xml2output($a_text, $a_wysiwyg = false, $a_replace_lists = true)
980  {
981  // note: the order of the processing steps is crucial
982  // and should be the same as in input2xml() in REVERSE order!
983 
984  // xml to bb code
985  $any = "[^>]*";
986  $a_text = eregi_replace("<Comment[^>]*>","[com]",$a_text);
987  $a_text = eregi_replace("</Comment>","[/com]",$a_text);
988  $a_text = eregi_replace("<Comment/>","[com][/com]",$a_text);
989  $a_text = eregi_replace("<Emph>","[emp]",$a_text);
990  $a_text = eregi_replace("</Emph>","[/emp]",$a_text);
991  $a_text = eregi_replace("<Emph/>","[emp][/emp]",$a_text);
992  $a_text = eregi_replace("<Strong>","[str]",$a_text);
993  $a_text = eregi_replace("</Strong>","[/str]",$a_text);
994  $a_text = eregi_replace("<Strong/>","[str][/str]",$a_text);
995  $a_text = eregi_replace("<Footnote[^>]*>","[fn]",$a_text);
996  $a_text = eregi_replace("</Footnote>","[/fn]",$a_text);
997  $a_text = eregi_replace("<Footnote/>","[fn][/fn]",$a_text);
998  $a_text = eregi_replace("<Quotation[^>]*>","[quot]",$a_text);
999  $a_text = eregi_replace("</Quotation>","[/quot]",$a_text);
1000  $a_text = eregi_replace("<Quotation/>","[quot][/quot]",$a_text);
1001  $a_text = eregi_replace("<Code[^>]*>","[code]",$a_text);
1002  $a_text = eregi_replace("</Code>","[/code]",$a_text);
1003  $a_text = eregi_replace("<Code/>","[code][/code]",$a_text);
1004  $a_text = eregi_replace("<Accent>","[acc]",$a_text);
1005  $a_text = eregi_replace("</Accent>","[/acc]",$a_text);
1006  $a_text = eregi_replace("<Important>","[imp]",$a_text);
1007  $a_text = eregi_replace("</Important>","[/imp]",$a_text);
1008  $a_text = eregi_replace("<Keyw>","[kw]",$a_text);
1009  $a_text = eregi_replace("</Keyw>","[/kw]",$a_text);
1010 
1011  // replace lists
1012  if ($a_replace_lists)
1013  {
1014 //echo "<br>".htmlentities($a_text);
1015  $a_text = ilPCParagraph::xml2outputReplaceLists($a_text);
1016 //echo "<br>".htmlentities($a_text);
1017  }
1018 
1019  // internal links
1020  while (eregi("<IntLink($any)>", $a_text, $found))
1021  {
1022  $found[0];
1023  $attribs = ilUtil::attribsToArray($found[1]);
1024  $target = explode("_", $attribs["Target"]);
1025  $target_id = $target[count($target) - 1];
1026  $inst_str = (!is_int(strpos($attribs["Target"], "__")))
1027  ? $inst_str = "inst=\"".$target[1]."\" "
1028  : $inst_str = "";
1029  switch($attribs["Type"])
1030  {
1031  case "PageObject":
1032  $tframestr = (!empty($attribs["TargetFrame"]))
1033  ? " target=\"".$attribs["TargetFrame"]."\""
1034  : "";
1035  $ancstr = (!empty($attribs["Anchor"]))
1036  ? ' anchor="'.$attribs["Anchor"].'"'
1037  : "";
1038  $a_text = eregi_replace("<IntLink".$found[1].">","[iln ".$inst_str."page=\"".$target_id."\"$tframestr$ancstr]",$a_text);
1039  break;
1040 
1041  case "StructureObject":
1042  $tframestr = (!empty($attribs["TargetFrame"]))
1043  ? " target=\"".$attribs["TargetFrame"]."\""
1044  : "";
1045  $a_text = eregi_replace("<IntLink".$found[1].">","[iln ".$inst_str."chap=\"".$target_id."\"$tframestr]",$a_text);
1046  break;
1047 
1048  case "GlossaryItem":
1049  $tframestr = (empty($attribs["TargetFrame"]) || $attribs["TargetFrame"] == "Glossary")
1050  ? ""
1051  : " target=\"".$attribs["TargetFrame"]."\"";
1052  $a_text = eregi_replace("<IntLink".$found[1].">","[iln ".$inst_str."term=\"".$target_id."\"".$tframestr."]",$a_text);
1053  break;
1054 
1055  case "MediaObject":
1056  if (empty($attribs["TargetFrame"]))
1057  {
1058  $a_text = eregi_replace("<IntLink".$found[1].">","[iln ".$inst_str."media=\"".$target_id."\"/]",$a_text);
1059  }
1060  else
1061  {
1062  $a_text = eregi_replace("<IntLink".$found[1].">","[iln media=\"".$target_id."\"".
1063  " target=\"".$attribs["TargetFrame"]."\"]",$a_text);
1064  }
1065  break;
1066 
1067  // Repository Item (using ref id)
1068  case "RepositoryItem":
1069  if ($inst_str == "")
1070  {
1072  }
1073  else
1074  {
1075  $rtype = $target[count($target) - 2];
1076  $target_type = $rtype;
1077  }
1078  $a_text = eregi_replace("<IntLink".$found[1].">","[iln ".$inst_str."$target_type=\"".$target_id."\"".$tframestr."]",$a_text);
1079  break;
1080 
1081  // Download File (not in repository, Object ID)
1082  case "File":
1083  $a_text = eregi_replace("<IntLink".$found[1].">","[iln ".$inst_str."dfile=\"".$target_id."\"".$tframestr."]",$a_text);
1084  break;
1085 
1086  default:
1087  $a_text = eregi_replace("<IntLink".$found[1].">","[iln]",$a_text);
1088  break;
1089  }
1090  }
1091  $a_text = eregi_replace("</IntLink>","[/iln]",$a_text);
1092 
1093  // external links
1094  while (eregi("<ExtLink($any)>", $a_text, $found))
1095  {
1096  $found[0];
1097  $attribs = ilUtil::attribsToArray($found[1]);
1098  //$found[1] = str_replace("?", "\?", $found[1]);
1099  $tstr = "";
1100  if (in_array($attribs["TargetFrame"], array("FAQ", "Glossary", "Media")))
1101  {
1102  $tstr = ' target="'.$attribs["TargetFrame"].'"';
1103  }
1104  $a_text = str_replace("<ExtLink".$found[1].">","[xln url=\"".$attribs["Href"]."\"$tstr]",$a_text);
1105  }
1106  $a_text = eregi_replace("</ExtLink>","[/xln]",$a_text);
1107 
1108  // anchor
1109  while (eregi("<Anchor($any)>", $a_text, $found))
1110  {
1111  $found[0];
1112  $attribs = ilUtil::attribsToArray($found[1]);
1113  $a_text = str_replace("<Anchor".$found[1].">","[anc name=\"".$attribs["Name"]."\"]",$a_text);
1114  }
1115  $a_text = eregi_replace("</Anchor>","[/anc]",$a_text);
1116 
1117 
1118  // br to linefeed
1119  if (!$a_wysiwyg)
1120  {
1121  $a_text = str_replace("<br />", "\n", $a_text);
1122  $a_text = str_replace("<br/>", "\n", $a_text);
1123  }
1124 
1125 if (!$a_wysiwyg)
1126 {
1127  // prevent curly brackets from being swallowed up by template engine
1128  $a_text = str_replace("{", "&#123;", $a_text);
1129  $a_text = str_replace("}", "&#125;", $a_text);
1130 
1131  // unmask html
1132  $a_text = str_replace("&lt;", "<", $a_text);
1133  $a_text = str_replace("&gt;", ">",$a_text);
1134 
1135  // this is needed to allow html like <tag attribute="value">... in paragraphs
1136  $a_text = str_replace("&quot;", "\"", $a_text);
1137 
1138  // make ampersands in (enabled) html attributes work
1139  // e.g. <a href="foo.php?n=4&t=5">hhh</a>
1140  $a_text = str_replace("&amp;", "&", $a_text);
1141 
1142  // make &gt; and $lt; work to allow (disabled) html descriptions
1143  $a_text = str_replace("&lt;", "&amp;lt;", $a_text);
1144  $a_text = str_replace("&gt;", "&amp;gt;", $a_text);
1145 }
1146  return $a_text;
1147  //return str_replace("<br />", chr(13).chr(10), $a_text);
1148  }
1149 
1156  function autoSplit($a_text)
1157  {
1158  $a_text = str_replace ("=<SimpleBulletList>", "=<br /><SimpleBulletList>", $a_text);
1159  $a_text = str_replace ("=<SimpleNumberedList>", "=<br /><SimpleNumberedList>", $a_text);
1160  $a_text = str_replace ("</SimpleBulletList>=", "</SimpleBulletList><br />=", $a_text);
1161  $a_text = str_replace ("</SimpleNumberedList>=", "</SimpleNumberedList><br />=", $a_text);
1162  $a_text = "<br />".$a_text."<br />"; // add preceding and trailing br
1163 
1164  $chunks = array();
1165  $c_text = $a_text;
1166 //echo "0";
1167  while ($c_text != "")
1168  {
1169 //var_dump($c_text); flush();
1170 //echo "1";
1171  $s1 = strpos($c_text, "<br />=");
1172  if (is_int($s1))
1173  {
1174 //echo "2";
1175  $s2 = strpos($c_text, "<br />==");
1176  if (is_int($s2) && $s2 <= $s1)
1177  {
1178 //echo "3";
1179  $s3 = strpos($c_text, "<br />===");
1180  if (is_int($s3) && $s3 <= $s2) // possible level three header
1181  {
1182 //echo "4";
1183  $n = strpos($c_text, "<br />", $s3 + 1);
1184  if ($n > ($s3+9) && substr($c_text, $n-3, 9) == "===<br />")
1185  {
1186 //echo "5";
1187  // found level three header
1188  if ($s3 > 0 || $head != "")
1189  {
1190 //echo "6";
1191  $chunks[] = array("level" => 0,
1192  "text" => $this->removeTrailingBr($head.substr($c_text, 0, $s3)));
1193  $head = "";
1194  }
1195  $chunks[] = array("level" => 3,
1196  "text" => trim(substr($c_text, $s3+9, $n-$s3-12)));
1197  $c_text = $this->handleNextBr(substr($c_text, $n+6));
1198  }
1199  else
1200  {
1201 //echo "7";
1202  $head.= substr($c_text, 0, $n);
1203  $c_text = substr($c_text, $n);
1204  }
1205  }
1206  else // possible level two header
1207  {
1208 //echo "8";
1209  $n = strpos($c_text, "<br />", $s2 + 1);
1210  if ($n > ($s2+8) && substr($c_text, $n-2, 8) == "==<br />")
1211  {
1212 //echo "9";
1213  // found level two header
1214  if ($s2 > 0 || $head != "")
1215  {
1216 //echo "A";
1217  $chunks[] = array("level" => 0,
1218  "text" => $this->removeTrailingBr($head.substr($c_text, 0, $s2)));
1219  $head = "";
1220  }
1221  $chunks[] = array("level" => 2, "text" => trim(substr($c_text, $s2+8, $n-$s2-10)));
1222  $c_text = $this->handleNextBr(substr($c_text, $n+6));
1223  }
1224  else
1225  {
1226 //echo "B";
1227  $head.= substr($c_text, 0, $n);
1228  $c_text = substr($c_text, $n);
1229  }
1230  }
1231  }
1232  else // possible level one header
1233  {
1234 //echo "C";
1235  $n = strpos($c_text, "<br />", $s1 + 1);
1236  if ($n > ($s1+7) && substr($c_text, $n-1, 7) == "=<br />")
1237  {
1238 //echo "D";
1239  // found level one header
1240  if ($s1 > 0 || $head != "")
1241  {
1242 //echo "E";
1243  $chunks[] = array("level" => 0,
1244  "text" => $this->removeTrailingBr($head.substr($c_text, 0, $s1)));
1245  $head = "";
1246  }
1247  $chunks[] = array("level" => 1, "text" => trim(substr($c_text, $s1+7, $n-$s1-8)));
1248  $c_text = $this->handleNextBr(substr($c_text, $n+6));
1249 //echo "<br>ctext:".htmlentities($c_text)."<br>";
1250  }
1251  else
1252  {
1253  $head.= substr($c_text, 0, $n);
1254  $c_text = substr($c_text, $n);
1255 //echo "<br>head:".$head."c_text:".$c_text."<br>";
1256  }
1257  }
1258  }
1259  else
1260  {
1261 //echo "G";
1262  $chunks[] = array("level" => 0, "text" => $head.$c_text);
1263  $head = "";
1264  $c_text = "";
1265  }
1266  }
1267  if (count($chunks) == 0)
1268  {
1269  $chunks[] = array("level" => 0, "text" => "");
1270  }
1271 
1272 
1273  // remove preceding br
1274  if (substr($chunks[0]["text"], 0, 6) == "<br />")
1275  {
1276  $chunks[0]["text"] = substr($chunks[0]["text"], 6);
1277  }
1278 
1279  // remove trailing br
1280  if (substr($chunks[count($chunks) - 1]["text"],
1281  strlen($chunks[count($chunks) - 1]["text"]) - 6, 6) == "<br />")
1282  {
1283  $chunks[count($chunks) - 1]["text"] =
1284  substr($chunks[count($chunks) - 1]["text"], 0, strlen($chunks[count($chunks) - 1]["text"]) - 6);
1285  if ($chunks[count($chunks) - 1]["text"] == "")
1286  {
1287  unset($chunks[count($chunks) - 1]);
1288  }
1289  }
1290  return $chunks;
1291  }
1292 
1296  function handleNextBr($a_str)
1297  {
1298  // do not remove, if next line starts with a "=", otherwise two
1299  // headlines in a row will not be recognized
1300  if (substr($a_str, 0, 6) == "<br />" && substr($a_str, 6, 1) != "=")
1301  {
1302  $a_str = substr($a_str, 6);
1303  }
1304  else
1305  {
1306  // if next line starts with a "=" we need to reinsert the <br />
1307  // otherwise it will not be recognized
1308  if (substr($a_str, 0, 1) == "=")
1309  {
1310  $a_str = "<br />".$a_str;
1311  }
1312  }
1313  return $a_str;
1314  }
1315 
1319  function removeTrailingBr($a_str)
1320  {
1321  if (substr($a_str, strlen($a_str) - 6) == "<br />")
1322  {
1323  $a_str = substr($a_str, 0, strlen($a_str) - 6);
1324  }
1325  return $a_str;
1326  }
1327 
1331  function getType()
1332  {
1333  return ($this->getCharacteristic() == "Code")?"src":parent::getType();
1334  }
1335 
1339 
1346  function saveJS($a_pg_obj, $a_content, $a_char, $a_pc_id, $a_insert_at = "")
1347  {
1348  global $ilUser;
1349 
1350  $t = self::handleAjaxContent($a_content);
1351  if ($text === false)
1352  {
1353  return false;
1354  }
1355 
1356  $pc_id = explode(":", $a_pc_id);
1357  $insert_at = explode(":", $a_insert_at);
1358  $t_id = explode(":", $t["id"]);
1359 
1360  // insert new paragraph
1361  if ($a_insert_at != "")
1362  {
1363  $par = new ilPCParagraph($this->dom);
1364  $par->create($a_pg_obj, $insert_at[0], $insert_at[1]);
1365  }
1366  else
1367  {
1368  $par = $a_pg_obj->getContentObject($pc_id[0], $pc_id[1]);
1369  }
1370 
1371  if ($a_insert_at != "")
1372  {
1373  $pc_id = $a_pg_obj->generatePCId();
1374  $par->writePCId($pc_id);
1375  $this->inserted_pc_id = $pc_id;
1376  }
1377  else
1378  {
1379  $this->inserted_pc_id = $pc_id[1];
1380  }
1381 
1382  $par->setLanguage($ilUser->getLanguage());
1383  $par->setCharacteristic($t["class"]);
1384 
1385  $t2 = $par->input2xml($t["text"], true, false);
1387  $updated = $par->setText($t2, true);
1388 
1389  if ($updated !== true)
1390  {
1391  echo $updated; exit;
1392  return false;
1393  }
1394  $updated = $a_pg_obj->update();
1395  return $updated;
1396  }
1397 
1404  function getLastSavedPCId($a_pg_obj, $a_as_ajax_str = false)
1405  {
1406  if ($a_as_ajax_str)
1407  {
1408  $a_pg_obj->stripHierIDs();
1409  $a_pg_obj->addHierIds();
1410  $ids = "###";
1411 //var_dump($this->inserted_pc_ids);
1412  $combined = $a_pg_obj->getHierIdsForPCIds(
1413  array($this->inserted_pc_id));
1414  foreach ($combined as $pc_id => $hier_id)
1415  {
1416 //echo "1";
1417  $ids.= $sep.$hier_id.":".$pc_id;
1418  $sep = ";";
1419  }
1420  $ids.= "###";
1421  return $ids;
1422  }
1423 
1424  return $this->inserted_pc_id;
1425  }
1426 
1427 
1431  static function handleAjaxContent($a_content)
1432  {
1433  $a_content = "<dummy>".$a_content."</dummy>";
1434 
1435  $doc = new DOMDocument();
1436 
1437  $content = ilUtil::stripSlashes($a_content, false);
1438 
1439 // $content = str_replace("&lt;", "<", $content);
1440 // $content = str_replace("&gt;", ">", $content);
1441 //echo "<br><br>".htmlentities($content); mk();
1442  $res = $doc->loadXML($content);
1443 
1444  if (!$res)
1445  {
1446  return false;
1447  }
1448 
1449  // convert tags
1450  $xpath = new DOMXpath($doc);
1451 
1452  $elements = $xpath->query("//span");
1453  include_once("./Services/Utilities/classes/class.ilDOM2Util.php");
1454  while (!is_null($elements) && !is_null($element = $elements->item(0)))
1455  {
1456  //$element = $elements->item(0);
1457  $class = $element->getAttribute("class");
1458  if (substr($class, 0, 16) == "ilc_text_inline_")
1459  {
1460  $class_arr = explode(" ", $class);
1461  $cnode = ilDOM2Util::changeName($element, "il".substr($class_arr[0], 16), false);
1462  for ($i = 1; $i < count($class_arr); $i++)
1463  {
1464  $cnode = ilDOM2Util::addParent($cnode, "il".substr($class_arr[$i], 16));
1465  }
1466  }
1467  else
1468  {
1469  ilDOM2Util::replaceByChilds($element);
1470  }
1471 
1472  $elements = $xpath->query("//span");
1473  }
1474 
1475  // convert tags
1476  $xpath = new DOMXpath($doc);
1477  $elements = $xpath->query("/dummy/div");
1478 
1479  $ret = array();
1480  if (!is_null($elements))
1481  {
1482  foreach ($elements as $element)
1483  {
1484  $id = $element->getAttribute("id");
1485  $class = $element->getAttribute("class");
1486  $class = substr($class, 15);
1487  if (trim($class) == "")
1488  {
1489  $class = "Standard";
1490  }
1491 
1492  $text = $doc->saveXML($element);
1493  $text = str_replace("<br/>", "\n", $text);
1494 
1495  // remove wrapping div
1496  $pos = strpos($text, ">");
1497  $text = substr($text, $pos + 1);
1498  $pos = strrpos($text, "<");
1499  $text = substr($text, 0, $pos);
1500 
1501  // todo: remove empty spans <span ...> </span>
1502 
1503  // replace tags by bbcode
1504  foreach (ilPageContentGUI::_getCommonBBButtons() as $bb => $cl)
1505  {
1506  if (!in_array($bb, array("code", "tex", "fn", "xln")))
1507  {
1508  $text = str_replace("<il".$cl.">",
1509  "[".$bb."]", $text);
1510  $text = str_replace("</il".$cl.">",
1511  "[/".$bb."]", $text);
1512  $text = str_replace("<il".$cl."/>", "", $text);
1513  }
1514  }
1515  $text = str_replace(array("<code>", "</code>"),
1516  array("[code]", "[/code]"), $text);
1517 
1518  $text = str_replace("<code/>", "", $text);
1519  $text = str_replace('<ul class="ilc_list_u_BulletedList"/>', "", $text);
1520  $text = str_replace('<ul class="ilc_list_o_NumberedList"/>', "", $text);
1521 
1522  $ret[] = array("text" => $text, "id" => $id, "class" => $class);
1523  }
1524  }
1525 
1526  // we should only have one here!
1527  return $ret[0];
1528  }
1529 
1533  static function handleAjaxContentPost($text)
1534  {
1535  $text = str_replace(array("&lt;ul&gt;", "&lt;/ul&gt;"),
1536  array("<SimpleBulletList>", "</SimpleBulletList>"), $text);
1537  $text = str_replace(array("&lt;ul class='ilc_list_u_BulletedList'&gt;", "&lt;/ul&gt;"),
1538  array("<SimpleBulletList>", "</SimpleBulletList>"), $text);
1539  $text = str_replace(array("&lt;ul class=\"ilc_list_u_BulletedList\"&gt;", "&lt;/ul&gt;"),
1540  array("<SimpleBulletList>", "</SimpleBulletList>"), $text);
1541  $text = str_replace(array("&lt;ol&gt;", "&lt;/ol&gt;"),
1542  array("<SimpleNumberedList>", "</SimpleNumberedList>"), $text);
1543  $text = str_replace(array("&lt;ol class='ilc_list_o_NumberedList'&gt;", "&lt;/ol&gt;"),
1544  array("<SimpleNumberedList>", "</SimpleNumberedList>"), $text);
1545  $text = str_replace(array("&lt;ol class=\"ilc_list_o_NumberedList\"&gt;", "&lt;/ol&gt;"),
1546  array("<SimpleNumberedList>", "</SimpleNumberedList>"), $text);
1547  $text = str_replace(array("&lt;li&gt;", "&lt;/li&gt;"),
1548  array("<SimpleListItem>", "</SimpleListItem>"), $text);
1549  $text = str_replace(array("&lt;li class='ilc_list_item_StandardListItem'&gt;", "&lt;/li&gt;"),
1550  array("<SimpleListItem>", "</SimpleListItem>"), $text);
1551  $text = str_replace(array("&lt;li class=\"ilc_list_item_StandardListItem\"&gt;", "&lt;/li&gt;"),
1552  array("<SimpleListItem>", "</SimpleListItem>"), $text);
1553 
1554  $text = str_replace(array("&lt;li class=\"ilc_list_item_StandardListItem\"/&gt;"),
1555  array("<SimpleListItem></SimpleListItem>"), $text);
1556 
1557  $text = str_replace("<SimpleBulletList><br />", "<SimpleBulletList>", $text);
1558  $text = str_replace("<SimpleNumberedList><br />", "<SimpleNumberedList>", $text);
1559  $text = str_replace("<br /><SimpleBulletList>", "<SimpleBulletList>", $text);
1560  $text = str_replace("<br /><SimpleNumberedList>", "<SimpleNumberedList>", $text);
1561  $text = str_replace("</SimpleBulletList><br />", "</SimpleBulletList>", $text);
1562  $text = str_replace("</SimpleNumberedList><br />", "</SimpleNumberedList>", $text);
1563  $text = str_replace("</SimpleListItem><br />", "</SimpleListItem>", $text);
1564 
1565  return $text;
1566  }
1567 
1568 }
1569 ?>