58 static public function setDisplay(
bool $bUseDisplay =
true): void
60 self::$display_errors = $bUseDisplay;
69 public function __call(
string $name, array $arguments): void
71 $msg =
"Unknown class-method: '".$name.
"'\nParams:\n";
82 public static function __callStatic(
string $name, array $arguments): void
84 $msg =
"Unknown static class-method: '".$name.
"'\nParams:\n";
108 static public function install_table(
string $table_name=
'',
string $table_fields=
''): bool
110 if (($table_name ==
'') || ($table_fields ==
'')) {
114 $table = TABLE_PREFIX . $table_name;
115 $database->simple_query(
"CREATE TABLE `" . $table .
"` (" . $table_fields .
") ");
138 static public function encrypt_table(
string $table_name =
'', array $aListOfFields =[],
string $field_condition =
''): bool
140 if ($table_name ==
'')
144 if (!is_array($aListOfFields))
146 LEPTON_tools::display(
"REQUIRED list of names nof table fields must be an array!",
"div",
"ui red message");
150 if ( $field_condition ==
'' ) {
158 $table_content = array();
160 "SELECT * FROM ".TABLE_PREFIX.$table_name.
" ",
166 foreach ($table_content as $to_encrypt)
168 $database->secure_build_and_execute(
'UPDATE', TABLE_PREFIX . $table_name, $to_encrypt,
'' . $field_condition .
' =' . $to_encrypt[$field_condition], $aListOfFields);
193 static public function decrypt_table(
string $table_name =
'', array $aListOfFields = [],
string $field_condition =
'')
195 if ($table_name ==
'')
200 if (!is_array($aListOfFields))
202 LEPTON_tools::display(
"REQUIRED list of names of table-fields must be an array!",
"div",
"ui red message");
206 if ($field_condition ==
'')
215 $table_content = array();
217 "SELECT * FROM " . TABLE_PREFIX . $table_name .
" ",
224 foreach ($table_content as $to_decrypt)
227 'UPDATE', TABLE_PREFIX.$table_name,
229 $field_condition.
' ='.$to_decrypt[$field_condition]
254 static public function insert_values(
string $table_name=
'',
string $field_values =
''): bool
256 if (($table_name ==
'') || ($field_values ==
'')) {
261 $table = TABLE_PREFIX . $table_name;
262 $database->simple_query(
"INSERT INTO `" . $table .
"` VALUES " . $field_values .
" ");
280 static public function drop_table(
string $table_name=
''): bool
282 if ($table_name ==
'')
287 $table = TABLE_PREFIX . $table_name;
289 $database->simple_query(
"DROP TABLE IF EXISTS `" . $table .
"` ");
304 static public function rename_table(
string $table_name =
''): bool
306 if ($table_name ==
'')
311 $table_source = TABLE_PREFIX . $table_name;
312 $table_target = TABLE_PREFIX .
'xsik_' . $table_name;
314 $database->simple_query(
"RENAME TABLE `" . $table_source .
"` TO `" . $table_target .
"` ");
330 if ($table_name ==
'')
335 $table_source = TABLE_PREFIX . $table_name;
336 $table_target = TABLE_PREFIX .
'xsik_' . $table_name;
338 $database->simple_query(
"CREATE TABLE `" . $table_target .
"` LIKE `" . $table_source .
"`");
339 $database->simple_query(
"INSERT INTO `" . $table_target .
"` SELECT * FROM `" . $table_source .
"`");
361 if (is_string($aFileNames))
363 $aFileNames = [ $aFileNames ];
366 foreach ($aFileNames as $del)
370 foreach ($del as $subItem)
377 $temp_path = ((!str_contains($del, LEPTON_PATH)) ? LEPTON_PATH :
"") . $del;
378 if (file_exists($temp_path))
380 $result = unlink($temp_path);
381 if (
false === $result)
383 echo
"<p>Cannot delete file " . $temp_path .
". Please check file permissions and ownership or delete file manually.</p>";
405 if (is_string($directory_names))
407 $directory_names = [$directory_names];
412 foreach ($directory_names as $del)
414 $temp_path = LEPTON_PATH . $del;
415 if (file_exists($temp_path))
418 if (
false === $result)
420 echo
"Cannot delete directory ".$temp_path.
". Please check directory permissions and ownership or deleted directories manually.";
442 if (is_string($directory_names))
444 $directory_names = [$directory_names];
448 foreach ($directory_names as $rename)
450 $source_path = LEPTON_PATH . $rename[
'source'];
451 $target_path = LEPTON_PATH . $rename[
'target'];
452 if (file_exists($source_path))
456 if (
false === $result)
458 echo
"Cannot rename file ".$source_path.
". Please check directory permissions and ownership manually.";
478 static public function include_files(array|
string $file_names=[],
bool $interrupt=
true): void
480 if (is_string($file_names))
482 $file_names = [$file_names];
485 foreach ($file_names as $requestedFile)
487 $temp_path = LEPTON_PATH . $requestedFile;
488 if (file_exists($temp_path))
490 require_once $temp_path;
491 } elseif($interrupt ===
true)
494 "<pre class='ui message'>\nCan't include: ".$temp_path.
"\n</pre>",
516 static public function require_alternative(
string $file_name,
string $usage =
'backend'): bool
518 if (($usage ==
'frontend') || ($usage ==
'backend'))
520 $temp_path = LEPTON_PATH.(($usage ===
'backend') ? self::ALT_BACKEND_FILE : self::
ALT_FRONTEND_FILE).$file_name;
522 if (file_exists($temp_path))
524 require_once $temp_path;
544 static public function install_modules(array $module_names = [] ): void
546 global $module_name, $module_license, $module_author, $module_directory, $module_version, $module_function, $module_description, $module_platform, $module_guid, $lepton_platform;
547 if (is_string($module_names))
549 $module_names = [$module_names];
554 foreach ($module_names as $temp_addon)
556 $test =
$database->get_one(
"SELECT `addon_id` FROM `" . TABLE_PREFIX .
"addons` WHERE `directory` = '" . $temp_addon .
"' ");
561 'module_license',
'module_author' ,
'module_name',
'module_directory',
562 'module_version',
'module_function',
'module_description',
563 'module_platform',
'module_guid'
566 foreach ($module_vars as $varname)
568 if (isset(${$varname}))
574 $temp_path = LEPTON_PATH .
'/modules/'.$temp_addon ;
575 require $temp_path.
'/info.php';
595 static public function upgrade_modules(
string|array $module_names = []): void
597 if (is_string($module_names))
599 $module_names = array($module_names);
603 foreach ($module_names as $update)
605 $temp_path = LEPTON_PATH .
"/modules/" . $update .
"/upgrade.php";
606 if (file_exists($temp_path))
617 'module_license',
'module_author' ,
'module_name',
'module_directory',
618 'module_version',
'module_function',
'module_description',
619 'module_platform',
'module_guid'
623 if (isset(${$varname}))
648 static public function install_droplets(
string $module_name=
'',
string|array $zip_names=[]): void
650 droplets::getInstance();
652 if (is_string($zip_names))
654 $zip_names = array($zip_names);
656 foreach ($zip_names as $to_install)
658 $temp_path = LEPTON_PATH .
"/modules/" . $module_name .
"/install/".$to_install.
".zip";
659 if (file_exists($temp_path))
661 $result = droplet_install($temp_path, LEPTON_PATH .
'/temp/unzip/');
662 if (count($result[
'errors']) > 0)
664 die (
'ERROR: file is missing: <b> ' . (implode(
'<br />\n', $result[
'errors'])) .
' </b>.');
687 if (is_string($droplet_names))
689 $droplet_names = [$droplet_names];
693 foreach ($droplet_names as $to_uninstall)
697 "SELECT `id` FROM ".TABLE_PREFIX.
"mod_droplets WHERE `name` = '".$to_uninstall.
"' ",
702 if (isset($to_delete[
'id']))
704 $database->simple_query(
"DELETE FROM `" . TABLE_PREFIX .
"mod_droplets` WHERE `id` = " . $to_delete[
'id']);
705 $database->simple_query(
"DELETE FROM `" . TABLE_PREFIX .
"mod_droplets_permissions` WHERE `id` = " . $to_delete[
'id']);
731 static function register(): bool
733 if (0 === func_num_args())
738 $all_args = func_get_args();
739 foreach($all_args as &$param)
741 if (
true === is_array($param))
743 foreach ($param as $ref)
750 if (!function_exists($param))
752 $lookUpPath = LEPTON_PATH .
"/framework/functions/function." . $param .
".php";
753 if (file_exists($lookUpPath))
755 require_once $lookUpPath;
785 $ini_file_name = LEPTON_PATH.
"/config/lepton.ini.php";
787 if (
true === file_exists($ini_file_name))
789 $config = parse_ini_string(
";" . file_get_contents($ini_file_name),
true);
790 if ($config[
'custom_vars'][
'additional_email_chars'] !=
'')
792 $add_custom = $config[
'custom_vars'][
'additional_email_chars'];
795 return !((
false === filter_var($sEmail, FILTER_VALIDATE_EMAIL)
796 || (!preg_match(
'#^[' .LEPTON_core::getInstance()->email_chars.$add_custom.
']+$#', $sEmail))));
812 return (preg_match(
'/^['.LEPTON_core::getInstance()->string_secure.
']+$/i', $sString) === 1);
838 $ini_file_name = LEPTON_PATH .
"/config/lepton.ini.php";
840 if (
true === file_exists($ini_file_name))
842 $config = parse_ini_string(
";" . file_get_contents($ini_file_name),
true);
843 if ($config[
'custom_vars'][
'additional_password_chars'] !=
'')
845 $add_custom = $config[
'custom_vars'][
'additional_password_chars'];
848 return !((
false === !preg_match(
'/[^'.LEPTON_core::getInstance()->password_chars.$add_custom.
']/', $sPassword)));
875 $ini_file_name = LEPTON_PATH.
"/config/lepton.ini.php";
877 if (
true === file_exists($ini_file_name))
879 $config = parse_ini_string(
";".file_get_contents($ini_file_name),
true);
880 if ($config[
'custom_vars'][
'additional_usernames_chars'] !=
'')
882 $add_custom = $config[
'custom_vars'][
'additional_usernames_chars'];
886 return !!preg_match(
"#^[" . LEPTON_core::getInstance()->username_chars . $add_custom .
"]+$#", $sName);
917 return !!preg_match(
"~^[".LEPTON_core::getInstance()->hex_chars.
"]+$~", $sHexHash);
928 public static function restoreSpecialChars(
string &$sAnyString, array $aAnyAssocArray = self::SPECIAL_CHARS_RESTORE): void
930 $aLookUp = array_keys($aAnyAssocArray);
931 $aReplace = array_values($aAnyAssocArray);
933 $sAnyString = str_replace($aLookUp, $aReplace, $sAnyString);
944 if (file_exists(self::HTACCESS_PATH))
946 unlink(self::HTACCESS_PATH);
947 unlink(self::HTPASSWD_PATH);
950 $htuser = $admin_username;
951 $random_value = random_int(100000,999999);
952 $htpassword = password_hash((
string)$random_value, PASSWORD_DEFAULT );
954$htcontent =
"# .htaccess-Datei
956AuthName 'Protected area - Please insert password!'
957AuthUserFile ".self::HTPASSWD_PATH.
"
958require user ".$htuser.
"
961$htpwcontent =
"# Password file, user:".$htuser.
", password: ".$random_value.
"
962".$htuser.
":".$htpassword.
"
965 file_put_contents(self::HTACCESS_PATH,$htcontent);
966 file_put_contents(self::HTPASSWD_PATH,$htpwcontent);
983 echo
LEPTON_tools::display(
'USERNAME is mandantory as second parameter in this method',
'pre',
'ui red message');
987 if (file_exists(LEPTON_PATH . $path .
'/.htaccess'))
989 unlink(LEPTON_PATH.$path.
'/.htaccess');
990 unlink(LEPTON_PATH.$path.
'/.htpasswd');
994 $random_value = random_int(100000,999999);
995 $htpassword = password_hash((
string)$random_value, PASSWORD_DEFAULT );
997$htcontent =
"# .htaccess-Datei
999AuthName 'Protected area - Please insert password!'
1000AuthUserFile ".LEPTON_PATH.$path.
"/.htpasswd
1001require user ".$htuser.
"
1004$htpwcontent =
"# Password file, user:".$htuser.
", password: ".$random_value.
"
1005".$htuser.
":".$htpassword.
"
1008 file_put_contents(LEPTON_PATH . $path .
'/.htaccess', $htcontent);
1009 file_put_contents(LEPTON_PATH . $path .
'/.htpasswd', $htpwcontent);
1029 static function array_orderby(array $array,
string $on,
int $order = SORT_ASC): array
1032 $sortable_array = [];
1037 $lookUpKeys = explode(
",", $on);
1038 $keys = array_map(
"trim", $lookUpKeys);
1040 foreach ($array as $k => $v)
1044 if (isset($v[$keys[0]]))
1046 $sortable_array[$k] =
"";
1047 foreach ($keys as $term)
1049 if (isset($v[$term]))
1051 $sortable_array[$k] .= $v[$term];
1056 $sortable_array[$k] = $v;
1064 asort($sortable_array, SORT_NATURAL|SORT_FLAG_CASE);
1068 arsort($sortable_array, SORT_NATURAL|SORT_FLAG_CASE);
1076 foreach ($sortable_array as $k => $v)
1078 if ($keepAssoc ===
true)
1080 $new_array[$k] = $array[$k];
1082 $new_array[] = $array[$k];
1091 static public function themeExists(
string $sThemeName =
""): bool
1093 $result =
LEPTON_database::getInstance()->get_one(
"SELECT `directory` FROM `".TABLE_PREFIX.
"addons` WHERE `directory` ='".$sThemeName.
"'");
1094 return (!is_null($result));
1121 static public function moveThemeFiles(
string $sModuleDirectory =
""): void
1127 foreach ($aAllThemes as $sForTheme)
1129 $sBaseSourcePath = LEPTON_PATH .
"/modules/" . $sSingleModuleDirectory .
"/backendthemes/" . $sForTheme;
1130 $sTargetPath = LEPTON_PATH .
"/templates/" . $sForTheme .
"/backend/" . $sSingleModuleDirectory;
1132 if (
true === file_exists($sBaseSourcePath))
1148 if (
true === is_dir($dirsource))
1150 if(($deep === 0) && (
false === is_dir($dirdest)))
1152 LEPTON_core::make_dir($dirdest);
1154 $dir= dir($dirsource);
1155 while ( $file = $dir->read() )
1157 if( $file[0] ===
"." )
1161 if( !is_dir($dirsource.
"/".$file) )
1163 copy($dirsource .
"/" . $file, $dirdest .
"/" . $file);
1164 LEPTON_core::change_mode($dirdest .
"/" . $file);
1166 LEPTON_core::make_dir($dirdest .
"/" . $file);
1176 if (!file_exists(dirname($dirsource, 2) .
"/.git"))
1195 foreach ($aAllThemes as $aTempThemeDirectory)
1208 if (empty($anyNameOrPath))
1218 $backtrace = debug_backtrace();
1220 if (isset($backtrace[1][
'file']))
1228 return ($aTemp[0] === $aTempTest[0]) ? $aTemp[0] :
"";
1239 "SELECT `directory` FROM `" . TABLE_PREFIX .
"addons` WHERE `function` = 'theme'",
1244 $aReturnValues = [];
1245 foreach($aAllThemes as $aTempTheme)
1247 $aReturnValues[] = $aTempTheme[
"directory"];
1249 return $aReturnValues;
1259 final static public function getPathElements(
string $anyNameOrPath =
""): array
1262 DIRECTORY_SEPARATOR,
1264 LEPTON_PATH . DIRECTORY_SEPARATOR .
"modules" . DIRECTORY_SEPARATOR,
1282 if (function_exists(
'com_create_guid'))
1284 $guid = com_create_guid();
1285 $guid = strtolower($guid);
1286 if (str_starts_with($guid,
'{'))
1288 $guid = substr($guid, 1);
1290 if (strpos($guid,
'}') == strlen($guid) - 1)
1292 $guid = substr($guid, 0, strlen($guid) - 1);
1298 return sprintf(
'%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
1299 random_int(0, 0xffff),
1300 random_int(0, 0xffff),
1301 random_int(0, 0xffff),
1302 random_int(0, 0xffff),
1303 random_int(0, 0x0fff) | 0x4000,
1304 random_int(0, 0x3fff) | 0x8000,
1305 random_int(0, 0xffff),
1306 random_int(0, 0xffff)