chevereto-free/app/routes/route.page.php

54 lines
1.5 KiB
PHP
Raw Normal View History

2016-08-18 20:39:31 +00:00
<?php
/* --------------------------------------------------------------------
2020-09-25 20:27:24 +00:00
This file is part of Chevereto Free.
https://chevereto.com/free
2016-08-18 20:39:31 +00:00
2020-09-25 20:27:24 +00:00
(c) Rodolfo Berrios <rodolfo@chevereto.com>
2016-08-18 20:39:31 +00:00
2020-09-25 20:27:24 +00:00
For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.
2016-08-18 20:39:31 +00:00
--------------------------------------------------------------------- */
2018-04-17 21:25:26 +00:00
2016-08-18 20:39:31 +00:00
$route = function($handler) {
2018-04-17 21:25:26 +00:00
2016-08-18 20:39:31 +00:00
$request_url_key = implode('/', $handler->request);
2018-04-17 21:25:26 +00:00
2016-08-18 20:39:31 +00:00
// Get this page
$page = CHV\Page::getSingle($request_url_key);
2018-04-17 21:25:26 +00:00
2016-08-18 20:39:31 +00:00
// Exists or is active or is type default?
if(!$page or !$page['is_active'] or $page['type'] !== 'internal') {
return $handler->issue404();
}
2018-04-17 21:25:26 +00:00
2016-08-18 20:39:31 +00:00
// No file path set
if(!$page['file_path_absolute']) {
return $handler->issue404();
}
2018-04-17 21:25:26 +00:00
2016-08-18 20:39:31 +00:00
// File path doesn't exists
if(!file_exists($page['file_path_absolute'])) {
return $handler->issue404();
}
2018-04-17 21:25:26 +00:00
2016-08-18 20:39:31 +00:00
$pathinfo = pathinfo($page['file_path_absolute']);
$page_extension = G\get_file_extension($page['file_path_absolute']);
2018-04-17 21:25:26 +00:00
2016-08-18 20:39:31 +00:00
// Inject theme based path
$handler->path_theme = G\add_ending_slash($pathinfo['dirname']);
$handler->template = $pathinfo['filename'] . '.' . $page_extension;
2018-04-17 21:25:26 +00:00
2016-08-18 20:39:31 +00:00
// Add page meta data
$page_metas = [
'pre_doctitle' => $page['title'],
'meta_description' => htmlspecialchars($page['description']),
'meta_keywords' => htmlspecialchars($page['keywords'])
];
foreach($page_metas as $k => $v) {
if($v == NULL) continue;
$handler->setVar($k, $v);
}
};