aboutsummaryrefslogtreecommitdiffstats
path: root/admin/plugins.php
diff options
context:
space:
mode:
authorpatdenice <patdenice@piwigo.org>2008-03-02 17:53:23 +0000
committerpatdenice <patdenice@piwigo.org>2008-03-02 17:53:23 +0000
commit78e175b3fb7c8d2f9824b15632595523f9ea236c (patch)
treef4ee8463f6b506e3deb474853bf5c4e28db5963c /admin/plugins.php
parentfab44f72a89396d624be49311fc0622635d44f8a (diff)
Enhance plugins administtration
git-svn-id: http://piwigo.org/svn/trunk@2242 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to '')
-rw-r--r--admin/plugins.php223
1 files changed, 87 insertions, 136 deletions
diff --git a/admin/plugins.php b/admin/plugins.php
index 1c467a4c2..63054fc55 100644
--- a/admin/plugins.php
+++ b/admin/plugins.php
@@ -28,7 +28,7 @@ if( !defined("PHPWG_ROOT_PATH") )
die ("Hacking attempt!");
}
-include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
+include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php');
check_status(ACCESS_ADMINISTRATOR);
$my_base_url = PHPWG_ROOT_PATH.'admin.php?page=plugins';
@@ -37,13 +37,13 @@ $my_base_url = PHPWG_ROOT_PATH.'admin.php?page=plugins';
// +-----------------------------------------------------------------------+
// | perform requested actions |
// +-----------------------------------------------------------------------+
-if ( isset($_GET['action']) and isset($_GET['plugin']) and !is_adviser() )
+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];
+ $crt_db_plugin = $crt_db_plugin[0];
}
else
{
@@ -51,26 +51,26 @@ if ( isset($_GET['action']) and isset($_GET['plugin']) and !is_adviser() )
}
$errors = array();
- $file_to_include = PHPWG_PLUGINS_PATH.$plugin_id.'/maintain.inc.php';
+ $file_to_include = PHPWG_PLUGINS_PATH . $plugin_id . '/maintain.inc.php';
- switch ( $_GET['action'] )
+ switch ($_GET['action'])
{
case 'install':
- if ( !empty($crt_db_plugin))
+ if (!empty($crt_db_plugin))
{
array_push($errors, 'CANNOT install - ALREADY INSTALLED');
break;
}
$fs_plugins = get_fs_plugins();
- if ( !isset( $fs_plugins[$plugin_id] ) )
+ if (!isset($fs_plugins[$plugin_id]))
{
array_push($errors, 'CANNOT install - NO SUCH PLUGIN');
break;
}
- if ( file_exists($file_to_include) )
+ if (file_exists($file_to_include))
{
include_once($file_to_include);
- if ( function_exists('plugin_install') )
+ if (function_exists('plugin_install'))
{
plugin_install($plugin_id, $fs_plugins[$plugin_id]['version'], $errors);
}
@@ -78,28 +78,28 @@ if ( isset($_GET['action']) and isset($_GET['plugin']) and !is_adviser() )
if (empty($errors))
{
$query = '
-INSERT INTO '.PLUGINS_TABLE.' (id,version) VALUES ("'
-.$plugin_id.'","'.$fs_plugins[$plugin_id]['version'].'"
+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) )
+ if (!isset($crt_db_plugin))
{
- array_push($errors, 'CANNOT '. $_GET['action'] .' - NOT INSTALLED');
+ array_push($errors, 'CANNOT ' . $_GET['action'] . ' - NOT INSTALLED');
break;
}
- if ($crt_db_plugin['state']!='inactive')
+ if ($crt_db_plugin['state'] != 'inactive')
{
- array_push($errors, 'invalid current state '.$crt_db_plugin['state']);
+ array_push($errors, 'invalid current state ' . $crt_db_plugin['state']);
break;
}
- if ( file_exists($file_to_include) )
+ if (file_exists($file_to_include))
{
include_once($file_to_include);
- if ( function_exists('plugin_activate') )
+ if (function_exists('plugin_activate'))
{
plugin_activate($plugin_id, $crt_db_plugin['version'], $errors);
}
@@ -107,165 +107,116 @@ INSERT INTO '.PLUGINS_TABLE.' (id,version) VALUES ("'
if (empty($errors))
{
$query = '
-UPDATE '.PLUGINS_TABLE.' SET state="active" WHERE id="'.$plugin_id.'"';
+UPDATE ' . PLUGINS_TABLE . ' SET state="active" WHERE id="' . $plugin_id . '"';
pwg_query($query);
}
break;
case 'deactivate':
- if ( !isset($crt_db_plugin) )
+ if (!isset($crt_db_plugin))
{
- die ('CANNOT '. $_GET['action'] .' - NOT INSTALLED');
+ die ('CANNOT ' . $_GET['action'] . ' - NOT INSTALLED');
}
- if ($crt_db_plugin['state']!='active')
+ if ($crt_db_plugin['state'] != 'active')
{
- die('invalid current state '.$crt_db_plugin['state']);
+ die('invalid current state ' . $crt_db_plugin['state']);
}
$query = '
-UPDATE '.PLUGINS_TABLE.' SET state="inactive" WHERE id="'.$plugin_id.'"';
+UPDATE ' . PLUGINS_TABLE . ' SET state="inactive" WHERE id="' . $plugin_id . '"';
pwg_query($query);
-
- @include_once($file_to_include);
- if ( function_exists('plugin_deactivate') )
+ if (file_exists($file_to_include))
{
- plugin_deactivate($plugin_id);
+ include_once($file_to_include);
+ if (function_exists('plugin_deactivate'))
+ {
+ plugin_deactivate($plugin_id);
+ }
}
break;
case 'uninstall':
- if ( !isset($crt_db_plugin) )
+ if (!isset($crt_db_plugin))
{
- die ('CANNOT '. $_GET['action'] .' - NOT INSTALLED');
+ die ('CANNOT ' . $_GET['action'] . ' - NOT INSTALLED');
}
$query = '
-DELETE FROM '.PLUGINS_TABLE.' WHERE id="'.$plugin_id.'"';
+DELETE FROM ' . PLUGINS_TABLE . ' WHERE id="' . $plugin_id . '"';
pwg_query($query);
-
- @include_once($file_to_include);
- if ( function_exists('plugin_uninstall') )
+ if (file_exists($file_to_include))
+ {
+ include_once($file_to_include);
+ if (function_exists('plugin_uninstall'))
+ {
+ plugin_uninstall($plugin_id);
+ }
+ }
+ break;
+
+ case 'delete':
+ if (!pm_deltree(PHPWG_PLUGINS_PATH . $plugin_id))
{
- plugin_uninstall($plugin_id);
+ send_pm_trash(PHPWG_PLUGINS_PATH . $plugin_id);
}
break;
}
if (empty($errors))
- {
- // do the redirection so that we allow the plugins to load/unload
- redirect($my_base_url);
- }
- else
- {
+ {
+ $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 |
+// | Sections definitions |
// +-----------------------------------------------------------------------+
-$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)
+if (empty($_GET['section']))
+{
+ $page['section'] = 'list';
+}
+else
{
- $db_plugins_by_id[$db_plugin['id']] = $db_plugin;
+ $page['section'] = $_GET['section'];
}
+$tab_link = $my_base_url . '&amp;section=';
-$template->set_filenames(array('plugins' => 'admin/plugins.tpl'));
+// TabSheet
+$tabsheet = new tabsheet();
+// TabSheet initialization
+$tabsheet->add('list', l10n('plugins_tab_list'), $tab_link.'list');
+$tabsheet->add('update', l10n('plugins_tab_update'), $tab_link.'update');
+$tabsheet->add('new', l10n('plugins_tab_new'), $tab_link.'new');
+// TabSheet selection
+$tabsheet->select($page['section']);
+// Assign tabsheet to template
+$tabsheet->assign();
-$num=0;
-foreach( $fs_plugins as $plugin_id => $fs_plugin )
-{
- $display_name = $fs_plugin['name'];
- if ( !empty($fs_plugin['uri']) )
- {
- $display_name='<a href="'.$fs_plugin['uri'].'">'.$display_name.'</a>';
- }
- $desc = $fs_plugin['description'];
- if (!empty($fs_plugin['author']))
- {
- $desc.= ' (<em>';
- if (!empty($fs_plugin['author uri']))
- {
- $desc.= '<a href="'.$fs_plugin['author uri'].'">'.$fs_plugin['author'].'</a>';
- }
- else
- {
- $desc.= $fs_plugin['author'];
- }
- $desc.= '</em>)';
- }
-
- $tpl_plugin =
- array(
- 'NAME' => $display_name,
- 'VERSION' => $fs_plugin['version'],
- 'DESCRIPTION' => $desc,
- 'actions' => array(),
- );
+$my_base_url .= '&section=' . $page['section'];
- $action_url = $my_base_url.'&amp;plugin='.$plugin_id;
- if ( isset($db_plugins_by_id[$plugin_id]) )
- { // already in the database
- // MAYBE TODO HERE: check for the version and propose upgrade action
- switch ($db_plugins_by_id[$plugin_id]['state'])
- {
- case 'active':
- $tpl_plugin['actions'][] =
- array(
- 'U_ACTION' => $action_url . '&amp;action=deactivate',
- 'L_ACTION' => l10n('Deactivate'),
- );
- break;
- case 'inactive':
- $tpl_plugin['actions'][] =
- array(
- 'U_ACTION' => $action_url . '&amp;action=activate',
- 'L_ACTION' => l10n('Activate'),
- );
- $tpl_plugin['actions'][] =
- array(
- 'U_ACTION' => $action_url . '&amp;action=uninstall',
- 'L_ACTION' => l10n('Uninstall'),
- 'CONFIRM' => true,
- );
- break;
- }
- }
- else
- {
- $tpl_plugin['actions'][] =
- array(
- 'U_ACTION' => $action_url . '&amp;action=install',
- 'L_ACTION' => l10n('Install'),
- 'CONFIRM' => true,
- );
- }
- $template->append('plugins', $tpl_plugin);
+// +-----------------------------------------------------------------------+
+// | 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;
}
-$missing_plugin_ids = array_diff(
- array_keys($db_plugins_by_id), array_keys($fs_plugins)
- );
-foreach( $missing_plugin_ids as $plugin_id )
-{
- $action_url = $my_base_url.'&amp;plugin='.$plugin_id;
-
- $template->append( 'plugins',
- array(
- 'NAME' => $plugin_id,
- 'VERSION' => $db_plugins_by_id[$plugin_id]['version'],
- 'DESCRIPTION' => "ERROR: THIS PLUGIN IS MISSING BUT IT IS INSTALLED! UNINSTALL IT NOW !",
- 'actions' => array ( array (
- 'U_ACTION' => $action_url . '&amp;action=uninstall',
- 'L_ACTION' => l10n('Uninstall'),
- ) )
- )
- );
-}
+include(PHPWG_ROOT_PATH.'admin/plugins_'.$page['section'].'.php');
$template->assign_var_from_handle('ADMIN_CONTENT', 'plugins');
-?>
+
+?> \ No newline at end of file