Class: Post

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/post.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.in_forum(forum) ⇒ Object



55
56
57
# File 'app/models/post.rb', line 55

def self.in_forum(forum)
  in_topics(forum.topics)
end

Instance Method Details

#body_htmlObject

so that page comments can be rendered from a radius tag



129
130
131
132
133
134
135
136
# File 'app/models/post.rb', line 129

def body_html
  if body
    html = RedCloth.new(body, [ :hard_breaks, :filter_html ]).to_html(:textile, :smilies)
    Sanitize.clean(html, Sanitize::Config::RELAXED)
  else
    ""
  end
end

#comment?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'app/models/post.rb', line 67

def comment?
  !!page
end

#date_htmlObject



138
139
140
# File 'app/models/post.rb', line 138

def date_html
  self.created_at.to_s
end

#dom_idObject



154
155
156
# File 'app/models/post.rb', line 154

def dom_id
  "post_#{self.id}"
end

#editable_by?(reader = nil) ⇒ Boolean

Returns:

  • (Boolean)


111
112
113
114
# File 'app/models/post.rb', line 111

def editable_by?(reader=nil)
  return false unless reader
  still_editable? && reader.id == reader_id
end

#editable_intervalObject



95
96
97
# File 'app/models/post.rb', line 95

def editable_interval
  Radiant::Config['forum.editable_period'].to_i.minutes if Radiant::Config['forum.editable_period']
end

#first?Boolean

Returns:

  • (Boolean)


83
84
85
# File 'app/models/post.rb', line 83

def first?
  !holder || holder.new_record? || holder.posts.first == self
end

#forumObject



79
80
81
# File 'app/models/post.rb', line 79

def forum
  topic.forum unless comment?
end

#has_replies?Boolean

Returns:

  • (Boolean)


91
92
93
# File 'app/models/post.rb', line 91

def has_replies?
  holder.posts.last != self
end

#holderObject



59
60
61
# File 'app/models/post.rb', line 59

def holder
  page || topic
end

#locked?Boolean

Returns:

  • (Boolean)


87
88
89
# File 'app/models/post.rb', line 87

def locked?
  holder && holder.locked?
end

#notify_holder_of_creationObject



150
151
152
# File 'app/models/post.rb', line 150

def notify_holder_of_creation
  holder.notice_creation_of(self)
end

#notify_holder_of_destructionObject



146
147
148
# File 'app/models/post.rb', line 146

def notify_holder_of_destruction
  holder.notice_destruction_of(self)
end

#page_when_paginatedObject



75
76
77
# File 'app/models/post.rb', line 75

def page_when_paginated
  holder.page_for(self)
end

#reply?Boolean

Returns:

  • (Boolean)


71
72
73
# File 'app/models/post.rb', line 71

def reply?
  !comment? && !first?
end

#save_attachments(files = nil) ⇒ Object



142
143
144
# File 'app/models/post.rb', line 142

def save_attachments(files=nil)
  files.collect {|file| self.attachments.create(:file => file) unless file.blank? } if files
end

#still_editable?Boolean

Returns:

  • (Boolean)


107
108
109
# File 'app/models/post.rb', line 107

def still_editable?
  !editable_interval || Time.now - self.created_at < editable_interval
end

#still_editable_forObject



99
100
101
102
103
104
105
# File 'app/models/post.rb', line 99

def still_editable_for
  if editable_interval && still_editable?
    self.created_at + editable_interval - Time.now 
  else
    0
  end
end

#titleObject



63
64
65
# File 'app/models/post.rb', line 63

def title
  holder.title if holder
end

#visible_to?(reader = nil) ⇒ Boolean

Returns:

  • (Boolean)


116
117
118
119
120
121
122
123
124
125
126
# File 'app/models/post.rb', line 116

def visible_to?(reader=nil)
  if topic && !topic.visible_to?(reader)
    false
  elsif page && !page.visible_to?(reader)
    false
  elsif !reader && !Radiant::Config['forum.public?']
    false
  else
    true
  end
end