/**
  * Set (xml) content of text paragraph.
  *
  * @param	string		$a_text			text content
  * @param	boolean		$a_auto_split	auto split paragraph at headlines true/false
  */
 function setText($a_text, $a_auto_split = false)
 {
     //var_dump($a_text);
     if (!is_array($a_text)) {
         $text = array(array("level" => 0, "text" => $a_text));
     } else {
         $text = $a_text;
     }
     if ($a_auto_split) {
         $text = $this->autoSplit($a_text);
     }
     // DOMXML_LOAD_PARSING, DOMXML_LOAD_VALIDATING, DOMXML_LOAD_RECOVERING
     $check = "";
     foreach ($text as $t) {
         $check .= "<Paragraph>" . $t["text"] . "</Paragraph>";
     }
     /*$temp_dom = domxml_open_mem('<?xml version="1.0" encoding="UTF-8"?><Paragraph>'.$text[0]["text"].'</Paragraph>',
     		DOMXML_LOAD_PARSING, $error);*/
     $temp_dom = domxml_open_mem('<?xml version="1.0" encoding="UTF-8"?><Paragraph>' . $check . '</Paragraph>', DOMXML_LOAD_PARSING, $error);
     //$this->text = $a_text;
     // remove all childs
     if (empty($error)) {
         $temp_dom = domxml_open_mem('<?xml version="1.0" encoding="UTF-8"?><Paragraph>' . $text[0]["text"] . '</Paragraph>', DOMXML_LOAD_PARSING, $error);
         // delete children of paragraph node
         $children = $this->par_node->child_nodes();
         for ($i = 0; $i < count($children); $i++) {
             $this->par_node->remove_child($children[$i]);
         }
         // copy new content children in paragraph node
         $xpc = xpath_new_context($temp_dom);
         $path = "//Paragraph";
         $res =& xpath_eval($xpc, $path);
         if (count($res->nodeset) == 1) {
             $new_par_node =& $res->nodeset[0];
             $new_childs = $new_par_node->child_nodes();
             for ($i = 0; $i < count($new_childs); $i++) {
                 $cloned_child =& $new_childs[$i]->clone_node(true);
                 $this->par_node->append_child($cloned_child);
             }
             $orig_characteristic = $this->getCharacteristic();
             // if headlines are entered and current characteristic is a headline
             // use no characteristic as standard
             if (count($text) > 1 && substr($orig_characteristic, 0, 8) == "Headline") {
                 $orig_characteristic = "";
             }
             if ($text[0]["level"] > 0) {
                 $this->par_node->set_attribute("Characteristic", 'Headline' . $text[0]["level"]);
             }
         }
         $ok = true;
         $c_node = $this->node;
         // add other chunks afterwards
         for ($i = 1; $i < count($text); $i++) {
             if ($ok) {
                 $next_par = new ilPCParagraph($this->dom);
                 $next_par->createAfter($c_node);
                 $next_par->setLanguage($this->getLanguage());
                 if ($text[$i]["level"] > 0) {
                     $next_par->setCharacteristic("Headline" . $text[$i]["level"]);
                 } else {
                     $next_par->setCharacteristic($orig_characteristic);
                 }
                 $ok = $next_par->setText($text[$i]["text"], false);
                 $c_node = $next_par->node;
             }
         }
         return true;
     } else {
         // We want the correct number of \n here to have the real lines numbers
         $text = str_replace("<br>", "\n", $check);
         // replace <br> with \n to get correct line
         $text = str_replace("<br/>", "\n", $text);
         $text = str_replace("<br />", "\n", $text);
         $text = str_replace("</SimpleListItem>", "</SimpleListItem>\n", $text);
         $text = str_replace("<SimpleBulletList>", "\n<SimpleBulletList>", $text);
         $text = str_replace("<SimpleNumberedList>", "\n<SimpleNumberedList>", $text);
         $text = str_replace("<Paragraph>\n", "<Paragraph>", $text);
         $text = str_replace("</Paragraph>", "</Paragraph>\n", $text);
         include_once "./Services/Dom/classes/class.ilDomDocument.php";
         $doc = new ilDOMDocument();
         $text = '<?xml version="1.0" encoding="UTF-8"?><Paragraph>' . $text . '</Paragraph>';
         //echo htmlentities($text);
         $this->success = $doc->loadXML($text);
         $error = $doc->errors;
         $estr = "";
         foreach ($error as $e) {
             $e = str_replace(" in Entity", "", $e);
             $estr .= $e . "<br />";
         }
         return $estr;
     }
 }
Esempio n. 2
0
 function importCell($lng, &$cellNode, &$aRow)
 {
     /*echo "add Cell";
     		var_dump($cellNode);*/
     $aCell = $this->addCell($aRow);
     $par = new ilPCParagraph($this->getPage());
     $par->createAtNode($aCell);
     $par->setText($par->input2xml($this->extractText($cellNode)));
     $par->setCharacteristic("TableContent");
     $par->setLanguage($lng);
     $this->importCellAttributes($cellNode, $aCell);
 }