[geeklog-cvs] geeklog: New plugin API function PLG_pluginStateChange

geeklog-cvs at lists.geeklog.net geeklog-cvs at lists.geeklog.net
Thu Apr 16 09:38:10 EDT 2009


details:   http://project.geeklog.net/cgi-bin/hgweb.cgi/rev/deca272b55c8
changeset: 6947:deca272b55c8
user:      Dirk Haun <dirk at haun-online.de>
date:      Wed Apr 15 20:24:04 2009 +0200
description:
New plugin API function PLG_pluginStateChange

diffstat:

3 files changed, 56 insertions(+), 5 deletions(-)
public_html/admin/plugins.php |   23 ++++++++++++++++++-----
public_html/docs/history      |    1 +
system/lib-plugins.php        |   37 +++++++++++++++++++++++++++++++++++++

diffs (152 lines):

diff -r ee900b120ca7 -r deca272b55c8 public_html/admin/plugins.php
--- a/public_html/admin/plugins.php	Mon Apr 13 19:31:28 2009 +0200
+++ b/public_html/admin/plugins.php	Wed Apr 15 20:24:04 2009 +0200
@@ -35,7 +35,7 @@
 
 /**
 * This is the plugin administration page. Here you can install, uninstall,
-* enable, disable, and upload plugins.
+* upgrade, enable, disable, and upload plugins.
 *
 */
 
@@ -186,10 +186,12 @@
             PLG_enableStateChange($P['pi_name'], true);
             DB_change($_TABLES['plugins'], 'pi_enabled', 1,
                                            'pi_name', $P['pi_name']);
+            PLG_pluginStateChange($P['pi_name'], 'enabled');
         } elseif (!isset($pi_name_arr[$P['pi_name']]) && $P['pi_enabled'] == 1) {  // disable it
             PLG_enableStateChange($P['pi_name'], false);
             DB_change($_TABLES['plugins'], 'pi_enabled', 0,
                                            'pi_name', $P['pi_name']);
+            PLG_pluginStateChange($P['pi_name'], 'disabled');
         }
     }
 }
@@ -223,13 +225,18 @@
         $pi_gl_version = addslashes ($pi_gl_version);
         $pi_homepage = addslashes ($pi_homepage);
 
-        $currentState = DB_getItem ($_TABLES['plugins'], 'pi_enabled',
-                                    "pi_name= '{$pi_name}' LIMIT 1");
+        $currentState = DB_getItem($_TABLES['plugins'], 'pi_enabled',
+                                   "pi_name= '{$pi_name}' LIMIT 1");
         if ($currentState != $enabled) {
-            PLG_enableStateChange ($pi_name, ($enabled == 1) ? true : false);
+            PLG_enableStateChange($pi_name, ($enabled == 1) ? true : false);
         }
 
