Convert some Extensions to SimpleExtensions with priorities
This commit is contained in:
parent
d80ccbe497
commit
da449245de
@ -19,9 +19,8 @@
|
|||||||
* from Essex"
|
* from Essex"
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class BanWords implements Extension {
|
class BanWords extends SimpleExtension {
|
||||||
public function receive_event(Event $event) {
|
public function onInitExt(InitExtEvent $event) {
|
||||||
if($event instanceof InitExtEvent) {
|
|
||||||
global $config;
|
global $config;
|
||||||
$config->set_default_string('banned_words', "
|
$config->set_default_string('banned_words', "
|
||||||
a href=
|
a href=
|
||||||
@ -50,10 +49,10 @@ ultram
|
|||||||
very nice site
|
very nice site
|
||||||
viagra
|
viagra
|
||||||
xanax
|
xanax
|
||||||
");
|
");
|
||||||
}
|
}
|
||||||
|
|
||||||
if($event instanceof CommentPostingEvent) {
|
public function onCommentPosting(CommentPostingEvent $event) {
|
||||||
global $config;
|
global $config;
|
||||||
$banned = $config->get_string("banned_words");
|
$banned = $config->get_string("banned_words");
|
||||||
$comment = strtolower($event->comment);
|
$comment = strtolower($event->comment);
|
||||||
@ -79,13 +78,13 @@ xanax
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if($event instanceof SetupBuildingEvent) {
|
public function onSetupBuilding(SetupBuildingEvent $event) {
|
||||||
$sb = new SetupBlock("Banned Phrases");
|
$sb = new SetupBlock("Banned Phrases");
|
||||||
$sb->add_label("One per line, lines that start with slashes are treated as regex<br/>");
|
$sb->add_label("One per line, lines that start with slashes are treated as regex<br/>");
|
||||||
$sb->add_longtext_option("banned_words");
|
$sb->add_longtext_option("banned_words");
|
||||||
$event->panel->add_block($sb);
|
$event->panel->add_block($sb);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
public function get_priority() {return 30;}
|
||||||
}
|
}
|
||||||
add_event_listener(new BanWords(), 30); // before the comment is added
|
|
||||||
?>
|
?>
|
||||||
|
@ -30,19 +30,21 @@ class AddImageHashBanEvent extends Event {
|
|||||||
}
|
}
|
||||||
// }}}
|
// }}}
|
||||||
class ImageBan implements Extension {
|
class ImageBan implements Extension {
|
||||||
var $theme;
|
public function onInitExt(InitExtEvent $event) {
|
||||||
|
global $config, $database;
|
||||||
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 InitExtEvent) {
|
|
||||||
if($config->get_int("ext_imageban_version") < 1) {
|
if($config->get_int("ext_imageban_version") < 1) {
|
||||||
$this->install();
|
$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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if($event instanceof DataUploadEvent) {
|
public function onDataUpload(DataUploadEvent $event) {
|
||||||
|
global $database;
|
||||||
$row = $database->db->GetRow("SELECT * FROM image_bans WHERE hash = ?", $event->hash);
|
$row = $database->db->GetRow("SELECT * FROM image_bans WHERE hash = ?", $event->hash);
|
||||||
if($row) {
|
if($row) {
|
||||||
log_info("image_hash_ban", "Blocked image ({$event->hash})");
|
log_info("image_hash_ban", "Blocked image ({$event->hash})");
|
||||||
@ -50,7 +52,10 @@ class ImageBan implements Extension {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(($event instanceof PageRequestEvent) && $event->page_matches("image_hash_ban")) {
|
public function onPageRequest(PageRequestEvent $event) {
|
||||||
|
global $config, $database, $page, $user;
|
||||||
|
|
||||||
|
if($event->page_matches("image_hash_ban")) {
|
||||||
if($user->is_admin()) {
|
if($user->is_admin()) {
|
||||||
if($event->get_arg(0) == "add") {
|
if($event->get_arg(0) == "add") {
|
||||||
if(isset($_POST['hash']) && isset($_POST['reason'])) {
|
if(isset($_POST['hash']) && isset($_POST['reason'])) {
|
||||||
@ -87,39 +92,29 @@ class ImageBan implements Extension {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if($event instanceof UserBlockBuildingEvent) {
|
public function onUserBlockBuilding(UserBlockBuildingEvent $event) {
|
||||||
|
global $user;
|
||||||
if($user->is_admin()) {
|
if($user->is_admin()) {
|
||||||
$event->add_link("Image Bans", make_link("image_hash_ban/list/1"));
|
$event->add_link("Image Bans", make_link("image_hash_ban/list/1"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if($event instanceof AddImageHashBanEvent) {
|
public function onAddImageHashBan(AddImageHashBanEvent $event) {
|
||||||
$this->add_image_hash_ban($event->hash, $event->reason);
|
$this->add_image_hash_ban($event->hash, $event->reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
if($event instanceof RemoveImageHashBanEvent) {
|
public function onRemoveImageHashBan(RemoveImageHashBanEvent $event) {
|
||||||
$this->remove_image_hash_ban($event->hash);
|
$this->remove_image_hash_ban($event->hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
if($event instanceof ImageAdminBlockBuildingEvent) {
|
public function onImageAdminBlockBuilding(ImageAdminBlockBuildingEvent $event) {
|
||||||
|
global $user;
|
||||||
if($user->is_admin()) {
|
if($user->is_admin()) {
|
||||||
$event->add_part($this->theme->get_buttons_html($event->image));
|
$event->add_part($this->theme->get_buttons_html($event->image));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
// DB funness
|
// DB funness
|
||||||
|
|
||||||
@ -145,6 +140,7 @@ class ImageBan implements Extension {
|
|||||||
$database->Execute("DELETE FROM image_bans WHERE hash = ?", array($hash));
|
$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
|
|
||||||
?>
|
?>
|
||||||
|
@ -8,9 +8,8 @@
|
|||||||
* Description: Shows an error message when the user views a page with no content
|
* Description: Shows an error message when the user views a page with no content
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class Handle404 implements Extension {
|
class Handle404 extends SimpleExtension {
|
||||||
public function receive_event(Event $event) {
|
public function onPageRequest(PageRequestEvent $event) {
|
||||||
if($event instanceof PageRequestEvent) {
|
|
||||||
global $page;
|
global $page;
|
||||||
// hax.
|
// hax.
|
||||||
if($page->mode == "page" && (!isset($page->blocks) || $this->count_main($page->blocks) == 0)) {
|
if($page->mode == "page" && (!isset($page->blocks) || $this->count_main($page->blocks) == 0)) {
|
||||||
@ -23,7 +22,6 @@ class Handle404 implements Extension {
|
|||||||
$page->add_block(new Block("Explanation", "No handler could be found for the page '$h_pagename'"));
|
$page->add_block(new Block("Explanation", "No handler could be found for the page '$h_pagename'"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private function count_main($blocks) {
|
private function count_main($blocks) {
|
||||||
$n = 0;
|
$n = 0;
|
||||||
@ -32,6 +30,7 @@ class Handle404 implements Extension {
|
|||||||
}
|
}
|
||||||
return $n;
|
return $n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function get_priority() {return 99;}
|
||||||
}
|
}
|
||||||
add_event_listener(new Handle404(), 99); // hax++
|
|
||||||
?>
|
?>
|
||||||
|
@ -6,14 +6,8 @@
|
|||||||
* Visibility: admin
|
* Visibility: admin
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class Upgrade implements Extension {
|
class Upgrade extends SimpleExtension {
|
||||||
public function receive_event(Event $event) {
|
public function onInitExt(InitExtEvent $event) {
|
||||||
if($event instanceof InitExtEvent) {
|
|
||||||
$this->do_things();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private function do_things() {
|
|
||||||
global $config, $database;
|
global $config, $database;
|
||||||
|
|
||||||
if(!is_numeric($config->get_string("db_version"))) {
|
if(!is_numeric($config->get_string("db_version"))) {
|
||||||
@ -36,8 +30,6 @@ class Upgrade implements Extension {
|
|||||||
log_info("upgrade", "Database at version 7");
|
log_info("upgrade", "Database at version 7");
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO:
|
|
||||||
// add column image->locked
|
|
||||||
if($config->get_int("db_version") < 8) {
|
if($config->get_int("db_version") < 8) {
|
||||||
// if this fails, don't try again
|
// if this fails, don't try again
|
||||||
$config->set_int("db_version", 8);
|
$config->set_int("db_version", 8);
|
||||||
@ -47,6 +39,7 @@ class Upgrade implements Extension {
|
|||||||
log_info("upgrade", "Database at version 8");
|
log_info("upgrade", "Database at version 8");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function get_priority() {return 5;}
|
||||||
}
|
}
|
||||||
add_event_listener(new Upgrade(), 5);
|
|
||||||
?>
|
?>
|
||||||
|
@ -66,17 +66,15 @@ class ImageAdminBlockBuildingEvent extends Event {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class ViewImage implements Extension {
|
class ViewImage extends SimpleExtension {
|
||||||
var $theme;
|
public function onPageRequest(PageRequestEvent $event) {
|
||||||
|
global $page;
|
||||||
|
|
||||||
public function receive_event(Event $event) {
|
if(
|
||||||
global $config, $database, $page, $user;
|
|
||||||
if(is_null($this->theme)) $this->theme = get_theme_object($this);
|
|
||||||
|
|
||||||
if(is_a($event, 'PageRequestEvent') && (
|
|
||||||
$event->page_matches("post/prev") ||
|
$event->page_matches("post/prev") ||
|
||||||
$event->page_matches("post/next")
|
$event->page_matches("post/next")
|
||||||
)) {
|
) {
|
||||||
|
|
||||||
$image_id = int_escape($event->get_arg(0));
|
$image_id = int_escape($event->get_arg(0));
|
||||||
|
|
||||||
if(isset($_GET['search'])) {
|
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_id = int_escape($event->get_arg(0));
|
||||||
|
|
||||||
$image = Image::by_id($image_id);
|
$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']);
|
$image_id = int_escape($_POST['image_id']);
|
||||||
|
|
||||||
send_event(new ImageInfoSetEvent(Image::by_id($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_mode("redirect");
|
||||||
$page->set_redirect(make_link("post/view/$image_id", $query));
|
$page->set_redirect(make_link("post/view/$image_id", $query));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if($event instanceof DisplayingImageEvent) {
|
public function onDisplayingImage(DisplayingImageEvent $event) {
|
||||||
$iibbe = new ImageInfoBoxBuildingEvent($event->get_image(), $user);
|
$iibbe = new ImageInfoBoxBuildingEvent($event->get_image(), $user);
|
||||||
send_event($iibbe);
|
send_event($iibbe);
|
||||||
ksort($iibbe->parts);
|
ksort($iibbe->parts);
|
||||||
$this->theme->display_page($page, $event->get_image(), $iibbe->parts);
|
$this->theme->display_page($event->get_image(), $iibbe->parts);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
add_event_listener(new ViewImage());
|
|
||||||
?>
|
?>
|
||||||
|
@ -4,7 +4,9 @@ class ViewImageTheme extends Themelet {
|
|||||||
/*
|
/*
|
||||||
* Build a page showing $image and some info about it
|
* 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()));
|
$metatags = str_replace(" ", ", ", html_escape($image->get_tag_list()));
|
||||||
|
|
||||||
$page->set_title("Image {$image->id}: ".html_escape($image->get_tag_list()));
|
$page->set_title("Image {$image->id}: ".html_escape($image->get_tag_list()));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user