1: <?php
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: $plugin_is_filter = 1000 | ADMIN_PLUGIN | FEATURE_PLUGIN;
37: $plugin_description = gettext('Utility to divert access to the gallery to a screen saying the site is upgrading.');
38: $plugin_author = "Stephen Billard (sbillard)";
39: $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.');
40:
41: switch (OFFSET_PATH) {
42: case 0:
43: $state = @$_zp_conf_vars['site_upgrade_state'];
44: if ((!zp_loggedin(ADMIN_RIGHTS) && $state == 'closed_for_test') || $state == 'closed') {
45: if (isset($_zp_conf_vars['special_pages']['page']['rewrite'])) {
46: $page = $_zp_conf_vars['special_pages']['page']['rewrite'];
47: } else {
48: $page = 'page';
49: }
50: if (!preg_match('~' . preg_quote($page) . '/setup_set-mod_rewrite\?z=setup$~', $_SERVER['REQUEST_URI'])) {
51: header('location: ' . WEBPATH . '/' . USER_PLUGIN_FOLDER . '/site_upgrade/closed.php');
52: exit();
53: }
54: }
55: break;
56: default:
57: zp_register_filter('admin_utilities_buttons', 'site_upgrade_button');
58: zp_register_filter('installation_information', 'site_upgrade_status');
59:
60: function site_upgrade_status() {
61: global $_zp_conf_vars;
62: switch (@$_zp_conf_vars['site_upgrade_state']) {
63: case 'closed':
64: ?>
65: <li>
66: <?php echo gettext('Site status:'); ?> <span style="color:RED"><strong><?php echo gettext('The site is closed!'); ?></strong></span>
67: </li>
68: <?php
69: break;
70: case 'closed_for_test';
71: ?>
72: <li>
73: <?php echo gettext('Site status:'); ?> <span style="color:RED"><strong><?php echo gettext('The site is in test mode!'); ?></strong></span>
74: </li>
75: <?php
76: break;
77: default:
78: ?>
79: <li>
80: <?php echo gettext('Site status:'); ?> <strong><?php echo gettext('The site is opened'); ?></strong>
81: </li>
82: <?php
83: break;
84: }
85: }
86:
87: function site_upgrade_button($buttons) {
88: global $_zp_conf_vars;
89: $ht = @file_get_contents(SERVERPATH . '/.htaccess');
90: preg_match('|[# ][ ]*RewriteRule(.*)plugins/site_upgrade/closed|', $ht, $matches);
91: if (!$matches || strpos($matches[0], '#') === 0) {
92: $state = @$_zp_conf_vars['site_upgrade_state'];
93: } else {
94: $state = 'closed';
95: }
96: $buttons[] = array(
97: 'XSRFTag' => 'site_upgrade_refresh',
98: 'category' => gettext('Admin'),
99: 'enable' => true,
100: 'button_text' => gettext('Restore site_upgrade files'),
101: 'formname' => 'refreshHTML',
102: 'action' => WEBPATH . '/' . ZENFOLDER . '/admin.php',
103: 'icon' => 'images/refresh.png',
104: '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.'),
105: 'alt' => '',
106: 'hidden' => '<input type="hidden" name="refreshHTML" value="1" />',
107: 'rights' => ADMIN_RIGHTS
108: );
109: switch ($state) {
110: case 'closed':
111: $buttons[] = array(
112: 'XSRFTag' => 'site_upgrade',
113: 'category' => gettext('Admin'),
114: 'enable' => true,
115: 'button_text' => gettext('Site » test mode'),
116: 'formname' => 'site_upgrade.php',
117: 'action' => WEBPATH . '/' . ZENFOLDER . '/' . PLUGIN_FOLDER . '/site_upgrade/site_upgrade.php',
118: 'icon' => 'images/lock_open.png',
119: 'title' => gettext('Make the site available for viewing administrators only.'),
120: 'alt' => '',
121: 'hidden' => '<input type="hidden" name="siteState" value="closed_for_test" />',
122: 'rights' => ADMIN_RIGHTS
123: );
124: break;
125: case 'closed_for_test':
126: $buttons[] = array(
127: 'XSRFTag' => 'site_upgrade',
128: 'category' => gettext('Admin'),
129: 'enable' => true,
130: 'button_text' => gettext('Site » open'),
131: 'formname' => 'site_upgrade.php',
132: 'action' => WEBPATH . '/' . ZENFOLDER . '/' . PLUGIN_FOLDER . '/site_upgrade/site_upgrade.php',
133: 'icon' => 'images/lock.png',
134: 'title' => gettext('Make site available for viewing.'),
135: 'alt' => '',
136: 'hidden' => '<input type="hidden" name="siteState" value="open" />',
137: 'rights' => ADMIN_RIGHTS
138: );
139: break;
140: default:
141: $buttons[] = array(
142: 'XSRFTag' => 'site_upgrade',
143: 'category' => gettext('Admin'),
144: 'enable' => true,
145: 'button_text' => gettext('Site » close'),
146: 'formname' => 'site_upgrade.php',
147: 'action' => WEBPATH . '/' . ZENFOLDER . '/' . PLUGIN_FOLDER . '/site_upgrade/site_upgrade.php',
148: 'icon' => 'images/lock.png',
149: 'title' => gettext('Make site unavailable for viewing by redirecting to the "closed.html" page.'),
150: 'alt' => '',
151: 'hidden' => '<input type="hidden" name="siteState" value="closed" />',
152: 'rights' => ADMIN_RIGHTS
153: );
154: break;
155: }
156:
157: return $buttons;
158: }
159:
160: if (isset($_REQUEST['refreshHTML'])) {
161: XSRFdefender('site_upgrade_refresh');
162: $_GET['report'] = gettext('site_upgrade files Restored to original.');
163: } else {
164: break;
165: }
166: case 2:
167: mkdir_recursive(SERVERPATH . '/' . USER_PLUGIN_FOLDER . '/site_upgrade/', FOLDER_MOD);
168: copy(SERVERPATH . '/' . ZENFOLDER . '/' . PLUGIN_FOLDER . '/site_upgrade/closed.php', SERVERPATH . '/' . USER_PLUGIN_FOLDER . '/site_upgrade/closed.php');
169: if (isset($_REQUEST['refreshHTML']) || !file_exists(SERVERPATH . '/' . USER_PLUGIN_FOLDER . '/site_upgrade/closed.htm')) {
170: $html = file_get_contents(SERVERPATH . '/' . ZENFOLDER . '/' . PLUGIN_FOLDER . '/site_upgrade/closed.htm');
171: $html = sprintf($html, sprintf(gettext('%s upgrade'), $_zp_gallery->getTitle()), FULLWEBPATH . '/' . ZENFOLDER . '/images/zen-logo.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');
172: file_put_contents(SERVERPATH . '/' . USER_PLUGIN_FOLDER . '/site_upgrade/closed.htm', $html);
173: }
174: if (isset($_REQUEST['refreshHTML']) || !file_exists(SERVERPATH . '/' . USER_PLUGIN_FOLDER . '/site_upgrade/rss_closed.xml')) {
175: require_once(SERVERPATH . '/' . ZENFOLDER . '/' . PLUGIN_FOLDER . '/rss.php');
176:
177: class setupRSS extends RSS {
178:
179: public function getitems() {
180: $this->feedtype = 'setup';
181: $items = array();
182: $items[] = array('title' => gettext('RSS suspended'),
183: 'link' => '',
184: 'enclosure' => '',
185: 'category' => '',
186: 'media_content' => '',
187: 'media_thumbnail' => '',
188: 'pubdate' => date("r", time()),
189: 'desc' => gettext('The RSS feed is currently not available.'));
190: return $items;
191: }
192:
193: protected function startCache() {
194:
195: }
196:
197: protected function endCache() {
198:
199: }
200:
201: }
202:
203: $obj = new setupRSS(array('rss' => 'site_closed'));
204: ob_start();
205: $obj->printFeed();
206: $xml = ob_get_contents();
207: ob_end_clean();
208: file_put_contents(SERVERPATH . '/' . USER_PLUGIN_FOLDER . '/site_upgrade/rss-closed.xml', $xml);
209: }
210: if (isset($_REQUEST['refreshHTML']) || !file_exists(SERVERPATH . '/' . USER_PLUGIN_FOLDER . '/site_upgrade/externalFeed_closed.xml')) {
211: require_once(SERVERPATH . '/' . ZENFOLDER . '/' . PLUGIN_FOLDER . '/externalFeed.php');
212:
213: class setupexternalFeed extends externalFeed {
214:
215: public function getitems() {
216: $this->feedtype = 'setup';
217: $items = array();
218: $items[] = array('title' => gettext('externalFeed suspended'),
219: 'link' => '',
220: 'enclosure' => '',
221: 'category' => '',
222: 'media_content' => '',
223: 'media_thumbnail' => '',
224: 'pubdate' => date("r", time()),
225: 'desc' => gettext('The external feed is currently not available.'));
226: return $items;
227: }
228:
229: protected function startCache() {
230:
231: }
232:
233: protected function endCache() {
234:
235: }
236:
237: }
238:
239: $obj = new setupexternalFeed(array('external' => 'site_closed'));
240: ob_start();
241: $obj->printFeed();
242: $xml = ob_get_contents();
243: ob_end_clean();
244: file_put_contents(SERVERPATH . '/' . USER_PLUGIN_FOLDER . '/site_upgrade/externalFeed-closed.xml', $xml);
245: }
246: setOptionDefault('zp_plugin_site_upgrade', $plugin_is_filter);
247: break;
248: }
249: ?>
250: