summaryrefslogtreecommitdiff
path: root/modules/server_add/controllers/server_add.php
diff options
context:
space:
mode:
Diffstat (limited to 'modules/server_add/controllers/server_add.php')
-rw-r--r--modules/server_add/controllers/server_add.php103
1 files changed, 42 insertions, 61 deletions
diff --git a/modules/server_add/controllers/server_add.php b/modules/server_add/controllers/server_add.php
index 4cd3cec7..45ec0a2e 100644
--- a/modules/server_add/controllers/server_add.php
+++ b/modules/server_add/controllers/server_add.php
@@ -18,26 +18,38 @@
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
class Server_Add_Controller extends Controller {
- public function index($id) {
- $paths = unserialize(module::get_var("server_add", "authorized_paths"));
-
+ public function browse($id) {
if (!user::active()->admin) {
access::forbidden();
}
+
+ $paths = unserialize(module::get_var("server_add", "authorized_paths"));
+ foreach (array_keys($paths) as $path) {
+ $files[$path] = basename($path);
+ }
+
$item = ORM::factory("item", $id);
$view = new View("server_add_tree_dialog.html");
$view->item = $item;
+ $view->tree = new View("server_add_tree.html");
+ $view->tree->files = $files;
+ print $view;
+ }
- $tree = new View("server_add_tree.html");
- $tree->data = array();
- $tree->checked = false;
- $tree->tree_id = "tree_$id";
- foreach (array_keys($paths) as $path) {
- $tree->data[$path] = array("path" => $path, "is_dir" => true);
+ private function _validate_path($path) {
+ if (!is_readable($path) || is_link($path)) {
+ throw new Exception("@todo BAD_PATH");
}
- $view->tree = $tree->__toString();
- print $view;
+
+ $authorized_paths = unserialize(module::get_var("server_add", "authorized_paths"));
+ foreach (array_keys($authorized_paths) as $valid_path) {
+ if (strpos($path, $valid_path) === 0) {
+ return;
+ }
+ }
+
+ throw new Exception("@todo BAD_PATH");
}
public function children() {
@@ -45,31 +57,32 @@ class Server_Add_Controller extends Controller {
access::forbidden();
}
- $paths = unserialize(module::get_var("server_add", "authorized_paths"));
- $path_valid = false;
- $path = $this->input->post("path");
- $checked = $this->input->post("checked") == "true";
+ $path = $this->input->get("path");
+ $this->_validate_path($path);
- foreach (array_keys($paths) as $valid_path) {
- if ($path_valid = strpos($path, $valid_path) === 0) {
- break;
+ $tree = new View("server_add_tree.html");
+ $tree->files = array();
+ $tree->tree_id = substr(md5($path), 10);
+
+ foreach (glob("$path/*") as $file) {
+ if (!is_readable($file)) {
+ continue;
}
- }
- if (empty($path_valid)) {
- throw new Exception("@todo BAD_PATH");
- }
- if (!is_readable($path) || is_link($path)) {
- kohana::show_404();
- }
+ if (!is_dir($file)) {
+ $ext = strtolower(pathinfo($file, PATHINFO_EXTENSION));
+ if (!in_array($ext, array("gif", "jpeg", "jpg", "png", "flv", "mp4"))) {
+ continue;
+ }
+ }
- $tree = new View("server_add_tree.html");
- $tree->data = $this->_get_children($path);
- $tree->checked = $checked;
- $tree->tree_id = "tree_" . md5($path);
+ $tree->files[$file] = basename($file);
+ }
print $tree;
}
+ /* ================================================================================ */
+
function start($id) {
if (!user::active()->admin) {
access::forbidden();
@@ -237,36 +250,4 @@ class Server_Add_Controller extends Controller {
return $count;
}
-
- private function _get_children($path) {
- $directory_list = $file_list = array();
- $files = new DirectoryIterator($path);
- foreach ($files as $file) {
- if ($file->isDot() || $file->isLink()) {
- continue;
- }
- $filename = $file->getFilename();
- if ($filename[0] != ".") {
- if ($file->isDir()) {
- $directory_list[$filename] = array("path" => $file->getPathname(), "is_dir" => true);
- } else {
- $extension = strtolower(substr(strrchr($filename, '.'), 1));
- if ($file->isReadable() &&
- in_array($extension, array("gif", "jpeg", "jpg", "png", "flv", "mp4"))) {
- $file_list[$filename] = array("path" => $file->getPathname(), "is_dir" => false);
- }
- }
- }
- }
-
- ksort($directory_list);
- ksort($file_list);
-
- // We can't use array_merge here because if a file name is numeric, it will
- // get renumbered, so lets do it ourselves
- foreach ($file_list as $file => $fileinfo) {
- $directory_list[$file] = $fileinfo;
- }
- return $directory_list;
- }
} \ No newline at end of file