]> 91.132.146.200 Git - scientia.git/commitdiff
more cleanups
authorBanana <mail@bananas-playground.net>
Sun, 2 Jun 2024 08:26:38 +0000 (10:26 +0200)
committerBanana <mail@bananas-playground.net>
Sun, 2 Jun 2024 08:26:38 +0000 (10:26 +0200)
Signed-off-by: Banana <mail@bananas-playground.net>
17 files changed:
documentation/requirements.md
documentation/upgrade-from-1.0.md [new file with mode: 0644]
documentation/upgrade-from-1.0.txt [deleted file]
webroot/api.php
webroot/config/config.php.default
webroot/index.php
webroot/lib/entry.class.php
webroot/lib/i18n.class.php
webroot/lib/i18n/de.ini
webroot/lib/i18n/en.ini
webroot/lib/summoner.class.php
webroot/view/_foot.php
webroot/view/_head.php
webroot/view/entry/entry.html
webroot/view/entry/entry.php
webroot/view/list/list.html
webroot/view/list/list.php

index b39e34260594ae7f157a3ea9ee707a075eb1a608..acd720c5dc547dbfd721b51c9a67e32f74440253 100644 (file)
@@ -1,5 +1,5 @@
 # Requirements
 
 + A Webserver (tested on Apache 2.4)
-+ PHP 8+ with mysqli, mbstring, curl
++ PHP 8.1+ with mysqli, mbstring, curl
 + MySQL 8+ / MariaDB 10.2
