tag history -> simpleext

This commit is contained in:
Shish 2012-01-30 03:46:38 +00:00
parent 0ea3ff5af3
commit 444fdb1f04

View File

@ -5,65 +5,61 @@
* Description: Keep a record of tag changes, and allows you to revert changes. * Description: Keep a record of tag changes, and allows you to revert changes.
*/ */
class Tag_History implements Extension { class Tag_History extends SimpleExtension {
var $theme;
// in before tags are actually set, so that "get current tags" works // in before tags are actually set, so that "get current tags" works
public function get_priority() {return 40;} public function get_priority() {return 40;}
public function receive_event(Event $event) { public function onInitExtEvent($event) {
global $config, $database, $page, $user; global $config;
if(is_null($this->theme)) $this->theme = get_theme_object($this); $config->set_default_int("history_limit", -1);
if(($event instanceof InitExtEvent)) { // shimmie is being installed so call install to create the table.
$config->set_default_int("history_limit", -1); 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)) public function onAdminBuildingEvent($event) {
{ global $user;
if(isset($_POST['revert_ip']) && $user->is_admin() && $user->check_auth_token())
{ 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); $revert_ip = filter_var($_POST['revert_ip'], FILTER_VALIDATE_IP, FILTER_FLAG_NO_RES_RANGE);
if ($revert_ip === false) { if ($revert_ip === false) {
// invalid ip given. // invalid ip given.
$this->theme->display_admin_block('Invalid IP'); $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; 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 else {
{ $revert_date = null;
$this->theme->display_admin_block(); // add a block to the admin panel
} }
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"))) public function onPageRequest($event) {
{ global $config, $page;
if($event->get_arg(0) == "revert")
{ 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 // this is a request to revert to a previous version of the tags
if($config->get_bool("tag_edit_anon") || !$user->is_anonymous()) { if($config->get_bool("tag_edit_anon") || !$user->is_anonymous()) {
if(isset($_POST['revert'])) { 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 // must be an attempt to view a tag history
$image_id = int_escape($event->get_arg(0)); $image_id = int_escape($event->get_arg(0));
$this->theme->display_history_page($page, $image_id, $this->get_tag_history_from_id($image_id)); $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()); $this->theme->display_global_page($page, $this->get_global_tag_history());
} }
} }
}
if(($event instanceof DisplayingImageEvent))
{ public function onDisplayingImage($event) {
// handle displaying a link on the view page global $page;
$this->theme->display_history_link($page, $event->image->id); // 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 public function onImageDeletion($event) {
$this->delete_all_tag_history($event->image->id); // 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 "); public function onSetupBuilding($event) {
$sb->add_int_option("history_limit"); $sb = new SetupBlock("Tag History");
$sb->add_label(" entires per image"); $sb->add_label("Limit to ");
$sb->add_label("<br>(-1 for unlimited)"); $sb->add_int_option("history_limit");
$event->panel->add_block($sb); $sb->add_label(" entires per image");
} $sb->add_label("<br>(-1 for unlimited)");
if(($event instanceof TagSetEvent)) { $event->panel->add_block($sb);
$this->add_tag_history($event->image, $event->tags); }
}
if($event instanceof UserBlockBuildingEvent) { public function onTagSetEvent($event) {
if($user->is_admin()) { $this->add_tag_history($event->image, $event->tags);
$event->add_link("Tag Changes", make_link("tag_history")); }
}
public function onUserBlockBuilding($event) {
global $user;
if($user->is_admin()) {
$event->add_link("Tag Changes", make_link("tag_history"));
} }
} }