Skip to content
This repository has been archived by the owner on Oct 5, 2023. It is now read-only.

Commit

Permalink
Bug #381, implement site readonly mode, PHP + JS + CSS
Browse files Browse the repository at this point in the history
  • Loading branch information
nfreear committed Mar 1, 2019
1 parent eda381b commit a3f7cdc
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 1 deletion.
1 change: 1 addition & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module.exports = function (grunt) {
},
jshint: {
options: {
esversion: 6, // Use 'const' etc.!
bitwise: true,
curly: true,
eqeqeq: true,
Expand Down
14 changes: 14 additions & 0 deletions _design/styles_1_1.css
Original file line number Diff line number Diff line change
Expand Up @@ -2505,5 +2505,19 @@ form.gsc-search-box input {
padding: 0; margin: 0;
}

/* Site readonly.
*/
body.readonly a.disabled,
body.readonly input[ disabled ],
#login-form [ type = submit ][ disabled ] {
cursor: not-allowed;
/* pointer-events: none; */
}

a.disabled:focus,
a.disabled:hover {
opacity: .6;
transition: all 5s;
}

/* End. */
Expand Down
14 changes: 14 additions & 0 deletions _scripts/custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,18 @@ window.jQuery(function ($) {
function rot13(s) {
return s.replace(/[a-zA-Z]/g, function(c){ return String.fromCharCode((c<="Z"?90:122) >= (c=c.charCodeAt(0)+13) ? c : c-26); });
}

/* Site readonly.
*/
const $READONLY = $('body.readonly');

$READONLY.find('#login-form, #register_form').find(':input').attr({ disabled: 'disabled', title: 'Readonly mode' });

$READONLY.find('a[ href *= auth ]').on('click', (ev) => {
ev.preventDefault();
console.warn('Readonly: auth click');
})
.addClass('disabled').attr({ title: 'Readonly mode' });

console.warn($READONLY.length ? 'Site readonly.' : 'Site read-write.');
});
4 changes: 4 additions & 0 deletions system/application/config/cloudengine.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
|--------------------------------------------------------------------------
*/

// Site readonly and/ or debug settings.
$config['readonly'] = false;
$config['debug'] = false;

// Basic site info

$config['site_name'] = 'Your Site';
Expand Down
25 changes: 25 additions & 0 deletions system/application/controllers/auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ function Auth() {
$this->load->library('form_validation');
}

/** Remap: Site readonly.
*/
public function _remap($method) {
if (config_item('readonly')) {
$this->_show_readonly_page();
} else {
$this->$method();
}
}

/**
* User login form and processing for user login form
*
Expand Down Expand Up @@ -423,4 +433,19 @@ function _fullname_check($str) {

return $contains_space;
}

/** Site readonly page.
*/
protected function _show_readonly_page() {
header('HTTP/1.1 503 Not Available');

$this->load->library('Layout');
$this->layout->setLayout('layout_offline');

$view_data = array(
'title' => t('Site is readonly'),
'message' => t("Site login and registration are disabled. <pre>\n\n\n503 Not Available </pre>"),
);
echo $this->layout->view('error/site_offline', $view_data, true);
}
}
5 changes: 4 additions & 1 deletion system/application/views/layout/header.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
?><!DOCTYPE html><html <?=$this->lang->lang_tag()?>><head>
<?php $this->load->view('layout/_site-head.php'); ?>
</head>
<body id="<?= $navigation ?>">
<body id="<?= $navigation ?>" class="<?php echo config_item('readonly') ? 'readonly' : ''; ?>">
<?php $page = $_SERVER['REQUEST_URI']; ?>
<div id="site-header">
<?php $this->load->view('layout/_site-header'); ?>
Expand All @@ -20,6 +20,9 @@
<div id="site-body">
<div id="page">
<div id="content">
<?php if (config_item('readonly')): ?>
<p class="warn readonly-message"> The web-site is currently in readonly mode. Login and registration are disabled. </p>
<?php endif; ?>
<?php if (!config_item('x_live')): ?>
<p class="test_install warn"> <?= $this->config->item('test_install_message') ?></p>
<?php endif; ?>
Expand Down

0 comments on commit a3f7cdc

Please sign in to comment.