jpmobile 0.0.4 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +227 -0
- data/Rakefile +6 -13
- data/lib/jpmobile/docomo_guid.rb +42 -0
- data/lib/jpmobile/filter.rb +1 -1
- data/lib/jpmobile/helpers.rb +2 -1
- data/lib/jpmobile/hook_action_controller.rb +12 -0
- data/lib/jpmobile/hook_action_view.rb +82 -72
- data/lib/jpmobile/{hook_abstract_request.rb → hook_request.rb} +1 -1
- data/lib/jpmobile/mobile/au.rb +9 -3
- data/lib/jpmobile/mobile/z_display_info_docomo.rb +10 -2
- data/lib/jpmobile/mobile/z_ip_addresses_au.rb +1 -26
- data/lib/jpmobile/mobile/z_ip_addresses_willcom.rb +2 -4
- data/lib/jpmobile/rack/auth.rb +55 -0
- data/lib/jpmobile/rack/combined_logger.rb +54 -0
- data/lib/jpmobile/rack/request.rb +7 -0
- data/lib/jpmobile/rack/trans_sid.rb +14 -0
- data/lib/jpmobile/trans_sid.rb +70 -62
- data/lib/jpmobile/version.rb +1 -1
- data/test/{au_test.rb → legacy/au_test.rb} +0 -0
- data/test/{autoload_test.rb → legacy/autoload_test.rb} +0 -0
- data/test/{docomo_test.rb → legacy/docomo_test.rb} +0 -0
- data/test/{emoticon_functional_test.rb → legacy/emoticon_functional_test.rb} +1 -1
- data/test/{emoticon_test.rb → legacy/emoticon_test.rb} +0 -0
- data/test/{filter_test.rb → legacy/filter_test.rb} +0 -0
- data/test/{helper.rb → legacy/helper.rb} +4 -5
- data/test/{helpers_test.rb → legacy/helpers_test.rb} +1 -1
- data/test/{softbank_test.rb → legacy/softbank_test.rb} +0 -0
- data/test/{willcom_test.rb → legacy/willcom_test.rb} +0 -0
- data/test/rails/overrides/app/controllers/application.rb +5 -0
- data/test/rails/overrides/app/controllers/docomo_guid_controller.rb +13 -0
- data/test/rails/overrides/app/controllers/filter_controller.rb +26 -0
- data/test/rails/overrides/app/controllers/mobile_spec_controller.rb +5 -0
- data/test/rails/overrides/app/controllers/template_path_controller.rb +6 -0
- data/test/rails/overrides/app/controllers/trans_sid_controller.rb +28 -0
- data/test/rails/overrides/app/views/filter/index.html.erb +0 -0
- data/test/rails/overrides/app/views/hankaku_filter/index.html.erb +0 -0
- data/test/rails/overrides/app/views/template_path/_partial.html.erb +1 -0
- data/test/rails/overrides/app/views/template_path/_partial_mobile.html.erb +1 -0
- data/test/rails/overrides/app/views/template_path/_partial_mobile_docomo.html.erb +1 -0
- data/test/rails/overrides/app/views/template_path/index.html.erb +1 -0
- data/test/rails/overrides/app/views/template_path/index_mobile.html.erb +1 -0
- data/test/rails/overrides/app/views/template_path/index_mobile_docomo.html.erb +1 -0
- data/test/rails/overrides/app/views/template_path/partial.html.erb +2 -0
- data/test/rails/overrides/lib/tasks/rspec.rake +165 -0
- data/test/rails/overrides/spec/controllers/docomo_guid_spec.rb +77 -0
- data/test/rails/overrides/spec/controllers/docomo_spec.rb +28 -0
- data/test/rails/overrides/spec/controllers/emobile_spec.rb +35 -0
- data/test/rails/overrides/spec/controllers/filter_spec.rb +157 -0
- data/test/rails/overrides/spec/controllers/pc_spec.rb +11 -0
- data/test/rails/overrides/spec/controllers/softbank_emulator_spec.rb +40 -0
- data/test/rails/overrides/spec/controllers/template_path_spec.rb +115 -0
- data/test/rails/overrides/spec/controllers/trans_sid_spec.rb +98 -0
- data/test/rails/overrides/spec/helpers/helpers_spec.rb +13 -0
- data/test/rails/overrides/spec/rcov.opts +2 -0
- data/test/rails/overrides/spec/rspec.rake +165 -0
- data/test/rails/overrides/spec/spec.opts +4 -0
- data/test/rails/overrides/spec/spec_helper.rb +47 -0
- data/test/rails/rails_root/README +256 -0
- data/test/rails/rails_root/Rakefile +10 -0
- data/test/rails/rails_root/app/controllers/application.rb +5 -0
- data/test/rails/rails_root/app/controllers/docomo_guid_controller.rb +13 -0
- data/test/rails/rails_root/app/controllers/filter_controller.rb +26 -0
- data/test/rails/rails_root/app/controllers/mobile_spec_controller.rb +5 -0
- data/test/rails/rails_root/app/controllers/template_path_controller.rb +6 -0
- data/test/rails/rails_root/app/controllers/trans_sid_controller.rb +26 -0
- data/test/rails/rails_root/app/helpers/application_helper.rb +3 -0
- data/test/rails/rails_root/app/views/template_path/index.html.erb +1 -0
- data/test/rails/rails_root/app/views/template_path/index_mobile.html.erb +1 -0
- data/test/rails/rails_root/app/views/template_path/index_mobile_docomo.html.erb +1 -0
- data/test/rails/rails_root/config/boot.rb +109 -0
- data/test/rails/rails_root/config/database.yml +22 -0
- data/test/rails/rails_root/config/environment.rb +75 -0
- data/test/rails/rails_root/config/environments/development.rb +17 -0
- data/test/rails/rails_root/config/environments/production.rb +24 -0
- data/test/rails/rails_root/config/environments/test.rb +22 -0
- data/test/rails/rails_root/config/initializers/inflections.rb +10 -0
- data/test/rails/rails_root/config/initializers/mime_types.rb +5 -0
- data/test/rails/rails_root/config/initializers/new_rails_defaults.rb +17 -0
- data/test/rails/rails_root/config/locales/en.yml +5 -0
- data/test/rails/rails_root/config/routes.rb +43 -0
- data/test/rails/rails_root/db/development.sqlite3 +0 -0
- data/test/rails/rails_root/db/schema.rb +14 -0
- data/test/rails/rails_root/db/test.sqlite3 +0 -0
- data/test/rails/rails_root/doc/README_FOR_APP +5 -0
- data/test/rails/rails_root/lib/tasks/rspec.rake +165 -0
- data/test/rails/rails_root/log/development.log +38 -0
- data/test/rails/rails_root/log/production.log +0 -0
- data/test/rails/rails_root/log/server.log +0 -0
- data/test/rails/rails_root/log/test.log +401 -0
- data/test/rails/rails_root/public/404.html +30 -0
- data/test/rails/rails_root/public/422.html +30 -0
- data/test/rails/rails_root/public/500.html +33 -0
- data/test/rails/rails_root/public/dispatch.cgi +10 -0
- data/test/rails/rails_root/public/dispatch.fcgi +24 -0
- data/test/rails/rails_root/public/dispatch.rb +10 -0
- data/test/rails/rails_root/public/favicon.ico +0 -0
- data/test/rails/rails_root/public/images/rails.png +0 -0
- data/test/rails/rails_root/public/index.html +274 -0
- data/test/rails/rails_root/public/javascripts/application.js +2 -0
- data/test/rails/rails_root/public/javascripts/controls.js +963 -0
- data/test/rails/rails_root/public/javascripts/dragdrop.js +973 -0
- data/test/rails/rails_root/public/javascripts/effects.js +1128 -0
- data/test/rails/rails_root/public/javascripts/prototype.js +4320 -0
- data/test/rails/rails_root/public/robots.txt +5 -0
- data/test/rails/rails_root/script/about +4 -0
- data/test/rails/rails_root/script/console +3 -0
- data/test/rails/rails_root/script/dbconsole +3 -0
- data/test/rails/rails_root/script/destroy +3 -0
- data/test/rails/rails_root/script/generate +3 -0
- data/test/rails/rails_root/script/performance/benchmarker +3 -0
- data/test/rails/rails_root/script/performance/profiler +3 -0
- data/test/rails/rails_root/script/performance/request +3 -0
- data/test/rails/rails_root/script/plugin +3 -0
- data/test/rails/rails_root/script/process/inspector +3 -0
- data/test/rails/rails_root/script/process/reaper +3 -0
- data/test/rails/rails_root/script/process/spawner +3 -0
- data/test/rails/rails_root/script/runner +3 -0
- data/test/rails/rails_root/script/server +3 -0
- data/test/rails/rails_root/spec/controllers/docomo_guid_spec.rb +77 -0
- data/test/rails/rails_root/spec/controllers/docomo_spec.rb +28 -0
- data/test/rails/rails_root/spec/controllers/emobile_spec.rb +35 -0
- data/test/rails/rails_root/spec/controllers/filter_spec.rb +157 -0
- data/test/rails/rails_root/spec/controllers/pc_spec.rb +11 -0
- data/test/rails/rails_root/spec/controllers/softbank_emulator_spec.rb +40 -0
- data/test/rails/rails_root/spec/controllers/template_path_spec.rb +85 -0
- data/test/rails/rails_root/spec/controllers/trans_sid_spec.rb +96 -0
- data/test/rails/rails_root/spec/helpers/helpers_spec.rb +13 -0
- data/test/rails/rails_root/spec/rcov.opts +2 -0
- data/test/rails/rails_root/spec/rspec.rake +165 -0
- data/test/rails/rails_root/spec/spec.opts +4 -0
- data/test/rails/rails_root/spec/spec_helper.rb +47 -0
- data/test/rails/rails_root/test/performance/browsing_test.rb +9 -0
- data/test/rails/rails_root/test/test_helper.rb +38 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/CHANGELOG +7 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/MIT-LICENSE +7 -0
- data/{README → test/rails/rails_root/vendor/plugins/jpmobile/README.rdoc} +15 -17
- data/test/rails/rails_root/vendor/plugins/jpmobile/Rakefile +116 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/init.rb +3 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/install.rb +1 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile.rb +42 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/datum_conv.rb +72 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/docomo_guid.rb +42 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/email.rb +19 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/emoticon.rb +123 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/emoticon/au.rb +1287 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/emoticon/conversion_table.rb +3908 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/emoticon/docomo.rb +255 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/emoticon/softbank.rb +477 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/emoticon/z_combine.rb +20 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/filter.rb +173 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/helpers.rb +185 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/hook_action_controller.rb +11 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/hook_action_view.rb +142 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/hook_request.rb +13 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mobile/abstract_mobile.rb +73 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mobile/au.rb +97 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mobile/display.rb +33 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mobile/docomo.rb +97 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mobile/emobile.rb +17 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mobile/softbank.rb +110 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mobile/willcom.rb +39 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mobile/z_display_info_docomo.rb +688 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mobile/z_ip_addresses_au.rb +22 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mobile/z_ip_addresses_docomo.rb +12 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mobile/z_ip_addresses_emobile.rb +10 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mobile/z_ip_addresses_softbank.rb +17 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mobile/z_ip_addresses_willcom.rb +117 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/position.rb +67 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/request_with_mobile.rb +44 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/trans_sid.rb +105 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/util.rb +21 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/version.rb +9 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/spec/spec.opts +6 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/spec/spec_helper.rb +36 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/spec/unit/detect_by_email_spec.rb +31 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/spec/unit/detect_by_ua_spec.rb +42 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/spec/unit/is_carrier_spec.rb +93 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/spec/unit/spec_helper.rb +5 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/spec/unit/util_spec.rb +28 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/spec/unit/valid_ip_spec.rb +60 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/tasks/jpmobile_tasks.rake +59 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/tools/emoji/genregexp.rb +47 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/tools/generate_au_emoticon_table.rb +34 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/tools/generate_docomo_emoticon_table.rb +34 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/tools/generate_emoticon_conversion_table.rb +107 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/tools/generate_softbank_emoticon_table.rb +32 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/tools/list_gps_unsupported_au.rb +23 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/tools/update_display_info_docomo.rb +45 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/tools/update_ip_addresses_au.rb +29 -0
- data/test/rails/rails_root/vendor/plugins/jpmobile/tools/update_ip_addresses_willcom.rb +17 -0
- data/tools/update_ip_addresses_au.rb +15 -5
- metadata +188 -22
@@ -0,0 +1,20 @@
|
|
1
|
+
$KCODE='u'
|
2
|
+
module Jpmobile
|
3
|
+
module Emoticon
|
4
|
+
SJIS_TO_UNICODE = {}
|
5
|
+
SJIS_TO_UNICODE.update(DOCOMO_SJIS_TO_UNICODE)
|
6
|
+
SJIS_TO_UNICODE.update(AU_SJIS_TO_UNICODE)
|
7
|
+
SJIS_TO_UNICODE.freeze
|
8
|
+
UNICODE_TO_SJIS = SJIS_TO_UNICODE.invert.freeze
|
9
|
+
|
10
|
+
SJIS_REGEXP = Regexp.union(*SJIS_TO_UNICODE.keys.map{|s| Regexp.compile(Regexp.escape([s].pack('n'),"s"),nil,'s')})
|
11
|
+
SOFTBANK_WEBCODE_REGEXP = Regexp.union(*([/(?!)/n]+SOFTBANK_WEBCODE_TO_UNICODE.keys.map{|x| "\x1b\x24#{x}\x0f"}))
|
12
|
+
|
13
|
+
DOCOMO_SJIS_REGEXP = Regexp.union(*DOCOMO_SJIS_TO_UNICODE.keys.map{|s| Regexp.compile(Regexp.escape([s].pack('n'),"s"),nil,'s')})
|
14
|
+
AU_SJIS_REGEXP = Regexp.union(*AU_SJIS_TO_UNICODE.keys.map{|s| Regexp.compile(Regexp.escape([s].pack('n'),"s"),nil,'s')})
|
15
|
+
SOFTBANK_UNICODE_REGEXP = Regexp.union(*SOFTBANK_UNICODE_TO_WEBCODE.keys.map{|x| [x].pack('U')}).freeze
|
16
|
+
|
17
|
+
EMOTICON_UNICODES = UNICODE_TO_SJIS.keys|SOFTBANK_UNICODE_TO_WEBCODE.keys.map{|k|k+0x1000}
|
18
|
+
UTF8_REGEXP = Regexp.union(*EMOTICON_UNICODES.map{|x| [x].pack('U')}).freeze
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,173 @@
|
|
1
|
+
# = 文字コードフィルタ
|
2
|
+
# thanks to masuidrive <masuidrive (at) masuidrive.jp>
|
3
|
+
|
4
|
+
require 'scanf'
|
5
|
+
|
6
|
+
class ActionController::Base #:nodoc:
|
7
|
+
def self.mobile_filter(options={})
|
8
|
+
options = {:emoticon=>true, :hankaku=>false}.update(options)
|
9
|
+
|
10
|
+
if options[:emoticon]
|
11
|
+
around_filter Jpmobile::Filter::Emoticon::Outer.new # 外部エンコーディング<->数値文字参照
|
12
|
+
end
|
13
|
+
around_filter Jpmobile::Filter::Sjis.new
|
14
|
+
if options[:emoticon]
|
15
|
+
around_filter Jpmobile::Filter::Emoticon::Inner.new # 数値文字参照<->UTF-8
|
16
|
+
end
|
17
|
+
if options[:hankaku]
|
18
|
+
around_filter Jpmobile::Filter::HankakuKana.new
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
module Jpmobile
|
24
|
+
# =文字コードフィルタモジュール。
|
25
|
+
module Filter
|
26
|
+
# 文字コードフィルタのベースクラス。
|
27
|
+
class Base
|
28
|
+
def initialize
|
29
|
+
@counter = 0 # render :component 時に多重で適用されるのを防ぐ
|
30
|
+
end
|
31
|
+
# 外部コードから内部コードに変換
|
32
|
+
def before(controller)
|
33
|
+
@counter += 1
|
34
|
+
return unless @counter == 1
|
35
|
+
if respond_to?(:to_internal) && apply_incoming?(controller)
|
36
|
+
Util.deep_apply(controller.params) do |value|
|
37
|
+
value = to_internal(value, controller)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
# 内部コードから外部コードに変換
|
42
|
+
def after(controller)
|
43
|
+
@counter -= 1
|
44
|
+
return unless @counter.zero?
|
45
|
+
if respond_to?(:to_external) && apply_outgoing?(controller)
|
46
|
+
controller.response.body = to_external(controller.response.body, controller)
|
47
|
+
after_after(controller) if respond_to? :after_after
|
48
|
+
end
|
49
|
+
end
|
50
|
+
# 入力時(params)にこのフィルタを適用するか
|
51
|
+
def apply_incoming?(controller); true; end
|
52
|
+
# 出力時(response.body)にこのフィルタを適用するべきか
|
53
|
+
def apply_outgoing?(controller); true; end
|
54
|
+
end
|
55
|
+
|
56
|
+
# 携帯電話の場合にのみ適用したい場合に Jpmobile::Base の派生クラスに include する。
|
57
|
+
module ApplyOnlyForMobile
|
58
|
+
def apply_incoming?(controller)
|
59
|
+
controller.request.mobile?
|
60
|
+
end
|
61
|
+
def apply_outgoing?(controller)
|
62
|
+
[nil, "text/html", "application/xhtml+xml"].include?(controller.response.content_type) &&
|
63
|
+
controller.request.mobile?
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
# Shift_JISとUnicodeのフィルタ(NKFを使用)
|
68
|
+
class Sjis < Base
|
69
|
+
# UTF-8からShift_JISに変換する。
|
70
|
+
def to_external(str, controller)
|
71
|
+
NKF.nkf('-m0 -x -Ws', str)
|
72
|
+
end
|
73
|
+
# Shift_JISからUTF-8に変換する。
|
74
|
+
def to_internal(str, controller)
|
75
|
+
NKF.nkf('-m0 -x -Sw', str)
|
76
|
+
end
|
77
|
+
# afterfilterを実行した後に実行する。
|
78
|
+
def after_after(controller)
|
79
|
+
unless controller.response.body.blank?
|
80
|
+
# 500.htmlなどをUTF-8で書いたとき、docomoで文字化けするのを防ぐため
|
81
|
+
# response_bodyが空の場合はShift_JISを指定しない
|
82
|
+
controller.response.charset = "Shift_JIS"
|
83
|
+
end
|
84
|
+
end
|
85
|
+
# to_internalを適用するべきかどうかを返す。
|
86
|
+
def apply_incoming?(controller)
|
87
|
+
# Vodafone 3G/Softbank(Shift-JISにすると絵文字で不具合が生じる)以外の
|
88
|
+
# 携帯電話の場合に適用する。
|
89
|
+
mobile = controller.request.mobile
|
90
|
+
mobile && !(mobile.instance_of?(Jpmobile::Mobile::Vodafone)||mobile.instance_of?(Jpmobile::Mobile::Softbank))
|
91
|
+
end
|
92
|
+
def apply_outgoing?(controller)
|
93
|
+
[nil, "text/html", "application/xhtml+xml"].include?(controller.response.content_type) &&
|
94
|
+
apply_incoming?(controller)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
# テーブルに基づくフィルタ
|
99
|
+
class FilterTable < Base
|
100
|
+
cattr_reader :internal, :external
|
101
|
+
def to_internal(str, controller)
|
102
|
+
filter(str, external, internal)
|
103
|
+
end
|
104
|
+
def to_external(str, controller)
|
105
|
+
filter(str, internal, external)
|
106
|
+
end
|
107
|
+
private
|
108
|
+
def filter(str, from, to)
|
109
|
+
str = str.clone
|
110
|
+
from.each_with_index do |int, i|
|
111
|
+
str.gsub!(int, to[i])
|
112
|
+
end
|
113
|
+
str
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
# 半角カナと全角カナのフィルタ
|
118
|
+
class HankakuKana < FilterTable
|
119
|
+
include ApplyOnlyForMobile
|
120
|
+
@@internal = %w(ガ ギ グ ゲ ゴ ザ ジ ズ ゼ ゾ ダ ヂ ヅ デ ド バ ビ ブ ベ ボ パ ピ プ ペ ポ ヴ ア イ ウ エ オ カ キ ク ケ コ サ シ ス セ ソ タ チ ツ テ ト ナ ニ ヌ ネ ノ ハ ヒ フ ヘ ホ マ ミ ム メ モ ヤ ユ ヨ ラ リ ル レ ロ ワ ヲ ン ャ ュ ョ ァ ィ ゥ ェ ォ ッ ゛ ゜ ー ).freeze
|
121
|
+
@@external = %w(ガ ギ グ ゲ ゴ ザ ジ ズ ゼ ゾ ダ ヂ ヅ デ ド バ ビ ブ ベ ボ パ ピ プ ペ ポ ヴ ア イ ウ エ オ カ キ ク ケ コ サ シ ス セ ソ タ チ ツ テ ト ナ ニ ヌ ネ ノ ハ ヒ フ ヘ ホ マ ミ ム メ モ ヤ ユ ヨ ラ リ ル レ ロ ワ ヲ ン ャ ュ ョ ァ ィ ゥ ェ ォ ッ ゙ ゚ ー).freeze
|
122
|
+
end
|
123
|
+
|
124
|
+
# 絵文字変換フィルタ
|
125
|
+
module Emoticon
|
126
|
+
# 絵文字Outer
|
127
|
+
# 外部エンコーディング(携帯電話側)とUnicode数値文字参照を相互に変換。
|
128
|
+
class Outer < Base
|
129
|
+
include ApplyOnlyForMobile
|
130
|
+
def to_internal(str, controller)
|
131
|
+
method_name = "external_to_unicodecr_" +
|
132
|
+
controller.request.mobile.class.name[/::(\w*)$/, 1].downcase
|
133
|
+
if Jpmobile::Emoticon.respond_to?(method_name)
|
134
|
+
Jpmobile::Emoticon.send(method_name, str)
|
135
|
+
else
|
136
|
+
str # 対応する変換メソッドが定義されていない場合は素通し
|
137
|
+
end
|
138
|
+
end
|
139
|
+
def to_external(str, controller)
|
140
|
+
# 使用する変換テーブルの決定
|
141
|
+
table = nil
|
142
|
+
to_sjis = false
|
143
|
+
case controller.request.mobile
|
144
|
+
when Jpmobile::Mobile::Docomo
|
145
|
+
table = Jpmobile::Emoticon::CONVERSION_TABLE_TO_DOCOMO
|
146
|
+
to_sjis = true
|
147
|
+
when Jpmobile::Mobile::Au
|
148
|
+
table = Jpmobile::Emoticon::CONVERSION_TABLE_TO_AU
|
149
|
+
to_sjis = true
|
150
|
+
when Jpmobile::Mobile::Jphone
|
151
|
+
table = Jpmobile::Emoticon::CONVERSION_TABLE_TO_SOFTBANK
|
152
|
+
to_sjis = true
|
153
|
+
when Jpmobile::Mobile::Softbank
|
154
|
+
table = Jpmobile::Emoticon::CONVERSION_TABLE_TO_SOFTBANK
|
155
|
+
end
|
156
|
+
|
157
|
+
Jpmobile::Emoticon::unicodecr_to_external(str, table, to_sjis)
|
158
|
+
end
|
159
|
+
end
|
160
|
+
# 絵文字Inner
|
161
|
+
# Unicode数値文字参照とUTF-8を相互に変換
|
162
|
+
class Inner < Base
|
163
|
+
include ApplyOnlyForMobile
|
164
|
+
def to_internal(str, controller)
|
165
|
+
Jpmobile::Emoticon::unicodecr_to_utf8(str)
|
166
|
+
end
|
167
|
+
def to_external(str, controller)
|
168
|
+
Jpmobile::Emoticon::utf8_to_unicodecr(str)
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
@@ -0,0 +1,185 @@
|
|
1
|
+
# =位置情報等を要求するヘルパー
|
2
|
+
module Jpmobile
|
3
|
+
# 携帯電話端末に位置情報を要求するための、特殊なリンクを出力するヘルパー群。
|
4
|
+
# 多くのキャリアでは特殊なFORMでも位置情報を要求できる。
|
5
|
+
module Helpers
|
6
|
+
# 位置情報(緯度経度がとれるもの。オープンiエリアをのぞく)要求するリンクを作成する。
|
7
|
+
# 位置情報を受け取るページを +url_for+ に渡す引数の形式で +options+ に指定する。
|
8
|
+
# :show_all => +true+ とするとキャリア判別を行わず全てキャリアのリンクを返す。
|
9
|
+
# 第1引数に文字列を与えるとその文字列をアンカーテキストにする。
|
10
|
+
# 第1引数がHashの場合はデフォルトのアンカーテキストを出力する。
|
11
|
+
def get_position_link_to(str=nil, options={})
|
12
|
+
if str.is_a?(Hash)
|
13
|
+
options = str
|
14
|
+
str = nil
|
15
|
+
end
|
16
|
+
show_all = nil
|
17
|
+
if options.is_a?(Hash)
|
18
|
+
options = options.symbolize_keys
|
19
|
+
show_all = options.delete(:show_all)
|
20
|
+
end
|
21
|
+
|
22
|
+
# TODO: コード汚い
|
23
|
+
s = []
|
24
|
+
if show_all || request.mobile.instance_of?(Mobile::Docomo)
|
25
|
+
s << docomo_foma_gps_link_to(str||"DoCoMo FOMA(GPS)", options)
|
26
|
+
end
|
27
|
+
if show_all || request.mobile.instance_of?(Mobile::Au)
|
28
|
+
if show_all || request.mobile.supports_gps?
|
29
|
+
s << au_gps_link_to(str||"au(GPS)", options)
|
30
|
+
end
|
31
|
+
if show_all || (!(request.mobile.supports_gps?) && request.mobile.supports_location?)
|
32
|
+
s << au_location_link_to(str||"au(antenna)", options)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
if show_all || request.mobile.instance_of?(Mobile::Jphone)
|
36
|
+
s << jphone_location_link_to(str||"Softbank(antenna)", options)
|
37
|
+
end
|
38
|
+
if show_all || request.mobile.instance_of?(Mobile::Vodafone) || request.mobile.instance_of?(Mobile::Softbank)
|
39
|
+
s << softbank_location_link_to(str||"Softbank 3G(GPS)", options)
|
40
|
+
end
|
41
|
+
if show_all || request.mobile.instance_of?(Mobile::Willcom)
|
42
|
+
s << willcom_location_link_to(str||"Willcom", options)
|
43
|
+
end
|
44
|
+
return s.join("<br>\n")
|
45
|
+
end
|
46
|
+
|
47
|
+
# DoCoMo FOMAでGPS位置情報を取得するためのリンクを返す。
|
48
|
+
def docomo_foma_gps_link_to(str, options={})
|
49
|
+
url = options
|
50
|
+
if options.is_a?(Hash)
|
51
|
+
options = options.symbolize_keys
|
52
|
+
options[:only_path] = false
|
53
|
+
url = url_for(options)
|
54
|
+
end
|
55
|
+
return %{<a href="#{url}" lcs>#{str}</a>}
|
56
|
+
end
|
57
|
+
|
58
|
+
# DoCoMoでオープンiエリアを取得するためのURLを返す。
|
59
|
+
def docomo_openiarea_url_for(options={})
|
60
|
+
url = options
|
61
|
+
if options.is_a?(Hash)
|
62
|
+
options = options.symbolize_keys
|
63
|
+
options[:only_path] = false
|
64
|
+
posinfo = options.delete(:posinfo) || "1" # 基地局情報を元に測位した緯度経度情報を要求
|
65
|
+
url = url_for(options)
|
66
|
+
end
|
67
|
+
return "http://w1m.docomo.ne.jp/cp/iarea?ecode=OPENAREACODE&msn=OPENAREAKEY&posinfo=#{posinfo}&nl=#{CGI.escape(url)}"
|
68
|
+
end
|
69
|
+
|
70
|
+
# DoCoMoでオープンiエリアを取得するためのリンクを返す。
|
71
|
+
def docomo_openiarea_link_to(str, options={})
|
72
|
+
link_to_url(str, docomo_openiarea_url_for(options))
|
73
|
+
end
|
74
|
+
|
75
|
+
# DoCoMoで端末製造番号等を取得するためのリンクを返す。
|
76
|
+
def docomo_utn_link_to(str, options={})
|
77
|
+
url = options
|
78
|
+
if options.is_a?(Hash)
|
79
|
+
options = options.symbolize_keys
|
80
|
+
options[:only_path] = false
|
81
|
+
url = url_for(options)
|
82
|
+
end
|
83
|
+
return %{<a href="#{url}" utn>#{str}</a>}
|
84
|
+
end
|
85
|
+
|
86
|
+
# DoCoMoでiモードIDを取得するためのリンクを返す。
|
87
|
+
def docomo_guid_link_to(str, options={})
|
88
|
+
url = options
|
89
|
+
if options.is_a?(Hash)
|
90
|
+
options = options.symbolize_keys
|
91
|
+
options[:guid] = "ON"
|
92
|
+
url = url_for(options)
|
93
|
+
end
|
94
|
+
return link_to_url(str, url)
|
95
|
+
end
|
96
|
+
|
97
|
+
# au GPS位置情報を取得するためのURLを返す。
|
98
|
+
def au_gps_url_for(options={})
|
99
|
+
url = options
|
100
|
+
datum = 0 # 0:wgs84, 1:tokyo
|
101
|
+
unit = 0 # 0:dms, 1:deg
|
102
|
+
if options.is_a?(Hash)
|
103
|
+
options = options.symbolize_keys
|
104
|
+
options[:only_path] = false
|
105
|
+
datum = (options.delete(:datum) || 0 ).to_i # 0:wgs84, 1:tokyo
|
106
|
+
unit = (options.delete(:unit) || 0 ).to_i # 0:dms, 1:deg
|
107
|
+
url = url_for(options)
|
108
|
+
end
|
109
|
+
return "device:gpsone?url=#{CGI.escape(url)}&ver=1&datum=#{datum}&unit=#{unit}&acry=0&number=0"
|
110
|
+
end
|
111
|
+
|
112
|
+
# au GPS位置情報を取得するためのリンクを返す。
|
113
|
+
def au_gps_link_to(str, options={})
|
114
|
+
link_to_url(str, au_gps_url_for(options))
|
115
|
+
end
|
116
|
+
|
117
|
+
# au 簡易位置情報を取得するためのURLを返す。
|
118
|
+
def au_location_url_for(options={})
|
119
|
+
url = options
|
120
|
+
if options.is_a?(Hash)
|
121
|
+
options = options.symbolize_keys
|
122
|
+
options[:only_path] = false
|
123
|
+
url = url_for(options)
|
124
|
+
end
|
125
|
+
return "device:location?url=#{CGI.escape(url)}"
|
126
|
+
end
|
127
|
+
|
128
|
+
# au 簡易位置情報を取得するためのリンクを返す。
|
129
|
+
def au_location_link_to(str, options={})
|
130
|
+
link_to_url(str, au_location_url_for(options))
|
131
|
+
end
|
132
|
+
|
133
|
+
# J-PHONE 位置情報 (基地局) を取得するためのリンクを返す。
|
134
|
+
def jphone_location_link_to(str,options={})
|
135
|
+
url = options
|
136
|
+
if options.is_a?(Hash)
|
137
|
+
options = options.symbolize_keys
|
138
|
+
options[:only_path] = false
|
139
|
+
url = url_for(options)
|
140
|
+
end
|
141
|
+
return %{<a z href="#{url}">#{str}</a>}
|
142
|
+
end
|
143
|
+
|
144
|
+
# Softbank(含むVodafone 3G)で位置情報を取得するためのURLを返す。
|
145
|
+
def softbank_location_url_for(options={})
|
146
|
+
url = options
|
147
|
+
mode = "auto"
|
148
|
+
if options.is_a?(Hash)
|
149
|
+
options = options.symbolize_keys
|
150
|
+
mode = options.delete(:mode) || "auto"
|
151
|
+
options[:only_path] = false
|
152
|
+
url = url_for(options)
|
153
|
+
end
|
154
|
+
url.sub!(/\?/, '&')
|
155
|
+
return "location:#{mode}?url=#{url}"
|
156
|
+
end
|
157
|
+
|
158
|
+
# Softbank(含むVodafone 3G)で位置情報を取得するためのリンクを返す。
|
159
|
+
def softbank_location_link_to(str,options={})
|
160
|
+
link_to_url(str,softbank_location_url_for(options))
|
161
|
+
end
|
162
|
+
|
163
|
+
# Willcom 基地局位置情報を取得するためのURLを返す。
|
164
|
+
def willcom_location_url_for(options={})
|
165
|
+
url = options
|
166
|
+
if options.is_a?(Hash)
|
167
|
+
options = options.symbolize_keys
|
168
|
+
options[:only_path] = false
|
169
|
+
url = url_for(options)
|
170
|
+
end
|
171
|
+
return "http://location.request/dummy.cgi?my=#{url}&pos=$location"
|
172
|
+
end
|
173
|
+
|
174
|
+
# Willcom 基地局位置情報を取得するためのリンクを返す。
|
175
|
+
def willcom_location_link_to(str,options={})
|
176
|
+
link_to_url(str, willcom_location_url_for(options))
|
177
|
+
end
|
178
|
+
|
179
|
+
private
|
180
|
+
# 外部へのリンク
|
181
|
+
def link_to_url(str, url)
|
182
|
+
%{<a href="#{url}">#{str}</a>}
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
class ActionController::Base
|
2
|
+
include Jpmobile::Helpers
|
3
|
+
before_filter :gettext_force_ja_for_mobile
|
4
|
+
# gettextが組み込まれている場合、携帯電話からのアクセスをjaロケールに強制する。
|
5
|
+
def gettext_force_ja_for_mobile
|
6
|
+
begin
|
7
|
+
::GetText.locale = 'ja' if request.mobile?
|
8
|
+
rescue NameError
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,142 @@
|
|
1
|
+
# = viewの自動切り替え
|
2
|
+
#
|
3
|
+
# Rails 2.1.0 対応 http://d.hatena.ne.jp/kusakari/20080620/1213931903
|
4
|
+
# thanks to id:kusakari
|
5
|
+
#
|
6
|
+
#:stopdoc:
|
7
|
+
# helperを追加
|
8
|
+
ActionView::Base.class_eval { include Jpmobile::Helpers }
|
9
|
+
#:startdoc:
|
10
|
+
|
11
|
+
require 'action_pack'
|
12
|
+
require 'action_view'
|
13
|
+
|
14
|
+
# ActionView::Base を拡張して携帯からのアクセスの場合に携帯向けビューを優先表示する。
|
15
|
+
# Vodafone携帯(request.mobile == Jpmobile::Mobile::Vodafone)の場合、
|
16
|
+
# index_mobile_vodafone.rhtml
|
17
|
+
# index_mobile_softbank.rhtml
|
18
|
+
# index_mobile.rhtml
|
19
|
+
# index.rhtml
|
20
|
+
# の順にテンプレートが検索される。
|
21
|
+
# BUG: 現状、上記の例では index.rhtml が存在しない場合に振り分けが行われない
|
22
|
+
# (ダミーファイルを置くことで回避可能)。
|
23
|
+
|
24
|
+
class ActionView::Base #:nodoc:
|
25
|
+
delegate :default_url_options, :to => :controller unless respond_to?(:default_url_options)
|
26
|
+
|
27
|
+
if ::ActionPack::VERSION::MAJOR >=2 and ::ActionPack::VERSION::MINOR >= 3
|
28
|
+
### Rails 2.3 or higher
|
29
|
+
alias find_template_without_jpmobile find_template #:nodoc:
|
30
|
+
alias render_partial_without_jpmobile render_partial #:nodoc:
|
31
|
+
|
32
|
+
def find_template(template_path)
|
33
|
+
mobile_path = mobile_template_path(template_path)
|
34
|
+
return mobile_path.nil? ? _pick_template_without_jpmobile(template_path) :
|
35
|
+
_pick_template_without_jpmobile(mobile_path)
|
36
|
+
end
|
37
|
+
|
38
|
+
def render_partial(options = {}) #:nodoc:
|
39
|
+
case partial_path = options[:partial]
|
40
|
+
when String, Symbol, NilClass
|
41
|
+
mobile_path = mobile_template_path(partial_path, true)
|
42
|
+
options = options.merge(:partial => mobile_path) if mobile_path
|
43
|
+
end
|
44
|
+
render_partial_without_jpmobile(options)
|
45
|
+
end
|
46
|
+
|
47
|
+
elsif ::ActionPack::VERSION::MAJOR >=2 and ::ActionPack::VERSION::MINOR >= 2
|
48
|
+
### Rails 2.2 or higher
|
49
|
+
alias _pick_template_without_jpmobile _pick_template #:nodoc:
|
50
|
+
alias render_partial_without_jpmobile render_partial #:nodoc:
|
51
|
+
|
52
|
+
def _pick_template(template_path)
|
53
|
+
mobile_path = mobile_template_path(template_path)
|
54
|
+
return mobile_path.nil? ? _pick_template_without_jpmobile(template_path) :
|
55
|
+
_pick_template_without_jpmobile(mobile_path)
|
56
|
+
end
|
57
|
+
|
58
|
+
def render_partial(options = {}) #:nodoc:
|
59
|
+
case partial_path = options[:partial]
|
60
|
+
when String, Symbol, NilClass
|
61
|
+
mobile_path = mobile_template_path(partial_path, true)
|
62
|
+
options = options.merge(:partial => mobile_path) if mobile_path
|
63
|
+
end
|
64
|
+
render_partial_without_jpmobile(options)
|
65
|
+
end
|
66
|
+
|
67
|
+
else
|
68
|
+
### Rails 2.1 or lower
|
69
|
+
alias render_file_without_jpmobile render_file #:nodoc:
|
70
|
+
alias render_partial_without_jpmobile render_partial #:nodoc:
|
71
|
+
|
72
|
+
def render_file(template_path, use_full_path = true, local_assigns = {})
|
73
|
+
mobile_path = mobile_template_path(template_path)
|
74
|
+
return mobile_path.nil? ? render_file_without_jpmobile(template_path, use_full_path, local_assigns) :
|
75
|
+
render_file_without_jpmobile(mobile_path, use_full_path, local_assigns)
|
76
|
+
end
|
77
|
+
|
78
|
+
def render_partial(partial_path, object_assigns = nil, local_assigns = {}) #:nodoc:
|
79
|
+
mobile_path = mobile_template_path(partial_path, true) if partial_path.class === "String"
|
80
|
+
return mobile_path.nil? ? render_partial_without_jpmobile(partial_path, object_assigns, local_assigns) :
|
81
|
+
render_partial_without_jpmobile(mobile_path, object_assigns, local_assigns)
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
|
86
|
+
def mobile_template_candidates
|
87
|
+
candidates = []
|
88
|
+
c = controller.request.mobile.class
|
89
|
+
while c != Jpmobile::Mobile::AbstractMobile
|
90
|
+
candidates << "mobile_"+c.to_s.split(/::/).last.downcase
|
91
|
+
c = c.superclass
|
92
|
+
end
|
93
|
+
candidates << "mobile"
|
94
|
+
end
|
95
|
+
|
96
|
+
def mobile_template_partial mobile_path
|
97
|
+
# ActionView::PartialTemplate#extract_partial_name_and_path の動作を模倣
|
98
|
+
if mobile_path.include?('/')
|
99
|
+
path = File.dirname(mobile_path)
|
100
|
+
partial_name = File.basename(mobile_path)
|
101
|
+
else
|
102
|
+
path = self.controller.class.controller_path
|
103
|
+
partial_name = mobile_path
|
104
|
+
end
|
105
|
+
File.join(path, "_#{partial_name}")
|
106
|
+
end
|
107
|
+
|
108
|
+
def mobile_path template_path, type
|
109
|
+
"#{template_path}_#{type}"
|
110
|
+
end
|
111
|
+
|
112
|
+
def mobile_template_path(template_path, partial=false)
|
113
|
+
if controller.is_a?(ActionController::Base) && m = controller.request.mobile
|
114
|
+
mobile_template_candidates.each do |v|
|
115
|
+
mpath = mobile_path template_path, v
|
116
|
+
if partial
|
117
|
+
full_path = mobile_template_partial mpath
|
118
|
+
else
|
119
|
+
full_path = mpath
|
120
|
+
end
|
121
|
+
if template_exists?(full_path)
|
122
|
+
return mpath
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
return nil
|
127
|
+
end
|
128
|
+
|
129
|
+
if ::ActionPack::VERSION::MAJOR >=2 and ::ActionPack::VERSION::MINOR >= 2
|
130
|
+
### Rails 2.2 or higher
|
131
|
+
def template_exists?(template_name)
|
132
|
+
send(:_pick_template_without_jpmobile, template_name) ? true : false
|
133
|
+
rescue ActionView::MissingTemplate
|
134
|
+
false
|
135
|
+
end
|
136
|
+
else
|
137
|
+
### Rails 2.1 or lower
|
138
|
+
def template_exists?(template_name)
|
139
|
+
finder.file_exists?(template_name)
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|