From 4b77c534cc0157061350c02bce0c9d2420357760 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20Hord=C3=A9?= Date: Sat, 2 Jan 2021 19:58:35 +0100 Subject: [PATCH] feat: translation is operationnal. History files are OK --- css/style.css | 35 +++++++++++++++++++++ hosts/localhost/config.php | 2 +- hosts/localhost/content/dependencies.md | 11 +++++-- hosts/localhost/content/features.md | 1 + hosts/localhost/content/index.md | 2 +- hosts/localhost/content/usage.md | 2 +- index.php | 22 ++++++++----- js/functions.js | 37 +++++++++++++++++++++- js/functionsadmin.js | 41 ++++++++++++++++++++++--- js/magnifik.js | 1 + js/toc.bundle.js | 1 + lang/en.json | 26 ++++++++++++++++ lang/en.php | 24 --------------- lang/fr.json | 26 ++++++++++++++++ lang/fr.php | 15 --------- lib/functions.php | 21 ++++++++----- readme.md | 2 +- 17 files changed, 204 insertions(+), 65 deletions(-) create mode 100644 js/magnifik.js create mode 100644 js/toc.bundle.js create mode 100644 lang/en.json delete mode 100644 lang/en.php create mode 100644 lang/fr.json delete mode 100644 lang/fr.php diff --git a/css/style.css b/css/style.css index 6188b0c..7ff37ec 100644 --- a/css/style.css +++ b/css/style.css @@ -78,6 +78,38 @@ body { } } +.toc +{ + margin-top: 56px; + left:auto; + background: #eee; + width: 20%; + border: 1px solid #ddd; + color: #333; +} +.toc > ul +{ + list-style-type: none; + margin: 8px; + padding: 0px; +} +.toc a { + color: #333; +} +.toc .toc-h3 { + margin-left: 10px +} +.toc .toc-h4 { + margin-left: 20px +} +.toc-active { + color: #000; + font-weight: bold; +} +.toc.right { + right: 0 +} + blockquote { font-style: normal; @@ -197,9 +229,12 @@ flex-wrap: wrap; .alert { display: none; position: fixed; + font-weight: bold; + font-size: 1.5rem; top: 10px; right: 10px; cursor: pointer; + z-index: 1500000; } .imagepreview img diff --git a/hosts/localhost/config.php b/hosts/localhost/config.php index b9a1112..a9159fd 100644 --- a/hosts/localhost/config.php +++ b/hosts/localhost/config.php @@ -8,7 +8,7 @@ define('ALLOWED_EXT','jpg,svg,gif,png,c,tgz,tar.gz,gz,tar,sql,ico'); define('PASSWORD', 'c7ad44cbad762a5da0a452f9e854fdc1e0e7a52a38015f23f3eab1d80b931dd472634dfac71cd34ebc35d16ab7fb8a90c81f975113d6c7538dc69dd8de9077ec'); define('LOG_FILE', 'log.txt'); define('ACCESS_IP', ''); -define('HISTORY_FILE', 'history.txt'); +define('HISTORY_FILE', 'history'); define('MAX_HISTORY_FILES', 5); define('LANGUAGE', 'en'); \ No newline at end of file diff --git a/hosts/localhost/content/dependencies.md b/hosts/localhost/content/dependencies.md index 1ee73ca..4fcaee8 100644 --- a/hosts/localhost/content/dependencies.md +++ b/hosts/localhost/content/dependencies.md @@ -25,14 +25,21 @@ * https://github.com/PrismLibrary/Prism +## Table of Contents + + * https://github.com/jgallen23/toc + ## Icons * https://github.com/FortAwesome/Font-Awesome +## Interface + * https://github.com/mobify/magnifik + * https://github.com/codepo8/css-fork-on-github-ribbon + ## Essential * https://github.com/twbs/bootstrap * https://github.com/jquery/jquery * https://github.com/popperjs/popper-core - * https://github.com/zenorocha/clipboard.js - * https://github.com/codepo8/css-fork-on-github-ribbon \ No newline at end of file + * https://github.com/zenorocha/clipboard.js \ No newline at end of file diff --git a/hosts/localhost/content/features.md b/hosts/localhost/content/features.md index f16b4d7..5b18729 100644 --- a/hosts/localhost/content/features.md +++ b/hosts/localhost/content/features.md @@ -9,6 +9,7 @@ 3. Integrated Image viewer 4. Restricted access by ip address 5. Admin access logging +6. Table of contents ## Planned diff --git a/hosts/localhost/content/index.md b/hosts/localhost/content/index.md index 55d3103..2c818cd 100644 --- a/hosts/localhost/content/index.md +++ b/hosts/localhost/content/index.md @@ -7,7 +7,7 @@ This website is heavily formated with markdown format ! __ __ _ _____ | \/ | | | | __ \ | \ / | __ _ _ __| | _| | | | ___ ___ - | |\/| |/ _` | \'__| |/ / | | |/ _ \ / __| + | |\/| |/ _` | '__| |/ / | | |/ _ \ / __| | | | | (_| | | | <| |__| | (_) | (__ |_| |_|\__,_|_| |_|\_\_____/ \___/ \___| ``` diff --git a/hosts/localhost/content/usage.md b/hosts/localhost/content/usage.md index 726b0b6..3e1641b 100644 --- a/hosts/localhost/content/usage.md +++ b/hosts/localhost/content/usage.md @@ -17,7 +17,7 @@ unzip v6.0.0.zip mv emoji-data-v6.0.0 emoji-data ``` -## Configuration +## Multiples hosts There is a sample website in the "[website_root]/hosts/locahost" directory. It's easy to add a new one, you create one subfolder by name served by your webserver. diff --git a/index.php b/index.php index 6cd9564..b064527 100644 --- a/index.php +++ b/index.php @@ -24,12 +24,16 @@ include LIB_DIR."/ParsedownExtra.php"; include LIB_DIR."/ParsedownExtraPlus.php"; include LIB_DIR."/functions.php"; +### Translations +loadlang(LANGUAGE); +global $LANG; + ### Security testip(); logprotect(); ### Sessions -session_name($_SERVER['SERVER_NAME']); +session_name(markdoc); session_start(); /*var_dump($_POST); @@ -57,17 +61,17 @@ else if (isset($_POST['action'])) } else { - $content = '

Mot de passe incorrect.

'; - $log = file_exists(LOG_FILE) ? unserialize(file_get_contents(LOG_FILE)) : array(); + $content = '

'.$LANG['BADPASS'].'

'; + $log = file_exists(LOG_DIR) ? unserialize(file_get_contents(LOG_DIR)) : array(); if (isset($log[$_SERVER['REMOTE_ADDR']]) === false) { $log[$_SERVER['REMOTE_ADDR']] = array('num' => 0, 'time' => 0); } $log[$_SERVER['REMOTE_ADDR']]['num'] += 1; $log[$_SERVER['REMOTE_ADDR']]['time'] = time(); - file_put_contents(LOG_FILE, serialize($log)); + file_put_contents(LOG_DIR, serialize($log)); } - } + } else $content='

Aucun mot de passe renseigné !

'; } @@ -181,15 +185,16 @@ print(($_SESSION['md_admin'] == true)?'
  • ").addClass(l.itemClass(n,i,f,l.prefix)).append(u);o.append(d)}),e.html(o)})},jQuery.fn.toc.defaults={container:"body",listType:"
      ",selectors:"h1,h2,h3",smoothScrolling:function(e,o,r){t(e).smoothScroller({offset:o.scrollToOffset}).on("smoothScrollerComplete",function(){r()})},scrollToOffset:0,prefix:"toc",activeClass:"toc-active",onHighlight:function(){},highlightOnScroll:!0,highlightOffset:100,anchorName:function(o,r,l){if(r.id.length)return r.id;var n=t(r).text().replace(/[^a-z0-9]/gi," ").replace(/\s+/g,"-").toLowerCase();if(e[n]){for(var i=2;e[n+i];)i++;n=n+"-"+i}return e[n]=!0,l+"-"+n},headerText:function(t,e,o){return o.text()},itemClass:function(t,e,o,r){return r+"-"+o[0].tagName.toLowerCase()}}}(jQuery); \ No newline at end of file diff --git a/lang/en.json b/lang/en.json new file mode 100644 index 0000000..83bef6f --- /dev/null +++ b/lang/en.json @@ -0,0 +1,26 @@ +{ + "MENU": "Menu", + "HOME" : "Home", + "GLOSSARY" : "Glossary", + "MARKDOC" : "About MarKdoc", + "ADMIN" : "Admin", + "ABOUT" : "About...", + "SEARCH" : "Search", + "VIEW" : "View", + "SAVE" : "Save", + "LOGIN" : "Login", + "NOPASS" : "No password is given !", + "ALREADYLOG" : "You're already connected !", + "BADPASS" : "The password is incorrect !", + "FOUND" : "

      Search results

      There is %s results :

      ", + "404" : "Error 404: file not found !", + "404X2" : "Error 404 on searching customized 404 error file !", + "CONFIG" : "Configuration", + "PASSWORD" : "Admin password", + "LOGOUT" : "Logout", + "LOADING" : "Loading...", + "AJAXERROR" : "Ajax error when loading data !", + "SELECTERROR" : "Error when selecting item.", + "NOTCODED" : "Fonction is not yet implemented.", + "BLOCKIP" : "This IP address is blocked due to unsuccessful login attempts." +} \ No newline at end of file diff --git a/lang/en.php b/lang/en.php deleted file mode 100644 index 7c97cda..0000000 --- a/lang/en.php +++ /dev/null @@ -1,24 +0,0 @@ -

      There is %s results :'; -$lang['404'] ='Error 404: file not found !'; -$lang['404X2'] ='Error 404 on searching customized 404 error file !'; -$lang['CONFIG'] ='Configuration'; -$lang['PASSWORD'] ='Admin password'; -$lang['LOGOUT'] ='Logout'; -$lang['LOADING'] ='Loading...'; -$lang['AJAXERROR'] ='Ajax error when loading data !'; -$lang['SELECTERROR']='Error when selecting item.' -$lang['NOTCODED'] ='Fonction is not yet implemented.' \ No newline at end of file diff --git a/lang/fr.json b/lang/fr.json new file mode 100644 index 0000000..f334692 --- /dev/null +++ b/lang/fr.json @@ -0,0 +1,26 @@ +{ + "MENU": "Menu", + "HOME" : "Accueil", + "GLOSSARY" : "Glossaire", + "MARKDOC" : "A propos de MarKdoc", + "ADMIN" : "Admin", + "ABOUT" : "A propos", + "SEARCH" : "Rechercher", + "VIEW" : "Voir", + "SAVE" : "Sauver", + "LOGIN" : "Se connecter", + "NOPASS" : "Aucun mot de passe n'a été saisi !", + "ALREADYLOG" : "Vous êtes déjà connecté !", + "BADPASS" : "Le mot de passe est incorrect !", + "FOUND" : "

      Résultats de recherche

      Il y a %s occurence(s) trouvée(s):

      ", + "404" : "Erreur 404: fichier non trouvé !", + "404X2" : "Erreur 404 sur fichier 404 personnalisé !", + "CONFIG" : "Configuration", + "PASSWORD" : "Mot de passe", + "LOGOUT" : "Se déconnecter", + "LOADING" : "Chargement...", + "AJAXERROR" : "Erreur ajax durant chargement !", + "SELECTERROR" : "Erreur de selection.", + "NOTCODED" : "La fonction n'est pas implementée.", + "BLOCKIP" : "Cette adresse IP est bloquée à cause de trop de tentatives de connexion non réussies." +} diff --git a/lang/fr.php b/lang/fr.php deleted file mode 100644 index 5aeb765..0000000 --- a/lang/fr.php +++ /dev/null @@ -1,15 +0,0 @@ -

      Il y a %s occurence(s) trouvée(s):' \ No newline at end of file diff --git a/lib/functions.php b/lib/functions.php index 394dd4b..640f8dd 100644 --- a/lib/functions.php +++ b/lib/functions.php @@ -178,15 +178,21 @@ function searchstr($path, $string){ return array('files' => $files, 'totalFiles' => $totalFiles); } +function loadlang($language) +{ + global $LANG; + $LANG=json_decode(file_get_contents(ROOT_DIR."lang/".$language.".json"),true); +} + function history($file) { if (is_numeric(MAX_HISTORY_FILES) && MAX_HISTORY_FILES > 0) { - $file_dir = dirname($file); + $file_dir = str_replace(CONTENT_DIR,"",dirname($file)."/"); $file_name = basename($file); - $file_history_dir = HISTORY_DIR . '/' . str_replace(MAIN_DIR, '', $file_dir); + $file_history_dir = HISTORY_DIR . $file_dir; foreach ([HISTORY_DIR, $file_history_dir] as $dir) { if (file_exists($dir) === false || is_dir($dir) === false) { - mkdir($dir); + mkdir($dir,0755,true); } } $history_files = scandir($file_history_dir); @@ -199,14 +205,15 @@ function history($file) if (count($history_files) >= MAX_HISTORY_FILES) { foreach ($history_files as $key => $history_file) { if ($key < 1) { - unlink($file_history_dir . DS . $history_file); + unlink($file_history_dir . '/' . $history_file); unset($history_files[$key]); } else { - rename($file_history_dir . DS . $history_file, $file_history_dir . DS . $file_name . '.' . ($key - 1)); + $newfile_name=pathinfo(basename($history_file))['filename']; + rename($file_history_dir . '/' . $history_file, $file_history_dir . '/' . $newfile_name . '.' . ($key - 1)); } } } - copy($file, $file_history_dir . DS . $file_name . '.' . count($history_files)); + copy($file, $file_history_dir . '/' . $file_name . '.' . count($history_files)); } } @@ -222,7 +229,7 @@ function setcontent($url,$data) else if (is_writable($file)) { file_put_contents($file, $data); - //history($file); + history($file); $content='success|Fichier enregistré.'; } else if (!is_writable($file)) diff --git a/readme.md b/readme.md index 55d3103..2c818cd 100644 --- a/readme.md +++ b/readme.md @@ -7,7 +7,7 @@ This website is heavily formated with markdown format ! __ __ _ _____ | \/ | | | | __ \ | \ / | __ _ _ __| | _| | | | ___ ___ - | |\/| |/ _` | \'__| |/ / | | |/ _ \ / __| + | |\/| |/ _` | '__| |/ / | | |/ _ \ / __| | | | | (_| | | | <| |__| | (_) | (__ |_| |_|\__,_|_| |_|\_\_____/ \___/ \___| ```