Changeset 125

User picture

Author: Technocrat

(2011/08/26 16:25) 9 months ago

HTML support

Affected files

Added trunk/plugins/html/lib/plugins/config/htmlpurifier_config.php

Show contents

Added trunk/plugins/html/lib/plugins/config/htmlpurifier_location.php

Show contents

Updated trunk/plugins/html/lib/plugins/type/html.php Download diff

124125
12
12
13
class HTML extends interfaces\Type_Plugin {
13
class HTML extends interfaces\Type_Plugin {
14
	/**
14
	/**
15
	 * Default setting for HTMLPurifier
16
	 *
17
	 * @var string
18
	 */
19
	private $_default = array(
20
							'HTML' => array('TidyLevel' => 'heavy', 'Doctype' => 'XHTML 1.0 Transitional'),
21
 							'Core' => array('EscapeNonASCIICharacters' => true),
22
						);
23
	/**
24
	 * Holds the HTML Purifier instance
15
	 * Holds the HTML Purifier instance
25
	 *
16
	 *
26
	 * @var class
17
	 * @var class
...
...
37
	/**
28
	/**
38
	 * Constructor
29
	 * Constructor
39
	 */
30
	 */
40
	final protected function __construct() { }
31
	final protected function __construct() {
32
		if (($location = \piv\core\Config_Factory::getInstance()->htmlpurifier_location->get()) !== false) {
33
			require $location.'HTMLPurifier.auto.php';
34
			$purifier_config = \HTMLPurifier_Config::createDefault();
35
			$config = \piv\core\Config_Factory::getInstance()->htmlpurifier_config->get();
36
			foreach ($config as $category => $setting_array) {
37
				foreach ($config[$category] as $setting => $value) {
38
					$purifier_config->set($category.'.'.$setting, $value);
39
				}
40
			}
41
			$this->_purifier = new \HTMLPurifier($purifier_config);
42
		} else {
43
			trigger_error('Could not load HTMLPurifier', E_USER_ERROR);
44
		}
45
	}
41
46
42
	/**
47
	/**
43
	 * Retrieves the singleton instance of this class.
48
	 * Retrieves the singleton instance of this class.
...
...
57
	}
62
	}
58
63
59
	public function convert($data) {
64
	public function convert($data) {
60
		if (!($this->_purifier instanceof \HTMLPurifier)) {
61
			$this->_purifier = new \HTMLPurifier($this->_default);
62
		}
63
64
		//If the data is an array
65
		//If the data is an array
65
		if (is_array($data)) {
66
		if (is_array($data)) {
66
			//Purify it
67
			//Purify it

Added trunk/plugins/html/Readme.txt

Show contents

Updated trunk/tests/index.php Download diff

124125
1
<?php
1
<?php
2
$class = 'hidden';
2
$class = 'hidden';
3
$type = '';
3
$type = '';
4
4
if (!empty($_POST)) {
5
if (!empty($_POST)) {
5
	$time_start = microtime(true);
6
	$time_start = microtime(true);
6
	require dirname(dirname(__FILE__)).'/lib/phpInputValidator.php';
7
	require dirname(dirname(__FILE__)).'/lib/phpInputValidator.php';
...
...
16
		$value = $getvar->string(array('variable' => 'input_text', 'location' => 'POST', 'multibyte' => true));
17
		$value = $getvar->string(array('variable' => 'input_text', 'location' => 'POST', 'multibyte' => true));
17
		$value = htmlentities($value, ENT_NOQUOTES, 'UTF-8');
18
		$value = htmlentities($value, ENT_NOQUOTES, 'UTF-8');
18
		$class = 'result';
19
		$class = 'result';
20
	} else if ($type == 'html') {
21
		$getvar->config->htmlpurifier_location(dirname(dirname(__FILE__)).'/htmlpurifier');
22
		$getvar->config->htmlpurifier_config(array(
23
							'HTML' => array('TidyLevel' => 'heavy', 'Doctype' => 'XHTML 1.0 Transitional'),
24
 							'Core' => array('EscapeNonASCIICharacters' => true),
25
							));
26
		$value = $getvar->html(array('variable' => 'input_textarea', 'location' => 'POST', 'multibyte' => true));
27
		$class = 'result';
19
	} else {
28
	} else {
20
		$value = $getvar->{$type}(array('variable' => 'input_text', 'location' => 'POST'));
29
		$value = $getvar->{$type}(array('variable' => 'input_text', 'location' => 'POST'));
21
		$class = 'result';
30
		$class = 'result';
...
...
77
					<option value="ipv4">IP Address (IP v4)</option>
86
					<option value="ipv4">IP Address (IP v4)</option>
78
					<option value="ipv6">IP Address (IP v6)</option>
87
					<option value="ipv6">IP Address (IP v6)</option>
79
					<option value="hostname">Hostname</option>
88
					<option value="hostname">Hostname</option>
89
					<?php if
(file_exists(dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR.'lib'.DIRECTORY_SEPARATOR.'plugins'.DIRECTORY_SEPARATOR.'type'.DIRECTORY_SEPARATOR.'html.php')) {
?>
90
					<option value="html">String (html)</option>
91
					<?php }?>
80
					<option value="string">String (no html)</option>
92
					<option value="string">String (no html)</option>
81
					<option value="hex">Hex</option>
93
					<option value="hex">Hex</option>
82
					<option value="hex_color">Hex Color</option>
94
					<option value="hex_color">Hex Color</option>