Skip to content
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

Merged
merged 16 commits into from
Jun 2, 2017
Merged

improve mobile checks #15228

merged 16 commits into from
Jun 2, 2017

Conversation

photodude
Copy link
Contributor

@photodude photodude commented Apr 11, 2017

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

only check for resolution in user agent once to determine mobile
@photodude
Copy link
Contributor Author

@rdeutz, @mbabker, @wilsonge
Any thoughts on these changes?

@zero-24 zero-24 added this to the Joomla 3.7.1 milestone Apr 22, 2017
@wilsonge
Copy link
Contributor

wilsonge commented Apr 22, 2017

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 :)

@dgrammatiko
Copy link
Contributor

I've proposed this before, but I will do it again, let's use: https://github.com/serbanghita/Mobile-Detect

@brianteeman
Copy link
Contributor

@photodude
Copy link
Contributor Author

@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).

@dgrammatiko
Copy link
Contributor

@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:
screen shot 2017-04-22 at 20 18 02

Use other people's code when it's an obvious win!

@mbabker
Copy link
Contributor

mbabker commented Apr 22, 2017

If someone does a PR that at least proxies the internals of either JBrowser or Joomla\Application\Web\WebClient (or both) to another library we could use it. We'd need that to help with the transition away from our own code.

@wilsonge
Copy link
Contributor

wilsonge commented Apr 22, 2017

@photodude if you match this if https://github.com/photodude/joomla-cms/blob/f1a5b8df900c31d21e93291286dedd405ca5320c/libraries/joomla/environment/browser.php#L229-L242 then you're never going to reach the edge browser elseif afterwards

@photodude
Copy link
Contributor Author

@wilsonge that is technically a bug in the existing code too I overlooked the if elseif; I was thinking it was two different conditionals as it should be. Corrected, as mobile and browser are different properties.

@photodude
Copy link
Contributor Author

@dgt41 I'm all for using an external solution. We will never be able to properly maintain every browser combination and properly check them.
See joomla-framework/application#59 where we have been discussing that for Joomla\Application\Web\WebClient

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 get_browser() although that requires setting another ini value at runtime with ini_set('browscap', '[thebrowscap.ini file location]'); and parsing the returned object. I'm leaning that direction since many other userland browscap libraries don't support the range of PHP versions that Joomla does.

@photodude
Copy link
Contributor Author

@brianteeman Yes, there is a mobile detection in Joomla\Application\Web\WebClient. as there currently is here in JBrowser. There is work needed here; either fixing, or proxying to a 3rdparty library, or making JBrowser an alias of Joomla\Application\Web\WebClient

The focus in this PR is improving (and apparently fixing) the current JBrowser mobile detection.

@photodude
Copy link
Contributor Author

@mbabker can you rerun the appveyor tests. There was an unrelated failure in one of the Cachelite tests. Thanks in advance.

@photodude
Copy link
Contributor Author

@wilsonge with the correction to the conditional, do you think this is good to go?

@zero-24 zero-24 modified the milestones: Joomla 3.7.1, Joomla 3.7.2 May 12, 2017
@rdeutz rdeutz modified the milestones: Joomla 3.7.2, Joomla 3.7.3 May 18, 2017
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);
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Contributor Author

@photodude photodude Jun 1, 2017

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

@infograf768
Copy link
Member

Question:
Can we serve different contents depending on this detection?
For example, a different content depending if mobile or desktop.
And usable in a multilingual setting?

@photodude
Copy link
Contributor Author

@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 JBrowser::mobile === true but I am unaware of any examples showing such a content switching based on the value of JBrowser::mobile.

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)
Copy link
Contributor

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.

Copy link
Contributor Author

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)
Copy link
Contributor

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?

@Quy
Copy link
Contributor

Quy commented Jun 1, 2017

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.

@ghost
Copy link

ghost commented Jun 2, 2017

Have tested successfully using "Firefox > Responsive Design Mode" – ist this Test-Scenario enough for marking as successfully Test?

@photodude
Copy link
Contributor Author

@franz-wohlkoenig Looking over the code JBrowser seems to only be used in JHtml::includeRelativeFiles and affects JHtml::stylesheet. Any general testing should be sufficient unless you can find a template that uses different files for different browsers and want to test with multiple browsers. Since that is a very unique situation, general use testing, Code review and the unit tests should be sufficient for now.

Likely need to look at depreciating JBrowser for 4.0 and just use the framework browser detection in the application library.

@ghost
Copy link

ghost commented Jun 2, 2017

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.

@joomla-cms-bot joomla-cms-bot removed this from the Joomla 3.7.3 milestone Jun 2, 2017
@ghost
Copy link

ghost commented Jun 2, 2017

RTC after two successful tests.

@joomla-cms-bot joomla-cms-bot added the RTC This Pull Request is Ready To Commit label Jun 2, 2017
@wilsonge wilsonge merged commit 3f15a2d into joomla:staging Jun 2, 2017
@joomla-cms-bot joomla-cms-bot removed the RTC This Pull Request is Ready To Commit label Jun 2, 2017
@wilsonge wilsonge modified the milestones: Joomla 4.0, Joomla 3.7.3 Jun 2, 2017
@wilsonge
Copy link
Contributor

wilsonge commented Jun 2, 2017

Thanks!

@infograf768
Copy link
Member

@photodude
Please look at #17139 urgently

@photodude
Copy link
Contributor Author

@infograf768 I have reviewed it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

10 participants