mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-04 01:01:41 +09:00
Allow tablets to be treated as mobile or not depending on configuration
This commit is contained in:
parent
e8d4c1f27f
commit
ad8a07096c
9 changed files with 94 additions and 101 deletions
|
|
@ -587,7 +587,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';
|
||||
|
|
|
|||
|
|
@ -12,113 +12,73 @@ 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']) ? $_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)
|
||||
{
|
||||
$_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 +98,7 @@ class Mobile
|
|||
{
|
||||
return Rhymix\Framework\UA::isTablet();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set mobile mode
|
||||
*
|
||||
|
|
@ -147,11 +107,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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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'));
|
||||
|
|
|
|||
|
|
@ -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.';
|
||||
|
|
|
|||
|
|
@ -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 = '최하단에 코드를 삽입합니다. 관리자 페이지에서는 수행되지 않습니다.';
|
||||
|
|
|
|||
|
|
@ -78,11 +78,24 @@
|
|||
<label class="x_control-label">{$lang->use_mobile_view}</label>
|
||||
<div class="x_controls">
|
||||
<label for="use_mobile_view_y" class="x_inline">
|
||||
<input type="radio" name="use_mobile_view" id="use_mobile_view_y" value="Y" checked="checked"|cond="$use_mobile_view == 'Y'" />
|
||||
<input type="radio" name="use_mobile_view" id="use_mobile_view_y" value="Y" checked="checked"|cond="$use_mobile_view" />
|
||||
{$lang->cmd_yes}
|
||||
</label>
|
||||
<label for="use_mobile_view_n" class="x_inline">
|
||||
<input type="radio" name="use_mobile_view" id="use_mobile_view_n" value="N" checked="checked"|cond="$use_mobile_view != 'Y'" />
|
||||
<input type="radio" name="use_mobile_view" id="use_mobile_view_n" value="N" checked="checked"|cond="!$use_mobile_view" />
|
||||
{$lang->cmd_no}
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="x_control-group">
|
||||
<label class="x_control-label">{$lang->tablets_as_mobile}</label>
|
||||
<div class="x_controls">
|
||||
<label for="tablets_as_mobile_y" class="x_inline">
|
||||
<input type="radio" name="tablets_as_mobile" id="tablets_as_mobile_y" value="Y" checked="checked"|cond="$tablets_as_mobile" />
|
||||
{$lang->cmd_yes}
|
||||
</label>
|
||||
<label for="tablets_as_mobile_n" class="x_inline">
|
||||
<input type="radio" name="tablets_as_mobile" id="tablets_as_mobile_n" value="N" checked="checked"|cond="!$tablets_as_mobile" />
|
||||
{$lang->cmd_no}
|
||||
</label>
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue