示例#1
0
 function delete_cell($name)
 {
     $results = array();
     $name = strtolower($name);
     $class_suffix = '_cell';
     $controller_path = FCPATH . 'application/cell/controllers/' . $name . $class_suffix . EXT;
     $views_path = FCPATH . 'application/cell/views/' . $name . $class_suffix . '/';
     directory_delete($views_path, true, $results);
     if (delete_file($controller_path)) {
         array_push($results, $controller_path);
     }
     return $results;
 }
示例#2
0
 function clean_cache_file($CI)
 {
     $CI->load->library('cfg');
     $cache = array();
     array_push($cache, Cfg::system('cache', 'file'));
     array_push($cache, Cfg::system('cache', 'output'));
     array_push($cache, Cfg::system('cache', 'config'));
     array_push($cache, Cfg::system('cache', 'model'));
     if (array_filter(array_map(function ($t) {
         return directory_delete(FCPATH . implode(DIRECTORY_SEPARATOR, $t), false);
     }, $cache))) {
         return '已經清除所有 file cache!';
     } else {
         return '清除 file cache 失敗!';
     }
 }
示例#3
0
 public function test_directory()
 {
     $dir1 = path(self::getDir(), 'dir_1/dir1');
     $dir1_file = path($dir1, 'foo.txt');
     $dir1_file_content = 'foo bar';
     $dir2 = path(self::getDir(), 'dir_2/dir2');
     $dir2_file = path($dir2, 'foo.txt');
     $dir3 = path(self::getDir(), 'dir_3/dir3');
     $dir3_file = path($dir3, 'foo.txt');
     $dir4 = path(self::getDir(), '/dir_3/dir-3');
     $dir4_name = 'dir-3';
     $dir4_file = path($dir4, 'foo.txt');
     $this->assertFalse(directory_exists($dir1));
     directory_create($dir1);
     file_write($dir1_file, $dir1_file_content);
     $this->assertTrue(directory_exists($dir1));
     $this->assertFalse(directory_exists($dir2));
     directory_create(path($dir1, 'yolo'));
     directory_copy($dir1_file, $dir2);
     directory_delete($dir2);
     directory_copy($dir1, $dir2);
     $this->assertTrue(file_exists($dir2_file));
     $this->assertEquals(file_read($dir1_file), file_read($dir2_file));
     $this->assertFalse(directory_exists($dir3));
     directory_move($dir2, $dir3);
     $this->assertFalse(directory_exists($dir2));
     $this->assertTrue(directory_exists($dir3));
     $this->assertTrue(file_exists($dir3_file));
     $this->assertEquals(file_read($dir1_file), file_read($dir3_file));
     $this->assertFalse(directory_exists($dir4));
     directory_rename($dir3, $dir4_name);
     $this->assertTrue(directory_exists($dir4));
     $this->assertFalse(directory_exists($dir3));
     $this->assertTrue(file_exists($dir4_file));
     $this->assertEquals(file_read($dir1_file), file_read($dir4_file));
     $this->assertEquals(['foo.txt', 'yolo'], directory_list($dir1));
     $this->assertEquals([path($dir1, 'foo.txt'), path($dir1, 'yolo')], directory_list($dir1, true));
     $this->assertEquals([], directory_list('yada'));
     $this->assertEquals(['dir_1', 'dir_2', 'dir_3'], directory_list(self::getDir()));
     directory_delete(self::getDir());
     $this->assertFalse(directory_exists(self::getDir()));
     $this->assertEquals('dir1', directory_get_name($dir1));
     $this->assertEquals(self::getDir() . '/dir_1', directory_get_parent($dir1));
 }
