aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrvelices <rv-github@modusoptimus.com>2008-03-06 02:29:29 +0000
committerrvelices <rv-github@modusoptimus.com>2008-03-06 02:29:29 +0000
commitd96b476bd8dc2c38c68294a82c786c9d2a32d288 (patch)
treed199be649c85722649cacad548196a9fd643956b
parent37446caa5c362d998be6e1343995a5a7548a98a6 (diff)
- plugins.php does only the tabsheet - nothing else
- need to review plugins_update.php upgrade action git-svn-id: http://piwigo.org/svn/trunk@2255 68402e56-0260-453c-a942-63ccdbb3a9ee
-rw-r--r--admin/include/functions_plugins.inc.php98
-rw-r--r--admin/plugins.php162
-rw-r--r--admin/plugins_list.php175
-rw-r--r--admin/plugins_new.php18
-rw-r--r--admin/plugins_update.php15
5 files changed, 279 insertions, 189 deletions
diff --git a/admin/include/functions_plugins.inc.php b/admin/include/functions_plugins.inc.php
index b51a22fd2..3e79988fd 100644
--- a/admin/include/functions_plugins.inc.php
+++ b/admin/include/functions_plugins.inc.php
@@ -85,6 +85,93 @@ function get_fs_plugins()
}
/**
+ * Activates a plugin. It will be loaded only on the next page ...
+ * @param string $plugin_id the plugin to activate
+ * @param array $errors errors to be returned
+ */
+function activate_plugin($plugin_id, &$errors)
+{
+ // the plugin_id must exist in the DB as inactive
+ $db_plugins = get_db_plugins('', $plugin_id);
+ if (!empty($db_plugins))
+ {
+ $crt_db_plugin = $db_plugins[0];
+ if ($crt_db_plugin['state'] != 'inactive')
+ {
+ array_push($errors, 'CANNOT ACTIVATE - INVALID CURRENT STATE ' . $crt_db_plugin['state']);
+ return false;
+ }
+ }
+ else
+ {
+ array_push($errors, 'CANNOT ACTIVATE - NOT INSTALLED');
+ return false;
+ }
+
+ // now try to activate it
+ $file_to_include = PHPWG_PLUGINS_PATH . $plugin_id . '/maintain.inc.php';
+ if (file_exists($file_to_include))
+ {
+ include_once($file_to_include);
+ if (function_exists('plugin_activate'))
+ {
+ plugin_activate($plugin_id, $crt_db_plugin['version'], $errors);
+ }
+ }
+ if (empty($errors))
+ {
+ $query = '
+UPDATE ' . PLUGINS_TABLE . ' SET state="active" WHERE id="' . $plugin_id . '"';
+ pwg_query($query);
+ return true;
+ }
+ return false;
+}
+
+
+/**
+ * Deactivates a plugin. It will be unloaded only on the next page ...
+ * @param string $plugin_id the plugin to activate
+ * @param array $errors errors to be returned
+ */
+function deactivate_plugin($plugin_id, &$errors)
+{
+ // the plugin_id must exist in the DB as inactive
+ $db_plugins = get_db_plugins('', $plugin_id);
+ if (!empty($db_plugins))
+ {
+ $crt_db_plugin = $db_plugins[0];
+ if ($crt_db_plugin['state'] != 'active')
+ {
+ array_push($errors, 'CANNOT DEACTIVATE - INVALID CURRENT STATE ' . $crt_db_plugin['state']);
+ return false;
+ }
+ }
+ else
+ {
+ array_push($errors, 'CANNOT DEACTIVATE - NOT INSTALLED');
+ return false;
+ }
+
+ // now try to deactivate it
+ $query = '
+UPDATE ' . PLUGINS_TABLE . ' SET state="inactive" WHERE id="' . $plugin_id . '"';
+ pwg_query($query);
+
+ $file_to_include = PHPWG_PLUGINS_PATH . $plugin_id . '/maintain.inc.php';
+ if (file_exists($file_to_include))
+ {
+ include_once($file_to_include);
+ if (function_exists('plugin_deactivate'))
+ {
+ plugin_deactivate($plugin_id);
+ }
+ }
+ return true;
+}
+
+
+/**
* Retrieves an url for a plugin page.
* @param string file - php script full name
*/
@@ -287,6 +374,7 @@ function extension_name_compare($a, $b)
{
return strcmp(strtolower($a['ext_name']), strtolower($b['ext_name']));
}
+
function extension_author_compare($a, $b)
{
$r = strcmp(strtolower($a['author']), strtolower($b['author']));
@@ -294,4 +382,14 @@ function extension_author_compare($a, $b)
else return $r;
}
+function plugin_author_compare($a, $b)
+{
+ return strcasecmp( $a['author'], $b['author']);
+}
+
+function plugin_version_compare($a, $b)
+{
+ return version_compare( $a['version'], $b['version']);
+}
+
?> \ No newline at end of file
diff --git a/admin/plugins.php b/admin/plugins.php
index a4260513b..2206be228 100644
--- a/admin/plugins.php
+++ b/admin/plugins.php
@@ -31,8 +31,6 @@ if( !defined("PHPWG_ROOT_PATH") )
include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php');
check_status(ACCESS_ADMINISTRATOR);
-$my_base_url = PHPWG_ROOT_PATH.'admin.php?page=plugins';
-
// +-----------------------------------------------------------------------+
// | Sections definitions |
@@ -46,7 +44,7 @@ else
$page['section'] = $_GET['section'];
}
-$tab_link = $my_base_url . '&amp;section=';
+$tab_link = get_root_url().'admin.php?page=plugins&amp;section=';
// TabSheet
$tabsheet = new tabsheet();
@@ -59,168 +57,10 @@ $tabsheet->select($page['section']);
// Assign tabsheet to template
$tabsheet->assign();
-$my_base_url .= '&section=' . $page['section'];
-
-
-// +-----------------------------------------------------------------------+
-// | perform requested actions |
-// +-----------------------------------------------------------------------+
-if (isset($_GET['action']) and isset($_GET['plugin']) and !is_adviser())
-{
- $plugin_id = $_GET['plugin'];
- $crt_db_plugin = get_db_plugins('', $plugin_id);
- if (!empty($crt_db_plugin))
- {
- $crt_db_plugin = $crt_db_plugin[0];
- }
- else
- {
- unset($crt_db_plugin);
- }
-
- $errors = array();
- $file_to_include = PHPWG_PLUGINS_PATH . $plugin_id . '/maintain.inc.php';
-
- switch ($_GET['action'])
- {
- case 'install':
- if (!empty($crt_db_plugin))
- {
- array_push($errors, 'CANNOT install - ALREADY INSTALLED');
- break;
- }
- $fs_plugins = get_fs_plugins();
- if (!isset($fs_plugins[$plugin_id]))
- {
- array_push($errors, 'CANNOT install - NO SUCH PLUGIN');
- break;
- }
- if (file_exists($file_to_include))
- {
- include_once($file_to_include);
- if (function_exists('plugin_install'))
- {
- plugin_install($plugin_id, $fs_plugins[$plugin_id]['version'], $errors);
- }
- }
- if (empty($errors))
- {
- $query = '
-INSERT INTO ' . PLUGINS_TABLE . ' (id,version) VALUES ("'
-. $plugin_id . '","' . $fs_plugins[$plugin_id]['version'] . '"
-)';
- pwg_query($query);
- }
- break;
-
- case 'activate':
- if (!isset($crt_db_plugin))
- {
- array_push($errors, 'CANNOT ' . $_GET['action'] . ' - NOT INSTALLED');
- break;
- }
- if ($crt_db_plugin['state'] != 'inactive')
- {
- array_push($errors, 'invalid current state ' . $crt_db_plugin['state']);
- break;
- }
- if (file_exists($file_to_include))
- {
- include_once($file_to_include);
- if (function_exists('plugin_activate'))
- {
- plugin_activate($plugin_id, $crt_db_plugin['version'], $errors);
- }
- }
- if (empty($errors))
- {
- $query = '
-UPDATE ' . PLUGINS_TABLE . ' SET state="active" WHERE id="' . $plugin_id . '"';
- pwg_query($query);
- }
- break;
-
- case 'deactivate':
- if (!isset($crt_db_plugin))
- {
- die ('CANNOT ' . $_GET['action'] . ' - NOT INSTALLED');
- }
- if ($crt_db_plugin['state'] != 'active')
- {
- die('invalid current state ' . $crt_db_plugin['state']);
- }
- $query = '
-UPDATE ' . PLUGINS_TABLE . ' SET state="inactive" WHERE id="' . $plugin_id . '"';
- pwg_query($query);
- if (file_exists($file_to_include))
- {
- include_once($file_to_include);
- if (function_exists('plugin_deactivate'))
- {
- plugin_deactivate($plugin_id);
- }
- }
- break;
-
- case 'uninstall':
- if (!isset($crt_db_plugin))
- {
- die ('CANNOT ' . $_GET['action'] . ' - NOT INSTALLED');
- }
- $query = '
-DELETE FROM ' . PLUGINS_TABLE . ' WHERE id="' . $plugin_id . '"';
- pwg_query($query);
- if (file_exists($file_to_include))
- {
- include_once($file_to_include);
- if (function_exists('plugin_uninstall'))
- {
- plugin_uninstall($plugin_id);
- }
- }
- break;
-
- case 'delete':
- if (!empty($crt_db_plugin))
- {
- array_push($errors, 'CANNOT delete - PLUGIN IS INSTALLED');
- }
- elseif (!deltree(PHPWG_PLUGINS_PATH . $plugin_id))
- {
- send_to_trash(PHPWG_PLUGINS_PATH . $plugin_id);
- }
- break;
- }
- if (empty($errors))
- {
- $my_base_url .= isset($_GET['upgrade']) ?
- '&plugin='.$plugin_id.'&upgrade='.$_GET['upgrade'].'&reactivate=true':'';
-
- $my_base_url .= isset($_GET['upgradestatus']) ?
- '&plugin='.$plugin_id.'&upgradestatus='.$_GET['upgradestatus']:'';
-
- redirect($my_base_url);
- }
- else
- {
- $page['errors'] = array_merge($page['errors'], $errors);
- }
-}
-
// +-----------------------------------------------------------------------+
// | start template output |
// +-----------------------------------------------------------------------+
-$fs_plugins = get_fs_plugins();
-uasort($fs_plugins, 'name_compare');
-$db_plugins = get_db_plugins();
-$db_plugins_by_id = array();
-foreach ($db_plugins as $db_plugin) {
- $db_plugins_by_id[$db_plugin['id']] = $db_plugin;
-}
include(PHPWG_ROOT_PATH.'admin/plugins_'.$page['section'].'.php');
-
-$template->assign_var_from_handle('ADMIN_CONTENT', 'plugins');
-
?> \ No newline at end of file
diff --git a/admin/plugins_list.php b/admin/plugins_list.php
index 7e7a153cb..3c6dfd512 100644
--- a/admin/plugins_list.php
+++ b/admin/plugins_list.php
@@ -28,29 +28,163 @@ if( !defined("PHPWG_ROOT_PATH") )
die ("Hacking attempt!");
}
-$template->set_filenames(array('plugins' => 'admin/plugins_list.tpl'));
-//----------------------------------------------------------------sort options
-$order = isset($_GET['order']) ? $_GET['order'] : 'name';
+// +-----------------------------------------------------------------------+
+// | perform requested actions |
+// +-----------------------------------------------------------------------+
+if (isset($_GET['action']) and isset($_GET['plugin']) and !is_adviser())
+{
+ $plugin_id = $_GET['plugin'];
+ $crt_db_plugin = get_db_plugins('', $plugin_id);
+ if (!empty($crt_db_plugin))
+ {
+ $crt_db_plugin = $crt_db_plugin[0];
+ }
+ else
+ {
+ unset($crt_db_plugin);
+ }
-$template->assign('order',
- array(htmlentities($my_base_url.'&order=name') => l10n('Name'),
- htmlentities($my_base_url.'&order=status') => l10n('Status')
- )
- );
-
-$template->assign('selected', htmlentities($my_base_url.'&order=').$order);
+ $errors = array();
+ $file_to_include = PHPWG_PLUGINS_PATH . $plugin_id . '/maintain.inc.php';
+
+ switch ($_GET['action'])
+ {
+ case 'install':
+ if (!empty($crt_db_plugin))
+ {
+ array_push($errors, 'CANNOT install - ALREADY INSTALLED');
+ break;
+ }
+ $fs_plugins = get_fs_plugins();
+ if (!isset($fs_plugins[$plugin_id]))
+ {
+ array_push($errors, 'CANNOT install - NO SUCH PLUGIN');
+ break;
+ }
+ if (file_exists($file_to_include))
+ {
+ include_once($file_to_include);
+ if (function_exists('plugin_install'))
+ {
+ plugin_install($plugin_id, $fs_plugins[$plugin_id]['version'], $errors);
+ }
+ }
+ if (empty($errors))
+ {
+ $query = '
+INSERT INTO ' . PLUGINS_TABLE . ' (id,version) VALUES ("'
+. $plugin_id . '","' . $fs_plugins[$plugin_id]['version'] . '"
+)';
+ pwg_query($query);
+ }
+ break;
+
+ case 'activate':
+ activate_plugin($plugin_id, $errors);
+ break;
+ case 'deactivate':
+ deactivate_plugin($plugin_id, $errors);
+ break;
+
+ case 'uninstall':
+ if (!isset($crt_db_plugin))
+ {
+ die ('CANNOT ' . $_GET['action'] . ' - NOT INSTALLED');
+ }
+ $query = '
+DELETE FROM ' . PLUGINS_TABLE . ' WHERE id="' . $plugin_id . '"';
+ pwg_query($query);
+ if (file_exists($file_to_include))
+ {
+ include_once($file_to_include);
+ if (function_exists('plugin_uninstall'))
+ {
+ plugin_uninstall($plugin_id);
+ }
+ }
+ break;
+
+ case 'delete':
+ if (!empty($crt_db_plugin))
+ {
+ array_push($errors, 'CANNOT delete - PLUGIN IS INSTALLED');
+ }
+ elseif (!deltree(PHPWG_PLUGINS_PATH . $plugin_id))
+ {
+ send_to_trash(PHPWG_PLUGINS_PATH . $plugin_id);
+ }
+ break;
+ }
+ if (empty($errors))
+ {
+ redirect(
+ get_root_url()
+ .'admin.php'
+ .get_query_string_diff( array('action', 'plugin') )
+ );
+ }
+ else
+ {
+ $page['errors'] = array_merge($page['errors'], $errors);
+ }
+}
+
+
+$fs_plugins = get_fs_plugins();
+$db_plugins = get_db_plugins();
+$db_plugins_by_id = array();
+foreach ($db_plugins as $db_plugin)
+{
+ $db_plugins_by_id[$db_plugin['id']] = $db_plugin;
+}
// +-----------------------------------------------------------------------+
// | start template output |
// +-----------------------------------------------------------------------+
-if ($order == 'status')
+$template->set_filenames(array('plugins' => 'admin/plugins_list.tpl'));
+
+$base_url = get_root_url().'admin.php';
+
+//----------------------------------------------------------------sort options
+$selected_order = isset($_GET['order']) ? $_GET['order'] : 'name';
+
+$url = $base_url.get_query_string_diff( array('action', 'plugin', 'order'));
+
+$template->assign('order',
+ array(
+ $url.'&amp;order=name' => l10n('Name'),
+ $url.'&amp;order=status' => l10n('Status'),
+ $url.'&amp;order=author' => l10n('Author'),
+ $url.'&amp;order=id' => l10n('Id'),
+ )
+ );
+
+$template->assign('selected', $url.'&amp;order='.$selected_order);
+
+switch ($selected_order)
{
- $fs_plugins = sort_plugins_by_state($fs_plugins, $db_plugins_by_id);
+ case 'name':
+ uasort($fs_plugins, 'name_compare');
+ break;
+ case 'id':
+ uksort($fs_plugins, 'strcasecmp');
+ break;
+ case 'author':
+ uasort($fs_plugins, 'plugin_author_compare');
+ break;
+ case 'status':
+ $fs_plugins = sort_plugins_by_state($fs_plugins, $db_plugins_by_id);
+ break;
}
+
+//--------------------------------------------------------------display plugins
+
+$url = $base_url.get_query_string_diff( array('action', 'plugin') );
+
foreach($fs_plugins as $plugin_id => $fs_plugin)
{
$display_name = $fs_plugin['name'];
@@ -80,23 +214,23 @@ foreach($fs_plugins as $plugin_id => $fs_plugin)
'VERSION' => $fs_plugin['version'],
'DESCRIPTION' => $desc);
- $action_url = htmlentities($my_base_url) . '&amp;plugin=' . $plugin_id;
+ $action_url = $url.'&amp;plugin='.$plugin_id;
if (isset($db_plugins_by_id[$plugin_id]))
- {
+ {
switch ($db_plugins_by_id[$plugin_id]['state'])
{
case 'active':
- $tpl_plugin['actions'][] =
+ $tpl_plugin['actions'][] =
array('U_ACTION' => $action_url . '&amp;action=deactivate',
'L_ACTION' => l10n('Deactivate'));
break;
case 'inactive':
- $tpl_plugin['actions'][] =
+ $tpl_plugin['actions'][] =
array('U_ACTION' => $action_url . '&amp;action=activate',
'L_ACTION' => l10n('Activate'));
- $tpl_plugin['actions'][] =
+ $tpl_plugin['actions'][] =
array('U_ACTION' => $action_url . '&amp;action=uninstall',
'L_ACTION' => l10n('Uninstall'),
'CONFIRM' => l10n('Are you sure?'));
@@ -105,11 +239,11 @@ foreach($fs_plugins as $plugin_id => $fs_plugin)
}
else
{
- $tpl_plugin['actions'][] =
+ $tpl_plugin['actions'][] =
array('U_ACTION' => $action_url . '&amp;action=install',
'L_ACTION' => l10n('Install'),
'CONFIRM' => l10n('Are you sure?'));
- $tpl_plugin['actions'][] =
+ $tpl_plugin['actions'][] =
array('U_ACTION' => $action_url . '&amp;action=delete',
'L_ACTION' => l10n('plugins_delete'),
'CONFIRM' => l10n('plugins_confirm_delete'));
@@ -123,7 +257,7 @@ $missing_plugin_ids = array_diff(
foreach($missing_plugin_ids as $plugin_id)
{
- $action_url = $my_base_url.'&amp;plugin='.$plugin_id;
+ $action_url = $url.'&amp;plugin='.$plugin_id;
$template->append( 'plugins',
array(
@@ -138,4 +272,5 @@ foreach($missing_plugin_ids as $plugin_id)
);
}
+$template->assign_var_from_handle('ADMIN_CONTENT', 'plugins');
?> \ No newline at end of file
diff --git a/admin/plugins_new.php b/admin/plugins_new.php
index 186a1901e..8720228f6 100644
--- a/admin/plugins_new.php
+++ b/admin/plugins_new.php
@@ -1,7 +1,7 @@
<?php
// +-----------------------------------------------------------------------+
// | PhpWebGallery - a PHP based picture gallery |
-// | Copyright (C) 2003-2007 PhpWebGallery Team - http://phpwebgallery.net |
+// | Copyright (C) 2003-2008 PhpWebGallery Team - http://phpwebgallery.net |
// +-----------------------------------------------------------------------+
// | file : $Id$
// | last update : $Date$
@@ -28,6 +28,11 @@ if( !defined("PHPWG_ROOT_PATH") )
die ("Hacking attempt!");
}
+
+$fs_plugins = get_fs_plugins();
+$my_base_url= get_root_url().'admin.php'.get_query_string_diff( array('install', 'extension', 'installstatus', 'order') );
+
+
$template->set_filenames(array('plugins' => 'admin/plugins_new.tpl'));
@@ -75,11 +80,11 @@ if (isset($_GET['installstatus']))
$order = isset($_GET['order']) ? $_GET['order'] : 'date';
$template->assign('order',
- array(htmlentities($my_base_url.'&order=date') => l10n('Post date'),
- htmlentities($my_base_url.'&order=name') => l10n('Name'),
- htmlentities($my_base_url.'&order=author') => l10n('Author')));
+ array($my_base_url.'&amp;order=date' => l10n('Post date'),
+ $my_base_url.'&amp;order=name' => l10n('Name'),
+ $my_base_url.'&amp;order=author' => l10n('Author')));
-$template->assign('selected', htmlentities($my_base_url.'&order=').$order);
+$template->assign('selected', $my_base_url.'&amp;order='.$order);
// +-----------------------------------------------------------------------+
@@ -102,7 +107,7 @@ if ($plugins_infos !== false)
nl2br(htmlspecialchars(strip_tags(
utf8_encode($plugin['description'])))));
- $url_auto_install = htmlentities($my_base_url)
+ $url_auto_install = $my_base_url
. '&amp;extension=' . $plugin['id_extension']
. '&amp;install=%2Fupload%2Fextension-' . $plugin['id_extension']
. '%2Frevision-' . $plugin['id_revision'] . '%2F'
@@ -129,4 +134,5 @@ else
array_push($page['errors'], l10n('plugins_server_error'));
}
+$template->assign_var_from_handle('ADMIN_CONTENT', 'plugins');
?> \ No newline at end of file
diff --git a/admin/plugins_update.php b/admin/plugins_update.php
index 43aab8d56..2799fa89b 100644
--- a/admin/plugins_update.php
+++ b/admin/plugins_update.php
@@ -1,7 +1,7 @@
<?php
// +-----------------------------------------------------------------------+
// | PhpWebGallery - a PHP based picture gallery |
-// | Copyright (C) 2003-2007 PhpWebGallery Team - http://phpwebgallery.net |
+// | Copyright (C) 2003-2008 PhpWebGallery Team - http://phpwebgallery.net |
// +-----------------------------------------------------------------------+
// | file : $Id$
// | last update : $Date$
@@ -28,6 +28,16 @@ if( !defined("PHPWG_ROOT_PATH") )
die ("Hacking attempt!");
}
+$fs_plugins = get_fs_plugins();
+$my_base_url= get_root_url().'admin.php'.get_query_string_diff( array('upgrade', 'plugin', 'reactivate', 'action', 'upgradestatus') );
+
+$db_plugins = get_db_plugins();
+$db_plugins_by_id = array();
+foreach ($db_plugins as $db_plugin)
+{
+ $db_plugins_by_id[$db_plugin['id']] = $db_plugin;
+}
+
$template->set_filenames(array('plugins' => 'admin/plugins_update.tpl'));
@@ -113,7 +123,7 @@ if ($plugins_infos !== false)
else
{
// Plugin need upgrade
- $url_auto_update = htmlentities($my_base_url)
+ $url_auto_update = $my_base_url
. '&amp;plugin=' . $plugin_id
. (
(isset($db_plugins_by_id[$plugin_id])
@@ -154,4 +164,5 @@ else
array_push($page['errors'], l10n('plugins_server_error'));
}
+$template->assign_var_from_handle('ADMIN_CONTENT', 'plugins');
?> \ No newline at end of file