<?php

/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */

/**
 * Maple - PHP Web Application Framework
 *
 * PHP versions 4 and 5
 *
 * LICENSE: This source file is subject to version 3.0 of the PHP license
 * that is available through the world-wide-web at the following URI:
 * http://www.php.net/license/3_0.txt.  If you did not receive a copy of
 * the PHP License and are unable to obtain it through the web, please
 * send a note to license@php.net so we can mail you a copy immediately.
 *
 * @package     Maple.filter
 * @author      netnee
 * @license     http://www.php.net/license/3_0.txt  PHP License 3.0
 */
require_once 'Net/UserAgent/Mobile.php';

/**
 * Mobileの実行準備および実行を行うFilter
 *
 * @package     Maple.filter
 * @author      TAKAHASHI Kunihiko <kunit@kunit.jp>
 * @copyright   2004-2006 The Maple Project
 * @license     http://www.php.net/license/3_0.txt  PHP License 3.0
 * @access      public
 * @since       3.0.0
 */
class Filter_Mobile extends Filter
{
    /**
     * コンストラクター
     *
     * @access  public
     * @since   3.0.0
     */
    function Filter_Mobile()
    {
        parent::Filter();
    }

    /**
     * Mobileの処理を実行
     *
     * @access  public
     * @since   3.0.0
     **/
    function execute()
    {
        $log =& LogFactory::getLog();
        $log->trace("Filter_Mobileの前処理が実行されました", "Filter_Mobile#execute");

        $container =& DIContainerFactory::getContainer();

        $f = false;
        if ($this->getSize() > 0) {
            $value = $this->getAttribute("mobile");
            if (isset($value)) {
                $mobile = &Net_UserAgent_Mobile::isMobile();
                if ($mobile) {
                    $f = true;
                }
            }
        }

        if ($f===true) {
            $log->trace("携帯 ", "Filter_Mobile#execute");

            $dirname = dirname($_SERVER['SCRIPT_NAME']);
            $dirname = ($dirname=="/") ? "" : $dirname;

            header("location: " . URL_ROOT . $dirname. "/?action=mobile_portal&".SID); 
            exit; 
        }


        $filterChain =& $container->getComponent("FilterChain");
        $filterChain->execute();

        $log->trace("Filter_Mobileの後処理が実行されました", "Filter_Mobile#execute");
    }
}
?>