示例#4
0
 function directory_delete($dir, $is_root = true, &$path = null)
 {
     $dir = rtrim($dir, DIRECTORY_SEPARATOR);
     if (!($current_dir = @opendir($dir))) {
         return false;
     }
     while (false !== ($filename = @readdir($current_dir))) {
         if ($filename != '.' and $filename != '..') {
             if (is_dir($dir . DIRECTORY_SEPARATOR . $filename)) {
                 if (substr($filename, 0, 1) != '.') {
                     directory_delete($dir . DIRECTORY_SEPARATOR . $filename, true, $path);
                 }
             } else {
                 if (delete_file($p = $dir . DIRECTORY_SEPARATOR . $filename) && $path !== null) {
                     array_push($path, $p);
                 }
             }
         }
     }
     @closedir($current_dir);
     return $is_root ? @rmdir($dir) : true;
 }
 public function doConfigPageInit($page)
 {
     $request = $_REQUEST;
     $request['action'] = !empty($request['action']) ? $request['action'] : "";
     switch ($page) {
         case 'directory':
             //check for ajax request and process that immediately
             if (isset($_REQUEST['ajaxgettr'])) {
                 //got ajax request
                 $opts = $opts = explode('|', urldecode($_REQUEST['ajaxgettr']));
                 if ($opts[0] == 'all') {
                     echo directory_draw_entries_all_users($opts[1]);
                 } else {
                     if ($opts[0] != '') {
                         $real_id = $opts[0];
                         $name = '';
                         $realname = $opts[1];
                         $audio = 'vm';
                     } else {
                         $real_id = 'custom';
                         $name = $opts[1];
                         $realname = 'Custom Entry';
                         $audio = 'tts';
                     }
                     echo directory_draw_entries_tr($opts[0], $real_id, $name, $realname, $audio, '', $opts[2]);
                 }
                 exit;
             }
             $requestvars = array('id', 'action', 'entries', 'newentries', 'def_dir', 'Submit');
             foreach ($requestvars as $var) {
                 switch ($var) {
                     case 'def_dir':
                         $rvars_def = false;
                         break;
                     default:
                         $rvars_def = '';
                         break;
                 }
                 ${$var} = isset($_REQUEST[$var]) ? $_REQUEST[$var] : $rvars_def;
             }
             if (isset($Submit) && $Submit == 'Submit' && isset($def_dir) && $def_dir !== false) {
                 directory_save_default_dir($def_dir);
             }
             break;
     }
     if ($page == 'directory') {
         //get variables for directory_details
         $requestvars = array('id', 'dirname', 'description', 'announcement', 'callid_prefix', 'alert_info', 'repeat_loops', 'repeat_recording', 'invalid_recording', 'invalid_destination', 'retivr', 'say_extension');
         foreach ($requestvars as $var) {
             $vars[$var] = isset($_REQUEST[$var]) ? $_REQUEST[$var] : null;
         }
         $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : null;
         $entries = isset($_REQUEST['entries']) ? $_REQUEST['entries'] : null;
         //$entries=(($entries)?array_values($entries):'');//reset keys
         switch ($action) {
             case 'edit':
                 //get real dest
                 $vars['invalid_destination'] = $_REQUEST[$_REQUEST['goto0'] . '0'];
                 $vars['id'] = directory_save_dir_details($vars);
                 \directory_save_dir_entries($vars['id'], $entries);
                 $this_dest = directory_getdest($vars['id']);
                 \fwmsg::set_dest($this_dest[0]);
                 needreload();
                 $_REQUEST['id'] = $vars['id'];
                 break;
             case 'delete':
                 directory_delete($vars['id']);
                 needreload();
                 break;
         }
     }
 }
示例#6
0
 public function clean_cell($keys)
 {
     if ($this->configs['driver'] == 'redis') {
         array_unshift($keys, $this->configs['redis_main_key']);
         $keys = implode(':', $keys);
         $keys = !preg_match('/\\*$/', $keys) ? $this->CI->redis->exists($keys) ? array($keys) : array() : $this->CI->redis->keys($keys);
         if ($keys) {
             foreach ($keys as $key) {
                 $this->CI->redis->del($keys);
             }
         }
         return true;
     } else {
         if (($last = array_pop($keys)) != '*') {
             array_push($keys, $this->configs['file_is_md5'] ? md5($last . $this->configs['file_prefix']) : $last . $this->configs['file_prefix']);
         }
         $keys = FCPATH . implode(DIRECTORY_SEPARATOR, array_merge($this->configs['folders']['cache'], $keys));
         if (is_file($keys) && !preg_match('/\\*$/', $keys)) {
             @unlink($keys);
             return !file_exists($keys);
         } else {
             if (is_dir($keys)) {
                 $this->CI->load->helper('directory');
                 return directory_delete($keys, $keys != FCPATH . implode(DIRECTORY_SEPARATOR, $this->configs['folders']['cache']));
             } else {
                 return false;
             }
         }
     }
 }
示例#7
0
/**
 * Take the call and properly dispatch it to the methods below.  This method
 * assumes valid input.
 */
