Addon 2x Browser Detection - Phát hiện trình duyệt cho XenForo 2 2.1.1

PVS

Generalissimo
Thành viên BQT
Browser Detection - Phát hiện trình duyệt cho XenForo 2 2.1.1

Một shim light-weight xung quanh Mobile_detect cho XenForo 2

Cách sử dụng (trong template)

Add-on tiêm biến toàn cục $mobileDetect, kiểm tra xem biến đó có được đặt trước khi gọi bất kỳ phương thức nào để ngăn lỗi trong quá trình nâng cấp hoặc nếu add-on bị tắt.

HTML:
<xf:if is="$xf.mobileDetect && $xf.mobileDetect.isMobile()">
    Is Mobile
<xf:else />
    Not Mobile
</xf:if>

HTML:
<xf:if is="$xf.mobileDetect && $xf.mobileDetect.is('Firefox')">
    Is Firefox
<xf:else />
    Not Firefox
</xf:if>

HTML:
<xf:if is="$xf.mobileDetect && $xf.mobileDetect.is('Chrome')">
    Is Chrome
<xf:else />
    Not Chrome
</xf:if>

Cách sử dụng (bằng php)
PHP:
$mobileDetect = \SV\BrowserDetection\Listener::getMobileDetection();
$isMobile = $mobileDetect && $mobileDetect->isMobile() ? "_m1" : "_m0";

Bộ nhớ đệm trang XF2.1
Phát hiện di động tích hợp với bộ nhớ đệm toàn trang XF2.1 +, thêm vào config.php đoạn code sau;
PHP:
$config['pageCache']['onSetup'] = function (\XF\PageCache $pageCache) {
    $pageCache->setCacheIdGenerator(function(\XF\Http\Request $request) {
        return \SV\BrowserDetection\CacheHelper::getPageCacheId($request);
    });
};

Chúc các bạn thành công.


Nguồn: xenforo.com​
 

Đính kèm

  • addon-Xon-BrowserDetection-2.1.1.zip
    43.1 KB · Lượt xem: 6

Hướng dẫn sử dụng

XenForo 1 XenForo 2
Translate by PVS

Hỗ trợ trực tuyến

Support Quảng cáo
Mr. San (PVS)

Skype chat, instant message

Mr. Tuấn (Blue)

Skype chat, instant message

Mr. Tuấn
0988 488 096
Mr. Trọng
0906 081 284
kinhdoanh@vnxf.vn

Nhà Tài Trợ

Mút Xốp Không Gian
pallet Thịnh Phát
Điện Lạnh Thịnh Phát
Top