[9707] | 1 | <?php |
---|
| 2 | |
---|
| 3 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
| 4 | |
---|
[9712] | 5 | include_once(AUTOUPDATE_PATH.'include/functions.inc.php'); |
---|
| 6 | include_once(PHPWG_ROOT_PATH.'admin/include/pclzip.lib.php'); |
---|
| 7 | |
---|
[9707] | 8 | /* |
---|
| 9 | STEP: |
---|
| 10 | 0 = check is needed. If version is latest or check fail, we stay on step 0 |
---|
| 11 | 1 = new version on same branch AND new branch are available => user may choose upgrade. |
---|
| 12 | 2 = upgrade on same branch |
---|
| 13 | 3 = upgrade on different branch |
---|
| 14 | */ |
---|
| 15 | $step = isset($_GET['step']) ? $_GET['step'] : 0; |
---|
| 16 | $upgrade_to = isset($_GET['to']) ? $_GET['to'] : ''; |
---|
| 17 | |
---|
| 18 | // +-----------------------------------------------------------------------+ |
---|
| 19 | // | Step 0 | |
---|
| 20 | // +-----------------------------------------------------------------------+ |
---|
| 21 | if ($step == 0) |
---|
| 22 | { |
---|
| 23 | $template->assign(array( |
---|
| 24 | 'CHECK_VERSION' => false, |
---|
| 25 | 'DEV_VERSION' => false, |
---|
| 26 | ) |
---|
| 27 | ); |
---|
| 28 | |
---|
| 29 | if (preg_match('/(\d+\.\d+)\.(\d+)/', PHPWG_VERSION, $matches)) |
---|
| 30 | { |
---|
| 31 | $url = PHPWG_URL.'/download/all_versions.php'; |
---|
| 32 | $url .= '?rand='.md5(uniqid(rand(), true)); // Avoid server cache |
---|
| 33 | |
---|
| 34 | if (@fetchRemote($url, $result) |
---|
| 35 | and $all_versions = @explode("\n", $result) |
---|
| 36 | and is_array($all_versions)) |
---|
| 37 | { |
---|
| 38 | $template->assign('CHECK_VERSION', true); |
---|
| 39 | |
---|
| 40 | $last_version = trim($all_versions[0]); |
---|
| 41 | $upgrade_to = $last_version; |
---|
| 42 | |
---|
| 43 | if (version_compare(PHPWG_VERSION, $last_version, '<')) |
---|
| 44 | { |
---|
| 45 | $new_branch = preg_replace('/(\d+\.\d+)\.\d+/', '$1', $last_version); |
---|
| 46 | $actual_branch = $matches[1]; |
---|
| 47 | |
---|
| 48 | if ($new_branch == $actual_branch) |
---|
| 49 | { |
---|
| 50 | $step = 2; |
---|
| 51 | } |
---|
| 52 | else |
---|
| 53 | { |
---|
| 54 | $step = 3; |
---|
| 55 | |
---|
| 56 | // Check if new version exists in same branch |
---|
| 57 | foreach ($all_versions as $version) |
---|
| 58 | { |
---|
| 59 | $new_branch = preg_replace('/(\d+\.\d+)\.\d+/', '$1', $version); |
---|
| 60 | |
---|
| 61 | if ($new_branch == $actual_branch) |
---|
| 62 | { |
---|
| 63 | if (version_compare(PHPWG_VERSION, $version, '<')) |
---|
| 64 | { |
---|
| 65 | $step = 1; |
---|
| 66 | } |
---|
| 67 | break; |
---|
| 68 | } |
---|
| 69 | } |
---|
| 70 | } |
---|
| 71 | } |
---|
| 72 | } |
---|
| 73 | } |
---|
| 74 | else |
---|
| 75 | { |
---|
| 76 | $template->assign('DEV_VERSION', true); |
---|
| 77 | } |
---|
| 78 | } |
---|
| 79 | |
---|
| 80 | // +-----------------------------------------------------------------------+ |
---|
| 81 | // | Step 1 | |
---|
| 82 | // +-----------------------------------------------------------------------+ |
---|
| 83 | if ($step == 1) |
---|
| 84 | { |
---|
| 85 | $template->assign(array( |
---|
| 86 | 'MINOR_VERSION' => $version, |
---|
| 87 | 'MAJOR_VERSION' => $last_version, |
---|
| 88 | ) |
---|
| 89 | ); |
---|
| 90 | } |
---|
| 91 | |
---|
| 92 | // +-----------------------------------------------------------------------+ |
---|
| 93 | // | Step 2 | |
---|
| 94 | // +-----------------------------------------------------------------------+ |
---|
| 95 | if ($step == 2 and is_webmaster()) |
---|
| 96 | { |
---|
| 97 | if (isset($_POST['submit']) and isset($_POST['upgrade_to'])) |
---|
| 98 | { |
---|
| 99 | autoupdate_upgrade_to($_POST['upgrade_to'], $step); |
---|
| 100 | } |
---|
| 101 | } |
---|
| 102 | |
---|
| 103 | // +-----------------------------------------------------------------------+ |
---|
| 104 | // | Step 3 | |
---|
| 105 | // +-----------------------------------------------------------------------+ |
---|
| 106 | if ($step == 3 and is_webmaster()) |
---|
| 107 | { |
---|
| 108 | if (isset($_POST['dumpDatabase'])) |
---|
| 109 | { |
---|
| 110 | autoupdate_dump_database(); |
---|
| 111 | } |
---|
| 112 | |
---|
| 113 | if (isset($_POST['submit']) and isset($_POST['upgrade_to'])) |
---|
| 114 | { |
---|
| 115 | autoupdate_upgrade_to($_POST['upgrade_to'], $step); |
---|
| 116 | } |
---|
[10028] | 117 | |
---|
| 118 | include_once(AUTOUPDATE_PATH.'include/autoupdate.class.php'); |
---|
| 119 | $autoupdate = new autoupdate(); |
---|
[10037] | 120 | $autoupdate->get_merged_extensions($upgrade_to); |
---|
[10028] | 121 | $autoupdate->get_server_extensions($upgrade_to); |
---|
| 122 | $template->assign('missing', $autoupdate->missing); |
---|
[9707] | 123 | } |
---|
| 124 | |
---|
| 125 | // +-----------------------------------------------------------------------+ |
---|
| 126 | // | Process template | |
---|
| 127 | // +-----------------------------------------------------------------------+ |
---|
| 128 | |
---|
| 129 | if (!is_webmaster()) |
---|
| 130 | { |
---|
| 131 | array_push($page['errors'], l10n('Webmaster status is required.')); |
---|
| 132 | } |
---|
| 133 | |
---|
| 134 | $template->assign(array( |
---|
| 135 | 'STEP' => $step, |
---|
| 136 | 'AU_URL' => get_root_url().'admin.php?page=plugin-'.basename(dirname(__FILE__)), |
---|
| 137 | 'PHPWG_VERSION' => PHPWG_VERSION, |
---|
| 138 | 'UPGRADE_TO' => $upgrade_to, |
---|
| 139 | 'RELEASE_URL' => PHPWG_URL.'/releases/'.$upgrade_to, |
---|
| 140 | ) |
---|
| 141 | ); |
---|
| 142 | |
---|
[9712] | 143 | $template->set_filename('plugin_admin_content', realpath(AUTOUPDATE_PATH.'template/update_pwg.tpl')); |
---|
[9707] | 144 | $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content'); |
---|
| 145 | |
---|
| 146 | ?> |
---|