folio3_maintenanceMode - Version 1.0.0

Version Notes

The basic functionality is to put the website into Maintenance mode. Additionally this extension has a count down and it also supports IP White listing.

Download this release

Release Info

Developer Folio3
Extension folio3_maintenanceMode
Version 1.0.0
Comparing to
See all releases


Version 1.0.0

app/code/community/Folio3/MaintenanceMode/Block/Adminhtml/System/Config/Date.php ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Folio3_MaintenanceMode_Block_Adminhtml_System_Config_Date extends Mage_Adminhtml_Block_System_Config_Form_Field
3
+ {
4
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
5
+ {
6
+ $date = new Varien_Data_Form_Element_Date;
7
+ $timeFormat = ' H:mm:ss';
8
+ $dateTimeformat = 'MM/d/y ' . $timeFormat;
9
+
10
+ $data = array(
11
+ 'name' => $element->getName(),
12
+ 'html_id' => $element->getId(),
13
+ 'image' => $this->getSkinUrl('images/grid-cal.gif'),
14
+ );
15
+
16
+ $date->setData($data);
17
+ $value = $element->getValue();
18
+ if($value == "Today"){
19
+ $value = strtotime('now');
20
+ }
21
+
22
+ $date->setValue($value, $dateTimeformat);
23
+ $date->setTime($date->getValue("H:mm"));
24
+
25
+ $date->setFormat($dateTimeformat);
26
+ $date->setForm($element->getForm());
27
+
28
+ return $date->getElementHtml();
29
+ }
30
+ }
app/code/community/Folio3/MaintenanceMode/Block/Page.php ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Folio3_MaintenanceMode_Block_Page extends Mage_Core_Block_Template{
3
+ private $helper, $storeCode;
4
+
5
+ public function __construct(){
6
+ parent::__construct();
7
+
8
+ $this->helper = Mage::helper('Folio3_MaintenanceMode');
9
+ $this->storeCode = Mage::app()->getRequest()->getStoreCodeFromPath();
10
+ }
11
+
12
+ private function _loadBlock(){
13
+ $staticBlockId = $this->helper->getConfig('pageStaticBlock', $this->storeCode);
14
+ $pageContentBlock = $this->getLayout()->createBlock('cms/block')->setBlockId($staticBlockId);
15
+
16
+ $this->append($pageContentBlock);
17
+ }
18
+
19
+ public function getStaticPageIdentifier(){
20
+ $this->_loadBlock();
21
+ return $this->getSortedChildren()[0];
22
+ }
23
+
24
+ public function hasCountdown(){
25
+ $showCountdown = $this->helper->getConfig('showCountdown', $this->storeCode);
26
+ if($showCountdown) {
27
+ if ($this->getCountDownTime() !== '') {
28
+ return true;
29
+ }
30
+ }
31
+
32
+ return false;
33
+ }
34
+
35
+ public function getCountDownTime(){
36
+ $upDateTime = $this->helper->getConfig('upDateTime', $this->storeCode);
37
+
38
+ if($upDateTime !== ''){
39
+ $upDateTime = strtotime($upDateTime);
40
+ $Now = strtotime('now');
41
+
42
+ $Diff = $upDateTime - $Now;
43
+ if($Diff > 0){
44
+ return $Diff;
45
+ }
46
+ }
47
+
48
+ return '';
49
+ }
50
+ }
51
+ ?>
app/code/community/Folio3/MaintenanceMode/Controller/Router/Standard.php ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Folio3_MaintenanceMode_Controller_Router_Standard extends Mage_Core_Controller_Varien_Router_Standard {
4
+ public function match(Zend_Controller_Request_Http $request) {
5
+ $helper = Mage::helper('Folio3_MaintenanceMode');
6
+ $storeCode = $request->getStoreCodeFromPath();
7
+
8
+ $isEnabled = $helper->getConfig('isEnabled', $storeCode);
9
+ if ($isEnabled) {
10
+ $allowedIPs = $helper->getAllowedIPs($storeCode);
11
+ $currentIP = $_SERVER['REMOTE_ADDR'];
12
+
13
+ $adminAccess = $helper->getConfig('adminAccess', $storeCode);
14
+ $adminIp = null;
15
+ if ($adminAccess) {
16
+ //get the admin session
17
+ Mage::getSingleton('core/session', array('name' => 'adminhtml'));
18
+
19
+
20
+ //verify if the user is logged in to the backend
21
+ $adminSession = Mage::getSingleton('admin/session');
22
+ if ($adminSession->isLoggedIn()) {
23
+ //do stuff
24
+ $adminIp = $adminSession['_session_validator_data']['remote_addr'];
25
+ }
26
+ }
27
+
28
+ if ($currentIP !== $adminIp) {
29
+ if (!in_array($currentIP, $allowedIPs)) {
30
+ $pageBlock = $helper->getMaintenancePageBlock();
31
+
32
+ // if custom maintenance page is defined in backend, display this one
33
+ if ($pageBlock->toHtml() !== '') {
34
+ Mage::getSingleton('core/session', array('name' => 'front'));
35
+
36
+ $response = $this->getFront()->getResponse();
37
+
38
+ $response->setHeader('HTTP/1.1', '503 Service Temporarily Unavailable');
39
+ $response->setHeader('Status', '503 Service Temporarily Unavailable');
40
+ $response->setHeader('Retry-After', '5000');
41
+
42
+ $response->setBody($pageBlock->toHtml());
43
+ $response->sendHeaders();
44
+ $response->outputBody();
45
+ }
46
+
47
+ exit();
48
+ }
49
+ }
50
+ }
51
+
52
+ return parent::match($request);
53
+ }
54
+ }
app/code/community/Folio3/MaintenanceMode/Helper/Data.php ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Folio3_MaintenanceMode_Helper_Data extends Mage_Core_Helper_Abstract {
3
+ public function getConfig($key, $storeId = null) {
4
+ $path = 'MaintenanceMode/config/' . $key;
5
+ return Mage::getStoreConfig($path, $storeId);
6
+ }
7
+
8
+ public function getMaintenancePageBlock(){
9
+ $block = Mage::app()
10
+ ->loadArea('frontend')
11
+ ->getLayout()
12
+ ->createBlock('folio3_maintenanceMode/page')
13
+ ->setTemplate('maintenanceMode/page.phtml');
14
+
15
+ return $block;
16
+ }
17
+
18
+ public function getAllowedIPs($storeCode){
19
+ $allowedIPsString = $this->getConfig('allowedIPs', $storeCode);
20
+
21
+ // remove spaces from string
22
+ $allowedIPsString = trim(preg_replace('/ +/', ',', preg_replace('/[\n\r]/', ' ', $allowedIPsString)), ' ,');
23
+ $allowedIPs = array();
24
+ if ('' !== trim($allowedIPsString)) {
25
+ $allowedIPs = explode(',', $allowedIPsString);
26
+ }
27
+
28
+ return $allowedIPs;
29
+ }
30
+ }
31
+
app/code/community/Folio3/MaintenanceMode/etc/config.xml ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Folio3_MaintenanceMode>
5
+ <version>1.0.0</version>
6
+ </Folio3_MaintenanceMode>
7
+ </modules>
8
+ <global>
9
+ <models>
10
+ <Folio3_MaintenanceMode>
11
+ <class>Folio3_MaintenanceMode_Model</class>
12
+ </Folio3_MaintenanceMode>
13
+ </models>
14
+ <blocks>
15
+ <folio3_maintenanceMode>
16
+ <class>Folio3_MaintenanceMode_Block</class>
17
+ </folio3_maintenanceMode>
18
+ </blocks>
19
+ <helpers>
20
+ <Folio3_MaintenanceMode>
21
+ <class>Folio3_MaintenanceMode_Helper</class>
22
+ </Folio3_MaintenanceMode>
23
+ </helpers>
24
+ </global>
25
+ <stores>
26
+ <default>
27
+ <web>
28
+ <routers>
29
+ <standard>
30
+ <area>frontend</area>
31
+ <class>Folio3_MaintenanceMode_Controller_Router_Standard</class>
32
+ </standard>
33
+ </routers>
34
+ </web>
35
+ </default>
36
+ </stores>
37
+ <default>
38
+ <web>
39
+ <routers>
40
+ <standard>
41
+ <area>frontend</area>
42
+ <class>Folio3_MaintenanceMode_Controller_Router_Standard</class>
43
+ </standard>
44
+ </routers>
45
+ </web>
46
+ <MaintenanceMode>
47
+ <config>
48
+ <isEnabled>0</isEnabled>
49
+ <adminAccess>1</adminAccess>
50
+ <allowedIPs></allowedIPs>
51
+ <pageContent><![CDATA[<h1>we are sorry but this store is down for maintenance</h1>
52
+ <h2>please try again later ...</h2>]]></pageContent>
53
+ <upDateTime>Today</upDateTime>
54
+ </config>
55
+ </MaintenanceMode>
56
+ </default>
57
+ <adminhtml>
58
+ <acl>
59
+ <resources>
60
+ <admin>
61
+ <children>
62
+ <system>
63
+ <children>
64
+ <config>
65
+ <children>
66
+ <MaintenanceMode>
67
+ <title>Maintenance Mode</title>
68
+ </MaintenanceMode>
69
+ </children>
70
+ </config>
71
+ </children>
72
+ </system>
73
+ </children>
74
+ </admin>
75
+ </resources>
76
+ </acl>
77
+ </adminhtml>
78
+ </config>
app/code/community/Folio3/MaintenanceMode/etc/system.xml ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <tabs>
4
+ <folio3 translate="label" module="Folio3_MaintenanceMode">
5
+ <label>Folio3 Extensions</label>
6
+ <sort_order>100</sort_order>
7
+ </folio3>
8
+ </tabs>
9
+
10
+ <sections>
11
+ <MaintenanceMode translate="label" module="Folio3_MaintenanceMode">
12
+ <label>Maintenance Mode</label>
13
+ <tab>folio3</tab>
14
+ <frontend_type>text</frontend_type>
15
+ <sort_order>998</sort_order>
16
+ <show_in_default>1</show_in_default>
17
+ <show_in_website>1</show_in_website>
18
+ <show_in_store>1</show_in_store>
19
+ <groups>
20
+ <config translate="label">
21
+ <label>Configuration</label>
22
+ <frontend_type>text</frontend_type>
23
+ <sort_order>1</sort_order>
24
+ <show_in_default>1</show_in_default>
25
+ <show_in_website>0</show_in_website>
26
+ <show_in_store>1</show_in_store>
27
+ <fields>
28
+ <isEnabled translate="label">
29
+ <label>Maintenance Mode?</label>
30
+ <comment>Enable Maintenance Mode?</comment>
31
+ <frontend_type>select</frontend_type>
32
+ <source_model>adminhtml/system_config_source_yesno</source_model>
33
+ <sort_order>1</sort_order>
34
+ <show_in_default>1</show_in_default>
35
+ <show_in_website>0</show_in_website>
36
+ <show_in_store>1</show_in_store>
37
+ </isEnabled>
38
+ <adminAccess translate="label">
39
+ <label>Admin Access</label>
40
+ <comment>Administrators bypass Maintenance Mode?</comment>
41
+ <frontend_type>select</frontend_type>
42
+ <source_model>adminhtml/system_config_source_yesno</source_model>
43
+ <sort_order>2</sort_order>
44
+ <show_in_default>1</show_in_default>
45
+ <show_in_website>0</show_in_website>
46
+ <show_in_store>1</show_in_store>
47
+ </adminAccess>
48
+ <allowedIPs translate="label">
49
+ <label>Allowed IPs</label>
50
+ <comment><![CDATA[List of Allowed IPs (One per line)]]></comment>
51
+ <frontend_type>textarea</frontend_type>
52
+ <sort_order>3</sort_order>
53
+ <show_in_default>1</show_in_default>
54
+ <show_in_website>0</show_in_website>
55
+ <show_in_store>1</show_in_store>
56
+ </allowedIPs>
57
+ <pageStaticBlock>
58
+ <label>Maintenance Page (Static Block)</label>
59
+ <comment>Select a static block for your maintenance page.</comment>
60
+ <frontend_type>select</frontend_type>
61
+ <source_model>cms/resource_block_collection</source_model>
62
+ <sort_order>4</sort_order>
63
+ <show_in_default>1</show_in_default>
64
+ <show_in_website>0</show_in_website>
65
+ <show_in_store>1</show_in_store>
66
+ </pageStaticBlock>
67
+ <showCountdown translate="label comment">
68
+ <label>Enable Countdown</label>
69
+ <comment>Enable/Disable counter on the maintenance page</comment>
70
+ <frontend_type>select</frontend_type>
71
+ <source_model>adminhtml/system_config_source_yesno</source_model>
72
+ <sort_order>5</sort_order>
73
+ <show_in_default>1</show_in_default>
74
+ <show_in_website>0</show_in_website>
75
+ <show_in_store>1</show_in_store>
76
+ </showCountdown>
77
+ <upDateTime translate="label comment">
78
+ <label>Expected Up Date/Time</label>
79
+ <frontend_type>text</frontend_type>
80
+ <frontend_model>folio3_maintenanceMode/adminhtml_system_config_date</frontend_model>
81
+ <sort_order>6</sort_order>
82
+ <show_in_default>1</show_in_default>
83
+ <show_in_website>0</show_in_website>
84
+ <show_in_store>1</show_in_store>
85
+ </upDateTime>
86
+ </fields>
87
+ </config>
88
+ </groups>
89
+ </MaintenanceMode>
90
+ </sections>
91
+ </config>
app/design/frontend/base/default/template/maintenanceMode/page.phtml ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
2
+ "http://www.w3.org/TR/html4/strict.dtd">
3
+ <html>
4
+ <head>
5
+ <title>Site Under Maintenance</title>
6
+
7
+ <link rel="stylesheet" type="text/css" href="<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_JS);?>countdown/jquery.countdown.css">
8
+ <script type="text/javascript" src="<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_JS);?>countdown/jquery.min.js"></script>
9
+ <script type="text/javascript" src="<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_JS);?>countdown/jquery.plugin.min.js"></script>
10
+ <script type="text/javascript" src="<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_JS);?>countdown/jquery.countdown.min.js"></script>
11
+
12
+ <?php if($this->hasCountdown()) : ?>
13
+ <script type="text/javascript">
14
+ jQuery(document).ready(function(){
15
+ jQuery('#counter').countdown({
16
+ until: '<?php echo $this->getCountDownTime(); ?>',
17
+ format: 'dHMs'
18
+ });
19
+ });
20
+ </script>
21
+ <?php endif; ?>
22
+
23
+ <style>
24
+ *{
25
+ margin: 0px;
26
+ passing: 0px;
27
+ }
28
+
29
+ body{
30
+ background-color: #222222;
31
+ color: #DDDDDD;
32
+ font-family: sans-serif;
33
+ margin-top: 350px;
34
+ }
35
+
36
+ .block{
37
+ padding: 25px;
38
+ background-color: #555555;
39
+ }
40
+ </style>
41
+ </head>
42
+ <body>
43
+ <div class="block">
44
+ <?php echo $this->getChildHtml($this->getStaticPageIdentifier()); ?>
45
+ <div id="counter"></div>
46
+ </div>
47
+ </body>
48
+ </html>
app/etc/modules/Folio3_MaintenanceMode.xml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Folio3_MaintenanceMode>
5
+ <active>true</active>
6
+ <codePool>community</codePool>
7
+ </Folio3_MaintenanceMode>
8
+ </modules>
9
+ </config>
package.xml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>folio3_maintenanceMode</name>
4
+ <version>1.0.0</version>
5
+ <stability>stable</stability>
6
+ <license uri="https://opensource.org/licenses/OSL-3.0">Open Software License (OSL)</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>The basic functionality is to put the website into Maintenance mode. Additionally this extension has a count down and it also supports IP White listing. </summary>
10
+ <description>The basic functionality is to put the website into Maintenance mode. Additionally this extension has a count down and it also supports IP White listing. </description>
11
+ <notes>The basic functionality is to put the website into Maintenance mode. Additionally this extension has a count down and it also supports IP White listing. </notes>
12
+ <authors><author><name>Folio3</name><user>MAG003179920</user><email>ecommerce@folio3.com</email></author></authors>
13
+ <date>2016-10-04</date>
14
+ <time>08:50:21</time>
15
+ <contents><target name="magecommunity"><dir name="Folio3"><dir name="MaintenanceMode"><dir name="Block"><dir name="Adminhtml"><dir name="System"><dir name="Config"><file name="Date.php" hash="3a2ecd4b91754de34af2145f0c98a131"/></dir></dir></dir><file name="Page.php" hash="f94becb61af14c1a4d55c853fb077b85"/></dir><dir name="Controller"><dir name="Router"><file name="Standard.php" hash="cf793b1f0d146a052dee568e4962602d"/></dir></dir><dir name="Helper"><file name="Data.php" hash="97f8ad002ca4a4b0c22029807c135b0a"/></dir><dir name="etc"><file name="config.xml" hash="ce61a055d827ab9b340407fdd25e45bc"/><file name="system.xml" hash="8653337ef0ccef347f4066f8c38fa5a4"/></dir></dir></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="template"><dir name="maintenanceMode"><file name="page.phtml" hash="56b6a0290e84bb0e14ec804453289636"/></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Folio3_MaintenanceMode.xml" hash="92214472862c74ecda87315862630ab3"/></dir></target></contents>
16
+ <compatible/>
17
+ <dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php></required></dependencies>
18
+ </package>