static function _handleImportRepositoryLinks($a_rep_import_id, $a_rep_type, $a_rep_ref_id) { include_once "./Services/Link/classes/class.ilInternalLink.php"; //echo "-".$a_rep_import_id."-".$a_rep_ref_id."-"; $sources = ilInternalLink::_getSourcesOfTarget("obj", ilInternalLink::_extractObjIdOfTarget($a_rep_import_id), ilInternalLink::_extractInstOfTarget($a_rep_import_id)); //var_dump($sources); foreach ($sources as $source) { //echo "A"; if ($source["type"] == "lm:pg") { //echo "B"; include_once "./Modules/LearningModule/classes/class.ilLMPage.php"; if (self::_exists("lm", $source["id"], $source["lang"])) { $page_obj = new ilLMPage($source["id"], 0, $source["lang"]); if (!$page_obj->page_not_found) { //echo "C"; $page_obj->handleImportRepositoryLink($a_rep_import_id, $a_rep_type, $a_rep_ref_id); } $page_obj->update(); } } } }
/** * 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); } } }
/** * list definitions of a term */ function listDefinitions($a_ref_id = 0, $a_term_id = 0, $a_get_html = false) { global $ilUser, $ilAccess, $ilias, $lng, $ilCtrl; if ($a_ref_id == 0) { $ref_id = (int) $_GET["ref_id"]; } else { $ref_id = $a_ref_id; } if ($a_term_id == 0) { $term_id = $this->term_id; } else { $term_id = $a_term_id; } if (!$ilAccess->checkAccess("read", "", $ref_id)) { $ilias->raiseError($lng->txt("permission_denied"), $ilias->error_obj->MESSAGE); } // tabs if ($this->glossary->getPresentationMode() != "full_def") { $this->showDefinitionTabs("content"); } $term = new ilGlossaryTerm($term_id); if (!$a_get_html) { $tpl = $this->tpl; require_once "./Modules/Glossary/classes/class.ilGlossaryDefPageGUI.php"; $tpl->getStandardTemplate(); // $this->setTabs(); if ($this->offlineMode()) { $style_name = $ilUser->prefs["style"] . ".css"; $tpl->setVariable("LOCATION_STYLESHEET", "./" . $style_name); } else { $this->setLocator(); } // content style $tpl->setCurrentBlock("ContentStyle"); if (!$this->offlineMode()) { $tpl->setVariable("LOCATION_CONTENT_STYLESHEET", ilObjStyleSheet::getContentStylePath($this->glossary->getStyleSheetId())); } else { $tpl->setVariable("LOCATION_CONTENT_STYLESHEET", "content.css"); } $tpl->parseCurrentBlock(); // syntax style $tpl->setCurrentBlock("SyntaxStyle"); if (!$this->offlineMode()) { $tpl->setVariable("LOCATION_SYNTAX_STYLESHEET", ilObjStyleSheet::getSyntaxStylePath()); } else { $tpl->setVariable("LOCATION_SYNTAX_STYLESHEET", "syntaxhighlight.css"); } $tpl->parseCurrentBlock(); $tpl->setTitleIcon(ilUtil::getImagePath("icon_term_b.png")); $tpl->setTitle($this->lng->txt("cont_term") . ": " . $term->getTerm()); // load template for table $tpl->addBlockfile("ADM_CONTENT", "def_list", "tpl.glossary_definition_list.html", "Modules/Glossary"); } else { // content style $this->tpl->setCurrentBlock("ContentStyle"); if (!$this->offlineMode()) { $this->tpl->setVariable("LOCATION_CONTENT_STYLESHEET", ilObjStyleSheet::getContentStylePath($this->glossary->getStyleSheetId())); } else { $this->tpl->setVariable("LOCATION_CONTENT_STYLESHEET", "content.css"); } $this->tpl->parseCurrentBlock(); // syntax style $this->tpl->setCurrentBlock("SyntaxStyle"); if (!$this->offlineMode()) { $this->tpl->setVariable("LOCATION_SYNTAX_STYLESHEET", ilObjStyleSheet::getSyntaxStylePath()); } else { $this->tpl->setVariable("LOCATION_SYNTAX_STYLESHEET", "syntaxhighlight.css"); } $this->tpl->parseCurrentBlock(); $tpl = new ilTemplate("tpl.glossary_definition_list.html", true, true, "Modules/Glossary"); } $defs = ilGlossaryDefinition::getDefinitionList($term_id); $tpl->setVariable("TXT_TERM", $term->getTerm()); $this->mobs = array(); for ($j = 0; $j < count($defs); $j++) { $def = $defs[$j]; $page_gui = new ilGlossaryDefPageGUI($def["id"]); $page_gui->setStyleId($this->glossary->getStyleSheetId()); $page = $page_gui->getPageObject(); // internal links $page->buildDom(); $int_links = $page->getInternalLinks(); $link_xml = $this->getLinkXML($int_links); $page_gui->setLinkXML($link_xml); if ($this->offlineMode()) { $page_gui->setOutputMode("offline"); $page_gui->setOfflineDirectory($this->getOfflineDirectory()); } $page_gui->setSourcecodeDownloadScript($this->getLink($ref_id)); $page_gui->setFullscreenLink($this->getLink($ref_id, "fullscreen", $term_id, $def["id"])); $page_gui->setTemplateOutput(false); $page_gui->setRawPageContent(true); $page_gui->setFileDownloadLink($this->getLink($ref_id, "downloadFile")); if (!$this->offlineMode()) { $output = $page_gui->preview(); } else { $output = $page_gui->presentation($page_gui->getOutputMode()); } if (count($defs) > 1) { $tpl->setCurrentBlock("definition_header"); $tpl->setVariable("TXT_DEFINITION", $this->lng->txt("cont_definition") . " " . ($j + 1)); $tpl->parseCurrentBlock(); } $tpl->setCurrentBlock("definition"); $tpl->setVariable("PAGE_CONTENT", $output); $tpl->parseCurrentBlock(); } // display possible backlinks $sources = ilInternalLink::_getSourcesOfTarget('git', $_GET['term_id'], 0); if ($sources) { $backlist_shown = false; foreach ($sources as $src) { $type = explode(':', $src['type']); if ($type[0] == 'lm') { if ($type[1] == 'pg') { $title = ilLMPageObject::_getPresentationTitle($src['id']); $lm_id = ilLMObject::_lookupContObjID($src['id']); $lm_title = ilObject::_lookupTitle($lm_id); $tpl->setCurrentBlock('backlink_item'); $ref_ids = ilObject::_getAllReferences($lm_id); $access = false; foreach ($ref_ids as $rid) { if ($ilAccess->checkAccess("read", "", $rid)) { $access = true; } } if ($access) { $tpl->setCurrentBlock("backlink_item"); $tpl->setVariable("BACKLINK_LINK", ILIAS_HTTP_PATH . "/goto.php?target=" . $type[1] . "_" . $src['id']); $tpl->setVariable("BACKLINK_ITEM", $lm_title . ": " . $title); $tpl->parseCurrentBlock(); $backlist_shown = true; } } } } if ($backlist_shown) { $tpl->setCurrentBlock("backlink_list"); $tpl->setVariable("BACKLINK_TITLE", $this->lng->txt('glo_term_used_in')); $tpl->parseCurrentBlock(); } } if (!$a_get_html) { $tpl->setCurrentBlock("perma_link"); $tpl->setVariable("PERMA_LINK", ILIAS_HTTP_PATH . "/goto.php?target=" . "git" . "_" . $term_id . "_" . $ref_id . "&client_id=" . CLIENT_ID); $tpl->setVariable("TXT_PERMA_LINK", $this->lng->txt("perma_link")); $tpl->setVariable("PERMA_TARGET", "_top"); $tpl->parseCurrentBlock(); } // highlighting? if ($_GET["srcstring"] != "" && !$this->offlineMode()) { include_once './Services/Search/classes/class.ilUserSearchCache.php'; $cache = ilUserSearchCache::_getInstance($ilUser->getId()); $cache->switchSearchType(ilUserSearchCache::LAST_QUERY); $search_string = $cache->getQuery(); include_once "./Services/UIComponent/TextHighlighter/classes/class.ilTextHighlighterGUI.php"; include_once "./Services/Search/classes/class.ilQueryParser.php"; $p = new ilQueryParser($search_string); $p->parse(); $words = $p->getQuotedWords(); if (is_array($words)) { foreach ($words as $w) { ilTextHighlighterGUI::highlight("ilGloContent", $w, $tpl); } } $this->fill_on_load_code = true; } if ($this->offlineMode() || $a_get_html) { return $tpl->get(); } }
/** * Rename page */ function rename($a_new_name) { global $ilDB; // replace unallowed characters $a_new_name = str_replace(array("<", ">"), '', $a_new_name); // replace multiple whitespace characters by one single space $a_new_name = trim(preg_replace('!\\s+!', ' ', $a_new_name)); $page_title = ilWikiUtil::makeDbTitle($a_new_name); $pg_id = ilWikiPage::_getPageIdForWikiTitle($this->getWikiId(), $page_title); $xml_new_name = str_replace("&", "&", $a_new_name); if ($pg_id == 0 || $pg_id == $this->getId()) { include_once "./Services/COPage/classes/class.ilInternalLink.php"; $sources = ilInternalLink::_getSourcesOfTarget("wpg", $this->getId(), 0); foreach ($sources as $s) { if ($s["type"] == "wpg:pg") { $wpage = new ilWikiPage($s["id"]); $col = ilWikiUtil::processInternalLinks($wpage->getXmlContent(), 0, IL_WIKI_MODE_EXT_COLLECT); $new_content = $wpage->getXmlContent(); foreach ($col as $c) { // this complicated procedure is needed due to the fact // that depending on the collation e = é is true // in the (mysql) database // see bug http://www.ilias.de/mantis/view.php?id=11227 $t1 = ilWikiUtil::makeDbTitle($c["nt"]->mTextform); $t2 = ilWikiUtil::makeDbTitle($this->getTitle()); // this one replaces C2A0 ( ) by a usual space // otherwise the comparision will fail, since you // get these characters from tiny if more than one // space is repeated in a string. This may not be // 100% but we do not store $t1 anywhere and only // modify it for the comparison $t1 = preg_replace('/\\xC2\\xA0/', ' ', $t1); $t2 = preg_replace('/\\xC2\\xA0/', ' ', $t2); $set = $ilDB->query($q = "SELECT " . $ilDB->quote($t1, "text") . " = " . $ilDB->quote($t2, "text") . " isequal"); $rec = $ilDB->fetchAssoc($set); if ($rec["isequal"]) { $new_content = str_replace("[[" . $c["nt"]->mTextform . "]]", "[[" . $xml_new_name . "]]", $new_content); if ($c["text"] != "") { $new_content = str_replace("[[" . $c["text"] . "]]", "[[" . $xml_new_name . "]]", $new_content); } $add = $c["text"] != "" ? "|" . $c["text"] : ""; $new_content = str_replace("[[" . $c["nt"]->mTextform . $add . "]]", "[[" . $xml_new_name . $add . "]]", $new_content); } } $wpage->setXmlContent($new_content); //echo htmlentities($new_content); $wpage->update(); } } include_once "./Modules/Wiki/classes/class.ilObjWiki.php"; if (ilObjWiki::_lookupStartPage($this->getWikiId()) == $this->getTitle()) { ilObjWiki::writeStartPage($this->getWikiId(), $a_new_name); } $this->setTitle($a_new_name); $this->update(); } return $a_new_name; }
/** * Get number of usages * * @param int term id * @return int number of usages */ static function getUsages($a_term_id) { include_once "./Services/COPage/classes/class.ilInternalLink.php"; return ilInternalLink::_getSourcesOfTarget("git", $a_term_id, 0); }
/** * 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": $page_obj =& new ilPageObject($this->content_object->getType(), $page_arr[1]); break; case "gdf": $page_obj =& new ilPageObject("gdf", $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]; $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") { $page_object = new ilPageObject($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; } } }
/** * Check access rights for glossary terms * This checks also learning modules linking the term * * @param int object id (glossary) * @param int page id (definition) * @return boolean access given (true/false) */ private function checkAccessGlossaryTerm($obj_id, $page_id) { // give access if glossary is readable if ($this->checkAccessObject($obj_id)) { return true; } include_once "./Modules/Glossary/classes/class.ilGlossaryDefinition.php"; include_once "./Modules/Glossary/classes/class.ilGlossaryTerm.php"; $term_id = ilGlossaryDefinition::_lookupTermId($page_id); include_once './Services/COPage/classes/class.ilInternalLink.php'; $sources = ilInternalLink::_getSourcesOfTarget('git', $term_id, 0); if ($sources) { foreach ($sources as $src) { switch ($src['type']) { // Give access if term is linked by a learning module with read access. // The term including media is shown by the learning module presentation! case 'lm:pg': include_once "./Modules/LearningModule/classes/class.ilLMObject.php"; $src_obj_id = ilLMObject::_lookupContObjID($src['id']); if ($this->checkAccessObject($src_obj_id, 'lm')) { return true; } break; // Don't yet give access if the term is linked by another glossary // The link will lead to the origin glossary which is already checked /* case 'gdf:pg': $src_term_id = ilGlossaryDefinition::_lookupTermId($src['id']); $src_obj_id = ilGlossaryTerm::_lookGlossaryID($src_term_id); if ($this->checkAccessObject($src_obj_id, 'glo')) { return true; } break; */ } } } }