Chris PeBenito 696b41
Chris PeBenito 696b41
/**
Chris PeBenito 696b41
 * Smarty plugin
Chris PeBenito 696b41
 * @package Smarty
Chris PeBenito 696b41
 * @subpackage plugins
Chris PeBenito 696b41
 */
Chris PeBenito 696b41
Chris PeBenito 696b41
/**
Chris PeBenito 696b41
 * delete a dir recursively (level=0 -> keep root)
Chris PeBenito 696b41
 * WARNING: no tests, it will try to remove what you tell it!
Chris PeBenito 696b41
 *
Chris PeBenito 696b41
 * @param string $dirname
Chris PeBenito 696b41
 * @param integer $level
Chris PeBenito 696b41
 * @param integer $exp_time
Chris PeBenito 696b41
 * @return boolean
Chris PeBenito 696b41
 */
Chris PeBenito 696b41
Chris PeBenito 696b41
//  $dirname, $level = 1, $exp_time = null
Chris PeBenito 696b41
Chris PeBenito 696b41
function smarty_core_rmdir($params, &$smarty)
Chris PeBenito 696b41
{
Chris PeBenito 696b41
   if(!isset($params['level'])) { $params['level'] = 1; }
Chris PeBenito 696b41
   if(!isset($params['exp_time'])) { $params['exp_time'] = null; }
Chris PeBenito 696b41
Chris PeBenito 696b41
   if($_handle = @opendir($params['dirname'])) {
Chris PeBenito 696b41
Chris PeBenito 696b41
        while (false !== ($_entry = readdir($_handle))) {
Chris PeBenito 696b41
            if ($_entry != '.' && $_entry != '..') {
Chris PeBenito 696b41
                if (@is_dir($params['dirname'] . DIRECTORY_SEPARATOR . $_entry)) {
Chris PeBenito 696b41
                    $_params = array(
Chris PeBenito 696b41
                        'dirname' => $params['dirname'] . DIRECTORY_SEPARATOR . $_entry,
Chris PeBenito 696b41
                        'level' => $params['level'] + 1,
Chris PeBenito 696b41
                        'exp_time' => $params['exp_time']
Chris PeBenito 696b41
                    );
Chris PeBenito 696b41
                    require_once(SMARTY_CORE_DIR . 'core.rmdir.php');
Chris PeBenito 696b41
                    smarty_core_rmdir($_params, $smarty);
Chris PeBenito 696b41
                }
Chris PeBenito 696b41
                else {
Chris PeBenito 696b41
                    $smarty->_unlink($params['dirname'] . DIRECTORY_SEPARATOR . $_entry, $params['exp_time']);
Chris PeBenito 696b41
                }
Chris PeBenito 696b41
            }
Chris PeBenito 696b41
        }
Chris PeBenito 696b41
        closedir($_handle);
Chris PeBenito 696b41
   }
Chris PeBenito 696b41
Chris PeBenito 696b41
   if ($params['level']) {
Chris PeBenito 696b41
       return @rmdir($params['dirname']);
Chris PeBenito 696b41
   }
Chris PeBenito 696b41
   return (bool)$_handle;
Chris PeBenito 696b41
Chris PeBenito 696b41
}
Chris PeBenito 696b41
Chris PeBenito 696b41
/* vim: set expandtab: */
Chris PeBenito 696b41
Chris PeBenito 696b41
?>