Browse Source

Beta 0.6.0 - 15 mars 2016 - ChangeLog view TODO

Signed-off-by: Adrien Kara <adrien.ph@gmail.com>
master
Adrien Kara 5 years ago
parent
commit
f6c6c00e9e
13 changed files with 310 additions and 154 deletions
  1. 3
      Content/Saison01/Chappitre2/Ep1/fr-fr.txt
  2. 1
      Content/Saison01/fr-fr.txt
  3. 26
      Database/Config.json
  4. 3
      Database/Content.json
  5. 94
      Include/Configuration/Config.inc.conf.php
  6. 194
      Include/ContentManager.inc.php
  7. 2
      Include/ErrorsAndInfos.inc.php
  8. 31
      Include/Main.inc.php
  9. 8
      Library/LittleSecureLib.php
  10. 27
      Public/Templates/Default/config.json
  11. 23
      Public/Templates/Default/index.tpl.php
  12. 2
      Public/index.php
  13. 50
      TODO

3
Content/Saison01/Chappitre2/Ep1/fr-fr.txt

@ -1 +1,4 @@
Je suis un home louable,<br />
à la minute ou a l'heure,<br />
mes seinssavent aimer létable durable<br />
blablabla

1
Content/Saison01/fr-fr.txt

@ -0,0 +1 @@
!PHP:returnMenu(jsonLoad('Content'), 'Pages/Saison01'):PHP!

26
Database/Config.json

@ -0,0 +1,26 @@
{
"onlyHTTPS": false,
"debugMode": true,
"serverUrl": "localhost/Public/",
"supportedLanguage": ["fr-fr", "en-us"],
"defaultLanguage": "fr-fr",
"defaultCharset": "UTF-8",
"tplName": "Default",
"webName": "Iglou.eu",
"webDescription": "Blablabla Mister Freeman. Welcom to my web Site ! The right man in the wrong place can make all the difference in the world",
"Template": {
"Default": {
"files": {
"main": "index.tpl.php"
},
"Scheme": {
"module1": "headerHTML($contentJo);",
"module2": "returnMenu($contentJo, 'Pages', 1);",
"module3": "returnPage($contentJo, $currentPg);"
},
"Config": {
"bg_color": "#980646"
}
}
}
}

3
Database/Content.json

