2 /***************************************************************************
3 * Copyright (C) 2003-2004 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
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. *
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. *
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 *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
22 // {{{ class XOrgPlugin
27 * this class is used for plugins whose behavior depends only from the GET.
31 * @author Pierre Habouzit <pierre.habouzit@polytechnique.org>
33 * @since Classe available since 0.9.2
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 */
45 // {{{ function XOrgPlugin()
48 * the constructor override $_get_vars settings by prefixing the names with $prefix
50 function XOrgPlugin($funcname='', $prefix='')
52 $this->_callback
= $funcname;
53 $this->_prefix
= $prefix;
54 foreach ($this->_get_vars
as $key=>$val) {
55 $this->_get_vars
[$key] = $prefix.$val;
60 // {{{ function get_value()
62 /** transparent access to $_GET, wrt the right $prefix
64 function get_value($key)
66 return Get
::get($this->_prefix
.$key);
70 // {{{ function make_url()
72 /** construct an url with the given parameters to drive the plugin.
73 * leave all other GET params alone
75 function make_url($params)
78 $args = isset($params) ?
$params : Array();
80 if (!is_array($args)) {
81 if (count($this->_get_vars
)!=1) {
82 return "<p class='erreur'>params should be an array</p>";
84 $args = Array($this->_get_vars
[0]=>$params);
88 foreach ($_GET as $key=>$val) {
89 if (in_array($key,$this->_get_vars
) && array_key_exists($key,$args)) {
92 $get[] = urlencode($key) . '=' . urlencode($val);
95 foreach ($this->_get_vars
as $key) {
96 if (array_key_exists($key,$args)) {
98 $get[] = urlencode($key) . '=' . urlencode($args[$key]);
100 } elseif (Get
::has('key')) {
101 $get[] = urlencode($key) . '=' . urlencode(Get
::get($key));
105 return $_SERVER['PHP_SELF'] . '?' . join('&',$get);
109 // {{{ function show()
111 /** need to be overriden. */
120 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker: