Resource icon

Browser Detection 2.3.1

No permission to download
If I don't have page caching enabled, Do I have to enable it in order to add these lines to config.php?
PHP:
$config['pageCache']['onSetup'] = function (\XF\PageCache $pageCache) {

    $pageCache->setCacheIdGenerator(function(\XF\Http\Request $request) {

        return \SV\BrowserDetection\CacheHelper::getPageCacheId($request);

    });

};

I only have these memecach cache settings in my config.php
Code:
$config['cache']['enabled'] = true;
$config['cache']['provider'] = 'Memcached';
$config['cache']['config'] = [
    'server' => '127.0.0.1'
];

$config['cache']['sessions'] = true;
 
You will only need those extra lines if you have pagecaching enabled.
Something like:
Code:
$config['pageCache']['enabled'] = true;
$config['pageCache']['onSetup'] = function (\XF\PageCache $pageCache) {
    $pageCache->setCacheIdGenerator(function(\XF\Http\Request $request) {
        return \SV\BrowserDetection\CacheHelper::getPageCacheId($request);
    });
};
$config['cache']['context']['page']['provider'] = 'Redis';
$config['cache']['context']['page']['config'] = [
        'host' => '127.0.0.1',
        'port' => 6379
        ];

...but I like your question, because I have recently turned on pagecaching and totally forgot about this extra piece of code!
 
If I don't have page caching enabled, Do I have to enable it in order to add these lines to config.php?
Nope, that is only required if you are using page cache and need to cache output for mobile vs desktop clients
 
If I'm using this add-on only because it is a requirement for Elastic Search Essentials add-on and I have pagecache on.
Do I need those extra lines in config.php?
 
If you are using page cache, I'ld recommend it. Elasticsearch Essentials add-on does vary HTML based on if the user is mobile/desktop.
 
Something like this should work;
PHP:
$xf.mobileDetect && $xf.mobileDetect.isMobile()
I appreciate your help, Xon. I did try that after installing the addon - but it doesn't appear to do anything.

1644973804212.webp

I've tried with, and without both parts just in case I've misunderstood. Example -

$xf.mobileDetect && $xf.mobileDetect.isMobile()
$xf.mobileDetect
$xf.mobileDetect.isMobile()

I appreciate your time.
 
The 'isMobile' check is based on user-agent, how are you testing it?
Via dev tools on Google Chrome. I emulated an iPhone XR and a few others. I assumed as you can't edit them, they contain the appropriate user-agent strings.
 
@Xon any idea why the following conditional triggers this error?
Code:
<xf:if is="$xf.mobileDetect && $xf.mobileDetect.isMobile() || $xf.mobileDetect.is-tablet()">

  • ErrorException: Template error: [E_USER_WARNING] Cannot call method is-tablet on a non-object (NULL)
  • src/XF/Template/Templater.php:1176
 
@Xon any idea why the following conditional triggers this error?
Code:
<xf:if is="$xf.mobileDetect && $xf.mobileDetect.isMobile() || $xf.mobileDetect.is-tablet()">

The isTablet invocation isn't right, and you need brackets around the Or'ed parts.

Something like:
XML:
<xf:if is="$xf.mobileDetect && ($xf.mobileDetect.isMobile() || $xf.mobileDetect.isTablet())">
 
ErrorException: Template error: [E_WARNING] preg_match(): Null byte in regex src/addons/SV/BrowserDetection/MobileDetect.php:1327

Code:
Трассировка стека
#0 [internal function]: XF\Template\Templater->handleTemplateError(2, '[E_WARNING] pre...', '/home/findozorn...', 1327)
#1 src/addons/SV/BrowserDetection/MobileDetect.php(1327): preg_match('##is', 'Mozilla/5.0 (Wi...', NULL)
#2 src/addons/SV/BrowserDetection/MobileDetect.php(1180): SV\BrowserDetection\MobileDetect->match('', NULL)
#3 src/addons/SV/BrowserDetection/MobileDetect.php(1248): SV\BrowserDetection\MobileDetect->matchDetectionRulesAgainstUA()
#4 src/addons/SV/BrowserDetection/MobileDetectCache.php(56): SV\BrowserDetection\MobileDetect->isMobile()
#5 src/addons/SV/BrowserDetection/MobileDetectCache.php(40): SV\BrowserDetection\MobileDetectCache->isMobile()
#6 src/XF/Template/Templater.php(1195): SV\BrowserDetection\MobileDetectCache->getHtmlCss()
#7 internal_data/code_cache/templates/l9/s28/public/PAGE_CONTAINER.php(316): XF\Template\Templater->method(Object(SV\BrowserDetection\MobileDetectCache), 'getHtmlCss', Array)
#8 src/XF/Template/Templater.php(1655): XF\Template\Templater->{closure}(Object(NF\Tickets\XF\Template\Templater), Array, NULL)
#9 src/addons/MaZ/AUN/XF/Template/Templater.php(39): XF\Template\Templater->renderTemplate('PAGE_CONTAINER', Array, true, NULL)
#10 src/XF/Pub/App.php(565): MaZ\AUN\XF\Template\Templater->renderTemplate('public:PAGE_CON...', Array)
#11 src/XF/App.php(2283): XF\Pub\App->renderPageHtml('

<style>   
    .fo...', Array, Object(XF\Mvc\Reply\View), Object(XF\Mvc\Renderer\Html))
#12 src/XF/Mvc/Dispatcher.php(404): XF\App->renderPage('

<style>   
    .fo...', Object(XF\Mvc\Reply\View), Object(XF\Mvc\Renderer\Html))
#13 src/XF/Mvc/Dispatcher.php(60): XF\Mvc\Dispatcher->render(Object(XF\Mvc\Reply\View), 'html')
#14 src/XF/App.php(2485): XF\Mvc\Dispatcher->run()
#15 src/XF.php(524): XF\App->run()
#16 index.php(20): XF::runApp('XF\\Pub\\App')
#17 {main}
Содержимое запроса
array(4) {
  ["url"] => string(53) "/forum/threads/belye-dengi-beliedengi-ru-otzyvy.2747/"
  ["referrer"] => string(23) "https://www.google.com/"
  ["_GET"] => array(0) {
  }
  ["_POST"] => array(0) {
  }
}

v 2.2.16
php 8.1
im also hav addonslab core addon which has crushed today with kinda similar error
 
Is this a once-off thing or is it reoccurring?

Have you done any modifications to the MobileDetect (ie adding new matching rules)? It shouldn't be running the regex ##is for one as that isn't in a list of any of it's regexes
 
Last edited:
Is this a once-off thing or is it reoccurring?
it's only happened once in the entire time
Have you done any modifications to the MobileDetect (ie adding new matching rules)? It shouldn't be running the regex ##is for one as that isn't in a list of any of it's regexes
not but i think its related to error i mentioned above as Core addon also have Mobile detect library (\src\addons\AddonsLab\Core\vendor\mobiledetect\mobiledetectlib\mobile_detect.php) and stack trace is pointing to code snippet with regex ##is.

here it is
Code:
public function match($regex, $userAgent = null)

    {

        if (!\is_string($userAgent) && !\is_string($this->userAgent)) {

            return false;

        }

        $match = (bool) preg_match(sprintf('#%s#is', $regex), (false === empty($userAgent) ? $userAgent : (is_string($this->userAgent) ? $this->userAgent : '')), $matches);

        // If positive match is found, store the results for debug.

        if ($match) {

            $this->matchingRegex = $regex;

            $this->matchesArray = $matches;

        }

        return $match;

    }


well threre is no issue with your addon i guess but just fyi
 
Back
Top Bottom