About
ǶϷۥ֥CISSPʾ󥷥ƥॻƥץեåʥǧˤĤ⺣˿òҤǴäƤޤ

LINKS

Advertisements

Jul 24, 2005


[Blosxom] ASINプラグイン・改 00:26
というわけで、新しいAmazonアフィリエイトに対応したBlosxom用ASINプラグインを作ってみました。

予め定義した携帯用Flavourかどうかを判別し、<a href="ASIN:1234567890"></a>として張ったリンクをAmazon.co.jpアソシエイトプログラムの個別商品リンクに書き換えます。

(モバイル用個別商品リンク)
<a href="http://www.amazon.co.jp/gp/aw/rd.html?url=/gp/aw/d.html
&lc=msn&a=[ASINコード]&at=[アソシエイトID]"&uid=NULLGWDOCOMO>
<img src="http://www.assoc-amazon.jp/e/ir?t=[アソシエイトID]&l=msn&o=9
&a=[ASINコード]" width="1" height="1" border="0" alt=""
style="border:none !important; margin:0px !important;" />

(PC用個別商品リンク)
<a href="http://www.amazon.co.jp/exec/obidos/redirect?path=ASIN/[ASINコード]
&link_code=as2&camp=247&tag=[アソシエイトID]&creative=1211" >
<img src="http://www.assoc-amazon.jp/e/ir?t=[アソシエイトID]&l=as2&o=9
&a=[ASINコード]" width="1" height="1" border="0" alt=""
style="border:none !important; margin:0px !important;" />

以前のエントリでも書いた、インプレッションデータ用の1×1サイズの画像も追加されるようになってます。またモバイル向け商品画像は自動的に80x80にサイズ変換がされるようURL変換を合わせて行うようにしてあります。

このまま差し替えて使い物になるかはまだ怪しいですが、一応晒してみるということで。


# Blosxom Plugin: ASIN
# Author: Nelson Minar <nelson@monkey.org>
# Version: 20030301
# http://www.nelson.monkey.org/~nelson/weblog/
# License: Public Domain

# Revised Version: 20050723
# Revised By: Hitoshi Kikuchi <h_kiku@bywaysideway.com>
# License: Public Domain

# ASIN is a Blosxom plugin that simplifies linking into Amazon's catalog.
# A link in a story like this:
# <a href="asin:B000003RGY">the album I'm listening to</a>
#
# In the case of PC access, turn into a link like this:
# <a href="http://www.amazon.co.jp/exec/obidos/redirect?path=ASIN/B000003RGY&
# link_code=as2&camp=247&tag=hogehoge-22&creative=1211">
# <img src="http://www.assoc-amazon.jp/e/ir?t=hogehoge-22&l=as2&o=9&a=B000003RGY"
# width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" />
# the album I'm listening to</a>
#
# In the case of Mobile access, turn into a link like this:
# <a href="http://www.amazon.co.jp/gp/aw/rd.html?url=/gp/aw/d.html&
# lc=msn&a=B000003RGY&at=hogehoge-22&uid=NULLGWDOCOMO">
# <img src="http://www.assoc-amazon.jp/e/ir?t=hogehoge-22&l=msn&o=9&a=B000003RGY"
# width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" />
# the album I'm listening to</a>
#
# This link format is not a guaranteed standard, in particular link_code and img src part.
# For the authority see
# https://associates.amazon.co.jp/gp/associates/network/build-links/individual/main.html
#
# Installation:
# Modify the $associateID (or don't :-)
# Modify the $mobFlavour
# Drop asin into your plugins directory
#

package asin;

$associateID = 'bywaysideway-22';
$mobFlavour = 'm2';

sub start {
1;
}

sub rewriteASIN {
if ($Blosxom::flavour eq $mobFlavour) {
my ($url) = @_;
$url =~ s%<a\s[^>]*href=\"asin:(\w+)[^>]+>%"<a href=\"http://www.amazon.co.jp/gp/aw/rd.html?url=\%2Fgp\%2Faw\%2Fd.html&lc=msn&a=$1&at=$associateID&uid=NULLGWDOCOMO\"><img src=\"http://www.assoc-amazon.jp/e/ir?t=$associateID&l=msn&o=9&a=$1\" width=\"1\" height=\"1\" border=\"0\" alt=\"\" style=\"border:none !important; margin:0px !important;\" />"%ies;
return $url;
}

my ($url) = @_;
$url =~ s%<a\s[^>]*href=\"asin:(\w+)[^>]+>%"<a href=\"http://www.amazon.co.jp/exec/obidos/redirect?path=ASIN/$1&link_code=as2&camp=247&tag=$associateID&creative=1211\" target=\"_blank\"><img src=\"http://www.assoc-amazon.jp/e/ir?t=$associateID&l=as2&o=9&a=$1\" width=\"1\" height=\"1\" border=\"0\" alt=\"\" style=\"border:none !important; margin:0px !important;\" />"%ies;
return $url;

}

sub rewriteIMG {
my ($url) = @_;
$url =~ s|([A-Z0-9]+\.0[0-9]\.)\w+\.jpg|$1_AA80_FMjpg_SCTZZZZZZZ_\.jpg|g;
return $url;

}

# Modify the body of stories by rewriting asin: URIs to real URLs
sub story {
my($pkg, $path, $filename, $story_ref, $title_ref, $body_ref) = @_;
# Rewrite any <a href="asin:..."> tag in the post body
$$body_ref =~ s/(<a\s[^>]*href="asin:[^>]+>)/rewriteASIN($1)/geis;

if ($Blosxom::flavour eq $mobFlavour) {
$$body_ref =~ s/(<img\s[^>]*src="http:\/\/images(-)*\w*\.amazon\.[^>]+\/>)/rewriteIMG($1)/geis;
}

1;
}

1;


ブログランキング・にほんブログ村へ にほんブログ村 サラリーマン日記ブログ 30代サラリーマンへ [ブログランキングへ]
| コメント&トラックバック (1) | Parmanent link /Blosxom/1122132369.html |
モバイル用のクエリ文字列 - Posted by kiku at 2005/07/24 (Sun) 23:53:32
モバイル用の部分を1点修正しました。

&uid=NULLGWDOCOMO
をクエリ文字列末尾に付加。はずさないとVodafone以外の大手では動かない可能性が。でもVodafone的には非推奨クエリなんですけど。。。。
トラックバック、コメントは必要に応じて削除する場合があります。
This blog can only accept your comment in Japanese.
If you want to comment me, please start with greetings using 2-byte chars. :-)
Thank you for your understanding.
トラックバックの送信先:
http://blog.bywaysideway.com/Blosxom/1122132369.tb
コメントを書く:

Ready to post a comment.