a_href() fixed to return the value (not to print it)
authorshort <>
Thu, 25 Apr 2002 17:01:40 +0000 (17:01 +0000)
committershort <>
Thu, 25 Apr 2002 17:01:40 +0000 (17:01 +0000)
a_href() enhanced to generate optimal URLs for all types of clients

common.php

index de6252b..048176a 100644 (file)
@@ -631,10 +631,20 @@ function a_href($url,$contents)
 {
        global $have_ent;
 
-       print("<a href=\"");
-       if (ereg("^[a-z]+://",$url) && !$have_ent)
-               $url="redirect.php?location=".urlencode($url);
-       print(htmlspecialchars($url)."\">$contents</a>");
+       $r="<a href=\"";
+       $urlent=htmlspecialchars($url);
+            if ($url==$urlent)
+               $r.=$url;
+       else if (!ereg("^[a-z]+://",$url))      // $url is our resource
+               $r.=$urlent;
+       else if (isset($have_ent) && !$have_ent)        // non-ent client
+               $r.=$url;
+       else if ($have_ent) // ent client
+               $r.=$urlent;
+       else // unknown client, htmlspecialchars() should not be needed here
+               $r.=htmlspecialchars("redirect.php?location=".urlencode($url));
+       $r.="\">$contents</a>";
+       return($r);
 }
 
 function footer($delimit=true)