BlueShoes Application Framework made with PHP http://www.blueshoes.org/


Packageindex Classtrees Modulegroups Elementlist Report XML Files

File: C:/usr/local/lib/php/blueshoes-4.2/core/net/Bs_Url.class.php
BlueShoes Application Framework - net

Bs_Url

Bs_Object
   |
  +-- Bs_Url

Url (and email) utility class.

 

private class Bs_Url extends Bs_Object

Url (and email) utility class.
dependencies: none

Authors
Version4.0.$id$
Copyrightblueshoes.org

 

Methods inherited from Bs_Object

isex, isexception, tostring, tohtml, persist, unpersist, bs_object, bbsetoutput, bbawake, bbisawake, bbxmsg, bbxfunctionstart, bbxfunctionend, bbxecho, bbxvar, bbxvardump, bbforcetrace, bbbufferstart, bbbufferget, bbbufferendflush, bbbufferendclean

Public Method Summary

array

getPossibleDomains4url(string $url)

Returns an array with all possible ways of writing that domain name.
array

parseUrlExtended(string $url)

Parse a URL and return its components.
string

getUrlJunk(string $junk, [ mixed $url ])

returns the desired parts of the given url as a string.
string

glueUrl(array $url)

opposite function of php's parse_url() and $this->parseUrlExtended().
string

getDomain4url(string $url, [ integer $num ])

Return the domain part of an url.
string

getDirectory4url(string $url)

Return the directory part of an url.
string

getFile4url(string $url)

Return the file part of an url.
string

enableUrl(string $str)

Makes the urls and emails in a string clickable.
string

hashArrayToQueryString(array &$hashArray, [ string $prefix, string $firstSeparator ])

Takes a hash array and returns a query string.
void

addQueryParam(string $url)

Adds a key/value pair to the querystring of the given url.
void

modifyQueryParam(string $url, string $key, string $val, [ string $force ])

Changes the value of a querystring param in an url.
string

crossUrlDecode( $source)

cross (browser/configuration/encoding) url decode.
mixed

getLastDir(string $url)

returns the last dir of an url.
void

Bs_Url()

Warning: documentation is missing.

Private Method Summary

bool

checkSyntax(string $url)

Checks whether the syntax of $url is valid or not.
bool

validate(string $url)

validate an url.
double

ipToNumber(string $ip)

Convert an ip address to its numerical value eg '216.32.74.53' => 3625994805
string

numberToIp(double $num)

Convert a numerical url to an ip address eg 3625994805 => '216.32.74.53'
array

explodeIp(string $ip, [ string $zerofill ])

explodes the 4 int-parts of an ip address into a zerobased array.
void

hashArrayToHiddenFields( &$hashArray, string $prefix)

void

removeQueryParam()

void

breadCrumb(string $url)

bool

similar(string $urlOne, string $urlTwo)

calculates the similarity of two given url's.
void

_removeFile( $url)

[NOinnerNO] private helper function.
void

validateEmail( $email)

Warning: documentation is missing.
void

validateURL( $url)

Warning: documentation is missing.
void

convertURLS( $text)

Warning: documentation is missing.
void

convertMail( $text)

Warning: documentation is missing.
void

convertAllLinks( $text)

Warning: documentation is missing.

Private Constant Summary

BS_URL_VERSION >>4.0.$x$<< Warning: documentation is missing.

Public Method Details

getPossibleDomains4url

public array getPossibleDomains4url( string $url )

  Returns an array with all possible ways of writing that domain name.
example:www.blueshoes.org can be written as:http://www.blueshoes.orghttp://www.blueshoes.org/http://blueshoes.orghttp://blueshoes.org/http://111.111.111.111http://111.111.111.111/

Parameter
string $url
Returns array


parseUrlExtended

public 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#fragmentexample: url https://bill:gates@order.blue-shoes.com:81/forms/form.php?lang=fr&sid=456456#addressthe returned associative array contains these parts (if present):+-------------+-----------------------+---------------------------------------------------------+| 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 |+-------------+-----------------------+---------------------------------------------------------+

Parameter
string $url
Returns array

(see description)

Throws bool FALSE

getUrlJunk

public string getUrlJunk( string $junk, [ mixed $url ] )

  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 themas they are described here.scheme://user:pass@host:port/path?query#fragmentexample: url https://bill:gates@order.blue-shoes.com: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--][-----] relToDirectoryparam $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 describedto be without them. eg if you want the port, you don't get '81' you get ':81' here. if youare 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 submittedalong with the address to the server. this information will be kept by the client browserto jump to the right place once the page has been rendered.examples:getUrlJunk('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'getUrlJunk('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'getUrlJunk('suPhopqF', 'https://order.blue-shoes.com/forms/form.php');returns 'https://order.blue-shoes.com/forms/form.php'maybe also check the ecg tests.

Parameter
string $junk
(see above)
mixed $url = >>NULL<<
(an url as a string, a hash that you got from $this->parseUrlExtended(), null if you want to use the current user-requested url.)
Returns string

Throws bool FALSE

glueUrl

public string glueUrl( array $url )

  opposite function of php's parse_url() and $this->parseUrlExtended().

Parameter
array $url
Returns string

the glued url
@throw bool FALSE


getDomain4url

public string getDomain4url( string $url, [ integer $num ] )

  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'

Parameter
string $url
integer $num = >>2<<
number of domains (parts) to return. default is 2.
Returns string

the domain
@throw bool FALSE


getDirectory4url

public 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.

Parameter
string $url
Returns string

the directory
@throw bool FALSE


getFile4url

public 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' => ''

Parameter
string $url
Returns string

the file
@throw bool FALSE


enableUrl

public 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), andworks 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>), andworks 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-enabledWritten by Fredrik Kristiansen (russlndr at online.no) and Albrecht Guenther (ag at phprojekt.de).

