• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

content/classes/Pages/class.ilPageObject.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003         +-----------------------------------------------------------------------------+
00004         | ILIAS open source                                                           |
00005         +-----------------------------------------------------------------------------+
00006         | Copyright (c) 1998-2001 ILIAS open source, University of Cologne            |
00007         |                                                                             |
00008         | This program is free software; you can redistribute it and/or               |
00009         | modify it under the terms of the GNU General Public License                 |
00010         | as published by the Free Software Foundation; either version 2              |
00011         | of the License, or (at your option) any later version.                      |
00012         |                                                                             |
00013         | This program is distributed in the hope that it will be useful,             |
00014         | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
00015         | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
00016         | GNU General Public License for more details.                                |
00017         |                                                                             |
00018         | You should have received a copy of the GNU General Public License           |
00019         | along with this program; if not, write to the Free Software                 |
00020         | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. |
00021         +-----------------------------------------------------------------------------+
00022 */
00023 
00024 //require_once("content/classes/class.ilLMObject.php");
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 
00049 class ilPageObject
00050 {
00051         var $id;
00052         var $ilias;
00053         var $dom;
00054         var $xml;
00055         var $encoding;
00056         var $node;
00057         var $cur_dtd = "ilias_pg_0_1.dtd";
00058         var $contains_int_link;
00059         var $needs_parsing;
00060         var $parent_type;
00061         var $parent_id;
00062         var $update_listeners;
00063         var $update_listener_cnt;
00064         var $dom_builded;
00065 
00070         function ilPageObject($a_parent_type, $a_id = 0, $a_halt = true)
00071         {
00072                 global $ilias;
00073 
00074                 $this->parent_type = $a_parent_type;
00075                 $this->id = $a_id;
00076                 $this->ilias =& $ilias;
00077 
00078                 $this->contains_int_link = false;
00079                 $this->needs_parsing = false;
00080                 $this->update_listeners = array();
00081                 $this->update_listener_cnt = 0;
00082                 $this->dom_builded = false;
00083                 $this->halt_on_error = $a_halt;
00084                 $this->page_not_found = false;
00085 
00086                 if($a_id != 0)
00087                 {
00088                         $this->read();
00089                 }
00090         }
00091 
00092         function haltOnError($a_halt)
00093         {
00094                 $this->halt_on_error = $a_halt;
00095         }
00096 
00100         function read()
00101         {
00102                 global $ilBench;
00103 
00104                 $ilBench->start("ContentPresentation", "ilPageObject_read");
00105 
00106                 $query = "SELECT * FROM page_object WHERE page_id = '".$this->id."' ".
00107                         "AND parent_type='".$this->getParentType()."'";
00108                 $pg_set = $this->ilias->db->query($query);
00109                 if (!($this->page_record = $pg_set->fetchRow(DB_FETCHMODE_ASSOC)))
00110                 {
00111                         if ($this->halt_on_error)
00112                         {
00113                                 echo "Error: Page ".$this->id." is not in database".
00114                                         " (parent type ".$this->getParentType().")."; exit;
00115                         }
00116                         else
00117                         {
00118                                 $this->page_not_found = true;
00119                                 return;
00120                         }
00121                 }
00122                 $this->xml = $this->page_record["content"];
00123                 $this->setParentId($this->page_record["parent_id"]);
00124 
00125                 $ilBench->stop("ContentPresentation", "ilPageObject_read");
00126         }
00127 
00128         function buildDom()
00129         {
00130                 global $ilBench;
00131 
00132                 if ($this->dom_builded)
00133                 {
00134                         return;
00135                 }
00136 
00137 //echo "<br><br>".$this->getId().":xml:".htmlentities($this->getXMLContent(true)).":<br>";
00138 
00139                 $ilBench->start("ContentPresentation", "ilPageObject_buildDom");
00140                 $this->dom = @domxml_open_mem($this->getXMLContent(true), DOMXML_LOAD_VALIDATING, $error);
00141                 $ilBench->stop("ContentPresentation", "ilPageObject_buildDom");
00142 
00143         /*      if (!is_object($this->dom)) {
00144                         print_r($error);
00145                         echo "<br><br>".$this->getId().":xml:".htmlentities($this->getXMLContent(true)).":<br>";
00146                 }*/
00147                 $xpc = xpath_new_context($this->dom);
00148                 $path = "//PageObject";
00149                 $res =& xpath_eval($xpc, $path);
00150                 if (count($res->nodeset) == 1)
00151                 {
00152                         $this->node =& $res->nodeset[0];
00153                 }
00154 
00155                 if (empty($error))
00156                 {
00157                         $this->dom_builded = true;
00158                         return true;
00159                 }
00160                 else
00161                 {
00162                         return $error;
00163                 }
00164         }
00165 
00166         function freeDom()
00167         {
00168                 //$this->dom->free();
00169                 unset($this->dom);
00170         }
00171 
00172         function &getDom()
00173         {
00174                 return $this->dom;
00175         }
00176 
00180         function setId($a_id)
00181         {
00182                 $this->id = $a_id;
00183         }
00184 
00185         function getId()
00186         {
00187                 return $this->id;
00188         }
00189 
00190         function setParentId($a_id)
00191         {
00192                 $this->parent_id = $a_id;
00193         }
00194 
00195         function getParentId()
00196         {
00197                 return $this->parent_id;
00198         }
00199 
00200         function setParentType($a_type)
00201         {
00202                 $this->parent_type = $a_type;
00203         }
00204 
00205         function getParentType()
00206         {
00207                 return $this->parent_type;
00208         }
00209 
00210         function addUpdateListener(&$a_object, $a_method, $a_parameters = "")
00211         {
00212                 $cnt = $this->update_listener_cnt;
00213                 $this->update_listeners[$cnt]["object"] =& $a_object;
00214                 $this->update_listeners[$cnt]["method"] = $a_method;
00215                 $this->update_listeners[$cnt]["parameters"] = $a_parameters;
00216                 $this->update_listener_cnt++;
00217         }
00218 
00219         function callUpdateListeners()
00220         {
00221                 for($i=0; $i<$this->update_listener_cnt; $i++)
00222                 {
00223                         $object =& $this->update_listeners[$i]["object"];
00224                         $method = $this->update_listeners[$i]["method"];
00225                         $parameters = $this->update_listeners[$i]["parameters"];
00226                         $object->$method($parameters);
00227                 }
00228         }
00229 
00230         function &getContentObject($a_hier_id)
00231         {
00232 //echo ":".$a_hier_id.":";
00233 //echo "Content:".htmlentities($this->getXMLFromDOM()).":<br>";
00234 //echo "ilPageObject::getContentObject:hierid:".$a_hier_id.":<br>";
00235                 $cont_node =& $this->getContentNode($a_hier_id);
00236 //echo "ilPageObject::getContentObject:nodename:".$cont_node->node_name().":<br>";
00237                 switch($cont_node->node_name())
00238                 {
00239                         case "PageContent":
00240                                 $child_node =& $cont_node->first_child();
00241 //echo "<br>nodename:".$child_node->node_name();
00242                                 switch($child_node->node_name())
00243                                 {
00244                                         case "Paragraph":
00245                                                 require_once("content/classes/Pages/class.ilPCParagraph.php");
00246                                                 $par =& new ilPCParagraph($this->dom);
00247                                                 $par->setNode($cont_node);
00248                                                 $par->setHierId($a_hier_id);
00249                                                 return $par;
00250 
00251                                         case "Table":
00252                                                 require_once("content/classes/Pages/class.ilPCTable.php");
00253                                                 $tab =& new ilPCTable($this->dom);
00254                                                 $tab->setNode($cont_node);
00255                                                 $tab->setHierId($a_hier_id);
00256                                                 return $tab;
00257 
00258                                         case "MediaObject":
00259                                                 require_once("content/classes/Media/class.ilObjMediaObject.php");
00260 //echo "ilPageObject::getContentObject:nodename:".$child_node->node_name().":<br>";
00261                                                 $mal_node =& $child_node->first_child();
00262 //echo "ilPageObject::getContentObject:nodename:".$mal_node->node_name().":<br>";
00263                                                 $id_arr = explode("_", $mal_node->get_attribute("OriginId"));
00264                                                 $mob_id = $id_arr[count($id_arr) - 1];
00265                                                 $mob =& new ilObjMediaObject($mob_id);
00266                                                 $mob->setDom($this->dom);
00267                                                 $mob->setNode($cont_node);
00268                                                 $mob->setHierId($a_hier_id);
00269                                                 return $mob;
00270 
00271                                         case "List":
00272                                                 require_once("content/classes/Pages/class.ilPCList.php");
00273                                                 $list =& new ilPCList($this->dom);
00274                                                 $list->setNode($cont_node);
00275                                                 $list->setHierId($a_hier_id);
00276                                                 return $list;
00277 
00278                                         case "FileList":
00279                                                 require_once("content/classes/Pages/class.ilPCFileList.php");
00280                                                 $file_list =& new ilPCFileList($this->dom);
00281                                                 $file_list->setNode($cont_node);
00282                                                 $file_list->setHierId($a_hier_id);
00283                                                 return $file_list;
00284 
00285                                         // note: assessment handling is forwarded to assessment gui classes
00286                                         case "Question":
00287                                                 require_once("content/classes/Pages/class.ilPCQuestion.php");
00288                                                 $pc_question =& new ilPCQuestion($this->dom);
00289                                                 $pc_question->setNode($cont_node);
00290                                                 $pc_question->setHierId($a_hier_id);
00291                                                 return $pc_question;
00292                                 }
00293                                 break;
00294 
00295                         case "TableData":
00296                                 require_once("content/classes/Pages/class.ilPCTableData.php");
00297                                 $td =& new ilPCTableData($this->dom);
00298                                 $td->setNode($cont_node);
00299                                 $td->setHierId($a_hier_id);
00300                                 return $td;
00301 
00302                         case "ListItem":
00303                                 require_once("content/classes/Pages/class.ilPCListItem.php");
00304                                 $td =& new ilPCListItem($this->dom);
00305                                 $td->setNode($cont_node);
00306                                 $td->setHierId($a_hier_id);
00307                                 return $td;
00308 
00309                         case "FileItem":
00310                                 require_once("content/classes/Pages/class.ilPCFileItem.php");
00311                                 $file_item =& new ilPCFileItem($this->dom);
00312                                 $file_item->setNode($cont_node);
00313                                 $file_item->setHierId($a_hier_id);
00314                                 return $file_item;
00315 
00316                 }
00317         }
00318 
00319         function &getContentNode($a_hier_id)
00320         {
00321                 // search for attribute "//*[@HierId = '%s']".
00322 //echo "get node :$a_hier_id:";
00323                 $xpc = xpath_new_context($this->dom);
00324                 if($a_hier_id == "pg")
00325                 {
00326                         return $this->node;
00327                 }
00328                 else
00329                 {
00330                         $path = "//*[@HierId = '$a_hier_id']";
00331                 }
00332                 $res =& xpath_eval($xpc, $path);
00333 //echo "count:".count($res->nodeset).":hierid:$a_hier_id:";
00334                 if (count($res->nodeset) == 1)
00335                 {
00336                         $cont_node =& $res->nodeset[0];
00337                         return $cont_node;
00338                 }
00339         }
00340 
00341         // only for test purposes
00342         function lookforhier($a_hier_id)
00343         {
00344                 $xpc = xpath_new_context($this->dom);
00345                 $path = "//*[@HierId = '$a_hier_id']";
00346                 $res =& xpath_eval($xpc, $path);
00347                 if (count($res->nodeset) == 1)
00348                         return "YES";
00349                 else
00350                         return "NO";
00351         }
00352 
00353 
00354         function &getNode()
00355         {
00356                 return $this->node;
00357         }
00358 
00359 
00368         function setXMLContent($a_xml, $a_encoding = "UTF-8")
00369         {
00370                 $this->encoding = $a_encoding;
00371                 $this->xml = $a_xml;
00372         }
00373 
00380         function appendXMLContent($a_xml)
00381         {
00382                 $this->xml.= $a_xml;
00383         }
00384 
00385 
00389         function getXMLContent($a_incl_head = false)
00390         {
00391                 // build full http path for XML DOCTYPE header.
00392                 // Under windows a relative path doesn't work :-(
00393                 if($a_incl_head)
00394                 {
00395                         $enc_str = (!empty($this->encoding))
00396                                 ? "encoding=\"".$this->encoding."\""
00397                                 : "";
00398                         return "<?xml version=\"1.0\" $ecn_str ?>".
00399                 "<!DOCTYPE PageObject SYSTEM \"".ILIAS_ABSOLUTE_PATH."/xml/".$this->cur_dtd."\">".
00400                                 $this->xml;
00401                 }
00402                 else
00403                 {
00404                         return $this->xml;
00405                 }
00406         }
00407 
00412         function getXMLFromDom($a_incl_head = false, $a_append_mobs = false, $a_append_bib = false,
00413                 $a_append_str = "", $a_omit_pageobject_tag = false)
00414         {
00415                 if ($a_incl_head)
00416                 {
00417                         return $this->dom->dump_mem(0, $this->encoding);
00418                 }
00419                 else
00420                 {
00421                         // append multimedia object elements
00422                         if ($a_append_mobs || $a_append_bib || $a_append_link_info)
00423                         {
00424                                 $mobs = "";
00425                                 $bibs = "";
00426                                 if ($a_append_mobs)
00427                                 {
00428                                         $mobs =& $this->getMultimediaXML();
00429                                 }
00430                                 if ($a_append_bib)
00431                                 {
00432                                         $bibs =& $this->getBibliographyXML();
00433                                 }
00434                                 $trans =& $this->getLanguageVariablesXML();
00435                                 return "<dummy>".$this->dom->dump_node($this->node).$mobs.$bibs.$trans.$a_append_str."</dummy>";
00436                         }
00437                         else
00438                         {
00439                                 if (is_object($this->dom))
00440                                 {
00441                                         if ($a_omit_pageobject_tag)
00442                                         {
00443                                                 $xml = "";
00444                                                 $childs =& $this->node->child_nodes();
00445                                                 for($i = 0; $i < count($childs); $i++)
00446                                                 {
00447                                                         $xml.= $this->dom->dump_node($childs[$i]);
00448                                                 }
00449                                                 return $xml;
00450                                         }
00451                                         else
00452                                         {
00453                                                 return $this->dom->dump_node($this->node);
00454                                         }
00455                                 }
00456                                 else
00457                                 {
00458                                         return "";
00459                                 }
00460                         }
00461                 }
00462         }
00463 
00467         function getLanguageVariablesXML()
00468         {
00469                 global $lng;
00470 
00471                 $xml = "<LVs>";
00472                 $lang_vars = array("ordering_question_javascript_hint", "reset_definitions", "reset_pictures", 
00473                         "matching_question_javascript_hint", "matches", "ed_insert_par", "ed_insert_code",
00474                         "ed_insert_table", "ed_insert_media", "ed_insert_list",
00475                         "ed_insert_filelist", "ed_paste_clip", "ed_edit",
00476                         "ed_edit_prop", "ed_delete", "ed_moveafter", "ed_movebefore",
00477                         "ed_go", "ed_new_row_after", "ed_new_row_before",
00478                         "ed_new_col_after", "ed_new_col_before", "ed_delete_col",
00479                         "ed_delete_row", "ed_class", "ed_width", "ed_align_left",
00480                         "ed_align_right", "ed_align_center", "ed_align_left_float",
00481                         "ed_align_right_float", "ed_delete_item", "ed_new_item_before",
00482                         "ed_new_item_after", "ed_copy_clip", "please_select", "ed_split_page",
00483                         "ed_item_up", "ed_item_down", "ed_row_up", "ed_row_down",
00484                         "ed_col_left", "ed_col_right", "ed_split_page_next");
00485 
00486                 foreach ($lang_vars as $lang_var)
00487                 {
00488                         $this->appendLangVarXML($xml, $lang_var);
00489                 }
00490 
00491                 $xml.= "</LVs>";
00492 
00493                 return $xml;
00494         }
00495 
00496         function appendLangVarXML(&$xml, $var)
00497         {
00498                 global $lng;
00499 
00500                 $xml.= "<LV name=\"$var\" value=\"".$lng->txt("cont_".$var)."\"/>";
00501         }
00502 
00503         function getFirstParagraphText()
00504         {
00505                 $xpc = xpath_new_context($this->dom);
00506                 $path = "//Paragraph[1]";
00507                 $res =& xpath_eval($xpc, $path);
00508                 if (count($res->nodeset) > 0)
00509                 {
00510                         $cont_node =& $res->nodeset[0]->parent_node();
00511                         $par =& new ilPCParagraph($this->dom);
00512                         $par->setNode($cont_node);
00513                         return $par->getText();
00514                 }
00515                 else
00516                 {
00517                         return "";
00518                 }
00519         }
00520 
00521 
00530         function setContainsIntLink($a_contains_link)
00531         {
00532                 $this->contains_int_link = $a_contains_link;
00533         }
00534 
00539         function containsIntLink()
00540         {
00541                 return $this->contains_int_link;
00542         }
00543 
00544         function needsImportParsing($a_parse = "")
00545         {
00546 
00547                 if ($a_parse === true)
00548                 {
00549                         $this->needs_parsing = true;
00550                 }
00551                 if ($a_parse === false)
00552                 {
00553                         $this->needs_parsing = false;
00554                 }
00555                 return $this->needs_parsing;
00556         }
00557 
00562     function getBibliographyXML()
00563         {
00564         global $ilias;
00565 
00566                 // todo: access to $_GET and $_POST variables is not
00567                 // allowed in non GUI classes!
00568                 //
00569                 // access to db table object_reference is not allowed here!
00570         $r = $ilias->db->query("SELECT * FROM object_reference WHERE ref_id='".$_GET["ref_id"]."' ");
00571         $row = $r->fetchRow(DB_FETCHMODE_ASSOC);
00572 
00573         include_once("./classes/class.ilNestedSetXML.php");
00574         $nested = new ilNestedSetXML();
00575         $bibs_xml = $nested->export($row["obj_id"], "bib");
00576 
00577         return $bibs_xml;
00578     }
00579 
00580 
00585         function collectMediaObjects($a_inline_only = true)
00586         {
00587 //echo htmlentities($this->getXMLFromDom());
00588                 // determine all media aliases of the page
00589                 $xpc = xpath_new_context($this->dom);
00590                 $path = "//MediaObject/MediaAlias";
00591                 $res =& xpath_eval($xpc, $path);
00592                 $mob_ids = array();
00593                 for($i = 0; $i < count($res->nodeset); $i++)
00594                 {
00595                         $id_arr = explode("_", $res->nodeset[$i]->get_attribute("OriginId"));
00596                         $mob_id = $id_arr[count($id_arr) - 1];
00597                         $mob_ids[$mob_id] = $mob_id;
00598                 }
00599 
00600                 // determine all inline internal media links
00601                 $xpc = xpath_new_context($this->dom);
00602                 $path = "//IntLink[@Type = 'MediaObject']";
00603                 $res =& xpath_eval($xpc, $path);
00604 
00605                 for($i = 0; $i < count($res->nodeset); $i++)
00606                 {
00607                         if (($res->nodeset[$i]->get_attribute("TargetFrame") == "") ||
00608                                 (!$a_inline_only))
00609                         {
00610                                 $target = $res->nodeset[$i]->get_attribute("Target");
00611                                 $id_arr = explode("_", $target);
00612                                 if (($id_arr[1] == IL_INST_ID) ||
00613                                         (substr($target, 0, 4) == "il__"))
00614                                 {
00615                                         $mob_id = $id_arr[count($id_arr) - 1];
00616                                         $mob_ids[$mob_id] = $mob_id;
00617                                 }
00618                         }
00619                 }
00620 
00621                 return $mob_ids;
00622         }
00623 
00624 
00628         function getInternalLinks()
00629         {
00630 //echo "<br>PageObject::getInternalLinks[".$this->getId()."]";
00631                 // get all internal links of the page
00632                 $xpc = xpath_new_context($this->dom);
00633                 $path = "//IntLink";
00634                 $res =& xpath_eval($xpc, $path);
00635 
00636                 $links = array();
00637                 for($i = 0; $i < count($res->nodeset); $i++)
00638                 {
00639                         $target = $res->nodeset[$i]->get_attribute("Target");
00640                         $type = $res->nodeset[$i]->get_attribute("Type");
00641                         $targetframe = $res->nodeset[$i]->get_attribute("TargetFrame");
00642                         $links[$target.":".$type.":".$targetframe] =
00643                                 array("Target" => $target, "Type" => $type,
00644                                         "TargetFrame" => $targetframe);
00645                 }
00646                 unset($xpc);
00647 
00648                 // get all media aliases
00649                 $xpc = xpath_new_context($this->dom);
00650                 $path = "//MediaAlias";
00651                 $res =& xpath_eval($xpc, $path);
00652 
00653                 require_once("content/classes/Media/class.ilMediaItem.php");
00654                 for($i = 0; $i < count($res->nodeset); $i++)
00655                 {
00656                         $oid = $res->nodeset[$i]->get_attribute("OriginId");
00657                         if (substr($oid, 0, 4) =="il__")
00658                         {
00659                                 $id_arr = explode("_", $oid);
00660                                 $id = $id_arr[count($id_arr) - 1];
00661 
00662                                 $med_links = ilMediaItem::_getMapAreasIntLinks($id);
00663                                 foreach($med_links as $key => $med_link)
00664                                 {
00665                                         $links[$key] = $med_link;
00666                                 }
00667                         }
00668                 }
00669                 unset($xpc);
00670 
00671                 return $links;
00672         }
00673 
00677         function collectFileItems()
00678         {
00679 //echo "<br>PageObject::collectFileItems[".$this->getId()."]";
00680                 // determine all media aliases of the page
00681                 $xpc = xpath_new_context($this->dom);
00682                 $path = "//FileItem/Identifier";
00683                 $res =& xpath_eval($xpc, $path);
00684                 $file_ids = array();
00685                 for($i = 0; $i < count($res->nodeset); $i++)
00686                 {
00687                         $id_arr = explode("_", $res->nodeset[$i]->get_attribute("Entry"));
00688                         $file_id = $id_arr[count($id_arr) - 1];
00689                         $file_ids[$file_id] = $file_id;
00690                 }
00691 
00692                 return $file_ids;
00693         }
00694 
00699         function getMultimediaXML()
00700         {
00701                 $mob_ids = $this->collectMediaObjects();
00702 
00703                 // get xml of corresponding media objects
00704                 $mobs_xml = "";
00705                 require_once("content/classes/Media/class.ilObjMediaObject.php");
00706                 foreach($mob_ids as $mob_id => $dummy)
00707                 {
00708                         $mob_obj =& new ilObjMediaObject($mob_id);
00709                         $mobs_xml .= $mob_obj->getXML(IL_MODE_OUTPUT);
00710                 }
00711                 return $mobs_xml;
00712         }
00713 
00717         function getMediaAliasElement($a_mob_id, $a_nr = 1)
00718         {
00719                 $xpc = xpath_new_context($this->dom);
00720                 $path = "//MediaObject/MediaAlias[@OriginId='il__mob_$a_mob_id']";
00721                 $res =& xpath_eval($xpc, $path);
00722                 $mal_node =& $res->nodeset[$a_nr - 1];
00723                 $mob_node =& $mal_node->parent_node();
00724 
00725                 return $this->dom->dump_node($mob_node);
00726         }
00727 
00728         function validateDom()
00729         {
00730 //echo "<br>PageObject::validateDom[".$this->getId()."]";
00731 
00732 //echo "<br>PageObject::update:".htmlentities($this->getXMLFromDom()).":"; exit;
00733                 $this->stripHierIDs();
00734                 @$this->dom->validate($error);
00735                 return $error;
00736         }
00737 
00753         function addHierIDs()
00754         {
00755                 $this->hier_ids = array();
00756                 $this->first_row_ids = array();
00757                 $this->first_col_ids = array();
00758                 $this->list_item_ids = array();
00759                 $this->file_item_ids = array();
00760 
00761                 // set hierarchical ids for Paragraphs, Tables, TableRows and TableData elements
00762                 $xpc = xpath_new_context($this->dom);
00763                 //$path = "//Paragraph | //Table | //TableRow | //TableData";
00764                 $path = "//PageContent | //TableRow | //TableData | //ListItem | //FileItem";
00765                 $res =& xpath_eval($xpc, $path);
00766                 for($i = 0; $i < count($res->nodeset); $i++)
00767                 {
00768                         $cnode = $res->nodeset[$i];
00769                         $ctag = $cnode->node_name();
00770 
00771                         // get hierarchical id of previous sibling
00772                         $sib_hier_id = "";
00773                         while($cnode =& $cnode->previous_sibling())
00774                         {
00775                                 if (($cnode->node_type() == XML_ELEMENT_NODE)
00776                                         && $cnode->has_attribute("HierId"))
00777                                 {
00778                                         $sib_hier_id = $cnode->get_attribute("HierId");
00779                                         //$sib_hier_id = $id_attr->value();
00780                                         break;
00781                                 }
00782                         }
00783 
00784                         if ($sib_hier_id != "")         // set id to sibling id "+ 1"
00785                         {
00786                                 $node_hier_id = ilPageContent::incEdId($sib_hier_id);
00787                                 $res->nodeset[$i]->set_attribute("HierId", $node_hier_id);
00788                                 $this->hier_ids[] = $node_hier_id;
00789                                 if ($ctag == "TableData")
00790                                 {
00791                                         if (substr($par_hier_id,strlen($par_hier_id)-2) == "_1")
00792                                         {
00793                                                 $this->first_row_ids[] = $node_hier_id;
00794                                         }
00795                                 }
00796                                 if ($ctag == "ListItem")
00797                                 {
00798                                         $this->list_item_ids[] = $node_hier_id;
00799                                 }
00800                                 if ($ctag == "FileItem")
00801                                 {
00802                                         $this->file_item_ids[] = $node_hier_id;
00803                                 }
00804                         }
00805                         else                                            // no sibling -> node is first child
00806                         {
00807                                 // get hierarchical id of next parent
00808                                 $cnode = $res->nodeset[$i];
00809                                 $par_hier_id = "";
00810                                 while($cnode =& $cnode->parent_node())
00811                                 {
00812                                         if (($cnode->node_type() == XML_ELEMENT_NODE)
00813                                                 && $cnode->has_attribute("HierId"))
00814                                         {
00815                                                 $par_hier_id = $cnode->get_attribute("HierId");
00816                                                 //$par_hier_id = $id_attr->value();
00817                                                 break;
00818                                         }
00819                                 }
00820 
00821                                 if (($par_hier_id != "") && ($par_hier_id != "pg"))             // set id to parent_id."_1"
00822                                 {
00823                                         $node_hier_id = $par_hier_id."_1";
00824                                         $res->nodeset[$i]->set_attribute("HierId", $node_hier_id);
00825                                         $this->hier_ids[] = $node_hier_id;
00826                                         if ($ctag == "TableData")
00827                                         {
00828                                                 $this->first_col_ids[] = $node_hier_id;
00829                                                 if (substr($par_hier_id,strlen($par_hier_id)-2) == "_1")
00830                                                 {
00831                                                         $this->first_row_ids[] = $node_hier_id;
00832                                                 }
00833                                         }
00834                                         if ($ctag == "ListItem")
00835                                         {
00836                                                 $this->list_item_ids[] = $node_hier_id;
00837                                         }
00838                                         if ($ctag == "FileItem")
00839                                         {
00840                                                 $this->file_item_ids[] = $node_hier_id;
00841                                         }
00842 
00843                                 }
00844                                 else            // no sibling, no parent -> first node
00845                                 {
00846                                         $node_hier_id = "1";
00847                                         $res->nodeset[$i]->set_attribute("HierId", $node_hier_id);
00848                                         $this->hier_ids[] = $node_hier_id;
00849                                 }
00850                         }
00851                 }
00852 
00853                 // set special hierarchical id "pg" for pageobject
00854                 $xpc = xpath_new_context($this->dom);
00855                 $path = "//PageObject";
00856                 $res =& xpath_eval($xpc, $path);
00857                 for($i = 0; $i < count($res->nodeset); $i++)    // should only be 1
00858                 {
00859                         $res->nodeset[$i]->set_attribute("HierId", "pg");
00860                         $this->hier_ids[] = "pg";
00861                 }
00862                 unset($xpc);
00863         }
00864 
00868         function getHierIds()
00869         {
00870                 return $this->hier_ids;
00871         }
00872 
00873 
00877         function getFirstRowIds()
00878         {
00879                 return $this->first_row_ids;
00880         }
00881         
00885         function getFirstColumnIds()
00886         {
00887                 return $this->first_col_ids;
00888         }
00889         
00893         function getListItemIds()
00894         {
00895                 return $this->list_item_ids;
00896         }
00897         
00901         function getFileItemIds()
00902         {
00903                 return $this->file_item_ids;
00904         }
00905         
00909         function stripHierIDs()
00910         {
00911                 if(is_object($this->dom))
00912                 {
00913                         $xpc = xpath_new_context($this->dom);
00914                         $path = "//*[@HierId]";
00915                         $res =& xpath_eval($xpc, $path);
00916                         for($i = 0; $i < count($res->nodeset); $i++)    // should only be 1
00917                         {
00918                                 if ($res->nodeset[$i]->has_attribute("HierId"))
00919                                 {
00920                                         $res->nodeset[$i]->remove_attribute("HierId");
00921                                 }
00922                         }
00923                         unset($xpc);
00924                 }
00925         }
00926 
00930         function addFileSizes()
00931         {
00932                 $xpc = xpath_new_context($this->dom);
00933                 $path = "//FileItem";
00934                 $res =& xpath_eval($xpc, $path);
00935                 for($i = 0; $i < count($res->nodeset); $i++)
00936                 {
00937                         $cnode =& $res->nodeset[$i];
00938                         $size_node =& $this->dom->create_element("Size");
00939                         $size_node =& $cnode->append_child($size_node);
00940 
00941                         $childs =& $cnode->child_nodes();
00942                         $size = "";
00943                         for($j = 0; $j < count($childs); $j++)
00944                         {
00945                                 if ($childs[$j]->node_name() == "Identifier")
00946                                 {
00947                                         if ($childs[$j]->has_attribute("Entry"))
00948                                         {
00949                                                 $entry = $childs[$j]->get_attribute("Entry");
00950                                                 $entry_arr = explode("_", $entry);
00951                                                 $id = $entry_arr[count($entry_arr) - 1];
00952                                                 require_once("classes/class.ilObjFile.php");
00953                                                 $size = ilObjFile::_lookupFileSize($id);
00954                                         }
00955                                 }
00956                         }
00957                         $size_node->set_content($size);
00958                 }
00959 
00960                 unset($xpc);
00961         }
00962 
00966         function resolveIntLinks()
00967         {
00968                 // resolve normal internal links
00969                 $xpc = xpath_new_context($this->dom);
00970                 $path = "//IntLink";
00971                 $res =& xpath_eval($xpc, $path);
00972                 for($i = 0; $i < count($res->nodeset); $i++)
00973                 {
00974                         $target = $res->nodeset[$i]->get_attribute("Target");
00975                         $type = $res->nodeset[$i]->get_attribute("Type");
00976                         
00977                         $new_target = ilInternalLink::_getIdForImportId($type, $target);
00978                         if ($new_target !== false)
00979                         {
00980                                 $res->nodeset[$i]->set_attribute("Target", $new_target);
00981                         }
00982                         else            // check wether link target is same installation
00983                         {
00984                                 if (ilInternalLink::_extractInstOfTarget($target) == IL_INST_ID &&
00985                                         IL_INST_ID > 0)
00986                                 {
00987                                         $new_target = ilInternalLink::_removeInstFromTarget($target);
00988                                         if (ilInternalLink::_exists($type, $new_target))
00989                                         {
00990                                                 $res->nodeset[$i]->set_attribute("Target", $new_target);        
00991                                         }
00992                                 }
00993                         }
00994 
00995                 }
00996                 unset($xpc);
00997 
00998                 // resolve internal links in map areas
00999                 $xpc = xpath_new_context($this->dom);
01000                 $path = "//MediaAlias";
01001                 $res =& xpath_eval($xpc, $path);
01002 //echo "<br><b>page::resolve</b><br>";
01003 //echo "Content:".htmlentities($this->getXMLFromDOM()).":<br>";
01004                 for($i = 0; $i < count($res->nodeset); $i++)
01005                 {
01006                         $orig_id = $res->nodeset[$i]->get_attribute("OriginId");
01007                         $id_arr = explode("_", $orig_id);
01008                         $mob_id = $id_arr[count($id_arr) - 1];
01009                         ilMediaItem::_resolveMapAreaLinks($mob_id);
01010                 }
01011         }
01012 
01016         function createFromXML()
01017         {
01018                 global $lng;
01019 
01020 //echo "<br>PageObject::createFromXML[".$this->getId()."]";
01021 
01022                 if($this->getXMLContent() == "")
01023                 {
01024                         $this->setXMLContent("<PageObject></PageObject>");
01025                 }
01026                 // create object
01027                 $query = "INSERT INTO page_object (page_id, parent_id, content, parent_type) VALUES ".
01028                         "('".$this->getId()."', '".$this->getParentId()."','".ilUtil::prepareDBString($this->getXMLContent()).
01029                         "', '".$this->getParentType()."')";
01030                 if(!$this->ilias->db->checkQuerySize($query))
01031                 {
01032                         $this->ilias->raiseError($lng->txt("check_max_allowed_packet_size"),$this->ilias->error_obj->MESSAGE);
01033                         return false;
01034                 }
01035 
01036                 $this->ilias->db->query($query);
01037 //echo "created page:".htmlentities($this->getXMLContent())."<br>";
01038         }
01039 
01040         /*
01041         function &copy()
01042         {
01043                 $page_object =& new ilPageObject($this->getParentType());
01044                 $page_object->setParentId($this->getParentId());
01045                 $page_object->setXMLXContent($this->getXMLContent());
01046         }*/
01047 
01048 
01052         function updateFromXML()
01053         {
01054                 global $lng;
01055 //echo "<br>PageObject::updateFromXML[".$this->getId()."]";
01056 //echo "update:".ilUtil::prepareDBString(($this->getXMLContent())).":<br>";
01057 //echo "update:".htmlentities(ilUtil::prepareDBString(($this->getXMLContent()))).":<br>";
01058                 $query = "UPDATE page_object ".
01059                         "SET content = '".ilUtil::prepareDBString(($this->getXMLContent()))."' ".
01060                         ", parent_id='".$this->getParentId()."' ".
01061                         "WHERE page_id = '".$this->getId()."' AND parent_type='".$this->getParentType()."'";
01062 
01063                 if(!$this->ilias->db->checkQuerySize($query))
01064                 {
01065                         $this->ilias->raiseError($lng->txt("check_max_allowed_packet_size"),$this->ilias->error_obj->MESSAGE);
01066                         return false;
01067                 }
01068                 $this->ilias->db->query($query);
01069 
01070                 return true;
01071         }
01072 
01076         function update($a_validate = true)
01077         {
01078                 global $lng;
01079 //echo "<br>PageObject::update[".$this->getId()."],validate($a_validate)";
01080 
01081 //echo "<br>PageObject::update:".$this->getXMLFromDom().":";
01082 //echo "<br>PageObject::update:".htmlentities($this->getXMLFromDom()).":"; exit;
01083                 // test validating
01084                 if($a_validate)
01085                 {
01086                         $errors = $this->validateDom();
01087                 }
01088                 if(empty($errors))
01089                 {
01090                         $query = "UPDATE page_object ".
01091                                 "SET content = '".ilUtil::prepareDBString(($this->getXMLFromDom()))."' ".
01092                                 ", parent_id='".$this->getParentId()."' ".
01093                                 " WHERE page_id = '".$this->getId().
01094                                 "' AND parent_type='".$this->getParentType()."'";
01095                         if(!$this->ilias->db->checkQuerySize($query))
01096                         {
01097                                 $this->ilias->raiseError($lng->txt("check_max_allowed_packet_size"),$this->ilias->error_obj->MESSAGE);
01098                                 return false;
01099                         }
01100 
01101                         $this->ilias->db->query($query);
01102                         $this->saveMobUsage($this->getXMLFromDom());
01103                         $this->saveFileUsage();
01104                         $this->saveInternalLinks($this->getXMLFromDom());
01105                         $this->callUpdateListeners();
01106 //echo "<br>PageObject::update:".htmlentities($this->getXMLContent()).":";
01107                         return true;
01108                 }
01109                 else
01110                 {
01111                         return $errors;
01112                 }
01113         }
01114 
01115 
01119         function delete()
01120         {
01121                 $mobs = array();
01122                 $files = array();
01123                 
01124                 if (!$this->page_not_found)
01125                 {
01126                         $this->buildDom();
01127                         $mobs = $this->collectMediaObjects(false);
01128                         $files = $this->collectFileItems();
01129                 }
01130 
01131                 // delete mob usages
01132                 $this->saveMobUsage("<dummy></dummy>");
01133 
01134                 // delete internal links
01135                 $this->saveInternalLinks("<dummy></dummy>");
01136 
01137                 // delete all file usages
01138                 include_once("classes/class.ilObjFile.php");
01139                 ilObjFile::_deleteAllUsages($this->getParentType().":pg", $this->getId());
01140 
01141                 // delete page_object entry
01142                 $query = "DELETE FROM page_object ".
01143                         "WHERE page_id = '".$this->getId().
01144                         "' AND parent_type='".$this->getParentType()."'";
01145                 $this->ilias->db->query($query);
01146 
01147                 foreach ($mobs as $mob_id)
01148                 {
01149                         $mob_obj =& new ilObjMediaObject($mob_id);
01150                         $mob_obj->delete();
01151                 }
01152 
01153                 include_once("classes/class.ilObjFile.php");
01154                 foreach ($files as $file_id)
01155                 {
01156                         $file_obj =& new ilObjFile($file_id, false);
01157                         $file_obj->delete();
01158                 }
01159 
01160         }
01161 
01162 
01168         function saveMobUsage($a_xml)
01169         {
01170 //echo "<br>PageObject::saveMobUsage[".$this->getId()."]";
01171 
01172                 $doc = domxml_open_mem($a_xml);
01173 
01174                 // media aliases
01175                 $xpc = xpath_new_context($doc);
01176                 $path = "//MediaAlias";
01177                 $res =& xpath_eval($xpc, $path);
01178                 $usages = array();
01179                 for ($i=0; $i < count($res->nodeset); $i++)
01180                 {
01181                         $id_arr = explode("_", $res->nodeset[$i]->get_attribute("OriginId"));
01182                         $mob_id = $id_arr[count($id_arr) - 1];
01183                         if ($mob_id > 0)
01184                         {
01185                                 $usages[$mob_id] = true;
01186                         }
01187                 }
01188 
01189                 // media objects
01190                 $xpc = xpath_new_context($doc);
01191                 $path = "//MediaObject/MetaData/General/Identifier";
01192                 $res =& xpath_eval($xpc, $path);
01193                 for ($i=0; $i < count($res->nodeset); $i++)
01194                 {
01195                         $mob_entry = $res->nodeset[$i]->get_attribute("Entry");
01196                         $mob_arr = explode("_", $mob_entry);
01197                         $mob_id = $mob_arr[count($mob_arr) - 1];
01198                         if ($mob_id > 0)
01199                         {
01200                                 $usages[$mob_id] = true;
01201                         }
01202                 }
01203 
01204                 // internal links
01205                 $xpc = xpath_new_context($doc);
01206                 $path = "//IntLink[@Type='MediaObject']";
01207                 $res =& xpath_eval($xpc, $path);
01208                 for ($i=0; $i < count($res->nodeset); $i++)
01209                 {
01210                         $mob_target = $res->nodeset[$i]->get_attribute("Target");
01211                         $mob_arr = explode("_", $mob_target);
01212                         $mob_id = $mob_arr[count($mob_arr) - 1];
01213                         if ($mob_id > 0)
01214                         {
01215                                 $usages[$mob_id] = true;
01216                         }
01217                 }
01218 
01219                 include_once("content/classes/Media/class.ilObjMediaObject.php");
01220                 ilObjMediaObject::_deleteAllUsages($this->getParentType().":pg", $this->getId());
01221                 foreach($usages as $mob_id => $val)
01222                 {
01223                         ilObjMediaObject::_saveUsage($mob_id, $this->getParentType().":pg", $this->getId());
01224                 }
01225         }
01226 
01230         function saveFileUsage()
01231         {
01232 //echo "<br>PageObject::saveFileUsage[".$this->getId()."]";
01233                 $file_ids = $this->collectFileItems();
01234                 include_once("classes/class.ilObjFile.php");
01235                 ilObjFile::_deleteAllUsages($this->getParentType().":pg", $this->getId());
01236                 foreach($file_ids as $file_id)
01237                 {
01238                         ilObjFile::_saveUsage($file_id, $this->getParentType().":pg", $this->getId());
01239                 }
01240         }
01241 
01242 
01248         function saveInternalLinks($a_xml)
01249         {
01250 //echo "<br>PageObject::saveInternalLinks[".$this->getId()."]";
01251                 $doc = domxml_open_mem($a_xml);
01252 
01253 
01254                 include_once("content/classes/Pages/class.ilInternalLink.php");
01255                 ilInternalLink::_deleteAllLinksOfSource($this->getParentType().":pg", $this->getId());
01256 
01257                 // get all internal links
01258                 $xpc = xpath_new_context($doc);
01259                 $path = "//IntLink";
01260                 $res =& xpath_eval($xpc, $path);
01261                 for ($i=0; $i < count($res->nodeset); $i++)
01262                 {
01263                         $link_type = $res->nodeset[$i]->get_attribute("Type");
01264 
01265                         switch ($link_type)
01266                         {
01267                                 case "StructureObject":
01268                                         $t_type = "st";
01269                                         break;
01270 
01271                                 case "PageObject":
01272                                         $t_type = "pg";
01273                                         break;
01274 
01275                                 case "GlossaryItem":
01276                                         $t_type = "git";
01277                                         break;
01278 
01279                                 case "MediaObject":
01280                                         $t_type = "mob";
01281                                         break;
01282 
01283                                 case "RepositoryItem":
01284                                         $t_type = "obj";
01285                                         break;
01286                         }
01287 
01288                         $target = $res->nodeset[$i]->get_attribute("Target");
01289                         $target_arr = explode("_", $target);
01290                         $t_id = $target_arr[count($target_arr) - 1];
01291 
01292                         // link to other internal object
01293                         if (is_int(strpos($target, "__")))
01294                         {
01295                                 $t_inst = 0;
01296                         }
01297                         else    // link to unresolved object in other installation
01298                         {
01299                                 $t_inst = $target_arr[1];
01300                         }
01301 
01302                         if ($t_id > 0)
01303                         {
01304                                 ilInternalLink::_saveLink($this->getParentType().":pg", $this->getId(), $t_type,
01305                                         $t_id, $t_inst);
01306                         }
01307                 }
01308 
01309         }
01310 
01311 
01315         function create()
01316         {
01317                 $this->createFromXML();
01318         }
01319 
01327         function deleteContent($a_hid, $a_update = true)
01328         {
01329                 $curr_node =& $this->getContentNode($a_hid);
01330                 $curr_node->unlink_node($curr_node);
01331                 if ($a_update)
01332                 {
01333                         return $this->update();
01334                 }
01335         }
01336 
01344         function deleteContentFromHierId($a_hid, $a_update = true)
01345         {
01346                 $hier_ids = $this->getHierIds();
01347                 
01348                 // iterate all hierarchical ids
01349                 foreach ($hier_ids as $hier_id)
01350                 {
01351                         // delete top level nodes only
01352                         if (!is_int(strpos($hier_id, "_")))
01353                         {
01354                                 if ($hier_id != "pg" && $hier_id >= $a_hid)
01355                                 {
01356                                         $curr_node =& $this->getContentNode($hier_id);
01357                                         $curr_node->unlink_node($curr_node);
01358                                 }
01359                         }
01360                 }
01361                 if ($a_update)
01362                 {
01363                         return $this->update();
01364                 }
01365         }
01366 
01374         function deleteContentBeforeHierId($a_hid, $a_update = true)
01375         {
01376                 $hier_ids = $this->getHierIds();
01377                 
01378                 // iterate all hierarchical ids
01379                 foreach ($hier_ids as $hier_id)
01380                 {
01381                         // delete top level nodes only
01382                         if (!is_int(strpos($hier_id, "_")))
01383                         {
01384                                 if ($hier_id != "pg" && $hier_id < $a_hid)
01385                                 {
01386                                         $curr_node =& $this->getContentNode($hier_id);
01387                                         $curr_node->unlink_node($curr_node);
01388                                 }
01389                         }
01390                 }
01391                 if ($a_update)
01392                 {
01393                         return $this->update();
01394                 }
01395         }
01396         
01397         
01405         function _moveContentAfterHierId(&$a_source_page, &$a_target_page, $a_hid)
01406         {
01407                 $hier_ids = $a_source_page->getHierIds();
01408 
01409                 $copy_ids = array();
01410 
01411                 // iterate all hierarchical ids
01412                 foreach ($hier_ids as $hier_id)
01413                 {
01414                         // move top level nodes only
01415                         if (!is_int(strpos($hier_id, "_")))
01416                         {
01417                                 if ($hier_id != "pg" && $hier_id >= $a_hid)
01418                                 {
01419                                         $copy_ids[] = $hier_id;
01420                                 }
01421                         }
01422                 }
01423                 asort($copy_ids);
01424 
01425                 $parent_node =& $a_target_page->getContentNode("pg");
01426                 $target_dom =& $a_target_page->getDom();
01427                 $parent_childs =& $parent_node->child_nodes();
01428                 $first_child =& $parent_childs[0];
01429                 $cnt_parent_childs = count($parent_childs);
01430 
01431                 foreach($copy_ids as $copy_id)
01432                 {
01433                         $source_node =& $a_source_page->getContentNode($copy_id);
01434 
01435                         $new_node =& $source_node->clone_node(true);
01436                         $new_node->unlink_node($new_node);
01437 
01438                         $source_node->unlink_node($source_node);
01439 
01440                         if($cnt_parent_childs == 0)
01441                         {
01442                                 $new_node =& $parent_node->append_child($new_node);
01443                         }
01444                         else
01445                         {
01446                                 //$target_dom->import_node($new_node);
01447                                 $new_node =& $first_child->insert_before($new_node, $first_child);
01448                         }
01449                         $parent_childs =& $parent_node->child_nodes();
01450 
01451                         $cnt_parent_childs++;
01452                 }
01453 
01454                 $a_target_page->update();
01455                 $a_source_page->update();
01456 
01457         }
01458 
01462         function insertContent(&$a_cont_obj, $a_pos, $a_mode = IL_INSERT_AFTER)
01463         {
01464                 // move mode into container elements is always INSERT_CHILD
01465                 $curr_node =& $this->getContentNode($a_pos);
01466                 $curr_name = $curr_node->node_name();
01467                 if (($curr_name == "TableData") || ($curr_name == "PageObject") ||
01468                         ($curr_name == "ListItem"))
01469                 {
01470                         $a_mode = IL_INSERT_CHILD;
01471                 }
01472 
01473 
01474                 if($a_mode != IL_INSERT_CHILD)                  // determine parent hierarchical id
01475                 {                                                                               // of sibling at $a_pos
01476                         $pos = explode("_", $a_pos);
01477                         $target_pos = array_pop($pos);
01478                         $parent_pos = implode($pos, "_");
01479                 }
01480                 else            // if we should insert a child, $a_pos is alreade the hierarchical id
01481                 {                       // of the parent node
01482                         $parent_pos = $a_pos;
01483                 }
01484 
01485                 // get the parent node
01486                 if($parent_pos != "")
01487                 {
01488                         $parent_node =& $this->getContentNode($parent_pos);
01489                 }
01490                 else
01491                 {
01492                         $parent_node =& $this->getNode();
01493                 }
01494 
01495                 // count the parent children
01496                 $parent_childs =& $parent_node->child_nodes();
01497                 $cnt_parent_childs = count($parent_childs);
01498 //echo "ZZ$a_mode";
01499                 switch ($a_mode)
01500                 {
01501                         // insert new node after sibling at $a_pos
01502                         case IL_INSERT_AFTER:
01503                                 $new_node =& $a_cont_obj->getNode();
01504                                 //$a_pos = ilPageContent::incEdId($a_pos);
01505                                 //$curr_node =& $this->getContentNode($a_pos);
01506 //echo "behind $a_pos:";
01507                                 if($succ_node =& $curr_node->next_sibling())
01508                                 {
01509                                         $new_node =& $succ_node->insert_before($new_node, $succ_node);
01510                                 }
01511                                 else
01512                                 {
01513 //echo "movin doin append_child";
01514                                         $new_node =& $parent_node->append_child($new_node);
01515                                 }
01516                                 $a_cont_obj->setNode($new_node);
01517                                 break;
01518 
01519                         case IL_INSERT_BEFORE:
01520 //echo "INSERT_BEF";
01521                                 $new_node =& $a_cont_obj->getNode();
01522                                 $succ_node =& $this->getContentNode($a_pos);
01523                                 $new_node =& $succ_node->insert_before($new_node, $succ_node);
01524                                 $a_cont_obj->setNode($new_node);
01525                                 break;
01526 
01527                         // insert new node as first child of parent $a_pos (= $a_parent)
01528                         case IL_INSERT_CHILD:
01529 //echo "insert as child:parent_childs:$cnt_parent_childs:<br>";
01530                                 $new_node =& $a_cont_obj->getNode();
01531                                 if($cnt_parent_childs == 0)
01532                                 {
01533                                         $new_node =& $parent_node->append_child($new_node);
01534                                 }
01535                                 else
01536                                 {
01537                                         $new_node =& $parent_childs[0]->insert_before($new_node, $parent_childs[0]);
01538                                 }
01539                                 $a_cont_obj->setNode($new_node);
01540 //echo "PP";
01541                                 break;
01542                 }
01543 
01544         }
01545 
01546 
01551         function moveContentBefore($a_source, $a_target)
01552         {
01553                 if($a_source == $a_target)
01554                 {
01555                         return;
01556                 }
01557 
01558                 // clone the node
01559                 $content =& $this->getContentObject($a_source);
01560                 $source_node =& $content->getNode();
01561                 $clone_node =& $source_node->clone_node(true);
01562 
01563                 // delete source node
01564                 $this->deleteContent($a_source, false);
01565 
01566                 // insert cloned node at target
01567                 $content->setNode($clone_node);
01568                 $this->insertContent($content, $a_target, IL_INSERT_BEFORE);
01569                 return $this->update();
01570 
01571         }
01572 
01577         function moveContentAfter($a_source, $a_target)
01578         {
01579 //echo "source:$a_source:target:$a_target:<br>";
01580                 if($a_source == $a_target)
01581                 {
01582                         return;
01583                 }
01584 
01585 //echo "move source:$a_source:to:$a_target:<br>";
01586 
01587 
01588                 // clone the node
01589                 $content =& $this->getContentObject($a_source);
01590 //echo ":".get_class($content).":";
01591                 $source_node =& $content->getNode();
01592                 $clone_node =& $source_node->clone_node(true);
01593 
01594                 // delete source node
01595                 $this->deleteContent($a_source, false);
01596 
01597                 // insert cloned node at target
01598                 $content->setNode($clone_node);
01599                 $this->insertContent($content, $a_target, IL_INSERT_AFTER);
01600                 return $this->update();
01601         }
01602 
01606         function bbCode2XML(&$a_content)
01607         {
01608                 $a_content = eregi_replace("\[com\]","<Comment>",$a_content);
01609                 $a_content = eregi_replace("\[\/com\]","</Comment>",$a_content);
01610                 $a_content = eregi_replace("\[emp]","<Emph>",$a_content);
01611                 $a_content = eregi_replace("\[\/emp\]","</Emph>",$a_content);
01612                 $a_content = eregi_replace("\[str]","<Strong>",$a_content);
01613                 $a_content = eregi_replace("\[\/str\]","</Strong>",$a_content);
01614         }
01615 
01620         function insertInstIntoIDs($a_inst)
01621         {
01622 //echo "insertinto:$a_inst:<br>";
01623                 // insert inst id into internal links
01624                 $xpc = xpath_new_context($this->dom);
01625                 $path = "//IntLink";
01626                 $res =& xpath_eval($xpc, $path);
01627                 for($i = 0; $i < count($res->nodeset); $i++)
01628                 {
01629                         $target = $res->nodeset[$i]->get_attribute("Target");
01630                         $type = $res->nodeset[$i]->get_attribute("Type");
01631 
01632                         if (substr($target, 0, 4) == "il__")
01633                         {
01634                                 $new_target = "il_".$a_inst."_".substr($target, 4, strlen($target) - 4);
01635                                 $res->nodeset[$i]->set_attribute("Target", $new_target);
01636                         }
01637                 }
01638                 unset($xpc);
01639 
01640                 // insert inst id into media aliases
01641                 $xpc = xpath_new_context($this->dom);
01642                 $path = "//MediaAlias";
01643                 $res =& xpath_eval($xpc, $path);
01644                 for($i = 0; $i < count($res->nodeset); $i++)
01645                 {
01646                         $origin_id = $res->nodeset[$i]->get_attribute("OriginId");
01647                         if (substr($origin_id, 0, 4) == "il__")
01648                         {
01649                                 $new_id = "il_".$a_inst."_".substr($origin_id, 4, strlen($origin_id) - 4);
01650                                 $res->nodeset[$i]->set_attribute("OriginId", $new_id);
01651                         }
01652                 }
01653                 unset($xpc);
01654 
01655                 // insert inst id file item identifier entries
01656                 $xpc = xpath_new_context($this->dom);
01657                 $path = "//FileItem/Identifier";
01658                 $res =& xpath_eval($xpc, $path);
01659                 for($i = 0; $i < count($res->nodeset); $i++)
01660                 {
01661                         $origin_id = $res->nodeset[$i]->get_attribute("Entry");
01662                         if (substr($origin_id, 0, 4) == "il__")
01663                         {
01664                                 $new_id = "il_".$a_inst."_".substr($origin_id, 4, strlen($origin_id) - 4);
01665                                 $res->nodeset[$i]->set_attribute("Entry", $new_id);
01666                         }
01667                 }
01668                 unset($xpc);
01669                 
01670                 // insert inst id into 
01671                 $xpc = xpath_new_context($this->dom);
01672                 $path = "//Question";
01673                 $res =& xpath_eval($xpc, $path);
01674                 for($i = 0; $i < count($res->nodeset); $i++)
01675                 {
01676                         $qref = $res->nodeset[$i]->get_attribute("QRef");
01677 //echo "<br>setted:".$qref;
01678                         if (substr($qref, 0, 4) == "il__")
01679                         {
01680                                 $new_id = "il_".$a_inst."_".substr($qref, 4, strlen($qref) - 4);
01681 //echo "<br>setting:".$new_id;
01682                                 $res->nodeset[$i]->set_attribute("QRef", $new_id);
01683                         }
01684                 }
01685                 unset($xpc);
01686 
01687         }
01688 
01693         function highlightText($a_text, $proglang, $autoindent)
01694         {
01695 
01696                 if (!$this->hasHighlighter($proglang)) {
01697                         $proglang="plain";
01698                 }
01699 
01700                 require_once("syntax_highlight/php/HFile/HFile_$proglang.php");
01701                 $classname =  "HFile_$proglang";
01702                 $h_instance = new $classname();
01703                 if ($autoindent == "n") {
01704                         $h_instance ->notrim   = 1;
01705                         $h_instance ->indent   = array ("");
01706                         $h_instance ->unindent = array ("");
01707                 }
01708 
01709                 $highlighter = new Core($h_instance, new Output_css());
01710                 $a_text = $highlighter->highlight_text(html_entity_decode($a_text));
01711 
01712                 //$a_text = str_replace("&","&amp;",$a_text);
01713                 //$a_text = str_replace("<","&lt;", $a_text);
01714                 //$a_text = str_replace(">","&gt;", $a_text);
01715                 return $a_text;
01716         }
01717 
01718         function hasHighlighter ($hfile_ext) {
01719                 return file_exists ("syntax_highlight/php/HFile/HFile_$hfile_ext.php");
01720         }
01721 
01727         function addSourceCodeHighlighting()
01728         {
01729                 $xpc = xpath_new_context($this->dom);
01730                 $path = "//Paragraph[@Characteristic = 'Code']";
01731                 $res = & xpath_eval($xpc, $path);
01732                 for($i = 0; $i < count($res->nodeset); $i++)
01733                 {
01734                         $context_node = $res->nodeset[$i];
01735                         $n = $context_node->parent_node();
01736                         $char = $context_node->get_attribute('Characteristic');
01737                         $subchar = $context_node->get_attribute('SubCharacteristic');
01738                         $showlinenumbers = $context_node->get_attribute('ShowLineNumbers');
01739                         $downloadtitle = $context_node->get_attribute('DownloadTitle');
01740                         $autoindent = $context_node->get_attribute('AutoIndent');
01741 
01742                         $content = "";
01743 
01744 
01745                         // get XML Content
01746                         $childs = $context_node->child_nodes();
01747 
01748                         for($j=0; $j<count($childs); $j++)
01749                         {
01750                                 $content .= $this->dom->dump_node($childs[$j]);
01751                         }
01752 
01753                         //if ($subchar == "html")
01754                         //{
01755                         //$content = str_replace("&amp;lt;", "&lt;", $content);
01756                         //$content = str_replace("&amp;gt;", "&gt;", $content);
01757                         //$content = str_replace("&", "&amp;amp;", $content);
01758                         //}
01759 
01760                         while ($context_node->has_child_nodes ())
01761                         {
01762                                 $node_del = $context_node->first_child ();
01763                                 $context_node->remove_child ($node_del);
01764                         }
01765 
01766                         $content = str_replace("<br />", "<br/>", $content );
01767                         $content = str_replace("<br/>", "\n", $content);
01768                         $rownums = count(split ("\n",$content));
01769 
01770                         $plain_content = html_entity_decode($content);
01771                         $plain_content = preg_replace ("/\&#x([1-9a-f]{2});?/ise","chr (base_convert (\\1, 16, 10))",$plain_content);
01772                         $plain_content = preg_replace ("/\&#(\d+);?/ise","chr (\\1)",$plain_content);
01773                         $content = $this->highlightText($plain_content, $subchar, $autoindent);
01774 
01775                         $content = str_replace("&amp;lt;", "&lt;", $content);
01776                         $content = str_replace("&amp;gt;", "&gt;", $content);
01777                         $content = str_replace("&", "&amp;", $content);
01778 
01779                         //$rows          = htmlentities ("<TR valign=\"top\">");
01780                         $rows    = "<TR valign=\"top\">";
01781                         $rownumbers = "<TD nowrap=\"nowrap\" class=\"ilc_LineNumbers\"><PRE>";
01782 
01783                         if (strcmp($showlinenumbers,"y")==0)
01784                         {
01785                                 for ($j=0; $j < $rownums; $j++)
01786                                 {
01787                                         $indentno      = strlen($rownums) - strlen($j+1) + 2;
01788                                         $rownumeration = ($j+1);
01789                                         $rownumbers   .= $rownumeration;
01790                                         if ($j < $rownums-1)
01791                                         {
01792                                                 $rownumbers .= "<br />";
01793                                         }
01794                                 }
01795                                 //$rows .= $rownumbers.htmlentities ("</PRE></TD>");
01796                                 $rows .= $rownumbers."</PRE></TD>";
01797                         }
01798                         //$rows .= htmlentities ("<TD class=\"ilc_Sourcecode\"><PRE>").$content.htmlentities ("</PRE></TD></TR>");
01799                         $rows .= "<TD class=\"ilc_Sourcecode\"><PRE>".$content."</PRE></TD></TR>";
01800 
01801                         $newcontent = str_replace("\n", "<br />", $rows);
01802                         
01803                         // fix for ie explorer which is not able to produce empty line feeds with <br /><br />
01804                         $newcontent  = str_replace("<br /><br />", "<br/> <br />", $newcontent  );
01805 //echo "<br>".htmlentities($newcontent);
01806                         $context_node->set_content($newcontent);
01807                 }
01808 
01809         }
01810 
01811         function send_paragraph ($par_id, $filename) {
01812                 $this->builddom();
01813 
01814                 $mydom = $this->dom;
01815 
01816                 $xpc = xpath_new_context($mydom);
01817 
01818                 $path = "//PageContent[position () = $par_id]/Paragraph";
01819 
01820                 $res = & xpath_eval($xpc, $path);
01821 
01822                 if (count ($res->nodeset) != 1)
01823                         die ("Should not happen");
01824 
01825                 $context_node = $res->nodeset[0];
01826 
01827                 // get plain text
01828 
01829                 $childs = $context_node->child_nodes();
01830 
01831                 for($j=0; $j<count($childs); $j++)
01832                 {
01833                         $content .= $mydom->dump_node($childs[$j]);
01834                 }
01835 
01836                 $content = str_replace("<br />", "\n", $content);
01837                 $content = str_replace("<br/>", "\n", $content);
01838 
01839                 $plain_content = html_entity_decode($content);
01840 
01841                 ilUtil::deliverData($plain_content, $filename);
01842                 /*
01843                 $file_type = "application/octet-stream";
01844                 header("Content-type: ".$file_type);
01845                 header("Content-disposition: attachment; filename=\"$filename\"");
01846                 echo $plain_content;*/
01847                 exit();
01848         }
01849 
01853         function getFO()
01854         {
01855                 $xml = $this->getXMLFromDom(false, true, true);
01856                 $xsl = file_get_contents("./content/page_fo.xsl");
01857                 $args = array( '/_xml' => $xml, '/_xsl' => $xsl );
01858                 $xh = xslt_create();
01859 
01860                 $params = array ();
01861 
01862 
01863                 $fo = xslt_process($xh,"arg:/_xml","arg:/_xsl",NULL,$args, $params);
01864 
01865                 // do some replacements
01866                 $fo = str_replace("\n", "", $fo);
01867                 $fo = str_replace("<br/>", "<br>", $fo);
01868                 $fo = str_replace("<br>", "\n", $fo);
01869 
01870                 xslt_free($xh);
01871 
01872                 //
01873                 $fo = substr($fo, strpos($fo,">") + 1);
01874 //echo "<br><b>fo:</b><br>".htmlentities($fo); flush();
01875                 return $fo;
01876         }
01877 }
01878 ?>

Generated on Fri Dec 13 2013 09:06:36 for ILIAS Release_3_4_x_branch .rev 46804 by  doxygen 1.7.1