]> git.openstreetmap.org Git - rails.git/blobdiff - lib/rich_text.rb
Merge remote-tracking branch 'upstream/pull/2023'
[rails.git] / lib / rich_text.rb
index 83eb235401c6f88cf0a0d6eab46b9ce781dcea2c..d0539b2b081293e12d68d80b8b1058286c8167d8 100644 (file)
@@ -1,4 +1,8 @@
 module RichText
 module RichText
+  SPAMMY_PHRASES = [
+    "Business Description:", "Additional Keywords:"
+  ].freeze
+
   def self.new(format, text)
     case format
     when "html" then HTML.new(text || "")
   def self.new(format, text)
     case format
     when "html" then HTML.new(text || "")
@@ -36,7 +40,13 @@ module RichText
         link_proportion = link_size.to_f / doc.content.length.to_f
       end
 
         link_proportion = link_size.to_f / doc.content.length.to_f
       end
 
-      [link_proportion - 0.2, 0.0].max * 200 + link_count * 40
+      spammy_phrases = SPAMMY_PHRASES.count do |phrase|
+        doc.content.include?(phrase)
+      end
+
+      [link_proportion - 0.2, 0.0].max * 200 +
+        link_count * 40 +
+        spammy_phrases * 40
     end
 
     protected
     end
 
     protected
@@ -47,9 +57,9 @@ module RichText
 
     def linkify(text)
       if text.html_safe?
 
     def linkify(text)
       if text.html_safe?
-        Rinku.auto_link(text, :urls, tag_options(:rel => "nofollow")).html_safe
+        Rinku.auto_link(text, :urls, tag_builder.tag_options(:rel => "nofollow")).html_safe
       else
       else
-        Rinku.auto_link(text, :urls, tag_options(:rel => "nofollow"))
+        Rinku.auto_link(text, :urls, tag_builder.tag_options(:rel => "nofollow"))
       end
     end
   end
       end
     end
   end