function remove_dir($dirname) { global $messageStack; $error = false; if ($dir = @dir($dirname)) { $dir->rewind(); while ($file = $dir->read()) { //echo $dirname . '/' . $file . '<br />'; if ($file != "." && $file != ".." && $file != ".htaccess" && $file != ".keep") { if (is_dir($dirname . '/' . $file)) { // another directory, recurse $error |= remove_dir($dirname . '/' . $file); // if it was a directory, it should be empty now if (!@rmdir($dirname . '/' . $file)) { $error |= true; $messageStack->add('Couldn\'t delete ' . $dirname . '/' . $file . '.', 'error'); } } else { if (!@unlink($dirname . '/' . $file)) { $error |= true; $messageStack->add('Couldn\'t delete ' . $dirname . '/' . $file . '.', 'error'); } } } } $dir->close(); } else { $error |= true; } return $error; }
public function deleteEntirely($include_this) { if (!$this->exists()) { return true; } remove_dir($this->getPath(), false); }
/** * Purge all caches when settings changed. */ function filter_tex_updatedcallback($name) { global $CFG, $DB; reset_text_filters_cache(); if (file_exists("{$CFG->dataroot}/filter/tex")) { remove_dir("{$CFG->dataroot}/filter/tex"); } if (file_exists("{$CFG->dataroot}/filter/algebra")) { remove_dir("{$CFG->dataroot}/filter/algebra"); } if (file_exists("{$CFG->tempdir}/latex")) { remove_dir("{$CFG->tempdir}/latex"); } $DB->delete_records('cache_filters', array('filter' => 'tex')); $DB->delete_records('cache_filters', array('filter' => 'algebra')); if (!isset($CFG->filter_tex_pathlatex)) { // detailed settings not present yet return; } $pathlatex = trim($CFG->filter_tex_pathlatex, " '\""); $pathdvips = trim($CFG->filter_tex_pathdvips, " '\""); $pathconvert = trim($CFG->filter_tex_pathconvert, " '\""); if (!(is_file($pathlatex) && is_executable($pathlatex) && is_file($pathdvips) && is_executable($pathdvips) && is_file($pathconvert) && is_executable($pathconvert))) { // LaTeX, dvips or convert are not available, and mimetex can only produce GIFs so... set_config('filter_tex_convertformat', 'gif'); } }
function finish($postid, $cloneid, $url, $fromform, $uploadfolder, $ajaxdata = '') { // Clear out used playspace and/or uploadfolder if (isset($fromform->attachmentplayspace)) { // Unless we're keeping it, wipe the playspace forum::delete_attachment_playspace($fromform->attachmentplayspace, optional_param('keepplayspace', 0, PARAM_INT)); } // Get rid of temporary upload folder if ($uploadfolder) { remove_dir($uploadfolder); } global $ajax; if ($ajax) { if ($ajaxdata) { // Print AJAX data if specified header('Content-Type: text/plain'); print $ajaxdata; exit; } else { // Default otherwise is to print post forum_post::print_for_ajax_and_exit($postid, $cloneid, array(forum_post::OPTION_DISCUSSION_SUBJECT => true)); } } redirect($url); }
function game_OnExportHTML($game, $context, $html) { global $CFG; /* if( $game->gamekind == 'cross'){ $destdir = "{$CFG->dataroot}/{$game->course}/export"; if( !file_exists( $destdir)){ mkdir( $destdir); } game_OnExportHTML_cross( $game, $context, $html, $destdir); return; } */ $destdir = game_export_createtempdir(); switch ($game->gamekind) { case 'cross': game_OnExportHTML_cross($game, $context, $html, $destdir); break; case 'hangman': game_OnExportHTML_hangman($game, $context, $html, $destdir); break; case 'snakes': game_OnExportHTML_snakes($game, $html, $destdir); break; case 'millionaire': game_OnExportHTML_millionaire($game, $context, $html, $destdir); break; } remove_dir($destdir); }
function tearDown() { global $CFG, $db; if (!is_null($this->real_dataroot) && $this->real_dataroot != $CFG->dataroot) { remove_dir($CFG->dataroot); } $db = $this->real_db; $CFG->dataroot = $this->real_dataroot; }
public function __construct() { $path = __STORAGE . '/DirectoryTest'; if (is_dir($path)) { if (!remove_dir($path)) { echo "Ooh epic!"; die; } } $this->instance = new Directory($path, true); }
function create_incremental($courseid, $oldbackup, $newbackup) { global $CFG; $incremental_config = backup_get_config(); //set directory paths if (!empty($incremental_config->backup_inc_destination)) { $backuppath = $incremental_config->backup_inc_destination . '/' . $courseid . '/'; } else { $backuppath = $CFG->dataroot . '/' . $courseid . '/backupdata/'; } $temppath = $CFG->dataroot . '/temp/incrementals/' . $courseid . '/'; $newtempdir = str_ireplace('backup-', '', str_ireplace('.zip', '', $newbackup)); //strip out .zip and backup from the string. $oldtempdir = str_ireplace('backup-', '', str_ireplace('.zip', '', $oldbackup)); if (!check_dir_exists($temppath . $newtempdir, true, true)) { //now create folder for newtempdir error('failed to create temp dir for new backup' . $temppath . $newtempdir); } if (!check_dir_exists($temppath . $oldtempdir, true, true)) { //now create folder for newtempdir error('failed to create temp dir for old backup' . $temppath . $oldtempdir); } //create incremental directory if doesn't exist if (!check_dir_exists($backuppath . 'incrementals', true, true)) { error('failed to create incrementals directory'); } //unzip each backup file into the temp dirs if (!unzip_file($backuppath . $oldbackup, $temppath . $oldtempdir, false)) { error('Couldn\'t unzip old backup'); } if (!unzip_file($backuppath . $newbackup, $temppath . $newtempdir, false)) { error('Couldn\'t unzip new backup'); } //now run the compare against both and create the diff. $mydiff = new xdelta(); $mydiff->create_diff($temppath . $oldtempdir, $temppath . $newtempdir, $backuppath . 'incrementals/' . md5($oldbackup) . '-' . md5($newbackup) . '.zip'); if (isset($mydiff->error)) { if ($mydiff->error == 'coursenotchanged') { //this course has not changed since the last backup so don't generate any more incrementals - and return false so that the $newbackup can be deleted. remove_dir($temppath . $oldtempdir); remove_dir($temppath . $newtempdir); return false; } else { print_object($mydiff); error("XDELTA diff failed!!- olddir:" . $temppath . $oldtempdir . "<br>Newdir:" . $temppath . $newtempdir . "<br>Backuppath:" . $backuppath . 'incrementals/' . md5($oldbackup) . '-' . md5($newbackup) . '.zip'); } } //now delete the tmp directories. remove_dir($temppath . $oldtempdir); remove_dir($temppath . $newtempdir); return true; }
function useredit_update_picture(&$usernew, &$userform) { global $CFG; if (isset($usernew->deletepicture) and $usernew->deletepicture) { $location = $CFG->dataroot . '/users/' . $usernew->id; @remove_dir($location); set_field('user', 'picture', 0, 'id', $usernew->id); } else { if ($usernew->picture = save_profile_image($usernew->id, $userform->get_um(), 'users')) { set_field('user', 'picture', 1, 'id', $usernew->id); } } }
function useredit_update_picture(&$usernew, &$userform) { global $CFG; if (isset($usernew->deletepicture) and $usernew->deletepicture) { $location = make_user_directory($usernew->id, true); @remove_dir($location); set_field('user', 'picture', 0, 'id', $usernew->id); } else { if ($usernew->picture = save_profile_image($usernew->id, $userform->get_um(), 'user')) { set_field('user', 'picture', 1, 'id', $usernew->id); } } }
function useredit_update_picture(&$usernew, $userform) { global $CFG, $DB; if (isset($usernew->deletepicture) and $usernew->deletepicture) { $location = make_user_directory($usernew->id, true); @remove_dir($location); $DB->set_field('user', 'picture', 0, array('id' => $usernew->id)); } else { if ($userform->get_new_filename('imagefile')) { $usernew->picture = (int) save_profile_image($usernew->id, $userform, 'user', 'imagefile'); $DB->set_field('user', 'picture', $usernew->picture, array('id' => $usernew->id)); } } }
/** * This page export the game to javame for mobile phones * * @author bdaloukas * @version $Id: exportjavame.php,v 1.17 2011/08/03 20:04:32 bdaloukas Exp $ * @package game **/ function game_OnExportJavaME($game, $javame) { global $CFG, $DB; $courseid = $game->course; $course = $DB->get_record('course', array('id' => $courseid)); $destdir = game_export_createtempdir(); if ($javame->type == 'hangmanp') { $destmobiledir = 'hangmanp'; } else { $destmobiledir = 'hangman'; } $src = $CFG->dirroot . '/mod/game/export/javame/' . $destmobiledir . '/simple'; if ($javame->filename == '') { $javame->filename = 'moodle' . $destmobiledir; } $handle = opendir($src); while (false !== ($item = readdir($handle))) { if ($item != '.' && $item != '..') { if (!is_dir($src . '/' . $item)) { $itemdest = $item; if (substr($item, -5) == '.java') { continue; //don't copy the java source code files } if (substr($itemdest, -8) == '-1.class') { $itemdest = substr($itemdest, 0, -8) . '$1.class'; } copy($src . '/' . $item, $destdir . '/' . $itemdest); } } } mkdir($destdir . '/META-INF'); game_exportjavame_exportdata($src, $destmobiledir, $destdir, $game, $javame->maxpicturewidth, $javame->maxpictureheight); game_create_manifest_mf($destdir . '/META-INF', $javame, $destmobiledir); $filejar = game_create_jar($destdir, $course, $javame); if ($filejar == '') { $filezip = game_create_zip($destdir, $course->id, $javame->filename . '.zip'); } else { $filezip = ''; } if ($destdir != '') { remove_dir($destdir); } if ($filezip != '') { echo "unzip the {$filezip} in a directory and when you are in this directory use the command <br><b>jar cvfm {$javame->filename}.jar META-INF/MANIFEST.MF<br></b> to produce the jar files<br><br>"; } $file = $filejar != '' ? $filejar : $filezip; $fullfile = "{$CFG->dataroot}/{$courseid}/export/{$file}"; game_send_stored_file($fullfile); }
function remove_dir($folder) { $dir = dir($folder); while ($file = $dir->read()) { if ($file != '.' && $file != '..') { if (filetype($dir->path . $file) == 'file') { @unlink($dir->path . $file); } if (filetype($dir->path . $file) == 'dir') { remove_dir($dir->path . $file . '/'); } } } }
function cache() { global $_G; if ($_GET['onsubmit'] && check()) { if ($_GET[postdb][system_cache] == 1) { memory('clear'); loadcache($_G[_config][cache_list], 'update'); } api_post(array('m' => 'cache', 'a' => 'update', 'cache_list' => implode(',', $_G[_config][cache_list]))); remove_dir('web/templates_c/'); cpmsg('更新成功', 'success', 'm=tools&a=cache'); return false; } $this->show('tools/cache'); }
/** * Purge all caches when settings changed. */ function filter_tex_updatedcallback($name) { global $CFG; if (file_exists("{$CFG->dataroot}/filter/tex")) { remove_dir("{$CFG->dataroot}/filter/tex"); } if (file_exists("{$CFG->dataroot}/filter/algebra")) { remove_dir("{$CFG->dataroot}/filter/algebra"); } if (file_exists("{$CFG->dataroot}/temp/latex")) { remove_dir("{$CFG->dataroot}/temp/latex"); } delete_records('cache_filters', 'filter', 'tex'); delete_records('cache_filters', 'filter', 'algebra'); }
/** * process */ public static function process() { if (!theme_cache::current_user_can('manage_options')) { return false; } @ini_set('max_input_nesting_level', '10000'); @ini_set('max_execution_time', 0); remove_dir(theme_features::get_stylesheet_directory() . theme_features::$basedir_js_min); theme_features::minify_force(theme_features::get_stylesheet_directory() . theme_features::$basedir_js_src); remove_dir(theme_features::get_stylesheet_directory() . theme_features::$basedir_css_min); theme_features::minify_force(theme_features::get_stylesheet_directory() . theme_features::$basedir_css_src); theme_features::minify_force(theme_features::get_stylesheet_directory() . theme_features::$basedir_addons); theme_file_timestamp::set_timestamp(); wp_redirect(add_query_arg(__CLASS__, 1, theme_options::get_url())); die; }
/** * Purge all caches when settings changed. */ function filter_tex_updatedcallback($name) { global $CFG, $DB; reset_text_filters_cache(); if (file_exists("{$CFG->dataroot}/filter/tex")) { remove_dir("{$CFG->dataroot}/filter/tex"); } if (file_exists("{$CFG->dataroot}/filter/algebra")) { remove_dir("{$CFG->dataroot}/filter/algebra"); } if (file_exists("{$CFG->dataroot}/temp/latex")) { remove_dir("{$CFG->dataroot}/temp/latex"); } $DB->delete_records('cache_filters', array('filter' => 'tex')); $DB->delete_records('cache_filters', array('filter' => 'algebra')); }
/** * Testing cachestore_file::get with prescan enabled and with * deleting the cache between the prescan and the call to get. * * The deleting of cache simulates some other process purging * the cache. */ public function test_cache_get_with_prescan_and_purge() { global $CFG; $definition = cache_definition::load_adhoc(cache_store::MODE_REQUEST, 'cachestore_file', 'phpunit_test'); $name = 'File test'; $path = make_cache_directory('cachestore_file_test'); $cache = new cachestore_file($name, array('path' => $path, 'prescan' => true)); $cache->initialise($definition); $cache->set('testing', 'value'); $path = make_cache_directory('cachestore_file_test'); $cache = new cachestore_file($name, array('path' => $path, 'prescan' => true)); $cache->initialise($definition); // Let's pretend that some other process purged caches. remove_dir($CFG->cachedir . '/cachestore_file_test', true); make_cache_directory('cachestore_file_test'); $cache->get('testing'); }
function remove_dir($dir) { if (is_dir($dir)) { $objects = scandir($dir); foreach ($objects as $object) { if ($object != "." && $object != "..") { if (filetype($dir . "/" . $object) == "dir") { remove_dir($dir . "/" . $object); } else { unlink($dir . "/" . $object); } } } reset($objects); rmdir($dir); } }
function remove_dir($dir) { $handle = opendir($dir); while (false!==($item = readdir($handle))) { if($item != '.' && $item != '..') { if(is_dir($dir.'/'.$item)) { remove_dir($dir.'/'.$item); }else{ unlink($dir.'/'.$item); } } } closedir($handle); if(rmdir($dir)) { $success = true; } return $success; }
/** * Purge all caches when settings changed. */ function filter_tex_updatedcallback($name) { global $CFG; reset_text_filters_cache(); if (file_exists("{$CFG->dataroot}/filter/tex")) { remove_dir("{$CFG->dataroot}/filter/tex"); } if (file_exists("{$CFG->dataroot}/filter/algebra")) { remove_dir("{$CFG->dataroot}/filter/algebra"); } if (file_exists("{$CFG->dataroot}/temp/latex")) { remove_dir("{$CFG->dataroot}/temp/latex"); } delete_records('cache_filters', 'filter', 'tex'); delete_records('cache_filters', 'filter', 'algebra'); if (!(is_file($CFG->filter_tex_pathlatex) && is_executable($CFG->filter_tex_pathlatex) && is_file($CFG->filter_tex_pathdvips) && is_executable($CFG->filter_tex_pathdvips) && is_file($CFG->filter_tex_pathconvert) && is_executable($CFG->filter_tex_pathconvert))) { // LaTeX, dvips or convert are not available, and mimetex can only produce GIFs so... set_config('filter_tex_convertformat', 'gif'); } }
function game_OnExportHTML($game, $context, $html) { global $CFG; $destdir = game_export_createtempdir(); switch ($game->gamekind) { case 'cross': game_OnExportHTML_cross($game, $context, $html, $destdir); break; case 'hangman': game_OnExportHTML_hangman($game, $context, $html, $destdir); break; case 'snakes': game_OnExportHTML_snakes($game, $html, $destdir, $context); break; case 'millionaire': game_OnExportHTML_millionaire($game, $context, $html, $destdir); break; } remove_dir($destdir); }
function remove_dir($directory) { $dir = opendir($directory); try { while ($file = readdir($dir)) { if (is_file("{$directory}/{$file}")) { unlink("{$directory}/{$file}"); } else { if (is_dir("{$directory}/{$file}") && $file !== '.' && $file !== '..') { remove_dir("{$directory}/{$file}"); } } } closedir($dir); rmdir($directory); return 1; } catch (Exception $e) { return 0; } }
function remove_dir($path) { if (file_exists($path) && is_dir($path)) { $dirHandle = opendir($path); while (false !== ($file = readdir($dirHandle))) { if ($file != '.' && $file != '..') { $tmpPath = $path . '/' . $file; if (is_dir($tmpPath)) { remove_dir($tmpPath); } else { if (file_exists($tmpPath)) { unlink($tmpPath); } } } } closedir($dirHandle); if (file_exists($path)) { rmdir($path); } } }
function close() { global $CFG; require_once $CFG->libdir . '/filelib.php'; $dir = 'temp/ods/' . time(); make_upload_directory($dir); make_upload_directory($dir . '/META-INF'); $dir = "{$CFG->dataroot}/{$dir}"; $files = array(); $handle = fopen("{$dir}/mimetype", 'w'); fwrite($handle, get_ods_mimetype()); $files[] = "{$dir}/mimetype"; $handle = fopen("{$dir}/content.xml", 'w'); fwrite($handle, get_ods_content($this->worksheets)); $files[] = "{$dir}/content.xml"; $handle = fopen("{$dir}/meta.xml", 'w'); fwrite($handle, get_ods_meta()); $files[] = "{$dir}/meta.xml"; $handle = fopen("{$dir}/styles.xml", 'w'); fwrite($handle, get_ods_styles()); $files[] = "{$dir}/styles.xml"; $handle = fopen("{$dir}/META-INF/manifest.xml", 'w'); fwrite($handle, get_ods_manifest()); $files[] = "{$dir}/META-INF"; $filename = "{$dir}/result.ods"; zip_files($files, $filename); $handle = fopen($filename, 'rb'); $contents = fread($handle, filesize($filename)); fclose($handle); remove_dir($dir); // cleanup the temp directory send_file($contents, $this->filename, 0, 0, true, true, 'application/vnd.oasis.opendocument.spreadsheet'); }
$ret .= '$string' . "[ '{$name}'] = " . $strings_lang[$name] . "\r\n"; } } if ($lang != 'en') { $untranslated = $auntranslated[$lang]; if ($untranslated != '') { $ret .= "\r\n//Untranslated\r\n" . $untranslated; } } mkdir($destdir . '/' . $lang); $file = $destdir . '/' . $lang . '/game.php'; file_put_contents($file, $ret); } $file_sorted = 'game_lang_sorted.zip'; $filezip = game_create_zip($destdir, $COURSE->id, $file_sorted); remove_dir($destdir); echo "<br><a href=\"{$CFG->wwwroot}/file.php/1/export/{$file_sorted}\">Sorted translation files</a>"; asort($en); $sprev = ''; $keyprev = ''; $ret = ''; foreach ($en as $key => $s) { if ($s == $sprev) { $ret .= "<tr><td>{$key}</td><td>{$keyprev}</td><td>{$s}</td></tr>\r\n"; } $sprev = $s; $keyprev = $key; } if ($ret != '') { echo '<br><center><b>Same translations<center></b><br><table border=1><tr><td><b>Word1</td><td><b>Word2</td><td><b>Translation</td></tr>' . $ret . '</table>'; }
/** * Reset RSS cache * * @return boolean success if cache clear or didn't exist */ public static function reset_cache() { $cachedir = moodle_simplepie::get_cache_directory(); return remove_dir($cachedir); }
/** * Resets all data related to filters, called during upgrade or when filter settings change. * * @global object * @global object * @return void */ function reset_text_filters_cache() { global $CFG, $DB; $DB->delete_records('cache_text'); $purifdir = $CFG->dataroot . '/cache/htmlpurifier'; remove_dir($purifdir, true); }
function remove_dir($dir) { if (!file_exists($dir)) { return true; } if (!is_dir($dir) || is_link($dir)) { return unlink($dir); } foreach (scandir($dir) as $item) { if ($item == '.' || $item == '..') { continue; } if (!remove_dir($dir . "/" . $item)) { chmod($dir . "/" . $item, 0777); if (!remove_dir($dir . "/" . $item)) { return false; } } } return rmdir($dir); }
public function __destruct() { if (!debugging('', DEBUG_DEVELOPER)) { remove_dir($this->tempdir); } }