diff options
Diffstat (limited to 'admin')
-rw-r--r-- | admin/include/plugins.class.php | 130 | ||||
-rw-r--r-- | admin/plugins_list.php | 64 | ||||
-rw-r--r-- | admin/themes/default/template/plugins_list.tpl | 20 |
3 files changed, 177 insertions, 37 deletions
diff --git a/admin/include/plugins.class.php b/admin/include/plugins.class.php index 4aa7223bb..7ae27a00f 100644 --- a/admin/include/plugins.class.php +++ b/admin/include/plugins.class.php @@ -26,6 +26,7 @@ class plugins var $fs_plugins = array(); var $db_plugins_by_id = array(); var $server_plugins = array(); + var $default_plugins = array('LocalFilesEditor', 'language_switch', 'c13y_upgrade', 'admin_multi_view'); /** * Initialize $fs_plugins and $db_plugins_by_id @@ -185,6 +186,9 @@ DELETE FROM ' . PLUGINS_TABLE . ' WHERE id=\'' . $plugin_id . '\''; array_push($errors, 'CANNOT DELETE - NO SUCH PLUGIN'); break; } + $query = ' +DELETE FROM ' . PLUGINS_TABLE . ' WHERE id=\'' . $plugin_id . '\''; + pwg_query($query); if (!$this->deltree(PHPWG_PLUGINS_PATH . $plugin_id)) { $this->send_to_trash(PHPWG_PLUGINS_PATH . $plugin_id); @@ -283,23 +287,12 @@ DELETE FROM ' . PLUGINS_TABLE . ' WHERE id=\'' . $plugin_id . '\''; } } - /** - * Retrieve PEM server datas to $server_plugins - */ - function get_server_plugins($new=false) + // Retrieve PEM versions + function get_versions_to_check($version=PHPWG_VERSION) { - global $user; - - $get_data = array( - 'category_id' => 12, - 'format' => 'php', - ); - - // Retrieve PEM versions - $version = PHPWG_VERSION; $versions_to_check = array(); - $url = PEM_URL . '/api/get_version_list.php'; - if (fetchRemote($url, $result, $get_data) and $pem_versions = @unserialize($result)) + $url = PEM_URL . '/api/get_version_list.php?category=12&format=php'; + if (fetchRemote($url, $result) and $pem_versions = @unserialize($result)) { if (!preg_match('/^\d+\.\d+\.\d+/', $version)) { @@ -314,6 +307,17 @@ DELETE FROM ' . PLUGINS_TABLE . ' WHERE id=\'' . $plugin_id . '\''; } } } + return $versions_to_check; + } + + /** + * Retrieve PEM server datas to $server_plugins + */ + function get_server_plugins($new=false) + { + global $user; + + $versions_to_check = $this->get_versions_to_check(); if (empty($versions_to_check)) { return false; @@ -331,12 +335,13 @@ DELETE FROM ' . PLUGINS_TABLE . ' WHERE id=\'' . $plugin_id . '\''; // Retrieve PEM plugins infos $url = PEM_URL . '/api/get_revision_list.php'; - $get_data = array_merge($get_data, array( + $get_data = array( + 'category_id' => 12, + 'format' => 'php', 'last_revision_only' => 'true', 'version' => implode(',', $versions_to_check), 'lang' => substr($user['language'], 0, 2), 'get_nb_downloads' => 'true', - ) ); if (!empty($plugins_to_check)) @@ -365,6 +370,73 @@ DELETE FROM ' . PLUGINS_TABLE . ' WHERE id=\'' . $plugin_id . '\''; } return false; } + + function get_incompatible_plugins() + { + if (isset($_SESSION['incompatible_plugins'])) + { + return $_SESSION['incompatible_plugins']; + } + + $_SESSION['incompatible_plugins'] = array(); + + $versions_to_check = $this->get_versions_to_check(); + if (empty($versions_to_check)) + { + return false; + } + + // Plugins to check + $plugins_to_check = array(); + foreach($this->fs_plugins as $fs_plugin) + { + if (isset($fs_plugin['extension'])) + { + $plugins_to_check[] = $fs_plugin['extension']; + } + } + + // Retrieve PEM plugins infos + $url = PEM_URL . '/api/get_revision_list.php'; + $get_data = array( + 'category_id' => 12, + 'format' => 'php', + 'version' => implode(',', $versions_to_check), + 'extension_include' => implode(',', $plugins_to_check), + ); + + if (fetchRemote($url, $result, $get_data)) + { + $pem_plugins = @unserialize($result); + if (!is_array($pem_plugins)) + { + return false; + } + + $server_plugins = array(); + foreach ($pem_plugins as $plugin) + { + if (!isset($server_plugins[$plugin['extension_id']])) + { + $server_plugins[$plugin['extension_id']] = array(); + } + array_push($server_plugins[$plugin['extension_id']], $plugin['revision_name']); + } + + foreach ($this->fs_plugins as $plugin_id => $fs_plugin) + { + if (isset($fs_plugin['extension']) + and !in_array($plugin_id, $this->default_plugins) + and $fs_plugin['version'] != 'auto' + and (!isset($server_plugins[$fs_plugin['extension']]) or !in_array($fs_plugin['version'], $server_plugins[$fs_plugin['extension']]))) + { + $_SESSION['incompatible_plugins'][$plugin_id] = $fs_plugin['version']; + } + } + return $_SESSION['incompatible_plugins']; + } + return false; + } /** * Sort $server_plugins @@ -483,6 +555,30 @@ DELETE FROM ' . PLUGINS_TABLE . ' WHERE id=\'' . $plugin_id . '\''; @unlink($archive); return $status; } + + function get_merged_extensions($version=PHPWG_VERSION) + { + if (!isset($_SESSION['merged_extensions'])) + { + $_SESSION['merged_extensions'] = array(); + if (fetchRemote(MERGED_EXTENSIONS_URL, $result)) + { + $rows = explode("\n", $result); + foreach ($rows as $row) + { + if (preg_match('/^(\d+\.\d+): *(.*)$/', $row, $match)) + { + if (version_compare($version, $match[1], '>=')) + { + $extensions = explode(',', trim($match[2])); + $_SESSION['merged_extensions'] = array_merge($_SESSION['merged_extensions'], $extensions); + } + } + } + } + } + return $_SESSION['merged_extensions']; + } /** * delete $path directory diff --git a/admin/plugins_list.php b/admin/plugins_list.php index 21e8ec3f2..6fee091e7 100644 --- a/admin/plugins_list.php +++ b/admin/plugins_list.php @@ -67,9 +67,20 @@ $plugins->set_tabsheet($page['page']); // +-----------------------------------------------------------------------+ $plugins->sort_fs_plugins('name'); +$plugins->get_merged_extensions(); +$plugins->get_incompatible_plugins(); +$merged_plugins = array(); foreach($plugins->fs_plugins as $plugin_id => $fs_plugin) { + if (isset($_SESSION['incompatible_plugins'][$plugin_id]) + and $fs_plugin['version'] != $_SESSION['incompatible_plugins'][$plugin_id]) + { + // Incompatible plugins must be reinitilized + unset($_SESSION['incompatible_plugins']); + $plugins->get_incompatible_plugins(); + } + $tpl_plugin = array( 'NAME' => $fs_plugin['name'], 'VISIT_URL' => $fs_plugin['uri'], @@ -77,9 +88,17 @@ foreach($plugins->fs_plugins as $plugin_id => $fs_plugin) 'DESC' => $fs_plugin['description'], 'AUTHOR' => $fs_plugin['author'], 'AUTHOR_URL' => @$fs_plugin['author uri'], - 'U_ACTION' => sprintf($action_url, $plugin_id) + 'U_ACTION' => sprintf($action_url, $plugin_id), + 'INCOMPATIBLE' => isset($_SESSION['incompatible_plugins'][$plugin_id]), ); + if (isset($fs_plugin['extension']) and in_array($fs_plugin['extension'], $_SESSION['merged_extensions'])) + { + $tpl_plugin['STATE'] = 'merged'; + array_push($merged_plugins, $tpl_plugin); + continue; + } + if (isset($plugins->db_plugins_by_id[$plugin_id])) { $tpl_plugin['STATE'] = $plugins->db_plugins_by_id[$plugin_id]['state']; @@ -92,32 +111,41 @@ foreach($plugins->fs_plugins as $plugin_id => $fs_plugin) $template->append('plugins', $tpl_plugin); } +$template->append('plugin_states', 'active'); +$template->append('plugin_states', 'inactive'); +$template->append('plugin_states', 'uninstalled'); + $missing_plugin_ids = array_diff( array_keys($plugins->db_plugins_by_id), array_keys($plugins->fs_plugins) ); -foreach($missing_plugin_ids as $plugin_id) +if (count($missing_plugin_ids) > 0) { - $template->append( - 'plugins', - array( - 'NAME' => $plugin_id, - 'VERSION' => $plugins->db_plugins_by_id[$plugin_id]['version'], - 'DESC' => "ERROR: THIS PLUGIN IS MISSING BUT IT IS INSTALLED! UNINSTALL IT NOW !", - 'U_ACTION' => sprintf($action_url, $plugin_id), - 'STATE' => 'missing', - ) - ); + foreach($missing_plugin_ids as $plugin_id) + { + $template->append( + 'plugins', + array( + 'NAME' => $plugin_id, + 'VERSION' => $plugins->db_plugins_by_id[$plugin_id]['version'], + 'DESC' => "ERROR: THIS PLUGIN IS MISSING BUT IT IS INSTALLED! UNINSTALL IT NOW !", + 'U_ACTION' => sprintf($action_url, $plugin_id), + 'STATE' => 'missing', + ) + ); + } + $template->append('plugin_states', 'missing'); } -$template->append('plugin_states', 'active'); -$template->append('plugin_states', 'inactive'); -$template->append('plugin_states', 'uninstalled'); - -if (count($missing_plugin_ids) > 0) +if (count($merged_plugins) > 0) { - $template->append('plugin_states', 'missing'); + foreach($merged_plugins as $tpl_plugin) + { + $tpl_plugin['DESC'] = l10n("THIS PLUGIN IS NOW PART OF PIWIGO CORE. UNINSTALL IT NOW."); + $template->append('plugins', $tpl_plugin); + } + $template->append('plugin_states', 'merged'); } $template->assign_var_from_handle('ADMIN_CONTENT', 'plugins'); diff --git a/admin/themes/default/template/plugins_list.tpl b/admin/themes/default/template/plugins_list.tpl index d6a8364ee..c1a3a3696 100644 --- a/admin/themes/default/template/plugins_list.tpl +++ b/admin/themes/default/template/plugins_list.tpl @@ -1,3 +1,16 @@ +{footer_script} +var incompatible_msg = '{'WARNING! This plugin does not seem to be compatible with this version of Piwigo.'|@translate|@escape:'javascript'}'; +incompatible_msg += '\n'; +incompatible_msg += '{'Do you want to activate anyway?'|@translate|@escape:'javascript'}'; + +{literal} +jQuery(document).ready(function() { + jQuery('.incompatible').click(function() { + return confirm(incompatible_msg); + }); +}); +{/literal}{/footer_script} + <div class="titrePage"> <h2>{'Plugins'|@translate}</h2> </div> @@ -19,6 +32,9 @@ {elseif $plugin_state == 'missing'} {'Missing Plugins'|@translate} + {elseif $plugin_state == 'merged'} + {'Obsolete Plugins'|@translate} + {/if} </legend> {foreach from=$plugins item=plugin name=plugins_loop} @@ -35,14 +51,14 @@ <a href="{$plugin.U_ACTION}&action=deactivate">{'Deactivate'|@translate}</a> {elseif $plugin_state == 'inactive'} - <a href="{$plugin.U_ACTION}&action=activate">{'Activate'|@translate}</a> + <a href="{$plugin.U_ACTION}&action=activate" {if $plugin.INCOMPATIBLE}class="incompatible"{/if}>{'Activate'|@translate}</a> | <a href="{$plugin.U_ACTION}&action=uninstall" onclick="return confirm('{'Are you sure?'|@translate|@escape:'javascript'}');">{'Uninstall'|@translate}</a> {elseif $plugin_state == 'uninstalled'} <a href="{$plugin.U_ACTION}&action=install">{'Install'|@translate}</a> | <a href="{$plugin.U_ACTION}&action=delete" onclick="return confirm('{'Are you sure you want to delete this plugin?'|@translate|@escape:'javascript'}');">{'Delete'|@translate}</a> - {elseif $plugin_state == 'missing'} + {elseif $plugin_state == 'missing' or $plugin_state == 'merged'} <a href="{$plugin.U_ACTION}&action=uninstall" onclick="return confirm('{'Are you sure?'|@translate|@escape:'javascript'}');">{'Uninstall'|@translate}</a> {/if} |