mirror of
https://github.com/Aviortheking/DeltaCMS.git
synced 2025-04-22 10:52:11 +00:00
too manu changes (will list by files)
.gitignore ignores some launch files changelog.md, readme.md added end file line public.php moved started the work on it router.php added require to functions & moved the function in the file set an ini value to show errors defied some constants moved the public page management to public/public.php exampleModule -> headGenerator.php started working on module management *.json reworked files function.php added this file to manages cores functions website.php the Website Object for theme & modules page.php created a test theme
This commit is contained in:
parent
0399e5043b
commit
bc8fba19d4
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
.vscode/
|
||||
cache/
|
@ -1,3 +0,0 @@
|
||||
function testModule($modulesVars, $elementVars) {
|
||||
return new DO
|
||||
}
|
5
admin/modules/default/headGenerator.php
Normal file
5
admin/modules/default/headGenerator.php
Normal file
@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
function headGenerator() {
|
||||
return "<title>Title</title>";
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
{
|
||||
"theme": "default",
|
||||
"cache": true,
|
||||
"modules": ["default"]
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1 @@
|
||||
{
|
||||
"default": {
|
||||
"URI": "pouet/pouet.php",
|
||||
"static": true
|
||||
}
|
||||
}
|
||||
{"Page":{"URI":"templates\/page.php","function":"page","static":true}}
|
||||
|
55
admin/system/functions.php
Normal file
55
admin/system/functions.php
Normal file
@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
function loadJSON($file) {
|
||||
return json_decode(file_get_contents($file), true);
|
||||
}
|
||||
|
||||
function getWebPage($useCache) {
|
||||
$fileCache = ROOT . "/cache" . URL . ".html";
|
||||
|
||||
if($useCache && file_exists($fileCache)) {
|
||||
return file_get_contents($fileCache);
|
||||
}
|
||||
|
||||
// var_dump(URL);
|
||||
$fileURI = ROOT . "/pages" . URL . ".json";
|
||||
$json = loadJSON($fileURI);
|
||||
$template = $json["template"];
|
||||
|
||||
$json["template"] = null;
|
||||
|
||||
define("PAGE", $json);
|
||||
|
||||
$templates = loadJSON(ROOT . "/admin/settings/templates.json");
|
||||
|
||||
require_once ROOT . "/admin/themes/" . SETTINGS["theme"] . "/" . $templates[$template]["URI"];
|
||||
|
||||
$function = $templates[$template]["function"];
|
||||
|
||||
if(function_exists($function)) {
|
||||
$content = $function();
|
||||
|
||||
if($useCache && $templates[$template]["static"]) file_put_contents($fileCache, $content);
|
||||
|
||||
return $content;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function endsWith($haystack, $needle) {
|
||||
$length = strlen($needle);
|
||||
if ($length == 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return (substr($haystack, -$length) === $needle);
|
||||
}
|
||||
|
||||
/*
|
||||
function generateWebPage()
|
||||
load pages/page.json
|
||||
load variables for theme
|
||||
generate the basic web page
|
||||
*/
|
||||
|
||||
?>
|
40
admin/system/website.php
Normal file
40
admin/system/website.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
class Website {
|
||||
|
||||
private $root;
|
||||
|
||||
private const TEMPLATEJSON = "templates.json";
|
||||
|
||||
|
||||
public function __construct(String $root) {
|
||||
$this->root = $root;
|
||||
}
|
||||
|
||||
private function getTemplateFileURI() {
|
||||
return $this->root . "/admin/settings/" . self::TEMPLATEJSON;
|
||||
}
|
||||
|
||||
public function addTemplate(String $name, String $path, String $func, $bool) {
|
||||
var_dump($_SERVER);
|
||||
|
||||
$val = array(
|
||||
$name => array(
|
||||
"URI" => $path,
|
||||
"function" => $func,
|
||||
"static" => $bool
|
||||
)
|
||||
);
|
||||
if(! file_exists($this->getTemplateFileURI())) {
|
||||
file_put_contents($this->getTemplateFileURI(), json_encode($val));
|
||||
} else {
|
||||
$json = json_decode(file_get_contents($this->getTemplateFileURI()), true);
|
||||
$json = array_merge($json, $val);
|
||||
file_put_contents($this->getTemplateFileURI(), json_encode($json));
|
||||
}
|
||||
}
|
||||
|
||||
public function addJS() {
|
||||
|
||||
}
|
||||
}
|
@ -1,3 +1,13 @@
|
||||
<?php
|
||||
|
||||
?>
|
||||
function page() {
|
||||
// require_once "includes/header.php";
|
||||
|
||||
// echo PAGE["content"];
|
||||
|
||||
// require_once "includes/footer.php";
|
||||
|
||||
return "<header>Header</header>" . PAGE["content"] . "<footer>Footer</footer>";
|
||||
}
|
||||
|
||||
?>
|
||||
|
@ -7,8 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
## [Unreleased]
|
||||
|
||||
### Added
|
||||
### Changed
|
||||
### Changed
|
||||
### Deprecated
|
||||
### Removed
|
||||
### Fixed
|
||||
### Security
|
||||
### Security
|
||||
|
@ -1,9 +1,9 @@
|
||||
{
|
||||
"title": "Home",
|
||||
"template": "page",
|
||||
"template": "Page",
|
||||
"access": "public",
|
||||
"content": "<h1>hello world</h1>",
|
||||
"content": "<main>Hello World</main>",
|
||||
"modules": {
|
||||
"?": "?"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
21
public.php
21
public.php
@ -1,21 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
|
||||
if cache is active
|
||||
if active is active load cache (scripts.js styles.css)
|
||||
load templates.json
|
||||
if template has cache for webpage and cache exist
|
||||
load the file
|
||||
else
|
||||
launch generateWebPage()
|
||||
|
||||
if modules are in the page
|
||||
load the modules
|
||||
|
||||
function generateWebPage()
|
||||
load pages/page.json
|
||||
load variables for theme
|
||||
generate the basic web page
|
||||
|
||||
*/
|
||||
?>
|
40
public/public.php
Normal file
40
public/public.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
/**
|
||||
* The process to load a public page (located in /pages)
|
||||
*/
|
||||
|
||||
$isCacheActive = SETTINGS["cache"];
|
||||
|
||||
$webPage = "<html><head><placeholder type=\"head\"/></head><body>" . getWebPage($isCacheActive) . "</body>";
|
||||
|
||||
//load .css & .js
|
||||
|
||||
$doc = new DOMDocument();
|
||||
libxml_use_internal_errors(true);
|
||||
$doc->loadHTML($webPage);
|
||||
libxml_clear_errors();
|
||||
|
||||
//handle modules here
|
||||
|
||||
echo $doc->saveHTML();
|
||||
|
||||
/*
|
||||
|
||||
if cache is active
|
||||
if active is active load cache (scripts.js styles.css)
|
||||
load templates.json
|
||||
if template has cache for webpage and cache exist
|
||||
load the file
|
||||
else
|
||||
launch generateWebPage()
|
||||
|
||||
load theme css & js
|
||||
|
||||
|
||||
if modules are in the page
|
||||
load the modules
|
||||
|
||||
|
||||
|
||||
*/
|
||||
?>
|
@ -267,4 +267,4 @@ if static is true then static webpage will be generated
|
||||
"static": false
|
||||
}
|
||||
}
|
||||
```
|
||||
```
|
||||
|
56
router.php
56
router.php
@ -1,20 +1,33 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* this file initialize some variables and do the first part of the routing (between public pages & admin pages)
|
||||
*/
|
||||
|
||||
require_once "admin/system/functions.php";
|
||||
|
||||
ini_set('display_errors', 'On');
|
||||
|
||||
$url = strtolower(endsWith($_SERVER["REQUEST_URI"], "/") ? $_SERVER["REQUEST_URI"] . "index" : $_SERVER["REQUEST_URI"]);
|
||||
|
||||
define("URL", $url);
|
||||
define("ROOT", __DIR__);
|
||||
|
||||
|
||||
define("SETTINGS", loadJSON(ROOT . "/admin/settings/admin.json"));
|
||||
// $website = new Website();
|
||||
// var_dump(__DIR__);
|
||||
$_SERVER = null;
|
||||
|
||||
if($url == "/test") {
|
||||
require_once "test.php";
|
||||
die;
|
||||
}
|
||||
|
||||
$_SERVER = null;
|
||||
$fileURI = "./pages" . $url . ".json";
|
||||
if(in_array(explode("/", $url)[1], ["login", "admin"])) echo ("this is the login/admin page");
|
||||
elseif (file_exists($fileURI)) {
|
||||
$json = json_decode(file_get_contents($fileURI));
|
||||
echo ($json->title);
|
||||
require_once "public/public.php";
|
||||
} else echo "404";
|
||||
/*
|
||||
|
||||
@ -30,39 +43,4 @@ verify if user is logged in
|
||||
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function endsWith($haystack, $needle) {
|
||||
$length = strlen($needle);
|
||||
if ($length == 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return (substr($haystack, -$length) === $needle);
|
||||
}
|
||||
|
||||
?>
|
||||
?>
|
||||
|
52
test.php
52
test.php
@ -1,31 +1,37 @@
|
||||
<?php
|
||||
ini_set('display_errors', 'On');
|
||||
|
||||
$doc = new DOMDocument();
|
||||
$test = "<html><body><p>pouet</p></body></html>";
|
||||
$doc->loadHTML($test);
|
||||
// $doc = new DOMDocument();
|
||||
// $test = "<html><body><p>pouet</p></body></html>";
|
||||
// $doc->loadHTML($test);
|
||||
|
||||
appendHTML($doc->getElementsByTagName("body")->item(0), "<img src=\"./\">");
|
||||
// appendHTML($doc->getElementsByTagName("body")->item(0), "<img src=\"./\">");
|
||||
|
||||
echo $doc->saveHTML();
|
||||
// echo $doc->saveHTML();
|
||||
|
||||
// echo gettype(true);
|
||||
|
||||
function appendHTML(DOMNode $parent, $source) {
|
||||
$tmpDoc = new DOMDocument();
|
||||
$html = "<html><body>";
|
||||
$html .= $source;
|
||||
$html .= "</body></html>";
|
||||
$tmpDoc->loadHTML('<?xml encoding="UTF-8">'.$html);
|
||||
// include_once "admin/system/website.php";
|
||||
// $website = new Website(__DIR__);
|
||||
// $website->addTemplate("Blog Page", "templates/blog.php", "page", true);
|
||||
|
||||
foreach ($tmpDoc->childNodes as $item)
|
||||
if ($item->nodeType == XML_PI_NODE)
|
||||
$tmpDoc->removeChild($item);
|
||||
$tmpDoc->encoding = 'UTF-8';
|
||||
|
||||
foreach ($tmpDoc->getElementsByTagName('body')->item(0)->childNodes as $node) {
|
||||
$importedNode = $parent->ownerDocument->importNode($node, true);
|
||||
$parent->appendChild($importedNode);
|
||||
}
|
||||
}
|
||||
// phpinfo();
|
||||
|
||||
?>
|
||||
// function appendHTML(DOMNode $parent, $source) {
|
||||
// $tmpDoc = new DOMDocument();
|
||||
// $html = "<html><body>";
|
||||
// $html .= $source;
|
||||
// $html .= "</body></html>";
|
||||
// $tmpDoc->loadHTML('<?xml encoding="UTF-8">'.$html);
|
||||
|
||||
// foreach ($tmpDoc->childNodes as $item)
|
||||
// if ($item->nodeType == XML_PI_NODE)
|
||||
// $tmpDoc->removeChild($item);
|
||||
// $tmpDoc->encoding = 'UTF-8';
|
||||
|
||||
// foreach ($tmpDoc->getElementsByTagName('body')->item(0)->childNodes as $node) {
|
||||
// $importedNode = $parent->ownerDocument->importNode($node, true);
|
||||
// $parent->appendChild($importedNode);
|
||||
// }
|
||||
// }
|
||||
|
||||
?>
|
||||
|
Loading…
x
Reference in New Issue
Block a user