Advertisement:

Author Topic: Mobile Device Detect  (Read 64054 times)

Offline emanuele

  • SMF Super Hero
  • *******
  • Posts: 14,156
  • Gender: Male
  • THERE'S JUST ME
Mobile Device Detect
« on: March 07, 2012, 02:29:20 PM »
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)
« Last Edit: March 24, 2012, 09:49:32 AM by emanuele »


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.

Offline Kreator

  • Jr. Member
  • **
  • Posts: 225
  • Gender: Male
    • Anim8orWorld on Facebook
    • Anim8orWorld
Re: Mobile Device Detect
« Reply #1 on: March 08, 2012, 01:39:31 AM »
will this have any advers effect if the tapatalk mod is installed ? just a thought

Offline emanuele

  • SMF Super Hero
  • *******
  • Posts: 14,156
  • Gender: Male
  • THERE'S JUST ME
Re: Mobile Device Detect
« Reply #2 on: March 08, 2012, 03:14:40 AM »
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.

Offline feline

  • SMF Hero
  • ******
  • Posts: 1,638
  • Gender: Female
Re: Mobile Device Detect
« Reply #3 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

A small hint to test if the theme changed to the selected Mobile theme ..
Code: [Select]
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.

Offline emanuele

  • SMF Super Hero
  • *******
  • Posts: 14,156
  • Gender: Male
  • THERE'S JUST ME
Re: Mobile Device Detect
« Reply #4 on: March 08, 2012, 08:52:07 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!

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
Code: [Select]
// 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.

Offline humbleworld

  • Sr. Member
  • ****
  • Posts: 886
    • best article
Re: Mobile Device Detect
« Reply #5 on: March 08, 2012, 10:49:33 PM »
Can we insert javascript ads on this mobile theme?

Offline feline

  • SMF Hero
  • ******
  • Posts: 1,638
  • Gender: Female
Re: Mobile Device Detect
« Reply #6 on: March 08, 2012, 11:21:56 PM »
Uhmm .. this mod is not a Theme  ;) only a small code part to detect a mobile device ..

Offline natenkiki2004

  • Semi-Newbie
  • *
  • Posts: 13
Re: Mobile Device Detect
« Reply #7 on: March 20, 2012, 03:03:08 PM »
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?

Offline emanuele

  • SMF Super Hero
  • *******
  • Posts: 14,156
  • Gender: Male
  • THERE'S JUST ME
Re: Mobile Device Detect
« Reply #8 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. :)


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.

Offline sandy89

  • Newbie
  • *
  • Posts: 2
Re: Mobile Device Detect
« Reply #9 on: March 21, 2012, 05:12:01 PM »
is there the same way to look from the new ipad..

Offline natenkiki2004

  • Semi-Newbie
  • *
  • Posts: 13
Re: Mobile Device Detect
« Reply #10 on: March 21, 2012, 11:34:11 PM »
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.

Offline phantomm

  • Sophist Member
  • *****
  • Posts: 1,065
  • Gender: Male
    • pages/smfpl/171860759503032 on Facebook
    • Polish ElkArte community
Re: Mobile Device Detect
« Reply #11 on: March 22, 2012, 03:41:51 AM »
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

My mods

Offline emanuele

  • SMF Super Hero
  • *******
  • Posts: 14,156
  • Gender: Male
  • THERE'S JUST ME
Re: Mobile Device Detect
« Reply #12 on: March 22, 2012, 10:34:44 AM »
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! :))

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.

Offline natenkiki2004

  • Semi-Newbie
  • *
  • Posts: 13
Re: Mobile Device Detect
« Reply #13 on: March 22, 2012, 03:14:13 PM »
Just installed the newest version, unfortunately I still get errors on SSI pages.

On Chrome while logged in:
Quote
Strict 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:
Quote
Strict 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.

Offline emanuele

  • SMF Super Hero
  • *******
  • Posts: 14,156
  • Gender: Male
  • THERE'S JUST ME
Re: Mobile Device Detect
« Reply #14 on: March 22, 2012, 03:30:52 PM »
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:
Code: [Select]
/**
* 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.

Offline natenkiki2004

  • Semi-Newbie
  • *
  • Posts: 13
Re: Mobile Device Detect
« Reply #15 on: March 22, 2012, 04:04:18 PM »
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.
« Last Edit: March 22, 2012, 06:13:43 PM by natenkiki2004 »

Offline natenkiki2004

  • Semi-Newbie
  • *
  • Posts: 13
Re: Mobile Device Detect
« Reply #16 on: March 24, 2012, 12:39:11 AM »
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.

Offline samurai-lupin

  • Full Member
  • ***
  • Posts: 522
Re: Mobile Device Detect
« Reply #17 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!

Offline cobland

  • Newbie
  • *
  • Posts: 4
Re: Mobile Device Detect
« Reply #18 on: April 02, 2012, 02:08:47 AM »
Hello,
may i unistall version 0.1.0 before install this?

thanks

Offline emanuele

  • SMF Super Hero
  • *******
  • Posts: 14,156
  • Gender: Male
  • THERE'S JUST ME
Re: Mobile Device Detect
« Reply #19 on: April 02, 2012, 05:12:14 AM »
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...

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.