themes
[ class tree: themes ] [ index: themes ] [ all elements ]

Source for file css_lib.php

Documentation is available at css_lib.php

  1. <?php
  2. /**
  3.  * @version $Header$
  4.  *  User css Library
  5.  *
  6.  * @package themes
  7.  */
  8.  
  9. /**
  10.  * css Library
  11.  *
  12.  * @package themes
  13.  */
  14. class cssLib extends BitBase {
  15.  
  16.     function list_css($path, &$back) {
  17.         $handle = opendir($path);
  18.  
  19.         while ($file = readdir($handle)) {
  20.             if (is_dir($path.'/'.$file) and $file <> ".." and $file <> "." and $file <> "CVS") {
  21.                 $back = $this->list_css($path.'/'.$file, $back);
  22.             } elseif ((substr($file, -4, 4) == ".css") and (ereg("^[-_a-zA-Z0-9\.]*$", $file))) {
  23.                 array_push($back, substr($path.'/'.$file, strlen(BIT_ROOT_PATH)));
  24.             }
  25.             unset($file);
  26.         }
  27.         closedir($handle);
  28.         unset($handle);
  29.  
  30.         return $back;
  31.     }
  32.  
  33.     function browse_css($path) {
  34.         if (!is_file($path)) {
  35.             return array("error" => "No such file : $path");
  36.         }
  37.  
  38.         $meat = implode("", file($path));
  39.  
  40.         $find[0] = "/\}/";
  41.         $repl[0] = "\n}\n";
  42.  
  43.         $find[1] = "/\{/";
  44.         $repl[1] = "\n{\n";
  45.  
  46.         $find[2] = "/\/\*/";
  47.         $repl[2] = "\n/*\n";
  48.  
  49.         $find[3] = "/\*\//";
  50.         $repl[3] = "\n*/\n";
  51.  
  52.         $find[4] = "/;/";
  53.         $repl[4] = ";\n";
  54.  
  55.         $find[5] = "/(W|w)hite/";
  56.         $repl[5] = "#FFFFFF";
  57.  
  58.         $find[6] = "/(B|b)lack/";
  59.         $repl[6] = "#000000";
  60.  
  61.         $res = preg_replace($find, $repl, $meat);
  62.         return array(
  63.             "error" => '',
  64.             "content" => split("\n", $res)
  65.         );
  66.     }
  67.  
  68.     function parse_css($data) {
  69.         $back = array();
  70.  
  71.         $index = 0;
  72.         $type = '';
  73.  
  74.         foreach ($data as $line) {
  75.             $line = trim($line);
  76.  
  77.             if ($line) {
  78.                 if (($type != "comment") and ($line == "/*")) {
  79.                     $type = "comment";
  80.  
  81.                     $index++;
  82.                     $back["$index"]["comment"] = '';
  83.                     $back["$index"]["items"] = array();
  84.                     $back["$index"]["attributes"] = array();
  85.                 } elseif (($type == "comment") and ($line == "*/")) {
  86.                     $type = "";
  87.                 } elseif ($type == "comment") {
  88.                     $back["$index"]["comment"] .= "$line\n";
  89.                 } elseif (($type == "items") and ($line == "{")) {
  90.                     $type = "attributes";
  91.                 } elseif ($type == "items") {
  92.                     $li = split(",", $line);
  93.  
  94.                     foreach ($li as $l) {
  95.                         $l = trim($l);
  96.  
  97.                         if ($l)
  98.                             $back["$index"]["items"][] = $l;
  99.                     }
  100.                 } elseif (($type == "attributes") and ($line == "}")) {
  101.                     $type = "";
  102.  
  103.                     $index++;
  104.                     $back["$index"]["comment"] = '';
  105.                     $back["$index"]["items"] = array();
  106.                     $back["$index"]["attributes"] = array();
  107.                 } elseif ($type == "attributes") {
  108.                     $parts = split(":", str_replace(";", "", $line));
  109.  
  110.                     if (isset($parts[0]) && isset($parts[1])) {
  111.                         $obj = trim($parts[0]);
  112.  
  113.                         $back["$index"]["attributes"]["$obj"] = trim($parts[1]);
  114.                     }
  115.                 } else {
  116.                     $li = split(",", $line);
  117.  
  118.                     foreach ($li as $l) {
  119.                         $l = trim($l);
  120.  
  121.                         if ($l)
  122.                             $back["$index"]["items"][] = $l;
  123.                     }
  124.  
  125.                     $type = "items";
  126.                 }
  127.  
  128.                 $back["content"] = $line;
  129.             }
  130.         }
  131.  
  132.         return $back;
  133.     }
  134.  
  135.     // Load CSS2 styled file (@import aware)
  136.     //
  137.     // TODO: Will M$ windowz eat '/' as path delimiter?
  138.     //
  139.     function load_css2_file($filename) {
  140.         $data = '';
  141.  
  142.         $path = dirname($filename);
  143.         if (!file_exists($filename)) {
  144.             return;
  145.         }
  146.  
  147.         $lines = file($filename);
  148.         foreach ($lines as $line) {
  149.             if (preg_match_all("/@import.*\([\'|\" ]*(.*)[\'|\" ]*\).*;/U", $line, $importfiles, PREG_SET_ORDER)) {
  150.                 foreach ($importfiles as $file) {
  151.                     $fileName = trim( $file[1] );
  152.                     if( $fileName != '../../base.css' ) {
  153.                         $import = $path.'/'.$fileName;
  154.                         $data .= $this->load_css2_file($import);
  155.                         $line = str_replace($file[0], "", $line);
  156.                     }
  157.                 }
  158.             }
  159.  
  160.             // TODO: Does it matter what $line may contain smth before '@import'? :)
  161.             $data .= $line;
  162.         }
  163.  
  164.         return $data;
  165.     }
  166. }
  167.  
  168. global $csslib;
  169. $csslib = new cssLib();
  170.  
  171. ?>

Documentation generated on Wed, 29 Jul 2015 13:56:17 +0000 by phpDocumentor 1.5.0-lsces