#1849: filter images for safebooru

This commit is contained in:
r888888888
2013-07-18 17:26:52 -07:00
parent 5ad3571d8b
commit 22bd07072a
6 changed files with 21 additions and 14 deletions

View File

@@ -1032,10 +1032,6 @@ class Post < ActiveRecord::Base
where("is_deleted = ?", true)
end
def visible(user)
Danbooru.config.can_user_see_post_conditions(user)
end
def commented_before(date)
where("last_commented_at < ?", date).order("last_commented_at DESC")
end
@@ -1151,6 +1147,13 @@ class Post < ActiveRecord::Base
extend SearchMethods
include PixivMethods
def visible?
return false if !Danbooru.config.can_user_see_post?(CurrentUser.user, self)
return false if CurrentUser.safe_mode? && rating != "s"
return false if is_banned? && !CurrentUser.is_gold?
return true
end
def reload(options = nil)
super
reset_tag_array_cache

View File

@@ -3,12 +3,8 @@ class PostPresenter < Presenter
if post.is_deleted? && options[:tags] !~ /status:(?:all|any|deleted|banned)/ && !options[:raw]
return ""
end
if post.is_banned? && !CurrentUser.is_gold?
return ""
end
unless Danbooru.config.can_user_see_post?(CurrentUser.user, post)
if !post.visible?
return ""
end
@@ -138,6 +134,7 @@ class PostPresenter < Presenter
def image_html(template)
return template.content_tag("p", "The artist requested removal of this image") if @post.is_banned? && !CurrentUser.user.is_gold?
return template.content_tag("p", template.link_to("You need a gold account to see this image.", template.upgrade_information_users_path)) if !Danbooru.config.can_user_see_post?(CurrentUser.user, @post)
return template.content_tag("p", "This image is unavailable") if !@post.visible?
if @post.is_flash?
template.render("posts/partials/show/flash", :post => @post)

View File

@@ -7,7 +7,9 @@
<% @comments.each do |comment| %>
<div class="post <%= PostPresenter.preview_class(comment.post) %>" <%= PostPresenter.preview_attributes(comment.post) %>>
<div class="preview">
<%= link_to(image_tag(comment.post.preview_file_url), post_path(comment.post)) %>
<% if comment.post.visible? %>
<%= link_to(image_tag(comment.post.preview_file_url), post_path(comment.post)) %>
<% end %>
</div>
<%= render :partial => "comments/partials/show/comment", :collection => [comment] %>
<div class="clearfix"></div>

View File

@@ -9,7 +9,9 @@
<% @posts.select {|x| Danbooru.config.can_user_see_post?(CurrentUser.user, x)}.each do |post| %>
<div class="post <%= PostPresenter.preview_class(post) %>" <%= PostPresenter.preview_attributes(post) %>>
<div class="preview">
<%= link_to(image_tag(post.preview_file_url), post_path(post)) %>
<% if post.visible? %>
<%= link_to(image_tag(post.preview_file_url), post_path(post)) %>
<% end %>
</div>
<%= render "comments/partials/index/list", :post => post, :comments => post.comments.visible(CurrentUser.user).recent.reverse, :show_header => true %>
<div class="clearfix"></div>

View File

@@ -4,7 +4,9 @@
<div class="list-of-comments">
<div class="post <%= PostPresenter.preview_class(@comment.post) %>" data-tags="<%= @comment.post.tag_string %>" data-uploader="<%= @comment.post.uploader_name %>" data-rating="<%= @comment.post.rating %>" data-flags="<%= @comment.post.status %>" data-score="<%= @comment.post.score %>" data-parent-id="<%= @comment.post.parent_id %>" data-has-children="<%= @comment.post.has_children? %>">
<div class="preview">
<%= link_to(image_tag(@comment.post.preview_file_url), post_path(@comment.post)) %>
<% if @comment.post.visible? %>
<%= link_to(image_tag(@comment.post.preview_file_url), post_path(@comment.post)) %>
<% end %>
</div>
<%= render :partial => "comments/partials/show/comment", :collection => [@comment] %>
<div class="clearfix"></div>

View File

@@ -1,2 +1,3 @@
<%= image_tag(post.file_url_for(CurrentUser.user), :width => post.image_width_for(CurrentUser.user), :height => post.image_height_for(CurrentUser.user), :id => "image", "data-original-width" => post.image_width, "data-original-height" => post.image_height, "data-large-width" => post.large_image_width, "data-large-height" => post.large_image_height, "data-tags" => post.tag_string, "data-uploader" => post.uploader_name, "data-rating" => post.rating, "data-flags" => post.status_flags, "data-parent-id" => post.parent_id, "data-has-children" => post.has_children?, "data-score" => post.score, "data-fav-count" => post.fav_count) %>
<% if post.visible? %>
<%= image_tag(post.file_url_for(CurrentUser.user), :width => post.image_width_for(CurrentUser.user), :height => post.image_height_for(CurrentUser.user), :id => "image", "data-original-width" => post.image_width, "data-original-height" => post.image_height, "data-large-width" => post.large_image_width, "data-large-height" => post.large_image_height, "data-tags" => post.tag_string, "data-uploader" => post.uploader_name, "data-rating" => post.rating, "data-flags" => post.status_flags, "data-parent-id" => post.parent_id, "data-has-children" => post.has_children?, "data-score" => post.score, "data-fav-count" => post.fav_count) %>
<% end %>