Sha256: 4f92a7f8d58b40c16035298b0db0a3ed42fe8c8f68331470caa5db20b4f206c6

Contents?: true

Size: 1.75 KB

Versions: 3

Compression:

Stored size: 1.75 KB

Contents

class Plugins::Textfilters::AmazonController < TextFilterPlugin::PostProcess
  plugin_display_name "Amazon"
  plugin_description "Automatically turn amazon:ASIN URLs into affiliate links to Amazon items using your Amazon Associate ID"

  def self.filtertext(controller, content, text, params)
    associateid = config_value(params,'amazon-associate-id')
    domain_suffix = config_value(params,'amazon-domain-suffix')
    content.whiteboard[:asins] = []
    text.gsub(/<a href="amazon:([^"]+)"/) do |match|
      content.whiteboard[:asins] = content.whiteboard[:asins].to_a | [$1]
      "<a href=\"http://www.amazon.#{domain_suffix}/exec/obidos/ASIN/#{$1}/#{associateid}\""
    end
  end

  def self.default_config
    {"amazon-associate-id" => {:default => "",
                               :description => "Amazon Associate ID",
                               :help => "Your Amazon Associate's ID (see http://amazon.com/associates).  Typo's Amazon filter will automatically add this ID to all amazon:ASIN URLs that you create."},
      "amazon-domain-suffix" => {:default => "com",
                               :description => "Amazon Domain Suffix",
                               :help => "Your Amazon Domain Suffix depends on the language or country you life in."}
                               }
  end

  def self.help_text
    %{
You can use `amazon:XXXX`-style URLs to refer to items for sale on
[Amazon.com](http://www.amazon.com).  If you provide an Amazon associate
ID in the filter configuration, then each of these URLs will be tagged
with your associate ID and you'll make money if someone buys an item
while using your link.  Example:

    <a href="amazon:097669400X">

turns into

    <a href="http://www.amazon.com/exec/obidos/ASIN/097669400X/scottstuff-20">}
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
typo-3.99.0 components/plugins/textfilters/amazon_controller.rb
typo-3.99.1 components/plugins/textfilters/amazon_controller.rb
typo-3.99.2 components/plugins/textfilters/amazon_controller.rb