- fix issue outlined by Emmanuel Engelhart <emmanuel@engelhart.org> on wikitech-l
[mediawiki.git] / PHPTAL-NP-0.7.0 / libs / PHPTAL / Filter.php
blob00c983d89c1647ece5cd8890c9e5739953d3f0af
1 <?php
3 define('PHPTAL_PRE_FILTER', 1);
4 define('PHPTAL_POST_FILTER', 2);
6 /**
7 * Interface for source filter.
9 * This interface may be used to implement input / output filters.
11 * If the template intermediate php code is up to date, pre filters won't be
12 * used on it.
14 * Output filters are only called on main template result.
17 * <?
18 * class MyFilter extends PHPTAL_Filter
19 * {
20 * function filter(&$tpl, $data, $mode)
21 * {
22 * // just to present $mode usage for input/output filters
23 * if ($mode == PHPTAL_POST_FILTER) {
24 * return PEAR::raiseError("MyFilter mustn't be used as a pre-filter');
25 * }
27 * // remove html comments from template source
28 * return preg_replace('/(<\!--.*?-->)/sm', '', $data);
29 * }
30 * }
32 * $tpl = PHPTAL('mytemplate.html');
33 * $tpl->addInputFilter( new MyFilter() );
34 * echo $tpl->execute();
36 * ?>
38 * @author Laurent Bedubourg <laurent.bedubourg@free.fr>
40 class PHPTAL_Filter
42 /**
43 * Filter some template source string.
45 * @param PHPTAL_Template $tpl
46 * The template which invoked this filter.
48 * @param string $data
49 * Data to filter.
51 * @param int $mode
52 * PHPTAL_PRE_FILTER | PHPTAL_POST_FILTER depending if this filter
53 * is registered as a pre-filter or as a post-filter.
56 function filter(&$tpl, $data, $mode)
58 return $data;