Beispiel #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 PageRequestEvent && $event->page_matches("admin")) {
         if (!$user->is_admin()) {
             $this->theme->display_permission_denied($page);
         } else {
             send_event(new AdminBuildingEvent($page));
         }
     }
     if ($event instanceof PageRequestEvent && $event->page_matches("admin_utils")) {
         if ($user->is_admin() && $user->check_auth_token()) {
             log_info("admin", "Util: {$_POST['action']}");
             set_time_limit(0);
             $redirect = false;
             switch ($_POST['action']) {
                 case 'delete by query':
                     $this->delete_by_query($_POST['query']);
                     $redirect = true;
                     break;
                 case 'lowercase all tags':
                     $this->lowercase_all_tags();
                     $redirect = true;
                     break;
                 case 'recount tag use':
                     $this->recount_tag_use();
                     $redirect = true;
                     break;
                 case 'purge unused tags':
                     $this->purge_unused_tags();
                     $redirect = true;
                     break;
                 case 'convert to innodb':
                     $this->convert_to_innodb();
                     $redirect = true;
                     break;
                 case 'database dump':
                     $this->dbdump($page);
                     break;
             }
             if ($redirect) {
                 $page->set_mode("redirect");
                 $page->set_redirect(make_link("admin"));
             }
         }
     }
     if ($event instanceof AdminBuildingEvent) {
         $this->theme->display_page($page);
         $this->theme->display_form($page);
     }
     if ($event instanceof UserBlockBuildingEvent) {
         if ($user->is_admin()) {
             $event->add_link("Board Admin", make_link("admin"));
         }
     }
 }
Beispiel #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);
     }
 }
Beispiel #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 InitExtEvent) {
         if ($config->get_int("ext_ipban_version") < 5) {
             $this->install();
         }
         $this->check_ip_ban();
     }
     if ($event instanceof PageRequestEvent && $event->page_matches("ip_ban")) {
         if ($user->is_admin()) {
             if ($event->get_arg(0) == "add" && $user->check_auth_token()) {
                 if (isset($_POST['ip']) && isset($_POST['reason']) && isset($_POST['end'])) {
                     if (empty($_POST['end'])) {
                         $end = null;
                     } else {
                         $end = $_POST['end'];
                     }
                     send_event(new AddIPBanEvent($_POST['ip'], $_POST['reason'], $end));
                     $page->set_mode("redirect");
                     $page->set_redirect(make_link("ip_ban/list"));
                 }
             } else {
                 if ($event->get_arg(0) == "remove" && $user->check_auth_token()) {
                     if (isset($_POST['id'])) {
                         send_event(new RemoveIPBanEvent($_POST['id']));
                         $page->set_mode("redirect");
                         $page->set_redirect(make_link("ip_ban/list"));
                     }
                 } else {
                     if ($event->get_arg(0) == "list") {
                         $bans = isset($_GET["all"]) ? $this->get_bans() : $this->get_active_bans();
                         $this->theme->display_bans($page, $bans);
                     }
                 }
             }
         } else {
             $this->theme->display_permission_denied($page);
         }
     }
     if ($event instanceof UserBlockBuildingEvent) {
         if ($user->is_admin()) {
             $event->add_link("IP Bans", make_link("ip_ban/list"));
         }
     }
     if ($event instanceof AddIPBanEvent) {
         $this->add_ip_ban($event->ip, $event->reason, $event->end, $user);
     }
     if ($event instanceof RemoveIPBanEvent) {
         $database->Execute("DELETE FROM bans WHERE id = :id", array("id" => $event->id));
         $database->cache->delete("ip_bans");
     }
 }
Beispiel #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 (is_a($event, 'PageRequestEvent') && ($event->page_matches("post/prev") || $event->page_matches("post/next"))) {
         $image_id = int_escape($event->get_arg(0));
         if (isset($_GET['search'])) {
             $search_terms = explode(' ', $_GET['search']);
             $query = "search=" . url_escape($_GET['search']);
         } else {
             $search_terms = array();
             $query = null;
         }
         $image = Image::by_id($image_id);
         if ($event->page_matches("post/next")) {
             $image = $image->get_next($search_terms);
         } else {
             $image = $image->get_prev($search_terms);
         }
         if (!is_null($image)) {
             $page->set_mode("redirect");
             $page->set_redirect(make_link("post/view/{$image->id}", $query));
         } else {
             $this->theme->display_error($page, "Image not found", "No more images");
         }
     }
     if ($event instanceof PageRequestEvent && $event->page_matches("post/view")) {
         $image_id = int_escape($event->get_arg(0));
         $image = Image::by_id($image_id);
         if (!is_null($image)) {
             send_event(new DisplayingImageEvent($image));
             $iabbe = new ImageAdminBlockBuildingEvent($image, $user);
             send_event($iabbe);
             ksort($iabbe->parts);
             $this->theme->display_admin_block($page, $iabbe->parts);
         } else {
             $this->theme->display_error($page, "Image not found", "No image in the database has the ID #{$image_id}");
         }
     }
     if ($event instanceof PageRequestEvent && $event->page_matches("post/set")) {
         $image_id = int_escape($_POST['image_id']);
         send_event(new ImageInfoSetEvent(Image::by_id($image_id)));
         $query = $_POST['query'];
         $page->set_mode("redirect");
         $page->set_redirect(make_link("post/view/{$image_id}", $query));
     }
     if ($event instanceof DisplayingImageEvent) {
         $iibbe = new ImageInfoBoxBuildingEvent($event->get_image(), $user);
         send_event($iibbe);
         ksort($iibbe->parts);
         $this->theme->display_page($page, $event->get_image(), $iibbe->parts);
     }
 }
