function recurse_php2phps_copy($src, $dst) { $dir = opendir($src); @mkdir($dst); while (false !== ($file = readdir($dir))) { if ($file != '.' && $file != '..') { if (is_dir($src . '/' . $file)) { recurse_php2phps_copy($src . '/' . $file, $dst . '/' . $file); } else { copy($src . '/' . $file, $dst . '/' . php2phps($file)); } } } closedir($dir); }
$file_name = $_FILES['themeFile']['name']; $file_name = php2phps($file_name); if(!is_dir("courses/theme_data")) mkdir("courses/theme_data", 0755); if (move_uploaded_file($_FILES['themeFile']['tmp_name'], "courses/theme_data/$file_name")) { require_once 'include/pclzip/pclzip.lib.php'; $archive = new PclZip("$webDir/courses/theme_data/$file_name"); if ($archive->extract(PCLZIP_OPT_PATH, 'courses/theme_data/temp') == 0) { die("Error : ".$archive->errorInfo(true)); } else { unlink("$webDir/courses/theme_data/$file_name"); $base64_str = file_get_contents("$webDir/courses/theme_data/temp/theme_options.txt"); unlink("$webDir/courses/theme_data/temp/theme_options.txt"); $theme_options = unserialize(base64_decode($base64_str)); $new_theme_id = Database::get()->query("INSERT INTO theme_options (name, styles) VALUES(?s, ?s)", $theme_options->name, $theme_options->styles)->lastInsertID; @rename("$webDir/courses/theme_data/temp/".intval($theme_options->id), "$webDir/courses/theme_data/temp/$new_theme_id"); recurse_php2phps_copy("$webDir/courses/theme_data/temp","$webDir/courses/theme_data"); removeDir("$webDir/courses/theme_data/temp"); Session::Messages($langThemeInstalled); } } } else { Session::Messages($langUnwantedFiletype); } redirect_to_home_page('modules/admin/theme_options.php'); } if (isset($_POST['optionsSave'])) { upload_images(); clear_default_settings(); $serialized_data = serialize($_POST); Database::get()->query("UPDATE theme_options SET styles = ?s WHERE id = ?d", $serialized_data, $theme_id); redirect_to_home_page('modules/admin/theme_options.php');