1 | <?php |
---|
2 | /** |
---|
3 | * @copyright 2005-2007 OpenPNE Project |
---|
4 | * @license http://www.php.net/license/3_01.txt PHP License 3.01 |
---|
5 | */ |
---|
6 | |
---|
7 | require_once './config.inc.php'; |
---|
8 | require_once OPENPNE_WEBAPP_DIR . '/init.inc'; |
---|
9 | |
---|
10 | $carrier = $argv[1]; |
---|
11 | $input_path = $argv[2]; |
---|
12 | $output_path = $argv[3]; |
---|
13 | |
---|
14 | if (empty($carrier) || empty($input_path)) { |
---|
15 | exit('carrier and input_path are must paramater'); |
---|
16 | } elseif (is_dir($input_path) === false) { |
---|
17 | exit('input_path is not directory'); |
---|
18 | } |
---|
19 | |
---|
20 | if (empty($output_path)) { |
---|
21 | $output_path = OPENPNE_PUBLIC_HTML_DIR . '/skin/default/img/emoji/' . $carrier . '/'; |
---|
22 | } elseif (is_dir($output_path) === false) { |
---|
23 | exit('output_path is not directory'); |
---|
24 | } |
---|
25 | |
---|
26 | switch ($carrier) { |
---|
27 | case 'i': |
---|
28 | convert_i_emoji_img($input_path, $output_path); |
---|
29 | break; |
---|
30 | case 'e': |
---|
31 | convert_e_emoji_img($input_path, $output_path); |
---|
32 | break; |
---|
33 | case 's': |
---|
34 | convert_s_emoji_img($input_path, $output_path); |
---|
35 | break; |
---|
36 | default: |
---|
37 | exit('carrier is not valid'); |
---|
38 | break; |
---|
39 | } |
---|
40 | |
---|
41 | function convert_i_emoji_img($input_path, $output_path) |
---|
42 | { |
---|
43 | $input_dir = opendir($input_path); |
---|
44 | |
---|
45 | if ($input_dir !== false && $output_dir !== false) { |
---|
46 | while (($file = readdir($input_dir)) !== false) { |
---|
47 | if (array_pop(explode('.', $file)) == 'gif') { |
---|
48 | $code = hexdec('0x' . basename($file, '.gif')); |
---|
49 | if ((0xF89F <= $code) && ($code <= 0xF8FC) || |
---|
50 | (0xF940 <= $code) && ($code <= 0xF949) || |
---|
51 | (0xF950 <= $code) && ($code <= 0xF952) || |
---|
52 | (0xF955 <= $code) && ($code <= 0xF957) || |
---|
53 | (0xF95B <= $code) && ($code <= 0xF95E) || |
---|
54 | (0xF972 <= $code) && ($code <= 0xF97E) || |
---|
55 | (0xF980 <= $code) && ($code <= 0xF9B0)) { |
---|
56 | $emoji_bin = pack("C*", $code >> 8, $code % 256); |
---|
57 | } else { |
---|
58 | $emoji_bin = pack("C*", 0xF9, $code); |
---|
59 | } |
---|
60 | $emoji_num = str_replace('%', '', emoji_escape_i($emoji_bin)); |
---|
61 | if (!empty($emoji_num)) { |
---|
62 | $input_emoji = $input_path . $file; |
---|
63 | $output_emoji = $output_path . $emoji_num . '.gif'; |
---|
64 | copy($input_emoji, $output_emoji); |
---|
65 | } |
---|
66 | } |
---|
67 | } |
---|
68 | } |
---|
69 | |
---|
70 | return false; |
---|
71 | } |
---|
72 | |
---|
73 | function convert_e_emoji_img($input_path, $output_path) //AU |
---|
74 | { |
---|
75 | $input_dir = opendir($input_path); |
---|
76 | |
---|
77 | if ($input_dir !== false && $output_dir !== false) { |
---|
78 | while (($file = readdir($input_dir)) !== false) { |
---|
79 | if (array_pop(explode('.', $file)) == 'gif') { |
---|
80 | $code = hexdec('0x' . basename($file, '.gif')); |
---|
81 | if ((0xF340 <= $code) && ($code <= 0xF37E) || |
---|
82 | (0xF380 <= $code) && ($code <= 0xF3FC) || |
---|
83 | (0xF440 <= $code) && ($code <= 0xF47E) || |
---|
84 | (0xF480 <= $code) && ($code <= 0xF493) || |
---|
85 | (0xF640 <= $code) && ($code <= 0xF67E) || |
---|
86 | (0xF680 <= $code) && ($code <= 0xF6FC) || |
---|
87 | (0xF740 <= $code) && ($code <= 0xF77E) || |
---|
88 | (0xF780 <= $code) && ($code <= 0xF7FC)) { |
---|
89 | $emoji_bin = pack("C*" , $code >> 8, $code % 256); |
---|
90 | } |
---|
91 | $emoji_num = str_replace('%', '', emoji_escape_ez($emoji_bin)); |
---|
92 | if (!empty($emoji_num)){ |
---|
93 | $input_emoji = $input_path . $file; |
---|
94 | $output_emoji = $output_path . $emoji_num . '.gif'; |
---|
95 | copy($input_emoji, $output_emoji); |
---|
96 | } |
---|
97 | } |
---|
98 | } |
---|
99 | } |
---|
100 | |
---|
101 | return false; |
---|
102 | } |
---|
103 | |
---|
104 | function convert_s_emoji_img($input_path, $output_path) //SoftBank |
---|
105 | { |
---|
106 | $input_dir = opendir($input_path); |
---|
107 | |
---|
108 | if ($input_dir !== false && $output_dir !== false) { |
---|
109 | while (($file = readdir($input_dir)) !== false) { |
---|
110 | if (array_pop(explode('.', $file)) == 'gif') { |
---|
111 | $emoji_num = get_s_emoji_number(basename($file,'.gif')); |
---|
112 | if ($emoji_num != 0){ |
---|
113 | $input_emoji = $input_path . $file; |
---|
114 | $output_emoji = $output_path . 's' . $emoji_num . '.gif'; |
---|
115 | copy($input_emoji,$output_emoji); |
---|
116 | } |
---|
117 | } |
---|
118 | } |
---|
119 | } |
---|
120 | } |
---|
121 | function get_s_emoji_number($file_basename) |
---|
122 | { |
---|
123 | $pattern_g = "/G[0-9a-z]+/"; |
---|
124 | $pattern_e = "/E[0-9a-z]+/"; |
---|
125 | $pattern_f = "/F[0-9a-z]+/"; |
---|
126 | $pattern_o = "/O[0-9a-z]+/"; |
---|
127 | $pattern_p = "/P[0-9a-z]+/"; |
---|
128 | $pattern_q = "/Q[0-9a-z]+/"; |
---|
129 | |
---|
130 | $emoji_num = 0; |
---|
131 | |
---|
132 | $pattern_num = "/[0-9a-z]+/"; |
---|
133 | preg_match($pattern_num,$file_basename,$result); |
---|
134 | |
---|
135 | if (preg_match($pattern_g,$file_basename)) { |
---|
136 | $group = hexdec($result[0]) - 32; |
---|
137 | }else if (preg_match($pattern_e,$file_basename)) { |
---|
138 | $group = hexdec($result[0]) + 100 - 32; |
---|
139 | }else if (preg_match($pattern_f,$file_basename)) { |
---|
140 | $group = hexdec($result[0]) + 200 - 32; |
---|
141 | }else if (preg_match($pattern_o,$file_basename)) { |
---|
142 | $group = hexdec($result[0]) + 300 - 32; |
---|
143 | }else if (preg_match($pattern_p,$file_basename)) { |
---|
144 | $group = hexdec($result[0]) + 400 - 32; |
---|
145 | }else if (preg_match($pattern_q,$file_basename)) { |
---|
146 | $group = hexdec($result[0]) + 500 - 32; |
---|
147 | } |
---|
148 | |
---|
149 | return $group; |
---|
150 | |
---|
151 | } |
---|
152 | ?> |
---|