function getCategories($root) { $xpath = xpath_new_context($root); $listNode = xpath_eval($xpath, "UL"); if (sizeof($listNode->nodeset) == 0) { $xpath = xpath_new_context($root); $nodes = xpath_eval($xpath, "LI"); } else { $xpath = xpath_new_context($listNode->nodeset[0]); $nodes = xpath_eval($xpath, "LI"); } return $nodes->nodeset; }
/** * export lm_data-table to xml-structure * * @param integer obj_id * @param integer depth * @param integer left left border of nested-set-structure * @param integer right right border of nested-set-structure * @access public * @return string xml */ function exportRekursiv($obj_id, $depth, $left, $right) { global $ilDB; // Jetzt alle lm_data anhand der obj_id auslesen. $query = "SELECT *\n FROM lm_tree, lm_data\n WHERE lm_tree.lm_id = " . $ilDB->quote($obj_id, "integer") . " \n AND lm_tree.child = lm_data.obj_id \n AND ( lm_data.type = 'st' OR lm_data.type = 'pg' )\n AND lm_tree.depth = " . $ilDB->quote($depth, "integer") . "\n AND lm_tree.lft > " . $ilDB->quote($left, "integer") . " and lm_tree.rgt < " . $ilDB->quote($right, "integer") . "\n ORDER BY lm_tree.lft"; $result = $ilDB->query($query); while (is_array($row = $ilDB->fetchAssoc($result))) { if ($row["type"] == "st") { $xml .= "<StructureObject>"; $nested = new ilNestedSetXML(); $xml .= $nested->export($row["obj_id"], "st"); $xml .= "\n"; $xml .= $this->exportRekursiv($obj_id, $depth + 1, $row["lft"], $row["rgt"]); $xml .= "</StructureObject>"; } if ($row["type"] == "pg") { $query = "SELECT * FROM page_object WHERE page_id= " . $ilDB->quote($row["obj_id"], "integer"); $result2 = $this->ilias->db->query($query); $row2 = $result2->fetchRow(DB_FETCHMODE_ASSOC); $PO = $row2["content"] . "\n"; if (stristr($PO, "MediaObject")) { $dom = domxml_open_mem($PO); $xpc = xpath_new_context($dom); $path = "//MediaObject/MediaAlias"; $res =& xpath_eval($xpc, $path); for ($i = 0; $i < count($res->nodeset); $i++) { $id_arr = explode("_", $res->nodeset[$i]->get_attribute("OriginId")); $mob_id = $id_arr[count($id_arr) - 1]; $this->mob_ids[$mob_id] = true; } } $nested = new ilNestedSetXML(); $mdxml = $nested->export($row["obj_id"], "pg"); $PO = str_replace("<PageObject>", "<PageObject>\n{$mdxml}\n", $PO); $xml .= $PO; } } return $xml; }
function importHtml($lng, $htmlTable) { $dummy = ilUtil::stripSlashes($htmlTable, false); //echo htmlentities($dummy); $dom = @domxml_open_mem($dummy, DOMXML_LOAD_PARSING, $error); if ($dom) { $xpc = @xpath_new_context($dom); // extract first table object $path = "//table[1] | //Table[1]"; $res = @xpath_eval($xpc, $path); if (count($res->nodeset) == 0) { $error = "Could not find a table root node"; } if (empty($error)) { for ($i = 0; $i < count($res->nodeset); $i++) { $node = $res->nodeset[$i]; $this->importTableAttributes($node); if ($node->has_child_nodes()) { foreach ($node->child_nodes() as $n) { if ($n->node_type() == XML_ELEMENT_NODE && strcasecmp($n->node_name(), "tr") == 0) { $this->importRow($lng, $n); } } } } } $dom->free(); } if (is_array($error)) { $errmsg = ""; foreach ($error as $errorline) { # Loop through all errors $errmsg .= "[" . $errorline['line'] . ", " . $errorline['col'] . "]: " . $errorline['errormessage'] . " at Node '" . $errorline['nodename'] . "'<br />"; } } else { $errmsg = $error; } if (empty($errmsg)) { return true; } $_SESSION["message"] = $errmsg; return false; }
function xpath_eval($eval_str) { return xpath_eval($this, $eval_str); }
function wms_layer4html($layer) { $estilos = wms_estilos($layer); if (count($estilos) > 0) { $ctxl = xpath_new_context($layer); $xp_namel = xpath_eval($ctxl, "/Name"); if (wms_xpnode2content($xp_namel) == "") { $xp_namel = xpath_eval($ctxl, "/name"); } $txt_namel = wms_xpnode2content($xp_namel); $html .= wms_layer3html($layer); foreach ($estilos as $estilo) { $html .= wms_layer2html($estilo, "estilo", $txt_namel); } } else { $html .= wms_layer2html($layer, "tema", ""); } return $html; }
private function generatePreview() { $xml = $this->getXMLContent(); $dom = @domxml_open_mem($xml, DOMXML_LOAD_PARSING, $error); $xpc = xpath_new_context($dom); $path = "////PlaceHolder"; $res =& xpath_eval($xpc, $path); foreach ($res->nodeset as $item) { $height = $item->get_attribute("Height"); $height = eregi_replace("px", "", $height); $height = $height / 10; $item->set_attribute("Height", $height . "px"); } $xsl = file_get_contents($this->getXSLPath()); $xml = $dom->dump_mem(0, "UTF-8"); $args = array('/_xml' => $xml, '/_xsl' => $xsl); $xh = xslt_create(); $output = xslt_process($xh, "arg:/_xml", "arg:/_xsl", NULL, $args, NULL); xslt_error($xh); xslt_free($xh); return $output; }
function getLayoutLinkTargets() { if (!is_object($this->layout_doc)) { return array(); } $xpc = xpath_new_context($this->layout_doc); $path = "/ilLayout/ilLinkTargets/LinkTarget"; $res = xpath_eval($xpc, $path); $targets = array(); for ($i = 0; $i < count($res->nodeset); $i++) { $type = $res->nodeset[$i]->get_attribute("Type"); $frame = $res->nodeset[$i]->get_attribute("Frame"); $onclick = $res->nodeset[$i]->get_attribute("OnClick"); $targets[$type] = array("Type" => $type, "Frame" => $frame, "OnClick" => $onclick); } return $targets; }
function _makeXSLTInclude(&$main_xsl) { $xpath = xpath_new_context($main_xsl); $res = xpath_eval($xpath, "//include"); $num = sizeof($res->nodeset); $needReCall = false; for ($i = 0; $i < $num; $i++) { $type = $res->nodeset[$i]->get_attribute("type"); if ($type != 'subtemplate') { /* $dom = new DomDocument("1.0"); $node = $dom->createElement("xsl:call-template", ""); /* = new DomElement( "xsl:call-template", "", "http://www.w3.org/1999/XSL/Transform"); // $dom->appendChild($node); $node->setAttribute( "name", "InsertBlock" ); $param = $dom->createElement("xsl:with-param"); $node->appendChild($param); */ // ñîçäàåì ýëåìåíò // $dom = domxml_new_doc("1.0"); $dom = $this->_xslt; $node = $this->_xslt->create_element("xsl:call-template", ""); $node->set_attribute("name", "InsertBlock"); // // $param = $dom->createElement("xsl:with-param", ""); // $param = $node->appendChild($param); $param = $node->new_child("xsl:with-param"); if (empty($type) || $type == 'default') { $param->set_content($res->nodeset[$i]->get_attribute("object")); } else { if ($type == 'condition') { $childs = $res->nodeset[$i]->child_nodes(); //print_r( $childs ); if (is_array($childs)) { $cnum = sizeof($childs); for ($j = 0; $j < $cnum; $j++) { $clone = $childs[$j]->clone_node(true); //$clone->set_namespace( $childs[$j]prefix(); $param->append_child($clone); } //foreach ( $childs as $child ) { //} } } } $param->set_attribute("name", "id"); $res->nodeset[$i]->replace_node($node); } else { $name = $res->nodeset[$i]->get_attribute("name"); if (isset($this->_templates['sub']) && array_key_exists($name, $this->_templates['sub'])) { $nodes = $this->_templates['sub'][$name]->getText(); if (is_array($nodes)) { $nnum = sizeof($nodes); for ($j = 0; $j < $nnum; $j++) { //print_r( $nodes[$j] ); // TODO: analyze it nafig // echo $res->nodeset[$i]->get_content(); //print_r($res->nodeset[$i]); /* echo $j."of $nnum vs $i<hr/>"; print_r($nodes[$j]); echo "<hr/>"; print_r($res->nodeset[$i]); echo "<hr/>"; print_r($res->nodeset[$i]); echo "<hr/>"; */ // echo $res->nodeset[$i]->get_content(); // $res->nodeset[$i]->insert_before( $nodes[$j], $res->nodeset[$i]); $res->nodeset[$i]->append_sibling($nodes[$j]); // if (in_array($)) /* if ($res->nodeset[$i]->get_content() != "") $res->nodeset[$i]->insert_before( $nodes[$i], $res->nodeset[$i] ); else $res->nodeset[$i]->append_child( $nodes[$j], $res->nodeset[$i] ); */ /* if ( $nodes[$j]->type == 1 ) { $this->_makeXSLTInclude( $nodes[$j] ); }*/ } } } $p = $res->nodeset[$i]->parent_node(); //print_r( $p ); $p->remove_child($res->nodeset[$i]); $needReCall = true; } } /**/ if ($needReCall) { $this->_makeXSLTInclude($main_xsl); } /**/ }
/** * Get initial opened content * * @param */ function getInitialOpenedContent() { $this->buildDom(); $xpc = xpath_new_context($this->dom); $path = "//PageObject/InitOpenedContent"; $res = xpath_eval($xpc, $path); $il_node = null; if (count($res->nodeset) > 0) { $init_node = $res->nodeset[0]; $childs = $init_node->child_nodes(); for ($i = 0; $i < count($childs); $i++) { if ($childs[$i]->node_name() == "IntLink") { $il_node = $childs[$i]; } } } if (!is_null($il_node)) { $id = $il_node->get_attribute("Target"); $link_type = $il_node->get_attribute("Type"); $target = $il_node->get_attribute("TargetFrame"); switch ($link_type) { case "MediaObject": $type = "media"; break; case "PageObject": $type = "page"; break; case "GlossaryItem": $type = "term"; break; } include_once "./Services/Link/classes/class.ilInternalLink.php"; $id = ilInternalLink::_extractObjIdOfTarget($id); return array("id" => $id, "type" => $type, "target" => $target); } return array(); }
/** * Delete all map areas */ function deleteAllMapAreas() { $xpc = xpath_new_context($this->dom); $path = "//PageContent[@HierId = '" . $this->hier_id . "']/" . $this->parent_node_name . "/MediaAliasItem[@Purpose='" . $this->purpose . "']/MapArea"; $res =& xpath_eval($xpc, $path); for ($i = 0; $i < count($res->nodeset); $i++) { $res->nodeset[$i]->unlink_node($res->nodeset[$i]); } }
/** * Modify page content after xsl * * @param string $a_output * @return string */ function modifyPageContentPostXsl($a_output, $outputmode = "presentation") { $dom = $this->getPage()->getDom(); $xpc = xpath_new_context($dom); $path = "//Paragraph"; //"[@Characteristic = 'Code']"; $res =& xpath_eval($xpc, $path); for ($i = 0; $i < count($res->nodeset); $i++) { $context_node = $res->nodeset[$i]; $char = $context_node->get_attribute('Characteristic'); if ($char != "Code") { continue; } $n = $context_node->parent_node(); $char = $context_node->get_attribute('Characteristic'); $subchar = $context_node->get_attribute('SubCharacteristic'); $showlinenumbers = $context_node->get_attribute('ShowLineNumbers'); $downloadtitle = $context_node->get_attribute('DownloadTitle'); $autoindent = $context_node->get_attribute('AutoIndent'); $content = ""; // get XML Content $childs = $context_node->child_nodes(); for ($j = 0; $j < count($childs); $j++) { $content .= $dom->dump_node($childs[$j]); } while ($context_node->has_child_nodes()) { $node_del = $context_node->first_child(); $context_node->remove_child($node_del); } $content = str_replace("<br />", "<br/>", utf8_decode($content)); $content = str_replace("<br/>", "\n", $content); $rownums = count(split("\n", $content)); $plain_content = html_entity_decode($content); $plain_content = preg_replace("/\\&#x([1-9a-f]{2});?/ise", "chr (base_convert (\\1, 16, 10))", $plain_content); $plain_content = preg_replace("/\\&#(\\d+);?/ise", "chr (\\1)", $plain_content); $content = utf8_encode($this->highlightText($plain_content, $subchar, $autoindent)); $content = str_replace("&lt;", "<", $content); $content = str_replace("&gt;", ">", $content); // $content = str_replace("&", "&", $content); //var_dump($content); $rows = "<tr valign=\"top\">"; $rownumbers = ""; $linenumbers = ""; //if we have to show line numbers if (strcmp($showlinenumbers, "y") == 0) { $linenumbers = "<td nowrap=\"nowrap\" class=\"ilc_LineNumbers\" >"; $linenumbers .= "<pre class=\"ilc_Code\">"; for ($j = 0; $j < $rownums; $j++) { $indentno = strlen($rownums) - strlen($j + 1) + 2; $rownumeration = $j + 1; $linenumbers .= "<span class=\"ilc_LineNumber\">{$rownumeration}</span>"; if ($j < $rownums - 1) { $linenumbers .= "\n"; } } $linenumbers .= "</pre>"; $linenumbers .= "</td>"; } $rows .= $linenumbers . "<td class=\"ilc_Sourcecode\"><pre class=\"ilc_Code\">" . $content . "</pre></td>"; $rows .= "</tr>"; // fix for ie explorer which is not able to produce empty line feeds with <br /><br />; // workaround: add a space after each br. $newcontent = str_replace("\n", "<br/>", $rows); // fix for IE $newcontent = str_replace("<br/><br/>", "<br/> <br/>", $newcontent); // falls drei hintereinander... $newcontent = str_replace("<br/><br/>", "<br/> <br/>", $newcontent); // workaround for preventing template engine // from hiding paragraph text that is enclosed // in curly brackets (e.g. "{a}", see ilLMEditorGUI::executeCommand()) $newcontent = str_replace("{", "{", $newcontent); $newcontent = str_replace("}", "}", $newcontent); //echo htmlentities($newcontent); $a_output = str_replace("[[[[[Code;" . ($i + 1) . "]]]]]", $newcontent, $a_output); if ($outputmode != "presentation" && is_object($this->getPage()->getOfflineHandler()) && trim($downloadtitle) != "") { // call code handler for offline versions $this->getPage()->getOfflineHandler()->handleCodeParagraph($this->getPage()->getId(), $i + 1, $downloadtitle, $plain_content); } } return $a_output; }
/** * Perform automatic modifications (may be overwritten by sub classes) */ function performAutomaticModifications() { if ($this->getGlossaryId() > 0) { // we fix glossary links here $this->buildDom(); $xpc = xpath_new_context($this->dom); $path = "//IntLink[@Type='GlossaryItem']"; $res =& xpath_eval($xpc, $path); for ($i = 0; $i < count($res->nodeset); $i++) { $target = $res->nodeset[$i]->get_attribute("Target"); //echo "<br>".$target; $tarr = explode("_", $target); $term_id = $tarr[count($tarr) - 1]; if (is_int(strpos($target, "__")) && $term_id > 0) { include_once "./Modules/Glossary/classes/class.ilGlossaryTerm.php"; //echo "<br>-".ilGlossaryTerm::_lookGlossaryID($term_id)."-".$this->getGlossaryId()."-"; if (ilGlossaryTerm::_lookGlossaryID($term_id) != $this->getGlossaryId()) { // copy the glossary term from glossary a to b $new_id = ilGlossaryTerm::_copyTerm($term_id, $this->getGlossaryId()); $res->nodeset[$i]->set_attribute("Target", "il__git_" . $new_id); } } } } //exit; }
/** * Edit data of table */ function editData() { global $lng, $ilCtrl; if (!ilPageEditorGUI::_doJSEditing()) { return $this->editDataCl(); } //var_dump($_GET); //var_dump($_POST); $this->setTabs(); $this->displayValidationError(); include_once "./Services/COPage/classes/class.ilPCParagraph.php"; $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.tabledata2.html", "Services/COPage"); $dtpl = $this->tpl; //$dtpl = new ilTemplate("tpl.tabledata.html", true, true, "Services/COPage"); $dtpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this, "tableAction")); // $dtpl->setVariable("BB_MENU", $this->getBBMenu("cell_0_0")); // $this->tpl->addJavascript("./Services/COPage/phpBB/3_0_5/editor.js"); // $this->tpl->addJavascript("./Services/COPage/js/page_editing.js"); $this->tpl->setVariable("WYSIWYG_ACTION", $ilCtrl->getFormAction($this, "updateJS")); // get all rows $xpc = xpath_new_context($this->dom); $path = "//PageContent[@HierId='" . $this->getHierId() . "']" . "/Table/TableRow"; $res =& xpath_eval($xpc, $path); for ($i = 0; $i < count($res->nodeset); $i++) { $xpc2 = xpath_new_context($this->dom); $path2 = "//PageContent[@HierId='" . $this->getHierId() . "']" . "/Table/TableRow[{$i}+1]/TableData"; $res2 =& xpath_eval($xpc2, $path2); // if this is the first row -> col icons if ($i == 0) { for ($j = 0; $j < count($res2->nodeset); $j++) { if ($j == 0) { $dtpl->touchBlock("empty_td"); } if ($j == 0) { if (count($res2->nodeset) == 1) { $move_type = "none"; } else { $move_type = "forward"; } } else { if ($j == count($res2->nodeset) - 1) { $move_type = "backward"; } else { $move_type = "both"; } } $dtpl->setCurrentBlock("col_icon"); $dtpl->setVariable("COL_ICON_ALT", $lng->txt("content_column")); $dtpl->setVariable("COL_ICON", ilUtil::getImagePath("col.png")); $dtpl->setVariable("COL_ONCLICK", "COL_" . $move_type); $dtpl->setVariable("NR", $j); $dtpl->parseCurrentBlock(); } $dtpl->setCurrentBlock("row"); $dtpl->parseCurrentBlock(); } for ($j = 0; $j < count($res2->nodeset); $j++) { // first col: row icons if ($j == 0) { if ($i == 0) { if (count($res->nodeset) == 1) { $move_type = "none"; } else { $move_type = "forward"; } } else { if ($i == count($res->nodeset) - 1) { $move_type = "backward"; } else { $move_type = "both"; } } $dtpl->setCurrentBlock("row_icon"); $dtpl->setVariable("ROW_ICON_ALT", $lng->txt("content_row")); $dtpl->setVariable("ROW_ICON", ilUtil::getImagePath("row.png")); $dtpl->setVariable("ROW_ONCLICK", "ROW_" . $move_type); $dtpl->setVariable("NR", $i); $dtpl->parseCurrentBlock(); } // cell if ($res2->nodeset[$j]->get_attribute("Hidden") != "Y") { $dtpl->setCurrentBlock("cell"); if (is_array($_POST["cmd"]) && key($_POST["cmd"]) == "update") { $s_text = ilUtil::stripSlashes("cell_" . $i . "_" . $j, false); } else { $s_text = ilPCParagraph::xml2output($this->content_obj->getCellText($i, $j), true, false); include_once "./Services/COPage/classes/class.ilPCParagraphGUI.php"; $s_text = ilPCParagraphGUI::xml2outputJS($s_text, "TableContent", $this->content_obj->readPCId() . "_" . $i . "_" . $j); } $dtpl->setVariable("PAR_TA_NAME", "cell[" . $i . "][" . $j . "]"); $dtpl->setVariable("PAR_TA_ID", "cell_" . $i . "_" . $j); $dtpl->setVariable("PAR_TA_CONTENT", $s_text); $cs = $res2->nodeset[$j]->get_attribute("ColSpan"); $rs = $res2->nodeset[$j]->get_attribute("RowSpan"); $dtpl->setVariable("WIDTH", "140"); $dtpl->setVariable("HEIGHT", "80"); if ($cs > 1) { $dtpl->setVariable("COLSPAN", 'colspan="' . $cs . '"'); $dtpl->setVariable("WIDTH", 140 + ($cs - 1) * 146); } if ($rs > 1) { $dtpl->setVariable("ROWSPAN", 'rowspan="' . $rs . '"'); $dtpl->setVariable("HEIGHT", 80 + ($rs - 1) * 86); } $dtpl->parseCurrentBlock(); } } $dtpl->setCurrentBlock("row"); $dtpl->parseCurrentBlock(); } // init menues $types = array("row", "col"); $moves = array("none", "backward", "both", "forward"); $commands = array("row" => array("newRowAfter" => "cont_ed_new_row_after", "newRowBefore" => "cont_ed_new_row_before", "moveRowUp" => "cont_ed_row_up", "moveRowDown" => "cont_ed_row_down", "deleteRow" => "cont_ed_delete_row"), "col" => array("newColAfter" => "cont_ed_new_col_after", "newColBefore" => "cont_ed_new_col_before", "moveColLeft" => "cont_ed_col_left", "moveColRight" => "cont_ed_col_right", "deleteCol" => "cont_ed_delete_col")); foreach ($types as $type) { foreach ($moves as $move) { foreach ($commands[$type] as $command => $lang_var) { if ($move == "none" && substr($command, 0, 4) == "move") { continue; } if ($move == "backward" && in_array($command, array("movedown", "moveright")) || $move == "forward" && in_array($command, array("moveup", "moveleft"))) { continue; } $this->tpl->setCurrentBlock("menu_item"); $this->tpl->setVariable("MENU_ITEM_TITLE", $lng->txt($lang_var)); $this->tpl->setVariable("CMD", $command); $this->tpl->setVariable("TYPE", $type); $this->tpl->parseCurrentBlock(); } $this->tpl->setCurrentBlock("menu"); $this->tpl->setVariable("TYPE", $type); $this->tpl->setVariable("MOVE", $move); $this->tpl->parseCurrentBlock(); } } $this->tpl->setVariable("FORMACTION2", $ilCtrl->getFormAction($this, "tableAction")); $this->tpl->setVariable("TXT_ACTION", $this->lng->txt("cont_table")); // js editing preparation include_once "./Services/YUI/classes/class.ilYuiUtil.php"; ilYuiUtil::initDragDrop(); ilYuiUtil::initConnection(); ilYuiUtil::initPanel(false); $GLOBALS["tpl"]->addJavascript("Services/RTE/tiny_mce_3_3_9_2/il_tiny_mce_src.js"); $GLOBALS["tpl"]->addJavaScript("./Services/COPage/js/ilcopagecallback.js"); $GLOBALS["tpl"]->addJavascript("Services/COPage/js/page_editing.js"); $GLOBALS["tpl"]->addOnloadCode("var preloader = new Image();\n\t\t\tpreloader.src = './templates/default/images/loader.gif';\n\t\t\tilCOPage.setContentCss('" . ilObjStyleSheet::getContentStylePath((int) $this->getStyleId()) . ", " . ilUtil::getStyleSheetLocation() . ", ./Services/COPage/css/tiny_extra.css');\n\t\t\tilCOPage.editTD('cell_0_0');\n\t\t\t\t"); $this->tpl->setVariable("IL_TINY_MENU", ilPageObjectGUI::getTinyMenu($this->pg_obj->getParentType(), false, $this->pg_obj->getParentType() == "wpg", false, $this->getStyleId(), false, true)); }
/** * get the values as an array from the childtags from the first match of the xpath expression * * @param string xpath expression * @return array with key->value of subtags * @access public */ function getXpathChildValues($expr) { $xpath = $this->xmldoc->xpath_new_context(); $xnode = xpath_eval($xpath, $expr); if (isset($xnode->nodeset[0])) { foreach ($xnode->nodeset[0]->children() as $child) { $children = $child->children(); $value[$child->{$this->tagname}] = $children[0]->content; } return $value; } return null; }
/** * Set data of cells */ function setData($a_data) { $ok = true; //var_dump($a_data); if (is_array($a_data)) { foreach ($a_data as $i => $row) { if (is_array($row)) { foreach ($row as $j => $cell) { //echo "<br><br>=".$cell."="; $temp_dom = @domxml_open_mem('<?xml version="1.0" encoding="UTF-8"?><Paragraph>' . $cell . '</Paragraph>', DOMXML_LOAD_PARSING, $error); $par_node = $this->getCellNode($i, $j); //echo "<br>=".htmlentities($this->dom->dump_node($par_node))."="; //echo "<br>-$i-$j-$cell-"; // remove all childs if (empty($error) && is_object($par_node)) { // delete children of paragraph node $children = $par_node->child_nodes(); for ($k = 0; $k < count($children); $k++) { $par_node->remove_child($children[$k]); } // 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 ($l = 0; $l < count($new_childs); $l++) { $cloned_child = $new_childs[$l]->clone_node(true); $par_node->append_child($cloned_child); //echo "<br>=".htmlentities($this->dom->dump_node($cloned_child))."="; } } } else { if (!empty($error)) { return $error; } } } } } } //exit; return true; }
/** * Returns additional menu informations decoded in the file that appears in the menu. * * You should subclass this method to make it work with your own * file formats. I used a simple XML format to store the content. * * @param string filename */ function exploreFile($file) { $xml = join('', @file($file)); if (!$xml) { return array(); } $doc = xmldoc($xml); $xpc = xpath_new_context($doc); $menu = xpath_eval($xpc, '//menu'); $node =& $menu->nodeset[0]; return array('title' => $node->content); }
/** * Get trigger nodes */ function getTriggerNodes($a_hier_id, $a_pc_id = "") { if ($a_pc_id != "") { $xpc = xpath_new_context($this->dom); $path = "//PageContent[@PCID = '" . $a_pc_id . "']/InteractiveImage/Trigger"; $res =& xpath_eval($xpc, $path); if (count($res->nodeset) > 0) { return $res->nodeset; } return array(); } $xpc = xpath_new_context($this->dom); $path = "//PageContent[@HierId = '" . $a_hier_id . "']/InteractiveImage/Trigger"; $res =& xpath_eval($xpc, $path); if (count($res->nodeset) > 0) { return $res->nodeset; } }
/** * 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; } }
/** * Set ExtLink Title * * @param * @return */ function setExtLinkTitle($a_nr, $a_title) { if ($this->getPcId() != "") { $xpc = xpath_new_context($this->dom); $path = "//PageContent[@PCID = '" . $this->getPcId() . "']/InteractiveImage/MediaAliasItem/MapArea[@Id='" . $a_nr . "']/ExtLink"; $res = xpath_eval($xpc, $path); if (count($res->nodeset) > 0) { $res->nodeset[0]->set_content($a_title); } return; } $xpc = xpath_new_context($this->dom); $path = "//PageContent[@HierId = '" . $this->hier_id . "']/InteractiveImage/MediaAliasItem/MapArea[@Id='" . $a_nr . "']/ExtLink"; $res =& xpath_eval($xpc, $path); if (count($res->nodeset) > 0) { $res->nodeset[0]->set_content($a_title); } }