]> git.sur5r.net Git - contagged/commitdiff
Handle URL field RFC conform
authorAndreas Gohr <gohr@cosmocode.de>
Mon, 9 Jul 2007 08:24:51 +0000 (10:24 +0200)
committerAndreas Gohr <gohr@cosmocode.de>
Mon, 9 Jul 2007 08:24:51 +0000 (10:24 +0200)
RCF 2079 specifies a value that contains a URL followed by white
space and then a human readable string.

The template now supports that.

darcs-hash:20070709082451-6e07b-571a3a7111aadf0b0b3bee7fa57c063bdc48fea9.gz

inc/smarty/plugins/modifier.http.php
templates/entry_show.tpl

index a3fffbce9b8573f61bd2a62f5f73ddf783f1b2b0..ecb52e76b0f9df53b79f7fdc2c25b22e4d4579e2 100644 (file)
@@ -10,9 +10,7 @@
  * Smarty plugin
  *
  * Type:     modifier
- * Name:     noteparser
  * Date:     2007-06-19
- * Purpose:  Add the http:// protocol if missing
  * Example:  {$foo|http}
  * @author   Andreas Gohr <gohr@cosmocode.de>
  * @param string
 function smarty_modifier_http($string){
     if(!$string) return '';
 
-    if(!preg_match('#^\w+://#',$string)){
-        $string = 'http://'.$string;
+    list($url,$name) = explode(' ',$string,2);
+
+
+    if(!preg_match('#^\w+://#',$url)){
+        $url = 'http://'.$url;
     }
 
-    return $string;
+    if(!$name) $name = $url;
+
+    return '<a href="'.htmlspecialchars($url).'" target="_blank">'.htmlspecialchars($name).'</a>';
 }
 
 /* vim: set expandtab: */
index 18cc419847da23b7ed9767c9396e884ad9e342cc..25c2b61c6ff37878065af683b65f7dfd9ed44100 100644 (file)
 {if $entry.url}
           <tr>
             <th>{$lang.url}:</th>
-            <td><a href="{$entry.url|http}" target="_blank">{$entry.url|h}</a></td>
+            <td>{$entry.url|http}</td>
           </tr>
 {/if}
 {if $entry.mail}