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

Generated on Fri Dec 13 2013 08:00:16 for ILIAS Release_3_3_x_branch .rev 46803 by  doxygen 1.7.1