Ejemplo n.º 1
0
 public function parse($query)
 {
     $post = null;
     if ($this->app->getCfg('sef', 0) == 0) {
         $id = $query->get('page_id');
         if (empty($id)) {
             $id = $query->get('p');
         }
         $post = MFactory::getWPost($id);
     } else {
         $segments = explode('/', $query->get('pagename'));
         if (empty($segments[0])) {
             return;
         }
         $post = get_page_by_path($segments[0]);
     }
     if (!is_object($post)) {
         $page_id = MFactory::getWOption($this->context . '_page_id');
         $post = MFactory::getWPost($page_id);
         $option = MRequest::getCmd('option', '');
         if (!is_object($post) or $option != 'com_' . $this->context) {
             return;
         }
         $query->set('page_id', $page_id);
         $query->set('post_type', 'page');
     }
     if ($this->_hasShortcode($post->post_content, $this->context) or $this->_hasShortcode($post->post_content, $this->context . '_item')) {
         MRequest::setVar('option', 'com_' . $this->context);
         $vars = $this->app->parse();
         //MRequest::set($vars, 'POST');
         //MRequest::set($vars, 'GET');
         $query->query_vars = array_merge($query->query_vars, $vars);
     }
 }
Ejemplo n.º 2
0
 protected function _buildSefRoute(&$uri)
 {
     // Get the route
     $route = $uri->getPath();
     $route = str_replace('index.php', '', $route);
     // Get the query data
     $query = $uri->getQuery(true);
     if (!isset($query['option'])) {
         return;
     }
     /*
      * Build the component route
      */
     $component = preg_replace('/[^A-Z0-9_\\.-]/i', '', $query['option']);
     $tmp = '';
     // Use the component routing handler if it exists
     $path = MPATH_WP_PLG . '/' . str_replace('com_', '', $component) . '/site/router.php';
     // Use the custom routing handler if it exists
     if (file_exists($path) && !empty($query)) {
         require_once $path;
         $function = str_replace('com_', '', $component) . 'BuildRoute';
         $function = str_replace(array("-", "."), "", $function);
         $parts = $function($query);
         // encode the route segments
         $parts = $this->_encodeSegments($parts);
         $result = implode('/', $parts);
         $tmp = $result != "" ? $result : '';
     }
     /*
      * Build the application route
      */
     if ($tmp) {
         $route .= '/' . $tmp;
     } elseif ($route == 'index.php') {
         $route = '';
     }
     $option_get = str_replace('com_', '', MRequest::getWord('option', ''));
     if (str_replace('com_', '', $component) == $option_get) {
         $page_id = MRequest::getInt('page_id');
     } else {
         $page_id = null;
     }
     if (empty($page_id)) {
         $page_id = MFactory::getWOption(str_replace('com_', '', $query['option']) . '_page_id');
     }
     if (!empty($page_id)) {
         $post = MFactory::getWPost($page_id);
         if (is_object($post)) {
             $route = $post->post_name . '/' . ltrim($route, '/');
         }
         $route = MUri::base(true) . '/' . ltrim($route, '/');
     }
     // Unset unneeded query information
     unset($query['option']);
     //Set query again in the URI
     $uri->setQuery($query);
     $uri->setPath($route);
 }