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")); } } }
public function onPageRequest(Event $event) { global $config, $database, $page, $user; // user info is shown on all pages if ($user->is_anonymous()) { $this->theme->display_login_block($page); } else { $ubbe = new UserBlockBuildingEvent(); send_event($ubbe); ksort($ubbe->parts); $this->theme->display_user_block($page, $user, $ubbe->parts); } if ($event->page_matches("user_admin")) { if ($event->get_arg(0) == "login") { if (isset($_POST['user']) && isset($_POST['pass'])) { $this->login($page); } else { $this->theme->display_login_page($page); } } else { if ($event->get_arg(0) == "logout") { set_prefixed_cookie("session", "", time() + 60 * 60 * 24 * $config->get_int('login_memory'), "/"); if (CACHE_HTTP) { # to keep as few versions of content as possible, # make cookies all-or-nothing set_prefixed_cookie("user", "", time() + 60 * 60 * 24 * $config->get_int('login_memory'), "/"); } log_info("user", "Logged out"); $page->set_mode("redirect"); $page->set_redirect(make_link()); } else { if ($event->get_arg(0) == "change_pass") { $this->change_password_wrapper($page); } else { if ($event->get_arg(0) == "change_email") { $this->change_email_wrapper($page); } else { if ($event->get_arg(0) == "recover") { $user = User::by_name($_POST['username']); if (is_null($user)) { $this->theme->display_error($page, "Error", "There's no user with that name"); } if (is_null($user->email)) { // } } else { if ($event->get_arg(0) == "create") { if (!$config->get_bool("login_signup_enabled")) { $this->theme->display_signups_disabled($page); } else { if (!isset($_POST['name'])) { $this->theme->display_signup_page($page); } else { if ($_POST['pass1'] != $_POST['pass2']) { $this->theme->display_error($page, "Password Mismatch", "Passwords don't match"); } else { try { if (!captcha_check()) { throw new UserCreationException("Error in captcha"); } $uce = new UserCreationEvent($_POST['name'], $_POST['pass1'], $_POST['email']); send_event($uce); $this->set_login_cookie($uce->username, $uce->password); $page->set_mode("redirect"); $page->set_redirect(make_link("user")); } catch (UserCreationException $ex) { $this->theme->display_error($page, "User Creation Error", $ex->getMessage()); } } } } } else { if ($event->get_arg(0) == "set_more") { $this->set_more_wrapper($page); } else { if ($event->get_arg(0) == "list") { // select users.id,name,joindate,admin, // (select count(*) from images where images.owner_id=users.id) as images, // (select count(*) from comments where comments.owner_id=users.id) as comments from users; // select users.id,name,joindate,admin,image_count,comment_count // from users // join (select owner_id,count(*) as image_count from images group by owner_id) as _images on _images.owner_id=users.id // join (select owner_id,count(*) as comment_count from comments group by owner_id) as _comments on _comments.owner_id=users.id; $this->theme->display_user_list($page, User::by_list(0), $user); } } } } } } } } } if ($event instanceof PageRequestEvent && $event->page_matches("user")) { $display_user = $event->count_args() == 0 ? $user : User::by_name($event->get_arg(0)); if ($event->count_args() == 0 && $user->is_anonymous()) { $this->theme->display_error($page, "Not Logged In", "You aren't logged in. First do that, then you can see your stats."); } else { if (!is_null($display_user)) { send_event(new UserPageBuildingEvent($display_user)); } else { $this->theme->display_error($page, "No Such User", "If you typed the ID by hand, try again; if you came from a link on this " . "site, it might be bug report time..."); } } } }
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)); } } }