forked from sbillard/netPhotoGraphics-DEV
/
site_upgrade.php
290 lines (277 loc) · 11.4 KB
/
site_upgrade.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
<?php
/**
* Provides a means to close access to your site for upgrading and testing.
*
* A button is placed in the <i>Utility functions</i> section of the Admin overview page to allow you
* to manage the state of your site. This button changes function depending on the state of the site. You may
* <i>close</i> a site, move a closed site to <i>test mode</i>, and then <i>open</i> the site.
*
* <i>Closing</i> the site will cause links to the site <i>front end</i> to be redirected to a script in
* the folder <var>plugins/site_upgrade</var>. Access to the admin pages remains available.
* You should close the site while
* you are uploading a new release so that users will not catch the site in an unstable state.
*
* After you have uploaded the new release and run Setup you place the site in <i>test mode</i>. In this mode
* only logged in <i>Administrators</i> can access the <i>front end</i>. You can then, as the administrator, view the
* site to be sure that all your changes are as you wish them to be.
*
* Once your testing is completed you <i>open</i> your site to all visitors.
*
* Change the files in <var>plugins/site_upgrade</var> to meet your needs. (<b>Note</b> these files will
* be copied to that folder during setup the first time you do an install. Setup will not overrite any existing
* versions of these files, so if a change is made to the distributed versions of the files you will have to update
* your copies either by removing them before running setup or by manually applying the distributed file changes to your
* files.)
*
*
* The plugin works best if <var>mod_rewrite</var> is active and the <var>.htaccess</var> file exists. If this is not the case
* the plugin will still work in most cases. However if you the release you are upgrading to has significant changes involving
* plugin loading of the front-end site there may be PHP failures due if the site is accessed while the files
* being uploaded are in a mixed release state.
*
* @author Stephen Billard (sbillard)
*
* @package plugins
* @subpackage admin
*/
$plugin_is_filter = defaultExtension(1000 | ADMIN_PLUGIN | FEATURE_PLUGIN);
$plugin_description = gettext('Utility to divert access to the gallery to a screen saying the site is upgrading.');
$plugin_author = "Stephen Billard (sbillard)";
$plugin_notice = (MOD_REWRITE) ? false : gettext('<em>mod_rewrite</em> is not enabled. This plugin may not work without rewrite redirection if the upgrade is significantly different than the running release.');
if (OFFSET_PATH) {
$_site_filelist = array(
'closed.htm' => '+', // copy and update
'closed.php' => '*', // just copy
// "feed" plugins. The convention is that the file name is plugin prefix-closed.xml
'rss-closed.xml' => 'RSS', // create from RSS class
'externalFeed-closed.xml' => 'externalFeed' // create from externamFeed class
);
}
switch (OFFSET_PATH) {
case 0:
function site_upgrade_notice($html) {
?>
<div style="width: 100%; position: fixed; top: 0px; left: 0px; z-index: 1000;" >
<p style="text-align: center;">
<strong style="background-color: #FFEFB7; color:black; padding: 5px;">
<?php echo gettext('Site is available for testing only.'); ?>
</strong>
</p>
</div>
<?php
}
$state = @$_zp_conf_vars['site_upgrade_state'];
if ((!zp_loggedin(ADMIN_RIGHTS | DEBUG_RIGHTS) && $state == 'closed_for_test') || $state == 'closed') {
if (isset($_zp_conf_vars['special_pages']['page']['rewrite'])) {
$page = $_zp_conf_vars['special_pages']['page']['rewrite'];
} else {
$page = 'page';
}
if (!preg_match('~' . preg_quote($page) . '/setup_set-mod_rewrite\?z=setup$~', $_SERVER['REQUEST_URI'])) {
header('location: ' . WEBPATH . '/' . USER_PLUGIN_FOLDER . '/site_upgrade/closed.php');
exit();
}
} else if ($state == 'closed_for_test') {
zp_register_filter('theme_body_open', 'site_upgrade_notice');
}
break;
default:
zp_register_filter('admin_utilities_buttons', 'site_upgrade_button');
zp_register_filter('installation_information', 'site_upgrade_status');
zp_register_filter('admin_note', 'site_upgrade_note');
function site_upgrade_note($where) {
global $_zp_conf_vars;
switch (@$_zp_conf_vars['site_upgrade_state']) {
case 'closed':
if ($where == 'Overview') {
?>
<form class="dirtylistening" name="site_upgrade_form" id="site_upgrade_form">
</form>
<script type="text/javascript">
$(document).ready(function () {
$('#site_upgrade_form').dirtyForms('setDirty');
$.DirtyForms.message = '<?php echo gettext('The site is closed!'); ?>';
});
</script>
<?php
}
?>
<p class="errorbox">
<strong><?php echo gettext('The site is closed!'); ?></strong></span>
</p>
<?php
break;
case 'closed_for_test';
?>
<p class="notebox">
<strong><?php echo gettext('Site is available for testing only.');
?></strong>
</p>
<?php
break;
}
}
function site_upgrade_status() {
global $_zp_conf_vars;
switch (@$_zp_conf_vars['site_upgrade_state']) {
case 'closed':
?>
<li>
<?php echo gettext('Site status:'); ?> <span style="color:RED"><strong><?php echo gettext('The site is closed!'); ?></strong></span>
</li>
<?php
break;
case 'closed_for_test';
?>
<li>
<?php echo gettext('Site status:'); ?> <span style="color:RED"><strong><?php echo gettext('The site is in test mode!'); ?></strong></span>
</li>
<?php
break;
default:
?>
<li>
<?php echo gettext('Site status:'); ?> <strong><?php echo gettext('The site is opened'); ?></strong>
</li>
<?php
break;
}
}
function site_upgrade_button($buttons) {
global $_zp_conf_vars, $_site_filelist;
$state = @$_zp_conf_vars['site_upgrade_state'];
$hash = '';
foreach ($_site_filelist as $name => $source) {
if (file_exists(SERVERPATH . '/' . USER_PLUGIN_FOLDER . '/site_upgrade/' . $name)) {
$hash .= md5(file_get_contents(SERVERPATH . '/' . USER_PLUGIN_FOLDER . '/site_upgrade/' . $name));
}
}
if ($hash !== getOption('site_upgrade_hash')) {
$buttons[] = array(
'XSRFTag' => 'site_upgrade_refresh',
'category' => gettext('Admin'),
'enable' => true,
'button_text' => gettext('Restore site_upgrade files'),
'formname' => 'refreshHTML',
'action' => FULLWEBPATH . '/' . ZENFOLDER . '/admin.php',
'icon' => 'images/refresh.png',
'title' => gettext('Restores the files in the "plugins/site_upgrade" folder to their default state. Note: this will overwrite any custom edits you may have made.'),
'alt' => '',
'hidden' => '<input type="hidden" name="refreshHTML" value="1" />',
'rights' => ADMIN_RIGHTS
);
}
switch ($state) {
case 'closed':
$buttons[] = array(
'XSRFTag' => 'site_upgrade',
'category' => gettext('Admin'),
'enable' => 2,
'button_text' => gettext('Site » test mode'),
'formname' => 'site_upgrade',
'action' => FULLWEBPATH . '/' . ZENFOLDER . '/' . PLUGIN_FOLDER . '/site_upgrade/site_upgrade.php',
'icon' => 'images/lock_open.png',
'title' => gettext('Make the site available for viewing administrators only.'),
'onclick' => "$('#site_upgrade_form').dirtyForms('setClean');this.form.submit();",
'alt' => '',
'hidden' => '<input type="hidden" name="siteState" value="closed_for_test" />',
'rights' => ADMIN_RIGHTS
);
break;
case 'closed_for_test':
$buttons[] = array(
'XSRFTag' => 'site_upgrade',
'category' => gettext('Admin'),
'enable' => 2,
'button_text' => gettext('Site » open'),
'formname' => 'site_upgrade',
'action' => FULLWEBPATH . '/' . ZENFOLDER . '/' . PLUGIN_FOLDER . '/site_upgrade/site_upgrade.php',
'icon' => 'images/lock.png',
'title' => gettext('Make site available for viewing.'),
'alt' => '',
'hidden' => '<input type="hidden" name="siteState" value="open" />',
'rights' => ADMIN_RIGHTS
);
list($diff, $needs) = checkSignature(0);
if (zpFunctions::hasPrimaryScripts() && empty($needs)) {
?>
<script type="text/javascript">
window.addEventListener('load', function () {
$('#site_upgrade').submit(function () {
return confirm('<?php echo gettext('Your setup scripts are not protected!'); ?>');
})
}, false);
</script>
<?php
}
break;
default:
$buttons[] = array(
'XSRFTag' => 'site_upgrade',
'category' => gettext('Admin'),
'enable' => true,
'button_text' => gettext('Site » close'),
'formname' => 'site_upgrade.php',
'action' => FULLWEBPATH . '/' . ZENFOLDER . '/' . PLUGIN_FOLDER . '/site_upgrade/site_upgrade.php',
'icon' => 'images/lock.png',
'title' => gettext('Make site unavailable for viewing by redirecting to the "closed.html" page.'),
'alt' => '',
'hidden' => '<input type="hidden" name="siteState" value="closed" />',
'rights' => ADMIN_RIGHTS
);
break;
}
return $buttons;
}
if (isset($_REQUEST['refreshHTML'])) {
XSRFdefender('site_upgrade_refresh');
$_GET['report'] = gettext('site_upgrade files Restored to original.');
} else {
break;
}
case 2:
mkdir_recursive(SERVERPATH . '/' . USER_PLUGIN_FOLDER . '/site_upgrade/', FOLDER_MOD);
$hash = '';
foreach ($_site_filelist as $name => $source) {
if (isset($_REQUEST['refreshHTML']) || !file_exists(SERVERPATH . '/' . USER_PLUGIN_FOLDER . '/site_upgrade/' . $name)) {
switch ($source) {
case '+':
case '*':
$data = file_get_contents(SERVERPATH . '/' . ZENFOLDER . '/' . PLUGIN_FOLDER . '/site_upgrade/' . $name);
if ($source != '*') {
$data = sprintf($data, sprintf(gettext('%s upgrade'), $_zp_gallery->getTitle()), FULLWEBPATH . '/' . ZENFOLDER . '/' . PLUGIN_FOLDER . '/site_upgrade/closed.png', sprintf(gettext('<strong><em>%s</em></strong> is undergoing an upgrade'), $_zp_gallery->getTitle()), '<a href="' . FULLWEBPATH . '/index.php">' . gettext('Please return later') . '</a>', FULLWEBPATH . '/index.php');
}
break;
default:
// Feed plugin
$plugin = substr($name, 0, strpos($name, '-')) . '.php';
$items = array(
array(
'title' => sprintf(gettext('%s suspended'), $source),
'link' => '',
'enclosure' => '',
'category' => '',
'media_content' => '',
'media_thumbnail' => '',
'pubdate' => date("r", time()),
'desc' => sprintf(gettext('The %s feed is currently not available.'), $source)
)
);
require_once(SERVERPATH . '/' . ZENFOLDER . '/' . PLUGIN_FOLDER . '/' . $plugin);
$obj = new $source(array(strtolower($source) => 'null'));
ob_start();
$obj->printFeed($items);
$data = ob_get_contents();
ob_end_clean();
break;
}
file_put_contents(SERVERPATH . '/' . USER_PLUGIN_FOLDER . '/site_upgrade/' . $name, $data);
$hash .= md5(file_get_contents(SERVERPATH . '/' . USER_PLUGIN_FOLDER . '/site_upgrade/' . $name));
}
}
if ($hash) {
setOption('site_upgrade_hash', $hash);
}
break;
}
?>