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

PVS

Super Moderator
Thành viên BQT
Tham gia
28/02/2015
Bài viết
16,728
Được Like
12,680
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

Dịch vụ XenForo của VNXF

Mr. Tuấn

Mobile/Zalo: 0988 488 096

Telegram: bluekpro

Email: [email protected]

Nhà Tài Trợ

Mút Xốp Không Gian
pallet Thịnh Phát
Top Bottom