$location = $_SERVER['HTTP_REFERER'];
}
- if ((substr_count($location, 'http://') == 0) && (substr_count($location, 'https://') == 0)) {
- $location = $CONFIG->url . $location;
- }
+ $location = elgg_normalize_url($location);
// return new forward location or false to stop the forward or empty string to exit
$current_page = current_page_url();
if (!isset($item['text'])) {
return FALSE;
}
+
+ if (!empty($item['href'])) {
+ $item['href'] = elgg_normalize_url($item['href']);
+ }
// we use persistent object properties in the submenu
// setup function, so normalize the array to an object.
}
$value = new stdClass();
- $value->url = $menu_url;
+ $value->url = elgg_normalize_url($menu_url);
$value->context = $context;
$CONFIG->menucontexts[] = $context;
return preg_replace('/&(?!amp;)/', '&', $url);
}
+/**
+ * Converts shorthand urls to absolute urls.
+ *
+ * If the url is already absolute or protocol-relative, no change is made.
+ *
+ * @example
+ * elgg_normalize_url(''); // 'http://my.site.com/'
+ * elgg_normalize_url('pg/dashboard'); // 'http://my.site.com/pg/dashboard'
+ * elgg_normalize_url('http://google.com/'); // no change
+ * elgg_normalize_url('//google.com/'); // no change
+ *
+ * @param string $url The URL to normalize
+ *
+ * @return string The absolute url
+ */
+function elgg_normalize_url($url) {
+ if (preg_match("#{^(https?:)?//#i", $url)) {
+ return $url;
+ }
+
+ return elgg_get_site_url().$url;
+}
+
/**
* When given a title, returns a version suitable for inclusion in a URL
*