/** * A utility function to test if the supplied url path is valid for the supplied content id * * @param string The partial url path to test * @return boolean */ public static function is_valid_url($url, $content_id = '') { // check for starting or ending slashes if (startswith($url, '/') || endswith($url, '/')) { return FALSE; } // first check for invalid chars. $translated = munge_string_to_url($url, false, true); if (strtolower($translated) != strtolower($url)) { return FALSE; } cms_route_manager::load_routes(); $route = cms_route_manager::find_match($url); if (!$route) { return TRUE; } if ($route->is_content()) { if ($content_id == '' || $route->get_content() == $content_id) { return TRUE; } } return FALSE; }
/** * Grab URLs from the content table and register them with the route manager. * * @since 1.9 * @author Robert Campbell <*****@*****.**> * @internal * @access private */ public function register_routes() { $gCms = cmsms(); $db = $gCms->GetDb(); $query = 'SELECT content_id,page_url FROM ' . cms_db_prefix() . 'content WHERE active = 1 AND default_content = 0 AND page_url != \'\''; $data = $db->GetArray($query); if (is_array($data)) { foreach ($data as $onerow) { $route = new CmsRoute($onerow['page_url'], $onerow['content_id'], '', TRUE); cms_route_manager::register($route); } } }
/** * Register a new route. * This method will not register duplicate routes. * * @param CmsRoute The route to register * @return boolean */ public static function register(CmsRoute $route) { if (self::route_exists($route)) { return TRUE; } if (!is_array(self::$_routes)) { self::$_routes = array(); } self::$_routes[] = $route; return TRUE; }
private static function _clear_cache() { @unlink(self::_get_cache_filespec()); self::$_routes = null; self::$_routes_loaded = FALSE; // note: dynamic routes don't get cleared. }
/** * A utility function to test if the supplied url path is valid for the supplied content id * * @param string The partial url path to test * @return boolean */ public static function is_valid_url($url, $content_id = '') { // check for starting or ending slashes if (startswith($url, '/') || endswith($url, '/')) { return FALSE; } // first check for invalid chars. // strip off any extension (that is like 5 chars or less) $pos = strrpos($url, '.'); if ($pos !== FALSE) { // have an extension. $ext = substr($url, $pos + 1); if (strlen($ext) >= 5 || munge_string_to_url($ext, false, true) != strtolower($ext)) { return FALSE; } $tmp = substr($url, 0, $pos); if (munge_string_to_url($tmp, false, true) != strtolower($tmp)) { return FALSE; } } else { $translated = munge_string_to_url($url, false, true); if (strtolower($translated) != strtolower($url)) { return FALSE; } } cms_route_manager::load_routes(); $route = cms_route_manager::find_match($url, TRUE); if (!$route) { return TRUE; } if ($route->is_content()) { if ($content_id == '' || $route->get_content() == $content_id) { return TRUE; } } return FALSE; }
/** * Delete the current content object from the database. * * @todo this function should return something, or throw an exception */ function Delete() { $gCms = cmsms(); global $debug_errors; $config = $gCms->GetConfig(); Events::SendEvent('Core', 'ContentDeletePre', array('content' => &$this)); $db = $gCms->GetDb(); $result = false; if (-1 > $this->mId) { if (true == $config["debug"]) { # :TODO: Translate the error message $debug_errors .= "<p>Could not delete content : invalid Id</p>\n"; } } else { $query = "DELETE FROM " . cms_db_prefix() . "content WHERE content_id = ?"; $dbresult = $db->Execute($query, array($this->mId)); if (!$dbresult) { if (true == $config["debug"]) { # :TODO: Translate the error message $debug_errors .= "<p>Error deleting content</p>\n"; } } // Fix the item_order if necessary $query = "UPDATE " . cms_db_prefix() . "content SET item_order = item_order - 1 WHERE parent_id = ? AND item_order > ?"; $result = $db->Execute($query, array($this->ParentId(), $this->ItemOrder())); $cachefilename = TMP_CACHE_LOCATION . '/contentcache.php'; @unlink($cachefilename); // DELETE properties $query = 'DELETE FROM ' . cms_db_prefix() . 'content_props WHERE content_id = ?'; $result = $db->Execute($query, array($this->mId)); $this->_props = null; // Delete additional editors. $query = 'DELETE FROM ' . cms_db_prefix() . 'additional_users WHERE content_id = ?'; $result = $db->Execute($query, array($this->mId)); $this->mAdditionalEditors = null; // Delete route if ($this->mURL != '') { cms_route_manager::del_static($this->mURL); } } Events::SendEvent('Core', 'ContentDeletePost', array('content' => &$this)); }
if (isset($check["Msg_text"]) && $check["Msg_text"] != "OK") { $errortables[] = $check["Table"]; } } $smarty->assign("errorcount", count($errortables)); if (count($errortables) > 0) { $smarty->assign("errortables", implode(",", $errortables)); } /* * * Cache and content * */ $contentops = cmsms()->GetContentOperations(); if (isset($_POST['updateurls'])) { cms_route_manager::rebuild_static_routes(); audit('', 'System maintenance', 'Static routes rebuilt'); $themeObject->ShowMessage(lang("routesrebuilt")); $smarty->assign("active_content", "true"); } if (isset($_POST['clearcache'])) { cmsms()->clear_cached_files(-1); // put mention into the admin log audit('', 'System maintenance', 'Cache cleared'); $themeObject->ShowMessage(lang("cachecleared")); $smarty->assign("active_content", "true"); } if (isset($_POST["updatehierarchy"])) { $contentops->SetAllHierarchyPositions(); audit('', 'System maintenance', 'Page hierarchy positions updated'); $themeObject->ShowMessage(lang("sysmain_hierarchyupdated"));
public static function register_static_route($news_url, $news_article_id, $detailpage = '') { if ($detailpage <= 0) { $gCms = cmsms(); $module = cms_utils::get_module('News'); $detailpage = $module->GetPreference('detail_returnid', -1); if ($detailpage == -1) { $detailpage = $gCms->GetContentOperations()->GetDefaultContent(); } } $parms = array('action' => 'detail', 'returnid' => $detailpage, 'articleid' => $news_article_id); $route = CmsRoute::new_builder($news_url, 'News', $news_article_id, $parms, TRUE); return cms_route_manager::add_static($route); }
// check for starting or ending slashes if (startswith($news_url, '/') || endswith($news_url, '/')) { $error = $this->ShowErrors($this->Lang('error_invalidurl')); } if ($error === FALSE) { // check for invalid chars. $translated = munge_string_to_url($news_url, false, true); if (strtolower($translated) != strtolower($news_url)) { $error = $this->ShowErrors($this->Lang('error_invalidurl')); } } if ($error === FALSE) { // make sure this url isn't taken. $news_url = trim($news_url, " /\t\r\n"); cms_route_manager::load_routes(); $route = cms_route_manager::find_match($news_url); if ($route) { // we're adding an article, not editing... any matching route is bad. $error = $this->ShowErrors($this->Lang('error_invalidurl')); } } } // // database work // if ($error !== FAlSE) { echo $error; } else { $articleid = $db->GenID(cms_db_prefix() . "module_news_seq"); $query = 'INSERT INTO ' . cms_db_prefix() . 'module_news (news_id, news_category_id, news_title, news_data, summary, status, news_date, start_time, end_time, create_date, modified_date,author_id,news_extra,news_url) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)'; if ($useexp == 1) {
public function CreateStaticRoutes() { $db = cmsms()->GetDb(); $route = new CmsRoute('/[nN]ews\\/(?P<articleid>[0-9]+)\\/(?P<returnid>[0-9]+)\\/(?P<junk>.*?)\\/d,(?P<detailtemplate>.*?)$/', $this->GetName()); cms_route_manager::add_static($route); $route = new CmsRoute('/[nN]ews\\/(?P<articleid>[0-9]+)\\/(?P<returnid>[0-9]+)\\/(?P<junk>.*?)$/', $this->GetName()); cms_route_manager::add_static($route); $route = new CmsRoute('/[nN]ews\\/(?P<articleid>[0-9]+)\\/(?P<returnid>[0-9]+)$/', $this->GetName()); cms_route_manager::add_static($route); $route = new CmsRoute('/[nN]ews\\/(?P<articleid>[0-9]+)$/', $this->GetName()); cms_route_manager::add_static($route); $query = 'SELECT news_id,news_url FROM ' . cms_db_prefix() . 'module_news WHERE status = ? AND news_url != ? AND ' . '(' . $db->ifNull('start_time', $db->DbTimeStamp(1)) . ' < NOW()) AND ' . '((' . $db->IfNull('end_time', $db->DbTimeStamp(1)) . ' = ' . $db->DbTimeStamp(1) . ') OR (end_time > NOW()))'; $query .= ' ORDER BY news_date DESC'; $tmp = $db->GetArray($query, array('published', '')); if (is_array($tmp)) { foreach ($tmp as $one) { news_admin_ops::register_static_route($one['news_url'], $one['news_id']); } } }
/** * Register a route to use for pretty url parsing * * Note: This method is not compatible wih lazy loading in the front end. * * @final * @see SetParameters * @param string Regular Expression Route to register * @param array Defaults for parameters that might not be included in the url * @return void */ public final function RegisterRoute($routeregex, $defaults = array()) { $route = new CmsRoute($routeregex, $this->GetName(), $defaults); cms_route_manager::register($route); }
function InitializeFrontend() { $gCms = cmsms(); $db = $gCms->GetDb(); $query = 'SELECT news_id,news_url FROM ' . cms_db_prefix() . 'module_news WHERE status = ? AND news_url != ? AND ' . '(' . $db->ifNull('start_time', $db->DbTimeStamp(1)) . ' < NOW()) AND ' . '((' . $db->IfNull('end_time', $db->DbTimeStamp(1)) . ' = ' . $db->DbTimeStamp(1) . ') OR (end_time > NOW()))'; $query .= ' ORDER BY news_date DESC'; $tmp = $db->GetArray($query, array('published', '')); if (is_array($tmp)) { $detailpage = $this->GetPreference('detail_returnid', -1); if ($detailpage == -1) { $contentops = $gCms->GetContentOperations(); $detailpage = $contentops->GetDefaultContent(); } foreach ($tmp as $one) { $parms = array('action' => 'detail', 'returnid' => $detailpage, 'articleid' => $one['news_id']); $route = new CmsRoute($one['news_url'], $this->GetName(), $parms, TRUE); cms_route_manager::register($route); } } $this->RestrictUnknownParams(); $this->RegisterRoute('/[nN]ews\\/(?P<articleid>[0-9]+)\\/(?P<returnid>[0-9]+)\\/(?P<junk>.*?)\\/d,(?P<detailtemplate>.*?)$/'); $this->RegisterRoute('/[nN]ews\\/(?P<articleid>[0-9]+)\\/(?P<returnid>[0-9]+)\\/(?P<junk>.*?)$/'); $this->RegisterRoute('/[nN]ews\\/(?P<articleid>[0-9]+)\\/(?P<returnid>[0-9]+)$/'); $this->RegisterRoute('/[nN]ews\\/(?P<articleid>[0-9]+)$/'); $this->SetParameterType('pagelimit', CLEAN_INT); $this->SetParameterType('browsecat', CLEAN_INT); $this->SetParameterType('showall', CLEAN_INT); $this->SetParameterType('showarchive', CLEAN_INT); $this->SetParameterType('sortasc', CLEAN_STRING); // should be int, or boolean $this->SetParameterType('sortby', CLEAN_STRING); $this->SetParameterType('detailpage', CLEAN_STRING); $this->SetParameterType('detailtemplate', CLEAN_STRING); $this->SetParameterType('formtemplate', CLEAN_STRING); $this->SetParameterType('browsecattemplate', CLEAN_STRING); $this->SetParameterType('summarytemplate', CLEAN_STRING); $this->SetParameterType('moretext', CLEAN_STRING); $this->SetParameterType('category', CLEAN_STRING); $this->SetParameterType('category_id', CLEAN_STRING); $this->SetParameterType('number', CLEAN_INT); $this->SetParameterType('start', CLEAN_INT); $this->SetParameterType('pagenumber', CLEAN_INT); $this->SetParameterType('articleid', CLEAN_INT); $this->SetParameterType('origid', CLEAN_INT); $this->SetParameterType('showtemplate', CLEAN_STRING); $this->SetParameterType('assign', CLEAN_STRING); $this->SetParameterType('inline', CLEAN_STRING); $this->SetParameterType('preview', CLEAN_STRING); // form parameters $this->SetParameterType('submit', CLEAN_STRING); $this->SetParameterType('cancel', CLEAN_STRING); $this->SetParameterType('category', CLEAN_STRING); $this->SetParameterType('title', CLEAN_STRING); $this->SetParameterType('content', CLEAN_STRING); $this->SetParameterType('summary', CLEAN_STRING); $this->SetParameterType('extra', CLEAN_STRING); $this->SetParameterType('postdate', CLEAN_STRING); $this->SetParameterType('postdate_Hour', CLEAN_STRING); $this->SetParameterType('postdate_Minute', CLEAN_STRING); $this->SetParameterType('postdate_Second', CLEAN_STRING); $this->SetParameterType('postdate_Month', CLEAN_STRING); $this->SetParameterType('postdate_Day', CLEAN_STRING); $this->SetParameterType('postdate_Year', CLEAN_STRING); $this->SetParameterType('startdate', CLEAN_STRING); $this->SetParameterType('startdate_Hour', CLEAN_STRING); $this->SetParameterType('startdate_Minute', CLEAN_STRING); $this->SetParameterType('startdate_Second', CLEAN_STRING); $this->SetParameterType('startdate_Month', CLEAN_STRING); $this->SetParameterType('startdate_Day', CLEAN_STRING); $this->SetParameterType('startdate_Year', CLEAN_STRING); $this->SetParameterType('enddate', CLEAN_STRING); $this->SetParameterType('enddate_Hour', CLEAN_STRING); $this->SetParameterType('enddate_Minute', CLEAN_STRING); $this->SetParameterType('enddate_Second', CLEAN_STRING); $this->SetParameterType('enddate_Month', CLEAN_STRING); $this->SetParameterType('enddate_Day', CLEAN_STRING); $this->SetParameterType('enddate_Year', CLEAN_STRING); $this->SetParameterType('useexp', CLEAN_INT); $this->SetParameterType('input_category', CLEAN_STRING); $this->SetParameterType('category_id', CLEAN_INT); $this->SetParameterType(CLEAN_REGEXP . '/news_customfield_.*/', CLEAN_STRING); $this->SetParameterType('junk', CLEAN_STRING); }
$sqlarray = $dict->CreateIndexSQL(cms_db_prefix() . 'news_postdate', cms_db_prefix() . 'module_news', 'news_date'); $dict->ExecuteSQLArray($sqlarray); $sqlarray = $dict->CreateIndexSQL(cms_db_prefix() . 'news_daterange', cms_db_prefix() . 'module_news', 'start_time,end_time'); $dict->ExecuteSQLArray($sqlarray); $sqlarray = $dict->CreateIndexSQL(cms_db_prefix() . 'news_author', cms_db_prefix() . 'module_news', 'author_id'); $dict->ExecuteSQLArray($sqlarray); $sqlarray = $dict->CreateIndexSQL(cms_db_prefix() . 'news_hier', cms_db_prefix() . 'module_news', 'news_category_id'); $dict->ExecuteSQLArray($sqlarray); $sqlarray = $dict->CreateIndexSQL(cms_db_prefix() . 'news_url', cms_db_prefix() . 'module_news', 'news_url'); $dict->ExecuteSQLArray($sqlarray); $sqlarray = $dict->CreateIndexSQL(cms_db_prefix() . 'news_startenddate', cms_db_prefix() . 'module_news', 'start_time,end_time'); $dict->ExecuteSQLArray($sqlarray); #Setup events $this->CreateEvent('NewsArticleAdded'); $this->CreateEvent('NewsArticleEdited'); $this->CreateEvent('NewsArticleDeleted'); $this->CreateEvent('NewsCategoryAdded'); $this->CreateEvent('NewsCategoryEdited'); $this->CreateEvent('NewsCategoryDeleted'); $this->RegisterModulePlugin(TRUE); $this->RegisterSmartyPlugin('news', 'function', 'function_plugin'); // and routes... $route = new CmsRoute('/[nN]ews\\/(?P<articleid>[0-9]+)\\/(?P<returnid>[0-9]+)\\/(?P<junk>.*?)\\/d,(?P<detailtemplate>.*?)$/', $this->GetName()); cms_route_manager::add_static($route); $route = new CmsRoute('/[nN]ews\\/(?P<articleid>[0-9]+)\\/(?P<returnid>[0-9]+)\\/(?P<junk>.*?)$/', $this->GetName()); cms_route_manager::add_static($route); $route = new CmsRoute('/[nN]ews\\/(?P<articleid>[0-9]+)\\/(?P<returnid>[0-9]+)$/', $this->GetName()); cms_route_manager::add_static($route); $route = new CmsRoute('/[nN]ews\\/(?P<articleid>[0-9]+)$/', $this->GetName()); cms_route_manager::add_static($route);
/** * A function tat, given the current request information will return * a pageid or an alias that should be used for the display * This method also handles matching routes and specifying which module * should be called with what parameters * * @internal * @access private * @return string */ function get_pageid_or_alias_from_url() { $gCms = cmsms(); $config = $gCms->GetConfig(); $contentops = $gCms->GetContentOperations(); $smarty = $gCms->GetSmarty(); $params =& $_REQUEST; if (isset($params['mact'])) { $ary = explode(',', cms_htmlentities($params['mact']), 4); $smarty->id = isset($ary[1]) ? $ary[1] : ''; } else { // old? $smarty->id = isset($params['id']) ? intval($params['id']) : ''; } $page = ''; if (isset($smarty->id) && isset($params[$smarty->id . 'returnid'])) { // get page from returnid parameter in module action $page = $params[$smarty->id . 'returnid']; } else { if (isset($config["query_var"]) && $config["query_var"] != '' && isset($_GET[$config["query_var"]])) { // using non friendly urls... get the page alias/id from the query var. $page = $_GET[$config["query_var"]]; } else { // either we're using pretty urls // or this is the default page. if (isset($_SERVER["REQUEST_URI"]) && !endswith($_SERVER['REQUEST_URI'], 'index.php')) { $matches = array(); if (preg_match('/.*index\\.php\\/(.*?)$/', $_SERVER['REQUEST_URI'], $matches)) { // pretty urls... grab all the stuff after the index.php $page = $matches[1]; } } } } // by here, if page is empty, use the default page id if ($page == '') { // assume default content $page = $contentops->GetDefaultContent(); } // by here, if we're not assuming pretty urls of any sort // and we have a value... we're done. if ($config['url_rewriting'] == 'none') { return $page; } // some kind of a pretty url. // strip off GET params. if (($tmp = strpos($page, '?')) !== FALSE) { $page = substr($page, 0, $tmp); } // strip off page extension if ($config['page_extension'] != '' && endswith($page, $config['page_extension'])) { $page = substr($page, 0, strlen($page) - strlen($config['page_extension'])); } // trim trailing / $page = rtrim($page, '/'); // see if there's a route that matches. $matched = false; $route = cms_route_manager::find_match($page); if (is_object($route)) { $matched = true; if ($route->is_content()) { // a route to a page. $page = $route->get_content(); } else { $matches = $route->get_results(); // it's a module route //Now setup some assumptions if (!isset($matches['id'])) { $matches['id'] = 'cntnt01'; } if (!isset($matches['action'])) { $matches['action'] = 'defaulturl'; } if (!isset($matches['inline'])) { $matches['inline'] = 0; } if (!isset($matches['returnid'])) { $matches['returnid'] = ''; } #Look for default page if (!isset($matches['module'])) { $matches['module'] = $route->get_dest(); } //Get rid of numeric matches foreach ($matches as $key => $val) { if (is_int($key)) { unset($matches[$key]); } else { if ($key != 'id') { $_REQUEST[$matches['id'] . $key] = $val; } } } //Now set any defaults that might not have been in the url $tmp = $route->get_defaults(); if (is_array($tmp) && count($tmp) > 0) { foreach ($tmp as $key => $val) { $_REQUEST[$matches['id'] . $key] = $val; if (array_key_exists($key, $matches)) { $matches[$key] = $val; } } } //Get a decent returnid if ($matches['returnid'] == '') { $matches['returnid'] = $contentops->GetDefaultPageID(); } // Put the resulting mact into the request so that the subsequent smarty plugins // can grab it... $_REQUEST['mact'] = $matches['module'] . ',' . $matches['id'] . ',' . $matches['action'] . ',' . $matches['inline']; $page = $matches['returnid']; $smarty->id = $matches['id']; } } // if no route matched... grab the alias from the last / if (($pos = strrpos($page, '/')) !== FALSE && $matched == false) { $page = substr($page, $pos + 1); } // if there's nothing use the default content. if (empty($page)) { // maybe it's the home page. $page = $contentops->GetDefaultContent(); } return $page; }