aboutsummaryrefslogtreecommitdiff
path: root/engine
diff options
context:
space:
mode:
Diffstat (limited to 'engine')
-rw-r--r--engine/lib/elgglib.php4
-rw-r--r--engine/lib/navigation.php6
-rw-r--r--engine/lib/output.php23
3 files changed, 29 insertions, 4 deletions
diff --git a/engine/lib/elgglib.php b/engine/lib/elgglib.php
index d162768f7..282b69fce 100644
--- a/engine/lib/elgglib.php
+++ b/engine/lib/elgglib.php
@@ -79,9 +79,7 @@ function forward($location = "") {
$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();
diff --git a/engine/lib/navigation.php b/engine/lib/navigation.php
index a5b087bd8..beb154f30 100644
--- a/engine/lib/navigation.php
+++ b/engine/lib/navigation.php
@@ -92,6 +92,10 @@ function elgg_add_submenu_item(array $item, $context = 'all', $group = 'default'
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.
@@ -420,7 +424,7 @@ function add_menu($menu_name, $menu_url, $menu_children = array(), $context = ""
}
$value = new stdClass();
- $value->url = $menu_url;
+ $value->url = elgg_normalize_url($menu_url);
$value->context = $context;
$CONFIG->menucontexts[] = $context;
diff --git a/engine/lib/output.php b/engine/lib/output.php
index 6fd820486..707d0b79a 100644
--- a/engine/lib/output.php
+++ b/engine/lib/output.php
@@ -140,6 +140,29 @@ function elgg_format_url($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
*
* @param string $title The title