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

Source for file styles.inc.php

Documentation is available at styles.inc.php

  1. <?php
  2. /**
  3. *  This file is part of the VCL for PHP project
  4. *
  5. *  Copyright (c) 2004-2007 qadram software <support@qadram.com>
  6. *
  7. *  Checkout AUTHORS file for more information on the developers
  8. *
  9. *  This library is free software; you can redistribute it and/or
  10. *  modify it under the terms of the GNU Lesser General Public
  11. *  License as published by the Free Software Foundation; either
  12. *  version 2.1 of the License, or (at your option) any later version.
  13. *
  14. *  This library is distributed in the hope that it will be useful,
  15. *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  17. *  Lesser General Public License for more details.
  18. *
  19. *  You should have received a copy of the GNU Lesser General Public
  20. *  License along with this library; if not, write to the Free Software
  21. *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
  22. *  USA
  23. *
  24. */
  25.  
  26. use_unit("controls.inc.php");
  27.  
  28. /**
  29.  * StyleSheet Class
  30.  * A class to allow import and use stylesheets
  31.  *
  32.  */
  33. class CustomStyleSheet extends Component
  34. {
  35.         protected $_filename="";
  36.         protected $_stylelist=array();
  37.         protected $_inclstandard=0;
  38.         protected $_inclid=0;
  39.         protected $_incsubstyle=0;
  40.  
  41.         /**
  42.          * Builds and returs back an array of Style names based on specified
  43.          * parameters
  44.          *
  45.          * @return array of names
  46.          */
  47.         function BuildStyleList($FileName$InclStandard$InclID$InclSubStyle)
  48.         {
  49.                 $array=array();
  50.  
  51.                 if (($FileName === ""|| (!file_exists($FileName))) return $array;
  52.                 if (($file fopen($FileName"r")) == falsereturn $array;
  53.  
  54.                 // Preload File, Parse out comments
  55.                 $flag false;
  56.                 while (!feof($file))
  57.                 {
  58.                         $line fgets($file4096);
  59.                         $line trim($line);
  60.                         while ($line != "")
  61.                         {
  62.                                 if ($flag)
  63.                                 {
  64.                                         $pos strpos($line"*/");
  65.                                         if ($pos === false$line "";
  66.                                         else
  67.                                         {
  68.                                                 $line substr($line$pos 3strlen($line));
  69.                                                 $flag false;
  70.                                         }
  71.                                 }
  72.                                 else
  73.                                 {
  74.                                         $pos strpos($line"/*");
  75.                                         if ($pos === false)
  76.                                         {
  77.                                                 $lines[$line;
  78.                                                 $line "";
  79.                                         }
  80.                                         else
  81.                                         {
  82.                                                 $flag true;
  83.                                                 if ($pos !== 0)
  84.                                                 {
  85.                                                         $temp trim(substr($line0$pos));
  86.                                                         if (!$temp===""$lines[$temp;
  87.                                                 }
  88.                                                 $line substr($line$pos 2strlen($line));
  89.                                         }
  90.                                 }
  91.                         }
  92.                 }
  93.                 fclose($file);
  94.                 // Nothing to work with
  95.                 if ((!isset($lines)) || (count($lines== 0)) return $array;
  96.  
  97.                 // Parse lines, remove CSS Definitions
  98.                 reset($lines);
  99.                 $flag false;
  100.                 while (list($index$lineeach($lines))
  101.                 {
  102.                         while ($line!=="")
  103.                         {
  104.                                 if ($flag)
  105.                                 {
  106.                                         $pos strpos($line"}");
  107.                                         if ($pos === false$line "";
  108.                                         else
  109.                                         {
  110.                                                 $line trim(substr($line$pos 1strlen($line)));
  111.                                                 $flag false;
  112.                                         }
  113.                                 }
  114.                                 else
  115.                                 {
  116.                                         $pos strpos($line"{");
  117.                                         if ($pos === false)
  118.                                         {
  119.                                                 if (($line!==""&& (!in_array($line$lines2)))
  120.                                                         $lines2[$line;
  121.                                                 $line "";
  122.                                         }
  123.                                         else
  124.                                         {
  125.                                                 $flag true;
  126.                                                 if ($pos !== 0)
  127.                                                 {
  128.                                                         $temp trim(substr($line0$pos));
  129.                                                         if ($temp!=="")
  130.                                                                 if ((!isset($lines2)) || (!in_array($temp$lines2)))
  131.                                                                         $lines2[$temp;
  132.                                                 }
  133.                                                 $line trim(substr($line$pos 1strlen($line)));
  134.                                         }
  135.                                 }
  136.                         }
  137.                 }
  138.                 // Nothing to work with
  139.                 if ((!isset($lines2)) || (count($lines2== 0)) return $array;
  140.  
  141.                 // Prepare style list
  142.                 reset($lines2);
  143.                 while (list($lineeach($lines2))
  144.                 {
  145.                         $words explode(","$line);
  146.                         reset($words);
  147.                         while (list($wordeach($words))
  148.                         {
  149.                                 $word trim($word);
  150.                                 if ($word == ""continue;
  151.  
  152.                                 if ($InclSubStyle == 0)
  153.                                 {
  154.                                         $pos1 strpos($word'.');
  155.                                         $pos2 strpos($word'#');
  156.                                         if (($pos1 === 0|| ($pos2 === 0))
  157.                                         {
  158.                                                 $prefix $word{0};
  159.                                                 $word trim(substr($word1strlen($word)));
  160.                                                 $parts split('[ .#]'$word);
  161.                                                 reset($parts);
  162.                                                 $part $prefix trim(current($parts));
  163.                                         }
  164.                                         else
  165.                                         {
  166.                                                 $parts split('[ .#]'$word);
  167.                                                 reset($parts);
  168.                                                 $part trim(current($parts));
  169.                                         }
  170.                                 }
  171.                                 else
  172.                                         $part $word;
  173.  
  174.                                 if (trim($part== ""continue;
  175.  
  176.                                 if ((isset($array)) && (in_array($part$array))) continue;
  177.  
  178.                                 $pos1 strpos($part'.');
  179.                                 $pos2 strpos($part'#');
  180.                                 if ((($InclStandard == 1&& ($pos1 === false&& ($pos2 === false))
  181.                                   || (($InclID == 1&& ($pos2 === 0))
  182.                                   || ($pos1 === 0)
  183.                                   )
  184.                                 {
  185.                                         $array[$part;
  186.                                 }
  187.                         }
  188.                 }
  189.                 return $array;
  190.         }
  191.  
  192.         protected function ParseCSSFile()
  193.         {
  194.                 $this->_stylelist=$this->BuildStyleList($this->FileName$this->_inclstandard$this->_inclid$this->_incsubstyle);
  195.         }
  196.  
  197.         function dumpHeaderCode()
  198.         {
  199.                 echo("<link rel=\"stylesheet\" href=\"" $this->_filename . "\" type=\"text/css\" />\n");
  200.         }
  201.  
  202.         function loaded()
  203.         {
  204.                 $this->ParseCSSFile();
  205.         }
  206.  
  207.         /**
  208.          * Specifies CSS File Name
  209.          *
  210.          * @return string 
  211.          */
  212.         protected function readFileName()               return $this->_filename}
  213.         protected function writeFileName($value)        $this->_filename=$value}
  214.         function defaultFileName()                      return ""}
  215.         /**
  216.          * Specifies if Styles array should include style names for HTML tags
  217.          *
  218.          * @return boolean 
  219.          */
  220.         protected function readIncludeStandard()        return $this->_inclstandard}
  221.         protected function writeIncludeStandard($value$this->_inclstandard = $value}
  222.         function defaultIncludeStandard()               return 0}
  223.         /**
  224.          * Specifies if Styles array should include class IDs
  225.          * If set to True, then to work properly IncludeSubStyle should be set to True also
  226.          *
  227.          * @return boolean 
  228.          */
  229.         protected function readIncludeID()              return $this->_inclid}
  230.         protected function writeIncludeID($value)       $this->_inclid = $value}
  231.         function defaultIncludeID()                     return 0}
  232.         /**
  233.          * Specifies if Styles array should include Class Names only or
  234.          * full class definitions including tag elements
  235.          *
  236.          * @return boolean 
  237.          */
  238.         protected function readIncludeSubStyle()        return $this->_incsubstyle}
  239.         protected function writeIncludeSubStyle($value$this->_incsubstyle = $value}
  240.         function defaultIncludeSubStyle()               return 0}
  241.         /**
  242.          * Array of Style Names from specified CSS File
  243.          *
  244.          * @return array 
  245.          */
  246.         function readStyles()                           $this->ParseCSSFile();
  247.                                                           return $this->_stylelist}
  248.         function writeStyles($value)                    $this->_stylelist = $value}
  249. }
  250.  
  251. /**
  252.  * StyleSheet Class
  253.  * A class to allow import and use stylesheets
  254.  *
  255.  */
  256. class StyleSheet extends CustomStyleSheet
  257. {
  258.         // Publish properties
  259.         
  260.         function getFileName()                  return $this->readFileName()}
  261.         function setFileName($value)            $this->writeFileName($value)}
  262.  
  263.         function getIncludeStandard()           return $this->readIncludeStandard()}
  264.         function setIncludeStandard($value)     $this->writeIncludeStandard($value)}
  265.  
  266.         function getIncludeID()                 return $this->readIncludeID()}
  267.         function setIncludeID($value)           $this->writeIncludeID($value)}
  268.  
  269.         function getIncludeSubStyle()           return $this->readIncludeSubStyle()}
  270.         function setIncludeSubStyle($value)     $this->writeIncludeSubStyle($value)}
  271. }
  272.  
  273. ?>

Documentation generated on Tue, 27 Mar 2007 13:35:57 +0200 by phpDocumentor 1.3.1