From: Johannes Keßler Date: Mon, 26 Sep 2022 11:38:21 +0000 (+0200) Subject: tab cleanup X-Git-Url: http://91.132.146.200/gitweb/?a=commitdiff_plain;h=192b58f5ff3628c57ae9a4fa1b06c9c4f3bd8e99;p=emere.git tab cleanup --- diff --git a/webroot/config/config.php.default b/webroot/config/config.php.default index f0247ab..b0872a3 100644 --- a/webroot/config/config.php.default +++ b/webroot/config/config.php.default @@ -34,7 +34,7 @@ const FE_LANG = "en"; # path settings const PATH_ABSOLUTE = '/home/some/path/emere/'; const PATH_LOGDIRECTORY = PATH_ABSOLUTE . '/log'; -const PATH_WEBROOT = '/'; +const PATH_WEBROOT = '/'; # please add a / at the end # database config const DB_HOST = '127.0.0.1'; diff --git a/webroot/index.php b/webroot/index.php index febe12b..6bef201 100644 --- a/webroot/index.php +++ b/webroot/index.php @@ -60,14 +60,14 @@ $TemplateData = array(); $_view = 'home'; if(isset($_GET['p']) && Summoner::validate($_GET['p'], 'nospace')) { - $_view = trim($_GET['p']); + $_view = trim($_GET['p']); } require_once 'view/'.$_view.'/'.$_view.'.php'; if(isset($TemplateData['refresh']) && !empty($TemplateData['refresh'])) { - header('Location: '.PATH_WEBROOT.$TemplateData['refresh']); - exit(); + header('Location: '.PATH_WEBROOT.$TemplateData['refresh']); + exit(); } # header information diff --git a/webroot/lib/item.class.php b/webroot/lib/item.class.php index a71e426..d9caebc 100644 --- a/webroot/lib/item.class.php +++ b/webroot/lib/item.class.php @@ -21,25 +21,25 @@ class Item { /** - * The DB object - * - * @var mysqli - */ - private mysqli $_DB; - - /** - * The data for this item - * - * @var array - */ - private array $_data; - - /** - * @param mysqli $databaseConnectionObject - */ - public function __construct(mysqli $databaseConnectionObject) { - $this->_DB = $databaseConnectionObject; - } + * The DB object + * + * @var mysqli + */ + private mysqli $_DB; + + /** + * The data for this item + * + * @var array + */ + private array $_data; + + /** + * @param mysqli $databaseConnectionObject + */ + public function __construct(mysqli $databaseConnectionObject) { + $this->_DB = $databaseConnectionObject; + } public function create(array $data): string { $ret = ""; diff --git a/webroot/lib/summoner.class.php b/webroot/lib/summoner.class.php index 4b23730..deeba4c 100644 --- a/webroot/lib/summoner.class.php +++ b/webroot/lib/summoner.class.php @@ -24,83 +24,83 @@ * 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 - */ - static function validate(string $input, string $mode = 'text', string $limit = "0"): bool { - // check if we have input - $input = trim($input); - - if($input == "") return false; - - $ret = false; - - switch ($mode) { - case 'mail': - if(filter_var($input,FILTER_VALIDATE_EMAIL) === $input) { - return true; - } - else { - return false; - } - break; - - case 'url': - if(filter_var($input,FILTER_VALIDATE_URL) === $input) { - return true; - } - else { - return false; - } + /** + * 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 = "0"): bool { + // check if we have input + $input = trim($input); + + if($input == "") return false; + + $ret = false; + + switch ($mode) { + case 'mail': + if(filter_var($input,FILTER_VALIDATE_EMAIL) === $input) { + return true; + } + else { + return false; + } + break; + + case 'url': + if(filter_var($input,FILTER_VALIDATE_URL) === $input) { + return true; + } + else { + return false; + } break; - case 'nospace': - // text without any whitespace and special chars - $pattern = '/[\p{L}\p{N}]/u'; - 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; - - case 'digit': - // only numbers and digit - // warning with negative numbers... - $pattern = '/[\p{N}\-]/'; - 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; - - # strange. the \p{M} is needed.. don't know why.. - case 'filename': - $pattern = '/[\p{L}\p{N}\p{M}\-_\.\p{Zs}]/u'; - break; - - case 'shortlink': - // special char string based on https://www.jwz.org/base64-shortlinks/ - $pattern = '/[\p{L}\p{N}\-_]/u'; - break; + case 'nospace': + // text without any whitespace and special chars + $pattern = '/[\p{L}\p{N}]/u'; + 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; + + case 'digit': + // only numbers and digit + // warning with negative numbers... + $pattern = '/[\p{N}\-]/'; + 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; + + # strange. the \p{M} is needed.. don't know why.. + case 'filename': + $pattern = '/[\p{L}\p{N}\p{M}\-_\.\p{Zs}]/u'; + break; + + case 'shortlink': + // special char string based on https://www.jwz.org/base64-shortlinks/ + $pattern = '/[\p{L}\p{N}\-_]/u'; + break; case 'datetime': // based on the format eg. 2022-09-25T22:00 @@ -112,101 +112,101 @@ class Summoner { case 'text': - default: - $pattern = '/[\p{L}\p{N}\p{P}\p{S}\p{Z}\p{M}\s]/u'; - } - - $value = preg_replace($pattern, '', $input); - - if($value === "") { - $ret = true; - } - - if(!empty($limit) && is_numeric($limit)) { - # isset starts with 0 - if(isset($input[$limit])) { - # too long - $ret = false; - } - } - - return $ret; - } - - /** - * 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 - */ - static function endsWith(string $haystack, string $needle): bool { - $length = strlen($needle); - if ($length == 0) { - return true; - } - - return (substr($haystack, -$length) === $needle); - } - - - /** - * create a short string based on a integer - * - * @see https://www.jwz.org/base64-shortlinks/ - * @param string $id - * @return string - */ - static function b64sl_pack_id(string $id): string { - $id = intval($id); - $ida = ($id > 0xFFFFFFFF ? $id >> 32 : 0); // 32 bit big endian, top - $idb = ($id & 0xFFFFFFFF); // 32 bit big endian, bottom - $id = pack ('N', $ida) . pack ('N', $idb); - $id = preg_replace('/^\000+/', '', "$id"); // omit high-order NUL bytes - $id = base64_encode ($id); - $id = str_replace ('+', '-', $id); // encode URL-unsafe "+" "/" - $id = str_replace ('/', '_', $id); - $id = preg_replace ('/=+$/', '', $id); // omit trailing padding bytes - 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 string - */ - static function b64sl_unpack_id(string $id): string { - $id = str_replace ('-', '+', $id); // decode URL-unsafe "+" "/" - $id = str_replace ('_', '/', $id); - $id = base64_decode ($id); - while (strlen($id) < 8) { $id = "\000$id"; } // pad with leading NULs - $a = unpack ('N*', $id); // 32 bit big endian - $id = ($a[1] << 32) | $a[2]; // pack top and bottom word - return $id; - } - - /** - * this only works with arrays and checking if the key is there and echo/return it. - * - * @param $array array - * @param $key string - * @return mixed - */ - static function ifset(array $array, string $key) { - return $array[$key] ?? ''; - } + default: + $pattern = '/[\p{L}\p{N}\p{P}\p{S}\p{Z}\p{M}\s]/u'; + } + + $value = preg_replace($pattern, '', $input); + + if($value === "") { + $ret = true; + } + + if(!empty($limit) && is_numeric($limit)) { + # isset starts with 0 + if(isset($input[$limit])) { + # too long + $ret = false; + } + } + + return $ret; + } + + /** + * 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 + */ + static function endsWith(string $haystack, string $needle): bool { + $length = strlen($needle); + if ($length == 0) { + return true; + } + + return (substr($haystack, -$length) === $needle); + } + + + /** + * create a short string based on a integer + * + * @see https://www.jwz.org/base64-shortlinks/ + * @param string $id + * @return string + */ + static function b64sl_pack_id(string $id): string { + $id = intval($id); + $ida = ($id > 0xFFFFFFFF ? $id >> 32 : 0); // 32 bit big endian, top + $idb = ($id & 0xFFFFFFFF); // 32 bit big endian, bottom + $id = pack ('N', $ida) . pack ('N', $idb); + $id = preg_replace('/^\000+/', '', "$id"); // omit high-order NUL bytes + $id = base64_encode ($id); + $id = str_replace ('+', '-', $id); // encode URL-unsafe "+" "/" + $id = str_replace ('/', '_', $id); + $id = preg_replace ('/=+$/', '', $id); // omit trailing padding bytes + 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 string + */ + static function b64sl_unpack_id(string $id): string { + $id = str_replace ('-', '+', $id); // decode URL-unsafe "+" "/" + $id = str_replace ('_', '/', $id); + $id = base64_decode ($id); + while (strlen($id) < 8) { $id = "\000$id"; } // pad with leading NULs + $a = unpack ('N*', $id); // 32 bit big endian + $id = ($a[1] << 32) | $a[2]; // pack top and bottom word + return $id; + } + + /** + * this only works with arrays and checking if the key is there and echo/return it. + * + * @param $array array + * @param $key string + * @return mixed + */ + static function ifset(array $array, string $key) { + return $array[$key] ?? ''; + } } diff --git a/webroot/view/_foot.php b/webroot/view/_foot.php index d5f6fbc..eda8635 100644 --- a/webroot/view/_foot.php +++ b/webroot/view/_foot.php @@ -1,3 +1,3 @@ - + diff --git a/webroot/view/_head.php b/webroot/view/_head.php index ee70071..1ac6045 100644 --- a/webroot/view/_head.php +++ b/webroot/view/_head.php @@ -1,15 +1,14 @@ - - <?php echo Summoner::ifset($TemplateData,'pageTitle').' - '; ?>emere - - + + <?php echo Summoner::ifset($TemplateData,'pageTitle').' - '; ?>emere + +
+ - - -

