1 |
efrain |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
/**
|
|
|
4 |
* Represents a pre or post processing filter on HTML Purifier's output
|
|
|
5 |
*
|
|
|
6 |
* Sometimes, a little ad-hoc fixing of HTML has to be done before
|
|
|
7 |
* it gets sent through HTML Purifier: you can use filters to acheive
|
|
|
8 |
* this effect. For instance, YouTube videos can be preserved using
|
|
|
9 |
* this manner. You could have used a decorator for this task, but
|
|
|
10 |
* PHP's support for them is not terribly robust, so we're going
|
|
|
11 |
* to just loop through the filters.
|
|
|
12 |
*
|
|
|
13 |
* Filters should be exited first in, last out. If there are three filters,
|
|
|
14 |
* named 1, 2 and 3, the order of execution should go 1->preFilter,
|
|
|
15 |
* 2->preFilter, 3->preFilter, purify, 3->postFilter, 2->postFilter,
|
|
|
16 |
* 1->postFilter.
|
|
|
17 |
*
|
|
|
18 |
* @note Methods are not declared abstract as it is perfectly legitimate
|
|
|
19 |
* for an implementation not to want anything to happen on a step
|
|
|
20 |
*/
|
|
|
21 |
|
|
|
22 |
class HTMLPurifier_Filter
|
|
|
23 |
{
|
|
|
24 |
|
|
|
25 |
/**
|
|
|
26 |
* Name of the filter for identification purposes.
|
|
|
27 |
* @type string
|
|
|
28 |
*/
|
|
|
29 |
public $name;
|
|
|
30 |
|
|
|
31 |
/**
|
|
|
32 |
* Pre-processor function, handles HTML before HTML Purifier
|
|
|
33 |
* @param string $html
|
|
|
34 |
* @param HTMLPurifier_Config $config
|
|
|
35 |
* @param HTMLPurifier_Context $context
|
|
|
36 |
* @return string
|
|
|
37 |
*/
|
|
|
38 |
public function preFilter($html, $config, $context)
|
|
|
39 |
{
|
|
|
40 |
return $html;
|
|
|
41 |
}
|
|
|
42 |
|
|
|
43 |
/**
|
|
|
44 |
* Post-processor function, handles HTML after HTML Purifier
|
|
|
45 |
* @param string $html
|
|
|
46 |
* @param HTMLPurifier_Config $config
|
|
|
47 |
* @param HTMLPurifier_Context $context
|
|
|
48 |
* @return string
|
|
|
49 |
*/
|
|
|
50 |
public function postFilter($html, $config, $context)
|
|
|
51 |
{
|
|
|
52 |
return $html;
|
|
|
53 |
}
|
|
|
54 |
}
|
|
|
55 |
|
|
|
56 |
// vim: et sw=4 sts=4
|