/**
  * モジュールの起動(シングルトン)
  *
  * @param  $name string 読み込むモジュール
  * @param  $type string OPTIONAL モジュールのタイプ(wp_attache_mobile|pear)
  * @param  $args mixed モジュールに渡す引数(PEAR のみ使用)
  */
 function &boot($name = null, $type = 'wp_attache_mobile', $args = null)
 {
     static $i = array();
     if (empty($name)) {
         $class = __CLASS__;
         $name = 'controller';
         $i[$name] = new $class();
     } elseif (!isset($i[$name])) {
         if ($type === 'wp_attache_mobile') {
             if (($path = realpath(dirname(__FILE__) . "/modules/{$name}.php")) === false) {
                 wp_attache_mobile::notice(sprintf(__('wp_attache_mobile: %s module not found.', 'wp_attache_mobile'), ucfirst($name)), 'error');
             } else {
                 include $path;
                 $class = "wp_attache_mobile_{$name}";
                 $i[$name] = new $class();
             }
         } elseif ($type === 'pear') {
             if (($path = realpath(sprintf("%s/%s.php", wp_attache_mobile_controller::pear_path(), str_replace('_', '/', $name)))) === false) {
                 wp_die(sprintf(__('wp_attache_mobile: %s PEAR library not found.', 'wp_attache_mobile'), $name));
                 wp_attache_mobile::notice(sprintf(__('wp_attache_mobile: %s PEAR library not found.', 'wp_attache_mobile'), $name), 'error');
             } else {
                 include $path;
                 if (method_exists($name, 'singleton')) {
                     $i[$name] =& call_user_func(array($name, 'singleton'), $args);
                 } else {
                     $i[$name] = new $name();
                 }
             }
         } else {
             wp_die(sprintf(__('wp_attache_mobile: %s is invalid module type.', 'wp_attache_mobile'), $type));
             wp_attache_mobile::notice(sprintf(__('wp_attache_mobile: %s is invalid module type.', 'wp_attache_mobile'), $type), 'error');
         }
     }
     return $i[$name];
 }
 /**
  * スニッフィング
  * 
  * @see wp-includes/template-loader.php
  */
 function sniffing($template)
 {
     $ua =& wp_attache_mobile_controller::boot('ua');
     if ($ua->_isMobile === true) {
         $theme = get_template();
         $themeRoots = get_theme_roots();
         $uaTemplate = str_replace('.php', ".{$ua->_ua}.php", $template);
         $mobileTemplate = str_replace('.php', ".{$ua->_agents['MOBILE']}.php", $template);
         if (file_exists($uaTemplate)) {
             $template = $uaTemplate;
         } elseif (file_exists($mobileTemplate)) {
             $template = $mobileTemplate;
         }
     }
     return $template;
 }
예제 #3
0
 /**
  * UA (とモバイルフラッグ)の判定
  */
 function set_ua()
 {
     $this->_agentMobile =& wp_attache_mobile_controller::boot('Net_UserAgent_Mobile', 'pear');
     if ($this->_agentMobile->isNonMobile()) {
         if (strpos($_SERVER['HTTP_USER_AGENT'], 'iPhone') !== false) {
             $this->_ua = $this->_agents['IPHONE'];
         } else {
             if (strpos($_SERVER['HTTP_USER_AGENT'], 'Android') !== false) {
                 $this->_ua = $this->_agents['ANDROID'];
             } else {
                 $this->_ua = $this->_agents['DEFAULT'];
             }
         }
     } else {
         $this->_ua = strtolower($this->_agentMobile->getCarrierLongName());
         $this->_isMobile = true;
     }
 }