Beispiel #5
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) {
         $config->set_default_int("history_limit", -1);
         // 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 PageRequestEvent && $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()) {
                 $this->process_revert_request($_POST['revert']);
             }
         } 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));
             } else {
                 $this->theme->display_global_page($page, $this->get_global_tag_history());
             }
         }
     }
     if ($event instanceof DisplayingImageEvent) {
         // 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
         $this->delete_all_tag_history($event->image->id);
     }
     if ($event instanceof SetupBuildingEvent) {
         $sb = new SetupBlock("Tag History");
         $sb->add_label("Limit to ");
         $sb->add_int_option("history_limit");
         $sb->add_label(" entires per image");
         $sb->add_label("<br>(-1 for unlimited)");
         $event->panel->add_block($sb);
     }
     if ($event instanceof TagSetEvent) {
         $this->add_tag_history($event->image, $event->tags);
     }
     if ($event instanceof UserBlockBuildingEvent) {
         if ($user->is_admin()) {
             $event->add_link("Tag Changes", make_link("tag_history"));
         }
     }
 }
Beispiel #6
0
 public function receive_event(Event $event)
 {
     if (is_null($this->theme)) {
         $this->theme = get_theme_object($this);
     }
     if ($event instanceof DataUploadEvent && $this->supported_ext($event->type) && $this->check_contents($event->tmpname)) {
         $hash = $event->hash;
         $ha = substr($hash, 0, 2);
         if (!move_upload_to_archive($event)) {
             return;
         }
         send_event(new ThumbnailGenerationEvent($event->hash, $event->type));
         $image = $this->create_image_from_data(warehouse_path("images", $hash), $event->metadata);
         if (is_null($image)) {
             throw new UploadException("SVG handler failed to create image object from data");
         }
         $iae = new ImageAdditionEvent($event->user, $image);
         send_event($iae);
         $event->image_id = $iae->image->id;
     }
     if ($event instanceof ThumbnailGenerationEvent && $this->supported_ext($event->type)) {
         $hash = $event->hash;
         $ha = substr($hash, 0, 2);
         global $config;
         //			if($config->get_string("thumb_engine") == "convert") {
         //				$w = $config->get_int("thumb_width");
         //				$h = $config->get_int("thumb_height");
         //				$q = $config->get_int("thumb_quality");
         //				$mem = $config->get_int("thumb_max_memory") / 1024 / 1024; // IM takes memory in MB
         //
         //				exec("convert images/{$ha}/{$hash}[0] -geometry {$w}x{$h} -quality {$q} jpg:thumbs/{$ha}/{$hash}");
         //			}
         //			else {
         copy("ext/handle_svg/thumb.jpg", warehouse_path("thumbs", $hash));
         //			}
     }
     if ($event instanceof DisplayingImageEvent && $this->supported_ext($event->image->ext)) {
         global $page;
         $this->theme->display_image($page, $event->image);
     }
     if ($event instanceof PageRequestEvent && $event->page_matches("get_svg")) {
         global $config, $database, $page;
         $id = int_escape($event->get_arg(0));
         $image = Image::by_id($id);
         $hash = $image->hash;
         $page->set_type("image/svg+xml");
         $page->set_mode("data");
         $page->set_data(file_get_contents(warehouse_path("images", $hash)));
     }
 }
Beispiel #7
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("system_info")) {
         if ($user->is_admin()) {
             $this->theme->display_info_page($page, $this->get_info());
         }
     }
     if ($event instanceof UserBlockBuildingEvent) {
         if ($user->is_admin()) {
             $event->add_link("System Info", make_link("system_info"));
         }
     }
 }
Beispiel #8
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 DisplayingImageEvent) {
         $this->theme->links_block($page, $this->data($event->image));
     }
     if ($event instanceof SetupBuildingEvent) {
         $sb = new SetupBlock("Link to Image");
         $sb->add_text_option("ext_link-img_text-link_format", "Text Link Format: ");
         $event->panel->add_block($sb);
     }
     if ($event instanceof InitExtEvent) {
         //just set default if empty.
         $config->set_default_string("ext_link-img_text-link_format", '$title - $id ($ext $size $filesize)');
     }
 }
Beispiel #9
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 SetupBuildingEvent) {
         $sb = new SetupBlock("Downtime");
         $sb->add_bool_option("downtime", "Disable non-admin access: ");
         $sb->add_longtext_option("downtime_message", "<br>");
         $event->panel->add_block($sb);
     }
     if ($event instanceof PageRequestEvent) {
         if ($config->get_bool("downtime")) {
             $this->check_downtime($event);
             $this->theme->display_notification($page);
         }
     }
 }
Beispiel #10
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("bookmark")) {
         if ($event->get_arg(0) == "add") {
             if (isset($_POST['url'])) {
                 $page->set_mode("redirect");
                 $page->set_redirect(make_link("user"));
             }
         } else {
             if ($event->get_arg(0) == "remove") {
                 if (isset($_POST['id'])) {
                     $page->set_mode("redirect");
                     $page->set_redirect(make_link("user"));
                 }
             }
         }
     }
 }
