Esempio 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;
 }
Esempio n. 2
0
            $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);
        }
    }
}
Esempio n. 3
0
<?php

/*
 * Describe what it does to show you're not that dumb!
 *
 **/
/** @var $ctrl \bbn\mvc\controller */
if (isset($ctrl->arguments[0])) {
    $ctrl->set_mode("image");
    $is_tmp = false;
    if ($ctrl->arguments[0] === 'tmp' && \bbn\str::is_integer($ctrl->arguments[1])) {
        array_shift($ctrl->arguments);
        $is_tmp = 1;
        $path = BBN_USER_PATH . 'tmp/' . array_shift($ctrl->arguments) . '/';
    }
    if (isset($path)) {
        $file = $path . implode("/", $ctrl->arguments);
        $ctrl->obj->img = $file;
        //die();
        //die(var_dump($file, is_file($file)));
        //die(var_dump($ctrl->mvc));
    }
}
Esempio n. 4
0
 **/
/** @var $ctrl \bbn\mvc\controller */
if (!isset($ctrl->arguments[0])) {
    $id_perm = $ctrl->inc->perm->get_option_root();
    $perm =& $ctrl->inc->perm;
    $ctrl->add_data(['cat' => $id_perm, 'lng' => ['refresh_all_permissions' => _("Refresh all permissions"), 'confirm_update_permissions' => _("Are you sure you wanna update all permissions? It might take a while..."), 'total_updated' => _("A total of {0} permissions has been added"), 'no_permission_updated' => _("No permission has been added")], 'tree' => $ctrl->inc->options->map(function ($r) use($perm) {
        if (empty($r['icon'])) {
            if (substr($r['code'], -1) === '/') {
                $r['icon'] = 'fa fa-folder';
            } else {
                $r['icon'] = 'fa fa-file';
            }
        }
        if ($perm->has($r['id'])) {
            $o = ['id' => $r['id'], 'text' => $r['text'], 'code' => $r['code'], 'icon' => $r['icon'], 'is_parent' => empty($r['num_children']) ? false : true];
            if ($o['is_parent']) {
                $o['items'] = $r['items'];
            }
            return $o;
        }
    }, $id_perm, true)]);
    $ctrl->combo(_("Permissions"), $ctrl->data);
} else {
    if (\bbn\str::is_integer($ctrl->arguments[0])) {
        $ctrl->add_data(['id' => $ctrl->arguments[0], 'full' => isset($ctrl->post['full']) ? $ctrl->post['full'] : false, 'routes' => $ctrl->get_routes()]);
        $ctrl->obj->data = $ctrl->get_model();
    } else {
        $ctrl->add_data(['action' => $ctrl->arguments[0]], $ctrl->post);
        $ctrl->obj->data = $ctrl->get_model();
    }
}
Esempio n. 5
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;
        }
    }
}
Esempio n. 6
0
<?php

