2007-10-22 00:13:57 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Name: Image Hash Ban
|
2007-12-04 18:20:46 +00:00
|
|
|
* Author: ATravelingGeek <atg@atravelinggeek.com>
|
2007-10-22 00:13:57 +00:00
|
|
|
* Link: http://atravelinggeek.com/
|
|
|
|
* License: GPLv2
|
|
|
|
* Description: Ban images based on their hash
|
|
|
|
* Based on the ResolutionLimit and IPban extensions by Shish
|
|
|
|
* Version 0.1
|
|
|
|
* October 21, 2007
|
|
|
|
*/
|
|
|
|
|
|
|
|
// RemoveImageHashBanEvent {{{
|
|
|
|
class RemoveImageHashBanEvent extends Event {
|
|
|
|
var $hash;
|
|
|
|
|
|
|
|
public function RemoveImageHashBanEvent($hash) {
|
|
|
|
$this->hash = $hash;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// }}}
|
|
|
|
// AddImageHashBanEvent {{{
|
|
|
|
class AddImageHashBanEvent extends Event {
|
|
|
|
var $hash;
|
|
|
|
var $reason;
|
|
|
|
|
|
|
|
public function AddImageHashBanEvent($hash, $reason) {
|
|
|
|
$this->hash = $hash;
|
|
|
|
$this->reason = $reason;
|
|
|
|
}
|
|
|
|
}
|
2008-04-06 16:43:09 +00:00
|
|
|
// }}}
|
2007-10-22 00:13:57 +00:00
|
|
|
class Image_Hash_Ban extends Extension {
|
2008-04-06 16:43:09 +00:00
|
|
|
var $theme;
|
|
|
|
|
2007-10-22 00:13:57 +00:00
|
|
|
public function receive_event($event) {
|
2008-04-06 16:47:05 +00:00
|
|
|
if(is_null($this->theme)) $this->theme = get_theme_object("Image_Hash_Ban", "ImageBanTheme");
|
|
|
|
|
|
|
|
if(is_a($event, 'InitExtEvent')) {
|
2007-10-22 00:13:57 +00:00
|
|
|
global $config;
|
|
|
|
if($config->get_int("ext_imageban_version") < 1) {
|
|
|
|
$this->install();
|
|
|
|
}
|
|
|
|
}
|
2008-04-06 16:47:05 +00:00
|
|
|
|
2008-04-04 22:41:45 +00:00
|
|
|
if(is_a($event, 'DataUploadEvent')) {
|
|
|
|
global $database;
|
2008-04-06 16:47:05 +00:00
|
|
|
|
2007-10-22 00:13:57 +00:00
|
|
|
$image = $event->image;
|
|
|
|
$tmp_hash = $image->hash;
|
2008-04-06 16:47:05 +00:00
|
|
|
|
2007-10-22 00:13:57 +00:00
|
|
|
if ($database->db->GetOne("SELECT COUNT(*) FROM image_bans WHERE hash = ?", $tmp_hash) == 1) {
|
2008-04-06 16:47:05 +00:00
|
|
|
$event->veto("This image has been banned!");
|
2008-04-04 22:41:45 +00:00
|
|
|
}
|
2007-10-22 00:13:57 +00:00
|
|
|
}
|
2008-04-06 16:47:05 +00:00
|
|
|
|
2007-10-22 00:13:57 +00:00
|
|
|
if(is_a($event, 'PageRequestEvent') && ($event->page_name == "image_hash_ban")) {
|
2008-04-06 16:47:05 +00:00
|
|
|
if($event->user->is_admin()) {
|
2007-10-22 00:13:57 +00:00
|
|
|
if($event->get_arg(0) == "add") {
|
|
|
|
if(isset($_POST['hash']) && isset($_POST['reason'])) {
|
|
|
|
send_event(new AddImageHashBanEvent($_POST['hash'], $_POST['reason']));
|
|
|
|
|
|
|
|
global $page;
|
|
|
|
$page->set_mode("redirect");
|
|
|
|
$page->set_redirect(make_link("admin"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if($event->get_arg(0) == "remove") {
|
|
|
|
if(isset($_POST['hash'])) {
|
|
|
|
send_event(new RemoveImageHashBanEvent($_POST['hash']));
|
|
|
|
|
|
|
|
global $page;
|
|
|
|
$page->set_mode("redirect");
|
|
|
|
$page->set_redirect(make_link("admin"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-04-06 16:47:05 +00:00
|
|
|
|
2007-10-22 00:13:57 +00:00
|
|
|
if(is_a($event, 'AdminBuildingEvent')) {
|
|
|
|
global $page;
|
|
|
|
$this->theme->display_Image_hash_Bans($page, $this->get_image_hash_bans());
|
|
|
|
}
|
2008-04-06 16:47:05 +00:00
|
|
|
|
|
|
|
if(is_a($event, 'AddImageHashBanEvent')) {
|
2007-10-22 00:13:57 +00:00
|
|
|
$this->add_image_hash_ban($event->hash, $event->reason);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(is_a($event, 'RemoveImageHashBanEvent')) {
|
|
|
|
$this->remove_image_hash_ban($event->hash);
|
|
|
|
}
|
2008-04-06 16:47:05 +00:00
|
|
|
|
|
|
|
if(is_a($event, 'DisplayingImageEvent')) {
|
2007-10-22 00:13:57 +00:00
|
|
|
global $user;
|
|
|
|
if($user->is_admin()) {
|
|
|
|
$this->theme->display_image_banner($event->page, $event->image->hash);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-04-06 16:47:05 +00:00
|
|
|
|
2007-10-22 00:13:57 +00:00
|
|
|
protected function install() {
|
|
|
|
global $database;
|
|
|
|
global $config;
|
|
|
|
$database->Execute("CREATE TABLE image_bans (
|
|
|
|
id int(11) NOT NULL auto_increment,
|
2008-04-06 16:47:05 +00:00
|
|
|
hash char(32) default NULL,
|
|
|
|
date datetime default NULL,
|
|
|
|
reason varchar(255) default NULL,
|
|
|
|
PRIMARY KEY (id)
|
|
|
|
)");
|
2007-10-22 00:13:57 +00:00
|
|
|
$config->set_int("ext_imageban_version", 1);
|
|
|
|
}
|
2008-04-06 16:47:05 +00:00
|
|
|
|
2007-10-22 00:13:57 +00:00
|
|
|
// DB funness
|
2008-04-06 16:47:05 +00:00
|
|
|
|
|
|
|
public function get_image_hash_bans() {
|
2007-10-22 00:13:57 +00:00
|
|
|
// FIXME: many
|
|
|
|
global $database;
|
2008-01-05 00:22:19 +00:00
|
|
|
$bans = $database->get_all("SELECT * FROM image_bans");
|
2007-10-22 00:13:57 +00:00
|
|
|
if($bans) {return $bans;}
|
|
|
|
else {return array();}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function add_image_hash_ban($hash, $reason) {
|
|
|
|
global $database;
|
|
|
|
$database->Execute(
|
|
|
|
"INSERT INTO image_bans (hash, reason, date) VALUES (?, ?, now())",
|
|
|
|
array($hash, $reason));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function remove_image_hash_ban($hash) {
|
|
|
|
global $database;
|
|
|
|
$database->Execute("DELETE FROM image_bans WHERE hash = ?", array($hash));
|
|
|
|
}
|
2008-04-06 16:47:05 +00:00
|
|
|
|
2007-10-22 00:13:57 +00:00
|
|
|
}
|
|
|
|
add_event_listener(new Image_Hash_Ban(), 30); // in before resolution limit plugin
|
2007-12-04 18:20:46 +00:00
|
|
|
?>
|