Beispiel #11
0
 public function receive_event(Event $event)
 {
     if (is_null($this->theme)) {
         $this->theme = get_theme_object($this);
     }
     if ($event instanceof DisplayingImageEvent) {
         global $page, $config, $user;
         if ($config->get_bool("tag_edit_anon") || $user->id != $config->get_int("anon_id") && $config->get_bool("ext_tagger_enabled")) {
             $this->theme->build_tagger($page, $event);
         }
     }
     if ($event instanceof SetupBuildingEvent) {
         $sb = new SetupBlock("Tagger");
         $sb->add_bool_option("ext_tagger_enabled", "Enable Tagger");
         $sb->add_int_option("ext_tagger_search_delay", "<br/>Delay queries by ");
         $sb->add_label(" milliseconds.");
         $sb->add_label("<br/>Limit queries returning more than ");
         $sb->add_int_option("ext_tagger_tag_max");
         $sb->add_label(" tags to ");
         $sb->add_int_option("ext_tagger_limit");
         $event->panel->add_block($sb);
     }
 }
Beispiel #12
0
 public function receive_event(Event $event)
 {
     global $user;
     if (is_null($this->theme)) {
         $this->theme = get_theme_object($this);
     }
     if ($event instanceof ImageInfoSetEvent) {
         if (isset($_POST["tag_edit__author"])) {
             send_event(new AuthorSetEvent($event->image, $user, $_POST["tag_edit__author"]));
         }
     }
     if ($event instanceof AuthorSetEvent) {
         $this->update_author($event);
     }
     if ($event instanceof InitExtEvent) {
         $this->try_install();
     }
     if ($event instanceof ImageInfoBoxBuildingEvent) {
         $this->add_author_field_to_image($event);
     }
     if ($event instanceof PageRequestEvent) {
         $this->handle_commands($event);
     }
 }
Beispiel #13
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) {
         $config->set_default_bool('report_image_show_thumbs', true);
         if ($config->get_int("ext_report_image_version") < 1) {
             $this->install();
         }
     }
     if ($event instanceof PageRequestEvent && $event->page_matches("image_report")) {
         if ($event->get_arg(0) == "add") {
             if (isset($_POST['image_id']) && isset($_POST['reason'])) {
                 $image_id = int_escape($_POST['image_id']);
                 send_event(new AddReportedImageEvent($image_id, $user->id, $_POST['reason']));
                 $page->set_mode("redirect");
                 $page->set_redirect(make_link("post/view/{$image_id}"));
             }
         } else {
             if ($event->get_arg(0) == "remove") {
                 if (isset($_POST['id'])) {
                     if ($user->is_admin()) {
                         send_event(new RemoveReportedImageEvent($_POST['id']));
                         $page->set_mode("redirect");
                         $page->set_redirect(make_link("image_report/list"));
                     }
                 }
             } else {
                 if ($event->get_arg(0) == "list") {
                     if ($user->is_admin()) {
                         $this->theme->display_reported_images($page, $this->get_reported_images());
                     }
                 }
             }
         }
     }
     if ($event instanceof AddReportedImageEvent) {
         $database->Execute("INSERT INTO image_reports(image_id, reporter_id, reason)\n\t\t\t\t\tVALUES (?, ?, ?)", array($event->image_id, $event->reporter_id, $event->reason));
     }
     if ($event instanceof RemoveReportedImageEvent) {
         $database->Execute("DELETE FROM image_reports WHERE id = ?", array($event->id));
     }
     if ($event instanceof DisplayingImageEvent) {
         if ($config->get_bool('report_image_anon') || !$user->is_anonymous()) {
             $this->theme->display_image_banner($page, $event->image);
         }
     }
     if ($event instanceof SetupBuildingEvent) {
         $sb = new SetupBlock("Report Image Options");
         $sb->add_bool_option("report_image_anon", "Allow anonymous image reporting: ");
         $sb->add_bool_option("report_image_show_thumbs", "<br>Show thumbnails in admin panel: ");
         $event->panel->add_block($sb);
     }
     if ($event instanceof UserBlockBuildingEvent) {
         if ($user->is_admin()) {
             $event->add_link("Reported Images", make_link("image_report/list"));
         }
     }
     if ($event instanceof ImageDeletionEvent) {
         $database->Execute("DELETE FROM image_reports WHERE image_id = ?", array($event->image->id));
     }
 }
