Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 37 additions & 10 deletions core/components/articles/model/articles/articlesrouter.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
* Place, Suite 330, Boston, MA 02111-1307 USA
*
* @package articles
*
* File updated for 1.7.6
*/
class ArticlesRouter {
/** @var modX $modx */
Expand Down Expand Up @@ -52,28 +54,45 @@ public function route() {
/* get resource to redirect to */
$resourceId = false;
$prefix = 'arc_';
$startPageResId = false;
$startPagePrefix = '';
$startPageId = $this->modx->getOption('site_start');
foreach ($containerIds as $archive) {
if (empty($archive)) continue;
$archive = explode(':',$archive);
$archiveId = $archive[0];
$alias = array_search($archiveId,$this->modx->aliasMap);
if ($alias && strpos($search,$alias) !== false) {
$search = str_replace($alias,'',$search);

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;

if (!$resourceId) {
if ($startPageResId) {
$resourceId = $startPageResId;
$prefix = $startPagePrefix;
} else return false;
}
/* figure out archiving */
$params = explode('/', $search);
if (count($params) < 1) return false;

/* tag handling! */
if ($params[0] == 'tags') {
$_GET['tag'] = $params[1];
$_REQUEST[$prefix.'author'] = $_GET['tag'] = urldecode($params[1]);
/* author based */
} else if ($params[0] == 'user' || $params[0] == 'author') {
$_GET[$prefix.'author'] = $params[1];
$_REQUEST[$prefix.'author'] = $_GET[$prefix.'author'] = urldecode($params[1]);

/* numeric "archives/1234" */
} else if ($params[0] == 'archives' && !empty($params[1])) {
Expand All @@ -85,9 +104,17 @@ public function route() {
/* 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];
$pyear = $params[0];
$pmonth = 1;
$pday = 1;
if (isset($params[1])) $pmonth = $params[1];
if (isset($params[2])) $pday = $params[2];
if (checkdate($pmonth, $pday, $pyear)) {
$_REQUEST[$prefix.'year'] = $_GET[$prefix.'year'] = $params[0];
if (isset($params[1])) $_REQUEST[$prefix.'month'] = $_GET[$prefix.'month'] = $params[1];
if (isset($params[2])) $_REQUEST[$prefix.'day'] = $_GET[$prefix.'day'] = $params[2];
$result = true;
} else return false;
}

/* forward */
Expand Down