/** * deletes a directory recursively * Bf_Filesystem::deleteRecursive(JPATH_ROOT .'/tmp', TRUE); * * @param string $target * @param bool $ignoreWarnings * @param array $msg * * @return bool */ static function deleteRecursive($target, $ignoreWarnings = FALSE, $msg = array()) { $exceptions = array('.', '..'); if (!($sourceDir = @opendir($target))) { if ($ignoreWarnings !== TRUE) { $msg['result'] = 'failure'; $msg['errors'][] = $target; return $msg; } } if (!$sourceDir) { return; } while (FALSE !== ($sibling = readdir($sourceDir))) { if (!in_array($sibling, $exceptions)) { $object = str_replace('//', '/', $target . '/' . $sibling); if (is_dir($object)) { $msg = Bf_Filesystem::deleteRecursive($object, $ignoreWarnings, $msg); } if (is_file($object)) { bfLog::log('Deleting ' . $object); $result = unlink($object); if ($result) { $msg['deleted_files'][] = $object; } if (!$result) { $msg['errors'][] = $object; } } } } closedir($sourceDir); if (is_dir($target)) { bfLog::log('Deleting ' . $target); if ($result = rmdir($target)) { $msg['deleted_folders'][] = $target; $msg['result'] = 'success'; } else { bfLog::log(sprintf('Deleting %S FAILED', $target)); $msg['result'] = 'failure'; } } else { } return $msg; }
/** * Generic function for updating the configuration.php file * * @param $param string * @param $value string|int */ private function _setConfigParam($param, $value, $type = 'int') { // Require more complex methods for dealing with files require 'bfFilesystem.php'; if ($type == 'int') { if ($value == "true") { $value = 1; } else { if ($value == "false") { $value = 0; } else { $value = 0; } } } $config = JFactory::getConfig(); if (version_compare(JVERSION, '3.0', 'ge')) { $config->set($param, $value); } else { $config->setValue('config.' . $param, $value); } $newConfig = $config->toString('PHP', 'config', array('class' => 'JConfig')); /** * On some occasions, Joomla! 1.6+ ignores the configuration and * produces "class c". Let's fix this! */ $newConfig = str_replace('class c {', 'class JConfig {', $newConfig); $newConfig = str_replace('namespace c;', '', $newConfig); // Set the correct location of the file $filename = JPATH_ROOT . DIRECTORY_SEPARATOR . 'configuration.php'; // Try to write out the configuration.php $result = Bf_Filesystem::_write($filename, $newConfig); if ($result !== FALSE) { bfEncrypt::reply('success', array($param => $value)); } else { bfEncrypt::reply(bfReply::ERROR, array('msg' => 'Could Not Save Config value for ' . $param)); } }