module Formol module PostsHelper def link_to_post_position(post, index) idx = ((params[:page] || 1) - 1) * per_page + index + 1 return link_to "##{idx}", "#formol_post_#{post.id}" end def link_to_last_fives_post_position(post, topic, index) idx = topic.posts_count - index return link_to "##{idx}", "#formol_post_#{post.id}" end def display_avatars?(user) return true unless user user.preference.display_avatars? end def display_signatures?(user, post) s = post.display_signature? && !post.user.preference.signature.blank? (s && user ? user.preference.display_signatures? : s) end def avatar_for(user) img = if user.respond_to?(:avatar_url) && user.avatar_url.present? user.avatar_url elsif user.respond_to?(:email) && user.email.present? require 'digest/md5' unless defined?(Digest::MD5) email_h = Digest::MD5.hexdigest(user.email.to_s.strip.downcase) options = { :s => 100, :d => default_avatar } "http://www.gravatar.com/avatar/#{email_h}?#{options.to_param}" else default_avatar end image_tag(img, :alt => user.display_name) end def default_avatar img = Formol.config.default_avatar img && URI(img).absolute? ? img : request.protocol + request.host_with_port + path_to_image(img) end end end