Beispiel #14
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("alias")) {
         if ($event->get_arg(0) == "add") {
             if ($user->is_admin()) {
                 if (isset($_POST['oldtag']) && isset($_POST['newtag'])) {
                     try {
                         $aae = new AddAliasEvent($_POST['oldtag'], $_POST['newtag']);
                         send_event($aae);
                         $page->set_mode("redirect");
                         $page->set_redirect(make_link("alias/list"));
                     } catch (AddAliasException $ex) {
                         $this->theme->display_error($page, "Error adding alias", $ex->getMessage());
                     }
                 }
             }
         } else {
             if ($event->get_arg(0) == "remove") {
                 if ($user->is_admin()) {
                     if (isset($_POST['oldtag'])) {
                         $database->Execute("DELETE FROM aliases WHERE oldtag=?", array($_POST['oldtag']));
                         log_info("alias_editor", "Deleted alias for " . $_POST['oldtag']);
                         $page->set_mode("redirect");
                         $page->set_redirect(make_link("alias/list"));
                     }
                 }
             } else {
                 if ($event->get_arg(0) == "list") {
                     $page_number = $event->get_arg(1);
                     if (is_null($page_number) || !is_numeric($page_number)) {
                         $page_number = 0;
                     } else {
                         if ($page_number <= 0) {
                             $page_number = 0;
                         } else {
                             $page_number--;
                         }
                     }
                     $alias_per_page = $config->get_int('alias_items_per_page', 30);
                     if ($database->engine->name == "mysql") {
                         $query = "SELECT oldtag, newtag FROM aliases ORDER BY newtag ASC LIMIT ?, ?";
                     } else {
                         $query = "SELECT oldtag, newtag FROM aliases ORDER BY newtag ASC OFFSET ? LIMIT ?";
                     }
                     $alias = $database->db->GetAssoc($query, array($page_number * $alias_per_page, $alias_per_page));
                     $total_pages = ceil($database->db->GetOne("SELECT COUNT(*) FROM aliases") / $alias_per_page);
                     $this->theme->display_aliases($page, $alias, $user->is_admin(), $page_number + 1, $total_pages);
                 } else {
                     if ($event->get_arg(0) == "export") {
                         $page->set_mode("data");
                         $page->set_type("text/plain");
                         $page->set_data($this->get_alias_csv($database));
                     } else {
                         if ($event->get_arg(0) == "import") {
                             if ($user->is_admin()) {
                                 print_r($_FILES);
                                 if (count($_FILES) > 0) {
                                     global $database;
                                     $tmp = $_FILES['alias_file']['tmp_name'];
                                     $contents = file_get_contents($tmp);
                                     $this->add_alias_csv($database, $contents);
                                     $page->set_mode("redirect");
                                     $page->set_redirect(make_link("alias/list"));
                                 } else {
                                     $this->theme->display_error($page, "No File Specified", "You have to upload a file");
                                 }
                             } else {
                                 $this->theme->display_error($page, "Admins Only", "Only admins can edit the alias list");
                             }
                         }
                     }
                 }
             }
         }
     }
     if ($event instanceof AddAliasEvent) {
         global $database;
         $pair = array($event->oldtag, $event->newtag);
         if ($database->db->GetRow("SELECT * FROM aliases WHERE oldtag=? AND lower(newtag)=lower(?)", $pair)) {
             throw new AddAliasException("That alias already exists");
         } else {
             $database->Execute("INSERT INTO aliases(oldtag, newtag) VALUES(?, ?)", $pair);
             log_info("alias_editor", "Added alias for {$event->oldtag} -> {$event->newtag}");
         }
     }
     if ($event instanceof UserBlockBuildingEvent) {
         if ($user->is_admin()) {
             $event->add_link("Alias Editor", make_link("alias/list"));
         }
     }
 }
Beispiel #15
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_numeric_score_version", 0) < 1) {
             $this->install();
         }
     }
     if ($event instanceof DisplayingImageEvent) {
         if (!$user->is_anonymous()) {
             $html = $this->theme->get_voter_html($event->image);
             $page->add_block(new Block("Image Score", $html, "left", 20));
         }
     }
     if ($event instanceof UserPageBuildingEvent) {
         $html = $this->theme->get_nuller_html($event->display_user);
         $page->add_block(new Block("Votes", $html, "main", 60));
     }
     if ($event instanceof PageRequestEvent) {
         if ($event->page_matches("numeric_score_votes")) {
             $image_id = int_escape($event->get_arg(0));
             $x = $database->get_all("SELECT users.name as username, user_id, score \n\t\t\t\t\tFROM numeric_score_votes \n\t\t\t\t\tJOIN users ON numeric_score_votes.user_id=users.id\n\t\t\t\t\tWHERE image_id=?", array($image_id));
             $html = "<table>";
             foreach ($x as $vote) {
                 $html .= "<tr><td>";
                 $html .= "<a href='/user/{$vote['username']}'>{$vote['username']}</a>";
                 $html .= "</td><td>";
                 $html .= $vote['score'];
                 $html .= "</td></tr>";
             }
             die($html);
         }
         if ($event->page_matches("numeric_score_vote") && $user->check_auth_token()) {
             if (!$user->is_anonymous()) {
                 $image_id = int_escape($_POST['image_id']);
                 $char = $_POST['vote'];
                 $score = null;
                 if ($char == "up") {
                     $score = 1;
                 } else {
                     if ($char == "null") {
                         $score = 0;
                     } else {
                         if ($char == "down") {
                             $score = -1;
                         }
                     }
                 }
                 if (!is_null($score) && $image_id > 0) {
                     send_event(new NumericScoreSetEvent($image_id, $user, $score));
                 }
                 $page->set_mode("redirect");
                 $page->set_redirect(make_link("post/view/{$image_id}"));
             }
         }
         if ($event->page_matches("numeric_score/remove_votes_on") && $user->check_auth_token()) {
             if ($user->is_admin()) {
                 $image_id = int_escape($_POST['image_id']);
                 $database->execute("DELETE FROM numeric_score_votes WHERE image_id=?", array($image_id));
                 $database->execute("UPDATE images SET numeric_score=0 WHERE id=?", array($image_id));
                 $page->set_mode("redirect");
                 $page->set_redirect(make_link("post/view/{$image_id}"));
             }
         }
         if ($event->page_matches("numeric_score/remove_votes_by") && $user->check_auth_token()) {
             if ($user->is_admin()) {
                 $user_id = int_escape($_POST['user_id']);
                 $image_ids = $database->get_col("SELECT image_id FROM numeric_score_votes WHERE user_id=?", array($user_id));
                 $database->execute("DELETE FROM numeric_score_votes WHERE user_id=? AND image_id IN ?", array($user_id, $image_ids));
                 $database->execute("UPDATE images SET numeric_score=(SELECT SUM(score) FROM numeric_score_votes WHERE image_id=images.id) WHERE images.id IN ?", array($image_ids));
                 $page->set_mode("redirect");
                 $page->set_redirect(make_link());
             }
         }
     }
     if ($event instanceof NumericScoreSetEvent) {
         log_info("numeric_score", "Rated Image #{$event->image_id} as {$event->score}");
         $this->add_vote($event->image_id, $user->id, $event->score);
     }
     if ($event instanceof ImageDeletionEvent) {
         $database->execute("DELETE FROM numeric_score_votes WHERE image_id=?", array($event->image->id));
     }
     if ($event instanceof ParseLinkTemplateEvent) {
         $event->replace('$score', $event->image->numeric_score);
     }
     if ($event instanceof SearchTermParseEvent) {
         $matches = array();
         if (preg_match("/^score(<|<=|=|>=|>)(\\d+)\$/", $event->term, $matches)) {
             $cmp = $matches[1];
             $score = $matches[2];
             $event->add_querylet(new Querylet("numeric_score {$cmp} {$score}"));
         }
         if (preg_match("/^upvoted_by=(.*)\$/", $event->term, $matches)) {
             $duser = User::by_name($matches[1]);
             if (is_null($duser)) {
                 throw new SearchTermParseException("Can't find the user named " . html_escape($matches[1]));
             }
             $event->add_querylet(new Querylet("images.id in (SELECT image_id FROM numeric_score_votes WHERE user_id=? AND score=1)", array($duser->id)));
         }
         if (preg_match("/^downvoted_by=(.*)\$/", $event->term, $matches)) {
             $duser = User::by_name($matches[1]);
             if (is_null($duser)) {
                 throw new SearchTermParseException("Can't find the user named " . html_escape($matches[1]));
             }
             $event->add_querylet(new Querylet("images.id in (SELECT image_id FROM numeric_score_votes WHERE user_id=? AND score=-1)", array($duser->id)));
         }
         if (preg_match("/^upvoted_by_id=(\\d+)\$/", $event->term, $matches)) {
             $iid = int_escape($matches[1]);
             $event->add_querylet(new Querylet("images.id in (SELECT image_id FROM numeric_score_votes WHERE user_id=? AND score=1)", array($iid)));
         }
         if (preg_match("/^downvoted_by_id=(\\d+)\$/", $event->term, $matches)) {
             $iid = int_escape($matches[1]);
             $event->add_querylet(new Querylet("images.id in (SELECT image_id FROM numeric_score_votes WHERE user_id=? AND score=-1)", array($iid)));
         }
     }
 }
