00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 require_once("content/classes/Pages/class.ilPageContent.php");
00026 require_once("content/classes/Pages/class.ilPCParagraph.php");
00027 require_once("./syntax_highlight/php/Beautifier/Init.php");
00028 require_once("./syntax_highlight/php/Output/Output_css.php");
00029
00030
00031 define("IL_INSERT_BEFORE", 0);
00032 define("IL_INSERT_AFTER", 1);
00033 define("IL_INSERT_CHILD", 2);
00034
00035 define ("IL_CHAPTER_TITLE", "st_title");
00036 define ("IL_PAGE_TITLE", "pg_title");
00037 define ("IL_NO_HEADER", "none");
00038
00050 class ilPageObject
00051 {
00052 var $id;
00053 var $ilias;
00054 var $dom;
00055 var $xml;
00056 var $encoding;
00057 var $node;
00058 var $cur_dtd = "ilias_pg_3_7.dtd";
00059 var $contains_int_link;
00060 var $needs_parsing;
00061 var $parent_type;
00062 var $parent_id;
00063 var $update_listeners;
00064 var $update_listener_cnt;
00065 var $offline_handler;
00066 var $dom_builded;
00067
00072 function ilPageObject($a_parent_type, $a_id = 0, $a_halt = true)
00073 {
00074 global $ilias;
00075
00076 $this->parent_type = $a_parent_type;
00077 $this->id = $a_id;
00078 $this->ilias =& $ilias;
00079
00080 $this->contains_int_link = false;
00081 $this->needs_parsing = false;
00082 $this->update_listeners = array();
00083 $this->update_listener_cnt = 0;
00084 $this->dom_builded = false;
00085 $this->halt_on_error = $a_halt;
00086 $this->page_not_found = false;
00087 $this->encoding = "UTF-8";
00088 if($a_id != 0)
00089 {
00090 $this->read();
00091 }
00092 }
00093
00094 function haltOnError($a_halt)
00095 {
00096 $this->halt_on_error = $a_halt;
00097 }
00098
00102 function read()
00103 {
00104 global $ilBench;
00105
00106 $ilBench->start("ContentPresentation", "ilPageObject_read");
00107
00108 $query = "SELECT * FROM page_object WHERE page_id = '".$this->id."' ".
00109 "AND parent_type='".$this->getParentType()."'";
00110 $pg_set = $this->ilias->db->query($query);
00111 if (!($this->page_record = $pg_set->fetchRow(DB_FETCHMODE_ASSOC)))
00112 {
00113 if ($this->halt_on_error)
00114 {
00115 echo "Error: Page ".$this->id." is not in database".
00116 " (parent type ".$this->getParentType().")."; exit;
00117 }
00118 else
00119 {
00120 $this->page_not_found = true;
00121 return;
00122 }
00123 }
00124 $this->xml = $this->page_record["content"];
00125 $this->setParentId($this->page_record["parent_id"]);
00126
00127 $ilBench->stop("ContentPresentation", "ilPageObject_read");
00128 }
00129
00136 function _exists($a_parent_type, $a_id)
00137 {
00138 global $ilDB;
00139
00140 $query = "SELECT * FROM page_object WHERE page_id = ".$ilDB->quote($a_id)." ".
00141 "AND parent_type= ".$ilDB->quote($a_parent_type);
00142 $set = $ilDB->query($query);
00143 if ($row = $set->fetchRow(DB_FETCHMODE_ASSOC))
00144 {
00145 return true;
00146 }
00147 else
00148 {
00149 return false;
00150 }
00151 }
00152
00153
00154 function buildDom()
00155 {
00156 global $ilBench;
00157
00158 if ($this->dom_builded)
00159 {
00160 return;
00161 }
00162
00163
00164
00165 $ilBench->start("ContentPresentation", "ilPageObject_buildDom");
00166 $this->dom = @domxml_open_mem($this->getXMLContent(true), DOMXML_LOAD_VALIDATING, $error);
00167 $ilBench->stop("ContentPresentation", "ilPageObject_buildDom");
00168
00169
00170
00171
00172
00173 $xpc = xpath_new_context($this->dom);
00174 $path = "//PageObject";
00175 $res =& xpath_eval($xpc, $path);
00176 if (count($res->nodeset) == 1)
00177 {
00178 $this->node =& $res->nodeset[0];
00179 }
00180
00181 if (empty($error))
00182 {
00183 $this->dom_builded = true;
00184 return true;
00185 }
00186 else
00187 {
00188 return $error;
00189 }
00190 }
00191
00192 function freeDom()
00193 {
00194
00195 unset($this->dom);
00196 }
00197
00198 function &getDom()
00199 {
00200 return $this->dom;
00201 }
00202
00206 function setId($a_id)
00207 {
00208 $this->id = $a_id;
00209 }
00210
00211 function getId()
00212 {
00213 return $this->id;
00214 }
00215
00216 function setParentId($a_id)
00217 {
00218 $this->parent_id = $a_id;
00219 }
00220
00221 function getParentId()
00222 {
00223 return $this->parent_id;
00224 }
00225
00226 function setParentType($a_type)
00227 {
00228 $this->parent_type = $a_type;
00229 }
00230
00231 function getParentType()
00232 {
00233 return $this->parent_type;
00234 }
00235
00236 function addUpdateListener(&$a_object, $a_method, $a_parameters = "")
00237 {
00238 $cnt = $this->update_listener_cnt;
00239 $this->update_listeners[$cnt]["object"] =& $a_object;
00240 $this->update_listeners[$cnt]["method"] = $a_method;
00241 $this->update_listeners[$cnt]["parameters"] = $a_parameters;
00242 $this->update_listener_cnt++;
00243 }
00244
00245 function callUpdateListeners()
00246 {
00247 for($i=0; $i<$this->update_listener_cnt; $i++)
00248 {
00249 $object =& $this->update_listeners[$i]["object"];
00250 $method = $this->update_listeners[$i]["method"];
00251 $parameters = $this->update_listeners[$i]["parameters"];
00252 $object->$method($parameters);
00253 }
00254 }
00255
00256 function &getContentObject($a_hier_id)
00257 {
00258 global $ilCtrl;
00259
00260
00261
00262
00263 $cont_node =& $this->getContentNode($a_hier_id);
00264
00265 switch($cont_node->node_name())
00266 {
00267 case "PageContent":
00268 $child_node =& $cont_node->first_child();
00269
00270 switch($child_node->node_name())
00271 {
00272 case "Paragraph":
00273 require_once("content/classes/Pages/class.ilPCParagraph.php");
00274 $par =& new ilPCParagraph($this->dom);
00275 $par->setNode($cont_node);
00276 $par->setHierId($a_hier_id);
00277 return $par;
00278
00279 case "Table":
00280 require_once("content/classes/Pages/class.ilPCTable.php");
00281 $tab =& new ilPCTable($this->dom);
00282 $tab->setNode($cont_node);
00283 $tab->setHierId($a_hier_id);
00284 return $tab;
00285
00286 case "MediaObject":
00287 require_once("content/classes/Media/class.ilObjMediaObject.php");
00288
00289 $mal_node =& $child_node->first_child();
00290
00291 $id_arr = explode("_", $mal_node->get_attribute("OriginId"));
00292 $mob_id = $id_arr[count($id_arr) - 1];
00293
00294
00295 if (!ilObject::_exists($mob_id) && in_array("delete", $_POST))
00296 {
00297 $mob_id = 0;
00298 }
00299
00300 $mob =& new ilObjMediaObject($mob_id);
00301 $mob->setDom($this->dom);
00302 $mob->setNode($cont_node);
00303 $mob->setHierId($a_hier_id);
00304 return $mob;
00305
00306 case "List":
00307 require_once("content/classes/Pages/class.ilPCList.php");
00308 $list =& new ilPCList($this->dom);
00309 $list->setNode($cont_node);
00310 $list->setHierId($a_hier_id);
00311 return $list;
00312
00313 case "FileList":
00314 require_once("content/classes/Pages/class.ilPCFileList.php");
00315 $file_list =& new ilPCFileList($this->dom);
00316 $file_list->setNode($cont_node);
00317 $file_list->setHierId($a_hier_id);
00318 return $file_list;
00319
00320
00321 case "Question":
00322 require_once("content/classes/Pages/class.ilPCQuestion.php");
00323 $pc_question =& new ilPCQuestion($this->dom);
00324 $pc_question->setNode($cont_node);
00325 $pc_question->setHierId($a_hier_id);
00326 return $pc_question;
00327 }
00328 break;
00329
00330 case "TableData":
00331 require_once("content/classes/Pages/class.ilPCTableData.php");
00332 $td =& new ilPCTableData($this->dom);
00333 $td->setNode($cont_node);
00334 $td->setHierId($a_hier_id);
00335 return $td;
00336
00337 case "ListItem":
00338 require_once("content/classes/Pages/class.ilPCListItem.php");
00339 $td =& new ilPCListItem($this->dom);
00340 $td->setNode($cont_node);
00341 $td->setHierId($a_hier_id);
00342 return $td;
00343
00344 case "FileItem":
00345 require_once("content/classes/Pages/class.ilPCFileItem.php");
00346 $file_item =& new ilPCFileItem($this->dom);
00347 $file_item->setNode($cont_node);
00348 $file_item->setHierId($a_hier_id);
00349 return $file_item;
00350
00351 }
00352 }
00353
00354 function &getContentNode($a_hier_id)
00355 {
00356
00357
00358 $xpc = xpath_new_context($this->dom);
00359 if($a_hier_id == "pg")
00360 {
00361 return $this->node;
00362 }
00363 else
00364 {
00365 $path = "//*[@HierId = '$a_hier_id']";
00366 }
00367 $res =& xpath_eval($xpc, $path);
00368
00369 if (count($res->nodeset) == 1)
00370 {
00371 $cont_node =& $res->nodeset[0];
00372 return $cont_node;
00373 }
00374 }
00375
00376
00377 function lookforhier($a_hier_id)
00378 {
00379 $xpc = xpath_new_context($this->dom);
00380 $path = "//*[@HierId = '$a_hier_id']";
00381 $res =& xpath_eval($xpc, $path);
00382 if (count($res->nodeset) == 1)
00383 return "YES";
00384 else
00385 return "NO";
00386 }
00387
00388
00389 function &getNode()
00390 {
00391 return $this->node;
00392 }
00393
00394
00403 function setXMLContent($a_xml, $a_encoding = "UTF-8")
00404 {
00405 $this->encoding = $a_encoding;
00406 $this->xml = $a_xml;
00407 }
00408
00415 function appendXMLContent($a_xml)
00416 {
00417 $this->xml.= $a_xml;
00418 }
00419
00420
00424 function getXMLContent($a_incl_head = false)
00425 {
00426
00427
00428 if($a_incl_head)
00429 {
00430
00431 $enc_str = (!empty($this->encoding))
00432 ? "encoding=\"".$this->encoding."\""
00433 : "";
00434 return "<?xml version=\"1.0\" $enc_str ?>".
00435 "<!DOCTYPE PageObject SYSTEM \"".ILIAS_ABSOLUTE_PATH."/xml/".$this->cur_dtd."\">".
00436 $this->xml;
00437 }
00438 else
00439 {
00440 return $this->xml;
00441 }
00442 }
00443
00448 function getXMLFromDom($a_incl_head = false, $a_append_mobs = false, $a_append_bib = false,
00449 $a_append_str = "", $a_omit_pageobject_tag = false)
00450 {
00451 if ($a_incl_head)
00452 {
00453
00454 return $this->dom->dump_mem(0, $this->encoding);
00455 }
00456 else
00457 {
00458
00459 if ($a_append_mobs || $a_append_bib || $a_append_link_info)
00460 {
00461 $mobs = "";
00462 $bibs = "";
00463 if ($a_append_mobs)
00464 {
00465 $mobs =& $this->getMultimediaXML();
00466 }
00467 if ($a_append_bib)
00468 {
00469 $bibs =& $this->getBibliographyXML();
00470 }
00471 $trans =& $this->getLanguageVariablesXML();
00472 return "<dummy>".$this->dom->dump_node($this->node).$mobs.$bibs.$trans.$a_append_str."</dummy>";
00473 }
00474 else
00475 {
00476 if (is_object($this->dom))
00477 {
00478 if ($a_omit_pageobject_tag)
00479 {
00480 $xml = "";
00481 $childs =& $this->node->child_nodes();
00482 for($i = 0; $i < count($childs); $i++)
00483 {
00484 $xml.= $this->dom->dump_node($childs[$i]);
00485 }
00486 return $xml;
00487 }
00488 else
00489 {
00490 $xml = $this->dom->dump_mem(0, $this->encoding);
00491 $xml = eregi_replace("<\?xml[^>]*>","",$xml);
00492 $xml = eregi_replace("<!DOCTYPE[^>]*>","",$xml);
00493
00494 return $xml;
00495
00496
00497
00498 }
00499 }
00500 else
00501 {
00502 return "";
00503 }
00504 }
00505 }
00506 }
00507
00511 function getLanguageVariablesXML()
00512 {
00513 global $lng;
00514
00515 $xml = "<LVs>";
00516 $lang_vars = array("ed_insert_par", "ed_insert_code",
00517 "ed_insert_table", "ed_insert_media", "ed_insert_list",
00518 "ed_insert_filelist", "ed_paste_clip", "ed_edit",
00519 "ed_edit_prop", "ed_delete", "ed_moveafter", "ed_movebefore",
00520 "ed_go", "ed_new_row_after", "ed_new_row_before",
00521 "ed_new_col_after", "ed_new_col_before", "ed_delete_col",
00522 "ed_delete_row", "ed_class", "ed_width", "ed_align_left",
00523 "ed_align_right", "ed_align_center", "ed_align_left_float",
00524 "ed_align_right_float", "ed_delete_item", "ed_new_item_before",
00525 "ed_new_item_after", "ed_copy_clip", "please_select", "ed_split_page",
00526 "ed_item_up", "ed_item_down", "ed_row_up", "ed_row_down",
00527 "ed_col_left", "ed_col_right", "ed_split_page_next","ed_enable",
00528 "de_activate");
00529
00530 foreach ($lang_vars as $lang_var)
00531 {
00532 $this->appendLangVarXML($xml, $lang_var);
00533 }
00534
00535 $xml.= "</LVs>";
00536
00537 return $xml;
00538 }
00539
00540 function appendLangVarXML(&$xml, $var)
00541 {
00542 global $lng;
00543
00544 $xml.= "<LV name=\"$var\" value=\"".$lng->txt("cont_".$var)."\"/>";
00545 }
00546
00547 function getFirstParagraphText()
00548 {
00549 $xpc = xpath_new_context($this->dom);
00550 $path = "//Paragraph[1]";
00551 $res =& xpath_eval($xpc, $path);
00552 if (count($res->nodeset) > 0)
00553 {
00554 $cont_node =& $res->nodeset[0]->parent_node();
00555 $par =& new ilPCParagraph($this->dom);
00556 $par->setNode($cont_node);
00557 return $par->getText();
00558 }
00559 else
00560 {
00561 return "";
00562 }
00563 }
00564
00565
00574 function setContainsIntLink($a_contains_link)
00575 {
00576 $this->contains_int_link = $a_contains_link;
00577 }
00578
00583 function containsIntLink()
00584 {
00585 return $this->contains_int_link;
00586 }
00587
00588 function needsImportParsing($a_parse = "")
00589 {
00590
00591 if ($a_parse === true)
00592 {
00593 $this->needs_parsing = true;
00594 }
00595 if ($a_parse === false)
00596 {
00597 $this->needs_parsing = false;
00598 }
00599 return $this->needs_parsing;
00600 }
00601
00606 function getBibliographyXML()
00607 {
00608 global $ilias;
00609
00610
00611
00612
00613
00614 $r = $ilias->db->query("SELECT * FROM object_reference WHERE ref_id='".$_GET["ref_id"]."' ");
00615 $row = $r->fetchRow(DB_FETCHMODE_ASSOC);
00616
00617 include_once("./classes/class.ilNestedSetXML.php");
00618 $nested = new ilNestedSetXML();
00619 $bibs_xml = $nested->export($row["obj_id"], "bib");
00620
00621 return $bibs_xml;
00622 }
00623
00624
00629 function collectMediaObjects($a_inline_only = true)
00630 {
00631
00632
00633 $xpc = xpath_new_context($this->dom);
00634 $path = "//MediaObject/MediaAlias";
00635 $res =& xpath_eval($xpc, $path);
00636 $mob_ids = array();
00637 for($i = 0; $i < count($res->nodeset); $i++)
00638 {
00639 $id_arr = explode("_", $res->nodeset[$i]->get_attribute("OriginId"));
00640 $mob_id = $id_arr[count($id_arr) - 1];
00641 $mob_ids[$mob_id] = $mob_id;
00642 }
00643
00644
00645 $xpc = xpath_new_context($this->dom);
00646 $path = "//IntLink[@Type = 'MediaObject']";
00647 $res =& xpath_eval($xpc, $path);
00648
00649 for($i = 0; $i < count($res->nodeset); $i++)
00650 {
00651 if (($res->nodeset[$i]->get_attribute("TargetFrame") == "") ||
00652 (!$a_inline_only))
00653 {
00654 $target = $res->nodeset[$i]->get_attribute("Target");
00655 $id_arr = explode("_", $target);
00656 if (($id_arr[1] == IL_INST_ID) ||
00657 (substr($target, 0, 4) == "il__"))
00658 {
00659 $mob_id = $id_arr[count($id_arr) - 1];
00660 if (ilObject::_exists($mob_id))
00661 {
00662 $mob_ids[$mob_id] = $mob_id;
00663 }
00664 }
00665 }
00666 }
00667
00668 return $mob_ids;
00669 }
00670
00671
00675 function getInternalLinks()
00676 {
00677
00678 $xpc = xpath_new_context($this->dom);
00679 $path = "//IntLink";
00680 $res =& xpath_eval($xpc, $path);
00681
00682 $links = array();
00683 for($i = 0; $i < count($res->nodeset); $i++)
00684 {
00685 $target = $res->nodeset[$i]->get_attribute("Target");
00686 $type = $res->nodeset[$i]->get_attribute("Type");
00687 $targetframe = $res->nodeset[$i]->get_attribute("TargetFrame");
00688 $links[$target.":".$type.":".$targetframe] =
00689 array("Target" => $target, "Type" => $type,
00690 "TargetFrame" => $targetframe);
00691
00692
00693 if ($type == "MediaObject" && $targetframe == "")
00694 {
00695 if (substr($target, 0, 4) =="il__")
00696 {
00697 $id_arr = explode("_", $target);
00698 $id = $id_arr[count($id_arr) - 1];
00699
00700 $med_links = ilMediaItem::_getMapAreasIntLinks($id);
00701 foreach($med_links as $key => $med_link)
00702 {
00703 $links[$key] = $med_link;
00704 }
00705 }
00706
00707 }
00708
00709 }
00710 unset($xpc);
00711
00712
00713 $xpc = xpath_new_context($this->dom);
00714 $path = "//MediaAlias";
00715 $res =& xpath_eval($xpc, $path);
00716
00717 require_once("content/classes/Media/class.ilMediaItem.php");
00718 for($i = 0; $i < count($res->nodeset); $i++)
00719 {
00720 $oid = $res->nodeset[$i]->get_attribute("OriginId");
00721 if (substr($oid, 0, 4) =="il__")
00722 {
00723 $id_arr = explode("_", $oid);
00724 $id = $id_arr[count($id_arr) - 1];
00725
00726 $med_links = ilMediaItem::_getMapAreasIntLinks($id);
00727 foreach($med_links as $key => $med_link)
00728 {
00729 $links[$key] = $med_link;
00730 }
00731 }
00732 }
00733 unset($xpc);
00734
00735 return $links;
00736 }
00737
00741 function collectFileItems()
00742 {
00743
00744
00745 $xpc = xpath_new_context($this->dom);
00746 $path = "//FileItem/Identifier";
00747 $res =& xpath_eval($xpc, $path);
00748 $file_ids = array();
00749 for($i = 0; $i < count($res->nodeset); $i++)
00750 {
00751 $id_arr = explode("_", $res->nodeset[$i]->get_attribute("Entry"));
00752 $file_id = $id_arr[count($id_arr) - 1];
00753 $file_ids[$file_id] = $file_id;
00754 }
00755
00756 return $file_ids;
00757 }
00758
00763 function getMultimediaXML()
00764 {
00765 $mob_ids = $this->collectMediaObjects();
00766
00767
00768 $mobs_xml = "";
00769 require_once("content/classes/Media/class.ilObjMediaObject.php");
00770 foreach($mob_ids as $mob_id => $dummy)
00771 {
00772 if (ilObject::_exists($mob_id))
00773 {
00774 $mob_obj =& new ilObjMediaObject($mob_id);
00775 $mobs_xml .= $mob_obj->getXML(IL_MODE_OUTPUT);
00776 }
00777 }
00778 return $mobs_xml;
00779 }
00780
00784 function getMediaAliasElement($a_mob_id, $a_nr = 1)
00785 {
00786 $xpc = xpath_new_context($this->dom);
00787 $path = "//MediaObject/MediaAlias[@OriginId='il__mob_$a_mob_id']";
00788 $res =& xpath_eval($xpc, $path);
00789 $mal_node =& $res->nodeset[$a_nr - 1];
00790 $mob_node =& $mal_node->parent_node();
00791
00792 return $this->dom->dump_node($mob_node);
00793 }
00794
00795 function validateDom()
00796 {
00797
00798
00799
00800 $this->stripHierIDs();
00801 @$this->dom->validate($error);
00802 return $error;
00803 }
00804
00820 function addHierIDs()
00821 {
00822 $this->hier_ids = array();
00823 $this->first_row_ids = array();
00824 $this->first_col_ids = array();
00825 $this->list_item_ids = array();
00826 $this->file_item_ids = array();
00827
00828
00829 $xpc = xpath_new_context($this->dom);
00830
00831 $path = "//PageContent | //TableRow | //TableData | //ListItem | //FileItem";
00832 $res =& xpath_eval($xpc, $path);
00833 for($i = 0; $i < count($res->nodeset); $i++)
00834 {
00835 $cnode = $res->nodeset[$i];
00836 $ctag = $cnode->node_name();
00837
00838
00839 $sib_hier_id = "";
00840 while($cnode =& $cnode->previous_sibling())
00841 {
00842 if (($cnode->node_type() == XML_ELEMENT_NODE)
00843 && $cnode->has_attribute("HierId"))
00844 {
00845 $sib_hier_id = $cnode->get_attribute("HierId");
00846
00847 break;
00848 }
00849 }
00850
00851 if ($sib_hier_id != "")
00852 {
00853 $node_hier_id = ilPageContent::incEdId($sib_hier_id);
00854 $res->nodeset[$i]->set_attribute("HierId", $node_hier_id);
00855 $this->hier_ids[] = $node_hier_id;
00856 if ($ctag == "TableData")
00857 {
00858 if (substr($par_hier_id,strlen($par_hier_id)-2) == "_1")
00859 {
00860 $this->first_row_ids[] = $node_hier_id;
00861 }
00862 }
00863 if ($ctag == "ListItem")
00864 {
00865 $this->list_item_ids[] = $node_hier_id;
00866 }
00867 if ($ctag == "FileItem")
00868 {
00869 $this->file_item_ids[] = $node_hier_id;
00870 }
00871 }
00872 else
00873 {
00874
00875 $cnode = $res->nodeset[$i];
00876 $par_hier_id = "";
00877 while($cnode =& $cnode->parent_node())
00878 {
00879 if (($cnode->node_type() == XML_ELEMENT_NODE)
00880 && $cnode->has_attribute("HierId"))
00881 {
00882 $par_hier_id = $cnode->get_attribute("HierId");
00883
00884 break;
00885 }
00886 }
00887
00888 if (($par_hier_id != "") && ($par_hier_id != "pg"))
00889 {
00890 $node_hier_id = $par_hier_id."_1";
00891 $res->nodeset[$i]->set_attribute("HierId", $node_hier_id);
00892 $this->hier_ids[] = $node_hier_id;
00893 if ($ctag == "TableData")
00894 {
00895 $this->first_col_ids[] = $node_hier_id;
00896 if (substr($par_hier_id,strlen($par_hier_id)-2) == "_1")
00897 {
00898 $this->first_row_ids[] = $node_hier_id;
00899 }
00900 }
00901 if ($ctag == "ListItem")
00902 {
00903 $this->list_item_ids[] = $node_hier_id;
00904 }
00905 if ($ctag == "FileItem")
00906 {
00907 $this->file_item_ids[] = $node_hier_id;
00908 }
00909
00910 }
00911 else
00912 {
00913 $node_hier_id = "1";
00914 $res->nodeset[$i]->set_attribute("HierId", $node_hier_id);
00915 $this->hier_ids[] = $node_hier_id;
00916 }
00917 }
00918 }
00919
00920
00921 $xpc = xpath_new_context($this->dom);
00922 $path = "//PageObject";
00923 $res =& xpath_eval($xpc, $path);
00924 for($i = 0; $i < count($res->nodeset); $i++)
00925 {
00926 $res->nodeset[$i]->set_attribute("HierId", "pg");
00927 $this->hier_ids[] = "pg";
00928 }
00929 unset($xpc);
00930 }
00931
00935 function getHierIds()
00936 {
00937 return $this->hier_ids;
00938 }
00939
00940
00944 function getFirstRowIds()
00945 {
00946 return $this->first_row_ids;
00947 }
00948
00952 function getFirstColumnIds()
00953 {
00954 return $this->first_col_ids;
00955 }
00956
00960 function getListItemIds()
00961 {
00962 return $this->list_item_ids;
00963 }
00964
00968 function getFileItemIds()
00969 {
00970 return $this->file_item_ids;
00971 }
00972
00976 function stripHierIDs()
00977 {
00978 if(is_object($this->dom))
00979 {
00980 $xpc = xpath_new_context($this->dom);
00981 $path = "//*[@HierId]";
00982 $res =& xpath_eval($xpc, $path);
00983 for($i = 0; $i < count($res->nodeset); $i++)
00984 {
00985 if ($res->nodeset[$i]->has_attribute("HierId"))
00986 {
00987 $res->nodeset[$i]->remove_attribute("HierId");
00988 }
00989 }
00990 unset($xpc);
00991 }
00992 }
00993
00997 function addFileSizes()
00998 {
00999 $xpc = xpath_new_context($this->dom);
01000 $path = "//FileItem";
01001 $res =& xpath_eval($xpc, $path);
01002 for($i = 0; $i < count($res->nodeset); $i++)
01003 {
01004 $cnode =& $res->nodeset[$i];
01005 $size_node =& $this->dom->create_element("Size");
01006 $size_node =& $cnode->append_child($size_node);
01007
01008 $childs =& $cnode->child_nodes();
01009 $size = "";
01010 for($j = 0; $j < count($childs); $j++)
01011 {
01012 if ($childs[$j]->node_name() == "Identifier")
01013 {
01014 if ($childs[$j]->has_attribute("Entry"))
01015 {
01016 $entry = $childs[$j]->get_attribute("Entry");
01017 $entry_arr = explode("_", $entry);
01018 $id = $entry_arr[count($entry_arr) - 1];
01019 require_once("classes/class.ilObjFile.php");
01020 $size = ilObjFile::_lookupFileSize($id);
01021 }
01022 }
01023 }
01024 $size_node->set_content($size);
01025 }
01026
01027 unset($xpc);
01028 }
01029
01033 function resolveIntLinks()
01034 {
01035
01036 $xpc = xpath_new_context($this->dom);
01037 $path = "//IntLink";
01038 $res =& xpath_eval($xpc, $path);
01039 for($i = 0; $i < count($res->nodeset); $i++)
01040 {
01041 $target = $res->nodeset[$i]->get_attribute("Target");
01042 $type = $res->nodeset[$i]->get_attribute("Type");
01043
01044 $new_target = ilInternalLink::_getIdForImportId($type, $target);
01045 if ($new_target !== false)
01046 {
01047 $res->nodeset[$i]->set_attribute("Target", $new_target);
01048 }
01049 else
01050 {
01051 if (ilInternalLink::_extractInstOfTarget($target) == IL_INST_ID &&
01052 IL_INST_ID > 0)
01053 {
01054 $new_target = ilInternalLink::_removeInstFromTarget($target);
01055 if (ilInternalLink::_exists($type, $new_target))
01056 {
01057 $res->nodeset[$i]->set_attribute("Target", $new_target);
01058 }
01059 }
01060 }
01061
01062 }
01063 unset($xpc);
01064
01065
01066 $xpc = xpath_new_context($this->dom);
01067 $path = "//MediaAlias";
01068 $res =& xpath_eval($xpc, $path);
01069
01070
01071 for($i = 0; $i < count($res->nodeset); $i++)
01072 {
01073 $orig_id = $res->nodeset[$i]->get_attribute("OriginId");
01074 $id_arr = explode("_", $orig_id);
01075 $mob_id = $id_arr[count($id_arr) - 1];
01076 ilMediaItem::_resolveMapAreaLinks($mob_id);
01077 }
01078 }
01079
01083 function createFromXML()
01084 {
01085 global $lng;
01086
01087
01088
01089 if($this->getXMLContent() == "")
01090 {
01091 $this->setXMLContent("<PageObject></PageObject>");
01092 }
01093
01094 $query = "INSERT INTO page_object (page_id, parent_id, content, parent_type) VALUES ".
01095 "('".$this->getId()."', '".$this->getParentId()."','".ilUtil::prepareDBString($this->getXMLContent()).
01096 "', '".$this->getParentType()."')";
01097 if(!$this->ilias->db->checkQuerySize($query))
01098 {
01099 $this->ilias->raiseError($lng->txt("check_max_allowed_packet_size"),$this->ilias->error_obj->MESSAGE);
01100 return false;
01101 }
01102
01103 $this->ilias->db->query($query);
01104
01105 }
01106
01107
01108
01109
01110
01111
01112
01113
01114
01115
01119 function updateFromXML()
01120 {
01121 global $lng;
01122
01123
01124
01125 $query = "UPDATE page_object ".
01126 "SET content = '".ilUtil::prepareDBString(($this->getXMLContent()))."' ".
01127 ", parent_id='".$this->getParentId()."' ".
01128 "WHERE page_id = '".$this->getId()."' AND parent_type='".$this->getParentType()."'";
01129
01130 if(!$this->ilias->db->checkQuerySize($query))
01131 {
01132 $this->ilias->raiseError($lng->txt("check_max_allowed_packet_size"),$this->ilias->error_obj->MESSAGE);
01133 return false;
01134 }
01135 $this->ilias->db->query($query);
01136
01137 return true;
01138 }
01139
01143 function update($a_validate = true)
01144 {
01145 global $lng;
01146
01147
01148
01149
01150
01151 if($a_validate)
01152 {
01153 $errors = $this->validateDom();
01154 }
01155 if(empty($errors))
01156 {
01157 $content = ilUtil::prepareDBString(($this->getXMLFromDom()));
01158
01159 $query = "UPDATE page_object ".
01160 "SET content = '".$content."' ".
01161 ", parent_id='".$this->getParentId()."' ".
01162 " WHERE page_id = '".$this->getId().
01163 "' AND parent_type='".$this->getParentType()."'";
01164 if(!$this->ilias->db->checkQuerySize($query))
01165 {
01166 $this->ilias->raiseError($lng->txt("check_max_allowed_packet_size"),$this->ilias->error_obj->MESSAGE);
01167 return false;
01168 }
01169
01170 $this->ilias->db->query($query);
01171
01172
01173 include_once("content/classes/Media/class.ilObjMediaObject.php");
01174 $mob_ids = ilObjMediaObject::_getMobsOfObject(
01175 $this->getParentType().":pg", $this->getId());
01176 $this->saveMobUsage($this->getXMLFromDom());
01177 foreach($mob_ids as $mob)
01178 {
01179 if (ilObject::_exists($mob))
01180 {
01181 $mob_obj = new ilObjMediaObject($mob);
01182 $usages = $mob_obj->getUsages();
01183 if (count($usages) == 0)
01184 {
01185 $mob_obj->delete();
01186 }
01187 }
01188 }
01189
01190
01191 include_once("classes/class.ilObjFile.php");
01192 $file_ids = ilObjFile::_getFilesOfObject(
01193 $this->getParentType().":pg", $this->getId());
01194 $this->saveFileUsage();
01195 foreach($file_ids as $file)
01196 {
01197 if (ilObject::_exists($file))
01198 {
01199 $file_obj = new ilObjFile($file, false);
01200 $usages = $file_obj->getUsages();
01201 if (count($usages) == 0)
01202 {
01203 $file_obj->delete();
01204 }
01205 }
01206 }
01207
01208
01209 $this->saveInternalLinks($this->getXMLFromDom());
01210 $this->callUpdateListeners();
01211
01212 return true;
01213 }
01214 else
01215 {
01216 return $errors;
01217 }
01218 }
01219
01220
01224 function delete()
01225 {
01226 $mobs = array();
01227 $files = array();
01228
01229 if (!$this->page_not_found)
01230 {
01231 $this->buildDom();
01232 $mobs = $this->collectMediaObjects(false);
01233 $files = $this->collectFileItems();
01234 }
01235
01236
01237 $this->saveMobUsage("<dummy></dummy>");
01238
01239
01240 $this->saveInternalLinks("<dummy></dummy>");
01241
01242
01243 include_once("classes/class.ilObjFile.php");
01244 ilObjFile::_deleteAllUsages($this->getParentType().":pg", $this->getId());
01245
01246
01247 $query = "DELETE FROM page_object ".
01248 "WHERE page_id = '".$this->getId().
01249 "' AND parent_type='".$this->getParentType()."'";
01250 $this->ilias->db->query($query);
01251
01252 foreach ($mobs as $mob_id)
01253 {
01254 if (ilObject::_exists($mob_id))
01255 {
01256 $mob_obj =& new ilObjMediaObject($mob_id);
01257 $mob_obj->delete();
01258 }
01259 }
01260
01261 include_once("classes/class.ilObjFile.php");
01262 foreach ($files as $file_id)
01263 {
01264 if (ilObject::_exists($file_id))
01265 {
01266 $file_obj =& new ilObjFile($file_id, false);
01267 $file_obj->delete();
01268 }
01269 }
01270
01271 }
01272
01273
01279 function saveMobUsage($a_xml)
01280 {
01281
01282
01283 $doc = domxml_open_mem($a_xml);
01284
01285
01286 $xpc = xpath_new_context($doc);
01287 $path = "//MediaAlias";
01288 $res =& xpath_eval($xpc, $path);
01289 $usages = array();
01290 for ($i=0; $i < count($res->nodeset); $i++)
01291 {
01292 $id_arr = explode("_", $res->nodeset[$i]->get_attribute("OriginId"));
01293 $mob_id = $id_arr[count($id_arr) - 1];
01294 if ($mob_id > 0)
01295 {
01296 $usages[$mob_id] = true;
01297 }
01298 }
01299
01300
01301 $xpc = xpath_new_context($doc);
01302 $path = "//MediaObject/MetaData/General/Identifier";
01303 $res =& xpath_eval($xpc, $path);
01304 for ($i=0; $i < count($res->nodeset); $i++)
01305 {
01306 $mob_entry = $res->nodeset[$i]->get_attribute("Entry");
01307 $mob_arr = explode("_", $mob_entry);
01308 $mob_id = $mob_arr[count($mob_arr) - 1];
01309 if ($mob_id > 0)
01310 {
01311 $usages[$mob_id] = true;
01312 }
01313 }
01314
01315
01316 $xpc = xpath_new_context($doc);
01317 $path = "//IntLink[@Type='MediaObject']";
01318 $res =& xpath_eval($xpc, $path);
01319 for ($i=0; $i < count($res->nodeset); $i++)
01320 {
01321 $mob_target = $res->nodeset[$i]->get_attribute("Target");
01322 $mob_arr = explode("_", $mob_target);
01323 $mob_id = $mob_arr[count($mob_arr) - 1];
01324 if ($mob_id > 0)
01325 {
01326 $usages[$mob_id] = true;
01327 }
01328 }
01329
01330 include_once("content/classes/Media/class.ilObjMediaObject.php");
01331 ilObjMediaObject::_deleteAllUsages($this->getParentType().":pg", $this->getId());
01332 foreach($usages as $mob_id => $val)
01333 {
01334 ilObjMediaObject::_saveUsage($mob_id, $this->getParentType().":pg", $this->getId());
01335 }
01336 }
01337
01341 function saveFileUsage()
01342 {
01343
01344 $file_ids = $this->collectFileItems();
01345 include_once("classes/class.ilObjFile.php");
01346 ilObjFile::_deleteAllUsages($this->getParentType().":pg", $this->getId());
01347 foreach($file_ids as $file_id)
01348 {
01349 ilObjFile::_saveUsage($file_id, $this->getParentType().":pg", $this->getId());
01350 }
01351 }
01352
01353
01359 function saveInternalLinks($a_xml)
01360 {
01361
01362 $doc = domxml_open_mem($a_xml);
01363
01364
01365 include_once("content/classes/Pages/class.ilInternalLink.php");
01366 ilInternalLink::_deleteAllLinksOfSource($this->getParentType().":pg", $this->getId());
01367
01368
01369 $xpc = xpath_new_context($doc);
01370 $path = "//IntLink";
01371 $res =& xpath_eval($xpc, $path);
01372 for ($i=0; $i < count($res->nodeset); $i++)
01373 {
01374 $link_type = $res->nodeset[$i]->get_attribute("Type");
01375
01376 switch ($link_type)
01377 {
01378 case "StructureObject":
01379 $t_type = "st";
01380 break;
01381
01382 case "PageObject":
01383 $t_type = "pg";
01384 break;
01385
01386 case "GlossaryItem":
01387 $t_type = "git";
01388 break;
01389
01390 case "MediaObject":
01391 $t_type = "mob";
01392 break;
01393
01394 case "RepositoryItem":
01395 $t_type = "obj";
01396 break;
01397 }
01398
01399 $target = $res->nodeset[$i]->get_attribute("Target");
01400 $target_arr = explode("_", $target);
01401 $t_id = $target_arr[count($target_arr) - 1];
01402
01403
01404 if (is_int(strpos($target, "__")))
01405 {
01406 $t_inst = 0;
01407 }
01408 else
01409 {
01410 $t_inst = $target_arr[1];
01411 }
01412
01413 if ($t_id > 0)
01414 {
01415 ilInternalLink::_saveLink($this->getParentType().":pg", $this->getId(), $t_type,
01416 $t_id, $t_inst);
01417 }
01418 }
01419
01420 }
01421
01422
01426 function create()
01427 {
01428 $this->createFromXML();
01429 }
01430
01438 function deleteContent($a_hid, $a_update = true)
01439 {
01440 $curr_node =& $this->getContentNode($a_hid);
01441 $curr_node->unlink_node($curr_node);
01442 if ($a_update)
01443 {
01444 return $this->update();
01445 }
01446 }
01447
01455 function deleteContents($a_hids, $a_update = true)
01456 {
01457 if (!is_array($a_hids))
01458 {
01459 return;
01460 }
01461 foreach($a_hids as $a_hid)
01462 {
01463 $curr_node =& $this->getContentNode($a_hid);
01464 if (is_object($curr_node))
01465 {
01466 $parent_node = $curr_node->parent_node();
01467 if ($parent_node->node_name() != "TableRow")
01468 {
01469 $curr_node->unlink_node($curr_node);
01470 }
01471 }
01472 }
01473 if ($a_update)
01474 {
01475 return $this->update();
01476 }
01477 }
01478
01483 function switchEnableMultiple($a_hids, $a_update = true)
01484 {
01485 if (!is_array($a_hids))
01486 {
01487 return;
01488 }
01489 $obj = & $this->content_obj;
01490
01491 foreach($a_hids as $a_hid)
01492 {
01493 $curr_node =& $this->getContentNode($a_hid);
01494 if (is_object($curr_node))
01495 {
01496 if ($curr_node->node_name() == "PageContent")
01497 {
01498 $cont_obj =& $this->getContentObject($a_hid);
01499 if ($cont_obj->isEnabled ())
01500 $cont_obj->disable ();
01501 else
01502 $cont_obj->enable ();
01503 }
01504 }
01505 }
01506
01507 if ($a_update)
01508 {
01509 return $this->update();
01510 }
01511 }
01512
01513
01521 function deleteContentFromHierId($a_hid, $a_update = true)
01522 {
01523 $hier_ids = $this->getHierIds();
01524
01525
01526 foreach ($hier_ids as $hier_id)
01527 {
01528
01529 if (!is_int(strpos($hier_id, "_")))
01530 {
01531 if ($hier_id != "pg" && $hier_id >= $a_hid)
01532 {
01533 $curr_node =& $this->getContentNode($hier_id);
01534 $curr_node->unlink_node($curr_node);
01535 }
01536 }
01537 }
01538 if ($a_update)
01539 {
01540 return $this->update();
01541 }
01542 }
01543
01551 function deleteContentBeforeHierId($a_hid, $a_update = true)
01552 {
01553 $hier_ids = $this->getHierIds();
01554
01555
01556 foreach ($hier_ids as $hier_id)
01557 {
01558
01559 if (!is_int(strpos($hier_id, "_")))
01560 {
01561 if ($hier_id != "pg" && $hier_id < $a_hid)
01562 {
01563 $curr_node =& $this->getContentNode($hier_id);
01564 $curr_node->unlink_node($curr_node);
01565 }
01566 }
01567 }
01568 if ($a_update)
01569 {
01570 return $this->update();
01571 }
01572 }
01573
01574
01582 function _moveContentAfterHierId(&$a_source_page, &$a_target_page, $a_hid)
01583 {
01584 $hier_ids = $a_source_page->getHierIds();
01585
01586 $copy_ids = array();
01587
01588
01589 foreach ($hier_ids as $hier_id)
01590 {
01591
01592 if (!is_int(strpos($hier_id, "_")))
01593 {
01594 if ($hier_id != "pg" && $hier_id >= $a_hid)
01595 {
01596 $copy_ids[] = $hier_id;
01597 }
01598 }
01599 }
01600 asort($copy_ids);
01601
01602 $parent_node =& $a_target_page->getContentNode("pg");
01603 $target_dom =& $a_target_page->getDom();
01604 $parent_childs =& $parent_node->child_nodes();
01605 $cnt_parent_childs = count($parent_childs);
01606
01607 $first_child =& $parent_childs[0];
01608 foreach($copy_ids as $copy_id)
01609 {
01610 $source_node =& $a_source_page->getContentNode($copy_id);
01611
01612 $new_node =& $source_node->clone_node(true);
01613 $new_node->unlink_node($new_node);
01614
01615 $source_node->unlink_node($source_node);
01616
01617 if($cnt_parent_childs == 0)
01618 {
01619 $new_node =& $parent_node->append_child($new_node);
01620 }
01621 else
01622 {
01623
01624 $new_node =& $first_child->insert_before($new_node, $first_child);
01625 }
01626 $parent_childs =& $parent_node->child_nodes();
01627
01628
01629 }
01630
01631 $a_target_page->update();
01632 $a_source_page->update();
01633
01634 }
01635
01639 function insertContent(&$a_cont_obj, $a_pos, $a_mode = IL_INSERT_AFTER)
01640 {
01641
01642 $curr_node =& $this->getContentNode($a_pos);
01643 $curr_name = $curr_node->node_name();
01644 if (($curr_name == "TableData") || ($curr_name == "PageObject") ||
01645 ($curr_name == "ListItem"))
01646 {
01647 $a_mode = IL_INSERT_CHILD;
01648 }
01649
01650
01651 if($a_mode != IL_INSERT_CHILD)
01652 {
01653 $pos = explode("_", $a_pos);
01654 $target_pos = array_pop($pos);
01655 $parent_pos = implode($pos, "_");
01656 }
01657 else
01658 {
01659 $parent_pos = $a_pos;
01660 }
01661
01662
01663 if($parent_pos != "")
01664 {
01665 $parent_node =& $this->getContentNode($parent_pos);
01666 }
01667 else
01668 {
01669 $parent_node =& $this->getNode();
01670 }
01671
01672
01673 $parent_childs =& $parent_node->child_nodes();
01674 $cnt_parent_childs = count($parent_childs);
01675
01676 switch ($a_mode)
01677 {
01678
01679 case IL_INSERT_AFTER:
01680 $new_node =& $a_cont_obj->getNode();
01681
01682
01683
01684 if($succ_node =& $curr_node->next_sibling())
01685 {
01686 $new_node =& $succ_node->insert_before($new_node, $succ_node);
01687 }
01688 else
01689 {
01690
01691 $new_node =& $parent_node->append_child($new_node);
01692 }
01693 $a_cont_obj->setNode($new_node);
01694 break;
01695
01696 case IL_INSERT_BEFORE:
01697
01698 $new_node =& $a_cont_obj->getNode();
01699 $succ_node =& $this->getContentNode($a_pos);
01700 $new_node =& $succ_node->insert_before($new_node, $succ_node);
01701 $a_cont_obj->setNode($new_node);
01702 break;
01703
01704
01705 case IL_INSERT_CHILD:
01706
01707 $new_node =& $a_cont_obj->getNode();
01708 if($cnt_parent_childs == 0)
01709 {
01710 $new_node =& $parent_node->append_child($new_node);
01711 }
01712 else
01713 {
01714 $new_node =& $parent_childs[0]->insert_before($new_node, $parent_childs[0]);
01715 }
01716 $a_cont_obj->setNode($new_node);
01717
01718 break;
01719 }
01720
01721 }
01722
01723
01728 function moveContentBefore($a_source, $a_target)
01729 {
01730 if($a_source == $a_target)
01731 {
01732 return;
01733 }
01734
01735
01736 $content =& $this->getContentObject($a_source);
01737 $source_node =& $content->getNode();
01738 $clone_node =& $source_node->clone_node(true);
01739
01740
01741 $this->deleteContent($a_source, false);
01742
01743
01744 $content->setNode($clone_node);
01745 $this->insertContent($content, $a_target, IL_INSERT_BEFORE);
01746 return $this->update();
01747
01748 }
01749
01754 function moveContentAfter($a_source, $a_target)
01755 {
01756
01757 if($a_source == $a_target)
01758 {
01759 return;
01760 }
01761
01762
01763
01764
01765
01766 $content =& $this->getContentObject($a_source);
01767
01768 $source_node =& $content->getNode();
01769 $clone_node =& $source_node->clone_node(true);
01770
01771
01772 $this->deleteContent($a_source, false);
01773
01774
01775 $content->setNode($clone_node);
01776 $this->insertContent($content, $a_target, IL_INSERT_AFTER);
01777 return $this->update();
01778 }
01779
01783 function bbCode2XML(&$a_content)
01784 {
01785 $a_content = eregi_replace("\[com\]","<Comment>",$a_content);
01786 $a_content = eregi_replace("\[\/com\]","</Comment>",$a_content);
01787 $a_content = eregi_replace("\[emp]","<Emph>",$a_content);
01788 $a_content = eregi_replace("\[\/emp\]","</Emph>",$a_content);
01789 $a_content = eregi_replace("\[str]","<Strong>",$a_content);
01790 $a_content = eregi_replace("\[\/str\]","</Strong>",$a_content);
01791 }
01792
01797 function insertInstIntoIDs($a_inst)
01798 {
01799
01800
01801 $xpc = xpath_new_context($this->dom);
01802 $path = "//IntLink";
01803 $res =& xpath_eval($xpc, $path);
01804 for($i = 0; $i < count($res->nodeset); $i++)
01805 {
01806 $target = $res->nodeset[$i]->get_attribute("Target");
01807 $type = $res->nodeset[$i]->get_attribute("Type");
01808
01809 if (substr($target, 0, 4) == "il__")
01810 {
01811 $new_target = "il_".$a_inst."_".substr($target, 4, strlen($target) - 4);
01812 $res->nodeset[$i]->set_attribute("Target", $new_target);
01813 }
01814 }
01815 unset($xpc);
01816
01817
01818 $xpc = xpath_new_context($this->dom);
01819 $path = "//MediaAlias";
01820 $res =& xpath_eval($xpc, $path);
01821 for($i = 0; $i < count($res->nodeset); $i++)
01822 {
01823 $origin_id = $res->nodeset[$i]->get_attribute("OriginId");
01824 if (substr($origin_id, 0, 4) == "il__")
01825 {
01826 $new_id = "il_".$a_inst."_".substr($origin_id, 4, strlen($origin_id) - 4);
01827 $res->nodeset[$i]->set_attribute("OriginId", $new_id);
01828 }
01829 }
01830 unset($xpc);
01831
01832
01833 $xpc = xpath_new_context($this->dom);
01834 $path = "//FileItem/Identifier";
01835 $res =& xpath_eval($xpc, $path);
01836 for($i = 0; $i < count($res->nodeset); $i++)
01837 {
01838 $origin_id = $res->nodeset[$i]->get_attribute("Entry");
01839 if (substr($origin_id, 0, 4) == "il__")
01840 {
01841 $new_id = "il_".$a_inst."_".substr($origin_id, 4, strlen($origin_id) - 4);
01842 $res->nodeset[$i]->set_attribute("Entry", $new_id);
01843 }
01844 }
01845 unset($xpc);
01846
01847
01848 $xpc = xpath_new_context($this->dom);
01849 $path = "//Question";
01850 $res =& xpath_eval($xpc, $path);
01851 for($i = 0; $i < count($res->nodeset); $i++)
01852 {
01853 $qref = $res->nodeset[$i]->get_attribute("QRef");
01854
01855 if (substr($qref, 0, 4) == "il__")
01856 {
01857 $new_id = "il_".$a_inst."_".substr($qref, 4, strlen($qref) - 4);
01858
01859 $res->nodeset[$i]->set_attribute("QRef", $new_id);
01860 }
01861 }
01862 unset($xpc);
01863
01864 }
01865
01870 function highlightText($a_text, $proglang, $autoindent)
01871 {
01872
01873 if (!$this->hasHighlighter($proglang)) {
01874 $proglang="plain";
01875 }
01876
01877 require_once("./syntax_highlight/php/HFile/HFile_".$proglang.".php");
01878 $classname = "HFile_$proglang";
01879 $h_instance = new $classname();
01880 if ($autoindent == "n") {
01881 $h_instance ->notrim = 1;
01882 $h_instance ->indent = array ("");
01883 $h_instance ->unindent = array ("");
01884 }
01885
01886 $highlighter = new Core($h_instance, new Output_css());
01887 $a_text = $highlighter->highlight_text(html_entity_decode($a_text));
01888
01889 return $a_text;
01890 }
01891
01892 function hasHighlighter ($hfile_ext) {
01893 return file_exists ("syntax_highlight/php/HFile/HFile_".$hfile_ext.".php");
01894 }
01895
01901 function addSourceCodeHighlighting($outputmode = "presentation")
01902 {
01903 $xpc = xpath_new_context($this->dom);
01904 $path = "//Paragraph";
01905 $res = & xpath_eval($xpc, $path);
01906 for($i = 0; $i < count($res->nodeset); $i++)
01907 {
01908 $context_node = $res->nodeset[$i];
01909 $char = $context_node->get_attribute('Characteristic');
01910
01911 if ($char != "Code")
01912 continue;
01913
01914 $n = $context_node->parent_node();
01915 $char = $context_node->get_attribute('Characteristic');
01916 $subchar = $context_node->get_attribute('SubCharacteristic');
01917 $showlinenumbers = $context_node->get_attribute('ShowLineNumbers');
01918 $downloadtitle = $context_node->get_attribute('DownloadTitle');
01919 $autoindent = $context_node->get_attribute('AutoIndent');
01920
01921 $content = "";
01922
01923
01924
01925 $childs = $context_node->child_nodes();
01926
01927 for($j=0; $j<count($childs); $j++)
01928 {
01929 $content .= $this->dom->dump_node($childs[$j]);
01930 }
01931
01932 while ($context_node->has_child_nodes ())
01933 {
01934 $node_del = $context_node->first_child ();
01935 $context_node->remove_child ($node_del);
01936 }
01937
01938 $content = str_replace("<br />", "<br/>", utf8_decode($content) );
01939 $content = str_replace("<br/>", "\n", $content);
01940 $rownums = count(split ("\n",$content));
01941
01942 $plain_content = html_entity_decode($content);
01943 $plain_content = preg_replace ("/\&#x([1-9a-f]{2});?/ise","chr (base_convert (\\1, 16, 10))",$plain_content);
01944 $plain_content = preg_replace ("/\&#(\d+);?/ise","chr (\\1)",$plain_content);
01945 $content = utf8_encode($this->highlightText($plain_content, $subchar, $autoindent));
01946
01947 $content = str_replace("&lt;", "<", $content);
01948 $content = str_replace("&gt;", ">", $content);
01949 $content = str_replace("&", "&", $content);
01950
01951 $rows = "<TR valign=\"top\">";
01952 $rownumbers = "";
01953
01954
01955 if (strcmp($showlinenumbers,"y")==0)
01956 {
01957 $linenumbers = "<TD nowrap=\"nowrap\" class=\"ilc_LineNumbers\" >";
01958 $linenumbers .= "<PRE class=\"ilc_Code\">";
01959
01960 for ($j=0; $j < $rownums; $j++)
01961 {
01962 $indentno = strlen($rownums) - strlen($j+1) + 2;
01963 $rownumeration = ($j+1);
01964 $linenumbers .= "<span class=\"ilc_LineNumber\">$rownumeration</span>";
01965 if ($j < $rownums-1)
01966 {
01967 $linenumbers .= "\n";
01968 }
01969 }
01970 $linenumbers .= "</PRE>";
01971 $linenumbers .= "</TD>";
01972 }
01973
01974 $rows .= $linenumbers."<TD class=\"ilc_Sourcecode\"><PRE class=\"ilc_Code\">".$content."</PRE></TD></TR>";
01975 $rows .= "</TR>";
01976
01977
01978
01979 $newcontent = str_replace("\n", "<br/>",$rows);
01980
01981 $newcontent = str_replace("<br/><br/>", "<br/> <br/>",$newcontent);
01982
01983 $newcontent = str_replace("<br/><br/>", "<br/> <br/>",$newcontent);
01984
01985
01986
01987 $context_node->set_content($newcontent);
01988 if ($outputmode != "presentation" && is_object($this->offline_handler)
01989 && trim($downloadtitle) != "")
01990 {
01991
01992 $this->offline_handler->handleCodeParagraph ($this->id, $i + 1, $downloadtitle, $plain_content);
01993 }
01994 }
01995 }
01996
01997
01998 function send_paragraph ($par_id, $filename) {
01999 $this->builddom();
02000
02001 $mydom = $this->dom;
02002
02003 $xpc = xpath_new_context($mydom);
02004
02005 $path = "//PageContent[position () = $par_id]/Paragraph";
02006
02007 $res = & xpath_eval($xpc, $path);
02008
02009 if (count ($res->nodeset) != 1)
02010 die ("Should not happen");
02011
02012 $context_node = $res->nodeset[0];
02013
02014
02015
02016 $childs = $context_node->child_nodes();
02017
02018 for($j=0; $j<count($childs); $j++)
02019 {
02020 $content .= $mydom->dump_node($childs[$j]);
02021 }
02022
02023 $content = str_replace("<br />", "\n", $content);
02024 $content = str_replace("<br/>", "\n", $content);
02025
02026 $plain_content = html_entity_decode($content);
02027
02028 ilUtil::deliverData($plain_content, $filename);
02029
02030
02031
02032
02033
02034 exit();
02035 }
02036
02040 function getFO()
02041 {
02042 $xml = $this->getXMLFromDom(false, true, true);
02043 $xsl = file_get_contents("./content/page_fo.xsl");
02044 $args = array( '/_xml' => $xml, '/_xsl' => $xsl );
02045 $xh = xslt_create();
02046
02047 $params = array ();
02048
02049
02050 $fo = xslt_process($xh,"arg:/_xml","arg:/_xsl",NULL,$args, $params);
02051
02052
02053 $fo = str_replace("\n", "", $fo);
02054 $fo = str_replace("<br/>", "<br>", $fo);
02055 $fo = str_replace("<br>", "\n", $fo);
02056
02057 xslt_free($xh);
02058
02059
02060 $fo = substr($fo, strpos($fo,">") + 1);
02061
02062 return $fo;
02063 }
02064
02065 function registerOfflineHandler ($handler) {
02066 $this->offline_handler = $handler;
02067 }
02068
02072 function _lookupContainsDeactivatedElements($a_id, $a_parent_type)
02073 {
02074 global $ilDB;
02075
02076 $query = "SELECT * FROM page_object WHERE page_id = ".
02077 $ilDB->quote($a_id)." AND ".
02078 " parent_type = ".$ilDB->quote($a_parent_type)." AND ".
02079 " content LIKE '%PageContent Enabled=\"False\"%'";
02080 $obj_set = $ilDB->query($query);
02081
02082 if ($obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC))
02083 {
02084 return true;
02085 }
02086
02087 return false;
02088 }
02089
02090 }
02091 ?>