| 1 | <?php |
| 2 | /*************************************************************************** |
| 3 | * Copyright (C) 2003-2006 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::v($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 | $args = array($this->_get_vars[0]=>$params); |
| 82 | } |
| 83 | |
| 84 | foreach ($_GET as $key=>$val) { |
| 85 | if ($key == 'n') { |
| 86 | continue; |
| 87 | } |
| 88 | if (in_array($key, $this->_get_vars) && array_key_exists($key, $args)) { |
| 89 | continue; |
| 90 | } |
| 91 | $get[] = urlencode($key) . '=' . urlencode($val); |
| 92 | } |
| 93 | |
| 94 | foreach ($this->_get_vars as $key) { |
| 95 | if (array_key_exists($key, $args)) { |
| 96 | if ($args[$key]) { |
| 97 | $get[] = urlencode($key) . '=' . urlencode($args[$key]); |
| 98 | } |
| 99 | } elseif (Get::has('key')) { |
| 100 | $get[] = urlencode($key) . '=' . urlencode(Get::v($key)); |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | return pl_self() . '?' . join('&', $get); |
| 105 | } |
| 106 | |
| 107 | // }}} |
| 108 | // {{{ function show() |
| 109 | |
| 110 | /** need to be overriden. */ |
| 111 | function show () |
| 112 | { return ''; } |
| 113 | |
| 114 | // }}} |
| 115 | } |
| 116 | |
| 117 | // }}} |
| 118 | |
| 119 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker: |
| 120 | ?> |