Permalink
Browse files

Added ability to turn under construction page on or off via the CMS f…

…or convenience.
  • Loading branch information...
frankmullenger committed Nov 14, 2011
1 parent 43d6fc0 commit f24d5b945b804936826b6c0ffccf9b876bfa7cd4
Showing with 67 additions and 14 deletions.
  1. +7 −3 README.md
  2. +2 −1 _config.php
  3. +56 −10 code/UnderConstruction.php
  4. +2 −0 lang/en_US.php
View
@@ -16,18 +16,22 @@ This is essentially just a much, much better version of the [holding page module
Additionally, when the under construction page is displayed it responds to the browser with a 503 - Service Unavailable HTTP status code.
-This module could easily be changed to generate any kind of maintenance page and return any kind of HTTP status code.
+This module could easily be changed to generate any kind of maintenance page and return any kind of HTTP status code.
+
+I have updated the module so that under construction pages can be turned on or off via the SiteConfig->Access tab for convenience.
Installation Instructions
-------------------------
1. Place this directory in the root of your SilverStripe installation and call it 'underconstruction'.
2. Visit yoursite.com/dev/build to rebuild the database and create the under construction page.
3. Check that the under construction page was created by looking for an error-503.html page in the /assets folder.
-4. If you want to update the error page at any time (because your page template has changed perhaps), just delete the error-503.html page in the /assets folder and run /dev/build again to regenerate it.
+4. If you want to update the error page at any time (because your page template has changed perhaps), just delete the error-503.html page in the /assets folder and run /dev/build again to regenerate it.
+5. If your site is in dev mode then the under construction page will not be shown.
+6. You will need to go to the SiteConfig->Access tab and tick the checkbox to 'Display an under construction page?'.
Usage Overview
--------------
1. Install the module using instructions above.
-2. When you no longer want to display the under construction page remove this module (by removing the 'underconstruction' directory).
+2. When you no longer want to display the under construction page you can either remove this module (by removing the 'underconstruction' directory) or uncheck the relevant checkbox in SiteConfig->Access tab.
View
@@ -1,4 +1,5 @@
<?php
DataObject::add_extension('Page', 'UnderConstruction_Decorator');
-DataObject::add_extension('Page_Controller', 'UnderConstruction_Extension');
+DataObject::add_extension('Page_Controller', 'UnderConstruction_Extension');
+DataObject::add_extension('SiteConfig', 'UnderConstruction_Settings');
View
@@ -50,7 +50,6 @@ function requireDefaultRecords() {
}
}
}
-
}
/**
@@ -69,16 +68,63 @@ class UnderConstruction_Extension extends Extension {
* @return Void
*/
public function onBeforeInit() {
-
- //Check to see if running /dev/build
- $runningDevBuild = $this->owner && $this->owner->data() instanceof ErrorPage;
- if (!Permission::check('ADMIN')
- && strpos($_SERVER['REQUEST_URI'], '/admin') === false
- && strpos($_SERVER['REQUEST_URI'], '/Security') === false
- && !$runningDevBuild) {
- Debug::friendlyError(503);
- exit;
+ $siteConfig = SiteConfig::current_site_config();
+ $siteUnderConstruction = $siteConfig->UnderConstruction;
+
+ if ($siteUnderConstruction) {
+
+ //Check to see if running /dev/build
+ $runningDevBuild = $this->owner && $this->owner->data() instanceof ErrorPage;
+
+ if (!Permission::check('ADMIN')
+ && strpos($_SERVER['REQUEST_URI'], '/admin') === false
+ && strpos($_SERVER['REQUEST_URI'], '/Security') === false
+ && !Director::isDev()
+ && !$runningDevBuild) {
+ Debug::friendlyError(503);
+ exit;
+ }
}
}
+}
+
+/**
+ * Decorator to add settings to config to make it easier to make the site live and
+ * turn off any 'Under Construction' pages.
+ *
+ * @author Frank Mullenger <frankmullenger@gmail.com>
+ * @package underconstruction
+ */
+class UnderConstruction_Settings extends DataObjectDecorator {
+
+ /**
+ * Add database field for flag to either display or hide under construction pages.
+ *
+ * @see DataObjectDecorator::extraStatics()
+ */
+ function extraStatics() {
+ return array(
+ 'db' => array(
+ 'UnderConstruction' => 'Boolean'
+ )
+ );
+ }
+
+ /**
+ * Adding field to allow CMS users to turn off under construction pages.
+ *
+ * @see DataObjectDecorator::updateCMSFields()
+ */
+ function updateCMSFields(FieldSet &$fields) {
+ $fields->addFieldToTab('Root.Access', new HeaderField(
+ 'UnderConstructionHeading',
+ _t('UnderConstruction.SETTINGSHEADING', 'Is this site under construction?'),
+ 2
+ ));
+ $fields->addFieldToTab('Root.Access', new CheckboxField(
+ 'UnderConstruction',
+ _t('UnderConstruction.SETTINGSCHECKBOXLABEL', '&nbsp; Display an under construction page?')
+ ));
+ }
}
View
@@ -3,6 +3,8 @@
global $lang;
$lang['en_US']['UnderConstruction']['CONTENT'] = '<p>Sorry, this site is currently under construction.</p>';
+$lang['en_US']['UnderConstruction']['SETTINGSCHECKBOXLABEL'] = '&nbsp; Display an under construction page?';
+$lang['en_US']['UnderConstruction']['SETTINGSHEADING'] = 'Is this site under construction?';
$lang['en_US']['UnderConstruction']['TITLE'] = 'Under Construction';
?>

0 comments on commit f24d5b9

Please sign in to comment.