Use dynamic image links
authorx2003bruneau <x2003bruneau@9869982d-c50d-0410-be91-f2a2ec7c7c7b>
Mon, 10 Jul 2006 09:01:39 +0000 (09:01 +0000)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Fri, 4 Jan 2008 23:34:50 +0000 (00:34 +0100)
git-svn-id: svn+ssh://murphy/home/svn/banana/trunk@73 9869982d-c50d-0410-be91-f2a2ec7c7c7b

banana/misc.inc.php
banana/spool.inc.php

index 3a086cf..5f35d80 100644 (file)
@@ -92,6 +92,32 @@ function makeHREF($params, $text = null)
     return '<a href="' . htmlentities($link) . $target . '">' . $text . '</a>';
 }
 
+/** Format tree images links
+ * @param img STRING Image name (without extension)
+ * @param alt STRING alternative string
+ * @param width INT  to force width of the image (null if not defined)
+ *
+ * This function can be overloaded by defining hook_makeImg()
+ */
+function makeImg($img, $alt, $width = null)
+{
+    if (function_exists('hook_makeImg')
+            && $res = hook_makeImg($img, $alt, $width)) {
+        return $res;
+    }
+
+    if (!is_null($width)) {
+        $width = ' width="' . $width . '"';
+    }
+
+    $proto = empty($_SERVER['HTTPS']) ? 'http://' : 'https://';
+    $host  = $_SERVER['HTTP_HOST'];
+    $file  = dirname($_SERVER['PHP_SELF']) . '/img/' . $img . '.gif';
+    $url   = $proto . $host . $file; 
+
+    return '<img src="' . $url . '"' . $width . ' alt="' . $alt . '" />';
+}
+
 /********************************************************************************
  * HTML STUFF
  * Taken from php.net
index e681a40..5b5bfb3 100644 (file)
@@ -313,16 +313,16 @@ class BananaSpool
 
     function _to_html($_id, $_index, $_first=0, $_last=0, $_ref="", $_pfx_node="", $_pfx_end="", $_head=true)
     {
-        $spfx_f   = '<img src="img/k1.gif" height="21" width="9" alt="o" />'
-        $spfx_n   = '<img src="img/k2.gif" height="21" width="9" alt="*" />'; 
-        $spfx_Tnd = '<img src="img/T-direct.gif" height="21" width="12" alt="+" />';
-        $spfx_Lnd = '<img src="img/L-direct.gif" height="21" width="12" alt="`" />';
-        $spfx_snd = '<img src="img/s-direct.gif" height="21" width="5" alt="-" />';
-        $spfx_T   = '<img src="img/T.gif" height="21" width="12" alt="+" />';
-        $spfx_L   = '<img src="img/L.gif" height="21" width="12" alt="`" />';
-        $spfx_s   = '<img src="img/s.gif" height="21" width="5" alt="-" />';
-        $spfx_e   = '<img src="img/e.gif" height="21" width="12" alt="&nbsp;" />';
-        $spfx_I   = '<img src="img/I.gif" height="21" width="12"alt="|" />';
+        $spfx_f   = makeImg('k1',       'o', 9)
+        $spfx_n   = makeImg('k2',       '*', 9);
+        $spfx_Tnd = makeImg('T-direct', '+', 12);
+        $spfx_Lnd = makeImg('L-direct', '`', 12);
+        $spfx_snd = makeImg('s-direct', '-', 5);
+        $spfx_T   = makeImg('T',        '+', 12);
+        $spfx_L   = makeImg('L',        '`', 12);
+        $spfx_s   = makeImg('s',        '-', 5);
+        $spfx_e   = makeImg('e',        '&nbsp;', 12);
+        $spfx_I   = makeImg('I',        '|', 12);
 
         if ($_index + $this->overview[$_id]->desc < $_first || $_index > $_last) {
             return;