Yii 1.1: ktai

Library for ktai(mobile phone in Japanese) web site
5 followers

This library provides emoji filter, ktai controller, mobile auth filter and so on. It may help your ktai web site.

Documentation

Requirements

  • Yii 1.1 or above
  • net_IPv4
  • html_css

Installation

  • pear install HTML_CSS
  • pear install Net_IPv4
  • Extract the release file under protected/
  • Copy or symlink image files under /images/emoji
  • I recommend copying net_IPv4 and html_css under venders/ directory.

Usage

  • .htaccess
php_value mb_language "Japanese"
php_value mbstring.detect_order "auto"
php_value mbstring.http_input "pass"
php_value mbstring.http_output "pass"
php_value mbstring.internal_encoding "UTF-8"
php_value mbstring.script_encoding "UTF-8"
php_value mb_regex_encoding "UTF-8"
  • controller

All filters depend on CHybridController, so you have to extends from CHybridController.

<?php
class MobileController extends CHybridController 
{
  public function filters()  {
    return array(
      array(
        'application.filters.ktai.AuthFilter',
        'docomoOfficial'=>true, // if your site is KOSHIKI SAITO
        'nonSupportBrowser'=>array(
          '/^DoCoMo\/1\.0(.*)$/',
          '/^J\-PHONE\/(.*)$/',
          '/^UP\.Browser\/(.*)$/',
          ),  
        'redirectForNonSupport'=>array('mobile/nonsupport'),
        'denyPcBrowser'=>true,
        'denyUnknownIP'=>true,
        'redirectForPcBrowser'=>array('pc/index'),
      ),  
      ),  
      'accessControl',
      array(
        'application.filters.ktai.CssFilter',
        'baseDir'=>Yii::app()->getBasePath().'/../',
        ),
      array(
        'application.filters.ktai.EmojiFilter',
      ),  
    );  
  }
  • Directory Tree

HybridController overwites the render function to alternate view files for each carrier.

css/
  mobile/
    docomo.css // for CssFilter
protected/
  controllers/
    NormalController.php
    MobileController.php
  views/
    mobile/
      index.php // default view file
      docomo/index.php // view file for docomo if it exists
      au/index.php
      softbank/index.php
    normal/
      index.php
    email/
      hoge.php
        mobile/
          hoge.php // mobile mail template if it exists
  • view file

if you want to show emoji in your view file, see EX below.

[i:20] // docomo emoji
[s:20] // softbank emoji
[e:20] // au emoji
[*:tel] // DENWA icon for all carrier
[*:fine] // HARE icon for all carrier

if you see your site in different carrier, [i:20] will be converted into img tag

  • css compatible

This library uses HTML_CSS_Mobile, so you don't need to worry about class attribute for docomo template.

See detail: http://coderepos.org/share/browser/lang/php/HTML_CSS_Mobile/

docomo.css

.hoge {
 font-size:x-small;
}

hoge.php(view file)

&lt;div class="hoge"&gt;fuga&lt;/div&gt;

CssFilter automatically convert your css into style attribute. As a rsult, view file will be like this.

&lt;div class="hoge" style="font-size:x-small"&gt;fuga&lt;/div&gt;

When you see your site with other browser, CssFilter doesn't work.

  • mail

Use the mail library if you want to send mail for both pc and mobile.

config/main.php

:
:
    'mailer' => array(
      'class'=>'application.extensions.mailer.EMailer',
      'pathViews'=>'application.views.email',
      'pathLayouts'=>'application.views.email.layouts',
      'lang'=>'japanese',
      'internalEnc'=>'UTF-8',
      'CharSet'=>'iso-2022-jp',
      'Encoding'=>'7bit',
      'FromName'=>'',
    ), 
:
:
   'params'=>array(
      'mobileDomain'=>array(
         1=>'docomo.ne.jp',
            'ezweb.ne.jp',
            'softbank.ne.jp',
            'disney.ne.jp',
            't.vodafone.ne.jp',
            'd.vodafone.ne.jp',
            'h.vodafone.ne.jp',
            'c.vodafone.ne.jp',
            'k.vodafone.ne.jp',
            'r.vodafone.ne.jp',
            'n.vodafone.ne.jp',
            's.vodafone.ne.jp',
            'q.vodafone.ne.jp',
      ),
    ),
  • Send email
Yii::app()->mailer->From=xxxxxx@softbank.ne.jp; 
Yii::app()->mailer->AddAddress(xxxxx@softbank.ne.jp);
Yii::app()->mailer->Subject='日本語OK'; 
Yii::app()->mailer->getView('hoge'))
Yii::app()->mailer->Send();

In this case, if the email address contains a domain which is listed in the main.php, this mailer will use mobile template (views/email/mobile/hoge.php). If it doesn't exist, view/email/hoge.php will be used instead.

  • input tag for mobile

input tag is chaotic because each carrier has their own format, but CMhtml class may help you.

echo CMhtml::activeTextField($model, "user", array('size'=>'20','class'=>'sfont'),'alphabet');
 
// It is almost same as CHtml. I just add one more argument.
// 4th argument should be
//  * hiragana
//  * hankakukana
//  * alphabet
//  * numeric

Change Log

February 15, 2012

  • Re-factoring the entire structure

November 23, 2010

  • Use UTF-8 for softbank

February 22, 2010

  • HTML helper for mobile input fields

February 20, 2010 (2nd)

  • add mailer.
  • good-bye useragent_mobile.
  • bug fix.

February 20, 2010

  • css filter support for docomo template
  • add useful emoji function

February 17, 2010

  • Output filter for docomo, supporting both uid=NULLGWDOCOMO and guid=on.

February 16, 2010

  • ktai controller and Auth filter are added.

February 2, 2009

  • Initial release.

Total 2 comments

#6956 report it
junamai2000 at 2012/02/15 09:07pm
RE: POST/GETパラメータに日本語が存在する場合に発生する問題の対処方法

御報告ありがとうございました。

私自身このextention使っているのですが、かなり構造を変えていて、こちらのファイルを全く更新していませんでした。 とりあえず、私が使っているバージョンと揃えるために0.9としてアップデートしました。

リポジトリはこちらで公開しております。 https://github.com/junamai2000/ktai

よろしくお願いいたします。

#6941 report it
rizme at 2012/02/15 03:04am
POST/GETパラメータに日本語が存在する場合に発生する問題の対処方法

ktai-0.8において、POST/GETパラメータに日本語が含まれていると、 Undefined variable: filterChain というPHPのエラーが発生すると思います。

以下のようにソースを修正することで、対処可能です。

#filters/ktai/EmojiFilter.php
*** 14,15 ***
-array_walk_recursive($_POST, array('EmojiFilter', 'convert'));
+array_walk_recursive($_POST, array('EmojiFilter', 'convert'),
+    array('filterChain'=>$filterChain));
-array_walk_recursive($_GET, array('EmojiFilter', 'convert'));
+array_walk_recursive($_GET, array('EmojiFilter', 'convert'),
+    array('filterChain'=>$filterChain));

*** 31 ***
-static function convert(&$val, $key)
+static function convert(&$val, $key, $userData)

*** 35 ***
-if (!$filterChain->controller->isSoftbank) {
+if (!$userData['filterChain']->controller->isSoftbank) {

Leave a comment

Please to leave your comment.

Create extension