From 144c2fb61ee30e1168a6afe3b0332485d748d608 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Fri, 20 Nov 2009 13:04:54 -0800 Subject: Minor reformatting. --- modules/gallery/views/simple_uploader.html.php | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'modules') diff --git a/modules/gallery/views/simple_uploader.html.php b/modules/gallery/views/simple_uploader.html.php index bc478232..d23b89e0 100644 --- a/modules/gallery/views/simple_uploader.html.php +++ b/modules/gallery/views/simple_uploader.html.php @@ -106,8 +106,9 @@
">
- html::purify($item->title))) ?> - + + html::purify($item->title))) ?> +
@@ -121,15 +122,15 @@
-

- -

-
    - parents() as $i => $parent): ?> - > title) ?> - -
  • title) ?>
  • -
+

+ +

+
    + parents() as $i => $parent): ?> + > title) ?> + +
  • title) ?>
  • +
-- cgit v1.2.3 From 5e9bbbe490e40da103e0a7960312ab1c814dafa3 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Fri, 20 Nov 2009 19:41:45 -0800 Subject: Convert the Simple Uploader form over to Forge, and use the event model to let the Tags module modify it. This brings it inline with our other module-extensible form based interactions. --- modules/gallery/controllers/simple_uploader.php | 25 +++- modules/gallery/libraries/Form_Uploadify.php | 54 +++++++ .../gallery/libraries/Form_Uploadify_buttons.php | 25 ++++ modules/gallery/module.info | 3 +- modules/gallery/views/form_uploadify.html.php | 123 ++++++++++++++++ .../gallery/views/form_uploadify_buttons.html.php | 8 ++ modules/gallery/views/simple_uploader.html.php | 160 --------------------- modules/tag/helpers/tag_event.php | 26 +++- 8 files changed, 253 insertions(+), 171 deletions(-) create mode 100644 modules/gallery/libraries/Form_Uploadify.php create mode 100644 modules/gallery/libraries/Form_Uploadify_buttons.php create mode 100644 modules/gallery/views/form_uploadify.html.php create mode 100644 modules/gallery/views/form_uploadify_buttons.html.php delete mode 100644 modules/gallery/views/simple_uploader.html.php (limited to 'modules') diff --git a/modules/gallery/controllers/simple_uploader.php b/modules/gallery/controllers/simple_uploader.php index c6d7fc83..255d5df2 100644 --- a/modules/gallery/controllers/simple_uploader.php +++ b/modules/gallery/controllers/simple_uploader.php @@ -26,9 +26,7 @@ class Simple_Uploader_Controller extends Controller { $item = $item->parent(); } - $v = new View("simple_uploader.html"); - $v->item = $item; - print $v; + print self::get_add_form($item); } public function start() { @@ -67,9 +65,11 @@ class Simple_Uploader_Controller extends Controller { html::anchor("photos/$item->id", t("view photo"))); } - $tags = $this->input->post("tags"); - if (!(empty($tags))) { - module::event("add_tags_to_item", $item, $tags); + // We currently have no way of showing errors if validation fails, so only call our event + // handlers if validation passes. + $form = self::get_add_form($album); + if ($form->validate()) { + module::event("add_photos_form_completed", $item, $form); } } catch (Exception $e) { Kohana::log("alert", $e->__toString()); @@ -95,4 +95,17 @@ class Simple_Uploader_Controller extends Controller { print json_encode(array("result" => "success")); } + public function get_add_form($album) { + $form = new Forge("simple_uploader/finish", "", "post", array("id" => "g-add-photos-form")); + $group = $form->group("add_photos") + ->label(t("Add photos to %album_title", array("album_title" => html::purify($album->title)))); + $group->uploadify("uploadify")->album($album); + + $group = $form->group("actions"); + $group->uploadify_buttons(""); + + module::event("add_photos_form", $album, $form); + + return $form; + } } diff --git a/modules/gallery/libraries/Form_Uploadify.php b/modules/gallery/libraries/Form_Uploadify.php new file mode 100644 index 00000000..b1d9fa74 --- /dev/null +++ b/modules/gallery/libraries/Form_Uploadify.php @@ -0,0 +1,54 @@ + false, + "type" => "UNKNOWN", + "url" => "", + "text" => ""); + + public function __construct($name) { + parent::__construct($name); + $this->data["script_data"] = array( + "g3sid" => Session::instance()->id(), + "user_agent" => Input::instance()->server("HTTP_USER_AGENT"), + "csrf" => access::csrf_token()); + } + + public function album(Item_Model $album) { + $this->data["album"] = $album; + return $this; + } + + public function script_data($key, $value) { + $this->data["script_data"][$key] = $value; + } + + public function render() { + $v = new View("form_uploadify.html"); + $v->album = $this->data["album"]; + $v->script_data = $this->data["script_data"]; + return $v; + } + + public function validate() { + return true; + } +} \ No newline at end of file diff --git a/modules/gallery/libraries/Form_Uploadify_buttons.php b/modules/gallery/libraries/Form_Uploadify_buttons.php new file mode 100644 index 00000000..549010b8 --- /dev/null +++ b/modules/gallery/libraries/Form_Uploadify_buttons.php @@ -0,0 +1,25 @@ + + + + + + + +
    +
  • + suhosin.session.encrypt setting from Suhosin. You must disable this setting to upload photos.", + array("encrypt_url" => "http://www.hardened-php.net/suhosin/configuration.html#suhosin.session.encrypt", + "suhosin_url" => "http://www.hardened-php.net/suhosin/")) ?> +
  • +
+ + +
+

+ +

+
    + parents() as $i => $parent): ?> + > title) ?> + +
  • title) ?>
  • +
