MDL-10870 A few more fixes to the file.php page's navigation
[moodle-pu.git] / lib / smarty / core / core.rm_auto.php
blobb7cdaf8c5d790e444ce16a5f9712d2013fe445b1
1 <?php
2 /**
3 * Smarty plugin
4 * @package Smarty
5 * @subpackage plugins
6 */
8 /**
9 * delete an automagically created file by name and id
11 * @param string $auto_base
12 * @param string $auto_source
13 * @param string $auto_id
14 * @param integer $exp_time
15 * @return boolean
18 // $auto_base, $auto_source = null, $auto_id = null, $exp_time = null
20 function smarty_core_rm_auto($params, &$smarty)
22 if (!@is_dir($params['auto_base']))
23 return false;
25 if(!isset($params['auto_id']) && !isset($params['auto_source'])) {
26 $_params = array(
27 'dirname' => $params['auto_base'],
28 'level' => 0,
29 'exp_time' => $params['exp_time']
31 require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.rmdir.php');
32 $_res = smarty_core_rmdir($_params, $smarty);
33 } else {
34 $_tname = $smarty->_get_auto_filename($params['auto_base'], $params['auto_source'], $params['auto_id']);
36 if(isset($params['auto_source'])) {
37 if (isset($params['extensions'])) {
38 $_res = false;
39 foreach ((array)$params['extensions'] as $_extension)
40 $_res |= $smarty->_unlink($_tname.$_extension, $params['exp_time']);
41 } else {
42 $_res = $smarty->_unlink($_tname, $params['exp_time']);
44 } elseif ($smarty->use_sub_dirs) {
45 $_params = array(
46 'dirname' => $_tname,
47 'level' => 1,
48 'exp_time' => $params['exp_time']
50 require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.rmdir.php');
51 $_res = smarty_core_rmdir($_params, $smarty);
52 } else {
53 // remove matching file names
54 $_handle = opendir($params['auto_base']);
55 $_res = true;
56 while (false !== ($_filename = readdir($_handle))) {
57 if($_filename == '.' || $_filename == '..') {
58 continue;
59 } elseif (substr($params['auto_base'] . DIRECTORY_SEPARATOR . $_filename, 0, strlen($_tname)) == $_tname) {
60 $_res &= (bool)$smarty->_unlink($params['auto_base'] . DIRECTORY_SEPARATOR . $_filename, $params['exp_time']);
66 return $_res;
69 /* vim: set expandtab: */