示例#1
0
 /**
  * Create a uri based on a full or partial url string
  *
  * @param   string  $url  The URI
  *
  * @return  JUri
  *
  * @since   3.2
  */
 protected function createURI($url)
 {
     // Create the URI
     $uri = parent::createURI($url);
     // Get the itemid form the URI
     $itemid = $uri->getVar('Itemid');
     if (is_null($itemid)) {
         if ($option = $uri->getVar('option')) {
             $item = $this->menu->getItem($this->getVar('Itemid'));
             if (isset($item) && $item->component == $option) {
                 $uri->setVar('Itemid', $item->id);
             }
         } else {
             if ($option = $this->getVar('option')) {
                 $uri->setVar('option', $option);
             }
             if ($itemid = $this->getVar('Itemid')) {
                 $uri->setVar('Itemid', $itemid);
             }
         }
     } else {
         if (!$uri->getVar('option')) {
             if ($item = $this->menu->getItem($itemid)) {
                 $uri->setVar('option', $item->component);
             }
         }
     }
     return $uri;
 }
示例#2
0
 /**
  * Build the SEF route
  *
  * @param   JRouterSite  &$router  Router object
  * @param   JUri         &$uri     URI object to process
  *
  * @return  void
  * 
  * @since   4.0
  */
 public function buildSefRoute(&$router, &$uri)
 {
     // Get the route
     $route = $uri->getPath();
     // 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 = '';
     $Itemid = isset($query['Itemid']) ? $query['Itemid'] : null;
     $crouter = $this->getComponentRouter($component);
     $parts = $crouter->build($query);
     $tmp = trim(implode('/', $parts));
     if (empty($query['Itemid']) && !empty($Itemid)) {
         $query['Itemid'] = $Itemid;
     }
     // Build the application route
     if (isset($query['Itemid']) && ($item = $this->menu->getItem($query['Itemid']))) {
         if (is_object($item) && $query['option'] == $item->component) {
             if (!$item->home) {
                 $tmp = !empty($tmp) ? $item->route . '/' . $tmp : $item->route;
             }
             unset($query['Itemid']);
         }
     } else {
         $tmp = 'component/' . substr($query['option'], 4) . '/' . $tmp;
     }
     $route .= '/' . $tmp;
     // Unset unneeded query information
     unset($query['option']);
     // Set query again in the URI
     $uri->setQuery($query);
     $uri->setPath(trim($route, '/'));
 }
示例#3
0
 /**
  * Parse method for URLs
  * This method is meant to transform the human readable URL back into
  * query parameters. It is only executed when SEF mode is switched on.
  *
  * @param   array  &$segments  The segments of the URL to parse.
  *
  * @return  array  The URL attributes to be used by the application.
  *
  * @since   3.3
  */
 public function parse(&$segments)
 {
     /*
      * Available urls:
      *
      * projects
      * {project}
      * {project}/issues
      * {project}/{issue}
      * {project}/{issue}/edit
      * comment/edit/{comment}
      * comments
      */
     $query = array('option' => 'com_monitor');
     if (empty($query['Itemid'])) {
         $menuItem = $this->menu->getActive();
     } else {
         $menuItem = $this->menu->getItem($query['Itemid']);
     }
     if (empty(array_filter($segments))) {
         return $menuItem->query;
     }
     $menuQuery = $menuItem !== null && $menuItem->query['option'] === self::COMPONENT ? $menuItem->query : null;
     self::convertTaskToView($menuQuery);
     $menuView = isset($menuQuery['view']) ? $menuQuery['view'] : null;
     if ($segments[0] == 'projects') {
         $query['view'] = 'projects';
     } elseif ($segments[0] == 'issues') {
         $query['view'] = 'issues';
         if ($menuView == 'project' && isset($menuQuery['id'])) {
             $query['project_id'] = $menuQuery['id'];
         }
     } elseif ($segments[0] == 'comment') {
         $query['view'] = 'comment';
         $query['layout'] = $segments[1] === 'delete' ? 'delete' : 'edit';
         if (isset($segments[1]) && $segments[1] == 'new' && is_numeric($segments[2])) {
             $query['issue_id'] = $segments[2];
         } elseif (is_numeric($segments[2])) {
             $query['id'] = $segments[2];
         }
     } elseif ($segments[0] == 'comments') {
         $query['view'] = 'comments';
     } elseif (is_numeric($segments[0])) {
         $query['view'] = 'issue';
         $query['id'] = $segments[0];
         if (isset($segments[1]) && $segments[1] === 'edit') {
             $query['layout'] = 'edit';
         }
     } elseif ($segments[0] === 'edit' || $segments[0] === 'new') {
         $query['layout'] = 'edit';
         if ($menuView === 'comment') {
             $query['view'] = 'comment';
             if (is_numeric($segments[1])) {
                 if ($segments[0] === 'new') {
                     $query['issue_id'] = $segments[1];
                 } else {
                     $query['id'] = $segments[1];
                 }
             }
         } else {
             $query['view'] = 'issue';
             if ($segments[0] === 'new') {
                 if (isset($menuQuery['id'])) {
                     $query['project_id'] = $menuQuery['id'];
                 } elseif (isset($menuQuery['project_id'])) {
                     $query['project_id'] = $menuQuery['project_id'];
                 }
             } else {
                 if (isset($menuQuery['id'])) {
                     $query['id'] = $menuQuery['id'];
                 }
             }
         }
     } else {
         // {project}
         if (!isset($segments[1])) {
             $id = $this->modelProject->resolveAlias($segments[0]);
             $query['view'] = 'project';
             $query['id'] = $id;
         } else {
             // {project}/issues
             if ($segments[1] === 'issues') {
                 $id = $this->modelProject->resolveAlias($segments[0]);
                 $query['view'] = 'issues';
                 $query['project_id'] = $id;
             } else {
                 $query['view'] = 'issue';
                 // {project}/new
                 if ($segments[1] === 'new') {
                     $id = $this->modelProject->resolveAlias($segments[0]);
                     $query['layout'] = 'edit';
                     $query['project_id'] = $id;
                 } elseif (is_numeric($segments[1])) {
                     $query['id'] = $segments[1];
                     // {project}/{issue}/edit
                     if (isset($segments[2]) && $segments[2] == 'edit') {
                         $query['layout'] = 'edit';
                     }
                 }
             }
         }
     }
     return $query;
 }