This commit is contained in:
2019-03-02 15:54:10 +01:00
parent bc8fba19d4
commit 17f223d517
32 changed files with 366 additions and 288 deletions

4
src/.htaccess Normal file
View File

@ -0,0 +1,4 @@
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ ./admin/init.php [L,QSA]

8
src/admin/init.php Normal file
View File

@ -0,0 +1,8 @@
<?php
ini_set('display_errors', 'On');
define("ROOT", __DIR__);
// require_once ROOT . "/system/router.php";
// define("ROUTER", Router::getRouter());

View File

View File

@ -0,0 +1,3 @@
<?php
//page where you edit a frontend page in the adminPanel

View File

@ -0,0 +1 @@
<?php

View File

@ -0,0 +1,5 @@
{
"theme": "default",
"cache": true,
"modules": ["default"]
}

45
src/admin/system/Enum.php Normal file
View File

@ -0,0 +1,45 @@
<?php
//
abstract class Enum {
private static $constCacheArray = NULL;
private static function getConstants() {
if (self::$constCacheArray == NULL) {
self::$constCacheArray = [];
}
$calledClass = get_called_class();
if (!array_key_exists($calledClass, self::$constCacheArray)) {
$reflect = new ReflectionClass($calledClass);
self::$constCacheArray[$calledClass] = $reflect->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;
// }

View File

@ -0,0 +1,6 @@
<?php
class OptionTypes extends Enum {
const String = 0;
const Integer = 1;
}

View File

@ -0,0 +1,35 @@
<?php
class Router {
private static $instance;
private $routeList = [];
private function __construct() {}
public static function getInstance() {
if($instance !== null) {
Router::$instance = new Self();
}
return Router::$instance;
}
public function addRoute(string $regex, $function) {
$this->routeList[$regex] = $function;
}
public function search(String $route) {
foreach ($this->routeList as $key => $value) {
if(preg_match($key, $route)) {
return $value;
}
}
return null;
}
}

View 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
*/
?>

View File

@ -0,0 +1,75 @@
<?php
/*
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)
*/
/*
menu = Module.addMenu("menuName");
menu.addItem("itemName", function());
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)
*/
class Menu {
private $items = array();
public function __construct() {
}
public function addMenu(Menu $menu) {
array_push($this->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 {
}

View File

@ -0,0 +1,55 @@
<?php
/**
* classe pour gerer le routage des pages
* la variable static $router sert a utiliser le router dans plusieurs fichier
* sans forcement avoir une obligation de nom de variable
* de plus ils sert a garder une route unique
*/
class Router {
//variable static pour stocker le router
private static $router = null;
//definit le router
public function __construct() {
if(Router::$router != null) {
return Router::$router;
} else Router::$router = $this;
}
//fonction static pour recuperer un router déjà crée
public static function getRouter() {
if(Router::$router == null) {
Router::$router = new Router();
}
return Router::$router;
}
//liste des routes
private $routeList = array();
//ajout d'une route
public function addRoute($route, $page) {
$this->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);
});
}
}

View 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() {
}
}

37
src/test.php Normal file
View File

@ -0,0 +1,37 @@
<?php
// $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();
// echo gettype(true);
// include_once "admin/system/website.php";
// $website = new Website(__DIR__);
// $website->addTemplate("Blog Page", "templates/blog.php", "page", true);
// 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);
// }
// }
?>