Initial version of report_image extention
git-svn-id: file:///home/shish/svn/shimmie2/trunk@568 7f39781d-f577-437e-ae19-be835c7a54ca
This commit is contained in:
parent
917609636e
commit
e4e9c34297
151
contrib/report_image/main.php
Executable file
151
contrib/report_image/main.php
Executable file
@ -0,0 +1,151 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Name: Report Images
|
||||||
|
* Author: ATravelingGeek (atg@atravelinggeek.com
|
||||||
|
* Link: http://atravelinggeek.com/
|
||||||
|
* License: GPLv2
|
||||||
|
* Description: Report images as dupes/illegal/etc
|
||||||
|
* Version 0.1
|
||||||
|
* October 23, 2007
|
||||||
|
*/
|
||||||
|
|
||||||
|
class RemoveReportedImageEvent extends Event {
|
||||||
|
var $id;
|
||||||
|
|
||||||
|
public function RemoveReportedImageEvent($id) {
|
||||||
|
$this->id = $id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class AddReportedImageEvent extends Event {
|
||||||
|
var $reporter_name;
|
||||||
|
var $image_id;
|
||||||
|
var $reason_type;
|
||||||
|
var $reason;
|
||||||
|
public function AddReportedImageEvent($image_id, $reporter_name, $reason_type, $reason) {
|
||||||
|
$this->reporter_name = $reporter_name;
|
||||||
|
$this->image_id = $image_id;
|
||||||
|
$this->reason_type = $reason_type;
|
||||||
|
$this->reason = $reason;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class ReportImage extends Extension {
|
||||||
|
public function receive_event($event) {
|
||||||
|
|
||||||
|
if(is_null($this->theme)) $this->theme = get_theme_object("ReportImage", "ReportImageTheme");
|
||||||
|
|
||||||
|
if(is_a($event, 'InitExtEvent')) {
|
||||||
|
global $config;
|
||||||
|
if($config->get_int("ext_ReportImage_version") < 2) {
|
||||||
|
$this->install();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(is_a($event, 'PageRequestEvent') && ($event->page_name == "ReportImage")) {
|
||||||
|
global $user;
|
||||||
|
if($event->get_arg(0) == "add") {
|
||||||
|
if(isset($_POST['image_id']) && isset($_POST['reason_type']) && isset($_POST['reason'])) {
|
||||||
|
send_event(new AddReportedImageEvent($_POST['image_id'], $event->user->name, $_POST['reason_type'], $_POST['reason']));
|
||||||
|
global $page;
|
||||||
|
$page->set_mode("redirect");
|
||||||
|
$page->set_redirect(make_link("post/view/".int_escape($_POST['image_id'])));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if($event->get_arg(0) == "remove") {
|
||||||
|
if(isset($_POST['id'])) {
|
||||||
|
send_event(new RemoveReportedImageEvent($_POST['id']));
|
||||||
|
global $page;
|
||||||
|
$page->set_mode("redirect");
|
||||||
|
$page->set_redirect(make_link("admin"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(is_a($event, 'AdminBuildingEvent')) {
|
||||||
|
global $page;
|
||||||
|
$this->theme->display_reported_images($page, $this->get_reported_images());
|
||||||
|
}
|
||||||
|
|
||||||
|
if(is_a($event, 'AddReportedImageEvent')) {
|
||||||
|
$this->add_reported_image($event->image_id, $event->reporter_name, $event->reason_type, $event->reason);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(is_a($event, 'RemoveReportedImageEvent')) {
|
||||||
|
$this->remove_reported_image($event->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(is_a($event, 'DisplayingImageEvent')) {
|
||||||
|
global $user;
|
||||||
|
global $config;
|
||||||
|
if(!$config->get_bool('report_image_anon') && $user->is_anonymous()) {
|
||||||
|
// Show nothing
|
||||||
|
} else {
|
||||||
|
$this->theme->display_image_banner($event->page, $event->image->id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(is_a($event, 'SetupBuildingEvent')) {
|
||||||
|
$sb = new SetupBlock("Report Image Options");
|
||||||
|
$sb->add_bool_option("report_image_anon", "Allow anonymous image reporting: ");
|
||||||
|
// I'll add this feature in soonish if anyone wants it.
|
||||||
|
// $sb->add_label("<br>");
|
||||||
|
// $sb->add_bool_option("report_image_sgow_thumbs", "Show thumbnails in admin panel: ");
|
||||||
|
$event->panel->add_block($sb);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function install() {
|
||||||
|
global $database;
|
||||||
|
global $config;
|
||||||
|
if($config->get_int("ext_ReportImage_version") < 1) {
|
||||||
|
$database->Execute("CREATE TABLE ReportImage (
|
||||||
|
id int(11) NOT NULL auto_increment,
|
||||||
|
image_id int(11) default NULL,
|
||||||
|
reporter_name int(11) default NULL,
|
||||||
|
reason_type varchar(255) default NULL,
|
||||||
|
reason varchar(255) default NULL,
|
||||||
|
PRIMARY KEY (id)
|
||||||
|
)");
|
||||||
|
$config->set_int("ext_ReportImage_version", 1);
|
||||||
|
}
|
||||||
|
if($config->get_int("ext_ReportImage_version") < 2) {
|
||||||
|
$database->Execute("ALTER TABLE `reportimage`
|
||||||
|
CHANGE `reporter_id` `reporter_name` VARCHAR( 32 ) NULL DEFAULT NULL
|
||||||
|
");
|
||||||
|
$config->set_int("ext_ReportImage_version", 2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// DB funness
|
||||||
|
|
||||||
|
public function get_reported_images() {
|
||||||
|
// FIXME: many
|
||||||
|
global $database;
|
||||||
|
$reportedimages = $database->db->GetAll("SELECT * FROM ReportImage");
|
||||||
|
if($reportedimages) {return $reportedimages;}
|
||||||
|
else {return array();}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_reported_image($id) {
|
||||||
|
global $database;
|
||||||
|
return $database->db->GetRow("SELECT * FROM ReportImage WHERE id = ?", array($id));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function add_reported_image($image_id, $reporter_name, $reason_type, $reason) {
|
||||||
|
global $database;
|
||||||
|
$database->Execute(
|
||||||
|
"INSERT INTO ReportImage (image_id, reporter_name, reason_type, reason) VALUES (?, ?, ?, ?)",
|
||||||
|
array($image_id, $reporter_name, $reason_type, $reason));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function remove_reported_image($id) {
|
||||||
|
global $database;
|
||||||
|
$database->Execute("DELETE FROM ReportImage WHERE id = ?", array($id));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
add_event_listener(new ReportImage(), 29); // Not sure what I'm in before.
|
||||||
|
?>
|
37
contrib/report_image/report_image.js
Executable file
37
contrib/report_image/report_image.js
Executable file
@ -0,0 +1,37 @@
|
|||||||
|
/*
|
||||||
|
* Name: Report Images
|
||||||
|
* Author: ATravelingGeek (atg@atravelinggeek.com
|
||||||
|
* Link: http://atravelinggeek.com/
|
||||||
|
* License: GPLv2
|
||||||
|
* Description: Report images as dupes/illegal/etc
|
||||||
|
* Version 0.2
|
||||||
|
* October 24, 2007
|
||||||
|
*/
|
||||||
|
|
||||||
|
function validate_report()
|
||||||
|
{
|
||||||
|
if(document.ReportImage.reason_type.value=="Select a reason...") {
|
||||||
|
alert("Please select a reason!");
|
||||||
|
document.ReportImage.reason_type.focus();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(document.ReportImage.reason.value == "Please enter a reason" || document.ReportImage.reason.value == '' || document.ReportImage.reason.value == "Please enter the Image ID") {
|
||||||
|
alert("Please enter a reason!");
|
||||||
|
document.ReportImage.reason.focus();
|
||||||
|
document.ReportImage.reason.select();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function change_reason()
|
||||||
|
{
|
||||||
|
if(document.ReportImage.reason_type.value == "Duplicate"){
|
||||||
|
document.ReportImage.reason.value = "Enter the Image ID";
|
||||||
|
} else {
|
||||||
|
document.ReportImage.reason.value = "Please enter a reason";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
84
contrib/report_image/theme.php
Executable file
84
contrib/report_image/theme.php
Executable file
@ -0,0 +1,84 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Name: Report Images
|
||||||
|
* Author: ATravelingGeek (atg@atravelinggeek.com
|
||||||
|
* Link: http://atravelinggeek.com/
|
||||||
|
* License: GPLv2
|
||||||
|
* Description: Report images as dupes/illegal/etc
|
||||||
|
* Version 0.2
|
||||||
|
* October 24, 2007
|
||||||
|
*/
|
||||||
|
|
||||||
|
class ReportImageTheme extends Themelet {
|
||||||
|
public function display_reported_images($page, $reportedimages) {
|
||||||
|
$h_reportedimages = "";
|
||||||
|
foreach($reportedimages as $reportedimage) {
|
||||||
|
// If the reason is 'Duplicate' make the 'reason' field a link to the reported image
|
||||||
|
if ($reportedimage['reason_type'] == "Duplicate")
|
||||||
|
{
|
||||||
|
$reason = "<a href=\"".make_link("post/view/{$reportedimage['reason']}")."\">".$reportedimage['reason']."</a>";
|
||||||
|
} else {
|
||||||
|
$reason = $reportedimage['reason'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$image_link = "<a href=\"".make_link("post/view/{$reportedimage['image_id']}")."\">".$reportedimage['image_id']."</a>";
|
||||||
|
$userlink = "<a href='".make_link("user/{$reportedimage['reporter_name']}")."'>{$reportedimage['reporter_name']}</a>";
|
||||||
|
|
||||||
|
$h_reportedimages .= "
|
||||||
|
<tr>
|
||||||
|
<td>{$image_link}</td>
|
||||||
|
<td>{$userlink}</td>
|
||||||
|
<td>{$reportedimage['reason_type']}</td>
|
||||||
|
<td>{$reason}</td>
|
||||||
|
<td>
|
||||||
|
<form action='".make_link("ReportImage/remove")."' method='POST'>
|
||||||
|
<input type='hidden' name='id' value='{$reportedimage['id']}'>
|
||||||
|
<input type='submit' value='Remove'>
|
||||||
|
</form>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
";
|
||||||
|
}
|
||||||
|
$html = "
|
||||||
|
<table border='1'>
|
||||||
|
<thead><td>Image</td><td>Reporter</td><td>Reason Type</td><td>Reason / Image ID</td><td>Action</td></thead>
|
||||||
|
$h_reportedimages
|
||||||
|
</table>
|
||||||
|
";
|
||||||
|
|
||||||
|
$page->add_block(new Block("Reported Images", $html));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function display_page($page) {
|
||||||
|
$page->set_title("Reported Images");
|
||||||
|
$page->set_heading("Reported Images");
|
||||||
|
$page->add_block(new NavBlock());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function display_image_banner($page, $image) {
|
||||||
|
|
||||||
|
global $config;
|
||||||
|
|
||||||
|
$page->add_header("<script type='text/javascript' src='".get_base_href()."/ext/report_image/report_image.js'></script>");
|
||||||
|
|
||||||
|
$i_image = int_escape($image);
|
||||||
|
$html = "
|
||||||
|
<form name='ReportImage' action='".make_link("ReportImage/add")."' onsubmit='return validate_report()' method='POST'>
|
||||||
|
<input type='hidden' name='image_id' value='$i_image'>
|
||||||
|
<select onchange='change_reason()' name='reason_type'>
|
||||||
|
<option style='font-weight:bold' selected>Select a reason...</option>
|
||||||
|
<option value='Other'>Other</option>
|
||||||
|
<option value='Violates Rules'>Violates Rules</option>
|
||||||
|
<option value='Illegal'>Illegal</option>
|
||||||
|
<option value='Duplicate'>Duplicate</option>
|
||||||
|
<input type='field' name='reason' value='Please enter a reason' onclick='document.ReportImage.reason.select()'>
|
||||||
|
</select>
|
||||||
|
<input type='submit' value='Report'>
|
||||||
|
</form>
|
||||||
|
";
|
||||||
|
$page->add_block(new Block("Report Image", $html, "left"));
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
Loading…
x
Reference in New Issue
Block a user