MobilePictogramConverterをiPhoneに対応させてみる。

CakePHPで携帯サイトを作っています。
このサイトをiPhoneにも対応させたのですが、携帯で入力した絵文字がiPhoneで表示されない。。。

キャリア間の絵文字変換にはMobilePictogramConverterを使わせてもらっていますが、
これをiPhoneに対応させてみました。

MobilePictogramConverterの使い方について

編集対象は「MobilePictogramConverter/Carrier/common.php」です。

ファイル先頭の定数定義に以下を追加します。
(変換先キャリアにiPhoneを追加。)

  define('MPC_TO_SOFTBANK', 'SOFTBANK');
+ define('MPC_TO_IPHONE', 'IPHONE');
  /* 変換後の絵文字体系 */

UserAgentからキャリアを割り出す正規表現iPhoneを追加。

  var $mobile_user_agent = array(
    'DoCoMo'   => '/^DoCoMo\/\d\.\d[ \/]/',
+   'iPhone'   => '/iPhone/',
    'SoftBank' => '/^(?:(?:SoftBank|Vodafone|J-PHONE)\/\d\.\d|MOT-)/',

自動変換用のメソッドにiPhone用の設定を追加

 function autoConvert($toCharset = null)
 {
     $useragent = $_SERVER['HTTP_USER_AGENT'];
     if (preg_match($this->getRegexp('DoCoMo'), $useragent)) {
         $to     = MPC_TO_FOMA;
         $option = MPC_TO_OPTION_RAW;
+    } elseif (preg_match($this->getRegexp('iPhone'), $useragent)) {
+        $to     = MPC_TO_IPHONE;
+        $option = MPC_TO_OPTION_RAW;

変換テーブルを指定するコードのiPhone対応

 function encoder($data)
 {
     $buf  = '';
     $to   = $this->getTo();
+    $c    = ($to == MPC_TO_EZWEB) ? 'e' : (($to == MPC_TO_SOFTBANK || $to == MPC_TO_IPHONE) ? 's' : 'i');

ソフトバンク向けの変換コードの中のiPhone対応。

 function s_options_encode($dec)
 {
     switch($this->getOption()) {
         case MPC_TO_OPTION_RAW:
             list($hex1, $hex2) = sscanf(dechex($dec), '%02s%02s');
(中略)
             $char3 = $dec2 + $num;
             $buf   = pack('C*', 0xEE, $char2, $char3);

+            if($this->getTo() == MPC_TO_IPHONE){
+              $buf = bin2hex(mb_convert_encoding($buf, 'unicode', 'UTF-8'));
+              $buf = "&#x{$buf};";
+              break;
+            }
             
             if ($this->getFromCharset() === 'SJIS') {...

※ MobilePictogramConverterの本家って現在はリンク切れしてますね。。。
いいモジュールなんで、メンテがとまってしまって残念です。
でもまあ、絵文字変換モジュールのメンテって、細かい問題がいっぱいあって大変なんでしょうねー。