main
Robert 4 months ago
parent aee3d4388a
commit 1c633b9ef6
  1. 12
      src/bootstrap/main.php
  2. 24
      src/bootstrap/requires.php
  3. 10
      src/bootstrap/safer_io.php
  4. 2
      src/classes/app.php
  5. 2
      src/classes/arrays/mocking/phone.php
  6. 14
      src/classes/assets.php
  7. 88
      src/classes/common.php
  8. 14
      src/classes/database/model.php
  9. 4
      src/classes/html_document.php
  10. 2
      src/classes/memory_usage.php
  11. 8
      src/classes/misc.php
  12. 2
      src/classes/random_engine.php
  13. 2
      src/classes/services/emailer.php
  14. 18
      src/classes/services/encryption.php
  15. 2
      src/classes/services/log.php
  16. 2
      src/classes/session_management.php
  17. 4
      src/classes/strings/mb_string_fns.php
  18. 7
      src/classes/strings/string_fns.php
  19. 4
      src/classes/tag_matches.php
  20. 10
      src/classes/time_zones.php
  21. 2
      src/classes/traits/database/run_sql.php
  22. 6
      src/classes/traits/database/validation.php
  23. 4
      src/classes/validator.php
  24. 2
      src/classes/view.php

@ -10,13 +10,6 @@ declare(strict_types=1);
namespace CodeHydrater\bootstrap; namespace CodeHydrater\bootstrap;
// Polyfill for PHP 4 to 7
if (!function_exists('str_contains')) {
function str_contains($haystack, $needle) {
return $needle !== '' && mb_strpos($haystack, $needle) !== false;
}
}
$mem_baseline = memory_get_usage(); $mem_baseline = memory_get_usage();
require_once CodeHydrater_FRAMEWORK . 'bootstrap/errors.php'; require_once CodeHydrater_FRAMEWORK . 'bootstrap/errors.php';
@ -120,9 +113,9 @@ final class configure {
return; return;
} }
if ($key === false) { if ($key === false) {
common::wipe(self::$config[strtolower($name)]); \CodeHydrater\common::wipe(self::$config[strtolower($name)]);
} }
common::wipe(self::$config[strtolower($name)][strtolower($key)]); \CodeHydrater\common::wipe(self::$config[strtolower($name)][strtolower($key)]);
} }
public static function load_array(array $a): void { public static function load_array(array $a): void {
@ -268,7 +261,6 @@ final class di {
// Initialize our Dependency Injector // Initialize our Dependency Injector
registry::set('di', new di()); registry::set('di', new di());
require_once CodeHydrater_FRAMEWORK . 'bootstrap/common.php';
require_once CodeHydrater_FRAMEWORK . 'bootstrap/requires.php'; require_once CodeHydrater_FRAMEWORK . 'bootstrap/requires.php';
require_once CodeHydrater_FRAMEWORK . 'bootstrap/auto_loader.php'; require_once CodeHydrater_FRAMEWORK . 'bootstrap/auto_loader.php';

@ -10,8 +10,6 @@ declare(strict_types=1);
namespace CodeHydrater\bootstrap; namespace CodeHydrater\bootstrap;
use CodeHydrater\bootstrap\common;
enum UseDir: string { enum UseDir: string {
case FIXED = "Fixed"; case FIXED = "Fixed";
case FRAMEWORK = "Framework"; case FRAMEWORK = "Framework";
@ -95,6 +93,18 @@ final class requires {
return (file_exists($dir)) ? $dir : false; return (file_exists($dir)) ? $dir : false;
} }
private static function string_last_position(string $string, string $needle, int $offset = 0, $encoding = null) {
return (extension_loaded('mbstring')) ? mb_strrpos($string, $needle, $offset, $encoding) : strrpos($string, $needle, $offset);
}
private static function string_sub_part(string $string, int $offset = 0, int $length = null, $encoding = null) {
if ($length === null) {
return (extension_loaded('mbstring')) ? mb_substr($string, $offset,mb_strlen($string), $encoding) : substr($string, $offset, strlen($string));
} else {
return (extension_loaded('mbstring')) ? mb_substr($string, $offset, $length, $encoding) : substr($string, $offset, $length);
}
}
/** /**
* @return Cleaned FileName or False * @return Cleaned FileName or False
*/ */
@ -108,14 +118,14 @@ final class requires {
if (empty($file)) { if (empty($file)) {
return false; return false;
} }
$pos_last_occurrence = self::string_last_position($file, ".");
$pos = common::string_last_position($file, "."); if ($pos_last_occurrence === false) {
if ($pos === false) {
$file_type = ".php"; $file_type = ".php";
$file_name = $file; $file_name = $file;
} else { } else {
$file_name = common::get_string_left($file, $pos); $file_name = self::string_sub_part($file, 0, $pos_last_occurrence);
$file_kind = common::get_string_right($file, common::string_length($file) - $pos); // Keep offset negitive, to get file kind...
$file_kind = self::string_sub_part($file, -(strlen($file) - $pos_last_occurrence));
$file_type = match ($file_kind) { $file_type = match ($file_kind) {
".twig" => ".twig", ".twig" => ".twig",
".tpl" => ".tpl", ".tpl" => ".tpl",

@ -94,6 +94,10 @@ final class safer_io {
self::$DATA_INPUTS[$var_name] : null; self::$DATA_INPUTS[$var_name] : null;
} }
private static function get_count($i): int {
return (is_array($i) || is_object($i)) ? count($i) : 0;
}
public static function grab_all_post_data( public static function grab_all_post_data(
int $bytes_limit = 650000, int $bytes_limit = 650000,
int $max_params = 400 int $max_params = 400
@ -276,7 +280,7 @@ final class safer_io {
if (is_string($item)) { if (is_string($item)) {
return trim($item); return trim($item);
} }
if (\bs_tts\common::get_count($data)) { if (self::get_count($data)) {
$ret = []; $ret = [];
foreach($data as $text) { foreach($data as $text) {
if (is_bool($text) || is_int($text)) { if (is_bool($text) || is_int($text)) {
@ -396,7 +400,7 @@ final class safer_io {
private static function get_safer_html($data, use_io $a) { private static function get_safer_html($data, use_io $a) {
if (is_string($data)) { if (is_string($data)) {
return self::get_safer_string($data, $a); return self::get_safer_string($data, $a);
} else if (common::get_count($data)) { } else if (self::get_count($data)) {
$ret = []; $ret = [];
foreach($data as $text) { foreach($data as $text) {
if (is_bool($text) || is_int($text)) { if (is_bool($text) || is_int($text)) {
@ -492,7 +496,7 @@ final class safer_io {
if ($field_type == FIELD_FILTER::raw_string || if ($field_type == FIELD_FILTER::raw_string ||
$field_type == FIELD_FILTER::raw $field_type == FIELD_FILTER::raw
) { ) {
if (common::get_count($safer_data)) { if (self::get_count($safer_data)) {
$safer_data = $safer_data[0]; $safer_data = $safer_data[0];
} }
} }

@ -22,7 +22,7 @@ class app {
$dot_position = strpos($route, '.'); $dot_position = strpos($route, '.');
if ($dot_position !== false) { if ($dot_position !== false) {
$offset = strlen($route) - $dot_position; $offset = strlen($route) - $dot_position;
$ext = \CodeHydrater\bootstrap\common::get_string_right($route, $offset); $ext = common::get_string_right($route, $offset);
if ($ext === ".php") { if ($ext === ".php") {
$this->local404(); $this->local404();
} }

@ -10,7 +10,7 @@ class phone {
const AREACODES = [201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 212, 213, 214, 215, 216, 217, 218, 219, 220, 224, 225, 226, 228, 229, 231, 234, 236, 239, 240, 242, 246, 248, 249, 250, 251, 252, 253, 254, 256, 260, 262, 264, 267, 268, 269, 270, 272, 276, 281, 284, 289, 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, 312, 313, 314, 315, 316, 317, 318, 319, 320, 321, 323, 325, 330, 331, 334, 336, 337, 339, 340, 343, 345, 346, 347, 351, 352, 360, 361, 364, 365, 380, 385, 386, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 412, 413, 414, 415, 416, 417, 418, 419, 423, 424, 425, 430, 431, 432, 434, 435, 437, 438, 440, 441, 442, 443, 450, 458, 469, 470, 473, 475, 478, 479, 480, 484, 501, 502, 503, 504, 505, 506, 507, 508, 509, 510, 512, 513, 514, 515, 516, 517, 518, 519, 520, 530, 531, 534, 539, 540, 541, 548, 551, 559, 561, 562, 563, 567, 570, 571, 573, 574, 575, 579, 580, 581, 585, 586, 587, 601, 602, 603, 604, 605, 606, 607, 608, 609, 610, 612, 613, 614, 615, 616, 617, 618, 619, 620, 623, 626, 628, 629, 630, 631, 636, 639, 641, 646, 647, 649, 650, 651, 657, 660, 661, 662, 664, 667, 669, 670, 671, 678, 681, 682, 684, 701, 702, 703, 704, 705, 706, 707, 708, 709, 712, 713, 714, 715, 716, 717, 718, 719, 720, 721, 724, 725, 727, 731, 732, 734, 737, 740, 743, 747, 754, 757, 758, 760, 762, 763, 765, 767, 769, 770, 772, 773, 774, 775, 778, 779, 780, 781, 782, 784, 785, 786, 787, 801, 802, 803, 804, 805, 806, 807, 808, 809, 810, 812, 813, 814, 815, 816, 817, 818, 819, 825, 828, 829, 830, 831, 832, 843, 845, 847, 848, 849, 850, 854, 856, 857, 858, 859, 860, 862, 863, 864, 865, 867, 868, 869, 870, 872, 873, 876, 878, 901, 902, 903, 904, 905, 906, 907, 908, 909, 910, 912, 913, 914, 915, 916, 917, 918, 919, 920, 925, 928, 929, 930, 931, 934, 936, 937, 938, 939, 940, 941, 947, 949, 951, 952, 954, 956, 959, 970, 971, 972, 973, 978, 979, 980, 984, 985, 989]; const AREACODES = [201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 212, 213, 214, 215, 216, 217, 218, 219, 220, 224, 225, 226, 228, 229, 231, 234, 236, 239, 240, 242, 246, 248, 249, 250, 251, 252, 253, 254, 256, 260, 262, 264, 267, 268, 269, 270, 272, 276, 281, 284, 289, 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, 312, 313, 314, 315, 316, 317, 318, 319, 320, 321, 323, 325, 330, 331, 334, 336, 337, 339, 340, 343, 345, 346, 347, 351, 352, 360, 361, 364, 365, 380, 385, 386, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 412, 413, 414, 415, 416, 417, 418, 419, 423, 424, 425, 430, 431, 432, 434, 435, 437, 438, 440, 441, 442, 443, 450, 458, 469, 470, 473, 475, 478, 479, 480, 484, 501, 502, 503, 504, 505, 506, 507, 508, 509, 510, 512, 513, 514, 515, 516, 517, 518, 519, 520, 530, 531, 534, 539, 540, 541, 548, 551, 559, 561, 562, 563, 567, 570, 571, 573, 574, 575, 579, 580, 581, 585, 586, 587, 601, 602, 603, 604, 605, 606, 607, 608, 609, 610, 612, 613, 614, 615, 616, 617, 618, 619, 620, 623, 626, 628, 629, 630, 631, 636, 639, 641, 646, 647, 649, 650, 651, 657, 660, 661, 662, 664, 667, 669, 670, 671, 678, 681, 682, 684, 701, 702, 703, 704, 705, 706, 707, 708, 709, 712, 713, 714, 715, 716, 717, 718, 719, 720, 721, 724, 725, 727, 731, 732, 734, 737, 740, 743, 747, 754, 757, 758, 760, 762, 763, 765, 767, 769, 770, 772, 773, 774, 775, 778, 779, 780, 781, 782, 784, 785, 786, 787, 801, 802, 803, 804, 805, 806, 807, 808, 809, 810, 812, 813, 814, 815, 816, 817, 818, 819, 825, 828, 829, 830, 831, 832, 843, 845, 847, 848, 849, 850, 854, 856, 857, 858, 859, 860, 862, 863, 864, 865, 867, 868, 869, 870, 872, 873, 876, 878, 901, 902, 903, 904, 905, 906, 907, 908, 909, 910, 912, 913, 914, 915, 916, 917, 918, 919, 920, 925, 928, 929, 930, 931, 934, 936, 937, 938, 939, 940, 941, 947, 949, 951, 952, 954, 956, 959, 970, 971, 972, 973, 978, 979, 980, 984, 985, 989];
private static function rnd_a(array $a) { private static function rnd_a(array $a) {
$array_count = \CodeHydrater\bootstrap\common::get_count($a); $array_count = \CodeHydrater\common::get_count($a);
return $a[rand(0, $array_count - 1)]; return $a[rand(0, $array_count - 1)];
} }

@ -35,10 +35,10 @@ final class assets {
if ($path === null || $path === '') { if ($path === null || $path === '') {
return false; return false;
} }
if (bootstrap\common::get_string_left($path, strlen($open_base_dir_path)) == $open_base_dir_path) { if (common::get_string_left($path, strlen($open_base_dir_path)) == $open_base_dir_path) {
return false; return false;
} }
if (bootstrap\common::get_string_left($path, 1) == '/') { if (common::get_string_left($path, 1) == '/') {
return true; return true;
} }
return false; return false;
@ -100,7 +100,7 @@ final class assets {
* @retval boolean|string false is not found, else Asset REF * @retval boolean|string false is not found, else Asset REF
*/ */
public static function wrap_asset(string $file, string $scope = 'project') { public static function wrap_asset(string $file, string $scope = 'project') {
$scope = bootstrap\common::string_to_lowercase($scope); $scope = \CodeHydrater\strings\string_facade::strtolower($scope);
if ($scope === 'cdn') { if ($scope === 'cdn') {
$proto = bootstrap\safer_io::get_clean_server_var('SERVER_PROTOCOL'); $proto = bootstrap\safer_io::get_clean_server_var('SERVER_PROTOCOL');
if ($proto === null) { if ($proto === null) {
@ -108,7 +108,7 @@ final class assets {
} else { } else {
$protocol = strtolower(substr($proto, 0, strpos($proto, '/'))) . '://'; $protocol = strtolower(substr($proto, 0, strpos($proto, '/'))) . '://';
} }
return (bootstrap\common::is_string_found($file, '://') === true) ? $file : $protocol . $file; return (common::is_string_found($file, '://') === true) ? $file : $protocol . $file;
} }
if ($scope === 'project' || $scope === 'app') { if ($scope === 'project' || $scope === 'app') {
$path = PROJECT_ASSETS_DIR . "/"; $path = PROJECT_ASSETS_DIR . "/";
@ -129,7 +129,7 @@ final class assets {
* @return string|bool * @return string|bool
*/ */
private static function project_paths(string $file, string $scope = 'project'): string | bool { private static function project_paths(string $file, string $scope = 'project'): string | bool {
$scope = bootstrap\common::string_to_lowercase($scope); $scope = \CodeHydrater\strings\string_facade::strtolower($scope);
if ($scope === 'cdn') { if ($scope === 'cdn') {
return ""; return "";
} else if ($scope === 'project' || $scope === 'app') { } else if ($scope === 'project' || $scope === 'app') {
@ -214,7 +214,7 @@ final class assets {
$safe_path = security::filter_uri($path); $safe_path = security::filter_uri($path);
$safe_file = security::filter_uri($file); $safe_file = security::filter_uri($file);
if (bootstrap\common::is_string_found($safe_file, '.auto.js')) { if (common::is_string_found($safe_file, '.auto.js')) {
$production = (bootstrap\is_live()); $production = (bootstrap\is_live());
$safe_file = str_replace('.auto.js', '', $safe_file); $safe_file = str_replace('.auto.js', '', $safe_file);
if ( $production && file_exists($safe_path . $safe_file . '.min.js') ) { if ( $production && file_exists($safe_path . $safe_file . '.min.js') ) {
@ -223,7 +223,7 @@ final class assets {
return (file_exists($safe_path . $safe_file . '.js')) ? $safe_file . '.js' : false; return (file_exists($safe_path . $safe_file . '.js')) ? $safe_file . '.js' : false;
} }
if (bootstrap\common::is_string_found($safe_file, '.auto.css')) { if (common::is_string_found($safe_file, '.auto.css')) {
$production = (bootstrap\is_live()); $production = (bootstrap\is_live());
$safe_file = str_replace('.auto.css', '', $safe_file); $safe_file = str_replace('.auto.css', '', $safe_file);
if ( $production && file_exists($safe_path . $safe_file . '.min.css') ) { if ( $production && file_exists($safe_path . $safe_file . '.min.css') ) {

@ -8,7 +8,8 @@ declare(strict_types=1);
* @license MIT * @license MIT
*/ */
namespace CodeHydrater\bootstrap; namespace CodeHydrater;
use CodeHydrater\strings\string_facade as F;
final class common { final class common {
@ -21,32 +22,39 @@ final class common {
} }
/** /**
* * @todo add object checking...
* @param type $ret option to check for false error condition * @param type $ret option to check for false error condition
* @return bool true if false/error found * @return bool true if false/error found
*/ */
public static function is_error($ret): bool { public static function is_error($ret): bool {
$lr = self::string_to_lowercase(trim($ret)); if ($ret === false) {
return ($ret === false || $lr === 'false') ? true : false; return true;
}
if (is_string($ret)) {
$lr = F::strtolower(F::trim($ret));
return ($lr === 'false') ? true : false;
}
throw new \Exception("Unknown state of on error");
} }
public static function return_bool_as_yes_no(bool $b_data): string { public static function return_bool_as_yes_no(bool $b_data): string {
return ($b_data) ? 'y' : 'n'; // if true=y, else =n return ($b_data) ? 'y' : 'n'; // if true=y, else =n
} }
public static function get_bool($bool, $throw = true): bool { public static function get_bool($bool, $throw = true): ?bool {
if (is_bool($bool)) { if (is_bool($bool)) {
return $bool; return $bool;
} }
if (is_string($bool)) { if (is_string($bool)) {
$bool = self::string_to_lowercase(trim($bool)); $bool = F::strtolower(F::trim($bool));
} }
switch ($bool) { switch ($bool) {
case ':null':
case null:
return null;
case '0': case '0':
case 'false': case 'false':
case ':false': case ':false':
case ':null':
case null:
case 'no': case 'no':
case 'n': case 'n':
case 'disable': case 'disable':
@ -74,50 +82,17 @@ final class common {
} }
// Begin Strings Functions here:: // Begin Strings Functions here::
public static function string_to_lowercase(string $string, $encoding = null): string {
if (null === $encoding) {
$encoding = mb_internal_encoding();
}
return (extension_loaded('mbstring')) ? mb_strtolower($string, $encoding) : strtolower($string);
}
public static function string_to_uppercase(string $string, $encoding = null): string {
if (null === $encoding) {
$encoding = mb_internal_encoding();
}
return (extension_loaded('mbstring')) ? mb_strtoupper($string, $encoding) : strtoupper($string);
}
public static function string_length(string $string, $encoding = null) {
if (null === $encoding) {
$encoding = mb_internal_encoding();
}
return (extension_loaded('mbstring')) ? mb_strlen($string, $encoding) : strlen($string);
}
public static function string_position(string $string, string $needle, int $offset = 0, $encoding = null) { public static function string_position(string $string, string $needle, int $offset = 0, $encoding = null) {
if (null === $encoding) { return F::strpos($string, $needle, $offset);
$encoding = mb_internal_encoding();
}
return (extension_loaded('mbstring')) ? mb_strpos($string, $needle, $offset, $encoding) : strpos($string, $needle, $offset);
} }
public static function string_last_position(string $string, string $needle, int $offset = 0, $encoding = null) { public static function string_last_position(string $string, string $needle, int $offset = 0, $encoding = null) {
if (null === $encoding) { return F::strrpos($string, $needle, $offset);
$encoding = mb_internal_encoding();
}
return (extension_loaded('mbstring')) ? mb_strrpos($string, $needle, $offset, $encoding) : strrpos($string, $needle, $offset);
} }
public static function string_trim($string, $charlist = null) { public static function string_trim($string, $charlist = null) {
if (is_null($charlist)) { if (is_null($charlist)) {
return trim($string); return F::trim($string);
} else { } else {
$charlist = preg_quote($charlist, '/'); $charlist = preg_quote($charlist, '/');
return preg_replace("/(^[$charlist]+)|([$charlist]+$)/us", '', $string); return preg_replace("/(^[$charlist]+)|([$charlist]+$)/us", '', $string);
@ -126,7 +101,7 @@ final class common {
public static function string_rtrim($string, $charlist = null) { public static function string_rtrim($string, $charlist = null) {
if (is_null($charlist)) { if (is_null($charlist)) {
return rtrim($string); return F::rtrim($string);
} else { } else {
$charlist = preg_quote($charlist, '/'); $charlist = preg_quote($charlist, '/');
return preg_replace("/([$charlist]+$)/us", '', $string); return preg_replace("/([$charlist]+$)/us", '', $string);
@ -135,7 +110,7 @@ final class common {
public static function string_ltrim($string, $charlist = null) { public static function string_ltrim($string, $charlist = null) {
if (is_null($charlist)) { if (is_null($charlist)) {
return ltrim($string); return F::ltrim($string);
} else { } else {
$charlist = preg_quote($charlist, '/'); $charlist = preg_quote($charlist, '/');
return preg_replace("/(^[$charlist]+)/us", '', $string); return preg_replace("/(^[$charlist]+)/us", '', $string);
@ -143,10 +118,7 @@ final class common {
} }
public static function string_cmp($str1, $str2, $encoding = null) { public static function string_cmp($str1, $str2, $encoding = null) {
if (null === $encoding) { return strcmp(F::strtoupper($str1, $encoding), F::strtoupper($str2, $encoding));
$encoding = mb_internal_encoding();
}
return strcmp(mb_strtoupper($str1, $encoding), mb_strtoupper($str2, $encoding));
} }
/* /*
@ -154,22 +126,14 @@ final class common {
*/ */
public static function string_first_position(string $string, string $needle, int $offset = 0, $encoding = null) { public static function string_first_position(string $string, string $needle, int $offset = 0, $encoding = null) {
if (null === $encoding) { return F::stripos($string, $needle, $offset);
$encoding = mb_internal_encoding();
}
return (extension_loaded('mbstring')) ? mb_stripos($string, $needle, $offset, $encoding) : stripos($string, $needle, $offset);
} }
public static function string_sub_part(string $string, int $offset = 0, int $length = null, $encoding = null) { public static function string_sub_part(string $string, int $offset = 0, int $length = null, $encoding = null) {
if (null === $encoding) {
$encoding = mb_internal_encoding();
}
if ($length === null) { if ($length === null) {
return (extension_loaded('mbstring')) ? mb_substr($string, $offset, self::string_length($string), $encoding) : substr($string, $offset, strlen($string)); return F::substr($string, $offset, strlen($string));
} else { } else {
return (extension_loaded('mbstring')) ? mb_substr($string, $offset, $length, $encoding) : substr($string, $offset, $length); return F::substr($string, $offset, $length);
} }
} }
@ -204,7 +168,7 @@ final class common {
} }
} }
/** /**
* Will get only the right part of string by length. * Will get only the right part of string by length.
* @param string $str * @param string $str
* @param int $length * @param int $length

@ -88,12 +88,12 @@ class model {
foreach(SafeIO::db_sanitize($input) as $data) { foreach(SafeIO::db_sanitize($input) as $data) {
$key = $data['name'] ?? false; $key = $data['name'] ?? false;
$value = $data['db'] ?? null; $value = $data['db'] ?? null;
$error_count = (isset($data['errors'])) ? \CodeHydrater\bootstrap\common::get_count($data['errors']) : 0; $error_count = (isset($data['errors'])) ? \CodeHydrater\common::get_count($data['errors']) : 0;
if ($error_count) { if ($error_count) {
return false; return false;
} }
if (isset($data['meta']['missing']) && \CodeHydrater\bootstrap\common::get_count($data['meta']['missing'])) { if (isset($data['meta']['missing']) && \CodeHydrater\common::get_count($data['meta']['missing'])) {
$this->missing = $data['meta']['missing']; $this->missing = $data['meta']['missing'];
} }
@ -362,11 +362,11 @@ class model {
$safe_key = addslashes($key); $safe_key = addslashes($key);
$parm = ($bind) ? ":{$safe_text}" : "'{$safe_text}'"; $parm = ($bind) ? ":{$safe_text}" : "'{$safe_text}'";
$ret = "HEX(AES_ENCRYPT($parm},'{$safe_key}'))"; $ret = "HEX(AES_ENCRYPT($parm},'{$safe_key}'))";
\CodeHydrater\bootstrap\common::wipe($key); \CodeHydrater\common::wipe($key);
\CodeHydrater\bootstrap\common::wipe($safe_key); \CodeHydrater\common::wipe($safe_key);
\CodeHydrater\bootstrap\common::wipe($data); \CodeHydrater\common::wipe($data);
\CodeHydrater\bootstrap\common::wipe($safe_text); \CodeHydrater\common::wipe($safe_text);
\CodeHydrater\bootstrap\common::wipe($parm); \CodeHydrater\scommon::wipe($parm);
return $ret; return $ret;
} }

@ -38,7 +38,7 @@ class html_document {
$this->description = bootstrap\configure::get('html', 'description') ?? ''; $this->description = bootstrap\configure::get('html', 'description') ?? '';
$this->robots = bootstrap\configure::get('html', 'robots'); $this->robots = bootstrap\configure::get('html', 'robots');
$css = bootstrap\configure::get('html', 'css'); $css = bootstrap\configure::get('html', 'css');
if (bootstrap\common::get_count($css) > 0) { if (common::get_count($css) > 0) {
foreach($css as $file=>$path) { foreach($css as $file=>$path) {
if (is_array($file)) continue; if (is_array($file)) continue;
if (is_array($path)) { if (is_array($path)) {
@ -55,7 +55,7 @@ class html_document {
} }
} }
$js = bootstrap\configure::get('html', 'javascript'); $js = bootstrap\configure::get('html', 'javascript');
if (bootstrap\common::get_count($js) >0) { if (common::get_count($js) >0) {
foreach($js as $file=>$path) { foreach($js as $file=>$path) {
if (is_array($file)) continue; if (is_array($file)) continue;
if (is_array($path)) { if (is_array($path)) {

@ -29,7 +29,7 @@ final class memory_usage {
public static function get_memory_stats($echo = true) { public static function get_memory_stats($echo = true) {
global $mem_baseline; global $mem_baseline;
$check = bootstrap\common::get_bool(misc::request_var('debug')); $check = common::get_bool(misc::request_var('debug'));
if ($check || defined('DEBUG') && DEBUG === true) { if ($check || defined('DEBUG') && DEBUG === true) {
$now_mem = memory_get_usage(); $now_mem = memory_get_usage();

@ -50,7 +50,7 @@ final class misc {
if ($var === null || $var2 === null) { if ($var === null || $var2 === null) {
return false; return false;
} }
return (bootstrap\common::string_to_lowercase(trim($var)) === bootstrap\common::string_to_lowercase(trim($var2))); return (\CodeHydrater\strings\string_facade::strtolower(\CodeHydrater\strings\string_facade::trim($var)) === \CodeHydrater\strings\string_facade::strtolower(\CodeHydrater\strings\string_facade::trim($var2)));
} }
/** /**
@ -59,7 +59,7 @@ final class misc {
* @retval string * @retval string
*/ */
public static function safe_lowercase_trim(string $var): string { public static function safe_lowercase_trim(string $var): string {
return (bootstrap\common::string_to_lowercase(trim($var))); return (\CodeHydrater\strings\string_facade::strtolower(\CodeHydrater\strings\string_facade::trim($var)));
} }
/** /**
@ -284,8 +284,8 @@ final class misc {
$dot_position = strpos($method, '.'); $dot_position = strpos($method, '.');
if ($dot_position !== false) { if ($dot_position !== false) {
$offset = strlen($method) - $dot_position; $offset = strlen($method) - $dot_position;
$ext = \CodeHydrater\bootstrap\common::get_string_right($method, $offset); $ext = \CodeHydrater\common::get_string_right($method, $offset);
$method = \CodeHydrater\bootstrap\common::get_string_left($method, $dot_position); $method = \CodeHydrater\common::get_string_left($method, $dot_position);
} else { } else {
$ext = ".html"; $ext = ".html";
} }

@ -61,7 +61,7 @@ class random_engine {
} }
private function select_from_array(array $a, int $num ): array { private function select_from_array(array $a, int $num ): array {
$array_count = \CodeHydrater\bootstrap\common::get_count($a) - 1; $array_count = \CodeHydrater\common::get_count($a) - 1;
if ($array_count < 1) { if ($array_count < 1) {
return []; return [];
} }

@ -48,7 +48,7 @@ class emailer {
$default = (isset($value[0])) ? $value[0] : null; $default = (isset($value[0])) ? $value[0] : null;
switch (\CodeHydrater\bootstrap\common::string_to_lowercase($key)) { switch (strtolower($key)) {
case 'to': case 'to':
if (is_array($value)) { if (is_array($value)) {
$mto = (isset($value['addresses']) && is_array($value['addresses'])) ? $value['addresses'] : false; $mto = (isset($value['addresses']) && is_array($value['addresses'])) ? $value['addresses'] : false;

@ -269,11 +269,11 @@ md5-128 0.77
OPENSSL_RAW_DATA, OPENSSL_RAW_DATA,
$iv $iv
); );
\CodeHydrater\bootstrap\common::wipe($text); \CodeHydrater\common::wipe($text);
\CodeHydrater\bootstrap\common::wipe($key); \CodeHydrater\common::wipe($key);
\CodeHydrater\bootstrap\common::wipe($encKey); \CodeHydrater\common::wipe($encKey);
$hmac = hash_hmac($this->default_hash, $iv . $ciphertext, $hmacKey); $hmac = hash_hmac($this->default_hash, $iv . $ciphertext, $hmacKey);
\CodeHydrater\bootstrap\common::wipe($hmacKey); \CodeHydrater\common::wipe($hmacKey);
if (! $this->binary) { if (! $this->binary) {
return (! $this->url_encode) ? base64_encode($hmac . $iv . $ciphertext) : \CodeHydrater\misc::base64url_encode($hmac . $iv . $ciphertext); return (! $this->url_encode) ? base64_encode($hmac . $iv . $ciphertext) : \CodeHydrater\misc::base64url_encode($hmac . $iv . $ciphertext);
} else { } else {
@ -312,10 +312,10 @@ md5-128 0.77
OPENSSL_RAW_DATA, OPENSSL_RAW_DATA,
$iv $iv
); );
\CodeHydrater\bootstrap\common::wipe($ciphertext); \CodeHydrater\common::wipe($ciphertext);
\CodeHydrater\bootstrap\common::wipe($key); \CodeHydrater\common::wipe($key);
\CodeHydrater\bootstrap\common::wipe($encKey); \CodeHydrater\common::wipe($encKey);
\CodeHydrater\bootstrap\common::wipe($keys); \CodeHydrater\common::wipe($keys);
return $ret; return $ret;
} }
@ -339,7 +339,7 @@ md5-128 0.77
} }
$ret = bin2hex(pack('H*', $key)); $ret = bin2hex(pack('H*', $key));
\CodeHydrater\bootstrap\common::wipe($key); \CodeHydrater\common::wipe($key);
return $ret; return $ret;
} }

@ -43,7 +43,7 @@ final class log {
// $success = @touch($file); // $success = @touch($file);
if ($success === false) { if ($success === false) {
$this->handle = false; $this->handle = false;
\CodeHydrater\bootstrap\common::dump($file); \CodeHydrater\common::dump($file);
return false; return false;
} }

@ -68,7 +68,7 @@ final class session_management {
if ($rights === false) { if ($rights === false) {
return false; return false;
} }
if (! bootstrap\common::is_json($right)) { if (! common::is_json($right)) {
return false; return false;
} }
$assoc = true; // Use Array format $assoc = true; // Use Array format

@ -21,6 +21,10 @@ class mb_string_fns {
return strlen($string) !== mb_strlen($string, 'UTF-8'); return strlen($string) !== mb_strlen($string, 'UTF-8');
} }
public static function str_contains(string $haystack, string $needle) {
return $needle !== '' && mb_strpos($haystack, $needle) !== false;
}
// Return character by Unicode code point value // Return character by Unicode code point value
public static function chr(int $codepoint, ?string $encoding = null): string|false { public static function chr(int $codepoint, ?string $encoding = null): string|false {
return mb_chr($codepoint, $encoding); return mb_chr($codepoint, $encoding);

@ -70,7 +70,12 @@ class string_fns {
public static function has_multibyte_chars(string $string) { public static function has_multibyte_chars(string $string) {
return (bool) preg_match('/[\xC2-\xDF][\x80-\xBF]|\xE0[\xA0-\xBF][\x80-\xBF]|[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}|\xED[\x80-\x9F][\x80-\xBF]|\xF0[\x90-\xBF][\x80-\xBF]{2}|[\xF1-\xF3][\x80-\xBF]{3}|\xF4[\x80-\x8F][\x80-\xBF]{2}/', $string); return (bool) preg_match('/[\xC2-\xDF][\x80-\xBF]|\xE0[\xA0-\xBF][\x80-\xBF]|[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}|\xED[\x80-\x9F][\x80-\xBF]|\xF0[\x90-\xBF][\x80-\xBF]{2}|[\xF1-\xF3][\x80-\xBF]{3}|\xF4[\x80-\x8F][\x80-\xBF]{2}/', $string);
} }
// Return character by Unicode code point value
public static function str_contains(string $haystack, string $needle) {
return $needle !== '' && strpos($haystack, $needle) !== false;
}
// Return character by Unicode code point value
public static function chr(int $codepoint): string|false { public static function chr(int $codepoint): string|false {
return chr($codepoint); return chr($codepoint);
} }

@ -23,7 +23,7 @@ const tags_to_check = array('div', 'span', 'form', 'i*', 'a*', 'h1', 'p*');
public static function check_tags(string $page): array { public static function check_tags(string $page): array {
$alert = ''; $alert = '';
$output = ''; $output = '';
$l_page = bootstrap\common::string_to_lowercase($page); $l_page = \CodeHydrater\strings\string_facade::strtolower($page);
unset($page); unset($page);
$assets = "/assets/uikit/css/uikit.gradient.min.css"; $assets = "/assets/uikit/css/uikit.gradient.min.css";
@ -32,7 +32,7 @@ public static function check_tags(string $page): array {
$ui_end = '</b></div>'; $ui_end = '</b></div>';
foreach (self::tags_to_check as $tag_name) { foreach (self::tags_to_check as $tag_name) {
if (bootstrap\common::is_string_found($tag_name, '*')) { if (common::is_string_found($tag_name, '*')) {
$tag_name = str_replace('*', '', $tag_name); $tag_name = str_replace('*', '', $tag_name);
$otag = "<{$tag_name}>"; // Open Tag $otag = "<{$tag_name}>"; // Open Tag
$open = substr_count($l_page, $otag); // Count open tags in page $open = substr_count($l_page, $otag); // Count open tags in page

@ -46,7 +46,7 @@ final class time_zones {
} }
private static function mdy($userTime, $format) { private static function mdy($userTime, $format) {
switch (bootstrap\common::string_to_lowercase($format)) { switch (\CodeHydrater\strings\string_facade::strtolower($format)) {
case 'actions': case 'actions':
return $userTime->format('m-d-Y / h:iA'); return $userTime->format('m-d-Y / h:iA');
case 'report': case 'report':
@ -74,7 +74,7 @@ final class time_zones {
} }
private static function dmy($userTime, $format) { private static function dmy($userTime, $format) {
switch (bootstrap\common::string_to_lowercase($format)) { switch (\CodeHydrater\strings\string_facade::strtolower($format)) {
case 'actions': case 'actions':
return $userTime->format('d-m-Y / h:iA'); return $userTime->format('d-m-Y / h:iA');
case 'report': case 'report':
@ -102,7 +102,7 @@ final class time_zones {
} }
private static function ymd($userTime, $format) { private static function ymd($userTime, $format) {
switch (bootstrap\common::string_to_lowercase($format)) { switch (\CodeHydrater\strings\string_facade::strtolower($format)) {
case 'actions': case 'actions':
return $userTime->format('Y-m-d / h:iA'); return $userTime->format('Y-m-d / h:iA');
case 'report': case 'report':
@ -130,7 +130,7 @@ final class time_zones {
} }
public static function dt_format($userTime, $format, $country) { public static function dt_format($userTime, $format, $country) {
switch (bootstrap\common::string_to_lowercase($format)) { switch (\CodeHydrater\strings\string_facade::strtolower($format)) {
case 'object': case 'object':
return $userTime; return $userTime;
case 'unix': case 'unix':
@ -171,7 +171,7 @@ final class time_zones {
return $userTime->format('Y-m-d H:i:s'); return $userTime->format('Y-m-d H:i:s');
} }
switch (bootstrap\common::string_to_lowercase($country)) { switch (\CodeHydrater\strings\string_facade::strtolower($country)) {
case 'china': case 'china':
return self::ymd($userTime, $format); return self::ymd($userTime, $format);
case 'int': case 'int':

@ -8,7 +8,7 @@ trait run_sql {
public function run($sql, $bind=""): int { public function run($sql, $bind=""): int {
$pdostmt = $this->pdo->prepare(trim($sql)); $pdostmt = $this->pdo->prepare(trim($sql));
if (\CodeHydrater\bootstrap\common::get_count($bind) > 0) { if (\CodeHydrater\common::get_count($bind) > 0) {
$exec = $pdostmt->execute($bind); $exec = $pdostmt->execute($bind);
} else { } else {
$exec = $pdostmt->execute(); $exec = $pdostmt->execute();

@ -17,7 +17,7 @@ trait validation {
* @retval bool true valid, false failed tests * @retval bool true valid, false failed tests
*/ */
public function validate_mysql(): bool { public function validate_mysql(): bool {
$tbl = (\CodeHydrater\bootstrap\common::is_string_found($this->table, "`")) ? $this->table : "`{$this->table}`"; $tbl = (\CodeHydrater\common::is_string_found($this->table, "`")) ? $this->table : "`{$this->table}`";
foreach ($this->members as $field => $value) { foreach ($this->members as $field => $value) {
if ($field == $this->primary_key) { if ($field == $this->primary_key) {
continue; continue;
@ -61,7 +61,7 @@ trait validation {
case 'NEWDECIMAL': case 'NEWDECIMAL':
$prec = intval($meta['precision']); $prec = intval($meta['precision']);
$maxlen = $len - $prec; $maxlen = $len - $prec;
if (!\CodeHydrater\bootstrap\common::is_string_found($value, '.')) { if (!\CodeHydrater\common::is_string_found($value, '.')) {
$this->do_verr("Failed Validation: No Decimal Found in field {$field}"); $this->do_verr("Failed Validation: No Decimal Found in field {$field}");
return false; return false;
} }
@ -169,7 +169,7 @@ trait validation {
public function is_valid_mysql_date(string $str): bool { public function is_valid_mysql_date(string $str): bool {
$date_parts = explode('-', $str); $date_parts = explode('-', $str);
if (\CodeHydrater\bootstrap\common::count($date_parts) != 3) if (\CodeHydrater\common::count($date_parts) != 3)
return false; return false;
if ((strlen($date_parts[0]) != 4) || (!is_numeric($date_parts[0]))) if ((strlen($date_parts[0]) != 4) || (!is_numeric($date_parts[0])))
return false; return false;

@ -30,7 +30,7 @@ class validator {
private static function make_arrays(array $data, $field): array { private static function make_arrays(array $data, $field): array {
$dataset = []; $dataset = [];
if (isset($data[$field])) { if (isset($data[$field])) {
if (bootstrap\common::get_count($data[$field])) { if (common::get_count($data[$field])) {
foreach($data[$field] as $the_data) { foreach($data[$field] as $the_data) {
$dataset[] = $the_data; $dataset[] = $the_data;
} }
@ -100,7 +100,7 @@ class validator {
private static function is_required(array $data, string $field): bool { private static function is_required(array $data, string $field): bool {
if (isset($data[$field])) { if (isset($data[$field])) {
if (bootstrap\common::get_count($data[$field])) { if (common::get_count($data[$field])) {
return false; // Should not be an array here return false; // Should not be an array here
} }
if (is_string($data[$field])) { if (is_string($data[$field])) {

@ -222,7 +222,7 @@ final class view {
$page_output .= ob_get_clean(); $page_output .= ob_get_clean();
try { try {
if (bootstrap\common::get_bool(bootstrap\configure::get('CodeHydrater', 'check_HTML_tags')) === true) { if (common::get_bool(bootstrap\configure::get('CodeHydrater', 'check_HTML_tags')) === true) {
$tags = \CodeHydrater\tag_matches::check_tags($page_output); $tags = \CodeHydrater\tag_matches::check_tags($page_output);
if (! empty($tags['output'])) { if (! empty($tags['output'])) {
$page_output .= $tags['output']; $page_output .= $tags['output'];

Loading…
Cancel
Save