Beispiel #16
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)));
         }
     }
 }
Beispiel #17
0
 public function receive_event(Event $event)
 {
     global $config, $database, $page, $user;
     if (is_null($this->theme)) {
         $this->theme = get_theme_object($this);
     }
     $is_full = disk_free_space(realpath("./images/")) < 100 * 1024 * 1024;
     if ($event instanceof InitExtEvent) {
         global $config;
         $config->set_default_int('upload_count', 3);
         $config->set_default_int('upload_size', '1MB');
         $config->set_default_bool('upload_anon', false);
     }
     if ($event instanceof PostListBuildingEvent) {
         global $user;
         if ($this->can_upload($user)) {
             if ($is_full) {
                 $this->theme->display_full($page);
             } else {
                 $this->theme->display_block($page);
             }
         }
     }
     if ($event instanceof PageRequestEvent && $event->page_matches("upload")) {
         if (count($_FILES) + count($_POST) > 0) {
             $tags = Tag::explode($_POST['tags']);
             $source = isset($_POST['source']) ? $_POST['source'] : null;
             if ($this->can_upload($user)) {
                 $ok = true;
                 foreach ($_FILES as $file) {
                     $ok = $ok & $this->try_upload($file, $tags, $source);
                 }
                 foreach ($_POST as $name => $value) {
                     if (substr($name, 0, 3) == "url" && strlen($value) > 0) {
                         $ok = $ok & $this->try_transload($value, $tags, $source);
                     }
                 }
                 $this->theme->display_upload_status($page, $ok);
             } else {
                 $this->theme->display_permission_denied($page);
             }
         } else {
             if (!empty($_GET['url'])) {
                 global $user;
                 if ($this->can_upload($user)) {
                     $url = $_GET['url'];
                     $tags = array('tagme');
                     if (!empty($_GET['tags']) && $_GET['tags'] != "null") {
                         $tags = Tag::explode($_GET['tags']);
                     }
                     $ok = $this->try_transload($url, $tags, $url);
                     $this->theme->display_upload_status($page, $ok);
                 } else {
                     $this->theme->display_permission_denied($page);
                 }
             } else {
                 if (!$is_full) {
                     $this->theme->display_page($page);
                 }
             }
         }
     }
     if ($event instanceof SetupBuildingEvent) {
         $sb = new SetupBlock("Upload");
         $sb->position = 10;
         $sb->add_int_option("upload_count", "Max uploads: ");
         $sb->add_shorthand_int_option("upload_size", "<br>Max size per file: ");
         $sb->add_bool_option("upload_anon", "<br>Allow anonymous uploads: ");
         $sb->add_choice_option("transload_engine", array("Disabled" => "none", "cURL" => "curl", "fopen" => "fopen", "WGet" => "wget"), "<br>Transload: ");
         $event->panel->add_block($sb);
     }
     if ($event instanceof DataUploadEvent) {
         global $config;
         if ($is_full) {
             throw new UploadException("Upload failed; disk nearly full");
         }
         if (filesize($event->tmpname) > $config->get_int('upload_size')) {
             $size = to_shorthand_int(filesize($event->tmpname));
             $limit = to_shorthand_int($config->get_int('upload_size'));
             throw new UploadException("File too large ({$size} &gt; {$limit})");
         }
     }
 }
