image_hash_ban whitespacing

git-svn-id: file:///home/shish/svn/shimmie2/trunk@759 7f39781d-f577-437e-ae19-be835c7a54ca
This commit is contained in:
shish 2008-04-06 16:47:05 +00:00
parent 7db7096b2e
commit 52639e6c3a

View file

@ -34,15 +34,13 @@ class Image_Hash_Ban extends Extension {
var $theme; var $theme;
public function receive_event($event) { public function receive_event($event) {
if(is_null($this->theme)) $this->theme = get_theme_object("Image_Hash_Ban", "ImageBanTheme");
if(is_null($this->theme)) $this->theme = get_theme_object("Image_Hash_Ban", "ImageBanTheme"); if(is_a($event, 'InitExtEvent')) {
if(is_a($event, 'InitExtEvent')) {
global $config; global $config;
if($config->get_int("ext_imageban_version") < 1) { if($config->get_int("ext_imageban_version") < 1) {
$this->install(); $this->install();
} }
} }
if(is_a($event, 'DataUploadEvent')) { if(is_a($event, 'DataUploadEvent')) {
@ -52,14 +50,12 @@ class Image_Hash_Ban extends Extension {
$tmp_hash = $image->hash; $tmp_hash = $image->hash;
if ($database->db->GetOne("SELECT COUNT(*) FROM image_bans WHERE hash = ?", $tmp_hash) == 1) { if ($database->db->GetOne("SELECT COUNT(*) FROM image_bans WHERE hash = ?", $tmp_hash) == 1) {
$event->veto("This image has been banned!"); $event->veto("This image has been banned!");
} }
} }
if(is_a($event, 'PageRequestEvent') && ($event->page_name == "image_hash_ban")) { if(is_a($event, 'PageRequestEvent') && ($event->page_name == "image_hash_ban")) {
global $user; if($event->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'])) {
send_event(new AddImageHashBanEvent($_POST['hash'], $_POST['reason'])); send_event(new AddImageHashBanEvent($_POST['hash'], $_POST['reason']));
@ -67,7 +63,6 @@ class Image_Hash_Ban extends Extension {
global $page; global $page;
$page->set_mode("redirect"); $page->set_mode("redirect");
$page->set_redirect(make_link("admin")); $page->set_redirect(make_link("admin"));
} }
} }
else if($event->get_arg(0) == "remove") { else if($event->get_arg(0) == "remove") {
@ -87,7 +82,7 @@ class Image_Hash_Ban extends Extension {
$this->theme->display_Image_hash_Bans($page, $this->get_image_hash_bans()); $this->theme->display_Image_hash_Bans($page, $this->get_image_hash_bans());
} }
if(is_a($event, 'AddImageHashBanEvent')) { if(is_a($event, 'AddImageHashBanEvent')) {
$this->add_image_hash_ban($event->hash, $event->reason); $this->add_image_hash_ban($event->hash, $event->reason);
} }
@ -95,15 +90,12 @@ class Image_Hash_Ban extends Extension {
$this->remove_image_hash_ban($event->hash); $this->remove_image_hash_ban($event->hash);
} }
if(is_a($event, 'DisplayingImageEvent')) { if(is_a($event, 'DisplayingImageEvent')) {
global $user; global $user;
if($user->is_admin()) { if($user->is_admin()) {
$this->theme->display_image_banner($event->page, $event->image->hash); $this->theme->display_image_banner($event->page, $event->image->hash);
} }
} }
} }
protected function install() { protected function install() {
@ -111,30 +103,22 @@ class Image_Hash_Ban extends Extension {
global $config; global $config;
$database->Execute("CREATE TABLE image_bans ( $database->Execute("CREATE TABLE image_bans (
id int(11) NOT NULL auto_increment, id int(11) NOT NULL auto_increment,
hash char(32) default NULL, hash char(32) default NULL,
date datetime default NULL, date datetime default NULL,
reason varchar(255) default NULL, reason varchar(255) default NULL,
PRIMARY KEY (id) PRIMARY KEY (id)
)"); )");
$config->set_int("ext_imageban_version", 1); $config->set_int("ext_imageban_version", 1);
} }
// DB funness // DB funness
public function get_image_hash_bans() { public function get_image_hash_bans() {
// FIXME: many // FIXME: many
global $database; global $database;
$bans = $database->get_all("SELECT * FROM image_bans"); $bans = $database->get_all("SELECT * FROM image_bans");
if($bans) {return $bans;} if($bans) {return $bans;}
else {return array();} else {return array();}
}
public function get_image_hash_ban($hash) {
global $database;
// yes, this is "? LIKE var", because ? is the thing with matching tokens
// actually, slow
// return $database->db->GetRow("SELECT * FROM bans WHERE ? LIKE ip AND date < now() AND (end > now() OR isnull(end))", array($ip));
return $database->db->GetRow("SELECT * FROM image_bans WHERE hash = ? AND date < now()", array($hash));
} }
public function add_image_hash_ban($hash, $reason) { public function add_image_hash_ban($hash, $reason) {