Beskrivning
XC1 Maintenance tillåter dig att sätta webbplatsen i ”underhållsläge”, kommer att försöka ladda 503.php i antingen ditt ”child” eller ”parent” -tema.
Källkod
/*
Plugin Name: XC1 Maintenance
Plugin URI: http://www.xc1.se
Description: Puts the site into maintenance mode by sending a '503 Service Unavailable' status to all unauthenticated clients.
Author: Anders Hassis (Original idea by Zorex (http://blog.zorex.info/?page_id=144) and Robert Wetzlmayr (http://talkpress.de/blip/wet-maintenance-wordpress-plugin)
Version: 1.0
Author URI: http://xc1.se
License: GPL 2.0, @see http://www.gnu.org/licenses/gpl-2.0.html
*/
if(preg_match('#' . basename(__FILE__) . '#', $_SERVER['PHP_SELF'])) {
die('You are not allowed to call this page directly.');
}
// Buckle up!
$maintenance = new XC1_Maintenance();
class XC1_Maintenance {
public $version = '1.0';
public $err = false;
public $msg = '';
public $allSettings = array();
public function XC1_Maintenance() {
$this->allSettings = get_option('OfflineModeSettings');
# Display the splash if enabled
add_action('send_headers', array(&$this, 'activateMaintenancePage'));
# Admin part below
$data = array( 'OfflineMode_type' => '',
'OfflineMode_enable' => '',
'OfflineMode_startTime' => 0);
add_option('OfflineModeSettings',$data,'OfflineMode Settings');
add_action('admin_menu', array(&$this, 'addSettingsPage') );
add_action('admin_notices', array(&$this, 'adminNoticeMsg') );
}
# ----------------------------------------------------------------
# Show the settings link for this plugin
# ----------------------------------------------------------------
public function addSettingsPage() {
if (function_exists('add_options_page')) {
add_options_page('XC1 Maintenance', 'XC1 Maintenance', 8, basename(__FILE__), array(&$this, 'optionPage') ) ;
}
}
public function maintenance_header($status_header, $header, $text, $protocol) {
return "$protocol 503 Service Unavailable";
}
public function maintenance_feed() {
die('<?xml version="1.0" encoding="UTF-8"?><status>Service unavailable</status>');
}
public function add_feed_actions() {
$feeds = array ('rdf', 'rss', 'rss2', 'atom');
foreach ($feeds as $feed) {
add_action('do_feed_'.$feed, array(&$this, 'wet_maintenance_feed'), 1, 1);
}
}
# ----------------------------------------------------------------
# Show the options of the settings
# ----------------------------------------------------------------
public function optionPage() {
# User is authorized
if( $this->isAuthorized() ) {
if (isset($_POST['OfflineMode_submit'])) {
$data = array( 'OfflineMode_enable' => ((int) $_POST['OfflineMode_enable']), 'OfflineMode_startTime' => time() );
update_option('OfflineModeSettings',$data);
if (isset($_POST['OfflineMode_redirect']))
$url = $_POST['OfflineMode_redirect'];
else
$url = $_SERVER['REQUEST_URI'];
echo "<div id=\"message\" class=\"updated fade\"><p>Inställningar uppdaterade.</p> <a href=\"".$url."\">Gå tillbaka</a>.</div>";
die();
}
# Fill the settings to the form
if( $this->allSettings['OfflineMode_enable'] ) {
$enabled = ' checked="checked"';
}
# Got msg to display?
$this->msgBox();
# ---- Start HTML for settings page ----
?>
<div class="wrap">
<h2>XC1 Maintenance</h2>
<form action="<?php echo $_SERVER['REQUEST_URI'];?>" method="post">
<table class="form-table">
<tr valign="top">
<th scope="row">Aktivera XC1 Maintenance</th>
<td>
<input type="checkbox" id="OfflineMode_enable" name="OfflineMode_enable" value="1"<?php echo $enabled; ?> />
<label for="OfflineMode_enable">Stänger av webbplatsen och visar 503.php i ditt tema.</label>
<input type="hidden" name="OfflineMode_redirect" value="<?php echo $_SERVER['REQUEST_URI'];?>" />
</td>
</tr>
</table>
<p class="submit">
<input type="submit" name="OfflineMode_submit" value="Uppdatera" class="button" />
</p>
</form>
</div><?php
}
}
# ----------------------------------------------------------------
# Is user authorized to perform this action?
# ----------------------------------------------------------------
public function isAuthorized() {
return current_user_can('activate_plugins');
}
# ----------------------------------------------------------------
# Display the msg box if we got msg to display
# ----------------------------------------------------------------
public function msgBox() {
if( $this->msg != NULL ) {
# ---- Start of HTML for msg box ----
?>
<div id="message" class="updated fade"><p><?php echo $this->msg; ?></p></div>
<?php
}
}
# ----------------------------------------------------------------
# Display the notice box when OfflineMode is enabled
# ----------------------------------------------------------------
public function adminNoticeMsg() {
# User is authorized
if( $this->isAuthorized() && $this->allSettings['OfflineMode_enable'] ) {
# ---- Admin notice msg ----
?>
<div class="error">
<p>
<strong>XC1 Maintenance</strong> är aktivt. Glöm inte att <a href="admin.php?page=<?php echo basename(__FILE__); ?>">inaktivera</a> det så fort du är klar.
</p>
</div>
<?php
}
}
public function activateMaintenancePage() {
# Run the splash page lorr
if ( $this->allSettings['OfflineMode_enable'] && !$this->isAuthorized() ) {
add_filter('status_header', array(&$this, 'maintenance_header', 10, 4) );
$this->add_feed_actions();
if (file_exists(get_stylesheet_directory() . '/503.php'))
$file = get_stylesheet_directory() . '/503.php';
else
$file = get_template_directory().'/503.php';
include_once( $file );
exit();
}
}
}




[...] har laddat upp ett wordpress-tillägg under namnet XC1 Maintenance, det används för att sätta webbplatsen i underhållsläge. Inte så mycket mer att säga om [...]