[geeklog-cvs] geeklog: Introduce plugin load order. Feature request #1247.

geeklog-cvs at lists.geeklog.net geeklog-cvs at lists.geeklog.net
Thu Jan 27 11:28:41 EST 2011


changeset 8076:1e5441342ba0
url:  http://project.geeklog.net/cgi-bin/hgwebdir.cgi/geeklog/rev/1e5441342ba0
user: Rouslan Placella <rouslan at placella.com>
date: Wed Jan 26 15:50:29 2011 +0000
description:
Introduce plugin load order. Feature request #1247.

diffstat:

 language/english.php                 |   3 +
 public_html/admin/plugins.php        |  93 ++++++++++++++++++++++++++++++++++-
 sql/mssql_tableanddata.php           |   3 +-
 sql/mysql_tableanddata.php           |   1 +
 sql/pgsql_tableanddata.php           |   1 +
 sql/updates/mssql_1.7.1_to_1.8.0.php |   2 +
 sql/updates/mysql_1.7.1_to_1.8.0.php |   2 +
 sql/updates/pgsql_1.7.1_to_1.8.0.php |   2 +
 system/lib-admin.php                 |  15 +++++-
 system/lib-plugins.php               |   3 +-
 10 files changed, 117 insertions(+), 8 deletions(-)

diffs (282 lines):

diff -r addd1ffcf1fc -r 1e5441342ba0 language/english.php
--- a/language/english.php	Wed Jan 26 20:46:56 2011 +0100
+++ b/language/english.php	Wed Jan 26 15:50:29 2011 +0000
@@ -1088,6 +1088,9 @@
     40 => 'You can upload a plugin archive (.tar.gz, .tgz, .zip) directly here:',
     41 => 'Upload',
     42 => 'Click to update',
+    43 => 'Load Order',
+    44 => 'Move plugin up the load order',
+    45 => 'Move plugin down the load order',
 
     // to match the PHP error constants,
     // http://www.php.net/manual/en/features.file-upload.errors.php
diff -r addd1ffcf1fc -r 1e5441342ba0 public_html/admin/plugins.php
--- a/public_html/admin/plugins.php	Wed Jan 26 20:46:56 2011 +0100
+++ b/public_html/admin/plugins.php	Wed Jan 26 15:50:29 2011 +0000
@@ -2,19 +2,20 @@
 
 /* Reminder: always indent with 4 spaces (no tabs). */
 // +---------------------------------------------------------------------------+
-// | Geeklog 1.6                                                               |
+// | Geeklog 1.8                                                               |
 // +---------------------------------------------------------------------------+
 // | plugins.php                                                               |
 // |                                                                           |
 // | Geeklog plugin administration page.                                       |
 // +---------------------------------------------------------------------------+
-// | Copyright (C) 2000-2010 by the following authors:                         |
+// | Copyright (C) 2000-2011 by the following authors:                         |
 // |                                                                           |
 // | Authors: Tony Bibbs        - tony AT tonybibbs DOT com                    |
 // |          Mark Limburg      - mlimburg AT users DOT sourceforge DOT net    |
 // |          Jason Whittenburg - jwhitten AT securitygeeks DOT com            |
 // |          Dirk Haun         - dirk AT haun-online DOT de                   |
 // |          Matt West         - matt AT mattdanger DOT net                   |
+// |          Rouslan Placella  - rouslan {at} placella {dot} com              |
 // +---------------------------------------------------------------------------+
 // |                                                                           |
 // | This program is free software; you can redistribute it and/or             |
@@ -463,16 +464,19 @@
 
     require_once $_CONF['path_system'] . 'lib-admin.php';
 
