00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 require_once("content/classes/Pages/class.ilPageContent.php");
00026 require_once("content/classes/Pages/class.ilPCParagraph.php");
00027 require_once("./syntax_highlight/php/Beautifier/Init.php");
00028 require_once("./syntax_highlight/php/Output/Output_css.php");
00029
00030
00031 define("IL_INSERT_BEFORE", 0);
00032 define("IL_INSERT_AFTER", 1);
00033 define("IL_INSERT_CHILD", 2);
00034
00035 define ("IL_CHAPTER_TITLE", "st_title");
00036 define ("IL_PAGE_TITLE", "pg_title");
00037 define ("IL_NO_HEADER", "none");
00038
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
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
00145
00146
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
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
00234
00235
00236 $cont_node =& $this->getContentNode($a_hier_id);
00237
00238 switch($cont_node->node_name())
00239 {
00240 case "PageContent":
00241 $child_node =& $cont_node->first_child();
00242
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
00262 $mal_node =& $child_node->first_child();
00263
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
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
00323
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
00335 if (count($res->nodeset) == 1)
00336 {
00337 $cont_node =& $res->nodeset[0];
00338 return $cont_node;
00339 }
00340 }
00341
00342
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
00393
00394 if($a_incl_head)
00395 {
00396
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
00420 return $this->dom->dump_mem(0, $this->encoding);
00421 }
00422 else
00423 {
00424
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
00463
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
00577
00578
00579
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
00598
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
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 $mob_ids[$mob_id] = $mob_id;
00627 }
00628 }
00629 }
00630
00631 return $mob_ids;
00632 }
00633
00634
00638 function getInternalLinks()
00639 {
00640
00641 $xpc = xpath_new_context($this->dom);
00642 $path = "//IntLink";
00643 $res =& xpath_eval($xpc, $path);
00644
00645 $links = array();
00646 for($i = 0; $i < count($res->nodeset); $i++)
00647 {
00648 $target = $res->nodeset[$i]->get_attribute("Target");
00649 $type = $res->nodeset[$i]->get_attribute("Type");
00650 $targetframe = $res->nodeset[$i]->get_attribute("TargetFrame");
00651 $links[$target.":".$type.":".$targetframe] =
00652 array("Target" => $target, "Type" => $type,
00653 "TargetFrame" => $targetframe);
00654
00655
00656 if ($type == "MediaObject" && $targetframe == "")
00657 {
00658 if (substr($target, 0, 4) =="il__")
00659 {
00660 $id_arr = explode("_", $target);
00661 $id = $id_arr[count($id_arr) - 1];
00662
00663 $med_links = ilMediaItem::_getMapAreasIntLinks($id);
00664 foreach($med_links as $key => $med_link)
00665 {
00666 $links[$key] = $med_link;
00667 }
00668 }
00669
00670 }
00671
00672 }
00673 unset($xpc);
00674
00675
00676 $xpc = xpath_new_context($this->dom);
00677 $path = "//MediaAlias";
00678 $res =& xpath_eval($xpc, $path);
00679
00680 require_once("content/classes/Media/class.ilMediaItem.php");
00681 for($i = 0; $i < count($res->nodeset); $i++)
00682 {
00683 $oid = $res->nodeset[$i]->get_attribute("OriginId");
00684 if (substr($oid, 0, 4) =="il__")
00685 {
00686 $id_arr = explode("_", $oid);
00687 $id = $id_arr[count($id_arr) - 1];
00688
00689 $med_links = ilMediaItem::_getMapAreasIntLinks($id);
00690 foreach($med_links as $key => $med_link)
00691 {
00692 $links[$key] = $med_link;
00693 }
00694 }
00695 }
00696 unset($xpc);
00697
00698 return $links;
00699 }
00700
00704 function collectFileItems()
00705 {
00706
00707
00708 $xpc = xpath_new_context($this->dom);
00709 $path = "//FileItem/Identifier";
00710 $res =& xpath_eval($xpc, $path);
00711 $file_ids = array();
00712 for($i = 0; $i < count($res->nodeset); $i++)
00713 {
00714 $id_arr = explode("_", $res->nodeset[$i]->get_attribute("Entry"));
00715 $file_id = $id_arr[count($id_arr) - 1];
00716 $file_ids[$file_id] = $file_id;
00717 }
00718
00719 return $file_ids;
00720 }
00721
00726 function getMultimediaXML()
00727 {
00728 $mob_ids = $this->collectMediaObjects();
00729
00730
00731 $mobs_xml = "";
00732 require_once("content/classes/Media/class.ilObjMediaObject.php");
00733 foreach($mob_ids as $mob_id => $dummy)
00734 {
00735 $mob_obj =& new ilObjMediaObject($mob_id);
00736 $mobs_xml .= $mob_obj->getXML(IL_MODE_OUTPUT);
00737 }
00738 return $mobs_xml;
00739 }
00740
00744 function getMediaAliasElement($a_mob_id, $a_nr = 1)
00745 {
00746 $xpc = xpath_new_context($this->dom);
00747 $path = "//MediaObject/MediaAlias[@OriginId='il__mob_$a_mob_id']";
00748 $res =& xpath_eval($xpc, $path);
00749 $mal_node =& $res->nodeset[$a_nr - 1];
00750 $mob_node =& $mal_node->parent_node();
00751
00752 return $this->dom->dump_node($mob_node);
00753 }
00754
00755 function validateDom()
00756 {
00757
00758
00759
00760 $this->stripHierIDs();
00761 @$this->dom->validate($error);
00762 return $error;
00763 }
00764
00780 function addHierIDs()
00781 {
00782 $this->hier_ids = array();
00783 $this->first_row_ids = array();
00784 $this->first_col_ids = array();
00785 $this->list_item_ids = array();
00786 $this->file_item_ids = array();
00787
00788
00789 $xpc = xpath_new_context($this->dom);
00790
00791 $path = "//PageContent | //TableRow | //TableData | //ListItem | //FileItem";
00792 $res =& xpath_eval($xpc, $path);
00793 for($i = 0; $i < count($res->nodeset); $i++)
00794 {
00795 $cnode = $res->nodeset[$i];
00796 $ctag = $cnode->node_name();
00797
00798
00799 $sib_hier_id = "";
00800 while($cnode =& $cnode->previous_sibling())
00801 {
00802 if (($cnode->node_type() == XML_ELEMENT_NODE)
00803 && $cnode->has_attribute("HierId"))
00804 {
00805 $sib_hier_id = $cnode->get_attribute("HierId");
00806
00807 break;
00808 }
00809 }
00810
00811 if ($sib_hier_id != "")
00812 {
00813 $node_hier_id = ilPageContent::incEdId($sib_hier_id);
00814 $res->nodeset[$i]->set_attribute("HierId", $node_hier_id);
00815 $this->hier_ids[] = $node_hier_id;
00816 if ($ctag == "TableData")
00817 {
00818 if (substr($par_hier_id,strlen($par_hier_id)-2) == "_1")
00819 {
00820 $this->first_row_ids[] = $node_hier_id;
00821 }
00822 }
00823 if ($ctag == "ListItem")
00824 {
00825 $this->list_item_ids[] = $node_hier_id;
00826 }
00827 if ($ctag == "FileItem")
00828 {
00829 $this->file_item_ids[] = $node_hier_id;
00830 }
00831 }
00832 else
00833 {
00834
00835 $cnode = $res->nodeset[$i];
00836 $par_hier_id = "";
00837 while($cnode =& $cnode->parent_node())
00838 {
00839 if (($cnode->node_type() == XML_ELEMENT_NODE)
00840 && $cnode->has_attribute("HierId"))
00841 {
00842 $par_hier_id = $cnode->get_attribute("HierId");
00843
00844 break;
00845 }
00846 }
00847
00848 if (($par_hier_id != "") && ($par_hier_id != "pg"))
00849 {
00850 $node_hier_id = $par_hier_id."_1";
00851 $res->nodeset[$i]->set_attribute("HierId", $node_hier_id);
00852 $this->hier_ids[] = $node_hier_id;
00853 if ($ctag == "TableData")
00854 {
00855 $this->first_col_ids[] = $node_hier_id;
00856 if (substr($par_hier_id,strlen($par_hier_id)-2) == "_1")
00857 {
00858 $this->first_row_ids[] = $node_hier_id;
00859 }
00860 }
00861 if ($ctag == "ListItem")
00862 {
00863 $this->list_item_ids[] = $node_hier_id;
00864 }
00865 if ($ctag == "FileItem")
00866 {
00867 $this->file_item_ids[] = $node_hier_id;
00868 }
00869
00870 }
00871 else
00872 {
00873 $node_hier_id = "1";
00874 $res->nodeset[$i]->set_attribute("HierId", $node_hier_id);
00875 $this->hier_ids[] = $node_hier_id;
00876 }
00877 }
00878 }
00879
00880
00881 $xpc = xpath_new_context($this->dom);
00882 $path = "//PageObject";
00883 $res =& xpath_eval($xpc, $path);
00884 for($i = 0; $i < count($res->nodeset); $i++)
00885 {
00886 $res->nodeset[$i]->set_attribute("HierId", "pg");
00887 $this->hier_ids[] = "pg";
00888 }
00889 unset($xpc);
00890 }
00891
00895 function getHierIds()
00896 {
00897 return $this->hier_ids;
00898 }
00899
00900
00904 function getFirstRowIds()
00905 {
00906 return $this->first_row_ids;
00907 }
00908
00912 function getFirstColumnIds()
00913 {
00914 return $this->first_col_ids;
00915 }
00916
00920 function getListItemIds()
00921 {
00922 return $this->list_item_ids;
00923 }
00924
00928 function getFileItemIds()
00929 {
00930 return $this->file_item_ids;
00931 }
00932
00936 function stripHierIDs()
00937 {
00938 if(is_object($this->dom))
00939 {
00940 $xpc = xpath_new_context($this->dom);
00941 $path = "//*[@HierId]";
00942 $res =& xpath_eval($xpc, $path);
00943 for($i = 0; $i < count($res->nodeset); $i++)
00944 {
00945 if ($res->nodeset[$i]->has_attribute("HierId"))
00946 {
00947 $res->nodeset[$i]->remove_attribute("HierId");
00948 }
00949 }
00950 unset($xpc);
00951 }
00952 }
00953
00957 function addFileSizes()
00958 {
00959 $xpc = xpath_new_context($this->dom);
00960 $path = "//FileItem";
00961 $res =& xpath_eval($xpc, $path);
00962 for($i = 0; $i < count($res->nodeset); $i++)
00963 {
00964 $cnode =& $res->nodeset[$i];
00965 $size_node =& $this->dom->create_element("Size");
00966 $size_node =& $cnode->append_child($size_node);
00967
00968 $childs =& $cnode->child_nodes();
00969 $size = "";
00970 for($j = 0; $j < count($childs); $j++)
00971 {
00972 if ($childs[$j]->node_name() == "Identifier")
00973 {
00974 if ($childs[$j]->has_attribute("Entry"))
00975 {
00976 $entry = $childs[$j]->get_attribute("Entry");
00977 $entry_arr = explode("_", $entry);
00978 $id = $entry_arr[count($entry_arr) - 1];
00979 require_once("classes/class.ilObjFile.php");
00980 $size = ilObjFile::_lookupFileSize($id);
00981 }
00982 }
00983 }
00984 $size_node->set_content($size);
00985 }
00986
00987 unset($xpc);
00988 }
00989
00993 function resolveIntLinks()
00994 {
00995
00996 $xpc = xpath_new_context($this->dom);
00997 $path = "//IntLink";
00998 $res =& xpath_eval($xpc, $path);
00999 for($i = 0; $i < count($res->nodeset); $i++)
01000 {
01001 $target = $res->nodeset[$i]->get_attribute("Target");
01002 $type = $res->nodeset[$i]->get_attribute("Type");
01003
01004 $new_target = ilInternalLink::_getIdForImportId($type, $target);
01005 if ($new_target !== false)
01006 {
01007 $res->nodeset[$i]->set_attribute("Target", $new_target);
01008 }
01009 else
01010 {
01011 if (ilInternalLink::_extractInstOfTarget($target) == IL_INST_ID &&
01012 IL_INST_ID > 0)
01013 {
01014 $new_target = ilInternalLink::_removeInstFromTarget($target);
01015 if (ilInternalLink::_exists($type, $new_target))
01016 {
01017 $res->nodeset[$i]->set_attribute("Target", $new_target);
01018 }
01019 }
01020 }
01021
01022 }
01023 unset($xpc);
01024
01025
01026 $xpc = xpath_new_context($this->dom);
01027 $path = "//MediaAlias";
01028 $res =& xpath_eval($xpc, $path);
01029
01030
01031 for($i = 0; $i < count($res->nodeset); $i++)
01032 {
01033 $orig_id = $res->nodeset[$i]->get_attribute("OriginId");
01034 $id_arr = explode("_", $orig_id);
01035 $mob_id = $id_arr[count($id_arr) - 1];
01036 ilMediaItem::_resolveMapAreaLinks($mob_id);
01037 }
01038 }
01039
01043 function createFromXML()
01044 {
01045 global $lng;
01046
01047
01048
01049 if($this->getXMLContent() == "")
01050 {
01051 $this->setXMLContent("<PageObject></PageObject>");
01052 }
01053
01054 $query = "INSERT INTO page_object (page_id, parent_id, content, parent_type) VALUES ".
01055 "('".$this->getId()."', '".$this->getParentId()."','".ilUtil::prepareDBString($this->getXMLContent()).
01056 "', '".$this->getParentType()."')";
01057 if(!$this->ilias->db->checkQuerySize($query))
01058 {
01059 $this->ilias->raiseError($lng->txt("check_max_allowed_packet_size"),$this->ilias->error_obj->MESSAGE);
01060 return false;
01061 }
01062
01063 $this->ilias->db->query($query);
01064
01065 }
01066
01067
01068
01069
01070
01071
01072
01073
01074
01075
01079 function updateFromXML()
01080 {
01081 global $lng;
01082
01083
01084
01085 $query = "UPDATE page_object ".
01086 "SET content = '".ilUtil::prepareDBString(($this->getXMLContent()))."' ".
01087 ", parent_id='".$this->getParentId()."' ".
01088 "WHERE page_id = '".$this->getId()."' AND parent_type='".$this->getParentType()."'";
01089
01090 if(!$this->ilias->db->checkQuerySize($query))
01091 {
01092 $this->ilias->raiseError($lng->txt("check_max_allowed_packet_size"),$this->ilias->error_obj->MESSAGE);
01093 return false;
01094 }
01095 $this->ilias->db->query($query);
01096
01097 return true;
01098 }
01099
01103 function update($a_validate = true)
01104 {
01105 global $lng;
01106
01107
01108
01109
01110
01111 if($a_validate)
01112 {
01113 $errors = $this->validateDom();
01114 }
01115 if(empty($errors))
01116 {
01117 $content = ilUtil::prepareDBString(($this->getXMLFromDom()));
01118
01119 $query = "UPDATE page_object ".
01120 "SET content = '".$content."' ".
01121 ", parent_id='".$this->getParentId()."' ".
01122 " WHERE page_id = '".$this->getId().
01123 "' AND parent_type='".$this->getParentType()."'";
01124 if(!$this->ilias->db->checkQuerySize($query))
01125 {
01126 $this->ilias->raiseError($lng->txt("check_max_allowed_packet_size"),$this->ilias->error_obj->MESSAGE);
01127 return false;
01128 }
01129
01130 $this->ilias->db->query($query);
01131 $this->saveMobUsage($this->getXMLFromDom());
01132 $this->saveFileUsage();
01133 $this->saveInternalLinks($this->getXMLFromDom());
01134 $this->callUpdateListeners();
01135
01136 return true;
01137 }
01138 else
01139 {
01140 return $errors;
01141 }
01142 }
01143
01144
01148 function delete()
01149 {
01150 $mobs = array();
01151 $files = array();
01152
01153 if (!$this->page_not_found)
01154 {
01155 $this->buildDom();
01156 $mobs = $this->collectMediaObjects(false);
01157 $files = $this->collectFileItems();
01158 }
01159
01160
01161 $this->saveMobUsage("<dummy></dummy>");
01162
01163
01164 $this->saveInternalLinks("<dummy></dummy>");
01165
01166
01167 include_once("classes/class.ilObjFile.php");
01168 ilObjFile::_deleteAllUsages($this->getParentType().":pg", $this->getId());
01169
01170
01171 $query = "DELETE FROM page_object ".
01172 "WHERE page_id = '".$this->getId().
01173 "' AND parent_type='".$this->getParentType()."'";
01174 $this->ilias->db->query($query);
01175
01176 foreach ($mobs as $mob_id)
01177 {
01178 $mob_obj =& new ilObjMediaObject($mob_id);
01179 $mob_obj->delete();
01180 }
01181
01182 include_once("classes/class.ilObjFile.php");
01183 foreach ($files as $file_id)
01184 {
01185 $file_obj =& new ilObjFile($file_id, false);
01186 $file_obj->delete();
01187 }
01188
01189 }
01190
01191
01197 function saveMobUsage($a_xml)
01198 {
01199
01200
01201 $doc = domxml_open_mem($a_xml);
01202
01203
01204 $xpc = xpath_new_context($doc);
01205 $path = "//MediaAlias";
01206 $res =& xpath_eval($xpc, $path);
01207 $usages = array();
01208 for ($i=0; $i < count($res->nodeset); $i++)
01209 {
01210 $id_arr = explode("_", $res->nodeset[$i]->get_attribute("OriginId"));
01211 $mob_id = $id_arr[count($id_arr) - 1];
01212 if ($mob_id > 0)
01213 {
01214 $usages[$mob_id] = true;
01215 }
01216 }
01217
01218
01219 $xpc = xpath_new_context($doc);
01220 $path = "//MediaObject/MetaData/General/Identifier";
01221 $res =& xpath_eval($xpc, $path);
01222 for ($i=0; $i < count($res->nodeset); $i++)
01223 {
01224 $mob_entry = $res->nodeset[$i]->get_attribute("Entry");
01225 $mob_arr = explode("_", $mob_entry);
01226 $mob_id = $mob_arr[count($mob_arr) - 1];
01227 if ($mob_id > 0)
01228 {
01229 $usages[$mob_id] = true;
01230 }
01231 }
01232
01233
01234 $xpc = xpath_new_context($doc);
01235 $path = "//IntLink[@Type='MediaObject']";
01236 $res =& xpath_eval($xpc, $path);
01237 for ($i=0; $i < count($res->nodeset); $i++)
01238 {
01239 $mob_target = $res->nodeset[$i]->get_attribute("Target");
01240 $mob_arr = explode("_", $mob_target);
01241 $mob_id = $mob_arr[count($mob_arr) - 1];
01242 if ($mob_id > 0)
01243 {
01244 $usages[$mob_id] = true;
01245 }
01246 }
01247
01248 include_once("content/classes/Media/class.ilObjMediaObject.php");
01249 ilObjMediaObject::_deleteAllUsages($this->getParentType().":pg", $this->getId());
01250 foreach($usages as $mob_id => $val)
01251 {
01252 ilObjMediaObject::_saveUsage($mob_id, $this->getParentType().":pg", $this->getId());
01253 }
01254 }
01255
01259 function saveFileUsage()
01260 {
01261
01262 $file_ids = $this->collectFileItems();
01263 include_once("classes/class.ilObjFile.php");
01264 ilObjFile::_deleteAllUsages($this->getParentType().":pg", $this->getId());
01265 foreach($file_ids as $file_id)
01266 {
01267 ilObjFile::_saveUsage($file_id, $this->getParentType().":pg", $this->getId());
01268 }
01269 }
01270
01271
01277 function saveInternalLinks($a_xml)
01278 {
01279
01280 $doc = domxml_open_mem($a_xml);
01281
01282
01283 include_once("content/classes/Pages/class.ilInternalLink.php");
01284 ilInternalLink::_deleteAllLinksOfSource($this->getParentType().":pg", $this->getId());
01285
01286
01287 $xpc = xpath_new_context($doc);
01288 $path = "//IntLink";
01289 $res =& xpath_eval($xpc, $path);
01290 for ($i=0; $i < count($res->nodeset); $i++)
01291 {
01292 $link_type = $res->nodeset[$i]->get_attribute("Type");
01293
01294 switch ($link_type)
01295 {
01296 case "StructureObject":
01297 $t_type = "st";
01298 break;
01299
01300 case "PageObject":
01301 $t_type = "pg";
01302 break;
01303
01304 case "GlossaryItem":
01305 $t_type = "git";
01306 break;
01307
01308 case "MediaObject":
01309 $t_type = "mob";
01310 break;
01311
01312 case "RepositoryItem":
01313 $t_type = "obj";
01314 break;
01315 }
01316
01317 $target = $res->nodeset[$i]->get_attribute("Target");
01318 $target_arr = explode("_", $target);
01319 $t_id = $target_arr[count($target_arr) - 1];
01320
01321
01322 if (is_int(strpos($target, "__")))
01323 {
01324 $t_inst = 0;
01325 }
01326 else
01327 {
01328 $t_inst = $target_arr[1];
01329 }
01330
01331 if ($t_id > 0)
01332 {
01333 ilInternalLink::_saveLink($this->getParentType().":pg", $this->getId(), $t_type,
01334 $t_id, $t_inst);
01335 }
01336 }
01337
01338 }
01339
01340
01344 function create()
01345 {
01346 $this->createFromXML();
01347 }
01348
01356 function deleteContent($a_hid, $a_update = true)
01357 {
01358 $curr_node =& $this->getContentNode($a_hid);
01359 $curr_node->unlink_node($curr_node);
01360 if ($a_update)
01361 {
01362 return $this->update();
01363 }
01364 }
01365
01373 function deleteContentFromHierId($a_hid, $a_update = true)
01374 {
01375 $hier_ids = $this->getHierIds();
01376
01377
01378 foreach ($hier_ids as $hier_id)
01379 {
01380
01381 if (!is_int(strpos($hier_id, "_")))
01382 {
01383 if ($hier_id != "pg" && $hier_id >= $a_hid)
01384 {
01385 $curr_node =& $this->getContentNode($hier_id);
01386 $curr_node->unlink_node($curr_node);
01387 }
01388 }
01389 }
01390 if ($a_update)
01391 {
01392 return $this->update();
01393 }
01394 }
01395
01403 function deleteContentBeforeHierId($a_hid, $a_update = true)
01404 {
01405 $hier_ids = $this->getHierIds();
01406
01407
01408 foreach ($hier_ids as $hier_id)
01409 {
01410
01411 if (!is_int(strpos($hier_id, "_")))
01412 {
01413 if ($hier_id != "pg" && $hier_id < $a_hid)
01414 {
01415 $curr_node =& $this->getContentNode($hier_id);
01416 $curr_node->unlink_node($curr_node);
01417 }
01418 }
01419 }
01420 if ($a_update)
01421 {
01422 return $this->update();
01423 }
01424 }
01425
01426
01434 function _moveContentAfterHierId(&$a_source_page, &$a_target_page, $a_hid)
01435 {
01436 $hier_ids = $a_source_page->getHierIds();
01437
01438 $copy_ids = array();
01439
01440
01441 foreach ($hier_ids as $hier_id)
01442 {
01443
01444 if (!is_int(strpos($hier_id, "_")))
01445 {
01446 if ($hier_id != "pg" && $hier_id >= $a_hid)
01447 {
01448 $copy_ids[] = $hier_id;
01449 }
01450 }
01451 }
01452 asort($copy_ids);
01453
01454 $parent_node =& $a_target_page->getContentNode("pg");
01455 $target_dom =& $a_target_page->getDom();
01456 $parent_childs =& $parent_node->child_nodes();
01457 $first_child =& $parent_childs[0];
01458 $cnt_parent_childs = count($parent_childs);
01459
01460 foreach($copy_ids as $copy_id)
01461 {
01462 $source_node =& $a_source_page->getContentNode($copy_id);
01463
01464 $new_node =& $source_node->clone_node(true);
01465 $new_node->unlink_node($new_node);
01466
01467 $source_node->unlink_node($source_node);
01468
01469 if($cnt_parent_childs == 0)
01470 {
01471 $new_node =& $parent_node->append_child($new_node);
01472 }
01473 else
01474 {
01475
01476 $new_node =& $first_child->insert_before($new_node, $first_child);
01477 }
01478 $parent_childs =& $parent_node->child_nodes();
01479
01480 $cnt_parent_childs++;
01481 }
01482
01483 $a_target_page->update();
01484 $a_source_page->update();
01485
01486 }
01487
01491 function insertContent(&$a_cont_obj, $a_pos, $a_mode = IL_INSERT_AFTER)
01492 {
01493
01494 $curr_node =& $this->getContentNode($a_pos);
01495 $curr_name = $curr_node->node_name();
01496 if (($curr_name == "TableData") || ($curr_name == "PageObject") ||
01497 ($curr_name == "ListItem"))
01498 {
01499 $a_mode = IL_INSERT_CHILD;
01500 }
01501
01502
01503 if($a_mode != IL_INSERT_CHILD)
01504 {
01505 $pos = explode("_", $a_pos);
01506 $target_pos = array_pop($pos);
01507 $parent_pos = implode($pos, "_");
01508 }
01509 else
01510 {
01511 $parent_pos = $a_pos;
01512 }
01513
01514
01515 if($parent_pos != "")
01516 {
01517 $parent_node =& $this->getContentNode($parent_pos);
01518 }
01519 else
01520 {
01521 $parent_node =& $this->getNode();
01522 }
01523
01524
01525 $parent_childs =& $parent_node->child_nodes();
01526 $cnt_parent_childs = count($parent_childs);
01527
01528 switch ($a_mode)
01529 {
01530
01531 case IL_INSERT_AFTER:
01532 $new_node =& $a_cont_obj->getNode();
01533
01534
01535
01536 if($succ_node =& $curr_node->next_sibling())
01537 {
01538 $new_node =& $succ_node->insert_before($new_node, $succ_node);
01539 }
01540 else
01541 {
01542
01543 $new_node =& $parent_node->append_child($new_node);
01544 }
01545 $a_cont_obj->setNode($new_node);
01546 break;
01547
01548 case IL_INSERT_BEFORE:
01549
01550 $new_node =& $a_cont_obj->getNode();
01551 $succ_node =& $this->getContentNode($a_pos);
01552 $new_node =& $succ_node->insert_before($new_node, $succ_node);
01553 $a_cont_obj->setNode($new_node);
01554 break;
01555
01556
01557 case IL_INSERT_CHILD:
01558
01559 $new_node =& $a_cont_obj->getNode();
01560 if($cnt_parent_childs == 0)
01561 {
01562 $new_node =& $parent_node->append_child($new_node);
01563 }
01564 else
01565 {
01566 $new_node =& $parent_childs[0]->insert_before($new_node, $parent_childs[0]);
01567 }
01568 $a_cont_obj->setNode($new_node);
01569
01570 break;
01571 }
01572
01573 }
01574
01575
01580 function moveContentBefore($a_source, $a_target)
01581 {
01582 if($a_source == $a_target)
01583 {
01584 return;
01585 }
01586
01587
01588 $content =& $this->getContentObject($a_source);
01589 $source_node =& $content->getNode();
01590 $clone_node =& $source_node->clone_node(true);
01591
01592
01593 $this->deleteContent($a_source, false);
01594
01595
01596 $content->setNode($clone_node);
01597 $this->insertContent($content, $a_target, IL_INSERT_BEFORE);
01598 return $this->update();
01599
01600 }
01601
01606 function moveContentAfter($a_source, $a_target)
01607 {
01608
01609 if($a_source == $a_target)
01610 {
01611 return;
01612 }
01613
01614
01615
01616
01617
01618 $content =& $this->getContentObject($a_source);
01619
01620 $source_node =& $content->getNode();
01621 $clone_node =& $source_node->clone_node(true);
01622
01623
01624 $this->deleteContent($a_source, false);
01625
01626
01627 $content->setNode($clone_node);
01628 $this->insertContent($content, $a_target, IL_INSERT_AFTER);
01629 return $this->update();
01630 }
01631
01635 function bbCode2XML(&$a_content)
01636 {
01637 $a_content = eregi_replace("\[com\]","<Comment>",$a_content);
01638 $a_content = eregi_replace("\[\/com\]","</Comment>",$a_content);
01639 $a_content = eregi_replace("\[emp]","<Emph>",$a_content);
01640 $a_content = eregi_replace("\[\/emp\]","</Emph>",$a_content);
01641 $a_content = eregi_replace("\[str]","<Strong>",$a_content);
01642 $a_content = eregi_replace("\[\/str\]","</Strong>",$a_content);
01643 }
01644
01649 function insertInstIntoIDs($a_inst)
01650 {
01651
01652
01653 $xpc = xpath_new_context($this->dom);
01654 $path = "//IntLink";
01655 $res =& xpath_eval($xpc, $path);
01656 for($i = 0; $i < count($res->nodeset); $i++)
01657 {
01658 $target = $res->nodeset[$i]->get_attribute("Target");
01659 $type = $res->nodeset[$i]->get_attribute("Type");
01660
01661 if (substr($target, 0, 4) == "il__")
01662 {
01663 $new_target = "il_".$a_inst."_".substr($target, 4, strlen($target) - 4);
01664 $res->nodeset[$i]->set_attribute("Target", $new_target);
01665 }
01666 }
01667 unset($xpc);
01668
01669
01670 $xpc = xpath_new_context($this->dom);
01671 $path = "//MediaAlias";
01672 $res =& xpath_eval($xpc, $path);
01673 for($i = 0; $i < count($res->nodeset); $i++)
01674 {
01675 $origin_id = $res->nodeset[$i]->get_attribute("OriginId");
01676 if (substr($origin_id, 0, 4) == "il__")
01677 {
01678 $new_id = "il_".$a_inst."_".substr($origin_id, 4, strlen($origin_id) - 4);
01679 $res->nodeset[$i]->set_attribute("OriginId", $new_id);
01680 }
01681 }
01682 unset($xpc);
01683
01684
01685 $xpc = xpath_new_context($this->dom);
01686 $path = "//FileItem/Identifier";
01687 $res =& xpath_eval($xpc, $path);
01688 for($i = 0; $i < count($res->nodeset); $i++)
01689 {
01690 $origin_id = $res->nodeset[$i]->get_attribute("Entry");
01691 if (substr($origin_id, 0, 4) == "il__")
01692 {
01693 $new_id = "il_".$a_inst."_".substr($origin_id, 4, strlen($origin_id) - 4);
01694 $res->nodeset[$i]->set_attribute("Entry", $new_id);
01695 }
01696 }
01697 unset($xpc);
01698
01699
01700 $xpc = xpath_new_context($this->dom);
01701 $path = "//Question";
01702 $res =& xpath_eval($xpc, $path);
01703 for($i = 0; $i < count($res->nodeset); $i++)
01704 {
01705 $qref = $res->nodeset[$i]->get_attribute("QRef");
01706
01707 if (substr($qref, 0, 4) == "il__")
01708 {
01709 $new_id = "il_".$a_inst."_".substr($qref, 4, strlen($qref) - 4);
01710
01711 $res->nodeset[$i]->set_attribute("QRef", $new_id);
01712 }
01713 }
01714 unset($xpc);
01715
01716 }
01717
01722 function highlightText($a_text, $proglang, $autoindent)
01723 {
01724
01725 if (!$this->hasHighlighter($proglang)) {
01726 $proglang="plain";
01727 }
01728
01729 require_once("./syntax_highlight/php/HFile/HFile_".$proglang.".php");
01730 $classname = "HFile_$proglang";
01731 $h_instance = new $classname();
01732 if ($autoindent == "n") {
01733 $h_instance ->notrim = 1;
01734 $h_instance ->indent = array ("");
01735 $h_instance ->unindent = array ("");
01736 }
01737
01738 $highlighter = new Core($h_instance, new Output_css());
01739 $a_text = $highlighter->highlight_text(html_entity_decode($a_text));
01740
01741 return $a_text;
01742 }
01743
01744 function hasHighlighter ($hfile_ext) {
01745 return file_exists ("syntax_highlight/php/HFile/HFile_".$hfile_ext.".php");
01746 }
01747
01753 function addSourceCodeHighlighting($outputmode = "presentation")
01754 {
01755 $xpc = xpath_new_context($this->dom);
01756 $path = "//Paragraph";
01757 $res = & xpath_eval($xpc, $path);
01758 for($i = 0; $i < count($res->nodeset); $i++)
01759 {
01760 $context_node = $res->nodeset[$i];
01761 $char = $context_node->get_attribute('Characteristic');
01762
01763 if ($char != "Code")
01764 continue;
01765
01766 $n = $context_node->parent_node();
01767 $char = $context_node->get_attribute('Characteristic');
01768 $subchar = $context_node->get_attribute('SubCharacteristic');
01769 $showlinenumbers = $context_node->get_attribute('ShowLineNumbers');
01770 $downloadtitle = $context_node->get_attribute('DownloadTitle');
01771 $autoindent = $context_node->get_attribute('AutoIndent');
01772
01773 $content = "";
01774
01775
01776
01777 $childs = $context_node->child_nodes();
01778
01779 for($j=0; $j<count($childs); $j++)
01780 {
01781 $content .= $this->dom->dump_node($childs[$j]);
01782 }
01783
01784 while ($context_node->has_child_nodes ())
01785 {
01786 $node_del = $context_node->first_child ();
01787 $context_node->remove_child ($node_del);
01788 }
01789
01790 $content = str_replace("<br />", "<br/>", $content );
01791 $content = str_replace("<br/>", "\n", $content);
01792 $rownums = count(split ("\n",$content));
01793
01794 $plain_content = html_entity_decode($content);
01795 $plain_content = preg_replace ("/\&#x([1-9a-f]{2});?/ise","chr (base_convert (\\1, 16, 10))",$plain_content);
01796 $plain_content = preg_replace ("/\&#(\d+);?/ise","chr (\\1)",$plain_content);
01797 $content = utf8_encode($this->highlightText($plain_content, $subchar, $autoindent));
01798
01799 $content = str_replace("&lt;", "<", $content);
01800 $content = str_replace("&gt;", ">", $content);
01801 $content = str_replace("&", "&", $content);
01802
01803
01804 $rows = "<TR valign=\"top\">";
01805 $rownumbers = "<TD nowrap=\"nowrap\" class=\"ilc_LineNumbers\"><PRE>";
01806
01807 if (strcmp($showlinenumbers,"y")==0)
01808 {
01809 for ($j=0; $j < $rownums; $j++)
01810 {
01811 $indentno = strlen($rownums) - strlen($j+1) + 2;
01812 $rownumeration = ($j+1);
01813 $rownumbers .= $rownumeration;
01814 if ($j < $rownums-1)
01815 {
01816 $rownumbers .= "<br />";
01817 }
01818 }
01819
01820 $rows .= $rownumbers."</PRE></TD>";
01821 }
01822
01823 $rows .= "<TD class=\"ilc_Sourcecode\"><PRE>".$content."</PRE></TD></TR>";
01824
01825
01826
01827 $newcontent = str_replace("\n", "<br/>", $rows);
01828
01829 $context_node->set_content($newcontent);
01830 if ($outputmode != "presentation" && is_object($this->offline_handler)
01831 && trim($downloadtitle) != "")
01832 {
01833
01834 $this->offline_handler->handleCodeParagraph ($this->id, $i + 1, $downloadtitle, $plain_content);
01835 }
01836 }
01837 }
01838
01839
01840 function send_paragraph ($par_id, $filename) {
01841 $this->builddom();
01842
01843 $mydom = $this->dom;
01844
01845 $xpc = xpath_new_context($mydom);
01846
01847 $path = "//PageContent[position () = $par_id]/Paragraph";
01848
01849 $res = & xpath_eval($xpc, $path);
01850
01851 if (count ($res->nodeset) != 1)
01852 die ("Should not happen");
01853
01854 $context_node = $res->nodeset[0];
01855
01856
01857
01858 $childs = $context_node->child_nodes();
01859
01860 for($j=0; $j<count($childs); $j++)
01861 {
01862 $content .= $mydom->dump_node($childs[$j]);
01863 }
01864
01865 $content = str_replace("<br />", "\n", $content);
01866 $content = str_replace("<br/>", "\n", $content);
01867
01868 $plain_content = html_entity_decode($content);
01869
01870 ilUtil::deliverData($plain_content, $filename);
01871
01872
01873
01874
01875
01876 exit();
01877 }
01878
01882 function getFO()
01883 {
01884 $xml = $this->getXMLFromDom(false, true, true);
01885 $xsl = file_get_contents("./content/page_fo.xsl");
01886 $args = array( '/_xml' => $xml, '/_xsl' => $xsl );
01887 $xh = xslt_create();
01888
01889 $params = array ();
01890
01891
01892 $fo = xslt_process($xh,"arg:/_xml","arg:/_xsl",NULL,$args, $params);
01893
01894
01895 $fo = str_replace("\n", "", $fo);
01896 $fo = str_replace("<br/>", "<br>", $fo);
01897 $fo = str_replace("<br>", "\n", $fo);
01898
01899 xslt_free($xh);
01900
01901
01902 $fo = substr($fo, strpos($fo,">") + 1);
01903
01904 return $fo;
01905 }
01906
01907 function registerOfflineHandler ($handler) {
01908 $this->offline_handler = $handler;
01909 }
01910 }
01911 ?>