Mobile / Browser Detection in Template

xF2 Unmaintained Mobile / Browser Detection in Template 1

No permission to download
Q: Why use this template syntax instead of a CSS media query?
A: That is a 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, a mobile phone is not detected as mobile)
A: Try a 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: I still want to use this addon 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 should choose, whether you want to enable guest page caching for mobile / non mobile.
    If most of your guests are mobile, then you should enable guest page caching for mobile.
    And vice versa.
  2. You create a PHP file, named guest_page_caching_mobile_detect.php in your /src/
    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 (#261):
    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. :)