root/platform/tdiary/plugin/google_adsense.rb

Revision 5057, 5.5 kB (checked in by hsbt, 11 months ago)

platform/tdiary/plugin: changed file encoding to UTF-8

Line 
1#
2# Google AdSense plugin for tDiary
3#
4# Copyright (C) 2004 Kazuhiko <kazuhiko@fdiary.net>
5# You can redistribute it and/or modify it under GPL2.
6#
7# modified by TADA Tadashi <sho@spc.gr.jp>
8#
9def google_adsense( layout = nil )
10        google_adsense_init( layout )
11        google_ad_client = "pub-3317603667498586"
12        google_ad_size = [
13                [468, 60],      # 0
14                [120, 600],     # 1
15                [728, 90],      # 2
16                [300, 250],     # 3
17                [125, 125],     # 4
18                [160, 600],     # 5
19                [120, 240],     # 6
20                [180, 150], # 7
21                [250, 250], # 8
22                [336, 280]  # 9
23        ]
24        <<-EOF
25<script type="text/javascript"><!--
26google_ad_client = "#{google_ad_client}";
27google_alternate_ad_url = ""
28google_ad_width = #{google_ad_size[@conf['google_adsense.layout']][0]};
29google_ad_height = #{google_ad_size[@conf['google_adsense.layout']][1]};
30google_ad_format = "#{google_ad_size[@conf['google_adsense.layout']][0]}x#{google_ad_size[@conf['google_adsense.layout']][1]}_as";
31google_color_border = "#{h @conf['google_adsense.color.border']}";
32google_color_bg = "#{h @conf['google_adsense.color.bg']}";
33google_color_link = "#{h @conf['google_adsense.color.link']}";
34google_color_url = "#{h @conf['google_adsense.color.url']}";
35google_color_text = "#{h @conf['google_adsense.color.text']}";
36//--></script>
37<script type="text/javascript"
38        src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
39</script>
40  EOF
41end
42
43def google_adsense_init( layout )
44        if layout != nil then
45                @conf['google_adsense.layout'] = layout.to_i
46        else
47                @conf['google_adsense.layout'] = 0 unless @conf['google_adsense.layout']
48        end
49        @conf['google_adsense.layout'] = @conf['google_adsense.layout'].to_i
50        if @conf['google_adsense.layout'] < 0 or @conf['google_adsense.layout'] > 9 then
51                @conf['google_adsense.layout'] = 0
52        end
53
54        @conf['google_adsense.color.border'] = 'CCCCCC' unless @conf['google_adsense.color.border']
55        @conf['google_adsense.color.bg'] = 'FFFFFF' unless @conf['google_adsense.color.bg']
56        @conf['google_adsense.color.link'] = '000000' unless @conf['google_adsense.color.link']
57        @conf['google_adsense.color.url'] = '666666' unless @conf['google_adsense.color.url']
58        @conf['google_adsense.color.text'] = '333333' unless @conf['google_adsense.color.text']
59end
60
61# insert section target tags
62add_body_enter_proc do |date|
63        "<!-- google_ad_section_start -->\n"
64end
65add_body_leave_proc do |date|
66        "<!-- google_ad_section_end -->\n"
67end
68
69add_conf_proc( 'google_adsense', 'Google AdSense' ) do
70        if @mode == 'saveconf' then
71                @conf['google_adsense.layout'] = @cgi.params['google_adsense.layout'][0].to_i
72                @conf['google_adsense.color.border'] = @cgi.params['google_adsense.color.border'][0]
73                @conf['google_adsense.color.bg'] = @cgi.params['google_adsense.color.bg'][0]
74                @conf['google_adsense.color.link'] = @cgi.params['google_adsense.color.link'][0]
75                @conf['google_adsense.color.url'] = @cgi.params['google_adsense.color.url'][0]
76                @conf['google_adsense.color.text'] = @cgi.params['google_adsense.color.text'][0]
77        else
78                google_adsense_init( nil )
79        end
80
81        <<-HTML
82        <h3>バナーのサイズ(#{@conf['google_adsense.layout']})</h3>
83        <p>広告バナーのサイズは全部で7種類あります。お好きなサイズを選んでください。</p>
84        <p><select name="google_adsense.layout">
85                <option value="0"#{' selected' if @conf['google_adsense.layout'] == 0}>横長小・広告2つ(468, 60)</option>
86                <option value="2"#{' selected' if @conf['google_adsense.layout'] == 2}>横長大・広告4つ(728, 90)</option>
87                <option value="4"#{' selected' if @conf['google_adsense.layout'] == 4}>方形微小・広告1つ(125, 125)</option>
88                <option value="7"#{' selected' if @conf['google_adsense.layout'] == 7}>方形小・広告1つ(180, 150)</option>
89                <option value="8"#{' selected' if @conf['google_adsense.layout'] == 8}>方形中・広告3つ(250, 250)</option>
90                <option value="3"#{' selected' if @conf['google_adsense.layout'] == 3}> 方形大・広告4つ(300, 250)</option>
91                <option value="9"#{' selected' if @conf['google_adsense.layout'] == 9}> 方形特大・広告4つ(336, 280)</option>
92                <option value="6"#{' selected' if @conf['google_adsense.layout'] == 6}> 縦長小・広告2つ(120, 240)</option>
93                <option value="1"#{' selected' if @conf['google_adsense.layout'] == 1}> 縦長中・広告4つ(120, 600)</option>
94                <option value="5"#{' selected' if @conf['google_adsense.layout'] == 5}> 縦長大・広告5つ(160, 600)</option>
95        </select></p>
96        <h3>バナーの色</h3>
97        <p>バナーの各パーツの色を指定できます。HTMLやCSSと同じ、6桁の16進数で指定します。</p>
98        <table style="margin-left: 2em;">
99                <tr><td>枠</td><td style="background-color: ##{h @conf['google_adsense.color.border']};">&nbsp;<input name="google_adsense.color.border" size="7" value="#{h @conf['google_adsense.color.border']}">&nbsp;</td></tr>
100                <tr><td>背景</td><td style="background-color: ##{h @conf['google_adsense.color.bg']};">&nbsp;<input name="google_adsense.color.bg" size="7" value="#{h @conf['google_adsense.color.bg']}">&nbsp;</td></tr>
101                <tr><td>リンク</td><td style="background-color: ##{h @conf['google_adsense.color.link']};">&nbsp;<input name="google_adsense.color.link" size="7" value="#{h @conf['google_adsense.color.link']}">&nbsp;</td></tr>
102                <tr><td>URL</td><td style="background-color: ##{h @conf['google_adsense.color.url']};">&nbsp;<input name="google_adsense.color.url" size="7" value="#{h @conf['google_adsense.color.url']}">&nbsp;</td></tr>
103                <tr><td>テキスト</td><td style="background-color: ##{h @conf['google_adsense.color.text']};">&nbsp;<input name="google_adsense.color.text" size="7" value="#{h @conf['google_adsense.color.text']}">&nbsp;</td></tr>
104        </table>
105        HTML
106end
107
Note: See TracBrowser for help on using the browser.