+    reorderplugins();
+
     $retval = '';
     $header_arr = array(      # display 'text' and use table field 'field'
         array('text' => $LANG_ADMIN['edit'], 'field' => 'edit', 'sort' => false),
+        array('text' => $LANG32[43], 'field' => 'pi_load', 'sort' => true),
         array('text' => $LANG32[16], 'field' => 'pi_name', 'sort' => true),
         array('text' => $LANG32[17], 'field' => 'pi_version', 'sort' => true),
         array('text' => $LANG32[18], 'field' => 'pi_gl_version', 'sort' => true),
         array('text' => $LANG_ADMIN['enabled'], 'field' => 'pi_enabled', 'sort' => true)
     );
 
-    $defsort_arr = array('field' => 'pi_name', 'direction' => 'asc');
+    $defsort_arr = array('field' => 'pi_load', 'direction' => 'asc');
 
     $menu_arr = array (
                     array('url' => $_CONF['site_admin_url'],
@@ -495,7 +499,7 @@
 
     $query_arr = array(
         'table' => 'plugins',
-        'sql' => "SELECT pi_name, pi_version, pi_gl_version, "
+        'sql' => "SELECT pi_name, pi_version, pi_gl_version, pi_load, "
                 ."pi_enabled, pi_homepage FROM {$_TABLES['plugins']} WHERE 1=1",
         'query_fields' => array('pi_name'),
         'default_filter' => ''
@@ -518,6 +522,79 @@
 }
 
 /**
+* Re-orders all plugins by load order in increments of 10
+*
+* @return   void
+*
+*/
+function reorderplugins()
+{
+    global $_TABLES;
+
+    $pluginOrd = 10;
+    $stepNumber = 10;
+
+    $sql = "SELECT * FROM {$_TABLES['plugins']} ORDER BY pi_load ASC;";
+    $result = DB_query($sql);
+    while ($A = DB_fetchArray($result)) {
+        if ($A['pi_load'] != $pluginOrd) {  // only update incorrect ones
+            DB_query("UPDATE {$_TABLES['plugins']} SET pi_load = '{$pluginOrd}' WHERE pi_name = '{$A['pi_name']}'");
+        }
+        $pluginOrd += $stepNumber;
+    }
+}
+
+/**
+* Change the load order of a plugin
+*
+* @param    string  $pi_name    Name of the plugin
+* @param    mixed   $where      Where to move the plugin specified by $pi_name.
+*                               Valid values are "up" and "dn", which stand for
+*                               "Move 'Up' or 'Down' through the load order"
+*                               or any integer between 0 and 10000.
+* @return   void
+*
+*/
+function change_load_order($pi_name='', $where='')
+{
+    if (!empty($pi_name) && !empty($where)) {
+        global $_CONF, $_TABLES;
+        $q = "SELECT pi_load FROM {$_TABLES['plugins']} WHERE pi_name = '$pi_name'";
+        $q = DB_query($q);
+        if (DB_numRows($q) == 1) { // if the plugin exists
+            $query = '';
+            switch ($where) {
+                case ("up"):
+                    $A = DB_fetchArray($q);
+                    if ($A['pi_load'] > 10) { // no negative values
+                        $query = "UPDATE {$_TABLES['plugins']} SET pi_load = pi_load-11 WHERE pi_name = '{$pi_name}'";
+                    }
+                    break;
+
+                case ("dn"):
+                    $query = "UPDATE {$_TABLES['plugins']} SET pi_load = pi_load+11 WHERE pi_name = '{$pi_name}'";
+                    break;
+
+                default:
+                    if (is_numeric($where) && $where >= 0 && $where <= 10000) {
+                        $where = (int)$where;
+                        $query = "UPDATE {$_TABLES['plugins']} SET pi_load = {$where} WHERE pi_name = '{$pi_name}'";
+                    } else {
+                        COM_errorLog("plugins admin error: Attempt to assign an invalid load order '$where' to plugin '$pi_name'");
+                    }
+                    break;
+            }
+            if (!empty($query)) {
+                DB_query($query);
+                reorderplugins();
+            }
+        } else {
+            COM_errorLog("plugins admin error: Attempt to move a non existent plugin: $pi_name");
+        }
+    }
+}
+
+/**
  * Check if an error occured while uploading a file
  *
  * @param   array   $mFile  $_FILE['uploaded_file']
@@ -1281,6 +1358,14 @@
     $display .= plugineditor(COM_applyFilter($_GET['pi_name']));
     $display .= COM_siteFooter();
 
+} elseif ($mode == 'change_load_order') {
+    SEC_checkToken();
+    if (SEC_hasRights('plugin.edit')) {
+        change_load_order(COM_applyFilter($_GET['pi_name']), COM_applyFilter($_GET['where']));
+    }
+    echo COM_refresh($_CONF['site_admin_url'] . '/plugins.php');
+    exit;
+
 } elseif ((($mode == $LANG_ADMIN['save']) && !empty($LANG_ADMIN['save'])) && SEC_checkToken()) {
     $enabled = '';
     if (isset($_POST['enabled'])) {
diff -r addd1ffcf1fc -r 1e5441342ba0 sql/mssql_tableanddata.php
--- a/sql/mssql_tableanddata.php	Wed Jan 26 20:46:56 2011 +0100
+++ b/sql/mssql_tableanddata.php	Wed Jan 26 15:50:29 2011 +0000
@@ -242,7 +242,8 @@
     [pi_version] [varchar] (20) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
     [pi_gl_version] [varchar] (20) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
     [pi_enabled] [tinyint] NOT NULL ,
-    [pi_homepage] [varchar] (128) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL
+    [pi_homepage] [varchar] (128) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
+    [pi_load] [smallint] NOT NULL DEFAULT 10000
 ) ON [PRIMARY]
 ";
 
diff -r addd1ffcf1fc -r 1e5441342ba0 sql/mysql_tableanddata.php
--- a/sql/mysql_tableanddata.php	Wed Jan 26 20:46:56 2011 +0100
+++ b/sql/mysql_tableanddata.php	Wed Jan 26 15:50:29 2011 +0000
@@ -238,6 +238,7 @@
   pi_gl_version varchar(20) NOT NULL default '',
   pi_enabled tinyint(1) unsigned NOT NULL default '1',
   pi_homepage varchar(128) NOT NULL default '',
+  pi_load smallint(5) unsigned NOT NULL default '10000',
   INDEX plugins_enabled(pi_enabled),
   PRIMARY KEY  (pi_name)
 ) ENGINE=MyISAM
diff -r addd1ffcf1fc -r 1e5441342ba0 sql/pgsql_tableanddata.php
--- a/sql/pgsql_tableanddata.php	Wed Jan 26 20:46:56 2011 +0100
+++ b/sql/pgsql_tableanddata.php	Wed Jan 26 15:50:29 2011 +0000
@@ -235,6 +235,7 @@
   pi_gl_version varchar(20) NOT NULL default '',
   pi_enabled smallint  NOT NULL default '1',
   pi_homepage varchar(128) NOT NULL default '',
+  pi_load smallint NOT NULL default '10000',
   PRIMARY KEY  (pi_name)
   );
   CREATE INDEX plugins_enabled ON {$_TABLES['plugins']}(pi_enabled);
diff -r addd1ffcf1fc -r 1e5441342ba0 sql/updates/mssql_1.7.1_to_1.8.0.php
--- a/sql/updates/mssql_1.7.1_to_1.8.0.php	Wed Jan 26 20:46:56 2011 +0100
+++ b/sql/updates/mssql_1.7.1_to_1.8.0.php	Wed Jan 26 15:50:29 2011 +0000
@@ -1,5 +1,7 @@
 <?php
 
+// Enable plugin load order
+$_SQL[] = "ALTER TABLE {$_TABLES['plugins']} ADD [pi_load] [smallint] NOT NULL DEFAULT 10000";
 
 /**
  * Add new config options
diff -r addd1ffcf1fc -r 1e5441342ba0 sql/updates/mysql_1.7.1_to_1.8.0.php
--- a/sql/updates/mysql_1.7.1_to_1.8.0.php	Wed Jan 26 20:46:56 2011 +0100
+++ b/sql/updates/mysql_1.7.1_to_1.8.0.php	Wed Jan 26 15:50:29 2011 +0000
@@ -1,5 +1,7 @@
 <?php
 
+// Enable plugin load order
+$_SQL[] = "ALTER TABLE {$_TABLES['plugins']} ADD pi_load smallint(5) unsigned NOT NULL default '10000'";
 
 /**
  * Add new config options
diff -r addd1ffcf1fc -r 1e5441342ba0 sql/updates/pgsql_1.7.1_to_1.8.0.php
--- a/sql/updates/pgsql_1.7.1_to_1.8.0.php	Wed Jan 26 20:46:56 2011 +0100
+++ b/sql/updates/pgsql_1.7.1_to_1.8.0.php	Wed Jan 26 15:50:29 2011 +0000
@@ -1,5 +1,7 @@
 <?php
 
+// Enable plugin load order
+$_SQL[] = "ALTER TABLE {$_TABLES['plugins']} ADD COLUMN pi_load smallint NOT NULL DEFAULT (10000)::smallint";
 
 /**
  * Add new config options
diff -r addd1ffcf1fc -r 1e5441342ba0 system/lib-admin.php
--- a/system/lib-admin.php	Wed Jan 26 20:46:56 2011 +0100
+++ b/system/lib-admin.php	Wed Jan 26 15:50:29 2011 +0000
@@ -2,13 +2,13 @@
 
 /* Reminder: always indent with 4 spaces (no tabs). */
 // +---------------------------------------------------------------------------+
-// | Geeklog 1.7                                                               |
+// | Geeklog 1.8                                                               |
 // +---------------------------------------------------------------------------+
 // | lib-admin.php                                                             |
 // |                                                                           |
 // | Admin-related functions needed in more than one place.                    |
 // +---------------------------------------------------------------------------+
-// | Copyright (C) 2000-2010 by the following authors:                         |
+// | Copyright (C) 2000-2011 by the following authors:                         |
 // |                                                                           |
 // | Authors: Tony Bibbs         - tony AT tonybibbs DOT com                   |
 // |          Mark Limburg       - mlimburg AT users DOT sourceforge DOT net   |
@@ -1131,6 +1131,17 @@
         }
         break;
 
+    case 'pi_load':
+        $csrftok = '&' . CSRF_TOKEN . '=' . $token;
+        $style   = "style='vertical-align: text-bottom;'";
+        $upimg   = $_CONF['layout_url'] . '/images/admin/up.png';
+        $dnimg   = $_CONF['layout_url'] . '/images/admin/down.png';
+        $url     = $_CONF['site_admin_url'] . '/plugins.php?mode=change_load_order&pi_name=' . $A['pi_name'] . $csrftok . '&where=';
+        $retval .= COM_CreateLink( "<img $style alt='+' src='$upimg'" . XHTML . ">", $url . 'up' , array('title' => $LANG32[44]));
+        $retval .= ' ' . $A['pi_load'] . ' ';
+        $retval .= COM_CreateLink( "<img $style alt='-' src='$dnimg'" . XHTML . ">", $url . 'dn' , array('title' => $LANG32[45]));
+        break;
+
     case 'pi_enabled':
         $not_present = false;
         if ($A['pi_enabled'] == 1) {
diff -r addd1ffcf1fc -r 1e5441342ba0 system/lib-plugins.php
--- a/system/lib-plugins.php	Wed Jan 26 20:46:56 2011 +0100
+++ b/system/lib-plugins.php	Wed Jan 26 15:50:29 2011 +0000
@@ -63,7 +63,8 @@
 $PLG_buffered = false;
 
 // buffer enabled plugins
-$result = DB_query("SELECT pi_name FROM {$_TABLES['plugins']} WHERE pi_enabled = 1");
+$result = DB_query("SELECT pi_name FROM {$_TABLES['plugins']} WHERE pi_enabled = 1 ORDER BY pi_load ASC");
+
 /**
 * @global array List of all active plugins
 */



More information about the geeklog-cvs mailing list