Mobile / Browser Detection in Template

Unmaintained Mobile / Browser Detection in Template 1

No permission to download
Q : Why use this template syntax instead of CSS media query ?
A : That is personal preference. But personally i think hiding content with CSS is not "100% proper", because the browser still loads the HTML code. And it depends on your case too.

Q : Why mobile detection result is wrong ? (for example mobile phone is not detected as mobile)
A : Try live demo of the library that i use here : http://demo.mobiledetect.net/
If the result there is wrong, then their user agent database is incorrect / outdated.

Q : How to uninstall this addon?
A : Please remove all custom function of this addon (such as cutemb_is_mobile) in your templates before uninstalling.

Q : I still want to use this add on with guest page caching enabled, and i only use cutemb_is_mobile() and i don't use other functions such as cutemb_is_chrome().
A : The answer is quite long :
  1. You create a PHP file, named guest_page_caching_mobile_detect.php in your /src/
  2. Open this https://raw.githubusercontent.com/serbanghita/Mobile-Detect/master/Mobile_Detect.php
    Copy and paste the content into your guest_page_caching_mobile_detect.php
  3. Find Line #25
    PHP:
    class Mobile_Detect

    Change into
    PHP:
    class Guest_Page_Caching_Mobile_Detect
  4. Backup your config.php to your local computer.
  5. Open your config.php file and add these lines (line position doesn't matter)
    PHP:
    require_once('guest_page_caching_mobile_detect.php');
    $_detect = new Guest_Page_Caching_Mobile_Detect();
    define('MY_IS_MOBILE', intval($_detect->isMobile()));
  6. Open /xrc/XF/PageCache.php, backup a copy to your local computer.
  7. Find this line (#264) :
    PHP:
    return 'page_' . sha1($uri) . '_' . strlen($uri) . "_s{$styleId}_l{$languageId}_v" . self::CACHE_VERSION;
  8. Change into :
    PHP:
    return 'page_' . sha1($uri) . '_' . strlen($uri) . "_s{$styleId}_l{$languageId}_v" . self::CACHE_VERSION.'_m'.constant('MY_IS_MOBILE');
  9. Save.
  10. Now guest page caching should work in both mobile & non-mobile. :)
Top Bottom