-
Notifications
You must be signed in to change notification settings - Fork 0
/
mb.php
executable file
·315 lines (262 loc) · 7.66 KB
/
mb.php
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
<?php
/**
* Mobile_Object
*
* @category Addon
* @package addon.mobile
* @author Yutaka Ebine <yutaka@ebine.org>
* @copyright 2004-2010 Mori Reo <mori.reo@sabel.jp>
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
*/
class mb
{
/**
* @var Mobile_Carrier_Abstract
*/
protected static $carrier = null;
protected static $pictmap = array();
public static function setup(Mobile_Carrier_Abstract $carrier)
{
self::$carrier = $carrier;
}
public static function get_carrier()
{
return self::$carrier;
}
public static function get_carrier_id()
{
return self::$carrier->getCarrierId();
}
public static function get_pictgram()
{
return self::$carrier->getPictgram();
}
public static function is_docomo()
{
return self::$carrier->isDocomo();
}
public static function is_ezweb()
{
return self::$carrier->isEzweb();
}
public static function is_softbank()
{
return self::$carrier->isSoftbank();
}
public static function is_mobile()
{
return self::$carrier->isMobile();
}
public static function get_doctype()
{
return self::$carrier->getDocType();
}
public static function get_content_type()
{
return self::$carrier->getContentType();
}
public static function get_mobile_id()
{
return self::$carrier->getMobileId();
}
public static function get_charset()
{
return self::$carrier->getCharset();
}
public static function to_client_charset($str)
{
return mb_convert_encoding($str, self::get_charset(), APP_ENCODING);
}
public static function get_fontsize($size = "")
{
return self::$carrier->getFontSize($size);
}
public static function strwidth($str)
{
$str = preg_replace("/\{e:[0-9]{3}\}/", "__", $str);
return mb_strwidth($str);
}
public static function stromit($str, $charCount, $marker = "…")
{
$charCount *= 2;
$str = str_replace(array("\r", "\n"), "", $str);
$tmp = preg_replace('/\{e:[0-9]{3}\}/', "\000\000", $str, -1, $pgCount);
if ($pgCount >= 1 && ($pgCount = substr_count(mb_strimwidth($tmp, 0, $charCount), "\000\000")) > 0) {
$tmp = mb_strimwidth($tmp, 0, $charCount);
if (substr($tmp, -1) === "\000" && substr($tmp, -2) !== "\000\000") {
$tmp = substr($tmp, 0, -1);
}
$width = mb_strwidth($tmp) + $pgCount * 7 - $pgCount * 2;
$trimmed = mb_strimwidth($str, 0, $width);
} else {
$trimmed = mb_strimwidth($str, 0, $charCount);
}
return ($trimmed === $str) ? $str : $trimmed . $marker;
}
public static function input_normal($name, $value = "", $type = "text", $size = null)
{
return self::$carrier->normalInput(
$name, self::output($value, false, true), $type, $size
);
}
public static function input_kana($name, $value = "", $type = "text", $size = null)
{
return self::$carrier->kanaInput(
$name, self::output($value, false, true), $type, $size
);
}
public static function input_alpha($name, $value = "", $type = "text", $size = null)
{
return self::$carrier->alphaInput(
$name, self::output($value, false, true), $type, $size
);
}
public static function input_number($name, $value = "", $type = "text", $size = null)
{
return self::$carrier->numberInput(
$name, self::output($value, false, true), $type, $size
);
}
public static function textarea($name, $value = "", $rows = 5)
{
return '<textarea rows="' . $rows . '" name="' . $name . '">' .
self::output($value, false, true) . '</textarea>';
}
public static function hr($color = "#999999", $bgColor = "#ffffff", $size = "1")
{
return self::$carrier->hr($color, $bgColor, $size);
}
public static function marquee($bgColor, $textColor, $text, $fontSize = null)
{
if (empty($fontSize)) {
$fontSize = self::get_fontsize();
}
if (self::is_mobile()) {
return '<div class="marquee" style="display: -wap-marquee; -wap-marquee-style: scroll; '
. '-wap-marquee-dir: rtl; -wap-marquee-loop: 32; background-color: ' . $bgColor . ';">'
. '<span style="color: ' . $textColor . '; font-size: ' . $fontSize . ';">' . $text
. '</span></div>';
} else {
return '<marquee style="background-color: ' . $bgColor . ';">'
. '<span style="color: ' . $textColor . ';">' . $text . '</span>'
. '</marquee>';
}
}
public static function pictgram($webCode)
{
$map = self::get_pictgram_map();
switch ($carrier = self::$carrier->getCarrierId()) {
case MOBILE_DOCOMO_ID:
case MOBILE_EZWEB_ID:
case MOBILE_SOFTBANK_ID:
if (isset($map[$webCode][$carrier])) {
return $map[$webCode][$carrier];
} else {
return "〓";
}
default:
if (isset($map[$webCode])) {
return sprintf(
'<img class="pictgram" src="%s" alt="絵文字" />',
linkto("/images/emoji/{$webCode}.gif")
);
} else {
return "〓";
}
}
}
public static function output($str, $toHalfWidth = true, $forInput = false, $escape = true)
{
if (is_empty($str)) {
return "";
} elseif ($escape) {
$str = htmlescape($str);
}
$map = self::get_pictgram_map();
if (preg_match_all('/\{e:[0-9]{3}\}/', $str, $matches) > 0) {
switch ($carrier = self::$carrier->getCarrierId()) {
case MOBILE_DOCOMO_ID:
case MOBILE_EZWEB_ID:
case MOBILE_SOFTBANK_ID:
foreach ($matches[0] as $webCode) {
$code = substr($webCode, 3, 3);
if (isset($map[$code][$carrier])) {
$str = str_replace($webCode, $map[$code][$carrier], $str);
}
}
break;
default:
if (!$forInput) {
foreach ($matches[0] as $webCode) {
$code = substr($webCode, 3, 3);
if (!$forInput) {
$str = str_replace($webCode, '<img class="pictgram" src="/images/emoji/' . $code . '.gif" alt="" />', $str);
}
}
}
}
}
return ($toHalfWidth) ? mb_convert_kana($str, "ka") : $str;
}
public static function remove_pictcode($str)
{
return preg_replace("/\{e:[0-9]{3}\}/", "", $str);
}
public static function get_model()
{
$model = self::$carrier->toModelName(
self::get_useragent_mobile()->getModel()
);
return (empty($model)) ? "UNKNOWN" : $model;
}
public static function get_useragent_mobile()
{
static $mobile = null;
if ($mobile === null) {
@require_once ("Net" . DS . "UserAgent" . DS . "Mobile.php");
$mobile = @Net_UserAgent_Mobile::factory();
}
return $mobile;
}
public static function get_pictgram_map()
{
if (empty(self::$pictmap)) {
self::$pictmap = Mobile_Pictgram_Abstract::getWebToMobileMap();
}
return self::$pictmap;
}
public static function is_mobile_email($email)
{
$mobileDomains = array(
"docomo.ne.jp",
"ezweb.ne.jp",
"softbank.ne.jp",
"vodafone.ne.jp",
"disney.ne.jp",
//"pdx.ne.jp",
//"i.softbank.jp",
//"emnet.ne.jp"
);
list (, $domain) = explode("@", $email);
foreach ($mobileDomains as $mdomain) {
if ($mdomain === substr($domain, -strlen($mdomain))) {
return true;
}
}
return false;
}
/**
* alias
*/
public static function get_doc_type()
{
return self::get_doctype();
}
/**
* alias
*/
public static function get_font_size()
{
return self::get_fontsize();
}
}