From 87c31f432bba901429a1c4bf942264a03d9e2b6e Mon Sep 17 00:00:00 2001 From: shish Date: Thu, 6 Dec 2007 10:21:23 +0000 Subject: [PATCH] move all events into event.class.php for neatness and more controlled load order git-svn-id: file:///home/shish/svn/shimmie2/trunk@627 7f39781d-f577-437e-ae19-be835c7a54ca --- core/event.class.php | 235 +++++++++++++++++++++- core/events/configsave.event.php | 14 -- core/events/dataupload.event.php | 23 --- core/events/displayingimage.event.php | 23 --- core/events/imageaddition.event.php | 16 -- core/events/imagedeletion.event.php | 17 -- core/events/initext.event.php | 10 - core/events/pagerequest.event.php | 35 ---- core/events/parselinktemplate.event.php | 17 -- core/events/sourceset.event.php | 17 -- core/events/tagset.event.php | 17 -- core/events/textformatting.event.php | 20 -- core/events/thumbnailgeneration.event.php | 15 -- 13 files changed, 233 insertions(+), 226 deletions(-) delete mode 100644 core/events/configsave.event.php delete mode 100644 core/events/dataupload.event.php delete mode 100644 core/events/displayingimage.event.php delete mode 100644 core/events/imageaddition.event.php delete mode 100644 core/events/imagedeletion.event.php delete mode 100644 core/events/initext.event.php delete mode 100644 core/events/pagerequest.event.php delete mode 100644 core/events/parselinktemplate.event.php delete mode 100644 core/events/sourceset.event.php delete mode 100644 core/events/tagset.event.php delete mode 100644 core/events/textformatting.event.php delete mode 100644 core/events/thumbnailgeneration.event.php diff --git a/core/event.class.php b/core/event.class.php index 48a4f390..a9761877 100644 --- a/core/event.class.php +++ b/core/event.class.php @@ -4,12 +4,243 @@ * generic parent class */ class Event { - var $vetoed = false; - var $veto_reason; + var $vetoed = false, $veto_reason = null; public function veto($reason="") { $this->vetoed = true; $this->veto_reason = $reason; } } + + +/* + * ConfigSaveEvent: + * Sent when the setup screen's 'set' button has been + * activated; new config options are in $_POST + */ +class ConfigSaveEvent extends Event { + var $config; + + public function ConfigSaveEvent($config) { + $this->config = $config; + } +} + + +/* + * DataUploadEvent: + * $user -- the user uploading the data + * $tmpname -- the temporary file used for upload + * $metadata -- info about the file, should contain at least "filename", "extension", "tags" and "source" + * + * Some data is being uploaded. Should be caught by a file handler. + */ +class DataUploadEvent extends Event { + var $user, $tmpname, $metadata, $hash, $type; + + public function DataUploadEvent($user, $tmpname, $metadata) { + $this->user = $user; + $this->tmpname = $tmpname; + + $this->metadata = $metadata; + $this->metadata['hash'] = md5_file($tmpname); + $this->metadata['size'] = filesize($tmpname); + + // useful for most file handlers, so pull directly into fields + $this->hash = $this->metadata['hash']; + $this->type = strtolower($metadata['extension']); + } +} + + +/* + * DisplayingImageEvent: + * $image -- the image being displayed + * $page -- the page to display on + * + * Sent when an image is ready to display. Extensions who + * wish to appear on the "view" page should listen for this, + * which only appears when an image actually exists. + */ +class DisplayingImageEvent extends Event { + var $image, $page; + + public function DisplayingImageEvent($image, $page) { + $this->image = $image; + $this->page = $page; + } + + public function get_image() { + return $this->image; + } +} + + +/* + * ImageAdditionEvent: + * $user -- the user adding the image + * $image -- the image being added + * + * An image is being added to the database + */ +class ImageAdditionEvent extends Event { + var $user, $image; + + public function ImageAdditionEvent($user, $image) { + $this->image = $image; + $this->user = $user; + } +} + + +/* + * ImageDeletionEvent: + * $image -- the image being deleted + * + * An image is being deleted. Used by things like tags + * and comments handlers to clean out related rows in + * their tables + */ +class ImageDeletionEvent extends Event { + var $image; + + public function ImageDeletionEvent($image) { + $this->image = $image; + } +} + + +/* + * InitExtEvent: + * A wake-up call for extensions + */ +class InitExtEvent extends Event { + public function InitExtEvent() { + } +} + + +/* + * PageRequestEvent: + * $page_name -- the main name of the page, eg "post" + * $args -- the arguments, eg "list" + * $page -- a page object to add things to + * $user -- the user requesting the page + * get_arg(int) + * count_args() + * + * User requests /view/42 -> an event is generated with + * $page_name="view" and $args=array("42"); + * + * Used for initial page generation triggers + */ +class PageRequestEvent extends Event { + var $page_name, $args, $page, $user; + + public function PageRequestEvent($page_name, $args, $page, $user) { + $this->page_name = $page_name; + $this->args = $args; + $this->page = $page; + $this->user = $user; + } + + public function get_arg($n) { + return isset($this->args[$n]) ? $this->args[$n] : null; + } + + public function count_args() { + return isset($this->args) ? count($this->args) : 0; + } +} + + +/* + * ParseLinkTemplateEvent: + * $link -- the formatted link + * $original -- the formatting string, for reference + * $image -- the image who's link is being parsed + */ +class ParseLinkTemplateEvent extends Event { + var $link, $original; + var $image; + + public function ParseLinkTemplateEvent($link, $image) { + $this->link = $link; + $this->original = $link; + $this->image = $image; + } + + public function replace($needle, $replace) { + $this->link = str_replace($needle, $replace, $this->link); + } +} + + +/* + * SourceSetEvent: + * $image_id + * $source + * + */ +class SourceSetEvent extends Event { + var $image_id; + var $source; + + public function SourceSetEvent($image_id, $source) { + $this->image_id = $image_id; + $this->source = $source; + } +} + + +/* + * TagSetEvent: + * $image_id + * $tags + * + */ +class TagSetEvent extends Event { + var $image_id; + var $tags; + + public function TagSetEvent($image_id, $tags) { + $this->image_id = $image_id; + $this->tags = $tags; + } +} + + +/* + * TextFormattingEvent: + * $original - for reference + * $formatted - with formatting applied + * $stripped - with formatting removed + * + */ +class TextFormattingEvent extends Event { + var $original; + var $formatted; + var $stripped; + + public function TextFormattingEvent($text) { + $this->original = $text; + $this->formatted = $text; + $this->stripped = $text; + } +} + + +/* + * ThumbnailGenerationEvent: + * Request a thumb be made for an image + */ +class ThumbnailGenerationEvent extends Event { + var $hash; + var $type; + + public function ThumbnailGenerationEvent($hash, $type) { + $this->hash = $hash; + $this->type = $type; + } +} ?> diff --git a/core/events/configsave.event.php b/core/events/configsave.event.php deleted file mode 100644 index cc8f5bf1..00000000 --- a/core/events/configsave.event.php +++ /dev/null @@ -1,14 +0,0 @@ -config = $config; - } -} -?> diff --git a/core/events/dataupload.event.php b/core/events/dataupload.event.php deleted file mode 100644 index 3fb78cfa..00000000 --- a/core/events/dataupload.event.php +++ /dev/null @@ -1,23 +0,0 @@ -user = $user; - $this->tmpname = $tmpname; - - $this->metadata = $metadata; - $this->metadata['hash'] = md5_file($tmpname); - $this->metadata['size'] = filesize($tmpname); - - // useful for most file handlers, so pull directly into fields - $this->hash = $this->metadata['hash']; - $this->type = strtolower($metadata['extension']); - } -} -?> diff --git a/core/events/displayingimage.event.php b/core/events/displayingimage.event.php deleted file mode 100644 index 030dc56d..00000000 --- a/core/events/displayingimage.event.php +++ /dev/null @@ -1,23 +0,0 @@ -image = $image; - $this->page = $page; - } - - public function get_image() { - return $this->image; - } -} -?> diff --git a/core/events/imageaddition.event.php b/core/events/imageaddition.event.php deleted file mode 100644 index 45765a4d..00000000 --- a/core/events/imageaddition.event.php +++ /dev/null @@ -1,16 +0,0 @@ -image = $image; - $this->user = $user; - } -} -?> diff --git a/core/events/imagedeletion.event.php b/core/events/imagedeletion.event.php deleted file mode 100644 index 9c30aa94..00000000 --- a/core/events/imagedeletion.event.php +++ /dev/null @@ -1,17 +0,0 @@ -image = $image; - } -} -?> diff --git a/core/events/initext.event.php b/core/events/initext.event.php deleted file mode 100644 index 7c01f5df..00000000 --- a/core/events/initext.event.php +++ /dev/null @@ -1,10 +0,0 @@ - diff --git a/core/events/pagerequest.event.php b/core/events/pagerequest.event.php deleted file mode 100644 index f05f073e..00000000 --- a/core/events/pagerequest.event.php +++ /dev/null @@ -1,35 +0,0 @@ - an event is generated with - * $page="view" and $args=array("42"); - * - * Used for initial page generation triggers - */ -class PageRequestEvent extends Event { - var $page_name; - var $args; - var $page; - var $user; - - public function PageRequestEvent($page_name, $args, $page, $user) { - $this->page_name = $page_name; - $this->args = $args; - $this->page = $page; - $this->user = $user; - } - - public function get_arg($n) { - return isset($this->args[$n]) ? $this->args[$n] : null; - } - - public function count_args() { - return isset($this->args) ? count($this->args) : 0; - } -} -?> diff --git a/core/events/parselinktemplate.event.php b/core/events/parselinktemplate.event.php deleted file mode 100644 index 7dcb2093..00000000 --- a/core/events/parselinktemplate.event.php +++ /dev/null @@ -1,17 +0,0 @@ -link = $link; - $this->original = $link; - $this->image = $image; - } - - public function replace($needle, $replace) { - $this->link = str_replace($needle, $replace, $this->link); - } -} -?> diff --git a/core/events/sourceset.event.php b/core/events/sourceset.event.php deleted file mode 100644 index ddd99463..00000000 --- a/core/events/sourceset.event.php +++ /dev/null @@ -1,17 +0,0 @@ -image_id = $image_id; - $this->source = $source; - } -} -?> diff --git a/core/events/tagset.event.php b/core/events/tagset.event.php deleted file mode 100644 index 8ea3b8f5..00000000 --- a/core/events/tagset.event.php +++ /dev/null @@ -1,17 +0,0 @@ -image_id = $image_id; - $this->tags = $tags; - } -} -?> diff --git a/core/events/textformatting.event.php b/core/events/textformatting.event.php deleted file mode 100644 index 38608e41..00000000 --- a/core/events/textformatting.event.php +++ /dev/null @@ -1,20 +0,0 @@ -original = $text; - $this->formatted = $text; - $this->stripped = $text; - } -} -?> diff --git a/core/events/thumbnailgeneration.event.php b/core/events/thumbnailgeneration.event.php deleted file mode 100644 index bfa03794..00000000 --- a/core/events/thumbnailgeneration.event.php +++ /dev/null @@ -1,15 +0,0 @@ -hash = $hash; - $this->type = $type; - } -} -?>