ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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
4require_once("./Services/COPage/classes/class.ilPageContent.php");
5
17{
21 protected $user;
22
23 public $dom;
24 public $par_node; // node of Paragraph element
25
26 protected static $bb_tags = array(
27 "com" => "Comment",
28 "emp" => "Emph",
29 "str" => "Strong",
30 "fn" => "Footnote",
31 "code" => "Code",
32 "acc" => "Accent",
33 "imp" => "Important",
34 "kw" => "Keyw",
35 "sub" => "Sub",
36 "sup" => "Sup",
37 "quot" => "Quotation",
38 );
39
43 public function init()
44 {
45 global $DIC;
46
47 $this->user = $DIC->user();
48 $this->setType("par");
49 }
50
56 protected static function getBBMap()
57 {
58 return self::$bb_tags;
59 }
60
66 protected static function getXMLTagMap()
67 {
68 return array_flip(self::$bb_tags);
69 }
70
71
72
78 public function setNode($a_node)
79 {
80 parent::setNode($a_node); // this is the PageContent node
81
82 $childs = $a_node->child_nodes();
83 for ($i = 0; $i < count($childs); $i++) {
84 if ($childs[$i]->node_name() == "Paragraph") {
85 $this->par_node = $childs[$i]; //... and this the Paragraph node
86 }
87 }
88 }
89
90
96 public function createAtNode(&$node)
97 {
98 $this->node = $this->createPageContentNode();
99 $this->par_node = $this->dom->create_element("Paragraph");
100 $this->par_node = $this->node->append_child($this->par_node);
101 $this->par_node->set_attribute("Language", "");
102 $node->append_child($this->node);
103 }
104
110 public function createBeforeNode(&$node)
111 {
112 $this->node = $this->createPageContentNode();
113 $this->par_node = $this->dom->create_element("Paragraph");
114 $this->par_node = $this->node->append_child($this->par_node);
115 $this->par_node->set_attribute("Language", "");
116 $node->insert_before($this->node, $node);
117 }
118
125 public function createAfter($node)
126 {
127 $this->node = $this->createPageContentNode(false);
128 if ($succ_node = $node->next_sibling()) {
129 $this->node = $succ_node->insert_before($this->node, $succ_node);
130 } else {
131 $parent_node = $node->parent_node();
132 $this->node = $parent_node->append_child($this->node);
133 }
134 $this->par_node = $this->dom->create_element("Paragraph");
135 $this->par_node = $this->node->append_child($this->par_node);
136 $this->par_node->set_attribute("Language", "");
137 }
138
146 public function create(&$a_pg_obj, $a_hier_id, $a_pc_id = "")
147 {
148 //echo "-$a_pc_id-";
149 //echo "<br>-".htmlentities($a_pg_obj->getXMLFromDom())."-<br><br>"; mk();
150 $this->node = $this->dom->create_element("PageContent");
151
152 // this next line kicks out placeholders, if something is inserted
153 $a_pg_obj->insertContent($this, $a_hier_id, IL_INSERT_AFTER, $a_pc_id);
154
155 $this->par_node = $this->dom->create_element("Paragraph");
156 $this->par_node = $this->node->append_child($this->par_node);
157 $this->par_node->set_attribute("Language", "");
158 }
159
166 public function setText($a_text, $a_auto_split = false)
167 {
168 if (!is_array($a_text)) {
169 $text = array(array("level" => 0, "text" => $a_text));
170 } else {
171 $text = $a_text;
172 }
173 if ($a_auto_split) {
174 $text = $this->autoSplit($a_text);
175 }
176
177
178 $error = $this->checkTextArray($text);
179
180 /* we currently do no try to fix xml
181 if (!empty($error)) {
182 $text = $this->fixTextArray($text);
183 $error = $this->checkTextArray($text);
184 };*/
185
186 // remove all childs
187 if (empty($error)) {
188 $temp_dom = domxml_open_mem(
189 '<?xml version="1.0" encoding="UTF-8"?><Paragraph>' . $text[0]["text"] . '</Paragraph>',
191 $error
192 );
193
194 // delete children of paragraph node
195 $children = $this->par_node->child_nodes();
196 for ($i = 0; $i < count($children); $i++) {
197 $this->par_node->remove_child($children[$i]);
198 }
199
200 // copy new content children in paragraph node
201 $xpc = xpath_new_context($temp_dom);
202 $path = "//Paragraph";
203 $res = xpath_eval($xpc, $path);
204 if (count($res->nodeset) == 1) {
205 $new_par_node = $res->nodeset[0];
206 $new_childs = $new_par_node->child_nodes();
207
208 for ($i = 0; $i < count($new_childs); $i++) {
209 $cloned_child = $new_childs[$i]->clone_node(true);
210 $this->par_node->append_child($cloned_child);
211 }
212 $orig_characteristic = $this->getCharacteristic();
213
214 // if headlines are entered and current characteristic is a headline
215 // use no characteristic as standard
216 if ((count($text) > 1) && (substr($orig_characteristic, 0, 8) == "Headline")) {
217 $orig_characteristic = "";
218 }
219 if ($text[0]["level"] > 0) {
220 $this->par_node->set_attribute("Characteristic", 'Headline' . $text[0]["level"]);
221 }
222 }
223
224 $ok = true;
225
226 $c_node = $this->node;
227 // add other chunks afterwards
228 for ($i = 1; $i < count($text); $i++) {
229 if ($ok) {
230 $next_par = new ilPCParagraph($this->getPage());
231 $next_par->createAfter($c_node);
232 $next_par->setLanguage($this->getLanguage());
233 if ($text[$i]["level"] > 0) {
234 $next_par->setCharacteristic("Headline" . $text[$i]["level"]);
235 } else {
236 $next_par->setCharacteristic($orig_characteristic);
237 }
238 $ok = $next_par->setText($text[$i]["text"], false);
239 $c_node = $next_par->node;
240 }
241 }
242
243 return true;
244 } else {
245 // We want the correct number of \n here to have the real lines numbers
246 $check = array_reduce($text, function ($t, $i) {
247 return $t . $i["text"];
248 });
249 $text = str_replace("<br>", "\n", $check); // replace <br> with \n to get correct line
250 $text = str_replace("<br/>", "\n", $text);
251 $text = str_replace("<br />", "\n", $text);
252 $text = str_replace("</SimpleListItem>", "</SimpleListItem>\n", $text);
253 $text = str_replace("<SimpleBulletList>", "\n<SimpleBulletList>", $text);
254 $text = str_replace("<SimpleNumberedList>", "\n<SimpleNumberedList>", $text);
255 $text = str_replace("<Paragraph>\n", "<Paragraph>", $text);
256 $text = str_replace("</Paragraph>", "</Paragraph>\n", $text);
257 include_once("./Services/Dom/classes/class.ilDomDocument.php");
258 $doc = new ilDOMDocument();
259 $text = '<?xml version="1.0" encoding="UTF-8"?><Paragraph>' . $text . '</Paragraph>';
260 //echo htmlentities($text);
261 $this->success = $doc->loadXML($text);
262 $error = $doc->errors;
263 $estr = "";
264 foreach ($error as $e) {
265 $e = str_replace(" in Entity", "", $e);
266 $estr .= $e . "<br />";
267 }
268 if (DEVMODE) {
269 $estr .= "<br />" . $text;
270 }
271
272 return $estr;
273 }
274 }
275
281 protected function checkTextArray($text)
282 {
283 $check = "";
284 foreach ($text as $t) {
285 $check .= "<Paragraph>" . $t["text"] . "</Paragraph>";
286 }
287 $error = null;
288 //try {
289 $temp_dom = domxml_open_mem(
290 '<?xml version="1.0" encoding="UTF-8"?><Paragraph>' . $check . '</Paragraph>',
292 $error
293 );
294 //} catch (Exception $e) {
295
296 //}
297 return $error;
298 }
299
304 protected function fixTextArray($text)
305 {
306 $dom = new DOMDocument();
307 $dom->recover = true;
308 // try to fix
309 for ($i = 0; $i < count($text); $i++) {
310 $dom->loadXML('<?xml version="1.0" encoding="UTF-8"?><Paragraph>' . $text[$i]["text"] . '</Paragraph>',
311 LIBXML_NOWARNING | LIBXML_NOERROR);
312 foreach($dom->childNodes as $node) {
313 if ($node->nodeName == "Paragraph") {
314 $inner = "";
315 foreach ($node->childNodes as $child)
316 {
317 $inner .= $dom->saveXML($child);
318 }
319 $text[$i]["text"] = $inner;
320 }
321 }
322 }
323 return $text;
324 }
325
331 public function getText($a_short_mode = false)
332 {
333 if (is_object($this->par_node)) {
334 $content = "";
335 $childs = $this->par_node->child_nodes();
336 for ($i = 0; $i < count($childs); $i++) {
337 $content .= $this->dom->dump_node($childs[$i]);
338 }
339 return $content;
340 } else {
341 return "";
342 }
343 }
344
348 public function getParagraphSequenceContent($a_pg_obj)
349 {
350 $childs = $this->par_node->parent_node()->parent_node()->child_nodes();
351 $seq = array();
352 $cur_seq = array();
353 $found = false;
354 $pc_id = $this->readPCId();
355 $hier_id = $this->readHierId();
356 for ($i = 0; $i < count($childs); $i++) {
357 $pchilds = $childs[$i]->child_nodes();
358 if ($pchilds[0]->node_name() == "Paragraph" &&
359 $pchilds[0]->get_attribute("Characteristic") != "Code") {
360 $cur_seq[] = $childs[$i];
361
362 // check whether this is the sequence of the current paragraph
363 if ($childs[$i]->get_attribute("PCID") == $pc_id &&
364 $childs[$i]->get_attribute("HierId") == $hier_id) {
365 $found = true;
366 }
367
368 // if this is the current sequenc, get it
369 if ($found) {
370 $seq = $cur_seq;
371 }
372 } else {
373 // non-paragraph element found -> init the current sequence
374 $cur_seq = array();
375 $found = false;
376 }
377 }
378
379 $content = "";
380 $ids = "###";
381 $id_sep = "";
382 foreach ($seq as $p_node) {
383 $ids .= $id_sep . $p_node->get_attribute("HierId") . ":" . $p_node->get_attribute("PCID");
384 $po = $a_pg_obj->getContentObject(
385 $p_node->get_attribute("HierId"),
386 $p_node->get_attribute("PCID")
387 );
388 $s_text = $po->getText();
389 $s_text = $po->xml2output($s_text, true, false);
390 $char = $po->getCharacteristic();
391 if ($char == "") {
392 $char = "Standard";
393 }
394 $s_text = ilPCParagraphGUI::xml2outputJS($s_text, $char, $po->readPCId());
395 $content .= $s_text;
396 $id_sep = ";";
397 }
398 $ids .= "###";
399
400 return $ids . $content;
401 }
402
408 public function setCharacteristic($a_char)
409 {
410 if (!empty($a_char)) {
411 $this->par_node->set_attribute("Characteristic", $a_char);
412 } else {
413 if ($this->par_node->has_attribute("Characteristic")) {
414 $this->par_node->remove_attribute("Characteristic");
415 }
416 }
417 }
418
424 public function getCharacteristic()
425 {
426 if (is_object($this->par_node)) {
427 return $this->par_node->get_attribute("Characteristic");
428 }
429 }
430
431
435 public function setSubCharacteristic($a_char)
436 {
437 if (!empty($a_char)) {
438 $this->par_node->set_attribute("SubCharacteristic", $a_char);
439 } else {
440 if ($this->par_node->has_attribute("SubCharacteristic")) {
441 $this->par_node->remove_attribute("SubCharacteristic");
442 }
443 }
444 }
445
451 public function getAutoIndent()
452 {
453 return $this->par_node->get_attribute("AutoIndent");
454 }
455
456 public function setAutoIndent($a_char)
457 {
458 if (!empty($a_char)) {
459 $this->par_node->set_attribute("AutoIndent", $a_char);
460 } else {
461 if ($this->par_node->has_attribute("AutoIndent")) {
462 $this->par_node->remove_attribute("AutoIndent");
463 }
464 }
465 }
466
470 public function getSubCharacteristic()
471 {
472 return $this->par_node->get_attribute("SubCharacteristic");
473 }
474
479 public function setDownloadTitle($a_char)
480 {
481 if (!empty($a_char)) {
482 $this->par_node->set_attribute("DownloadTitle", $a_char);
483 } else {
484 if ($this->par_node->has_attribute("DownloadTitle")) {
485 $this->par_node->remove_attribute("DownloadTitle");
486 }
487 }
488 }
489
493 public function getDownloadTitle()
494 {
495 return $this->par_node->get_attribute("DownloadTitle");
496 }
497
502 public function setShowLineNumbers($a_char)
503 {
504 $a_char = empty($a_char)?"n":$a_char;
505
506 $this->par_node->set_attribute("ShowLineNumbers", $a_char);
507 }
508
513 public function getShowLineNumbers()
514 {
515 return $this->par_node->get_attribute("ShowLineNumbers");
516 }
517
521 public function setLanguage($a_lang)
522 {
523 $this->par_node->set_attribute("Language", $a_lang);
524 }
525
529 public function getLanguage()
530 {
531 return $this->par_node->get_attribute("Language");
532 }
533
534 public function input2xml($a_text, $a_wysiwyg = 0, $a_handle_lists = true)
535 {
536 return $this->_input2xml($a_text, $this->getLanguage(), $a_wysiwyg, $a_handle_lists);
537 }
538
547 protected static function replaceBBCode($a_text, $a_bb, $a_tag)
548 {
549 $a_text = preg_replace('/\[' . $a_bb . '\]/i', "<" . $a_tag . ">", $a_text);
550 $a_text = preg_replace('/\[\/' . $a_bb . '\]/i', "</" . $a_tag . ">", $a_text);
551 return $a_text;
552 }
553
554
558 public static function _input2xml($a_text, $a_lang, $a_wysiwyg = 0, $a_handle_lists = true)
559 {
560 if (!$a_wysiwyg) {
561 $a_text = ilUtil::stripSlashes($a_text, false);
562 }
563
564 if ($a_wysiwyg) {
565 $a_text = str_replace("<br />", chr(10), $a_text);
566 }
567
568 // note: the order of the processing steps is crucial
569 // and should be the same as in xml2output() in REVERSE order!
570 $a_text = trim($a_text);
571
572 //echo "<br>between:".htmlentities($a_text);
573
574 // mask html
575 if (!$a_wysiwyg) {
576 $a_text = str_replace("&", "&amp;", $a_text);
577 }
578 $a_text = str_replace("<", "&lt;", $a_text);
579 $a_text = str_replace(">", "&gt;", $a_text);
580
581 // Reconvert PageTurn and BibItemIdentifier
582 $a_text = preg_replace('/&lt;([\s\/]*?PageTurn.*?)&gt;/i', "<$1>", $a_text);
583 $a_text = preg_replace('/&lt;([\s\/]*?BibItemIdentifier.*?)&gt;/i', "<$1>", $a_text);
584
585 //echo "<br>second:".htmlentities($a_text);
586
587 // mask curly brackets
588 /*
589 echo htmlentities($a_text);
590 $a_text = str_replace("{", "&#123;", $a_text);
591 $a_text = str_replace("}", "&#125;", $a_text);
592 echo htmlentities($a_text);*/
593 // linefeed to br
594 $a_text = str_replace(chr(13) . chr(10), "<br />", $a_text);
595 $a_text = str_replace(chr(13), "<br />", $a_text);
596 $a_text = str_replace(chr(10), "<br />", $a_text);
597
598 if ($a_handle_lists) {
599 $a_text = ilPCParagraph::input2xmlReplaceLists($a_text);
600 }
601
602 foreach (self::getBBMap() as $bb => $tag) {
603 // remove empty tags
604 $a_text = str_replace("[" . $bb . "][/" . $bb . "]", "", $a_text);
605
606 // replace bb code by tag
607 $a_text = self::replaceBBCode($a_text, $bb, $tag);
608 }
609
610 $a_text = self::intLinks2xml($a_text);
611
612 // external link
613 $ws = "[ \t\r\f\v\n]*";
614 // remove empty external links
615 while (preg_match("~\[(xln$ws(url$ws=$ws\"([^\"])*\")$ws(target$ws=$ws(\"(Glossary|FAQ|Media)\"))?$ws)\]\[\/xln\]~i", $a_text, $found)) {
616 $a_text = str_replace($found[0], "", $a_text);
617 }
618 while (preg_match('~\[(xln$ws(url$ws=$ws(([^]])*)))$ws\]\[\/xln\]~i', $a_text, $found)) {
619 $a_text = str_replace($found[0], "", $a_text);
620 }
621 // external links
622 while (preg_match("~\[(xln$ws(url$ws=$ws\"([^\"])*\")$ws(target$ws=$ws(\"(Glossary|FAQ|Media)\"))?$ws)\]~i", $a_text, $found)) {
623 $attribs = ilUtil::attribsToArray($found[2]);
624 if (isset($attribs["url"])) {
625 $a2 = ilUtil::attribsToArray($found[4]);
626 $tstr = "";
627 if (in_array($a2["target"], array("FAQ", "Glossary", "Media"))) {
628 $tstr = ' TargetFrame="' . $a2["target"] . '"';
629 }
630 $a_text = str_replace("[" . $found[1] . "]", "<ExtLink Href=\"" . $attribs["url"] . "\"$tstr>", $a_text);
631 } else {
632 $a_text = str_replace("[" . $found[1] . "]", "[error: xln" . $found[1] . "]", $a_text);
633 }
634 }
635
636 // ie/tinymce fix for links without "", see bug #8391
637 while (preg_match('~\[(xln$ws(url$ws=$ws(([^]])*)))$ws\]~i', $a_text, $found)) {
638 if ($found[3] != "") {
639 $a_text = str_replace("[" . $found[1] . "]", "<ExtLink Href=\"" . $found[3] . "\">", $a_text);
640 } else {
641 $a_text = str_replace("[" . $found[1] . "]", "[error: xln" . $found[1] . "]", $a_text);
642 }
643 }
644 $a_text = preg_replace('~\[\/xln\]~i', "</ExtLink>", $a_text);
645
646 // anchor
647 $ws = "[ \t\r\f\v\n]*";
648 while (preg_match("~\[(anc$ws(name$ws=$ws\"([^\"])*\")$ws)\]~i", $a_text, $found)) {
649 $attribs = ilUtil::attribsToArray($found[2]);
650 $a_text = str_replace("[" . $found[1] . "]", "<Anchor Name=\"" . $attribs["name"] . "\">", $a_text);
651 }
652 $a_text = preg_replace("~\[\/anc\]~i", "</Anchor>", $a_text);
653
654 // marked text
655 while (preg_match("~\[(marked$ws(class$ws=$ws\"([^\"])*\")$ws)\]~i", $a_text, $found)) {
656 $attribs = ilUtil::attribsToArray($found[2]);
657 if (isset($attribs["class"])) {
658 $a_text = str_replace("[" . $found[1] . "]", "<Marked Class=\"" . $attribs["class"] . "\">", $a_text);
659 } else {
660 $a_text = str_replace("[" . $found[1] . "]", "[error:marked" . $found[1] . "]", $a_text);
661 }
662 }
663 $a_text = preg_replace('~\[\/marked\]~i', "</Marked>", $a_text);
664
665
666 //echo htmlentities($a_text); exit;
667 return $a_text;
668 }
669
676 public static function intLinks2xml($a_text)
677 {
678 global $DIC;
679
680 $objDefinition = $DIC["objDefinition"];
681
682 $rtypes = $objDefinition->getAllRepositoryTypes();
683
684 // internal links
685 //$any = "[^\]]*"; // this doesn't work :-(
686 $ws = "[ \t\r\f\v\n]*";
687 $ltypes = "page|chap|term|media|obj|dfile|sess|wpage|ppage|" . implode("|", $rtypes);
688 // empty internal links
689 while (preg_match('~\[(iln' . $ws . '((inst' . $ws . '=' . $ws . '([\"0-9])*)?' . $ws .
690 "((" . $ltypes . ")$ws=$ws([\"0-9])*)$ws" .
691 "(target$ws=$ws(\"(New|FAQ|Media)\"))?$ws(anchor$ws=$ws(\"([^\"])*\"))?$ws))\]\[\/iln\]~i", $a_text, $found)) {
692 $a_text = str_replace($found[0], "", $a_text);
693 }
694 while (preg_match('~\[(iln' . $ws . '((inst' . $ws . '=' . $ws . '([\"0-9])*)?' . $ws .
695 "((" . $ltypes . ")$ws=$ws([\"0-9])*)$ws" .
696 "(target$ws=$ws(\"(New|FAQ|Media)\"))?$ws(anchor$ws=$ws(\"([^\"])*\"))?$ws))\]~i", $a_text, $found)) {
697 $attribs = ilUtil::attribsToArray($found[2]);
698 $inst_str = $attribs["inst"];
699 // pages
700 if (isset($attribs["page"])) {
701 $tframestr = "";
702 if (!empty($found[10])) {
703 $tframestr = " TargetFrame=\"" . $found[10] . "\" ";
704 }
705 $ancstr = "";
706 if ($attribs["anchor"] != "") {
707 $ancstr = ' Anchor="' . $attribs["anchor"] . '" ';
708 }
709 // see 26066 for addcslashes
710 $a_text = preg_replace(
711 '/\[' . addcslashes($found[1], '/') . '\]/i',
712 "<IntLink Target=\"il_" . $inst_str . "_pg_" . $attribs['page'] . "\" Type=\"PageObject\"" . $tframestr . $ancstr . ">",
713 $a_text
714 );
715 }
716 // chapters
717 elseif (isset($attribs["chap"])) {
718 if (!empty($found[10])) {
719 $tframestr = " TargetFrame=\"" . $found[10] . "\" ";
720 } else {
721 $tframestr = "";
722 }
723 $a_text = preg_replace(
724 '/\[' . $found[1] . '\]/i',
725 "<IntLink Target=\"il_" . $inst_str . "_st_" . $attribs['chap'] . "\" Type=\"StructureObject\"" . $tframestr . ">",
726 $a_text
727 );
728 }
729 // glossary terms
730 elseif (isset($attribs["term"])) {
731 switch ($found[10]) {
732 case "New":
733 $tframestr = " TargetFrame=\"New\" ";
734 break;
735
736 default:
737 $tframestr = " TargetFrame=\"Glossary\" ";
738 break;
739 }
740 $a_text = preg_replace(
741 '/\[' . $found[1] . '\]/i',
742 "<IntLink Target=\"il_" . $inst_str . "_git_" . $attribs['term'] . "\" Type=\"GlossaryItem\" $tframestr>",
743 $a_text
744 );
745 }
746 // wiki pages
747 elseif (isset($attribs["wpage"])) {
748 $tframestr = "";
749 $a_text = preg_replace(
750 '/\[' . $found[1] . '\]/i',
751 "<IntLink Target=\"il_" . $inst_str . "_wpage_" . $attribs['wpage'] . "\" Type=\"WikiPage\" $tframestr>",
752 $a_text
753 );
754 }
755 // portfolio pages
756 elseif (isset($attribs["ppage"])) {
757 $tframestr = "";
758 $a_text = preg_replace(
759 '/\[' . $found[1] . '\]/i',
760 "<IntLink Target=\"il_" . $inst_str . "_ppage_" . $attribs['ppage'] . "\" Type=\"PortfolioPage\" $tframestr>",
761 $a_text
762 );
763 }
764 // media object
765 elseif (isset($attribs["media"])) {
766 if (!empty($found[10])) {
767 $tframestr = " TargetFrame=\"" . $found[10] . "\" ";
768 $a_text = preg_replace(
769 '/\[' . $found[1] . '\]/i',
770 "<IntLink Target=\"il_" . $inst_str . "_mob_" . $attribs['media'] . "\" Type=\"MediaObject\"" . $tframestr . ">",
771 $a_text
772 );
773 } else {
774 $a_text = preg_replace(
775 '/\[' . $found[1] . '\]/i',
776 "<IntLink Target=\"il_" . $inst_str . "_mob_" . $attribs['media'] . "\" Type=\"MediaObject\"/>",
777 $a_text
778 );
779 }
780 }
781 // direct download file (no repository object)
782 elseif (isset($attribs["dfile"])) {
783 $a_text = preg_replace(
784 '/\[' . $found[1] . '\]/i',
785 "<IntLink Target=\"il_" . $inst_str . "_dfile_" . $attribs['dfile'] . "\" Type=\"File\">",
786 $a_text
787 );
788 }
789 // repository items (id is ref_id (will be used internally but will
790 // be replaced by object id for export purposes)
791 else {
792 foreach ($objDefinition->getAllRepositoryTypes() as $t) {
793 if (isset($attribs[$t])) {
794 $obj_id = $attribs[$t];
795 }
796 }
797 if (isset($attribs["obj"])) {
798 $obj_id = $attribs["obj"];
799 }
800
801 if ($obj_id > 0) {
802 if ($inst_str == "") {
803 $a_text = preg_replace(
804 '/\[' . $found[1] . '\]/i',
805 "<IntLink Target=\"il_" . $inst_str . "_obj_" . $obj_id . "\" Type=\"RepositoryItem\">",
806 $a_text
807 );
808 } else {
809 $a_text = preg_replace(
810 '/\[' . $found[1] . '\]/i',
811 "<IntLink Target=\"il_" . $inst_str . "_" . $found[6] . "_" . $obj_id . "\" Type=\"RepositoryItem\">",
812 $a_text
813 );
814 }
815 } else {
816 $a_text = preg_replace('/\[' . $found[1] . '\]/i', "[error: iln" . $found[1] . "]", $a_text);
817 }
818 }
819 }
820
821 while (preg_match("~\[(iln$ws((inst$ws=$ws([\"0-9])*)?" . $ws . "media$ws=$ws([\"0-9])*)$ws)/\]~i", $a_text, $found)) {
822 $attribs = ilUtil::attribsToArray($found[2]);
823 $inst_str = $attribs["inst"];
824 $a_text = preg_replace(
825 '~\[' . $found[1] . '/\]~i',
826 "<IntLink Target=\"il_" . $inst_str . "_mob_" . $attribs['media'] . "\" Type=\"MediaObject\"/>",
827 $a_text
828 );
829 }
830
831 // user
832 while (preg_match("~\[(iln$ws((inst$ws=$ws([\"0-9])*)?" . $ws . "user$ws=$ws(\"([^\"])*)\")$ws)/\]~i", $a_text, $found)) {
833 $attribs = ilUtil::attribsToArray($found[2]);
834 $inst_str = $attribs["inst"];
835 include_once("./Services/User/classes/class.ilObjUser.php");
836 $user_id = ilObjUser::_lookupId($attribs['user']);
837 $a_text = preg_replace(
838 '~\[' . $found[1] . '/\]~i',
839 "<IntLink Target=\"il_" . $inst_str . "_user_" . $user_id . "\" Type=\"User\"/>",
840 $a_text
841 );
842 }
843
844 $a_text = preg_replace('~\[\/iln\]~i', "</IntLink>", $a_text);
845 return $a_text;
846 }
847
848
856 public static function input2xmlReplaceLists($a_text)
857 {
858 $rows = explode("<br />", $a_text . "<br />");
859 //var_dump($a_text);
860
861 $old_level = 0;
862
863 $text = "";
864
865 foreach ($rows as $row) {
866 $level = 0;
867 if (str_replace("#", "*", substr($row, 0, 3)) == "***") {
868 $level = 3;
869 } elseif (str_replace("#", "*", substr($row, 0, 2)) == "**") {
870 $level = 2;
871 } elseif (str_replace("#", "*", substr($row, 0, 1)) == "*") {
872 $level = 1;
873 }
874
875 // end previous line
876 if ($level < $old_level) {
877 for ($i = $old_level; $i > $level; $i--) {
878 $text .= "</SimpleListItem></" . $clist[$i] . ">";
879 }
880 if ($level > 0) {
881 $text .= "</SimpleListItem>";
882 }
883 } elseif ($old_level > 0 && $level > 0 && ($level == $old_level)) {
884 $text .= "</SimpleListItem>";
885 } elseif (($level == $old_level) && $text != "") {
886 $text .= "<br />";
887 }
888
889 // start next line
890 if ($level > $old_level) {
891 for ($i = $old_level + 1; $i <= $level; $i++) {
892 if (substr($row, $i - 1, 1) == "*") {
893 $clist[$i] = "SimpleBulletList";
894 } else {
895 $clist[$i] = "SimpleNumberedList";
896 }
897 $text .= "<" . $clist[$i] . "><SimpleListItem>";
898 }
899 } elseif ($old_level > 0 && $level > 0) {
900 $text .= "<SimpleListItem>";
901 }
902 $text .= substr($row, $level);
903
904 $old_level = $level;
905 }
906
907 // remove "<br />" at the end
908 if (substr($text, strlen($text) - 6) == "<br />") {
909 $text = substr($text, 0, strlen($text) - 6);
910 }
911
912 return $text;
913 }
914
922 public static function xml2outputReplaceLists($a_text)
923 {
924 $segments = ilPCParagraph::segmentString($a_text, array("<SimpleBulletList>", "</SimpleBulletList>",
925 "</SimpleListItem>", "<SimpleListItem>", "<SimpleListItem/>", "<SimpleNumberedList>", "</SimpleNumberedList>"));
926
927 $current_list = array();
928 $text = "";
929 for ($i = 0; $i <= count($segments); $i++) {
930 if ($segments[$i] == "<SimpleBulletList>") {
931 if (count($current_list) == 0) {
932 $list_start = true;
933 }
934 array_push($current_list, "*");
935 $li = false;
936 } elseif ($segments[$i] == "<SimpleNumberedList>") {
937 if (count($current_list) == 0) {
938 $list_start = true;
939 }
940 array_push($current_list, "#");
941 $li = false;
942 } elseif ($segments[$i] == "</SimpleBulletList>") {
943 array_pop($current_list);
944 $li = false;
945 } elseif ($segments[$i] == "</SimpleNumberedList>") {
946 array_pop($current_list);
947 $li = false;
948 } elseif ($segments[$i] == "<SimpleListItem>") {
949 $li = true;
950 } elseif ($segments[$i] == "</SimpleListItem>") {
951 $li = false;
952 } elseif ($segments[$i] == "<SimpleListItem/>") {
953 if ($list_start) {
954 $text .= "<br />";
955 $list_start = false;
956 }
957 foreach ($current_list as $list) {
958 $text .= $list;
959 }
960 $text .= "<br />";
961 $li = false;
962 } else {
963 if ($li) {
964 if ($list_start) {
965 $text .= "<br />";
966 $list_start = false;
967 }
968 foreach ($current_list as $list) {
969 $text .= $list;
970 }
971 }
972 $text .= $segments[$i];
973 if ($li) {
974 $text .= "<br />";
975 }
976 $li = false;
977 }
978 }
979
980 // remove trailing <br />, if text ends with list
981 if ($segments[count($segments) - 1] == "</SimpleBulletList>" ||
982 $segments[count($segments) - 1] == "</SimpleNumberedList>" &&
983 substr($text, strlen($text) - 6) == "<br />") {
984 $text = substr($text, 0, strlen($text) - 6);
985 }
986
987 return $text;
988 }
989
993 public static function segmentString($a_haystack, $a_needles)
994 {
995 $segments = array();
996
997 $nothing_found = false;
998 while (!$nothing_found) {
999 $nothing_found = true;
1000 $found = -1;
1001 foreach ($a_needles as $needle) {
1002 $pos = stripos($a_haystack, $needle);
1003 if (is_int($pos) && ($pos < $found || $found == -1)) {
1004 $found = $pos;
1005 $found_needle = $needle;
1006 $nothing_found = false;
1007 }
1008 }
1009 if ($found > 0) {
1010 $segments[] = substr($a_haystack, 0, $found);
1011 $a_haystack = substr($a_haystack, $found);
1012 }
1013 if ($found > -1) {
1014 $segments[] = substr($a_haystack, 0, strlen($found_needle));
1015 $a_haystack = substr($a_haystack, strlen($found_needle));
1016 }
1017 }
1018 if ($a_haystack != "") {
1019 $segments[] = $a_haystack;
1020 }
1021
1022 return $segments;
1023 }
1024
1032 public static function xml2output($a_text, $a_wysiwyg = false, $a_replace_lists = true, $unmask = true)
1033 {
1034 // note: the order of the processing steps is crucial
1035 // and should be the same as in input2xml() in REVERSE order!
1036
1037 // xml to bb code
1038 $any = "[^>]*";
1039
1040 foreach (self::getBBMap() as $bb => $tag) {
1041 $a_text = preg_replace('~<' . $tag . '[^>]*>~i', "[" . $bb . "]", $a_text);
1042 $a_text = preg_replace('~</' . $tag . '>~i', "[/" . $bb . "]", $a_text);
1043 $a_text = preg_replace('~<' . $tag . '/>~i', "[" . $bb . "][/" . $bb . "]", $a_text);
1044 }
1045
1046 // replace lists
1047 if ($a_replace_lists) {
1048 //echo "<br>".htmlentities($a_text);
1049 $a_text = ilPCParagraph::xml2outputReplaceLists($a_text);
1050 //echo "<br>".htmlentities($a_text);
1051 }
1052
1053 // internal links
1054 while (preg_match('~<IntLink(' . $any . ')>~i', $a_text, $found)) {
1055 $found[0];
1056 $attribs = ilUtil::attribsToArray($found[1]);
1057 $target = explode("_", $attribs["Target"]);
1058 $target_id = $target[count($target) - 1];
1059 $inst_str = (!is_int(strpos($attribs["Target"], "__")))
1060 ? $inst_str = "inst=\"" . $target[1] . "\" "
1061 : $inst_str = "";
1062 switch ($attribs["Type"]) {
1063 case "PageObject":
1064 $tframestr = (!empty($attribs["TargetFrame"]))
1065 ? " target=\"" . $attribs["TargetFrame"] . "\""
1066 : "";
1067 $ancstr = (!empty($attribs["Anchor"]))
1068 ? ' anchor="' . $attribs["Anchor"] . '"'
1069 : "";
1070 $a_text = preg_replace('~<IntLink' . $found[1] . '>~i', "[iln " . $inst_str . "page=\"" . $target_id . "\"$tframestr$ancstr]", $a_text);
1071 break;
1072
1073 case "StructureObject":
1074 $tframestr = (!empty($attribs["TargetFrame"]))
1075 ? " target=\"" . $attribs["TargetFrame"] . "\""
1076 : "";
1077 $a_text = preg_replace('~<IntLink' . $found[1] . '>~i', "[iln " . $inst_str . "chap=\"" . $target_id . "\"$tframestr]", $a_text);
1078 break;
1079
1080 case "GlossaryItem":
1081 $tframestr = (empty($attribs["TargetFrame"]) || $attribs["TargetFrame"] == "Glossary")
1082 ? ""
1083 : " target=\"" . $attribs["TargetFrame"] . "\"";
1084 $a_text = preg_replace('~<IntLink' . $found[1] . '>~i', "[iln " . $inst_str . "term=\"" . $target_id . "\"" . $tframestr . "]", $a_text);
1085 break;
1086
1087 case "WikiPage":
1088 $tframestr = "";
1089 $a_text = preg_replace('~<IntLink' . $found[1] . '>~i', "[iln " . $inst_str . "wpage=\"" . $target_id . "\"" . $tframestr . "]", $a_text);
1090 break;
1091
1092 case "PortfolioPage":
1093 $tframestr = "";
1094 $a_text = preg_replace('~<IntLink' . $found[1] . '>~i', "[iln " . $inst_str . "ppage=\"" . $target_id . "\"" . $tframestr . "]", $a_text);
1095 break;
1096
1097 case "MediaObject":
1098 if (empty($attribs["TargetFrame"])) {
1099 $a_text = preg_replace('~<IntLink' . $found[1] . '>~i', "[iln " . $inst_str . "media=\"" . $target_id . "\"/]", $a_text);
1100 } else {
1101 $a_text = preg_replace('~<IntLink' . $found[1] . '>~i', "[iln media=\"" . $target_id . "\"" .
1102 " target=\"" . $attribs["TargetFrame"] . "\"]", $a_text);
1103 }
1104 break;
1105
1106 // Repository Item (using ref id)
1107 case "RepositoryItem":
1108 if ($inst_str == "") {
1110 } else {
1111 $rtype = $target[count($target) - 2];
1112 $target_type = $rtype;
1113 }
1114 $a_text = preg_replace('~<IntLink' . $found[1] . '>~i', "[iln " . $inst_str . "$target_type=\"" . $target_id . "\"" . $tframestr . "]", $a_text);
1115 break;
1116
1117 // Download File (not in repository, Object ID)
1118 case "File":
1119 $a_text = preg_replace('~<IntLink' . $found[1] . '>~i', "[iln " . $inst_str . "dfile=\"" . $target_id . "\"" . $tframestr . "]", $a_text);
1120 break;
1121
1122 // User
1123 case "User":
1124 include_once("./Services/User/classes/class.ilObjUser.php");
1125 $a_text = preg_replace('~<IntLink' . $found[1] . '>~i', "[iln " . $inst_str . "user=\"" . ilObjUser::_lookupLogin($target_id) . "\"/]", $a_text);
1126 break;
1127
1128 default:
1129 $a_text = preg_replace('~<IntLink' . $found[1] . '>~i', "[iln]", $a_text);
1130 break;
1131 }
1132 }
1133 $a_text = str_replace("</IntLink>", "[/iln]", $a_text);
1134
1135 // external links
1136 while (preg_match('~<ExtLink(' . $any . ')>~i', $a_text, $found)) {
1137 $found[0];
1138 $attribs = ilUtil::attribsToArray($found[1]);
1139 //$found[1] = str_replace("?", "\?", $found[1]);
1140 $tstr = "";
1141 if (in_array($attribs["TargetFrame"], array("FAQ", "Glossary", "Media"))) {
1142 $tstr = ' target="' . $attribs["TargetFrame"] . '"';
1143 }
1144 $a_text = str_replace("<ExtLink" . $found[1] . ">", "[xln url=\"" . $attribs["Href"] . "\"$tstr]", $a_text);
1145 }
1146 $a_text = str_replace("</ExtLink>", "[/xln]", $a_text);
1147
1148 // anchor
1149 while (preg_match('~<Anchor(' . $any . '/)>~i', $a_text, $found)) {
1150 $found[0];
1151 $attribs = ilUtil::attribsToArray($found[1]);
1152 $a_text = str_replace("<Anchor" . $found[1] . ">", "[anc name=\"" . $attribs["Name"] . "\"][/anc]", $a_text);
1153 }
1154 while (preg_match('~<Anchor(' . $any . ')>~i', $a_text, $found)) {
1155 $found[0];
1156 $attribs = ilUtil::attribsToArray($found[1]);
1157 $a_text = str_replace("<Anchor" . $found[1] . ">", "[anc name=\"" . $attribs["Name"] . "\"]", $a_text);
1158 }
1159 $a_text = str_replace("</Anchor>", "[/anc]", $a_text);
1160
1161 // marked text
1162 while (preg_match('~<Marked(' . $any . ')>~i', $a_text, $found)) {
1163 $found[0];
1164 $attribs = ilUtil::attribsToArray($found[1]);
1165 $a_text = str_replace("<Marked" . $found[1] . ">", "[marked class=\"" . $attribs["Class"] . "\"]", $a_text);
1166 }
1167 $a_text = str_replace("</Marked>", "[/marked]", $a_text);
1168
1169 // br to linefeed
1170 if (!$a_wysiwyg) {
1171 $a_text = str_replace("<br />", "\n", $a_text);
1172 $a_text = str_replace("<br/>", "\n", $a_text);
1173 }
1174
1175 if (!$a_wysiwyg) {
1176 // prevent curly brackets from being swallowed up by template engine
1177 $a_text = str_replace("{", "&#123;", $a_text);
1178 $a_text = str_replace("}", "&#125;", $a_text);
1179
1180 // unmask html
1181 if ($unmask) {
1182 $a_text = str_replace("&lt;", "<", $a_text);
1183 $a_text = str_replace("&gt;", ">", $a_text);
1184 }
1185
1186 // this is needed to allow html like <tag attribute="value">... in paragraphs
1187 $a_text = str_replace("&quot;", "\"", $a_text);
1188
1189 // make ampersands in (enabled) html attributes work
1190 // e.g. <a href="foo.php?n=4&t=5">hhh</a>
1191 $a_text = str_replace("&amp;", "&", $a_text);
1192
1193 // make &gt; and $lt; work to allow (disabled) html descriptions
1194 if ($unmask) {
1195 $a_text = str_replace("&lt;", "&amp;lt;", $a_text);
1196 $a_text = str_replace("&gt;", "&amp;gt;", $a_text);
1197 }
1198 }
1199 return $a_text;
1200 //return str_replace("<br />", chr(13).chr(10), $a_text);
1201 }
1202
1209 public function autoSplit($a_text)
1210 {
1211 $a_text = str_replace("=<SimpleBulletList>", "=<br /><SimpleBulletList>", $a_text);
1212 $a_text = str_replace("=<SimpleNumberedList>", "=<br /><SimpleNumberedList>", $a_text);
1213 $a_text = str_replace("</SimpleBulletList>=", "</SimpleBulletList><br />=", $a_text);
1214 $a_text = str_replace("</SimpleNumberedList>=", "</SimpleNumberedList><br />=", $a_text);
1215 $a_text = "<br />" . $a_text . "<br />"; // add preceding and trailing br
1216
1217 $chunks = array();
1218 $c_text = $a_text;
1219 //echo "0";
1220 while ($c_text != "") {
1221 //var_dump($c_text); flush();
1222 //echo "1";
1223 $s1 = strpos($c_text, "<br />=");
1224 if (is_int($s1)) {
1225 //echo "2";
1226 $s2 = strpos($c_text, "<br />==");
1227 if (is_int($s2) && $s2 <= $s1) {
1228 //echo "3";
1229 $s3 = strpos($c_text, "<br />===");
1230 if (is_int($s3) && $s3 <= $s2) { // possible level three header
1231 //echo "4";
1232 $n = strpos($c_text, "<br />", $s3 + 1);
1233 if ($n > ($s3 + 9) && substr($c_text, $n - 3, 9) == "===<br />") {
1234 //echo "5";
1235 // found level three header
1236 if ($s3 > 0 || $head != "") {
1237 //echo "6";
1238 $chunks[] = array("level" => 0,
1239 "text" => $this->removeTrailingBr($head . substr($c_text, 0, $s3)));
1240 $head = "";
1241 }
1242 $chunks[] = array("level" => 3,
1243 "text" => trim(substr($c_text, $s3 + 9, $n - $s3 - 12)));
1244 $c_text = $this->handleNextBr(substr($c_text, $n + 6));
1245 } else {
1246 //echo "7";
1247 $head .= substr($c_text, 0, $n);
1248 $c_text = substr($c_text, $n);
1249 }
1250 } else { // possible level two header
1251 //echo "8";
1252 $n = strpos($c_text, "<br />", $s2 + 1);
1253 if ($n > ($s2 + 8) && substr($c_text, $n - 2, 8) == "==<br />") {
1254 //echo "9";
1255 // found level two header
1256 if ($s2 > 0 || $head != "") {
1257 //echo "A";
1258 $chunks[] = array("level" => 0,
1259 "text" => $this->removeTrailingBr($head . substr($c_text, 0, $s2)));
1260 $head = "";
1261 }
1262 $chunks[] = array("level" => 2, "text" => trim(substr($c_text, $s2 + 8, $n - $s2 - 10)));
1263 $c_text = $this->handleNextBr(substr($c_text, $n + 6));
1264 } else {
1265 //echo "B";
1266 $head .= substr($c_text, 0, $n);
1267 $c_text = substr($c_text, $n);
1268 }
1269 }
1270 } else { // possible level one header
1271 //echo "C";
1272 $n = strpos($c_text, "<br />", $s1 + 1);
1273 if ($n > ($s1 + 7) && substr($c_text, $n - 1, 7) == "=<br />") {
1274 //echo "D";
1275 // found level one header
1276 if ($s1 > 0 || $head != "") {
1277 //echo "E";
1278 $chunks[] = array("level" => 0,
1279 "text" => $this->removeTrailingBr($head . substr($c_text, 0, $s1)));
1280 $head = "";
1281 }
1282 $chunks[] = array("level" => 1, "text" => trim(substr($c_text, $s1 + 7, $n - $s1 - 8)));
1283 $c_text = $this->handleNextBr(substr($c_text, $n + 6));
1284 //echo "<br>ctext:".htmlentities($c_text)."<br>";
1285 } else {
1286 $head .= substr($c_text, 0, $n);
1287 $c_text = substr($c_text, $n);
1288 //echo "<br>head:".$head."c_text:".$c_text."<br>";
1289 }
1290 }
1291 } else {
1292 //echo "G";
1293 $chunks[] = array("level" => 0, "text" => $head . $c_text);
1294 $head = "";
1295 $c_text = "";
1296 }
1297 }
1298 if (count($chunks) == 0) {
1299 $chunks[] = array("level" => 0, "text" => "");
1300 }
1301
1302
1303 // remove preceding br
1304 if (substr($chunks[0]["text"], 0, 6) == "<br />") {
1305 $chunks[0]["text"] = substr($chunks[0]["text"], 6);
1306 }
1307
1308 // remove trailing br
1309 if (substr(
1310 $chunks[count($chunks) - 1]["text"],
1311 strlen($chunks[count($chunks) - 1]["text"]) - 6,
1312 6
1313 ) == "<br />") {
1314 $chunks[count($chunks) - 1]["text"] =
1315 substr($chunks[count($chunks) - 1]["text"], 0, strlen($chunks[count($chunks) - 1]["text"]) - 6);
1316 if ($chunks[count($chunks) - 1]["text"] == "") {
1317 unset($chunks[count($chunks) - 1]);
1318 }
1319 }
1320 return $chunks;
1321 }
1322
1326 public function handleNextBr($a_str)
1327 {
1328 // do not remove, if next line starts with a "=", otherwise two
1329 // headlines in a row will not be recognized
1330 if (substr($a_str, 0, 6) == "<br />" && substr($a_str, 6, 1) != "=") {
1331 $a_str = substr($a_str, 6);
1332 } else {
1333 // if next line starts with a "=" we need to reinsert the <br />
1334 // otherwise it will not be recognized
1335 if (substr($a_str, 0, 1) == "=") {
1336 $a_str = "<br />" . $a_str;
1337 }
1338 }
1339 return $a_str;
1340 }
1341
1345 public function removeTrailingBr($a_str)
1346 {
1347 if (substr($a_str, strlen($a_str) - 6) == "<br />") {
1348 $a_str = substr($a_str, 0, strlen($a_str) - 6);
1349 }
1350 return $a_str;
1351 }
1352
1356 public function getType()
1357 {
1358 return ($this->getCharacteristic() == "Code")?"src":parent::getType();
1359 }
1360
1364
1371 public function saveJS($a_pg_obj, $a_content, $a_char, $a_pc_id, $a_insert_at = "")
1372 {
1374
1375 $this->log->debug("step 1: " . substr($a_content, 0, 1000));
1377 $this->log->debug("step 2: " . substr($t["text"], 0, 1000));
1378 if ($t === false) {
1379 return false;
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 $par = new ilPCParagraph($this->getPage());
1388 $par->create($a_pg_obj, $insert_at[0], $insert_at[1]);
1389 } else {
1390 $par = $a_pg_obj->getContentObject($pc_id[0], $pc_id[1]);
1391 }
1392
1393 if ($a_insert_at != "") {
1394 $pc_id = $a_pg_obj->generatePCId();
1395 $par->writePCId($pc_id);
1396 $this->inserted_pc_id = $pc_id;
1397 } else {
1398 $this->inserted_pc_id = $pc_id[1];
1399 }
1400
1401 $par->setLanguage($ilUser->getLanguage());
1402 $par->setCharacteristic($t["class"]);
1403
1404 $t2 = $par->input2xml($t["text"], true, false);
1405 $this->log->debug("step 3: " . substr($t2, 0, 1000));
1406
1408 $this->log->debug("step 4: " . substr($t2, 0, 1000));
1409
1410 $updated = $par->setText($t2, true);
1411
1412 if ($updated !== true) {
1413 echo $updated;
1414 exit;
1415 return false;
1416 }
1417 $updated = $par->updatePage($a_pg_obj);
1418 //$updated = $a_pg_obj->update();
1419 return $updated;
1420 }
1421
1428 public function getLastSavedPCId($a_pg_obj, $a_as_ajax_str = false)
1429 {
1430 if ($a_as_ajax_str) {
1431 $a_pg_obj->stripHierIDs();
1432 $a_pg_obj->addHierIds();
1433 $ids = "###";
1434 //var_dump($this->inserted_pc_ids);
1435 $combined = $a_pg_obj->getHierIdsForPCIds(
1436 array($this->inserted_pc_id)
1437 );
1438 foreach ($combined as $pc_id => $hier_id) {
1439 //echo "1";
1440 $ids .= $sep . $hier_id . ":" . $pc_id;
1441 $sep = ";";
1442 }
1443 $ids .= "###";
1444 return $ids;
1445 }
1446
1447 return $this->inserted_pc_id;
1448 }
1449
1450
1454 public static function handleAjaxContent($a_content)
1455 {
1456 $a_content = "<dummy>" . $a_content . "</dummy>";
1457
1458 $doc = new DOMDocument();
1459
1460 $content = ilUtil::stripSlashes($a_content, false);
1461
1462 // $content = str_replace("&lt;", "<", $content);
1463 // $content = str_replace("&gt;", ">", $content);
1464 //echo "<br><br>".htmlentities($content); mk();
1465 $res = $doc->loadXML($content);
1466
1467 if (!$res) {
1468 return false;
1469 }
1470
1471 // convert tags
1472 $xpath = new DOMXpath($doc);
1473
1474 $tags = self::getXMLTagMap();
1475
1476 $elements = $xpath->query("//span");
1477 include_once("./Services/Utilities/classes/class.ilDOM2Util.php");
1478 while (!is_null($elements) && !is_null($element = $elements->item(0))) {
1479 //$element = $elements->item(0);
1480 $class = $element->getAttribute("class");
1481 if (substr($class, 0, 16) == "ilc_text_inline_") {
1482 $class_arr = explode(" ", $class);
1483 $tag = substr($class_arr[0], 16);
1484 if (isset($tags[$tag])) { // known tag like strong
1485 $cnode = ilDOM2Util::changeName($element, "il" . substr($class_arr[0], 16), false);
1486 } else { // unknown tag -> marked text
1487 $cnode = ilDOM2Util::changeName($element, "ilMarked", false);
1488 $cnode->setAttribute("Class", substr($class_arr[0], 16));
1489 }
1490 for ($i = 1; $i < count($class_arr); $i++) {
1491 $tag = substr($class_arr[$i], 16);
1492 if (isset($tags[$tag])) { // known tag like strong
1493 $cnode = ilDOM2Util::addParent($cnode, "il" . substr($class_arr[$i], 16));
1494 } else { // unknown tag -> marked element
1495 $cnode = ilDOM2Util::addParent($cnode, "ilMarked");
1496 $cnode->setAttribute("Class", substr($class_arr[$i], 16));
1497 }
1498 }
1499 } else {
1501 }
1502
1503 $elements = $xpath->query("//span");
1504 }
1505
1506 // convert tags
1507 $xpath = new DOMXpath($doc);
1508 $elements = $xpath->query("/dummy/div");
1509
1510 $ret = array();
1511 if (!is_null($elements)) {
1512 foreach ($elements as $element) {
1513 $id = $element->getAttribute("id");
1514 $class = $element->getAttribute("class");
1515 $class = substr($class, 15);
1516 if (trim($class) == "") {
1517 $class = "Standard";
1518 }
1519
1520 $text = $doc->saveXML($element);
1521 $text = str_replace("<br/>", "\n", $text);
1522
1523 // remove wrapping div
1524 $pos = strpos($text, ">");
1525 $text = substr($text, $pos + 1);
1526 $pos = strrpos($text, "<");
1527 $text = substr($text, 0, $pos);
1528
1529 // todo: remove empty spans <span ...> </span>
1530
1531 // replace tags by bbcode
1532 foreach (ilPageContentGUI::_getCommonBBButtons() as $bb => $cl) {
1533 if (!in_array($bb, array("code", "tex", "fn", "xln"))) {
1534 $text = str_replace(
1535 "<il" . $cl . ">",
1536 "[" . $bb . "]",
1537 $text
1538 );
1539 $text = str_replace(
1540 "</il" . $cl . ">",
1541 "[/" . $bb . "]",
1542 $text
1543 );
1544 $text = str_replace("<il" . $cl . "/>", "", $text);
1545 }
1546 }
1547 $text = str_replace(
1548 array("<code>", "</code>"),
1549 array("[code]", "[/code]"),
1550 $text
1551 );
1552 $text = str_replace(
1553 array('<sup class="ilc_sup_Sup">', "</sup>"),
1554 array("[sup]", "[/sup]"),
1555 $text
1556 );
1557 $text = str_replace(
1558 array('<sub class="ilc_sub_Sub">', "</sub>"),
1559 array("[sub]", "[/sub]"),
1560 $text
1561 );
1562
1563 $text = str_replace("<code/>", "", $text);
1564 $text = str_replace('<ul class="ilc_list_u_BulletedList"/>', "", $text);
1565 $text = str_replace('<ul class="ilc_list_o_NumberedList"/>', "", $text);
1566
1567 // replace marked text
1568 // external links
1569 $any = "[^>]*";
1570 while (preg_match('~<ilMarked(' . $any . ')>~i', $text, $found)) {
1571 $found[0];
1572 $attribs = ilUtil::attribsToArray($found[1]);
1573 $text = str_replace("<ilMarked" . $found[1] . ">", "[marked class=\"" . $attribs["Class"] . "\"]", $text);
1574 }
1575 $text = str_replace("</ilMarked>", "[/marked]", $text);
1576
1577
1578 $ret[] = array("text" => $text, "id" => $id, "class" => $class);
1579 }
1580 }
1581
1582 // we should only have one here!
1583 return $ret[0];
1584 }
1585
1589 public static function handleAjaxContentPost($text)
1590 {
1591 $text = str_replace(
1592 array("&lt;ul&gt;", "&lt;/ul&gt;"),
1593 array("<SimpleBulletList>", "</SimpleBulletList>"),
1594 $text
1595 );
1596 $text = str_replace(
1597 array("&lt;ul class='ilc_list_u_BulletedList'&gt;", "&lt;/ul&gt;"),
1598 array("<SimpleBulletList>", "</SimpleBulletList>"),
1599 $text
1600 );
1601 $text = str_replace(
1602 array("&lt;ul class=\"ilc_list_u_BulletedList\"&gt;", "&lt;/ul&gt;"),
1603 array("<SimpleBulletList>", "</SimpleBulletList>"),
1604 $text
1605 );
1606 $text = str_replace(
1607 array("&lt;ol&gt;", "&lt;/ol&gt;"),
1608 array("<SimpleNumberedList>", "</SimpleNumberedList>"),
1609 $text
1610 );
1611 $text = str_replace(
1612 array("&lt;ol class='ilc_list_o_NumberedList'&gt;", "&lt;/ol&gt;"),
1613 array("<SimpleNumberedList>", "</SimpleNumberedList>"),
1614 $text
1615 );
1616 $text = str_replace(
1617 array("&lt;ol class=\"ilc_list_o_NumberedList\"&gt;", "&lt;/ol&gt;"),
1618 array("<SimpleNumberedList>", "</SimpleNumberedList>"),
1619 $text
1620 );
1621 $text = str_replace(
1622 array("&lt;li&gt;", "&lt;/li&gt;"),
1623 array("<SimpleListItem>", "</SimpleListItem>"),
1624 $text
1625 );
1626 $text = str_replace(
1627 array("&lt;li class='ilc_list_item_StandardListItem'&gt;", "&lt;/li&gt;"),
1628 array("<SimpleListItem>", "</SimpleListItem>"),
1629 $text
1630 );
1631 $text = str_replace(
1632 array("&lt;li class=\"ilc_list_item_StandardListItem\"&gt;", "&lt;/li&gt;"),
1633 array("<SimpleListItem>", "</SimpleListItem>"),
1634 $text
1635 );
1636
1637 $text = str_replace(
1638 array("&lt;li class=\"ilc_list_item_StandardListItem\"/&gt;"),
1639 array("<SimpleListItem></SimpleListItem>"),
1640 $text
1641 );
1642
1643 $text = str_replace("<SimpleBulletList><br />", "<SimpleBulletList>", $text);
1644 $text = str_replace("<SimpleNumberedList><br />", "<SimpleNumberedList>", $text);
1645 $text = str_replace("<br /><SimpleBulletList>", "<SimpleBulletList>", $text);
1646 $text = str_replace("<br /><SimpleNumberedList>", "<SimpleNumberedList>", $text);
1647 $text = str_replace("</SimpleBulletList><br />", "</SimpleBulletList>", $text);
1648 $text = str_replace("</SimpleNumberedList><br />", "</SimpleNumberedList>", $text);
1649 $text = str_replace("</SimpleListItem><br />", "</SimpleListItem>", $text);
1650
1651 return $text;
1652 }
1653
1661 public function updatePage($a_page)
1662 {
1663 $a_page->beforePageContentUpdate($this);
1664
1665 $ret = $a_page->update();
1666 return $ret;
1667 }
1668
1675 public function autoLinkGlossaries($a_glos)
1676 {
1677 if (is_array($a_glos) && count($a_glos) > 0) {
1678 // check which terms occur in the text (we may
1679 // get some false positives due to the strip_tags, but
1680 // we do not want to find strong or list or other stuff
1681 // within the tags
1682 $text = strip_tags($this->getText());
1683 $found_terms = array();
1684 foreach ($a_glos as $glo) {
1685 if (ilObject::_lookupType($glo) == "glo") {
1686 $ref_ids = ilObject::_getAllReferences($glo);
1687 $glo_ref_id = current($ref_ids);
1688 if ($glo_ref_id > 0) {
1689 $terms = ilGlossaryTerm::getTermList($glo_ref_id);
1690 foreach ($terms as $t) {
1691 if (is_int(stripos($text, $t["term"]))) {
1692 $found_terms[$t["id"]] = $t;
1693 }
1694 }
1695 }
1696 }
1697 }
1698 // did we find anything? -> modify content
1699 if (count($found_terms) > 0) {
1700 self::linkTermsInDom($this->dom, $found_terms, $this->par_node);
1701 }
1702 }
1703 }
1704
1711 protected static function linkTermsInDom($a_dom, $a_terms, $a_par_node = null)
1712 {
1713 // sort terms by their length (shortes first)
1714 // to prevent that nested tags are builded
1715 foreach ($a_terms as $k => $t) {
1716 $a_terms[$k]["termlength"] = strlen($t["term"]);
1717 }
1718 $a_terms = ilUtil::sortArray($a_terms, "termlength", "asc", true);
1719
1720
1721 if ($a_dom instanceof php4DOMDocument) {
1722 $a_dom = $a_dom->myDOMDocument;
1723 }
1724 if ($a_par_node instanceof php4DOMElement) {
1725 $a_par_node = $a_par_node->myDOMNode;
1726 }
1727
1728 $xpath = new DOMXPath($a_dom);
1729
1730 if ($a_par_node == null) {
1731 $parnodes = $xpath->query("//Paragraph[@Characteristic != 'Code']");
1732 } else {
1733 $parnodes = $xpath->query(".//Paragraph[@Characteristic != 'Code']", $a_par_node->parentNode);
1734 }
1735
1736 include_once("./Services/Utilities/classes/class.ilStr.php");
1737
1738 foreach ($parnodes as $parnode) {
1739 $textnodes = $xpath->query('.//text()', $parnode);
1740 foreach ($textnodes as $node) {
1741 $p = $node->getNodePath();
1742
1743 // we do not change text nodes inside of links
1744 if (!is_int(strpos($p, "/IntLink")) &&
1745 !is_int(strpos($p, "/ExtLink"))) {
1746 $node_val = $node->nodeValue;
1747
1748 // all terms
1749 foreach ($a_terms as $t) {
1750 $pos = ilStr::strIPos($node_val, $t["term"]);
1751
1752 // if term found
1753 while (is_int($pos)) {
1754 // check if we are in a tex tag, see #22261
1755 $tex_bpos = ilStr::strrPos(ilStr::subStr($node_val, 0, $pos), "[tex]");
1756 $tex_epos = ilStr::strPos($node_val, "[/tex]", $tex_bpos);
1757 if ($tex_bpos > 0 && $tex_epos > 0 && $tex_bpos < $pos && $tex_epos > $pos) {
1758 $pos += ilStr::strLen($t["term"]);
1759 } else {
1760
1761 // check if the string is not included in another word
1762 // note that []
1763 $valid_limiters = array("", " ", "&nbsp;", ".", ",", ":", ";", "!", "?", "\"", "'", "(", ")");
1764 $b = ($pos > 0)
1765 ? ilStr::subStr($node_val, $pos - 1, 1)
1766 : "";
1767 $a = ilStr::subStr($node_val, $pos + ilStr::strLen($t["term"]), 1);
1768 if ((in_array($b, $valid_limiters) || htmlentities($b, null, 'utf-8') == "&nbsp;") && in_array($a, $valid_limiters)) {
1769 $mid = '[iln term="' . $t["id"] . '"]' .
1770 ilStr::subStr($node_val, $pos, ilStr::strLen($t["term"])) .
1771 "[/iln]";
1772
1773 $node_val = ilStr::subStr($node_val, 0, $pos) .
1774 $mid .
1775 ilStr::subStr($node_val, $pos + ilStr::strLen($t["term"]));
1776
1777 $pos += ilStr::strLen($mid);
1778 } else {
1779 $pos += ilStr::strLen($t["term"]);
1780 }
1781 }
1782 $pos = ilStr::strIPos($node_val, $t["term"], $pos);
1783 }
1784
1785 // insert [iln] tags
1786 }
1787
1788 $node->nodeValue = $node_val;
1789 }
1790
1791 // var_dump($p);
1792// var_dump($node->nodeValue);
1793 }
1794
1795
1796 // dump paragraph node
1797 $text = $a_dom->saveXML($parnode);
1798 $text = substr($text, 0, strlen($text) - strlen("</Paragraph>"));
1799 $text = substr($text, strpos($text, ">") + 1);
1800
1801 // replace [iln] by tags with xml representation
1802 $text = self::intLinks2xml($text);
1803
1804 // "set text"
1805 $temp_dom = domxml_open_mem(
1806 '<?xml version="1.0" encoding="UTF-8"?><Paragraph>' . $text . '</Paragraph>',
1808 $error
1809 );
1810 $temp_dom = $temp_dom->myDOMDocument;
1811
1812 if (empty($error)) {
1813 // delete children of paragraph node
1814 $children = $parnode->childNodes;
1815 while ($parnode->hasChildNodes()) {
1816 $parnode->removeChild($parnode->firstChild);
1817 }
1818
1819 // copy new content children in paragraph node
1820 $xpath_temp = new DOMXPath($temp_dom);
1821 $temp_pars = $xpath_temp->query("//Paragraph");
1822
1823 foreach ($temp_pars as $new_par_node) {
1824 $new_childs = $new_par_node->childNodes;
1825
1826 foreach ($new_childs as $new_child) {
1827 //$cloned_child = $new_child->cloneNode(true);
1828 $cloned_child = $a_dom->importNode($new_child, true);
1829 $parnode->appendChild($cloned_child);
1830 }
1831 }
1832 }
1833 }
1834 // exit;
1835 }
1836
1837
1844 public static function autoLinkGlossariesPage($a_page, $a_terms)
1845 {
1846 $a_page->buildDom();
1847 $a_dom = $a_page->getDom();
1848
1849 self::linkTermsInDom($a_dom, $a_terms);
1850
1851 $a_page->update();
1852 }
1853
1862 public static function afterPageUpdate($a_page, DOMDocument $a_domdoc, $a_xml, $a_creation)
1863 {
1864 // pc paragraph
1865 self::saveMetaKeywords($a_page, $a_domdoc);
1866 self::saveAnchors($a_page, $a_domdoc);
1867 }
1868
1874 public static function beforePageDelete($a_page)
1875 {
1876 // delete anchors
1877 self::_deleteAnchors($a_page->getParentType(), $a_page->getId(), $a_page->getLanguage());
1878 }
1879
1888 public static function afterPageHistoryEntry($a_page, DOMDocument $a_old_domdoc, $a_old_xml, $a_old_nr)
1889 {
1890 }
1891
1897 public static function saveAnchors($a_page, $a_domdoc)
1898 {
1899 self::_deleteAnchors($a_page->getParentType(), $a_page->getId(), $a_page->getLanguage());
1900
1901 // get all anchors
1902 $xpath = new DOMXPath($a_domdoc);
1903 $nodes = $xpath->query('//Anchor');
1904 $saved = array();
1905 foreach ($nodes as $node) {
1906 $name = $node->getAttribute("Name");
1907 if (trim($name) != "" && !in_array($name, $saved)) {
1908 self::_saveAnchor($a_page->getParentType(), $a_page->getId(), $a_page->getLanguage(), $name);
1909 $saved[] = $name;
1910 }
1911 }
1912 }
1913
1917 public static function _deleteAnchors($a_parent_type, $a_page_id, $a_page_lang)
1918 {
1919 global $DIC;
1920
1921 $ilDB = $DIC->database();
1922
1923 $ilDB->manipulate(
1924 "DELETE FROM page_anchor WHERE " .
1925 " page_parent_type = " . $ilDB->quote($a_parent_type, "text") .
1926 " AND page_id = " . $ilDB->quote($a_page_id, "integer") .
1927 " AND page_lang = " . $ilDB->quote($a_page_lang, "text")
1928 );
1929 }
1930
1934 public static function _saveAnchor($a_parent_type, $a_page_id, $a_page_lang, $a_anchor_name)
1935 {
1936 global $DIC;
1937
1938 $ilDB = $DIC->database();
1939
1940 $ilDB->manipulate("INSERT INTO page_anchor " .
1941 "(page_parent_type, page_id, page_lang, anchor_name) VALUES (" .
1942 $ilDB->quote($a_parent_type, "text") . "," .
1943 $ilDB->quote($a_page_id, "integer") . "," .
1944 $ilDB->quote($a_page_lang, "text") . "," .
1945 $ilDB->quote($a_anchor_name, "text") .
1946 ")");
1947 }
1948
1952 public static function _readAnchors($a_parent_type, $a_page_id, $a_page_lang = "-")
1953 {
1954 global $DIC;
1955
1956 $ilDB = $DIC->database();
1957
1958 $and_lang = ($a_page_lang != "")
1959 ? " AND page_lang = " . $ilDB->quote($a_page_lang, "text")
1960 : "";
1961
1962 $set = $ilDB->query(
1963 "SELECT * FROM page_anchor " .
1964 " WHERE page_parent_type = " . $ilDB->quote($a_parent_type, "text") .
1965 " AND page_id = " . $ilDB->quote($a_page_id, "integer") .
1966 $and_lang
1967 );
1968 $anchors = array();
1969 while ($rec = $ilDB->fetchAssoc($set)) {
1970 $anchors[] = $rec["anchor_name"];
1971 }
1972 return $anchors;
1973 }
1974
1981 public static function saveMetaKeywords($a_page, $a_domdoc)
1982 {
1983 // not nice, should be set by context per method
1984 if ($a_page->getParentType() == "gdf" ||
1985 $a_page->getParentType() == "lm") {
1986 // get existing keywords
1987 $keywords = array();
1988
1989 // find all Keyw tags
1990 $xpath = new DOMXPath($a_domdoc);
1991 $nodes = $xpath->query('//Keyw');
1992 foreach ($nodes as $node) {
1993 $k = trim(strip_tags($node->nodeValue));
1994 if (!in_array($k, $keywords)) {
1995 $keywords[] = $k;
1996 }
1997 }
1998
1999 $meta_type = ($a_page->getParentType() == "gdf")
2000 ? "gdf"
2001 : "pg";
2002 $meta_rep_id = $a_page->getParentId();
2003 $meta_id = $a_page->getId();
2004
2005 include_once("./Services/MetaData/classes/class.ilMD.php");
2006 $md_obj = new ilMD($meta_rep_id, $meta_id, $meta_type);
2007 $mkeywords = array();
2008 $lang = "";
2009 if (is_object($md_section = $md_obj->getGeneral())) {
2010 foreach ($ids = $md_section->getKeywordIds() as $id) {
2011 $md_key = $md_section->getKeyword($id);
2012 $mkeywords[] = strtolower($md_key->getKeyword());
2013 if ($lang == "") {
2014 $lang = $md_key->getKeywordLanguageCode();
2015 }
2016 }
2017 if ($lang == "") {
2018 foreach ($ids = $md_section->getLanguageIds() as $id) {
2019 $md_lang = $md_section->getLanguage($id);
2020 if ($lang == "") {
2021 $lang = $md_lang->getLanguageCode();
2022 }
2023 }
2024 }
2025 foreach ($keywords as $k) {
2026 if (!in_array(strtolower($k), $mkeywords)) {
2027 if (trim($k) != "" && $lang != "") {
2028 $md_key = $md_section->addKeyword();
2029 $md_key->setKeyword(ilUtil::stripSlashes($k));
2030 $md_key->setKeywordLanguage(new ilMDLanguageItem($lang));
2031 $md_key->save();
2032 }
2033 $mkeywords[] = strtolower($k);
2034 }
2035 }
2036 }
2037 }
2038 }
2039
2043 public function getJavascriptFiles($a_mode)
2044 {
2045 $adve_settings = new ilSetting("adve");
2046
2047 if ($a_mode != "edit" && $adve_settings->get("auto_url_linking")) {
2048 include_once("./Services/Link/classes/class.ilLinkifyUtil.php");
2050 }
2051
2052 return array();
2053 }
2054
2061 public function getOnloadCode($a_mode)
2062 {
2063 $adve_settings = new ilSetting("adve");
2064
2065 if ($a_mode != "edit" && $adve_settings->get("auto_url_linking")) {
2066 return array("il.ExtLink.autolink('.ilc_Paragraph, .ilc_page_fn_Footnote','ilc_link_ExtLink');");
2067 }
2068
2069 return array();
2070 }
2071}
user()
Definition: user.php:4
$n
Definition: RandomTest.php:85
An exception for terminatinating execution or to throw for unit testing.
const IL_INSERT_AFTER
static addParent($node, $name)
Add parent.
static replaceByChilds($node)
Replace a node by its child.
static changeName($node, $name, $keep_attributes=true)
Change name of a node.
static getTermList( $a_glo_ref_id, $searchterm="", $a_first_letter="", $a_def="", $a_tax_node=0, $a_add_amet_fields=false, array $a_amet_filter=null, $a_include_references=false)
Get all terms for given set of glossary ids.
static getLocalJsPaths()
Get paths of necessary js files.
static _lookupLogin($a_user_id)
lookup login
static _lookupId($a_user_str)
Lookup id by login.
static _getAllReferences($a_id)
get all reference ids of object
static _lookupType($a_id, $a_reference=false)
lookup object type
static xml2outputJS($s_text, $char, $a_pc_id)
Prepare content for js output.
Class ilPCParagraph.
getText($a_short_mode=false)
Get (xml) content of paragraph.
handleNextBr($a_str)
Remove preceding
static getXMLTagMap()
Get tag to bb map.
static intLinks2xml($a_text)
internal links to xml
removeTrailingBr($a_str)
Remove trailing
static _saveAnchor($a_parent_type, $a_page_id, $a_page_lang, $a_anchor_name)
Save an anchor.
getLastSavedPCId($a_pg_obj, $a_as_ajax_str=false)
Get last inserted pc ids.
static _readAnchors($a_parent_type, $a_page_id, $a_page_lang="-")
Read anchors of a page.
getType()
Need to override getType from ilPageContent to distinguish between Pararagraph and Source.
static _input2xml($a_text, $a_lang, $a_wysiwyg=0, $a_handle_lists=true)
converts user input to xml
static autoLinkGlossariesPage($a_page, $a_terms)
Auto link glossary of whole page.
static xml2output($a_text, $a_wysiwyg=false, $a_replace_lists=true, $unmask=true)
Converts xml from DB to output in edit textarea.
static linkTermsInDom($a_dom, $a_terms, $a_par_node=null)
Link terms in a dom page object in bb style.
setNode($a_node)
Set Page Content Node.
getShowLineNumbers()
get attribute showlinenumbers
autoLinkGlossaries($a_glos)
Auto link glossaries.
static saveAnchors($a_page, $a_domdoc)
Save anchors.
static handleAjaxContent($a_content)
Handle ajax content.
init()
Init page content component.
setSubCharacteristic($a_char)
set attribute subcharacteristic
createAtNode(&$node)
Create new page content (incl.
input2xml($a_text, $a_wysiwyg=0, $a_handle_lists=true)
createAfter($node)
Create paragraph node (incl.
static input2xmlReplaceLists($a_text)
Converts xml from DB to output in edit textarea.
static beforePageDelete($a_page)
Before page is being deleted.
setDownloadTitle($a_char)
set attribute download title
create(&$a_pg_obj, $a_hier_id, $a_pc_id="")
Create paragraph node (incl.
checkTextArray($text)
Check text array.
static xml2outputReplaceLists($a_text)
Replaces with *.
getAutoIndent()
Get AutoIndent (Code Paragraphs)
getDownloadTitle()
get attribute download title
static afterPageUpdate($a_page, DOMDocument $a_domdoc, $a_xml, $a_creation)
After page has been updated (or created)
setText($a_text, $a_auto_split=false)
Set (xml) content of text paragraph.
static replaceBBCode($a_text, $a_bb, $a_tag)
Replace bb code.
getOnloadCode($a_mode)
Get onload code.
static getBBMap()
Get bb to xml tag map.
setShowLineNumbers($a_char)
set attribute showlinenumbers
setLanguage($a_lang)
set language
static afterPageHistoryEntry($a_page, DOMDocument $a_old_domdoc, $a_old_xml, $a_old_nr)
After page history entry has been created.
setCharacteristic($a_char)
Set Characteristic of paragraph.
static handleAjaxContentPost($text)
Post input2xml handling of ajax content.
static saveMetaKeywords($a_page, $a_domdoc)
save all keywords
static segmentString($a_haystack, $a_needles)
Segments a string into an array at each position of a substring.
saveJS($a_pg_obj, $a_content, $a_char, $a_pc_id, $a_insert_at="")
Save input coming from ajax.
getLanguage()
get language
createBeforeNode(&$node)
Create new page content (incl.
autoSplit($a_text)
This function splits a paragraph text that has been already processed with input2xml at each header p...
getParagraphSequenceContent($a_pg_obj)
Get paragraph sequenc of current paragraph.
updatePage($a_page)
Update page object (it would be better to have this centralized and to change the constructors and pa...
getSubCharacteristic()
get attribute subcharacteristic
static _deleteAnchors($a_parent_type, $a_page_id, $a_page_lang)
Delete anchors of a page.
getCharacteristic()
Get characteristic of paragraph.
getJavascriptFiles($a_mode)
Get Javascript files.
static _getCommonBBButtons()
Get common bb buttons.
Class ilPageContent.
createPageContentNode($a_set_this_node=true)
Create page content node (always use this method first when adding a new element)
readHierId()
Read PC Id.
readPCId()
Read PC Id.
setType($a_type)
Set Type.
ILIAS Setting Class.
static strPos($a_haystack, $a_needle, $a_offset=null)
Definition: class.ilStr.php:30
static strrPos($a_haystack, $a_needle, $a_offset=null)
Definition: class.ilStr.php:39
static strIPos($a_haystack, $a_needle, $a_offset=null)
Definition: class.ilStr.php:48
static subStr($a_str, $a_start, $a_length=null)
Definition: class.ilStr.php:15
static strLen($a_string)
Definition: class.ilStr.php:78
static sortArray( $array, $a_array_sortby, $a_array_sortorder=0, $a_numeric=false, $a_keep_keys=false)
sortArray
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
static attribsToArray($a_str)
converts a string of format var1 = "val1" var2 = "val2" ... into an array
$target_id
Definition: goto.php:49
$target_type
Definition: goto.php:48
xpath_eval($xpath_context, $eval_str, $contextnode=null)
domxml_open_mem($str, $mode=0, &$error=null)
xpath_new_context($dom_document)
const DOMXML_LOAD_PARSING
exit
Definition: login.php:29
if($format !==null) $name
Definition: metadata.php:230
$i
Definition: metadata.php:24
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
$ret
Definition: parser.php:6
foreach($_POST as $key=> $value) $res
global $ilDB
success()
Definition: success.php:2
$ilUser
Definition: imgupload.php:18
$a_content
Definition: workflow.php:93
$lang
Definition: xapiexit.php:8
$DIC
Definition: xapitoken.php:46
$rows
Definition: xhr_table.php:10