Smarty(); $this->ua =& $ua; $this->internal_encoding = $internal_encoding; // キャリア毎のテンプレート・ディレクトリ設定 if(!$this->ua->is_mobile()) { $this->template_encoding = $template_encoding; $this->output_encoding = ($output_encoding) ? $output_encoding : $template_encoding; $this->html_charset = $html_charset; } else { $this->template_encoding = array('templates/i' => 'SJIS-win', 'templates/e' => 'SJIS-win', 'templates/v' => 'SJIS-win', 'templates/v3g' => 'UTF-8', 'templates/w' => 'SJIS-win', 'templates' => $template_encoding); $this->output_encoding = array('templates/i' => 'SJIS-win', 'templates/e' => 'SJIS-win', 'templates/v' => 'SJIS-win', 'templates/v3g' => 'UTF-8', 'templates/w' => 'SJIS-win', 'templates' => $output_encoding); $this->html_charset = array('templates/i' => 'Shift_JIS', 'templates/e' => 'Shift_JIS', 'templates/v' => 'Shift_JIS', 'templates/v3g' => 'UTF-8', 'templates/w' => 'Shift_JIS', 'templates' => $this->html_charset); if($this->ua->get_carrier() === $this->ua->CARRIER_DOCOMO()) { $this->template_dir = array('templates/i', 'templates/e', 'templates/v', 'templates/w', 'templates'); $this->compile_dir = 'templates_c/i'; } elseif($this->ua->get_carrier() === $this->ua->CARRIER_EZWEB()) { $this->template_dir = array('templates/e', 'templates/i', 'templates/v', 'templates/w', 'templates'); $this->compile_dir = 'templates_c/e'; } elseif($this->ua->get_carrier() === $this->ua->CARRIER_VODAFONE() && !$this->ua->is_3g()) { $this->template_dir = array('templates/v', 'templates/i', 'templates/e', 'templates/w', 'templates'); $this->compile_dir = 'templates_c/v'; } elseif($this->ua->get_carrier() === $this->ua->CARRIER_VODAFONE() && $this->ua->is_3g()) { $this->template_dir = array('templates/v3g', 'templates/v', 'templates/i', 'templates/e', 'templates/w', 'templates'); $this->compile_dir = 'templates_c/v3g'; } elseif($this->ua->get_carrier() === $this->ua->CARRIER_WILLCOM()) { $this->template_dir = array('templates/w', 'templates/i', 'templates/e', 'templates/v', 'templates'); $this->compile_dir = 'templates_c/w'; } } $this->plugins_dir = array('plugins', dirname(__FILE__).'/plugins'); $this->register_prefilter(array(&$this, '_prefilter')); $this->register_postfilter(array(&$this, '_postfilter')); $this->register_outputfilter(array(&$this, '_outputfilter')); register_shutdown_function(array(&$this, '_unSmarty')); } /** * デストラクタ * * @access public */ function _unSmarty() {} function display($template) { parent::display($template); } function _prefilter($tpl_source, &$smarty) { // SJIS系の場合はEUC-JPへ変換 $template_encoding = $this->get_template_encoding($smarty); if(preg_match('/^SJIS.*/', $template_encoding)) { return mb_convert_encoding($tpl_source, "EUC-JP", $template_encoding); } elseif($this->template_encoding == $this->internal_encoding) { return $tpl_source; } else { return mb_convert_encoding($tpl_source, $this->internal_encoding, $template_encoding); } } function _postfilter($tpl_source, &$smarty) { // SJISの場合はEUC-JPから出力エンコーディングへ変換する $template_encoding = $this->get_template_encoding($smarty); if(preg_match('/^SJIS.*/', $template_encoding)) { return mb_convert_encoding($tpl_source, $this->internal_encoding, "EUC-JP"); } else { return $tpl_source; } } function _outputfilter($tpl_output, &$smarty) { if(!is_array($this->output_encoding)) { $output_encoding = $this->output_encoding; } elseif(!array_key_exists($smarty->real_dir, $this->output_encoding)) { $output_encoding = $this->ua->get_encoding(); } else { $output_encoding = $this->output_encoding[$smarty->real_dir]; } if($output_encoding == $this->internal_encoding) { } else { $tpl_output = mb_convert_encoding($tpl_output, $output_encoding, $this->internal_encoding); } // 絵文字差替え if($this->ua->is_mobile()) { return $this->ua->emoji->replace(&$tpl_output); } else { return $tpl_output; } } /** * 内部エンコーディングと出力エンコーディングを考慮したデータ出力 * * @access private * @param Mixed $arg 出力データ */ function _echo($arg) { echo $arg; return; } /** * 内部エンコーディングを返す * * @access private * @return String 出力文字コード */ function get_internal_encoding() { return $this->internal_encoding; } /** * テンプレートエンコーディングを返す * * @access private * @return String 出力文字コード */ function get_template_encoding(&$smarty) { if(!is_array($this->template_encoding)) { return $this->template_encoding; } elseif(!array_key_exists($smarty->real_dir, $this->template_encoding)) { return $this->ua->get_encoding(); } else { return $this->template_encoding[$smarty->real_dir]; } } /** * 出力エンコーディングを返す * * @access private * @return String 出力文字コード */ function get_output_encoding() { if(!is_array($this->output_encoding)) { return $this->output_encoding; } elseif(!array_key_exists($this->real_dir, $this->output_encoding)) { return $this->ua->get_encoding(); } else { return $this->output_encoding[$this->real_dir]; } } /** * 出力文字コードを返す * * @access private * @return String 出力文字コード */ function get_html_charset() { if(!is_array($this->html_charset)) { return $this->html_charset; } elseif(!array_key_exists($this->real_dir, $this->html_charset)) { return ""; } else { return $this->html_charset[$this->real_dir]; } } } ?>