Beispiel #1
0
	/**
	 * Returns a representative URL of the current route state.
	 * Optional segments and parameters may be passed to set the route state.
	 *
	 * @param array mixed $segments				- Assoc array of segment => value
	 * @param array mixed $parameters			- Array of parameter values, in order
	 * @param string $query_string				- Query string to append to the url
	 * @param int $override_method				- Allows the Friendly URL method to be overridden
	 * @param bool $canonical					- If true, don't encode for output
	 * @return string							- The URL representing the route
	 */
	public function getCurrentURL(array $segments = null, array $parameters = null, $query_string = '', $override_method = false, $canonical = false)
	{
		// Ensure the route is valid
		if (!$this->isValid())
		{
			throw (new vB_Exception_Router('A route URL was requested but the route is invalid'));
		}
		// Set any values specified
		if ($segments)
		{
			$this->setSegments($segments);
		}

		// Set new parameters if specified
		if ($parameters)
		{
			$this->setParameters($parameters);
		}

		if (!$canonical)
		{
			// Ensure the route path is fresh
			$this->assertRoutePath();
			$route_path = $this->_route_path;
		}
		else
		{
			$route_path = $this->buildRoutePath(true);
		}

		// Chop the route segment
		if (vB::$vbulletin->options['friendlyurl'] != vB_Router::METHOD_REWRITE)
		{
			$route_path = $route_path ? substr($route_path, strpos($route_path, '/')) : '';
		}

		// Return the appropriate route path
		if ((vB::$vbulletin->options['friendlyurl'] != vB_Router::METHOD_REWRITE) AND ($route_path == $this->_class_segment))
		{
			$url = trim(vB_Router::getBaseRoutingURL($this->_class_segment, false, $override_method), '/?');
		}
		else
		{
			// Return the URL
			$slash = ($route_path == $this->_class_segment) ? '/' : '';
			$url = trim(vB_Router::getBaseRoutingURL($this->_class_segment, true, $override_method) . ltrim($route_path, '/') . $slash, '?');
		}

		if (($sessionurl = vB::$vbulletin->session->vars['sessionurl']) OR $query_string)
		{
			$q = (false == strpos($url, '?')) ? '?' : '&';
			$url .= $q . ($sessionurl ? $sessionurl . ($query_string ? '&' . $query_string : '') : '') ;
		}

		//we get some trailing &'s. Let's get rid of them
		if (substr($url, - 1) == '&')
		{
			$url = substr($url, 0, strlen($url) - 1);
		}

		if (substr($url, -5) == '&')
		{
			$url = substr($url, 0, strlen($url) - 5);
		}

		return $url;
	}
Beispiel #2
0
 /**
  * Returns a representative URL of the current route state.
  * Optional segments and parameters may be passed to set the route state.
  *
  * @param array mixed $segments				- Assoc array of segment => value
  * @param array mixed $parameters			- Array of parameter values, in order
  * @param string $query_string				- Query string to append to the url
  * @param int $override_method				- Allows the Friendly URL method to be overridden
  * @param bool $canonical					- If true, don't encode for output
  * @return string							- The URL representing the route
  */
 public function getCurrentURL(array $segments = null, array $parameters = null, $query_string = '', $override_method = false, $canonical = false)
 {
     // Ensure the route is valid
     if (!$this->isValid()) {
         throw new vB_Exception_Router('A route URL was requested but the route is invalid');
     }
     // Set any values specified
     if ($segments) {
         $this->setSegments($segments);
     }
     // Set new parameters if specified
     if ($parameters) {
         $this->setParameters($parameters);
     }
     if (!$canonical) {
         // Ensure the route path is fresh
         $this->assertRoutePath();
         $route_path = $this->_route_path;
     } else {
         $route_path = $this->buildRoutePath(true);
     }
     // Chop the route segment
     if (vB::$vbulletin->options['friendlyurl'] != vB_Router::METHOD_REWRITE) {
         $route_path = $route_path ? substr($route_path, strpos($route_path, '/')) : '';
     }
     // Return the appropriate route path
     if (vB::$vbulletin->options['friendlyurl'] != vB_Router::METHOD_REWRITE and $route_path == $this->_class_segment) {
         $url = trim(vB_Router::getBaseRoutingURL($this->_class_segment, false, $override_method), '/?');
     } else {
         // Return the URL
         $slash = $route_path == $this->_class_segment ? '/' : '';
         $url = trim(vB_Router::getBaseRoutingURL($this->_class_segment, true, $override_method) . ltrim($route_path, '/') . $slash, '?');
     }
     //are we forcing an absolute path?
     if ($this->_force_absolute_path) {
         //the url should start with the bburl. If it doesn't, then prepend it.
         if (strtolower(substr($url, 0, 5)) != 'http:' and strtolower(substr($url, 0, 6)) != 'https:') {
             $url = vB::$vbulletin->options['bburl'] . '/' . $url;
         }
     }
     if ($sessionurl = vB::$vbulletin->session->vars['sessionurl'] or $query_string) {
         $q = false == strpos($url, '?') ? '?' : '&';
         $url .= $q . ($sessionurl ? $sessionurl . ($query_string ? $query_string : '') : $query_string);
     }
     //we get some trailing &'s. Let's get rid of them
     if (substr($url, -1) == '&') {
         $url = substr($url, 0, strlen($url) - 1);
     }
     if (substr($url, -5) == '&') {
         $url = substr($url, 0, strlen($url) - 5);
     }
     return $url;
 }
