def spam_score
changeset_score = self.changesets.limit(10).length * 50
trace_score = self.traces.limit(10).length * 50
- diary_entry_score = self.diary_entries.inject(0) { |s,e| s += OSM.spam_score(e.body) }
- diary_comment_score = self.diary_comments.inject(0) { |s,e| s += OSM.spam_score(e.body) }
+ diary_entry_score = self.diary_entries.inject(0) { |s,e| s += e.body.spam_score }
+ diary_comment_score = self.diary_comments.inject(0) { |s,c| s += c.body.spam_score }
- score = OSM.spam_score(self.description)
+ score = self.description.spam_score
score += diary_entry_score / self.diary_entries.length if self.diary_entries.length > 0
score += diary_comment_score / self.diary_comments.length if self.diary_comments.length > 0
score -= changeset_score
require 'rexml/text'
require 'xml/libxml'
require 'digest/md5'
- require 'nokogiri'
if defined?(SystemTimer)
Timer = SystemTimer
"AND #{prefix}longitude BETWEEN #{bbox.min_lon} AND #{bbox.max_lon}"
end
- # Return a spam score for a chunk of text
- def self.spam_score(text)
- link_count = 0
- link_size = 0
-
- doc = Nokogiri::HTML(Rinku.auto_link(text, :urls))
-
- if doc.content.length > 0
- doc.xpath("//a").each do |link|
- link_count += 1
- link_size += link.content.length
- end
-
- link_proportion = link_size.to_f / doc.content.length.to_f
- else
- link_proportion = 0
- end
-
- return [link_proportion - 0.2, 0.0].max * 200 + link_count * 20
- end
-
def self.legal_text_for_country(country_code)
file_name = File.join(Rails.root, "config", "legales", country_code.to_s + ".yml")
file_name = File.join(Rails.root, "config", "legales", DEFAULT_LEGALE + ".yml") unless File.exist? file_name
end
end
- class HTML < String
+ class Base < String
+ def spam_score
+ link_count = 0
+ link_size = 0
+
+ doc = Nokogiri::HTML(to_html)
+
+ if doc.content.length > 0
+ doc.xpath("//a").each do |link|
+ link_count += 1
+ link_size += link.content.length
+ end
+
+ link_proportion = link_size.to_f / doc.content.length.to_f
+ else
+ link_proportion = 0
+ end
+
+ return [link_proportion - 0.2, 0.0].max * 200 + link_count * 20
+ end
+ end
+
+ class HTML < Base
include ActionView::Helpers::TextHelper
include ActionView::Helpers::TagHelper
end
end
- class Markdown < String
+ class Markdown < Base
def to_html
html_parser.render(self).html_safe
end