Module: DmForum::ForumHelper
- Included in:
- ApplicationHelper
- Defined in:
- app/helpers/dm_forum/forum_helper.rb
Instance Method Summary collapse
-
#edited_on_tag(post) ⇒ Object
——————————————————————————.
-
#feed_icon_tag(title, url) ⇒ Object
——————————————————————————.
-
#forum_comment_user_state(forum_comment) ⇒ Object
——————————————————————————.
-
#forum_crumbs(forum = nil) ⇒ Object
——————————————————————————.
-
#forum_topic_icon(forum_topic) ⇒ Object
——————————————————————————.
-
#last_active ⇒ Object
——————————————————————————.
-
#modify_history(function, name, path, params_hash = nil) ⇒ Object
——————————————————————————.
-
#recent_forum_activity(forum) ⇒ Object
used to know if a forum has changed since we read it last ——————————————————————————.
-
#recent_topic_activity(topic) ⇒ Object
used to know if a topic has changed since we read it last ——————————————————————————.
-
#topic_title_link(topic, options) ⇒ Object
——————————————————————————.
-
#voice_count ⇒ Object
Ripe for optimization ——————————————————————————.
Instance Method Details
#edited_on_tag(post) ⇒ Object
27 28 29 30 31 |
# File 'app/helpers/dm_forum/forum_helper.rb', line 27 def edited_on_tag(post) if (post.updated_at - post.created_at > 5.minutes) %{<span class='date'>#{I18n.t 'fms.post_edited', :when => time_ago_in_words(post.updated_at)}</span>}.html_safe end end |
#feed_icon_tag(title, url) ⇒ Object
59 60 61 62 |
# File 'app/helpers/dm_forum/forum_helper.rb', line 59 def feed_icon_tag(title, url) # (@feed_icons ||= []) << { :url => url, :title => title } # link_to image_tag('feed-icon.png', :size => '14x14', :alt => "Subscribe to #{title}"), url end |
#forum_comment_user_state(forum_comment) ⇒ Object
99 100 101 102 103 104 105 106 107 |
# File 'app/helpers/dm_forum/forum_helper.rb', line 99 def forum_comment_user_state(forum_comment) if forum_comment.user.is_admin? I18n.t 'fms.user_is_administrator', :default => 'Administator' elsif can?(:moderate, forum_comment.forum_topic.forum) I18n.t 'fms.user_is_moderator', :default => 'Moderator' elsif forum_comment.user.suspended? forum_comment.user.state end end |
#forum_crumbs(forum = nil) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'app/helpers/dm_forum/forum_helper.rb', line 65 def forum_crumbs(forum = nil) seperator = "<span class='arrow'><i class='icon-angle-right'></i></span>".html_safe out = "".html_safe out += link_to(I18n.t('fms.forums'), forum_root_path) + seperator if forum out += link_to(forum.name, forum_path(forum)) page = session[:forum_page] ? session[:forum_page][forum.id] : nil if page and page != 1 out += "<small style='color:#ccc'>(".html_safe out += link_to(I18n.t('fms.page_nr'), forum_path(:id => forum, :page => page)) out += ")</small>".html_safe end out += seperator end return out end |
#forum_topic_icon(forum_topic) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'app/helpers/dm_forum/forum_helper.rb', line 83 def forum_topic_icon(forum_topic) if recent_topic_activity(forum_topic) style = "style='color:green'" recent_txt = I18n.t('fms.views_forums.recent_activity') else stlye = '' recent_txt = I18n.t('fms.views_forums.no_recent_activity') end if forum_topic.locked? "<i class='icon-lock icon-large' #{style} title='#{I18n.t('fms.views_forums.comma_locked_topic')}'></i>".html_safe else "<i class='icon-comments icon-large' #{style} title='#{recent_txt}'></i>".html_safe end end |
#last_active ⇒ Object
48 49 50 |
# File 'app/helpers/dm_forum/forum_helper.rb', line 48 def last_active session[:last_active] ||= Time.now.utc end |
#modify_history(function, name, path, params_hash = nil) ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'app/helpers/dm_forum/forum_helper.rb', line 15 def modify_history(function, name, path, params_hash=nil) state = "null" query_string = "?" if params_hash state = params_hash.to_json params_hash.each { |k,v| query_string << "#{k}=#{v}&" } end query_string = query_string.chop %{history.#{function}(#{state}, '#{j(name)}', '#{j(path+query_string)}');}.html_safe end |
#recent_forum_activity(forum) ⇒ Object
used to know if a forum has changed since we read it last
42 43 44 45 |
# File 'app/helpers/dm_forum/forum_helper.rb', line 42 def recent_forum_activity(forum) return false unless user_signed_in? && forum.recent_topic return forum.recent_topic.last_updated_at > ((session[:forums] ||= {})[forum.id] || last_active) end |
#recent_topic_activity(topic) ⇒ Object
used to know if a topic has changed since we read it last
35 36 37 38 |
# File 'app/helpers/dm_forum/forum_helper.rb', line 35 def recent_topic_activity(topic) return false unless user_signed_in? return topic.last_updated_at > ((session[:forum_topics] ||= {})[topic.id] || last_active) end |
#topic_title_link(topic, options) ⇒ Object
5 6 7 8 9 10 11 12 |
# File 'app/helpers/dm_forum/forum_helper.rb', line 5 def topic_title_link(topic, ) if topic.title =~ /^\[([^\]]{1,15})\]((\s+)\w+.*)/ "<span class='flag'>#{$1}</span>" + link_to($2.strip, forum_forum_topic_path(@forum, topic), ) else link_to(topic.title, forum_forum_topic_path(@forum, topic), ) end end |