/**
  * Test the setPath method.
  *
  * @return  void
  *
  * @since   11.1
  * @covers  JUri::setPath
  */
 public function testSetPath()
 {
     $this->object->setPath('/this/is/a/path/to/a/file.htm');
     $this->assertThat($this->object->getPath(), $this->equalTo('/this/is/a/path/to/a/file.htm'));
 }
Exemplo n.º 2
0
 /**
  * isUserOperation
  *
  * @param \JUri $uri
  *
  * @return  boolean
  */
 public function isUserOperation(\JUri $uri)
 {
     $path = $uri->getPath();
     $root = \JUri::root(true);
     $route = substr($path, strlen($root));
     return strpos($route, '/api/user') === 0;
 }
Exemplo n.º 3
0
 /**
  * Function to build a sef route
  *
  * @param   JUri  $uri  The uri
  *
  * @return  void
  */
 protected function _buildSefRoute($uri)
 {
     // Get the route
     $route = $uri->getPath();
     // Get the query data
     $query = $uri->getQuery(true);
     if (!isset($query['option'])) {
         return;
     }
     $app = JApplication::getInstance('site');
     $menu = $app->getMenu();
     /*
      * Build the component route
      */
     $component = preg_replace('/[^A-Z0-9_\\.-]/i', '', $query['option']);
     $tmp = '';
     $itemID = !empty($query['Itemid']) ? $query['Itemid'] : null;
     // Use the component routing handler if it exists
     $path = JPATH_SITE . '/components/' . $component . '/router.php';
     // Use the custom routing handler if it exists
     if (file_exists($path) && !empty($query)) {
         require_once $path;
         $function = substr($component, 4) . 'BuildRoute';
         $function = str_replace(array("-", "."), "", $function);
         $parts = $function($query);
         // Encode the route segments
         if ($component != 'com_search') {
             // Cheep fix on searches
             $parts = $this->_encodeSegments($parts);
         } else {
             // Fix up search for URL
             $total = count($parts);
             for ($i = 0; $i < $total; $i++) {
                 // Urlencode twice because it is decoded once after redirect
                 $parts[$i] = urlencode(urlencode(stripcslashes($parts[$i])));
             }
         }
         $result = implode('/', $parts);
         $tmp = $result != "" ? $result : '';
     }
     /*
      * Build the application route
      */
     $built = false;
     if (!empty($query['Itemid'])) {
         $item = $menu->getItem($query['Itemid']);
         if (is_object($item) && $query['option'] == $item->component) {
             if (!$item->home || $item->language != '*') {
                 $tmp = !empty($tmp) ? $item->route . '/' . $tmp : $item->route;
             }
             $built = true;
         }
     }
     if (empty($query['Itemid']) && !empty($itemID)) {
         $query['Itemid'] = $itemID;
     }
     if (!$built) {
         $tmp = 'component/' . substr($query['option'], 4) . '/' . $tmp;
     }
     if ($tmp) {
         $route .= '/' . $tmp;
     } elseif ($route == 'index.php') {
         $route = '';
     }
     // Unset unneeded query information
     if (isset($item) && $query['option'] == $item->component) {
         unset($query['Itemid']);
     }
     unset($query['option']);
     // Set query again in the URI
     $uri->setQuery($query);
     $uri->setPath($route);
 }
 /**
  * Generate a URI based on current URL.
  *
  * @param JUri $url
  *
  * @return string
  */
 private function getCurrentURI(JUri $url)
 {
     $uri = $url->getPath();
     if ($url->getQuery()) {
         $uri .= "?" . $url->getQuery();
     }
     return $uri;
 }
Exemplo n.º 5
0
 /**
  * Tests the buildBase() method
  *
  * @return  void
  *
  * @since   4.0
  */
 public function testBuildBase()
 {
     $server = array('HTTP_HOST' => 'www.example.com:80', 'SCRIPT_NAME' => '/joomla/index.php', 'PHP_SELF' => '/joomla/index.php', 'REQUEST_URI' => '/joomla/index.php?var=value 10');
     $_SERVER = array_merge($_SERVER, $server);
     $uri = new JUri('index.php');
     $this->assertEquals('index.php', $uri->getPath());
     $this->object->buildBase($this->object, $uri);
     $this->assertEquals(JUri::base(true) . '/' . 'index.php', $uri->getPath());
 }
Exemplo n.º 6
0
 /**
  * Parse rule hook.
  *
  * @param \JRouter $router The router object.
  * @param \JUri    $uri    The uri object.
  *
  * @return  array
  *
  * @throws \InvalidArgumentException
  */
 public function parseRule(\JRouter $router, \JUri $uri)
 {
     $path = $uri->getPath();
     // No path & method, return 404.
     if ($this->isRoot($uri)) {
         throw new \InvalidArgumentException('No method.', 404);
     }
     // Direct our URI to component
     $path = 'component/' . $this->component . '/' . $path;
     $uri->setPath($path);
     $uri->setVar('format', 'json');
     return array();
 }
Exemplo n.º 7
0
 /**
  * Give a relative path, return path with host.
  *
  * @param   string $path A system path.
  *
  * @return  string  Path with host added.
  */
 public static function pathAddHost($path)
 {
     if (!$path) {
         return '';
     }
     // Build path
     $uri = new \JUri($path);
     if ($uri->getHost()) {
         return $path;
     }
     $uri->parse(\JUri::root());
     $root_path = $uri->getPath();
     if (strpos($path, $root_path) === 0) {
         $num = Utf8String::strlen($root_path);
         $path = Utf8String::substr($path, $num);
     }
     $uri->setPath($uri->getPath() . $path);
     $uri->setScheme('http');
     $uri->setQuery(null);
     return $uri->toString();
 }