mirror of
https://github.com/Aviortheking/DeltaCMS.git
synced 2025-04-22 10:52:11 +00:00
many changes
updated composer.json to user psr-4 autoloader updated .htaccess to point to the correct file Rewrite of most of the project
This commit is contained in:
parent
17f223d517
commit
e4d59be18c
@ -1 +0,0 @@
|
|||||||
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;}}}
|
|
@ -2,6 +2,7 @@
|
|||||||
"name": "avior/admin-panel",
|
"name": "avior/admin-panel",
|
||||||
"type": "project",
|
"type": "project",
|
||||||
"license": "MIT License",
|
"license": "MIT License",
|
||||||
|
"description": "WIP Project",
|
||||||
"authors": [
|
"authors": [
|
||||||
{
|
{
|
||||||
"name": "Avior",
|
"name": "Avior",
|
||||||
@ -9,12 +10,8 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"classmap": [
|
"psr-4": {
|
||||||
"src/admin/system/"
|
"AdminPanel\\": "src/"
|
||||||
]
|
}
|
||||||
},
|
|
||||||
"require": {},
|
|
||||||
"require-dev": {
|
|
||||||
"phpunit/phpunit": "^8"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
RewriteEngine on
|
RewriteEngine on
|
||||||
|
|
||||||
RewriteCond %{REQUEST_FILENAME} !-f
|
RewriteCond %{REQUEST_FILENAME} !-f
|
||||||
RewriteRule ^(.*)$ ./admin/init.php [L,QSA]
|
RewriteRule ^(.*)$ ./index.php [L,QSA]
|
||||||
|
10
src/Classes/Controller.php
Normal file
10
src/Classes/Controller.php
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace AdminPanel\Classes;
|
||||||
|
|
||||||
|
class Controller {
|
||||||
|
|
||||||
|
|
||||||
|
//TODO implements functions and variables to add functionnalities to controllers
|
||||||
|
|
||||||
|
}
|
@ -1,8 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
//
|
namespace AdminPanel\Classes\Enum;
|
||||||
|
|
||||||
abstract class Enum {
|
abstract class Enum {
|
||||||
|
/** @var null|array $constCacheArray */
|
||||||
private static $constCacheArray = NULL;
|
private static $constCacheArray = NULL;
|
||||||
|
|
||||||
private static function getConstants() {
|
private static function getConstants() {
|
16
src/Modules/Index/Controller/IndexController.php
Normal file
16
src/Modules/Index/Controller/IndexController.php
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace AdminPanel\Modules\Index\Controller;
|
||||||
|
|
||||||
|
use AdminPanel\Classes\Controller;
|
||||||
|
|
||||||
|
class IndexController extends Controller {
|
||||||
|
|
||||||
|
public function index() {
|
||||||
|
return "hello world!";
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test() {
|
||||||
|
return "test working!";
|
||||||
|
}
|
||||||
|
}
|
19
src/Modules/Index/index.json
Normal file
19
src/Modules/Index/index.json
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
{
|
||||||
|
"routes": {
|
||||||
|
"route_name": {
|
||||||
|
"path": "/",
|
||||||
|
"controller": "\\AdminPanel\\Modules\\Index\\Controller\\IndexController",
|
||||||
|
"function": "index"
|
||||||
|
},
|
||||||
|
"route_name2": {
|
||||||
|
"path": "/test/{slug}/",
|
||||||
|
"controller": "\\AdminPanel\\Modules\\Index\\Controller\\IndexController",
|
||||||
|
"function": "test",
|
||||||
|
"args": {
|
||||||
|
"slug": {
|
||||||
|
"regex": "/[a-z]+/"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
13
src/Modules/ModuleName/Controller/ExampleController.php
Normal file
13
src/Modules/ModuleName/Controller/ExampleController.php
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace AdminPanel\Modules\ModuleName\Controller;
|
||||||
|
|
||||||
|
use AdminPanel\Classes\Controller;
|
||||||
|
|
||||||
|
|
||||||
|
class ExampleController extends Controller {
|
||||||
|
|
||||||
|
public function example() {
|
||||||
|
return "hello Controller!";
|
||||||
|
}
|
||||||
|
}
|
9
src/Modules/ModuleName/modulename.json
Normal file
9
src/Modules/ModuleName/modulename.json
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"routes": {
|
||||||
|
"route_name": {
|
||||||
|
"path": "/example",
|
||||||
|
"controller": "\\AdminPanel\\Modules\\ModuleName\\Controller\\ExampleController",
|
||||||
|
"function": "example"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,8 +0,0 @@
|
|||||||
<?php
|
|
||||||
ini_set('display_errors', 'On');
|
|
||||||
|
|
||||||
define("ROOT", __DIR__);
|
|
||||||
|
|
||||||
// require_once ROOT . "/system/router.php";
|
|
||||||
|
|
||||||
// define("ROUTER", Router::getRouter());
|
|
@ -1,3 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
//page where you edit a frontend page in the adminPanel
|
|
@ -1 +0,0 @@
|
|||||||
<?php
|
|
@ -1,5 +0,0 @@
|
|||||||
{
|
|
||||||
"theme": "default",
|
|
||||||
"cache": true,
|
|
||||||
"modules": ["default"]
|
|
||||||
}
|
|
@ -1,6 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
class OptionTypes extends Enum {
|
|
||||||
const String = 0;
|
|
||||||
const Integer = 1;
|
|
||||||
}
|
|
@ -1,35 +0,0 @@
|
|||||||
<?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;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
@ -1,55 +0,0 @@
|
|||||||
<?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
|
|
||||||
*/
|
|
||||||
|
|
||||||
?>
|
|
@ -1,75 +0,0 @@
|
|||||||
<?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 {
|
|
||||||
|
|
||||||
}
|
|
@ -1,55 +0,0 @@
|
|||||||
<?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);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,40 +0,0 @@
|
|||||||
<?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() {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
73
src/index.php
Normal file
73
src/index.php
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
<?php
|
||||||
|
ini_set('display_errors', 'On');
|
||||||
|
|
||||||
|
define("ROOT", __DIR__);
|
||||||
|
|
||||||
|
use AdminPanel\Classes\Controller;
|
||||||
|
|
||||||
|
/** @var Composer\Autoload\ClassLoader $loader */
|
||||||
|
$loader = require_once ROOT . "/../vendor/autoload.php";
|
||||||
|
// var_dump($_SERVER["REQUEST_URI"] . "/");
|
||||||
|
// $_SERVER["REQUEST_URI"] = "/test/";
|
||||||
|
//get all dirs
|
||||||
|
$modulesDIR = ROOT . "/Modules";
|
||||||
|
$modules = array_diff(scandir($modulesDIR), array('..', '.'));
|
||||||
|
|
||||||
|
/** @var string $module */
|
||||||
|
foreach ($modules as $module) {
|
||||||
|
$moduleDIR = $modulesDIR . "/" . $module;
|
||||||
|
if (is_dir($moduleDIR)) {
|
||||||
|
$json = json_decode(file_get_contents($moduleDIR . "/" . strtolower($module) . ".json"));
|
||||||
|
foreach ($json->routes as $routeName => $routeArgs) {
|
||||||
|
$args = isset($routeArgs->args) ? $routeArgs->args : new stdClass();
|
||||||
|
|
||||||
|
if(slugEqualToURI($routeArgs->path, $_SERVER["REQUEST_URI"], $args)) {
|
||||||
|
$loader->loadClass($routeArgs->controller);
|
||||||
|
$function = $routeArgs->function;
|
||||||
|
echo (new $routeArgs->controller)->$function();
|
||||||
|
die;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// echo Controller::example();
|
||||||
|
|
||||||
|
// require_once ROOT . "/system/router.php";
|
||||||
|
|
||||||
|
// define("ROUTER", Router::getRouter());
|
||||||
|
function startsWith($haystack, $needle)
|
||||||
|
{
|
||||||
|
$length = strlen($needle);
|
||||||
|
return (substr($haystack, 0, $length) === $needle);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $uri
|
||||||
|
* @param string $slug
|
||||||
|
* @param object $options options->regex &| options->setting
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
function slugEqualToURI($slug, $uri, $options) {
|
||||||
|
$uri = explode("/", trim($uri, "\/"));
|
||||||
|
$slug = explode("/", trim($slug, '\/'));
|
||||||
|
|
||||||
|
if(count($uri) != count($slug)) return false;
|
||||||
|
|
||||||
|
foreach ($slug as $key => $value) {
|
||||||
|
|
||||||
|
if(preg_match("/{.+}/", $value)) {
|
||||||
|
$elemnt = preg_replace("/{|}/", "", $value);
|
||||||
|
$elOptions = $options->$elemnt;
|
||||||
|
if($elOptions->regex != null && preg_match($elOptions->regex, $uri[$key])) continue;
|
||||||
|
else return false;
|
||||||
|
//TODO correspond with module settings
|
||||||
|
} else {
|
||||||
|
if($value == $uri[$key]) continue;
|
||||||
|
else return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
37
src/test.php
37
src/test.php
@ -1,37 +0,0 @@
|
|||||||
<?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);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
?>
|
|
@ -1,34 +0,0 @@
|
|||||||
<?php
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
|
||||||
|
|
||||||
final class TestEnum extends TestCase {
|
|
||||||
|
|
||||||
public function testInstantiateEnum(): void {
|
|
||||||
$this->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)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user