JURI
JURI provides a number of methods and properties for handling Uniform Resource Identifiers (URIs). It also provides a means of obtaining the URI of the current request regardless of the web server on which Joomla is running.
The formal structure of a URI is defined in RFC3986 and the following is an example taken from that document:
foo://example.com:8042/over/there?name=ferret#nose
\_/ \______________/\_________/ \_________/ \__/
| | | | |
scheme authority path query fragment
The scheme and path components are required, though the path may be empty (no characters). When authority is present, the path must either be empty or begin with a slash ("/") character. When authority is not present, the path cannot begin with two slash characters ("//").
The scheme usually specifies the internet protocol that is to be used to access the resource. For example, 'http' indicates that the HyperText Transfer Protocol is to be used.
The authority field can be sub-divided into user information, host and port number parts. The user information part allows a URI to contain authentication information, usually in the form 'username:password', although this format is deprecated as "The passing of authentication information in clear text has proven to be a security risk in almost every case where it has been used." However, as URIs containing authentication information are still available on the internet, the JURI class will continue to support the generation and parsing of user authentication information.
The query part may contain multiple items, separated by '&' characters.
The JURI class effectively provides a wrapper around the PHP parse_url function.
Contents |
Defined in
/libraries/joomla/environment/uri.php
Extends
Get and Set Methods
Get and set methods are provided for all the component parts of a URI. The following names of the component parts are used:
http://fredbloggs:itsasecret@www.example.com:8080/path/to/Joomla/index.php?task=view&id=32#anchorthis \__/ \________/ \________/ \_____________/ \__/\_______________________/ \_____________/ \________/ | | | | | | | | scheme user pass host port path query fragment
The example column in the following table illustrates the result of each of the get methods on the URI above.
| Get method | Set method | Description | Example |
|---|---|---|---|
| getFragment | setFragment | Fragment (everything after the '#'). This is often referred to as an anchor. | anchorthis |
| getHost | setHost | Hostname or IP address. For example, 'www.joomla.org' or '192.168.2.45'. | www.example.com |
| getPass | setPass | Password part of the authority. | itsasecret |
| getPath | setPath | Path string. Note that the path always includes the leading "/" character. | /path/to/Joomla/index.php |
| getPort | setPort | Port number. Specific schemes (protocols) have their own defaults (for example, 'http' is port 80, 'ftp' is port 21). | 8080 |
| getQuery | setQuery | Query in string format. For example, "foo=bar&x=y". See also buildQuery. | task=view&id=32 |
| getScheme | setScheme | Scheme (protocol). For example, 'http', 'https', 'ftp'. | http |
| getUser | setUser | Username part of the authority. | fredbloggs |
| getVar | setVar | An individual query item value from within the query part. See also delVar. | 32 |
Other Methods
| Method name | Description |
|---|---|
| base | Returns the base URI of the request, regardless of the URI object. |
| buildQuery | Build the query part of a URI from an array of query items. |
| current | Returns the current URI of the request without the query part, regardless of the URI object. |
| delVar | Removes an individual query item. See also getVar and setVar. |
| getInstance | Returns a reference to the global JURI object, only creating it if it doesn't already exist. The global URI object represents the URI that caused the current page to be rendered. |
| isInternal | Checks whether the URI is internal; that is, on the same host as Joomla. |
| isSSL | Checks whether the URI is using the 'https' scheme (protocol). |
| parse | Parse the URI and populate the class fields. |
| root | Returns the root URI of the request, regardless of the URI object. |
| toString | Returns the full URI represented by the URI object in string format. |
Importing
jimport( 'joomla.environment.uri' );