Beispiel #3
0
 /**
  * Returns a representative URL of the current route state.
  * Optional segments and parameters may be passed to set the route state.
  *
  * @param array mixed $segments				- Assoc array of segment => value
  * @param array mixed $parameters			- Array of parameter values, in order
  * @param string $query_string				- Query string to append to the url
  * @param int $override_method				- Allows the Friendly URL method to be overridden
  * @param bool $canonical					- If true, don't encode for output
  * @return string							- The URL representing the route
  */
 public function getCurrentURL(array $segments = null, array $parameters = null, $query_string = '', $override_method = false, $canonical = false)
 {
     // Ensure the route is valid
     if (!$this->isValid()) {
         throw new vB_Exception_Router('A route URL was requested but the route is invalid');
     }
     // Set any values specified
     if ($segments) {
         $this->setSegments($segments);
     }
     // Set new parameters if specified
     if ($parameters) {
         $this->setParameters($parameters);
     }
     if (!$canonical) {
         // Ensure the route path is fresh
         $this->assertRoutePath();
         $route_path = $this->_route_path;
     } else {
         $route_path = $this->buildRoutePath(true);
     }
     // Chop the route segment
     if (vB::$vbulletin->options['friendlyurl'] != vB_Router::METHOD_REWRITE) {
         $route_path = $route_path ? substr($route_path, strpos($route_path, '/')) : '';
     }
     // Return the appropriate route path
     if (vB::$vbulletin->options['friendlyurl'] != vB_Router::METHOD_REWRITE and $route_path == $this->_class_segment) {
         $url = trim(vB_Router::getBaseRoutingURL($this->_class_segment, false, $override_method), '/?');
     } else {
         // Return the URL
         $slash = $route_path == $this->_class_segment ? '/' : '';
         $url = trim(vB_Router::getBaseRoutingURL($this->_class_segment, true, $override_method) . ltrim($route_path, '/') . $slash, '?');
     }
     /* Disabling for now as urls are erroneously cached
     		// Add sessionurl and query string
     		// TODO: allow boolean true to get current query string.
     		if (($sessionurl = vB::$vbulletin->session->vars['sessionurl']) OR $query_string)
     		{
     			$q = (false == strpos('?', $url)) ? '?' : '';
     			$url .= $q . ($sessionurl ? $sessionurl . ($query_string ? '&' : '') : '') . trim($query_string, '&');
     		}
     		*/
     if ($sessionurl = vB::$vbulletin->session->vars['sessionurl'] or $query_string) {
         $q = false == strpos($url, '?') ? '?' : '&';
         $url .= $q . ($sessionurl ? $sessionurl . ($query_string ? '&' . $query_string : '') : '');
     }
     return $url;
 }