Просмотр исходного кода

more cleanups

Signed-off-by: Banana <mail@bananas-playground.net>
Banana 3 месяцев назад
Родитель
Сommit
073bc7858c

+ 1 - 1
documentation/requirements.md

@@ -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

+ 21 - 0
documentation/upgrade-from-1.0.md

@@ -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';
+```

+ 0 - 6
documentation/upgrade-from-1.0.txt

@@ -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.

+ 25 - 25
webroot/api.php

@@ -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

+ 1 - 1
webroot/config/config.php.default

@@ -2,7 +2,7 @@
 /**
  * scientia
  *
- * Copyright 2022 Johannes Keßler
+ * Copyright 2022 - 2024 Johannes Keßler
  *
  * https://www.bananas-playground.net/projekt/scientia/
  *

+ 18 - 18
webroot/index.php

@@ -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';

+ 146 - 146
webroot/lib/entry.class.php

@@ -2,7 +2,7 @@
 /**
  * scientia
  *
- * Copyright 2022 Johannes Keßler
+ * Copyright 2022 - 2024 Johannes Keßler
  *
  * https://www.bananas-playground.net/projekt/scientia/
  *
@@ -21,149 +21,149 @@
  * 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]);
+    }
 }

+ 43 - 43
webroot/lib/i18n.class.php

@@ -2,7 +2,7 @@
 /**
  * scientia
  *
- * Copyright 2023 Johannes Keßler
+ * Copyright 2023 - 2024 Johannes Keßler
  *
  * https://www.bananas-playground.net/projekt/scientia/
  *
@@ -16,49 +16,49 @@
  */
 
 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;
+    }
 }

+ 2 - 2
webroot/lib/i18n/de.ini

@@ -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.
+text.noentries=Nichts vorhanden.

+ 1 - 2
webroot/lib/i18n/en.ini

@@ -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.
-

+ 71 - 86
webroot/lib/summoner.class.php

@@ -2,7 +2,7 @@
 /**
  * scientia
  *
- * Copyright 2023 Johannes Keßler
+ * Copyright 2023 - 2024 Johannes Keßler
  *
  * https://www.bananas-playground.net/projekt/scientia/
  *
@@ -21,23 +21,23 @@
  * 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;
+        }
+    }
 }

+ 3 - 3
webroot/view/_foot.php

@@ -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>

+ 7 - 7
webroot/view/_head.php

@@ -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>

+ 15 - 15
webroot/view/entry/entry.html

@@ -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>

+ 22 - 22
webroot/view/entry/entry.php

@@ -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;
+        }
+    }
 }

+ 14 - 14
webroot/view/list/list.html

@@ -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 } ?>

+ 50 - 50
webroot/view/list/list.php

@@ -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());
 }