Question Guest Page Cache + Mobile Detection

Status
Not open for further replies.

PurseBlog

Customer
Hi!

As part of a mobile theme I have some logic in plugin form that determines whether a user comes from a mobile device and then shows the mobile theme (instead of the desktop version).

Code:
if (!$vbulletin->options['forumops_mobile_groups'] or 
    is_member_of($vbulletin->userinfo, explode(',', $vbulletin->options['forumops_mobile_groups']))
) {
    if ($show['forumops_mobile'] !== true) {
        if (reset(explode('.', str_replace('www.', '', $_SERVER['SERVER_NAME']))) == 'm') {
            $show['forumops_mobile'] = true;
        }
        
        /**
        * @link http://stackoverflow.com/questions/6636306/mobile-browser-detection/6643934#6643934
        */
        if ($show['mobile_device'] = preg_match(
             '#\b(ip(hone|od)|android\b.+\bmobile|opera m(ob|in)i|windows (phone|ce)|blackberry'.
                 '|s(ymbian|eries60|amsung)|p(alm|rofile/midp|laystation portable)|nokia|fennec|htc[\-_]'.
                 '|up\.browser|[1-4][0-9]{2}x[1-4][0-9]{2})\b#i', 
        
            $_SERVER['HTTP_USER_AGENT']
        )) {
            $show['forumops_mobile'] = true;
        }
        
        $forceDesktop = !empty($_GET['forceDesktop']) || !empty($_COOKIE['tpf-bypass']);
        
        if ($forceDesktop) {
            $show['forumops_mobile'] = false;
        }
        
        $forceMobile = !empty($_GET['forceMobile']) || !empty($_COOKIE['tpf-mobile']);
        if ($forceMobile) {
            $show['forumops_mobile'] = true;
        }

    }
    
    if ($show['forumops_mobile']) {
        $styleid    = $vbulletin->options['forumops_mobile_styleid'];
        $userselect = true;
    }
}

if ($show['forumops_mobile'] !== true) {
    $show['forumops_mobile'] = false;
}

Hook location is style_fetch. When I enable guest full page caching, this logic no longer works. Which hook location do I place this plugin code in so that it triggers before the page cache?

Thanks!
 
The guest cache runs on global_bootstrap_complete on execution order 1. I'm not sure if your logic would still work if it was shifted to that location, however.
 
Status
Not open for further replies.

Legacy vB Optimise

vBulletin 3.8.x vBulletin 4.x.x
Seller
DragonByte Technologies
Release date
Last update
Total downloads
1,972
Customer rating
0.00 star(s) 0 ratings
Back
Top