Parameter
string $str
Returns string


hashArrayToQueryString

public 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=&yourParamsHerehave no fear, even ubs.com/e-banking uses a querystring var called dummy :) (or change the 3rd param).

Parameter
array &$hashArray
hashArray of the values
string $prefix = >>''<<
see example
string $firstSeparator = >>'&'<<
default is '&' may also be '?' or ''.
Returns string

returns a string that can be attached to the querystring. returns an empty string '' if param $hashArray is not an array.


addQueryParam

public void addQueryParam( string $url )

  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 mightlook like http://www.domain.com/file.php?x=y#anchor, go figure.

Parameter
string $url
Returns void


modifyQueryParam

public void modifyQueryParam( string $url, string $key, string $val, [ string $force ] )

  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');

Parameter
string $url
string $key
string $val
string $force = >>TRUE<<
if the key does not exist in the url, should it be added? default=TRUE.
@throw bool FALSE if $url is not a valid url.
Returns void


crossUrlDecode

public string crossUrlDecode( $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 codeaswell which uses this method, namely Bs_TextType. --andrejgot this from:igjav@cesga.es 16-May-2002 05:48http://www.php.net/manual/en/function.urldecode.phpThis seems to decode correctly between most browsers and charater codingconfigurations. Specially indicated for direct parsing of URL as it comes onenvironment variables

Parameter
$source
Warning: documentation is missing.
Returns string


getLastDir

public mixed getLastDir( string $url )

  returns the last dir of an url.
i'm not that proud of that code :/examples for last dir:/some/path/file/ => 'file'/some/path/something => array('path', 'file) not sure if something is a file or a dir./some/path/something.html => 'path'

Parameter
string $url
(without the http://www.domain.com part)
Returns mixed

a string or a vector with 2 strings

Throws false

Bs_Url

public void Bs_Url( )

 

Warning: documentation is missing.

Returns void


Private Method Details

checkSyntax

private 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.

Parameter
string $url
Returns bool

true if it's a valid url, false if not.


validate

private 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 toment...

Parameter
string $url
Returns bool

true if url is valid and it exists, false if not.


ipToNumber

private double ipToNumber( string $ip )

  Convert an ip address to its numerical value eg '216.32.74.53' => 3625994805
note: ie6beta doesn't support such urls.

Parameter
string $ip
an ip address
Returns double

the numerical value
@throw bool FALSE on an invalid ip address.

Copyright rick lee-morlang rick@serveyor.com (thanx)

numberToIp

private string numberToIp( double $num )

  Convert a numerical url to an ip address eg 3625994805 => '216.32.74.53'

Parameter
double $num
the number
Returns string

the ip address
@throw bool FALSE if $number is not numeric.

Copyright rick lee-morlang rick@serveyor.com (thanx)

explodeIp

private array explodeIp( string $ip, [ string $zerofill ] )

  explodes the 4 int-parts of an ip address into a zerobased array.
eg '127.0.0.1' => array('127', '000', '000', '001')

Parameter
string $ip
an ip address eg '127.0.0.1'
string $zerofill = >>FALSE<<
whether to zero fill numbers or not, eg 127.0.0.1 => 127.000.000.001. default is FALSE.
Returns array

a zerobased string-array with 4 elements. (not int!! because this would convert 001 -> 1 etc.)
@throw bool FALSE on an invalid ip address.


hashArrayToHiddenFields

private void hashArrayToHiddenFields( &$hashArray, string $prefix )

 

Parameter
&$hashArray
Warning: documentation is missing.
string $prefix
Warning: documentation is missing.
Returns void


removeQueryParam

private void removeQueryParam( )

 

Returns void


breadCrumb

private void breadCrumb( string $url )

 

Parameter
string $url
Warning: documentation is missing.
Returns void

Copyright Jim Fletcher jim@websitecode.com path.php v1.2 28/01/2001 http://www.zend.com/codex.php?id=362&single=1

similar

private 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, justgive something like /some/dir/and/file.html. if the 2 url's are not onthe same host, this makes not much sense anyway.examples (check the ecg):RESULT URL ONE URL TWOtrue '/' ''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'

Parameter
string $urlOne
string $urlTwo
Returns bool

TRUE if there is some appropriate similarity, FALSE if not.


_removeFile

private void _removeFile( $url )

  [NOinnerNO] private helper function.
returns a vector with 2 elements. element 1 being the url without any possiblefile ending (everything to the last slash (excluding). element 2 being thefile ending IF it could be a directory, eg in '/some/thing' because it has no dot.it could be meant '/some/thing/' or it could be a read file.if there is no leftover url to work on, or there is no file part that could bea directory, then this part of the returned vector is set to NULL.

Parameter
$url
Warning: documentation is missing.
Returns void


validateEmail

private void validateEmail( $email )

 

Warning: documentation is missing.

Parameter
$email
Warning: documentation is missing.
Returns void


validateURL

private void validateURL( $url )

 

Warning: documentation is missing.

Parameter
$url
Warning: documentation is missing.
Returns void


convertURLS

private void convertURLS( $text )

 

Warning: documentation is missing.

Parameter
$text
Warning: documentation is missing.
Returns void


convertMail

private void convertMail( $text )

 

Warning: documentation is missing.

Parameter
$text
Warning: documentation is missing.
Returns void


convertAllLinks

private void convertAllLinks( $text )

 

Warning: documentation is missing.

Parameter
$text
Warning: documentation is missing.
Returns void


Private Constant Details

BS_URL_VERSION

define( BS_URL_VERSION, >>4.0.$x$<< )
Case: default: case sensitive




Packageindex Classtrees Modulegroups Elementlist Report XML Files
PHPDoc 1.0beta