XC1 Maintenance

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('Service unavailable');
	}
	
	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 "

Inställningar uppdaterade.

Gå tillbaka.
"; 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 ---- ?>

XC1 Maintenance

<form action="" method="post">
Aktivera XC1 Maintenance <input type="checkbox" id="OfflineMode_enable" name="OfflineMode_enable" value="1" /> <input type="hidden" name="OfflineMode_redirect" value="" />

msg != NULL ) { # ---- Start of HTML for msg box ---- ?>

msg; ?>

isAuthorized() && $this->allSettings['OfflineMode_enable'] ) { # ---- Admin notice msg ---- ?>

XC1 Maintenance är aktivt. Glöm inte att <a href="admin.php?page=">inaktivera det så fort du är klar.

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(); } } }

One reply on “XC1 Maintenance”

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.