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