+
+ +
+ + +
+
+
    +
+
diff --git a/modules/gallery/views/form_uploadify_buttons.html.php b/modules/gallery/views/form_uploadify_buttons.html.php new file mode 100644 index 00000000..d88bb6aa --- /dev/null +++ b/modules/gallery/views/form_uploadify_buttons.html.php @@ -0,0 +1,8 @@ + + + + diff --git a/modules/gallery/views/simple_uploader.html.php b/modules/gallery/views/simple_uploader.html.php deleted file mode 100644 index d23b89e0..00000000 --- a/modules/gallery/views/simple_uploader.html.php +++ /dev/null @@ -1,160 +0,0 @@ - - - - - - -"> -
- - html::purify($item->title))) ?> - -
-
- -
    -
  • - suhosin.session.encrypt setting from Suhosin. You must disable this setting to upload photos.", - array("encrypt_url" => "http://www.hardened-php.net/suhosin/configuration.html#suhosin.session.encrypt", - "suhosin_url" => "http://www.hardened-php.net/suhosin/")) ?> -
  • -
- - -
-

- -

-
    - parents() as $i => $parent): ?> - > title) ?> - -
  • title) ?>
  • -
-
- -
- - -
-
-
    -
-
- - -
- - -
- - - - - -
- diff --git a/modules/tag/helpers/tag_event.php b/modules/tag/helpers/tag_event.php index 19c917ac..a857a99d 100644 --- a/modules/tag/helpers/tag_event.php +++ b/modules/tag/helpers/tag_event.php @@ -98,13 +98,31 @@ class tag_event_Core { $data[] = join(" ", tag::item_tags($item)); } - static function add_tags_to_item($item, $tags) { - foreach (split(",", $tags) as $tag_name) { + static function add_photos_form($album, $form) { + $group = $form->add_photos; + $group->input("tags") + ->label(t("Add tags to all uploaded files")) + ->value(""); + $group->uploadify->script_data("tags", ""); + + $autocomplete_url = url::site("tags/autocomplete"); + $group->script("") + ->text("$('input[name=tags]') + .autocomplete( + '$autocomplete_url', + {max: 30, multiple: true, multipleSeparator: ',', cacheLength: 1} + ) + .change(function (event) { + $('#g-uploadify').uploadifySettings('scriptData', {'tags': $(this).val()}); + });"); + } + + static function add_photos_form_completed($album, $form) { + foreach (split(",", $form->add_photos->tags->value) as $tag_name) { $tag_name = trim($tag_name); if ($tag_name) { - $tag = tag::add($item, $tag_name); + $tag = tag::add($album, $tag_name); } } } - } -- cgit v1.2.3