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

More freedom for styling the under construction page #6

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
32 changes: 26 additions & 6 deletions code/UnderConstruction.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
<?php

/**
* Under construction base class - allowing configuration
*/
class UnderConstruction extends Object {

}


/**
* Decorator to essentially create a static under construction {@link ErrorPage} in the assets folder
* with the aid of requireDefaultRecords().
Expand All @@ -22,12 +31,12 @@ function requireDefaultRecords() {
mkdir(ASSETS_PATH);
}

$pageUnderConstructionErrorPage = DataObject::get_one('ErrorPage', "\"ErrorCode\" = '503'");
$pageUnderConstructionErrorPage = DataObject::get_one('UnderConstructionErrorPage', "\"ErrorCode\" = '503'");
$pageUnderConstructionErrorPageExists = ($pageUnderConstructionErrorPage && $pageUnderConstructionErrorPage->exists()) ? true : false;
$pageUnderConstructionErrorPagePath = ErrorPage::get_filepath_for_errorcode(503);
$pageUnderConstructionErrorPagePath = UnderConstructionErrorPage::get_filepath_for_errorcode(503);
if(!($pageUnderConstructionErrorPageExists && file_exists($pageUnderConstructionErrorPagePath))) {
if(!$pageUnderConstructionErrorPageExists) {
$pageUnderConstructionErrorPage = new ErrorPage();
$pageUnderConstructionErrorPage = new UnderConstructionErrorPage();
$pageUnderConstructionErrorPage->ErrorCode = 503;
$pageUnderConstructionErrorPage->Title = _t('UnderConstruction.TITLE', 'Under Construction');
$pageUnderConstructionErrorPage->Content = _t('UnderConstruction.CONTENT', '<p>Sorry, this site is currently under construction.</p>');
Expand Down Expand Up @@ -75,9 +84,19 @@ public function onBeforeInit() {
if ($siteUnderConstruction) {

//Check to see if running /dev/build
$runningDevBuild = $this->owner && $this->owner->data() instanceof ErrorPage;

if (!Permission::check('ADMIN')
$runningDevBuild = $this->owner && ($this->owner->data() instanceof ErrorPage || $this->owner->data() instanceof UnderConstructionErrorPage);

//Check whether the current member is in any allowed groups
//You can set allowed groups in your config file
$inAllowedGroup = false;
$member = Member::currentUser();
if ($member && is_array($groups = UnderConstruction::config()->allowed_groups)) {
if ($member->inGroups($groups)) {
$inAllowedGroup = true;
}
}
if (!Permission::check('ADMIN')
&& !$inAllowedGroup
&& strpos($_SERVER['REQUEST_URI'], '/admin') === false
&& strpos($_SERVER['REQUEST_URI'], '/Security') === false
&& !Director::isDev()
Expand All @@ -89,6 +108,7 @@ public function onBeforeInit() {
}
}


/**
* Decorator to add settings to config to make it easier to make the site live and
* turn off any 'Under Construction' pages.
Expand Down
17 changes: 17 additions & 0 deletions code/UnderConstructionErrorPage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php
class UnderConstructionErrorPage extends ErrorPage {
}

class UnderConstructionErrorPage_Controller extends ErrorPage_Controller {

public function init(){
parent::init();

//Allowing to clear requirements via config
if (UnderConstructionErrorPage::config()->clear_requirements) {
Requirements::clear();
}

}

}