/** * Deletes a directory (with recursive sub-directory support) * * @parm string Path of directory to remove * @return bool True on success, false on fail * */ function INST_deleteDir($path) { if (!is_string($path) || $path == "") { return false; } if (function_exists('set_time_limit')) { @set_time_limit(30); } if (@is_dir($path)) { if (!($dh = @opendir($path))) { return false; } while (false !== ($f = readdir($dh))) { if ($f == '..' || $f == '.') { continue; } INST_deleteDir("{$path}/{$f}"); } closedir($dh); return @rmdir($path); } else { return @unlink($path); } return false; }
/** * Removes unused / obsolete files from tree. * * @return html a list of files removed or errors if there were any... * */ function INST_doFileCleanUp() { global $_GLFUSION, $_CONF, $_TABLES, $LANG_INSTALL; global $obsoletePrivateDir, $obsoletePublicDir, $obsoletePrivateFiles, $obsoletePublicFiles; $language = $_GLFUSION['language']; $_GLFUSION['currentstep'] = 'complete'; $retval = ''; $failure = ''; if (isset($obsoletePrivateFiles) && is_array($obsoletePrivateFiles) && count($obsoletePrivateFiles) > 0) { foreach ($obsoletePrivateFiles as $file) { if (file_exists($_CONF['path'] . $file)) { $rc = @unlink($_CONF['path'] . $file); if ($rc === false) { $failure .= '<li>FILE: ' . $_CONF['path'] . $file . '</li>'; } } } } if (isset($obsoletePublicFiles) && is_array($obsoletePublicFiles) && count($obsoletePublicFiles) > 0) { foreach ($obsoletePublicFiles as $file) { if (file_exists($_CONF['path_html'] . $file)) { $rc = @unlink($_CONF['path_html'] . $file); if ($rc === false) { $failure .= '<li>FILE: ' . $_CONF['path_html'] . $file . '</li>'; } } } } if (isset($obsoletePublicDir) && is_array($obsoletePublicDir) && count($obsoletePublicDir) > 0) { foreach ($obsoletePublicDir as $directory) { if (is_dir($_CONF['path_html'] . $directory)) { $rc = INST_deleteDir($_CONF['path_html'] . $directory); if ($rc === false) { $failure .= '<li>DIR: ' . $_CONF['path_html'] . $directory . '</li>'; } } } } if (isset($obsoletePrivateDir) && is_array($obsoletePrivateDir) && count($obsoletePrivateDir) > 0) { foreach ($obsoletePrivateDir as $directory) { if (is_dir($_CONF['path'] . $directory)) { $rc = INST_deleteDir($_CONF['path'] . $directory); if ($rc === false) { $failure .= '<li>DIR: ' . $_CONF['path'] . $directory . '</li>'; } } } } // special handling of the theme files from 1.5.0 and 1.5.1 if ($_GLFUSION['original_version'] == '1.5.0' || $_GLFUSION['original_version'] == '1.5.1') { if (file_exists('deleted15.php')) { include 'deleted15.php'; if (isset($obsoleteTemplateFiles) && is_array($obsoleteTemplateFiles) && count($obsoleteTemplateFiles) > 0) { foreach ($obsoleteTemplateFiles as $item) { if (file_exists($_CONF['path_html'] . $item['file'])) { $sha = sha1_file($_CONF['path_html'] . $item['file']); if ($sha == $item['sha1']) { $rc = @unlink($_CONF['path_html'] . $item['file']); if ($rc === false) { $failure .= '<li>FILE: ' . $_CONF['path_html'] . $item['file'] . '</li>'; } } else { COM_errorLog("UPGRADE: Keeping modified template file: " . $item['file']); } } } } } if (isset($obsoleteTemplateDir) && is_array($obsoleteTemplateDir) && count($obsoleteTemplateDir) > 0) { foreach ($obsoleteTemplateDir as $directory) { if (is_dir($_CONF['path_html'] . $directory)) { $rc = INST_deleteDirIfEmpty($_CONF['path_html'] . $directory); } } } } // test failure message //$failure = '<li>DIR: Test failure message</li><li>FILE: /www/www/www/www.txt</li>'; if ($failure == '') { $method = $_GLFUSION['method']; header('Location: success.php?type=' . $method . '&language=' . $language); exit; } $T = new TemplateLite('templates/'); $T->set_file('page', 'removefiles_complete.thtml'); $T->set_var(array('step_heading' => $LANG_INSTALL['obsolete_confirm'], 'lang_complete' => $LANG_INSTALL['complete'], 'hiddenfields' => _buildHiddenFields())); if ($failure != '') { $T->set_var(array('confirm_heading' => $LANG_INSTALL['obsolete_confirm'], 'confirm_message' => '<div class="uk-alert uk-alert-danger">' . $LANG_INSTALL['removal_fail_msg'] . '</div>', 'confirm_details' => '<ul class="uk-list uk-list-striped">' . $failure . '</ul>')); } else { $T->set_var(array('confirm_heading' => $LANG_INSTALL['removal_success'], 'confirm_details' => $LANG_INSTALL['removal_success_msg'])); } $T->parse('output', 'page'); return $T->finish($T->get_var('output')); }