diff --git a/www/admin/class_test.array.php b/www/admin/class_test.array.php index 57ae270c..0f9f7d8c 100644 --- a/www/admin/class_test.array.php +++ b/www/admin/class_test.array.php @@ -23,16 +23,14 @@ if (!defined('SET_SESSION_NAME')) { define('SET_SESSION_NAME', EDIT_SESSION_NAME); } // define log file id -$LOG_FILE_ID = 'classTest-datetime'; +$LOG_FILE_ID = 'classTest-array'; ob_end_flush(); use CoreLibs\Combined\ArrayHandler; $basic = new CoreLibs\Basic(); -$_array= new CoreLibs\Combined\ArrayHandler(); -$array_class = 'CoreLibs\Combination\ArrayHandler'; - -// define a list of from to color sets for conversion test +// $_array= new CoreLibs\Combined\ArrayHandler(); +// $array_class = 'CoreLibs\Combination\ArrayHandler'; print "
tag added
+ * DEPRCATE LATER
+ * @_deprecated Use \CoreLibs\Debug\Support::printAr() instead
*/
public static function printAr(array $array): string
{
- return "".print_r($array, true)."
";
+ return \CoreLibs\Debug\Support::printAr($array);
}
+ /**
+ * if there is a need to find out which parent method called a child method,
+ * eg for debugging, this function does this
+ * call this method in the child method and you get the parent function that called
+ * @param int $level debug level, default 2
+ * @return ?string null or the function that called the function where this method is called
+ * @deprecated Use \CoreLibs\Debug\Support::getCallerMethod() instead
+ */
+ public static function getCallerMethod(int $level = 2): ?string
+ {
+ trigger_error('Method '.__METHOD__.' is deprecated, use \CoreLibs\Debug\Support::getCallerMethod()', E_USER_DEPRECATED);
+ return \CoreLibs\Debug\Support::getCallerMethod($level);
+ }
+
+ // *** SYSTEM HANDLING
+ // [!!! DEPRECATED !!!]
+ // Moved to \CoreLibs\Get\System
+
/**
* helper function for PHP file upload error messgaes to messge string
* @param int $error_code integer _FILE upload error code
* @return string message string, translated
+ * @deprecated Use \CoreLibs\Get\System::fileUploadErrorMessage() instead
*/
public function fileUploadErrorMessage(int $error_code): string
{
- switch ($error_code) {
- case UPLOAD_ERR_INI_SIZE:
- $message = 'The uploaded file exceeds the upload_max_filesize directive in php.ini';
- break;
- case UPLOAD_ERR_FORM_SIZE:
- $message = 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form';
- break;
- case UPLOAD_ERR_PARTIAL:
- $message = 'The uploaded file was only partially uploaded';
- break;
- case UPLOAD_ERR_NO_FILE:
- $message = 'No file was uploaded';
- break;
- case UPLOAD_ERR_NO_TMP_DIR:
- $message = 'Missing a temporary folder';
- break;
- case UPLOAD_ERR_CANT_WRITE:
- $message = 'Failed to write file to disk';
- break;
- case UPLOAD_ERR_EXTENSION:
- $message = 'File upload stopped by extension';
- break;
- default:
- $message = 'Unknown upload error';
- break;
- }
- return $message;
+ trigger_error('Method '.__METHOD__.' is deprecated, use \CoreLibs\Get\System::fileUploadErrorMessage()', E_USER_DEPRECATED);
+ return \CoreLibs\Get\System::fileUploadErrorMessage($error_code);
}
// ****** DEBUG/ERROR FUNCTIONS ******
// ****** RANDOM KEY GEN ******
-
- // METHOD: initRandomKeyData
- // PARAMS: none
- // RETURN: none
- // DESC : sets the random key range with the default values
- /**
- * sets the random key range with the default values
- * @return void has no return
- */
- private function initRandomKeyData()
- {
- // random key generation
- $this->key_range = array_merge(range('A', 'Z'), range('a', 'z'), range('0', '9'));
- $this->one_key_length = count($this->key_range);
- // pow($this->one_key_length, 4);
- // default set to 4, should be more than enought (62*62*62*62)
- $this->key_length = 4;
- }
-
- /**
- * validates they key length for random string generation
- * @param int $key_length key length
- * @return bool true for valid, false for invalid length
- */
- private function validateRandomKeyLenght(int $key_length): bool
- {
- if (is_numeric($key_length) &&
- $key_length > 0 &&
- $key_length <= $this->max_key_length
- ) {
- return true;
- } else {
- return false;
- }
- }
+ // [!!! DEPRECATED !!!]
+ // Moved to \CoreLibs\Create\RandomKey
/**
* sets the key length and checks that they key given is valid
* if failed it will not change the default key length and return false
* @param int $key_length key length
* @return bool true/false for set status
+ * @deprecated Use \CoreLibs\Create\RandomKey::setRandomKeyLength() instead
*/
public function initRandomKeyLength(int $key_length): bool
{
- // only if valid int key with valid length
- if ($this->validateRandomKeyLenght($key_length) === true) {
- $this->key_length = $key_length;
- return true;
- } else {
- return false;
- }
+ trigger_error('Method '.__METHOD__.' is deprecated, use \CoreLibs\Create\RandomKey::setRandomKeyLength()', E_USER_DEPRECATED);
+ return \CoreLibs\Create\RandomKey::setRandomKeyLength($key_length);
}
/**
@@ -893,25 +669,17 @@ class Basic
* this will not set the class key length variable
* @param int $key_length key length override, -1 for use default
* @return string random key
+ * @deprecated Use \CoreLibs\Create\RandomKey::randomKeyGen() instead
*/
public function randomKeyGen(int $key_length = -1): string
{
- $use_key_length = 0;
- // only if valid int key with valid length
- if ($this->validateRandomKeyLenght($key_length) === true) {
- $use_key_length = $key_length;
- } else {
- $use_key_length = $this->key_length;
- }
-
- $pieces = [];
- for ($i = 1; $i <= $use_key_length; $i ++) {
- $pieces[] = $this->key_range[random_int(0, $this->one_key_length - 1)];
- }
- return join('', $pieces);
+ trigger_error('Method '.__METHOD__.' is deprecated, use \CoreLibs\Create\RandomKey::randomKeyGen()', E_USER_DEPRECATED);
+ return \CoreLibs\Create\RandomKey::randomKeyGen($key_length);
}
- // ****** RANDOM KEY GEN ******
+ // ****** MAGIC LINK/CHECKED/SELECTED ******
+ // [!!! DEPRECATED !!!]
+ // Moved to \CoreLibs\Output\Form\Elements
/**
* returns 'checked' or 'selected' if okay
@@ -944,24 +712,19 @@ class Basic
return \CoreLibs\Output\Form\Elements::magicLinks($string, $target);
}
+ // *** SYSTEM HANDLING
+ // [!!! DEPRECATED !!!]
+ // Moved to \CoreLibs\Get\System
+
/**
* get the host name without the port as given by the SELF var
- * @return string host name
+ * @return array host name/port name
+ * @deprecated Use \CoreLibs\Get\System::getHostName() instead
*/
- public function getHostName(): string
+ public function getHostName(): array
{
- $port = '';
- if ($_SERVER['HTTP_HOST'] && preg_match("/:/", $_SERVER['HTTP_HOST'])) {
- list($host_name, $port) = explode(":", $_SERVER['HTTP_HOST']);
- } elseif ($_SERVER['HTTP_HOST']) {
- $host_name = $_SERVER['HTTP_HOST'];
- } else {
- $host_name = 'NA';
- }
- $this->host_port = $port ? $port : 80;
- $this->host_name = $host_name;
- // also return for old type call
- return $host_name;
+ trigger_error('Method '.__METHOD__.' is deprecated, use \CoreLibs\Get\System::getHostName()', E_USER_DEPRECATED);
+ return \CoreLibs\Get\System::getHostName();
}
/**
@@ -970,20 +733,18 @@ class Basic
* 0: keep filename as is
* 2: keep filename as is, but add dirname too
* @return string filename
+ * @deprecated Use \CoreLibs\Get\System::getPageName() instead
*/
public static function getPageName(int $strip_ext = 0): string
{
- // get the file info
- $page_temp = pathinfo($_SERVER['PHP_SELF']);
- if ($strip_ext == 1) {
- return $page_temp['filename'];
- } elseif ($strip_ext == 2) {
- return $_SERVER['PHP_SELF'];
- } else {
- return $page_temp['basename'];
- }
+ trigger_error('Method '.__METHOD__.' is deprecated, use \CoreLibs\Get\System::getPageName()', E_USER_DEPRECATED);
+ return \CoreLibs\Get\System::getPageName($strip_ext);
}
+ // *** FILE HANDLING
+ // [!!! DEPRECATED !!!]
+ // Moved to \CoreLibs\Check\File
+
/**
* quick return the extension of the given file name
* @param string $filename file name
@@ -1009,6 +770,8 @@ class Basic
}
// *** ARRAY HANDLING
+ // [!!! DEPRECATED !!!]
+ // Moved to \CoreLibs\Combined\ArrayHandler
/**
* searches key = value in an array / array
@@ -1174,6 +937,8 @@ class Basic
}
// *** ARRAY HANDLING END
+ // [!!! DEPRECATED !!!]
+ // Moved to \CoreLibs\Language\Encoding
/**
* wrapper function for mb mime convert, for correct conversion with long strings
diff --git a/www/lib/CoreLibs/Check/Email.php b/www/lib/CoreLibs/Check/Email.php
index 02c0013d..263b31a7 100644
--- a/www/lib/CoreLibs/Check/Email.php
+++ b/www/lib/CoreLibs/Check/Email.php
@@ -4,76 +4,109 @@ namespace CoreLibs\Check;
class Email
{
- private static $mobile_email_type = [];
- private static $mobile_email_type_short = [];
+ // this is for error check parts in where the email regex failed
+ private static $email_regex_check = [
+ 0 => "^[A-Za-z0-9!#$%&'*+\-\/=?^_`{|}~][A-Za-z0-9!#$%:\(\)&'*+\-\/=?^_`{|}~\.]{0,63}@[a-zA-Z0-9\-]+(\.[a-zA-Z0-9\-]{1,})*\.([a-zA-Z]{2,}){1}$", // MASTER
+ 1 => "@(.*)@(.*)", // double @
+ 2 => "^[A-Za-z0-9!#$%&'*+-\/=?^_`{|}~][A-Za-z0-9!#$%:\(\)&'*+-\/=?^_`{|}~\.]{0,63}@", // wrong part before @
+ 3 => "@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]{1,})*\.([a-zA-Z]{2,}){1}$", // wrong part after @
+ 4 => "@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]{1,})*\.", // wrong domain name part
+ 5 => "\.([a-zA-Z]{2,6}){1}$", // wrong top level part
+ 6 => "@(.*)\.{2,}", // double .. in domain name part
+ 7 => "@.*\.$" // ends with a dot, top level, domain missing
+ ];
+ // the array with the mobile types that are valid
+ private static $mobile_email_type = [
+ '.*@docomo\.ne\.jp$' => 'keitai_docomo',
+ '.*@([a-z0-9]{2}\.)?ezweb\.ne\.jp$' => 'keitai_kddi_ezweb', # correct are a[2-4], b2, c[1-9], e[2-9], h[2-4], t[1-9]
+ '.*@(ez[a-j]{1}\.)?ido\.ne\.jp$' => 'keitai_kddi_ido', # ez[a-j] or nothing
+ '.*@([a-z]{2}\.)?sky\.tu-ka\.ne\.jp$' => 'keitai_kddi_tu-ka', # (sky group)
+ '.*@([a-z]{2}\.)?sky\.tk[kc]{1}\.ne\.jp$' => 'keitai_kddi_sky', # (sky group) [tkk,tkc only]
+ '.*@([a-z]{2}\.)?sky\.dtg\.ne\.jp$' => 'keitai_kddi_dtg', # dtg (sky group)
+ '.*@[tkdhcrnsq]{1}\.vodafone\.ne\.jp$' => 'keitai_softbank_vodafone', # old vodafone [t,k,d,h,c,r,n,s,q]
+ '.*@jp-[dhtkrsnqc]{1}\.ne\.jp$' => 'keitai_softbank_j-phone', # very old j-phone (pre vodafone) [d,h,t,k,r,s,n,q,c]
+ '.*@([dhtcrknsq]{1}\.)?softbank\.ne\.jp$' => 'keitai_softbank', # add i for iphone also as keitai, others similar to the vodafone group
+ '.*@i{1}\.softbank(\.ne)?\.jp$' => 'smartphone_softbank_iphone', # add iPhone also as keitai and not as pc
+ '.*@disney\.ne\.jp$' => 'keitai_softbank_disney', # (kids)
+ '.*@willcom\.ne\.jp$' => 'keitai_willcom',
+ '.*@willcom\.com$' => 'keitai_willcom', # new for pdx.ne.jp address
+ '.*@willcom\.com$' => 'keitai_willcom', # new for pdx.ne.jp address
+ '.*@wcm\.ne\.jp$' => 'keitai_willcom', # old willcom wcm.ne.jp
+ '.*@pdx\.ne\.jp$' => 'keitai_willcom_pdx', # old pdx address for willcom
+ '.*@bandai\.jp$' => 'keitai_willcom_bandai', # willcom paipo! (kids)
+ '.*@pipopa\.ne\.jp$' => 'keitai_willcom_pipopa', # willcom paipo! (kids)
+ '.*@([a-z0-9]{2,4}\.)?pdx\.ne\.jp$' => 'keitai_willcom_pdx', # actually only di,dj,dk,wm -> all others are "wrong", but none also allowed?
+ '.*@ymobile([1]{1})?\.ne\.jp$' => 'keitai_willcom_ymobile', # ymobile, ymobile1 techincally not willcom, but I group them there (softbank sub)
+ '.*@y-mobile\.ne\.jp$' => 'keitai_willcom_ymobile', # y-mobile techincally not willcom, but I group them there (softbank sub)
+ '.*@emnet\.ne\.jp$' => 'keitai_willcom_emnet', # e-mobile, group will willcom
+ '.*@emobile\.ne\.jp$' => 'keitai_willcom_emnet', # e-mobile, group will willcom
+ '.*@emobile-s\.ne\.jp$' => 'keitai_willcom_emnet' # e-mobile, group will willcom
+ ];
+ // short list for mobile email types
+ private static $mobile_email_type_short = [
+ 'keitai_docomo' => 'docomo',
+ 'keitai_kddi_ezweb' => 'kddi',
+ 'keitai_kddi' => 'kddi',
+ 'keitai_kddi_tu-ka' => 'kddi',
+ 'keitai_kddi_sky' => 'kddi',
+ 'keitai_softbank' => 'softbank',
+ 'smartphone_softbank_iphone' => 'iphone',
+ 'keitai_softbank_disney' => 'softbank',
+ 'keitai_softbank_vodafone' => 'softbank',
+ 'keitai_softbank_j-phone' => 'softbank',
+ 'keitai_willcom' => 'willcom',
+ 'keitai_willcom_pdx' => 'willcom',
+ 'keitai_willcom_bandai' => 'willcom',
+ 'keitai_willcom_pipopa' => 'willcom',
+ 'keitai_willcom_ymobile' => 'willcom',
+ 'keitai_willcom_emnet' => 'willcom',
+ 'pc_html' => 'pc',
+ // old sets -> to be removed later
+ 'docomo' => 'docomo',
+ 'kddi_ezweb' => 'kddi',
+ 'kddi' => 'kddi',
+ 'kddi_tu-ka' => 'kddi',
+ 'kddi_sky' => 'kddi',
+ 'softbank' => 'softbank',
+ 'keitai_softbank_iphone' => 'iphone',
+ 'softbank_iphone' => 'iphone',
+ 'softbank_disney' => 'softbank',
+ 'softbank_vodafone' => 'softbank',
+ 'softbank_j-phone' => 'softbank',
+ 'willcom' => 'willcom',
+ 'willcom_pdx' => 'willcom',
+ 'willcom_bandai' => 'willcom',
+ 'willcom_pipopa' => 'willcom',
+ 'willcom_ymobile' => 'willcom',
+ 'willcom_emnet' => 'willcom',
+ 'pc' => 'pc'
+ ];
- public function __construct()
+ /**
+ * Undocumented function
+ *
+ * @param int $type Which position in the regex list to get
+ * if not set or not valid get default pos 0
+ * @return string
+ */
+ public static function getEmailRegex(int $type = 0): string
{
- // the array with the mobile types that are valid
- self::$mobile_email_type = [
- '.*@docomo\.ne\.jp$' => 'keitai_docomo',
- '.*@([a-z0-9]{2}\.)?ezweb\.ne\.jp$' => 'keitai_kddi_ezweb', # correct are a[2-4], b2, c[1-9], e[2-9], h[2-4], t[1-9]
- '.*@(ez[a-j]{1}\.)?ido\.ne\.jp$' => 'keitai_kddi_ido', # ez[a-j] or nothing
- '.*@([a-z]{2}\.)?sky\.tu-ka\.ne\.jp$' => 'keitai_kddi_tu-ka', # (sky group)
- '.*@([a-z]{2}\.)?sky\.tk[kc]{1}\.ne\.jp$' => 'keitai_kddi_sky', # (sky group) [tkk,tkc only]
- '.*@([a-z]{2}\.)?sky\.dtg\.ne\.jp$' => 'keitai_kddi_dtg', # dtg (sky group)
- '.*@[tkdhcrnsq]{1}\.vodafone\.ne\.jp$' => 'keitai_softbank_vodafone', # old vodafone [t,k,d,h,c,r,n,s,q]
- '.*@jp-[dhtkrsnqc]{1}\.ne\.jp$' => 'keitai_softbank_j-phone', # very old j-phone (pre vodafone) [d,h,t,k,r,s,n,q,c]
- '.*@([dhtcrknsq]{1}\.)?softbank\.ne\.jp$' => 'keitai_softbank', # add i for iphone also as keitai, others similar to the vodafone group
- '.*@i{1}\.softbank(\.ne)?\.jp$' => 'smartphone_softbank_iphone', # add iPhone also as keitai and not as pc
- '.*@disney\.ne\.jp$' => 'keitai_softbank_disney', # (kids)
- '.*@willcom\.ne\.jp$' => 'keitai_willcom',
- '.*@willcom\.com$' => 'keitai_willcom', # new for pdx.ne.jp address
- '.*@wcm\.ne\.jp$' => 'keitai_willcom', # old willcom wcm.ne.jp
- '.*@pdx\.ne\.jp$' => 'keitai_willcom_pdx', # old pdx address for willcom
- '.*@bandai\.jp$' => 'keitai_willcom_bandai', # willcom paipo! (kids)
- '.*@pipopa\.ne\.jp$' => 'keitai_willcom_pipopa', # willcom paipo! (kids)
- '.*@([a-z0-9]{2,4}\.)?pdx\.ne\.jp$' => 'keitai_willcom_pdx', # actually only di,dj,dk,wm -> all others are "wrong", but none also allowed?
- '.*@ymobile([1]{1})?\.ne\.jp$' => 'keitai_willcom_ymobile', # ymobile, ymobile1 techincally not willcom, but I group them there (softbank sub)
- '.*@y-mobile\.ne\.jp$' => 'keitai_willcom_ymobile', # y-mobile techincally not willcom, but I group them there (softbank sub)
- '.*@emnet\.ne\.jp$' => 'keitai_willcom_emnet', # e-mobile, group will willcom
- '.*@emobile\.ne\.jp$' => 'keitai_willcom_emnet', # e-mobile, group will willcom
- '.*@emobile-s\.ne\.jp$' => 'keitai_willcom_emnet' # e-mobile, group will willcom
- ];
- // short list for mobile email types
- self::$mobile_email_type_short = [
- 'keitai_docomo' => 'docomo',
- 'keitai_kddi_ezweb' => 'kddi',
- 'keitai_kddi' => 'kddi',
- 'keitai_kddi_tu-ka' => 'kddi',
- 'keitai_kddi_sky' => 'kddi',
- 'keitai_softbank' => 'softbank',
- 'smartphone_softbank_iphone' => 'iphone',
- 'keitai_softbank_disney' => 'softbank',
- 'keitai_softbank_vodafone' => 'softbank',
- 'keitai_softbank_j-phone' => 'softbank',
- 'keitai_willcom' => 'willcom',
- 'keitai_willcom_pdx' => 'willcom',
- 'keitai_willcom_bandai' => 'willcom',
- 'keitai_willcom_pipopa' => 'willcom',
- 'keitai_willcom_ymobile' => 'willcom',
- 'keitai_willcom_emnet' => 'willcom',
- 'pc_html' => 'pc',
- // old sets -> to be removed later
- 'docomo' => 'docomo',
- 'kddi_ezweb' => 'kddi',
- 'kddi' => 'kddi',
- 'kddi_tu-ka' => 'kddi',
- 'kddi_sky' => 'kddi',
- 'softbank' => 'softbank',
- 'keitai_softbank_iphone' => 'iphone',
- 'softbank_iphone' => 'iphone',
- 'softbank_disney' => 'softbank',
- 'softbank_vodafone' => 'softbank',
- 'softbank_j-phone' => 'softbank',
- 'willcom' => 'willcom',
- 'willcom_pdx' => 'willcom',
- 'willcom_bandai' => 'willcom',
- 'willcom_pipopa' => 'willcom',
- 'willcom_ymobile' => 'willcom',
- 'willcom_emnet' => 'willcom',
- 'pc' => 'pc'
- ];
+ // make sure type is in valid range
+ if ($type < 0 || $type >= count(self::$email_regex_check)) {
+ $type = 0;
+ }
+ return self::$email_regex_check[$type];
+ }
+
+ /**
+ * get the full check array
+ * this will be deprected at some point
+ *
+ * @return array
+ */
+ public static function getEmailRegexCheck(): array
+ {
+ return self::$email_regex_check;
}
/**
diff --git a/www/lib/CoreLibs/Check/File.php b/www/lib/CoreLibs/Check/File.php
index 30061388..0f06fa62 100644
--- a/www/lib/CoreLibs/Check/File.php
+++ b/www/lib/CoreLibs/Check/File.php
@@ -1,7 +1,7 @@
initRandomKeyData();
+ }
+ /**
+ * sets the random key range with the default values
+ * @return void has no return
+ */
+ private static function initRandomKeyData()
+ {
+ // random key generation
+ self::$key_range = array_merge(range('A', 'Z'), range('a', 'z'), range('0', '9'));
+ self::$one_key_length = count(self::$key_range);
+ }
+
+ /**
+ * validates they key length for random string generation
+ * @param int $key_length key length
+ * @return bool true for valid, false for invalid length
+ */
+ private static function validateRandomKeyLenght(int $key_length): bool
+ {
+ if (is_numeric($key_length) &&
+ $key_length > 0 &&
+ $key_length <= self::$max_key_length
+ ) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ /**
+ * sets the key length and checks that they key given is valid
+ * if failed it will not change the default key length and return false
+ * @param int $key_length key length
+ * @return bool true/false for set status
+ */
+ public static function setRandomKeyLength(int $key_length): bool
+ {
+ // only if valid int key with valid length
+ if (self::validateRandomKeyLenght($key_length) === true) {
+ self::$key_length = $key_length;
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ /**
+ * get the current set random key length
+ *
+ * @return int Current set key length
+ */
+ public static function getRandomKeyLength(): int
+ {
+ return self::$key_length;
+ }
+
+ /**
+ * creates a random key based on the key_range with key_length
+ * if override key length is set, it will check on valid key and use this
+ * this will not set the class key length variable
+ * @param int $key_length key length override, -1 for use default
+ * @return string random key
+ */
+ public static function randomKeyGen(int $key_length = -1): string
+ {
+ // init random key strings if not set
+ if (!is_numeric(self::$one_key_length)) {
+ self::initRandomKeyData();
+ }
+ $use_key_length = 0;
+ // only if valid int key with valid length
+ if (self::validateRandomKeyLenght($key_length) === true) {
+ $use_key_length = $key_length;
+ } else {
+ $use_key_length = self::$key_length;
+ }
+
+ $pieces = [];
+ for ($i = 1; $i <= $use_key_length; $i ++) {
+ $pieces[] = self::$key_range[random_int(0, self::$one_key_length - 1)];
+ }
+ return join('', $pieces);
+ }
+}
diff --git a/www/lib/CoreLibs/Debug/FileWriter.php b/www/lib/CoreLibs/Debug/FileWriter.php
new file mode 100644
index 00000000..f2f98303
--- /dev/null
+++ b/www/lib/CoreLibs/Debug/FileWriter.php
@@ -0,0 +1,61 @@
+script_starttime = microtime(true);
+ // set per run UID for logging
+ $this->running_uid = \CoreLibs\Create\Hash::__uniqId();
+ // set the page name
+ $this->page_name = \CoreLibs\Get\System::getPageName();
+ // set host name
+ list($this->host_name , $this->host_port) = \CoreLibs\Get\System::getHostName();
+ // add port to host name if not port 80
+ if ($this->host_port != 80) {
+ $this->host_name .= ':'.$this->host_port;
+ }
+ // can be overridden with basicSetLogFileId
+ if (isset($GLOBALS['LOG_FILE_ID'])) {
+ $this->basicSetLogId($GLOBALS['LOG_FILE_ID']);
+ } elseif (defined('LOG_FILE_ID')) {
+ $this->basicSetLogId(LOG_FILE_ID);
+ }
+
+ // init the log levels
+ $this->setLogLevels();
+ }
+
+ /**
+ * sets the internal log file prefix id
+ * string must be a alphanumeric string
+ * if non valid string is given it returns the previous set one only
+ * @param string $string log file id string value
+ * @return string returns the set log file id string
+ */
+ public function basicSetLogId(string $string): string
+ {
+ if (preg_match("/^\w+$/", $string)) {
+ $this->log_file_id = $string;
+ }
+ return $this->log_file_id;
+ }
+
+ /**
+ * init the basic log levels based on global set variables
+ *
+ * @return void
+ */
+ private function setLogLevels(): void
+ {
+ // if given via parameters, only for all
+ // globals overrule given settings, for one (array), eg $ECHO['db'] = 1;
+ if (isset($GLOBALS['DEBUG']) && is_array($GLOBALS['DEBUG'])) {
+ $this->debug_output = $GLOBALS['DEBUG'];
+ }
+ if (isset($GLOBALS['ECHO']) && is_array($GLOBALS['ECHO'])) {
+ $this->echo_output = $GLOBALS['ECHO'];
+ }
+ if (isset($GLOBALS['PRINT']) && is_array($GLOBALS['PRINT'])) {
+ $this->print_output = $GLOBALS['PRINT'];
+ }
+
+ // exclude these ones from output
+ if (isset($GLOBALS['DEBUG_NOT']) && is_array($GLOBALS['DEBUG_NOT'])) {
+ $this->debug_output_not = $GLOBALS['DEBUG_NOT'];
+ }
+ if (isset($GLOBALS['ECHO_NOT']) && is_array($GLOBALS['ECHO_NOT'])) {
+ $this->echo_output_not = $GLOBALS['ECHO_NOT'];
+ }
+ if (isset($GLOBALS['PRINT_NOT']) && is_array($GLOBALS['PRINT_NOT'])) {
+ $this->print_output_not = $GLOBALS['PRINT_NOT'];
+ }
+
+ // all overrule
+ $this->debug_output_all = $GLOBALS['DEBUG_ALL'] ?? false;
+ $this->echo_output_all = $GLOBALS['ECHO_ALL'] ?? false;
+ $this->print_output_all = $GLOBALS['PRINT_ALL'] ?? false;
+
+ // GLOBAL rules for log writing
+ $this->log_print_file_date = $GLOBALS['LOG_PRINT_FILE_DATE'] ?? true;
+ $this->log_per_level = $GLOBALS['LOG_PER_LEVEL'] ?? false;
+ $this->log_per_class = $GLOBALS['LOG_PER_CLASS'] ?? false;
+ $this->log_per_page = $GLOBALS['LOG_PER_PAGE'] ?? false;
+ $this->log_per_run = $GLOBALS['LOG_PER_RUN'] ?? false;
+ }
+
+ /**
+ * passes list of level names, to turn on debug
+ * eg $foo->debugFor('print', 'on', ['LOG', 'DEBUG', 'INFO']);
+ * @param string $type error, echo, print
+ * @param string $flag on/off
+ * array $array of levels to turn on/off debug
+ * @return void has no return
+ */
+ public function debugFor(string $type, string $flag): void
+ {
+ $debug_on = func_get_args();
+ array_shift($debug_on); // kick out type
+ array_shift($debug_on); // kick out flag (on/off)
+ if (count($debug_on) >= 1) {
+ foreach ($debug_on as $level) {
+ $switch = $type.'_output';
+ if ($flag == 'off') {
+ $switch .= '_not';
+ }
+ $this->{$switch}[$level] = true;
+ }
+ }
+ }
+
+ /**
+ * checks if we have a need to work on certain debug output
+ * Needs debug/echo/print ad target for which of the debug flag groups we check
+ * also needs level string to check in the per level output flag check.
+ * In case we have invalid target it will return false
+ * @param string $target target group to check debug/echo/print
+ * @param string $level level to check in detailed level flag
+ * @return bool true on access allowed or false on no access
+ */
+ private function doDebugTrigger(string $target, string $level): bool
+ {
+ $access = false;
+ // check if we do debug, echo or print
+ switch ($target) {
+ case 'debug':
+ if ((
+ (isset($this->debug_output[$level]) && $this->debug_output[$level]) ||
+ $this->debug_output_all
+ ) &&
+ (!isset($this->debug_output_not[$level]) ||
+ (isset($this->debug_output_not[$level]) && !$this->debug_output_not[$level])
+ )
+ ) {
+ $access = true;
+ }
+ break;
+ case 'echo':
+ if ((
+ (isset($this->echo_output[$level]) && $this->echo_output[$level]) ||
+ $this->echo_output_all
+ ) &&
+ (!isset($this->echo_output_not[$level]) ||
+ (isset($this->echo_output_not[$level]) && !$this->echo_output_not[$level])
+ )
+ ) {
+ $access = true;
+ }
+ break;
+ case 'print':
+ if ((
+ (isset($this->print_output[$level]) && $this->print_output[$level]) ||
+ $this->print_output_all
+ ) &&
+ (!isset($this->print_output_not[$level]) ||
+ (isset($this->print_output_not[$level]) && !$this->print_output_not[$level])
+ )
+ ) {
+ $access = true;
+ }
+ break;
+ }
+ return $access;
+ }
+
+ /**
+ * write debug data to error_msg array
+ * @param string $level id for error message, groups messages together
+ * @param string $string the actual error message
+ * @param bool $strip default on false, if set to true,
+ * all html tags will be stripped and
changed to \n
+ * this is only used for debug output
+ * @return bool True if logged, false if not logged
+ */
+ public function debug(string $level, string $string, bool $strip = false): bool
+ {
+ if (!$this->doDebugTrigger('debug', $level)) {
+ return false;
+ }
+ if (!isset($this->error_msg[$level])) {
+ $this->error_msg[$level] = '';
+ }
+ // get the last class entry and wrie that
+ $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS) ?? [['class' => get_class($this)]];
+ $class = end($backtrace)['class'];
+ // get timestamp
+ $timestamp = \CoreLibs\Debug\Support::printTime();
+ // HTML string, create only if we have echo
+ if ($this->doDebugTrigger('echo', $level)) {
+ $error_string = ''
+ .'['.$timestamp.'] '
+ .'['.$level.'] '
+ .'['.$this->host_name.'] '
+ .'['.$this->page_name.'] '
+ .'['.$this->running_uid.'] '
+ .'{'.$class.'} - '.\CoreLibs\Convert\Html::htmlent($string)
+ ."";
+ }
+ // if stripping all html, etc is requested
+ if ($strip) {
+ // find any
and replace them with \n
+ $string = str_replace('
', "\n", $string);
+ // strip rest of html elements
+ $string = preg_replace("/(<\/?)(\w+)([^>]*>)/", '', $string);
+ }
+ // same string put for print (no html data inside)
+ $error_string_print =
+ '['.$timestamp.'] '
+ .'['.$this->host_name.'] '
+ .'['.\CoreLibs\Get\System::getPageName(2).'] '
+ .'['.$this->running_uid.'] '
+ .'{'.$class.'} '
+ .'<'.$level.'> - '
+ .$string;
+ $error_string_print .= "\n";
+ // write to file if set
+ $this->writeErrorMsg($level, $error_string_print);
+ // write to error level
+ if ($this->doDebugTrigger('echo', $level)) {
+ $this->error_msg[$level] .= $error_string;
+ }
+ return true;
+ }
+
+ /**
+ * merges the given error array with the one from this class
+ * only merges visible ones
+ * @param array $error_msg error array
+ * @return void has no return
+ */
+ public function mergeErrors(array $error_msg = []): void
+ {
+ if (!is_array($error_msg)) {
+ $error_msg = [];
+ }
+ foreach ($error_msg as $level => $msg) {
+ $this->error_msg[$level] .= $msg;
+ }
+ }
+
+ /**
+ * prints out the error string
+ * @param string $string prefix string for header
+ * @return string error msg for all levels
+ */
+ public function printErrorMsg(string $string = ''): string
+ {
+ $string_output = '';
+ if ($this->debug_output_all) {
+ if ($this->error_msg_prefix) {
+ $string = $this->error_msg_prefix;
+ }
+ $script_end = microtime(true) - $this->script_starttime;
+ foreach ($this->error_msg as $level => $temp_debug_output) {
+ if ($this->doDebugTrigger('debug', $level)) {
+ if ($this->doDebugTrigger('echo', $level)) {
+ $string_output = ''
+ .'['.$level.'] '
+ .($string ? "**** ".\CoreLibs\Convert\Html::htmlent($string)." ****\n" : "")
+ .''
+ .$temp_debug_output;
+ } // echo it out
+ } // do printout
+ } // for each level
+ // create the output wrapper around, so we have a nice formated output per class
+ if ($string_output) {
+ $string_prefix = ''
+ .'{'.get_class($this).'}';
+ $string_output = $string_prefix.$string_output
+ .'Script Run Time: '.$script_end.''
+ .'';
+ }
+ }
+ return $string_output;
+ }
+
+ /**
+ * writes error msg data to file for current level
+ * @param string $level the level to write
+ * @param string $error_string error string to write
+ * @return bool True if message written, FAlse if not
+ */
+ private function writeErrorMsg(string $level, string $error_string): bool
+ {
+ // only write if write is requested
+ if (!($this->doDebugTrigger('debug', $level) &&
+ $this->doDebugTrigger('print', $level))
+ ) {
+ return false;
+ }
+ // replace all html tags
+ // $error_string = preg_replace("/(<\/?)(\w+)([^>]*>)/", "##\\2##", $error_string);
+ // $error_string = preg_replace("/(<\/?)(\w+)([^>]*>)/", "", $error_string);
+ // replace special line break tag
+ // $error_string = str_replace('', "\n", $error_string);
+
+ // init output variable
+ $output = $error_string; // output formated error string to output file
+ // init base file path
+ $fn = BASE.LOG.$this->log_print_file.'.'.$this->log_file_name_ext;
+ // log ID prefix settings, if not valid, replace with empty
+ if (preg_match("/^[A-Za-z0-9]+$/", $this->log_file_id)) {
+ $rpl_string = '_'.$this->log_file_id;
+ } else {
+ $rpl_string = '';
+ }
+ $fn = str_replace('##LOGID##', $rpl_string, $fn); // log id (like a log file prefix)
+
+ if ($this->log_per_run) {
+ if (isset($GLOBALS['LOG_FILE_UNIQUE_ID'])) {
+ $this->log_file_unique_id = $GLOBALS['LOG_FILE_UNIQUE_ID'];
+ }
+ if (!$this->log_file_unique_id) {
+ $GLOBALS['LOG_FILE_UNIQUE_ID'] = $this->log_file_unique_id = date('Y-m-d_His').'_U_'.substr(hash('sha1', uniqid((string)mt_rand(), true)), 0, 8);
+ }
+ $rpl_string = '_'.$this->log_file_unique_id; // add 8 char unique string
+ } else {
+ $rpl_string = !$this->log_print_file_date ? '' : '_'.date('Y-m-d'); // add date to file
+ }
+ $fn = str_replace('##DATE##', $rpl_string, $fn); // create output filename
+
+ $rpl_string = !$this->log_per_level ? '' : '_'.$level; // if request to write to one file
+ $fn = str_replace('##LEVEL##', $rpl_string, $fn); // create output filename
+
+ $rpl_string = !$this->log_per_class ? '' : '_'.str_replace('\\', '-', get_class($this)); // set sub class settings
+ $fn = str_replace('##CLASS##', $rpl_string, $fn); // create output filename
+
+ $rpl_string = !$this->log_per_page ? '' : '_'.\CoreLibs\Get\System::getPageName(1); // if request to write to one file
+ $fn = str_replace('##PAGENAME##', $rpl_string, $fn); // create output filename
+
+ // write to file
+ // first check if max file size is is set and file is bigger
+ if ($this->log_max_filesize > 0 && ((filesize($fn) / 1024) > $this->log_max_filesize)) {
+ // for easy purpose, rename file only to attach timestamp, nur sequence numbering
+ rename($fn, $fn.'.'.date("YmdHis"));
+ }
+ $fp = fopen($fn, 'a');
+ if ($fp !== false) {
+ fwrite($fp, $output);
+ fclose($fp);
+ } else {
+ echo "";
+ }
+ return true;
+ }
+
+ /**
+ * unsests the error message array
+ * can be used if writing is primary to file
+ * if no level given resets all
+ * @param string $level optional level
+ * @return void has no return
+ */
+ public function resetErrorMsg(string $level = ''): void
+ {
+ if (!$level) {
+ $this->error_msg = [];
+ } elseif (isset($this->error_msg[$level])) {
+ unset($this->error_msg[$level]);
+ }
+ }
+}
+
+// __END__
diff --git a/www/lib/CoreLibs/Debug/RunningTime.php b/www/lib/CoreLibs/Debug/RunningTime.php
new file mode 100644
index 00000000..0c4b1136
--- /dev/null
+++ b/www/lib/CoreLibs/Debug/RunningTime.php
@@ -0,0 +1,119 @@
+Started at: ";
+ } else {
+ self::$endtime = ((float)$micro + (float)$timestamp);
+ self::$runningtime_string .= $simple ? 'End: ' : "Stopped at: ";
+ }
+ self::$runningtime_string .= date('Y-m-d H:i:s', (int)$timestamp);
+ self::$runningtime_string .= ' '.$micro.($simple ? ', ' : '
');
+ // if both are set
+ if (self::$starttime && self::$endtime) {
+ $running_time = self::$endtime - self::$starttime;
+ self::$runningtime_string .= ($simple ? 'Run: ' : "Script running time: ").$running_time." s";
+ // reset start & end time after run
+ self::$starttime = 0;
+ self::$endtime = 0;
+ }
+ return $running_time;
+ }
+
+ /**
+ * get the runningTime string (for debug visual)
+ *
+ * @return string
+ */
+ public static function runningTimeString(): string
+ {
+ return self::$runningtime_string;
+ }
+}
+
+// __END__
diff --git a/www/lib/CoreLibs/Debug/Support.php b/www/lib/CoreLibs/Debug/Support.php
new file mode 100644
index 00000000..445e3a40
--- /dev/null
+++ b/www/lib/CoreLibs/Debug/Support.php
@@ -0,0 +1,60 @@
+= 1, round that size
+ if ($set_microtime == -1) {
+ $string .= substr($microtime, 1);
+ } elseif ($set_microtime >= 1) {
+ // in round case we run this through number format to always get the same amount of digits
+ $string .= substr(number_format(round((float)$microtime, $set_microtime), $set_microtime), 1);
+ }
+ return $string;
+ }
+
+ /**
+ * prints a html formatted (pre) array
+ * @param array $array any array
+ * @return string formatted array for output with tag added
+ */
+ public static function printAr(array $array): string
+ {
+ return "".print_r($array, true)."
";
+ }
+
+ /**
+ * if there is a need to find out which parent method called a child method,
+ * eg for debugging, this function does this
+ * call this method in the child method and you get the parent function that called
+ * @param int $level debug level, default 2
+ * @return ?string null or the function that called the function where this method is called
+ */
+ public static function getCallerMethod(int $level = 1): ?string
+ {
+ $traces = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
+ // print \CoreLibs\Debug\Support::printAr($traces);
+ // We should check from top down if unset?
+ // sets the start point here, and in level two (the sub call) we find this
+ if (isset($traces[$level])) {
+ return $traces[$level]['function'];
+ }
+ return null;
+ }
+}
+
+// __END__
diff --git a/www/lib/CoreLibs/Get/System.php b/www/lib/CoreLibs/Get/System.php
new file mode 100644
index 00000000..a7450afa
--- /dev/null
+++ b/www/lib/CoreLibs/Get/System.php
@@ -0,0 +1,85 @@
+