Customizing SMF > Modifications and Packages

Mobile Device Detect

(1/21) > >>

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)

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

emanuele:
Unfortunately I have no idea...

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

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

--- End code ---
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
--- End quote ---
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.

--- End quote ---
Yep, I tried to override this behaviour with

--- Code: --- // On-the-fly override settings...hope is enough...
$modSettings['theme_allow'] = true;
--- End code ---
but now that I think about it I don't remember if I checked if it works or not... :laugh:

Navigation

[0] Message Index

[#] Next page

Go to full version