getMessage()); } log_print("generating thumbnail for $original_file"); $output = shell_exec(THUMBNAIL_SCRIPT." '$original_file' '$thumbnail_file' 2>&1"); if ($output) log_print($output); if (substr_count(strtolower((string) $output), "error")) { log_error("Thumbnail failed"); log_print(ROOT_URL.IMG_DIR.$path); return ROOT_URL.IMG_DIR.$path; } return_thumbnail: return ROOT_URL.THUMBNAIL_DIR.$thumbnail_name; } function add_seperator_ab(string $separator, string $a, string $b): string { if ($a === "") return $b; return $a.$separator.$b; } function is_valid_file_type(string $filename): bool { foreach (FILE_EXTENSIONS as $file_extension) { if (str_ends_with($filename, $file_extension)) return true; } return false; } function is_image_file_type(string $filename): bool { foreach(IMAGE_EXTENSIONS as $file_extension) { if(str_ends_with($filename, $file_extension)) return true; } return false; } function get_config(): array { $config_data = file_exists(__DIR__ . "/../config.json") ? json_decode(file_get_contents(__DIR__ . "/../config.json"), true) : null; if (!is_valid_config_data($config_data)) { log_error("Config invalid, falling back to default. Please check config.json"); $config_data = json_decode(file_get_contents(__DIR__ . "/../config.default.json"), true); if (!is_valid_config_data($config_data)) log_error("Default config invalid. Please check or create config.json"); } return $config_data; } function is_valid_config_data(?array $data): bool { if (!$data) return false; $keys = ["ROOT_URL", "ROOT_DIR", "IMG_DIR", "THUMBNAIL_DIR"]; foreach ($keys as $key) { if (!isset($data[$key])) return false; switch ($key) { case "ROOT_URL": case "THUMBNAIL_DIR": break; case "ROOT_DIR": if (!is_dir($data[$key])) return false; break; case "IMG_DIR": if (!is_dir($data["ROOT_DIR"].$data[$key])) return false; break; } } return true; } main(); ?>