]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
Refs #2463: Added elgg_normalize_url. forward() and add_menu() make use of it
authorewinslow <ewinslow@36083f99-b078-4883-b0ff-0f9b5a30f544>
Tue, 2 Nov 2010 19:22:35 +0000 (19:22 +0000)
committerewinslow <ewinslow@36083f99-b078-4883-b0ff-0f9b5a30f544>
Tue, 2 Nov 2010 19:22:35 +0000 (19:22 +0000)
git-svn-id: http://code.elgg.org/elgg/trunk@7194 36083f99-b078-4883-b0ff-0f9b5a30f544

engine/lib/elgglib.php
engine/lib/navigation.php
engine/lib/output.php

index d162768f7be9d4769e767efeed8c8a2ccced6947..282b69fce77a4c141c36eae44718ba4d7e0d954a 100644 (file)
@@ -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();
index a5b087bd826655413696c83ca53d2bd91866727d..beb154f30c90492b7dada7a4b0519e1cb192c13e 100644 (file)
@@ -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;
index 6fd8204867772190486e8f0c703af19a21a2013e..707d0b79a2e9330d09f3d6ee13830a189bf3a45d 100644 (file)
@@ -139,6 +139,29 @@ function elgg_format_url($url) {
        return preg_replace('/&(?!amp;)/', '&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
  *