mirror of
https://github.com/Aviortheking/DeltaCMS.git
synced 2025-06-13 17:49:19 +00:00
Moved index & htaccess to public folder
This commit is contained in:
33
public/.htaccess
Normal file
33
public/.htaccess
Normal file
@ -0,0 +1,33 @@
|
||||
# Apache version required 2.x
|
||||
|
||||
<IfModule mod_rewrite.c>
|
||||
RewriteEngine On
|
||||
|
||||
RewriteCond %{REQUEST_FILENAME} !-f
|
||||
|
||||
RewriteRule ^(.*)$ index.php [L]
|
||||
</IfModule>
|
||||
|
||||
ErrorDocument 403 /index.php
|
||||
|
||||
|
||||
<FilesMatch ".*\.(php)$">
|
||||
<IfVersion < 2.4>
|
||||
Order Allow,Deny
|
||||
Deny from all
|
||||
</IfVersion>
|
||||
<IfVersion >= 2.4>
|
||||
Require all denied
|
||||
</IfVersion>
|
||||
</FilesMatch>
|
||||
|
||||
# on donne l'autorisation d'acceder au fichier handler.php (sinon le site ne sera pas foncitonnel)
|
||||
<FilesMatch "^index.php">
|
||||
<IfVersion < 2.4>
|
||||
Order Allow,Deny
|
||||
Allow from all
|
||||
</IfVersion>
|
||||
<IfVersion >= 2.4>
|
||||
Require all granted
|
||||
</IfVersion>
|
||||
</FilesMatch>
|
113
public/index.php
Normal file
113
public/index.php
Normal file
@ -0,0 +1,113 @@
|
||||
<?php
|
||||
|
||||
use AdminPanel\AdminPanel;
|
||||
|
||||
session_start();
|
||||
ini_set('display_errors', 'On');
|
||||
|
||||
/** @var Composer\Autoload\ClassLoader $loader */
|
||||
$loader = require_once __DIR__ . "/../vendor/autoload.php";
|
||||
|
||||
//die;
|
||||
$ap = AdminPanel::getInstance();
|
||||
// dd($ap);
|
||||
/*
|
||||
1: get all the template folders
|
||||
2: match routes directly with modules
|
||||
*/
|
||||
$cache = $ap->getCache();
|
||||
|
||||
if (!$ap->isCacheEnabled()) {
|
||||
$cache->clear();
|
||||
}
|
||||
|
||||
$caches = $cache->getMultiple(array(
|
||||
'routes',
|
||||
'templates',
|
||||
'forms'
|
||||
));
|
||||
|
||||
//if cache don't exist create it!
|
||||
$cachesBool = $caches["routes"] === null || $caches['templates'] === null || $caches['forms'] === null;
|
||||
if (!$ap->isCacheEnabled() || $cachesBool) {
|
||||
$cache->clear();
|
||||
$modulesDIR = dirname(__DIR__) . "/src/Modules";
|
||||
$modules = array_diff(scandir($modulesDIR), array('..', '.'));
|
||||
/** @var string $module */
|
||||
foreach ($modules as $module) {
|
||||
$moduleDIR = $modulesDIR . "/" . $module;
|
||||
if (is_dir($moduleDIR) && is_file($moduleDIR . "/" . strtolower($module) . ".json")) {
|
||||
$json = json_decode(file_get_contents($moduleDIR . "/" . strtolower($module) . ".json"));
|
||||
if (isset($json->templateFolder)) {
|
||||
$cache->set(
|
||||
'templates',
|
||||
array_merge($cache->get('templates', array()), array(
|
||||
$module => $moduleDIR . $json->templateFolder
|
||||
))
|
||||
);
|
||||
}
|
||||
foreach ($json->routes as $routeName => $routeArgs) {
|
||||
if (isset($routeArgs->file)) {
|
||||
$routeArgs->file = $moduleDIR . $routeArgs->file;
|
||||
}
|
||||
$cache->set('routes', array_merge(
|
||||
$cache->get('routes', array()),
|
||||
array(
|
||||
$routeName => $routeArgs
|
||||
)
|
||||
));
|
||||
}
|
||||
if (isset($json->forms)) {
|
||||
foreach ($json->forms as $formName => $formArgs) {
|
||||
$cache->set('forms', array_merge(
|
||||
$cache->get('forms', array()),
|
||||
array(
|
||||
$formName => $formArgs
|
||||
)
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$caches = $cache->getMultiple(array(
|
||||
'routes',
|
||||
'templates',
|
||||
'forms'
|
||||
));
|
||||
}
|
||||
//load each templates
|
||||
foreach ($caches['templates'] as $key => $value) {
|
||||
$ap->addLoaderFolder($value, $key);
|
||||
}
|
||||
foreach ($caches['routes'] as $key => $value) {
|
||||
$args = isset($value->args) ? $value->args : new stdClass();
|
||||
$composants = slugEqualToURI($value->path, filter_input(INPUT_SERVER, "REQUEST_URI"), $args);
|
||||
// dump($composants !== false);
|
||||
if ($composants !== false) {
|
||||
if (isset($value->file)) {
|
||||
if (isset($value->type)) {
|
||||
header("Content-Type: " . $value->type . "; charset=UTF-8");
|
||||
}
|
||||
echo file_get_contents($value->file);
|
||||
die;
|
||||
}
|
||||
$loader->loadClass($value->controller);
|
||||
$function = $value->function;
|
||||
// dump($function);
|
||||
/** @var AdminPanel\Classes\Controller $controller */
|
||||
$controller = new $value->controller();
|
||||
// dd(new $routeArgs->controller());
|
||||
if ($composants) {
|
||||
$controller->setUrlArguments($composants);
|
||||
}
|
||||
// if(isset($json->templateFolder)) $controller->loadTwig($json->templateFolder);
|
||||
echo $controller->$function();
|
||||
die;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
http_response_code(404);
|
||||
echo "404";
|
Reference in New Issue
Block a user