.

Url Class Reference
[Lib]

Wrapper around URL handling and processing. More...

Inheritance diagram for Url:
Referer

List of all members.

Public Member Functions

  __construct ($url= '', $fallback_host= '')
  Constructor.
  __sleep ()
  Serialize in a freindly format.
  __toString ()
  Prints this query as a string.
  __wakeup ()
  build ($mode=Url::ABSOLUTE, $encoding=Url::ENCODE_PARAMS)
  Returns this query as a string.
  clean ()
  Remove all non-ASCII chars from the path (not the query!).
  clear_query ()
  Remove query parameters.
  equals ($other, $mode=self::EQUALS_FULL)
  Compare this URL to an other.
  get_fragment ()
  Return fragment (stuff after "#").
  get_host ()
  Return host (e.g.
  get_path ()
  Return the path only.
  get_port ()
  get_query ($encode=Url::ENCODE_PARAMS)
  Return full query.
  get_query_param ($name, $default=false, $encode=Url::NO_ENCODE_PARAMS)
  Return query paramter.
  get_query_params ($encode=Url::NO_ENCODE_PARAMS)
  Return query paramters as associative array.
  get_scheme ()
  Return scheme (http, ftp etc).
  is_ancestor_of ($path_to_check)
  Returns true, if this URL is identical or below the given $path_to_check.
  is_empty ()
  Returns true if the URL is empty (that is no host is specified).
  is_same_as ($path_to_check)
  Returns true, if this URL is identical the given $path_to_check.
  is_valid ()
  Returns true if this is a valid URL.
  output ()
  Prints this query as a string.
  parse_host ()
  Returns the host split into an array.
  redirect ($permanent=self::TEMPORARY)
  Redirect to this Url.
  replace_query_parameter ($name, $value)
  Replaces or adds parameter to query string.
  replace_query_parameters ($arr_params)
  Replace an array of paramters at once.
  set_fragment ($fragment)
  Set fragment (stuff after "#").
  set_host ($host)
  Set Host.
  set_host_array ($arr_host)
  Set host data from array.
  set_path ($path)
  Set the path for this url.
  set_port ($port)
  set_query ($query)
  Set query as string.
  set_scheme ($scheme)
  Set scheme (http, ftp etc).

Static Public Member Functions

static  create ($url)
  Create new Url instance.
static  create_with_fallback_host ($url, $host)
  Create new Url instance.
static  current ()
  Static returns the current URL.
static  validate_current ()

Public Attributes

const  ABSOLUTE = 'absolute'
const  ENCODE_PARAMS = 'encode'
const  EQUALS_FULL = 0
  When comparing URLs, ignore only fragment.
const  EQUALS_IGNORE_QUERY = 1
  When comparing URLs, ignore query (and fragment).
const  NO_ENCODE_PARAMS = 'encodenot'
const  PERMANENT = true
const  RELATIVE = 'relative'
const  TEMPORARY = false

Protected Member Functions

  callback_urlencode (&$value, $key=false)
  Callback to urlencode values - does not actually walk.
  clean_path_for_comparison ($path_to_check)
  do_parse_url ($url, $fallback_host= '')
  This wraps PHP parse_url.
  parse ($url, $fallback_host= '')
  Parse URL into Urls.
  parse_query ($query)
  Split a query into items and return them as associative array.
  query_reduce (&$current, $sep, $key, $value)
  Reduces set of params to query string (a=b&c=d.

Detailed Description

Wrapper around URL handling and processing.

Author:
Gerd Riesselmann

Definition at line 8 of file url.cls.php.


Constructor & Destructor Documentation

Url::__construct ( url = '',
fallback_host = ''  
)

Constructor.

Parameters:
string  The URL to wrap around

Definition at line 35 of file url.cls.php.

00035                                                                     {
00036                 $this->parse($url, $fallback_host);
00037         }

Member Function Documentation

Url::__sleep (  ) 

Serialize in a freindly format.

Returns:
unknown

Definition at line 149 of file url.cls.php.

00149                                   {
00150                 $this->url = $this->build();
00151                 return array('url');
00152         }
Url::__toString (  ) 

Prints this query as a string.

Returns:
void
Exceptions:
Throws  an exception if hostname is empty

Definition at line 596 of file url.cls.php.

00596                                      {
00597                 return $this->build();
00598         }                       
Url::__wakeup (  ) 

Definition at line 154 of file url.cls.php.

00154                                    {
00155                 $this->parse($this->url); 
00156         }
Url::build ( mode = Url::ABSOLUTE,
encoding = Url::ENCODE_PARAMS  
)

Returns this query as a string.

The URL is not ready for outputting it on an HTML page, it must be HTMLescaped before! It is however URL escaped.

Returns:
string This Url as a string.
Exceptions:
Throws  an exception if hostname is empty

Reimplemented in Referer.

Definition at line 544 of file url.cls.php.

00544                                                                                  {
00545                 $out = '';
00546                 
00547                 if ($mode == Url::ABSOLUTE) {
00548                         $out .= $this->get_scheme();
00549                         $out .= '://';
00550                 
00551                         $host = $this->get_host();
00552                         if (empty($host)) {
00553                                 throw new Exception('Url: No Host specified!');
00554                         }
00555                         $out .= $host;
00556                         $port = $this->get_port();
00557                         if ($port) {
00558                                 $out .= ':' . $port; 
00559                         }
00560                 }
00561                 
00562                 $out .= '/';
00563                 $out .= $this->get_path();
00564                                  
00565                 $query = $this->get_query($encoding);
00566                 if (!empty($query)) {
00567                         $out .= '?' . $query;
00568                 }
00569                 
00570                 $anchor = $this->get_fragment();
00571                 if (!empty($anchor)) {
00572                         $out .= '#' . $anchor;
00573                 }
00574                 
00575                 return $out;
00576         }
Url::callback_urlencode ( &$  value,
key = false  
) [protected]

Callback to urlencode values - does not actually walk.

Definition at line 333 of file url.cls.php.

00333                                                                      {
00334                 $value = urlencode($value);
00335         }
Url::clean (  ) 

Remove all non-ASCII chars from the path (not the query!).

Returns:
url Reference to this

Definition at line 605 of file url.cls.php.

00605                          {
00606                 $ret = Arr::get_item($this->data, 'path', '');
00607                 $this->data['path'] = String::plain_ascii($ret);
00608                 return $this;   
00609         }
Url::clean_path_for_comparison ( path_to_check  )  [protected]

Definition at line 681 of file url.cls.php.

00681                                                                      {
00682                 foreach(array('?', '#') as $remove) {
00683                         $pos = strpos($path_to_check, $remove);
00684                         if ($pos !== false) {
00685                                 $path_to_check = substr($path_to_check, 0, $pos);
00686                         }
00687                 }
00688 
00689                 $path_to_check = ltrim($path_to_check, "/");
00690                 return $path_to_check;
00691         }
Url::clear_query (  ) 

Remove query parameters.

Returns:
Url Reference to self

Definition at line 643 of file url.cls.php.

00643                                       {
00644                 $this->data['query'] = array();
00645                 return $this;
00646         }
static Url::create ( url  )  [static]

Create new Url instance.

Parameters:
string  Path
Returns:
Url

Reimplemented in Referer.

Definition at line 204 of file url.cls.php.

00204                                             {
00205                 return new Url($url);
00206         }
static Url::create_with_fallback_host ( url,
host  
) [static]

Create new Url instance.

If url's host is empty use the given one

Parameters:
string  Path
string  Fallback host
Returns:
Url

Definition at line 215 of file url.cls.php.

00215                                                                       {
00216                 return new Url($url, $host);
00217         }
static Url::current (  )  [static]

Static returns the current URL.

Returns:
Url

Reimplemented in Referer.

Definition at line 190 of file url.cls.php.

00190                                          {
00191                 static $_url = false;
00192                 if ($_url === false) {
00193                         $_url = new Url(RequestInfo::current()->url_invoked());
00194                 }
00195                 return clone($_url);
00196         }       
Url::do_parse_url ( url,
fallback_host = ''  
) [protected]

This wraps PHP parse_url.

Parameters:
string  $url
string  $fallback_host host to use if URL is relative
Returns:
array

Definition at line 46 of file url.cls.php.

00046                                                                    {
00047                 // Make http default protocol
00048                 if (strpos($url, '://') === false) {
00049                         if (substr($url, 0, 1) == '/') {
00050                                 $url = $fallback_host . $url;
00051                         }
00052                         $url = 'http://' . $url; 
00053                 }
00054                 $ret = false;
00055                 try {
00056                         $ret = @parse_url($url);
00057                 }
00058                 catch (Exception $ex) {
00059                         // IF APP_THROW_ON_WARNING is enabled, we must catch!
00060                         $ret = array();                 
00061                 }
00062                 if ($ret === false) {
00063                         $ret = array();
00064                 }
00065                 return $ret;
00066         }
Url::equals ( other,
mode = self::EQUALS_FULL  
)

Compare this URL to an other.

Parameters:
string|Url  $other Other URL
enum  $mode Either EQUALS_FULL or EQUALS_IGNORE_QUERY
Returns:
bool

Definition at line 165 of file url.cls.php.

00165                                                                 {
00166                 $check_against = ($other instanceof Url) ? $other : Url::create($other);
00167                 $ret = true;
00168                 $ret = $ret && $this->get_path() == $check_against->get_path();
00169                 $ret = $ret && $this->get_host() == $check_against->get_host();
00170                 $ret = $ret && $this->get_port() == $check_against->get_port();
00171                 $ret = $ret && $this->get_scheme() == $check_against->get_scheme();
00172                 if ($mode == self::EQUALS_FULL) {
00173                         $ret = $ret && $this->get_query() == $check_against->get_query();
00174                 }
00175                 return $ret;
00176         }
Url::get_fragment (  ) 

Return fragment (stuff after "#").

Definition at line 502 of file url.cls.php.

00502                                        {
00503                 return $this->data['fragment'];
00504         }
Url::get_host (  ) 

Return host (e.g.

"www.example.com")

Definition at line 366 of file url.cls.php.

00366                                    {
00367                 // to_lower() removed, since it is already done in setter
00368                 return $this->data['host']; 
00369         }
Url::get_path (  ) 

Return the path only.

Definition at line 263 of file url.cls.php.

00263                                    {
00264                 return $this->data['path'];                             
00265         }
Url::get_port (  ) 

Definition at line 495 of file url.cls.php.

00495                                    {
00496                 return $this->data['port'];
00497         }
Url::get_query ( encode = Url::ENCODE_PARAMS  ) 

Return full query.

Definition at line 281 of file url.cls.php.

00281                                                               {
00282                 $sep = html_entity_decode(ini_get('arg_separator.output'), ENT_QUOTES, GyroLocale::get_charset());
00283                 $ret = '';
00284                 foreach($this->get_query_params($encode) as $key => $value) {
00285                         $this->query_reduce($ret, $sep, $key, $value);
00286                 }
00287                 return $ret;
00288         }
Url::get_query_param ( name,
default = false,
encode = Url::NO_ENCODE_PARAMS  
)

Return query paramter.

Definition at line 317 of file url.cls.php.

00317                                                                                                 {
00318                 $ret = Arr::get_item($this->data['query'], $name, $default);
00319                 if ($encode == Url::ENCODE_PARAMS) {
00320                         if (is_array($ret)) {
00321                                 array_walk_recursive($ret, array($this, 'callback_urlencode'));
00322                         }
00323                         else {
00324                                 $this->callback_urlencode($ret);
00325                         }
00326                 }
00327                 return $ret;            
00328         }
Url::get_query_params ( encode = Url::NO_ENCODE_PARAMS  ) 

Return query paramters as associative array.

Definition at line 340 of file url.cls.php.

00340                                                                         {
00341                 $ret = Arr::get_item($this->data, 'query', array());
00342                 if ($encode == Url::ENCODE_PARAMS) {
00343                         array_walk_recursive($ret, array($this, 'callback_urlencode'));
00344                 }
00345                 return $ret;
00346         }
Url::get_scheme (  ) 

Return scheme (http, ftp etc).

Definition at line 351 of file url.cls.php.

00351                                      {
00352                 return $this->data['scheme'];
00353         }
Url::is_ancestor_of ( path_to_check  ) 

Returns true, if this URL is identical or below the given $path_to_check.

E.g. Checking an URL of /a/b/c against /a/b would return true, checking against /a/b/c/d would return false

Definition at line 653 of file url.cls.php.

00653                                                        {
00654                 $path_to_check = trim($this->clean_path_for_comparison($path_to_check), '/');
00655                 $current = trim($this->get_path(), '/');
00656         
00657                 $ret = false; 
00658                 if (!empty($current) && !empty($path_to_check) && strpos($current . '/', $path_to_check . '/') === 0) {
00659                         $ret = true;
00660                 }
00661                 else if (empty($current) && empty($path_to_check)) {
00662                         $ret = true;
00663                 }               
00664                 
00665                 return $ret;
00666         }
Url::is_empty (  ) 

Returns true if the URL is empty (that is no host is specified).

Definition at line 181 of file url.cls.php.

00181                                    {
00182                 return $this->data['host'] === '';
00183         }
Url::is_same_as ( path_to_check  ) 

Returns true, if this URL is identical the given $path_to_check.

Query and fragment are ignored. Other than equals() this function works on a path or even a malformed URL. It's similar to is_ancestor_of() in how it works.

Definition at line 674 of file url.cls.php.

00674                                                    {
00675                 $path_to_check = $this->clean_path_for_comparison($path_to_check);
00676                 $current = ltrim($this->get_path(), '/');
00677 
00678                 return $current == $path_to_check;
00679         }
Url::is_valid (  ) 

Returns true if this is a valid URL.

Definition at line 520 of file url.cls.php.

00520                                    {
00521                 $ret = !$this->is_empty();
00522                 
00523                 $src_host = $this->get_host();
00524                 if ($ret && !Validation::is_ip($src_host)) {
00525                         $ret = $ret && (preg_match('|^([A-Z0-9][A-Z0-9_-]*)(\.[A-Z0-9][A-Z0-9_-]*)+$|i', $src_host) != 0);
00526                         if ($ret) {
00527                                 $host = $this->parse_host();
00528                                 $ret = $ret && !empty($host['tld']);
00529                                 $ret = $ret && !empty($host['domain']); 
00530                         }
00531                 }
00532                                 
00533                 return $ret; 
00534         }
Url::output (  ) 

Prints this query as a string.

Returns:
Url Reference to self
Exceptions:
Throws  an exception if hostname is empty

Definition at line 584 of file url.cls.php.

00584                                  {
00585                 $out = $this->build(true);
00586                 print $out;
00587                 return $this;
00588         }
Url::parse ( url,
fallback_host = ''  
) [protected]

Parse URL into Urls.

Definition at line 71 of file url.cls.php.

00071                                                             {
00072                 $url = trim($url);
00073                 $data = array();
00074                 if (!empty($url)) {
00075                         $data = $this->do_parse_url($url, $fallback_host);
00076                 }
00077                 
00078                 $this->set_scheme(Arr::get_item($data, 'scheme', 'http'));
00079                 $this->set_host(Arr::get_item($data, 'host', ''));
00080                 $this->set_port(Arr::get_item($data, 'port', ''));
00081                 $this->set_path(Arr::get_item($data, 'path', ''));
00082                 $this->set_fragment(Arr::get_item($data, 'fragment', ''));
00083                 $this->set_query(Arr::get_item($data, 'query', ''));
00084         }
Url::parse_host (  ) 

Returns the host split into an array.

The array returns has five members

tld => (semi) top level domain like 'com' or 'co.uk' sld => second level domain like 'example' in www.example.com domain => sld.tld subdomain => rest, e.g. 'www' from www.example.com data => Array of parts, like ('www', 'example', 'com')

Returns:
Array Associative array

Definition at line 442 of file url.cls.php.

00442                                      {
00443                 $host = $this->get_host();
00444                 $ret = array(
00445                         'tld' => '',
00446                         'sld' => '',
00447                         'domain' => '',
00448                         'subdomain' => '',
00449                         'data' => explode('.', $host)
00450                 );
00451                 $l_host = strlen($host);  // Cache string length
00452                 if ($l_host > 0) {
00453                         require_once(dirname(__FILE__) . '/data/tld.lst.php');
00454                         $tlds = get_tlds();
00455                         // We do not have utf 8 here, so we can use native string functions,
00456                         // no String::xxxx wrappers. They perform notably faster.
00457                         foreach($tlds as $tld) {
00458                                 $l_tld_check = strlen($tld) + 1; // +1 is for the '.' we will add later on
00459                                 // A valid domain name is x.[TLD], so the host must be at least by one
00460                                 // char longer than the ".[TLD]"  
00461                                 if ($l_tld_check >= $l_host) {
00462                                         // Impossible match...
00463                                         continue;
00464                                 } 
00465                                 
00466                                 // The below is equal to (String::ends_with($host, '.' . $tld))
00467                                 if (substr($host, -$l_tld_check, $l_tld_check) === '.' . $tld) {
00468                                         $ret['tld'] = $tld;
00469                                         $tmp = explode('.', $tld);
00470                                         $count_data = count($ret['data']);
00471                                         $count_tld = count($tmp);
00472                                         $index_domain = $count_data - $count_tld - 1; // -1 is for 0-based
00473                                         if ($index_domain >= 0) {
00474                                                 $ret['sld'] = $ret['data'][$index_domain];
00475                                                 $arr_subdomain = array();
00476                                                 for($i = 0; $i < $index_domain; $i++) {
00477                                                         $arr_subdomain[] = $ret['data'][$i];
00478                                                 }
00479                                                 $ret['subdomain'] = implode('.', $arr_subdomain);
00480                                                 $ret['domain'] = $ret['sld'] . '.' . $ret['tld'];
00481                                         }
00482                                         break;
00483                                 }
00484                         } 
00485                 }
00486                 unset($tlds); // Saves Memory, I think.
00487                 return $ret;
00488         }
Url::parse_query ( query  )  [protected]

Split a query into items and return them as associative array.

Parameters:
string  $query
Returns:
string

Definition at line 92 of file url.cls.php.

00092                                                {
00093                 $ret = array();
00094                 
00095                 // Input separator may be a list of chars!
00096                 $sep = ini_get('arg_separator.input');
00097                 $l = String::length($sep);
00098                 if ($l > 1) {
00099                         // We have a list, take first char as separator and replace all others with it 
00100                         $all_seps = $sep;
00101                         $sep = String::substr($all_seps, 0, 1);                 
00102                         for ($i = 1; $i < $l; $i++) {
00103                                 $query = str_replace(String::substr($all_seps,$i, 1), $sep, $query);
00104                         }
00105                 }
00106                 
00107                 // Now split query and process it
00108                 $arrItems = explode($sep, $query);
00109                 foreach($arrItems as $query_item) {
00110                         $arr = explode('=', $query_item, 2);
00111                         $pname = String::convert(urldecode($arr[0]));
00112                         $pvalue = (count($arr) > 1) ? String::convert(urldecode($arr[1])) : '';
00113                         if (!empty($pname)) {
00114                                 if (substr($pname, -2) == '[]') {
00115                                         $ret[$pname][] = $pvalue;
00116                                 }
00117                                 else {
00118                                         $ret[$pname] = $pvalue;
00119                                 }
00120                         }
00121                 }
00122                 
00123                 return $ret;
00124                 
00125                 // GR: What is disadvantage of this code? 
00126                 // - Will understand arrays, this class however won't (get_query_params(), get_query_param()) - which maybe is a bug of Url class. 
00127                 // - "my value=something" wil become array['my_value' => 'something'], note the underscore
00128                 // - Does not respect setting of arg_seperator.input
00129                 //
00130                 // Left here as reminder, though
00131                 // $ret = array();
00132                 // $temp = array();
00133                 // parse_str($query, $temp);
00134                 // foreach($temp as $key => $value) {
00135                 //      $pname = String::convert(urldecode($key));
00136                 //      $pvalue = String::convert(urldecode($value));
00137                 //      if (!empty($pname)) {
00138                 //              $ret[$pname] = $pvalue;
00139                 //      }
00140                 // }
00141                 // return $ret;
00142         }
Url::query_reduce ( &$  current,
sep,
key,
value  
) [protected]

Reduces set of params to query string (a=b&c=d.

..)

Parameters:
string  $current Recent output
string  $sep Separator
string  $key Name of param
mixed  $value Value of param

Definition at line 298 of file url.cls.php.

00298                                                                        {
00299                 if ($key) {
00300                         if (is_array($value)) {
00301                                 foreach($value as $v) {
00302                                         $this->query_reduce($current, $sep, $key, $v);
00303                                 }
00304                         }
00305                         else {
00306                                 if ($current) {
00307                                         $current .= $sep;
00308                                 }
00309                                 $current .= $key . '=' . $value;
00310                         }
00311                 }
00312         }
Url::redirect ( permanent = self::TEMPORARY  ) 

Redirect to this Url.

Parameters:
bool  If true, a permanent, else a temporary redirect is done

Definition at line 620 of file url.cls.php.

00620                                                              {
00621                 if (headers_sent() == false) {
00622                         $address = 'Location: ' . $this->build();
00623                         if ($permanent == self::PERMANENT) {
00624                                 Common::send_status_code(301); // Moved Permanently
00625                         }
00626                         else {
00627                                 Common::send_status_code(302); // Moved Temporarily
00628                         }
00629                         session_write_close(); // Fixes some issues with Sessions not getting save on redirect
00630                         header($address);
00631                         exit;
00632                 }
00633                 else {
00634                         throw new Exception('Url: Redirect to ' . $this->build() . ' not possible, headers already sent'); 
00635                 }
00636         }
Url::replace_query_parameter ( name,
value  
)

Replaces or adds parameter to query string.

Returns this

Parameters:
String  Parameter name
String  Paremeter value
Returns:
Url Reference to self

Definition at line 226 of file url.cls.php.

00226                                                                {
00227                 if ($value === '' || $value === false) {
00228                         unset($this->data['query'][$name]);
00229                 }
00230                 else {
00231                         $this->data['query'][$name] = $value;
00232                 }
00233                 return $this;
00234         }
Url::replace_query_parameters ( arr_params  ) 

Replace an array of paramters at once.

Parameters:
array  $arr_params Associativea array
Returns:
Url

Definition at line 242 of file url.cls.php.

00242                                                               {
00243                 foreach($arr_params as $key => $value) {
00244                         $this->replace_query_parameter($key, $value);
00245                 }
00246                 return $this;
00247         }
Url::set_fragment ( fragment  ) 

Set fragment (stuff after "#").

Returns:
Url

Definition at line 511 of file url.cls.php.

00511                                                 {
00512                 $this->data['fragment'] = $fragment;
00513                 return $this;
00514         }
Url::set_host ( host  ) 

Set Host.

Returns:
Url

Definition at line 376 of file url.cls.php.

00376                                         {
00377                 $this->data['host'] = String::to_lower($host);
00378                 return $this;
00379         }
Url::set_host_array ( arr_host  ) 

Set host data from array.

The array posted should be an associative array with these members:

tld => (semi) top level domain like 'com' or 'co.uk' sld => second level domain like 'example' in www.example.com domain => sld.tld - Only if tld and sld are ommitted! subdomain => rest, e.g. 'www' from www.example.com

Definition at line 391 of file url.cls.php.

00391                                                   {
00392                 $arr_temp = $this->parse_host();
00393                 if (isset($arr_host['subdomain'])) {
00394                         $arr_temp['subdomain'] = $arr_host['subdomain'];
00395                 }
00396                 if (isset($arr_host['domain'])) {
00397                         $arr_temp['domain'] = $arr_host['domain'];
00398                 }
00399                 else {
00400                         if (isset($arr_host['tld'])) {
00401                                 $arr_temp['tld'] = $arr_host['tld'];
00402                         }
00403                         if (isset($arr_host['sld'])) {
00404                                 $arr_temp['sld'] = $arr_host['sld'];
00405                         }
00406                         unset($arr_temp['domain']);
00407                 }
00408                 
00409                 // Build...
00410                 $arr_build = array();
00411                 if (!empty($arr_temp['subdomain'])) {
00412                         $arr_build[] = $arr_temp['subdomain'];
00413                 }
00414                 if (!empty($arr_temp['domain'])) {
00415                         $arr_build[] = $arr_temp['domain'];
00416                 }
00417                 else {
00418                         if (!empty($arr_temp['sld'])) {
00419                                 $arr_build[] = $arr_temp['sld'];
00420                         }
00421                         if (!empty($arr_temp['tld'])) {
00422                                 $arr_build[] = $arr_temp['tld'];
00423                         }
00424                 }
00425 
00426                 return $this->set_host(implode('.', $arr_build));               
00427         }
Url::set_path ( path  ) 

Set the path for this url.

Parameters:
string  The new path
Returns:
Url Reference to self

Definition at line 255 of file url.cls.php.

00255                                         {
00256                 $this->data['path'] = ltrim($path, '/');
00257                 return $this;
00258         }
Url::set_port ( port  ) 

Definition at line 490 of file url.cls.php.

00490                                         {
00491                 $this->data['port'] = ($port) ? intval($port) : $port;
00492                 return $this;
00493         }
Url::set_query ( query  ) 

Set query as string.

Parameters:
string  $query
Returns:
Url

Definition at line 273 of file url.cls.php.

00273                                           {
00274                 $this->data['query'] = $this->parse_query($query);
00275                 return $this;
00276         }
Url::set_scheme ( scheme  ) 

Set scheme (http, ftp etc).

Definition at line 358 of file url.cls.php.

00358                                             {
00359                 $this->data['scheme'] = $scheme;
00360                 return $this;
00361         }
static Url::validate_current (  )  [static]

Definition at line 693 of file url.cls.php.

00693                                                   {
00694                 if (!empty($_POST)) {
00695                         return;
00696                 }
00697                 
00698                 $url = Url::current();
00699                 $path = trim($url->get_path());
00700                 
00701                 if ($path == Config::get_value(Config::URL_BASEDIR)) {
00702                         return;
00703                 } 
00704 
00705 
00706                 //$pathclean = trim(str_replace('%20', '', $path), '/'); // created endless circles of redirects
00707                 //$pathclean = trim($path, '/');
00708                 $pathclean = str_replace('%20', '', $path);
00709                 $pathclean = str_replace('//', '/', $pathclean);
00710                 
00711                 $dirs = explode('/', $pathclean);
00712                 $dirsclean = array();
00713                 for ($i = 0; $i < sizeof($dirs); $i++) {
00714                         if ('.' === $dirs[$i]) {
00715                                 continue;
00716                         }
00717                         if ('..' === $dirs[$i] && $i > 0 && '..' != $dirsclean[sizeof($dirsclean) - 1]) {
00718                                 array_pop($dirsclean);
00719                                 continue;
00720                         }
00721                         array_push($dirsclean, $dirs[$i]);
00722                 }
00723                 $pathclean = implode('/', $dirsclean);
00724                 $url->set_path($pathclean);
00725                 if ($url->build(Url::ABSOLUTE, Url::ENCODE_PARAMS) != RequestInfo::current()->url_invoked(RequestInfo::ABSOLUTE)) {
00726                         $url->redirect(self::PERMANENT);
00727                         exit();
00728                 } 
00729                 
00730                 $pos = String::strpos($path, '&'); 
00731                 if ($pos !== false) {
00732                         $path = String::left($path, $pos) . '?' . String::substr($path, $pos + 1);
00733                         $url->set_path($path);
00734                         $url->redirect(self::PERMANENT);
00735                         exit();
00736                 }
00737         }

Member Data Documentation

const Url::ABSOLUTE = 'absolute'

Definition at line 12 of file url.cls.php.

const Url::ENCODE_PARAMS = 'encode'

Definition at line 15 of file url.cls.php.

const Url::EQUALS_FULL = 0

When comparing URLs, ignore only fragment.

Definition at line 21 of file url.cls.php.

When comparing URLs, ignore query (and fragment).

Definition at line 25 of file url.cls.php.

const Url::NO_ENCODE_PARAMS = 'encodenot'

Definition at line 16 of file url.cls.php.

Definition at line 10 of file url.cls.php.

const Url::RELATIVE = 'relative'

Definition at line 13 of file url.cls.php.

Definition at line 9 of file url.cls.php.


The documentation for this class was generated from the following file: