plugins are now "reentrant" for free !
authorx2000habouzit <x2000habouzit>
Fri, 29 Oct 2004 01:51:32 +0000 (01:51 +0000)
committerx2000habouzit <x2000habouzit>
Fri, 29 Oct 2004 01:51:32 +0000 (01:51 +0000)
really nice hack (IMHO)

include/trombi.inc.php
include/xorg.plugin.inc.php

index 98f4ace..a225416 100644 (file)
@@ -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);
 
index 5185fd6..c7d0a09 100644 (file)
  *  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('&amp;',$get);
     }
+
+    /** need to be overriden.  */
+    function show () { return ''; }
 }
 
 ?>