Commit | Line | Data |
---|---|---|
6855525e JL |
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 | { | |
7bece6dd | 50 | global $page; |
6855525e JL |
51 | $name = $this->name; |
52 | ||
53 | $mask = "/(\{$name(\s+[^\}]*)?\})/"; | |
54 | $bits = preg_split($mask, $input, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE); | |
55 | $output = ""; | |
56 | while($bit = array_shift($bits)) { | |
7bece6dd JL |
57 | $matches = array(); |
58 | if (preg_match($mask, $bit, $matches)) { | |
59 | if ($matches[2]) | |
60 | { | |
61 | $argstr = array_shift($bits); | |
62 | } else { | |
63 | $argstr = ""; | |
64 | } | |
6855525e JL |
65 | $argbits = preg_split("/\s/", trim($argstr)); |
66 | $args = array(); | |
67 | foreach($argbits as $argbit) | |
68 | { | |
69 | if (preg_match('/([a-zA-Z]+)=([\'"])(.*)\2$/', $argbit, $matches)) { | |
70 | $args[$matches[1]] = $matches[3]; | |
71 | } | |
72 | } | |
73 | $output .= $this->show($args); | |
74 | } else { | |
75 | $output .= $bit; | |
76 | } | |
77 | } | |
78 | return $output; | |
79 | } | |
80 | ||
81 | ||
82 | /** Show an instance of the plugin. This is called by filter() every time | |
83 | * a tag representing the plugin is found. | |
84 | */ | |
85 | function show() | |
86 | { | |
87 | return ''; | |
88 | } | |
89 | ||
90 | ||
91 | } | |
92 | ||
93 | ?> |