Skip to content

Commit

Permalink
Homepage|Url: Fixed Url parsing and added setScheme() and setHost() m…
Browse files Browse the repository at this point in the history
…ethods
  • Loading branch information
danij-deng committed Jun 15, 2012
1 parent 7045d65 commit 16cba8f
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 4 deletions.
37 changes: 34 additions & 3 deletions web/classes/url.class.php
Expand Up @@ -65,7 +65,7 @@ public function __construct($str=NULL)

private function parse($str)
{
$u = parse_url($str);
$u = parse_url(trim($str));

if(isset($u['scheme']))
$this->scheme = $u['scheme'];
Expand Down Expand Up @@ -106,6 +106,37 @@ private function parse($str)
$this->args = $a;
}

public function setScheme($scheme='')
{
if(!strcasecmp(gettype($scheme), 'string') && strlen($scheme))
{
$this->scheme = $scheme;
}
else
{
unset($this->scheme);
}
return $this;
}

public function &scheme()
{
return $this->scheme;
}

public function setHost($host='')
{
if(!strcasecmp(gettype($host), 'string') && strlen($host))
{
$this->host = $host;
}
else
{
unset($this->host);
}
return $this;
}

public function &host()
{
return $this->host;
Expand All @@ -126,7 +157,7 @@ public function &args()
*
* [scheme]://[user]:[pass]@[host]/[path]?[query]#[fragment]
*/
public function toString($sep, $encode=true)
public function toString($sep='&', $encode=true)
{
$str = '';
if(isset($this->scheme))
Expand All @@ -150,7 +181,7 @@ public function toString($sep, $encode=true)
{
$str .= $this->path;

if(isset($this->args))
if(isset($this->args) && count($this->args))
{
if($encode)
{
Expand Down
12 changes: 11 additions & 1 deletion web/includes/utilities.inc.php
Expand Up @@ -23,6 +23,8 @@
* @author Copyright &copy; 2009-2012 Daniel Swanson <danij@dengine.net>
*/

require_once(DIR_CLASSES.'/url.class.php');

includeGuard('Utils');

function checkImagePath($path, $formats)
Expand Down Expand Up @@ -230,7 +232,15 @@ function json_encode_clean(&$array, $flags=0, $indent_level=0)

function generateHyperlinkHTML($uri, $maxLength=40, $cssClass=NULL)
{
$uri = strval($uri);
if($uri instanceof Url)
{
$uri = $uri->toString();
}
else
{
$uri = strval($uri);
}

$maxLength = (integer)$maxLength;
if($maxLength < 0) $maxLength = 0;
if(!is_null($cssClass))
Expand Down

0 comments on commit 16cba8f

Please sign in to comment.