Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

General update #4

Merged
5 commits merged into from
Jan 19, 2011
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion LICENCE
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ unless otherwise specified, released under the MIT licence as follows:

----- begin license block -----

Copyright 2008-2010 Alistair Kearney
Copyright 2008-2011 Alistair Kearney

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
15 changes: 11 additions & 4 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
This extension enables a Maintenance mode for Symphony.
It is part of the Symphony core download package.

- Version: 1.3
- Date: 24th December 2010
- Version: 1.4
- Date: 19th January 2011
- Requirements: Symphony 2.0.6
- Author: Alistair Kearney, [email protected]
- Constributors: [A list of contributors can be found in the commit history](http://github.com/symhonycms/maintenance_mode/commits/master)
- Author: Alistair Kearney, [email protected], and the Symphony Team, [email protected]
- Constributors: [A list of contributors can be found in the commit history](http://github.com/symphonycms/maintenance_mode/commits/master)
- GitHub Repository: <http://github.com/symphonycms/maintenance_mode>

## Synopsis
Expand All @@ -20,6 +20,13 @@ Information about [installing and updating extensions](http://symphony-cms.com/l

## Change Log

**Version 1.4**

- Added page type "maintenance" to the suggestion list
- Fixed error handling
- Removed empty language files
- Updated included translations

**Version 1.3**

- Made extension responsible for it's own Configuration settings
Expand Down
257 changes: 172 additions & 85 deletions extension.driver.php
Original file line number Diff line number Diff line change
@@ -1,137 +1,224 @@
<?php

Class extension_maintenance_mode extends Extension{
Class extension_maintenance_mode extends Extension {

public function about(){
public function about() {
return array(
'name' => 'Maintenance Mode',
'version' => '1.3',
'release-date' => '2010-12-24',
'version' => '1.4',
'release-date' => '2011-01-19',
'author' => array(
'name' => 'Alistair Kearney',
'website' => 'http://pointybeard.com',
'email' => '[email protected]'
)
array(
'name' => 'Alistair Kearney',
'website' => 'http://pointybeard.com',
'email' => '[email protected]'
),
array(
'name' => 'Symphony Team',
'website' => 'http://symphony-cms.com',
'email' => '[email protected]'
)
)
);
}

public function install() {
Symphony::Configuration()->set('enabled', 'no', 'maintenance_mode');
Administration::instance()->saveConfig();
}

public function uninstall() {
Symphony::Configuration()->remove('maintenance_mode');
}

public function getSubscribedDelegates(){
return array(
array(
'page' => '/system/preferences/',
'delegate' => 'AddCustomPreferenceFieldsets',
'callback' => 'appendPreferences'
),

array(
'page' => '/system/preferences/',
'delegate' => 'Save',
'callback' => '__SavePreferences'
),

),
array(
'page' => '/system/preferences/',
'delegate' => 'CustomActions',
'callback' => '__toggleMaintenanceMode'
),

array(
'page' => '/backend/',
'delegate' => 'AppendPageAlert',
'callback' => '__appendAlert'
),
array(
'page' => '/blueprints/pages/',
'delegate' => 'AppendPageContent',
'callback' => '__appendType'
),
array(
'page' => '/frontend/',
'delegate' => 'FrontendPrePageResolve',
'callback' => '__checkForMaintenanceMode'
),

array(
'page' => '/frontend/',
'delegate' => 'FrontendParamsResolve',
'callback' => '__addParam'
),

array(
'page' => '/backend/',
'delegate' => 'AppendPageAlert',
'callback' => '__appendAlert'
),

)
);
}

public function install() {
Symphony::Configuration()->set('enabled', 'no', 'maintenance_mode');
Administration::instance()->saveConfig();
}

public function uninstall() {
Symphony::Configuration()->remove('maintenance_mode');

/**
* Append maintenance mode preferences
*
* @param array $context
* delegate context
*/
public function appendPreferences($context) {

// Create preference group
$group = new XMLElement('fieldset');
$group->setAttribute('class', 'settings');
$group->appendChild(new XMLElement('legend', __('Maintenance Mode')));

// Append settings
$label = Widget::Label();
$input = Widget::Input('settings[maintenance_mode][enabled]', 'yes', 'checkbox');
if(Symphony::Configuration()->get('enabled', 'maintenance_mode') == 'yes') $input->setAttribute('checked', 'checked');
$label->setValue($input->generate() . ' ' . __('Enable maintenance mode'));
$group->appendChild($label);

// Append help
$group->appendChild(new XMLElement('p', __('Maintenance mode will redirect all visitors, other than developers, to the specified maintenance page. To specify a maintenance page, give a page a type of <code>maintenance</code>'), array('class' => 'help')));

// Append new preference group
$context['wrapper']->appendChild($group);
}

/**
* Save preferences
*
* @param array $context
* delegate context
*/
public function __SavePreferences($context) {

// Disable maintenance mode by default
if(!is_array($context['settings'])) {
$context['settings'] = array('maintenance_mode' => array('enabled' => 'no'));
}

// Disable maintenance mode if it has not been set to 'yes'
elseif(!isset($context['settings']['maintenance_mode'])) {
$context['settings']['maintenance_mode'] = array('enabled' => 'no');
}
}

public function __toggleMaintenanceMode($context){
if($_REQUEST['action'] == 'toggle-maintenance-mode'){
$value = (Symphony::Configuration()->get('enabled', 'maintenance_mode') == 'no' ? 'yes' : 'no');

/**
* Toggle maintenance mode and redirect to the previous page, if specified.
*/
public function __toggleMaintenanceMode() {
if($_REQUEST['action'] == 'toggle-maintenance-mode') {

// Toogle mode
$value = (Symphony::Configuration()->get('enabled', 'maintenance_mode') == 'no' ? 'yes' : 'no');
Symphony::Configuration()->set('enabled', $value, 'maintenance_mode');
Administration::instance()->saveConfig();
redirect((isset($_REQUEST['redirect']) ? SYMPHONY_URL . $_REQUEST['redirect'] : Administration::instance()->getCurrentPageURL() . '/'));

// Redirect
redirect((isset($_REQUEST['redirect']) ? URL . '/symphony' . $_REQUEST['redirect'] : Administration::instance()->getCurrentPageURL() . '/'));
}
}

public function __appendAlert($context){


/**
* Append notice that the site is currently in maintenance mode offering a link
* to switch to live mode if no other alert is set.
*
* @param array $context
* delegate context
*/
public function __appendAlert($context) {

// Check for other alerts
if(!is_null($context['alert'])) return;

if(Symphony::Configuration()->get('enabled', 'maintenance_mode') == 'yes'){
Administration::instance()->Page->pageAlert(__('This site is currently in maintenance mode.') . ' <a href="' . SYMPHONY_URL . '/system/preferences/?action=toggle-maintenance-mode&amp;redirect=' . getCurrentPage() . '">' . __('Restore?') . '</a>', Alert::NOTICE);

// Site in maintenance mode
if(Symphony::Configuration()->get('enabled', 'maintenance_mode') == 'yes') {
Administration::instance()->Page->pageAlert(
__('This site is currently in maintenance mode.') . ' <a href="' . URL . '/symphony/system/preferences/?action=toggle-maintenance-mode&amp;redirect=' . getCurrentPage() . '">' . __('Restore?') . '</a>',
Alert::NOTICE
);
}
}

public function __addParam($context){
$context['params']['site-mode'] = (Symphony::Configuration()->get('enabled', 'maintenance_mode') == 'yes' ? 'maintenance' : 'live');
}

public function __checkForMaintenanceMode($context){

if(!Frontend::instance()->isLoggedIn() && Symphony::Configuration()->get('enabled', 'maintenance_mode') == 'yes'){

$context['row'] = Symphony::Database()->fetchRow(0, "
SELECT `tbl_pages`.* FROM `tbl_pages`, `tbl_pages_types`
WHERE `tbl_pages_types`.page_id = `tbl_pages`.id
AND tbl_pages_types.`type` = 'maintenance'
LIMIT 1
");

if(empty($context['row'])){
Administration::instance()->customError(E_USER_ERROR, __('Website Offline'), __('This site is currently in maintenance. Please check back at a later date.'), false, true);

/**
* Append type for maintenance pages to page editor.
*
* @param array $context
* delegate context
*/
public function __appendType($context) {

// Find page types
$elements = $context['form']->getChildren();
$fieldset = $elements[3]->getChildren();
$group = $fieldset[2]->getChildren();
$div = $group[1]->getChildren();
$types = $div[2]->getChildren();

// Search for existing maintenance type
$flag = false;
foreach($types as $type) {
if($type->getValue() == 'maintenance') {
$flag = true;
}

}


// Append maintenance type
if($flag == false) {
$mode = new XMLElement('li', 'maintenance');
$types[1]->appendChild($mode);
}
}

public function __SavePreferences($context){

if(!is_array($context['settings'])) $context['settings'] = array('maintenance_mode' => array('enabled' => 'no'));

elseif(!isset($context['settings']['maintenance_mode'])){
$context['settings']['maintenance_mode'] = array('enabled' => 'no');

/**
* Redirect to maintenance page, if site is in maintenance and the user is not logged in
*
* @param array $context
* delegate context
*/
public function __checkForMaintenanceMode($context) {
if(!Symphony::Engine()->isLoggedIn() && Symphony::Configuration()->get('enabled', 'maintenance_mode') == 'yes'){

// Find custom maintenance page
$context['row'] = Symphony::Database()->fetchRow(0,
"SELECT `tbl_pages`.* FROM `tbl_pages`, `tbl_pages_types`
WHERE `tbl_pages_types`.page_id = `tbl_pages`.id
AND tbl_pages_types.`type` = 'maintenance'
LIMIT 1"
);

// Default maintenance message
if(empty($context['row'])) {
Symphony::Engine()->customError(
__('Website Offline'),
__('This site is currently in maintenance. Please check back at a later date.')
);
}
}

}

public function appendPreferences($context){

$group = new XMLElement('fieldset');
$group->setAttribute('class', 'settings');
$group->appendChild(new XMLElement('legend', __('Maintenance Mode')));

$label = Widget::Label();
$input = Widget::Input('settings[maintenance_mode][enabled]', 'yes', 'checkbox');
if($this->_Parent->Configuration->get('enabled', 'maintenance_mode') == 'yes') $input->setAttribute('checked', 'checked');
$label->setValue($input->generate() . ' ' . __('Enable maintenance mode'));
$group->appendChild($label);

$group->appendChild(new XMLElement('p', __('Maintenance mode will redirect all visitors, other than developers, to the specified maintenance page. To specify a maintenance page, give a page a type of <code>maintenance</code>'), array('class' => 'help')));

$context['wrapper']->appendChild($group);


/**
* Add site mode to parameter pool
*
* @param array $context
* delegate context
*/
public function __addParam($context) {
$context['params']['site-mode'] = (Symphony::Configuration()->get('enabled', 'maintenance_mode') == 'yes' ? 'maintenance' : 'live');
}

}
15 changes: 6 additions & 9 deletions lang/lang.de.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,14 @@
'author' => array(
'name' => 'Nils Hörrmann',
'email' => '[email protected]',
'website' => 'http://www.nilshoerrmann.de'
'website' => 'http://nilshoerrmann.de'
),
'release-date' => '2009-12-29'
'release-date' => '2010-01-19'
);


/*
* EXTENSION: Maintenance Mode
* Localisation strings
/**
* Maintenance Mode
*/

$dictionary = array(

'Maintenance Mode' =>
Expand All @@ -24,8 +21,8 @@
'Enable maintenance mode' =>
'Wartungsmodus aktivieren',

'Maintenance mode will redirect all visitors, other than developers, to the specified maintenance page.' =>
'Der Wartungsmodus leitet alle Besucher, die nicht als Entwickler registriert sind, auf eine festgelegte Wartungsseite um (Seitentyp: <code>maintenance</code>).',
'Maintenance mode will redirect all visitors, other than developers, to the specified maintenance page. To specify a maintenance page, give a page a type of <code>maintenance</code>' =>
'Der Wartungsmodus leitet alle Besucher, die nicht als Entwickler registriert sind, auf eine festgelegte Wartungsseite um. Sie können diese Seite mittels des Seitentyps <code>maintenance</code> festlegen.',

'This site is currently in maintenance mode.' =>
'Diese Seite ist derzeit im Wartungsmodus.',
Expand Down
Loading