Source for file CSS.php

Documentation is available at CSS.php

  1. <?php
  2. // vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 fdm=marker encoding=utf8 :
  3. /**
  4.  * Pxxo - build self-supported and interoperable Web graphical components
  5.  * 
  6.  * Copyright (c) 2008, Nicolas Thouvenin
  7.  *
  8.  * All rights reserved.
  9.  *
  10.  * Redistribution and use in source and binary forms, with or without
  11.  * modification, are permitted provided that the following conditions are met:
  12.  *
  13.  *     * Redistributions of source code must retain the above copyright
  14.  *       notice, this list of conditions and the following disclaimer.
  15.  *     * Redistributions in binary form must reproduce the above copyright
  16.  *       notice, this list of conditions and the following disclaimer in the
  17.  *       documentation and/or other materials provided with the distribution.
  18.  *     * Neither the name of the author nor the names of its contributors may be
  19.  *       used to endorse or promote products derived from this software without
  20.  *       specific prior written permission.
  21.  *
  22.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
  23.  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  24.  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  25.  * DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
  26.  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  27.  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  28.  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  29.  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  30.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  31.  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32.  
  33.  * @package    Pxxo
  34.  * @copyright  Copyright (c) 2008 Nicolas Thouvenin
  35.  * @license    http://opensource.org/licenses/bsd-license.php
  36.  * @version    $Id$
  37.  */
  38. require_once 'Pxxo/Buffer/Resource.php';
  39.  
  40. /**
  41. * Classe permet de gérer l'accès à des flux de données comme des ressources CSS
  42.  *
  43.  * @package    Pxxo
  44.  * @copyright  Copyright (c) 2008 Nicolas Thouvenin
  45.  * @license    http://opensource.org/licenses/bsd-license.php
  46.  */
  47. {
  48.     /**
  49.      * @var     string type du contenu du flux
  50.      */
  51.     protected $type = 'css';
  52.     /**
  53.      * @var        string  media pour lequel est destiné le CSS
  54.      */
  55.     protected $media = 'screen';
  56.     /**
  57.      * @var        string condition d'application de la feuille CSS
  58.      */
  59.      public $condition = '';
  60.      /**
  61.      * @var integer importance du Buffer
  62.      */
  63.      protected $weight = 1000;
  64.     /**
  65.      * Constructeur PHP5
  66.      *
  67.      * @param    string localisation du flux
  68.      */
  69.     function __construct($p)
  70.     {
  71.         parent::__construct($p);
  72.     }
  73.     /**
  74.      * Filtre permettant de minimiser du Code CSS
  75.      *
  76.      * @param   string chaine de caractère
  77.      * @return    string chaine de caractère compressée
  78.      */
  79.     public function compress($s
  80.     {
  81.         $s preg_replace('/\s+/'' '$s);
  82.         $s preg_replace('/\/\*.*?\*\//'''$s);
  83.         return trim($s);
  84.     }
  85.     /**
  86.      * Fixe le type de média qui utilisera le css
  87.      *
  88.      * @param    string 
  89.      */
  90.     public function setMedia($s
  91.     {
  92.         $this->media = $s;
  93.     }
  94.     /**
  95.      * Retourne le media qui utilisera le css
  96.      *
  97.      * @return    string 
  98.      */
  99.     public function getMedia(
  100.     {
  101.         return $this->media;
  102.     }
  103.     /**
  104.     * Retrourne une chaine en HTML permettant de charger la ressource
  105.     *
  106.     * @return    string chaine de caractère en HTML
  107.     */
  108.     public function getHTML(
  109.     {
  110.         $htmlstring '';
  111.         if (!empty($this->condition)) $htmlstring .= '<!--['.$this->condition.']>'."\n";;
  112.         if ($this->disposition != 'inline'{
  113.             $htmlstring .= '<link rel="stylesheet" type="text/css" href="'.$this->get().'" media="'.strtolower($this->media).'" />'."\n";
  114.         }
  115.         else {
  116.             $htmlstring .= '<style type="text/css" media="'.strtolower($this->media).'">'.$this->getContent().'</style>'."\n";
  117.         }
  118.         if (!empty($this->condition)) $htmlstring .= '<![endif]-->'."\n";;
  119.         return $htmlstring;
  120.     }
  121.     /**
  122.      * Renvoi le type étendu du Buffer
  123.      *
  124.      * @return    string 
  125.      */
  126.     public function getExtendedType(
  127.     {
  128.         return $this->type.':'.$this->disposition.':'.$this->media;
  129.     }
  130. }

Documentation generated on Thu, 13 Mar 2008 22:03:13 +0100 by phpDocumentor 1.4.1