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