Example #1
0
 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;
         }
     }
 }
Example #2
0
 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"));
                 }
             }
         }
     }
 }
Example #3
0
 public function onPageRequest(PageRequestEvent $event)
 {
     global $config, $user, $page;
     if ($user->is_admin() && isset($_GET['sha'])) {
         if ($event->page_matches("update/download")) {
             $ok = $this->download_shimmie();
             $page->set_mode("redirect");
             if ($ok) {
                 $page->set_redirect(make_link("update/update", "sha=" . $_GET['sha']));
             } else {
                 $page->set_redirect(make_link("admin"));
             }
             //TODO: Show error?
         } elseif ($event->page_matches("update/update")) {
             $ok = $this->update_shimmie();
             $page->set_mode("redirect");
             if ($ok) {
                 $page->set_redirect(make_link("admin"));
             } else {
                 $page->set_redirect(make_link("admin"));
             }
             //TODO: Show error?
         }
     }
 }
Example #4
0
 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));
             }
         }
     }
 }
Example #5
0
 private function is_safe_page(PageRequestEvent $event)
 {
     if ($event->page_matches("user_admin/login")) {
         return true;
     } else {
         return false;
     }
 }
Example #6
0
 public function onPageRequest(PageRequestEvent $event)
 {
     global $page, $user;
     if ($event->page_matches("regen_thumb") && $user->can("delete_image") && isset($_POST['image_id'])) {
         $image = Image::by_id(int_escape($_POST['image_id']));
         send_event(new ThumbnailGenerationEvent($image->hash, $image->ext, true));
         $this->theme->display_results($page, $image);
     }
 }
Example #7
0
 public function onPageRequest(PageRequestEvent $event)
 {
     global $user;
     if ($event->page_matches("system_info")) {
         if ($user->can("view_sysinfo")) {
             $this->theme->display_info_page($this->get_info());
         }
     }
 }
Example #8
0
 public function onPageRequest(PageRequestEvent $event)
 {
     if ($event->page_matches("rss/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);
         $this->do_rss($images, $search_terms, $page_number);
     }
 }
Example #9
0
 public function onPageRequest(PageRequestEvent $event)
 {
     global $page, $user;
     if ($event->page_matches("tags/categories")) {
         if ($user->is_admin()) {
             $this->page_update();
             $this->show_tag_categories($page);
         }
     }
 }
Example #10
0
 public function onPageRequest(PageRequestEvent $event)
 {
     global $config, $page;
     if ($event->page_matches("home")) {
         $base_href = get_base_href();
         $sitename = $config->get_string('title');
         $theme_name = $config->get_string('theme');
         $body = $this->get_body();
         $this->theme->display_page($page, $sitename, $base_href, $theme_name, $body);
     }
 }
Example #11
0
 public function onPageRequest(PageRequestEvent $event)
 {
     global $page, $user;
     if ($event->page_matches("bulk_add_csv")) {
         if ($user->is_admin() && $user->check_auth_token() && isset($_POST['csv'])) {
             set_time_limit(0);
             $this->add_csv($_POST['csv']);
             $this->theme->display_upload_results($page);
         }
     }
 }
Example #12
0
 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();
         }
     }
 }
Example #13
0
 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)));
     }
 }
Example #14
0
 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}"));
     }
 }
Example #15
0
 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));
                 }
             }
         }
     }
 }
Example #16
0
 public function onPageRequest(PageRequestEvent $event)
 {
     global $page, $user;
     if ($event->page_matches("bulk_add")) {
         if ($user->is_admin() && $user->check_auth_token() && isset($_POST['dir'])) {
             set_time_limit(0);
             $bae = new BulkAddEvent($_POST['dir']);
             send_event($bae);
             if (strlen($bae->results) > 0) {
                 $this->theme->add_status("Adding files", $bae->results);
             }
             $this->theme->display_upload_results($page);
         }
     }
 }
Example #17
0
 public function onPageRequest(PageRequestEvent $event)
 {
     if ($event->page_matches("mail/test")) {
         global $page;
         $page->set_mode("data");
         echo "Alert: uncomment this page's code on /ext/mail/main.php starting on line 33, and change the email address. Make sure you're using a server with a domain, not localhost.";
         /*
         echo "Preparing to send message:<br>";
         echo "created new mail object. sending now... ";
         $email = new Email("*****@*****.**", "hello", "hello world", "this is a test message.");
         $email->send();
         echo "sent.";
         */
     }
 }
Example #18
0
 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);
         }
     }
 }