@ -15,6 +15,7 @@
},
"Saison01": {
"category": true,
"andAPage": true,
"title": {
"fr-fr": "Saison 01",
"en-us": "Saison 01"
@ -35,7 +36,7 @@
"Ep1": {
"category": false,
"title": {
"fr-fr": "Episode1",
"fr-fr": "Épisode1",
"en-us": "Machin"
}
},

94
Include/Configuration/Config.inc.conf.php

@ -1,65 +1,55 @@
<?php
function cmsConfig($arg, $change = 0, $newValue = null)
{
// $serverUrl use $_SERVER['SERVER_NAME'] if is empty.
// WARN : SERVER_NAME is based on 'ServerName' HTTP server option
// but HTTP_HOST which is defined by header(Client side), when SERVER_NAME is called return HTTP host header ...
// this is an Apache bug ! To solve it set 'UseCanonicalName' directive to 'on' in the '<VirtualHost>'
static $serverUrl ='http://localhost/Public/'; // $_SERVER['SERVER_NAME']
static $onlyHTTPS = false; // HTTPS Only - If is true and https is not activated, script dies !
static $activeDebugMode = true;
static $cmsConfig;
// Template selector
// Template should be in 'Public/Templates/*'
static $templateUsed = 'Default';
static $templateIndex = 'index.tpl.php';
if (null === $cmsConfig) {
$cmsConfig = jsonLoad('Config');
// Location; Empty = root; add "/";
static $pgLocation = 'Plugins/';
static $dbLocation = 'Database/';
// DB
static $dbGuest = 'Guest.json';
static $dbErrors = 'Errors.json';
static $dbContent = 'Content.json';
static $dbPlugins = 'Plugins.json';
// Language !lowercase!
static $defaultLanguage = 'fr-fr';
static $defaultCharset = 'utf-8';
// Web site description
static $webName = 'Iglou.eu';
static $webDescription = 'Blablabla Mister Freeman. Welcom to my web Site ! The right man in the wrong place can make all the difference in the world';
if ($cmsConfig['onlyHTTPS']) {
$cmsConfig['serverUrl'] = 'https://'.$cmsConfig['serverUrl'];
} else {
$cmsConfig['serverUrl'] = 'http://'.$cmsConfig['serverUrl'];
}
}
// Content option
static $contentFileExt = '.txt';
static $contentFolder = 'Content/';
if ($change) {
$cmsConfig[$arg] = $newValue;
$arg = $cmsConfig[$arg];
} elseif ((array) $arg === $arg) {
foreach ($arg as &$value) {
if (isset($cmsConfig[$value])) {
$foreach[$value] = $cmsConfig[$value];
} else {
$foreach[$value] = 0;
}
}
// ! END OF CONRFIG ! //
$arg = &$foreach;
} else {
if (isset($cmsConfig[$arg])) {
$arg = $cmsConfig[$arg];
} else {
$arg = 0;
}
}
// Mixing var
static $templateDir ;
static $templateLink ;
return ($arg);
}
static $dbGuestPath ;
static $dbErrorsPath ;
static $dbContentPath ;
static $dbPluginsPath ;
function dataConfig($arg)
{
static $view_fd = 'Public/';
if (null === $templateDir) {
$templateDir = 'Public/Templates/'.$templateUsed.'/';
$templateLink = $serverUrl.'Templates/'.$templateUsed.'/';
static $template_fd = 'Templates/';
static $plugins_fd = 'Plugins/';
static $database_fd = 'Database/';
static $content_fd = 'Content/';
static $database_ext = '.json';
static $content_ext = '.txt';
$dbGuestPath = APP_ROOT.$dbLocation.$dbGuest;
$dbErrorsPath = APP_ROOT.$dbLocation.$dbErrors;
$dbContentPath = APP_ROOT.$dbLocation.$dbContent;
$dbPluginsPath = APP_ROOT.$dbLocation.$dbPlugins;
}
if ($change) {
$$arg = $newValue;
$arg = ${$arg};
} elseif ((array) $arg === $arg) {
if ((array) $arg === $arg) {
foreach ($arg as &$value) {
if (isset($$value)) {
$foreach[$value] = ${$value};
@ -77,5 +67,5 @@ function cmsConfig($arg, $change = 0, $newValue = null)
}
}
return ($arg);
return $arg;
}

194
Include/ContentManager.inc.php

@ -1,4 +1,47 @@
<?php
/* --- TMP --- */
function parseAndPutsTpl()
{
$tplConfig = cmsConfig(array('tplName', 'Template'));
$tplGetCtt = dataConfig(array('view_fd', 'template_fd'));
$tplGetCtt = APP_ROOT.$tplGetCtt['view_fd'].$tplGetCtt['template_fd'].$tplConfig['tplName'];
$tplConfig = $tplConfig['Template'][$tplConfig['tplName']];
$contentJo = jsonLoad('Content');
$currentPg = currentPage();
if (!isset($tplConfig['files'][$currentPg])) {
$tplGetCtt .= '/'.$tplConfig['files']['main'];
} else {
$tplGetCtt .= '/'.$tplConfig['files'][$currentPg];
}
$tplGetCtt = file_get_contents($tplGetCtt, null, null);
foreach ($tplConfig['Scheme'] as $key => &$value) {
$tplGetCtt = str_replace('[M:'.$key.']', '<?php echo '.$value.' ?>', $tplGetCtt);
}
foreach ($tplConfig['Config'] as $key => &$value) {
$tplGetCtt = str_replace('[C:'.$key.']', $value, $tplGetCtt);
}
echo eval('?>'.$tplGetCtt);
}
function cmsGetGlobalData()
{
$cmsConfig = cmsConfig(array('serverUrl', 'defaultLanguage', 'defaultCharset', 'tplName', 'webName', 'webDescription'));
$template_fd = dataConfig('template_fd');
$cmsConfig['tpl_url'] = $cmsConfig['serverUrl'].$template_fd.$cmsConfig['tplName'].'/';
$cmsConfig['header'] = '<meta http-equiv="content-type" content="text/html; charset='.$cmsConfig['defaultCharset'].'">
<title>'.$cmsConfig['webName'].': '.currentPage().'</title>
<meta name="description" content="'.$cmsConfig['webDescription'].'">
';
return $cmsConfig;
}
/* ---------- Content checker ---------- */
function currentPage()
{
@ -13,8 +56,8 @@ function currentPage()
function contentLanguage($arg)
{
if (isset($_COOKIE['LGG']) && array_key_exists($_COOKIE['LGG'], $arg)) {
$arg = $_COOKIE['LGG'];
if (isset($_SESSION['LGG']) && array_key_exists($_SESSION['LGG'], $arg)) {
$arg = $_SESSION['LGG'];
} else {
$arg = cmsConfig('defaultLanguage');
}
@ -24,52 +67,81 @@ function contentLanguage($arg)
function checkLanguage()
{
$buff = '';
$cmsConfig = cmsConfig(array('supportedLanguage', 'defaultLanguage'));
if (isset($_GET['LGG'])) {
$_COOKIE['LGG'] = securityParser(substr($_GET['LGG'], 0, 5), true);
$buff = securityParser(substr($_GET['LGG'], 0, 5), true);
if (in_array($buff, $cmsConfig['supportedLanguage'], true)) {
$_SESSION['LGG'] = $buff;
} else {
$_SESSION['LGG'] = $cmsConfig['defaultLanguage'];
}
} else {
/**
* levenshtein()
* Define on config file all language that this site use
* Check what is supported language has the least differance witch HTTP_ACCEPT_LANGUAGE
* If no word matches, assign defaultLanguage
**/
if (!isset($_COOKIE['LGG'])) {
if (!isset($_SESSION['LGG'])) {
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
$_COOKIE['LGG'] = securityParser(substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 5), true);
} elseif (!isset($_COOKIE['LGG'])) {
$_COOKIE['LGG'] = cmsConfig('defaultLanguage');
$buff = strtolower(securityParser(substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 5), true));
if (in_array($buff, $cmsConfig['supportedLanguage'], true)) {
$_SESSION['LGG'] = $buff;
} else {
$compare = tinyCompareLanguage(substr($buff, 0, 2), $cmsConfig['supportedLanguage']);
if ('' !== $compare) {
$_SESSION['LGG'] = $compare;
} else {
$_SESSION['LGG'] = $cmsConfig['defaultLanguage'];
}
}
} else {
$_SESSION['LGG'] = $cmsConfig['defaultLanguage'];
}
}
}
}
function tinyCompareLanguage($string, $arrLg)
{
foreach ($arrLg as &$value) {
if (substr($value, 0, 2) === $string) {
return $value;
}
}
return '';
}
/* ---------- Json manager ---------- */
function jsonLoaded($dbRead)
function jsonLoad($dbRead)
{
static $guest ;
static $errors ;
static $content;
static $plugins;
static $ext;
static $path;
static $Config;
static $Content;
static $Errors;
static $Guest;
static $Plugins;
if (null === $path) {
$ext = dataConfig('database_ext');
$path = APP_ROOT.dataConfig('database_fd');
}
if (null === $content) {
$confFile = cmsConfig(array('dbPluginsPath', 'dbGuestPath', 'dbErrorsPath', 'dbContentPath'));
$guest = readJson($confFile['dbGuestPath']);
$errors = readJson($confFile['dbErrorsPath']);
$content = readJson($confFile['dbContentPath']);
$plugins = readJson($confFile['dbPluginsPath']);
if (null === $$dbRead) {
$$dbRead = jsonRead($path.$dbRead.$ext);
}
return (${$dbRead});
}
function readJson($arg)
function jsonRead($arg)
{
$request = $arg;
if (is_file($arg)) {
$arg = file_get_contents($arg, null, null);
$arg = utf8_encode($arg);
$arg = json_decode($arg, true);
if (json_last_error()) {
@ -84,13 +156,13 @@ function readJson($arg)
function pluginsDb()
{
$dirConfig = strlen(APP_ROOT.cmsConfig('pgLocation'));
$dirConfig = strlen(APP_ROOT.dataConfig('plugins_fd'));
$requestBy = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 1)['0']['file'];
$requestBy = substr($requestBy, $dirConfig);
$requestBy = substr($requestBy, 0, strpos($requestBy, '/'));
return (jsonLoaded('plugins')[$requestBy]['DataBase']['Used']);
return (jsonLoad('Plugins')[$requestBy]['DataBase']['Used']);
}
/* ---------- Php content generator ---------- */
@ -117,8 +189,8 @@ function pluginsManager()
if ($pluginsLoading) {
$pluginsLoading = 0;
$pluginsList = jsonLoaded('plugins');
$pgLocation = APP_ROOT.cmsConfig('pgLocation');
$pluginsList = jsonLoad('Plugins');
$pgLocation = APP_ROOT.dataConfig('plugins_fd');
foreach ($pluginsList as $key => &$value) {
if ($pluginsList[$key]['Activate']) {
@ -131,7 +203,7 @@ function pluginsManager()
}
/* ---------- Return content ---------- */
function returnPage($pageContent, $page, $type = null, $execPhp = 0) // $type, must be Title or Text
function returnPage($pageContent, $page, $type = null, $execPhp = 1) // $type, must be Title or Text
{
$pageContent = $pageContent['Pages'];
@ -149,11 +221,11 @@ function returnPage($pageContent, $page, $type = null, $execPhp = 0) // $type, m
if ('Title' === $type) {
$outPut = $pageContent['title'][$language];
} else {
$outPut = cmsConfig(array('contentFileExt', 'contentFolder'));
$outPut = APP_ROOT.$outPut['contentFolder'].$page.'/'.$language.$outPut['contentFileExt'];
$outPut = dataConfig(array('content_fd', 'content_ext'));
$outPut = APP_ROOT.$outPut['content_fd'].$page.'/'.$language.$outPut['content_ext'];
$outPut = file_get_contents($outPut);
if ($execPhp) {
if ($execPhp && false !== strpos($outPut, '!PHP:')) {
execPhpContent($outPut, substr_count($outPut, '!PHP:'));
}
}
@ -168,27 +240,50 @@ function returnPage($pageContent, $page, $type = null, $execPhp = 0) // $type, m
return ($outPut);
}
function returnMenu(&$arrJson, $type, $cat = null, $tag = 'ul') // $type, must be 'ul', 'ol' and 'menu'
function returnMenu($menuContent, $cat, $depth = -1, $tag = 'ul') // $type, must be 'ul', 'ol' and 'menu'
{
if (isset($arrJson[$type]) || isset($arrJson[$type][$cat])) {
$outPut = '<'.$tag.'>';
$root = "";
if (null === $cat) {
$outPut .= arrayMenuParser($outPut, $arrJson[$type], $tag);
} else {
$outPut .= arrayMenuParser($outPut, $arrJson[$type][$cat], $tag);
if (false === strpos($cat, '/')) {
$menuContent = (isset($menuContent[$cat])) ? $menuContent[$cat] : false;
} else {
$i = 0;
foreach (explode("/", $cat) as &$value) {
$menuContent = (isset($menuContent[$value])) ? $menuContent[$value] : false;
// For include root patch to url, but not the first cat (page, extra, ...)
if (0 !== $i) {
if ("" === $root) {
$root .= $value;
} else {
$root .= '/'.$value;
}
}
++$i;
}
}
if (false !== $menuContent) {
$outPut = '<'.$tag.'>';
$outPut .= arrayMenuParser($outPut, $menuContent, $depth, $tag, $root);
$outPut .= '</'.$tag.'>'."\n";
} else {
$outPut = declareError('Menu => '.$type.' - '.$cat, 'Nfound')."\n";
$outPut = declareError('Menu => '.$cat, 'Nfound')."\n";
}
return ($outPut);
}
function arrayMenuParser(&$outPut, &$arg, &$tag, $root = "")
function arrayMenuParser(&$outPut, &$arg, &$depth, &$tag, $root)
{
if (0 === $depth) {
return null;
} elseif (0 < $depth) {
--$depth;
}
foreach ($arg as $key => &$value) {
if (isset($value['title'])) {
$key = ("" === $root) ? $key : $root.'/'.$key;
@ -202,8 +297,15 @@ function arrayMenuParser(&$outPut, &$arg, &$tag, $root = "")
}
if ($value['category']) {
$outPut .= '<li id="'.$keyId.'" class="category"><span>'.$value['title'][$language].'</span><'.$tag.'>';
$outPut .= arrayMenuParser($outPut, $value, $tag, $key);
$outPut .= '<li id="'.$keyId.'" class="category">';
if (isset($value['andAPage'])) {
$outPut .= '<a href="'.$link.'"><span>'.$value['title'][$language].'</span></a><'.$tag.'>';
} else {
$outPut .= '<span>'.$value['title'][$language].'</span><'.$tag.'>';
}
$outPut .= arrayMenuParser($outPut, $value, $depth, $tag, $key);
$outPut .= '</'.$tag.'></li>';
} else {
$outPut .= '<li id="'.$keyId.'" class="link"><a ';

2
Include/ErrorsAndInfos.inc.php

@ -1,7 +1,7 @@
<?php
function declareError($arg, $err)
{
$outPut = jsonLoaded('errors');
$outPut = jsonLoad('Errors');
switch ($err) {
case '404':

31
Include/Main.inc.php

@ -1,8 +1,12 @@
<?php
function main()
{
// Declare config
$outPut = cmsConfig(array('activeDebugMode', 'onlyHTTPS', 'templateDir', 'templateIndex'));
$cmsConfig = cmsConfig(array('debugMode', 'onlyHTTPS', 'defaultCharset'));
// Add php charset
header('Content-Type: text/html;charset='.$cmsConfig['defaultCharset']);
// Disable GC
if (gc_enabled()) {
@ -11,25 +15,22 @@ function main()
}
// Check php version and lib
if ($outPut['activeDebugMode']) {
if ($cmsConfig['debugMode']) {
phpChecker();
}
// Check HTTPS
if ($outPut['onlyHTTPS'] && empty($_SERVER["HTTPS"]) && strtolower($_SERVER["HTTPS"]) !== "on") {
if ($cmsConfig['onlyHTTPS'] && empty($_SERVER["HTTPS"]) && strtolower($_SERVER["HTTPS"]) !== "on") {
exit('DIE : Only HTTPS authorized');
}
// Cookies
if ($outPut['onlyHTTPS']) {
if ($cmsConfig['onlyHTTPS']) {
sessionStart(true);
} else {
sessionStart();
}
// Load DB and use
$jsonContent = jsonLoaded('content');
// Check language
checkLanguage();
@ -37,19 +38,5 @@ function main()
pluginsManager();
// Tpl include
require APP_ROOT.$outPut['templateDir'].$outPut['templateIndex'];
}
/* ---------- HTML ---------- */
function headerHTML(&$jsonContent)
{
$outPut = cmsConfig(array('serverUrl', 'defaultCharset', 'webName', 'webDescription'));
$outPut = '<link rel="stylesheet" href="'.$outPut['serverUrl'].'Medias/Errors/404.css">
<meta charset="'.$outPut['defaultCharset'].'">
<title>'.$outPut['webName'].': '.returnPage($jsonContent, currentPage(), 'Title').'</title>
<meta name="description" content="'.$outPut['webDescription'].'">
';
return ($outPut);
parseAndPutsTpl();
}

8
Library/LittleSecureLib.php

@ -251,12 +251,10 @@ function sessionId()
{
$idTime = &$_SESSION['idTime'];
if (empty($idTime)) {
if (empty($idTime) || $idTime >= $idTime + 600) {
//Nouvelle ID toute les 10mn
if ($idTime >= $idTime + 600) {
session_regenerate_id(true);
$idTime = time();
}
session_regenerate_id(true);
$idTime = time();
} else {
$idTime = time();
}

27
Public/Templates/Default/config.json

@ -0,0 +1,27 @@
{
"Profile": {
"name": "Default",
"version": "0.0.1",
"date": "12/03/2016",
"author": "Adrien Kara",
"e-mail": "adrien.ph@gmail.com",
"copyright": "Apache licence V2",
"description": "A very simple template, take it as base for yours."
},
"Files": {
"main": "index.tpl.php"
},
"Scheme": [
"module1",
"module2",
"module3"
],
"Config": {
"bg_color": {
"type": "color",
"value": "#000000",
"title": "Background color",
"description": "Select color for the template background"
}
}
}

23
Public/Templates/Default/index.tpl.php

@ -1,20 +1,27 @@
<?php defined('APP_ROOT') or die; ?>
<?php
defined('APP_ROOT') or die;
$data = cmsGetGlobalData();
?>
<!doctype html>
<html lang="fr">
<head>
<?php echo headerHTML($jsonContent); ?>
<link rel="stylesheet" href="<?php echo cmsConfig('templateLink'); ?>Css/normalize.css">
<?php echo $data['header']; ?>
<link rel="stylesheet" href="<?php echo $data['tpl_url']; ?>Css/normalize.css">
</head>
<body>
<!--[if lt IE 8]>
<p class="browserupgrade">You are using an <strong>outdated</strong> browser.
Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>
<![endif]-->
<?php echo returnMenu($jsonContent, 'Pages');
echo returnMenu($jsonContent, 'Pages', 'Saison01');
echo returnMenu($jsonContent, 'Extra', 'Friends');
echo returnPage($jsonContent, currentPage(), 'Text', 1);
echo timeDB(),'secondes - ',memoryDB(),'mo'; ?>
<div id=header>
[M:module2]
</div>
<div id=contens style="background: [C:bg_color];">
[M:module3]
</div>
<div id=footer>
<?php echo timeDB(),'secondes - ',memoryDB(),'mo'; ?>
</div>
</body>
</html>

2
Public/index.php

@ -17,7 +17,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
* ----------
* Beta 0.5.1 - 10 mars 2016
* Beta 0.6.0 - 15 mars 2016
* ----------
* IGLOU cms
** ---------- */

50
TODO

@ -1,21 +1,35 @@
#E50000: Urgent
#FF9B00: To do
#00E000: Can wait
-- AF --
add plugin mail
add admin state, function and GUI
change summons language function
administrator log(connexions, error)
plugins checker
file & folder Permissions checker
template interpreter(no php inside) pres interpreted file on ./tmp
user permissions user:group
check buffer overflow
maybe add namespace on secure lib
optimise for php7
go to php strict types !
language check force lower case
#00E000 add plugin mail
#E50000 add admin state, function and GUI
#00E000 change summons language function
#FF9B00 administrator log(connexions, error)
#FF9B00 plugins checker
#FF9B00 file & folder Permissions checker
#00E000 user permissions user:group
#00E000 maybe add namespace on secure lib, or prefix
#00E000 optimise for php7
#FF9B00 go to php strict types !
#00E000 Error page (404, ...)
-- RA --
language fr to fr-fr for more variety
correction by PSR standards
returnPage() accept accept the depth file
arrayMenuParser() add $root for depth file
-- For V1 --
#E50000 Clean git repos and clean commit, branch for dev and stable
#E50000 Restruct to fix MVC
#E50000 Profiling and opti
#E50000 Add licence on all files
-- RA --
#E50000 template interpreter
#FF9B00 menu category can be used like "page"
#00E000 add menu depth
#E50000 review config function and add json config file
#FF9B00 fix serveur url
#E50000 cmsGetGlobalData()
#FF9B00 fix menu url cat/cat...
#E50000 check if buffer overflow ps
#E50000 language check, force lower case, compare to supported language, supported language config ...
#E50000 Change _COOKIE to _SESSION (oups ...)
#E50000 Fix $idTime on libSecure
Loading…
Cancel
Save