Skip to content

Commit

Permalink
feat. add sub_url option into maintenance page
Browse files Browse the repository at this point in the history
  • Loading branch information
nivcoo committed Aug 28, 2021
1 parent 3cae21f commit c02b94c
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 12 deletions.
1 change: 1 addition & 0 deletions app/Config/Schema/schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ class AppSchema extends CakeSchema
];
public $maintenances = [
'id' => ['type' => 'integer', 'null' => false, 'default' => null, 'length' => 20, 'unsigned' => false, 'key' => 'primary'],
'sub_url' => ['type' => 'integer', 'null' => false, 'default' => 0, 'length' => 1, 'unsigned' => false],
'url' => ['type' => 'string', 'null' => false, 'default' => null, 'collate' => 'latin1_swedish_ci', 'charset' => 'latin1'],
'reason' => ['type' => 'string', 'null' => false, 'default' => null, 'collate' => 'latin1_swedish_ci', 'charset' => 'latin1'],
'active' => ['type' => 'integer', 'null' => false, 'default' => 1, 'length' => 1, 'unsigned' => false],
Expand Down
4 changes: 2 additions & 2 deletions app/Controller/AppController.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function beforeFilter()
'admin' => false,
]);
}

// Plugin disabled
if ($this->request->params['plugin']) {
$plugin = $this->EyPlugin->findPlugin('slugLower', $this->request->params['plugin']);
Expand Down Expand Up @@ -532,7 +532,7 @@ public function __initSeoConfiguration()
$this->loadModel('Seo');
$default = $this->Seo->find('first', ["conditions" => ['page' => null]]);
$current_url = $this->here;
$get_page = $this->Seo->find('first', ["conditions" => ['page' => $current_url]]);
$get_page = $this->Seo->find('first', ["conditions" => ['page LIKE' => $current_url . "%"]]);
$seo_config['title'] = (!empty($default['Seo']['title']) ? $default['Seo']['title'] : "{TITLE} - {WEBSITE_NAME}");
$seo_config['title'] = (!empty($get_page['Seo']['title']) ? $get_page['Seo']['title'] : $seo_config['title']);
$seo_config['description'] = (!empty($get_page['Seo']['description']) ? $get_page['Seo']['description'] : (!empty($default['Seo']['description']) ? $default['Seo']['description'] : ""));
Expand Down
1 change: 1 addition & 0 deletions app/Controller/MaintenanceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public function admin_edit($id = false)

$this->Maintenance->read(null, $id);
$this->Maintenance->set([
"sub_url" => $this->request->data["sub_url"],
"url" => $this->request->data["url"],
"reason" => $this->request->data["reason"]
]);
Expand Down
11 changes: 7 additions & 4 deletions app/Model/Maintenance.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ class Maintenance extends AppModel
{
function checkMaintenance($url = "")
{
$check = $this->find("first", ["conditions" => ["url" => $url, "active" => 1]]);
if ($check)
return $check;
$check = $this->find("first", ["conditions" => ["url LIKE" => $url . "%", "active" => 1]])["Maintenance"];
if ($check) {
if (!$check["sub_url"] && $check["url"] != $url)
return false;
return true;
}
$is_full = $this->isFullMaintenance();
if ($is_full)
return $is_full;
return true;
return false;
}

Expand Down
17 changes: 16 additions & 1 deletion app/View/Maintenance/admin_add.ctp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
<h3 class="card-title"><?= $Lang->get('MAINTENANCE__TITLE') ?></h3>
</div>
<div class="card-body">
<form method="post" data-ajax="true" data-redirect-url="<?= $this->Html->url(['controller' => 'maintenance', 'action' => 'index', 'admin' => 'true']) ?>">
<form method="post" data-ajax="true"
data-redirect-url="<?= $this->Html->url(['controller' => 'maintenance', 'action' => 'index', 'admin' => 'true']) ?>">
<div class="form-group">
<label><?= $Lang->get("MAINTENANCE__PAGE") ?></label><br>
<i><?= $Lang->get("MAINTENANCE__ADD_EXAMPLE") ?></i><br>
Expand All @@ -31,6 +32,20 @@
rows="10"></textarea>
</div>

<div class="form-group">
<input type="hidden" name="sub_url">
<div class="checkbox">
<input name="sub_url_checkbox"
type="checkbox">
<label><?= $Lang->get('MAINTENANCE__USE_SUB_URL') ?></label>
</div>
</div>
<script type="text/javascript">
$('input[name="sub_url_checkbox"]').on('change', function (e) {
$('input[name="sub_url').val($('input[name="sub_url_checkbox"]:checked').length > 0 ? '1' : '0')
})
</script>

<input type="hidden" name="data[_Token][key]" value="<?= $csrfToken ?>">

<div class="float-right">
Expand Down
14 changes: 14 additions & 0 deletions app/View/Maintenance/admin_edit.ctp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,20 @@
<textarea id="editor" name="reason" cols="30" rows="10"><?= $page["reason"] ?></textarea>
</div>

<div class="form-group">
<input type="hidden" name="sub_url" value="<?= $page['sub_url'] ?>">
<div class="checkbox">
<input name="sub_url_checkbox"
type="checkbox" <?= $page['sub_url'] == 1 ? 'checked' : '' ?>>
<label><?= $Lang->get('MAINTENANCE__USE_SUB_URL') ?></label>
</div>
</div>
<script type="text/javascript">
$('input[name="sub_url_checkbox"]').on('change', function (e) {
$('input[name="sub_url').val($('input[name="sub_url_checkbox"]:checked').length > 0 ? '1' : '0')
})
</script>

<input type="hidden" name="data[_Token][key]" value="<?= $csrfToken ?>">

<div class="float-right">
Expand Down
12 changes: 7 additions & 5 deletions app/View/Maintenance/admin_index.ctp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
<tr>
<th><?= $Lang->get("MAINTENANCE__PAGE") ?></th>
<th><?= $Lang->get("MAINTENANCE__REASON") ?></th>
<th><?= $Lang->get("MAINTENANCE__SUB_URL") ?></th>
<th><?= $Lang->get("GLOBAL__STATUS") ?></th>
<th><?= $Lang->get("GLOBAL__ACTIONS")?></th>
<th><?= $Lang->get("GLOBAL__ACTIONS") ?></th>
</tr>
</thead>

Expand All @@ -21,16 +22,17 @@
<tr>
<td><?= $v["Maintenance"]["url"] ?></td>
<td><?= $v["Maintenance"]["reason"] ?></td>
<td><?= $v["Maintenance"]["sub_url"] ? $Lang->get("GLOBAL__YES") : $Lang->get("GLOBAL__NO") ?></td>
<td><?= $v["Maintenance"]["active"] != 1 ? $Lang->get("GLOBAL__DISABLED") : $Lang->get("GLOBAL__ENABLED") ?></td>
<td>
<a href='<?= $this->Html->url(['action' => 'edit', $v["Maintenance"]['id']]) ?>'
class="btn btn-success"><?= $Lang->get('GLOBAL__EDIT') ?></a>
<?php if ($v["Maintenance"]["active"] == 1) { ?>
<a onClick="confirmDel('<?= $this->Html->url(['action' => 'disable', $v["Maintenance"]['id']]) ?>')"
class="btn btn-warning"><?= $Lang->get('GLOBAL__DISABLE') ?></a>
<a onClick="confirmDel('<?= $this->Html->url(['action' => 'disable', $v["Maintenance"]['id']]) ?>')"
class="btn btn-warning"><?= $Lang->get('GLOBAL__DISABLE') ?></a>
<?php } else { ?>
<a onClick="confirmDel('<?= $this->Html->url(['action' => 'enable', $v["Maintenance"]['id']]) ?>')"
class="btn btn-primary"><?= $Lang->get('GLOBAL__ENABLE') ?></a>
<a onClick="confirmDel('<?= $this->Html->url(['action' => 'enable', $v["Maintenance"]['id']]) ?>')"
class="btn btn-primary"><?= $Lang->get('GLOBAL__ENABLE') ?></a>
<?php } ?>
<a onClick="confirmDel('<?= $this->Html->url(['action' => 'delete', $v["Maintenance"]['id']]) ?>')"
class="btn btn-danger"><?= $Lang->get('GLOBAL__DELETE') ?></a>
Expand Down
2 changes: 2 additions & 0 deletions lang/en_UK.json
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,8 @@
"MAINTENANCE__DISABLED_PAGE": "Maintenance of page {PAGE} disabled",
"MAINTENANCE__ENABLED_PAGE": "Maintenance of page {PAGE} enabled",
"MAINTENANCE__DELETED_PAGE": "Maintenance of the deleted page {PAGE}",
"MAINTENANCE__USE_SUB_URL": "Apply maintenance to all urls starting with your url?",
"MAINTENANCE__SUB_URL": "Under URLs included",

"PAGE__ADD_SUCCESS": "Page added successfully!",
"PAGE__EDIT_SUCCESS": "Page modified successfully!",
Expand Down
2 changes: 2 additions & 0 deletions lang/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,8 @@
"MAINTENANCE__DISABLED_PAGE": "Maintenance of page {PAGE} disabled",
"MAINTENANCE__ENABLED_PAGE": "Maintenance of page {PAGE} enabled",
"MAINTENANCE__DELETED_PAGE": "Maintenance of the deleted page {PAGE}",
"MAINTENANCE__USE_SUB_URL": "Apply maintenance to all urls starting with your url?",
"MAINTENANCE__SUB_URL": "Under URLs included",

"PAGE__ADD_SUCCESS": "Page added successfully!",
"PAGE__EDIT_SUCCESS": "Page modified successfully!",
Expand Down
2 changes: 2 additions & 0 deletions lang/fr_FR.json
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,8 @@
"MAINTENANCE__DISABLED_PAGE": "Maintenance de la page {PAGE} désactivée",
"MAINTENANCE__ENABLED_PAGE": "Maintenance de la page {PAGE} activée",
"MAINTENANCE__DELETED_PAGE": "Maintenance de la page {PAGE} supprimée",
"MAINTENANCE__USE_SUB_URL": "Appliquer la maintenance à toute les urls commençant par votre url ?",
"MAINTENANCE__SUB_URL": "Sous URL incluses",

"PAGE__ADD_SUCCESS":"Page ajoutée avec succès !",
"PAGE__EDIT_SUCCESS":"Page modifiée avec succès !",
Expand Down
2 changes: 2 additions & 0 deletions lang/ru_RU.json
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,8 @@
"MAINTENANCE__DISABLED_PAGE": "Обслуживание страницы {PAGE} отключено",
"MAINTENANCE__ENABLED_PAGE": "Поддержка страницы {PAGE} включена",
"MAINTENANCE__DELETED_PAGE": "Обслуживание удаленной страницы {PAGE}",
"MAINTENANCE__USE_SUB_URL": "Применить обслуживание ко всем URL-адресам, начинающимся с вашего URL-адреса?",
"MAINTENANCE__SUB_URL": "Под включенными URL",

"PAGE__ADD_SUCCESS": "Страница успешно добавлена!",
"PAGE__EDIT_SUCCESS": "Страница успешно изменена!",
Expand Down

0 comments on commit c02b94c

Please sign in to comment.