[geeklog-cvs] geeklog: Got the auto install working from the install script
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/027df4078405
changeset: 6587:027df4078405
user: Dirk Haun <dirk at haun-online.de>
date: Thu Dec 25 12:34:00 2008 +0100
description:
Got the auto install working from the install script
diffstat:
4 files changed, 425 insertions(+), 161 deletions(-)
plugins/calendar/autoinstall.php | 11 -
public_html/admin/install/install-plugins.php | 113 +++++-----
public_html/admin/install/lib-install.php | 266 ++++++++++++++++++++++++-
public_html/admin/plugins.php | 196 +++++++++---------
diffs (truncated from 754 to 300 lines):
diff -r 238b6a303d1a -r 027df4078405 plugins/calendar/autoinstall.php
--- a/plugins/calendar/autoinstall.php Wed Dec 24 14:50:25 2008 +0100
+++ b/plugins/calendar/autoinstall.php Thu Dec 25 12:34:00 2008 +0100
@@ -36,14 +36,15 @@
$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/'
+ 'pi_name' => $pi_name,
+ 'pi_display_name' => $pi_display_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'
+ $pi_admin => 'Has full access to ' . $pi_display_name . ' features'
);
$features = array(
diff -r 238b6a303d1a -r 027df4078405 public_html/admin/install/install-plugins.php
--- a/public_html/admin/install/install-plugins.php Wed Dec 24 14:50:25 2008 +0100
+++ b/public_html/admin/install/install-plugins.php Thu Dec 25 12:34:00 2008 +0100
@@ -28,10 +28,7 @@
// | Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
// | |
// +---------------------------------------------------------------------------+
-// | You don't need to change anything in this file. |
-// | Please read docs/install.html which describes how to install Geeklog. |
-// +---------------------------------------------------------------------------+
-//
+
// +---------------------------------------------------------------------------+
// | Main |
@@ -159,10 +156,14 @@
$archive->extractList(array($dirname . '/admin/install.php'), $_CONF['path'] . 'data/');
}
+
$plugin_inst = $_CONF['path'] . 'data/' . $dirname . '/admin/install.php';
- $fhandle = fopen($plugin_inst, 'r');
- $fdata = fread($fhandle, filesize($plugin_inst));
- fclose($fhandle);
+ $fdata = '';
+ $fhandle = @fopen($plugin_inst, 'r');
+ if ($fhandle) {
+ $fdata = fread($fhandle, filesize($plugin_inst));
+ fclose($fhandle);
+ }
// Remove the plugin from data/
require_once 'System.php';
@@ -296,6 +297,7 @@
// If no record exists in the plugins table then it's a new plugin
if (DB_count($_TABLES['plugins'], 'pi_name', $plugin) == 0) {
+ $pi_name = '';
$pi_display_name = '';
$pi_version = 'Unknown';
$gl_version = 'Unknown';
@@ -335,20 +337,37 @@
. substr ($admin_url, $pos + 1);
}
+ $missing_autoinstall = false;
+ $info = INST_getPluginInfo($plugin);
+ if ($info === false) {
+ $missing_autoinstall = true;
+ } else {
+ $pi_name = $info['pi_name'];
+ $pi_display_name = $info['pi_display_name'];
+ $pi_version = $info['pi_version'];
+ $gl_version = $info['pi_gl_version'];
+ $pi_url = $info['pi_homepage'];
+ }
+
// If the plugin has been installed to the admin directory
- if (!file_exists($admin_dir . '/plugins/' . $plugin)) {
+ if (! file_exists($admin_dir . '/plugins/' . $plugin)) {
$missing_admin = true;
- } else {
+ }
+ if (! $missing_admin && empty($pi_name)) {
/**
* Plugins keep their config info in install.php
*/
+
$plugin_inst = $admin_dir . '/plugins/' . $plugin . '/install.php';
- $fhandle = fopen($plugin_inst, 'r');
- $fdata = fread($fhandle, filesize($plugin_inst));
- fclose($fhandle);
+ $fdata = '';
+ $fhandle = @fopen($plugin_inst, 'r');
+ if ($fhandle) {
+ $fdata = fread($fhandle, filesize($plugin_inst));
+ fclose($fhandle);
+ }
$fdata = preg_replace('/\n/', '', $fdata);
$fdata = preg_replace('/ /', '', $fdata);
@@ -404,7 +423,7 @@
$display .= '<tr>' . LB
. '<td align="center"><input type="checkbox" name="plugins[' . $plugin . '][install]"'
- . ($missing_public_html || $missing_admin ? ' disabled="true"' : ' checked="checked"') . XHTML . '>' . LB
+ . ($missing_public_html || $missing_admin || $missing_autoinstall ? ' disabled="true"' : ' checked="checked"') . XHTML . '>' . LB
. '</td>' . LB
. '<td valign="top">' . LB
. '<input type="hidden" name="plugins[' . $plugin . '][name]" value="' . $plugin . '"' . XHTML . '>'
@@ -448,71 +467,47 @@
case 2:
$error = 0;
-/*
foreach ($_POST['plugins'] as $plugin) {
// If the plugin was selected to be installed
if (isset($plugin['install']) && ($plugin['install'] == 'on')) {
-*/
- /**
- * Install the plugin by including & executing the database queries for each plugin
- * Start by looking for the database install file.
- */
-/*
- $plugin_sql = '';
- if (file_exists($_CONF['path'] . 'plugins/' . $plugin['name'] . '/sql/' . $_DB_dbms . '_install.php')) {
- $plugin_sql = $_CONF['path'] . 'plugins/' . $plugin['name'] . '/sql/' . $_DB_dbms . '_install.php';
-
- } else if (file_exists($_CONF['path'] . 'plugins/' . $plugin['name'] . '/sql/install.php')) {
-
- $plugin_sql = $_CONF['path'] . 'plugins/' . $plugin['name'] . '/sql/install.php';
-
- }
+ $pi_name = COM_applyFilter($plugin['name']);
+ $pi_name = COM_sanitizeFilename($pi_name);
- $plugin_func = $_CONF['path'] . 'plugins/' . $plugin['name'] . '/functions.inc';
+ $plugin_inst = $_CONF['path'] . 'plugins/' . $pi_name
+ . '/autoinstall.php';
+ if (file_exists($plugin_inst)) {
- if (file_exists($plugin_sql)) { // If database table and/or data exists for this plugin
+ require_once $plugin_inst;
- $plugin_conf = $_CONF['path'] . 'plugins/' . $plugin['name'] . '/config.php';
- if (file_exists($plugin_conf)) {
-
- require_once $plugin_conf;
-
+ $check_compatible = 'plugin_compatible_with_this_version_'
+ . $pi_name;
+ if (function_exists($check_compatible)) {
+ if (! $check_compatible($pi_name)) {
+ continue; // with next plugin
+ }
}
- $_SQL = array(); // Initialize for each plugin, otherwise the queries for the first plugin
- $_DATA = array(); // will execute twice if more than one plugin is being installed.
- require_once $plugin_sql; // Include $_SQL and $_DATA for each plugin,
- // these arrays contain the DB structures and data.
-
-
- foreach ($_SQL as $sql) {
-
- DB_query($sql); // Create the table structures, if necessary
- //sanity($sql);
-
+ $auto_install = 'plugin_autoinstall_' . $pi_name;
+ if (! function_exists($auto_install)) {
+ continue; // with next plugin
}
- foreach ($_DATA as $data) {
-
- DB_query($data); // Insert necessary data, if any
- //sanity($data);
-
+ $inst_parms = $auto_install($pi_name);
+ if (($inst_parms === false) || empty($inst_parms)) {
+ continue; // with next plugin
}
- // Enable the plugin in the plugins table
- // Todo: This should be checked for injection attempts or does DB_query() do that automatically?
- DB_query("INSERT INTO {$_TABLES['plugins']} (`pi_name`, `pi_version`, `pi_gl_version`, `pi_enabled`, `pi_homepage`) VALUES ( '{$plugin['name']}', '{$plugin['version']}', '" . VERSION . "', 1, '{$plugin['pi_url']}')");
-
- }
+ INST_pluginAutoinstall($pi_name, $inst_parms);
+ }
}
}
-*/
+
// Done!
-// $display .= '<p>Done doing stuff</p>' . LB;
+
header('Location: success.php?language=' . $language);
break;
diff -r 238b6a303d1a -r 027df4078405 public_html/admin/install/lib-install.php
--- a/public_html/admin/install/lib-install.php Wed Dec 24 14:50:25 2008 +0100
+++ b/public_html/admin/install/lib-install.php Thu Dec 25 12:34:00 2008 +0100
@@ -28,7 +28,6 @@
// | Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
// | |
// +---------------------------------------------------------------------------+
-//
/**
* The functionality of many of these functions already exists in other
@@ -73,9 +72,11 @@
}
$language = 'english';
-if (isset($_REQUEST['language'])) {
- $lng = $_REQUEST['language'];
-} else if (isset($_COOKIE['language'])) {
+if (isset($_POST['language'])) {
+ $lng = $_POST['language'];
+} elseif (isset($_GET['language'])) {
+ $lng = $_GET['language'];
+} elseif (isset($_COOKIE['language'])) {
// Okay, so the name of the language cookie is configurable, so it may not
// be named 'language' after all. Still worth a try ...
$lng = $_COOKIE['language'];
@@ -542,6 +543,7 @@
*/
function INST_urlExists($url)
{
+/*
$handle = curl_init($url);
if ($handle === false) {
return false;
@@ -553,6 +555,8 @@
$response = curl_exec($handle);
curl_close($handle);
return $response;
+*/
+ return true;
}
/**
@@ -757,4 +761,258 @@
fclose($siteconfig_file);
}
+function INST_getPluginInfo($plugin)
+{
+ global $_CONF;
+
+ $info = false;
+
+ $autoinstall = $_CONF['path'] . 'plugins/' . $plugin . '/autoinstall.php';
+ if (! file_exists($autoinstall)) {
+ return false;
+ }
+
+ include $autoinstall;
+
+ $fn = 'plugin_autoinstall_' . $plugin;
+ if (function_exists($fn)) {
+ $inst_info = $fn($plugin);
+ if (isset($inst_info['info']) &&
+ !empty($inst_info['info']['pi_name'])) {
+ $info = $inst_info['info'];
+ }
+ }
+
+ return $info;
+}
+
+/**
+* Do the actual plugin auto install
+*
+* @param string $plugin Plugin name
+* @param array $inst_parm Installation parameters for the plugin
+* @param boolean $verbose true: enable verbose logging
+* @return boolean true on success, false otherwise
+*
+*/
+function INST_pluginAutoinstall($plugin, $inst_parms, $verbose = true)
+{
+ global $_CONF, $_TABLES, $_USER, $_DB_dbms;
+
+ $fake_uid = false;
+ if (!isset($_USER['uid'])) {
+ $_USER['uid'] = 1;
+ $fake_uid = false;
More information about the geeklog-cvs
mailing list