-        DB_save ($_TABLES['plugins'], 'pi_name, pi_version, pi_gl_version, pi_enabled, pi_homepage', "'$pi_name', '$pi_version', '$pi_gl_version', $enabled, '$pi_homepage'");
+        DB_save($_TABLES['plugins'], 'pi_name, pi_version, pi_gl_version, pi_enabled, pi_homepage', "'$pi_name', '$pi_version', '$pi_gl_version', $enabled, '$pi_homepage'");
+
+        if ($currentState != $enabled) {
+            PLG_pluginStateChange($pi_name,
+                                  ($enabled == 1) ? 'enabled' : 'disabled');
+        }
 
         $retval = COM_refresh($_CONF['site_admin_url'] . '/plugins.php?msg=28');
     } else {
@@ -357,6 +364,7 @@
     $result = PLG_upgrade($pi_name);
     if ($result > 0 ) {
         if ($result === TRUE) { // Catch returns that are just true/false
+            PLG_pluginStateChange($pi_name, 'upgraded');
             $retval .= COM_refresh($_CONF['site_admin_url']
                     . '/plugins.php?msg=60');
         } else {  // Plugin returned a message number
@@ -396,6 +404,8 @@
     }
 
     if (PLG_uninstall($pi_name)) {
+        PLG_pluginStateChange($pi_name, 'uninstalled');
+
         $retval = 45; // success msg
     } else {
         $retval = 95; // error msg
@@ -749,6 +759,7 @@
                             ($code_version != $pi_version)) {
                         $result = PLG_upgrade($dirname);
                         if ($result === true) {
+                            PLG_pluginStateChange($dirname, 'upgraded');
                             $msg = 60; // successfully updated
                         } else {
                             $msg_with_plugin_name = true;
@@ -763,6 +774,7 @@
             } elseif (file_exists($plg_path . 'autoinstall.php')) {
                 // if the plugin has an autoinstall.php, install it now
                 if (plugin_autoinstall($pi_name)) {
+                    PLG_pluginStateChange($pi_name, 'installed');
                     $msg = 44; // successfully installed
                 } else {
                     $msg = 72; // an error occured while installing the plugin
@@ -1207,6 +1219,7 @@
             $plugin = COM_applyFilter($_GET['plugin']);
         }
         if (plugin_autoinstall($plugin)) {
+            PLG_pluginStateChange($plugin, 'installed');
             $display .= COM_refresh($_CONF['site_admin_url']
                                     . '/plugins.php?msg=44');
         } else {
diff -r ee900b120ca7 -r deca272b55c8 public_html/docs/history
--- a/public_html/docs/history	Mon Apr 13 19:31:28 2009 +0200
+++ b/public_html/docs/history	Wed Apr 15 20:24:04 2009 +0200
@@ -11,6 +11,7 @@
 + Comment moderation and editable comments, by Jared Wenerd
 
 Other changes:
+- New plugin API function PLG_pluginStateChange [Dirk]
 - Fixed dropdown for the "censor mode", which has more than the two options
   offered previously (bug #0000692) [Mike, Maciej Cupial]
 - Slightly faster template class (feature request #0000760, patches provided
diff -r ee900b120ca7 -r deca272b55c8 system/lib-plugins.php
--- a/system/lib-plugins.php	Mon Apr 13 19:31:28 2009 +0200
+++ b/system/lib-plugins.php	Wed Apr 15 20:24:04 2009 +0200
@@ -353,6 +353,7 @@
 * @param    string      $type       Plugin name
 * @param    boolean     $enable     true if enabling, false if disabling
 * @return   boolean     Returns true on success otherwise false
+* @see      PLG_pluginStateChange
 *
 */
 function PLG_enableStateChange ($type, $enable)
@@ -2575,4 +2576,40 @@
     return PLG_callFunctionForOnePlugin($function, $args);
 }
 
+/**
+* Inform plugins when another plugin's state changed
+*
+* Unlike PLG_enableStateChange, this function is called after the state
+* change.
+*
+* NOTE: You can not rely on being informed of state changes for 'installed',
+* 'uninstalled', and 'upgraded', as these may happen in the plugin's install
+* script, outside of Geeklog's control.
+*
+* @param    string  $type   plugin name
+* @param    string  $status new status: 'enabled', 'disabled', 'installed', 'uninstalled', 'upgraded'
+* @return   void
+* @see      PLG_enableStateChange
+* @since    Geeklog 1.6.0
+*
+*/
+function PLG_pluginStateChange($type, $status)
+{
+    global $_PLUGINS;
+
+    $args[1] = $type;
+    $args[2] = $status;
+    foreach ($_PLUGINS as $pi_name) {
+        if ($pi_name != $type) {
+            $function = 'plugin_pluginstatechange_' . $pi_name;
+            PLG_callFunctionForOnePlugin($function, $args);
+        }
+    }
+
+    $function = 'CUSTOM_pluginstatechange';
+    if (function_exists($function)) {
+        $function($type, $status);
+    }
+}
+
 ?>



More information about the geeklog-cvs mailing list