Procedural File: _url.funcs.php
Source Location: /blogs/inc/_core/_url.funcs.php
Functions
void disp_url(
string $url, [integer $max_length = NULL]
)
|
|
Display an URL, constrained to a max length
Parameters:
|
string |
$url: |
|
|
integer |
$max_length: |
|
fetch_remote_page [line 284]
string|false fetch_remote_page(
string $url, array &$info, [integer $timeout = NULL], [integer $max_size_kb = NULL]
)
|
|
Fetch remote page
Attempt to retrieve a remote page using a HTTP GET request, first with cURL, then fsockopen, then fopen.
cURL gets skipped, if $max_size_kb is requested, since there appears to be no method to control this.
Parameters:
|
string |
$url: |
URL |
|
array |
&$info: |
Info (by reference) 'error': holds error message, if any 'status': HTTP status (e.g. 200 or 404) 'used_method': Used method ("curl", "fopen", "fsockopen" or null if no method is available) |
|
integer |
$timeout: |
Timeout (default: 15 seconds) |
|
integer |
$max_size_kb: |
Maximum size in kB |
API Tags:
| Return: | The remote page as a string; false in case of error |
Information Tags:
| Todo: | dh> Should we try remaining methods, if the previous one(s) failed? |
| Todo: | Tblue> Also allow HTTP POST. |
get_allowed_uri_schemes [line 193]
array get_allowed_uri_schemes(
[string $context = 'posting']
)
|
|
Get allowed URI schemes for a given context.
Parameters:
|
string |
$context: |
Context ("posting", "commenting") |
string idna_decode(
string $url
)
|
|
Decode IDNA puny-code ("xn--..") to UTF-8 name.
Parameters:
API Tags:
| Return: | The decoded puny-code ("xn--..") (UTF8!) |
string idna_encode(
string $url
)
|
|
IDNA-Encode URL to Punycode.
Parameters:
API Tags:
| Return: | Encoded URL (ASCII) |
is_absolute_url [line 735]
boolean is_absolute_url(
string $url
)
|
|
Is a given URL absolute? Note: "//foo/bar" is absolute - leaving the protocol out.
Parameters:
boolean is_same_url(
$a, $b
)
|
|
Compare two given URLs, if they are the same.
This converts all urlencoded chars (e.g. "%AA") to lowercase. It appears that some webservers use lowercase for the chars (Apache), while others use uppercase (lighttpd).
Parameters:
make_rel_links_abs [line 694]
string make_rel_links_abs(
string $s, [string $host = NULL]
)
|
|
Make links in $s absolute.
It searches for "src" and "href" HTML tag attributes and makes the absolute.
Parameters:
|
string |
$s: |
content |
|
string |
$host: |
Hostname including scheme, e.g. http://example.com; defaults to $ReqHost |
API Tags:
string url_absolute(
string $url, [string $host = NULL]
)
|
|
Make an $url absolute according to $host, if it is not absolute yet.
Parameters:
|
string |
$url: |
URL |
|
string |
$host: |
Host (including protocol, e.g. 'http://example.com'); defaults to $ReqHost |
API Tags:
void url_add_param(
string $url, string|array $param, [string $glue = '&']
)
|
|
Add param(s) at the end of an URL, using either "?" or "&" depending on existing url
Parameters:
|
string |
$url: |
existing url |
|
string|array |
$param: |
Params to add (string as-is) or array, which gets urlencoded. |
|
string |
$glue: |
delimiter to use for more params |
void url_add_tail(
string $url, string $tail
)
|
|
Add a tail (starting with "/") at the end of an URL before any params (starting with "?")
Parameters:
|
string |
$url: |
existing url |
|
string |
$tail: |
tail to add |
void url_crumb(
string $crumb_name
)
|
|
Create a crumb param to be passed in action urls...
Parameters:
|
string |
$crumb_name: |
crumb_name |
url_rel_to_same_host [line 603]
string url_rel_to_same_host(
string $url, string $target_url
)
|
|
Try to make $url relative to $target_url, if scheme, host, user and pass matches.
This is useful for redirect_to params, to keep them short and avoid mod_security rejecting the request as "Not Acceptable" (whole URL as param).
Parameters:
|
string |
$url: |
URL to handle |
|
string |
$target_url: |
URL where we want to make $url relative to |
url_same_protocol [line 478]
string url_same_protocol(
string $url, [string $other_url = NULL]
)
|
|
Get $url with the same protocol (http/https) as $other_url.
Parameters:
|
string |
$url: |
URL |
|
string |
$other_url: |
other URL (defaults to $ReqHost) |
mixed validate_url(
string $url, [string $context = 'posting'], [boolean $antispam_check = true]
)
|
|
Check the validity of a given URL
Checks allowed URI schemes and URL ban list. URL can be empty.
Note: We have a problem when trying to "antispam" a keyword which is already blacklisted If that keyword appears in the URL... then the next page has a bad referer! :/
Parameters:
|
string |
$url: |
Url to validate |
|
string |
$context: |
Context ("posting", "commenting") |
|
boolean |
$antispam_check: |
also do an antispam check on the url |
API Tags:
| Return: | false (which means OK) or error message |
_http_wrapper_last_status [line 246]
integer|boolean _http_wrapper_last_status(
array &$headers
)
|
|
Get the last HTTP status code received by the HTTP/HTTPS wrapper of PHP.
Parameters:
|
array |
&$headers: |
The $http_response_header array (by reference). |
API Tags:
| Return: | False if no HTTP status header could be found, the HTTP status code otherwise. |