sitemap.inc.svn-base
来自「PHP 知识管理系统(基于树结构的知识管理系统), 英文原版的PHP源码。」· SVN-BASE 代码 · 共 676 行 · 第 1/2 页
SVN-BASE
676 行
$default->log->info("SiteMap:: getPageDB calling hasPermission with access: " . $sql->f("access_id")); if ($this->hasPermission($sql->f("access_id"))) { // return the page return $sql->f("page"); } } else { $_SESSION["errorMessage"] = $lang_err_database; return false; } } else { $_SESSION["errorMessage"] = $lang_err_database; return false; } } /** * Returns the page mapped to the (action, groupName) pair. (uses the array) * * @param string the action to lookup pages for * @return string the page to redirect to, or false if the user doesn't have access to the page */ function getPageArray($action) { global $default; if (KTLOG_CACHE) $default->log->info("SiteMap::getPage: checking ($action, " . (isset($_SESSION["userID"]) ? $_SESSION["userID"] : "") . ")"); $groupIDs = array(); // for each section foreach ($this->aSiteMap as $section => $valArr) { if (KTLOG_CACHE) $default->log->debug("Sitemap::getPage section=$section"); // for each group, page array combination foreach ($valArr as $requiredAccess => $pageArr) { // now loop through pages until we find the right one foreach ($pageArr as $ackshin => $page) { if ($ackshin == $action) { if (KTLOG_CACHE) $default->log->debug("Sitemap::getPageArray calling hasPermission current requiredAccess=$requiredAccess, action=$ackshin"); if ($this->hasPermission($requiredAccess)) { if (KTUtil::arrayGet($_SERVER, 'kt_no_extensions')) { return str_replace('.php', '', $page["page"]); } return $page["page"]; } } } } } // if the function hasn't returned already then the current // user does not have access to the action if (KTLOG_CACHE) $default->log->info("Sitemap::getPage: access denied for ($action, " . $_SESSION["userID"] . ")"); return false; } /** * Returns the section name of the supplied page * Checks whether to use the db or not and calls the appropriate method * * @param string the page to lookup the section for */ function getSectionName($sRequiredPage) { if ($this->bUseDB) { return $this->getSectionNameDB($sRequiredPage); } else { return $this->getSectionNameArray($sRequiredPage); } } /** * Returns the section name of the supplied page (uses the db) * * @param string the page to lookup the section for */ function getSectionNameDB($sRequiredPage) { global $default, $lang_err_database; $sql = $default->db; // lookup the page and access_id from the sitemap $sQuery = "SELECT SSL.name FROM $default->sitemap_table AS S INNER JOIN $default->site_sections_table AS SSL ON S.section_id=SSL.id WHERE S.page = ?";/*ok*/ $aParams = array($sRequiredPage); if ($sql->query(array($sQuery, $aParams))) { if ($sql->next_record()) { // return the section name return $sql->f("name"); } else { $_SESSION["errorMessage"] = $lang_err_database; return false; } } else { $_SESSION["errorMessage"] = $lang_err_database; return false; } } /** * Returns the section name of the supplied page (uses the array) * * @param string the page to lookup the section for */ function getSectionNameArray($sRequiredPage) { global $default; // for each section foreach ($this->aSiteMap as $section => $valArr) { // for each access, page array combination foreach ($valArr as $requiredAccess => $pageArr) { // now loop through pages until we find the right one foreach ($pageArr as $action => $page) { if ($sRequiredPage == $page["page"]) { return $section; } } } } } /** * Returns the default action for the supplied section * Checks whether to use the db or not and calls the appropriate method * * @param string the section name to return the default action for * @return string the controller action for the default page for this section */ function getDefaultAction($sSectionName) { if ($this->bUseDB) { return $this->getDefaultActionDB($sSectionName); } else { return $this->getDefaultActionArray($sSectionName); } } /** * Returns the default action for the supplied section (uses the db) * * @param string the section name to return the default action for * @return string the controller action for the default page for this section */ function getDefaultActionDB($sSectionName) { global $default, $lang_err_database; $sql = $default->db; // lookup sectionID $sectionID = lookupID($default->site_sections_table, "name", $sSectionName); if ($sectionID) { // lookup the default action for the specified section $sQuery = "SELECT action FROM $default->sitemap_table WHERE section_id = ? AND is_default = ? AND is_enabled = ?";/*ok*/ $aParams = array($sectionID, true, true); if ($sql->query(array($sQuery, $aParams))) { if ($sql->next_record()) { // return the section name return $sql->f("action"); } else { $_SESSION["errorMessage"] = $lang_err_database; return false; } } else { $_SESSION["errorMessage"] = $lang_err_database; return false; } } else { $_SESSION["errorMessage"] = "No such section name ($sSectionName) in the sitemap"; return false; } } /** * Returns the default action for the supplied section (uses the array) * * @param string the section name to return the default action for * @return string the controller action for the default page for this section */ function getDefaultActionArray($sSectionName) { global $default; // check if the section exists if (is_array($this->aSiteMap[$sSectionName])) { // initialise result array $results = array(); // need to loop through all (groupName, page) arrays in this section foreach ($this->aSiteMap[$sSectionName] as $requiredAccess => $pages) { if (KTLOG_CACHE) $default->log->debug("Sitemap::getDefaultActionArray calling hasPermission current requiredAccess=$requiredAccess"); if ($this->hasPermission($requiredAccess)) { foreach ($pages as $action => $pageArray) { if ($pageArray["default"] && $pageArray["enabled"]) { return $action; } } } else { return ""; } } } else { // supplied section not in sitemap // TODO: internal error code? $_SESSION["errorMessage"] = "$sSectionName not in SiteMap!"; return false; } } /** * Returns the action for a specific page- to enable redirects * Checks whether to use the db or not and calls the appropriate method * * @param string the page to perform the reverse lookup for * @return string the action for this page */ function getActionFromPage($sPage) { if ($this->bUseDB) { return $this->getActionFromPageDB($sPage); } else { return $this->getActionFromPageArray($sPage); } } /** * Returns the action for a specific page- to enable redirects (uses the db) * * @param string the page to perform the reverse lookup for * @return string the action for this page, false if there is no mapping */ function getActionFromPageDB($sPage) { global $default, $lang_err_database; $sql = $default->db; // lookup the action for the specified page if ($sql->query(array("SELECT action FROM $default->sitemap_table WHERE page = ?", $sPage))) {/*ok*/ if ($sql->next_record()) { // return the section name return $sql->f("action"); } else { $_SESSION["errorMessage"] = $lang_err_database; return false; } } else { $_SESSION["errorMessage"] = $lang_err_database; return false; } } /** * Returns the action for a specific page- to enable redirects (uses the array) * * @param string the page to perform the reverse lookup for * @return string the action for this page, false if there is no mapping */ function getActionFromPageArray($sPage) { global $default; if (KTLOG_CACHE) $default->log->debug("Sitemap::getActionFromPage: page=$sPage"); // for each section if (!strpos($sPage, '.php')) { $sPage .= '.php'; } foreach ($this->aSiteMap as $section => $valArr) { if (KTLOG_CACHE) $default->log->debug("Sitemap::getActionFromPage section=$section"); // for each group, page array combination foreach ($valArr as $requiredAccess => $pageArr) { if (KTLOG_CACHE) $default->log->debug("Sitemap::getActionFromPage access=$requiredAccess"); // now loop through pages until we find the right one foreach ($pageArr as $action => $page) { if (KTLOG_CACHE) $default->log->debug("Sitemap::getActionFromPage action=$action, reqPage=$sPage; page=" . $page["page"]); if ($sPage == $page["page"]) { if (KTLOG_CACHE) $default->log->debug("Sitemap::getActionFromPage found action=$action for page=$sPage"); return $action; } } } } return false; } /** * Prints the current site map */ function printMap() { if (!$this->bUseDB) { return arrayToString($this->aSiteMap); } } /** * Writes the current sitemap from the array to the DB */ function syncWithDB() { global $default; $sql = $default->db; // only if we're using the array if (!$this->bUseDB) { // clear section table if ($sql->query("DELETE from $default->site_sections_table")) { if (KTLOG_CACHE) $default->log->debug("Sitemap::syncWithDB removed sections"); } else { $default->log->error("Sitemap::syncWithDB remove sections failed"); } // clear sitemap table if ($sql->query("DELETE from $default->sitemap_table")) { if (KTLOG_CACHE) $default->log->debug("Sitemap::syncWithDB removed sitemap"); } else { $default->log->error("Sitemap::syncWithDB remove sitemap failed"); } // for each section foreach ($this->aSiteMap as $section => $valArr) { // insert into the section $aFieldValue = array( 'name' => $section, ); $id = DBUtil::autoInsert($default->site_sections_table, $aFieldValues); if (KTLOG_CACHE) $default->log->debug("Sitemap::syncWithDB insert=$sSectionSql"); if (PEAR::isError($id)) { $default->log->error("Sitemap::syncWithDB add section $section failed"); } else { $sectionID = $id; if (KTLOG_CACHE) $default->log->debug("Sitemap::syncWithDB added section $section; $sectionID"); } // for each group, page array combination foreach ($valArr as $requiredAccess => $pageArr) { // now loop through all the pages foreach ($pageArr as $action => $page) { $aFieldValues = array( action => $action, page => $page["page"], section_id => $sectionID, access_id => $requiredAccess, link_text => $page["description"], is_default => $page["default"], is_enabled => $page["enabled"], ); $id = DBUtil::autoInsert($default->sitemap_table, $aFieldValues); if (PEAR::isError($id)) { $default->log->error("Sitemap::syncWithDB sitemap insert failed ($sSiteMapSql)"); } else { if (KTLOG_CACHE) $default->log->debug("Sitemap::syncWithDb sitemap insert worked for ($action, " . $page["page"] . ")"); } } } } } }}?>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?