From 17f223d51701462e48b4effc7ec5d304e3a860e3 Mon Sep 17 00:00:00 2001 From: Avior Date: Sat, 2 Mar 2019 15:54:10 +0100 Subject: [PATCH] pouet --- .gitignore | 3 + .phpunit.result.cache | 1 + admin/admin.css | 0 admin/admin.js | 0 admin/index.php | 0 admin/modules/default/headGenerator.php | 5 - admin/settings/scripts.json | 0 admin/settings/styles.json | 0 admin/settings/templates.json | 1 - admin/themes/default/templates/page.php | 13 - admin/themes/default/theme.php | 0 composer.json | 20 ++ pages/index.json | 9 - pages/pokemon.json | 3 - public/public.php | 40 --- readme.md | 249 ++++++------------ router.php | 46 ---- .htaccess => src/.htaccess | 2 +- src/admin/init.php | 8 + .../admin}/modules/default/module.php | 0 src/admin/modules/frontend/edit.php | 3 + src/admin/modules/frontend/module.php | 1 + {admin => src/admin}/settings/admin.json | 0 src/admin/system/Enum.php | 45 ++++ src/admin/system/OptionTypes.php | 6 + src/admin/system/Router.php | 35 +++ {admin => src/admin}/system/functions.php | 0 src/admin/system/modules.php | 75 ++++++ src/admin/system/router.php | 55 ++++ {admin => src/admin}/system/website.php | 0 test.php => src/test.php | 0 tests/TestEnum.php | 34 +++ 32 files changed, 366 insertions(+), 288 deletions(-) create mode 100644 .phpunit.result.cache delete mode 100644 admin/admin.css delete mode 100644 admin/admin.js delete mode 100644 admin/index.php delete mode 100644 admin/modules/default/headGenerator.php delete mode 100644 admin/settings/scripts.json delete mode 100644 admin/settings/styles.json delete mode 100644 admin/settings/templates.json delete mode 100644 admin/themes/default/templates/page.php delete mode 100644 admin/themes/default/theme.php create mode 100644 composer.json delete mode 100644 pages/index.json delete mode 100644 pages/pokemon.json delete mode 100644 public/public.php delete mode 100644 router.php rename .htaccess => src/.htaccess (55%) create mode 100644 src/admin/init.php rename {admin => src/admin}/modules/default/module.php (100%) create mode 100644 src/admin/modules/frontend/edit.php create mode 100644 src/admin/modules/frontend/module.php rename {admin => src/admin}/settings/admin.json (100%) create mode 100644 src/admin/system/Enum.php create mode 100644 src/admin/system/OptionTypes.php create mode 100644 src/admin/system/Router.php rename {admin => src/admin}/system/functions.php (100%) create mode 100644 src/admin/system/modules.php create mode 100644 src/admin/system/router.php rename {admin => src/admin}/system/website.php (100%) rename test.php => src/test.php (100%) create mode 100644 tests/TestEnum.php diff --git a/.gitignore b/.gitignore index d781e64..a16f774 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ .vscode/ cache/ + +/vendor/ +composer.lock diff --git a/.phpunit.result.cache b/.phpunit.result.cache new file mode 100644 index 0000000..0778e9c --- /dev/null +++ b/.phpunit.result.cache @@ -0,0 +1 @@ +C:30:"PHPUnit\Runner\TestResultCache":204:{a:2:{s:7:"defects";a:1:{s:29:"TestEnum::testInstantiateEnum";i:3;}s:5:"times";a:3:{s:25:"TestEnum::testValidOption";d:0;s:25:"TestEnum::testIsValidName";d:0;s:29:"TestEnum::testInstantiateEnum";d:0.003;}}} \ No newline at end of file diff --git a/admin/admin.css b/admin/admin.css deleted file mode 100644 index e69de29..0000000 diff --git a/admin/admin.js b/admin/admin.js deleted file mode 100644 index e69de29..0000000 diff --git a/admin/index.php b/admin/index.php deleted file mode 100644 index e69de29..0000000 diff --git a/admin/modules/default/headGenerator.php b/admin/modules/default/headGenerator.php deleted file mode 100644 index cca252c..0000000 --- a/admin/modules/default/headGenerator.php +++ /dev/null @@ -1,5 +0,0 @@ -Title"; -} diff --git a/admin/settings/scripts.json b/admin/settings/scripts.json deleted file mode 100644 index e69de29..0000000 diff --git a/admin/settings/styles.json b/admin/settings/styles.json deleted file mode 100644 index e69de29..0000000 diff --git a/admin/settings/templates.json b/admin/settings/templates.json deleted file mode 100644 index ba2ab81..0000000 --- a/admin/settings/templates.json +++ /dev/null @@ -1 +0,0 @@ -{"Page":{"URI":"templates\/page.php","function":"page","static":true}} diff --git a/admin/themes/default/templates/page.php b/admin/themes/default/templates/page.php deleted file mode 100644 index 41d3e68..0000000 --- a/admin/themes/default/templates/page.php +++ /dev/null @@ -1,13 +0,0 @@ -Header" . PAGE["content"] . ""; -} - -?> diff --git a/admin/themes/default/theme.php b/admin/themes/default/theme.php deleted file mode 100644 index e69de29..0000000 diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..49cc7a4 --- /dev/null +++ b/composer.json @@ -0,0 +1,20 @@ +{ + "name": "avior/admin-panel", + "type": "project", + "license": "MIT License", + "authors": [ + { + "name": "Avior", + "email": "florian.bouillon@delta-wings.net" + } + ], + "autoload": { + "classmap": [ + "src/admin/system/" + ] + }, + "require": {}, + "require-dev": { + "phpunit/phpunit": "^8" + } +} diff --git a/pages/index.json b/pages/index.json deleted file mode 100644 index 1dee938..0000000 --- a/pages/index.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "title": "Home", - "template": "Page", - "access": "public", - "content": "
Hello World
", - "modules": { - "?": "?" - } -} diff --git a/pages/pokemon.json b/pages/pokemon.json deleted file mode 100644 index b966688..0000000 --- a/pages/pokemon.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "title":"test" -} \ No newline at end of file diff --git a/public/public.php b/public/public.php deleted file mode 100644 index 9a3484a..0000000 --- a/public/public.php +++ /dev/null @@ -1,40 +0,0 @@ -" . getWebPage($isCacheActive) . ""; - -//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 - - - -*/ -?> diff --git a/readme.md b/readme.md index df373aa..9980b02 100644 --- a/readme.md +++ b/readme.md @@ -6,19 +6,17 @@ - [Table of Content](#table-of-content) - [Description](#description) - [Changelog](#changelog) - - [Themes](#themes) - - [Templates](#templates) - - [styles & scripts](#styles--scripts) - - [Options](#options) - [Modules](#modules) + - [Routes](#routes) + - [Usage](#usage) + - [Menus](#menus) + - [Usage](#usage-1) + - [Options](#options) + - [Usage](#usage-2) - [Files/Folders architecture](#filesfolders-architecture) - [Configs files](#configs-files) - - [page.json (in `pages` folder)](#pagejson-in-pages-folder) - - [scripts.json & styles.json](#scriptsjson--stylesjson) - - [admin.json](#adminjson) - - [vars.json](#varsjson) - - [moduleName.json & themeName.json](#modulenamejson--themenamejson) - - [templates.json](#templatesjson) + - [site.json](#sitejson) + - [settings.json](#settingsjson) ## Description @@ -28,127 +26,113 @@ WIP see [changelog.md](./changelog.md) -## Themes +## Modules -### 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) +Modules are what that will manage the system in himself. ```php -website->addTemplate("Template Name", "templateURI/from/root/page.php", "functionName", true); +$module = new Module(); ``` -- `"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`) +Modules will have multiple constant -if cache is disabled globally static or not static pages will be updated at every load +### Routes -example: a template named `Blog Page` can be static while a `Blog List` shouldn't be static to load newly added blog pages +sitewide (except `/admin/*`) routes can be defined and will point to a function you will have to define + +#### Usage ```php -website->addTemplate("Blog Page", "templates/blog.php", "page", true); -website->addTemplate("Blog List", "templates/blog.php", "list", false); +$function = function($settings) { + return "html code"; +} +$module->addRoute("/regex-to-check-for-the-page/", $function); ``` -### styles & scripts +### Menus -themes must declare each scripts & styles so they can be cached when needed +On the admin-side you can add menus & items + +#### Usage ```php -website->addNewStyle("styleURI/from/style/root/page.css", "styleName", ["styleDependency"]); -website->addNewScript("scriptURI/from/script/root/page.js", "scriptName", ["scriptdependency", "JQuery"]); +$menu = $module->addMenu("Menu Name"); + +$pageFunction = function($settings) { + return "html code"; //not nor +} + +$menu->addItem("Item Name", $pageFunction); ``` -- `"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 +#### Usage ```php -$optionMenu = website->addOptionsMenu("Menu Name"); -``` +$options = $module->addOptionItem("Item 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" +$options->addOption("Option Name", "optionName", OptionTypes::text) +$options->addOption("optionVar", OptionTypes::Text, { + "name": "Name", + "placeholder": "placeholder", + "default": "defaultValue" + // more options will come later }); + + ``` -## Modules +```js +/* +possibilité de mettre des routes qui executent des functions +ajouter des pages dans la section d'admin +(Module) to initialize & manage the module +(Menu, Item from Menu) classes to manage adminPanel elements +(Variables) class to get/set used around the website vars +(OptionsItem from Item) to have a custom page for settings +(OptionsTab, Option) -modules will work like this in the `page.content` of the page `[moduleName variablesName="valueName"]` +*/ +$module = new Module(); -the module will then receive a variable named `$modVars` that will contain `$modVars->variableName` = `valueName` and will have to return a `String` Object +$menu = $module.addMenu("menuName"); +$menu.addItem("itemName", function()); -To keep the document strict it's advised to use the php `DOMDocument` Object +options = Module.addOptionsMenu("name"); + +optionTab = options.addOptionTab("name"); + +optionTab.addOption("test", =enum.text); + +//options added will be in the first tab named at the menu name +//if there is only one tab or no tab we won't show tabs +options.addOption("test", =enum.text); + +//add options if it is equal to something +//true/false is what it must be to be shown +//with be in js i think +options.addOption("option name"=String, enum.text=enumeType, "option to check", "regex to check with", must it true or false) + +``` ## Files/Folders architecture -- index.php (is it really necessary ?) - .htaccess (handle file redirection) -- router.php (handle the first route part ( separating the loading process)) -- uploads/ -- cache/ (public cache (won't be seen by client via .htaccess redirection)) - - .htaccess (make sure clients can't access this folder) - - scripts.js - - styles.css -- pages/ (NO `scripts.js` NOR `styles.css` NOR `admin` NOR `login` files must be in here) - - .htaccess (make sure clients can't access this folder) - - index.json (this index.json will be the root name "/") - - slugname.json (path = "/slugname") - - iamjson.json.json (path = "/iamjson.json" wand with a module/theme could just return json) - - folderslug/ - - index.json (path = "/folderslug" if no index.json is given there will be a 404 error for "/folderslug" but not for the "/folderslug/pouet") - - pouet.json (path = "/folderslug/pouet") - admin/ - .htaccess manage redirection for admin pages (pass throught a verify login script) - index.php - admin.js - admin.css - settings/ (settings files more infos [here](#config-files)) - - scripts.json (if cache is disabled these files will be used to get the styles & scripts) - - styles.json (else these files are only used to create the caches files) - - admin.json (admin settings (see admin.json section)) - - templates.json (simple name to redirect) + - site.json (adminPanel settings (see admin.json section)) - modules/ - moduleName/ - settings.json - - vars.json - - themes/ - - themeName/ - - settings.json - - vars.json - admin.json (used to see what to launch on the admin side) - options.json (options for modules & themes to be used site-wide) - templates.json (store the template used on the website with a link to there .php file) - - themes/ (when a new theme is loaded regenerate scripts.js & styles.css, an option will allow the use of direct files) - - default/ (a default theme will be here) - - theme.php - - themeName/ - - theme.php (only launched on theme load, to generate cache files & admin options files) - - public.php (launched everytime on website when page is launched (admins sections are excluded) - - admin.php (launched everytime on admin/themename/** launch (with args like page)) - - templates/ (all folders included under are optional anc can be located somewhere else in the theme folder) - - page.php (at least a template named "page" must exist to make the theme usable) - - templateName.php (file launched everytime a page is loaded with the template selected) - - css/ - - js/ - modules/ - default/ (a default module will be here) - module.php @@ -159,29 +143,11 @@ To keep the document strict it's advised to use the php `DOMDocument` Object ## Configs files -### page.json (in `pages` folder) +### site.json -```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": "

