Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Small fixes #143

Merged
merged 3 commits into from

2 participants

@Flameeyes

No description provided.

Flameeyes added some commits
@Flameeyes Flameeyes gravatar: fix generated HTML to validate correctly
This introduces a simple alt="" value which is required by the new
HTML5 validation, and also fixes the URL to use the correct &
syntax.
05e1372
@Flameeyes Flameeyes feeds: don't append the subtitle to the page title.
Since the subtitle is already passed to the feed itself, repeating it
here can only cause redundancies. Furthermore with the current version
of Typo, it's possible to change the format of the pages' titles.
6bf9a5b
app/models/feedback.rb
@@ -166,4 +166,18 @@ def feedback_not_closed
errors.add(:article_id, 'Comment are closed')
end
end
+
+ private
+ def akismet
+ @@akismet ||= akismet_client
@mvz Owner
mvz added a note

If @@akismet is false, this will trigger another call to akismet_client. Probably not what you want.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@mvz mvz was assigned
@mvz
Owner

I'm getting some failing specs now.

@Flameeyes

Can you show me where? I can't run the tests here...

@Flameeyes Flameeyes akismet: replace vendored, hacked, old akismet version with 1.0.0
The new version can be loaded through Gemfile instead and might work a
little better.
6b58e49
@Flameeyes

Actually, can you try this? :) Thanks!

@mvz
Owner

Looks good :).

@mvz mvz merged commit 652f6d6 into publify:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 13, 2013
  1. @Flameeyes

    gravatar: fix generated HTML to validate correctly

    Flameeyes authored
    This introduces a simple alt="" value which is required by the new
    HTML5 validation, and also fixes the URL to use the correct &
    syntax.
  2. @Flameeyes

    feeds: don't append the subtitle to the page title.

    Flameeyes authored
    Since the subtitle is already passed to the feed itself, repeating it
    here can only cause redundancies. Furthermore with the current version
    of Typo, it's possible to change the format of the pages' titles.
Commits on Feb 16, 2013
  1. @Flameeyes

    akismet: replace vendored, hacked, old akismet version with 1.0.0

    Flameeyes authored
    The new version can be loaded through Gemfile instead and might work a
    little better.
