-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
improve mobile checks #15228
improve mobile checks #15228
Conversation
only check for resolution in user agent once to determine mobile
I think this is wrong. For example edge handsets will now just be recognised as mobile but not as edge. Because they will trigger in the first if that does the mobile check, but not in the part that does the Ditto I assume iPhone's can be identified as Safari (or iOS Chrome by the user agent) and therefore shouldn't 'just' be a unknown browser mobile. But should trigger user agent checks so we know mobile and browser But I am not a user agent guru at all :) |
I've proposed this before, but I will do it again, let's use: https://github.com/serbanghita/Mobile-Detect |
Dont we have mobile detection already in https://github.com/joomla/joomla-cms/blob/staging/libraries/vendor/joomla/application/src/Web/WebClient.php |
@wilsonge I believe mobile is a wholly separate property from browser. I also believe the two are checked and set separately (although in the same function). |
@brianteeman and this is one of those areas that Joomla should not try to innovate by having it's own well abandoned code. Check the highlighted part of their repo and compare it to the last update of the Joomla's shiny WebClient.php: Use other people's code when it's an obvious win! |
If someone does a PR that at least proxies the internals of either |
@photodude if you match this |
@wilsonge that is technically a bug in the existing code too I overlooked the |
@dgt41 I'm all for using an external solution. We will never be able to properly maintain every browser combination and properly check them. but as @mbabker noted, someone needs to proxy the internals of our existing solutions to whatever option we use. I'm leaning towards pulling in the browscap.ini and use the php native |
@brianteeman Yes, there is a mobile detection in The focus in this PR is improving (and apparently fixing) the current |
@mbabker can you rerun the appveyor tests. There was an unrelated failure in one of the |
@wilsonge with the correction to the conditional, do you think this is good to go? |
if (strpos($this->lowerAgent, 'mobileexplorer') !== false | ||
|| strpos($this->lowerAgent, 'openwave') !== false | ||
|| strpos($this->lowerAgent, 'opera mini') !== false | ||
|| strpos($this->lowerAgent, 'opera mobi') !== false | ||
|| strpos($this->lowerAgent, 'operamini') !== false) | ||
|| strpos($this->lowerAgent, 'operamini') !== false | ||
|| preg_match('/(iPhone|iPod|iPad|Android|Mobile|Phone|BlackBerry)/i', $this->agent); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Blackberry is tested on line 413 so it can be removed here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would go the other way and remove the mobile set in the 413 conditional. mobile and browser should check/set separately.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If that is the case, then starting with line 378 to 413 would have to be changed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll try to get to those on Wednesday evening
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Quy the changes have been implemented
Question: |
@infograf768 It might be possible. Although, I'm more of a fan of responsive design and let the css control the view depending on the viewport size. As for content, it seems reasonable that a module could be set to change content when I've done a few things in the past where a module would show if it was desktop and would hide and show a different module if it was mobile, that switch was all controlled by css classes. |
|| preg_match('/(openwave|opera mini|opera mobi|operamini|avantgo|wap|elaine)/i', $this->agent) | ||
|| preg_match('/(iPhone|iPod|iPad|Android|Mobile|Phone|BlackBerry|Xiino|Palmscape|palmsource)/i', $this->agent) | ||
|| preg_match('/(Nokia|Ericsson|docomo|portalmmm|CriOS[/ ]([0-9.]+)|)/i', $this->agent) | ||
|| preg_match('/(digital paths|UP|UP.B|UP.L)/i', $this->agent) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Warning: preg_match(): Unknown modifier ']' in C:\xampp\htdocs\joomla-cms\libraries\joomla\environment\browser.php on line 238
Warning: preg_match(): Unknown modifier 'C' in C:\xampp\htdocs\joomla-cms\libraries\joomla\environment\browser.php on line 280
For UP
probably will have to append /
to prevent false match since it is doing an incase-sensitive match.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Quy I can not reproduce the Unknown modifier warnings. I have made some adjustments to the patterns that should fix those. Let me know if they are still occurring on your end.
|| strpos($this->lowerAgent, 'operamini') !== false) | ||
|| strpos($this->agent, 'MOT-') !== false | ||
|| strpos($this->lowerAgent, 'j-') !== false | ||
|| preg_match('/(openwave|opera mini|opera mobi|operamini|avantgo|wap|elaine)/i', $this->agent) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about combining mobileexplorer
here?
I have tested this item ✅ successfully on 4328de0 This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/15228. |
Have tested successfully using "Firefox > Responsive Design Mode" – ist this Test-Scenario enough for marking as successfully Test? |
@franz-wohlkoenig Looking over the code Likely need to look at depreciating JBrowser for 4.0 and just use the framework browser detection in the application library. |
I have tested this item ✅ successfully on 4328de0 This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/15228. |
RTC after two successful tests. |
Thanks! |
@photodude |
@infograf768 I have reviewed it. |
Pull Request for Issue mobile checks have multiple conditionals when one is sufficient
Summary of Changes
only check for resolution in user agent once to determine mobile
add common user agent strings that identify mobile
Fix mobile check to be separate from browser.
Testing Instructions
code review
(could apply patch and check on a mobile device or emulator that mobile is detected)
Expected result
mobile is easily and correctly detected.
Actual result
extraneous checks were in additional locations specific to certain browsers
Documentation Changes Required
none