summaryrefslogtreecommitdiff
path: root/core
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 /core
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.
Diffstat (limited to 'core')
-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
4 files changed, 14 insertions, 4 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;
}