Skip to content

Commit

Permalink
MDL-14898 upgraded html purifier to 3.1.0 in HEAD
Browse files Browse the repository at this point in the history
  • Loading branch information
skodak committed Jun 16, 2008
1 parent b553527 commit eb203ee
Show file tree
Hide file tree
Showing 290 changed files with 4,770 additions and 3,422 deletions.
9 changes: 0 additions & 9 deletions lib/htmlpurifier/HTMLPurifier.auto.php

This file was deleted.

20 changes: 0 additions & 20 deletions lib/htmlpurifier/HTMLPurifier.func.php

This file was deleted.

131 changes: 65 additions & 66 deletions lib/htmlpurifier/HTMLPurifier.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?php

/*!
* @mainpage
/*! @mainpage
*
* HTML Purifier is an HTML filter that will take an arbitrary snippet of
* HTML and rigorously test, validate and filter it into a version that
Expand All @@ -16,14 +15,12 @@
* -# Generating HTML from the purified tokens.
*
* However, most users will only need to interface with the HTMLPurifier
* class, so this massive amount of infrastructure is usually concealed.
* If you plan on working with the internals, be sure to include
* HTMLPurifier_ConfigSchema and HTMLPurifier_Config.
* and HTMLPurifier_Config.
*/

/*
HTML Purifier 2.1.4 - Standards Compliant HTML Filtering
Copyright (C) 2006-2007 Edward Z. Yang
HTML Purifier 3.1.0 - Standards Compliant HTML Filtering
Copyright (C) 2006-2008 Edward Z. Yang
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
Expand All @@ -40,32 +37,6 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

// constants are slow, but we'll make one exception
define('HTMLPURIFIER_PREFIX', dirname(__FILE__));

// every class has an undocumented dependency to these, must be included!
require_once 'HTMLPurifier/ConfigSchema.php'; // fatal errors if not included
require_once 'HTMLPurifier/Config.php';
require_once 'HTMLPurifier/Context.php';

require_once 'HTMLPurifier/Lexer.php';
require_once 'HTMLPurifier/Generator.php';
require_once 'HTMLPurifier/Strategy/Core.php';
require_once 'HTMLPurifier/Encoder.php';

require_once 'HTMLPurifier/ErrorCollector.php';
require_once 'HTMLPurifier/LanguageFactory.php';

HTMLPurifier_ConfigSchema::define(
'Core', 'CollectErrors', false, 'bool', '
Whether or not to collect errors found while filtering the document. This
is a useful way to give feedback to your users. <strong>Warning:</strong>
Currently this feature is very patchy and experimental, with lots of
possible error messages not yet implemented. It will not cause any problems,
but it may not help your users either. This directive has been available
since 2.0.0.
');

/**
* Facade that coordinates HTML Purifier's subsystems in order to purify HTML.
*
Expand All @@ -75,27 +46,36 @@
* -# Instance: new HTMLPurifier($config)
* -# Invocation: purify($html, $config)
* These configurations are entirely independent of each other and
* are *not* merged.
* are *not* merged (this behavior may change in the future).
*
* @todo We need an easier way to inject strategies, it'll probably end
* up getting done through config though.
* @todo We need an easier way to inject strategies using the configuration
* object.
*/
class HTMLPurifier
{

var $version = '2.1.4';
/** Version of HTML Purifier */
public $version = '3.1.0';

/** Constant with version of HTML Purifier */
const VERSION = '3.1.0';

/** Global configuration object */
public $config;

var $config;
var $filters = array();
/** Array of extra HTMLPurifier_Filter objects to run on HTML, for backwards compatibility */
private $filters = array();

var $strategy, $generator;
/** Single instance of HTML Purifier */
private static $instance;

protected $strategy, $generator;

/**
* Resultant HTMLPurifier_Context of last run purification. Is an array
* of contexts if the last called method was purifyArray().
* @public
*/
var $context;
public $context;

/**
* Initializes the purifier.
Expand All @@ -105,20 +85,20 @@ class HTMLPurifier
* The parameter can also be any type that
* HTMLPurifier_Config::create() supports.
*/
function HTMLPurifier($config = null) {
public function __construct($config = null) {

$this->config = HTMLPurifier_Config::create($config);

$this->strategy = new HTMLPurifier_Strategy_Core();
$this->generator = new HTMLPurifier_Generator();

}

/**
* Adds a filter to process the output. First come first serve
* @param $filter HTMLPurifier_Filter object
*/
function addFilter($filter) {
public function addFilter($filter) {
trigger_error('HTMLPurifier->addFilter() is deprecated, use configuration directives in the Filter namespace or Filter.Custom', E_USER_WARNING);
$this->filters[] = $filter;
}

Expand All @@ -132,8 +112,9 @@ function addFilter($filter) {
* that HTMLPurifier_Config::create() supports.
* @return Purified HTML
*/
function purify($html, $config = null) {
public function purify($html, $config = null) {

// :TODO: make the config merge in, instead of replace
$config = $config ? HTMLPurifier_Config::create($config) : $this->config;

// implementation is partially environment dependant, partially
Expand All @@ -142,8 +123,8 @@ function purify($html, $config = null) {

$context = new HTMLPurifier_Context();

// our friendly neighborhood generator, all primed with configuration too!
$this->generator->generateFromTokens(array(), $config, $context);
// setup HTML generator
$this->generator = new HTMLPurifier_Generator($config, $context);
$context->register('Generator', $this->generator);

// set up global context variables
Expand All @@ -164,8 +145,25 @@ function purify($html, $config = null) {

$html = HTMLPurifier_Encoder::convertToUTF8($html, $config, $context);

for ($i = 0, $size = count($this->filters); $i < $size; $i++) {
$html = $this->filters[$i]->preFilter($html, $config, $context);
// setup filters
$filter_flags = $config->getBatch('Filter');
$custom_filters = $filter_flags['Custom'];
unset($filter_flags['Custom']);
$filters = array();
foreach ($filter_flags as $filter => $flag) {
if (!$flag) continue;
$class = "HTMLPurifier_Filter_$filter";
$filters[] = new $class;
}
foreach ($custom_filters as $filter) {
// maybe "HTMLPurifier_Filter_$filter", but be consistent with AutoFormat
$filters[] = $filter;
}
$filters = array_merge($filters, $this->filters);
// maybe prepare(), but later

for ($i = 0, $filter_size = count($filters); $i < $filter_size; $i++) {
$html = $filters[$i]->preFilter($html, $config, $context);
}

// purified HTML
Expand All @@ -179,12 +177,11 @@ function purify($html, $config = null) {
$html, $config, $context
),
$config, $context
),
$config, $context
)
);

for ($i = $size - 1; $i >= 0; $i--) {
$html = $this->filters[$i]->postFilter($html, $config, $context);
for ($i = $filter_size - 1; $i >= 0; $i--) {
$html = $filters[$i]->postFilter($html, $config, $context);
}

$html = HTMLPurifier_Encoder::convertFromUTF8($html, $config, $context);
Expand All @@ -198,7 +195,7 @@ function purify($html, $config = null) {
* See HTMLPurifier::purify() for more details.
* @return Array of purified HTML
*/
function purifyArray($array_of_html, $config = null) {
public function purifyArray($array_of_html, $config = null) {
$context_array = array();
foreach ($array_of_html as $key => $html) {
$array_of_html[$key] = $this->purify($html, $config);
Expand All @@ -211,25 +208,27 @@ function purifyArray($array_of_html, $config = null) {
/**
* Singleton for enforcing just one HTML Purifier in your system
* @param $prototype Optional prototype HTMLPurifier instance to
* overload singleton with.
* overload singleton with, or HTMLPurifier_Config
* instance to configure the generated version with.
*/
function &instance($prototype = null) {
static $htmlpurifier;
if (!$htmlpurifier || $prototype) {
if (is_a($prototype, 'HTMLPurifier')) {
$htmlpurifier = $prototype;
public static function instance($prototype = null) {
if (!self::$instance || $prototype) {
if ($prototype instanceof HTMLPurifier) {
self::$instance = $prototype;
} elseif ($prototype) {
$htmlpurifier = new HTMLPurifier($prototype);
self::$instance = new HTMLPurifier($prototype);
} else {
$htmlpurifier = new HTMLPurifier();
self::$instance = new HTMLPurifier();
}
}
return $htmlpurifier;
return self::$instance;
}

function &getInstance($prototype = null) {
/**
* @note Backwards compatibility, see instance()
*/
public static function getInstance($prototype = null) {
return HTMLPurifier::instance($prototype);
}

}

Loading

0 comments on commit eb203ee

Please sign in to comment.