diff --git a/documentation/upgrade-from-1.0.md b/documentation/upgrade-from-1.0.md
new file mode 100644 (file)
index 0000000..3a9fa07
--- /dev/null
@@ -0,0 +1,21 @@
+# Config changes
+
+Update your existing `config.php` file with the following changes.
+Missing those changes, errors will happen.
+
+# i18n
+New config for i18n. Open config.php and add the following:
+```
+# language settings
+const FRONTEND_LANGUAGE = 'en';
+```
+currently only en (default) and de are available.
+
+#  Installation URL
+
+To provide the correct URL please add this.
+
+```
+# Installation Domain. Webrootpath will be added automatically
+const INSTALL_URL = 'http://localhost';
+```
diff --git a/documentation/upgrade-from-1.0.txt b/documentation/upgrade-from-1.0.txt
deleted file mode 100644 (file)
index 5b5b9d4..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-New config for i18n. Open config.php and add the following:
-
-# language settings
-const FRONTEND_LANGUAGE = 'en';
-
-currently only en (default) and de are available.
index 2791c290ce756c965282c74f3de976beabc3bcf6..062e51c99dfad67c7c785eeb22b85a1ac817a968 100644 (file)
@@ -2,7 +2,7 @@
 /**
  * scientia
  *
- * Copyright 2023 Johannes Keßler
+ * Copyright 2023 - 2024 Johannes Keßler
  *
  * https://www.bananas-playground.net/projekt/scientia/
  *
@@ -22,10 +22,10 @@ ini_set('error_reporting',-1); // E_ALL & E_STRICT
 ## check request
 $_urlToParse = filter_var($_SERVER['QUERY_STRING'],FILTER_UNSAFE_RAW, FILTER_FLAG_STRIP_LOW);
 if(!empty($_urlToParse)) {
-       # see http://de2.php.net/manual/en/regexp.reference.unicode.php
-       if(preg_match('/[\p{C}\p{M}\p{Sc}\p{Sk}\p{So}\p{Zl}\p{Zp}]/u',$_urlToParse) === 1) {
-               die('Malformed request. Make sure you know what you are doing.');
-       }
+    # see http://de2.php.net/manual/en/regexp.reference.unicode.php
+    if(preg_match('/[\p{C}\p{M}\p{Sc}\p{Sk}\p{So}\p{Zl}\p{Zp}]/u',$_urlToParse) === 1) {
+        die('Malformed request. Make sure you know what you are doing.');
+    }
 }
 
 ## config
@@ -53,21 +53,21 @@ if(DEBUG) error_log("Dump SERVER ".var_export($_SERVER,true));
 $_create = false;
 $filteredData = '';
 if ($_SERVER['REQUEST_METHOD'] === 'POST' && $_SERVER['CONTENT_TYPE'] === 'application/json; charset=UTF-8') {
-       $payload = json_decode(file_get_contents('php://input'), true);
-       if(DEBUG) error_log("[DEBUG] Dump payload ".var_export($payload,true));
-       if(!empty($payload)) {
-               if(isset($payload['asl']) && !empty($payload['asl'])
-                       && isset($payload['data']) && !empty($payload['data'])
-                       && isset(UPLOAD_SECRET[$payload['asl']])
-               ) {
-                       if(DEBUG) error_log("[DEBUG] Valid payload so far");
-                       $filteredData = filter_var($payload['data'],FILTER_SANITIZE_FULL_SPECIAL_CHARS);
-                       if(!empty($filteredData)) {
-                               if(DEBUG) error_log("[DEBUG] Validated payload");
-                               $_create = true;
-                       }
-               }
-       }
+    $payload = json_decode(file_get_contents('php://input'), true);
+    if(DEBUG) error_log("[DEBUG] Dump payload ".var_export($payload,true));
+    if(!empty($payload)) {
+        if(isset($payload['asl']) && !empty($payload['asl'])
+            && isset($payload['data']) && !empty($payload['data'])
+            && isset(UPLOAD_SECRET[$payload['asl']])
+        ) {
+            if(DEBUG) error_log("[DEBUG] Valid payload so far");
+            $filteredData = filter_var($payload['data'],FILTER_SANITIZE_FULL_SPECIAL_CHARS);
+            if(!empty($filteredData)) {
+                if(DEBUG) error_log("[DEBUG] Validated payload");
+                $_create = true;
+            }
+        }
+    }
 }
 
 ## default response
@@ -99,13 +99,13 @@ require_once 'lib/entry.class.php';
 $Entry = new Entry($DB);
 $do = $Entry->create($filteredData);
 if(!empty($do)) {
-       $contentBody['message'] = INSTALL_URL . PATH_WEBROOT . date('/Y/m/d/').$do;
+    $contentBody['message'] = INSTALL_URL . PATH_WEBROOT . date('/Y/m/d/').$do;
 }
 else {
-       $hash = md5($do.time());
-       error_log("[ERROR] $hash Can not create. ". var_export($do,true));
-       $contentBody['message'] = "Something went wrong. $hash";
-       $contentBody['status'] = 500;
+    $hash = md5($do.time());
+    error_log("[ERROR] $hash Can not create. ". var_export($do,true));
+    $contentBody['message'] = "Something went wrong. $hash";
+    $contentBody['status'] = 500;
 }
 
 # return
index cb416a31cb28f68667db21d1c94fe63c593efe8a..791186580d0898e09a878a6e32c55d49631d4bb5 100644 (file)
@@ -2,7 +2,7 @@
 /**
  * scientia
  *
- * Copyright 2022 Johannes Keßler
+ * Copyright 2022 - 2024 Johannes Keßler
  *
  * https://www.bananas-playground.net/projekt/scientia/
  *
index 97d81eb47cd22a18702f42e876e1839eaad1e5a1..4de0689c9c2a01d1588c5ec6a57a3a9b1de813a6 100644 (file)
@@ -2,7 +2,7 @@
 /**
  * scientia
  *
- * Copyright 2023 Johannes Keßler
+ * Copyright 2023 - 2024 Johannes Keßler
  *
  * https://www.bananas-playground.net/projekt/scientia/
  *
@@ -22,10 +22,10 @@ ini_set('error_reporting',-1); // E_ALL & E_STRICT
 ## check request
 $_urlToParse = filter_var($_SERVER['QUERY_STRING'],FILTER_UNSAFE_RAW, FILTER_FLAG_STRIP_LOW);
 if(!empty($_urlToParse)) {
-       # see http://de2.php.net/manual/en/regexp.reference.unicode.php
-       if(preg_match('/[\p{C}\p{M}\p{Sc}\p{Sk}\p{So}\p{Zl}\p{Zp}]/u',$_urlToParse) === 1) {
-               die('Malformed request. Make sure you know what you are doing.');
-       }
+    # see http://de2.php.net/manual/en/regexp.reference.unicode.php
+    if(preg_match('/[\p{C}\p{M}\p{Sc}\p{Sk}\p{So}\p{Zl}\p{Zp}]/u',$_urlToParse) === 1) {
+        die('Malformed request. Make sure you know what you are doing.');
+    }
 }
 
 ## config
@@ -35,10 +35,10 @@ require_once('config/config.php');
 ini_set('log_errors',true);
 ini_set('error_log',PATH_SYSTEMOUT.'/error.log');
 if(DEBUG === true) {
-       ini_set('display_errors',true);
+    ini_set('display_errors',true);
 }
 else {
-       ini_set('display_errors',false);
+    ini_set('display_errors',false);
 }
 
 # time settings
@@ -71,23 +71,23 @@ $_requestDateProvided = '';
 $TemplateData = array();
 
 if(isset($_GET['y']) && Summoner::validate($_GET['y'], 'digit')) {
-       $_year = trim($_GET['y']);
-       $_requestDateProvided .= 'Y';
+    $_year = trim($_GET['y']);
+    $_requestDateProvided .= 'Y';
 }
 if(isset($_GET['m']) && Summoner::validate($_GET['m'], 'digit')) {
-       $_month = trim($_GET['m']);
-       $_requestDateProvided .= '-m';
+    $_month = trim($_GET['m']);
+    $_requestDateProvided .= '-m';
 }
 if(isset($_GET['d']) && Summoner::validate($_GET['d'], 'digit')) {
-       $_day = trim($_GET['d']);
-       $_requestDateProvided .= '-d';
+    $_day = trim($_GET['d']);
+    $_requestDateProvided .= '-d';
 }
 if(isset($_GET['p']) && Summoner::validate($_GET['p'], 'nospace') && $_GET['p'] == "new") {
-       $_view = 'entry';
+    $_view = 'entry';
 }
 if(isset($_GET['id']) && Summoner::validate($_GET['id'], 'shortlink',4)) {
-       $_id = trim($_GET['id']);
-       $_view = 'entry';
+    $_id = trim($_GET['id']);
+    $_view = 'entry';
 }
 
 require_once 'view/'.$_view.'/'.$_view.'.php';
@@ -98,8 +98,8 @@ header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
 header("Cache-Control: post-check=0, pre-check=0", false);
 header("Pragma: no-cache");
 if(isset($TemplateData['refresh']) && !empty($TemplateData['refresh'])) {
-       header('Location: '.PATH_WEBROOT.$TemplateData['refresh']);
-       exit();
+    header('Location: '.PATH_WEBROOT.$TemplateData['refresh']);
+    exit();
 }
 
 require_once 'view/_head.php';
index 629a9e396110c2fff447cd173f76001242681bed..bbf236dc5af0e2d50a2cc394f0b38cce05b68b6c 100644 (file)
@@ -2,7 +2,7 @@
 /**
  * scientia
  *
- * Copyright 2022 Johannes Keßler
+ * Copyright 2022 - 2024 Johannes Keßler
  *
  * https://www.bananas-playground.net/projekt/scientia/
  *
  * Entry loading and creation
  */
 class Entry {
-       /**
-        * the global DB object
-        *
-        * @var mysqli
-        */
-       private mysqli $_DB;
-
-       /**
-        * Entry constructor.
-        *
-        * @param mysqli $db
-        */
-       public function __construct(mysqli $db) {
-               $this->_DB = $db;
-       }
-
-       /**
-        * Create a new entry with given data
-        * Data is not validated anymore
-        *
-        * @param string $data
-        * @return string
-        */
-       public function create(string $data): string {
-               $ret = '';
-
-               $_words = implode(' ', $this->_words($data));
-               $_ident = Summoner::b64sl_pack_id(rand(111111, 999999));
-               $queryStr = "INSERT INTO `".DB_PREFIX."_entry` SET
-                                               `created` = NOW(),
-                                               `date` = CURRENT_DATE(),
-                                               `ident` = '".$this->_DB->real_escape_string($_ident)."',
-                                               `body` = '".$this->_DB->real_escape_string($data)."',
-                                               `words` = '".$this->_DB->real_escape_string($_words)."'";
-               if(QUERY_DEBUG) error_log("[QUERY] ".__METHOD__." query: ".var_export($queryStr,true));
-
-               try {
-                       $this->_DB->query($queryStr);
-                       $ret = $_ident;
-               }
-               catch(Exception $e) {
-                       error_log("[ERROR] ".__METHOD__." catch: ".$e->getMessage());
-               }
-
-               return $ret;
-       }
-
-       /**
-        * Load an entry by given $id. Use date info to make sure that the context is correct
-        *
-        * @param string $y Year Y
-        * @param string $m Month m
-        * @param string $d Day d
-        * @param string $id Id of the entry
-        * @return array
-        */
-       public function load(string $y, string $m, string $d, string $id): array {
-               $ret = array();
-
-               if(!empty($id) && !empty($y) && !empty($m) && !empty($d)) {
-                       $queryStr = "SELECT `created`,`modified`,`body`
-                                                       FROM `".DB_PREFIX."_entry`
-                                                       WHERE `ident` = '".$this->_DB->real_escape_string($id)."'
-                                                               AND `date` = '".$this->_DB->real_escape_string($y.'-'.$m.'-'.$d)."'";
-                       if(QUERY_DEBUG) error_log("[QUERY] ".__METHOD__." query: ".var_export($queryStr,true));
-                       try {
-                               $query = $this->_DB->query($queryStr);
-                               if($query !== false && $query->num_rows > 0) {
-                                       $ret = $query->fetch_assoc();
-                               }
-                       }
-                       catch(Exception $e) {
-                               error_log("[ERROR] ".__METHOD__." catch: ".$e->getMessage());
-                       }
-               }
-
-               return $ret;
-       }
-
-       /**
-        * Update an entry by given $id and $data
-        *
-        * @param string $data
-        * @param string $id
-        * @return string
-        */
-       public function update(string $data, string $id): string {
-               $ret = '';
-
-               if(!empty($data) && !empty($id)) {
-                       $_words = implode(' ', $this->_words($data));
-                       $queryStr = "UPDATE `".DB_PREFIX."_entry` SET                                           
-                                                       `body` = '".$this->_DB->real_escape_string($data)."',
-                                                       `words` = '".$this->_DB->real_escape_string($_words)."'
-                                                       WHERE `ident` = '".$this->_DB->real_escape_string($id)."'";
-                       if(QUERY_DEBUG) error_log("[QUERY] ".__METHOD__." query: ".var_export($queryStr,true));
-                       try {
-                               $this->_DB->query($queryStr);
-                               $ret = $id;
-                       }
-                       catch(Exception $e) {
-                               error_log("[ERROR] ".__METHOD__." catch: ".$e->getMessage());
-                       }
-               }
-
-               return $ret;
-       }
-
-       /**
-        * Delete given id from _entry table
-        *
-        * @param string $id
-        * @return bool
-        */
-       public function delete(string $id): bool {
-               $ret = false;
-
-               if(!empty($id)) {
-                       $queryStr = "DELETE FROM `".DB_PREFIX."_entry`
-                                                       WHERE `ident` = '".$this->_DB->real_escape_string($id)."'";
-                       if(QUERY_DEBUG) error_log("[QUERY] ".__METHOD__." query: ".var_export($queryStr,true));
-                       try {
-                               $this->_DB->query($queryStr);
-                               $ret = true;
-                       }
-                       catch(Exception $e) {
-                               error_log("[ERROR] ".__METHOD__." catch: ".$e->getMessage());
-                       }
-               }
-
-               return $ret;
-       }
-
-       /**
-        * Create unique words from the given data
-        *
-        * @param $data string
-        * @return array
-        * @todo ignores
-        *
-        */
-       private function _words(string $data): array {
-               preg_match_all('/\w{3,}+/u',$data,$matches);
-               return array_unique($matches[0]);
-       }
+    /**
+     * the global DB object
+     *
+     * @var mysqli
+     */
+    private mysqli $_DB;
+
+    /**
+     * Entry constructor.
+     *
+     * @param mysqli $db
+     */
+    public function __construct(mysqli $db) {
+        $this->_DB = $db;
+    }
+
+    /**
+     * Create a new entry with given data
+     * Data is not validated anymore
+     *
+     * @param string $data
+     * @return string
+     */
+    public function create(string $data): string {
+        $ret = '';
+
+        $_words = implode(' ', $this->_words($data));
+        $_ident = Summoner::b64sl_pack_id(rand(111111, 999999));
+        $queryStr = "INSERT INTO `".DB_PREFIX."_entry` SET
+                        `created` = NOW(),
+                        `date` = CURRENT_DATE(),
+                        `ident` = '".$this->_DB->real_escape_string($_ident)."',
+                        `body` = '".$this->_DB->real_escape_string($data)."',
+                        `words` = '".$this->_DB->real_escape_string($_words)."'";
+        if(QUERY_DEBUG) error_log("[QUERY] ".__METHOD__." query: ".var_export($queryStr,true));
+
+        try {
+            $this->_DB->query($queryStr);
+            $ret = $_ident;
+        }
+        catch(Exception $e) {
+            error_log("[ERROR] ".__METHOD__." catch: ".$e->getMessage());
+        }
+
+        return $ret;
+    }
+
+    /**
+     * Load an entry by given $id. Use date info to make sure that the context is correct
+     *
+     * @param string $y Year Y
+     * @param string $m Month m
+     * @param string $d Day d
+     * @param string $id Id of the entry
+     * @return array
+     */
+    public function load(string $y, string $m, string $d, string $id): array {
+        $ret = array();
+
+        if(!empty($id) && !empty($y) && !empty($m) && !empty($d)) {
+            $queryStr = "SELECT `created`,`modified`,`body`
+                            FROM `".DB_PREFIX."_entry`
+                            WHERE `ident` = '".$this->_DB->real_escape_string($id)."'
+                                AND `date` = '".$this->_DB->real_escape_string($y.'-'.$m.'-'.$d)."'";
+            if(QUERY_DEBUG) error_log("[QUERY] ".__METHOD__." query: ".var_export($queryStr,true));
+            try {
+                $query = $this->_DB->query($queryStr);
+                if($query !== false && $query->num_rows > 0) {
+                    $ret = $query->fetch_assoc();
+                }
+            }
+            catch(Exception $e) {
+                error_log("[ERROR] ".__METHOD__." catch: ".$e->getMessage());
+            }
+        }
+
+        return $ret;
+    }
+
+    /**
+     * Update an entry by given $id and $data
+     *
+     * @param string $data
+     * @param string $id
+     * @return string
+     */
+    public function update(string $data, string $id): string {
+        $ret = '';
+
+        if(!empty($data) && !empty($id)) {
+            $_words = implode(' ', $this->_words($data));
+            $queryStr = "UPDATE `".DB_PREFIX."_entry` SET                                              
+                            `body` = '".$this->_DB->real_escape_string($data)."',
+                            `words` = '".$this->_DB->real_escape_string($_words)."'
+                            WHERE `ident` = '".$this->_DB->real_escape_string($id)."'";
+            if(QUERY_DEBUG) error_log("[QUERY] ".__METHOD__." query: ".var_export($queryStr,true));
+            try {
+                $this->_DB->query($queryStr);
+                $ret = $id;
+            }
+            catch(Exception $e) {
+                error_log("[ERROR] ".__METHOD__." catch: ".$e->getMessage());
+            }
+        }
+
+        return $ret;
+    }
+
+    /**
+     * Delete given id from _entry table
+     *
+     * @param string $id
+     * @return bool
+     */
+    public function delete(string $id): bool {
+        $ret = false;
+
+        if(!empty($id)) {
+            $queryStr = "DELETE FROM `".DB_PREFIX."_entry`
+                            WHERE `ident` = '".$this->_DB->real_escape_string($id)."'";
+            if(QUERY_DEBUG) error_log("[QUERY] ".__METHOD__." query: ".var_export($queryStr,true));
+            try {
+                $this->_DB->query($queryStr);
+                $ret = true;
+            }
+            catch(Exception $e) {
+                error_log("[ERROR] ".__METHOD__." catch: ".$e->getMessage());
+            }
+        }
+
+        return $ret;
+    }
+
+    /**
+     * Create unique words from the given data
+     *
+     * @param $data string
+     * @return array
+     * @todo ignores
+     *
+     */
+    private function _words(string $data): array {
+        preg_match_all('/\w{3,}+/u',$data,$matches);
+        return array_unique($matches[0]);
+    }
 }
