1 | <?php |
---|
2 | |
---|
3 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
4 | |
---|
5 | include(AUTOUPDATE_PATH.'include/functions.inc.php'); |
---|
6 | include(PHPWG_ROOT_PATH.'admin/include/pclzip.lib.php'); |
---|
7 | |
---|
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['saveTemplate']) and version_compare(PHPWG_VERSION, '2.1', '<')) |
---|
109 | { |
---|
110 | autoupdate_save_template_dir(); |
---|
111 | } |
---|
112 | |
---|
113 | if (isset($_POST['dumpDatabase'])) |
---|
114 | { |
---|
115 | autoupdate_dump_database(); |
---|
116 | } |
---|
117 | |
---|
118 | if (isset($_POST['submit']) and isset($_POST['upgrade_to'])) |
---|
119 | { |
---|
120 | autoupdate_upgrade_to($_POST['upgrade_to'], $step); |
---|
121 | } |
---|
122 | } |
---|
123 | |
---|
124 | // +-----------------------------------------------------------------------+ |
---|
125 | // | Process template | |
---|
126 | // +-----------------------------------------------------------------------+ |
---|
127 | |
---|
128 | if (!is_webmaster()) |
---|
129 | { |
---|
130 | array_push($page['errors'], l10n('Webmaster status is required.')); |
---|
131 | } |
---|
132 | |
---|
133 | $template->assign(array( |
---|
134 | 'STEP' => $step, |
---|
135 | 'AU_URL' => get_admin_plugin_menu_link(AUTOUPDATE_PATH . '/autoupdate.php'), |
---|
136 | 'PHPWG_VERSION' => PHPWG_VERSION, |
---|
137 | 'UPGRADE_TO' => $upgrade_to, |
---|
138 | 'RELEASE_URL' => PHPWG_URL.'/releases/'.$upgrade_to, |
---|
139 | ) |
---|
140 | ); |
---|
141 | |
---|
142 | $template->set_filename('plugin_admin_content', realpath(AUTOUPDATE_PATH.'template/autoupdate.tpl')); |
---|
143 | $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content'); |
---|
144 | |
---|
145 | ?> |
---|