Changeset 6167 for extensions
- Timestamp:
- May 13, 2010, 12:06:29 PM (15 years ago)
- Location:
- extensions/autoupdate
- Files:
-
- 8 added
- 6 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
extensions/autoupdate/autoupdate.php
r4711 r6167 2 2 3 3 load_language('plugin.lang', dirname(__FILE__).'/'); 4 5 if (isset($_GET['action']) and 6 ($_GET['action'] == 'check_autoupdate' or $_GET['action'] == 'check_upgrade' )) 7 { 8 unset($_SESSION['need_update']); 9 unset($_SESSION['plugins_need_update']); 10 } 11 12 if (isset($_GET['autoupdate'])) 13 { 14 if ($_GET['autoupdate'] == 'success') 15 { 16 array_push($page['infos'], sprintf(l10n('autoupdate_success'), PHPWG_VERSION)); 17 } 18 elseif ($file = $conf['local_data_dir'].'/autoupdate/'.$_GET['autoupdate'].'.zip' and file_exists($file)) 19 { 20 include(dirname(__FILE__).'/class.inc.php'); 21 include_once(PHPWG_ROOT_PATH.'admin/include/pclzip.lib.php'); 22 $autoupdate = new autoupdate(); 23 $zip = new PclZip($file); 24 if ($result = $zip->extract(PCLZIP_OPT_PATH, PHPWG_ROOT_PATH, 25 PCLZIP_OPT_REMOVE_PATH, $_GET['autoupdate'], 26 PCLZIP_OPT_SET_CHMOD, 0755, 27 PCLZIP_OPT_REPLACE_NEWER)) 28 { 29 //Check if all files were extracted 30 $error = ''; 31 foreach($result as $extract) 32 { 33 if (!in_array($extract['status'], array('ok', 'filtered', 'already_a_directory'))) 4 include(AUTOUPDATE_PATH.'include/functions.inc.php'); 5 include(PHPWG_ROOT_PATH.'admin/include/pclzip.lib.php'); 6 7 /* 8 STEP: 9 0 = check is needed. If version is latest or check fail, we stay on step 0 10 1 = new version on same branch AND new branch are available => user may choose upgrade. 11 2 = upgrade on same branch 12 3 = upgrade on different branch 13 */ 14 $step = isset($_GET['step']) ? $_GET['step'] : 0; 15 16 // +-----------------------------------------------------------------------+ 17 // | Step 0 | 18 // +-----------------------------------------------------------------------+ 19 if ($step == 0) 20 { 21 if (preg_match('/(\d+\.\d+)\.(\d+)/', PHPWG_VERSION, $matches) 22 and @fetchRemote(PHPWG_URL.'/download/all_versions.php', $result) 23 and $all_versions = @explode("\n", $result) 24 and is_array($all_versions)) 25 { 26 $template->assign('CHECK_VERSION', true); 27 28 $last_version = trim($all_versions[0]); 29 30 if (version_compare(PHPWG_VERSION, $last_version, '<')) 31 { 32 $new_branch = preg_replace('/(\d+\.\d+)\.\d+/', '$1', $last_version); 33 $actual_branch = $matches[1]; 34 35 if ($new_branch == $actual_branch) 36 { 37 $step = 2; 38 } 39 else 40 { 41 $step = 3; 42 43 // Check if new version exists in same branch 44 foreach ($all_versions as $version) 34 45 { 35 // Try to change chmod and extract 36 if (@chmod(PHPWG_ROOT_PATH.$extract['filename'], 0777) 37 and ($res = $zip->extract(PCLZIP_OPT_BY_NAME, $_GET['autoupdate'].'/'.$extract['filename'], 38 PCLZIP_OPT_PATH, PHPWG_ROOT_PATH, 39 PCLZIP_OPT_REMOVE_PATH, $_GET['autoupdate'], 40 PCLZIP_OPT_SET_CHMOD, 0755, 41 PCLZIP_OPT_REPLACE_NEWER)) 42 and isset($res[0]['status']) 43 and $res[0]['status'] == 'ok') 46 $new_branch = preg_replace('/(\d+\.\d+)\.\d+/', '$1', $version); 47 48 if ($new_branch == $actual_branch) 44 49 { 45 continue;46 }47 else48 {49 $error .= $extract['filename'].': '.$extract['status']."\n";50 if (version_compare(PHPWG_VERSION, $version, '<')) 51 { 52 $step = 1; 53 } 54 break; 50 55 } 51 56 } 52 57 } 53 54 if (empty($error))55 {56 if (file_exists(PHPWG_ROOT_PATH.'obsolete.list')57 and $old_files = file(PHPWG_ROOT_PATH.'obsolete.list', FILE_IGNORE_NEW_LINES)58 and !empty($old_files))59 {60 array_push($old_files, 'obsolete.list');61 foreach($old_files as $old_file)62 {63 $path = PHPWG_ROOT_PATH.$old_file;64 if (is_file($path))65 {66 @unlink($path);67 }68 elseif (is_dir($path))69 {70 $autoupdate->deltree($path);71 }72 }73 }74 if (preg_match('/\d+\.\d+\.\d+_to_(\d+\.\d+\.\d+)/', $_GET['autoupdate'], $matches))75 {76 unset($_SESSION['need_update']);77 $autoupdate->check_version($matches[1]);78 }79 $autoupdate->deltree($conf['local_data_dir'].'/autoupdate');80 invalidate_user_cache(true);81 $template->delete_compiled_templates();82 redirect('admin.php?autoupdate=success');83 }84 else85 {86 file_put_contents($conf['local_data_dir'].'/autoupdate/log_error.txt', $error);87 $relative_path = trim(str_replace(dirname(dirname(dirname(__FILE__))), '', $conf['local_data_dir']), '/\\');88 array_push($page['errors'], sprintf(l10n('autoupdate_extract_fail'), PHPWG_ROOT_PATH.$relative_path.'/autoupdate/log_error.txt'));89 }90 }91 else92 {93 $autoupdate->deltree($conf['local_data_dir'].'/autoupdate');94 array_push($page['errors'], l10n('autoupdate_fail'));95 58 } 96 59 } 97 60 else 98 61 { 99 @unlink($file); 100 array_push($page['errors'], l10n('autoupdate_fail')); 101 } 102 } 103 104 if (!isset($_SESSION['need_update']) or !isset($_SESSION['plugins_need_update']) 105 or $_SESSION['need_update'] !== false or $_SESSION['plugins_need_update'] !== array()) 106 { 107 $template->set_filename('autoupdate_head', realpath(dirname(__FILE__).'/head.tpl')); 108 array_push($header_notes, $template->parse('autoupdate_head', true)); 109 } 62 $template->assign('CHECK_VERSION', false); 63 } 64 } 65 66 // +-----------------------------------------------------------------------+ 67 // | Step 1 | 68 // +-----------------------------------------------------------------------+ 69 if ($step == 1) 70 { 71 $new_versions = array($last_version, $version); 72 $template->assign('new_versions', $new_versions); 73 } 74 75 // +-----------------------------------------------------------------------+ 76 // | Step 2 | 77 // +-----------------------------------------------------------------------+ 78 if ($step == 2) 79 { 80 if (isset($_POST['submit']) and isset($_POST['upgrade_to'])) 81 { 82 upgrade_to($_POST['upgrade_to'], $step); 83 } 84 85 $template->assign('UPGRADE_TO', isset($_GET['to']) ? $_GET['to'] : $last_version); 86 } 87 88 // +-----------------------------------------------------------------------+ 89 // | Step 3 | 90 // +-----------------------------------------------------------------------+ 91 if ($step == 3) 92 { 93 if (isset($_POST['saveTemplate'])) 94 { 95 $path = $conf['local_data_dir'].'/autoupdate'; 96 97 if (@mkgetdir($path) 98 and ($zip = tempnam($path, 'zip')) 99 and ($archive = new pclZip($zip)) 100 and ($v_list = $archive->add(PHPWG_ROOT_PATH.'template', PCLZIP_OPT_REMOVE_PATH, PHPWG_ROOT_PATH)) 101 and is_array($v_list) 102 and !empty($v_list)) 103 { 104 $http_headers = array( 105 'Content-Length: '.@filesize($zip), 106 'Content-Type: application/zip', 107 'Content-Disposition: attachment; filename="template.zip";', 108 'Content-Transfer-Encoding: binary', 109 ); 110 111 foreach ($http_headers as $header) { 112 header($header); 113 } 114 115 @readfile($zip); 116 autoupdate_deltree($conf['local_data_dir'].'/autoupdate'); 117 exit(); 118 } 119 120 array_push($page['errors'], l10n('Unable to send template directory.')); 121 } 122 123 if (isset($_POST['dumpDatabase'])) 124 { 125 if (version_compare(PHPWG_VERSION, '2.1', '<')) 126 { 127 global $cfgBase; 128 $conf['db_base'] = $cfgBase; 129 } 130 131 include(AUTOUPDATE_PATH.'include/mysqldump.php'); 132 133 $path = $conf['local_data_dir'].'/autoupdate'; 134 135 if (@mkgetdir($path) 136 and ($backupFile = tempnam($path, 'sql')) 137 and ($dumper = new MySQLDump($conf['db_base'],$backupFile,false,false))) 138 { 139 $tablesStructure = array( 140 CATEGORIES_TABLE, 141 COMMENTS_TABLE, 142 CONFIG_TABLE, 143 FAVORITES_TABLE, 144 GROUP_ACCESS_TABLE, 145 GROUPS_TABLE, 146 HISTORY_TABLE, 147 HISTORY_SUMMARY_TABLE, 148 IMAGE_CATEGORY_TABLE, 149 IMAGES_TABLE, 150 SESSIONS_TABLE, 151 SITES_TABLE, 152 USER_ACCESS_TABLE, 153 USER_GROUP_TABLE, 154 USERS_TABLE, 155 USER_INFOS_TABLE, 156 USER_FEED_TABLE, 157 WAITING_TABLE, 158 RATE_TABLE, 159 USER_CACHE_TABLE, 160 USER_CACHE_CATEGORIES_TABLE, 161 CADDIE_TABLE, 162 UPGRADE_TABLE, 163 SEARCH_TABLE, 164 USER_MAIL_NOTIFICATION_TABLE, 165 TAGS_TABLE, 166 IMAGE_TAG_TABLE, 167 PLUGINS_TABLE, 168 OLD_PERMALINKS_TABLE, 169 ); 170 171 $tablesData = $tablesStructure; 172 173 if (!isset($_POST['includeHistory'])) 174 { 175 unset($tablesData[6]); 176 } 177 178 foreach ($tablesStructure as $table) 179 { 180 $dumper->getTableStructure($table); 181 } 182 foreach ($tablesData as $table) 183 { 184 $dumper->getTableData($table); 185 } 186 } 187 188 if (@filesize($backupFile)) 189 { 190 $http_headers = array( 191 'Content-Length: '.@filesize($backupFile), 192 'Content-Type: text/x-sql', 193 'Content-Disposition: attachment; filename="database.sql";', 194 'Content-Transfer-Encoding: binary', 195 ); 196 197 foreach ($http_headers as $header) { 198 header($header); 199 } 200 201 @readfile($backupFile); 202 autoupdate_deltree($conf['local_data_dir'].'/autoupdate'); 203 exit(); 204 } 205 206 array_push($page['errors'], l10n('Unable to dump database.')); 207 } 208 209 if (isset($_POST['submit']) and isset($_POST['upgrade_to'])) 210 { 211 upgrade_to($_POST['upgrade_to'], $step); 212 } 213 214 $template->assign('UPGRADE_TO', isset($_GET['to']) ? $_GET['to'] : $last_version); 215 } 216 217 // +-----------------------------------------------------------------------+ 218 // | Process template | 219 // +-----------------------------------------------------------------------+ 220 221 $template->assign(array( 222 'STEP' => $step, 223 'AU_URL' => get_admin_plugin_menu_link(AUTOUPDATE_PATH . '/autoupdate.php'), 224 ) 225 ); 226 227 $template->set_filename('plugin_admin_content', realpath(AUTOUPDATE_PATH.'template/autoupdate.tpl')); 228 $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content'); 110 229 111 230 ?> -
extensions/autoupdate/index.php
r3575 r6167 1 1 <?php 2 2 // +-----------------------------------------------------------------------+ 3 // | PhpWebGallery - a PHP based picture gallery | 4 // | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net | 5 // | Copyright (C) 2003-2007 PhpWebGallery Team - http://phpwebgallery.net | 3 // | Piwigo - a PHP based picture gallery | 6 4 // +-----------------------------------------------------------------------+ 7 // | file : $Id: index.php 1912 2007-03-16 06:30:07Z rub $ 8 // | last update : $Date: 2007-03-16 07:30:07 +0100 (ven, 16 mar 2007) $ 9 // | last modifier : $Author: rub $ 10 // | revision : $Revision: 1912 $ 5 // | Copyright(C) 2008-2010 Piwigo Team http://piwigo.org | 6 // | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net | 7 // | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick | 11 8 // +-----------------------------------------------------------------------+ 12 9 // | This program is free software; you can redistribute it and/or modify | -
extensions/autoupdate/main.inc.php
r4711 r6167 11 11 if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); 12 12 13 if (script_basename() == 'admin') add_event_handler('get_admin_plugin_menu_links', 'check_for_auto_upgrade'); 13 define('AUTOUPDATE_PATH' , PHPWG_PLUGINS_PATH . basename(dirname(__FILE__)) . '/'); 14 15 if (script_basename() == 'admin') 16 add_event_handler('get_admin_plugin_menu_links', 'check_for_auto_upgrade'); 14 17 15 18 function check_for_auto_upgrade($plugin_menu_links) 16 19 { 17 global $template, $page, $conf, $header_notes ;20 global $template, $page, $conf, $header_notes, $prefixeTable; 18 21 19 22 if ($page['page'] == 'intro') 20 23 { 21 include(dirname(__FILE__).'/autoupdate.php'); 24 if (isset($_GET['action']) and 25 ($_GET['action'] == 'check_autoupdate' or $_GET['action'] == 'check_upgrade' )) 26 { 27 unset($_SESSION['need_update']); 28 unset($_SESSION['plugins_need_update']); 29 } 30 31 if (!isset($_SESSION['need_update']) or !isset($_SESSION['plugins_need_update']) 32 or $_SESSION['need_update'] !== false or $_SESSION['plugins_need_update'] !== array()) 33 { 34 $template->set_filename('autoupdate_head', realpath(AUTOUPDATE_PATH.'template/head.tpl')); 35 array_push($header_notes, $template->parse('autoupdate_head', true)); 36 } 22 37 } 23 38 24 if ($page['page'] == 'plugins_update' )39 if ($page['page'] == 'plugins_update' and method_exists('template', 'set_prefilter')) 25 40 { 26 41 include(dirname(__FILE__).'/plugins_update.php'); 27 42 } 28 43 44 array_push($plugin_menu_links, array( 45 'NAME' => 'Piwigo AutoUpgrade', 46 'URL' => get_admin_plugin_menu_link(AUTOUPDATE_PATH . '/autoupdate.php'))); 47 29 48 return $plugin_menu_links; 30 49 } -
extensions/autoupdate/maintain.inc.php
r4711 r6167 3 3 function plugin_activate() 4 4 { 5 global $prefixeTable ;5 global $prefixeTable, $conf; 6 6 7 $query = ' 7 if (!isset($conf['autoupdate_ignore_list'])) 8 { 9 $query = ' 8 10 INSERT INTO ' . CONFIG_TABLE . ' (param,value,comment) 9 11 VALUES ("autoupdate_ignore_list" , "'.addslashes(serialize(array())).'" , "Ignored plugin list for Piwigo Auto Update plugin");'; 10 12 11 pwg_query($query); 13 pwg_query($query); 14 } 12 15 } 13 16 -
extensions/autoupdate/plugins_update.php
r4711 r6167 5 5 function autoupdate_plugins_update_filter($content, &$smarty) 6 6 { 7 $search = '<a href="{$plugin.URL_DOWNLOAD}">{\'plugins_download\'|@translate}</a>'; 8 $replacement = ' <a href="{$plugin.URL_DOWNLOAD}">{\'plugins_download\'|@translate}</a><br> 7 $l_key = version_compare(PHPWG_VERSION, '2.1', '<') ? 'plugins_download' : 'Download file'; 8 9 $search = '<a href="{$plugin.URL_DOWNLOAD}">{\''.$l_key.'\'|@translate}</a>'; 10 11 $replacement = ' <a href="{$plugin.URL_DOWNLOAD}">{\''.$l_key.'\'|@translate}</a><br> 9 12 <a href="#" onClick="autoupdate_ignore(\'{$plugin.EXT_NAME}\', true, {$smarty.foreach.plugins_loop.index}); return false;" id="au_ignore_{$smarty.foreach.plugins_loop.index}_true" {if $plugin.EXT_NAME|@in_array:$AU_IGNORE_LIST}style="display: none;"{/if}>{\'Don\\\'t notify on admin homepage\'|@translate}</a> 10 13 <a href="#" onClick="autoupdate_ignore(\'{$plugin.EXT_NAME}\', false, {$smarty.foreach.plugins_loop.index}); return false;" id="au_ignore_{$smarty.foreach.plugins_loop.index}_false" {if !$plugin.EXT_NAME|@in_array:$AU_IGNORE_LIST}style="display: none;"{/if}>{\'Notify on admin homepage\'|@translate}</a>'; … … 18 21 jQuery.post( 19 22 "'.PHPWG_ROOT_PATH.'plugins/autoupdate/remote.php", 20 { "autoupdate_ignore []": [name, bool] },23 { "autoupdate_ignore'.(version_compare(PHPWG_VERSION, '2.1', '<') ? '[]' : '').'": [name, bool] }, 21 24 function(data) { 22 25 if (data == "ok") { … … 30 33 '; 31 34 32 //$template->delete_compiled_templates();33 35 $template->block_html_head('', $script_head, $smarty, $repeat); 34 36 $template->set_prefilter('plugins', 'autoupdate_plugins_update_filter'); -
extensions/autoupdate/remote.php
r4835 r6167 5 5 include_once( PHPWG_ROOT_PATH.'include/common.inc.php' ); 6 6 include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); 7 include_once(PHPWG_ROOT_PATH.'admin/include/functions_plugins.inc.php'); 7 8 8 9 check_status(ACCESS_ADMINISTRATOR); … … 12 13 and count($_POST['autoupdate_ignore']) == 2) 13 14 { 15 // Add or remove plugin from ignore list 14 16 $ignore = unserialize($conf['autoupdate_ignore_list']); 15 17 $ignore = array_flip($ignore); … … 43 45 else 44 46 { 47 // Check if gallery or plugins are up to date 45 48 load_language('plugin.lang', dirname(__FILE__).'/'); 46 49 header('Content-Type: text/html; charset=UTF-8'); 47 50 48 include(dirname(__FILE__).'/class.inc.php'); 49 $autoupdate = new autoupdate(); 50 51 echo $autoupdate->check_version(); 51 include(AUTOUPDATE_PATH.'include/functions_remote.inc.php'); 52 echo autoupdate_check_version(); 52 53 } 53 54 -
extensions/autoupdate/template/head.tpl
r6138 r6167 21 21 }); 22 22 } 23 24 function confirm_autoupdate() {ldelim}25 conf = confirm('{'autoupdate_alert'|@translate}');26 if (conf) jQuery('#autoupdate').html('Upgrade in progress... Please wait.');27 return conf;28 }29 23 </script> 30 24 {/html_head} 31 <p id="autoupdate"><img src="plugins/autoupdate/ ajax-loader.gif"> {'Checking upgrades for gallery and plugins...'|@translate}</p>25 <p id="autoupdate"><img src="plugins/autoupdate/template/ajax-loader.gif"> {'Checking upgrades for gallery and plugins...'|@translate}</p>
Note: See TracChangeset
for help on using the changeset viewer.