3declare(strict_types=1);
54 static public function setDisplay(
bool $bUseDisplay =
true): void
56 self::$display_errors = $bUseDisplay;
65 public function __call(
string $name, array $arguments): void
67 $msg =
"Unknown class-method: '".$name.
"'\nParams:\n";
78 public static function __callStatic(
string $name, array $arguments): void
80 $msg =
"Unknown static class-method: '".$name.
"'\nParams:\n";
104 static public function install_table(
string $table_name=
'',
string $table_fields=
''): bool
106 if (($table_name ==
'') || ($table_fields ==
'')) {
110 $table = TABLE_PREFIX . $table_name;
111 $database->simple_query(
"CREATE TABLE `" . $table .
"` (" . $table_fields .
") ");
134 static public function encrypt_table(
string $table_name =
'', array $aListOfFields =[],
string $field_condition =
''): bool
136 if ($table_name ==
'')
140 if (!is_array($aListOfFields))
142 LEPTON_tools::display(
"REQUIRED list of names nof table fields must be an array!",
"div",
"ui red message");
146 if ( $field_condition ==
'' ) {
154 $table_content = array();
156 "SELECT * FROM ".TABLE_PREFIX.$table_name.
" ",
162 foreach ($table_content as $to_encrypt)
164 $database->secure_build_and_execute(
'UPDATE', TABLE_PREFIX . $table_name, $to_encrypt,
'' . $field_condition .
' =' . $to_encrypt[$field_condition], $aListOfFields);
189 static public function decrypt_table(
string $table_name =
'', array $aListOfFields = [],
string $field_condition =
'')
191 if ($table_name ==
'')
196 if (!is_array($aListOfFields))
198 LEPTON_tools::display(
"REQUIRED list of names of table-fields must be an array!",
"div",
"ui red message");
202 if ($field_condition ==
'')
211 $table_content = array();
213 "SELECT * FROM " . TABLE_PREFIX . $table_name .
" ",
220 foreach ($table_content as $to_decrypt)
223 'UPDATE', TABLE_PREFIX.$table_name,
225 $field_condition.
' ='.$to_decrypt[$field_condition]
250 static public function insert_values(
string $table_name=
'',
string $field_values =
''): bool
252 if (($table_name ==
'') || ($field_values ==
'')) {
257 $table = TABLE_PREFIX . $table_name;
258 $database->simple_query(
"INSERT INTO `" . $table .
"` VALUES " . $field_values .
" ");
276 static public function drop_table(
string $table_name=
''): bool
278 if ($table_name ==
'')
283 $table = TABLE_PREFIX . $table_name;
285 $database->simple_query(
"DROP TABLE IF EXISTS `" . $table .
"` ");
302 if ($table_name ==
'')
307 $table_source = TABLE_PREFIX . $table_name;
308 $table_target = TABLE_PREFIX .
'xsik_' . $table_name;
310 $database->simple_query(
"RENAME TABLE `" . $table_source .
"` TO `" . $table_target .
"` ");
326 if ($table_name ==
'')
331 $table_source = TABLE_PREFIX . $table_name;
332 $table_target = TABLE_PREFIX .
'xsik_' . $table_name;
334 $database->simple_query(
"CREATE TABLE `" . $table_target .
"` LIKE `" . $table_source .
"`");
335 $database->simple_query(
"INSERT INTO `" . $table_target .
"` SELECT * FROM `" . $table_source .
"`");
357 if (is_string($aFileNames))
359 $aFileNames = [ $aFileNames ];
362 foreach ($aFileNames as $del)
366 foreach ($del as $subItem)
373 $temp_path = ((!str_contains($del, LEPTON_PATH)) ? LEPTON_PATH :
"") . $del;
374 if (file_exists($temp_path))
376 $result = unlink($temp_path);
377 if (
false === $result)
379 echo
"<p>Cannot delete file " . $temp_path .
". Please check file permissions and ownership or delete file manually.</p>";
403 foreach ($directory_names as $del)
405 $temp_path = LEPTON_PATH . $del;
406 if (file_exists($temp_path))
409 if (
false === $result)
411 echo
"Cannot delete directory ".$temp_path.
". Please check directory permissions and ownership or deleted directories manually.";
434 foreach ($directory_names as $rename)
436 $source_path = LEPTON_PATH . $rename[
'source'];
437 $target_path = LEPTON_PATH . $rename[
'target'];
438 if (file_exists($source_path))
442 if (
false === $result)
444 echo
"Cannot rename file ".$source_path.
". Please check directory permissions and ownership manually.";
464 static public function include_files(array|
string $file_names=[],
bool $interrupt=
true): void
466 if (is_string($file_names))
468 $file_names = [$file_names];
471 foreach ($file_names as $requestedFile)
473 $temp_path = LEPTON_PATH . $requestedFile;
474 if (file_exists($temp_path))
476 require_once $temp_path;
477 } elseif($interrupt ===
true)
480 "<pre class='ui message'>\nCan't include: ".$temp_path.
"\n</pre>",
504 if (($usage ==
'frontend') || ($usage ==
'backend'))
506 $temp_path = LEPTON_PATH.(($usage ===
'backend') ? self::ALT_BACKEND_FILE :
self::ALT_FRONTEND_FILE).$file_name;
508 if (file_exists($temp_path))
510 require_once $temp_path;
532 global $module_name, $module_license, $module_author, $module_directory, $module_version, $module_function, $module_description, $module_platform, $module_guid, $lepton_platform;
533 if (is_string($module_names))
535 $module_names = [$module_names];
540 foreach ($module_names as $temp_addon)
542 $test =
$database->get_one(
"SELECT `addon_id` FROM `" . TABLE_PREFIX .
"addons` WHERE `directory` = '" . $temp_addon .
"' ");
547 'module_license',
'module_author' ,
'module_name',
'module_directory',
548 'module_version',
'module_function',
'module_description',
549 'module_platform',
'module_guid'
552 foreach ($module_vars as $varname)
554 if (isset(${$varname}))
560 $temp_path = LEPTON_PATH .
'/modules/'.$temp_addon ;
561 require $temp_path.
'/info.php';
583 if (is_string($module_names))
585 $module_names = array($module_names);
589 foreach ($module_names as $update)
591 $temp_path = LEPTON_PATH .
"/modules/" . $update .
"/upgrade.php";
592 if (file_exists($temp_path))
603 'module_license',
'module_author' ,
'module_name',
'module_directory',
604 'module_version',
'module_function',
'module_description',
605 'module_platform',
'module_guid'
609 if (isset(${$varname}))
634 static public function install_droplets(
string $module_name=
'',
string|array $zip_names=[]): void
636 droplets::getInstance();
638 if (is_string($zip_names))
640 $zip_names = array($zip_names);
642 foreach ($zip_names as $to_install)
644 $temp_path = LEPTON_PATH .
"/modules/" . $module_name .
"/install/".$to_install.
".zip";
645 if (file_exists($temp_path))
647 $result = droplet_install($temp_path, LEPTON_PATH .
'/temp/unzip/');
648 if (count($result[
'errors']) > 0)
650 die (
'ERROR: file is missing: <b> ' . (implode(
'<br />\n', $result[
'errors'])) .
' </b>.');
673 if (is_string($droplet_names))
675 $droplet_names = [$droplet_names];
679 foreach ($droplet_names as $to_uninstall)
683 "SELECT `id` FROM ".TABLE_PREFIX.
"mod_droplets WHERE `name` = '".$to_uninstall.
"' ",
688 if (isset($to_delete[
'id']))
690 $database->simple_query(
"DELETE FROM `" . TABLE_PREFIX .
"mod_droplets` WHERE `id` = " . $to_delete[
'id']);
691 $database->simple_query(
"DELETE FROM `" . TABLE_PREFIX .
"mod_droplets_permissions` WHERE `id` = " . $to_delete[
'id']);
717 static function register(): bool
719 if (0 === func_num_args())
724 $all_args = func_get_args();
725 foreach($all_args as &$param)
727 if (
true === is_array($param))
729 foreach ($param as $ref)
736 if (!function_exists($param))
738 $lookUpPath = LEPTON_PATH .
"/framework/functions/function." . $param .
".php";
739 if (file_exists($lookUpPath))
741 require_once $lookUpPath;
771 $ini_file_name = LEPTON_PATH.
"/config/lepton.ini.php";
773 if (
true === file_exists($ini_file_name))
775 $config = parse_ini_string(
";" . file_get_contents($ini_file_name),
true);
776 if ($config[
'custom_vars'][
'additional_email_chars'] !=
'')
778 $add_custom = $config[
'custom_vars'][
'additional_email_chars'];
781 return !((
false === filter_var($sEmail, FILTER_VALIDATE_EMAIL)
782 || (!preg_match(
'#^[' .LEPTON_core::getInstance()->email_chars.$add_custom.
']+$#', $sEmail))));
807 $ini_file_name = LEPTON_PATH .
"/config/lepton.ini.php";
809 if (
true === file_exists($ini_file_name))
811 $config = parse_ini_string(
";" . file_get_contents($ini_file_name),
true);
812 if ($config[
'custom_vars'][
'additional_password_chars'] !=
'')
814 $add_custom = $config[
'custom_vars'][
'additional_password_chars'];
817 return !((
false === !preg_match(
'/[^'.LEPTON_core::getInstance()->password_chars.$add_custom.
']/', $sPassword)));
842 $ini_file_name = LEPTON_PATH .
"/config/lepton.ini.php";
844 if (
true === file_exists($ini_file_name))
846 $config = parse_ini_string(
";" . file_get_contents($ini_file_name),
true);
847 if ($config[
'custom_vars'][
'additional_usernames_chars'] !=
'')
849 $add_custom = $config[
'custom_vars'][
'additional_usernames_chars'];
853 return !!preg_match(
"#^[" . LEPTON_core::getInstance()->username_chars . $add_custom .
"]+$#", $sName);
884 return !!preg_match(
"~^[".LEPTON_core::getInstance()->hex_chars.
"]+$~", $sHexHash);
895 public static function restoreSpecialChars(
string &$sAnyString, array $aAnyAssocArray = self::SPECIAL_CHARS_RESTORE): void
897 $aLookUp = array_keys($aAnyAssocArray);
898 $aReplace = array_values($aAnyAssocArray);
900 $sAnyString = str_replace( $aLookUp, $aReplace, $sAnyString );
911 if (file_exists(self::HTACCESS_PATH))
913 unlink(self::HTACCESS_PATH);
914 unlink(self::HTPASSWD_PATH);
917 $htuser = $admin_username;
918 $random_value = random_int(100000,999999);
919 $htpassword = password_hash((
string)$random_value, PASSWORD_DEFAULT );
921$htcontent =
"# .htaccess-Datei
923AuthName 'Protected area - Please insert password!'
924AuthUserFile ".self::HTPASSWD_PATH.
"
925require user ".$htuser.
"
928$htpwcontent =
"# Password file, user:".$htuser.
", password: ".$random_value.
"
929".$htuser.
":".$htpassword.
"
932 file_put_contents(self::HTACCESS_PATH,$htcontent);
933 file_put_contents(self::HTPASSWD_PATH,$htpwcontent);
950 echo
LEPTON_tools::display(
'USERNAME is mandantory as second parameter in this method',
'pre',
'ui red message');
954 if (file_exists(LEPTON_PATH . $path .
'/.htaccess'))
956 unlink(LEPTON_PATH.$path.
'/.htaccess');
957 unlink(LEPTON_PATH.$path.
'/.htpasswd');
961 $random_value = random_int(100000,999999);
962 $htpassword = password_hash((
string)$random_value, PASSWORD_DEFAULT );
964$htcontent =
"# .htaccess-Datei
966AuthName 'Protected area - Please insert password!'
967AuthUserFile ".LEPTON_PATH.$path.
"/.htpasswd
968require user ".$htuser.
"
971$htpwcontent =
"# Password file, user:".$htuser.
", password: ".$random_value.
"
972".$htuser.
":".$htpassword.
"
975 file_put_contents(LEPTON_PATH . $path .
'/.htaccess', $htcontent);
976 file_put_contents(LEPTON_PATH . $path .
'/.htpasswd', $htpwcontent);
993 static function array_orderby(array $array,
string $on,
string $order = SORT_ASC): array
996 $sortable_array = [];
998 if (count($array) > 0)
1000 foreach ($array as $k => $v)
1004 foreach ($v as $k2 => $v2)
1008 $sortable_array[$k] = $v2;
1012 $sortable_array[$k] = $v;
1019 asort($sortable_array);
1023 arsort($sortable_array);
1031 foreach ($sortable_array as $k => $v)
1033 $new_array[$k] = $array[$k];
1043 $result =
LEPTON_database::getInstance()->get_one(
"SELECT `directory` FROM `".TABLE_PREFIX.
"addons` WHERE `directory` ='".$sThemeName.
"'");
1044 return ($result !== NULL);
1077 foreach ($aAllThemes as $sForTheme)
1079 $sBaseSourcePath = LEPTON_PATH .
"/modules/" . $sSingleModuleDirectory .
"/backendthemes/" . $sForTheme;
1080 $sTargetPath = LEPTON_PATH .
"/templates/" . $sForTheme .
"/backend/" . $sSingleModuleDirectory;
1082 if (
true === file_exists($sBaseSourcePath))
1099 if (
true === is_dir($dirsource))
1101 if(($deep === 0) && (
false === is_dir($dirdest)))
1103 LEPTON_core::make_dir($dirdest);
1105 $dir= dir($dirsource);
1106 while ( $file = $dir->read() )
1108 if( $file[0] ===
"." )
1112 if( !is_dir($dirsource.
"/".$file) )
1114 copy($dirsource .
"/" . $file, $dirdest .
"/" . $file);
1115 LEPTON_core::change_mode($dirdest .
"/" . $file);
1117 LEPTON_core::make_dir($dirdest .
"/" . $file);
1127 if (!file_exists(dirname($dirsource, 2) .
"/.git"))
1146 foreach ($aAllThemes as $aTempThemeDirectory)
1159 if (empty($anyNameOrPath))
1169 $backtrace = debug_backtrace();
1171 if (isset($backtrace[1][
'file']))
1179 return ($aTemp[0] === $aTempTest[0]) ? $aTemp[0] :
"";
1190 "SELECT `directory` FROM `" . TABLE_PREFIX .
"addons` WHERE `function` = 'theme'",
1195 $aReturnValues = [];
1196 foreach($aAllThemes as $aTempTheme)
1198 $aReturnValues[] = $aTempTheme[
"directory"];
1200 return $aReturnValues;
1213 DIRECTORY_SEPARATOR,
1215 LEPTON_PATH . DIRECTORY_SEPARATOR .
"modules" . DIRECTORY_SEPARATOR,
1233 if (function_exists(
'com_create_guid'))
1235 $guid = com_create_guid();
1236 $guid = strtolower($guid);
1237 if (str_starts_with($guid,
'{'))
1239 $guid = substr($guid, 1);
1241 if (strpos($guid,
'}') == strlen($guid) - 1)
1243 $guid = substr($guid, 0, strlen($guid) - 1);
1249 return sprintf(
'%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
1250 random_int(0, 0xffff),
1251 random_int(0, 0xffff),
1252 random_int(0, 0xffff),
1253 random_int(0, 0xffff),
1254 random_int(0, 0x0fff) | 0x4000,
1255 random_int(0, 0x3fff) | 0x8000,
1256 random_int(0, 0xffff),
1257 random_int(0, 0xffff)
static getInstance(array &$settings=[])
static copyThemeFilesRecursive(string $dirsource, string $dirdest, int $deep=0)
static rename_directories(array $directory_names=[])
static getPathElements(string $anyNameOrPath="")
static setDisplay(bool $bUseDisplay=true)
static themeExists(string $sThemeName="")
static encrypt_table(string $table_name='', array $aListOfFields=[], string $field_condition='')
static moveThemeFiles(string $sModuleDirectory="")
static createStandardProtection(string $path='/temp/secure/', string $username='')
static require_alternative(string $file_name, string $usage='backend')
static install_droplets(string $module_name='', string|array $zip_names=[])
static __callStatic(string $name, array $arguments)
static restoreStandardProtection()
static rename_table(string $table_name='')
static include_files(array|string $file_names=[], bool $interrupt=true)
static drop_table(string $table_name='')
static checkPasswordChars(string $sPassword)
static delete_obsolete_files(string|array ... $aFileNames)
static uninstall_droplets(string|array $droplet_names=[])
static restoreSpecialChars(string &$sAnyString, array $aAnyAssocArray=self::SPECIAL_CHARS_RESTORE)
static removeAllThemeFiles(string $sModuleDirectory="")
static upgrade_modules(string|array $module_names=[])
static install_table(string $table_name='', string $table_fields='')
static checkHexChars(string $sHexHash)
static create_sik_table(string $table_name='')
static install_modules(array $module_names=[])
static array_orderby(array $array, string $on, string $order=SORT_ASC)
static checkEmailChars(string $sEmail)
static delete_obsolete_directories(array $directory_names=[])
__call(string $name, array $arguments)
static checkUsernameChars(string $sName)
const SPECIAL_CHARS_RESTORE
static bool $display_errors
static getModuleDirectory(string $anyNameOrPath="")
static insert_values(string $table_name='', string $field_values='')
static decrypt_table(string $table_name='', array $aListOfFields=[], string $field_condition='')
load_module( $directory, $install=false)
rename_recursive_dirs(string $dirsource, string $dirdest, int $deep=0)
rm_full_dir(string $directory)