import of Diogenes 0.9.18
[diogenes.git] / include / Plugin / Filter.php
1 <?php
2 /*
3 * Copyright (C) 2003-2004 Polytechnique.org
4 * http://opensource.polytechnique.org/
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21 // dependency on PEAR
22 require_once 'Plugin/Skel.php';
23
24 /** This class describes a Diogenes filter plugin.
25 */
26 class Diogenes_Plugin_Filter extends Diogenes_Plugin_Skel
27 {
28 /** Plugin name */
29 var $name = "Plugin_Filter";
30
31 /** Plugin description */
32 var $description = "Filter plugin skeleton";
33
34 /** Plugin version */
35 var $version = "0.1";
36
37 /** Plugin type : filter */
38 var $type = "filter";
39
40
41 /** Apply filtering to the input and return an output.
42 *
43 * The default implementation searches for a tag whose name matches
44 * the plugin name and replaces it by the output of the show() method.
45 *
46 * @param $input
47 */
48 function filter($input)
49 {
50 $name = $this->name;
51
52 $mask = "/(\{$name(\s+[^\}]*)?\})/";
53 $bits = preg_split($mask, $input, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
54 $output = "";
55 while($bit = array_shift($bits)) {
56 if (preg_match($mask, $bit)) {
57 $argstr = array_shift($bits);
58 $argbits = preg_split("/\s/", trim($argstr));
59 $args = array();
60 foreach($argbits as $argbit)
61 {
62 if (preg_match('/([a-zA-Z]+)=([\'"])(.*)\2$/', $argbit, $matches)) {
63 $args[$matches[1]] = $matches[3];
64 }
65 }
66 $output .= $this->show($args);
67 } else {
68 $output .= $bit;
69 }
70 }
71 return $output;
72 }
73
74
75 /** Show an instance of the plugin. This is called by filter() every time
76 * a tag representing the plugin is found.
77 */
78 function show()
79 {
80 return '';
81 }
82
83
84 }
85
86 ?>