Skip to content

Instantly share code, notes, and snippets.

@vanchelo
Created July 6, 2012 12:07
Show Gist options
  • Save vanchelo/3059790 to your computer and use it in GitHub Desktop.
Save vanchelo/3059790 to your computer and use it in GitHub Desktop.
Pagebreaker
<?php
if ($modx->Event->name == 'OnPageNotFound') {
$uri = $_SERVER['REQUEST_URI'];
// Обычный ресурс
if (preg_match("#(\.*?[a-z0-9_\-]+)_p(\d+)\.html#si", $uri, $m)) {
$alias = preg_replace("#(\.*?[a-z0-9_\-]+)_p(\d+)(\.html)#si", "$1$3", $uri);
$alias = substr($alias, 1, strlen($alias));
}
// Контейнер
else if (preg_match("#(\.*?[a-z0-9_\-]+)/_p(\d+)\.html#si", $uri, $m)) {
$alias = preg_replace("#(\.*?/[a-z0-9_\-]+)/_p(\d+)(\.html)#si", "$1/", $uri);
$alias = substr($alias, 1, strlen($alias));
}
if ($res = $modx->getObject('modResource', array('uri' => $alias))) {
$id = $res->get('id');
$modx->sendForward($id);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment