Example #1
0
 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 ImageInfoBoxBuildingEvent) {
         if (!$config->get_bool("tageditcloud_disable")) {
             if ($this->can_tag($event->image)) {
                 if (!($cfg_minusage = $config->get_int("tageditcloud_minusage"))) {
                     $cfg_minusage = 2;
                 }
                 if (!($cfg_defcount = $config->get_int("tageditcloud_defcount"))) {
                     $cfg_defcount = 40;
                 }
                 if (!($cfg_maxcount = $config->get_int("tageditcloud_maxcount"))) {
                     $cfg_maxcount = 4096;
                 }
                 if ($config->get_string("tageditcloud_sort") != "p") {
                     $event->add_part($this->build_tag_map($event->image, $cfg_minusage, false), 40);
                 } else {
                     $event->add_part($this->build_tag_map($event->image, $cfg_defcount, $cfg_maxcount), 40);
                 }
             }
         }
     }
     if ($event instanceof InitExtEvent) {
         $config->set_default_bool("tageditcloud_disable", false);
         $config->set_default_bool("tageditcloud_usedfirst", true);
         $config->set_default_string("tageditcloud_sort", 'a');
         $config->set_default_int("tageditcloud_minusage", 2);
         $config->set_default_int("tageditcloud_defcount", 40);
         $config->set_default_int("tageditcloud_maxcount", 4096);
     }
     if ($event instanceof SetupBuildingEvent) {
         $sort_by = array('Alphabetical' => 'a', 'Popularity' => 'p');
         $sb = new SetupBlock("Tag Edit Cloud");
         $sb->add_bool_option("tageditcloud_disable", "Disable Tag Selection Cloud: ");
         $sb->add_choice_option("tageditcloud_sort", $sort_by, "<br>Sort the tags by:");
         $sb->add_bool_option("tageditcloud_usedfirst", "<br>Always show used tags first: ");
         $sb->add_label("<br><b>Alpha sort</b>:<br>Only show tags used at least ");
         $sb->add_int_option("tageditcloud_minusage");
         $sb->add_label(" times.<br><b>Popularity sort</b>:<br>Show ");
         $sb->add_int_option("tageditcloud_defcount");
         $sb->add_label(" tags by default.<br>Show a maximum of ");
         $sb->add_int_option("tageditcloud_maxcount");
         $sb->add_label(" tags.");
         $event->panel->add_block($sb);
     }
 }
Example #2
0
 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 PageRequestEvent && $event->page_matches("tag_edit")) {
         if ($event->get_arg(0) == "replace") {
             if ($user->is_admin() && isset($_POST['search']) && isset($_POST['replace'])) {
                 $search = $_POST['search'];
                 $replace = $_POST['replace'];
                 $this->mass_tag_edit($search, $replace);
                 $page->set_mode("redirect");
                 $page->set_redirect(make_link("admin"));
             }
         }
     }
     if ($event instanceof ImageInfoSetEvent) {
         if ($this->can_tag()) {
             send_event(new TagSetEvent($event->image, $_POST['tag_edit__tags']));
             if ($this->can_source()) {
                 send_event(new SourceSetEvent($event->image, $_POST['tag_edit__source']));
             }
         } else {
             $this->theme->display_error($page, "Error", "Anonymous tag editing is disabled");
         }
     }
     if ($event instanceof TagSetEvent) {
         $event->image->set_tags($event->tags);
     }
     if ($event instanceof SourceSetEvent) {
         $event->image->set_source($event->source);
     }
     if ($event instanceof ImageDeletionEvent) {
         $event->image->delete_tags_from_image();
     }
     if ($event instanceof AdminBuildingEvent) {
         $this->theme->display_mass_editor($page);
     }
     // When an alias is added, oldtag becomes inaccessable
     if ($event instanceof AddAliasEvent) {
         $this->mass_tag_edit($event->oldtag, $event->newtag);
     }
     if ($event instanceof ImageInfoBoxBuildingEvent) {
         if ($config->get_bool("tag_edit_anon") || !$user->is_anonymous()) {
             $event->add_part($this->theme->get_tag_editor_html($event->image), 40);
         }
         if ($config->get_bool("source_edit_anon") || !$user->is_anonymous()) {
             $event->add_part($this->theme->get_source_editor_html($event->image), 41);
         }
     }
     if ($event instanceof SetupBuildingEvent) {
         $sb = new SetupBlock("Tag Editing");
         $sb->add_bool_option("tag_edit_anon", "Allow anonymous tag editing: ");
         $sb->add_bool_option("source_edit_anon", "<br>Allow anonymous source editing: ");
         $event->panel->add_block($sb);
     }
 }
Example #3
0
 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 AdminBuildingEvent) {
         $this->theme->display_bulk_rater();
     }
     if ($event instanceof PageRequestEvent && $event->page_matches("admin/bulk_rate")) {
         global $database, $user, $page;
         if (!$user->is_admin()) {
             throw PermissionDeniedException();
         } else {
             $n = 0;
             while (true) {
                 $images = Image::find_images($n, 100, Tag::explode($_POST["query"]));
                 if (count($images) == 0) {
                     break;
                 }
                 foreach ($images as $image) {
                     send_event(new RatingSetEvent($image, $user, $_POST['rating']));
                 }
                 $n += 100;
             }
             #$database->execute("
             #	update images set rating=? where images.id in (
             #		select image_id from image_tags join tags
             #		on image_tags.tag_id = tags.id where tags.tag = ?);
             #	", array($_POST["rating"], $_POST["tag"]));
             $page->set_mode("redirect");
             $page->set_redirect(make_link("admin"));
         }
     }
     if ($event instanceof InitExtEvent) {
         if ($config->get_int("ext_ratings2_version") < 2) {
             $this->install();
         }
         $config->set_default_string("ext_rating_anon_privs", 'squ');
         $config->set_default_string("ext_rating_user_privs", 'sqeu');
         $config->set_default_string("ext_rating_admin_privs", 'sqeu');
     }
     if ($event instanceof RatingSetEvent) {
         $this->set_rating($event->image->id, $event->rating);
     }
     if ($event instanceof ImageInfoBoxBuildingEvent) {
         if ($this->can_rate()) {
             $event->add_part($this->theme->get_rater_html($event->image->id, $event->image->rating), 80);
         }
     }
     if ($event instanceof ImageInfoSetEvent) {
         if ($this->can_rate() && isset($_POST["rating"])) {
             send_event(new RatingSetEvent($event->image, $user, $_POST['rating']));
         }
     }
     if ($event instanceof SetupBuildingEvent) {
         $privs = array();
         $privs['Safe Only'] = 's';
         $privs['Safe and Unknown'] = 'su';
         $privs['Safe and Questionable'] = 'sq';
         $privs['Safe, Questionable, Unknown'] = 'squ';
         $privs['All'] = 'sqeu';
         $sb = new SetupBlock("Image Ratings");
         $sb->add_choice_option("ext_rating_anon_privs", $privs, "Anonymous: ");
         $sb->add_choice_option("ext_rating_user_privs", $privs, "<br>Users: ");
         $sb->add_choice_option("ext_rating_admin_privs", $privs, "<br>Admins: ");
         $event->panel->add_block($sb);
     }
     if ($event instanceof ParseLinkTemplateEvent) {
         $event->replace('$rating', $this->theme->rating_to_name($event->image->rating));
     }
     if ($event instanceof SearchTermParseEvent) {
         $matches = array();
         if (is_null($event->term) && $this->no_rating_query($event->context)) {
             $set = Ratings::privs_to_sql(Ratings::get_user_privs($user));
             $event->add_querylet(new Querylet("rating IN ({$set})"));
         }
         if (preg_match("/^rating=([sqeu]+)\$/", $event->term, $matches)) {
             $sqes = $matches[1];
             $arr = array();
             for ($i = 0; $i < strlen($sqes); $i++) {
                 $arr[] = "'" . $sqes[$i] . "'";
             }
             $set = join(', ', $arr);
             $event->add_querylet(new Querylet("rating IN ({$set})"));
         }
         if (preg_match("/^rating=(safe|questionable|explicit|unknown)\$/", strtolower($event->term), $matches)) {
             $text = $matches[1];
             $char = $text[0];
             $event->add_querylet(new Querylet("rating = ?", array($char)));
         }
     }
 }
Example #4
0
 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) {
         if ($config->get_int("ext_imageban_version") < 1) {
             $this->install();
         }
     }
     if ($event instanceof DataUploadEvent) {
         $row = $database->db->GetRow("SELECT * FROM image_bans WHERE hash = ?", $event->hash);
         if ($row) {
             log_info("image_hash_ban", "Blocked image ({$event->hash})");
             throw new UploadException("Image " . html_escape($row["hash"]) . " has been banned, reason: " . format_text($row["reason"]));
         }
     }
     if ($event instanceof PageRequestEvent && $event->page_matches("image_hash_ban")) {
         if ($user->is_admin()) {
             if ($event->get_arg(0) == "add") {
                 if (isset($_POST['hash']) && isset($_POST['reason'])) {
                     send_event(new AddImageHashBanEvent($_POST['hash'], $_POST['reason']));
                     $page->set_mode("redirect");
                     $page->set_redirect(make_link("image_hash_ban/list/1"));
                 }
                 if (isset($_POST['image_id'])) {
                     $image = Image::by_id(int_escape($_POST['image_id']));
                     if ($image) {
                         send_event(new ImageDeletionEvent($image));
                         $page->set_mode("redirect");
                         $page->set_redirect(make_link("post/list"));
                     }
                 }
             } else {
                 if ($event->get_arg(0) == "remove") {
                     if (isset($_POST['hash'])) {
                         send_event(new RemoveImageHashBanEvent($_POST['hash']));
                         $page->set_mode("redirect");
                         $page->set_redirect(make_link("image_hash_ban/list/1"));
                     }
                 } else {
                     if ($event->get_arg(0) == "list") {
                         $page_num = 0;
                         if ($event->count_args() == 2) {
                             $page_num = int_escape($event->get_arg(1));
                         }
                         $page_size = 100;
                         $page_count = ceil($database->db->getone("SELECT COUNT(id) FROM image_bans") / $page_size);
                         $this->theme->display_Image_hash_Bans($page, $page_num, $page_count, $this->get_image_hash_bans($page_num, $page_size));
                     }
                 }
             }
         }
     }
     if ($event instanceof UserBlockBuildingEvent) {
         if ($user->is_admin()) {
             $event->add_link("Image Bans", make_link("image_hash_ban/list/1"));
         }
     }
     if ($event instanceof AddImageHashBanEvent) {
         $this->add_image_hash_ban($event->hash, $event->reason);
     }
     if ($event instanceof RemoveImageHashBanEvent) {
         $this->remove_image_hash_ban($event->hash);
     }
     if ($event instanceof ImageAdminBlockBuildingEvent) {
         if ($user->is_admin()) {
             $event->add_part($this->theme->get_buttons_html($event->image));
         }
     }
 }