common.php/img() implemented to fully get rid of absolute image sizes
[www.energie.vellum.cz.git] / common.php
index db02711..449c87b 100644 (file)
@@ -124,16 +124,21 @@ function month_a($year,$month,$month_last=0)
        return($r);
 }
 
-function img_size($width,$height=0)
+function img_size($width,$height)
 {
-       if (!$height)
-               list($width,$height)=getimagesize($width);
        return("style=\"border:0;width:${width}px;height:${height}px\" width=\"$width\" height=\"$height\"");
 }
 
+function img($file,$alt,$attrs="")
+{
+       list($width,$height)=getimagesize($file);
+       return("<img src=\"$file\" alt=\"".htmlspecialchars($alt)."\" ".img_size($width,$height)
+                       .($attrs=="" ? "" : " ".$attrs)." />");
+}
+
 function gsm_banking()
 {
-       return("<img src=\"img/sluzby_bankovni_pggsm.gif\" ".img_size(89,31)." alt=\"Paegas GSM banking\" class=\"img-align\" />");
+       return(img("img/sluzby_bankovni_pggsm.gif","Paegas GSM banking","class=\"img-align\""));
 }
 
 function price_a()
@@ -170,8 +175,7 @@ function title_month($year,$month)
        return(""
                        ."<table border=\"0\" width=\"100%\">\n"
                        ."<tr><td align=\"center\"><table border=\"1\" cellpadding=\"10\">\n"
-                       ."<tr><td align=\"center\"><img src=\"".$month_a["img"]."\" ".img_size($month_a["img"])
-                       ." alt=\"titulní stránka ".$month_a["name"]."\" /></td></tr>\n"
+                       ."<tr><td align=\"center\">".img($month_a["img"],"titulní stránka ".$month_a["name"])."</td></tr>\n"
                        ."</table></td></tr>\n"
                        ."</table>\n"
                        );
@@ -181,8 +185,7 @@ function title_icons_table_month($year,$month,$month_last)
 {
        $month_a=month_a($year,$month,$month_last);
        print("<a href=\"title.php?year=$year&amp;month=$month\">"
-                               ."<img src=\"".$month_a["icon"]."\" ".img_size($month_a["icon"])
-                               ." alt=\"titulní stránka ".$month_a["name"]."\" /></a><br />"
+                               .img($month_a["icon"],"titulní stránka ".$month_a["name"])."</a><br />"
                        ."<a href=\"obsah.php?year=$year&amp;month=$month\">obsah ".$month_a["name"]."</a>"
                        );
 }