Changeset - 0e5a369b205f
[Not reviewed]
default
0 1 0
Nathan Brink (binki) - 13 years ago 2012-11-28 00:10:27
ohnobinki@ohnopublishing.net
Avoid creating links with extraneous forward-slashes in them, so that people end up at http://slatepermutate.org/ instead of http://slatepermutate.org//.
1 file changed with 3 insertions and 3 deletions:
0 comments (0 inline, 0 general)
inc/class.page.php
Show inline comments
 
@@ -711,49 +711,49 @@ class page
 
      {
 
	if (isset($_SERVER['SERVER_NAME']))
 
	  $host = $_SERVER['SERVER_NAME'];
 
	if (isset($_SERvER['HTTP_HOST']))
 
	  $host = $_SERVER['HTTP_HOST'];
 
      }
 

	
 
    if (empty($base_uri))
 
      if (strlen($host))
 
	{
 
	  $proto = 'http';
 
	  $port = NULL;
 
	  if (isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] != 80)
 
	    {
 
	      if ($_SERVER['SERVER_PORT'] == 443 || !empty($_SERVER['HTTPS']))
 
		$proto .= 's';
 
	      if ($_SERVER['SERVER_PORT'] != 433)
 
		$port = $_SERVER['SERVER_PORT'];
 
	    }
 
	  
 
	  $base_uri = $proto . '://' . $host;
 
	  if ($port !== NULL)
 
	    $base_uri .= ':' . $port;
 
	  list($base_request_uri) = explode('?', $_SERVER['REQUEST_URI'], 2);
 
	  $base_uri .= substr($base_request_uri, 0, strrpos($base_request_uri, '/')) . '/';
 
	  $base_uri .= rtrim(substr($base_request_uri, 0, strrpos($base_request_uri, '/')), '/') . '/';
 
	}
 

	
 
    if (empty($base_uri) && empty($uri))
 
      return './';
 

	
 
    return $base_uri . $uri;
 
  }
 

	
 
  /**
 
   * \brief
 
   *   Resolve an SSL address for a static asset.
 
   *
 
   * This is pretty much a hack in support of another hack. I need to
 
   * provide some assets over SSL; if the local server doesn’t support
 
   * that properly (such as by not having a properly signed SSL
 
   * certificate), a web-storage backend can be used instead. This can
 
   * only be used with static content.
 
   *
 
   * \param $uri
 
   *   The path to a static file which needs to be served over SSL.
 
   */
 
  public static function uri_resolve_sslasset($uri, $type)
 
  {
 
    global $s3_bucket, $s3_accesskey, $s3_secretkey;
 
@@ -915,47 +915,47 @@ class page
 
      return $path . "/";
 
    }
 
    else {
 
      return $path;
 
    }
 
  }
 

	
 
  /**
 
   * \brief
 
   *   Generate a URL to a given schedule.
 
   *
 
   * \return
 
   *   The URL used to access the schedule. You must call
 
   *   htmlentities() on this string if it is to be inserted into an
 
   *   XHTML document.
 
   */
 
  public function gen_share_url($id)
 
  {
 
    global $clean_urls, $short_url_base;
 

	
 
    if ($clean_urls && isset($short_url_base)) {
 
      return $this->add_trailing_slash($short_url_base) . $id;
 
    }
 
    elseif ($clean_urls) {
 
      return 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['REQUEST_URI']) . '/' . $id;
 
      return 'http://' . $_SERVER['HTTP_HOST'] . $this->add_trailing_slash(dirname($_SERVER['REQUEST_URI'])) . '' . $id;
 
    }
 
    else {
 
      return 'http://' . $_SERVER['HTTP_HOST']  . dirname($_SERVER['REQUEST_URI']) . '/process.php?s=' . $id;
 
      return 'http://' . $_SERVER['HTTP_HOST']  . $this->add_trailing_slash(dirname($_SERVER['REQUEST_URI'])) . 'process.php?s=' . $id;
 
    }
 
  }
 

	
 
  /**
 
   * \brief
 
   *   Generate special code to close a self-closing XHTML/HTML
 
   *   element.
 
   *
 
   * \return
 
   *   A string containing the correct self-closing chars. For
 
   *   example, this would be ' /' for XHTML.
 
   */
 
  public function element_self_close()
 
  {
 
    if ($this->xhtml)
 
      return ' /';
 
    return '';
 
  }
 
}
0 comments (0 inline, 0 general)