MikeTrin
02-25-2012, 01:22 PM
There's a lot of info on changing a users theme if they are using a mobile browser. I'm looking to just change a few images and adsense code on various templates.
I have a taken some code out of init.php that vbulletin uses to detect various mobile browsers.
I'm trying to create a single global variable that I can use vb if condition on it from any template on any theme. I've seen the VB_Template::preRegister code that lets you push php variables to single templates but I need it go to any template.
So the question is, which hook and how do create a global variable that can be accessed from any template. I'ved attempted to use global $mobilemt as seen below in the global_bootstrap_init_start hook and {vb:raw mobilemt} in a template with no luck.
global $mobilemt
$mobilemt = "no";
if (stripos($_SERVER['HTTP_USER_AGENT'], 'windows') === false)
{
if (
preg_match('/(up.browser|up.link|mmp|symbian|smartphone|midp|wa p|phone|android)/i', strtolower($_SERVER['HTTP_USER_AGENT']))
OR
stripos($_SERVER['HTTP_ACCEPT'],'application/vnd.wap.xhtml+xml') !== false
OR
((isset($_SERVER['HTTP_X_WAP_PROFILE']) OR isset($_SERVER['HTTP_PROFILE'])))
OR
stripos($_SERVER['ALL_HTTP'],'OperaMini') !== false
)
{
$mobile_browser = true;
}
// This array is big and may be bigger later on. So we move it to a second if.
elseif (in_array(
strtolower(substr($_SERVER['HTTP_USER_AGENT'], 0, 4)),
array(
'w3c ','acs-','alav','alca','amoi','audi','avan','benq','bird' ,'blac',
'blaz','brew','cell','cldc','cmd-','dang','doco','eric','hipt','inno',
'ipaq','java','jigs','kddi','keji','leno','lg-c','lg-d','lg-g','lge-',
'maui','maxo','midp','mits','mmef','mobi','mot-','moto','mwbp','nec-',
'newt','noki','oper','palm','pana','pant','phil',' play','port','prox',
'qwap','sage','sams','sany','sch-','sec-','send','seri','sgh-','shar',
'sie-','siem','smal','smar','sony','sph-','symb','t-mo','teli','tim-',
'tosh','tsm-','upg1','upsi','vk-v','voda','wap-','wapa','wapi','wapp',
'wapr','webc','winw','winw','xda ','xda-')
)
)
{
$mobile_browser = true;
}
}
if (
$mobile_browser
AND
preg_match('/(ipad|ipod|iphone|blackberry|android|pre\/|palm os|palm|hiptop|avantgo|plucker|xiino|blazer|elaine )/i', strtolower($_SERVER['HTTP_USER_AGENT']))
)
{
$mobile_browser_advanced = true;
}
if ($mobile_browser_advanced||$mobile_browser)
{
{
$mobilemt="yes";
}
}
I have a taken some code out of init.php that vbulletin uses to detect various mobile browsers.
I'm trying to create a single global variable that I can use vb if condition on it from any template on any theme. I've seen the VB_Template::preRegister code that lets you push php variables to single templates but I need it go to any template.
So the question is, which hook and how do create a global variable that can be accessed from any template. I'ved attempted to use global $mobilemt as seen below in the global_bootstrap_init_start hook and {vb:raw mobilemt} in a template with no luck.
global $mobilemt
$mobilemt = "no";
if (stripos($_SERVER['HTTP_USER_AGENT'], 'windows') === false)
{
if (
preg_match('/(up.browser|up.link|mmp|symbian|smartphone|midp|wa p|phone|android)/i', strtolower($_SERVER['HTTP_USER_AGENT']))
OR
stripos($_SERVER['HTTP_ACCEPT'],'application/vnd.wap.xhtml+xml') !== false
OR
((isset($_SERVER['HTTP_X_WAP_PROFILE']) OR isset($_SERVER['HTTP_PROFILE'])))
OR
stripos($_SERVER['ALL_HTTP'],'OperaMini') !== false
)
{
$mobile_browser = true;
}
// This array is big and may be bigger later on. So we move it to a second if.
elseif (in_array(
strtolower(substr($_SERVER['HTTP_USER_AGENT'], 0, 4)),
array(
'w3c ','acs-','alav','alca','amoi','audi','avan','benq','bird' ,'blac',
'blaz','brew','cell','cldc','cmd-','dang','doco','eric','hipt','inno',
'ipaq','java','jigs','kddi','keji','leno','lg-c','lg-d','lg-g','lge-',
'maui','maxo','midp','mits','mmef','mobi','mot-','moto','mwbp','nec-',
'newt','noki','oper','palm','pana','pant','phil',' play','port','prox',
'qwap','sage','sams','sany','sch-','sec-','send','seri','sgh-','shar',
'sie-','siem','smal','smar','sony','sph-','symb','t-mo','teli','tim-',
'tosh','tsm-','upg1','upsi','vk-v','voda','wap-','wapa','wapi','wapp',
'wapr','webc','winw','winw','xda ','xda-')
)
)
{
$mobile_browser = true;
}
}
if (
$mobile_browser
AND
preg_match('/(ipad|ipod|iphone|blackberry|android|pre\/|palm os|palm|hiptop|avantgo|plucker|xiino|blazer|elaine )/i', strtolower($_SERVER['HTTP_USER_AGENT']))
)
{
$mobile_browser_advanced = true;
}
if ($mobile_browser_advanced||$mobile_browser)
{
{
$mobilemt="yes";
}
}