Ejemplo n.º 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;
 }
Ejemplo n.º 2
0
<?php

/*
 * Describe what it does to show you're not that dumb!
 *
 **/
/** @var $ctrl \bbn\mvc\controller */
if (isset($ctrl->post['ref'])) {
    $path = BBN_USER_PATH . 'tmp/' . $ctrl->post['ref'];
    $files = \bbn\file\dir::get_files($path);
    $ctrl->post['files'] = $files;
}
$ctrl->obj = $ctrl->get_object_model($ctrl->post);
Ejemplo n.º 3
0
<?php

/*
 * Describe what it does or you're a pussy
 *
 **/
/** @var $model \bbn\mvc\model*/
if (isset($model->data['url'], $model->data['ref']) && \bbn\str::is_url($model->data['url'])) {
    $linkPreview = new \LinkPreview\LinkPreview($model->data['url']);
    $parsed = $linkPreview->getParsed();
    $path = BBN_USER_PATH . 'tmp/' . $model->data['ref'] . '/';
    $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);
Ejemplo n.º 4
0
         }
     }
 } else {
     // Get files and folders
     $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)) {
Ejemplo n.º 5
0
 $file = $path . '/' . $new;
 if (\bbn\file\dir::create_path($path) && move_uploaded_file($f['tmp_name'], $file)) {
     $tmp = \bbn\str::file_ext($new, 1);
     $fname = $tmp[0];
     $ext = $tmp[1];
     $ctrl->obj->success = 1;
     $archives = ['zip', 'rar', 'tar', 'gzip', 'iso'];
     $images = ['jpg', 'gif', 'jpeg', 'png', 'svg'];
     $files = [basename($file)];
     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'] = [];
Ejemplo n.º 6
0
 /**
  * Deletes all the content from a directory.
  *
  * If the $full param is set to true, it will also delete the directory itself.
  *
  * <code>
  * \bbn\file\dir::delete("C:\Documents\Test"); //Deletes "C:\Documents\Test" and subdirectories
  * \bbn\file\dir::delete("C:\Documents\Test", 0); //Deletes "C:\Documents\Test"
  * </code>
  * 
  * @param string $dir The directory path.
  * @param bool $full If set to true, it will also delete the directory itself. Default: "1".
  * 
  * @return bool 
  */
 public static function delete($dir, $full = 1)
 {
     $dir = self::clean($dir);
     if (is_dir($dir)) {
         $files = scandir($dir);
         foreach ($files as $file) {
             if ($file != "." && $file != "..") {
                 if (is_dir($dir . '/' . $file)) {
                     \bbn\file\dir::delete($dir . '/' . $file);
                 } else {
                     unlink($dir . '/' . $file);
                 }
             }
         }
         if ($full === 1) {
             return rmdir($dir);
         }
         return true;
     } else {
         if (is_file($dir)) {
             return unlink($dir);
         }
     }
     return false;
 }
Ejemplo n.º 7
0
<?php

/** @var $model \bbn\mvc\model */
//die(\bbn\file\dir::get_files(BBN_LOG_PATH));
$log_files = array_filter(\bbn\file\dir::get_files(BBN_DATA_PATH . 'logs'), function ($a) {
    return substr($a, -3) === 'log';
});
if (($log_file = ini_get('error_log')) && strpos($log_file, BBN_DATA_PATH . 'logs') === false) {
    array_unshift($log_files, $log_file);
}
$res = [];
foreach ($log_files as $lf) {
    $res[basename($lf)] = $lf;
}
ksort($res);
if (isset($model->data['log'])) {
    $output = [];
    if ($model->data['clear']) {
        file_put_contents($res[$model->data['log']], '');
    } else {
        $file = escapeshellarg($res[$model->data['log']]);
        // for the security concious (should be everyone!)
        $num_lines = isset($model->data['num_lines']) && \bbn\str::is_integer($model->data['num_lines']) && $model->data['num_lines'] > 0 && $model->data['num_lines'] <= 1000 ? $model->data['num_lines'] : 100;
        $line = "tail -n {$num_lines} {$file}";
        exec($line, $output);
        $res = [];
        $pid = 0;
    }
    return ['content' => implode("\n", $output)];
} else {
    $data = ['logs' => []];
Ejemplo n.º 8
0
<?php

/*
 * Describe what it does to show you're not that dumb!
 *
 **/
/** @var $ctrl \bbn\mvc\controller */
if (isset($ctrl->arguments[0]) && is_array($o = $ctrl->inc->options->get_cfg($ctrl->arguments[0]))) {
    $ctrl->add_data($o, ['id' => $ctrl->arguments[0], 'values' => $ctrl->inc->options->text_value_options($ctrl->arguments[0]), 'controllers' => array_map(function ($a) {
        $len = strlen(BBN_APP_PATH . 'mvc/private/');
        $tmp = $len + strlen('_options/');
        return ['text' => substr($a, $tmp, -4), 'value' => substr($a, $len, -4)];
    }, array_filter(\bbn\file\dir::get_files(BBN_APP_PATH . 'mvc/private/_options'), function ($b) {
        return substr($b, -4) === '.php';
    }))])->combo("Configuration", $ctrl->data);
}
Ejemplo n.º 9
0
 $id_plugins = $model->inc->perm->get_option_id('plugins');
 if (!$id_plugins) {
     $id_plugins = $opt->add(['id_parent' => $id_permission, 'code' => 'plugins', 'text' => _("Plugins"), 'value' => ['icon' => 'fa fa-plug']]);
 }
 // $id_page must be set to generate the page's permissions
 if ($id_page) {
     if (!isset($model->data['routes'])) {
         $model->data['routes'] = [];
     }
     $all = \bbn\file\dir::get_tree(BBN_APP_PATH . 'mvc/public', false, function ($a) {
         return ($a['type'] === 'dir' || $a['ext'] === 'php') && basename($a['name']) !== '_ctrl.php';
     });
     $all = $treat($all);
     foreach ($model->data['routes'] as $name => $path) {
         if ($tree = \bbn\file\dir::get_tree($path . '/mvc/public', false, function ($a) {
             return ($a['type'] === 'dir' || $a['ext'] === 'php') && basename($a['name']) !== '_ctrl.php';
         })) {
             $treated = $treat($tree);
             $merge($all, $treated, $name);
         }
     }
     usort($all, $sort);
     array_walk($all, $walk);
     $res['total'] = 0;
     //die(\bbn\x::dump($all));
     foreach ($all as $i => $it) {
         $it['cfg'] = json_encode(['order' => $i + 1]);
         $res['total'] += $add($it, $id_page);
     }
 }
 // $id_option must be set to generate the option's permissions