Allow text alternative for images to percolate all the way through template layers
[squirrelmail.git] / functions / html.php
index 4dc3f1e79d2d5e13ac3a4ae7175a42d023bb90d6..3172bc5044d4c7fd855e0def212b323d61fea25e 100644 (file)
  * @since 1.3.0
  */
 
+
+/**
+ * Generates a hyperlink
+ *
+ * @param string $uri     The target link location
+ * @param string $text    The link text 
+ * @param string $target  The location where the link should 
+ *                        be opened (OPTIONAL; default not used)
+ * @param string $onclick The onClick JavaScript handler (OPTIONAL; 
+ *                        default not used)
+ * @param string $class   The CSS class name (OPTIONAL; default
+ *                        not used)
+ * @param string $id      The ID name (OPTIONAL; default not used)
+ *
+ * @return string The desired hyperlink tag.
+ *
+ * @since 1.5.2
+ *
+ */
+function create_hyperlink($uri, $text, $target='', $onclick='', $class='', $id='') {
+
+    global $oTemplate;
+
+    $oTemplate->assign('uri', $uri);
+    $oTemplate->assign('text', $text);
+    $oTemplate->assign('target', $target);
+    $oTemplate->assign('onclick', $onclick);
+    $oTemplate->assign('class', $class);
+    $oTemplate->assign('id', $id);
+
+    return $oTemplate->fetch('hyperlink.tpl');
+
+}
+
+
+/**
+ * Generates an image tag
+ *
+ * @param string $src     The image source path
+ * @param string $alt     Alternate link text (OPTIONAL; default 
+ *                        not used)
+ * @param string $width   The width the image should be shown in 
+ *                        (OPTIONAL; default not used)
+ * @param string $height  The height the image should be shown in 
+ *                        (OPTIONAL; default not used)
+ * @param string $border  The image's border attribute value 
+ *                        (OPTIONAL; default not used)
+ * @param string $class   The CSS class name (OPTIONAL; default
+ *                        not used)
+ * @param string $id      The ID name (OPTIONAL; default not used)
+ * @param string $onclick The onClick JavaScript handler (OPTIONAL;
+ *                        default not used)
+ * @param string $title   The image's title attribute value 
+ *                        (OPTIONAL; default not used)
+ * @param string $align   The image's alignment attribute value 
+ *                        (OPTIONAL; default not used)
+ * @param string $hspace  The image's hspace attribute value 
+ *                        (OPTIONAL; default not used)
+ * @param string $vspace  The image's vspace attribute value 
+ *                        (OPTIONAL; default not used)
+ * @param string $text_alternative A text replacement for the entire
+ *                                 image tag, to be used at the 
+ *                                 discretion of the template set,
+ *                                 if for some reason the image tag
+ *                                 cannot or should not be produced
+ *                                 (OPTIONAL; default not used)
+ *
+ * @return string The desired hyperlink tag.
+ *
+ * @since 1.5.2
+ *
+ */
+function create_image($src, $alt='', $width='', $height='', 
+                      $border='', $class='', $id='', $onclick='', 
+                      $title='', $align='', $hspace='', $vspace='',
+                      $text_alternative='') {
+
+    global $oTemplate;
+
+    $oTemplate->assign('src', $src);
+    $oTemplate->assign('alt', $alt);
+    $oTemplate->assign('width', $width);
+    $oTemplate->assign('height', $height);
+    $oTemplate->assign('border', $border);
+    $oTemplate->assign('class', $class);
+    $oTemplate->assign('id', $id);
+    $oTemplate->assign('onclick', $onclick);
+    $oTemplate->assign('title', $title);
+    $oTemplate->assign('align', $align);
+    $oTemplate->assign('hspace', $hspace);
+    $oTemplate->assign('vspace', $vspace);
+    $oTemplate->assign('text_alternative', $text_alternative);
+
+    return $oTemplate->fetch('image.tpl');
+
+}
+
+
 /**
  * Generates html tags
  *
@@ -90,6 +188,7 @@ function html_tag( $tag,                // Tag to output
     return( $ret );
 }
 
+
 /**
  * handy function to set url vars
  *
@@ -109,7 +208,7 @@ function set_url_var($url, $var, $val=0, $link=true) {
                     '/.+(\\?'.$var.')=(.*)$/AU',     /* at front and only var */
                     '/.+(\\&'.$var.')=(.*)$/AU'      /* at the end */
                     );
-    preg_replace('/&/','&',$url);
+    $url = str_replace('&','&',$url);
 
     // FIXME: why switch is used instead of if () or one preg_match()
     switch (true) {
@@ -143,9 +242,6 @@ function set_url_var($url, $var, $val=0, $link=true) {
     if ($k) {
         if ($val) {
             $rpl = "$k=$val";
-            if ($link) {
-                $rpl = preg_replace('/&/','&',$rpl);
-            }
         } else {
             $rpl = '';
         }
@@ -155,5 +251,10 @@ function set_url_var($url, $var, $val=0, $link=true) {
         $pat = "/$k=$v/";
         $url = preg_replace($pat,$rpl,$url);
     }
+    if ($link) {
+        $url = str_replace('&','&',$url);
+    }
     return $url;
 }
+
+