/** * Returns info about the current page number. * * @param PageRequestEvent $event * @return array */ private function get_list_pageinfo(PageRequestEvent $event) { global $config, $database; // get the amount of images per page $images_per_page = $config->get_int('index_images'); // if there are no tags, use default if (is_null($event->get_arg(1))) { $prefix = ""; $page_number = int_escape($event->get_arg(0)); $total_pages = ceil($database->get_one("SELECT COUNT(*) FROM images") / $images_per_page); } else { // if there are tags, use pages with tags $prefix = url_escape($event->get_arg(0)) . "/"; $page_number = int_escape($event->get_arg(1)); $total_pages = ceil($database->get_one("SELECT count FROM tags WHERE tag=:tag", array("tag" => $event->get_arg(0))) / $images_per_page); } // creates previous & next values // When previous first page, go to last page if ($page_number <= 1) { $prev = $total_pages; } else { $prev = $page_number - 1; } if ($page_number >= $total_pages) { $next = 1; } else { $next = $page_number + 1; } // Create return array $pageinfo = array("prev" => $prefix . $prev, "next" => $prefix . $next); return $pageinfo; }
public function onPageRequest(PageRequestEvent $event) { global $page, $user; if ($event->page_matches("source_history/revert")) { // this is a request to revert to a previous version of the source if ($user->can("edit_image_tag")) { if (isset($_POST['revert'])) { $this->process_revert_request($_POST['revert']); } } } else { if ($event->page_matches("source_history/bulk_revert")) { if ($user->can("bulk_edit_image_tag") && $user->check_auth_token()) { $this->process_bulk_revert_request(); } } else { if ($event->page_matches("source_history/all")) { $page_id = int_escape($event->get_arg(0)); $this->theme->display_global_page($page, $this->get_global_source_history($page_id), $page_id); } else { if ($event->page_matches("source_history") && $event->count_args() == 1) { // must be an attempt to view a source history $image_id = int_escape($event->get_arg(0)); $this->theme->display_history_page($page, $image_id, $this->get_source_history_from_id($image_id)); } } } } }
public function onPageRequest(PageRequestEvent $event) { global $page, $user; $this->getTip(); if ($event->page_matches("tips") && $user->is_admin()) { switch ($event->get_arg(0)) { case "list": $this->manageTips(); $this->getAll(); break; case "save": if ($user->check_auth_token()) { $this->saveTip(); $page->set_mode("redirect"); $page->set_redirect(make_link("tips/list")); } break; case "status": // FIXME: HTTP GET CSRF $tipID = int_escape($event->get_arg(1)); $this->setStatus($tipID); $page->set_mode("redirect"); $page->set_redirect(make_link("tips/list")); break; case "delete": // FIXME: HTTP GET CSRF $tipID = int_escape($event->get_arg(1)); $this->deleteTip($tipID); $page->set_mode("redirect"); $page->set_redirect(make_link("tips/list")); break; } } }
public function onPageRequest(PageRequestEvent $event) { global $config, $page, $user; if ($event->page_matches("featured_image")) { if ($event->get_arg(0) == "set" && $user->check_auth_token()) { if ($user->can("edit_feature") && isset($_POST['image_id'])) { $id = int_escape($_POST['image_id']); if ($id > 0) { $config->set_int("featured_id", $id); log_info("featured", "Featured image set to {$id}", "Featured image set"); $page->set_mode("redirect"); $page->set_redirect(make_link("post/view/{$id}")); } } } if ($event->get_arg(0) == "download") { $image = Image::by_id($config->get_int("featured_id")); if (!is_null($image)) { $page->set_mode("data"); $page->set_type($image->get_mime_type()); $page->set_data(file_get_contents($image->get_image_filename())); } } if ($event->get_arg(0) == "view") { $image = Image::by_id($config->get_int("featured_id")); if (!is_null($image)) { send_event(new DisplayingImageEvent($image, $page)); } } } }
public function onPageRequest(PageRequestEvent $event) { global $database, $page, $user; if ($event->page_matches("untag")) { if ($user->can("ban_image")) { if ($event->get_arg(0) == "add") { $tag = $_POST["tag"]; $redirect = isset($_POST['redirect']) ? $_POST['redirect'] : "DNP"; $database->Execute("INSERT INTO untags(tag, redirect) VALUES (?, ?)", array($tag, $redirect)); $page->set_mode("redirect"); $page->set_redirect($_SERVER['HTTP_REFERER']); } else { if ($event->get_arg(0) == "remove") { if (isset($_POST['tag'])) { $database->Execute("DELETE FROM untags WHERE tag = ?", array($_POST['tag'])); flash_message("Image ban removed"); $page->set_mode("redirect"); $page->set_redirect($_SERVER['HTTP_REFERER']); } } 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->get_one("SELECT COUNT(tag) FROM untags") / $page_size); $this->theme->display_untags($page, $page_num, $page_count, $this->get_untags($page_num, $page_size)); } } } } } }
public function onPageRequest(PageRequestEvent $event) { global $page, $user; if ($event->page_matches("api/shimmie")) { $page->set_mode("data"); $page->set_type("text/plain"); if ($event->page_matches("api/shimmie/get_tags")) { $tag = $event->get_arg(0); if (empty($tag) && isset($_GET['tag'])) { $tag = $_GET['tag']; } $res = $this->api_get_tags($tag); $page->set_data(json_encode($res)); } elseif ($event->page_matches("api/shimmie/get_image")) { $arg = $event->get_arg(0); if (empty($arg) && isset($_GET['id'])) { $arg = $_GET['id']; } $image = Image::by_id(int_escape($arg)); // FIXME: handle null image $image->get_tag_array(); // tag data isn't loaded into the object until necessary $safe_image = new _SafeImage($image); $page->set_data(json_encode($safe_image)); } elseif ($event->page_matches("api/shimmie/find_images")) { $search_terms = $event->get_search_terms(); $page_number = $event->get_page_number(); $page_size = $event->get_page_size(); $images = Image::find_images(($page_number - 1) * $page_size, $page_size, $search_terms); $safe_images = array(); foreach ($images as $image) { $image->get_tag_array(); $safe_images[] = new _SafeImage($image); } $page->set_data(json_encode($safe_images)); } elseif ($event->page_matches("api/shimmie/get_user")) { $query = $user->id; $type = "id"; if ($event->count_args() == 1) { $query = $event->get_arg(0); $type = "name"; } elseif (isset($_GET['id'])) { $query = $_GET['id']; } elseif (isset($_GET['name'])) { $query = $_GET['name']; $type = "name"; } $all = $this->api_get_user($type, $query); $page->set_data(json_encode($all)); } else { $page->set_mode("redirect"); $page->set_redirect(make_link("ext_doc/shimmie_api")); } } }
public function onPageRequest(PageRequestEvent $event) { global $config, $database, $page, $user; if ($event->page_matches("image_hash_ban")) { if ($user->is_admin()) { if ($event->get_arg(0) == "dnp") { $image = Image::by_id(int_escape($event->get_arg(1))); if ($image) { send_event(new AddImageHashBanEvent($image->hash, "DNP")); send_event(new ImageDeletionEvent($image)); } $page->set_mode("redirect"); $page->set_redirect($_SERVER["HTTP_REFERER"]); } else { 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->get_one("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)); } } } } } } }
public function onPageRequest(PageRequestEvent $event) { global $page, $user; if ($event->page_matches("admin")) { if (!$user->can("manage_admintools")) { $this->theme->display_permission_denied(); } else { if ($event->count_args() == 0) { send_event(new AdminBuildingEvent($page)); } else { $action = $event->get_arg(0); $aae = new AdminActionEvent($action); if ($user->check_auth_token()) { log_info("admin", "Util: {$action}"); set_time_limit(0); send_event($aae); } if ($aae->redirect) { $page->set_mode("redirect"); $page->set_redirect(make_link("admin")); } } } } }
public function onPageRequest(PageRequestEvent $event) { global $page; if ($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")); } } } } }
public function onPageRequest(PageRequestEvent $event) { global $database, $page, $user; $blocks = $database->cache->get("blocks"); if ($blocks === false) { $blocks = $database->get_all("SELECT * FROM blocks"); $database->cache->set("blocks", $blocks, 600); } foreach ($blocks as $block) { if (fnmatch($block['pages'], implode("/", $event->args))) { $page->add_block(new Block($block['title'], $block['content'], $block['area'], $block['priority'])); } } if ($event->page_matches("blocks") && $user->can("manage_blocks")) { if ($event->get_arg(0) == "add") { if ($user->check_auth_token()) { $database->execute("\n\t\t\t\t\t\tINSERT INTO blocks (pages, title, area, priority, content)\n\t\t\t\t\t\tVALUES (?, ?, ?, ?, ?)\n\t\t\t\t\t", array($_POST['pages'], $_POST['title'], $_POST['area'], (int) $_POST['priority'], $_POST['content'])); log_info("blocks", "Added Block #" . $database->get_last_insert_id('blocks_id_seq') . " (" . $_POST['title'] . ")"); $database->cache->delete("blocks"); $page->set_mode("redirect"); $page->set_redirect(make_link("blocks/list")); } } if ($event->get_arg(0) == "update") { if ($user->check_auth_token()) { if (!empty($_POST['delete'])) { $database->execute("\n\t\t\t\t\t\t\tDELETE FROM blocks\n\t\t\t\t\t\t\tWHERE id=?\n\t\t\t\t\t\t", array($_POST['id'])); log_info("blocks", "Deleted Block #" . $_POST['id']); } else { $database->execute("\n\t\t\t\t\t\t\tUPDATE blocks SET pages=?, title=?, area=?, priority=?, content=?\n\t\t\t\t\t\t\tWHERE id=?\n\t\t\t\t\t\t", array($_POST['pages'], $_POST['title'], $_POST['area'], (int) $_POST['priority'], $_POST['content'], $_POST['id'])); log_info("blocks", "Updated Block #" . $_POST['id'] . " (" . $_POST['title'] . ")"); } $database->cache->delete("blocks"); $page->set_mode("redirect"); $page->set_redirect(make_link("blocks/list")); } } else { if ($event->get_arg(0) == "list") { $this->theme->display_blocks($database->get_all("SELECT * FROM blocks ORDER BY area, priority")); } } } }
public function onPageRequest(PageRequestEvent $event) { global $page, $user; if ($event->page_matches("image_report")) { if ($event->get_arg(0) == "add") { if (!empty($_POST['image_id']) && !empty($_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 { $this->theme->display_error(500, "Missing input", "Missing image ID or report reason"); } } else { if ($event->get_arg(0) == "remove") { if (!empty($_POST['id'])) { if ($user->can("view_image_report")) { send_event(new RemoveReportedImageEvent($_POST['id'])); $page->set_mode("redirect"); $page->set_redirect(make_link("image_report/list")); } } else { $this->theme->display_error(500, "Missing input", "Missing image ID"); } } else { if ($event->get_arg(0) == "remove_reports_by" && $user->check_auth_token()) { if ($user->can("view_image_report")) { $this->delete_reports_by(int_escape($_POST['user_id'])); $page->set_mode("redirect"); $page->set_redirect(make_link()); } } else { if ($event->get_arg(0) == "list") { if ($user->can("view_image_report")) { $this->theme->display_reported_images($page, $this->get_reported_images()); } } } } } } }
public function onPageRequest(PageRequestEvent $event) { global $config, $database, $page, $user; if ($event->page_matches("image_hash_ban")) { if ($user->can("ban_image")) { if ($event->get_arg(0) == "add") { $image = isset($_POST['image_id']) ? Image::by_id(int_escape($_POST['image_id'])) : null; $hash = isset($_POST["hash"]) ? $_POST["hash"] : $image->hash; $reason = isset($_POST['reason']) ? $_POST['reason'] : "DNP"; if ($hash) { send_event(new AddImageHashBanEvent($hash, $reason)); flash_message("Image ban added"); if ($image) { send_event(new ImageDeletionEvent($image)); flash_message("Image deleted"); } $page->set_mode("redirect"); $page->set_redirect($_SERVER['HTTP_REFERER']); } } else { if ($event->get_arg(0) == "remove") { if (isset($_POST['hash'])) { send_event(new RemoveImageHashBanEvent($_POST['hash'])); flash_message("Image ban removed"); $page->set_mode("redirect"); $page->set_redirect($_SERVER['HTTP_REFERER']); } } 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->get_one("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)); } } } } } }
private function api_danbooru(PageRequestEvent $event) { global $page; $page->set_mode("data"); if ($event->get_arg(1) == 'add_post' || $event->get_arg(1) == 'post' && $event->get_arg(2) == 'create.xml') { // No XML data is returned from this function $page->set_type("text/plain"); $this->api_add_post(); } elseif ($event->get_arg(1) == 'find_posts' || $event->get_arg(1) == 'post' && $event->get_arg(2) == 'index.xml') { $page->set_type("application/xml"); $page->set_data($this->api_find_posts()); } elseif ($event->get_arg(1) == 'find_tags') { $page->set_type("application/xml"); $page->set_data($this->api_find_tags()); } elseif ($event->get_arg(1) == 'post' && $event->get_arg(2) == 'show') { $fixedlocation = make_link("post/view/" . $event->get_arg(3)); $page->set_mode("redirect"); $page->set_redirect($fixedlocation); } }
public function onPageRequest(PageRequestEvent $event) { global $user; if ($event->page_matches("bulk_remove") && $user->is_admin() && $user->check_auth_token()) { if ($event->get_arg(0) == "confirm") { $this->do_bulk_remove(); } else { $this->show_confirm(); } } }
public function onPageRequest(PageRequestEvent $event) { global $config, $database, $page; if ($event->page_matches("get_svg")) { $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))); } }
public function onPageRequest(PageRequestEvent $event) { global $page; if ($event->page_matches("random_image")) { $action = ''; if ($event->count_args() == 1) { $action = $event->get_arg(0); $search_terms = array(); } else { if ($event->count_args() == 2) { $action = $event->get_arg(0); $search_terms = explode(' ', $event->get_arg(1)); } else { throw new SCoreException("Error: too many arguments."); } } $image = Image::by_random($search_terms); if ($action === "download") { if (!is_null($image)) { $page->set_mode("data"); $page->set_type($image->get_mime_type()); $page->set_data(file_get_contents($image->get_image_filename())); } } else { if ($action === "view") { if (!is_null($image)) { send_event(new DisplayingImageEvent($image, $page)); } } else { if ($action === "widget") { if (!is_null($image)) { $page->set_mode("data"); $page->set_type("text/html"); $page->set_data($this->theme->build_thumb_html($image)); } } } } } }
public function onPageRequest(PageRequestEvent $event) { global $page; if ($event->page_matches("get_ico")) { $id = int_escape($event->get_arg(0)); $image = Image::by_id($id); $hash = $image->hash; $ha = substr($hash, 0, 2); $page->set_type("image/x-icon"); $page->set_mode("data"); $page->set_data(file_get_contents("images/{$ha}/{$hash}")); } }
public function onPageRequest(PageRequestEvent $event) { global $database, $page; if ($event->page_matches("api/shimmie")) { $page->set_mode("data"); $page->set_type("text/plain"); if ($event->page_matches("api/shimmie/get_tags")) { if ($event->count_args() == 2) { $all = $database->get_all("SELECT tag FROM tags WHERE tag LIKE ?", array($event->get_arg(0) . "%")); } else { $all = $database->get_all("SELECT tag FROM tags"); } $res = array(); foreach ($all as $row) { $res[] = $row["tag"]; } $page->set_data(json_encode($res)); } if ($event->page_matches("api/shimmie/get_image")) { $image = Image::by_id(int_escape($event->get_arg(0))); $image->get_tag_array(); // tag data isn't loaded into the object until necessary $safe_image = new _SafeImage($image); $page->set_data(json_encode($safe_image)); } if ($event->page_matches("api/shimmie/find_images")) { $search_terms = $event->get_search_terms(); $page_number = $event->get_page_number(); $page_size = $event->get_page_size(); $images = Image::find_images(($page_number - 1) * $page_size, $page_size, $search_terms); $safe_images = array(); foreach ($images as $image) { $image->get_tag_array(); $safe_images[] = new _SafeImage($image); } $page->set_data(json_encode($safe_images)); } } }
public function onPageRequest(PageRequestEvent $event) { if ($event->page_matches("ip_ban")) { global $config, $database, $page, $user; if ($user->can("ban_ip")) { 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)); flash_message("Ban for {$_POST['ip']} added"); $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'])); flash_message("Ban removed"); $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(); } } }
public function onPageRequest(PageRequestEvent $event) { if ($event->page_matches("tagger/tags")) { global $page; //$match_tags = null; //$image_tags = null; $tags = null; if (isset($_GET['s'])) { // tagger/tags[/...]?s=$string // return matching tags in XML form $tags = $this->match_tag_list($_GET['s']); } else { if ($event->get_arg(0)) { // tagger/tags/$int // return arg[1] AS image_id's tag list in XML form $tags = $this->image_tag_list($event->get_arg(0)); } } $xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" . "<tags>" . $tags . "</tags>"; $page->set_mode("data"); $page->set_type("text/xml"); $page->set_data($xml); } }
public function onPageRequest(PageRequestEvent $event) { global $config, $database, $page; // Add in header code to let the browser know that the search plugin exists // We need to build the data for the header $search_title = $config->get_string('title'); $search_file_url = make_link('browser_search/please_dont_use_this_tag_as_it_would_break_stuff__search.xml'); $page->add_html_header("<link rel='search' type='application/opensearchdescription+xml' title='{$search_title}' href='{$search_file_url}'>"); // The search.xml file that is generated on the fly if ($event->page_matches("browser_search/please_dont_use_this_tag_as_it_would_break_stuff__search.xml")) { // First, we need to build all the variables we'll need $search_title = $config->get_string('title'); $search_form_url = make_link('post/list/{searchTerms}'); $suggenton_url = make_link('browser_search/') . "{searchTerms}"; $icon_b64 = base64_encode(file_get_contents("lib/static/favicon.ico")); // Now for the XML $xml = "\n\t\t\t\t<SearchPlugin xmlns='http://www.mozilla.org/2006/browser/search/' xmlns:os='http://a9.com/-/spec/opensearch/1.1/'>\n\t\t\t\t<os:ShortName>{$search_title}</os:ShortName>\n\t\t\t\t<os:InputEncoding>UTF-8</os:InputEncoding>\n\t\t\t\t<os:Image width='16' height='16'>data:image/x-icon;base64,{$icon_b64}</os:Image>\n\t\t\t\t<SearchForm>{$search_form_url}</SearchForm>\n\t\t\t\t<os:Url type='text/html' method='GET' template='{$search_form_url}'>\n\t\t\t\t <os:Param name='search' value='{searchTerms}'/>\n\t\t\t\t</os:Url>\n\t\t\t\t<Url type='application/x-suggestions+json' template='{$suggenton_url}'/>\n\t\t\t\t</SearchPlugin>\n\t\t\t"; // And now to send it to the browser $page->set_mode("data"); $page->set_type("text/xml"); $page->set_data($xml); } else { if ($event->page_matches("browser_search") && !$config->get_bool("disable_search_suggestions")) { // We have to build some json stuff $tag_search = $event->get_arg(0); // Now to get DB results if ($config->get_string("search_suggestions_results_order") == "a") { $tags = $database->execute("SELECT tag FROM tags WHERE tag LIKE ? AND count > 0 ORDER BY tag ASC LIMIT 30", array($tag_search . "%")); } else { $tags = $database->execute("SELECT tag FROM tags WHERE tag LIKE ? AND count > 0 ORDER BY count DESC LIMIT 30", array($tag_search . "%")); } // And to do stuff with it. We want our output to look like: // ["shimmie",["shimmies","shimmy","shimmie","21 shimmies","hip shimmies","skea shimmies"],[],[]] $json_tag_list = ""; $tags_array = array(); foreach ($tags as $tag) { array_push($tags_array, $tag['tag']); } $json_tag_list .= implode("\",\"", $tags_array); // And now for the final output $json_string = "[\"{$tag_search}\",[\"{$json_tag_list}\"],[],[]]"; $page->set_mode("data"); $page->set_data($json_string); } } }
public function onPageRequest(PageRequestEvent $event) { global $page, $user; if ($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->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->page_matches("post/set")) { $image_id = int_escape($_POST['image_id']); send_event(new ImageInfoSetEvent(Image::by_id($image_id))); $page->set_mode("redirect"); $page->set_redirect(make_link("post/view/{$image_id}", url_escape($_POST['query']))); } }
/** * Checks if the cron upload page has been accessed * and initializes the upload. * @param PageRequestEvent $event */ public function onPageRequest(PageRequestEvent $event) { global $config, $user; if ($event->page_matches("cron_upload")) { $this->upload_key = $config->get_string("cron_uploader_key", ""); // If the key is in the url, upload if ($this->upload_key != "" && $event->get_arg(0) == $this->upload_key) { // log in as admin $this->process_upload(); // Start upload } else { if ($user->is_admin()) { $this->set_dir(); $this->display_documentation(); } } } }
public function onPageRequest(PageRequestEvent $event) { global $page, $database; if ($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_list()); break; } $this->theme->display_page($page); } else { if ($event->page_matches("api/internal/tag_list/complete")) { if (!isset($_GET["s"])) { return; } //$limit = 0; $limitSQL = ""; $SQLarr = array("search" => $_GET["s"] . "%"); if (isset($_GET["limit"]) && $_GET["limit"] !== 0) { $limitSQL = "LIMIT :limit"; $SQLarr['limit'] = $_GET["limit"]; } $res = $database->get_col("SELECT tag FROM tags WHERE tag LIKE :search AND count > 0 {$limitSQL}", $SQLarr); $page->set_mode("data"); $page->set_type("text/plain"); $page->set_data(implode("\n", $res)); } } }
public function onPageRequest(PageRequestEvent $event) { global $page, $user; if ($event->page_matches("rotate") && $user->is_admin()) { // 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 ImageRotateException("Can not rotate Image: No valid Image ID given."); } $image = Image::by_id($image_id); if (is_null($image)) { $this->theme->display_error(404, "Image not found", "No image in the database has the ID #{$image_id}"); } else { /* Check if options were given to rotate an image. */ if (isset($_POST['rotate_deg'])) { /* get options */ $deg = 0; if (isset($_POST['rotate_deg'])) { $deg = int_escape($_POST['rotate_deg']); } /* Attempt to rotate the image */ try { $this->rotate_image($image_id, $deg); //$this->theme->display_rotate_page($page, $image_id); $page->set_mode("redirect"); $page->set_redirect(make_link("post/view/" . $image_id)); } catch (ImageRotateException $e) { $this->theme->display_rotate_error($page, "Error Rotating", $e->error); } } } } }
public function onPageRequest(PageRequestEvent $event) { global $page, $user; if ($event->page_matches("upload/replace")) { // check if the user is an administrator and can upload files. if (!$user->can("replace_image")) { $this->theme->display_permission_denied(); } else { if ($this->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(404, "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']; $source = isset($_GET['source']) ? $_GET['source'] : $url; $ok = $this->try_transload($url, $tags, $source, $image_id); $this->theme->display_upload_status($page, $ok); } else { $this->theme->display_replace_page($page, $image_id); } } } } else { if ($event->page_matches("upload")) { if (!$user->can("create_image")) { $this->theme->display_permission_denied(); } else { /* Regular Upload Image */ if (count($_FILES) + count($_POST) > 0) { $ok = true; foreach ($_FILES as $name => $file) { $tags = $this->tags_for_upload_slot(int_escape(substr($name, 4))); $source = isset($_POST['source']) ? $_POST['source'] : null; $ok = $ok & $this->try_upload($file, $tags, $source); } foreach ($_POST as $name => $value) { if (substr($name, 0, 3) == "url" && strlen($value) > 0) { $tags = $this->tags_for_upload_slot(int_escape(substr($name, 3))); $source = isset($_POST['source']) ? $_POST['source'] : $value; $ok = $ok & $this->try_transload($value, $tags, $source); } } $this->theme->display_upload_status($page, $ok); } else { if (!empty($_GET['url'])) { $url = $_GET['url']; $source = isset($_GET['source']) ? $_GET['source'] : $url; $tags = array('tagme'); if (!empty($_GET['tags']) && $_GET['tags'] != "null") { $tags = Tag::explode($_GET['tags']); } $ok = $this->try_transload($url, $tags, $source); $this->theme->display_upload_status($page, $ok); } else { if ($this->is_full) { $this->theme->display_full($page); } else { $this->theme->display_page($page); } } } } } } }
public function onPageRequest(PageRequestEvent $event) { global $page, $user; if ($event->page_matches("forum")) { switch ($event->get_arg(0)) { case "index": $this->show_last_threads($page, $event, $user->is_admin()); if (!$user->is_anonymous()) { $this->theme->display_new_thread_composer($page); } break; case "view": $threadID = int_escape($event->get_arg(1)); $pageNumber = int_escape($event->get_arg(2)); list($errors) = $this->sanity_check_viewed_thread($threadID); if ($errors != null) { $this->theme->display_error(500, "Error", $errors); break; } $this->show_posts($event, $user->is_admin()); if ($user->is_admin()) { $this->theme->add_actions_block($page, $threadID); } if (!$user->is_anonymous()) { $this->theme->display_new_post_composer($page, $threadID); } break; case "new": global $page; $this->theme->display_new_thread_composer($page); break; case "create": $redirectTo = "forum/index"; if (!$user->is_anonymous()) { list($errors) = $this->sanity_check_new_thread(); if ($errors != null) { $this->theme->display_error(500, "Error", $errors); break; } $newThreadID = $this->save_new_thread($user); $this->save_new_post($newThreadID, $user); $redirectTo = "forum/view/" . $newThreadID . "/1"; } $page->set_mode("redirect"); $page->set_redirect(make_link($redirectTo)); break; case "delete": $threadID = int_escape($event->get_arg(1)); $postID = int_escape($event->get_arg(2)); if ($user->is_admin()) { $this->delete_post($postID); } $page->set_mode("redirect"); $page->set_redirect(make_link("forum/view/" . $threadID)); break; case "nuke": $threadID = int_escape($event->get_arg(1)); if ($user->is_admin()) { $this->delete_thread($threadID); } $page->set_mode("redirect"); $page->set_redirect(make_link("forum/index")); break; case "answer": $threadID = int_escape($_POST["threadID"]); $total_pages = $this->get_total_pages_for_thread($threadID); if (!$user->is_anonymous()) { list($errors) = $this->sanity_check_new_post(); if ($errors != null) { $this->theme->display_error(500, "Error", $errors); break; } $this->save_new_post($threadID, $user); } $page->set_mode("redirect"); $page->set_redirect(make_link("forum/view/" . $threadID . "/" . $total_pages)); break; default: $page->set_mode("redirect"); $page->set_redirect(make_link("forum/index")); //$this->theme->display_error(400, "Invalid action", "You should check forum/index."); break; } } }
public function onPageRequest(PageRequestEvent $event) { global $config, $database, $page, $user; if ($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); $query = "SELECT oldtag, newtag FROM aliases ORDER BY newtag ASC LIMIT ? OFFSET ?"; $alias = $database->db->GetAssoc($query, array($alias_per_page, $page_number * $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()) { if (count($_FILES) > 0) { $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"); } } } } } } } }
public function onPageRequest(PageRequestEvent $event) { global $config, $page, $user; if ($event->page_matches("nicetest")) { $page->set_mode("data"); $page->set_data("ok"); } if ($event->page_matches("setup")) { if (!$user->can("change_setting")) { $this->theme->display_permission_denied(); } else { if ($event->get_arg(0) == "save" && $user->check_auth_token()) { send_event(new ConfigSaveEvent($config)); $config->save(); flash_message("Config saved"); $page->set_mode("redirect"); $page->set_redirect(make_link("setup")); } else { if ($event->get_arg(0) == "advanced") { $this->theme->display_advanced($page, $config->values); } else { $panel = new SetupPanel(); send_event(new SetupBuildingEvent($panel)); $this->theme->display_page($page, $panel); } } } } }
public function onPageRequest(PageRequestEvent $event) { global $config, $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) == "recover") { $user = User::by_name($_POST['username']); if (is_null($user)) { $this->theme->display_error(404, "Error", "There's no user with that name"); } else { if (is_null($user->email)) { $this->theme->display_error(400, "Error", "That user has no registered email address"); } else { // send 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(400, "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(400, "User Creation Error", $ex->getMessage()); } } } } } 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); } else { if ($event->get_arg(0) == "logout") { set_prefixed_cookie("session", "", time() + 60 * 60 * 24 * $config->get_int('login_memory'), "/"); if (CACHE_HTTP || SPEED_HAX) { # 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"); // Try forwarding to same page on logout unless user comes from registration page if ($config->get_int("user_loginshowprofile", 0) == 0 && isset($_SERVER['HTTP_REFERER']) && strstr($_SERVER['HTTP_REFERER'], "post/")) { $page->set_redirect($_SERVER['HTTP_REFERER']); } else { $page->set_redirect(make_link()); } } } } } } if (!$user->check_auth_token()) { return; } else { if ($event->get_arg(0) == "change_pass") { if (isset($_POST['id']) && isset($_POST['pass1']) && isset($_POST['pass2'])) { $duser = User::by_id($_POST['id']); if (!$duser instanceof User) { throw new NullUserException("Error: the user id does not exist!"); } $pass1 = $_POST['pass1']; $pass2 = $_POST['pass2']; $this->change_password_wrapper($duser, $pass1, $pass2); } } else { if ($event->get_arg(0) == "change_email") { if (isset($_POST['id']) && isset($_POST['address'])) { $duser = User::by_id($_POST['id']); if (!$duser instanceof User) { throw new NullUserException("Error: the user id does not exist!"); } $address = $_POST['address']; $this->change_email_wrapper($duser, $address); } } else { if ($event->get_arg(0) == "change_class") { global $_user_classes; if (isset($_POST['id']) && isset($_POST['class'])) { $duser = User::by_id($_POST['id']); if (!$duser instanceof User) { throw new NullUserException("Error: the user id does not exist!"); } $class = $_POST['class']; if (!array_key_exists($class, $_user_classes)) { throw Exception("Invalid user class: " . html_escape($class)); } $this->change_class_wrapper($duser, $class); } } else { if ($event->get_arg(0) == "delete_user") { $this->delete_user($page, isset($_POST["with_images"]), isset($_POST["with_comments"])); } } } } } } if ($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(401, "Not Logged In", "You aren't logged in. First do that, then you can see your stats."); } else { if (!is_null($display_user) && $display_user->id != $config->get_int("anon_id")) { $e = new UserPageBuildingEvent($display_user); send_event($e); $this->display_stats($e); } else { $this->theme->display_error(404, "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..."); } } } }