private function convertEmojiForInputCallback($value) { if (is_array($value)) { return array_map(array($this, 'convertEmojiForInputCallback'), $value); } $result = ''; for ($i = 0; $i < strlen($value); $i++) { $emoji = ''; $c1 = ord($value[$i]); if ($this->getContext()->getRequest()->getMobile()->isSoftBank()) { if ($c1 == 0xf7 || $c1 == 0xf9 || $c1 == 0xfb) { $bin = substr($value, $i, 2); $emoji = OpenPNE_KtaiEmoji::convertSoftBankEmojiToOpenPNEFormat($bin); } } elseif ($c1 == 0xf8 || $c1 == 0xf9) { $bin = substr($value, $i, 2); $emoji = OpenPNE_KtaiEmoji::convertDoCoMoEmojiToOpenPNEFormat($bin); } elseif (0xf3 <= $c1 && $c1 <= 0xf7) { $bin = substr($value, $i, 2); $emoji = OpenPNE_KtaiEmoji::convertEZWebEmojiToOpenPNEFormat($bin); } if ($emoji) { $result .= $emoji; $i++; } else { $result .= $value[$i]; if (0x81 <= $c1 && $c1 <= 0x9f || 0xe0 <= $c1) { $result .= $value[$i + 1]; $i++; } } } return $result; }
public function getListJson($controller, $contents) { sfContext::getInstance()->getConfiguration()->loadHelpers(array('Helper', 'Tag', 'Escaping', 'opUtil')); $result = array(); foreach ($contents as $content) { $data = array('number' => $content->number, 'level' => $content->level, 'member_url' => $controller->genUrl('@obj_member_profile?id=' . $content->member_id), 'member_name' => $content->Member->name, 'command' => $content->command, 'body' => $content->body, 'created_at' => $content->created_at); foreach ($data as &$d) { $d = sfOutputEscaper::escape(sfConfig::get('sf_escaping_method'), $d); $d = OpenPNE_KtaiEmoji::convertEmoji($d); } $data['body'] = op_auto_link_text(op_decoration(nl2br($data['body']))); $result[] = $data; } return json_encode($result); }
/** * Executes this filter. * * @param sfFilterChain $filterChain A sfFilterChain instance */ public function execute($filterChain) { $filterChain->execute(); $response = $this->getContext()->getResponse(); $request = $this->getContext()->getRequest(); $content = $response->getContent(); if (!$request->isMobile()) { list($list, $content) = opToolkit::replacePatternsToMarker($content); } $content = OpenPNE_KtaiEmoji::convertEmoji($content); if (!$request->isMobile()) { $content = str_replace(array_keys($list), array_values($list), $content); } $response->setContent($content); }
function _emoji_convert($matches) { $o_code = $matches[1]; switch ($GLOBALS['__Framework']['carrier']) { case 'i': case 'w': case 'em': $carrier = 'i'; break; case 's': $carrier = 's'; break; case 'e': $carrier = 'e'; break; default: $carrier = null; break; } $emoji_code = OpenPNE_KtaiEmoji::getInstance(); $c_emoji = $emoji_code->convert_emoji($o_code, $carrier); if ($c_emoji) { return $c_emoji; } else { return '〓'; } }
protected static function convertEmojiCallback($matches) { $o_code = $matches[1]; $c_carrier = sfConfig::get('op_opensocial_api_emoji_carrier', 'i'); $o_carrier = $o_code[0]; $o_id = substr($o_code, 2); $ktaiEmoji = OpenPNE_KtaiEmoji::getInstance(); if ($c_carrier == $o_carrier) { $emojiString = $ktaiEmoji->convert_emoji($o_code, $c_carrier); if ($emojiString) { if ('i' === $c_carrier) { return mb_convert_encoding($emojiString, 'UTF-8', 'SJIS-win'); } return $emojiString; } } elseif (isset($ktaiEmoji->relation_list[$o_carrier][$c_carrier][$o_id])) { return self::convertEmoji($ktaiEmoji->relation_list[$o_carrier][$c_carrier][$o_id]); } return '〓'; }
public static function convertSoftBankEmojiToOpenPNEFormat($bin) { $sjis1 = ord($bin[0]); $sjis2 = ord($bin[1]); $web1 = $web2 = 0; switch ($sjis1) { case 0xf9: if ($sjis2 >= 0x41 && $sjis2 <= 0x7e) { $web1 = ord('G'); $web2 = $sjis2 - 0x20; } elseif ($sjis2 >= 0x80 && $sjis2 <= 0x9b) { $web1 = ord('G'); $web2 = $sjis2 - 0x21; } elseif ($sjis2 >= 0xa1 && $sjis2 <= 0xed) { $web1 = ord('O'); $web2 = $sjis2 - 0x80; } break; case 0xf7: if ($sjis2 >= 0x41 && $sjis2 <= 0x7e) { $web1 = ord('E'); $web2 = $sjis2 - 0x20; } elseif ($sjis2 >= 0x80 && $sjis2 <= 0x9b) { $web1 = ord('E'); $web2 = $sjis2 - 0x21; } elseif ($sjis2 >= 0xa1 && $sjis2 <= 0xf3) { $web1 = ord('F'); $web2 = $sjis2 - 0x80; } break; case 0xfb: if ($sjis2 >= 0x41 && $sjis2 <= 0x7e) { $web1 = ord('P'); $web2 = $sjis2 - 0x20; } elseif ($sjis2 >= 0x80 && $sjis2 <= 0x8d) { $web1 = ord('P'); $web2 = $sjis2 - 0x21; } elseif ($sjis2 >= 0xa1 && $sjis2 <= 0xd7) { $web1 = ord('Q'); $web2 = $sjis2 - 0x80; } break; default: return ''; } $emoji_code = OpenPNE_KtaiEmoji::getInstance(); $code = $emoji_code->get_emoji_code4emoji(pack('c5', 0x1b, 0x24, $web1, $web2, 0xf), 's'); return '[' . $code . ']'; }
protected function convertSoftBankEmoji($matches) { $unicode = mb_convert_encoding($matches[0], 'UCS2', 'UTF-8'); $unicode = array(ord($unicode[0]), ord($unicode[1])); $bias = array(0x19, 0x40); switch ($unicode[0]) { case 0xe1: $bias[0] = 0x16; break; case 0xe2: $bias[0] = 0x15; $bias[1] = 0xa0; break; case 0xe3: case 0xe5: $bias[0] = 0x16; $bias[1] = 0xa0; break; case 0xe4: $bias[0] = 0x17; break; } if ($bias[1] == 0x40) { if ($unicode[1] >= 0x40) { $bias[1]++; } } return OpenPNE_KtaiEmoji::convertSoftBankEmojiToOpenPNEFormat(pack('C*', $unicode[0] + $bias[0], $unicode[1] + $bias[1])); }
public static function convertSoftBankEmojiToOpenPNEFormat($bin) { $sjis1 = ord($bin[0]); $sjis2 = ord($bin[1]); $codepoint = 0; switch ($sjis1) { case 0xf9: if ($sjis2 >= 0x41 && $sjis2 <= 0x7e) { $codepoint = 0xe000 + $sjis2 - 0x40; } elseif ($sjis2 >= 0x80 && $sjis2 <= 0x9b) { $codepoint = 0xe000 + $sjis2 - 0x41; } elseif ($sjis2 >= 0xa1 && $sjis2 <= 0xed) { $codepoint = 0xe300 + $sjis2 - 0xa0; } break; case 0xf7: if ($sjis2 >= 0x41 && $sjis2 <= 0x7e) { $codepoint = 0xe100 + $sjis2 - 0x40; } elseif ($sjis2 >= 0x80 && $sjis2 <= 0x9b) { $codepoint = 0xe100 + $sjis2 - 0x41; } elseif ($sjis2 >= 0xa1 && $sjis2 <= 0xf3) { $codepoint = 0xe200 + $sjis2 - 0xa0; } break; case 0xfb: if ($sjis2 >= 0x41 && $sjis2 <= 0x7e) { $codepoint = 0xe400 + $sjis2 - 0x40; } elseif ($sjis2 >= 0x80 && $sjis2 <= 0x8d) { $codepoint = 0xe400 + $sjis2 - 0x41; } elseif ($sjis2 >= 0xa1 && $sjis2 <= 0xd7) { $codepoint = 0xe500 + $sjis2 - 0xa0; } break; default: return ''; } $emoji_code = OpenPNE_KtaiEmoji::getInstance(); $code = $emoji_code->get_emoji_code4emoji(sprintf('&#x%04X;', $codepoint), 's'); return '[' . $code . ']'; }