From: x2000habouzit Date: Fri, 29 Oct 2004 01:51:32 +0000 (+0000) Subject: plugins are now "reentrant" for free ! X-Git-Tag: xorg/old~1145 X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;h=323c28ee774fc5e28ca4424c8c32ebd7082b6d7f;p=platal.git plugins are now "reentrant" for free ! really nice hack (IMHO) --- diff --git a/include/trombi.inc.php b/include/trombi.inc.php index 98f4ace..a225416 100644 --- a/include/trombi.inc.php +++ b/include/trombi.inc.php @@ -18,7 +18,7 @@ * Foundation, Inc., * * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * *************************************************************************** - $Id: trombi.inc.php,v 1.1 2004-10-28 20:28:41 x2000habouzit Exp $ + $Id: trombi.inc.php,v 1.2 2004-10-29 01:51:32 x2000habouzit Exp $ ***************************************************************************/ require_once('xorg.plugin.inc.php'); @@ -32,9 +32,12 @@ class Trombi extends XOrgPlugin { function setAdmin() { $this->admin = true; } function show() { + /* this point is nasty... but since show() is called from the template ... + * I can't see any more clever way to achieve that + */ global $page; - $offset = empty($_GET['offset']) ? 0 : intval($_GET['offset']); + $offset = $this->get_value('offset'); list($total, $list) = call_user_func($this->_callback, $offset, $this->limit); $page_max = intval(($total-1)/$this->limit); diff --git a/include/xorg.plugin.inc.php b/include/xorg.plugin.inc.php index 5185fd6..c7d0a09 100644 --- a/include/xorg.plugin.inc.php +++ b/include/xorg.plugin.inc.php @@ -18,17 +18,37 @@ * Foundation, Inc., * * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * *************************************************************************** - $Id: xorg.plugin.inc.php,v 1.1 2004-10-28 20:28:42 x2000habouzit Exp $ + $Id: xorg.plugin.inc.php,v 1.2 2004-10-29 01:51:32 x2000habouzit Exp $ ***************************************************************************/ + +/** class used for plugins whose behavior depends only from the GET. + */ class XOrgPlugin { + /** have to override, contents the fields names used to drive the plugin */ var $_get_vars = Array(); + /** some polymorphism at low cost, may be used, or not */ var $_callback; - - function XOrgPlugin($funcname) { + + /** constructor. + * the constructor override $_get_vars settings by prefixing the names with $prefix + */ + function XOrgPlugin($funcname='',$prefix='') { $this->_callback = $funcname; + $this->_prefix = $prefix; + foreach($this->_get_vars as $key=>$val) $this->_get_vars[$key] = $prefix.$val; + } + + /** transparent access to $_GET, wrt the right $prefix + */ + function get_value($key) { + if(empty($_GET[$this->_prefix.$key])) return ''; + return $_GET[$this->_prefix.$key]; } + /** construct an url with the given parameters to drive the plugin. + * leave all other GET params alone + */ function make_url($params) { $get = Array(); $args = empty($params) ? Array() : $params; @@ -57,6 +77,9 @@ class XOrgPlugin { return $_SERVER['PHP_SELF'] . '?' . join('&',$get); } + + /** need to be overriden. */ + function show () { return ''; } } ?>