index a7c63e3344d6c73b89354e9053340c42dd061f49..26788985d73a333217fc7ba86423febffd137d25 100644 (file)
@@ -2,7 +2,7 @@
 /**
  * scientia
  *
- * Copyright 2023 Johannes Keßler
+ * Copyright 2023 - 2024 Johannes Keßler
  *
  * https://www.bananas-playground.net/projekt/scientia/
  *
  */
 
 class I18n {
-       /**
-        * @var string The lang code
-        */
-       private string $_defaultLangToUse = 'en';
+    /**
+     * @var string The lang code
+     */
+    private string $_defaultLangToUse = 'en';
 
-       /**
-        * @var array The loaded lang information from the file
-        */
-       private array $_langData = array();
+    /**
+     * @var array The loaded lang information from the file
+     */
+    private array $_langData = array();
 
-       /**
-        * i18n constructor.
-        */
-       public function __construct() {
-               $_langFile = PATH_ABSOLUTE.'/lib/i18n/'.$this->_defaultLangToUse.'.ini';
-               if(defined('FRONTEND_LANGUAGE')) {
-                       $_langFile = PATH_ABSOLUTE.'/lib/i18n/'.FRONTEND_LANGUAGE.'.ini';
-                       if(file_exists($_langFile)) {
-                               $_langData = parse_ini_file($_langFile);
-                               if($_langData !== false) {
-                                       $this->_langData = $_langData;
-                               }
-                       }
-               }
-               else {
-                       $_langData = parse_ini_file($_langFile);
-                       if($_langData !== false) {
-                               $this->_langData = $_langData;
-                       }
-               }
-       }
+    /**
+     * i18n constructor.
+     */
+    public function __construct() {
+        $_langFile = PATH_ABSOLUTE.'/lib/i18n/'.$this->_defaultLangToUse.'.ini';
+        if(defined('FRONTEND_LANGUAGE')) {
+            $_langFile = PATH_ABSOLUTE.'/lib/i18n/'.FRONTEND_LANGUAGE.'.ini';
+            if(file_exists($_langFile)) {
+                $_langData = parse_ini_file($_langFile);
+                if($_langData !== false) {
+                    $this->_langData = $_langData;
+                }
+            }
+        }
+        else {
+            $_langData = parse_ini_file($_langFile);
+            if($_langData !== false) {
+                $this->_langData = $_langData;
+            }
+        }
+    }
 
-       /**
-        * Return text for given key for currently loaded lang
-        *
-        * @param string $key
-        * @return string
-        */
-       public function t(string $key): string {
-               $ret = $key;
-               if(isset($this->_langData[$key])) {
-                       $ret = $this->_langData[$key];
-               }
-               return $ret;
-       }
+    /**
+     * Return text for given key for currently loaded lang
+     *
+     * @param string $key
+     * @return string
+     */
+    public function t(string $key): string {
+        $ret = $key;
+        if(isset($this->_langData[$key])) {
+            $ret = $this->_langData[$key];
+        }
+        return $ret;
+    }
 }
