示例#1
0
 function tree($path, $ver_path, $c = false, $ext = false)
 {
     $res = [];
     foreach (\bbn\file\dir::get_files($path, 1) as $p) {
         if (empty($ext) || !empty($ext) && (\bbn\str::file_ext($p) === $ext || \bbn\str::file_ext($p) === '')) {
             $pa = substr($p, strlen($ver_path), strlen($p));
             $r = ['text' => basename($p), 'path' => strpos($pa, '/') === 0 ? substr($pa, 1, strlen($pa)) : $pa];
             if (!empty($c) && in_array($r['path'], $c)) {
                 $r['checked'] = 1;
             }
             if (is_dir($p)) {
                 $r['items'] = tree($p, $ver_path, $c, $ext);
             }
             if (!is_dir($p) || is_dir($p) && !empty($r['items'])) {
                 array_push($res, $r);
             }
         }
     }
     return $res;
 }
示例#2
0
文件: tree.php 项目: nabab/appui-ide
            $path = $path . (empty($model->data['path']) ? '' : $model->data['path']);
            $ff = \bbn\file\dir::get_files($path, 1);
            foreach ($ff as $f) {
                if (is_dir($f)) {
                    // Folder name
                    $fn = basename($f);
                    // Add folder to array
                    $folders[$fn] = ['path' => (empty($model->data['path']) ? '' : $model->data['path'] . '/') . $fn, 'name' => $fn, 'has_index' => \bbn\file\dir::has_file($f, 'index.php', 'index.html', 'index.htm') ? 1 : false, 'dir' => $current, 'parenthood' => true, 'is_svg' => false, 'is_viewable' => false, 'is_image' => false, 'default' => false, 'icon' => "folder-icon", 'bcolor' => $dir['bcolor'], 'type' => "dir"];
                    if (empty($model->data['onlydir'])) {
                        $folders[$fn]['is_parent'] = count(\bbn\file\dir::get_files($f, 1)) > 0;
                    } else {
                        $folders[$fn]['is_parent'] = count(\bbn\file\dir::get_dirs($f)) > 0;
                    }
                } else {
                    if (empty($model->data['onlydir']) && !in_array(\bbn\str::file_ext($f), $excluded)) {
                        // File extension
                        $ext = \bbn\str::file_ext($f);
                        // Filename
                        $fn = \bbn\str::file_ext($f, 1)[0];
                        // Add file
                        $files[$f] = ['path' => (empty($model->data['path']) ? '' : $model->data['path'] . '/') . basename($f), 'name' => $fn, 'has_index' => false, 'is_parent' => false, 'parenthood' => false, 'dir' => $current, 'is_svg' => $ext === 'svg', 'is_viewable' => in_array($ext, $file_check['viewables']) && $ext !== 'svg' ? true : false, 'is_image' => in_array($ext, $file_check['images']), 'default' => false, 'ext' => in_array($ext, $ext_icons) ? $ext : 'default', 'bcolor' => $dir['bcolor'], 'type' => "file"];
                        $files[$f]['default'] = !$files[$f]['is_svg'] && !$files[$f]['is_viewable'] && !$files[$f]['is_image'] ? true : false;
                    }
                }
            }
        }
        if (ksort($folders, SORT_STRING | SORT_FLAG_CASE) && ksort($files, SORT_STRING | SORT_FLAG_CASE)) {
            return empty($model->data['onlydir']) ? array_merge(array_values($folders), array_values($files)) : array_values($folders);
        }
    }
}
示例#3
0
 if (in_array($ext, $archives)) {
     $archive = \wapmorgan\UnifiedArchive\UnifiedArchive::open($file);
     \bbn\file\dir::create_path($path . '/' . $fname);
     if ($num = $archive->extractNode($path . '/' . $fname, '/')) {
         $tmp = getcwd();
         chdir($path);
         $all = \bbn\file\dir::scan($fname, 'file');
         foreach ($all as $a) {
             array_push($files, $a);
         }
         chdir($tmp);
     }
 }
 $ctrl->obj->files = [];
 foreach ($files as $f) {
     $tmp = \bbn\str::file_ext($f, 1);
     $fname = $tmp[0];
     $ext = $tmp[1];
     $res = ['name' => $f, 'size' => filesize($path . '/' . $f), 'extension' => '.' . $ext];
     if (in_array($ext, $images)) {
         // Creating thumbnails
         $res['imgs'] = [];
         $img = new \bbn\file\image($path . '/' . $f);
         if ($img->test() && ($imgs = $img->thumbs($path))) {
             array_push($res['imgs'], array_map(function ($a) use($path) {
                 return substr($a, strlen($path));
             }, $imgs));
         }
         $res['imgs']['length'] = count($res['imgs']);
     }
     array_push($ctrl->obj->files, $res);
示例#4
0
    $root = strval(time());
    \bbn\file\dir::create_path($path . $root);
    foreach ($parsed as $parserName => $link) {
        if ($parserName === 'general') {
            $r = ['url' => $link->getUrl(), 'realurl' => $link->getRealUrl(), 'title' => $link->getPageTitle(), 'desc' => $link->getDescription(), 'pictures' => []];
            $img = $link->getImage();
            $pictures = $link->getPictures();
            if (!is_array($pictures)) {
                $pictures = [];
            }
            if (!empty($img)) {
                array_unshift($pictures, $img);
            }
            foreach ($pictures as $pic) {
                $saved = @file_get_contents($pic);
                if ($saved && strlen($saved) > 1000) {
                    $new = \bbn\str::encode_filename(basename($pic), \bbn\str::file_ext(basename($pic)));
                    file_put_contents($path . $root . '/' . $new, $saved);
                    unset($saved);
                    $img = new \bbn\file\image($path . $root . '/' . $new);
                    if ($img->test() && ($imgs = $img->thumbs($path . $root))) {
                        array_push($r['pictures'], array_map(function ($a) use($path) {
                            return substr($a, strlen($path));
                        }, $imgs));
                    }
                }
            }
            return $r;
        }
    }
}
示例#5
0
<?php

/*
 * Describe what it does to show you're not that dumb!
 *
 **/
/** @var $ctrl \bbn\mvc\controller */
$ctrl->obj->success = false;
if (isset($ctrl->arguments[0], $ctrl->post['fileNames'])) {
    $path = BBN_USER_PATH . 'tmp/' . $ctrl->arguments[0];
    $new = \bbn\str::encode_filename($ctrl->post['fileNames'], \bbn\str::file_ext($ctrl->post['fileNames']));
    $file = $path . '/' . $new;
    if (is_file($file)) {
        $ctrl->obj->files = $ctrl->post['fileNames'];
        $ctrl->obj->success = unlink($file);
    }
}