page_title = t("Add from server"); $view->content = new View("admin_videos.html"); $view->content->form = $this->_get_admin_form(); $paths = unserialize(module::get_var("videos", "authorized_paths", "a:0:{}")); $view->content->paths = array_keys($paths); print $view; } public function add_path() { access::verify_csrf(); $form = $this->_get_admin_form(); $paths = unserialize(module::get_var("videos", "authorized_paths", "a:0:{}")); if ($form->validate()) { if (is_link($form->add_path->path->value)) { $form->add_path->path->add_error("is_symlink", 1); } else if (!is_readable($form->add_path->path->value)) { $form->add_path->path->add_error("not_readable", 1); } else { $path = $form->add_path->path->value; $paths[$path] = 1; module::set_var("videos", "authorized_paths", serialize($paths)); message::success(t("Added path %path", array("path" => $path))); videos::check_config($paths); url::redirect("admin/videos"); } } $view = new Admin_View("admin.html"); $view->content = new View("admin_videos.html"); $view->content->form = $form; $view->content->paths = array_keys($paths); print $view; } public function remove_path() { access::verify_csrf(); $path = Input::instance()->get("path"); $paths = unserialize(module::get_var("videos", "authorized_paths")); if (isset($paths[$path])) { unset($paths[$path]); message::success(t("Removed path %path", array("path" => $path))); module::set_var("videos", "authorized_paths", serialize($paths)); videos::check_config($paths); } url::redirect("admin/videos"); } public function autocomplete() { $directories = array(); $path_prefix = Input::instance()->get("q"); foreach (glob("{$path_prefix}*") as $file) { if (is_dir($file) && !is_link($file)) { $directories[] = $file; } } print implode("\n", $directories); } private function _get_admin_form() { $form = new Forge("admin/videos/add_path", "", "post", array("id" => "g-server-add-admin-form", "class" => "g-short-form")); $add_path = $form->group("add_path"); $add_path->input("path")->label(t("Path"))->rules("required")->id("g-path") ->error_messages("not_readable", t("This directory is not readable by the webserver")) ->error_messages("is_symlink", t("Symbolic links are not allowed")); $add_path->submit("add")->value(t("Add Path")); return $form; } }