Class: Bs_Url
Source Location: /core/net/Bs_Url.class.php
Bs_Object
|
--Bs_Url
Url (and email) utility class.
Author(s):
Version:
- 4.3.$Revision: 1.3 $ $Date: 2003/10/29 17:48:41 $
Copyright:
|
|
Inherited Variables
|
Inherited Methods
|
Class Details
Class Methods
constructor Bs_Url [line 22]
method addQueryParam [line 725]
void addQueryParam(
string
$url, string
$key, string
$val, bool
$force)
|
|
Adds a key/value pair to the querystring of the given url. Caution: If you are not sure or if it's possible that the param already exists in the url, better use modifyQueryParam(). this method just adds it, doesn't check for existance. note: param $val is urlEncoded, so don't do it yourself. example: addQueryParam('http://www.domain.com/file.php?key=val', 'key2', 'val2'); don't try this at home! you cannot just add &key=val to the url. because your url might look like http://www.domain.com/file.php?x=y#anchor, go figure.
Tags:
Parameters:
method breadCrumb [line 784]
void breadCrumb(
[mixed
$url = NULL])
|
|
Tags:
method checkSyntax [line 35]
bool checkSyntax(
string
$url)
|
|
Checks whether the syntax of $url is valid or not. does not check if the url exists though. note: mailto:my@email.com is validated as wrong, while mailto://my@email.com would be accepted.
Tags:
Parameters:
method crossUrlDecode [line 956]
string crossUrlDecode(
mixed
$source)
|
|
cross (browser/configuration/encoding) url decode. note: %A and %D (\r\n) need to be written as %A[somechar], example %Ax %Dx because this functions expects (and removes) another char, just like in %20 for a space. if you're gonna correct this, please correct it in the code aswell which uses this method, namely Bs_TextType. --andrej got this from: igjav@cesga.es 16-May-2002 05:48 http://www.php.net/manual/en/function.urldecode.php This seems to decode correctly between most browsers and charater coding configurations. Specially indicated for direct parsing of URL as it comes on environment variables
method enableUrl [line 615]
string enableUrl(
string
$str)
|
|
Makes the urls and emails in a string clickable. Example: $string = "I was a little yellow@duck.com who had a homepage at <http://me.duck.com>, http://www.me.duck.com or www.duck.com with ftp://file.duck.com. I'm a developer in Norway(www.norge.no), and works for DB Medialab, http://db.no, aka (www.db.no) [www.db.no], <www.duck.com> or {www.duck.com}. We are developing these sites http://www.dagbladet.no/nyheter/, http://www.dagbladet.no/nyheter/2001/01/29/239330.html, and http://start.no."; echo $enabled_urls_string = enableUrl($string); will print out: I was a little <a href="mailto:yellow@duck.com">yellow@duck.com</a> who had a homepage at a href="http://me.duck.com" target="_blank">http://me.duck.com</a>>, <a href="http://www.me.duck.com" target="_blank">http://www.me.duck.com</a> or <a href="http://www.duck.com" target="_blank">www.duck.com</a> with <a href="ftp://file.duck.com." target="_blank">ftp://file.duck.com.</a> I'm a developer in Norway(<a href="http://www.norge.no" target="_blank">www.norge.no</a>), and works for DB Medialab, <a href="http://db.no" target="_blank">http://db.no</a>, aka (<a href="http://www.db.no" target="_blank">www.db.no</a>) [<a href="http://www.db.no" target="_blank">www.db.no</a>], <www.duck.com> or {www.duck.com}. We are developing these sites <a href="http://www.dagbladet.no/nyheter/" target="_blank">http://www.dagbladet.no/nyheter/</a>, <a href="http://www.dagbladet.no/nyheter/2001/01/29/239330.html" target="_blank">http://www.dagbladet.no/nyheter/2001/01/29/239330.html</a>, and <a href="http://start.no." target="_blank">http://start.no.</a> CAUTION: as you can see in the example above, a few things don't work (properly): - if a url is at the end of a sentence (which ends with a dot) that dot is added to the url.
there are cases where it doesn't matter, but -> fix it.
- <www.duck.com> is not url-enabled
- {www.duck.com} is not url-enabled
Written by Fredrik Kristiansen (russlndr at online.no) and Albrecht Guenther (ag at phprojekt.de).
Tags:
Parameters:
method explodeIp [line 95]
array explodeIp(
string
$ip, [bool
$zerofill = FALSE])
|
|
explodes the 4 int-parts of an ip address into a zerobased array. eg '127.0.0.1' => array('127', '000', '000', '001')
Tags:
Parameters:
method getDirectory4url [line 500]
string getDirectory4url(
string
$url)
|
|
Return the directory part of an url. examples: 'http://blue-shoes.com:81/forms/form.php?lang=fr' => '/forms/' 'http://blue-shoes.com:81/forms/' => '/forms/' 'http://blue-shoes.com:81/file.html' => '/' 'http://blue-shoes.com:81/unknown' => '/' <= 'unknown' may be a directory... but we have to treat it as a file. 'http://blue-shoes.com/' => '/' 'http://blue-shoes.com' => '/' <= special case.
Tags:
Parameters:
method getDomain4url [line 465]
string getDomain4url(
string
$url, [int
$num = 2])
|
|
Return the domain part of an url. example: $url = 'http://some.really.long.domain.com/dir/file.html'; $topLevelDomain = getDomain($url, 1); // 'com' $secondLevelDomain = getDomain($url, 2); // 'domain.com' $thirdLevelDomain = getDomain($url, 3); // 'long.domain.com' $fullDomain = getDomain($url, -1); // 'some.really.long.domain.com'
Tags:
Parameters:
method getFile4url [line 534]
string getFile4url(
string
$url)
|
|
Return the file part of an url. examples: 'http://blue-shoes.com:81/forms/form.php?lang=fr' => 'form.php' 'http://blue-shoes.com:81/forms/' => '' 'http://blue-shoes.com:81/file.html' => 'file.html' 'http://blue-shoes.com:81/unknown' => 'unknown' <= 'unknown' may be a directory... but we have to treat it as a file. 'http://blue-shoes.com/' => '' 'http://blue-shoes.com' => ''
Tags:
Parameters:
method getLastDir [line 1011]
mixed getLastDir(
string
$url)
|
|
returns the last dir of an url. examples for last dir: /some/path/file/ => 'file' /some/path/something => array('path', 'something) //not sure if something is a file or a dir. /some/path/something.html => 'path'
Tags:
Parameters:
method getUrlChunk [line 245]
string getUrlChunk(
string
$junk, [mixed
$url = NULL])
|
|
returns the desired parts of the given url as a string. name definitions: even the W3C seems to have problems to name the parts of an url. what's an URL, URI, URN etc. so we came up with these names, partly from php, wherever the names came from, please use them as they are described here. scheme://user:pass@host:port/path?query#fragment example: url https://bill:gates@order.blueshoes.org:81/forms/form.php?lang=fr&sid=456456#address [---]scheme [-------host-------] []port [------query-----] [-----]fragment [--]user [---domain---] [-----]directory [---]pass [-file-] [-----path----] [--absToFragment-------------------------------------------------------------------] [--absToQuery--------------------------------------------------------------] [--absToPath--------------------------------------------] [--absToDirectory-------------------------------] [--absToPort------------------------------] [--relToFragment-------------------------] [--relToQuery--------------------] [--relToPath--] [-----] relToDirectory param $junk: this works similar to php's date() function. you pass a string with letters. +----------------+--------+-------------------------+----------------------------------------------------------------------------------------+ | PART | LETTER | EXAMPLE | RETURNED SEPARATOR CHARS | +----------------+--------+-------------------------+----------------------------------------------------------------------------------------+ | schme | s | http | :// (if user, host or domain follows) | | user | u | bill | -none- | | pass | P | gates | : (if user was before) | | host | h | order.blue-shoes.com | @ (if user or pass was before) | | domain | d | blue-shoes.com | -none- | | port | o | 81 | : (if host or domain was before) | | port | O (oh) | 81 | same as 'o' but only returned if != 80 (default port for http) | | path | p | /forms/form.php | -none- | | directory | i | /forms/ | -none- | | file | f | form.php | -none- | | query | q | lang=fr&sid=456456 | ? (if host, domain, port, path, directory, file or 3,4,5,8, or 9 was before) | | fragment | F | address | # (if host, domain, port, path, directory, file, query or 2,3,4,5,7,8 or 9 was before) | | absToFragment | 1 | https://bill:gates@order.blue-shoes.com:81/forms/form.php?lang=fr&sid=456456#address | | absToQuery | 2 | https://bill:gates@order.blue-shoes.com:81/forms/form.php?lang=fr&sid=456456 | | absToPath | 3 | https://bill:gates@order.blue-shoes.com:81/forms/form.php | | absToDirectory | 4 | https://bill:gates@order.blue-shoes.com:81/forms/ | | absToPort | 5 | https://bill:gates@order.blue-shoes.com:81 | | relToFragment | 6 | /forms/form.php?lang=fr&sid=456456#address | | relToQuery | 7 | /forms/form.php?lang=fr&sid=456456 | | relToPath | 8 | /forms/form.php | | relToDirectory | 9 | /forms/ | +----------------+--------+-------------------------+----------------------------------------------------------------------------------------+ note I: the parts are returned including "separator chars" even though the parts above are described to be without them. eg if you want the port, you don't get '81' you get ':81' here. if you are not happy with that, use $this->parseUrlExtended() and smile. note II: if a browser requests a website using a #fragment part, the fragment won't be submitted along with the address to the server. this information will be kept by the client browser to jump to the right place once the page has been rendered. examples: getUrlChunk('suPhopqF', 'https://bill:gates@order.blue-shoes.com:81/forms/form.php?lang=fr&sid=456456#address'); returns 'https://bill:gates@order.blue-shoes.com:81/forms/form.php?lang=fr&sid=456456#address' getUrlChunk('1', 'https://bill:gates@order.blue-shoes.com:81/forms/form.php?lang=fr&sid=456456#address'); returns 'https://bill:gates@order.blue-shoes.com:81/forms/form.php?lang=fr&sid=456456#address' getUrlChunk('suPhopqF', 'https://order.blue-shoes.com/forms/form.php'); returns 'https://order.blue-shoes.com/forms/form.php' maybe also check the ecg tests.
Tags:
Parameters:
method getUrlJunk [line 425]
void getUrlJunk(
mixed
$junk, [mixed
$url = NULL])
|
|
kept for backward compatibility, renamed. chunk instead of junk. :-)
method glueUrl [line 436]
string glueUrl(
array
$url)
|
|
opposite function of php's parse_url() and $this->parseUrlExtended().
Tags:
Parameters:
method hashArrayToHiddenFields [line 685]
void hashArrayToHiddenFields(
mixed
&$hashArray, [mixed
$prefix = ''])
|
|
Tags:
method hashArrayToQueryString [line 657]
string hashArrayToQueryString(
array
&$hashArray, [string
$prefix = ''], [string
$firstSeparator = '&'])
|
|
Takes a hash array and returns a query string. in other words make arrays persistant for clickthroughs. this function is rated INTELLIGENT :) example I: $hash['in']['a']['color'] = 'green'; $hash['in']['a']['message'] = 'hello world'; echo hashArrayToQueryString($hash) prints out "&in[a][color]=green&in[a][message]=hello+world" example II: $hash['in']['a']['color'] = 'green'; $hash['in']['a']['message'] = 'hello world'; echo hashArrayToQueryString($hash, 'aPoorMansNamespace', '?') prints out '?aPoorMansNamespace[in][a][color]=green&aPoorMansNamespace[in][a][message]=hello+world' if you pass a zerobased array that'll work also: $arr = array('foo', 'bar') => '&0=foo&1=bar' it starts with a "&" and not a "?" because there might be other params already set for your url. if not, you can trick it by doing someting like domain.com/myfile.php?dummy=&yourParamsHere have no fear, even ubs.com/e-banking uses a querystring var called dummy :) (or change the 3rd param).
Tags:
Parameters:
method ipToNumber [line 71]
integer ipToNumber(
string
$ip)
|
|
Convert an ip address to its numerical value eg '216.32.74.53' => 3625994805 NOTE: Because PHP's integer type is signed, and many IP addresses will result in negative integers!!!! You need to use the "%u" formatter of sprintf() or printf() to get the string representation of the unsigned IP address. e.g. sprintf("%u", ip2long($ip))
Tags:
Parameters:
method modifyQueryParam [line 763]
void modifyQueryParam(
string
$url, string
$key, string
$val, [bool
$force = TRUE])
|
|
Changes the value of a querystring param in an url. note I: param $key is case sensitive. note II: param $val is urlEncoded, so don't do it yourself. example: modifyQueryParam('http://www.domain.com/file.php?key=val', 'key', 'newval');
Tags:
Parameters:
method numberToIp [line 82]
string numberToIp(
integer
$num)
|
|
Convert a numerical url to an ip address eg 3625994805 => '216.32.74.53'
Tags:
Parameters:
method parseUrlExtended [line 150]
array parseUrlExtended(
string
$url)
|
|
Parse a URL and return its components. this method makes use of php's parse_url() and extends it. scheme://user:pass@host:port/path?query#fragment example: url https://bill:gates@order.blue-shoes.com:81/forms/form.php?lang=fr&sid=456456#address the returned associative array contains these parts (if present, so not all may be set!): +-------------+-----------------------+---------------------------------------------------------+ | PART | EXAMPLE | COMMENTS | +-------------+-----------------------+---------------------------------------------------------+ | scheme | https | http https ftp (mailto) gopher news telnet | | host | order.blue-shoes.com | | | port | 81 | default is 80. used even if it's 80 (if it's there). | | user | bill | | | pass | gates | | | path | /forms/form.php | starts with a slash | | query | lang=fr&sid=456456 | the ? is missing but the &'s aren't | | fragment | address | | | + domain | blue-shoes.com | no dot after the top level domain (.com.) <= extended | | + directory | /forms/ | starts and ends with a slash <= extended | | + file | form.php | no slash at the beginning <= extended | | + extension | php | since bs4.3, not converted to lowercase. <= extended | +-------------+-----------------------+---------------------------------------------------------+
Tags:
Parameters:
method realUrl [line 559]
string realUrl(
string
$url)
|
|
like php's realpath() but for urls. does not make an existance check.
Tags:
Parameters:
method removeQueryParam [line 742]
method similar [line 845]
bool similar(
string
$urlOne, string
$urlTwo)
|
|
calculates the similarity of two given url's. the url's have to be given without the http://www.domain.com part, just give something like /some/dir/and/file.html. if the 2 url's are not on the same host, this makes not much sense anyway. examples (check the ecg): RESULT URL ONE URL TWO true '/' '' false '/this/is/url/one/' '/la/lo/li/lala/l/' true '/url/with/same/end/directory/' '/another/thing/lala/lolo/directory' true '/url/with/same/end/directory/' '/another/thing/lala/lolo/directory/adf' true '/url/with/same/end/directory/' '/another/thing/lala/lolo/directory/adf.html' false '/url/with/same/end/directory/' '/another/thing/lala/lolo/directory.html' true '/url/with/typo/' 'url/wit/typpo'
Tags:
Parameters:
method validate [line 51]
bool validate(
string
$url)
|
|
validate an url. before tryting to connect to that url, we'll check the syntax using $this->checkSyntax(). note: of course it's possible that the server from $url is down at the moment...
Tags:
Parameters:
method _removeFile [line 1050]
void _removeFile(
mixed
$url)
|
|
|
|