index 5eeb16bfeee987c68683f6c8c381f0ef37d2d116..187aeb30db7a367f524117d7d9126393a1765865 100644 (file)
@@ -1,6 +1,6 @@
 ; scientia
 ;
-; Copyright 2022 Johannes Keßler
+; Copyright 2022 - 2024 Johannes Keßler
 ;
 ; https://www.bananas-playground.net/projekt/scientia/
 ;
@@ -18,4 +18,4 @@ form.checkbox.deleteentry=Eintrag löschen
 
 text.home=Index
 text.new=Neu
-text.noentries=Nichts vorhanden.
\ No newline at end of file
+text.noentries=Nichts vorhanden.
index 19677072b436d6b9a671300a387da001011cabd1..f56c741019a832d8e8e8f2794d75d70428747d9f 100644 (file)
@@ -1,6 +1,6 @@
 ; scientia
 ;
-; Copyright 2022 Johannes Keßler
+; Copyright 2022 - 2024 Johannes Keßler
 ;
 ; https://www.bananas-playground.net/projekt/scientia/
 ;
@@ -19,4 +19,3 @@ form.checkbox.deleteentry=Delete Entry
 text.home=Home
 text.new=New
 text.noentries=Nothing here.
-
index 4ee5b8748757d1191a000fa0a4ebb3ca10e7c9f0..d05407a8182e30b0b38a9146b30260b027c37dde 100644 (file)
@@ -2,7 +2,7 @@
 /**
  * scientia
  *
- * Copyright 2023 Johannes Keßler
+ * Copyright 2023 - 2024 Johannes Keßler
  *
  * https://www.bananas-playground.net/projekt/scientia/
  *
  * A static helper class
  */
 class Summoner {
-       /**
-        * validate the given string with the given type. Optional check the string
-        * length
-        *
-        * @param string $input The string to check
-        * @param string $mode How the string should be checked
-        * @param string $limit If int given the string is checked for length
-        *
-        * @return bool
-        *
-        * @see http://de.php.net/manual/en/regexp.reference.unicode.php
-        * http://www.sql-und-xml.de/unicode-database/#pc
-        *
-        * the pattern replaces all that is allowed. the correct result after
-        * the replace should be empty, otherwise are there chars which are not
-        * allowed
-        */
+    /**
+     * validate the given string with the given type. Optional check the string
+     * length
+     *
+     * @param string $input The string to check
+     * @param string $mode How the string should be checked
+     * @param string $limit If int given the string is checked for length
+     *
+     * @return bool
+     *
+     * @see http://de.php.net/manual/en/regexp.reference.unicode.php
+     * http://www.sql-und-xml.de/unicode-database/#pc
+     *
+     * the pattern replaces all that is allowed. the correct result after
+     * the replace should be empty, otherwise are there chars which are not
+     * allowed
+     */
     static function validate(string $input, string $mode='text', string $limit=''): bool {
         // check if we have input
         $input = trim($input);
@@ -54,7 +54,7 @@ class Summoner {
                 else {
                     return false;
                 }
-                       break;
+            break;
 
             case 'url':
                 if(filter_var($input,FILTER_VALIDATE_URL) === $input) {
@@ -63,41 +63,41 @@ class Summoner {
                 else {
                     return false;
                 }
-                       break;
+            break;
 
             case 'nospace':
                 // text without any whitespace and special chars
                 $pattern = '/[\p{L}\p{N}]/u';
-                       break;
+            break;
 
             case 'nospaceP':
                 // text without any whitespace and special chars
                 // but with Punctuation other
                 # http://www.sql-und-xml.de/unicode-database/po.html
                 $pattern = '/[\p{L}\p{N}\p{Po}\-]/u';
-                       break;
+            break;
 
             case 'digit':
                 // only numbers and digit
                 // warning with negative numbers...
                 $pattern = '/[\p{N}\-]/';
-                       break;
+            break;
 
             case 'pageTitle':
                 // text with whitespace and without special chars
                 // but with Punctuation
                 $pattern = '/[\p{L}\p{N}\p{Po}\p{Z}\s-]/u';
-                       break;
+            break;
 
             # strange. the \p{M} is needed.. don't know why..
             case 'filename':
                 $pattern = '/[\p{L}\p{N}\p{M}\-_\.\p{Zs}]/u';
-                       break;
+            break;
 
-                       case 'shortlink':
-                               // special char string based on https://www.jwz.org/base64-shortlinks/
-                               $pattern = '/[\p{L}\p{N}\-_]/u';
-                       break;
+            case 'shortlink':
+                // special char string based on https://www.jwz.org/base64-shortlinks/
+                $pattern = '/[\p{L}\p{N}\-_]/u';
+            break;
 
             case 'text':
             default:
@@ -121,25 +121,25 @@ class Summoner {
         return $ret;
     }
 
-       /**
-        * check if a string starts with a given string
-        *
-        * @param string $haystack
-        * @param string $needle
-        * @return boolean
-        */
+    /**
+     * check if a string starts with a given string
+     *
+     * @param string $haystack
+     * @param string $needle
+     * @return boolean
+     */
     static function startsWith(string $haystack, string $needle): bool {
         $length = strlen($needle);
         return (substr($haystack, 0, $length) === $needle);
     }
 
-       /**
-        * check if a string ends with a given string
-        *
-        * @param string $haystack
-        * @param string $needle
-        * @return boolean
-        */
+    /**
+     * check if a string ends with a given string
+     *
+     * @param string $haystack
+     * @param string $needle
+     * @return boolean
+     */
     static function endsWith(string $haystack, string $needle): bool {
         $length = strlen($needle);
         if ($length == 0) {
@@ -150,13 +150,13 @@ class Summoner {
     }
 
 
-       /**
-        * create a short string based on a integer
-        *
-        * @see https://www.jwz.org/base64-shortlinks/
-        * @param int $id
-        * @return string
-        */
+    /**
+     * create a short string based on a integer
+     *
+     * @see https://www.jwz.org/base64-shortlinks/
+     * @param int $id
+     * @return string
+     */
     static function b64sl_pack_id(int $id): string {
         $id = intval($id);
         $ida = ($id > 0xFFFFFFFF ? $id >> 32 : 0);     // 32 bit big endian, top
@@ -170,13 +170,13 @@ class Summoner {
         return $id;
     }
 
-       /**
-        * Decode a base64-encoded big-endian integer of up to 64 bits.
-        *
-        * @see https://www.jwz.org/base64-shortlinks/
-        * @param string $id
-        * @return int
-        */
+    /**
+     * Decode a base64-encoded big-endian integer of up to 64 bits.
+     *
+     * @see https://www.jwz.org/base64-shortlinks/
+     * @param string $id
+     * @return int
+     */
     static function b64sl_unpack_id(string $id): int {
         $id = str_replace ('-', '+', $id);             // decode URL-unsafe "+" "/"
         $id = str_replace ('_', '/', $id);
@@ -187,33 +187,18 @@ class Summoner {
         return $id;
     }
 
-       /**
-        * simulate the Null coalescing operator in php5
-        *
-        * this only works with arrays and checking if the key is there and echo/return it.
-        *
-        * http://php.net/manual/en/migration70.new-features.php#migration70.new-features.null-coalesce-op
-        *
-        * @param $array array
-        * @param $key string
-        * @return mixed
-        */
-       static function ifset(array $array, string $key): mixed {
-               return isset($array[$key]) ? $array[$key] : false;
-       }
-
-       /**
-        * a very simple HTTP_AUTH authentication.
-        * Needs FRONTEND_USERNAME and FRONTEND_PASSWORD defined
-        */
-       static function simpleAuth(): void {
-               if (!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW'])
-                       || $_SERVER['PHP_AUTH_USER'] !== FRONTEND_USERNAME || $_SERVER['PHP_AUTH_PW'] !== FRONTEND_PASSWORD
-               ) {
-                       header('WWW-Authenticate: Basic realm="Protected area"');
-                       header('HTTP/1.0 401 Unauthorized');
-                       echo 'No Access.';
-                       exit;
-               }
-       }
+    /**
+     * a very simple HTTP_AUTH authentication.
+     * Needs FRONTEND_USERNAME and FRONTEND_PASSWORD defined
+     */
+    static function simpleAuth(): void {
+        if (!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW'])
+            || $_SERVER['PHP_AUTH_USER'] !== FRONTEND_USERNAME || $_SERVER['PHP_AUTH_PW'] !== FRONTEND_PASSWORD
+        ) {
+            header('WWW-Authenticate: Basic realm="Protected area"');
+            header('HTTP/1.0 401 Unauthorized');
+            echo 'No Access.';
+            exit;
+        }
+    }
 }
index 45716f31618ae161922d5208ae2540379cfc8929..dfd91ea0acdbb9349eb382e0559487f9ad5e0708 100644 (file)
@@ -1,5 +1,5 @@
-       <footer>
-               <small><a href="https://www.bananas-playground.net/projekt/scientia/" target=_blank>scientia</small>
-       </footer>
+    <footer>
+        <small><a href="https://www.bananas-playground.net/projekt/scientia/" target=_blank>scientia</small>
+    </footer>
 </body>
 </html>
index 918a5a4cd9cf44569303b2f70687d3addf0aeb93..de043654b95094d9771944ed124855aa9e9f66d1 100644 (file)
@@ -1,11 +1,11 @@
 <html lang="en">
 <head>
-       <meta charset="utf-8">
-       <link rel="stylesheet" href="<?php echo PATH_WEBROOT; ?>/view/water.css">
-       <style>
-               body {
-                       max-width: 90%;
-               }
-       </style>
+    <meta charset="utf-8">
+    <link rel="stylesheet" href="<?php echo PATH_WEBROOT; ?>/view/water.css">
+    <style>
+        body {
+            max-width: 90%;
+        }
+    </style>
 </head>
 <body>
index e8f5c9557b55f2b773c3a0d156f348f7d29a171d..23a3c0df1da8dd8b119328f544d743a69aff6027 100644 (file)
@@ -1,21 +1,21 @@
 <p>
-       <a href="<?php echo PATH_WEBROOT; ?>"><?php echo $i18n->t('text.home'); ?></a>
-       <?php if(!empty($TemplateData['data'])) {
-       echo ' | ';
-       $_link = '';
-       foreach($TemplateData['data']['breadcrumb'] as $be) {
-               $_link .= '/'.$be;
-               echo '<a href="'.PATH_WEBROOT.$_link.'">'.$be.'</a> | ';
-       }
-       ?>
-       <a href="<?php echo PATH_WEBROOT; ?>/new"><?php echo $i18n->t('text.new'); ?></a>
-       <?php } ?>
+    <a href="<?php echo PATH_WEBROOT; ?>"><?php echo $i18n->t('text.home'); ?></a>
+    <?php if(!empty($TemplateData['data'])) {
+    echo ' | ';
+    $_link = '';
+    foreach($TemplateData['data']['breadcrumb'] as $be) {
+        $_link .= '/'.$be;
+        echo '<a href="'.PATH_WEBROOT.$_link.'">'.$be.'</a> | ';
+    }
+    ?>
+    <a href="<?php echo PATH_WEBROOT; ?>/new"><?php echo $i18n->t('text.new'); ?></a>
+    <?php } ?>
 </p>
 <?php if(!empty($TemplateData['data'])) { ?>
-<p>Created: <?php echo Summoner::ifset($TemplateData['data'],'created'); ?>, Updated: <?php echo Summoner::ifset($TemplateData['data'],'modified'); ?></p>
+<p>Created: <?php echo $TemplateData['data']['created'] ?? ''; ?>, Updated: <?php echo $TemplateData['data']['modified'] ?? ''; ?></p>
 <?php } ?>
 <form method="post">
-       <textarea rows="25" placeholder="write here" name="fdata[entry]"><?php echo Summoner::ifset($TemplateData['data'],'body'); ?></textarea>
-       <input type="submit" name="submitForm" value="<?php echo $i18n->t('form.button.save'); ?>">
-       <input type="checkbox" name="deleteEntry" value="yes" /> <small style="color: indianred"><?php echo $i18n->t('form.checkbox.deleteentry'); ?></small>
+    <textarea rows="25" placeholder="write here" name="fdata[entry]"><?php echo $TemplateData['data']['body'] ?? ''; ?></textarea>
+    <input type="submit" name="submitForm" value="<?php echo $i18n->t('form.button.save'); ?>">
+    <input type="checkbox" name="deleteEntry" value="yes" /> <small style="color: indianred"><?php echo $i18n->t('form.checkbox.deleteentry'); ?></small>
 </form>
index 704b56a734173ef46b0f3f18accf951a44c485dd..1dbe0fb53b339692e4c521b59e7c6233a8592710 100644 (file)
@@ -2,7 +2,7 @@
 /**
  * scientia
  *
- * Copyright 2022 Johannes Keßler
+ * Copyright 2022 - 2024 Johannes Keßler
  *
  * https://www.bananas-playground.net/projekt/scientia/
  *
@@ -20,30 +20,30 @@ $Entry = new Entry($DB);
 
 $TemplateData['data'] = array();
 if(!empty($_id)) {
-       $TemplateData['data'] = $Entry->load($_year,$_month,$_day,$_id);
-       $TemplateData['data']['breadcrumb'] = array($_year,$_month,$_day);
+    $TemplateData['data'] = $Entry->load($_year,$_month,$_day,$_id);
+    $TemplateData['data']['breadcrumb'] = array($_year,$_month,$_day);
 }
 
 if(isset($_POST['submitForm']) && isset($_POST['fdata'])) {
-       $fdata = $_POST['fdata'];
-       if(isset($fdata['entry']) && Summoner::validate($fdata['entry'])) {
-               $_dataToSave = trim($fdata['entry']);
+    $fdata = $_POST['fdata'];
+    if(isset($fdata['entry']) && Summoner::validate($fdata['entry'])) {
+        $_dataToSave = trim($fdata['entry']);
 
-               if(!empty($_id) && isset($_POST['deleteEntry']) && $_POST['deleteEntry'] == "yes") {
-                       $do = $Entry->delete($_id);
-                       $_r = '/';
-               }
-               elseif(!empty($_id)) {
-                       $do = $Entry->update($_dataToSave,$_id);
-                       $_r = '/'.$_year.'/'.$_month.'/'.$_day.'/'.$_id;
-               }
-               else {
-                       $do = $Entry->create($_dataToSave);
-                       $_r = date('/Y/m/d/').$do;;
-               }
+        if(!empty($_id) && isset($_POST['deleteEntry']) && $_POST['deleteEntry'] == "yes") {
+            $do = $Entry->delete($_id);
+            $_r = '/';
+        }
+        elseif(!empty($_id)) {
+            $do = $Entry->update($_dataToSave,$_id);
+            $_r = '/'.$_year.'/'.$_month.'/'.$_day.'/'.$_id;
+        }
+        else {
+            $do = $Entry->create($_dataToSave);
+            $_r = date('/Y/m/d/').$do;;
+        }
 
-               if($do !== false) {
-                       $TemplateData['refresh'] = $_r;
-               }
-       }
+        if($do !== false) {
+            $TemplateData['refresh'] = $_r;
+        }
+    }
 }
index 4c8111b6e49e4f704d4a3e7b482d592bfd1531ab..1e5517e09408ed8ded7a36f1a9c8d342016d1187 100644 (file)
@@ -1,27 +1,27 @@
 <form method="post">
-       <input type="text" name="searchInput" size="50" />
-       <input type="submit" name="submitForm" value="<?php echo $i18n->t('form.button.search'); ?>">
+    <input type="text" name="searchInput" size="50" />
+    <input type="submit" name="submitForm" value="<?php echo $i18n->t('form.button.search'); ?>">
 </form>
 <?php if(!empty($TemplateData['entries'])) { ?>
 <p>
-       <a href="<?php echo PATH_WEBROOT; ?>/"><?php echo $i18n->t('text.home'); ?></a> |
+    <a href="<?php echo PATH_WEBROOT; ?>/"><?php echo $i18n->t('text.home'); ?></a> |
 <?php
-       foreach($TemplateData['entries'] as $k=>$v) {
-               $_link = '';
-               foreach($v['breadcrumb'] as $be) {
-                       $_link .= '/'.$be;
-                       echo '<a href="'.PATH_WEBROOT.$_link.'">'.$be.'</a> | ';
-               }
+    foreach($TemplateData['entries'] as $k=>$v) {
+        $_link = '';
+        foreach($v['breadcrumb'] as $be) {
+            $_link .= '/'.$be;
+            echo '<a href="'.PATH_WEBROOT.$_link.'">'.$be.'</a> | ';
+        }
 ?>
-       <a href="<?php echo PATH_WEBROOT; ?>/new"><?php echo $i18n->t('text.new'); ?></a>
+    <a href="<?php echo PATH_WEBROOT; ?>/new"><?php echo $i18n->t('text.new'); ?></a>
 <p>
 <ul>
-       <?php foreach($v['e'] as $e) { ?>
-       <li><a href="<?php echo PATH_WEBROOT; ?>/<?php echo $e['link']; ?>"><?php echo $e['ident']; ?></a> <?php echo $e['date']; ?> <?php echo htmlspecialchars($e['body'],ENT_HTML5); ?></li>
-       <?php } ?>
+    <?php foreach($v['e'] as $e) { ?>
+    <li><a href="<?php echo PATH_WEBROOT; ?>/<?php echo $e['link']; ?>"><?php echo $e['ident']; ?></a> <?php echo $e['date']; ?> <?php echo htmlspecialchars($e['body'],ENT_HTML5); ?></li>
+    <?php } ?>
 </ul>
 <?php
-       }
+    }
 } else { ?>
 <p><?php echo $i18n->t('text.noentries'); ?></p>
 <?php } ?>
index 1a3553ed1241c988a410ed3da8c26ccd598fba64..23a03be8ba300c46e5adf0e8643ddfad29108b69 100644 (file)
@@ -2,7 +2,7 @@
 /**
  * scientia
  *
- * Copyright 2022 Johannes Keßler
+ * Copyright 2022 - 2024 Johannes Keßler
  *
  * https://www.bananas-playground.net/projekt/scientia/
  *
@@ -22,9 +22,9 @@ $queryLimit = " LIMIT 100";
 
 $searchTerm = '';
 if(isset($_POST['submitForm']) && isset($_POST['searchInput'])) {
-       if(Summoner::validate($_POST['searchInput'])) {
-               $searchTerm = trim($_POST['searchInput']);
-       }
+    if(Summoner::validate($_POST['searchInput'])) {
+        $searchTerm = trim($_POST['searchInput']);
+    }
 }
 
 // why?
@@ -33,41 +33,41 @@ if(isset($_POST['submitForm']) && isset($_POST['searchInput'])) {
 $_groupByFormat = $_year;
 $breadcrumb = array('Y');
 if(!empty($_requestDateProvided)) {
-       $_intervalStart = '';
-       $_intervalEnd = '';
+    $_intervalStart = '';
+    $_intervalEnd = '';
 
-       if($_requestDateProvided === 'Y-m-d') {
-               $queryLimit = "";
-               $_groupByFormat = $_year.'-'.$_month.'-'.$_day;
-               $_intervalStart = $_groupByFormat;
-               $_intervalEnd = $_groupByFormat;
-               $breadcrumb = array('Y','m','d');
-       }
-       elseif ($_requestDateProvided === 'Y-m') {
-               $queryLimit = "";
-               $_groupByFormat = $_year.'-'.$_month;
-               $_intervalStart = $_groupByFormat.'-01';
-               $_tDate = new DateTime( $_intervalStart );
-               $_monthDays = $_tDate->format( 't' );
-               $_intervalEnd = $_groupByFormat.'-'.$_monthDays;
-               $breadcrumb = array('Y','m');
-       }
-       elseif ($_requestDateProvided === 'Y') {
-               $_intervalStart = $_groupByFormat.'-01-01';
-               $_intervalEnd = $_groupByFormat.'-12-31';
-       }
+    if($_requestDateProvided === 'Y-m-d') {
+        $queryLimit = "";
+        $_groupByFormat = $_year.'-'.$_month.'-'.$_day;
+        $_intervalStart = $_groupByFormat;
+        $_intervalEnd = $_groupByFormat;
+        $breadcrumb = array('Y','m','d');
+    }
+    elseif ($_requestDateProvided === 'Y-m') {
+        $queryLimit = "";
+        $_groupByFormat = $_year.'-'.$_month;
+        $_intervalStart = $_groupByFormat.'-01';
+        $_tDate = new DateTime( $_intervalStart );
+        $_monthDays = $_tDate->format( 't' );
+        $_intervalEnd = $_groupByFormat.'-'.$_monthDays;
+        $breadcrumb = array('Y','m');
+    }
+    elseif ($_requestDateProvided === 'Y') {
+        $_intervalStart = $_groupByFormat.'-01-01';
+        $_intervalEnd = $_groupByFormat.'-12-31';
+    }
 
-       if(!empty($_intervalStart) && !empty($_intervalEnd)) {
-               $queryStr .= " WHERE e.date >= '".$_intervalStart."' AND e.date <= '".$_intervalEnd."'";
-               if(!empty($searchTerm)) {
-                       $queryStr .= " AND MATCH(e.words) AGAINST('".$DB->real_escape_string($searchTerm)."' IN BOOLEAN MODE)";
-               }
-       }
+    if(!empty($_intervalStart) && !empty($_intervalEnd)) {
+        $queryStr .= " WHERE e.date >= '".$_intervalStart."' AND e.date <= '".$_intervalEnd."'";
+        if(!empty($searchTerm)) {
+            $queryStr .= " AND MATCH(e.words) AGAINST('".$DB->real_escape_string($searchTerm)."' IN BOOLEAN MODE)";
+        }
+    }
 } else {
-       $_requestDateProvided = 'Y';
-       if(!empty($searchTerm)) {
-               $queryStr .= " WHERE MATCH(e.words) AGAINST('".$DB->real_escape_string($searchTerm)."' IN BOOLEAN MODE)";
-       }
+    $_requestDateProvided = 'Y';
+    if(!empty($searchTerm)) {
+        $queryStr .= " WHERE MATCH(e.words) AGAINST('".$DB->real_escape_string($searchTerm)."' IN BOOLEAN MODE)";
+    }
 }
 
 $queryStr .= " ORDER BY `created` DESC";
@@ -75,20 +75,20 @@ $queryStr .= $queryLimit;
 if(QUERY_DEBUG) error_log("[QUERY] query: ".var_export($queryStr,true));
 
 try {
-       $query = $DB->query($queryStr);
-       if($query !== false && $query->num_rows > 0) {
-               while(($result = $query->fetch_assoc()) != false) {
-                       $_d = new DateTime($result['date']);
-                       $_breadcrumb = array();
-                       foreach($breadcrumb as $_b) {
-                               $_breadcrumb[] = $_d->format($_b);
-                       }
-                       $TemplateData['entries'][$_d->format($_requestDateProvided)]['breadcrumb'] = $_breadcrumb;
-                       $TemplateData['entries'][$_d->format($_requestDateProvided)]['e'][$result['ident']] = $result;
-                       $TemplateData['entries'][$_d->format($_requestDateProvided)]['e'][$result['ident']]['link'] = str_replace('-','/',$result['date']).'/'.$result['ident'];
-               }
-       }
+    $query = $DB->query($queryStr);
+    if($query !== false && $query->num_rows > 0) {
+        while(($result = $query->fetch_assoc()) != false) {
+            $_d = new DateTime($result['date']);
+            $_breadcrumb = array();
+            foreach($breadcrumb as $_b) {
+                $_breadcrumb[] = $_d->format($_b);
+            }
+            $TemplateData['entries'][$_d->format($_requestDateProvided)]['breadcrumb'] = $_breadcrumb;
+            $TemplateData['entries'][$_d->format($_requestDateProvided)]['e'][$result['ident']] = $result;
+            $TemplateData['entries'][$_d->format($_requestDateProvided)]['e'][$result['ident']]['link'] = str_replace('-','/',$result['date']).'/'.$result['ident'];
+        }
+    }
 }
 catch(Exception $e) {
-       error_log("[ERROR] catch: ".$e->getMessage());
+    error_log("[ERROR] catch: ".$e->getMessage());
 }