deltree($pathfile); } else { @unlink($pathfile); } } } closedir($fh); return @rmdir($path); } } function check_version($version=PHPWG_VERSION) { global $conf; if (!isset($_SESSION['need_update'])) { $_SESSION['need_update'] = null; if (preg_match('/(\d+\.\d+)\.(\d+)/', $version, $matches) and @fetchRemote(PHPWG_URL.'/download/latest_version', $result)) { $lines = @explode("\r\n", $result); $new_version = trim($lines[1]); $new_branch = preg_replace('/(\d+\.\d+)\.\d+/', '$1', $new_version); $actual_branch = $matches[1]; $update_to = $actual_branch . '.' . ($matches[2]+1); if (version_compare($version, $new_version) < 0 and $actual_branch == $new_branch) { $_SESSION['need_update'] = $new_version; } else { $_SESSION['need_update'] = false; } } } if ($_SESSION['need_update']) { preg_match('/(\d+\.\d+)\.(\d+)/', $version, $matches); $update_to = $matches[1] . '.' . ($matches[2]+1); $path = $conf['local_data_dir'].'/autoupdate/'; $code = $version.'_to_'.$update_to; $filename = $path.$version.'_to_'.$update_to.'.zip'; mkgetdir($path); if (!file_exists($filename) or !filesize($filename)) { $zip = @fopen($filename, 'w+'); @fetchRemote(PHPWG_URL.'/download/dlcounter.php?code='.str_replace(array('.', '_'), '', $code), $zip); @fclose($zip); } if (file_exists($filename) and filesize($filename)) { if (isset($_GET['autoupdate']) and preg_match('/\d+\.\d+\.\d+_to_'.preg_quote($version).'/', $_GET['autoupdate'])) { redirect('admin.php?autoupdate='.$code); } else { return rtrim(l10n('A new version of Piwigo is available.'), '.').' ('.$_SESSION['need_update'].')
' . ''.l10n('Click here to upgrade automatically').''; } } else { @unlink($filename); return rtrim(l10n('A new version of Piwigo is available.'), '.').' ('.$_SESSION['need_update'].')
' . l10n('Piwigo cannot retrieve upgrade file from server').'
' . '' . sprintf(l10n('Click here to see Piwigo %s release notes'), $_SESSION['need_update']).''; } } else { // Gallery is up to date // Check plugins upgrade include_once(PHPWG_ROOT_PATH.'admin/include/plugins.class.php'); $plugins = new plugins(); $ignore_list = unserialize($conf['autoupdate_ignore_list']); if (!isset($_SESSION['plugins_need_update'])) { $_SESSION['plugins_need_update'] = null; $this->check_plugins_upgrade($plugins, $ignore_list); } elseif (!empty($_SESSION['plugins_need_update'])) { // Check if plugins have been upgraded since last check foreach($plugins->fs_plugins as $plugin_id => $fs_plugin) { if (isset($_SESSION['plugins_need_update'][$plugin_id]) and $plugins->plugin_version_compare($fs_plugin['version'], $_SESSION['plugins_need_update'][$plugin_id])) { // Plugin have been updated $this->check_plugins_upgrade($plugins, $ignore_list); } } } if (!empty($_SESSION['plugins_need_update'])) { return l10n('Some upgrades are available for you plugins').'
' . ''.l10n('Click here see upgrade plugins page').''; } } if ($_SESSION['need_update'] === false and $_SESSION['plugins_need_update'] === array()) { return l10n('Gallery and plugins are up to date'); } else { return l10n('Unable to check upgrades...') . '
' . l10n('Click here to check upgrades now') . ''; } } function check_plugins_upgrade($plugins, $ignore_list) { if ($plugins->get_server_plugins()) { $new_ignore_list = array(); $_SESSION['plugins_need_update'] = array(); foreach($plugins->fs_plugins as $plugin_id => $fs_plugin) { if (isset($fs_plugin['extension']) and isset($plugins->server_plugins[$fs_plugin['extension']])) { $plugin_info = $plugins->server_plugins[$fs_plugin['extension']]; if (!$plugins->plugin_version_compare($fs_plugin['version'], $plugin_info['revision_name'])) { if (in_array($fs_plugin['name'], $ignore_list)) { array_push($new_ignore_list, $fs_plugin['name']); } else { $_SESSION['plugins_need_update'][$plugin_id] = $plugin_info['revision_name']; } } } } // Update ignore list in database $query = ' UPDATE '.CONFIG_TABLE.' SET value = "'.addslashes(serialize($new_ignore_list)).'" WHERE param = "autoupdate_ignore_list" ;'; pwg_query($query); } } } ?>