[geeklog-cvs] geeklog: First attempt of a more generic plugin install

geeklog-cvs at lists.geeklog.net geeklog-cvs at lists.geeklog.net
Mon Jan 5 05:06:07 EST 2009


details:   http://project.geeklog.net/cgi-bin/hgweb.cgi/rev/238b6a303d1a
changeset: 6586:238b6a303d1a
user:      Dirk Haun <dirk at haun-online.de>
date:      Wed Dec 24 14:50:25 2008 +0100
description:
First attempt of a more generic plugin install

diffstat:

3 files changed, 498 insertions(+), 468 deletions(-)
plugins/calendar/autoinstall.php               |  112 +++++
public_html/admin/plugins.php                  |  462 ++++++++++++++++++++----
public_html/admin/plugins/calendar/install.php |  392 --------------------

diffs (truncated from 1103 to 300 lines):

diff -r 2638dcb8940d -r 238b6a303d1a plugins/calendar/autoinstall.php
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/plugins/calendar/autoinstall.php	Wed Dec 24 14:50:25 2008 +0100
@@ -0,0 +1,112 @@
+<?php
+
+/* Reminder: always indent with 4 spaces (no tabs). */
+// +---------------------------------------------------------------------------+
+// | Calendar plugin 1.1 for Geeklog                                           |
+// +---------------------------------------------------------------------------+
+// | autoinstall.php                                                           |
+// |                                                                           |
+// | This file provides helper functions for the automatic plugin install.     |
+// +---------------------------------------------------------------------------+
+// | Copyright (C) 2008 by the following authors:                              |
+// |                                                                           |
+// | Authors: Dirk Haun         - dirk AT haun-online DOT de                   |
+// +---------------------------------------------------------------------------+
+// |                                                                           |
+// | This program is free software; you can redistribute it and/or             |
+// | modify it under the terms of the GNU General Public License               |
+// | as published by the Free Software Foundation; either version 2            |
+// | of the License, or (at your option) any later version.                    |
+// |                                                                           |
+// | This program is distributed in the hope that it will be useful,           |
+// | but WITHOUT ANY WARRANTY; without even the implied warranty of            |
+// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             |
+// | GNU General Public License for more details.                              |
+// |                                                                           |
+// | You should have received a copy of the GNU General Public License         |
+// | along with this program; if not, write to the Free Software Foundation,   |
+// | Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.           |
+// |                                                                           |
+// +---------------------------------------------------------------------------+
+
+function plugin_autoinstall_calendar($pi_name)
+{
+    $pi_name         = 'calendar';
+    $pi_display_name = 'Calendar';
+    $pi_admin        = $pi_display_name . ' Admin';
+
+    $info = array(
+        'pi_name'       => $pi_name,
+        'pi_version'    => '1.1.0',
+        'pi_gl_version' => '1.6.0',
+        'pi_homepage'   => 'http://www.geeklog.net/'
+    );
+
+    $groups = array(
+        $pi_admin => 'Has full access to ' . $pi_name . ' features'
+    );
+
+    $features = array(
+        $pi_name . '.moderate'  => 'Ability to moderate pending events',
+        $pi_name . '.edit'      => 'Access to event editor',
+        $pi_name . '.submit'    => 'May skip the event submission queue'
+    );
+
+    $mappings = array(
+        $pi_name . '.moderate'  => array($pi_admin),
+        $pi_name . '.edit'      => array($pi_admin),
+        $pi_name . '.submit'    => array($pi_admin)
+    );
+
+    $inst_parms = array(
+        'info'      => $info,
+        'groups'    => $groups,
+        'features'  => $features,
+        'mappings'  => $mappings
+    );
+
+    return $inst_parms;
+}
+
+function plugin_load_configuration_calendar($pi_name)
+{
+    global $_CONF, $base_path;
+
+    $base_path = $_CONF['path'] . 'plugins/' . $pi_name . '/';
+
+    require_once $_CONF['path_system'] . 'classes/config.class.php';
+    require_once $base_path . 'install_defaults.php';
+
+    return plugin_initconfig_calendar();
+}
+
+function plugin_postinstall_calendar($pi_name)
+{
+    return true;
+}
+
+function plugin_compatible_with_this_version_calendar($pi_name)
+{
+    if (function_exists('COM_printUpcomingEvents')) {
+        // if this function exists, then someone's trying to install the
+        // plugin on Geeklog 1.4.0 or older - sorry, but that won't work
+        return false;
+    }   
+    
+    if (!function_exists('MBYTE_strpos')) {
+        // the plugin requires the multi-byte functions
+        return false; 
+    }   
+    
+    if (!function_exists('SEC_createToken')) {
+        return false;
+    }
+
+    if (!function_exists('COM_showMessageText')) {
+        return false;
+    }
+
+    return true;
+}
+
+?>
diff -r 2638dcb8940d -r 238b6a303d1a public_html/admin/plugins.php
--- a/public_html/admin/plugins.php	Mon Dec 22 15:11:36 2008 +0100
+++ b/public_html/admin/plugins.php	Wed Dec 24 14:50:25 2008 +0100
@@ -99,7 +99,7 @@
 
     $plg_templates = new Template($_CONF['path_layout'] . 'admin/plugins');
     $plg_templates->set_file('editor', 'editor.thtml');