Beispiel #18
0
 public function receive_event(Event $event)
 {
     global $config, $database, $page, $user;
     if (is_null($this->theme)) {
         $this->theme = get_theme_object($this);
     }
     // f*****g PHP "security" measures -_-;;;
     $free_num = @disk_free_space(realpath("./images/"));
     if ($free_num === FALSE) {
         $is_full = false;
     } else {
         $is_full = $free_num < 100 * 1024 * 1024;
     }
     if ($event instanceof InitExtEvent) {
         $config->set_default_int('upload_count', 3);
         $config->set_default_int('upload_size', '1MB');
         $config->set_default_bool('upload_anon', false);
         $config->set_default_bool('upload_replace', true);
     }
     if ($event instanceof PostListBuildingEvent) {
         if ($this->can_upload($user)) {
             if ($is_full) {
                 $this->theme->display_full($page);
             } else {
                 $this->theme->display_block($page);
             }
         }
     }
     if ($event instanceof PageRequestEvent) {
         if ($event->page_matches("upload/replace")) {
             /* Upload & Replace Image Request */
             if (!$config->get_bool("upload_replace")) {
                 throw new UploadException("Upload Replacing Images is not enabled.");
             }
             // check if the user is an administrator and can upload files.
             if (!$user->is_admin()) {
                 $this->theme->display_permission_denied($page);
             } else {
                 if ($is_full) {
                     throw new UploadException("Can not replace Image: disk nearly full");
                 }
                 // Try to get the image ID
                 $image_id = int_escape($event->get_arg(0));
                 if (empty($image_id)) {
                     $image_id = isset($_POST['image_id']) ? $_POST['image_id'] : null;
                 }
                 if (empty($image_id)) {
                     throw new UploadException("Can not replace Image: No valid Image ID given.");
                 }
                 $image_old = Image::by_id($image_id);
                 if (is_null($image_old)) {
                     $this->theme->display_error($page, "Image not found", "No image in the database has the ID #{$image_id}");
                 }
                 if (count($_FILES) + count($_POST) > 0) {
                     if (count($_FILES) > 1) {
                         throw new UploadException("Can not upload more than one image for replacing.");
                     }
                     $source = isset($_POST['source']) ? $_POST['source'] : null;
                     $tags = '';
                     // Tags aren't changed when uploading. Set to null to stop PHP warnings.
                     if (count($_FILES)) {
                         foreach ($_FILES as $file) {
                             $ok = $this->try_upload($file, $tags, $source, $image_id);
                             break;
                             // leave the foreach loop.
                         }
                     } else {
                         foreach ($_POST as $name => $value) {
                             if (substr($name, 0, 3) == "url" && strlen($value) > 0) {
                                 $ok = $this->try_transload($value, $tags, $source, $image_id);
                                 break;
                                 // leave the foreach loop.
                             }
                         }
                     }
                     $this->theme->display_upload_status($page, $ok);
                 } else {
                     if (!empty($_GET['url'])) {
                         $url = $_GET['url'];
                         $ok = $this->try_transload($url, $tags, $url, $image_id);
                         $this->theme->display_upload_status($page, $ok);
                     } else {
                         $this->theme->display_replace_page($page, $image_id);
                     }
                 }
             }
             // END of if admin / can_upload
         } else {
             if ($event->page_matches("upload")) {
                 if (!$this->can_upload($user)) {
                     $this->theme->display_permission_denied($page);
                 } else {
                     /* Regular Upload Image */
                     if (count($_FILES) + count($_POST) > 0) {
                         $tags = Tag::explode($_POST['tags']);
                         $source = isset($_POST['source']) ? $_POST['source'] : null;
                         $ok = true;
                         foreach ($_FILES as $file) {
                             $ok = $ok & $this->try_upload($file, $tags, $source);
                         }
                         foreach ($_POST as $name => $value) {
                             if (substr($name, 0, 3) == "url" && strlen($value) > 0) {
                                 $ok = $ok & $this->try_transload($value, $tags, $source);
                             }
                         }
                         $this->theme->display_upload_status($page, $ok);
                     } else {
                         if (!empty($_GET['url'])) {
                             $url = $_GET['url'];
                             $tags = array('tagme');
                             if (!empty($_GET['tags']) && $_GET['tags'] != "null") {
                                 $tags = Tag::explode($_GET['tags']);
                             }
                             $ok = $this->try_transload($url, $tags, $url);
                             $this->theme->display_upload_status($page, $ok);
                         } else {
                             if (!$is_full) {
                                 $this->theme->display_page($page);
                             }
                         }
                     }
                 }
                 // END of if  can_upload
             }
         }
     }
     // END of if PageRequestEvent
     if ($event instanceof SetupBuildingEvent) {
         $tes = array();
         $tes["Disabled"] = "none";
         if (function_exists("curl_init")) {
             $tes["cURL"] = "curl";
         }
         $tes["fopen"] = "fopen";
         $tes["WGet"] = "wget";
         $sb = new SetupBlock("Upload");
         $sb->position = 10;
         // Output the limits from PHP so the user has an idea of what they can set.
         $sb->add_label("<i>PHP's Upload Limit = " . ini_get('max_file_uploads') . "</i><br/>");
         $sb->add_int_option("upload_count", "Max uploads: ");
         $sb->add_label("<br/><i>PHP's Max Size Upload = " . ini_get('upload_max_filesize') . "</i><br/>");
         $sb->add_shorthand_int_option("upload_size", "<br/>Max size per file: ");
         $sb->add_bool_option("upload_anon", "<br/>Allow anonymous uploads: ");
         $sb->add_bool_option("upload_replace", "<br/>Allow replacing images: ");
         $sb->add_choice_option("transload_engine", $tes, "<br/>Transload: ");
         $event->panel->add_block($sb);
     }
     if ($event instanceof DataUploadEvent) {
         if ($is_full) {
             throw new UploadException("Upload failed; disk nearly full");
         }
         if (filesize($event->tmpname) > $config->get_int('upload_size')) {
             $size = to_shorthand_int(filesize($event->tmpname));
             $limit = to_shorthand_int($config->get_int('upload_size'));
             throw new UploadException("File too large ({$size} &gt; {$limit})");
         }
     }
 }
