Status
Not open for further replies.

semprot

Customer
If you use full page guest caching feature from vb optimise, you might need this plugin (or not).
When you use dartho's mobile lightweight style (like me), you might need this plugin.
If you do not use full page guest caching, you do not need this plugin.

This plugin will properly (at least in my board) redirect mobile guests to the mobile style, before vb optimise starts to cache mobile guests views.

First you can save this php file to your forum root (or any path it is fine), you can save it as "mobile_detect.php"
https://raw.github.com/serbanghita/Mobile-Detect/master/Mobile_Detect.php

Next, go to admincp > add new plugin

Hook Location : global_bootstrap_complete
Title : anything you want
Execution order : 0

PHP Code :
PHP:
require_once(DIR.'/x_kitchen/mobile_detect.php');

$mobile_style_id = 4;

$detect = new Mobile_Detect();

if ($detect->isMobile()) {
	$user_style_id = 0;

	if (defined('STYLE_ID')) {
		$user_style_id = STYLE_ID;
	}
	
	$cookie_prefix = '';
	if (defined('COOKIE_PREFIX')) {
		$cookie_prefix = COOKIE_PREFIX;
	}

	$_style_cookie = false;
	if (isset($_COOKIE[$cookie_prefix . 'userstyleid'])) {
		$_style_cookie = intval($_COOKIE[$cookie_prefix . 'userstyleid']);
	}

	if (isset($_GET['styleid'])) {
		$user_style_id = intval($_GET['styleid']);
	} else if (false !== $_style_cookie) {
		$user_style_id = $_style_cookie;
	}

	if (isset($_GET['x_mob_test'])) {
		var_dump($detect->isMobile(), $mobile_style_id, $user_style_id, $_style_cookie);
	}

	$redirect = false;

	if (false === $_style_cookie) {
		$redirect = true;
	} else if ($mobile_style_id != $user_style_id) {
		$redirect = true;
	}

	if (isset($_GET['x_mob_test'])) {
		var_dump($detect->isMobile(), $redirect, $mobile_style_id, $user_style_id, $_style_cookie);
	}

	if ($redirect) {
		header('Location: http://'.$_SERVER['SERVER_NAME'].'/forum.php?styleid='.$mobile_style_id.'&hook=1');
		exit();
	}
}

Next, hit save. Everything should work properly now :D

Note: maybe dbt staff can sticky this thread for other dbt customers :)
 
Last edited:
thank you, however i have a question, on my first visit as guest using mobile user agent (empty cookies & cache), i get desktop vboptimise cached page (i checked the html source code and there is "generated by vb optimise" comment).

But when i refreshed the second time using mobile user agent, the plugin above works and i am redirected to the mobile style, and i get mobile vboptimise cached page.

i have moved the hook location of my plugin to "global_bootstrap_init_start", it should be executed before "global_bootstrap_complete" & "global_complete" that vboptimise uses. any idea why?

and maybe if my code has a flaw you can fix it and include it on vboptimise? :)
 
I couldn't say, it looks fine at a glance. When I have time, I'll look into implementing this into vBO if the license for the MobileDetect class allows for it to be included in commercial projects.
 
Status
Not open for further replies.
Back
Top