File: google_adsense.rb

package info (click to toggle)
tdiary-contrib 5.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 2,772 kB
  • sloc: ruby: 17,305; javascript: 8,263; lisp: 562; xml: 451; php: 61; sql: 40; makefile: 18
file content (132 lines) | stat: -rw-r--r-- 6,328 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#
# Google AdSense plugin for tDiary
#
# Copyright (C) 2004 Kazuhiko <kazuhiko@fdiary.net>
# You can redistribute it and/or modify it under GPL2.
#
# modified by TADA Tadashi <t@tdtds.jp>
#
def google_adsense( layout = nil, slot = nil )
	google_adsense_init( layout )
	google_ad_client = "pub-3317603667498586"
	google_ad_size = [
		[468, 60],	# 0
		[120, 600],	# 1
		[728, 90],	# 2
		[300, 250],	# 3
		[125, 125],	# 4
		[160, 600],	# 5
		[120, 240],	# 6
		[180, 150], # 7
		[250, 250], # 8
		[336, 280], # 9
		[200, 200], # 10
		[234, 60]   # 11
	]
	result = <<-EOF
		<script type="text/javascript"><!--
		google_ad_client = "#{google_ad_client}";
		google_ad_width = #{google_ad_size[@conf['google_adsense.layout']][0]};
		google_ad_height = #{google_ad_size[@conf['google_adsense.layout']][1]};
	EOF

	if slot then
		result << <<-EOF
		google_ad_slot = "#{slot}";
		EOF
	else
		result << <<-EOF
		google_alternate_ad_url = ""
		google_ad_format = "#{google_ad_size[@conf['google_adsense.layout']][0]}x#{google_ad_size[@conf['google_adsense.layout']][1]}_as";
		google_color_border = "#{h @conf['google_adsense.color.border']}";
		google_color_bg = "#{h @conf['google_adsense.color.bg']}";
		google_color_link = "#{h @conf['google_adsense.color.link']}";
		google_color_url = "#{h @conf['google_adsense.color.url']}";
		google_color_text = "#{h @conf['google_adsense.color.text']}";
		EOF
	end

	result << <<-EOF
		//--></script>
		<script type="text/javascript"
			src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
		</script>
	EOF
	result.gsub( /^\t+/, '' )
end

def google_adsense_init( layout )
	if layout != nil then
		@conf['google_adsense.layout'] = layout.to_i
	else
		@conf['google_adsense.layout'] = 0 unless @conf['google_adsense.layout']
	end
	@conf['google_adsense.layout'] = @conf['google_adsense.layout'].to_i
	if @conf['google_adsense.layout'] < 0 or @conf['google_adsense.layout'] > 11 then
		@conf['google_adsense.layout'] = 0
	end

	@conf['google_adsense.color.border'] = 'CCCCCC' unless @conf['google_adsense.color.border']
	@conf['google_adsense.color.bg'] = 'FFFFFF' unless @conf['google_adsense.color.bg']
	@conf['google_adsense.color.link'] = '000000' unless @conf['google_adsense.color.link']
	@conf['google_adsense.color.url'] = '666666' unless @conf['google_adsense.color.url']
	@conf['google_adsense.color.text'] = '333333' unless @conf['google_adsense.color.text']
end

add_section_leave_proc do |date,index|
	if @mode == 'day' and index == 1 and @conf['google_adsense.slot'] then
		%Q|<div class="google-adsense">#{google_adsense( 0, @conf['google_adsense.slot'] )}</div>|
	else
		''
	end
end

# insert section target tags
add_body_enter_proc do |date|
	"<!-- google_ad_section_start -->\n"
end
add_body_leave_proc do |date|
	"<!-- google_ad_section_end -->\n"
end

add_conf_proc( 'google_adsense', 'Google AdSense' ) do
	if @mode == 'saveconf' then
		@conf['google_adsense.layout'] = @cgi.params['google_adsense.layout'][0].to_i
		@conf['google_adsense.color.border'] = @cgi.params['google_adsense.color.border'][0]
		@conf['google_adsense.color.bg'] = @cgi.params['google_adsense.color.bg'][0]
		@conf['google_adsense.color.link'] = @cgi.params['google_adsense.color.link'][0]
		@conf['google_adsense.color.url'] = @cgi.params['google_adsense.color.url'][0]
		@conf['google_adsense.color.text'] = @cgi.params['google_adsense.color.text'][0]
	else
		google_adsense_init( nil )
	end

	<<-HTML
	<h3>バナーのサイズ(#{@conf['google_adsense.layout']})</h3>
	<p>広告バナーのサイズは全部で12種類あります。お好きなサイズを選んでください。</p>
	<p><select name="google_adsense.layout">
		<option value="11"#{' selected' if @conf['google_adsense.layout'] == 11}>横長微小・広告1つ(234x60)</option>
		<option value="0"#{' selected' if @conf['google_adsense.layout'] == 0}>横長小・広告2つ(468x60)</option>
		<option value="2"#{' selected' if @conf['google_adsense.layout'] == 2}>横長大・広告4つ(728x90)</option>
		<option value="4"#{' selected' if @conf['google_adsense.layout'] == 4}>方形微小・広告1つ(125x125)</option>
		<option value="10"#{' selected' if @conf['google_adsense.layout'] == 10}>方形小・広告2つ(200x200)</option>
		<option value="8"#{' selected' if @conf['google_adsense.layout'] == 8}>方形中・広告3つ(250x250)</option>
		<option value="7"#{' selected' if @conf['google_adsense.layout'] == 7}>矩形小・広告1つ(180x150)</option>
		<option value="3"#{' selected' if @conf['google_adsense.layout'] == 3}>矩形大・広告4つ(300x250)</option>
		<option value="9"#{' selected' if @conf['google_adsense.layout'] == 9}>矩形特大・広告4つ(336x280)</option>
		<option value="6"#{' selected' if @conf['google_adsense.layout'] == 6}>縦長小・広告2つ(120x240)</option>
		<option value="1"#{' selected' if @conf['google_adsense.layout'] == 1}>縦長中・広告4つ(120x600)</option>
		<option value="5"#{' selected' if @conf['google_adsense.layout'] == 5}> 縦長大・広告5つ(160x600)</option>
	</select></p>
	<h3>バナーの色</h3>
	<p>バナーの各パーツの色を指定できます。HTMLやCSSと同じ、6桁の16進数で指定します。</p>
	<table style="margin-left: 2em;">
		<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>
		<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>
		<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>
		<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>
		<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>
	</table>
	HTML
end