function dispatch($arguments)
{
    if (array_key_exists('file', $arguments)) {
        if (array_key_exists('rename', $arguments)) {
            if (!file_directory_rename($arguments['filename'], $arguments['newname'], working_directory())) {
                http_error_exit('HTTP_CLIENT_FORBIDDEN');
            }
            return true;
        }
        if (array_key_exists('copy', $arguments)) {
            if (!($newentry = file_copy($arguments['filename'], working_directory()))) {
                http_error_exit('HTTP_CLIENT_FORBIDDEN');
            }
            echo json_encode($newentry);
            return true;
        }
        if (array_key_exists('delete', $arguments)) {
            if (!file_delete($arguments['filename'], working_directory())) {
                http_error_exit('HTTP_CLIENT_FORBIDDEN');
            }
            return true;
        }
    }
    if (array_key_exists('directory', $arguments)) {
        if (array_key_exists('listing', $arguments)) {
            echo json_encode(directory_listing());
            return true;
        }
        if (array_key_exists('create', $arguments)) {
            if (!directory_create($arguments['dirname'], working_directory())) {
                http_error_exit('HTTP_CLIENT_FORBIDDEN');
            }
            return true;
        }
        if (array_key_exists('delete', $arguments)) {
            if (!directory_delete($arguments['dirname'], working_directory())) {
                http_error_exit('HTTP_CLIENT_FORBIDDEN');
            }
            return true;
        }
        if (array_key_exists('rename', $arguments)) {
            if (!file_directory_rename($arguments['dirname'], $arguments['newname'], working_directory())) {
                http_error_exit('HTTP_CLIENT_FORBIDDEN');
            }
            return true;
        }
    }
    if (array_key_exists('image', $arguments)) {
    }
    if (array_key_exists('upload', $arguments)) {
        store_uploaded_file($arguments['filename'], $arguments['filedata'], working_directory());
        return true;
    }
    return false;
}
    exit;
}
if (isset($_GET["directory-js"])) {
    directory_js();
    exit;
}
if (isset($_GET["directory-popup"])) {
    directory_popup();
    exit;
}
if (isset($_POST["directory"])) {
    directory_save();
    exit;
}
if (isset($_POST["delete"])) {
    directory_delete();
    exit;
}
if (isset($_GET["png"])) {
    png();
    exit;
}
js();
function js()
{
    header("content-type: application/x-javascript");
    $tpl = new templates();
    $page = CurrentPageName();
    $meta = new mysql_meta();
    $hostname = $meta->uuid_to_host($_GET["uuid"]);
    $title = $tpl->javascript_parse_text("{directories_monitor}");
示例#9
0
 /**
  * Delete all files and directories inside a directory.
  *
  * @param $path
  */
 function directory_clear($path)
 {
     if (directory_exists($path)) {
         foreach (directory_list($path, true) as $file) {
             directory_delete($file);
         }
     }
 }
示例#10
0
 function directory_clean($dir)
 {
     directory_delete($dir, false);
 }
示例#11
0
 function create_cell($temp_path, $name, $methods = array())
 {
     $results = array();
     $name = strtolower($name);
     $methods = array_filter($methods);
     $class_suffix = '_cell';
     $method_prefix = '_cache_';
     $controllers_path = FCPATH . 'application/cell/controllers/';
     $views_path = FCPATH . 'application/cell/views/';
     $controllers = array_map(function ($t) {
         return basename($t, EXT);
     }, directory_map($controllers_path, 1));
     $views = directory_map($views_path, 1);
     if (!is_writable($controllers_path) || !is_writable($views_path)) {
         console_error("無法有寫入的權限!");
     }
     if ($controllers && in_array($file_name = $name . $class_suffix, $controllers) || $views && in_array($file_name, $views)) {
         console_error("名稱錯誤!");
     }
     $oldmask = umask(0);
     @mkdir($view_path = $views_path . $file_name . '/', 0777, true);
     umask($oldmask);
     $date = load_view($temp_path . 'cell.php', array('file_name' => $file_name, 'name' => $name, 'methods' => $methods, 'method_prefix' => $method_prefix));
     if (!write_file($controller_path = $controllers_path . $file_name . EXT, $date)) {
         console_error("新增 controller 失敗!");
     }
     array_push($results, $controller_path);
     if (!is_writable($view_path)) {
         delete_file($controller_path);
         console_error("新增 view 失敗!");
     }
     if (count(array_filter(array_map(function ($method) use($view_path, $temp_path, &$results) {
         $oldmask = umask(0);
         @mkdir($view_path . $method . '/', 0777, true);
         umask($oldmask);
         if (!is_writable($view_path . $method . '/')) {
             return null;
         }
         $files = array('content.css', 'content.scss', 'content.js', 'content.php');
         return count(array_filter(array_map(function ($file) use($view_path, $method, $temp_path, &$results) {
             $data = !is_readable($path = $temp_path . $method . '/' . $file) ? is_readable($path = $temp_path . 'index' . '/' . $file) ? load_view($path) : '' : load_view($path);
             if (write_file($view_path . $method . '/' . $file, $data)) {
                 array_push($results, $view_path . $method . '/' . $file);
                 return true;
             } else {
                 return false;
             }
         }, $files)));
     }, $methods))) != count($methods)) {
         delete_file($controller_path);
         directory_delete($view_path, true);
         console_error("新增 view 失敗!");
     }
     return $results;
 }
示例#12
0
 function letgo()
 {
     directory_delete(__DIR__ . '/path1');
     directory_delete(__DIR__ . '/path2');
 }