Beispiel #1
0
 public function onPostListBuilding($event)
 {
     global $config, $page, $user;
     $fid = $config->get_int("featured_id");
     if ($fid > 0) {
         $image = Image::by_id($fid);
         if (!is_null($image)) {
             if (class_exists("Ratings")) {
                 if (strpos(Ratings::get_user_privs($user), $image->rating) === FALSE) {
                     return;
                 }
             }
             $this->theme->display_featured($page, $image);
         }
     }
 }
Beispiel #2
0
 public function onPostListBuilding(PostListBuildingEvent $event)
 {
     global $config, $database, $page, $user;
     $fid = $config->get_int("featured_id");
     if ($fid > 0) {
         $image = $database->cache->get("featured_image_object:{$fid}");
         if ($image === false) {
             $image = Image::by_id($fid);
             if ($image) {
                 // make sure the object is fully populated before saving
                 $image->get_tag_array();
             }
             $database->cache->set("featured_image_object:{$fid}", $image, 600);
         }
         if (!is_null($image)) {
             if (class_exists("Ratings")) {
                 if (strpos(Ratings::get_user_privs($user), $image->rating) === FALSE) {
                     return;
                 }
             }
             $this->theme->display_featured($page, $image);
         }
     }
 }
Beispiel #3
0
 /**
  * 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);
 }
Beispiel #4
0
 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})"));
     }
 }
Beispiel #5
0
 private function build_page($current_page)
 {
     global $page;
     global $config;
     global $database;
     if (class_exists("Ratings")) {
         global $user;
         $user_ratings = Ratings::get_user_privs($user);
     }
     if (is_null($current_page) || $current_page <= 0) {
         $current_page = 1;
     }
     $threads_per_page = 10;
     $start = $threads_per_page * ($current_page - 1);
     $get_threads = "\n\t\t\tSELECT image_id,MAX(posted) AS latest\n\t\t\tFROM comments\n\t\t\tGROUP BY image_id\n\t\t\tORDER BY latest DESC\n\t\t\tLIMIT ? OFFSET ?\n\t\t\t";
     $result = $database->Execute($get_threads, array($threads_per_page, $start));
     $total_pages = (int) ($database->db->GetOne("SELECT COUNT(c1) FROM (SELECT COUNT(image_id) AS c1 FROM comments GROUP BY image_id) AS s1") / 10);
     $images = array();
     while (!$result->EOF) {
         $image = Image::by_id($result->fields["image_id"]);
         $comments = $this->get_comments($image->id);
         if (class_exists("Ratings")) {
             if (strpos($user_ratings, $image->rating) === FALSE) {
                 $image = null;
                 // this is "clever", I may live to regret it
             }
         }
         if (!is_null($image)) {
             $images[] = array($image, $comments);
         }
         $result->MoveNext();
     }
     $this->theme->display_comment_list($images, $current_page, $total_pages, $this->can_comment());
 }
Beispiel #6
0
 /**
  * @param int $current_page
  */
 private function build_page($current_page)
 {
     global $database, $user;
     $where = SPEED_HAX ? "WHERE posted > now() - interval '24 hours'" : "";
     $total_pages = $database->cache->get("comment_pages");
     if (empty($total_pages)) {
         $total_pages = (int) ($database->get_one("\n\t\t\t\tSELECT COUNT(c1)\n\t\t\t\tFROM (SELECT COUNT(image_id) AS c1 FROM comments {$where} GROUP BY image_id) AS s1\n\t\t\t") / 10);
         $database->cache->set("comment_pages", $total_pages, 600);
     }
     $total_pages = max($total_pages, 1);
     $current_page = clamp($current_page, 1, $total_pages);
     $threads_per_page = 10;
     $start = $threads_per_page * ($current_page - 1);
     $result = $database->Execute("\n\t\t\tSELECT image_id,MAX(posted) AS latest\n\t\t\tFROM comments\n\t\t\t{$where}\n\t\t\tGROUP BY image_id\n\t\t\tORDER BY latest DESC\n\t\t\tLIMIT :limit OFFSET :offset\n\t\t", array("limit" => $threads_per_page, "offset" => $start));
     $user_ratings = ext_is_live("Ratings") ? Ratings::get_user_privs($user) : "";
     $images = array();
     while ($row = $result->fetch()) {
         $image = Image::by_id($row["image_id"]);
         if (ext_is_live("Ratings") && !is_null($image) && strpos($user_ratings, $image->rating) === FALSE) {
             $image = null;
             // this is "clever", I may live to regret it
         }
         if (!is_null($image)) {
             $comments = $this->get_comments($image->id);
             $images[] = array($image, $comments);
         }
     }
     $this->theme->display_comment_list($images, $current_page, $total_pages, $user->can("create_comment"));
 }
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 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)));
         }
     }
 }