public function isMatch() { $promoSections = array('obrati_vnimanie', 'promotion'); require_once $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/prolog_before.php"; $this->_url = explode('?', $this->_url); $this->_url = $this->_url[0]; // Разберём адрес $urlParts = explode('/', $this->_url); // Удалим пустые элементы $urlParts = array_values(array_filter($urlParts, function ($el) { return !empty($el); })); if (count($urlParts) != 3) { return false; } $articleCode = $urlParts[2]; $articleMapper = new MH_Articles_ArticleMapper(); foreach ($promoSections as $sectionCode) { $section = MH_Articles_SectionRepository::o()->getSectionByCode($sectionCode); $article = $articleMapper->getByCode($articleCode, $section); if (!is_null($article->code)) { $this->_newUrl = '/' . $sectionCode . '/' . $article->code . '/'; return true; } } return false; }
public function getUrlById($id, $module = null) { if (empty($id)) { return ''; } // загружаем сразу пачку $id = (array) $id; // что потом вернуть, массив или один элемент $isSingle = 1 == count($id); if (is_null($module)) { // если модуль не передан, надо рассортировать все id по их модул¤м $moduleToIds = $this->_determineModules($id); } else { // если передан модуль, считаем, что он дл¤ всех id одинаковый $moduleToIds = array((string) $module => $id); } $result = array(); foreach ($moduleToIds as $module => $ids) { switch ($module) { case 'articles': $articleMapper = new MH_Articles_ArticleMapper(); foreach ($articleMapper->getByIds($ids) as $aid => $article) { $result[$aid] = $article->url; } break; case 'authors': $authorMapper = new MH_Authors_AuthorMapper(); foreach ($authorMapper->getById($ids) as $aid => $author) { $result[$aid] = $author->url; } break; default: // кака¤-то фигн¤ $result = array_merge($result, array_fill_keys($ids, '')); break; } } return $isSingle ? array_shift($result) : $result; }
public function isMatch() { if ($pos = strpos($this->_url, '?')) { $url = substr($this->_url, 0, $pos); } else { $url = $this->_url; } if (!preg_match('~^/(?:[a-z_]+/)?(?:[a-z_]+/)?(\\d{3,})/?$~', $url, $m)) { return false; } require_once $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/prolog_before.php"; $id = (int) $m[1]; $articleMapper = new MH_Articles_ArticleMapper(); // пробуем найти по id $article = $articleMapper->getByIds($id, array('getNonPublished' => true)); if ($article->isExists()) { $this->_newUrl = $article->url; return true; } else { return false; } }