Beispiel #19
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_numeric_score_version", 0) < 1) {
             $this->install();
         }
     }
     if ($event instanceof DisplayingImageEvent) {
         if (!$user->is_anonymous()) {
             $html = $this->theme->get_voter_html($event->image);
             $page->add_block(new Block("Image Score", $html, "left", 20));
         }
     }
     if ($event instanceof PageRequestEvent && $event->page_matches("numeric_score_vote")) {
         if (!$user->is_anonymous()) {
             $image_id = int_escape($_POST['image_id']);
             $char = $_POST['vote'];
             $score = 0;
             if ($char == "up") {
                 $score = 1;
             } else {
                 if ($char == "down") {
                     $score = -1;
                 }
             }
             if ($score != 0) {
                 send_event(new NumericScoreSetEvent($image_id, $user, $score));
             }
             $page->set_mode("redirect");
             $page->set_redirect(make_link("post/view/{$image_id}"));
         }
     }
     if ($event instanceof NumericScoreSetEvent) {
         $this->add_vote($event->image_id, $user->id, $event->score);
     }
     if ($event instanceof ImageDeletionEvent) {
         $database->execute("DELETE FROM numeric_score_votes WHERE image_id=?", array($event->image->id));
     }
     if ($event instanceof ParseLinkTemplateEvent) {
         $event->replace('$score', $event->image->numeric_score);
     }
     if ($event instanceof SearchTermParseEvent) {
         $matches = array();
         if (preg_match("/^score(<|<=|=|>=|>)(\\d+)\$/", $event->term, $matches)) {
             $cmp = $matches[1];
             $score = $matches[2];
             $event->add_querylet(new Querylet("numeric_score {$cmp} {$score}"));
         }
         if (preg_match("/^upvoted_by=(.*)\$/", $event->term, $matches)) {
             $duser = User::by_name($matches[1]);
             if (is_null($duser)) {
                 throw new SearchTermParseException("Can't find the user named " . html_escape($matches[1]));
             }
             $event->add_querylet(new Querylet("images.id in (SELECT image_id FROM numeric_score_votes WHERE user_id=? AND score=1)", array($duser->id)));
         }
         if (preg_match("/^downvoted_by=(.*)\$/", $event->term, $matches)) {
             $duser = User::by_name($matches[1]);
             if (is_null($duser)) {
                 throw new SearchTermParseException("Can't find the user named " . html_escape($matches[1]));
             }
             $event->add_querylet(new Querylet("images.id in (SELECT image_id FROM numeric_score_votes WHERE user_id=? AND score=-1)", array($duser->id)));
         }
     }
 }
Beispiel #20
0
 public function receive_event(Event $event)
 {
     global $config, $database, $page, $user;
     if ($this->theme == null) {
         $this->theme = get_theme_object($this);
     }
     if ($event instanceof InitExtEvent) {
         $config->set_default_int("tag_list_length", 15);
         $config->set_default_int("popular_tag_list_length", 15);
         $config->set_default_int("tags_min", 3);
         $config->set_default_string("info_link", 'http://en.wikipedia.org/wiki/$tag');
         $config->set_default_string("tag_list_image_type", 'related');
         $config->set_default_bool("tag_list_pages", false);
     }
     if ($event instanceof PageRequestEvent && $event->page_matches("tags")) {
         $this->theme->set_navigation($this->build_navigation());
         switch ($event->get_arg(0)) {
             default:
             case 'map':
                 $this->theme->set_heading("Tag Map");
                 $this->theme->set_tag_list($this->build_tag_map());
                 break;
             case 'alphabetic':
                 $this->theme->set_heading("Alphabetic Tag List");
                 $this->theme->set_tag_list($this->build_tag_alphabetic());
                 break;
             case 'popularity':
                 $this->theme->set_heading("Tag List by Popularity");
                 $this->theme->set_tag_list($this->build_tag_popularity());
                 break;
             case 'categories':
                 $this->theme->set_heading("Popular Categories");
                 $this->theme->set_tag_list($this->build_tag_categories());
                 break;
         }
         $this->theme->display_page($page);
     }
     if ($event instanceof PageRequestEvent && $event->page_matches("api/internal/tag_list/complete")) {
         $all = $database->get_all("SELECT tag FROM tags WHERE tag LIKE :search AND count > 0 LIMIT 10", array("search" => $_GET["s"] . "%"));
         $res = array();
         foreach ($all as $row) {
             $res[] = $row["tag"];
         }
         $page->set_mode("data");
         $page->set_type("text/plain");
         $page->set_data(implode("\n", $res));
     }
     if ($event instanceof PostListBuildingEvent) {
         if ($config->get_int('tag_list_length') > 0) {
             if (!empty($event->search_terms)) {
                 $this->add_refine_block($page, $event->search_terms);
             } else {
                 $this->add_popular_block($page);
             }
         }
     }
     if ($event instanceof DisplayingImageEvent) {
         if ($config->get_int('tag_list_length') > 0) {
             if ($config->get_string('tag_list_image_type') == 'related') {
                 $this->add_related_block($page, $event->image);
             } else {
                 $this->add_tags_block($page, $event->image);
             }
         }
     }
     if ($event instanceof SetupBuildingEvent) {
         $sb = new SetupBlock("Tag Map Options");
         $sb->add_int_option("tags_min", "Only show tags used at least ");
         $sb->add_label(" times");
         $sb->add_bool_option("tag_list_pages", "<br>Paged tag lists: ");
         $event->panel->add_block($sb);
         $sb = new SetupBlock("Popular / Related Tag List");
         $sb->add_int_option("tag_list_length", "Show top ");
         $sb->add_label(" related tags");
         $sb->add_int_option("popular_tag_list_length", "<br>Show top ");
         $sb->add_label(" popular tags");
         $sb->add_text_option("info_link", "<br>Tag info link: ");
         $sb->add_choice_option("tag_list_image_type", array("Image's tags only" => "tags", "Show related" => "related"), "<br>Image tag list: ");
         $sb->add_bool_option("tag_list_numbers", "<br>Show tag counts: ");
         $event->panel->add_block($sb);
     }
 }
