/** * index * * @param \dirp\http\request $req * @param \dirp\http\response $res */ public function index(\dirp\http\request $req, \dirp\http\response $res) { $path = file::safe_path($req->get('dir', '/')); $files = file::from_directory($path); $relative = file::to_relative_path($path); // most likely tried to list a file. a file is // not a directory, silly. if ($files === false) { $res->redirect($req->get_base_uri()); } $ev = event::fire('indexlist', array('files' => $files, 'body' => null, 'relative' => $relative, 'path' => $path)); // prepare the breadcrumb: $root = $req->get_base_uri() . '?dir='; $parts = explode('/', $relative); $crumbs = array(); foreach ($parts as $i => $crumb) { $crumbs[$crumb] = $root . '/' . rawurlencode(implode('/', array_slice($parts, 0, $i + 1))); } $this->master()->title = 'viewing: /' . $relative; $this->master()->css[] = \dirp\app::asset('css/index/index.css'); $this->master()->body = $this->view('list')->render(array('files' => $ev->files, 'relative' => $relative, 'crumbs' => $crumbs, 'root' => $req->get_base_uri() . '/', 'filesroot' => \dirp\app::cfg()->files_uri, 'body_override' => $ev->body, 'files_count' => 0)); }
/** * delete * deletes this file. depends on the 'disallow.delete' * configuration parameter. * * @return bool */ public function delete() { // users may chose to disallow any files to be // deleted through this method. not by any means // safe, but possibly a helper against buggy addons. if (\dirp\app::cfg()->disallow_delete) { return false; } if ($this->isfile) { return (bool) @unlink($this->fullpath); } elseif ($this->isdir) { return (bool) @rmdir($this->fullpath); } }
/** * _init * add dirtools config.php files to the privacy list. */ public static function _init() { if (!app::cfg()->private) { app::cfg()->private = array(); } app::cfg()->private[] = '/config/'; }