diff options
author | patdenice <patdenice@piwigo.org> | 2008-03-07 17:15:46 +0000 |
---|---|---|
committer | patdenice <patdenice@piwigo.org> | 2008-03-07 17:15:46 +0000 |
commit | c68914a3b962b39f341eb4a42f467f7c1143a8b9 (patch) | |
tree | 92db78f768036705f69312f518a1a3dfa4f248a3 | |
parent | 6ecb1f350753ac6c258677bb244d6003b3d359d3 (diff) |
Corrections in plugins management.
git-svn-id: http://piwigo.org/svn/trunk@2264 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to '')
-rw-r--r-- | admin/include/plugins.class.php | 189 | ||||
-rw-r--r-- | admin/plugins_list.php | 42 | ||||
-rw-r--r-- | admin/plugins_new.php | 63 | ||||
-rw-r--r-- | admin/plugins_update.php | 68 | ||||
-rw-r--r-- | include/constants.php | 2 |
5 files changed, 179 insertions, 185 deletions
diff --git a/admin/include/plugins.class.php b/admin/include/plugins.class.php index 490abf762..e26e0f3b9 100644 --- a/admin/include/plugins.class.php +++ b/admin/include/plugins.class.php @@ -26,71 +26,28 @@ class plugins { - var $page = ''; - var $order = ''; - var $my_base_url = ''; - var $html_base_url = ''; var $fs_plugins = array(); var $db_plugins_by_id = array(); var $server_plugins = array(); - function plugins($page='', $order='') + /** + * Initialize $fs_plugins and $db_plugins_by_id + */ + function plugins() { - $this->page = $page; - $this->order = $order; - - $this->my_base_url = get_root_url().'admin.php?page='.$this->page; - if (!empty($this->order)) - { - $this->my_base_url .= '&order=' . $this->order; - } - $this->html_base_url = htmlentities($this->my_base_url); - $this->get_fs_plugins(); + foreach (get_db_plugins() as $db_plugin) { $this->db_plugins_by_id[$db_plugin['id']] = $db_plugin; } } - /** - * Assign tabsheet - */ - function tabsheet() - { - include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php'); - $link = PHPWG_ROOT_PATH.'admin.php?page='; - - $tabsheet = new tabsheet(); - $tabsheet->add('plugins_list', l10n('plugins_tab_list'), $link.'plugins_list'); - $tabsheet->add('plugins_update', l10n('plugins_tab_update'), $link.'plugins_update'); - $tabsheet->add('plugins_new', l10n('plugins_tab_new'), $link.'plugins_new'); - $tabsheet->select($this->page); - $tabsheet->assign(); - } - - /** - * Set order - * @param array - order options - */ - function set_order_options($options) - { - global $template; - - $link = get_root_url().'admin.php?page='.$this->page.'&order='; - foreach($options as $key => $value) - { - $tpl_options[$link . $key] = $value; - } - $template->assign('order_options', $tpl_options); - $template->assign('order_selected', $link . $this->order); - } - /** * Perform requested actions * @param string - action * @param string - plugin id - * @param string - errors + * @param array - errors */ function perform_action($action, $plugin_id, $errors=array()) { @@ -219,7 +176,7 @@ DELETE FROM ' . PLUGINS_TABLE . ' WHERE id="' . $plugin_id . '"'; } /** - * Returns an array of plugins defined in the plugin directory + * Get plugins defined in the plugin directory */ function get_fs_plugins() { @@ -282,12 +239,15 @@ DELETE FROM ' . PLUGINS_TABLE . ' WHERE id="' . $plugin_id . '"'; } /** - * sort fs_plugins + * Sort fs_plugins */ - function sort_fs_plugins() + function sort_fs_plugins($order='name') { - switch ($this->order) + switch ($order) { + case 'name': + uasort($this->fs_plugins, 'name_compare'); + break; case 'status': $this->sort_plugins_by_state(); break; @@ -297,17 +257,15 @@ DELETE FROM ' . PLUGINS_TABLE . ' WHERE id="' . $plugin_id . '"'; case 'id': uksort($this->fs_plugins, 'strcasecmp'); break; - default: //sort by plugin name - uasort($this->fs_plugins, 'name_compare'); } } /** - * Retrieve PEM server datas + * Retrieve PEM server datas to $server_plugins */ - function check_server_plugins() + function get_server_plugins($new=false) { - foreach($this->fs_plugins as $plugin_id => $fs_plugin) + foreach($this->fs_plugins as $fs_plugin) { if (isset($fs_plugin['extension'])) { @@ -315,73 +273,37 @@ DELETE FROM ' . PLUGINS_TABLE . ' WHERE id="' . $plugin_id . '"'; } } $url = PEM_URL . '/uptodate.php?version=' . rawurlencode(PHPWG_VERSION) . '&extensions=' . implode(',', $plugins_to_check); - $url .= $this->page == 'plugins_new' ? '&newext=Plugin' : ''; + $url .= $new ? '&newext=Plugin' : ''; if (!empty($plugins_to_check) and $source = @file_get_contents($url)) { $this->server_plugins = @unserialize($source); - switch ($this->order) - { - case 'name': - uasort($this->server_plugins, array($this, 'extension_name_compare')); - break; - case 'author': - uasort($this->server_plugins, array($this, 'extension_author_compare')); - break; - default: // sort by id desc - krsort($this->server_plugins); - } } else { $this->server_plugins = false; } } - - /** - * Upgrade plugin - * @param string - archive URL - * @param string - plugin id - */ - function upgrade($source, $plugin_id) + + /** + * Sort $server_plugins + */ + function sort_server_plugins($order='date') { - if (isset($this->db_plugins_by_id[$plugin_id]) - and $this->db_plugins_by_id[$plugin_id]['state'] == 'active') - { - $this->perform_action('deactivate', $plugin_id); - - redirect( - $this->my_base_url - . '&upgrade=' . $source - . '&plugin=' . $plugin_id - . '&reactivate=true'); - } - - include(PHPWG_ROOT_PATH.'admin/include/pclzip.lib.php'); - $upgrade_status = $this->extract_plugin_files('upgrade', $source, $plugin_id); - - if (isset($_GET['reactivate'])) + switch ($order) { - $this->perform_action('activate', $plugin_id); + case 'date': + krsort($this->server_plugins); + break; + case 'name': + uasort($this->server_plugins, array($this, 'extension_name_compare')); + break; + case 'author': + uasort($this->server_plugins, array($this, 'extension_author_compare')); + break; } - redirect($this->my_base_url.'&plugin='.$plugin_id.'&upgradestatus='.$upgrade_status); - } - - - /** - * Install plugin - * @param string - archive URL - * @param string - extension id - */ - function install($source, $extension) - { - include(PHPWG_ROOT_PATH.'admin/include/pclzip.lib.php'); - $install_status = $this->extract_plugin_files('install', $source, $extension); - - redirect($this->my_base_url.'&installstatus='.$install_status); } - /** * Extract plugin files from archive * @param string - install or upgrade @@ -394,6 +316,7 @@ DELETE FROM ' . PLUGINS_TABLE . ' WHERE id="' . $plugin_id . '"'; { if (@copy(PEM_URL . str_replace(' ', '%20', $source), $archive)) { + include(PHPWG_ROOT_PATH.'admin/include/pclzip.lib.php'); $zip = new PclZip($archive); if ($list = $zip->listContent()) { @@ -447,50 +370,6 @@ DELETE FROM ' . PLUGINS_TABLE . ' WHERE id="' . $plugin_id . '"'; } /** - * get install or upgrade result - */ - function get_result($result, $plugin='') - { - global $page; - - switch ($result) - { - case 'ok': - if ($this->page == 'plugins_update') - { - array_push($page['infos'], - sprintf( - l10n('plugins_upgrade_ok'), - $this->fs_plugins[$plugin]['name'])); - } - else - { - array_push($page['infos'], - l10n('plugins_install_ok'), - l10n('plugins_install_need_activate')); - } - break; - - case 'temp_path_error': - array_push($page['errors'], l10n('plugins_temp_path_error')); - break; - - case 'dl_archive_error': - array_push($page['errors'], l10n('plugins_dl_archive_error')); - break; - - case 'archive_error': - array_push($page['errors'], l10n('plugins_archive_error')); - break; - - default: - array_push($page['errors'], - sprintf(l10n('plugins_extract_error'), $result), - l10n('plugins_check_chmod')); - } - } - - /** * delete $path directory * @param string - path */ @@ -521,7 +400,7 @@ DELETE FROM ' . PLUGINS_TABLE . ' WHERE id="' . $plugin_id . '"'; /** * send $path to trash directory - * @param string - path + * @param string - path */ function send_to_trash($path) { diff --git a/admin/plugins_list.php b/admin/plugins_list.php index 90a8ef722..ac5d5c1a2 100644 --- a/admin/plugins_list.php +++ b/admin/plugins_list.php @@ -33,28 +33,44 @@ include_once(PHPWG_ROOT_PATH.'admin/include/plugins.class.php'); $template->set_filenames(array('plugins' => 'admin/plugins_list.tpl')); $order = isset($_GET['order']) ? $_GET['order'] : 'name'; -$plugins = new plugins($page['page'], $order); +$base_url = get_root_url().'admin.php?page='.$page['page'].'&order='.$order; + +$plugins = new plugins(); //--------------------------------------------------perform requested actions if (isset($_GET['action']) and isset($_GET['plugin']) and !is_adviser()) { $page['errors'] = $plugins->perform_action($_GET['action'], $_GET['plugin'], $page['errors']); - - if (empty($page['errors'])) redirect($plugins->my_base_url); + + if (empty($page['errors'])) redirect($base_url); } +//--------------------------------------------------------------------Tabsheet +include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php'); +$link = get_root_url().'admin.php?page='; +$tabsheet = new tabsheet(); +$tabsheet->add('plugins_list', l10n('plugins_tab_list'), $link.'plugins_list'); +$tabsheet->add('plugins_update', l10n('plugins_tab_update'), $link.'plugins_update'); +$tabsheet->add('plugins_new', l10n('plugins_tab_new'), $link.'plugins_new'); +$tabsheet->select($page['page']); +$tabsheet->assign(); + +//---------------------------------------------------------------Order options +$link .= $page['page'].'&order='; +$template->assign('order_options', + array( + $link.'name' => l10n('Name'), + $link.'status' => l10n('Status'), + $link.'author' => l10n('Author'), + $link.'id' => 'Id')); +$template->assign('order_selected', $link.$order); + // +-----------------------------------------------------------------------+ // | start template output | // +-----------------------------------------------------------------------+ -$plugins->tabsheet(); -$plugins->sort_fs_plugins(); -$plugins->set_order_options(array( - 'name' => l10n('Name'), - 'status' => l10n('Status'), - 'author' => l10n('Author'), - 'id' => 'Id')); - +$plugins->sort_fs_plugins($order); + foreach($plugins->fs_plugins as $plugin_id => $fs_plugin) { $display_name = $fs_plugin['name']; @@ -84,7 +100,7 @@ foreach($plugins->fs_plugins as $plugin_id => $fs_plugin) 'VERSION' => $fs_plugin['version'], 'DESCRIPTION' => $desc); - $action_url = $plugins->html_base_url . '&plugin=' . $plugin_id; + $action_url = htmlentities($base_url).'&plugin='.$plugin_id; if (isset($plugins->db_plugins_by_id[$plugin_id])) { @@ -127,7 +143,7 @@ $missing_plugin_ids = array_diff( foreach($missing_plugin_ids as $plugin_id) { - $action_url = $plugins->html_base_url.'&plugin='.$plugin_id; + $action_url = htmlentities($base_url).'&plugin='.$plugin_id; $template->append( 'plugins', array( diff --git a/admin/plugins_new.php b/admin/plugins_new.php index 61e03893c..4ca829571 100644 --- a/admin/plugins_new.php +++ b/admin/plugins_new.php @@ -33,30 +33,73 @@ include_once(PHPWG_ROOT_PATH.'admin/include/plugins.class.php'); $template->set_filenames(array('plugins' => 'admin/plugins_new.tpl')); $order = isset($_GET['order']) ? $_GET['order'] : 'date'; +$base_url = get_root_url().'admin.php?page='.$page['page'].'&order='.$order; -$plugins = new plugins($page['page'], $order); +$plugins = new plugins(); //------------------------------------------------------automatic installation if (isset($_GET['install']) and isset($_GET['extension']) and !is_adviser()) { - $plugins->install($_GET['install'], $_GET['extension']); + $install_status = + $plugins->extract_plugin_files('install', $_GET['install'], $_GET['extension']); + + redirect($base_url.'&installstatus='.$install_status); } //--------------------------------------------------------------install result if (isset($_GET['installstatus'])) { - $plugins->get_result($_GET['installstatus']); + switch ($_GET['installstatus']) + { + case 'ok': + array_push($page['infos'], + l10n('plugins_install_ok'), + l10n('plugins_install_need_activate')); + break; + + case 'temp_path_error': + array_push($page['errors'], l10n('plugins_temp_path_error')); + break; + + case 'dl_archive_error': + array_push($page['errors'], l10n('plugins_dl_archive_error')); + break; + + case 'archive_error': + array_push($page['errors'], l10n('plugins_archive_error')); + break; + + default: + array_push($page['errors'], + sprintf(l10n('plugins_extract_error'), $_GET['installstatus']), + l10n('plugins_check_chmod')); + } } +//--------------------------------------------------------------------Tabsheet +include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php'); +$link = get_root_url().'admin.php?page='; +$tabsheet = new tabsheet(); +$tabsheet->add('plugins_list', l10n('plugins_tab_list'), $link.'plugins_list'); +$tabsheet->add('plugins_update', l10n('plugins_tab_update'), $link.'plugins_update'); +$tabsheet->add('plugins_new', l10n('plugins_tab_new'), $link.'plugins_new'); +$tabsheet->select($page['page']); +$tabsheet->assign(); + +//---------------------------------------------------------------Order options +$link .= $page['page'].'&order='; +$template->assign('order_options', + array( + $link.'date' => l10n('Post date'), + $link.'name' => l10n('Name'), + $link.'author' => l10n('Author'))); +$template->assign('order_selected', $link.$order); + // +-----------------------------------------------------------------------+ // | start template output | // +-----------------------------------------------------------------------+ -$plugins->tabsheet(); -$plugins->check_server_plugins(); -$plugins->set_order_options(array( - 'date' => l10n('Post date'), - 'name' => l10n('Name'), - 'author' => l10n('Author'))); +$plugins->get_server_plugins(true); +$plugins->sort_server_plugins($order); if ($plugins->server_plugins !== false) { @@ -71,7 +114,7 @@ if ($plugins->server_plugins !== false) nl2br(htmlspecialchars(strip_tags( utf8_encode($plugin['description']))))); - $url_auto_install = $plugins->html_base_url + $url_auto_install = htmlentities($base_url) . '&extension=' . $plugin['id_extension'] . '&install=%2Fupload%2Fextension-' . $plugin['id_extension'] . '%2Frevision-' . $plugin['id_revision'] . '%2F' diff --git a/admin/plugins_update.php b/admin/plugins_update.php index 0cf10e188..34ab6afce 100644 --- a/admin/plugins_update.php +++ b/admin/plugins_update.php @@ -32,25 +32,81 @@ include_once(PHPWG_ROOT_PATH.'admin/include/plugins.class.php'); $template->set_filenames(array('plugins' => 'admin/plugins_update.tpl')); -$plugins = new plugins($page['page']); +$base_url = get_root_url().'admin.php?page='.$page['page']; + +$plugins = new plugins(); //-----------------------------------------------------------automatic upgrade if (isset($_GET['upgrade']) and isset($_GET['plugin']) and !is_adviser()) { - $plugins->upgrade($_GET['upgrade'], $_GET['plugin']); + $plugin_id = $_GET['plugin']; + + if (isset($plugins->db_plugins_by_id[$plugin_id]) + and $plugins->db_plugins_by_id[$plugin_id]['state'] == 'active') + { + $plugins->perform_action('deactivate', $plugin_id); + + redirect($base_url + . '&upgrade=' . $_GET['upgrade'] + . '&plugin=' . $plugin_id + . '&reactivate=true'); + } + + $upgrade_status = + $plugins->extract_plugin_files('upgrade', $_GET['upgrade'], $plugin_id); + + if (isset($_GET['reactivate'])) + { + $plugins->perform_action('activate', $plugin_id); + } + redirect($base_url.'&plugin='.$plugin_id.'&upgradestatus='.$upgrade_status); } //--------------------------------------------------------------upgrade result if (isset($_GET['upgradestatus']) and isset($_GET['plugin'])) { - $plugins->get_result($_GET['upgradestatus'], $_GET['plugin']); + switch ($_GET['upgradestatus']) + { + case 'ok': + array_push($page['infos'], + sprintf( + l10n('plugins_upgrade_ok'), + $plugins->fs_plugins[$_GET['plugin']]['name'])); + break; + + case 'temp_path_error': + array_push($page['errors'], l10n('plugins_temp_path_error')); + break; + + case 'dl_archive_error': + array_push($page['errors'], l10n('plugins_dl_archive_error')); + break; + + case 'archive_error': + array_push($page['errors'], l10n('plugins_archive_error')); + break; + + default: + array_push($page['errors'], + sprintf(l10n('plugins_extract_error'), $_GET['installstatus']), + l10n('plugins_check_chmod')); + } } +//--------------------------------------------------------------------Tabsheet +include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php'); +$link = get_root_url().'admin.php?page='; +$tabsheet = new tabsheet(); +$tabsheet->add('plugins_list', l10n('plugins_tab_list'), $link.'plugins_list'); +$tabsheet->add('plugins_update', l10n('plugins_tab_update'), $link.'plugins_update'); +$tabsheet->add('plugins_new', l10n('plugins_tab_new'), $link.'plugins_new'); +$tabsheet->select($page['page']); +$tabsheet->assign(); + // +-----------------------------------------------------------------------+ // | start template output | // +-----------------------------------------------------------------------+ -$plugins->tabsheet(); -$plugins->check_server_plugins(); +$plugins->get_server_plugins(); if ($plugins->server_plugins !== false) { @@ -82,7 +138,7 @@ if ($plugins->server_plugins !== false) else { // Plugin need upgrade - $url_auto_update = $plugins->html_base_url + $url_auto_update = $base_url . '&plugin=' . $plugin_id . '&upgrade=%2Fupload%2Fextension-' . $fs_plugin['extension'] . '%2Frevision-' . $plugin_info['id_revision'] diff --git a/include/constants.php b/include/constants.php index 0a263dfbd..7b90de747 100644 --- a/include/constants.php +++ b/include/constants.php @@ -28,7 +28,7 @@ define('PHPWG_VERSION', 'Butterfly'); define('PHPWG_DOMAIN', 'phpwebgallery.net'); define('PHPWG_URL', 'http://www.'.PHPWG_DOMAIN); -define('PEM_URL', PHPWG_URL . '/ext'); +define('PEM_URL', 'http://' . PHPWG_DOMAIN . '/ext'); define('PHPWG_DEFAULT_LANGUAGE', 'en_UK'); define('PHPWG_DEFAULT_TEMPLATE', 'yoga/clear'); |