Mobile Device Detect

Started by emanuele, March 07, 2012, 02:29:20 PM

Previous topic - Next topic

emanuele

Link to Mod

A small mod that uses the code from the MobileESP Project in order to detect if the user visiting your forum is using a mobile device or not.

At the moment in this mod this function is used to allow admins to select a default theme for mobile devices.
Going to Admin > Configuration > Themes and Layout > Manage and Install a new dropdown is present where you will be able to select a theme for users with mobile devices.

Note: since the normal detection code would probably be too cumbersome for just define if a user is using a mobile device of not, I'm using a modified (untested in real world) version of the code and for that reason the detection could be not "perfect". Your feedback is highly appreciated!

The complete list of devices is too long to write here and now, look at the code. :P
A short list includes: iPhone, iPad, iPod, Android-based, Symbian OS-based, windows 7 and ce based, blackberry and others.

Once instantiated the class is placed in $context['device'], so that other mods and themes can use the it in order to do change their behaviour depending on the device.

Feel free to fork and help at https://github.com/emanuele45/Mobile-Device-Detect

Change log
  • 0.1.0: initial release
  • 0.2.0: the theme is set based on the function CheckIsMobile (provided by feline and just changed a bit), fixed an undefined index error, few other things. The code from Mobile EPS is still the re if anyone wants to use it.
  • 0.2.1: removed the __contruct function from the class to avoid php errors (Redefining already defined constructor)


Take a peek at what I'm doing! ;D




Hai bisogno di supporto in Italiano?

Aiutateci ad aiutarvi: spiegate bene il vostro problema: no, "non funziona" non è una spiegazione!!
1) Cosa fai,
2) cosa ti aspetti,
3) cosa ottieni.

Kreator

will this have any advers effect if the tapatalk mod is installed ? just a thought

emanuele

Unfortunately I have no idea...


Take a peek at what I'm doing! ;D




Hai bisogno di supporto in Italiano?

Aiutateci ad aiutarvi: spiegate bene il vostro problema: no, "non funziona" non è una spiegazione!!
1) Cosa fai,
2) cosa ti aspetti,
3) cosa ottieni.

feline

Thanks emanuele for sharing this  :)
I have tested that on our Site and it works very well ..
Tested with SMF4Iphone Theme and a Samsung Galaxy I9000 with Android 2.3.3

A small hint to test if the theme changed to the selected Mobile theme ..

if(isset($modSettings['mobile_theme_id']) && $modSettings['mobile_theme_id'] == $settings['theme_id'])
// put in the code where need if the mobile theme selected

That we use to hide the entire Portal  ;)

One small mistake we found .. You MUST enable "User can change Theme" in admin .. that is not the best.

emanuele

Quote from: feline on March 08, 2012, 07:06:26 AM
Thanks emanuele for sharing this  :)
I have tested that on our Site and it works very well ..
Tested with SMF4Iphone Theme and a Samsung Galaxy I9000 with Android 2.3.3
Great, thanks!

Quote from: feline on March 08, 2012, 07:06:26 AM
One small mistake we found .. You MUST enable "User can change Theme" in admin .. that is not the best.
Yep, I tried to override this behaviour with
// On-the-fly override settings...hope is enough...
$modSettings['theme_allow'] = true;

but now that I think about it I don't remember if I checked if it works or not... :laugh:


Take a peek at what I'm doing! ;D




Hai bisogno di supporto in Italiano?

Aiutateci ad aiutarvi: spiegate bene il vostro problema: no, "non funziona" non è una spiegazione!!
1) Cosa fai,
2) cosa ti aspetti,
3) cosa ottieni.

humbleworld

Can we insert javascript ads on this mobile theme?

feline

Uhmm .. this mod is not a Theme  ;) only a small code part to detect a mobile device ..

natenkiki2004

Just tried this mod on my website and it seems like pages created with SSI functions outside of the forum get an error:
Strict Standards: Redefining already defined constructor for class uagent_info in /home/natcom/public_html/hsc/Sources/Subs-MobileDetect.php on line 240

Is there something that needs to be called in SSI or on our custom pages?

emanuele

Hello natenkiki2004,

honestly I haven't tested it with SSI...
I'll soon replace almost all the code with the one feline gave me (I'm bit lazy in these days... :P), that should work without problems. :)


Take a peek at what I'm doing! ;D




Hai bisogno di supporto in Italiano?