This page is out of date. Refresh to see the latest.
View
1  Gemfile
@@ -40,6 +40,7 @@ gem 'acts_as_tree_rails3'
gem 'fog'
gem 'recaptcha', :require => 'recaptcha/rails', :branch => 'rails3'
gem 'carrierwave'
+gem 'akismet', '~> 1.0'
# TODO: Replace with jquery
gem 'prototype-rails', '~> 3.2.1'
View
2  app/helpers/application_helper.rb
@@ -70,7 +70,7 @@ def feed_title
if @feed_title.present?
@feed_title
elsif @page_title.present?
- "#{this_blog.blog_name} : #{@page_title}"
+ @page_title
else
this_blog.blog_name
end
View
32 app/models/feedback.rb
@@ -95,10 +95,6 @@ def classify
end
end
- def akismet
- Akismet.new(blog.sp_akismet_key, blog.base_url)
- end
-
def sp_is_spam?(options={})
sp = SpamProtection.new(blog)
Timeout.timeout(defined?($TESTING) ? 10 : 30) do
@@ -111,10 +107,11 @@ def sp_is_spam?(options={})
end
def akismet_is_spam?(options={})
- return false if blog.sp_akismet_key.blank?
+ return false if akismet.nil?
+
begin
Timeout.timeout(defined?($TESTING) ? 30 : 60) do
- akismet.commentCheck(akismet_options)
+ akismet.comment_check(ip, nil, akismet_options)
end
rescue Timeout::Error => e
nil
@@ -143,9 +140,12 @@ def report_as_ham
end
def report_as spam_or_ham
- return if blog.sp_akismet_key.blank?
+ return if akismet.nil?
begin
- Timeout.timeout(defined?($TESTING) ? 5 : 3600) { akismet.send("submit#{spam_or_ham.capitalize}", akismet_options) }
+ Timeout.timeout(defined?($TESTING) ? 5 : 3600) {
+ akismet.send("submit_#{spam_or_ham}",
+ ip, nil, akismet_options)
+ }
rescue Timeout::Error => e
nil
end
@@ -166,4 +166,20 @@ def feedback_not_closed
errors.add(:article_id, 'Comment are closed')
end
end
+
+ private
+ @@akismet = nil
+
+ def akismet
+ @@akismet = akismet_client if @@akismet.nil?
+ return @@akismet == false ? nil : @@akismet
+ end
+
+ def akismet_client
+ return false if blog.sp_akismet_key.blank?
+
+ client = Akismet::Client.new(blog.sp_akismet_key, blog.base_url)
+
+ return client.verify_key ? client : false
+ end
end
View
1  config/application.rb
@@ -62,7 +62,6 @@ class Application < Rails::Application
require 'rails_patch/active_support'
require "#{Rails.root.to_s}/vendor/plugins/typo_login_system/lib/login_system"
- require "#{Rails.root.to_s}/vendor/akismet/akismet"
Date::DATE_FORMATS.merge!(
:long_weekday => '%a %B %e, %Y %H:%M'
View
168 vendor/akismet/akismet.rb
@@ -1,168 +0,0 @@
-# Akismet
-#
-# Author:: David Czarnecki
-# Copyright:: Copyright (c) 2005 - David Czarnecki
-# License:: BSD
-#
-# Heavily modified for Typo by Scott Laird
-#
-class Akismet
- require 'net/http'
- require 'uri'
- require 'timeout'
-
- STANDARD_HEADERS = {
- 'User-Agent' => "Typo/#{TYPO_VERSION} | Akismet Ruby API/1.0",
- 'Content-Type' => 'application/x-www-form-urlencoded'
- }
-
- # Instance variables
- @apiKey
- @blog
- @verifiedKey
- @proxyPort = nil
- @proxyHost = nil
-
- # Create a new instance of the Akismet class
- #
- # apiKey
- # Your Akismet API key
- # blog
- # The blog associated with your api key
- def initialize(apiKey, blog)
- @apiKey = apiKey
- @blog = blog
- @verifiedKey = false
- end
-
- # Set proxy information
- #
- # proxyHost
- # Hostname for the proxy to use
- # proxyPort
- # Port for the proxy
- def setProxy(proxyHost, proxyPort)
- @proxyPort = proxyPort
- @proxyHost = proxyHost
- end
-
- # Call to check and verify your API key. You may then call the #hasVerifiedKey method to see if your key has been validated.
- def verifyAPIKey()
- http = Net::HTTP.new('rest.akismet.com', 80, @proxyHost, @proxyPort)
- path = '/1.1/verify-key'
-
- data="key=#{@apiKey}&blog=#{@blog}"
-
- resp, data = http.post(path, data, STANDARD_HEADERS)
- @verifiedKey = (data == "valid")
- end
-
- # Returns <tt>true</tt> if the API key has been verified, <tt>false</tt> otherwise
- def hasVerifiedKey()
- return @verifiedKey
- end
-
- # Internal call to Akismet. Prepares the data for posting to the Akismet service.
- #
- # akismet_function
- # The Akismet function that should be called
- # user_ip (required)
- # IP address of the comment submitter.
- # user_agent (required)
- # User agent information.
- # referrer (note spelling)
- # The content of the HTTP_REFERER header should be sent here.
- # permalink
- # The permanent location of the entry the comment was submitted to.
- # comment_type
- # May be blank, comment, trackback, pingback, or a made up value like "registration".
- # comment_author
- # Submitted name with the comment
- # comment_author_email
- # Submitted email address
- # comment_author_url
- # Commenter URL.
- # comment_content
- # The content that was submitted.
- # Other server enviroment variables
- # In PHP there is an array of enviroment variables called $_SERVER which contains information about the web server itself as well as a key/value for every HTTP header sent with the request. This data is highly useful to Akismet as how the submited content interacts with the server can be very telling, so please include as much information as possible.
- #options[:user_ip] = user_ip
- #options[:user_agent] = user_agent
- #options[:referrer] = referrer
- #options[:permalink] = permalink
- #options[:comment_type] = comment_type
- #options[:comment_author] = comment_author
- #options[:comment_author_email] = comment_author_email
- #options[:comment_author_url] = comment_author_url
- #options[:comment_content] = comment_content
-
- def callAkismet(akismet_function, options = {})
- result = false
- begin
- Timeout.timeout(5) do
- http = Net::HTTP.new("#{@apiKey}.rest.akismet.com", 80, @proxyHost, @proxyPort)
- path = "/1.1/#{akismet_function}"
-
- options[:blog] = @blog
- params=[]
-
- options.each_key do |key|
- params.push "#{key}=#{CGI.escape(options[key].to_s)}"
- end
-
- data = params.join('&')
- resp, data = http.post(path, data, STANDARD_HEADERS)
-
- unless data == 'true' or data == 'false' or data == ''
- STDERR.puts "AKISMET error: #{data}"
- end
-
- result = (data == "true" or data == '')
- end
- rescue => err
- STDERR.puts "AKISMET exception: #{err}"
- end
-
- return result
- end
-
- protected :callAkismet
-
- # This is basically the core of everything. This call takes a number of arguments and characteristics about the submitted content and then returns a thumbs up or thumbs down. Almost everything is optional, but performance can drop dramatically if you exclude certain elements.
- #
- # user_ip (required)
- # IP address of the comment submitter.
- # user_agent (required)
- # User agent information.
- # referrer (note spelling)
- # The content of the HTTP_REFERER header should be sent here.
- # permalink
- # The permanent location of the entry the comment was submitted to.
- # comment_type
- # May be blank, comment, trackback, pingback, or a made up value like "registration".
- # comment_author
- # Submitted name with the comment
- # comment_author_email
- # Submitted email address
- # comment_author_url
- # Commenter URL.
- # comment_content
- # The content that was submitted.
- # Other server enviroment variables
- # In PHP there is an array of enviroment variables called $_SERVER which contains information about the web server itself as well as a key/value for every HTTP header sent with the request. This data is highly useful to Akismet as how the submited content interacts with the server can be very telling, so please include as much information as possible.
- def commentCheck(options = {})
- return callAkismet('comment-check', options)
- end
-
- # This call is for submitting comments that weren't marked as spam but should have been. It takes identical arguments as comment check.
- # The call parameters are the same as for the #commentCheck method.
- def submitSpam(options = {})
- callAkismet('submit-spam', options)
- end
-
- # This call is intended for the marking of false positives, things that were incorrectly marked as spam. It takes identical arguments as comment check and submit spam.
- # The call parameters are the same as for the #commentCheck method.
- def submitHam(options = {})
- callAkismet('submit-ham', options)
- end
-end
View
4 vendor/plugins/typo_avatar_gravatar/lib/typo_avatar_gravatar.rb
@@ -25,8 +25,8 @@ def gravatar_tag(email, options={})
options[:default] = CGI::escape(options[:default]) if options.include?(:default)
options[:size] ||= 48
- url = "http://www.gravatar.com/avatar.php?" << options.map { |key,value| "#{key}=#{value}" }.sort.join("&")
- "<img src=\"#{url}\" class=\"avatar gravatar\" />"
+ url = "http://www.gravatar.com/avatar.php?" << options.map { |key,value| "#{key}=#{value}" }.sort.join("&amp;")
+ "<img src=\"#{url}\" class=\"avatar gravatar\" alt=\"Gravatar\" />"
end
end
end
Something went wrong with that request. Please try again.