From 18d6fa317c54363e3eb8bfed657ab771a5611201 Mon Sep 17 00:00:00 2001 From: Shish Date: Mon, 30 Jan 2012 03:22:41 +0000 Subject: [PATCH 1/3] adminpage -> simpleext --- contrib/admin/main.php | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/contrib/admin/main.php b/contrib/admin/main.php index c099b066..64298022 100644 --- a/contrib/admin/main.php +++ b/contrib/admin/main.php @@ -35,16 +35,11 @@ class AdminBuildingEvent extends Event { } } -class AdminPage implements Extension { - var $theme; +class AdminPage extends SimpleExtension { + public function onPageRequest($event) { + global $page, $user; - public function get_priority() {return 50;} - - public function receive_event(Event $event) { - global $config, $database, $page, $user; - if(is_null($this->theme)) $this->theme = get_theme_object($this); - - if(($event instanceof PageRequestEvent) && $event->page_matches("admin")) { + if($event->page_matches("admin")) { if(!$user->is_admin()) { $this->theme->display_permission_denied($page); } @@ -53,7 +48,7 @@ class AdminPage implements Extension { } } - if(($event instanceof PageRequestEvent) && $event->page_matches("admin_utils")) { + if($event->page_matches("admin_utils")) { if($user->is_admin() && $user->check_auth_token()) { log_info("admin", "Util: {$_POST['action']}"); set_time_limit(0); @@ -91,16 +86,18 @@ class AdminPage implements Extension { } } } + } - if($event instanceof AdminBuildingEvent) { - $this->theme->display_page($page); - $this->theme->display_form($page); - } + public function onAdminBuilding($event) { + global $page; + $this->theme->display_page($page); + $this->theme->display_form($page); + } - if($event instanceof UserBlockBuildingEvent) { - if($user->is_admin()) { - $event->add_link("Board Admin", make_link("admin")); - } + public function onUserBlockBuilding($event) { + global $user; + if($user->is_admin()) { + $event->add_link("Board Admin", make_link("admin")); } } From 0ea3ff5af39e1183ad13738be71cf157f4a1f831 Mon Sep 17 00:00:00 2001 From: Shish Date: Mon, 30 Jan 2012 03:39:00 +0000 Subject: [PATCH 2/3] wordfilter -> simpleext --- contrib/word_filter/main.php | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/contrib/word_filter/main.php b/contrib/word_filter/main.php index 5e4cddd2..1ce8e259 100644 --- a/contrib/word_filter/main.php +++ b/contrib/word_filter/main.php @@ -6,21 +6,20 @@ * Description: Simple search and replace */ -class WordFilter implements Extension { +class WordFilter extends SimpleExtension { // before emoticon filter public function get_priority() {return 40;} - public function receive_event(Event $event) { - if($event instanceof TextFormattingEvent) { - $event->formatted = $this->filter($event->formatted); - $event->stripped = $this->filter($event->stripped); - } - if(($event instanceof SetupBuildingEvent)) { - $sb = new SetupBlock("Word Filter"); - $sb->add_longtext_option("word_filter"); - $sb->add_label("
(each line should be search term and replace term, separated by a comma)"); - $event->panel->add_block($sb); - } + public function onTextFormatting($event) { + $event->formatted = $this->filter($event->formatted); + $event->stripped = $this->filter($event->stripped); + } + + public function onSetupBuilding($event) { + $sb = new SetupBlock("Word Filter"); + $sb->add_longtext_option("word_filter"); + $sb->add_label("
(each line should be search term and replace term, separated by a comma)"); + $event->panel->add_block($sb); } private function filter($text) { From 444fdb1f04db9033ba2c4d44b49ca8add7340f1d Mon Sep 17 00:00:00 2001 From: Shish Date: Mon, 30 Jan 2012 03:46:38 +0000 Subject: [PATCH 3/3] tag history -> simpleext --- contrib/tag_history/main.php | 149 +++++++++++++++++------------------ 1 file changed, 74 insertions(+), 75 deletions(-) diff --git a/contrib/tag_history/main.php b/contrib/tag_history/main.php index a1464323..6b6205af 100644 --- a/contrib/tag_history/main.php +++ b/contrib/tag_history/main.php @@ -5,65 +5,61 @@ * Description: Keep a record of tag changes, and allows you to revert changes. */ -class Tag_History implements Extension { - var $theme; - +class Tag_History extends SimpleExtension { // in before tags are actually set, so that "get current tags" works public function get_priority() {return 40;} - public function receive_event(Event $event) { - global $config, $database, $page, $user; - if(is_null($this->theme)) $this->theme = get_theme_object($this); + public function onInitExtEvent($event) { + global $config; + $config->set_default_int("history_limit", -1); - if(($event instanceof InitExtEvent)) { - $config->set_default_int("history_limit", -1); - - // shimmie is being installed so call install to create the table. - if($config->get_int("ext_tag_history_version") < 3) { - $this->install(); - } + // shimmie is being installed so call install to create the table. + if($config->get_int("ext_tag_history_version") < 3) { + $this->install(); } + } - if(($event instanceof AdminBuildingEvent)) - { - if(isset($_POST['revert_ip']) && $user->is_admin() && $user->check_auth_token()) - { - $revert_ip = filter_var($_POST['revert_ip'], FILTER_VALIDATE_IP, FILTER_FLAG_NO_RES_RANGE); - - if ($revert_ip === false) { - // invalid ip given. - $this->theme->display_admin_block('Invalid IP'); + public function onAdminBuildingEvent($event) { + global $user; + + if(isset($_POST['revert_ip']) && $user->is_admin() && $user->check_auth_token()) { + $revert_ip = filter_var($_POST['revert_ip'], FILTER_VALIDATE_IP, FILTER_FLAG_NO_RES_RANGE); + + if ($revert_ip === false) { + // invalid ip given. + $this->theme->display_admin_block('Invalid IP'); + return; + } + + if (isset($_POST['revert_date']) && !empty($_POST['revert_date'])) { + if (isValidDate($_POST['revert_date'])){ + $revert_date = addslashes($_POST['revert_date']); // addslashes is really unnecessary since we just checked if valid, but better safe. + } else { + $this->theme->display_admin_block('Invalid Date'); return; } - - if (isset($_POST['revert_date']) && !empty($_POST['revert_date'])) { - if (isValidDate($_POST['revert_date'])){ - $revert_date = addslashes($_POST['revert_date']); // addslashes is really unnecessary since we just checked if valid, but better safe. - } else { - $this->theme->display_admin_block('Invalid Date'); - return; - } - } else { - $revert_date = null; - } - - set_time_limit(0); // reverting changes can take a long time, disable php's timelimit if possible. - - // Call the revert function. - $this->process_revert_all_changes_by_ip($revert_ip, $revert_date); - // output results - $this->theme->display_revert_ip_results(); } - else - { - $this->theme->display_admin_block(); // add a block to the admin panel + else { + $revert_date = null; } + + set_time_limit(0); // reverting changes can take a long time, disable php's timelimit if possible. + + // Call the revert function. + $this->process_revert_all_changes_by_ip($revert_ip, $revert_date); + // output results + $this->theme->display_revert_ip_results(); } + else { + $this->theme->display_admin_block(); // add a block to the admin panel + } + } - if (($event instanceof PageRequestEvent) && ($event->page_matches("tag_history"))) - { - if($event->get_arg(0) == "revert") - { + public function onPageRequest($event) { + global $config, $page; + + if ($event->page_matches("tag_history")) { + if($event->get_arg(0) == "revert") { // this is a request to revert to a previous version of the tags if($config->get_bool("tag_edit_anon") || !$user->is_anonymous()) { if(isset($_POST['revert'])) { @@ -71,8 +67,7 @@ class Tag_History implements Extension { } } } - else if($event->count_args() == 1) - { + else if($event->count_args() == 1) { // must be an attempt to view a tag history $image_id = int_escape($event->get_arg(0)); $this->theme->display_history_page($page, $image_id, $this->get_tag_history_from_id($image_id)); @@ -81,32 +76,36 @@ class Tag_History implements Extension { $this->theme->display_global_page($page, $this->get_global_tag_history()); } } - - if(($event instanceof DisplayingImageEvent)) - { - // handle displaying a link on the view page - $this->theme->display_history_link($page, $event->image->id); - } - if(($event instanceof ImageDeletionEvent)) - { - // handle removing of history when an image is deleted - $this->delete_all_tag_history($event->image->id); - } - if(($event instanceof SetupBuildingEvent)) { - $sb = new SetupBlock("Tag History"); - $sb->add_label("Limit to "); - $sb->add_int_option("history_limit"); - $sb->add_label(" entires per image"); - $sb->add_label("
(-1 for unlimited)"); - $event->panel->add_block($sb); - } - if(($event instanceof TagSetEvent)) { - $this->add_tag_history($event->image, $event->tags); - } - if($event instanceof UserBlockBuildingEvent) { - if($user->is_admin()) { - $event->add_link("Tag Changes", make_link("tag_history")); - } + } + + public function onDisplayingImage($event) { + global $page; + // handle displaying a link on the view page + $this->theme->display_history_link($page, $event->image->id); + } + + public function onImageDeletion($event) { + // handle removing of history when an image is deleted + $this->delete_all_tag_history($event->image->id); + } + + public function onSetupBuilding($event) { + $sb = new SetupBlock("Tag History"); + $sb->add_label("Limit to "); + $sb->add_int_option("history_limit"); + $sb->add_label(" entires per image"); + $sb->add_label("
(-1 for unlimited)"); + $event->panel->add_block($sb); + } + + public function onTagSetEvent($event) { + $this->add_tag_history($event->image, $event->tags); + } + + public function onUserBlockBuilding($event) { + global $user; + if($user->is_admin()) { + $event->add_link("Tag Changes", make_link("tag_history")); } }