1<?php 2/** 3 * Provides a means to close access to your site for upgrading and testing. 4 * 5 * A button is placed in the <i>Utility functions</i> section of the Admin overview page to allow you 6 * to manage the state of your site. This button changes function depending on the state of the site. You may 7 * <i>close</i> a site, move a closed site to <i>test mode</i>, and then <i>open</i> the site. 8 * 9 * <i>Closing</i> the site will cause links to the site <i>front end</i> to be redirected to a script in 10 * the folder <var>plugins/site_upgrade</var>. Access to the admin pages remains available. 11 * You should close the site while 12 * you are uploading a new Zenphoto release so that users will not catch the site in an unstable state. 13 * 14 * After you have uploaded the new release and run Setup you place the site in <i>test mode</i>. In this mode 15 * only logged in <i>Administrators</i> can access the <i>front end</i>. You can then, as the administrator, view the 16 * site to be sure that all your changes are as you wish them to be. 17 * 18 * Once your testing is completed you <i>open</i> your site to all visitors. 19 * 20 * Change the files in <var>plugins/site_upgrade</var> to meet your needs. (<b>Note</b> these files will 21 * be copied to that folder during setup the first time you do an install. Setup will not overrite any existing 22 * versions of these files, so if a change is made to the Zenphoto versions of the files you will have to update 23 * your copies either by removing them before running setup or by manually applying the Zenphoto changes to your 24 * files.) 25 * 26 * 27 * The plugin works best if <var>mod_rewrite</var> is active and the <var>.htaccess</var> file exists. If this is not the case 28 * the plugin will still work in most cases. However if the release you are upgrading to has significant changes involving 29 * plugin loading of the front-end site there may be PHP failures due if the site is accessed while the files 30 * being uploaded are in a mixed release state. 31 * 32 * @author Stephen Billard (sbillard) 33 * @package plugins 34 * @subpackage site-upgrade 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$plugin_category = gettext('Admin'); 41switch (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 redirectURL(WEBPATH . '/' . USER_PLUGIN_FOLDER . '/site_upgrade/closed.php', '302'); 52 } 53 } 54 break; 55 default: 56 zp_register_filter('admin_utilities_buttons', 'site_upgrade_button'); 57 zp_register_filter('installation_information', 'site_upgrade_status'); 58 59 function site_upgrade_status() { 60 global $_zp_conf_vars; 61 switch (@$_zp_conf_vars['site_upgrade_state']) { 62 case 'closed': 63 ?> 64 <li> 65 <?php echo gettext('Site status:'); ?> <span style="color:RED"><strong><?php echo gettext('The site is closed!'); ?></strong></span> 66 </li> 67 <?php 68 break; 69 case 'closed_for_test'; 70 ?> 71 <li> 72 <?php echo gettext('Site status:'); ?> <span style="color:RED"><strong><?php echo gettext('The site is in test mode!'); ?></strong></span> 73 </li> 74 <?php 75 break; 76 default: 77 ?> 78 <li> 79 <?php echo gettext('Site status:'); ?> <strong><?php echo gettext('The site is opened'); ?></strong> 80 </li> 81 <?php 82 break; 83 } 84 } 85 86 function site_upgrade_button($buttons) { 87 global $_zp_conf_vars; 88 $ht = @file_get_contents(SERVERPATH . '/.htaccess'); 89 preg_match('|[# ][ ]*RewriteRule(.*)plugins/site_upgrade/closed|', $ht, $matches); 90 if (!$matches || strpos($matches[0], '#') === 0) { 91 $state = @$_zp_conf_vars['site_upgrade_state']; 92 } else { 93 $state = 'closed'; 94 } 95 $buttons[] = array( 96 'XSRFTag' => 'site_upgrade_refresh', 97 'category' => gettext('Admin'), 98 'enable' => true, 99 'button_text' => gettext('Restore site_upgrade files'), 100 'formname' => 'refreshHTML', 101 'action' => FULLWEBPATH . '/' . ZENFOLDER . '/admin.php', 102 'icon' => FULLWEBPATH . '/' . ZENFOLDER . '/images/refresh.png', 103 '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.'), 104 'alt' => '', 105 'hidden' => '<input type="hidden" name="refreshHTML" value="1" />', 106 'rights' => ADMIN_RIGHTS 107 ); 108 switch ($state) { 109 case 'closed': 110 $buttons[] = array( 111 'XSRFTag' => 'site_upgrade', 112 'category' => gettext('Admin'), 113 'enable' => true, 114 'button_text' => gettext('Site » test mode'), 115 'formname' => 'site_upgrade.php', 116 'action' => FULLWEBPATH . '/' . ZENFOLDER . '/' . PLUGIN_FOLDER . '/site_upgrade/site_upgrade.php', 117 'icon' => FULLWEBPATH . '/' . ZENFOLDER . '/images/lock_open.png', 118 'title' => gettext('Make the site available for viewing administrators only.'), 119 'alt' => '', 120 'hidden' => '<input type="hidden" name="siteState" value="closed_for_test" />', 121 'rights' => ADMIN_RIGHTS 122 ); 123 break; 124 case 'closed_for_test': 125 $buttons[] = array( 126 'XSRFTag' => 'site_upgrade', 127 'category' => gettext('Admin'), 128 'enable' => true, 129 'button_text' => gettext('Site » open'), 130 'formname' => 'site_upgrade.php', 131 'action' => FULLWEBPATH . '/' . ZENFOLDER . '/' . PLUGIN_FOLDER . '/site_upgrade/site_upgrade.php', 132 'icon' => FULLWEBPATH . '/' . ZENFOLDER . '/images/lock.png', 133 'title' => gettext('Make site available for viewing.'), 134 'alt' => '', 135 'hidden' => '<input type="hidden" name="siteState" value="open" />', 136 'rights' => ADMIN_RIGHTS 137 ); 138 break; 139 default: 140 $buttons[] = array( 141 'XSRFTag' => 'site_upgrade', 142 'category' => gettext('Admin'), 143 'enable' => true, 144 'button_text' => gettext('Site » close'), 145 'formname' => 'site_upgrade.php', 146 'action' => FULLWEBPATH . '/' . ZENFOLDER . '/' . PLUGIN_FOLDER . '/site_upgrade/site_upgrade.php', 147 'icon' => FULLWEBPATH . '/' . ZENFOLDER . '/images/lock.png', 148 'title' => gettext('Make site unavailable for viewing by redirecting to the "closed.html" page.'), 149 'alt' => '', 150 'hidden' => '<input type="hidden" name="siteState" value="closed" />', 151 'rights' => ADMIN_RIGHTS 152 ); 153 break; 154 } 155 156 return $buttons; 157 } 158 159 if (isset($_REQUEST['refreshHTML'])) { 160 XSRFdefender('site_upgrade_refresh'); 161 $_GET['report'] = gettext('site_upgrade files Restored to original.'); 162 } else { 163 break; 164 } 165 case 2: 166 mkdir_recursive(SERVERPATH . '/' . USER_PLUGIN_FOLDER . '/site_upgrade/', FOLDER_MOD); 167 copy(SERVERPATH . '/' . ZENFOLDER . '/' . PLUGIN_FOLDER . '/site_upgrade/closed.php', SERVERPATH . '/' . USER_PLUGIN_FOLDER . '/site_upgrade/closed.php'); 168 if (isset($_REQUEST['refreshHTML']) || !file_exists(SERVERPATH . '/' . USER_PLUGIN_FOLDER . '/site_upgrade/closed.htm')) { 169 $html = file_get_contents(SERVERPATH . '/' . ZENFOLDER . '/' . PLUGIN_FOLDER . '/site_upgrade/closed.htm'); 170 $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'); 171 file_put_contents(SERVERPATH . '/' . USER_PLUGIN_FOLDER . '/site_upgrade/closed.htm', $html); 172 } 173 if (isset($_REQUEST['refreshHTML']) || !file_exists(SERVERPATH . '/' . USER_PLUGIN_FOLDER . '/site_upgrade/rss_closed.xml')) { 174 require_once(SERVERPATH . '/' . ZENFOLDER . '/' . PLUGIN_FOLDER . '/rss.php'); 175 176 class setupRSS extends RSS { 177 178 public function getitems() { 179 $this->feedtype = 'setup'; 180 $items = array(); 181 $items[] = array('title' => gettext('RSS suspended'), 182 'link' => '', 183 'enclosure' => '', 184 'category' => '', 185 'media_content' => '', 186 'media_thumbnail' => '', 187 'pubdate' => date("r", time()), 188 'desc' => gettext('The RSS feed is currently not available.')); 189 return $items; 190 } 191 192 protected function startCache() { 193 194 } 195 196 protected function endCache() { 197 198 } 199 200 } 201 202 $obj = new setupRSS(array('rss' => 'site_closed')); 203 ob_start(); 204 $obj->printFeed(); 205 $xml = ob_get_contents(); 206 ob_end_clean(); 207 file_put_contents(SERVERPATH . '/' . USER_PLUGIN_FOLDER . '/site_upgrade/rss-closed.xml', $xml); 208 } 209 setOptionDefault('zp_plugin_site_upgrade', $plugin_is_filter); 210 break; 211} 212?> 213