]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
Refs #2463: Added url normalization support to output/url, output/confirmlink. Enhan...
authorewinslow <ewinslow@36083f99-b078-4883-b0ff-0f9b5a30f544>
Tue, 2 Nov 2010 20:16:13 +0000 (20:16 +0000)
committerewinslow <ewinslow@36083f99-b078-4883-b0ff-0f9b5a30f544>
Tue, 2 Nov 2010 20:16:13 +0000 (20:16 +0000)
git-svn-id: http://code.elgg.org/elgg/trunk@7199 36083f99-b078-4883-b0ff-0f9b5a30f544

engine/lib/output.php
views/default/output/confirmlink.php
views/default/output/url.php

index 335a53ac4edb2a9e95bdff199dcb94496b32d0a9..35ace7c09587348c6dd3939846db4cdc1d4bba49 100644 (file)
@@ -155,11 +155,20 @@ function elgg_format_url($url) {
  * @return string The absolute url
  */
 function elgg_normalize_url($url) {
+       // 'http://example.com', 'https://example.com', '//example.com'
        if (preg_match("#^(https?:)?//#i", $url)) {
                return $url;
-       }
+       } 
+       
+       // 'example.com', 'example.com/subpage'
+       elseif (preg_match("#[^/]*\.[^/]*/?#i", $url)) {
+               return "http://$url";
+       } 
        
-       return elgg_get_site_url().$url;
+       // 'pg/page/handler'
+       else {
+               return elgg_get_site_url().$url;
+       }
 }
 
 /**
index d7bb5c56f77a9c2ab7e553947f6b896f4bbb2284..4d1bc0ab9d22cf7fc18a7ef0c37f587487e5a981 100644 (file)
@@ -18,7 +18,7 @@ if (!$confirm) {
 }
 
 // always generate missing action tokens
-$link = elgg_add_action_tokens_to_url($vars['href']);
+$link = elgg_add_action_tokens_to_url(elgg_normalize_url($vars['href']));
 
 if (isset($vars['class']) && $vars['class']) {
        $class = 'class="' . $vars['class'] . '"';
index 9dd0bf3f5dae0b6ea3a10ca0a631e1ec675a569c..2a01e32d06c2b4b6b5be1f1a769735a95b9b70bb 100644 (file)
@@ -51,9 +51,7 @@ if (!empty($url)) {
                $text = htmlentities($url, ENT_QUOTES, 'UTF-8');
        }
 
-       if ((substr_count($url, "http://") == 0) && (substr_count($url, "https://") == 0)) {
-               $url = "http://" . $url;
-       }
+       $url = elgg_normalize_url($url);
 
        if (isset($vars['is_action'])) {
                $url = elgg_add_action_tokens_to_url($url);