2 require_once 'common.php';
\r
4 // {{{ class MPC_FOMA
\r
6 * FOMA
\8aG
\95¶
\8e\9a\95Ï
\8a·
\83x
\81[
\83X
\83N
\83\89\83X
\r
8 * @author ryster <ryster@php-develop.org>
\r
9 * @license http://www.opensource.org/licenses/mit-license.php The MIT License
\r
10 * @link http://php-develop.org/MobilePictogramConverter/
\r
12 class MPC_FOMA extends MPC_Common
\r
15 *
\8aG
\95¶
\8e\9a\92\8a\8fo
\90³
\8bK
\95\
\8c»
\r
19 'WEB' => '/&#(63\d{3});/ie',
\r
20 'IMG' => '/<img *src="{PATH}\/(63\d{3})\.gif" alt="" border="0" width="12" height="12" \/>/ie',
\r
24 *
\95¶
\8e\9a\97ñ
\82©
\82çi-mode
\8aG
\95¶
\8e\9a\82ð
\8c\9f\8fo
\82µ
\81A
\8ew
\92è
\82³
\82ê
\82½
\83t
\83H
\81[
\83}
\83b
\83g
\82É
\95Ï
\8a·
\r
25 *
\8aî
\96{
\81E
\8ag
\92£
\81E
\89B
\82µ
\8aG
\95¶
\8e\9a\88ê
\95\94\91Î
\89\9e\r
27 * @param string $to (MPC_TO_FOMA, MPC_TO_EZWEB, MPC_TO_SOFTBANK)
\r
28 * @param integer $option (MPC_TO_OPTION_RAW, MPC_TO_OPTION_WEB, MPC_TO_OPTION_IMG)
\r
31 function Convert($to, $option = MPC_TO_OPTION_RAW, $toCharset = null)
\r
34 $this->setOption($option);
\r
35 $str = $this->getString();
\r
36 $type = $this->getStringType();
\r
37 $fromCharset = $this->getFromCharset();
\r
40 if ($type != MPC_FROM_OPTION_RAW) {
\r
41 if ($type == MPC_FROM_OPTION_WEB) {
\r
42 $eval = ($fromCharset === MPC_FROM_CHARSET_UTF8) ? 'mb_convert_encoding(pack("H*", @$1), "UTF-8", "unicode")' : 'mb_convert_encoding(pack("H*", @$1), "SJIS-win", "unicode")';
\r
43 $str = preg_replace('/&#x([a-z0-9]{4});/ie', $eval, $str);
\r
45 $regex = str_replace('{PATH}', preg_quote(rtrim($this->getFOMAImagePath(), '/'), '/'), $this->getRegex($type));
\r
46 $eval = ($fromCharset !== MPC_FROM_CHARSET_SJIS) ? 'mb_convert_encoding(pack("H*", dechex($1)), $fromCharset, "SJIS-win")' : 'pack("H*", dechex($1))';
\r
47 $str = preg_replace($regex, $eval, $str);
\r
50 $this->setDS(unpack('C*', $str));
\r
51 $c = count($this->decstring);
\r
52 for ($this->i = 1;$this->i <= $c;$this->i++) {
\r
53 $result = $this->Inspection();
\r
54 if (is_null($result)) {
\r
58 //
\8aG
\95¶
\8e\9a\95Ï
\8a·
\8f\88\97\9d\r
59 if ($this->isPictogram($result)) {
\r
60 $decs = ($fromCharset == MPC_FROM_CHARSET_UTF8) ? unpack('C*', mb_convert_encoding(pack('C*', $result[0], $result[1], $result[2]), 'SJIS-win', 'UTF-8')) : $result;
\r
61 $dec = hexdec($this->decs2hex($decs));
\r
62 $this->setPictogram($this->encoder($dec));
\r
64 $this->setUnPictogram(pack('H*', $this->decs2hex($result)));
\r
67 $unpictograms = $this->getUnPictograms();
\r
68 $pictograms = $this->getPictograms();
\r
69 $this->ReleaseUnPictograms();
\r
70 $this->ReleasePictograms();
\r
71 $buf = $unpictograms + $pictograms;
\r
72 if (is_array($buf)) {
\r
74 return implode('', $buf);
\r
81 *
\95¶
\8e\9a\97ñ
\82©
\82çi-mode
\8aG
\95¶
\8e\9a\82ð
\8f\9c\8aO
\82·
\82é
\r
87 $str = $this->getString();
\r
88 $type = $this->getStringType();
\r
89 $fromCharset = $this->getFromCharset();
\r
92 if ($type != MPC_FROM_OPTION_RAW) {
\r
93 if ($type == MPC_FROM_OPTION_WEB) {
\r
94 $str = preg_replace('/&#x([a-z0-9]{4});/ie', '', $str);
\r
96 $regex = str_replace('{PATH}', preg_quote(rtrim($this->getFOMAImagePath(), '/'), '/'), $this->getRegex($type));
\r
97 return preg_replace($regex, '', $str);
\r
100 $this->setDS(unpack('C*', $str));
\r
101 $c = count($this->decstring);
\r
102 for ($this->i = 1;$this->i <= $c;$this->i++) {
\r
103 $result = $this->Inspection();
\r
104 if (is_null($result)) {
\r
108 //
\8aG
\95¶
\8e\9a\95Ï
\8a·
\8f\88\97\9d\r
109 if ($this->isPictogram($result) === false) {
\r
110 $this->setUnPictogram(pack('H*', $this->decs2hex($result)));
\r
113 //
\82±
\82±
\82Å
\95¶
\8e\9a\83R
\81[
\83h
\82Ì
\95Ï
\8a·
\82Æ
\82©
\82â
\82é
\97\
\92è
\r
114 $buf = $this->getUnPictograms();
\r
115 $this->ReleaseUnPictograms();
\r
116 if (is_array($buf)) {
\r
117 return implode('', $buf);
\r
124 *
\95¶
\8e\9a\97ñ
\82Éi-mode
\8aG
\95¶
\8e\9a\82ª
\89½
\8cÂ
\8aÜ
\82Ü
\82ê
\82Ä
\82¢
\82é
\82©
\83`
\83F
\83b
\83N
\r
131 $str = $this->getString();
\r
132 $type = $this->getStringType();
\r
133 $fromCharset = $this->getFromCharset();
\r
136 if ($type != MPC_FROM_OPTION_RAW) {
\r
137 if ($type == MPC_FROM_OPTION_WEB) {
\r
138 $count = preg_match_all('/&#x([a-z0-9]{4});/ie', $str, $r);
\r
140 $regex = str_replace('{PATH}', preg_quote(rtrim($this->getFOMAImagePath(), '/'), '/'), $this->getRegex($type));
\r
141 $count += preg_match_all($regex, $str, $r);
\r
145 $this->setDS(unpack('C*', $str));
\r
146 $c = count($this->decstring);
\r
147 for ($this->i = 1;$this->i <= $c;$this->i++) {
\r
148 $result = $this->Inspection();
\r
149 if (is_null($result)) {
\r
153 //
\8aG
\95¶
\8e\9a\95Ï
\8a·
\8f\88\97\9d\r
154 if ($this->isPictogram($result)) {
\r
165 *
\83o
\83C
\83i
\83\8a\82ªi-mode
\8aG
\95¶
\8e\9a\82©
\82Ç
\82¤
\82©
\81A
\83`
\83F
\83b
\83N
\r
167 * @param array $chars
\r
170 function isPictogram($chars)
\r
172 if ($this->getFromCharset() == MPC_FROM_CHARSET_UTF8) {
\r
173 if (count($chars) != 3){
\r
176 list($char1, $char2, $char3) = $chars;
\r
177 if ($char1 == 0xEE &&
\r
179 ($char2 == 0x98 && ($char3 >= 0xBE && $char3 <= 0xBF)) ||
\r
180 ($char2 == 0x99 && ($char3 >= 0x80 && $char3 <= 0xBF)) ||
\r
181 ($char2 == 0x9A && ($char3 >= 0x80 && $char3 <= 0xBA)) ||
\r
182 ($char2 == 0x9B && ($char3 >= 0x8E && $char3 <= 0xBF)) ||
\r
183 ($char2 == 0x9C && ($char3 >= 0x80 && $char3 <= 0xBF)) ||
\r
184 ($char2 == 0x9D && ($char3 >= 0x80 && $char3 <= 0x97))
\r
192 if (count($chars) != 2) {
\r
195 list($char1, $char2) = $chars;
\r
196 if ((($char1 == 0xF8) && ($char2 >= 0x9F) && ($char2 <= 0xFC)) || (($char1 == 0xF9) && (($char2 >= 0x40 && $char2 <= 0x4F) || ($char2 >= 0x50 && $char2 <= 0x7E) || ($char2 >= 0x80 && $char2 <= 0xFC)))) {
\r