public function onSearchTermParse(SearchTermParseEvent $event) { global $user; $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]+)|(safe|questionable|explicit|unknown))\$/D", strtolower($event->term), $matches)) { $ratings = $matches[1] ? $matches[1] : $matches[2][0]; $ratings = array_intersect(str_split($ratings), str_split(Ratings::get_user_privs($user))); $set = "'" . join("', '", $ratings) . "'"; $event->add_querylet(new Querylet("rating IN ({$set})")); } }
/** * Retrieve all the images in a pool, given a pool ID. * * @param PageRequestEvent $event * @param int $poolID */ private function get_posts($event, $poolID) { global $config, $user, $database; $pageNumber = int_escape($event->get_arg(2)); if (is_null($pageNumber) || !is_numeric($pageNumber)) { $pageNumber = 0; } else { if ($pageNumber <= 0) { $pageNumber = 0; } else { $pageNumber--; } } $poolID = int_escape($poolID); $pool = $this->get_pool($poolID); $imagesPerPage = $config->get_int("poolsImagesPerPage"); // WE CHECK IF THE EXTENSION RATING IS INSTALLED, WHICH VERSION AND IF IT // WORKS TO SHOW/HIDE SAFE, QUESTIONABLE, EXPLICIT AND UNRATED IMAGES FROM USER if (ext_is_live("Ratings")) { $rating = Ratings::privs_to_sql(Ratings::get_user_privs($user)); } if (isset($rating) && !empty($rating)) { $result = $database->get_all("\n\t\t\t\t\tSELECT p.image_id\n\t\t\t\t\tFROM pool_images AS p\n\t\t\t\t\tINNER JOIN images AS i ON i.id = p.image_id\n\t\t\t\t\tWHERE p.pool_id = :pid AND i.rating IN ({$rating})\n\t\t\t\t\tORDER BY p.image_order ASC\n\t\t\t\t\tLIMIT :l OFFSET :o", array("pid" => $poolID, "l" => $imagesPerPage, "o" => $pageNumber * $imagesPerPage)); $totalPages = ceil($database->get_one("\n\t\t\t\t\tSELECT COUNT(*) \n\t\t\t\t\tFROM pool_images AS p\n\t\t\t\t\tINNER JOIN images AS i ON i.id = p.image_id\n\t\t\t\t\tWHERE pool_id=:pid AND i.rating IN ({$rating})", array("pid" => $poolID)) / $imagesPerPage); } else { $result = $database->get_all("\n\t\t\t\t\tSELECT image_id\n\t\t\t\t\tFROM pool_images\n\t\t\t\t\tWHERE pool_id=:pid\n\t\t\t\t\tORDER BY image_order ASC\n\t\t\t\t\tLIMIT :l OFFSET :o", array("pid" => $poolID, "l" => $imagesPerPage, "o" => $pageNumber * $imagesPerPage)); $totalPages = ceil($database->get_one("SELECT COUNT(*) FROM pool_images WHERE pool_id=:pid", array("pid" => $poolID)) / $imagesPerPage); } $images = array(); foreach ($result as $singleResult) { $images[] = Image::by_id($singleResult["image_id"]); } $this->theme->view_pool($pool, $images, $pageNumber + 1, $totalPages); }
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))); } } }