hello world

" -} -``` +Site-wide settings (don't know if it will be accesible for modules) -### scripts.json & styles.json - -```json -{ - [ - "path/to/script" - ] -} -``` - -### admin.json +Location: `/admin/settings/` ```json { @@ -193,7 +159,11 @@ To keep the document strict it's advised to use the php `DOMDocument` Object } ``` -### vars.json +### settings.json + +Stock the module variables + +Location: `/admin/settings/modules/moduleName/` ```json { @@ -207,64 +177,3 @@ To keep the document strict it's advised to use the php `DOMDocument` Object } } ``` - -### 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.json - -liste des tempplates crée par le theme - -*voir si il y auras tout les themes ou seulement le theme actif* - -if static is true then static webpage will be generated - -```json -{ - "templateName": { - "URI": "templates/templateName.php", - "function": "functionName", - "static": false - } -} -``` diff --git a/router.php b/router.php deleted file mode 100644 index d0131dd..0000000 --- a/router.php +++ /dev/null @@ -1,46 +0,0 @@ - diff --git a/.htaccess b/src/.htaccess similarity index 55% rename from .htaccess rename to src/.htaccess index dae4960..2c5ea01 100644 --- a/.htaccess +++ b/src/.htaccess @@ -1,4 +1,4 @@ RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f -RewriteRule ^(.*)$ ./router.php [L,QSA] \ No newline at end of file +RewriteRule ^(.*)$ ./admin/init.php [L,QSA] diff --git a/src/admin/init.php b/src/admin/init.php new file mode 100644 index 0000000..e11836e --- /dev/null +++ b/src/admin/init.php @@ -0,0 +1,8 @@ +getConstants(); + } + return self::$constCacheArray[$calledClass]; + } + + public static function isValidName($name, $strict = false) { + $constants = self::getConstants(); + + if ($strict) { + return array_key_exists($name, $constants); + } + + $keys = array_map('strtolower', array_keys($constants)); + return in_array(strtolower($name), $keys); + } + + public static function isValidValue($value, $strict = true) { + $values = array_values(self::getConstants()); + return in_array($value, $values, $strict); + } +} + +// abstract class DaysOfWeek extends BasicEnum { +// const Sunday = 0; +// const Monday = 1; +// const Tuesday = 2; +// const Wednesday = 3; +// const Thursday = 4; +// const Friday = 5; +// const Saturday = 6; +// } diff --git a/src/admin/system/OptionTypes.php b/src/admin/system/OptionTypes.php new file mode 100644 index 0000000..7ebfba1 --- /dev/null +++ b/src/admin/system/OptionTypes.php @@ -0,0 +1,6 @@ +routeList[$regex] = $function; + } + + public function search(String $route) { + foreach ($this->routeList as $key => $value) { + if(preg_match($key, $route)) { + return $value; + } + } + return null; + } + + +} diff --git a/admin/system/functions.php b/src/admin/system/functions.php similarity index 100% rename from admin/system/functions.php rename to src/admin/system/functions.php diff --git a/src/admin/system/modules.php b/src/admin/system/modules.php new file mode 100644 index 0000000..54906e0 --- /dev/null +++ b/src/admin/system/modules.php @@ -0,0 +1,75 @@ +items, $menu); + } + + public function addItem(Item $item) { + array_push($this->items, $item); + } +} + +class Item { + + private $name; + private $url; + private $function; + + + + public function toLoad($function) { + $this->function = $function; + } + +} + +class OptionItem extends Item { + /* + + */ +} + + +abstract class Module { + +} diff --git a/src/admin/system/router.php b/src/admin/system/router.php new file mode 100644 index 0000000..173437e --- /dev/null +++ b/src/admin/system/router.php @@ -0,0 +1,55 @@ +routeList[$route] = $page; + } + + //fonction de recherche d'une route par rapport a un texte + //return function + public function search($path) { + foreach ($this->routeList as $reg => $page) { + if(preg_match($reg, $path)) { + return $page; + } + } + return function () { + return "404"; + }; + } + + public function redirecter($source, $redirectPage) { + $this->addRoute($source, function() { + header("Location: " . $redirectPage); + }); + } +} diff --git a/admin/system/website.php b/src/admin/system/website.php similarity index 100% rename from admin/system/website.php rename to src/admin/system/website.php diff --git a/test.php b/src/test.php similarity index 100% rename from test.php rename to src/test.php diff --git a/tests/TestEnum.php b/tests/TestEnum.php new file mode 100644 index 0000000..72bee17 --- /dev/null +++ b/tests/TestEnum.php @@ -0,0 +1,34 @@ +expectException(Error::class); + new Enum(); + } + + public function testValidOption(): void { + $this->assertEquals( + 0, + OptionTypes::String + ); + } + + public function testIsValidName(): void { + $this->assertEquals( + true, + OptionTypes::isValidName("String") + ); + $this->assertEquals( + false, + OptionTypes::isValidName("Sting") + ); + $this->assertEquals( + false, + OptionTypes::isValidName("string", true) + ); + } +}