Page 1 of 1

[Solved]Mobile Detect plugin won't work

Posted: Fri May 17, 2013 2:56 pm
by brutusmaximus
Hi there! I'm currently trying to implement a mobile detect php script, so that mobile user will get a light version of a slideshow.

PHP Mobile Detect Script: http://mobiledetect.net/
1. I placed the PHP script in the folder: /mdetect/MobileDetect.php
2. Created a plugin (see below) /plugin/function.mobile_detect.php
3. when I call {mobile_detect} my website only is displaying the html till the placed tag. No stylesheets are generated.

Code: Select all

<?php

function smarty_function_mobile_detect($params, $smarty)
{
include_once('/mdetect/Mobile_Detect.php');
$detect = new Mobile_Detect;
$deviceType = ($detect->isMobile() ? ($detect->isTablet() ? 'tablet' : 'phone') : 'computer');
$smarty->assign('deviceType', $deviceType);

 }
?>
My steps to solve the problem:
1. Smarty 3 include php guide: http://www.smarty.net/best_practices
2. Smarty debug = true (isn't generating any output) :(

3. Posting a forumpost ;) pls help

Re: Mobile Detect plugin won't work

Posted: Fri May 17, 2013 3:09 pm
by calguy1000
When working in PHP you need to be able to find, see, and interpret error messages. Check your error logs.

Re: Mobile Detect plugin won't work

Posted: Fri May 17, 2013 3:17 pm
by Rolf
Why not use CGExtentions module?

Code: Select all

{cge_is_smartphone assign='is_mobile'}
{if $is_mobile}
...
{else}
...
{/if}

Re: Mobile Detect plugin won't work

Posted: Fri May 17, 2013 4:13 pm
by brutusmaximus
Thanks for quick reply.

@Rolf wow that's a quick and great solution. Didn't know you'd could do that with cgextensions

@calguy great tip, now I'm looking for the logs :-\

Re: Mobile Detect plugin won't work

Posted: Fri May 17, 2013 4:20 pm
by brutusmaximus
Errorreporting enabled in the htacces

Code: Select all

php_flag register_globals On
# Level of log detail - log all errors
php_value error_reporting -1

# Write errors to log file
php_flag log_errors On

# Do not display errors in browser (production - Off, development - On)
php_flag display_errors On

# Do not display startup errors (production - Off, development - On)
# php_flag display_startup_errors Off

# Format errors in plain text
# Note: Leave this setting 'On' for xdebug's var_dump() output
php_flag html_errors On
Now it displays a error. (nice lessons learned here) ;)

Warning: include_once(/home/vhosting/h/../plugins/mdetect/Mobile_Detect.php) [function.include-once]: failed to open stream: No such file or directory in /home/vhosting/h/.../plugins/function.mobile_detect.php on line 5

Warning: include_once() [function.include]: Failed opening '/home/vhosting/h/.../plugins/mdetect/Mobile_Detect.php' for inclusion (include_path='.:/usr/share/php:/usr/share/pear') in /home/vhosting/h/../plugins/function.mobile_detect.php on line 5

Fatal error: Class 'Mobile_Detect' not found in /home/vhosting/h/.../plugins/function.mobile_detect.php on line 6

Now googling for a solution!

Re: Mobile Detect plugin won't work

Posted: Fri May 17, 2013 4:26 pm
by Rolf
brutusmaximus wrote:Now googling for a solution!
The error message seems clear to me...

Re: Mobile Detect plugin won't work

Posted: Fri May 17, 2013 4:34 pm
by brutusmaximus
Rolf wrote:
brutusmaximus wrote:Now googling for a solution!
The error message seems clear to me...
hahahahha yes the file was in the wrong directory ;)
I thought when you refer to a /dir/folder/file.php it's a absolute path. But for PHP it means the refered file should be in the same folder.


thanks @calguy and @rolf