tag history -> simpleext

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

View File

@ -5,17 +5,12 @@
* Description: Keep a record of tag changes, and allows you to revert changes.
*/
class Tag_History implements Extension {
var $theme;
class Tag_History extends SimpleExtension {
// in before tags are actually set, so that "get current tags" works
public function get_priority() {return 40;}
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)) {
public function onInitExtEvent($event) {
global $config;
$config->set_default_int("history_limit", -1);
// shimmie is being installed so call install to create the table.
@ -24,10 +19,10 @@ class Tag_History implements Extension {
}
}
if(($event instanceof AdminBuildingEvent))
{
if(isset($_POST['revert_ip']) && $user->is_admin() && $user->check_auth_token())
{
public function onAdminBuildingEvent($event) {
global $user;
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);
if ($revert_ip === false) {
@ -43,7 +38,8 @@ class Tag_History implements Extension {
$this->theme->display_admin_block('Invalid Date');
return;
}
} else {
}
else {
$revert_date = null;
}
@ -54,16 +50,16 @@ class Tag_History implements Extension {
// output results
$this->theme->display_revert_ip_results();
}
else
{
else {
$this->theme->display_admin_block(); // add a block to the admin panel
}
}
if (($event instanceof PageRequestEvent) && ($event->page_matches("tag_history")))
{
if($event->get_arg(0) == "revert")
{
public function onPageRequest($event) {
global $config, $page;
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
if($config->get_bool("tag_edit_anon") || !$user->is_anonymous()) {
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
$image_id = int_escape($event->get_arg(0));
$this->theme->display_history_page($page, $image_id, $this->get_tag_history_from_id($image_id));
@ -81,18 +76,20 @@ class Tag_History implements Extension {
$this->theme->display_global_page($page, $this->get_global_tag_history());
}
}
}
if(($event instanceof DisplayingImageEvent))
{
public function onDisplayingImage($event) {
global $page;
// handle displaying a link on the view page
$this->theme->display_history_link($page, $event->image->id);
}
if(($event instanceof ImageDeletionEvent))
{
public function onImageDeletion($event) {
// handle removing of history when an image is deleted
$this->delete_all_tag_history($event->image->id);
}
if(($event instanceof SetupBuildingEvent)) {
public function onSetupBuilding($event) {
$sb = new SetupBlock("Tag History");
$sb->add_label("Limit to ");
$sb->add_int_option("history_limit");
@ -100,15 +97,17 @@ class Tag_History implements Extension {
$sb->add_label("<br>(-1 for unlimited)");
$event->panel->add_block($sb);
}
if(($event instanceof TagSetEvent)) {
public function onTagSetEvent($event) {
$this->add_tag_history($event->image, $event->tags);
}
if($event instanceof UserBlockBuildingEvent) {
public function onUserBlockBuilding($event) {
global $user;
if($user->is_admin()) {
$event->add_link("Tag Changes", make_link("tag_history"));
}
}
}
protected function install()
{