summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBharat Mediratta <bharat@menalto.com>2008-11-28 19:37:01 +0000
committerBharat Mediratta <bharat@menalto.com>2008-11-28 19:37:01 +0000
commit8b6ed6c477771e42d43ea0684e5139cf361b6cee (patch)
tree38c0db7b9d53e8ffb52f4ffaea05fdebbb248530
parent1b1d3852949a39765a4c58df3bcbc9cd5a28e00e (diff)
Create module::event() which runs Gallery events. It works by
convention. To respond to the "photo_created" event in the gmaps module, you create modules/gmaps/helpers/gmaps_event.php containing class gmaps_event which has function photo_created. Renamed all events from gallery.foo.bar to foo_bar Updated tag module to use new convention.
-rw-r--r--core/controllers/items.php4
-rw-r--r--core/helpers/album.php2
-rw-r--r--core/helpers/module.php10
-rw-r--r--core/helpers/photo.php2
-rw-r--r--modules/comment/helpers/comment.php2
-rw-r--r--modules/tag/helpers/tag.php30
-rw-r--r--modules/tag/helpers/tag_event.php50
-rw-r--r--modules/tag/hooks/photo_created.php2
-rw-r--r--modules/user/controllers/logout.php2
-rw-r--r--modules/user/helpers/user.php6
10 files changed, 69 insertions, 41 deletions
diff --git a/core/controllers/items.php b/core/controllers/items.php
index fd5e337d..26b55492 100644
--- a/core/controllers/items.php
+++ b/core/controllers/items.php
@@ -102,7 +102,7 @@ class Items_Controller extends REST_Controller {
$item->delete();
}
- Event::run("gallery.{$item->type}.deleted", $item);
+ module::event("{$item->type}_deleted", $item);
url::redirect("{$parent->type}s/{$parent->id}");
}
@@ -135,7 +135,7 @@ class Items_Controller extends REST_Controller {
$item->save();
- Event::run("gallery.{$item->type}.changed", $item);
+ module::event("{$item->type}_changed", $item);
if (array_key_exists("_return", $post)) {
print $item->{$post["_return"]};
diff --git a/core/helpers/album.php b/core/helpers/album.php
index e3972975..dd62d693 100644
--- a/core/helpers/album.php
+++ b/core/helpers/album.php
@@ -54,7 +54,7 @@ class album_Core {
mkdir($thumbnail_dir);
}
- Event::run("gallery.album.created", $album);
+ module::event("album_created", $album);
return $album;
}
diff --git a/core/helpers/module.php b/core/helpers/module.php
index fc76c033..afba658a 100644
--- a/core/helpers/module.php
+++ b/core/helpers/module.php
@@ -54,4 +54,14 @@ class module_Core {
public static function installed() {
return ORM::factory("module")->find_all();
}
+
+ public static function event($name, &$data=null) {
+ foreach (self::installed() as $module) {
+ $class = "{$module->name}_event";
+ $function = str_replace(".", "_", $name);
+ if (method_exists($class, $function)) {
+ call_user_func_array(array($class, $function), array($data));
+ }
+ }
+ }
}
diff --git a/core/helpers/photo.php b/core/helpers/photo.php
index 05fb2fb1..fc23c375 100644
--- a/core/helpers/photo.php
+++ b/core/helpers/photo.php
@@ -78,7 +78,7 @@ class photo_Core {
->set_resize($filename, 640, 480)
->save();
- Event::run("gallery.photo.created", $photo);
+ module::event("photo_created", $photo);
return $result;
}
diff --git a/modules/comment/helpers/comment.php b/modules/comment/helpers/comment.php
index 8bbb68d6..8db2bda5 100644
--- a/modules/comment/helpers/comment.php
+++ b/modules/comment/helpers/comment.php
@@ -52,7 +52,7 @@ class comment_Core {
$comment->item_id = $item_id;
$comment->save();
- Event::run("gallery.comment.created", $comment);
+ module::event("comment_created", $comment);
return $comment;
}
diff --git a/modules/tag/helpers/tag.php b/modules/tag/helpers/tag.php
index 19e2238e..774e1fa1 100644
--- a/modules/tag/helpers/tag.php
+++ b/modules/tag/helpers/tag.php
@@ -88,34 +88,4 @@ class tag_Core {
$form->add_rules_from(ORM::factory("tag"));
return $form;
}
-
- /**
- * Handle the creation of a new photo.
- * @todo Get tags from the XMP and/or IPTC data in the image
- *
- * @param Item_Model $photo
- */
- public static function on_photo_create() {
- $photo = Event::$data;
- $path = $photo->file_path();
- $tags = array();
- $size = getimagesize($photo->file_path(), $info);
- if (is_array($info) && !empty($info["APP13"])) {
- $iptc = iptcparse($info["APP13"]);
- if (!empty($iptc["2#025"])) {
- foreach($iptc["2#025"] as $tag) {
- $tags[$tag]= 1;
- }
- }
- }
-
- // @todo figure out how to read the keywords from xmp
-
- foreach(array_keys($tags) as $tag) {
- self::add($photo, $tag);
- }
-
- return;
- }
-
}
diff --git a/modules/tag/helpers/tag_event.php b/modules/tag/helpers/tag_event.php
new file mode 100644
index 00000000..25a79c2a
--- /dev/null
+++ b/modules/tag/helpers/tag_event.php
@@ -0,0 +1,50 @@
+<?php defined("SYSPATH") or die("No direct script access.");
+/**
+ * Gallery - a web based photo album viewer and editor
+ * Copyright (C) 2000-2008 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.
+ */
+class tag_event_Core {
+ /**
+ * Handle the creation of a new photo.
+ * @todo Get tags from the XMP and/or IPTC data in the image
+ *
+ * @param Item_Model $photo
+ */
+ public static function photo_create($photo) {
+ print "PHOTO CREATE";
+
+ $path = $photo->file_path();
+ $tags = array();
+ $size = getimagesize($photo->file_path(), $info);
+ if (is_array($info) && !empty($info["APP13"])) {
+ $iptc = iptcparse($info["APP13"]);
+ if (!empty($iptc["2#025"])) {
+ foreach($iptc["2#025"] as $tag) {
+ $tags[$tag]= 1;
+ }
+ }
+ }
+
+ // @todo figure out how to read the keywords from xmp
+
+ foreach(array_keys($tags) as $tag) {
+ self::add($photo, $tag);
+ }
+
+ return;
+ }
+}
diff --git a/modules/tag/hooks/photo_created.php b/modules/tag/hooks/photo_created.php
deleted file mode 100644
index 8d033317..00000000
--- a/modules/tag/hooks/photo_created.php
+++ /dev/null
@@ -1,2 +0,0 @@
-<?php defined('SYSPATH') or die('No direct script access.');
-Event::add("gallery.photo.created", array('tag', 'on_photo_create'));
diff --git a/modules/user/controllers/logout.php b/modules/user/controllers/logout.php
index c9ad1b6a..19a8450b 100644
--- a/modules/user/controllers/logout.php
+++ b/modules/user/controllers/logout.php
@@ -21,7 +21,7 @@ class Logout_Controller extends Controller {
public function index() {
try {
Session::instance()->destroy();
- Event::run("gallery.user.logout", $user);
+ module::event("user_logout", $user);
} catch (Exception $e) {
Kohana::log("error", $e);
}
diff --git a/modules/user/helpers/user.php b/modules/user/helpers/user.php
index 0133a153..dac39980 100644
--- a/modules/user/helpers/user.php
+++ b/modules/user/helpers/user.php
@@ -81,7 +81,7 @@ class user_Core {
group::add_user(group::REGISTERED_USERS, $user->id);
- Event::run("gallery.user.created", $user);
+ module::event("user_created", $user);
return $user;
}
@@ -93,7 +93,7 @@ class user_Core {
*/
static function delete($id) {
ORM::factory("user", $id)->delete();
- Event::run("gallery.user.deleted", $user);
+ module::event("user_deleted", $user);
}
/**
@@ -149,7 +149,7 @@ class user_Core {
$user->save();
Session::instance()->set('user', $user);
- Event::run("gallery.user.login", $user);
+ module::event("user_login", $user);
}
/**