Пример #1
0
 /**
  * chapter/index and book/index by name callback
  * @param eRequest $request
  */
 public function chapterIdByTitle(eRequest $request)
 {
     $name = $request->getRequestParam('name');
     if ($id = $request->getRequestParam('id')) {
         $request->setRequestParam('name', $id);
         return;
     } elseif (!$name || is_numeric($name)) {
         if (ADMIN) {
             e107::getMessage()->addError("One of your page-chapters is missing a SEF URL value");
         }
         return;
     }
     $sql = e107::getDb('url');
     $name = e107::getParser()->toDB($name);
     if ($sql->select('page_chapters', 'chapter_id', "chapter_sef='{$name}'")) {
         $name = $sql->fetch();
         $request->setRequestParam('id', $name['chapter_id']);
         $request->setRequestParam('type', 'bk');
         e107::getMessage()->addDebug("Set CHAPTER ID =  '" . $name['chapter_id'] . "'");
     } elseif ($sql->select('page', 'page_id', "page_sef='{$name}'")) {
         $name = $sql->fetch();
         $request->setRequestParam('id', $name['page_id']);
         $request->setRequestParam('type', 'id');
         e107::getMessage()->addDebug("Set PAGE ID =  '" . $name['page_id'] . "'");
     } else {
         if (ADMIN) {
             e107::getMessage()->addError("Couldn't find a book, chapter or page with a SEF URL value of '" . $name . "'");
         }
         $request->setRequestParam('id', 0);
     }
 }
Пример #2
0
 /**
  * profile/edit & profile/view callback
  * @param eRequest $request
  */
 public function idByName(eRequest $request)
 {
     $name = $request->getRequestParam('name');
     if (!$name) {
         return;
     }
     // if id only is passed, don't do DB query
     if (is_numeric($name)) {
         $request->setRequestParam('id', $name)->setRequestParam('name', null);
         return;
     }
     $sql = e107::getDb('url');
     $name = e107::getParser()->toDB($name);
     if ($sql->db_Select('user', 'user_id', "user_name='{$name}'")) {
         $name = $sql->db_Fetch();
         $request->setRequestParam('id', $name['user_id']);
     }
 }
Пример #3
0
 /**
  * view/item by name callback
  * @param eRequest $request
  */
 public function itemIdByTitle(eRequest $request)
 {
     $name = $request->getRequestParam('name');
     if ($id = $request->getRequestParam('id')) {
         $request->setRequestParam('name', $id);
         return;
     } elseif (!$name || is_numeric($name)) {
         return;
     }
     $sql = e107::getDb('url');
     $name = e107::getParser()->toDB($name);
     if ($sql->db_Select('page', 'page_id', "page_theme='' AND page_sef='{$name}'")) {
         $name = $sql->db_Fetch();
         $request->setRequestParam('name', $name['page_id']);
     } else {
         $request->setRequestParam('name', 0);
     }
 }
Пример #4
0
 /**
  * list/items by name callback
  * @param eRequest $request
  */
 public function categoryIdByTitle(eRequest $request)
 {
     $name = $request->getRequestParam('name');
     if ($id = $request->getRequestParam('id')) {
         $request->setRequestParam('name', $id);
         return;
     } elseif (!$name) {
         return;
     } elseif (is_numeric($name)) {
         return;
     }
     $sql = e107::getDb('url');
     $id = e107::getParser()->toDB($name);
     if ($sql->db_Select('news_category', 'category_id', "category_sef='{$name}'")) {
         $name = $sql->db_Fetch();
         $request->setRequestParam('name', $name['category_id']);
     } else {
         $request->setRequestParam('name', 0);
     }
 }
Пример #5
0
 /**
  * Parases a URL based on this rule.
  * @param eRouter $manager the router/URL manager
  * @param eRequest $request the request object
  * @param string $pathInfo path info part of the URL
  * @param string $rawPathInfo path info that contains the potential URL suffix
  * @return mixed the route that consists of the controller ID and action ID or false on error
  */
 public function parseUrl($manager, $request, $pathInfo, $rawPathInfo)
 {
     $case = 'i';
     # 'i' = insensitive
     if ($this->urlSuffix !== null) {
         $pathInfo = $manager->removeUrlSuffix($rawPathInfo, $this->urlSuffix);
     }
     $pathInfo = rtrim($pathInfo, '/') . '/';
     // pathInfo is decoded, pattern could be encoded - required for proper url assemble (e.g. cyrillic chars)
     if (preg_match(rawurldecode($this->pattern) . $case, $pathInfo, $matches)) {
         foreach ($this->defaultParams as $name => $value) {
             //if (!isset($_GET[$name])) $_REQUEST[$name] = $_GET[$name] = $value;
             if (!$request->isRequestParam($name)) {
                 $request->setRequestParam($name, $value);
             }
         }
         $tr = array();
         foreach ($matches as $key => $value) {
             if (isset($this->references[$key])) {
                 $tr[$this->references[$key]] = $value;
             } elseif (isset($this->params[$key])) {
                 //$_REQUEST[$key] = $_GET[$key] = $value;
                 $request->setRequestParam($key, $value);
             }
         }
         if ($pathInfo !== $matches[0]) {
             $manager->parsePathInfo($request, ltrim(substr($pathInfo, strlen($matches[0])), '/'));
         }
         return null !== $this->routePattern ? strtr($this->route, $tr) : $this->route;
     } else {
         return false;
     }
 }