Example #19
0
 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));
                     }
                 }
             }
         }
     }
 }
Example #20
0
 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'])));
     }
 }
Example #21
0
 /**
  * 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();
             }
         }
     }
 }
Example #22
0
 public function onPageRequest(PageRequestEvent $event)
 {
     global $page, $user;
     if ($event->page_matches("change_favorite") && !$user->is_anonymous() && $user->check_auth_token()) {
         $image_id = int_escape($_POST['image_id']);
         if (($_POST['favorite_action'] == "set" || $_POST['favorite_action'] == "unset") && $image_id > 0) {
             if ($_POST['favorite_action'] == "set") {
                 send_event(new FavoriteSetEvent($image_id, $user, true));
                 log_debug("favourite", "Favourite set for {$image_id}", "Favourite added");
             } else {
                 send_event(new FavoriteSetEvent($image_id, $user, false));
                 log_debug("favourite", "Favourite removed for {$image_id}", "Favourite removed");
             }
         }
         $page->set_mode("redirect");
         $page->set_redirect(make_link("post/view/{$image_id}"));
     }
 }
Example #23
0
 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));
         }
     }
 }
Example #24
0
 public function onPageRequest(PageRequestEvent $event)
 {
     global $page, $user;
     if ($event->page_matches("mass_tagger/tag") && $user->is_admin()) {
         if (!isset($_POST['ids']) or !isset($_POST['tag'])) {
             return;
         }
         $tag = $_POST['tag'];
         $tag_array = explode(" ", $tag);
         $pos_tag_array = array();
         $neg_tag_array = array();
         foreach ($tag_array as $new_tag) {
             if (strpos($new_tag, '-') === 0) {
                 $neg_tag_array[] = substr($new_tag, 1);
             } else {
                 $pos_tag_array[] = $new_tag;
             }
         }
         $ids = explode(':', $_POST['ids']);
         $ids = array_filter($ids, 'is_numeric');
         $images = array_map("Image::by_id", $ids);
         if (isset($_POST['setadd']) && $_POST['setadd'] == 'set') {
             foreach ($images as $image) {
                 $image->set_tags(Tag::explode($tag));
             }
         } else {
             foreach ($images as $image) {
                 if (!empty($neg_tag_array)) {
                     $img_tags = array_merge($pos_tag_array, explode(" ", $image->get_tag_list()));
                     $img_tags = array_diff($img_tags, $neg_tag_array);
                     $image->set_tags(Tag::explode($img_tags));
                 } else {
                     $image->set_tags(Tag::explode($tag . " " . $image->get_tag_list()));
                 }
             }
         }
         $page->set_mode("redirect");
         if (!isset($_SERVER['HTTP_REFERER'])) {
             $_SERVER['HTTP_REFERER'] = make_link();
         }
         $page->set_redirect($_SERVER['HTTP_REFERER']);
     }
 }
Example #25
0
 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"));
             }
         }
     }
 }
Example #26
0
 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"));
                 }
             }
         }
     }
 }
Example #27
0
 public function onPageRequest(PageRequestEvent $event)
 {
     if ($event->page_matches("sitemap.xml")) {
         global $config;
         $this->sitemap_filepath = data_path("cache/sitemap.xml");
         // determine if new sitemap needs to be generated
         if ($this->new_sitemap_needed()) {
             // determine which type of sitemap to generate
             if ($config->get_bool("sitemap_generatefull", false)) {
                 $this->handle_full_sitemap();
                 // default false until cache fixed
             } else {
                 $this->handle_smaller_sitemap();
             }
         } else {
             $this->display_existing_sitemap();
         }
     }
 }
Example #28
0
 public function onPageRequest(PageRequestEvent $event)
 {
     global $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));
                     }
                 }
             }
         }
     }
 }
Example #29
0
 /**
  * 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;
 }
Example #30
0
 public function onPageRequest(PageRequestEvent $event)
 {
     global $config, $page;
     if ($event->page_matches("random")) {
         // set vars
         $page->title = "Random Images";
         $images_per_page = $config->get_int("random_images_list_count", 12);
         $random_images = array();
         $random_html = "<b>Refresh the page to view more images</b>\n\t\t\t<div class='shm-image-list'>";
         // generate random images
         for ($i = 0; $i < $images_per_page; $i++) {
             array_push($random_images, Image::by_random());
         }
         // create html to display images
         foreach ($random_images as $image) {
             $random_html .= $this->theme->build_thumb_html($image);
         }
         // display it
         $random_html .= "</div>";
         $page->add_block(new Block("Random Images", $random_html));
     }
 }