function securepages_url in Secure Pages 5
Same name and namespace in other branches
- 6 securepages.module \securepages_url()
Generate a URL from a Drupal menu path. Will also pass-through existing URLs.
When creating links in modules, consider whether l() could be a better alternative than url().
3 calls to securepages_url()
- securepages_form_alter in ./
securepages.module - Implementation of hook_form_alter()
- securepages_goto in ./
securepages.module - securepage_goto()
- securepages_link_alter in ./
securepages.module - Implementation of hook_link_alter()
File
- ./
securepages.module, line 270
Code
function securepages_url($path = NULL, $query = NULL, $fragment = NULL, $secure = FALSE) {
if (isset($fragment)) {
$fragment = '#' . $fragment;
}
// Return an external link if $path contains an allowed absolute URL.
// Only call the slow filter_xss_bad_protocol if $path contains a ':' before any / ? or #.
$colonpos = strpos($path, ':');
if ($colonpos !== FALSE && !preg_match('![/?#]!', substr($path, 0, $colonpos)) && filter_xss_bad_protocol($path, FALSE) == check_plain($path)) {
// Split off the fragment
if (strpos($path, '#') !== FALSE) {
list($path, $old_fragment) = explode('#', $path, 2);
if (isset($old_fragment) && !isset($fragment)) {
$fragment = '#' . $old_fragment;
}
}
// Append the query
if (isset($query)) {
$path .= (strpos($path, '?') !== FALSE ? '&' : '?') . $query;
}
// Reassemble
return $path . $fragment;
}
global $base_url;
static $script;
static $clean_url;
if (!isset($script)) {
// On some web servers, such as IIS, we can't omit "index.php". So, we
// generate "index.php?q=foo" instead of "?q=foo" on anything that is not
// Apache.
$script = strpos($_SERVER['SERVER_SOFTWARE'], 'Apache') === FALSE ? 'index.php' : '';
}
// Cache the clean_url variable to improve performance.
if (!isset($clean_url)) {
$clean_url = (bool) variable_get('clean_url', '0');
}
$base = securepages_baseurl($secure) . '/';
// The special path '<front>' links to the default front page.
if (!empty($path) && $path != '<front>' && function_exists('drupal_get_path_alias')) {
$path = drupal_get_path_alias($path);
$path = drupal_urlencode($path);
if (!$clean_url) {
if (!empty($query)) {
return $base . $script . '?q=' . $path . '&' . $query . $fragment;
}
else {
return $base . $script . '?q=' . $path . $fragment;
}
}
else {
if (!empty($query)) {
return $base . $path . '?' . $query . $fragment;
}
else {
return $base . $path . $fragment;
}
}
}
else {
if (!empty($query)) {
return $base . $script . '?' . $query . $fragment;
}
else {
return $base . $fragment;
}
}
}