OSDN Git Service

初回コミット(v2.6.17.1)
[magic3/magic3.git] / include / lib / MobilePictogramConverter-1.2.0 / Carrier / ezweb.php
1 <?php\r
2 require_once 'common.php';\r
3 \r
4 // {{{ class MPC_EZweb\r
5 /**\r
6 * EZweb\8aG\95\8e\9a\95Ï\8a·\83x\81[\83X\83N\83\89\83X\r
7\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
11 */\r
12 class MPC_EZweb extends MPC_Common\r
13 {\r
14     /**\r
15     * \8aG\95\8e\9a\92\8a\8fo\90³\8bK\95\\8c»\r
16     * @var string\r
17     */\r
18     var $regex = array(\r
19         'WEB' => '/<img\s+(icon|localsrc)="?([0-9]+)"?\s*>/ie',\r
20         'IMG' => '/(<img src="{PATH}\/(\d{1,3})\.gif" alt="" border="0" \/>)/ie',\r
21     );\r
22     \r
23     /**\r
24     * \95\8e\9a\97ñ\82©\82çEZweb\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\91Î\89\9e\r
26     * \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
29     * @return string\r
30     */\r
31     function Convert($to, $option = MPC_TO_OPTION_RAW)\r
32     {\r
33         if (isset($toCharset)) {\r
34             $this->setToCharset($toCharset);\r
35         }\r
36         $this->setTo($to);\r
37         $this->setOption($option);\r
38         $str         = $this->getString();\r
39         $type        = $this->getStringType();\r
40         $fromCharset = $this->getFromCharset();\r
41         \r
42         // RAW\82Ö\95Ï\8a·\r
43         if ($type != MPC_FROM_OPTION_RAW) {\r
44             if (empty($this->e2icon_table)) {\r
45                 require 'map/e2icon_table.php';\r
46             }\r
47             $regex = str_replace('{PATH}', preg_quote(rtrim($this->getEZwebImagePath(), '/'), '/'), $this->getRegex($type));\r
48             $eval  = ($fromCharset == MPC_FROM_CHARSET_UTF8) ? 'mb_convert_encoding(pack("H*", dechex(\$this->e2icon_table[$2] - 1792)), "UTF-8", "unicode")' : 'pack("H*", dechex(\$this->e2icon_table[$2]))';\r
49             $str   = preg_replace($regex, $eval, $str);\r
50         }\r
51         \r
52         $this->setDS(unpack('C*', $str));\r
53         $c = count($this->decstring);\r
54         for ($this->i = 1;$this->i <= $c;$this->i++) {\r
55             $result = $this->Inspection();\r
56             if (is_null($result)) {\r
57                 continue;\r
58             }\r
59             \r
60             // \8aG\95\8e\9a\95Ï\8a·\8f\88\97\9d\r
61             if ($this->isPictogram($result)) {\r
62                 $hex = ($fromCharset == MPC_FROM_CHARSET_UTF8) ? strtoupper(dechex(hexdec(bin2hex(mb_convert_encoding(pack('H*', $this->decs2hex($result)), 'unicode', 'utf-8'))) + 1792)) : $this->decs2hex($result);\r
63                 if (empty($this->e2icon_table)) {\r
64                     require 'map/e2icon_table.php';\r
65                 }\r
66                 list($iconno) = array_keys($this->e2icon_table, hexdec($hex));\r
67                 $this->setPictogram($this->encoder($iconno));\r
68             } else {\r
69                 $this->setUnPictogram(pack('H*', $this->decs2hex($result)));\r
70             }\r
71         }\r
72         // \82±\82±\82Å\95\8e\9a\83R\81[\83h\82Ì\95Ï\8a·\82Æ\82©\82â\82é\97\\92è\r
73         $buf = $this->getUnPictograms() + $this->getPictograms();\r
74         $this->ReleaseUnPictograms();\r
75         $this->ReleasePictograms();\r
76         if (is_array($buf)) {\r
77             ksort($buf);\r
78             return implode('', $buf);\r
79         } else {\r
80             return null;\r
81         }\r
82     }\r
83     \r
84     /**\r
85     * \95\8e\9a\97ñ\82©\82çEZweb\8aG\95\8e\9a\82ð\8f\9c\8aO\82·\82é\r
86     * \r
87     * @return string\r
88     */\r
89     function Except()\r
90     {\r
91         $str     = $this->getString();\r
92         $type    = $this->getStringType();\r
93         $charset = $this->getFromCharset();\r
94         \r
95         if ($type != MPC_FROM_OPTION_RAW) {\r
96             if (empty($this->e2icon_table)) {\r
97                 require 'map/e2icon_table.php';\r
98             }\r
99             $regex = str_replace('{PATH}', preg_quote(rtrim($this->getEZwebImagePath(), '/'), '/'), $this->getRegex($type));\r
100             return preg_replace($regex, '', $str);\r
101         }\r
102         \r
103         $this->setDS(unpack('C*', $str));\r
104         $c = count($this->decstring);\r
105         for ($this->i = 1;$this->i <= $c;$this->i++) {\r
106             $result = $this->Inspection();\r
107             if (is_null($result)) {\r
108                 continue;\r
109             }\r
110             if ($this->isPictogram($result) == false) {\r
111                 $this->setUnPictogram(pack('H*', $this->decs2hex($result)));\r
112             }\r
113         }\r
114         $buf = $this->getUnPictograms();\r
115         $this->ReleaseUnPictograms();\r
116         if (is_array($buf)) {\r
117             return implode('', $buf);\r
118         } else {\r
119             return null;\r
120         }\r
121     }\r
122     \r
123     /**\r
124     * \95\8e\9a\97ñ\82ÉEZweb\8aG\95\8e\9a\82ª\89½\8cÂ\8aÜ\82Ü\82ê\82Ä\82¢\82é\82©\83`\83F\83b\83N\r
125     *\r
126     * @return integer\r
127     */\r
128     function Count()\r
129     {\r
130         $count   = 0;\r
131         $str     = $this->getString();\r
132         $type    = $this->getStringType();\r
133         $charset = $this->getFromCharset();\r
134         \r
135         if ($type != MPC_FROM_OPTION_RAW) {\r
136             if (empty($this->e2icon_table)) {\r
137                 require 'map/e2icon_table.php';\r
138             }\r
139             $regex = str_replace('{PATH}', preg_quote(rtrim($this->getEZwebImagePath(), '/'), '/'), $this->getRegex($type));\r
140             return preg_replace($regex, '', $str);\r
141         }\r
142         \r
143         $this->setDS(unpack('C*', $str));\r
144         $c = count($this->decstring);\r
145         for ($this->i = 1;$this->i <= $c;$this->i++) {\r
146             $result = $this->Inspection();\r
147             if (is_null($result)) {\r
148                 continue;\r
149             }\r
150             if ($this->isPictogram($result) == true) {\r
151                 $count++;\r
152             }\r
153         }\r
154         $this->ReleaseUnPictograms();\r
155         return $count;\r
156     }\r
157     \r
158     /**\r
159     * \83o\83C\83i\83\8a\82ªEZweb\8aG\95\8e\9a\82©\82Ç\82¤\82©\81A\83`\83F\83b\83N\r
160     * \r
161     * @param array $chars\r
162     * @return boolean\r
163     */\r
164     function isPictogram($chars)\r
165     {\r
166         if ($this->getFromCharset() == MPC_FROM_CHARSET_UTF8) {\r
167             list($char1, $char2, $char3) = $chars;\r
168             if (\r
169                 ($char1 == 0xEE &&\r
170                     (\r
171                         ($char2 == 0xB1 && ($char3 >= 0x80 && $char3 <= 0xBE)) ||\r
172                         ($char2 == 0xB2 && ($char3 >= 0x80 && $char3 <= 0xBF)) ||\r
173                         ($char2 == 0xB3 && ($char3 >= 0x80 && $char3 <= 0xBC)) ||\r
174                         ($char2 == 0xB5 && ($char3 >= 0x80 && $char3 <= 0xBE)) ||\r
175                         ($char2 == 0xB6 && ($char3 >= 0x80 && $char3 <= 0x8D)) ||\r
176                         ($char2 == 0xBD && ($char3 >= 0x80 && $char3 <= 0xBE)) ||\r
177                         ($char2 == 0xBE && ($char3 >= 0x80 && $char3 <= 0xBF)) ||\r
178                         ($char2 == 0xBF && ($char3 >= 0x80 && $char3 <= 0xBC))\r
179                      )\r
180                 ) ||\r
181                 ($char1 == 0xEF &&\r
182                     (\r
183                         ($char2 == 0x81 && ($char3 >= 0x80 && $char3 <= 0xBE)) ||\r
184                         ($char2 == 0x82 && ($char3 >= 0x80 && $char3 <= 0xBF)) ||\r
185                         ($char2 == 0x83 && ($char3 >= 0x80 && $char3 <= 0xBC))\r
186                     )\r
187                 )\r
188             ) {\r
189                 $boolean = true;\r
190             } else {\r
191                 $boolean = false;\r
192             }\r
193         } else {\r
194             list($char1, $char2) = $chars;\r
195             if ((($char1 == 0xF3 || $char1 == 0xF6 || $char1 == 0xF7) && (($char2 >= 0x40 && $char2 <= 0x7E) || ($char2 >= 0x80 && $char2 <= 0xFC))) || ($char1 == 0xF4 && (($char2 >= 0x40 && $char2 <= 0x7E) || ($char2 >= 0x80 && $char2 <= 0x8D)))) {\r
196                 $boolean = true;\r
197             } else {\r
198                 $boolean = false;\r
199             }\r
200         }\r
201         return $boolean;\r
202     }\r
203 }\r
204 // }}}\r
205 ?>