Aiutateci ad aiutarvi: spiegate bene il vostro problema: no, "non funziona" non è una spiegazione!!
1) Cosa fai,
2) cosa ti aspetti,
3) cosa ottieni.

sandy89

is there the same way to look from the new ipad..

natenkiki2004

Quote from: emanuele on March 21, 2012, 07:38:37 AM
Hello natenkiki2004,

honestly I haven't tested it with SSI...
I'll soon replace almost all the code with the one feline gave me (I'm bit lazy in these days... :P), that should work without problems. :)

Thanks for being willing to do work on it. This is a good mod that should get more recognition. I don't mind being a tester for beta releases either.

Adrek

awesome mod ;)

and just to be sure, can i use it in my modification to hide something for mobile users?
Polskie wsparcie SMF na simplemachines.org

the simplest solution is most likely the right one

emanuele

Thanks. (Well, I just packaged it together with few changes...in the end the biggest thanks should go to Anthony Hand and his Mobile ESP project! :))

Quote from: sandy89 on March 21, 2012, 05:12:01 PM
is there the same way to look from the new ipad..
Hello sandy89,
please forgive me, but I'm not sure what the question is... :)

Okay, I updated the mod with the code feline gave me (well, a bit changed :P).
Now you can use the function CheckIsMobile to know if the user is using a mobile device or not. It simply returns tru or false as default behaviour, but I also added the option to return an array with informations about the device.


Take a peek at what I'm doing! ;D




Hai bisogno di supporto in Italiano?

Aiutateci ad aiutarvi: spiegate bene il vostro problema: no, "non funziona" non è una spiegazione!!
1) Cosa fai,
2) cosa ti aspetti,
3) cosa ottieni.

natenkiki2004

Just installed the newest version, unfortunately I still get errors on SSI pages.

On Chrome while logged in:
QuoteStrict Standards: Redefining already defined constructor for class uagent_info in /home/natcom/public_html/hsc/Sources/Subs-MobileDetect.php on line 386

On IE9 while logged out:
QuoteStrict Standards: Redefining already defined constructor for class uagent_info in /home/natcom/public_html/hsc/Sources/Subs-MobileDetect.php on line 386

Notice: SSI.php was unable to load a session! This may cause problems with logout and other functions - please make sure SSI.php is included before *anything* else in all your scripts! in /home/natcom/public_html/hsc/SSI.php on line 177
It also breaks the CSS for some reason on IE.

*EDIT*
There's no errors or broken CSS on the forum itself in IE or Chrome.

emanuele

Well, that particular error is most likely due to the fact that the class uses both the "pre-php5" and the "__constrct" way to define a constructor.

You can remove:
/**
* The constructor. Allows the latest PHP (5.0+) to locate a constructor object and initialize the object.
*/
function __construct()
{
$this->uagent_info();
}

and it should work the same.
Let me know, in case I can remove it entirely from the mod.


Take a peek at what I'm doing! ;D




Hai bisogno di supporto in Italiano?

Aiutateci ad aiutarvi: spiegate bene il vostro problema: no, "non funziona" non è una spiegazione!!
1) Cosa fai,
2) cosa ti aspetti,
3) cosa ottieni.

natenkiki2004

#15
That worked :) At least, it removed the error. I don't have a mobile device to test whether or not the mod still works properly. I'll try to get some of my users to test. Thanks.

*EDIT*
One user reports the forum theme changed. Will wait to hear back from others. Looking good so far though.

natenkiki2004

Another user confirms it works without that function. I see no problem on any pages in any browser so it seems to me like it would be good to update :) Thanks for providing a fix.

samurai-lupin

Hello, this sounds like a fantastic mod! Could you please do a SMF 1.1 version of it? Thank you!

cobland

Hello,
may i unistall version 0.1.0 before install this?

thanks

emanuele

Quote from: samurai-lupin on April 01, 2012, 08:14:43 PM
Hello, this sounds like a fantastic mod! Could you please do a SMF 1.1 version of it? Thank you!
Hello samurai-lupin,
it shouldn't be too difficult, but it's a while I don't do anything for 1.1...

Quote from: cobland on April 02, 2012, 02:08:47 AM
may i unistall version 0.1.0 before install this?
Hello cobland,
Yes, uninstall previous versions is better.


Take a peek at what I'm doing! ;D




Hai bisogno di supporto in Italiano?

Aiutateci ad aiutarvi: spiegate bene il vostro problema: no, "non funziona" non è una spiegazione!!
1) Cosa fai,
2) cosa ti aspetti,
3) cosa ottieni.

Advertisement: