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