0337d704 |
1 | <?php |
2 | /*************************************************************************** |
5ddeb07c |
3 | * Copyright (C) 2003-2007 Polytechnique.org * |
0337d704 |
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., * |
19 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * |
20 | ***************************************************************************/ |
21 | |
0337d704 |
22 | /** |
23 | * XOrg Plugins class |
24 | * |
25 | * this class is used for plugins whose behavior depends only from the GET. |
26 | * |
27 | * @category XOrgCore |
28 | * @package XOrgCore |
29 | * @author Pierre Habouzit <pierre.habouzit@polytechnique.org> |
30 | * @access public |
31 | * @since Classe available since 0.9.2 |
32 | */ |
33 | class XOrgPlugin |
34 | { |
0337d704 |
35 | /** have to override, contents the fields names used to drive the plugin */ |
7b728d84 |
36 | var $_get_vars = array(); |
0337d704 |
37 | /** some polymorphism at low cost, may be used, or not */ |
38 | var $_callback; |
39 | |
0337d704 |
40 | /** constructor. |
41 | * the constructor override $_get_vars settings by prefixing the names with $prefix |
42 | */ |
43 | function XOrgPlugin($funcname='', $prefix='') |
44 | { |
45 | $this->_callback = $funcname; |
46 | $this->_prefix = $prefix; |
47 | foreach ($this->_get_vars as $key=>$val) { |
48 | $this->_get_vars[$key] = $prefix.$val; |
49 | } |
50 | } |
51 | |
0337d704 |
52 | /** transparent access to $_GET, wrt the right $prefix |
53 | */ |
54 | function get_value($key) |
55 | { |
5e2307dc |
56 | return Get::v($this->_prefix.$key); |
0337d704 |
57 | } |
58 | |
0337d704 |
59 | /** construct an url with the given parameters to drive the plugin. |
60 | * leave all other GET params alone |
61 | */ |
62 | function make_url($params) |
63 | { |
64 | $get = Array(); |
65 | $args = isset($params) ? $params : Array(); |
66 | |
67 | if (!is_array($args)) { |
7b728d84 |
68 | $args = array($this->_get_vars[0]=>$params); |
0337d704 |
69 | } |
70 | |
71 | foreach ($_GET as $key=>$val) { |
27472b85 |
72 | if ($key == 'n') { |
7b728d84 |
73 | continue; |
74 | } |
75 | if (in_array($key, $this->_get_vars) && array_key_exists($key, $args)) { |
0337d704 |
76 | continue; |
77 | } |
78 | $get[] = urlencode($key) . '=' . urlencode($val); |
79 | } |
80 | |
81 | foreach ($this->_get_vars as $key) { |
7b728d84 |
82 | if (array_key_exists($key, $args)) { |
0337d704 |
83 | if ($args[$key]) { |
84 | $get[] = urlencode($key) . '=' . urlencode($args[$key]); |
85 | } |
86 | } elseif (Get::has('key')) { |
5e2307dc |
87 | $get[] = urlencode($key) . '=' . urlencode(Get::v($key)); |
0337d704 |
88 | } |
89 | } |
90 | |
d1ebc57a |
91 | return pl_self() . '?' . join('&', $get); |
0337d704 |
92 | } |
93 | |
0337d704 |
94 | /** need to be overriden. */ |
95 | function show () |
abc68084 |
96 | { |
97 | return ''; |
98 | } |
0337d704 |
99 | } |
100 | |
0337d704 |
101 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker: |
102 | ?> |