Class: Feedback
Constant Summary
StringLengthLimit::STRING_LIMIT
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
75
76
77
|
# File 'app/models/feedback.rb', line 75
def self.allowed_tags
@allowed_tags ||= Rails::Html::SafeListSanitizer.allowed_tags - ["img"]
end
|
.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
159
160
161
162
163
164
165
166
167
168
169
|
# File 'app/models/feedback.rb', line 159
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
123
124
125
126
127
128
129
|
# File 'app/models/feedback.rb', line 123
def akismet_options
{ type: self.class.to_s.downcase,
author: originator,
author_email: email,
author_url: url,
text: body }
end
|
#change_state! ⇒ Object
171
172
173
174
175
176
177
178
179
180
181
|
# File 'app/models/feedback.rb', line 171
def change_state!
result = ""
if spam? || presumed_spam?
mark_as_ham!
result = "ham"
else
mark_as_spam!
result = "spam"
end
result
end
|
#classify ⇒ Object
135
136
137
138
139
140
141
142
143
144
145
146
|
# File 'app/models/feedback.rb', line 135
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
83
84
85
86
87
88
89
90
|
# File 'app/models/feedback.rb', line 83
def classify_content
return unless unclassified?
case classify
when :ham then presume_ham
else presume_spam
end
end
|
#confirm_classification ⇒ Object
188
189
190
191
192
193
194
|
# File 'app/models/feedback.rb', line 188
def confirm_classification
if presumed_spam?
mark_as_spam
elsif presumed_ham?
mark_as_ham
end
end
|
#confirm_classification! ⇒ Object
183
184
185
186
|
# File 'app/models/feedback.rb', line 183
def confirm_classification!
confirm_classification
save!
end
|
#correct_url ⇒ Object
101
102
103
104
105
|
# File 'app/models/feedback.rb', line 101
def correct_url
return if url.blank?
self.url = "http://#{url}" unless %r{^https?://}.match?(url)
end
|
#feedback_allowed ⇒ Object
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
# File 'app/models/feedback.rb', line 107
def feedback_allowed
return unless article
unless blog_allows_feedback?
errors.add(:base, "#{plural_model_name} are disabled")
return
end
unless article_allows_feedback?
errors.add(:article, "Article is not open for #{plural_model_name.downcase}")
return
end
errors.add(:article, "#{plural_model_name} are closed") if article_closed_for_feedback?
end
|
#html_postprocess(_field, html) ⇒ Object
96
97
98
99
|
# File 'app/models/feedback.rb', line 96
def html_postprocess(_field, html)
helper = ContentTextHelpers.new
helper.sanitize(helper.auto_link(html), tags: self.class.allowed_tags)
end
|
#parent ⇒ Object
79
80
81
|
# File 'app/models/feedback.rb', line 79
def parent
article
end
|
#permalink_url(_anchor = :ignored, only_path = false) ⇒ Object
92
93
94
|
# File 'app/models/feedback.rb', line 92
def permalink_url(_anchor = :ignored, only_path = false)
article.permalink_url("#{self.class.to_s.downcase}-#{id}", only_path)
end
|
#published? ⇒ Boolean
224
225
226
|
# File 'app/models/feedback.rb', line 224
def published?
ham? || presumed_ham?
end
|
#report_as_ham ⇒ Object
208
209
210
211
212
213
214
215
216
217
218
|
# File 'app/models/feedback.rb', line 208
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
196
197
198
199
200
201
202
203
204
205
206
|
# File 'app/models/feedback.rb', line 196
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
220
221
222
|
# File 'app/models/feedback.rb', line 220
def send_notifications
nil
end
|
#sp_is_spam?(_options = {}) ⇒ Boolean
148
149
150
151
152
153
154
155
156
157
|
# File 'app/models/feedback.rb', line 148
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
131
132
133
|
# File 'app/models/feedback.rb', line 131
def spam_fields
[:title, :body, :ip, :url]
end
|
#spammy? ⇒ Boolean
232
233
234
|
# File 'app/models/feedback.rb', line 232
def spammy?
spam? || presumed_spam?
end
|
#status_confirmed? ⇒ Boolean
228
229
230
|
# File 'app/models/feedback.rb', line 228
def status_confirmed?
ham? || spam?
end
|