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

Generated on Fri Dec 13 2013 11:57:57 for ILIAS Release_3_6_x_branch .rev 46809 by  doxygen 1.7.1