Source for file HTML.php

Documentation is available at HTML.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.php';
  39.  
  40. /**
  41.  * Classe permet de gérer l'accès à des flux de données comme du HTML
  42.  *
  43.  * @package    Pxxo
  44.  * @copyright  Copyright (c) 2008 Nicolas Thouvenin
  45.  * @license    http://opensource.org/licenses/bsd-license.php
  46.  */
  47. class Pxxo_Buffer_HTML extends Pxxo_Buffer
  48. {
  49.     /**
  50.      * @var     string type du contenu du flux
  51.      */
  52.     protected $type = 'html';
  53.     /**
  54.      * Constructeur PHP5
  55.      *
  56.      * @param    string localisation du flux
  57.      */
  58.     function __construct($p)
  59.     {
  60.         parent::__construct($p);
  61.     }
  62.     /**
  63.     * Filtre permettant de minimiser du Code HTML
  64.     *
  65.     * @param   string chaine de caractère
  66.     * @return  string chaine de caractère compressée
  67.     */
  68.     public function compress($source
  69.     {
  70.         // Pull out the script blocks
  71.         preg_match_all("!<script[^>]+>.*?</script>!is"$source$match);
  72.         $_script_blocks $match[0];
  73.         $source preg_replace("!<script[^>]+>.*?</script>!is",
  74.             '@@@SMARTY:TRIM:SCRIPT@@@'$source);
  75.  
  76.         // Pull out the pre blocks
  77.         preg_match_all("!<pre>.*?</pre>!is"$source$match);
  78.         $_pre_blocks $match[0];
  79.         $source preg_replace("!<pre>.*?</pre>!is",
  80.             '@@@SMARTY:TRIM:PRE@@@'$source);
  81.  
  82.         // remove all leading spaces, tabs and carriage returns NOT
  83.         // preceeded by a php close tag.
  84.         $source preg_replace('/((?<!\?>)\n)[\s]+/m''\1'$source);
  85.  
  86.         // replace script blocks
  87.         foreach($_script_blocks as $curr_block{
  88.             $source preg_replace("!@@@SMARTY:TRIM:SCRIPT@@@!",$curr_block,$source,1);
  89.         }
  90.         // replace pre blocks
  91.         foreach($_pre_blocks as $curr_block{
  92.             $source preg_replace("!@@@SMARTY:TRIM:PRE@@@!",$curr_block,$source,1);
  93.         }
  94.  
  95.         return trim($source)
  96.     }
  97. }

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