Class: Feedback
Defined Under Namespace
Classes: ContentTextHelpers
Instance Attribute Summary
Attributes included from ContentBase
#just_changed_published_status
Class Method Summary
collapse
Instance Method Summary
collapse
#default_text_filter, #excerpt_text, #generate_html, #html, #html_map, #html_preprocess, included, #really_send_notifications, #send_notification_to_user, #text_filter
#create_guid
Class Method Details
.paginated(page, per_page) ⇒ Object
FIXME: Inline this method
71
72
73
|
# File 'app/models/feedback.rb', line 71
def self.paginated(page, per_page)
page(page).per(per_page)
end
|
Instance Method Details
#akismet_is_spam?(_options = {}) ⇒ Boolean
147
148
149
150
151
152
153
154
155
156
157
|
# File 'app/models/feedback.rb', line 147
def akismet_is_spam?(_options = {})
return false if akismet.nil?
begin
Timeout.timeout(60) do
akismet.(ip, user_agent, akismet_options)
end
rescue Timeout::Error
nil
end
end
|
#akismet_options ⇒ Object
111
112
113
114
115
116
117
|
# File 'app/models/feedback.rb', line 111
def akismet_options
{ type: self.class.to_s.downcase,
author: originator,
author_email: email,
author_url: url,
text: body }
end
|
#article_allows_this_feedback ⇒ Object
103
104
105
|
# File 'app/models/feedback.rb', line 103
def article_allows_this_feedback
article && blog_allows_feedback? && article_allows_feedback?
end
|
#blog_allows_feedback? ⇒ Boolean
107
108
109
|
# File 'app/models/feedback.rb', line 107
def blog_allows_feedback?
true
end
|
#change_state! ⇒ Object
159
160
161
162
163
164
165
166
167
168
169
|
# File 'app/models/feedback.rb', line 159
def change_state!
result = ""
if spam? || presumed_spam?
mark_as_ham!
result = "ham"
else
mark_as_spam!
result = "spam"
end
result
end
|
#classify ⇒ Object
123
124
125
126
127
128
129
130
131
132
133
134
|
# File 'app/models/feedback.rb', line 123
def classify
return :ham if user_id
return :spam if blog.
return :ham unless blog.sp_global
case sp_is_spam? || akismet_is_spam?
when nil then :spam
when true then :spam
when false then :ham
end
end
|
#classify_content ⇒ Object
79
80
81
82
83
84
85
86
|
# File 'app/models/feedback.rb', line 79
def classify_content
return unless unclassified?
case classify
when :ham then presume_ham
else presume_spam
end
end
|
#confirm_classification ⇒ Object
176
177
178
179
180
181
182
|
# File 'app/models/feedback.rb', line 176
def confirm_classification
if presumed_spam?
mark_as_spam
elsif presumed_ham?
mark_as_ham
end
end
|
#confirm_classification! ⇒ Object
171
172
173
174
|
# File 'app/models/feedback.rb', line 171
def confirm_classification!
confirm_classification
save!
end
|
#correct_url ⇒ Object
97
98
99
100
101
|
# File 'app/models/feedback.rb', line 97
def correct_url
return if url.blank?
self.url = "http://" + url.to_s unless %r{^https?://}.match?(url)
end
|
#feedback_not_closed ⇒ Object
208
209
210
|
# File 'app/models/feedback.rb', line 208
def feedback_not_closed
errors.add(:article_id, "Comment are closed") if article.
end
|
#html_postprocess(_field, html) ⇒ Object
92
93
94
95
|
# File 'app/models/feedback.rb', line 92
def html_postprocess(_field, html)
helper = ContentTextHelpers.new
helper.sanitize(helper.auto_link(html))
end
|
#parent ⇒ Object
75
76
77
|
# File 'app/models/feedback.rb', line 75
def parent
article
end
|
#permalink_url(_anchor = :ignored, only_path = false) ⇒ Object
88
89
90
|
# File 'app/models/feedback.rb', line 88
def permalink_url(_anchor = :ignored, only_path = false)
article.permalink_url("#{self.class.to_s.downcase}-#{id}", only_path)
end
|
#published? ⇒ Boolean
216
217
218
|
# File 'app/models/feedback.rb', line 216
def published?
ham? || presumed_ham?
end
|
#report_as_ham ⇒ Object
196
197
198
199
200
201
202
203
204
205
206
|
# File 'app/models/feedback.rb', line 196
def report_as_ham
return if akismet.nil?
begin
Timeout.timeout(5) do
akismet.ham(ip, user_agent, akismet_options)
end
rescue Timeout::Error
nil
end
end
|
#report_as_spam ⇒ Object
184
185
186
187
188
189
190
191
192
193
194
|
# File 'app/models/feedback.rb', line 184
def report_as_spam
return if akismet.nil?
begin
Timeout.timeout(5) do
akismet.submit_spam(ip, user_agent, akismet_options)
end
rescue Timeout::Error
nil
end
end
|
#send_notifications ⇒ Object
212
213
214
|
# File 'app/models/feedback.rb', line 212
def send_notifications
nil
end
|
#sp_is_spam?(_options = {}) ⇒ Boolean
136
137
138
139
140
141
142
143
144
145
|
# File 'app/models/feedback.rb', line 136
def sp_is_spam?(_options = {})
sp = SpamProtection.new(blog)
Timeout.timeout(30) do
spam_fields.any? do |field|
sp.is_spam?(send(field))
end
end
rescue Timeout::Error
nil
end
|
#spam_fields ⇒ Object
119
120
121
|
# File 'app/models/feedback.rb', line 119
def spam_fields
[:title, :body, :ip, :url]
end
|
#spammy? ⇒ Boolean
224
225
226
|
# File 'app/models/feedback.rb', line 224
def spammy?
spam? || presumed_spam?
end
|
#status_confirmed? ⇒ Boolean
220
221
222
|
# File 'app/models/feedback.rb', line 220
def status_confirmed?
ham? || spam?
end
|