class PostPresenter < Presenter attr_reader :pool, :next_post_in_pool def self.preview(post, options = {}) if post.nil? return "Expunged" end if !options[:show_deleted] && post.is_deleted? && options[:tags] !~ /status:(?:all|any|deleted|banned)/ && !options[:raw] return "" end if !post.visible? return "" end if post.is_ugoira? && !post.has_ugoira_webm? # ugoira preview gen is async so dont render it immediately return "" end path = options[:path_prefix] || "/posts" html = %{
} if options[:tags].present? && !CurrentUser.is_anonymous? tag_param = "?tags=#{CGI::escape(options[:tags])}" elsif options[:pool_id] || options[:pool] tag_param = "?pool_id=#{CGI::escape((options[:pool_id] || options[:pool].id).to_s)}" elsif options[:favgroup_id] || options[:favgroup] tag_param = "?favgroup_id=#{CGI::escape((options[:favgroup_id] || options[:favgroup].id).to_s)}" else tag_param = nil end html << %{} if options[:show_cropped] && post.has_cropped? src = post.cropped_file_url else src = post.preview_file_url end html << %{#{h(post.tag_string)}} html << %{} if options[:pool] html << %{

} html << %{} html << h(options[:pool].pretty_name.truncate(80)) html << %{} html << %{

} end if options[:size] html << %{

} html << post.file_size.to_formatted_s(:human_size) html << " (#{post.image_width}x#{post.image_height})" html << %{

} end html << %{
} html.html_safe end def self.preview_class(post, description = nil, options = {}) klass = "post-preview" klass << " large-cropped" if post.has_cropped? && options[:show_cropped] klass << " pooled" if description klass << " post-status-pending" if post.is_pending? klass << " post-status-flagged" if post.is_flagged? klass << " post-status-deleted" if post.is_deleted? klass << " post-status-has-parent" if post.parent_id klass << " post-status-has-children" if post.has_visible_children? klass end def self.data_attributes(post) attributes = %{ data-id="#{post.id}" data-has-sound="#{post.has_tag?('video_with_sound|flash_with_sound')}" data-tags="#{h(post.tag_string)}" data-pools="#{post.pool_string}" data-uploader="#{h(post.uploader_name)}" data-approver-id="#{post.approver_id}" data-rating="#{post.rating}" data-width="#{post.image_width}" data-height="#{post.image_height}" data-flags="#{post.status_flags}" data-parent-id="#{post.parent_id}" data-has-children="#{post.has_children?}" data-score="#{post.score}" data-views="#{post.view_count}" data-fav-count="#{post.fav_count}" data-pixiv-id="#{post.pixiv_id}" data-file-ext="#{post.file_ext}" data-source="#{h(post.source)}" data-normalized-source="#{h(post.normalized_source)}" data-is-favorited="#{post.favorited_by?(CurrentUser.user.id)}" } if post.visible? attributes += %{ data-md5="#{post.md5}" data-file-url="#{post.file_url}" data-large-file-url="#{post.large_file_url}" data-preview-file-url="#{post.preview_file_url}" } end attributes.html_safe end def initialize(post) @post = post end def tag_set_presenter @tag_set_presenter ||= TagSetPresenter.new(@post.tag_array) end def preview_html PostPresenter.preview(@post) end def humanized_tag_string @post.tag_string.split(/ /).slice(0, 25).join(", ").tr("_", " ") end def humanized_essential_tag_string @post.humanized_essential_tag_string end def categorized_tag_string string = [] if @post.copyright_tags.any? string << @post.copyright_tags.join(" ") end if @post.character_tags.any? string << @post.character_tags.join(" ") end if @post.artist_tags.any? string << @post.artist_tags.join(" ") end if @post.general_tags.any? string << @post.general_tags.join(" ") end string.join(" \n") end def humanized_categorized_tag_string string = [] if @post.copyright_tags.any? string << @post.copyright_tags end if @post.character_tags.any? string << @post.character_tags end if @post.artist_tags.any? string << @post.artist_tags end if @post.general_tags.any? string << @post.general_tags end string.flatten.slice(0, 25).join(", ").tr("_", " ") end 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.new_user_upgrade_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) elsif @post.is_video? template.render("posts/partials/show/video", :post => @post) elsif @post.is_ugoira? template.render("posts/partials/show/ugoira", :post => @post) elsif !@post.is_image? template.render("posts/partials/show/download", :post => @post) elsif @post.is_image? template.render("posts/partials/show/image", :post => @post) end end def tag_list_html(template, options = {}) tag_set_presenter.tag_list_html(template, options.merge(:show_extra_links => CurrentUser.user.is_gold?)) end def split_tag_list_html(template, options = {}) tag_set_presenter.split_tag_list_html(template, options.merge(:show_extra_links => CurrentUser.user.is_gold?)) end def inline_tag_list_html(template) tag_set_presenter.inline_tag_list(template) end def has_nav_links?(template) has_sequential_navigation?(template.params) || @post.pools.undeleted.any? || @post.favorite_groups(active_id=template.params[:favgroup_id]).any? end def has_sequential_navigation?(params) return false if params[:tags] =~ /(?:^|\s)(?:order|ordfav|ordpool):/i return false if params[:pool_id].present? || params[:favgroup_id].present? return CurrentUser.user.enable_sequential_post_navigation end def post_footer_for_pool_html(template) if template.params[:pool_id] pool = Pool.where(:id => template.params[:pool_id]).first return if pool.nil? return if pool.neighbors(@post).next.nil? template.link_to("Next in #{pool.pretty_name}", template.post_path(pool.neighbors(@post).next)) else nil end end def pool_html(template) html = ["" html.join("\n").html_safe end def pool_link_html(template, pool, options = {}) pool_html = [%{" pool_html end end