Initial support for theming
This commit is contained in:
parent
a6be3d7b2c
commit
02919b797f
7 changed files with 52 additions and 7 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1 +1 @@
|
|||
/src/vendor/
|
||||
/src/Vendor/
|
||||
|
|
|
@ -18,6 +18,6 @@
|
|||
}
|
||||
],
|
||||
"config": {
|
||||
"vendor-dir": "src/vendor"
|
||||
"vendor-dir": "src/Vendor"
|
||||
}
|
||||
}
|
||||
|
|
2
composer.lock
generated
2
composer.lock
generated
|
@ -4,7 +4,7 @@
|
|||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "66ce6cf62e0203516b5e2e40d90fac81",
|
||||
"content-hash": "c7f343aa119f2ca464f00c05981fff99",
|
||||
"packages": [
|
||||
{
|
||||
"name": "michelf/php-markdown",
|
||||
|
|
|
@ -4,12 +4,24 @@ use AntCMS\AntMarkdown;
|
|||
|
||||
class AntCMS {
|
||||
public function renderPage($page, $params = null){
|
||||
$start_time = microtime(true);
|
||||
$content = $this->getPage($page);
|
||||
|
||||
if(!$content){
|
||||
$this->renderException("404");
|
||||
} else {
|
||||
echo AntMarkdown::renderMarkdown($content);
|
||||
}
|
||||
|
||||
$markdown = AntMarkdown::renderMarkdown($content);
|
||||
$page = $this->getThemeContent();
|
||||
|
||||
$page = str_replace('<!--AntCMS-Body-->', $markdown, $page);
|
||||
$page = str_replace('<!--AntCMS-Title-->', 'AntCMS', $page);
|
||||
|
||||
$end_time = microtime(true);
|
||||
$elapsed_time = round($end_time - $start_time, 4);
|
||||
$page = str_replace('<!--AntCMS-Debug-->', '<p>Took ' . $elapsed_time . ' seconds to render the page.', $page);
|
||||
|
||||
echo $page;
|
||||
}
|
||||
|
||||
public function renderException($exceptionCode){
|
||||
|
@ -32,4 +44,24 @@ class AntCMS {
|
|||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function getThemeContent(){
|
||||
$themePath = appDir . "/Theme/default_layout.html";
|
||||
$themeContent = file_get_contents($themePath);
|
||||
|
||||
if(!$themeContent){
|
||||
$themeContent = '
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title><!--AntCMS-Title--></title>
|
||||
</head>
|
||||
<body>
|
||||
<!--AntCMS-Body-->
|
||||
</body>
|
||||
</html>';
|
||||
}
|
||||
|
||||
return $themeContent;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ class AntMarkdown{
|
|||
{
|
||||
$result = Markdown::defaultTransform($md);
|
||||
$result = preg_replace('/(?:~~)([^~~]*)(?:~~)/', '<s>$1</s>', $result);
|
||||
echo $result;
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
13
src/Theme/default_layout.html
Normal file
13
src/Theme/default_layout.html
Normal file
|
@ -0,0 +1,13 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title><!--AntCMS-Title--></title>
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.3.1/dist/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<!--AntCMS-Body-->
|
||||
<!--AntCMS-Debug-->
|
||||
</body>
|
||||
</html>
|
|
@ -4,7 +4,7 @@ error_reporting(E_ALL);
|
|||
ini_set('display_errors', 1);
|
||||
|
||||
const appDir = __DIR__;
|
||||
require_once __DIR__ . '/vendor/autoload.php';
|
||||
require_once __DIR__ . '/Vendor/autoload.php';
|
||||
require_once __DIR__ . '/AntCMS/App.php';
|
||||
require_once __DIR__ . '/AntCMS/Markdown.php';
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue