You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.6 KiB

8 years ago
8 years ago
  1. module ApplicationHelper
  2. def unique_tag(date, id, type)
  3. "tag:#{Rails.configuration.x.local_domain},#{date.strftime('%Y-%m-%d')}:objectId=#{id}:objectType=#{type}"
  4. end
  5. def unique_tag_to_local_id(tag, expected_type)
  6. matches = Regexp.new("objectId=([\\d]+):objectType=#{expected_type}").match(tag)
  7. return matches[1] unless matches.nil?
  8. end
  9. def local_id?(id)
  10. id.start_with?("tag:#{Rails.configuration.x.local_domain}")
  11. end
  12. def content_for_status(actual_status)
  13. if actual_status.local?
  14. linkify(actual_status)
  15. else
  16. sanitize(actual_status.content, tags: %w(a br p), attributes: %w(href rel))
  17. end
  18. end
  19. def account_from_mentions(search_string, mentions)
  20. mentions.each { |x| return x.account if x.account.acct.eql?(search_string) }
  21. # If that was unsuccessful, try fetching user from db separately
  22. # But this shouldn't ever happen if the mentions were created correctly!
  23. username, domain = search_string.split('@')
  24. if domain == Rails.configuration.x.local_domain
  25. account = Account.find_local(username)
  26. else
  27. account = Account.find_by(username: username, domain: domain)
  28. end
  29. account
  30. end
  31. def linkify(status)
  32. auto_link(HTMLEntities.new.encode(status.text), link: :urls, html: { rel: 'nofollow noopener' }).gsub(Account::MENTION_RE) do |m|
  33. account = account_from_mentions(Account::MENTION_RE.match(m)[1], status.mentions)
  34. "#{m.split('@').first}<a href=\"#{url_for_target(account)}\" class=\"mention\">@<span>#{account.acct}</span></a>"
  35. end.html_safe
  36. end
  37. def active_nav_class(path)
  38. current_page?(path) ? 'active' : ''
  39. end
  40. end