Пример #1
0
 public function frontendPreInitialise($context)
 {
     $conf = Symphony::Configuration()->{'rewrite'}();
     $url = $_SERVER['REQUEST_URI'];
     if (strpos($url, __SYM_COOKIE_PATH__) == 0) {
         $url = substr($url, strlen(__SYM_COOKIE_PATH__));
     }
     $url = trim($url, '/');
     foreach ($conf->rules as $rule) {
         $match = $rule->match;
         $replace = $rule->replace;
         $case = $rule->{'case-sensetive'} == 'yes';
         // Escape slashes:
         $match = str_replace('/', '\\/', $match);
         // Add regexp flags:
         $match = '/' . $match . '/' . ($case ? '' : 'i');
         if (preg_match($match, $url, $matches)) {
             $bits = preg_split('/(\\\\[0-9]+)/', $replace, 0, PREG_SPLIT_DELIM_CAPTURE);
             $redirect = '';
             foreach ($bits as $bit) {
                 if (preg_match('/^\\\\[0-9]+$/', $bit)) {
                     $index = (int) trim($bit, '\\');
                     if (isset($matches[$index])) {
                         $redirect .= $matches[$index];
                     }
                     continue;
                 }
                 $redirect .= $bit;
             }
             break;
         }
     }
     // Found a new URL:
     if (isset($redirect)) {
         $url = parse_url($redirect);
         $symphony_page = trim($url['path'], '/');
         $query_string = $url['query'] . '&symphony-page=' . $symphony_page;
         $query_array = $this->parseQueryString($query_string);
         $context['page'] = '/' . $symphony_page;
         $context['view'] = View::loadFromURL($context['page']);
         $_SERVER['QUERY_STRING'] = $query_string;
         $_GET = $query_array;
     }
 }
Пример #2
0
 public function resolve($url = NULL)
 {
     try {
         if (is_null($url)) {
             $views = View::findFromType('index');
             self::$view = array_shift($views);
         } else {
             self::$view = View::loadFromURL($url);
         }
         if (!self::$view instanceof View) {
             throw new Exception('Page not found');
         }
         if (!Frontend::instance()->isLoggedIn() && in_array('admin', self::$view->types)) {
             $views = View::findFromType('403');
             self::$view = array_shift($views);
             if (!self::$view instanceof View) {
                 throw new SymphonyErrorPage(__('Please <a href="%s">login</a> to view this page.', array(ADMIN_URL . '/login/')), __('Forbidden'), NULL, array('HTTP/1.0 403 Forbidden'));
             }
         }
     } catch (Exception $e) {
         $views = View::findFromType('404');
         self::$view = array_shift($views);
         if (!self::$view instanceof View) {
             throw new FrontendPageNotFoundException($url);
         }
     }
 }