-    $plg_templates->set_var( 'xhtml', XHTML );
+    $plg_templates->set_var('xhtml', XHTML);
     $plg_templates->set_var('site_url', $_CONF['site_url']);
     $plg_templates->set_var('site_admin_url', $_CONF['site_admin_url']);
     $plg_templates->set_var('layout_url', $_CONF['layout_url']);
@@ -161,20 +161,21 @@
 * @return   void
 *
 */
-function changePluginStatus ($pi_name_arr)
+function changePluginStatus($pi_name_arr)
 {
     global $_TABLES, $_DB_table_prefix;
+
     // first, get a list of all plugins
-    $rst = DB_query ("SELECT pi_name, pi_enabled FROM {$_TABLES['plugins']}");
+    $rst = DB_query("SELECT pi_name, pi_enabled FROM {$_TABLES['plugins']}");
     $plg_count = DB_numRows($rst);
-    for ($i=0; $i<$plg_count; $i++) { // iterate and check/change match with array
+    for ($i = 0; $i < $plg_count; $i++) { // iterate and check/change match with array
         $P = DB_fetchArray($rst);
-        if (isset($pi_name_arr[$P['pi_name']]) && $P['pi_enabled'] == 0) { // enable it
-            PLG_enableStateChange ($P['pi_name'], true);
-            DB_query ("UPDATE {$_TABLES['plugins']} SET pi_enabled = '1' WHERE pi_name = '{$P['pi_name']}'");
-        } else if (!isset($pi_name_arr[$P['pi_name']]) && $P['pi_enabled'] == 1) {  // disable it
-            PLG_enableStateChange ($P['pi_name'], false);
-            DB_query ("UPDATE {$_TABLES['plugins']} SET pi_enabled = '0' WHERE pi_name = '{$P['pi_name']}'");
+        if (isset($pi_name_arr[$P['pi_name']]) && ($P['pi_enabled'] == 0)) { // enable it
+            PLG_enableStateChange($P['pi_name'], true);
+            DB_query("UPDATE {$_TABLES['plugins']} SET pi_enabled = 1 WHERE pi_name = '{$P['pi_name']}'");
+        } elseif (!isset($pi_name_arr[$P['pi_name']]) && $P['pi_enabled'] == 1) {  // disable it
+            PLG_enableStateChange($P['pi_name'], false);
+            DB_query("UPDATE {$_TABLES['plugins']} SET pi_enabled = 0 WHERE pi_name = '{$P['pi_name']}'");
         }
     }
 }
@@ -218,7 +219,7 @@
 
         $retval = COM_refresh($_CONF['site_admin_url'] . '/plugins.php?msg=28');
     } else {
-        $retval .= COM_siteHeader ('menu', $LANG32[13]);
+        $retval .= COM_siteHeader('menu', $LANG32[13]);
         $retval .= COM_startBlock ($LANG32[13], '',
                             COM_getBlockTemplate ('_msg_block', 'header'));
         $retval .= COM_errorLog ('error saving plugin, no pi_name provided', 1);
@@ -233,52 +234,73 @@
 /**
 * Creates list of uninstalled plugins (if any) and offers install link to them.
 *
-* @return   string      HTML containing list of uninstalled plugins
+* @param    strint  $token  security token to use in list
+* @return   string          HTML containing list of uninstalled plugins
 *
 */
-function show_newplugins ($token)
+function show_newplugins($token)
 {
     global $_CONF, $_TABLES, $LANG32;
-    require_once( $_CONF['path_system'] . 'lib-admin.php' );
-    $plugins = array ();
+
+    require_once $_CONF['path_system'] . 'lib-admin.php';
+
+    $plugins = array();
     $plugins_dir = $_CONF['path'] . 'plugins/';
-    $fd = opendir ($plugins_dir);
+    $fd = opendir($plugins_dir);
     $index = 1;
     $retval = '';
     $data_arr = array();
-    while (($dir = @readdir ($fd)) == TRUE) {
+    while (($dir = @readdir($fd)) == TRUE) {
         if (($dir <> '.') && ($dir <> '..') && ($dir <> 'CVS') &&
                 (substr($dir, 0 , 1) <> '.') && is_dir($plugins_dir . $dir)) {
             clearstatcache ();
             // Check and see if this plugin is installed - if there is a record.
             // If not then it's a new plugin
-            if (DB_count($_TABLES['plugins'],'pi_name',$dir) == 0) {
+            if (DB_count($_TABLES['plugins'], 'pi_name', $dir) == 0) {
+                $plugin_ok = false;
+                $plugin_new_style = false;
                 // additionally, check if a 'functions.inc' exists
-                if (file_exists ($plugins_dir . $dir . '/functions.inc')) {
-                    // and finally, since we're going to link to it, check if
-                    // an install script exists
-                    $adminurl = $_CONF['site_admin_url'];
-                    if (strrpos ($adminurl, '/') == strlen ($adminurl)) {
-                        $adminurl = substr ($adminurl, 0, -1);
+                if (file_exists($plugins_dir . $dir . '/functions.inc')) {
+                    // new plugins will have a autoinstall.php
+                    if (file_exists($plugins_dir . $dir . '/autoinstall.php')) {
+                        $plugin_ok = true;
+                        $plugin_new_style = true;
+                    } else {
+                        // and finally, since we're going to link to it, check
+                        // if an install script exists
+                        $adminurl = $_CONF['site_admin_url'];
+                        if (strrpos($adminurl, '/') == strlen($adminurl)) {
+                            $adminurl = substr($adminurl, 0, -1);
+                        }
+                        $pos = strrpos($adminurl, '/');
+                        if ($pos === false) {
+                            // didn't work out - use the URL
+                            $admindir = $_CONF['site_admin_url'];
+                        } else {
+                            $admindir = $_CONF['path_html']
+                                      . substr($adminurl, $pos + 1);
+                        }
+                        $fh = @fopen($admindir . '/plugins/' . $dir
+                                     . '/install.php', 'r');
+                        if ($fh) {
+                            fclose($fh);
+                            $plugin_ok = true;
+                            $plugin_new_style = false;
+                        }
                     }
-                    $pos = strrpos ($adminurl, '/');
-                    if ($pos === false) {
-                        // didn't work out - use the URL
-                        $admindir = $_CONF['site_admin_url'];
-                    } else {
-                        $admindir = $_CONF['path_html']
-                                  . substr ($adminurl, $pos + 1);
-                    }
-                    $fh = @fopen ($admindir . '/plugins/' . $dir
-                        . '/install.php', 'r');
-                    if ($fh) {
-                        fclose ($fh);
+                    if ($plugin_ok) {
+                        if ($plugin_new_style) {
+                            $url = $_CONF['site_admin_url'] . '/plugins.php'
+                                 . '?mode=autoinstall&plugin=' . $dir;
+                        } else {
+                            $url = $_CONF['site_admin_url'] . '/plugins/' . $dir
+                                 . '/install.php?action=install';
+                        }
+                        $url .= '&' . CSRF_TOKEN . '=' . $token;
                         $data_arr[] = array(
-                            'pi_name' => $dir,
-                            'number' => $index,
-                            'install_link'=> COM_createLink($LANG32[22],
-                                $_CONF['site_admin_url'] . '/plugins/' . $dir
-                                . '/install.php?action=install&'.CSRF_TOKEN.'='.$token)
+                            'pi_name'      => $dir,
+                            'number'       => $index,
+                            'install_link' => COM_createLink($LANG32[22], $url)
                         );
                         $index++;
                     }
@@ -294,8 +316,8 @@
     );
 
     $text_arr = array('title' => $LANG32[14]);
-    $retval .= ADMIN_simpleList('', $header_arr, $text_arr,
-                           $data_arr);
+    $retval .= ADMIN_simpleList('', $header_arr, $text_arr, $data_arr);
+
     return $retval;
 }
 
@@ -306,27 +328,25 @@
 * @return             string   HTML for error or success message
 *
 */
-function do_update ($pi_name)
+function do_update($pi_name)
 {
-    global $_CONF, $LANG32, $LANG08, $MESSAGE, $_IMAGE_TYPE;
+    global $_CONF, $LANG32;
 
     $retval = '';
 
-    if (strlen ($pi_name) == 0) {
-        $retval .= COM_startBlock ($LANG32[13], '',
-                            COM_getBlockTemplate ('_msg_block', 'header'));
-        $retval .= COM_errorLog ($LANG32[12]);
-        $retval .= COM_endBlock (COM_getBlockTemplate ('_msg_block', 'footer'));



More information about the geeklog-cvs mailing list