Beispiel #21
0
 public function receive_event(Event $event)
 {
     if (is_null($this->theme)) {
         $this->theme = get_theme_object($this);
     }
     if ($event instanceof DataUploadEvent && $this->supported_ext($event->type) && $this->check_contents($event->tmpname)) {
         if (!move_upload_to_archive($event)) {
             return;
         }
         send_event(new ThumbnailGenerationEvent($event->hash, $event->type));
         /* Check if we are replacing an image */
         if (array_key_exists('replace', $event->metadata) && isset($event->metadata['replace'])) {
             /* hax: This seems like such a dirty way to do this.. */
             /* Validate things */
             $image_id = int_escape($event->metadata['replace']);
             /* Check to make sure the image exists. */
             $existing = Image::by_id($image_id);
             if (is_null($existing)) {
                 throw new UploadException("Image to replace does not exist!");
             }
             if ($existing->hash === $event->metadata['hash']) {
                 throw new UploadException("The uploaded image is the same as the one to replace.");
             }
             // even more hax..
             $event->metadata['tags'] = $existing->get_tag_list();
             $image = $this->create_image_from_data(warehouse_path("images", $event->metadata['hash']), $event->metadata);
             if (is_null($image)) {
                 throw new UploadException("Data handler failed to create image object from data");
             }
             $ire = new ImageReplaceEvent($image_id, $image);
             send_event($ire);
             $event->image_id = $image_id;
         } else {
             $image = $this->create_image_from_data(warehouse_path("images", $event->hash), $event->metadata);
             if (is_null($image)) {
                 throw new UploadException("Data handler failed to create image object from data");
             }
             $iae = new ImageAdditionEvent($event->user, $image);
             send_event($iae);
             $event->image_id = $iae->image->id;
             // Rating Stuff.
             if (!empty($event->metadata['rating'])) {
                 global $user;
                 $rating = $event->metadata['rating'];
                 send_event(new RatingSetEvent($image, $user, $rating));
             }
             // Locked Stuff.
             if (!empty($event->metadata['locked'])) {
                 $locked = $event->metadata['locked'];
                 send_event(new LockSetEvent($image, !empty($locked)));
             }
         }
     }
     if ($event instanceof ThumbnailGenerationEvent && $this->supported_ext($event->type)) {
         $this->create_thumb($event->hash);
     }
     if ($event instanceof DisplayingImageEvent && $this->supported_ext($event->image->ext)) {
         global $page;
         $this->theme->display_image($page, $event->image);
     }
     if ($event instanceof SetupBuildingEvent) {
         $sb = $this->setup();
         if ($sb) {
             $event->panel->add_block($sb);
         }
     }
 }
Beispiel #22
0
 public function receive_event(Event $event)
 {
     if (is_null($this->theme)) {
         $this->theme = get_theme_object($this);
     }
     if ($event instanceof DataUploadEvent && $this->supported_ext($event->type) && $this->check_contents($event->tmpname)) {
         if (!move_upload_to_archive($event)) {
             return;
         }
         send_event(new ThumbnailGenerationEvent($event->hash, $event->type));
         $image = $this->create_image_from_data(warehouse_path("images", $event->hash), $event->metadata);
         if (is_null($image)) {
             throw new UploadException("Data handler failed to create image object from data");
         }
         $iae = new ImageAdditionEvent($event->user, $image);
         send_event($iae);
         $event->image_id = $iae->image->id;
     }
     if ($event instanceof ThumbnailGenerationEvent && $this->supported_ext($event->type)) {
         $this->create_thumb($event->hash);
     }
     if ($event instanceof DisplayingImageEvent && $this->supported_ext($event->image->ext)) {
         global $page;
         $this->theme->display_image($page, $event->image);
     }
 }
Beispiel #23
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));
         }
     }
 }