Files
danbooru/app/helpers/posts_helper.rb
evazion 1e778dbbf6 posts: factor out post navbar into component.
* Factor out the post navbar into a component. The post navbar is the
  part of the post containing the current search, the list of pools, and
  the list of favgroups, along with next/prev navigation links.

* Change navbar markup: remove various unused CSS classes/IDs, change
  pools to use same markup as favgroups, replace nested <div>'s with
  flat <ul>/<li> list.

* Use CSS to truncate long searches/pool names/favgroup names if they're
  too wide for the screen (especially on mobile).
2021-01-29 21:46:21 -06:00

45 lines
1.4 KiB
Ruby

module PostsHelper
def reportbooru_enabled?
Danbooru.config.reportbooru_server.present? && Danbooru.config.reportbooru_key.present?
end
def discover_mode?
params[:tags] =~ /order:rank/ || params[:action] =~ /searches|viewed/
end
def missed_post_search_count_js(tags)
return unless reportbooru_enabled?
sig = generate_reportbooru_signature(tags)
render "posts/partials/index/missed_search_count", sig: sig
end
def post_search_count_js(tags)
return unless reportbooru_enabled?
sig = generate_reportbooru_signature("ps-#{tags}")
render "posts/partials/index/search_count", sig: sig
end
def post_view_count_js
return unless reportbooru_enabled?
msg = generate_reportbooru_signature(params[:id])
render "posts/partials/show/view_count", msg: msg
end
def generate_reportbooru_signature(value)
verifier = ActiveSupport::MessageVerifier.new(Danbooru.config.reportbooru_key, serializer: JSON, digest: "SHA256")
verifier.generate("#{value},#{session[:session_id]}")
end
def post_source_tag(source, normalized_source = source)
# Only allow http:// and https:// links. Disallow javascript: links.
if source =~ %r!\Ahttps?://!i
external_link_to(normalized_source, strip: :subdomain) + "&nbsp;".html_safe + link_to("»", source, rel: "external noreferrer nofollow")
else
source
end
end
end