diff options
author | Tim Almdal <tnalmdal@shaw.ca> | 2009-11-01 13:14:11 -0800 |
---|---|---|
committer | Tim Almdal <tnalmdal@shaw.ca> | 2009-11-01 13:14:11 -0800 |
commit | 809e738536b6639bb42ecae8eb1e183543fed93c (patch) | |
tree | 585365cff3fb009ebc4ad1d1485f4467791eacb1 /modules | |
parent | 91c5a9abb7b617e45b547ced6a28c14a64ef760f (diff) |
Try an new approach to extending forms. Create an extend_form event. For the first attempt replace the comment_add_form and item_add_form events.
Diffstat (limited to 'modules')
-rw-r--r-- | modules/comment/helpers/comment.php | 6 | ||||
-rw-r--r-- | modules/gallery/helpers/album.php | 4 | ||||
-rw-r--r-- | modules/gallery/helpers/movie.php | 5 | ||||
-rw-r--r-- | modules/gallery/helpers/photo.php | 4 | ||||
-rw-r--r-- | modules/recaptcha/config/recaptcha.php | 24 | ||||
-rw-r--r-- | modules/recaptcha/helpers/recaptcha_event.php | 10 | ||||
-rw-r--r-- | modules/tag/helpers/tag_event.php | 18 |
7 files changed, 56 insertions, 15 deletions
diff --git a/modules/comment/helpers/comment.php b/modules/comment/helpers/comment.php index 35685d8c..e2772707 100644 --- a/modules/comment/helpers/comment.php +++ b/modules/comment/helpers/comment.php @@ -72,7 +72,11 @@ class comment_Core { $group->input("url") ->label(t("Website (hidden)"))->id("g-url"); $group->textarea("text")->label(t("Comment")) ->id("g-text"); $group->hidden("item_id")->value($item->id); - module::event("comment_add_form", $form); + + $extend_form = (object)array("data" => $item, "form" => $form, "id" => "g-comment-form", + "append_to" => $group); + module::event("extend_form", $extend_form); + $group->submit("")->value(t("Add"))->class("ui-state-default ui-corner-all"); $active = identity::active_user(); diff --git a/modules/gallery/helpers/album.php b/modules/gallery/helpers/album.php index 72a79a75..c9c6e2c9 100644 --- a/modules/gallery/helpers/album.php +++ b/modules/gallery/helpers/album.php @@ -154,7 +154,9 @@ class album_Core { "DESC" => t("Descending"))) ->selected($parent->sort_order); - module::event("item_edit_form", $parent, $form); + $extend_form = (object)array("data" => $parent, "form" => $form, "id" => "g-edit-album-form", + "append_to" => $group); + module::event("extend_form", $extend_form); $group = $form->group("buttons")->label(""); $group->hidden("type")->value("album"); diff --git a/modules/gallery/helpers/movie.php b/modules/gallery/helpers/movie.php index e84e8ea6..9e663d1f 100644 --- a/modules/gallery/helpers/movie.php +++ b/modules/gallery/helpers/movie.php @@ -151,7 +151,9 @@ class movie_Core { "not_url_safe", t("The internet address should contain only letters, numbers, hyphens and underscores")); - module::event("item_edit_form", $movie, $form); + $extend_form = (object)array("data" => $parent, "form" => $form, "id" => "g-edit-movie-form", + "append_to" => $group); + module::event("extend_form", $extend_form); $group = $form->group("buttons")->label(""); $group->submit("")->value(t("Modify")); @@ -159,7 +161,6 @@ class movie_Core { return $form; } - static function getmoviesize($filename) { $ffmpeg = self::find_ffmpeg(); if (empty($ffmpeg)) { diff --git a/modules/gallery/helpers/photo.php b/modules/gallery/helpers/photo.php index 01cf5278..f5e1e1dc 100644 --- a/modules/gallery/helpers/photo.php +++ b/modules/gallery/helpers/photo.php @@ -179,7 +179,9 @@ class photo_Core { "not_url_safe", t("The internet address should contain only letters, numbers, hyphens and underscores")); - module::event("item_edit_form", $photo, $form); + $extend_form = (object)array("data" => $photo, "form" => $form, "id" => "g-edit-photo-form", + "append_to" => $group); + module::event("extend_form", $extend_form); $group = $form->group("buttons")->label(""); $group->submit("")->value(t("Modify")); diff --git a/modules/recaptcha/config/recaptcha.php b/modules/recaptcha/config/recaptcha.php new file mode 100644 index 00000000..04827673 --- /dev/null +++ b/modules/recaptcha/config/recaptcha.php @@ -0,0 +1,24 @@ +<?php defined("SYSPATH") or die("No direct script access."); +/** + * Gallery - a web based photo album viewer and editor + * Copyright (C) 2000-2009 Bharat Mediratta + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. + */ + +/** + * The list of forms that recaptcha should append itself to. + */ +$config["recaptcha"] = array("g-comment-form"); diff --git a/modules/recaptcha/helpers/recaptcha_event.php b/modules/recaptcha/helpers/recaptcha_event.php index feedced4..7a0b4f58 100644 --- a/modules/recaptcha/helpers/recaptcha_event.php +++ b/modules/recaptcha/helpers/recaptcha_event.php @@ -18,9 +18,13 @@ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ class recaptcha_event_Core { - static function comment_add_form($form) { - if (module::get_var("recaptcha", "public_key")) { - $form->add_comment->recaptcha("recaptcha")->label("")->id("g-recaptcha"); + static function extend_form($event_data) { + // @todo put into an admin interface + $config = Kohana::config("recaptcha"); + if (module::get_var("recaptcha", "public_key") && + in_array($event_data->id, $config["recaptcha"])) { + $input = empty($event_data->append_to) ? $event_data->form : $event_data->append_to; + $input->recaptcha("recaptcha")->label("")->id("g-recaptcha"); } } diff --git a/modules/tag/helpers/tag_event.php b/modules/tag/helpers/tag_event.php index 57986e40..cc134766 100644 --- a/modules/tag/helpers/tag_event.php +++ b/modules/tag/helpers/tag_event.php @@ -64,16 +64,20 @@ class tag_event_Core { tag::compact(); } - static function item_edit_form($item, $form) { - $url = url::site("tags/autocomplete"); - $form->script("") - ->text("$('form input[id=tags]').ready(function() { + static function extend_form($event_data) { + if (in_array($event_data->id, + array("g-edit-album-form", "g-edit-movie-form", "g-edit-photo-form"))) { + $url = url::site("tags/autocomplete"); + $event_data->form->script("") + ->text("$('form input[id=tags]').ready(function() { $('form input[id=tags]').autocomplete( '$url', {max: 30, multiple: true, multipleSeparator: ',', cacheLength: 1}); });"); - $tag_value = implode(", ", tag::item_tags($item)); - $form->edit_item->input("tags")->label(t("Tags (comma separated)")) - ->value($tag_value); + $tag_value = implode(", ", tag::item_tags($event_data->data)); + $input = empty($event_data->append_to) ? $event_data->form : $event_data->append_to; + $input->input("tags")->label(t("Tags (comma separated)")) + ->value($tag_value); + } } static function item_edit_form_completed($item, $form) { |