f6fba1880fa1f14fa445702e58ff94dd4529ef83
2 /***************************************************************************
3 * Copyright (C) 2003-2006 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
::v($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 $args = array($this->_get_vars
[0]=>$params);
84 foreach ($_GET as $key=>$val) {
88 if (in_array($key, $this->_get_vars
) && array_key_exists($key, $args)) {
91 $get[] = urlencode($key) . '=' . urlencode($val);
94 foreach ($this->_get_vars
as $key) {
95 if (array_key_exists($key, $args)) {
97 $get[] = urlencode($key) . '=' . urlencode($args[$key]);
99 } elseif (Get
::has('key')) {
100 $get[] = urlencode($key) . '=' . urlencode(Get
::v($key));
104 return pl_self() . '?' . join('&', $get);
108 // {{{ function show()
110 /** need to be overriden. */
119 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker: