Class: Feedback
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
70
71
72
|
# File 'app/models/feedback.rb', line 70
def self.allowed_tags
@allowed_tags ||= Rails::Html::SafeListSanitizer.allowed_tags - ["img"]
end
|
.paginated(page, per_page) ⇒ Object
FIXME: Inline this method
66
67
68
|
# File 'app/models/feedback.rb', line 66
def self.paginated(page, per_page)
page(page).per(per_page)
end
|
Instance Method Details
#akismet_is_spam?(_options = {}) ⇒ Boolean
142
143
144
145
146
147
148
149
150
151
152
|
# File 'app/models/feedback.rb', line 142
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
106
107
108
109
110
111
112
|
# File 'app/models/feedback.rb', line 106
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
102
103
104
|
# File 'app/models/feedback.rb', line 102
def article_allows_this_feedback
article && blog_allows_feedback? && article_allows_feedback?
end
|
#change_state! ⇒ Object
154
155
156
157
158
159
160
161
162
163
164
|
# File 'app/models/feedback.rb', line 154
def change_state!
result = ""
if spam? || presumed_spam?
mark_as_ham!
result = "ham"
else
mark_as_spam!
result = "spam"
end
result
end
|
#classify ⇒ Object
118
119
120
121
122
123
124
125
126
127
128
129
|
# File 'app/models/feedback.rb', line 118
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
78
79
80
81
82
83
84
85
|
# File 'app/models/feedback.rb', line 78
def classify_content
return unless unclassified?
case classify
when :ham then presume_ham
else presume_spam
end
end
|
#confirm_classification ⇒ Object
171
172
173
174
175
176
177
|
# File 'app/models/feedback.rb', line 171
def confirm_classification
if presumed_spam?
mark_as_spam
elsif presumed_ham?
mark_as_ham
end
end
|
#confirm_classification! ⇒ Object
166
167
168
169
|
# File 'app/models/feedback.rb', line 166
def confirm_classification!
confirm_classification
save!
end
|
#correct_url ⇒ Object
96
97
98
99
100
|
# File 'app/models/feedback.rb', line 96
def correct_url
return if url.blank?
self.url = "http://#{url}" unless %r{^https?://}.match?(url)
end
|
#feedback_not_closed ⇒ Object
203
204
205
|
# File 'app/models/feedback.rb', line 203
def feedback_not_closed
check_article_closed_for_feedback
end
|
#html_postprocess(_field, html) ⇒ Object
91
92
93
94
|
# File 'app/models/feedback.rb', line 91
def html_postprocess(_field, html)
helper = ContentTextHelpers.new
helper.sanitize(helper.auto_link(html), tags: self.class.allowed_tags)
end
|
#parent ⇒ Object
74
75
76
|
# File 'app/models/feedback.rb', line 74
def parent
article
end
|
#permalink_url(_anchor = :ignored, only_path = false) ⇒ Object
87
88
89
|
# File 'app/models/feedback.rb', line 87
def permalink_url(_anchor = :ignored, only_path = false)
article.permalink_url("#{self.class.to_s.downcase}-#{id}", only_path)
end
|
#published? ⇒ Boolean
211
212
213
|
# File 'app/models/feedback.rb', line 211
def published?
ham? || presumed_ham?
end
|
#report_as_ham ⇒ Object
191
192
193
194
195
196
197
198
199
200
201
|
# File 'app/models/feedback.rb', line 191
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
179
180
181
182
183
184
185
186
187
188
189
|
# File 'app/models/feedback.rb', line 179
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
207
208
209
|
# File 'app/models/feedback.rb', line 207
def send_notifications
nil
end
|
#sp_is_spam?(_options = {}) ⇒ Boolean
131
132
133
134
135
136
137
138
139
140
|
# File 'app/models/feedback.rb', line 131
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
114
115
116
|
# File 'app/models/feedback.rb', line 114
def spam_fields
[:title, :body, :ip, :url]
end
|
#spammy? ⇒ Boolean
219
220
221
|
# File 'app/models/feedback.rb', line 219
def spammy?
spam? || presumed_spam?
end
|
#status_confirmed? ⇒ Boolean
215
216
217
|
# File 'app/models/feedback.rb', line 215
def status_confirmed?
ham? || spam?
end
|