/** * Insert content template * * @param ilPageObject $a_pg_obj page object * @param string $a_hier_id Hierarchical ID * @param string $a_pc_id pc id * @param int $a_page_templ template page id */ function create($a_pg_obj, $a_hier_id, $a_pc_id, $a_page_templ) { $source_id = explode(":", $a_page_templ); $source_page = ilPageObjectFactory::getInstance($source_id[1], $source_id[0]); $source_page->buildDom(); $source_page->addHierIds(); $hier_ids = $source_page->getHierIds(); $copy_ids = array(); foreach ($hier_ids as $hier_id) { // move top level nodes only if (!is_int(strpos($hier_id, "_"))) { if ($hier_id != "pg" && $hier_id >= $a_hid) { $copy_ids[] = $hier_id; } } } asort($copy_ids); // get the target parent node $pos = explode("_", $a_pos); array_pop($pos); $parent_pos = implode($pos, "_"); if ($parent_pos != "") { $target_parent = $a_pg_obj->getContentNode($parent_pos); } else { $target_parent = $a_pg_obj->getNode(); } //$source_parent = $source_page->getContentNode("pg"); $curr_node = $a_pg_obj->getContentNode($a_hier_id, $a_pcid); foreach ($copy_ids as $copy_id) { $source_node = $source_page->getContentNode($copy_id); $new_node = $source_node->clone_node(true); $new_node->unlink_node($new_node); if ($succ_node = $curr_node->next_sibling()) { $succ_node->insert_before($new_node, $succ_node); } else { //echo "movin doin append_child"; $target_parent->append_child($new_node); } //$xpc = xpath_new_context($a_pg_obj->getDomDoc()); $xpath = new DOMXpath($a_pg_obj->getDomDoc()); //var_dump($new_node->myDOMNode); //echo "-".$new_node->get_attribute("PCID")."-"; exit; if ($new_node->get_attribute("PCID") != "") { $new_node->set_attribute("PCID", ""); } $els = $xpath->query(".//*[@PCID]", $new_node->myDOMNode); foreach ($els as $el) { $el->setAttribute("PCID", ""); } $curr_node = $new_node; } $a_pg_obj->update(); //$this->node = $this->createPageContentNode(); /*$a_pg_obj->insertContent($this, $a_hier_id, IL_INSERT_AFTER, $a_pc_id); $this->map_node =& $this->dom->create_element("Map"); $this->map_node =& $this->node->append_child($this->map_node); $this->map_node->set_attribute("Latitude", "0"); $this->map_node->set_attribute("Longitude", "0"); $this->map_node->set_attribute("Zoom", "3");*/ }
/** * Final processing * * @param array mapping array */ function finalProcessing($a_mapping) { $pages = $a_mapping->getMappingsOfEntity("Services/COPage", "pg"); $media_objects = $a_mapping->getMappingsOfEntity("Services/MediaObjects", "mob"); $file_objects = $a_mapping->getMappingsOfEntity("Modules/File", "file"); if (count($media_objects) > 0 || count($file_objects) > 0) { foreach ($pages as $p) { $id = explode(":", $p); if (count($id) == 2) { include_once "./Services/COPage/classes/class.ilPageObject.php"; if (ilPageObject::_exists($id[0], $id[1])) { include_once "./Services/COPage/classes/class.ilPageObjectFactory.php"; $new_page = ilPageObjectFactory::getInstance($id[0], $id[1]); $new_page->buildDom(); $med = $new_page->resolveMediaAliases($media_objects); $fil = $new_page->resolveFileItems($file_objects); if ($med || $fil) { $new_page->update(false, true); } } } } } }
/** * Update internal links, after multiple pages have been copied */ static function updateInternalLinks($a_copied_nodes, $a_parent_type = "lm") { $all_fixes = array(); foreach ($a_copied_nodes as $original_id => $copied_id) { $copied_type = ilLMObject::_lookupType($copied_id); $copy_lm = ilLMObject::_lookupContObjID($copied_id); if ($copied_type == "pg") { // // 1. Outgoing links from the copied page. // //$targets = ilInternalLink::_getTargetsOfSource($a_parent_type.":pg", $copied_id); include_once "./Modules/LearningModule/classes/class.ilLMPage.php"; $tpg = new ilLMPage($copied_id); $tpg->buildDom(); $il = $tpg->getInternalLinks(); $targets = array(); foreach ($il as $l) { $targets[] = array("type" => ilInternalLink::_extractTypeOfTarget($l["Target"]), "id" => (int) ilInternalLink::_extractObjIdOfTarget($l["Target"]), "inst" => (int) ilInternalLink::_extractInstOfTarget($l["Target"])); } $fix = array(); foreach ($targets as $target) { if (($target["inst"] == 0 || ($target["inst"] = IL_INST_ID)) && ($target["type"] == "pg" || $target["type"] == "st")) { // first check, whether target is also within the copied set if ($a_copied_nodes[$target["id"]] > 0) { $fix[$target["id"]] = $a_copied_nodes[$target["id"]]; } else { // now check, if a copy if the target is already in the same lm // only if target is not already in the same lm! $trg_lm = ilLMObject::_lookupContObjID($target["id"]); if ($trg_lm != $copy_lm) { $lm_data = ilLMObject::_getAllObjectsForImportId("il__" . $target["type"] . "_" . $target["id"]); $found = false; foreach ($lm_data as $item) { if (!$found && $item["lm_id"] == $copy_lm) { $fix[$target["id"]] = $item["obj_id"]; $found = true; } } } } } } // outgoing links to be fixed if (count($fix) > 0) { //echo "<br>--".$copied_id; //var_dump($fix); $t = ilObject::_lookupType($copy_lm); if (is_array($all_fixes[$t . ":" . $copied_id])) { $all_fixes[$t . ":" . $copied_id] += $fix; } else { $all_fixes[$t . ":" . $copied_id] = $fix; } } } if ($copied_type == "pg" || $copied_type == "st") { // // 2. Incoming links to the original pages // // A->B A2 (A+B currently copied) // A->C B2 // B->A // C->A C2->A (C already copied) $original_lm = ilLMObject::_lookupContObjID($original_id); $original_type = ilObject::_lookupType($original_lm); if ($original_lm != $copy_lm) { // This gets sources that link to A+B (so we have C here) // (this also does already the trick when instance map areas are given in C) // int_link, where target_type, target_id, target_inst -> ok $sources = ilInternalLink::_getSourcesOfTarget($copied_type, $original_id, 0); // mobs linking to $original_id // map_area, where link_type, target -> ok $mobs = ilMapArea::_getMobsForTarget("int", "il__" . $copied_type . "_" . $original_id); // pages using these mobs include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php"; foreach ($mobs as $mob) { // mob_usage, where id -> ok // mep_item, where foreign_id, type -> ok // mep_tree, where child -> already existed // il_news_item, where mob_id -> ok // map_area, where link_type, target -> aready existed // media_item, where id -> already existed // personal_clipboard, where item_id, type -> ok $usages = ilObjMediaObject::lookupUsages($mob); foreach ($usages as $usage) { if ($usage["type"] == "lm:pg" | $usage["type"] == "lm:st") { $sources[] = $usage; } } } $fix = array(); foreach ($sources as $source) { $stype = explode(":", $source["type"]); $source_type = $stype[1]; if ($source_type == "pg" || $source_type == "st") { // first of all: source must be in original lm $src_lm = ilLMObject::_lookupContObjID($source["id"]); if ($src_lm == $original_lm) { // check, if a copy if the source is already in the same lm // now we look for the latest copy of C in LM2 $lm_data = ilLMObject::_getAllObjectsForImportId("il__" . $source_type . "_" . $source["id"], $copy_lm); $found = false; foreach ($lm_data as $item) { if (!$found) { $fix[$item["obj_id"]][$original_id] = $copied_id; $found = true; } } } } } // outgoing links to be fixed if (count($fix) > 0) { foreach ($fix as $page_id => $fix_array) { $t = ilObject::_lookupType($copy_lm); if (is_array($all_fixes[$t . ":" . $page_id])) { $all_fixes[$t . ":" . $page_id] += $fix_array; } else { $all_fixes[$t . ":" . $page_id] = $fix_array; } } } } } } foreach ($all_fixes as $pg => $fixes) { $pg = explode(":", $pg); include_once "./Services/COPage/classes/class.ilPageObjectFactory.php"; $page = ilPageObjectFactory::getInstance($pg[0], $pg[1]); if ($page->moveIntLinks($fixes)) { $page->update(true, true); } } }
/** * Copy page to translation * * @param string $a_target_lang target language */ function copyPageToTranslation($a_target_lang) { $transl_page = ilPageObjectFactory::getInstance($this->getParentType(), 0, 0, $a_target_lang); $transl_page->setId($this->getId()); $transl_page->setParentId($this->getParentId()); $transl_page->setXMLContent($this->copyXMLContent()); $transl_page->setActive($this->getActive()); $transl_page->setActivationStart($this->getActivationStart()); $transl_page->setActivationEnd($this->getActivationEnd()); $transl_page->create(); }
/** * Standard Version of Fill Row. Most likely to * be overwritten by derived class. */ protected function fillRow($a_set) { global $lng, $ilCtrl, $ilAccess; $usage = $a_set; //var_dump($usage); if (is_int(strpos($usage["type"], ":"))) { $us_arr = explode(":", $usage["type"]); $usage["type"] = $us_arr[1]; $cont_type = $us_arr[0]; } //var_dump($usage); include_once './Services/Link/classes/class.ilLink.php'; switch ($usage["type"]) { case "pg": include_once "./Services/COPage/classes/class.ilPageObjectFactory.php"; $page_obj = ilPageObjectFactory::getInstance($cont_type, $usage["id"]); $item = array(); //$this->tpl->setVariable("TXT_OBJECT", $usage["type"].":".$usage["id"]); switch ($cont_type) { case "lm": require_once "./Modules/LearningModule/classes/class.ilObjContentObject.php"; require_once "./Modules/LearningModule/classes/class.ilObjLearningModule.php"; require_once "./Modules/LearningModule/classes/class.ilLMObject.php"; $lm_obj = new ilObjLearningModule($page_obj->getParentId(), false); $item["obj_type_txt"] = $this->lng->txt("obj_" . $cont_type); $item["obj_title"] = $lm_obj->getTitle(); $item["sub_txt"] = $this->lng->txt("pg"); $item["sub_title"] = ilLMObject::_lookupTitle($page_obj->getId()); $ref_id = $this->getFirstWritableRefId($lm_obj->getId()); if ($ref_id > 0) { $item["obj_link"] = ilLink::_getStaticLink($page_obj->getId() . "_" . $ref_id, "pg"); } break; case "wpg": require_once "./Modules/Wiki/classes/class.ilWikiPage.php"; $item["obj_type_txt"] = $this->lng->txt("obj_wiki"); $item["obj_title"] = ilObject::_lookupTitle($page_obj->getParentId()); $item["sub_txt"] = $this->lng->txt("pg"); $item["sub_title"] = ilWikiPage::lookupTitle($page_obj->getId()); $ref_id = $this->getFirstWritableRefId($page_obj->getParentId()); if ($ref_id > 0) { $item["obj_link"] = ilLink::_getStaticLink($ref_id, "wiki"); } break; case "gdf": require_once "./Modules/Glossary/classes/class.ilGlossaryTerm.php"; require_once "./Modules/Glossary/classes/class.ilGlossaryDefinition.php"; $term_id = ilGlossaryDefinition::_lookupTermId($page_obj->getId()); $glo_id = ilGlossaryTerm::_lookGlossaryId($term_id); $item["obj_type_txt"] = $this->lng->txt("obj_glo"); $item["obj_title"] = ilObject::_lookupTitle($glo_id); $item["sub_txt"] = $this->lng->txt("cont_term"); $item["sub_title"] = ilGlossaryTerm::_lookGlossaryTerm($term_id); $ref_id = $this->getFirstWritableRefId($page_obj->getParentId()); if ($ref_id > 0) { $item["obj_link"] = ilLink::_getStaticLink($ref_id, "glo"); } break; case "cont": $item["obj_type_txt"] = $this->lng->txt("obj_" . $cont_type); $item["obj_title"] = ilObject::_lookupTitle($page_obj->getId()); $ref_id = $this->getFirstWritableRefId($page_obj->getId()); if ($ref_id > 0) { $item["obj_link"] = ilLink::_getStaticLink($ref_id, $cont_type); } break; } break; case "mep": $item["obj_type_txt"] = $this->lng->txt("obj_mep"); $item["obj_title"] = ilObject::_lookupTitle($usage["id"]); $ref_id = $this->getFirstWritableRefId($usage["id"]); if ($ref_id > 0) { $item["obj_link"] = ilLink::_getStaticLink($ref_id, "mep"); } break; case "map": $item["obj_type_txt"] = $this->lng->txt("obj_mob"); $item["obj_title"] = ilObject::_lookupTitle($usage["id"]); $item["sub_txt"] = $this->lng->txt("cont_link_area"); break; } // show versions if (is_array($usage["hist_nr"]) && (count($usage["hist_nr"]) > 1 || $usage["hist_nr"][0] > 0)) { asort($usage["hist_nr"]); $ver = $sep = ""; if ($usage["hist_nr"][0] == 0) { array_shift($usage["hist_nr"]); $usage["hist_nr"][] = 0; } if (count($usage["hist_nr"]) > 5) { $ver .= "..., "; $cnt = count($usage["hist_nr"]) - 5; for ($i = 0; $i < $cnt; $i++) { unset($usage["hist_nr"][$i]); } } foreach ($usage["hist_nr"] as $nr) { if ($nr > 0) { $ver .= $sep . $nr; } else { $ver .= $sep . $this->lng->txt("cont_current_version"); } $sep = ", "; } $this->tpl->setCurrentBlock("versions"); $this->tpl->setVariable("TXT_VERSIONS", $this->lng->txt("cont_versions")); $this->tpl->setVariable("VAL_VERSIONS", $ver); $this->tpl->parseCurrentBlock(); } if ($item["obj_type_txt"] != "") { $this->tpl->setCurrentBlock("type"); $this->tpl->setVariable("TXT_TYPE", $this->lng->txt("type")); $this->tpl->setVariable("VAL_TYPE", $item["obj_type_txt"]); $this->tpl->parseCurrentBlock(); } if ($usage["type"] != "clip") { if ($item["obj_link"]) { $this->tpl->setCurrentBlock("linked_item"); $this->tpl->setVariable("TXT_OBJECT", $item["obj_title"]); $this->tpl->setVariable("HREF_LINK", $item["obj_link"]); $this->tpl->parseCurrentBlock(); } else { $this->tpl->setVariable("TXT_OBJECT_NO_LINK", $item["obj_title"]); } if ($item["sub_txt"] != "") { $this->tpl->setVariable("SEP", ", "); $this->tpl->setVariable("SUB_TXT", $item["sub_txt"]); if ($item["sub_title"] != "") { $this->tpl->setVariable("SEP2", ": "); $this->tpl->setVariable("SUB_TITLE", $item["sub_title"]); } } } else { $this->tpl->setVariable("TXT_OBJECT_NO_LINK", $this->lng->txt("cont_users_have_mob_in_clip1") . " " . $usage["cnt"] . " " . $this->lng->txt("cont_users_have_mob_in_clip2")); } }
/** * Get xml representation * * @param string entity * @param string schema version * @param array ids * @return string xml */ public function getXmlRepresentation($a_entity, $a_schema_version, $a_id) { if ($a_entity == "pg") { include_once "./Services/COPage/classes/class.ilPageObject.php"; $id = explode(":", $a_id); include_once "./Services/COPage/classes/class.ilPageObjectFactory.php"; $page_object = ilPageObjectFactory::getInstance($id[0], $id[1]); $page_object->buildDom(); $page_object->insertInstIntoIDs(IL_INST_ID); $pxml = $page_object->getXMLFromDom(false, false, false, "", true); $pxml = str_replace("&", "&", $pxml); $xml = "<PageObject>"; $xml .= $pxml; $xml .= "</PageObject>"; $page_object->freeDom(); return $xml; } if ($a_entity == "pgtp") { return $this->ds->getXmlRepresentation($a_entity, $a_schema_version, $a_id, "", true, true); } }
/** * show fullscreen view of media object */ function showMediaFullscreen($a_style_id = 0) { $this->tpl = new ilTemplate("tpl.fullscreen.html", true, true, "Services/COPage"); $this->tpl->setCurrentBlock("ContentStyle"); $this->tpl->setVariable("LOCATION_CONTENT_STYLESHEET", 0); $this->tpl->parseCurrentBlock(); $this->tpl->setVariable("PAGETITLE", " - " . ilObject::_lookupTitle($_GET["mob_id"])); $this->tpl->setVariable("LOCATION_STYLESHEET", ilUtil::getStyleSheetLocation()); $this->tpl->setCurrentBlock("ilMedia"); require_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php"; $media_obj =& new ilObjMediaObject($_GET["mob_id"]); if (!empty($_GET["pg_id"])) { include_once "./Services/COPage/classes/class.ilPageObjectFactory.php"; $pg_obj = ilPageObjectFactory::getInstance($this->obj->getParentType(), $_GET["pg_id"]); $pg_obj->buildDom(); $xml = "<dummy>"; // todo: we get always the first alias now (problem if mob is used multiple // times in page) $xml .= $pg_obj->getMediaAliasElement($_GET["mob_id"]); $xml .= $media_obj->getXML(IL_MODE_OUTPUT); $xml .= "</dummy>"; } else { $xml = "<dummy>"; $xml .= $media_obj->getXML(IL_MODE_ALIAS); $xml .= $media_obj->getXML(IL_MODE_OUTPUT); $xml .= "</dummy>"; } //echo htmlentities($xml); exit; $xsl = file_get_contents("./Services/COPage/xsl/page.xsl"); $args = array('/_xml' => $xml, '/_xsl' => $xsl); $xh = xslt_create(); //echo "<b>XML:</b>".htmlentities($xml); // determine target frames for internal links //$pg_frame = $_GET["frame"]; $wb_path = ilUtil::getWebspaceDir("output") . "/"; $mode = "fullscreen"; $params = array('mode' => $mode, 'webspace_path' => $wb_path); $output = xslt_process($xh, "arg:/_xml", "arg:/_xsl", NULL, $args, $params); echo xslt_error($xh); xslt_free($xh); // unmask user html $this->tpl->setVariable("MEDIA_CONTENT", $output); }
/** * parse pages that contain files, mobs and/or internal links */ function processPagesToParse() { /* $pg_mapping = array(); foreach($this->pg_mapping as $key => $value) { $pg_mapping[$key] = "il__pg_".$value; }*/ //echo "<br><b>processIntLinks</b>"; flush(); // outgoin internal links foreach ($this->pages_to_parse as $page_id) { $page_arr = explode(":", $page_id); //echo "<br>resolve:".$this->content_object->getType().":".$page_id; flush(); switch ($page_arr[0]) { case "lm": switch ($this->content_object->getType()) { case "lm": include_once "./Modules/LearningModule/classes/class.ilLMPage.php"; $page_obj = new ilLMPage($page_arr[1]); break; default: die("Unknown content type " . $this->content_object->getType()); } break; case "gdf": include_once "./Modules/Glossary/classes/class.ilGlossaryDefPage.php"; $page_obj = new ilGlossaryDefPage($page_arr[1]); break; case "qpl": $page_obj = new ilAssQuestionPage($page_arr[1]); break; } $page_obj->buildDom(); $page_obj->resolveIntLinks(); $page_obj->resolveIIMMediaAliases($this->mob_mapping); if (in_array($this->coType, array("lm", "dbk"))) { $page_obj->resolveQuestionReferences($this->qst_mapping); } $page_obj->update(false); if ($page_arr[0] == "gdf") { $def = new ilGlossaryDefinition($page_arr[1]); $def->updateShortText(); } unset($page_obj); } //echo "<br><b>map area internal links</b>"; flush(); // outgoins map area (mob) internal links foreach ($this->mobs_with_int_links as $mob_id) { ilMediaItem::_resolveMapAreaLinks($mob_id); } //echo "<br><b>incoming interna links</b>"; flush(); // incoming internal links $done = array(); foreach ($this->link_targets as $link_target) { //echo "doin link target:".$link_target.":<br>"; $link_arr = explode("_", $link_target); $target_inst = $link_arr[1]; $target_type = $link_arr[2]; $target_id = $link_arr[3]; //echo "<br>-".$target_type."-".$target_id."-".$target_inst."-"; $sources = ilInternalLink::_getSourcesOfTarget($target_type, $target_id, $target_inst); foreach ($sources as $key => $source) { //echo "got source:".$key.":<br>"; if (in_array($key, $done)) { continue; } $type_arr = explode(":", $source["type"]); // content object pages if ($type_arr[1] == "pg") { if (ilPageObject::_exists($type_arr[0], $source["id"])) { include_once "./Services/COPage/classes/class.ilPageObjectFactory.php"; $page_object = ilPageObjectFactory::getInstance($type_arr[0], $source["id"]); $page_object->buildDom(); $page_object->resolveIntLinks(); $page_object->update(); unset($page_object); } } // eventually correct links in questions to learning modules if ($type_arr[0] == "qst") { require_once "./Modules/TestQuestionPool/classes/class.assQuestion.php"; assQuestion::_resolveIntLinks($source["id"]); } // eventually correct links in survey questions to learning modules if ($type_arr[0] == "sqst") { require_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php"; SurveyQuestion::_resolveIntLinks($source["id"]); } $done[$key] = $key; } } }