if (isset($ctrl->post['current_pass'], $ctrl->post['pass1'], $ctrl->post['pass2'])) {
    if ($ctrl->post['pass1'] !== $ctrl->post['pass2']) {
        $ctrl->obj->error = "Les mots de passe ne correspondent pas.";
        $ctrl->obj->errorTitle = "Échec!";
    } else {
        if ($ctrl->obj->res = $ctrl->inc->user->set_password($ctrl->post['current_pass'], $ctrl->post['pass1'])) {
            $ctrl->obj->error = "Mot de passe modifié";
            $ctrl->obj->errorTitle = "Succès!";
        } else {
            $ctrl->obj->error = "L'ancien mot de passe n'est pas reconnu.";
            $ctrl->obj->errorTitle = "Échec!";
        }
    }
} else {
    if (isset($ctrl->post['email'], $ctrl->post['nom']) && \bbn\str::is_email($ctrl->post['email'])) {
        $change_theme = $ctrl->post['theme'] !== $ctrl->inc->session->get('info', 'theme');
        if ($ctrl->obj->res = $ctrl->inc->user->update_info($ctrl->post)) {
            if ($change_theme) {
                $ctrl->add_script('appui.fn.confirm("' . \bbn\str::escape_dquotes(_("Pour que le nouveau thème soit appliqué, il vous faut recharger l'application.\nVoulez-vous la recharger maintenant?")) . '", function(){document.location.reload();});');
            } else {
                $ctrl->obj->error = "Modification réussie";
                $ctrl->obj->errorTitle = "Succès!";
            }
        }
    } else {
        $ctrl->combo(_("Mon profil"), $ctrl->inc->user->get_session());
    }
}
Esempio n. 7
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);
Esempio n. 8
0
    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' => []];
    foreach ($res as $k => $v) {
        array_push($data['logs'], ['text' => $k]);
    }
    return $data;
}
Esempio n. 9
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);
    }
}
Esempio n. 10
0
            $o['items'] = $treat($t['items'], $o['code']);
        }
        array_push($res, $o);
    }
    return $res;
};
// Sort names between folders and files
$sort = function ($a, $b) use(&$sort) {
    if (substr($a['code'], -1) === '/') {
        $a['code'] = '00' . $a['code'];
    }
    if (substr($b['code'], -1) === '/') {
        $b['code'] = '00' . $b['code'];
    }
    $a = str_replace('.', '0', str_replace('_', '1', \bbn\str::change_case($a['code'], 'lower')));
    $b = str_replace('.', '0', str_replace('_', '1', \bbn\str::change_case($b['code'], 'lower')));
    return strcmp($a, $b);
};
// Sort items' hierarchy
$walk = function (&$a) use(&$walk, $sort) {
    if (!empty($a['items'])) {
        usort($a['items'], $sort);
        array_walk($a['items'], $walk);
    }
};
// Add options to the options table
$add = function ($o, $id_parent, $total = 0) use($opt, $db, &$add) {
    $items = isset($o['items']) ? $o['items'] : false;
    unset($o['items']);
    $o['id_parent'] = $id_parent;
    if (!($id = $opt->from_code($o['code'], $id_parent))) {
Esempio n. 11
0
<?php

/* @var $ctrl \bbn\mvc */
if (isset($ctrl->post['log'])) {
    $ctrl->data['log'] = $ctrl->post['log'];
    $ctrl->data['clear'] = !empty($ctrl->post['clear']);
    $ctrl->data['num_lines'] = isset($ctrl->post['num_lines']) && \bbn\str::is_integer($ctrl->post['num_lines']) ? $ctrl->post['num_lines'] : 100;
    $ctrl->obj = $ctrl->get_object_model();
} else {
    echo $ctrl->combo("Log files", ['root' => $ctrl->say_dir() . '/']);
}
Esempio n. 12
0
 $ln = 'bbn-ide-error_log-';
 $res = [];
 $lines = file($file);
 foreach ($lines as $o) {
     preg_match_all('/\\[([^\\]]+)\\]/', $o, $r);
     if (isset($r[1][0])) {
         if ($pos_mill = strpos($r[1][0], '.')) {
             $r[1][0] = substr($r[1][0], 0, $pos_mill) . substr($r[1][0], strpos($r[1][0], ' ', $pos_mill));
         }
         if (strpos($o, ' PHP ') && ($d = date_parse($r[1][0]))) {
             $php = strpos($o, ' PHP ') + 5;
             $coma = strrpos($o, ',');
             $reste = trim(substr($o, $php, $coma - $php));
             $time = mktime($d['hour'], $d['minute'], $d['second'], $d['month'], $d['day'], $d['year']);
             // Trace
             if (\bbn\str::is_integer(substr($reste, 0, 1))) {
                 if (isset($cur)) {
                     $idx = intval(trim(substr($reste, 0, strpos($reste, '.'))));
                     if ($idx === 1) {
                         $res[$cur]['trace'] = [];
                     }
                     $res[$cur]['trace'][$idx - 1] = ['index' => $idx, 'text' => trim(substr($reste, strpos($reste, '.') + 1))];
                 }
             } else {
                 if (strpos($reste, 'Stack trace:') === 0) {
                 } else {
                     if (isset($res[$reste])) {
                         $res[$reste]['count']++;
                         $res[$reste]['last_date'] = date('Y-m-d H:i:s', $time);
                     } else {
                         $cur = $reste;