powered by nequal
Home » Japanese_Mobile_Emoji » Timeline » 727

Changeset 727 -- 2009-04-19 20:01:47

Comment
[Add Tag:Release] Japanese_Mobile_Emoji

Diffs

Japanese_Mobile_Emoji/tags/0.1-beta/hello_world.php

@@ -0,0 +1,67 @@
+<?php
+require_once("Net/UserAgent/Mobile.php");
+require_once("Japanese_Mobile_Emoji.php");
+require_once("Japanese_Mobile_Emoji_Convert.php");
+
+ob_start();
+
+echo '<?xml version="1.0" encoding="UTF-8"?>';?>
+<!DOCTYPE html PUBLIC "-//i-mode group (ja)//DTD XHTML i-XHTML(Locale/Ver.=ja/2.0) 1.0//EN" "i-xhtml_4ja_10.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+<title>絵文字実装テスト用ページ</title>
+
+<style type="text/css">
+<![CDATA[
+a:focus{color:#FFFFFF}
+a:visited{color:#FF3366}
+a:link{color:#FF3366}
+}
+]]>
+</style>
+
+</head>
+<body style="background-color:#FFFFFF;color:#000000">
+<span style="font-size:small;">
+
+<?php
+echo "hello world";
+if(!empty($_SERVER["HTTPS"]) == "on"){
+	$this_url = "https://";
+}else{
+	$this_url = "http://";
+}
+$this_url .= $_SERVER["SERVER_NAME"].$_SERVER["SCRIPT_NAME"];
+?>
+
+[emoji:1]
+[emoji::1]
+[emoji:::1]
+
+<br />
+
+<img src="http://chart.apis.google.com/chart?
+chs=150x150&cht=qr&chl=<?php echo $this_url; ?>" />
+
+<br />
+
+<?php
+echo $this_url;
+?>
+</span>
+</body>
+</html><?php
+$bf = ob_get_clean();
+$emoji = Japanese_Mobile_Emoji::singleton();
+$emoji->setEmojiImg("/openper_JapaneseMobileEmoji/img/emoji/");
+$bf = $emoji->doConvert2output($bf);
+echo $bf;
+
+
+function pr($val){
+	echo "<pre>";
+	print_r($val);
+	echo "</pre>";
+}
+?>
\ ファイルの末尾に改行がありません

Japanese_Mobile_Emoji/tags/0.1-beta/emoji/img.csv

@@ -0,0 +1,252 @@
+1,sun
+2,cloud
+3,rain
+4,snow
+5,thunder
+6,typhoon
+7,mist
+8,sprinkle
+9,aries
+10,taurus
+11,gemini
+12,cancer
+13,leo
+14,virgo
+15,libra
+16,scorpius
+17,sagittarius
+18,capricornus
+19,aquarius
+20,fish
+21,sports
+22,baseball
+23,golf
+24,tennis
+25,soccer
+26,ski
+27,basketball
+28,motorsports
+29,pocketbell
+30,train
+31,subway
+32,bullettrain
+33,car
+34,rvcar
+35,bus
+36,ship
+37,airplane
+38,house
+39,building
+40,postoffice
+41,hospital
+42,bank
+43,atm
+44,hotel
+45,24hours
+46,gasstation
+47,parking
+48,signaler
+49,toilet
+50,restaurant
+51,cafe
+52,bar
+53,beer
+54,fastfood
+55,boutique
+56,hairsalon
+57,karaoke
+58,movie
+59,upwardright
+60,carouselpony
+61,music
+62,art
+63,drama
+64,event
+65,ticket
+66,smoking
+67,nosmoking
+68,camera
+69,bag
+70,book
+71,ribbon
+72,present
+73,birthday
+74,telephone
+75,mobilephone
+76,memo
+77,tv
+78,game
+79,cd
+80,heart
+81,spade
+82,diamond
+83,club
+84,eye
+85,ear
+86,rock
+87,scissors
+88,paper
+89,downwardright
+90,upwardleft
+91,foot
+92,shoe
+93,eyeglass
+94,wheelchair
+95,newmoon
+96,moon1
+97,moon2
+98,moon3
+99,fullmoon
+100,dog
+101,cat
+102,yacht
+103,xmas
+104,downwardleft
+105,phoneto
+106,mailto
+107,faxto
+108,info01
+109,info02
+110,mail
+111,by-d
+112,d-point
+113,yen
+114,free
+115,id
+116,key
+117,enter
+118,clear
+119,search
+120,new
+121,flag
+122,freedial
+123,sharp
+124,mobaq
+125,one
+126,two
+127,three
+128,four
+129,five
+130,six
+131,seven
+132,eight
+133,nine
+134,zero
+135,ok
+136,heart01
+137,heart02
+138,heart03
+139,heart04
+140,happy01
+141,angry
+142,despair
+143,sad
+144,wobbly
+145,up
+146,note
+147,spa
+148,cute
+149,kissmark
+150,shine
+151,flair
+152,annoy
+153,punch
+154,bomb
+155,notes
+156,down
+157,sleepy
+158,sign01
+159,sign02
+160,sign03
+161,impact
+162,sweat01
+163,sweat02
+164,dash
+165,sign04
+166,sign05
+167,slate
+168,pouch
+169,pen
+170,shadow
+171,chair
+172,night
+173,soon
+174,on
+175,end
+176,clock
+1001,appli01
+1002,appli02
+1003,t-shirt
+1004,moneybag
+1005,rouge
+1006,denim
+1007,snowboard
+1008,bell
+1009,door
+1010,dollar
+1011,pc
+1012,loveletter
+1013,wrench
+1014,pencil
+1015,crown
+1016,ring
+1017,sandclock
+1018,bicycle
+1019,japanesetea
+1020,watch
+1021,think
+1022,confident
+1023,coldsweats01
+1024,coldsweats02
+1025,pout
+1026,gawk
+1027,lovely
+1028,good
+1029,bleah
+1030,wink
+1031,happy02
+1032,bearing
+1033,catface
+1034,crying
+1035,weep
+1036,ng
+1037,clip
+1038,copyright
+1039,tm
+1040,run
+1041,secret
+1042,recycle
+1043,r-mark
+1044,danger
+1045,ban
+1046,empty
+1047,pass
+1048,full
+1049,leftright
+1050,updown
+1051,school
+1052,wave
+1053,fuji
+1054,clover
+1055,cherry
+1056,tulip
+1057,banana
+1058,apple
+1059,bud
+1060,maple
+1061,cherryblossom
+1062,riceball
+1063,cake
+1064,bottle
+1065,noodle
+1066,bread
+1067,snail
+1068,chick
+1069,penguin
+1070,pisces
+1071,delicious
+1072,smile
+1073,horse
+1074,pig
+1075,wine
+1076,shock
\ ファイルの末尾に改行がありません

Japanese_Mobile_Emoji/tags/0.1-beta/Japanese_Mobile_Emoji.php

@@ -0,0 +1,147 @@
+<?php
+require_once(dirname(__FILE__)."/Japanese_Mobile_Emoji_Convert.php");
+class Japanese_Mobile_Emoji{
+
+	/**
+	 * 自分自身のインスタンス
+	 * @var Japanese_Mobile_Emoji
+	 */
+	static $instance;
+
+	/**
+	 * @var JpMobileEmojiConvert
+	 */
+	protected $emojiConvert;
+
+	protected $outputCareer = "pc";
+
+
+	/**
+	 *
+	 * @var Net_UserAgent_Mobile
+	 */
+	protected $mobile;
+
+	protected $options = array(
+		"emoji_dir_path" => "/img/emoji/",	//絵文字画像のパス
+		"emoji_ext" => "gif",				//絵文字画像の拡張子
+	);
+
+	/**
+	 * インスタンスを返すメソッド
+	 * @return EmojiTest
+	 */
+	public function singleton(){
+		if(!isset(self::$instance)){
+			self::$instance = new Japanese_Mobile_Emoji();
+		}
+		return self::$instance;
+	}
+
+	/**
+	 * 初期設定
+	 * @return unknown_type
+	 */
+	protected function __construct(){
+		$this->mobile = Net_UserAgent_Mobile::singleton();
+
+		//出力キャリアを設定する
+		switch(true){
+			case $this->mobile->isDoCoMo():
+				$this->outputCareer = "docomo";
+				break;
+			case $this->mobile->isEZweb():
+				$this->outputCareer = "au";
+				break;
+			case $this->mobile->isSoftBank():
+				$this->outputCareer = "softbank";
+				break;
+
+			default:
+				$this->outputCareer = "pc";
+		}
+
+		//絵文字コンバート用のクラスのインスタンスを作成
+		$this->emojiConvert = Japanese_Mobile_Emoji_Convert::singleton(
+															$this->outputCareer,
+															$this->options["emoji_dir_path"],
+															$this->options["emoji_ext"]
+															);
+		//絵文字コードが読み込まれていない場合は読み込む
+//		if(empty($this->emojiCode)){
+//			$this->emojiConvert->loadEmojiCode();
+
+//		}
+	}
+
+
+	protected function emoji_output_change($matches){
+		//入力データが無い場合
+		if(empty($matches) || !is_array($matches) || count($matches) != 2){
+			return '';
+		}
+		//入力データを取得する
+		$emoji_num_csv = trim($matches[1]);
+		if(empty($emoji_num_csv)){
+			return '';
+		}
+		//変換する文字が無い場合はここまでで終了
+
+		//絵文字指定文字列を分割する
+		$emoji_num_array = array();
+		list($emoji_num_array["docomo"],$emoji_num_array["au"],$emoji_num_array["softbank"])
+			= 	explode(":", $emoji_num_csv);
+
+		if(in_array($this->outputCareer,array("docomo","au","softbank"))){
+			$convert_to = $this->outputCareer;
+		}else{
+			$convert_to = "img";
+		}
+		$emoji_numer = $this->emojiConvert->doNumberConvert($convert_to,$emoji_num_array);
+		return $this->emojiConvert->doEmojiConvert($convert_to,$emoji_numer);
+/*
+		switch($this->outputCareer){
+			case "docomo":
+//				pr($this->emojiCode->docomo->$emoji_num);
+//				return "&#x".$this->emojiCode->docomo->$emoji_num->unicode.";";
+
+				break;
+			case "au":
+				break;
+			case "softbank":
+				break;
+			default:
+				break;
+		}
+*/
+	}
+
+	public function doConvert2output($bf){
+		$bf = preg_replace_callback(
+				 		'/\[emoji:([0-9:]+)\]/',
+						array($this,'emoji_output_change'),
+						$bf
+					);
+		return $bf;
+	}
+
+	/**
+	 * 絵文字画像のパスと拡張子を設定する。変更する場合はdoConvert2outputの前にコールすること。
+	 * @param $emoji_dir_path	絵文字画像のパス
+	 * @param $emoji_extntion	絵文字画像の拡張子
+	 */
+	public function setEmojiImg($emoji_dir_path = null,$emoji_extntion = null){
+		$this->emojiConvert->setEmojiImg($emoji_dir_path,$emoji_extntion);
+	}
+
+	/**
+	 * このインスタンスの複製を許可しないようにする
+	 * @throws RuntimeException
+	 */
+	public final function __clone(){
+		throw new RuntimeException('Clone is not allowd against '.get_class($this));
+	}
+
+
+}
+?>
\ ファイルの末尾に改行がありません

Japanese_Mobile_Emoji/tags/0.1-beta/Japanese_Mobile_Emoji_Convert.php

@@ -0,0 +1,299 @@
+<?php
+class Japanese_Mobile_Emoji_Convert{
+
+	/**
+	 * 自分自身のインスタンス
+	 * @var Japanese_Mobile_Emoji_Convert
+	 */
+	static $instance;
+
+
+	/**
+	 * 絵文字番号変換
+	 * @var stdClass
+	 */
+	protected $convert_array;
+
+	/**
+	 * 絵文字コード
+	 * @var stdClass
+	 */
+	protected $emoji_code;
+
+
+	protected $img_path = "/img/emoji/";
+	protected $img_ext = "gif";
+
+	public function singleton($career,$img_path,$img_ext){
+		if(!isset(self::$instance)){
+			self::$instance = new Japanese_Mobile_Emoji_Convert($career,$img_path,$img_ext);
+		}
+		return self::$instance;
+	}
+
+	protected function __construct($career,$img_path = null,$img_ext = null){
+		if(!is_null($img_path)){
+			if(substr($img_path,-1) != "/"){
+				$img_path .= "/";
+			}
+			$this->img_path = $img_path;
+		}
+		if(!is_null($img_ext)){
+			$this->img_ext = str_replace(array(".","/"),"",$img_ext);
+		}
+		$this->loadEmojiCode($career);
+	}
+
+	/**
+	 * 絵文字画像のパスと拡張子を設定する。
+	 * @param $emoji_dir_path	絵文字画像のパス
+	 * @param $emoji_extntion	絵文字画像の拡張子
+	 */
+	public function setEmojiImg($emoji_dir_path = null,$emoji_extntion = null){
+		if(!is_null($emoji_dir_path)){
+			$this->img_path = $emoji_dir_path;
+		}
+		if(!is_null($emoji_extntion)){
+			$this->img_ext = $emoji_extntion;
+		}
+	}
+
+
+	/**
+	 * 絵文字コードを読み込む
+	 * @return unknown_type
+	 */
+	protected function loadEmojiCode($career){
+		if(!empty($this->emoji_code)){
+			return null;
+		}
+		//読み込むファイル名を取得する
+		$filepath = $this->getLoadEmojiCodeFilename($career);
+		//パスがnull以外且つ読み込み可能ならファイルを読み込んでjsonでコードする
+		if($career == "pc" && is_readable($filepath)){
+			$this->emoji_code = new stdClass();
+			$this->emoji_code->img = new stdClass();
+			$lines = file($filepath);
+			$line_cnt = count($lines);
+			for($i=0; $i<$line_cnt; $i++){
+				list($num,$name) = explode(",",$lines[$i]);
+				$this->emoji_code->img->{$num} = trim($name);
+			}
+			//pr($this->emoji_code);
+		}elseif(!is_null($filepath) && is_readable($filepath)){
+			$json = file_get_contents($filepath);
+			$this->emoji_code = json_decode($json);
+		}else{
+			//die("絵文字コードが読み込めません:".$filepath);
+		}
+	}
+
+
+	/**
+	 * 出力キャリアにあわせて絵文字コードのファイル名(パス)を返す
+	 * @param $career
+	 * @return string $path
+	 */
+	protected function getLoadEmojiCodeFilename($career){
+//		if(is_null($career)){
+//			$career = $this->outputCareer;
+//		}
+		$path = dirname(__FILE__)."/emoji/";
+		switch($career){
+			case "docomo":
+				$path .= "docomo_emoji.json";
+				break;
+			case "au":
+				$path .= "ezweb_emoji.json";
+				break;
+			case "softbank":
+				$path .= "softbank_emoji.json";
+				break;
+			default:
+				$path .= "img.csv";
+		}
+		return $path;
+	}
+
+
+	/**
+	 * キャリア間での絵文字番号を変換する
+	 * @param $emoji_num	絵文字番号
+	 * @param $to_career	出力キャリア
+	 * @param $from_career	絵文字番号キャリア
+	 * @return string		絵文字コード
+	 */
+	public function doNumberConvert($to_career,$emoji_num_array){
+		//pr(func_get_args());
+		$number = '';
+		switch ($to_career){
+			case "docomo":
+				$number = $this->convert2docomo($emoji_num_array);
+				break;
+			case "au":
+				$number = $this->convert2au($emoji_num_array);
+				break;
+			case "softbank":
+				$number = $this->convert2softbank($emoji_num_array);
+				break;
+			default:
+				if(isset($emoji_num_array["docomo"]) && $emoji_num_array["docomo"]){
+					$number = $emoji_num_array["docomo"];
+				}elseif(isset($emoji_num_array["au"]) && $emoji_num_array["au"]){
+					$number = $this->convert2docomo($emoji_num_array,"au");
+				}elseif(isset($emoji_num_array["softbank"]) && $emoji_num_array["softbank"]){
+					$number = $this->convert2docomo($emoji_num_array,"softbank");
+				}
+		}
+		return $number;
+	}
+
+		/**
+		 * ドコモ用に変換する
+		 * @param $emoji_num	絵文字番号
+		 * @param $from_career	絵文字番号キャリア
+		 * @return string		絵文字コード
+		 */
+		protected function convert2docomo($emoji_num_array){
+	//		pr($emoji_num_array);
+			$emoji_num = 0;
+			if(isset($emoji_num_array["docomo"]) && $emoji_num_array["docomo"]){
+				$emoji_num = $emoji_num_array["docomo"];
+			}else{
+				if(isset($emoji_num_array["au"]) && $emoji_num_array["au"]){
+					$this->loadConvertFile("ezweb");	//コンバートファイル読み込み
+					$emoji_num = $this->convert_array["ezweb"]->{$emoji_num_array["au"]}->docomo;
+				}elseif(isset($emoji_num_array["softbank"]) && $emoji_num_array["softbank"]){
+					$this->loadConvertFile("softbank");	//コンバートファイル読み込み
+					$emoji_num = $this->convert_array["softbank"]->{$emoji_num_array["softbank"]}->docomo;
+				}
+			}
+			return $emoji_num;
+		}
+		/**
+		 * au(ezweb)用に変換する
+		 * @param $emoji_num	絵文字番号
+		 * @param $from_career	絵文字番号キャリア
+		 * @return string		絵文字コード
+		 */
+		protected function convert2au($emoji_num_array){
+			$emoji_num = 0;
+			if(isset($emoji_num_array["au"]) && $emoji_num_array["au"]){
+				$emoji_num = $emoji_num_array["au"];
+			}else{
+
+				if(isset($emoji_num_array["docomo"]) && $emoji_num_array["docomo"]){
+					$this->loadConvertFile("docomo");	//コンバートファイル読み込み
+					$emoji_num = $this->convert_array["docomo"]->{$emoji_num_array["docomo"]}->ezweb;
+				}elseif(isset($emoji_num_array["softbank"]) && $emoji_num_array["softbank"]){
+					$this->loadConvertFile("softbank");	//コンバートファイル読み込み
+					$emoji_num = $this->convert_array["softbank"]->{$emoji_num_array["softbank"]}->ezweb;
+				}
+			}
+			return $emoji_num;
+		}
+
+		/**
+		 * ソフトバンク用に変換する
+		 * @param $emoji_num	絵文字番号
+		 * @param $from_career	絵文字番号キャリア
+		 * @return string		絵文字コード
+		 */
+		protected function convert2softbank($emoji_num_array){
+			$emoji_num = 0;
+			if(isset($emoji_num_array["softbank"]) && $emoji_num_array["softbank"]){
+				$emoji_num = $emoji_num_array["softbank"];
+			}else{
+
+				if(isset($emoji_num_array["docomo"]) && $emoji_num_array["docomo"]){
+					$this->loadConvertFile("docomo");	//コンバートファイル読み込み
+					$emoji_num = $this->convert_array["docomo"]->{$emoji_num_array["docomo"]}->softbank;
+				}elseif(isset($emoji_num_array["au"]) && $emoji_num_array["au"]){
+					$this->loadConvertFile("ezweb");	//コンバートファイル読み込み
+					$emoji_num = $this->convert_array["ezweb"]->{$emoji_num_array["au"]}->softbank;
+				}
+			}
+			return $emoji_num;
+		}
+
+
+		/**
+		 * 絵文字コードのコンバートデータファイルを読み込む
+		 * @param $career		読み込むファイルのキャリア名
+		 */
+		protected function loadConvertFile($career){
+			if(!isset($this->convert_array[$career])){
+				$filename = dirname(__FILE__)."/emoji/{$career}_convert.json";
+				if(file_exists($filename) && is_readable($filename)){
+					$json = file_get_contents($filename);
+					$obj = json_decode($json);
+					$this->convert_array[$career] = $obj->{$career};
+				}else{
+					die("convert data not found.");
+				}
+			}
+		}
+
+	/**
+	 * 絵文字番号を出力キャリア毎に会わせて得文字コードに変換する
+	 * @param $to_career
+	 * @param $emoji_number
+	 * @return unknown_type
+	 */
+	public function doEmojiConvert($to_career,$emoji_number){
+		switch($to_career){
+			case "docomo":
+				return $this->getEmojiCode4docomo($emoji_number);
+				break;
+			case "au":
+				return $this->getEmojiCode4au($emoji_number);
+				break;
+			case "softbank":
+				return $this->getEmojiCode4softbank($emoji_number);
+				break;
+			default:
+				return $this->getEmojiImgTag($emoji_number);
+		}
+	}
+		/**
+		 * 絵文字番号をドコモの絵文字コードに変換する
+		 * @return unknown_type
+		 */
+		protected function getEmojiCode4docomo($emoji_num){
+			if($emoji_num){
+				$str = "&#x".$this->emoji_code->docomo->$emoji_num->unicode.";";
+			return $str;
+			}
+
+		}
+
+		protected function getEmojiCode4au($emoji_num){
+//				pr($emoji_num);
+//				pr($this->emoji_code->ezweb);
+			if($emoji_num){
+				$str = "&#x".$this->emoji_code->ezweb->{$emoji_num}->unicode.";";
+			return $str;
+			}
+		}
+
+		protected function getEmojiCode4softbank($emoji_num){
+//				pr($emoji_num);
+//				pr($this->emoji_code->ezweb);
+			if($emoji_num){
+				$str = "&#x".$this->emoji_code->softbank->{$emoji_num}->unicode.";";
+			return $str;
+			}
+		}
+
+		protected function getEmojiImgTag($emoji_num){
+
+			$str = '<img src="'
+				.	$this->img_path
+				.	$this->emoji_code->img->{$emoji_num}.'.'.$this->img_ext
+				.	'" '
+				.	'class="emoji emoji_'.$emoji_num.'" />';
+			return $str;
+		}
+
+}
+?>
\ ファイルの末尾に改行がありません
属性に変更があったパス: Japanese_Mobile_Emoji/tags/0.1-beta
___________________________________________________________________
名前: svn:ignore
+ .buildpath
.project