mirror of
https://github.com/Aviortheking/DeltaCMS.git
synced 2025-06-07 23:39:54 +00:00
WIP
This commit is contained in:
parent
14a732c31e
commit
df674a7ec5
4
.htaccess
Normal file
4
.htaccess
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
RewriteEngine on
|
||||||
|
|
||||||
|
RewriteCond %{REQUEST_FILENAME} !-f
|
||||||
|
RewriteRule ^(.*)$ ./router.php [L,QSA]
|
0
admin/admin.css
Normal file
0
admin/admin.css
Normal file
0
admin/admin.js
Normal file
0
admin/admin.js
Normal file
0
admin/index.php
Normal file
0
admin/index.php
Normal file
3
admin/modules/default/exampleModule.php
Normal file
3
admin/modules/default/exampleModule.php
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
function testModule($modulesVars, $elementVars) {
|
||||||
|
return new DO
|
||||||
|
}
|
0
admin/modules/default/module.php
Normal file
0
admin/modules/default/module.php
Normal file
4
admin/settings/admin.json
Normal file
4
admin/settings/admin.json
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"theme": "default",
|
||||||
|
"modules": ["default"]
|
||||||
|
}
|
0
admin/settings/scripts.json
Normal file
0
admin/settings/scripts.json
Normal file
0
admin/settings/styles.json
Normal file
0
admin/settings/styles.json
Normal file
6
admin/settings/templates.json
Normal file
6
admin/settings/templates.json
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"default": {
|
||||||
|
"URI": "pouet/pouet.php",
|
||||||
|
"static": true
|
||||||
|
}
|
||||||
|
}
|
3
admin/themes/default/templates/page.php
Normal file
3
admin/themes/default/templates/page.php
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
?>
|
0
admin/themes/default/theme.php
Normal file
0
admin/themes/default/theme.php
Normal file
9
pages/index.json
Normal file
9
pages/index.json
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"title": "Home",
|
||||||
|
"template": "page",
|
||||||
|
"access": "public",
|
||||||
|
"content": "<h1>hello world</h1>",
|
||||||
|
"modules": {
|
||||||
|
"?": "?"
|
||||||
|
}
|
||||||
|
}
|
3
pages/pokemon.json
Normal file
3
pages/pokemon.json
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"title":"test"
|
||||||
|
}
|
21
public.php
Normal file
21
public.php
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
<?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
|
||||||
|
|
||||||
|
*/
|
||||||
|
?>
|
140
readme.md
140
readme.md
@ -8,10 +8,79 @@ WIP
|
|||||||
|
|
||||||
see [changelog.md](./changelog.md)
|
see [changelog.md](./changelog.md)
|
||||||
|
|
||||||
|
## Themes
|
||||||
|
|
||||||
|
### Templates
|
||||||
|
|
||||||
|
themes works via "templates".
|
||||||
|
|
||||||
|
first a template named "page" is a must, your template can be static or not (static templates will be updated on document update while not static the templateFile will always be used)
|
||||||
|
|
||||||
|
```php
|
||||||
|
website->addTemplate("Template Name", "templateURI/from/root/page.php", "functionName", true);
|
||||||
|
```
|
||||||
|
- `"Template Name"` is the shown name
|
||||||
|
- `"templateURI"` is the file URI
|
||||||
|
- `"functionName"` is the function used
|
||||||
|
- `true` is to says to the website if this template is static or not (default to `false`)
|
||||||
|
|
||||||
|
if cache is disabled globally static or not static pages will be updated at every load
|
||||||
|
|
||||||
|
example: a template named `Blog Page` can be static while a `Blog List` shouldn't be static to load newly added blog pages
|
||||||
|
|
||||||
|
```php
|
||||||
|
website->addTemplate("Blog Page", "templates/blog.php", "page", true);
|
||||||
|
website->addTemplate("Blog List", "templates/blog.php", "list", false);
|
||||||
|
```
|
||||||
|
|
||||||
|
### styles & scripts
|
||||||
|
|
||||||
|
themes must declare each scripts & styles so they can be cached when needed
|
||||||
|
|
||||||
|
```php
|
||||||
|
website->addNewStyle("styleURI/from/style/root/page.css", "styleName", ["styleDependency"]);
|
||||||
|
website->addNewScript("scriptURI/from/script/root/page.js", "scriptName", ["scriptdependency", "JQuery"]);
|
||||||
|
```
|
||||||
|
|
||||||
|
- `"styleURI"`/`"scriptURI"` is the link to the file
|
||||||
|
- [OPTIONAL] `"styleName"`/`"scriptName"` is the name of the style/script to be used by sub-dependencies
|
||||||
|
- [OPTIONAL] `["styleDependency"]`/`["scriptDependency", "JQuery"]` are used to load theses scripts after the followed dependencies
|
||||||
|
|
||||||
|
### Options
|
||||||
|
|
||||||
|
Options are declarated in the same file than before
|
||||||
|
and will be usable in the templates files
|
||||||
|
|
||||||
|
updating an option will update the static files
|
||||||
|
|
||||||
|
```php
|
||||||
|
$optionMenu = website->addOptionsMenu("Menu Name");
|
||||||
|
```
|
||||||
|
here we create a new option menu that will be located in the admin sidebar `theme -> Options` within the tabs
|
||||||
|
|
||||||
|
- `"Menu Name"` is the shown name
|
||||||
|
|
||||||
|
```php
|
||||||
|
$optionMenu->addTextOption("Option Name", "variableName", "defaultValue", {
|
||||||
|
"min": 1,
|
||||||
|
"max": 16,
|
||||||
|
"placeholder": "placeholder"
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
## Modules
|
||||||
|
|
||||||
|
modules will work like this in the `page.content` of the page `[moduleName variablesName="valueName"]`
|
||||||
|
|
||||||
|
the module will then receive a variable named `$modVars` that will contain `$modVars->variableName` = `valueName` and will have to return a `String` Object
|
||||||
|
|
||||||
|
To keep the document strict it's advised to use the php `DOMDocument` Object
|
||||||
|
|
||||||
## Files/Folders architecture
|
## Files/Folders architecture
|
||||||
|
|
||||||
- index.php (is it really necessary ?)
|
- index.php (is it really necessary ?)
|
||||||
- .htaccess (handle file redirection)
|
- .htaccess (handle file redirection)
|
||||||
|
- router.php (handle the first route part ( separating the loading process))
|
||||||
- uploads/
|
- uploads/
|
||||||
- cache/ (public cache (won't be seen by client via .htaccess redirection))
|
- cache/ (public cache (won't be seen by client via .htaccess redirection))
|
||||||
- .htaccess (make sure clients can't access this folder)
|
- .htaccess (make sure clients can't access this folder)
|
||||||
@ -36,9 +105,13 @@ see [changelog.md](./changelog.md)
|
|||||||
- admin.json (admin settings (see admin.json section))
|
- admin.json (admin settings (see admin.json section))
|
||||||
- templates.json (simple name to redirect)
|
- templates.json (simple name to redirect)
|
||||||
- modules/
|
- modules/
|
||||||
- moduleName.json
|
- moduleName/
|
||||||
|
- settings.json
|
||||||
|
- vars.json
|
||||||
- themes/
|
- themes/
|
||||||
- themeName.json
|
- themeName/
|
||||||
|
- settings.json
|
||||||
|
- vars.json
|
||||||
- admin.list (used to see what to launch on the admin side)
|
- admin.list (used to see what to launch on the admin side)
|
||||||
- options.list (options for modules & themes to be used site-wide)
|
- options.list (options for modules & themes to be used site-wide)
|
||||||
- templates.list (store the template used on the website with a link to there .php file)
|
- templates.list (store the template used on the website with a link to there .php file)
|
||||||
@ -64,6 +137,17 @@ see [changelog.md](./changelog.md)
|
|||||||
|
|
||||||
## Configs files
|
## Configs files
|
||||||
|
|
||||||
|
### page.json (in `pages` folder)
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"title": "pageTitle",
|
||||||
|
"template": "templateName",
|
||||||
|
"access": "typeOfAccess (public: everyone has access to the page, limited:only logged in users has access to the page, private: only the author & admins has access to the page)",
|
||||||
|
"author": "Aviortheking",
|
||||||
|
"content": "<h1>hello world</h1>"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
### scripts.json & styles.json
|
### scripts.json & styles.json
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
@ -83,25 +167,71 @@ see [changelog.md](./changelog.md)
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### moduleName.json & themeName.json
|
### vars.json
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"variable1": "value1",
|
"variable1": "value1",
|
||||||
"list1": [
|
"list1": [
|
||||||
"pouet1",
|
"pouet1",
|
||||||
"etc"
|
"etc"
|
||||||
]
|
],
|
||||||
"variableSet1": {
|
"variableSet1": {
|
||||||
"subVariable1": "value2"
|
"subVariable1": "value2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
### moduleName.json & themeName.json
|
||||||
|
*values for the options are located in the `vars.json` files*
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"title": "Menu Title",
|
||||||
|
"slug": "menu-title",
|
||||||
|
"options": {
|
||||||
|
"textOption": {
|
||||||
|
"type": "text",
|
||||||
|
"name": "Option Name",
|
||||||
|
},
|
||||||
|
"radioOption": {
|
||||||
|
"type": "radio",
|
||||||
|
"name": "Radio Option",
|
||||||
|
"values": [
|
||||||
|
"value1",
|
||||||
|
"value2",
|
||||||
|
"value3"
|
||||||
|
],
|
||||||
|
},
|
||||||
|
"selectOption": {
|
||||||
|
"type": "select",
|
||||||
|
"name": "Select",
|
||||||
|
"value": [
|
||||||
|
"value1",
|
||||||
|
"value2",
|
||||||
|
"value3",
|
||||||
|
"etc"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"title": "etc"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
### templates.list
|
### templates.list
|
||||||
|
|
||||||
*voir si il y auras tout les themes ou seulement le theme actif*
|
*voir si il y auras tout les themes ou seulement le theme actif*
|
||||||
|
|
||||||
|
if static is true then static webpage will be generated
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"templateName": templates/templateName.php
|
"templateName": {
|
||||||
|
"URI": "templates/templateName.php",
|
||||||
|
"function": "functionName",
|
||||||
|
"static": false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
68
router.php
Normal file
68
router.php
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
$url = strtolower(endsWith($_SERVER["REQUEST_URI"], "/") ? $_SERVER["REQUEST_URI"] . "index" : $_SERVER["REQUEST_URI"]);
|
||||||
|
|
||||||
|
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);
|
||||||
|
} else echo "404";
|
||||||
|
/*
|
||||||
|
|
||||||
|
verify if the page to load exist
|
||||||
|
if page is login/admin then continue;
|
||||||
|
elif the page is a file in /pages/pagename.json then continue
|
||||||
|
else return 404 error
|
||||||
|
|
||||||
|
verify if user is logged in
|
||||||
|
if the user is logged in & the page is login return to /admin
|
||||||
|
elif the user is not logged in & the page is admin return to /login
|
||||||
|
else start the process to load the page
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function endsWith($haystack, $needle) {
|
||||||
|
$length = strlen($needle);
|
||||||
|
if ($length == 0) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (substr($haystack, -$length) === $needle);
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
31
test.php
Normal file
31
test.php
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
ini_set('display_errors', 'On');
|
||||||
|
|
||||||
|
$doc = new DOMDocument();
|
||||||
|
$test = "<html><body><p>pouet</p></body></html>";
|
||||||
|
$doc->loadHTML($test);
|
||||||
|
|
||||||
|
appendHTML($doc->getElementsByTagName("body")->item(0), "<img src=\"./\">");
|
||||||
|
|
||||||
|
echo $doc->saveHTML();
|
||||||
|
|
||||||
|
|
||||||
|
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