[ Index ]
 

Code source de Horde 3.1.3

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/lib/Horde/MIME/Viewer/ -> css.php (source)

   1  <?php
   2  
   3  require_once dirname(__FILE__) . '/source.php';
   4  
   5  /**
   6   * The MIME_Viewer_css class renders CSS source as HTML with an effort
   7   * to remove potentially malicious code.
   8   *
   9   * $Horde: framework/MIME/MIME/Viewer/css.php,v 1.1.10.8 2006/06/01 03:08:53 chuck Exp $
  10   *
  11   * Copyright 2004-2006 Chuck Hagenbuch <chuck@horde.org>
  12   *
  13   * See the enclosed file COPYING for license information (LGPL). If you
  14   * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
  15   *
  16   * @author  Chuck Hagenbuch <chuck@horde.org>
  17   * @since   Horde 3.0
  18   * @package Horde_MIME_Viewer
  19   */
  20  class MIME_Viewer_css extends MIME_Viewer_source {
  21  
  22      /**
  23       * Render out the currently set contents.
  24       *
  25       * @param array $params  Any parameters the viewer may need.
  26       *
  27       * @return string  The rendered text.
  28       */
  29      function render($params = null)
  30      {
  31          $css = htmlspecialchars($this->mime_part->getContents(), ENT_NOQUOTES);
  32          $css = preg_replace_callback('!(}|\*/).*?({|/\*)!s', array($this, '_handles'), $css);
  33          $css = preg_replace_callback('!{[^}]*}!s', array($this, '_attributes'), $css);
  34          $css = preg_replace_callback('!/\*.*?\*/!s', array($this, '_comments'), $css);
  35          $css = trim($css);
  36  
  37          // Educated Guess at whether we are inline or not.
  38          if (headers_sent() || ob_get_length()) {
  39              return $this->lineNumber($css);
  40          } else {
  41              return Util::bufferOutput('require', $GLOBALS['registry']->get('templates', 'horde') . '/common-header.inc') .
  42                  $this->lineNumber($css) .
  43                  Util::bufferOutput('require', $GLOBALS['registry']->get('templates', 'horde') . '/common-footer.inc');
  44          }
  45      }
  46  
  47      function _comments($matches)
  48      {
  49          $patterns[] = '!(http://[/\w-.]+)!s';
  50          $replaces[] = '<a href="\\1">\\1</a>';
  51  
  52          $comments = preg_replace($patterns, $replaces, $matches[0]);
  53  
  54          return '<span class="comment">' . $comments . '</span>';
  55      }
  56  
  57      function _attributes($matches)
  58      {
  59          // Attributes.
  60          $patterns[] = '!([-\w]+\s*):!s';
  61          $replaces[] = '<span class="attr"">\\1</span>:';
  62  
  63          // Values.
  64          $patterns[] = '!:(\s*)(.+?)(\s*;)!s';
  65          $replaces[] = ':\\1<span class="value">\\2</span><span class="eol">\\3</span>';
  66  
  67          // URLs.
  68          $patterns[] = '!(url\([\'"]?)(.*?)([\'"]?\))!s';
  69          $replaces[] = '<span class="url">\\1<span class="file">\\2</span>\\3</span>';
  70  
  71          // Colors.
  72          $patterns[] = '!(#[[:xdigit:]]{3,6})!s';
  73          $replaces[] = '<span class="color">\\1</span>';
  74  
  75          // Parentheses.
  76          $patterns[] = '!({|})!s';
  77          $replaces[] = '<span class="parentheses">\\1</span>';
  78  
  79          // Unity.
  80          $patterns[] = '!(em|px|%)\b!s';
  81          $replaces[] = '<em>\\1</em>';
  82  
  83          return preg_replace($patterns, $replaces, $matches[0]);
  84      }
  85  
  86      function _handles($matches)
  87      {
  88          // HTML Tags.
  89          $patterns[] = '!\b(body|h\d|a|span|div|acronym|small|strong|em|pre|ul|ol|li|p)\b!s';
  90          $replaces[] = '<span class="htag">\\1</span>\\2';
  91  
  92          // IDs.
  93          $patterns[] = '!(#[-\w]+)!s';
  94          $replaces[] = '<span class="id">\\1</span>';
  95  
  96          // Class.
  97          $patterns[] = '!(\.[-\w]+)\b!s';
  98          $replaces[] = '<span class="class">\\1</span>';
  99  
 100          // METAs.
 101          $patterns[] = '!(:link|:visited|:hover|:active|:first-letter)!s';
 102          $replaces[] = '<span class="metac">\\1</span>';
 103  
 104          return preg_replace($patterns, $replaces, $matches[0]);
 105      }
 106  
 107  }


Généré le : Sun Feb 25 18:01:28 2007 par Balluche grâce à PHPXref 0.7