From 9e08285c003de4fcb2dad9bd6917c326961ed524 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sat, 14 Feb 2009 23:03:09 +0000 Subject: Say hello to the new Flash based uploader, courtesy of Eric Zelermyer. This requires a little trickery to proxy the session id and user agent through the ActionScript code so that we can assume the same session in the uploader. It's also using its own path to add photos since we'll want to have a slightly different protocol for dealing with responses (as opposed to JSON or HTML). A work in progress for sure, but it's already better than what we had before.?\024 --- core/SimpleUploader.swf | Bin 0 -> 301016 bytes core/controllers/simple_uploader.php | 55 +++++++++++++++++++++++++++++++++++ core/helpers/core_menu.php | 4 +-- core/hooks/init_gallery.php | 11 +++++++ core/views/simple_uploader.html.php | 30 +++++++++++++++++++ 5 files changed, 98 insertions(+), 2 deletions(-) create mode 100644 core/SimpleUploader.swf create mode 100644 core/controllers/simple_uploader.php create mode 100644 core/views/simple_uploader.html.php (limited to 'core') diff --git a/core/SimpleUploader.swf b/core/SimpleUploader.swf new file mode 100644 index 00000000..7b030809 Binary files /dev/null and b/core/SimpleUploader.swf differ diff --git a/core/controllers/simple_uploader.php b/core/controllers/simple_uploader.php new file mode 100644 index 00000000..e3ed84ec --- /dev/null +++ b/core/controllers/simple_uploader.php @@ -0,0 +1,55 @@ +item = $item; + $v->flash_vars = + "uploadUrl=" . urlencode( + url::site("simple_uploader/add_photo/$item->id" . + "?csrf=" . access::csrf_token() . + "&g3sid=" . Session::instance()->id() . + "&user_agent=" . Input::instance()->server("HTTP_USER_AGENT"))) . + "&title=" . urlencode(t("Add photos")) . + "&addLabel=" . urlencode(t("Choose photos to add...")); + print $v; + } + + public function add_photo($id) { + $album = ORM::factory("item", $id); + access::required("edit", $album); + access::verify_csrf(); + + $file_validation = new Validation($_FILES); + $file_validation->add_rules("file", "upload::valid", "upload::type[gif,jpg,png]"); + if ($file_validation->validate()) { + $temp_filename = upload::save("file"); + $photo = photo::create( + $album, + $temp_filename, + basename($temp_filename), + basename($temp_filename)); + log::success("content", "Added a photo", html::anchor("photos/$photo->id", "view photo")); + } + } +} diff --git a/core/helpers/core_menu.php b/core/helpers/core_menu.php index c1472001..2ec8e073 100644 --- a/core/helpers/core_menu.php +++ b/core/helpers/core_menu.php @@ -43,7 +43,7 @@ class core_menu_Core { ->id("edit_item") ->label($item->is_album() ? t("Edit album") : t("Edit photo")) ->url(url::site("form/edit/{$item->type}s/$item->id"))); - + // @todo Move album options menu to the album quick edit pane // @todo Create resized item quick edit pane menu if ($item->is_album()) { @@ -51,7 +51,7 @@ class core_menu_Core { ->append(Menu::factory("dialog") ->id("add_item") ->label(t("Add a photo")) - ->url(url::site("form/add/albums/$item->id?type=photo"))) + ->url(url::site("simple_uploader/app/$item->id"))) ->append(Menu::factory("dialog") ->id("add_album") ->label(t("Add an album")) diff --git a/core/hooks/init_gallery.php b/core/hooks/init_gallery.php index 27a4d8a4..89f97ef9 100644 --- a/core/hooks/init_gallery.php +++ b/core/hooks/init_gallery.php @@ -21,3 +21,14 @@ Event::add("system.ready", array("I18n", "instance")); Event::add("system.post_routing", array("theme", "load_themes")); Event::add("system.ready", array("module", "load_modules")); Event::add("system.post_routing", array("url", "parse_url")); + +// Override the cookie if we have a session id in the URL. +// @todo This should probably be an event callback +$input = Input::instance(); +if ($g3sid = $input->post("g3sid", $input->get("g3sid"))) { + $_COOKIE["g3sid"] = $g3sid; +} + +if ($user_agent = $input->post("user_agent", $input->get("user_agent"))) { + Kohana::$user_agent = $user_agent; +} diff --git a/core/views/simple_uploader.html.php b/core/views/simple_uploader.html.php new file mode 100644 index 00000000..c9389a13 --- /dev/null +++ b/core/views/simple_uploader.html.php @@ -0,0 +1,30 @@ + + +
+ $item->title)) ?> +
+ + + + + + + + " + quality="high" + bgcolor="#ffffff" + flashVars="" + width="470" height="400" name="" + align="middle" + play="true" + loop="false" + quality="high" + allowScriptAccess="sameDomain" + type="application/x-shockwave-flash" + pluginspage="http://www.adobe.com/go/getflashplayer"> + + -- cgit v1.2.3