[pmwiki-users] Idea for a recipe - Avoid Css Hacks

Carlos A. Bonamigo carlos.ab at gmail.com
Sun Nov 19 12:08:53 CST 2006


Hi again, I was looking for easier ways  to obtain browser compatibility for a 
skin and I saw an article about how to handle css with php.

The code looks like this:

<?php if (!defined('PmWiki')) exit();

 $d = detect();
 $b = $d['browser'];
 $v = $d['version'];
 $o = $d['os'];

 function detect()
     {
     $browser = array ("IE","OPERA","MOZILLA","NETSCAPE","FIREFOX","SAFARI");
     $os = array ("WIN","MAC","LINUX");
     $info['browser'] = "OTHER";
     $info['os'] = "OTHER";
     foreach ($browser as $parent)
         {
         $s = strpos(strtoupper($_SERVER['HTTP_USER_AGENT']), $parent);
         $f = $s + strlen($parent);
         $version = substr($_SERVER['HTTP_USER_AGENT'], $f, 5);
         $version = preg_replace('/[^0-9,.]/','',$version);
         if ($s)
             {
             $info['browser'] = $parent;
             $info['version'] = $version;
             }
         }
     foreach ($os as $val)
         {
         if (eregi($val,strtoupper($_SERVER['HTTP_USER_AGENT']))) $info['os'] 
= $val;
         }
     return $info;
     }

?>

and then you can specify rules for diferent browsers , versions  and OSes 
within skin.php, like this:

 if ($o == "WIN" && $b == "IE" && $v < 6) $HTMLStylesFmt['skin'] =" 
div#wikitext{color:red;background-color:transparent;}";

Making a way out of the labirynth css can be sometimes.

So, is it a good idea for a recipe?

Carlos


(The article and the script can be found here -> 
http://www.stylegala.com/articles/no_more_css_hacks.htm)




More information about the pmwiki-users mailing list