diff --git a/contrib/ban_words/main.php b/contrib/ban_words/main.php
index 840c198c..aee98417 100644
--- a/contrib/ban_words/main.php
+++ b/contrib/ban_words/main.php
@@ -19,11 +19,10 @@
* from Essex"
*/
-class BanWords implements Extension {
- public function receive_event(Event $event) {
- if($event instanceof InitExtEvent) {
- global $config;
- $config->set_default_string('banned_words', "
+class BanWords extends SimpleExtension {
+ public function onInitExt(InitExtEvent $event) {
+ global $config;
+ $config->set_default_string('banned_words', "
a href=
anal
blowjob
@@ -50,42 +49,42 @@ ultram
very nice site
viagra
xanax
- ");
- }
+");
+ }
- if($event instanceof CommentPostingEvent) {
- global $config;
- $banned = $config->get_string("banned_words");
- $comment = strtolower($event->comment);
+ public function onCommentPosting(CommentPostingEvent $event) {
+ global $config;
+ $banned = $config->get_string("banned_words");
+ $comment = strtolower($event->comment);
- foreach(explode("\n", $banned) as $word) {
- $word = trim(strtolower($word));
- if(strlen($word) == 0) {
- // line is blank
- continue;
+ foreach(explode("\n", $banned) as $word) {
+ $word = trim(strtolower($word));
+ if(strlen($word) == 0) {
+ // line is blank
+ continue;
+ }
+ else if($word[0] == '/') {
+ // lines that start with slash are regex
+ if(preg_match($word, $comment)) {
+ throw new CommentPostingException("Comment contains banned terms");
}
- else if($word[0] == '/') {
- // lines that start with slash are regex
- if(preg_match($word, $comment)) {
- throw new CommentPostingException("Comment contains banned terms");
- }
- }
- else {
- // other words are literal
- if(strpos($comment, $word) !== false) {
- throw new CommentPostingException("Comment contains banned terms");
- }
+ }
+ else {
+ // other words are literal
+ if(strpos($comment, $word) !== false) {
+ throw new CommentPostingException("Comment contains banned terms");
}
}
}
-
- if($event instanceof SetupBuildingEvent) {
- $sb = new SetupBlock("Banned Phrases");
- $sb->add_label("One per line, lines that start with slashes are treated as regex
");
- $sb->add_longtext_option("banned_words");
- $event->panel->add_block($sb);
- }
}
+
+ public function onSetupBuilding(SetupBuildingEvent $event) {
+ $sb = new SetupBlock("Banned Phrases");
+ $sb->add_label("One per line, lines that start with slashes are treated as regex
");
+ $sb->add_longtext_option("banned_words");
+ $event->panel->add_block($sb);
+ }
+
+ public function get_priority() {return 30;}
}
-add_event_listener(new BanWords(), 30); // before the comment is added
?>
diff --git a/contrib/image_hash_ban/main.php b/contrib/image_hash_ban/main.php
index eee5d6d7..292a9da6 100644
--- a/contrib/image_hash_ban/main.php
+++ b/contrib/image_hash_ban/main.php
@@ -30,27 +30,32 @@ class AddImageHashBanEvent extends Event {
}
// }}}
class ImageBan implements Extension {
- var $theme;
+ public function onInitExt(InitExtEvent $event) {
+ global $config, $database;
+ if($config->get_int("ext_imageban_version") < 1) {
+ $database->create_table("image_bans", "
+ id SCORE_AIPK,
+ hash CHAR(32) NOT NULL,
+ date DATETIME DEFAULT SCORE_NOW,
+ reason TEXT NOT NULL
+ ");
+ $config->set_int("ext_imageban_version", 1);
+ }
+ }
- public function receive_event(Event $event) {
+ public function onDataUpload(DataUploadEvent $event) {
+ global $database;
+ $row = $database->db->GetRow("SELECT * FROM image_bans WHERE hash = ?", $event->hash);
+ if($row) {
+ log_info("image_hash_ban", "Blocked image ({$event->hash})");
+ throw new UploadException("Image ".html_escape($row["hash"])." has been banned, reason: ".format_text($row["reason"]));
+ }
+ }
+
+ public function onPageRequest(PageRequestEvent $event) {
global $config, $database, $page, $user;
- if(is_null($this->theme)) $this->theme = get_theme_object($this);
- if($event instanceof InitExtEvent) {
- if($config->get_int("ext_imageban_version") < 1) {
- $this->install();
- }
- }
-
- if($event instanceof DataUploadEvent) {
- $row = $database->db->GetRow("SELECT * FROM image_bans WHERE hash = ?", $event->hash);
- if($row) {
- log_info("image_hash_ban", "Blocked image ({$event->hash})");
- throw new UploadException("Image ".html_escape($row["hash"])." has been banned, reason: ".format_text($row["reason"]));
- }
- }
-
- if(($event instanceof PageRequestEvent) && $event->page_matches("image_hash_ban")) {
+ if($event->page_matches("image_hash_ban")) {
if($user->is_admin()) {
if($event->get_arg(0) == "add") {
if(isset($_POST['hash']) && isset($_POST['reason'])) {
@@ -87,38 +92,28 @@ class ImageBan implements Extension {
}
}
}
+ }
- if($event instanceof UserBlockBuildingEvent) {
- if($user->is_admin()) {
- $event->add_link("Image Bans", make_link("image_hash_ban/list/1"));
- }
- }
-
- if($event instanceof AddImageHashBanEvent) {
- $this->add_image_hash_ban($event->hash, $event->reason);
- }
-
- if($event instanceof RemoveImageHashBanEvent) {
- $this->remove_image_hash_ban($event->hash);
- }
-
- if($event instanceof ImageAdminBlockBuildingEvent) {
- if($user->is_admin()) {
- $event->add_part($this->theme->get_buttons_html($event->image));
- }
+ public function onUserBlockBuilding(UserBlockBuildingEvent $event) {
+ global $user;
+ if($user->is_admin()) {
+ $event->add_link("Image Bans", make_link("image_hash_ban/list/1"));
}
}
- protected function install() {
- global $database;
- global $config;
- $database->create_table("image_bans", "
- id SCORE_AIPK,
- hash CHAR(32) NOT NULL,
- date DATETIME DEFAULT SCORE_NOW,
- reason TEXT NOT NULL
- ");
- $config->set_int("ext_imageban_version", 1);
+ public function onAddImageHashBan(AddImageHashBanEvent $event) {
+ $this->add_image_hash_ban($event->hash, $event->reason);
+ }
+
+ public function onRemoveImageHashBan(RemoveImageHashBanEvent $event) {
+ $this->remove_image_hash_ban($event->hash);
+ }
+
+ public function onImageAdminBlockBuilding(ImageAdminBlockBuildingEvent $event) {
+ global $user;
+ if($user->is_admin()) {
+ $event->add_part($this->theme->get_buttons_html($event->image));
+ }
}
// DB funness
@@ -145,6 +140,7 @@ class ImageBan implements Extension {
$database->Execute("DELETE FROM image_bans WHERE hash = ?", array($hash));
}
+ // in before resolution limit plugin
+ public function get_priority() {return 30;}
}
-add_event_listener(new ImageBan(), 30); // in before resolution limit plugin
?>
diff --git a/ext/handle_404/main.php b/ext/handle_404/main.php
index f5baf731..3a9a2503 100644
--- a/ext/handle_404/main.php
+++ b/ext/handle_404/main.php
@@ -8,20 +8,18 @@
* Description: Shows an error message when the user views a page with no content
*/
-class Handle404 implements Extension {
- public function receive_event(Event $event) {
- if($event instanceof PageRequestEvent) {
- global $page;
- // hax.
- if($page->mode == "page" && (!isset($page->blocks) || $this->count_main($page->blocks) == 0)) {
- $h_pagename = html_escape(implode('/', $event->args));
- header("HTTP/1.0 404 Page Not Found");
- log_debug("handle_404", "Hit 404: $h_pagename");
- $page->set_title("404");
- $page->set_heading("404 - No Handler Found");
- $page->add_block(new NavBlock());
- $page->add_block(new Block("Explanation", "No handler could be found for the page '$h_pagename'"));
- }
+class Handle404 extends SimpleExtension {
+ public function onPageRequest(PageRequestEvent $event) {
+ global $page;
+ // hax.
+ if($page->mode == "page" && (!isset($page->blocks) || $this->count_main($page->blocks) == 0)) {
+ $h_pagename = html_escape(implode('/', $event->args));
+ header("HTTP/1.0 404 Page Not Found");
+ log_debug("handle_404", "Hit 404: $h_pagename");
+ $page->set_title("404");
+ $page->set_heading("404 - No Handler Found");
+ $page->add_block(new NavBlock());
+ $page->add_block(new Block("Explanation", "No handler could be found for the page '$h_pagename'"));
}
}
@@ -32,6 +30,7 @@ class Handle404 implements Extension {
}
return $n;
}
+
+ public function get_priority() {return 99;}
}
-add_event_listener(new Handle404(), 99); // hax++
?>
diff --git a/ext/upgrade/main.php b/ext/upgrade/main.php
index dcadb884..30722eef 100644
--- a/ext/upgrade/main.php
+++ b/ext/upgrade/main.php
@@ -6,14 +6,8 @@
* Visibility: admin
*/
-class Upgrade implements Extension {
- public function receive_event(Event $event) {
- if($event instanceof InitExtEvent) {
- $this->do_things();
- }
- }
-
- private function do_things() {
+class Upgrade extends SimpleExtension {
+ public function onInitExt(InitExtEvent $event) {
global $config, $database;
if(!is_numeric($config->get_string("db_version"))) {
@@ -36,8 +30,6 @@ class Upgrade implements Extension {
log_info("upgrade", "Database at version 7");
}
- // TODO:
- // add column image->locked
if($config->get_int("db_version") < 8) {
// if this fails, don't try again
$config->set_int("db_version", 8);
@@ -47,6 +39,7 @@ class Upgrade implements Extension {
log_info("upgrade", "Database at version 8");
}
}
+
+ public function get_priority() {return 5;}
}
-add_event_listener(new Upgrade(), 5);
?>
diff --git a/ext/view/main.php b/ext/view/main.php
index f4da7507..f0f42ae2 100644
--- a/ext/view/main.php
+++ b/ext/view/main.php
@@ -66,17 +66,15 @@ class ImageAdminBlockBuildingEvent extends Event {
}
}
-class ViewImage implements Extension {
- var $theme;
+class ViewImage extends SimpleExtension {
+ public function onPageRequest(PageRequestEvent $event) {
+ global $page;
- public function receive_event(Event $event) {
- global $config, $database, $page, $user;
- if(is_null($this->theme)) $this->theme = get_theme_object($this);
-
- if(is_a($event, 'PageRequestEvent') && (
+ if(
$event->page_matches("post/prev") ||
$event->page_matches("post/next")
- )) {
+ ) {
+
$image_id = int_escape($event->get_arg(0));
if(isset($_GET['search'])) {
@@ -105,7 +103,7 @@ class ViewImage implements Extension {
}
}
- if(($event instanceof PageRequestEvent) && $event->page_matches("post/view")) {
+ if($event->page_matches("post/view")) {
$image_id = int_escape($event->get_arg(0));
$image = Image::by_id($image_id);
@@ -122,7 +120,7 @@ class ViewImage implements Extension {
}
}
- if(($event instanceof PageRequestEvent) && $event->page_matches("post/set")) {
+ if($event->page_matches("post/set")) {
$image_id = int_escape($_POST['image_id']);
send_event(new ImageInfoSetEvent(Image::by_id($image_id)));
@@ -131,14 +129,13 @@ class ViewImage implements Extension {
$page->set_mode("redirect");
$page->set_redirect(make_link("post/view/$image_id", $query));
}
+ }
- if($event instanceof DisplayingImageEvent) {
- $iibbe = new ImageInfoBoxBuildingEvent($event->get_image(), $user);
- send_event($iibbe);
- ksort($iibbe->parts);
- $this->theme->display_page($page, $event->get_image(), $iibbe->parts);
- }
+ public function onDisplayingImage(DisplayingImageEvent $event) {
+ $iibbe = new ImageInfoBoxBuildingEvent($event->get_image(), $user);
+ send_event($iibbe);
+ ksort($iibbe->parts);
+ $this->theme->display_page($event->get_image(), $iibbe->parts);
}
}
-add_event_listener(new ViewImage());
?>
diff --git a/ext/view/theme.php b/ext/view/theme.php
index 05d78386..62ae8204 100644
--- a/ext/view/theme.php
+++ b/ext/view/theme.php
@@ -4,7 +4,9 @@ class ViewImageTheme extends Themelet {
/*
* Build a page showing $image and some info about it
*/
- public function display_page(Page $page, Image $image, $editor_parts) {
+ public function display_page(Image $image, $editor_parts) {
+ global $page;
+
$metatags = str_replace(" ", ", ", html_escape($image->get_tag_list()));
$page->set_title("Image {$image->id}: ".html_escape($image->get_tag_list()));