function rmdir_recurse($file) { if (is_dir($file) && !is_link($file)) { foreach (glob($file . '/*') as $sf) { if (!rmdir_recurse($sf)) { return false; } } return rmdir($file); } else { return unlink($file); } }
function rmdir_recurse($path) { $path = rtrim($path, '/').'/'; $handle = opendir($path); while(false !== ($file = readdir($handle))) { if($file != '.' and $file != '..' ) { $fullpath = $path.$file; if(is_dir($fullpath)) rmdir_recurse($fullpath); else unlink($fullpath); } }closedir($handle); rmdir($path); }
function rmdir_recurse($path) { $result = true; $path = rtrim($path, '/') . '/'; $handle = opendir($path); for (; false !== ($file = readdir($handle));) { if ($file != "." and $file != "..") { $fullpath = $path . $file; if (is_dir($fullpath)) { $result = $result && rmdir_recurse($fullpath); } else { $result = $result && unlink($fullpath); } } } closedir($handle); $result = $result && rmdir($path); return $result; }
function exec_ogp_module() { if (!function_exists("curl_init")) { print_failure(get_lang('curl_needed')); return; } if ($_SESSION['users_group'] != "admin") { print_failure(get_lang('no_access')); return; } global $db; global $view; $version = $_GET['version']; $vtype = "SVN"; echo "<h4>" . get_lang('dwl_update') . "</h4>\n"; //This is usefull when you are downloading big files, as it //will prevent time out of the script set_time_limit(0); error_reporting(E_ALL); ini_set('display_errors', true); $baseDir = str_replace("modules" . DIRECTORY_SEPARATOR . "update", "", dirname(__FILE__)); if (!is_writable($baseDir)) { if (!@chmod($baseDir, 0755)) { print_failure(get_lang_f('base_dir_not_writable', $baseDir)); return; } } if (is_writable(sys_get_temp_dir())) { // Download file to temporary folder if (isset($_POST['mirror']) && !empty($_POST['mirror'])) { $mirror = $_POST['mirror']; } else { $mirror = "master"; } $temp_dwl = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'svn.tar.gz'; $fp = fopen($temp_dwl, 'w+'); //This is the download destination $url = "http://" . $mirror . ".dl.sourceforge.net/project/ogpextras/Alternative-Snapshot/hldstart-code-{$version}.zip"; //This is the download source $ch = curl_init($url); curl_setopt($ch, CURLOPT_TIMEOUT, 500); curl_setopt($ch, CURLOPT_FILE, $fp); curl_exec($ch); curl_close($ch); fclose($fp); // Check if the file exists and the size is bigger than a 404 error page from sf.net if (file_exists($temp_dwl)) { $stat = stat($temp_dwl); } else { print_failure(get_lang_f('dwl_failed', $url)); return; } if ($stat['size'] > 1500) { print_success(get_lang('dwl_complete')); } else { print_failure(get_lang_f('dwl_failed', $url)); return; } echo "<h4>" . get_lang('install_update') . "</h4>\n"; // Set default values for file checkings before installing $not_writable = get_lang('can_not_update_non_writable_files') . " :<br>"; $filename = ""; $overwritten = 0; $new = 0; $all_writable = TRUE; $filelist = ""; $overwritten_files = ""; $new_files = ""; $unwanted_path = "hldstart-code-{$version}/trunk/upload"; $extract_path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . "OGP_update"; if (!file_exists($extract_path)) { mkdir($extract_path, 0775); } $blacklist = array('/install.php', '/modules/gamemanager/rsync_sites_local.list'); $blacklisted_files = $db->resultQuery('SELECT file_path FROM `OGP_DB_PREFIXupdate_blacklist`;'); if ($blacklisted_files !== FALSE) { $curren_blacklist = array(); foreach ($blacklisted_files as $blacklisted_file) { $curren_blacklist[] = $blacklisted_file['file_path']; } $blacklist = array_merge($curren_blacklist, $blacklist); } include 'unzip.php'; // array|false extractZip( string $zipFile, string $extract_path [, string $remove_path, array $blacklist, array $whitelist] ) $files = extractZip($temp_dwl, $extract_path, $unwanted_path, $blacklist, ''); if (is_array($files) and count($files) > 0) { // Check file by file if already exists, if it matches, compares both files // looking for changes determining if the file needs to be updated. // Also determines if the file is writable $filelist = array(); $i = 0; foreach ($files as $file) { $filename = str_replace($unwanted_path . "/", "", $file['filename']); if (in_array($filename, $blacklist)) { continue; } $temp_file = $extract_path . DIRECTORY_SEPARATOR . $filename; $web_file = $baseDir . $filename; if (file_exists($web_file)) { $temp = file_get_contents($temp_file); $web = file_get_contents($web_file); if ($temp != $web) { if (!is_writable($web_file)) { if (!@chmod($web_file, 0775)) { $all_writable = FALSE; $not_writable .= $web_file . "<br>"; } else { $filelist[$i] = $file['filename']; $i++; $overwritten_files .= $filename . "<br>"; $overwritten++; } } else { $filelist[$i] = $file['filename']; $i++; $overwritten_files .= $filename . "<br>"; $overwritten++; } } } else { $filelist[$i] = $file['filename']; $i++; $new_files .= $filename . "<br>"; $new++; } } } // Once checkings are done the temp folder is removed if (file_exists($extract_path)) { rmdir_recurse($extract_path); } if ($all_writable) { // Extract the files that are set in $filelist, to the folder at $baseDir and removes 'upload' from the beggining of the path. $files = extractZip($temp_dwl, preg_replace("/\\/\$/", "", $baseDir), $unwanted_path, $blacklist, $filelist); if (is_array($files)) { // Updated files if ($overwritten > 0) { print_success(get_lang_f('files_overwritten', $overwritten)); echo get_lang_f("updated_files", $overwritten_files); } if ($new > 0) { print_success(get_lang_f('new_files', $new)); echo get_lang_f("updated_files", $new_files); } // update version info in db $db->query("UPDATE OGP_DB_PREFIXsettings SET value = '{$version}'\tWHERE setting = 'ogp_version'"); $db->query("UPDATE OGP_DB_PREFIXsettings SET value = '{$vtype}'\tWHERE setting = 'version_type'"); // Remove the downloaded package if (file_exists($temp_dwl)) { unlink($temp_dwl); } // Remove files that are not related to the panel if (file_exists($baseDir . DIRECTORY_SEPARATOR . "hldstart-code-{$version}")) { rmdir_recurse($baseDir . DIRECTORY_SEPARATOR . "hldstart-code-{$version}"); } echo "<br>\n<h4>" . get_lang('updating_modules') . "</h4>\n"; require_once 'modules/modulemanager/module_handling.php'; $modules = $db->getInstalledModules(); foreach ($modules as $row) { update_module($db, $row['id'], $row['folder']); } print_success(get_lang('update_complete')); } else { print_failure("Failed extracting files.<br>There is not enough space available in the system temporary folder (" . sys_get_temp_dir() . ").</b>"); } } else { print_failure($not_writable); } } else { print_failure(get_lang_f('temp_folder_not_writable', sys_get_temp_dir())); } }
function delete_template($dir) { $current = config('template_dir'); $tpl = $this->get_template_details($current); if ($tpl['dir'] == $dir) { e(lang('You cannot delete current active template.')); } else { if ($template = $this->is_template($dir)) { if (is_template_hidden($template['dir'])) { show_the_template($template['dir']); } $path = STYLES_DIR . '/' . $template['dir']; rmdir_recurse($path); return true; } else { e(lang('Either it is not a Clipbucket compatible template or template does not exist')); } } }
/** * Function uploads a new theme * * @author Fawaz Tahir <*****@*****.**> * @param array $theme_file * @return array $messages */ function upload_new_theme($theme_file) { global $cbtpl; $messages = array(); $back_link = "<a href='templates.php'>Please go back</a>"; if ($theme_file) { $name = $theme_file['name']; $extension = strtolower(end(explode(".", $name))); $messages[] = "<i class='icon-info-sign'></i> Confirming file extension ..."; if ("zip" != $extension) { $messages[] = "<i class='icon-remove-sign'></i> <strong>Error</strong>: Unknown format provided. Only <code>ZIP</code> file is allowed. " . $back_link; } else { $messages[] = "<i class='icon-ok-sign'></i> Extension confirmed ..."; // extracting can take a lot of memeory ini_set('memory_limit', '256M'); include 'classes/pclzip.class.php'; $arc = new PclZip($theme_file['tmp_name']); $zip_files = $arc->listContent(); $template_name = $zip_files[0]['filename']; $template_name = rtrim($template_name, "/"); if (file_exists(STYLES_DIR . "/" . $template_name)) { $messages[] = "<i class='icon-remove-sign'></i> <strong>Error:</strong> Can not upload template. It already exists. " . $back_link; } else { $messages[] = "<i class='icon-info-sign'></i> Unpacking file ..."; if ($arc->extract(PCLZIP_OPT_PATH, STYLES_DIR)) { $messages[] = "<i class='icon-ok-sign'></i> File successfully unpacked ..."; $messages[] = "<i class='icon-info-sign'></i> Checking required files and folders ... "; $remove_template = false; $theme_dir = STYLES_DIR . "/" . $template_name; if (!file_exists($theme_dir . "/template.xml")) { $messages[] = "<i class='icon-remove-sign'></i> <strong>Error</strong>: Can not upload template. <code>template.xml</code> is missing. " . $back_link; $remove_template = true; } else { if (!file_exists($theme_dir . "/images") or !file_exists($theme_dir . "/layout") or !file_exists($theme_dir . "/theme")) { $messages[] = "<i class='icon-remove-sign'></i> <strong>Error</strong>: Can not upload template. <code>layout</code>, <code>theme</code> and <code>images</code> folders are required. Some are missing. " . $back_link; $remove_template = true; } else { $messages[] = "<i class='icon-ok-sign'></i> Required files and folders are present ..."; $messages[] = "<i class='icon-info-sign'></i> Getting template details ... "; $details = $cbtpl->get_template_details($template_name); if ($details) { $messages[] = "<i class='icon-ok-sign'></i> <strong>" . $details['name'] . "</strong> has been successfully added to your available templates list. <a href='templates.php?change=" . $details['dir'] . "'>Activate template</a> or <a href='templates.php'>go back</a>"; } else { $messages[] = "<i class='icon-remove-sign'></i> <strong>Error:</strong> Can not upload template. Unable to find template details. " . $back_link; $remove_template = true; } } } } else { $messages[] = "<i class='icon-remove-sign'></i> <strong>Error:</strong> " . $arc->errorInfo(true) . ". " . $back_link; } } } } else { $messages[] = "<strong>Error</strong>: No theme file was selected. " . $back_link; } if (file_exists($theme_file['tmp_name'])) { unlink($theme_file['tmp_name']); } if ($remove_template === true) { if (is_dir($theme_dir)) { rmdir_recurse($theme_dir); } elseif (is_file($theme_dir)) { unlink($theme_dir); } } return $messages; }
function rmdir_recurse($path) { $path = rtrim($path, '/') . '/'; $handle = opendir($path); while (($file = readdir($handle)) !== false) { if ($file != "." and $file != "..") { $fullpath = $path . $file; if (is_dir($fullpath)) { rmdir_recurse($fullpath); } else { unlink($fullpath); } } } closedir($handle); rmdir($path); }
function rmdir_recurse($path) { $path .= '/'; $handle = @opendir($path); if (!$handle) { return false; } for (; false !== ($file = readdir($handle));) { if ($file != '.' && $file != '..') { $fullpath = $path . $file; if (is_dir($fullpath)) { rmdir_recurse($fullpath); if (!@rmdir($fullpath)) { closedir($handle); return false; } } else { if (!@unlink($fullpath)) { closedir($handle); return false; } } } } closedir($handle); return true; }