Skip to content

Commit

Permalink
improv. fix issue with sub_urls
Browse files Browse the repository at this point in the history
  • Loading branch information
nivcoo committed Aug 28, 2021
1 parent 76b7504 commit d9ffcbf
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 13 deletions.
2 changes: 2 additions & 0 deletions app/Config/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

Router::connect('/p/*', ['controller' => 'pages', 'action' => 'index']);

Router::connect('/maintenance/*', ['controller' => 'maintenance', 'action' => 'index']);

Router::connect('/profile', ['controller' => 'user', 'action' => 'profile']);

Router::connect('/profile/modify', ['controller' => 'user', 'action' => 'modify_profile']);
Expand Down
7 changes: 6 additions & 1 deletion app/Controller/AppController.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public function beforeFilter()
'action' => 'index',
'plugin' => false,
'admin' => false,
explode("/", $this->here)[1]
]);
}

Expand Down Expand Up @@ -532,7 +533,11 @@ 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 LIKE' => $current_url . "%"]]);
$get_page = [];
$start_url = "/" . explode("/", $current_url)[1];
$check = $this->Seo->find('first', ["conditions" => ['page LIKE' => $start_url . "%"]]);
if ($check && ($check['Seo']["url"] == $current_url || $current_url != "/"))
$get_page = $check;
$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
7 changes: 4 additions & 3 deletions app/Controller/MaintenanceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ public function index($url = "")
{
$this->set('title_for_layout', $this->Lang->get('MAINTENANCE__TITLE'));
$this->loadModel("Maintenance");

if ($this->Permissions->can("BYPASS_MAINTENANCE") || !$this->Maintenance->checkMaintenance("/" . $url))
$check = $this->Maintenance->checkMaintenance("/" . $url);
if ($this->Permissions->can("BYPASS_MAINTENANCE") || !$check) {
$this->redirect("/");
}

$msg = $this->Maintenance->checkMaintenance("/" . $url)["Maintenance"]["reason"];
$msg = $check["reason"];
$this->set(compact('msg'));
}

Expand Down
16 changes: 8 additions & 8 deletions app/Model/Maintenance.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ class Maintenance extends AppModel
{
function checkMaintenance($url = "")
{
$check = $this->find("first", ["conditions" => ["url LIKE" => $url . "%", "active" => 1]])["Maintenance"];
if ($check) {
if (!$check["sub_url"] && $check["url"] != $url)
return false;
return true;
}
$start_url = "/" . explode("/", $url)[1];
$check = $this->find("first", ["conditions" => ["url LIKE" => $start_url . "%", "active" => 1]])["Maintenance"];

if ($check && (($check["url"] == $url) || ($check["sub_url"] && $url != "/")))
return $check;

$is_full = $this->isFullMaintenance();
if ($is_full)
return true;
return $is_full;
return false;
}

function isFullMaintenance()
{
return $this->find("first", ["conditions" => ["url" => "", "active" => 1]]);
return $this->find("first", ["conditions" => ["url" => "", "active" => 1]])["Maintenance"];
}
}
2 changes: 1 addition & 1 deletion app/View/Maintenance/admin_add.ctp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
</div>

<div class="form-group">
<input type="hidden" name="sub_url">
<input type="hidden" name="sub_url" value="0">
<div class="checkbox">
<input name="sub_url_checkbox"
type="checkbox">
Expand Down

0 comments on commit d9ffcbf

Please sign in to comment.