diff --git a/classes/context/Context.class.php b/classes/context/Context.class.php index 0adb2add5..49718f480 100644 --- a/classes/context/Context.class.php +++ b/classes/context/Context.class.php @@ -593,7 +593,7 @@ class Context $db_info->sitelock_whitelist = count($config['lock']['allow']) ? $config['lock']['allow'] : array('127.0.0.1'); $db_info->embed_white_iframe = $config['mediafilter']['iframe'] ?: $config['embedfilter']['iframe']; $db_info->embed_white_object = $config['mediafilter']['object'] ?: $config['embedfilter']['object']; - $db_info->use_mobile_view = $config['use_mobile_view'] ? 'Y' : 'N'; + $db_info->use_mobile_view = (isset($config['mobile']['enabled']) ? $config['mobile']['enabled'] : $config['use_mobile_view']) ? 'Y' : 'N'; $db_info->use_prepared_statements = $config['use_prepared_statements'] ? 'Y' : 'N'; $db_info->use_rewrite = $config['use_rewrite'] ? 'Y' : 'N'; $db_info->use_sso = $config['use_sso'] ? 'Y' : 'N'; diff --git a/classes/mobile/Mobile.class.php b/classes/mobile/Mobile.class.php index 65b4276e3..5eb750c24 100644 --- a/classes/mobile/Mobile.class.php +++ b/classes/mobile/Mobile.class.php @@ -12,113 +12,74 @@ class Mobile * Whether mobile or not mobile mode * @var bool */ - public $ismobile = NULL; - + protected static $_ismobile = null; + /** - * Get instance of Mobile class(for singleton) - * + * Get instance of Mobile class + * * @return Mobile */ public function getInstance() { - static $theInstance; - if(!isset($theInstance)) - { - $theInstance = new Mobile(); - } - return $theInstance; + return new self(); } - + /** * Get current mobile mode - * - * @return bool If mobile mode returns true or false + * + * @return bool */ public static function isFromMobilePhone() { - return self::getInstance()->_isFromMobilePhone(); + // Return cached result. + if (self::$_ismobile !== null) + { + return self::$_ismobile; + } + + // Not mobile if disabled explicitly. + if (!self::isMobileEnabled() || Context::get('full_browse') || $_COOKIE["FullBrowse"]) + { + return self::$_ismobile = false; + } + + // Try to detect from URL arguments and cookies, and finally fall back to user-agent detection. + $m = Context::get('m'); + $cookie = (isset($_COOKIE['mobile']) && $_SESSION['user_agent'] === md5($_SERVER['HTTP_USER_AGENT'])) ? $_COOKIE['mobile'] : null; + if ($m === '1' || $cookie === 'true') + { + self::$_ismobile = TRUE; + } + elseif ($m === '0' || $cookie === 'false') + { + self::$_ismobile = FALSE; + } + else + { + self::$_ismobile = Rhymix\Framework\UA::isMobile() && (config('mobile.tablets') || !Rhymix\Framework\UA::isTablet()); + } + + // Set cookie to prevent recalculation. + if (!$cookie) + { + $_SESSION['user_agent'] = md5($_SERVER['HTTP_USER_AGENT']); + $_COOKIE['mobile'] = self::$_ismobile ? 'true' : 'false'; + setcookie('mobile', $_COOKIE['mobile'], 0, RX_BASEURL); + } + + return self::$_ismobile; } - + /** * Get current mobile mode * * @return bool */ - public function _isFromMobilePhone() + public static function _isFromMobilePhone() { - if($this->ismobile !== NULL) - { - return $this->ismobile; - } - if(!config('use_mobile_view') || Context::get('full_browse') || $_COOKIE["FullBrowse"]) - { - return $this->ismobile = false; - } - - $this->ismobile = FALSE; - - $m = Context::get('m'); - if(strlen($m) == 1) - { - if($m == "1") - { - $this->ismobile = TRUE; - } - elseif($m == "0") - { - $this->ismobile = FALSE; - } - } - elseif(isset($_COOKIE['mobile'])) - { - if($_COOKIE['user-agent'] == md5($_SERVER['HTTP_USER_AGENT'])) - { - if($_COOKIE['mobile'] == 'true') - { - $this->ismobile = TRUE; - } - else - { - $this->ismobile = FALSE; - } - } - else - { - setcookie("mobile", FALSE, 0, RX_BASEURL); - setcookie("user-agent", FALSE, 0, RX_BASEURL); - $this->ismobile = Rhymix\Framework\UA::isMobile() && !Rhymix\Framework\UA::isTablet(); - } - } - else - { - $this->ismobile = Rhymix\Framework\UA::isMobile() && !Rhymix\Framework\UA::isTablet(); - } - - if($this->ismobile !== NULL) - { - if($this->ismobile == TRUE) - { - if($_COOKIE['mobile'] != 'true') - { - $_COOKIE['mobile'] = 'true'; - setcookie("mobile", 'true', 0, RX_BASEURL); - } - } - elseif(isset($_COOKIE['mobile']) && $_COOKIE['mobile'] != 'false') - { - $_COOKIE['mobile'] = 'false'; - setcookie("mobile", 'false', 0, RX_BASEURL); - } - - if(isset($_COOKIE['mobile']) && $_COOKIE['user-agent'] != md5($_SERVER['HTTP_USER_AGENT'])) - { - setcookie("user-agent", md5($_SERVER['HTTP_USER_AGENT']), 0, RX_BASEURL); - } - } - - return $this->ismobile; + return self::isFromMobilePhone(); } - + /** * Detect mobile device by user agent * @@ -138,7 +99,7 @@ class Mobile { return Rhymix\Framework\UA::isTablet(); } - + /** * Set mobile mode * @@ -147,11 +108,21 @@ class Mobile */ public static function setMobile($ismobile) { - self::getInstance()->ismobile = (bool)$ismobile; + self::$_ismobile = (bool)$ismobile; } + /** + * Check if mobile view is enabled + * + * @raturn bool + */ public static function isMobileEnabled() { - return config('use_mobile_view'); + $mobile_enabled = config('mobile.enabled'); + if ($mobile_enabled === null) + { + $mobile_enabled = config('use_mobile_view') ? true : false; + } + return $mobile_enabled; } } diff --git a/common/defaults/config.php b/common/defaults/config.php index d01ac2f4f..ac92e84d7 100644 --- a/common/defaults/config.php +++ b/common/defaults/config.php @@ -111,7 +111,10 @@ return array( 'iframe' => array(), 'object' => array(), ), - 'use_mobile_view' => true, + 'mobile' => array( + 'enabled' => true, + 'tablets' => false, + ), 'use_prepared_statements' => true, 'use_rewrite' => true, 'use_sso' => false, diff --git a/common/framework/parsers/configparser.php b/common/framework/parsers/configparser.php index c8bff4e49..aa4501d9e 100644 --- a/common/framework/parsers/configparser.php +++ b/common/framework/parsers/configparser.php @@ -242,7 +242,7 @@ class ConfigParser } // Convert miscellaneous configuration. - $config['use_mobile_view'] = $db_info->use_mobile_view === 'N' ? false : true; + $config['mobile']['enabled'] = $db_info->use_mobile_view === 'N' ? false : true; $config['use_prepared_statements'] = $db_info->use_prepared_statements === 'Y' ? true : false; $config['use_rewrite'] = $db_info->use_rewrite === 'Y' ? true : false; $config['use_sso'] = $db_info->use_sso === 'Y' ? true : false; diff --git a/modules/admin/admin.admin.controller.php b/modules/admin/admin.admin.controller.php index ce0d1a4f1..595662f38 100644 --- a/modules/admin/admin.admin.controller.php +++ b/modules/admin/admin.admin.controller.php @@ -536,7 +536,12 @@ class adminAdminController extends admin Rhymix\Framework\Config::set('locale.default_timezone', $vars->default_timezone); // Mobile view - Rhymix\Framework\Config::set('use_mobile_view', $vars->use_mobile_view === 'Y'); + Rhymix\Framework\Config::set('mobile.enabled', $vars->use_mobile_view === 'Y'); + Rhymix\Framework\Config::set('mobile.tablets', $vars->tablets_as_mobile === 'Y'); + if (Rhymix\Framework\Config::get('use_mobile_view') !== null) + { + Rhymix\Framework\Config::set('use_mobile_view', $vars->use_mobile_view === 'Y'); + } // Favicon and mobicon $this->_saveFavicon('favicon.ico', $vars->is_delete_favicon); diff --git a/modules/admin/admin.admin.view.php b/modules/admin/admin.admin.view.php index d39096b9c..cbcc8d196 100644 --- a/modules/admin/admin.admin.view.php +++ b/modules/admin/admin.admin.view.php @@ -430,7 +430,8 @@ class adminAdminView extends admin Context::set('selected_timezone', Rhymix\Framework\Config::get('locale.default_timezone')); // Mobile view - Context::set('use_mobile_view', config('use_mobile_view') ? 'Y' : 'N'); + Context::set('use_mobile_view', (config('mobile.enabled') !== null ? config('mobile.enabled') : config('use_mobile_view')) ? true : false); + Context::set('tablets_as_mobile', config('mobile.tablets') ? true : false); // Favicon and mobicon and site default image $oAdminModel = getAdminModel('admin'); @@ -527,7 +528,6 @@ class adminAdminView extends admin Context::set('thumbnail_type', $config->thumbnail_type ?: 'crop'); // Other settings - Context::set('use_mobile_view', Rhymix\Framework\Config::get('use_mobile_view')); Context::set('use_rewrite', Rhymix\Framework\Config::get('use_rewrite')); Context::set('use_sso', Rhymix\Framework\Config::get('use_sso')); Context::set('delay_session', Rhymix\Framework\Config::get('session.delay')); diff --git a/modules/admin/lang/en.php b/modules/admin/lang/en.php index 85c7df284..2b42c904f 100644 --- a/modules/admin/lang/en.php +++ b/modules/admin/lang/en.php @@ -17,7 +17,7 @@ $lang->admin_info = 'Administrator Info'; $lang->admin_index = 'Index Admin Page'; $lang->control_panel = 'Dashboard'; $lang->site_title = 'Site Title'; -$lang->site_title = 'Site Subtitle'; +$lang->site_subtitle = 'Site Subtitle'; $lang->start_module = 'Homepage'; $lang->select_site = 'Site'; $lang->select_module_type = 'Module Type'; @@ -168,8 +168,9 @@ $lang->status = 'Status'; $lang->action = 'Execute'; $lang->use_rewrite = 'Use Rewrite Mode'; $lang->timezone = 'Time Zone'; -$lang->use_mobile_view = 'Enable Mobile Page'; +$lang->use_mobile_view = 'Enable Mobile View'; $lang->about_use_mobile_view = 'Show mobile page when visitors access with mobile devices.'; +$lang->tablets_as_mobile = 'Treat Tablets as Mobile'; $lang->thumbnail_type = 'Select thumbnail type.'; $lang->input_footer_script = 'Footer script'; $lang->detail_input_footer_script = 'The script is inserted into the bottom of body. It does not work at admin page.'; diff --git a/modules/admin/lang/ko.php b/modules/admin/lang/ko.php index c18857d87..b0a0a8edd 100644 --- a/modules/admin/lang/ko.php +++ b/modules/admin/lang/ko.php @@ -173,6 +173,7 @@ $lang->use_rewrite = '짧은 주소 사용'; $lang->timezone = '표준 시간대'; $lang->use_mobile_view = '모바일 뷰 사용'; $lang->about_use_mobile_view = '모바일 기기로 접속시 모바일 페이지를 보여줍니다.'; +$lang->tablets_as_mobile = '태블릿도 모바일 취급'; $lang->thumbnail_type = '썸네일 생성 방식'; $lang->input_footer_script = '하단(footer) 스크립트'; $lang->detail_input_footer_script = '최하단에 코드를 삽입합니다. 관리자 페이지에서는 수행되지 않습니다.'; diff --git a/modules/admin/tpl/config_general.html b/modules/admin/tpl/config_general.html index a865bd9d2..c1b13022b 100644 --- a/modules/admin/tpl/config_general.html +++ b/modules/admin/tpl/config_general.html @@ -78,11 +78,24 @@