- +

+ diff --git a/webroot/view/_menu.php b/webroot/view/_menu.php index d491c4b..f2dda07 100644 --- a/webroot/view/_menu.php +++ b/webroot/view/_menu.php @@ -1,5 +1,5 @@ diff --git a/webroot/view/_message.php b/webroot/view/_message.php index 0ad66e0..08fbe1e 100644 --- a/webroot/view/_message.php +++ b/webroot/view/_message.php @@ -18,31 +18,31 @@ * along with this program. If not, see . */ if(isset($TemplateData['message']['content']) && !empty($TemplateData['message']['content'])) { - $cssClass = 'blue-168'; - $headline = 'Info'; - if(isset($TemplateData['message']['status'])) { - switch($TemplateData['message']['status']) { - case 'error': - $cssClass = 'red-168'; - $headline = 'Error'; - break; - case 'warning': - $cssClass = 'yellow-168'; - $headline = 'Warning'; - break; - case 'success': - $cssClass = 'green-168'; - $headline = 'Success'; - break; + $cssClass = 'blue-168'; + $headline = 'Info'; + if(isset($TemplateData['message']['status'])) { + switch($TemplateData['message']['status']) { + case 'error': + $cssClass = 'red-168'; + $headline = 'Error'; + break; + case 'warning': + $cssClass = 'yellow-168'; + $headline = 'Warning'; + break; + case 'success': + $cssClass = 'green-168'; + $headline = 'Success'; + break; - case 'info': - default: + case 'info': + default: - } - } - ?> -
-

-

-
+ } + } + ?> +
+

+

+
diff --git a/webroot/view/item/item.html b/webroot/view/item/item.html index 986385b..2901733 100644 --- a/webroot/view/item/item.html +++ b/webroot/view/item/item.html @@ -1,62 +1,62 @@
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/webroot/view/item/item.php b/webroot/view/item/item.php index 82d64c8..e0d6b87 100644 --- a/webroot/view/item/item.php +++ b/webroot/view/item/item.php @@ -4,13 +4,13 @@ $ItemInput = new ItemInput($DB); $_id = false; if(isset($_GET['id']) && !empty($_GET['id'])) { - $_id = trim($_GET['id']); - $_id = Summoner::validate($_id,'nospace') ? $_id : false; + $_id = trim($_GET['id']); + $_id = Summoner::validate($_id,'nospace') ? $_id : false; } $TemplateData['pageTitle'] = 'New item'; if(!empty($_id)) { - $TemplateData['pageTitle'] = 'Edit item'; + $TemplateData['pageTitle'] = 'Edit item'; } $TemplateData['editData'] = array(); @@ -19,15 +19,17 @@ $TemplateData['message']['content'] = ""; $TemplateData['message']['status'] = ""; if(isset($_POST['fdata']) && !empty($_POST['fdata']) && isset($_POST['submitForm'])) { - $fdata = $_POST['fdata']; - if (!empty($fdata)) { + $fdata = $_POST['fdata']; + if (!empty($fdata)) { + + var_dump($fdata); $ItemInput->validateAndPrepare($fdata); - } else { - $TemplateData['message']['content'] = "Collection could not be loaded."; - $TemplateData['message']['status'] = "error"; - } + } else { + $TemplateData['message']['content'] = "Collection could not be loaded."; + $TemplateData['message']['status'] = "error"; + } }