Main Page | Modules | File List | File Members

URL editing and parsing


Functions

 links_normalize_url ($url)
 links_remove_empty_get_parms ($url)
 links_sort_get_parms ($url)
 links_sort_query_string ($query)
 links_remove_session_id ($url)
 links_check_trailing_slash ($url)
 links_cleanup_parms ($url)
 links_suggest_link_title ($link_spec, $default="")
 links_parse_url ($url, $accept_bare=TRUE, $accept_relative=TRUE, $accept_absolute=TRUE)

Function Documentation

links_check_trailing_slash url  ) 
 

If a link consists only of a protocol and hostname, add a trailing slash to explicitly request the default or index document. For example, "http://www.example.com" becomes "http://www.example.com/". This slightly speeds up page retrieval for the visitor, and also keeps from having these non-significant differences reflected in the database.

links_cleanup_parms url  ) 
 

The preg_replace() calls in the links_remove_...() functions may leave some cruft in the URL, such as "&&", "&?", or "?" or "&" as the first or last character. This function clears that problem up. It is called by the links_remove_...() functions and may also be of use to external applications.

links_normalize_url url  ) 
 

Certain common GET parameters, such as known session tags (e.g., PHPSESSID) don't really belong in a URL that is being permanently stored. This function strips out these known-undesirable parms.

WARNING: Changing this function, or others that it calls, may cause the MD5 sums of URLs in the database to need to be recalculated. If you make such changes, be sure to make a call to the function _links_recalc_all_url_md5() in the upgrade script.

links_parse_url url,
accept_bare = TRUE,
accept_relative = TRUE,
accept_absolute = TRUE
 

Checks the provided URL for valid syntax, and returns an associative array to report the findings. The array contains the following elements:

'url' => The original URL as passed to the function 'normalized' => The normalized version of the URL, which is also validated after normalization. This will be filled even if the source URL is not valid, though in that situation its results are undefined. 'valid' => Boolean TRUE or FALSE to indicate overall status 'errors' => A sub-array containing one or more error messages which the caller may optionally provide to the user. These have NOT been translated with t() before being returned; that is up to the calling application. This element will be UNSET if there were no errors. 'debug' => A sub-array containing diagnostics about the validation process. Used for testing; each element will be a string, though these are for programmers and not end users. 'scheme' => The URL scheme, if present or implied by type (based on the result URL, not the original), without trailing colon 'host' => The server name (host and/or domain), also set for bare email addresses if appropriate options enabled 'port' => Optional port number, if specified 'user' => Optional username, if specified, for regular URLS, or the local part of email addresses 'pass' => Optional password, if specified 'path' => An absolute or relative path depending on the URL format 'query' => GET parameters from the URL as a single string 'fragment' => Anything after a hashmark (#) character from the local part of the URL 'type' => One of the following, depending on the URL category: 'REMOTE' A traditional URL with sheme and hostname 'ABSOLUTE' A local absolute path 'RELATIVE' A local relative (or Drupal) path 'EMAIL' A bare email address or "mailto:" URL unset Unknown or invalid URL 'md5' => The MD5 hash of the lowercased, normalized URL

The parameters to the function are:

$url The URL to validate $accept_bare If TRUE, the function will also accept URLs with no scheme (that is, without "http://" etc.) as long as they begin with a valid hostname or match an email address. In this situation, the returned normalized URL will add the scheme as appropriate, including "mailto:" preceding an email address. The default scheme for anything not beginning with "ftp." is "http", except that "mailto" will be the scheme for email addresses. $accept_relative If TRUE, the function will accept relative paths (e.g., "node/1234"). In this situation, the returned normalized URL will not add a scheme or server name. If this is TRUE, then $accept_absolute is forced TRUE as well. $accept_absolute If TRUE, the function will accept local absolute paths (like a Drupal path, only beginning with a slash). in this situation, the returned normalized URL will not add a scheme or server name.

The PHP parse_url() function is deliberately not used here, because its validation is not extensive since it is intended only as a parser and not as a validator. The resemblence of this function's return values to those of parse_url() is not, however, an accident.

links_remove_empty_get_parms url  ) 
 

Remove empty GET parameters from a URL or bare query string. For example: http://example.com/abc.php?this=&that=55&other= becomes http://example.com/abc.php?that=55

TODO: Correctly handle links of the form http://example.com/abc.xyz?parm=xyz&parm2=123 (character entity encoding of ampersand delimiter)

links_remove_session_id url  ) 
 

This function removes known session ID strings from a URL. These are transient data from a particular browser on a particular day, and definitely do not belong in a links database. The search is not case sensitive. This also works on a bare query string rather than a full URL, and can be used that way.

links_sort_get_parms url  ) 
 

Order the GET parameters for a URL. This helps to detect URLs that are the same except for the parameter order. For exammple: http://example.com/abc.php?xyz=98&def=yes&abc=49 becomes: http://example.com/abc.php?abc=49&def=yes&xyz=98

Compare to links_sort_query_string() (which this function calls).

links_sort_query_string query  ) 
 

Orders the parameters in an HTTP GET query string. This helps to detect URLs that are the same except for the parameter order. For exammple: xyz=98&def=yes&abc=49 becomes: abc=49&def=yes&xyz=98

Accepts either "&" or the W3C-preferred "&" as a delimiter between parameters.

Compare to links_sort_get_parms() (which calls this function).

links_suggest_link_title link_spec,
default = ""
 

Given a link ID or URL, query the database to suggest a title for this link as it is being associated with a node. Basically, this will obtain the first assigned title (ordered by weight) of any existing node associations for this same link. A default value can be specified in case there's no good hint in the database. Failing all else, this function will return a very stripped down version of the URL itself as a suggested title.


Generated on Tue Aug 1 10:19:37 2006 for Drupal Links Package by  doxygen 1.4.4