# 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
--- /dev/null
+# 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';
+```
+++ /dev/null
-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.
/**
* scientia
*
- * Copyright 2023 Johannes Keßler
+ * Copyright 2023 - 2024 Johannes Keßler
*
* https://www.bananas-playground.net/projekt/scientia/
*
## 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
$_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
$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
/**
* scientia
*
- * Copyright 2022 Johannes Keßler
+ * Copyright 2022 - 2024 Johannes Keßler
*
* https://www.bananas-playground.net/projekt/scientia/
*
/**
* scientia
*
- * Copyright 2023 Johannes Keßler
+ * Copyright 2023 - 2024 Johannes Keßler
*
* https://www.bananas-playground.net/projekt/scientia/
*
## 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
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
$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';
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';
/**
* 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]);
+ }
}
/**
* 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;
+ }
}
; scientia
;
-; Copyright 2022 Johannes Keßler
+; Copyright 2022 - 2024 Johannes Keßler
;
; https://www.bananas-playground.net/projekt/scientia/
;
text.home=Index
text.new=Neu
-text.noentries=Nichts vorhanden.
\ No newline at end of file
+text.noentries=Nichts vorhanden.
; scientia
;
-; Copyright 2022 Johannes Keßler
+; Copyright 2022 - 2024 Johannes Keßler
;
; https://www.bananas-playground.net/projekt/scientia/
;
text.home=Home
text.new=New
text.noentries=Nothing here.
-
/**
* 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);
else {
return false;
}
- break;
+ break;
case 'url':
if(filter_var($input,FILTER_VALIDATE_URL) === $input) {
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:
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) {
}
- /**
- * 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
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);
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;
+ }
+ }
}
- <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>
<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>
<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>
/**
* scientia
*
- * Copyright 2022 Johannes Keßler
+ * Copyright 2022 - 2024 Johannes Keßler
*
* https://www.bananas-playground.net/projekt/scientia/
*
$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;
+ }
+ }
}
<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 } ?>
/**
* scientia
*
- * Copyright 2022 Johannes Keßler
+ * Copyright 2022 - 2024 Johannes Keßler
*
* https://www.bananas-playground.net/projekt/scientia/
*
$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?
$_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";
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());
}