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, included, #really_send_notifications, #send_notification_to_user, #text_filter
#create_guid
Class Method Details
74
75
76
|
# File 'app/models/feedback.rb', line 74
def self.allowed_tags
@allowed_tags ||= Rails::Html::SafeListSanitizer.allowed_tags - ["img"]
end
|
.paginated(page, per_page) ⇒ Object
FIXME: Inline this method
70
71
72
|
# File 'app/models/feedback.rb', line 70
def self.paginated(page, per_page)
page(page).per(per_page)
end
|
Instance Method Details
#akismet_is_spam?(_options = {}) ⇒ Boolean
158
159
160
161
162
163
164
165
166
167
168
|
# File 'app/models/feedback.rb', line 158
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
122
123
124
125
126
127
128
|
# File 'app/models/feedback.rb', line 122
def akismet_options
{ type: self.class.to_s.downcase,
author: originator,
author_email: email,
author_url: url,
text: body }
end
|
#change_state! ⇒ Object
170
171
172
173
174
175
176
177
178
179
180
|
# File 'app/models/feedback.rb', line 170
def change_state!
result = ""
if spam? || presumed_spam?
mark_as_ham!
result = "ham"
else
mark_as_spam!
result = "spam"
end
result
end
|
#classify ⇒ Object
134
135
136
137
138
139
140
141
142
143
144
145
|
# File 'app/models/feedback.rb', line 134
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
82
83
84
85
86
87
88
89
|
# File 'app/models/feedback.rb', line 82
def classify_content
return unless unclassified?
case classify
when :ham then presume_ham
else presume_spam
end
end
|
#confirm_classification ⇒ Object
187
188
189
190
191
192
193
|
# File 'app/models/feedback.rb', line 187
def confirm_classification
if presumed_spam?
mark_as_spam
elsif presumed_ham?
mark_as_ham
end
end
|
#confirm_classification! ⇒ Object
182
183
184
185
|
# File 'app/models/feedback.rb', line 182
def confirm_classification!
confirm_classification
save!
end
|
#correct_url ⇒ Object
100
101
102
103
104
|
# File 'app/models/feedback.rb', line 100
def correct_url
return if url.blank?
self.url = "http://#{url}" unless %r{^https?://}.match?(url)
end
|
#feedback_allowed ⇒ Object
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
# File 'app/models/feedback.rb', line 106
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
95
96
97
98
|
# File 'app/models/feedback.rb', line 95
def html_postprocess(_field, html)
helper = PublifyCore::ContentTextHelpers.new
helper.sanitize(helper.auto_link(html), tags: self.class.allowed_tags)
end
|
#parent ⇒ Object
78
79
80
|
# File 'app/models/feedback.rb', line 78
def parent
article
end
|
#permalink_url(_anchor = :ignored, only_path = false) ⇒ Object
91
92
93
|
# File 'app/models/feedback.rb', line 91
def permalink_url(_anchor = :ignored, only_path = false)
article.permalink_url("#{self.class.to_s.downcase}-#{id}", only_path)
end
|
#published? ⇒ Boolean
223
224
225
|
# File 'app/models/feedback.rb', line 223
def published?
ham? || presumed_ham?
end
|
#report_as_ham ⇒ Object
207
208
209
210
211
212
213
214
215
216
217
|
# File 'app/models/feedback.rb', line 207
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
195
196
197
198
199
200
201
202
203
204
205
|
# File 'app/models/feedback.rb', line 195
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
219
220
221
|
# File 'app/models/feedback.rb', line 219
def send_notifications
nil
end
|
#sp_is_spam?(_options = {}) ⇒ Boolean
147
148
149
150
151
152
153
154
155
156
|
# File 'app/models/feedback.rb', line 147
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
130
131
132
|
# File 'app/models/feedback.rb', line 130
def spam_fields
[:title, :body, :ip, :url]
end
|
#spammy? ⇒ Boolean
231
232
233
|
# File 'app/models/feedback.rb', line 231
def spammy?
spam? || presumed_spam?
end
|
#status_confirmed? ⇒ Boolean
227
228
229
|
# File 'app/models/feedback.rb', line 227
def status_confirmed?
ham? || spam?
end
|