Example #1
0
 /**
  * Returns a JUri instance with a prototype URI used as the base for the
  * other URIs created by the JSON renderer
  *
  * @return  Uri  The prototype JUri instance
  */
 protected function _getPrototypeURIForPagination()
 {
     $protoUri = new Uri(Uri::rebase('index.php', $this->container));
     $protoUri->setQuery($this->input->getData());
     $protoUri->delVar('savestate');
     $protoUri->delVar('base_path');
     return $protoUri;
 }
Example #2
0
 /**
  * Put a URL through the routing rules and return the routed URL.
  *
  * @param   string  $url      The URL to route
  * @param   boolean $rebase   Should I rebase the resulting URL? False to return a relative URL to the application's
  *                            live_site and base_url, as defined in the application configuration
  *
  * @return  string  The routed URL
  */
 public function route($url, $rebase = true)
 {
     // Initialise
     $routeResult = null;
     // Use the routing rules to produce a list of segments
     if (!empty($this->rules)) {
         /** @var Rule $rule */
         foreach ($this->rules as $rule) {
             $routeResult = $rule->route($url);
             if (is_array($routeResult)) {
                 break;
             }
         }
     }
     // Parse the URL into an object
     $uri = new Uri($url);
     if (!is_null($routeResult)) {
         // We'll replace the path and query string parameters with what the routing rule sent us
         $uri->setPath(implode('/', $routeResult['segments']));
         $uri->setQuery($routeResult['vars']);
     }
     // Do we have to rebase?
     if ($rebase) {
         // Get the base URL
         $baseUrl = $this->container->appConfig->get('base_url', '');
         if (empty($baseUrl)) {
             $baseUrl = '';
         }
         $baseUrl = rtrim($baseUrl, '/');
         if (strpos($baseUrl, 'http://') === 0 || strpos($baseUrl, 'https://') === 0) {
             $base = $baseUrl;
         } else {
             $base = Uri::base(false, $this->container);
             $base = rtrim($base, '/') . '/' . $baseUrl;
         }
         $rebaseURI = new Uri($base);
         // Merge the paths of the rebase and routed URIs. However if the router URI contains index.php
         // and the base URL ends in a .php script do not append index.php to the other .php script
         // (this is required for the WP integration to work properly)
         if (!($uri->getPath() == 'index.php' && substr($rebaseURI->getPath(), -4) == '.php')) {
             $rebaseURI->setPath(rtrim($rebaseURI->getPath(), '/') . '/' . $uri->getPath());
         }
         // Merge the query string parameters of the rebase and routed URIs
         $vars_routed = $uri->getQuery(true);
         $vars_rebase = $rebaseURI->getQuery(true);
         $rebaseURI->setQuery(array_merge($vars_rebase, $vars_routed));
         // We'll return the rebased URI
         $uri = $rebaseURI;
     }
     return $uri->toString();
 }