/** * Route the URL request based on the container IDs * * @return boolean */ public function route() { $serverUri = $this->modx->request->parameters['REQUEST']; $qmt = $serverUri[$this->modx->getOption('request_param_alias')]; // check to see there is a link rss comments if (preg_match("@comments-(.*?).rss@si", $qmt, $data)) { if (in_array($data[1], $this->aliasMap) && $data[0] == $qmt && $this->_hasConversations($data[1])) { $_REQUEST['comment'] = $data[1]; $_REQUEST['rss'] = 'true'; $this->modx->sendForward($data[1]); } } // check to see there is a link to a comment if (!preg_match("@/?comment-(.*?)-mt@si", $qmt, $data)) { return true; } $alias = str_replace($data[0], '', $qmt); $id = $alias === '/' ? $this->modx->getOption('site_start', 1) : $this->aliasMap[$alias]; if ($id) { if (isset($data[1]) && $this->_hasConversations($id)) { if ($data[1] == 'last' || intval($data[1]) || date('Y-m', strtotime($data[1]))) { $_REQUEST['comment'] = $data[1]; $this->modx->sendForward($id); } } } return true; }
/** * Prepare the request parameters. * * @access public * @return void */ public function setRequest() { $params = str_replace('.html', '', $this->urlParams); if ($this->regEx) { $params = preg_match($this->regEx, $params); } else { $params = explode('/', $params); } if (count($params) >= 1) { $setting = $this->requests[$this->alias]; // set the request parameters foreach ($params as $key => $value) { if (isset($setting['urlParams'][$key])) { $_REQUEST[$setting['urlParams'][$key]] = $value; } else { $_REQUEST['p' . ($key + 1)] = $value; } } } $this->modx->sendForward($this->resourceId); return; }
/** * @param $id * @param null $options */ public function sendForward($id, $options = null) { $this->modx->sendForward($id, $options); }
/** * Route the URL request based on the container IDs * @return boolean */ public function route() { $containerIds = $this->modx->getOption('articles.container_ids', null, ''); if (empty($containerIds)) { return false; } $containerIds = explode(',', $containerIds); /* handle redirects */ $search = $_SERVER['REQUEST_URI']; $base_url = $this->modx->getOption('base_url'); if ($base_url != '/') { $search = str_replace($base_url, '', $search); } $search = trim($search, '/'); /* get resource to redirect to */ $resourceId = false; $prefix = 'arc_'; foreach ($containerIds as $archive) { $archive = explode(':', $archive); $archiveId = $archive[0]; $alias = array_search($archiveId, $this->modx->aliasMap); if ($alias && strpos($search, $alias) !== false) { $search = str_replace($alias, '', $search); $resourceId = $archiveId; if (isset($archive[1])) { $prefix = $archive[1]; } } } if (!$resourceId) { return false; } /* figure out archiving */ $params = explode('/', $search); if (count($params) < 1) { return false; } /* tag handling! */ if ($params[0] == 'tags') { $_GET['tag'] = $params[1]; /* author based */ } else { if ($params[0] == 'user' || $params[0] == 'author') { $_GET[$prefix . 'author'] = $params[1]; /* numeric "archives/1234" */ } else { if ($params[0] == 'archives' && !empty($params[1])) { $resourceId = intval(trim(trim($params[1]), '/')); if (!empty($resourceId)) { $this->modx->sendForward($resourceId); } /* normal yyyy/mm/dd or yyyy/mm */ } else { /* set Archivist parameters for date-based archives */ $_GET[$prefix . 'year'] = $params[0]; if (isset($params[1])) { $_GET[$prefix . 'month'] = $params[1]; } if (isset($params[2])) { $_GET[$prefix . 'day'] = $params[2]; } } } } /* forward */ $this->modx->sendForward($resourceId); return true; }
/** * Route the URL request based on the container IDs * @return boolean */ public function route() { $containerIds = $this->modx->getOption('articles.container_ids', null, ''); if (empty($containerIds)) { return false; } $containerIds = explode(',', $containerIds); /* handle redirects */ $search = $_SERVER['REQUEST_URI']; $base_url = $this->modx->getOption('base_url'); if ($base_url != '/') { $search = str_replace($base_url, '', $search); } $search = trim($search, '/'); /* get resource to redirect to */ $resourceId = false; $prefix = 'arc_'; foreach ($containerIds as $archive) { if (empty($archive)) { continue; } $archive = explode(':', $archive); $archiveId = $archive[0]; if (method_exists($this->modx->context, 'getResourceURI')) { $alias = $this->modx->context->getResourceURI($archiveId); } else { $alias = is_array($this->modx->aliasMap) ? array_search($archiveId, $this->modx->aliasMap) : ''; } if ($alias && $startPageId == $archiveId) { $startPageResId = $archiveId; if (isset($archive[1])) { $startPagePrefix = $archive[1]; } } if ($alias && strpos($search, $alias) === 0) { $search = substr($search, strlen($alias)); $resourceId = $archiveId; if (isset($archive[1])) { $prefix = $archive[1]; } } } if (!$resourceId) { return false; } /* figure out archiving */ $params = explode('/', $search); if (count($params) < 1) { return false; } /* tag handling! */ if ($params[0] == 'tags') { $_REQUEST[$prefix . 'author'] = $_GET['tag'] = urldecode($params[1]); /* author based */ } else { if ($params[0] == 'user' || $params[0] == 'author') { $_REQUEST[$prefix . 'author'] = $_GET[$prefix . 'author'] = urldecode($params[1]); /* numeric "archives/1234" */ } else { if ($params[0] == 'archives' && !empty($params[1])) { $resourceId = intval(trim(trim($params[1]), '/')); if (!empty($resourceId)) { $this->modx->sendForward($resourceId); } /* normal yyyy/mm/dd or yyyy/mm */ } else { /* set Archivist parameters for date-based archives */ if (is_numeric($params[0])) { $_REQUEST[$prefix . 'year'] = $_GET[$prefix . 'year'] = $params[0]; if (isset($params[1]) && is_numeric($params[1])) { $_REQUEST[$prefix . 'month'] = $_GET[$prefix . 'month'] = $params[1]; } else { if (isset($params[1])) { // Display the default 404 page if "month" is not a number $this->modx->sendForward($this->modx->getOption('error_page'), 'HTTP/1.1 404 Not Found'); } } if (isset($params[2]) && is_numeric($params[2])) { $_REQUEST[$prefix . 'day'] = $_GET[$prefix . 'day'] = $params[2]; } else { if (isset($params[2])) { // Display the default 404 page if "day" is not a number $this->modx->sendForward($this->modx->getOption('error_page'), 'HTTP/1.1 404 Not Found'); } } } else { // Display the default 404 page if nothing found $this->modx->sendForward($this->modx->getOption('error_page'), 'HTTP/1.1 404 Not Found'); } } } } /* forward */ $this->modx->sendForward($resourceId); return true; }