If I understand correctly from "Make your site mobile with Mobile Tools", I can use Automatic Redirector of mobile users to the mobile site. That is great, but it does not look like I can then give the mobile user the choice to use the desktop site.

I also tried, "Display a message to mobile users when visiting the desktop site". It seems when I add a block in the desktop and mobile themes, the block appears when I view the desktop site with a mobile client. The block is not visible when I am on the mobile site with a mobile client.

Is this by design or have I done something wrong?

CommentFileSizeAuthor
#19 mobile_tools.zip10.87 KBtwom
#7 mobile_tools.zip10.89 KBtwom
#1 mobile_tools_redirect.png50.72 KBtwom
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

twom’s picture

Status: Active » Needs review
FileSize
50.72 KB

Hy,

I have optimized this functionality in the new mobile tools version that is in the dev repository.

The way it works is:

- if you choose redirection, each mobile user is redirected to the mobile url
- if you put a message in the block that is displayed in the mobile view with the nomobile=true argument, the user can go back to the desktop site and stay there (nomobile=true sets a cookie).

So important is to use the nomobile argument. See the attachement for an example.

Optional going back to the mobile site can be done using http://www.domain.com/gomobile (when mobile and desktop site are on a different domain and cannot share cookies) or by using http://m.domain.com?nomobile=false (only possible if you use a subdomain for the mobile site) . If you just do http://m.domain.com, the user will go back to the mobile site, but he will not be redirected automatically to it (since the nomobile=false has set the cookie to never redirect)... Still following?

I will try to document this issue a bit better...
Let me know if this works (and sorry that I force you to use the dev version ;) but I want to release it as soon as possible as a new stable Mobile Tools version)

waverate’s picture

Version: 6.x-1.8 » 6.x-1.x-dev

Tom,

Okay, upgraded to 6.x-1.x-dev (21 Oct 09). The dev is tougher to understand than the 6.x-1.8. I think I am actually worse off; let my explain. I have two (2) URLs for the site http://domain.com and http://m.domain.com. I am using User Agent Switcher 0.7.2 plugin for Firefox to save me from going between my iPhone and Desktop.

To try and simplify the setup, I am not using automatic redirection, I just want to have a block that toggles between the mobile and desktop sites. In the Mobile Tools block message options, for the Desktop site I have

(Check out our <a href="http://m.domain.com?nomobile=false">Mobile</a> site.)

and for the Mobile site I have

(Check out our <a href="http://domain.com?nomobile=true">Desktop</a> site.)

With the User Agent set to Firefox 3.5, I get the following results:

- http://domain.com shows the desktop theme and mobile tools block with "Check out our Desktop site" and links to http://domain.com?nomobile=true and the domain.com cookie has mt_redirect is true, and [I would not have expected this result]

- http://m.domain.com shows the mobile theme and mobile tools block with "Check out our Desktop site" and links to http://domain.com?nomobile=true and the m.domain.com cookie has mt_redirect is true. [I would have expected this result]

With the User Agent set to iPhone 3.0, I get the following results:

- http://domain.com shows the desktop theme and mobile tools block with "Check out our Mobile site" and links to http://m.domain.com?nomobile=false and the domain.com cookie has mt_redirect is true, and [I would have expected this result]

- http://m.domain.com shows the mobile theme and mobile tools block with "Check out our Mobile site" and links to http://m.domain.com?nomobile=false and the m.domain.com cookie has mt_redirect is true. [I would not have expected this result]

I am going to post this and then redo the check with automatic redirection and see if that makes a difference.

waverate’s picture

Same check as above except automatic redirection is enabled.

With the User Agent set to Firefox 3.5, I get the following results:

- http://domain.com was the same as without redirection, and

- http://m.domain.com was the same as without redirection.

With the User Agent set to iPhone 3.0, I get the following results:

- http://domain.com redirects to http://m.domain.com, shows the desktop theme and mobile tools block with "Check out our Mobile site" and links to http://m.domain.com?nomobile=false and the domain.com cookie has mt_redirect is true, and

- http://m.domain.com was the same as without redirection.

So it looks like automatic redirection only works for a Mobile user viewing a Desktop site. It does not work for a Desktop user viewing a mobile site.

Is this by design or can it change?

waverate’s picture

I don't know if this is relevant but I am getting the following messages in the error_log:

[error] [client x.x.x.x] PHP Notice: Undefined index: mobile_tools_nomobile in /var/www/html/drupal-6.14/sites/all/modules/mobile_tools/mobile_tools.module on line 400

kittysunshine’s picture

I just installed the latest dev version. This works great for (1) redirecting the mobile user to the mobile site and (2) allowing the mobile user to click a link to view the full site (using the ?nomobile=true flag) and (3) allowing the mobile user to return to the mobile site. Thank you so much!

One question/problem.

If the mobile user visits the full site again later, they are not redirected to the mobile site. I think most users are happy to use the mobile version most of the time, but just want to have the option to visit the full site occasionally. So, I would expect the redirect from the full site to the mobile site to work all the time *except* when a user clicks the link to the full site.

Is there a configuration for this scenario? Thanks!

twom’s picture

Thanks for the report. This is the error (and I found a second one explaining some of your behavior)!!
These are some ugly bugs :)

I'll fix it right away

twom’s picture

FileSize
10.89 KB

A new module file. Can you test this out?
I fixed a number of bugs... And it should fix all the bugs you mentioned!

I'll continue till it all works for you!

twom’s picture

@ kittsunshine thanks for testing. I have uploaded a new file (attached to my previous comment... Could you test this out? )

Can you clarify your use case more. Do you mean:
- Mobile user goes to the site and he is redirected to the mobile version
- He wants to see something on the desktop site, so he clicks on the 'go desktop' link
- he views the destkop page
- when he clicks a new page, he is for that page automatically redirected to the mobile site again?
=> this scenario is not supported. By providing the go back to the mobile site with the nomobile=false argument is maybe a solution

If it is this that you want, I'll have figure out something.

kittysunshine’s picture

Wow, fast work! I installed your updated .module file and I'm not seeing any differences (or problems!).

To clarify the use case, what I mean is:
- Mobile user goes to the site and he is redirected to the mobile version
- He wants to see something on the desktop site, so he clicks on the 'go desktop' link
- He views the desktop page and clicks on many more pages to look for what he wants, staying in the desktop site the whole time
- Later today or tomorrow he goes back to the desktop site and he is again redirected to the mobile version

I wonder -- would simply setting the cookie to expire at the end of the session solve the problem?

Also, I am using the nomobile=false argument for the link from the desktop site to the mobile site, but it doesn't seem to be clearing the cookie. If I click back over to the mobile site from the desktop site and then enter the desktop URL, it doesn't redirect. Should it?

Thanks so much!

twom’s picture

Thanks for the reply. Glad that everything is still working fine :)

I think your idea on expiration of the cookie is perfect. I can add such a setting to the module.

concerning the cookie problem that you have, there can be some reasons for that:

- If your url structure is m.domain.com and www.domain.com, make sure that the $cookie_domain in the settings.php file is correct in order to share the cookie between the mobile and desktop site (value should be 'domain.com'):

/**
 * Drupal automatically generates a unique session cookie name for each site
 * based on on its full domain name. If you have multiple domains pointing at
 * the same Drupal site, you can either redirect them all to a single domain
 * (see comment in .htaccess), or uncomment the line below and specify their
 * shared base domain. Doing so assures that users remain logged in as they
 * cross between your various domains.
 */
$cookie_domain = 'example.com'; 

Any success with this.

- If this does not work for some reason, I have also provided a path /gomobile (e.g. redirecting to the mobile site goes by pointing to http://www.domain.com/gomobile) that will set the cookie on your desktop site first and redirect to the mobile site... This is for example needed if you use www.domain.com and www.domain.mobi

Maybe other solutions are better :)

waverate’s picture

Tom,

Tested out the new module. Big improvement. No error_log messages.

With Automatic redirection disabled and:

1. with the User Agent set to Firefox 3.5, I get the following results:

- http://domain.com shows "Check out our Mobile site" and links to http://m.domain.com?nomobile=false [Perfect]

- http://m.domain.com shows "Check out our Desktop site" and links to http://domain.com?nomobile=true[Perfect]

2. with the User Agent set to iPhone 3.0, I get the following results:

- http://domain.com shows "Check out our Mobile site" and links to http://m.domain.com?nomobile=false[Perfect]

- http://m.domain.com shows "Check out our Desktop site" and links to http://domain.com?nomobile=true[Perfect]

With Automatic redirection enabled and:

1. with the User Agent set to Firefox 3.5, I get the following results:

- http://domain.com shows "Check out our Mobile site" and links to http://m.domain.com?nomobile=false [Perfect]

- http://m.domain.com after a series of failed redirects, returns

The page isn't redirecting properly [Not Expected]

2. with the User Agent set to iPhone 3.0, I get the following results:

- http://domain.com redirects to http://m.domain.com [Perfect]

- http://m.domain.com and shows "Check out our Desktop site" and links to http://domain.com?nomobile=true[Perfect]

There are a couple of things that could contribute to this problem.

1. I am using the front_page module (http://drupal.org/project/front) redirect to a splash page.

2. My URLs are actually http://m.domain.com/home and http://domain.com/home, thus the links from the mobile tools block is http://m.domain.com/home?nomobile=false, etc.

Is it by design that link from the mobile tools block always appends to the Mobile and Desktop URLs instead of appending to the current page.

Just a guess:

$base_url

instead of

mobile_tools_mobile_url and mobile_tools_desktop_url

twom’s picture

Hi,

Thank you for the excellence tests!!! We will have a good tested module by the end of the week (or even tomorrow)

What is the $base_url in your settings.php file?

Further I see a type at line 401: should be
$destination = variable_get('mobile_tools_desktop_url', $base_url); // desktop was written wrong

kittysunshine’s picture

An option to set the cookie to expire at the end of the session would be great! Thanks!

On the other issue, our development site where we're testing all this out, does not have separate domains! Our URL structure is http://domain.com and http://domain.com/mobile. Whether we use ?nomobile=false or /gomobile in the "mobile site" link, it doesn't seem to clear the cookie. The next time the user visits the desktop URL, they are not redirected.

Just to be clear, this is the use case I'm expecting:

- Mobile user goes to the desktop site and he is redirected to the mobile version
- He wants to see something on the desktop site, so he clicks on the "full site" link (http://domain.com/?nomobile=true)
- He wants to go back to the mobile site, so he clicks on the "mobile site" link (http://domain.com/mobile/?nomobile=false)
- Later today or tomorrow he enters the desktop URL and he is redirected to the mobile version

Is that how it should work? If so, for us, everything is working correctly except the last step. Any ideas?

By the way, when I first tested the /gomobile option, I was getting an access denied error on my iPhone. I checked permissions and recalled that when I installed Mobile Tools, since the permission said “configure Mobile Tools,” I had only given access to the administrative user. Once I gave permissions to anonymous users, it works great! Would it make more sense for the permission to say “access Mobile Tools” or “use Mobile tools”?

Thanks again!

waverate’s picture

Tom,

The typo in #12 fixed the problem with the site redirecting forever.

Unfortunately, I still see two things that I would not expect:

1. The mobile tools block show up on the Desktop page even when using the Desktop user agent.

2. When the mobile block show up in the above problem, the link http://m.domain.com?nomobile=false redirects back to the Desktop page. I would have expected it to go to the mobile page.

Finally, I was incorrect in suggesting using $base_url. I do not have it defined in setting.php. I was more referring to showing the page that the user was on but in the other theme.

For example, if the user was on http://domain.com/page5 and clicked the Mobile link, he would go to http://m.domain.com/page5?nomobile=false. As it stands, he would go back to http://m.domain.com?nomobile=false.

waverate’s picture

I can get the desired effect so solve item 1 above by adding the following to the Mobile Tools message block under, Show block if the following PHP code returns true.

<?php
  if ($_SESSION['mobile-tools-mobile-device']['type'] == 'mobile') {
    return TRUE;  // block will be shown
  }
  return FALSE;
?>

I am certain you have a more elegant solution. Or even a way to ask the administrator if he wants to do this on the configuration page.

twom’s picture

Hi,

The error you had regarding the wrong block was maybe because I forgot to say that before testing you should go to your mobile tools settings page and save the settings again (and be sure that the right message is displayed in the textarea where you have to put the desktop message and the mobile message... Maybe they are switched now :)).

This was needed because there was an error (wrong message in the right block).

Can you save your settings in the mobile tools module (and remove the fix you have created). The code that you propose is currently in the module.

Let me know if this works!

twom’s picture

@kittysunshine

Hi,

The problem you have is cause because the specific nature of using http://domain.com and http://domain.com/mobile
The module still has troubles with this approach. Using m.domain.com or wwW.domain.mobi versus wwW.domain.com is much more robust!

I'll try to find out how to make your situation work.

twom’s picture

@kittysunshine

Ok, I think it should be fixed!
Can you test it....
If this test passes, I will giv the dev branch an official 'stability' tag....

Thanks for all the help!

twom’s picture

FileSize
10.87 KB

This is the latest module (in case cvs is running behind)

waverate’s picture

Tom,

Latest module looks good. Tried your recommendation at topic #16 but no difference. Only annoying problem is that the mobile tools block appears on the Desktop page but considering that there is a work around with the php code at #15; I am not too worried about getting it fixed in the module until you can get a chance.

Great work getting this module up and running nicely.

twom’s picture

Hi Waverate,

I misunderstood the question. It is indeed implemented like that that the block always appears.
I could make a checkbox in the configuration page asking if the block should only appear on the mobile site, or also on the desktop site.

Reason why I did not do this is that most of the time the mobile link is also displayed on the mobile site.

But your work around works fine, and I think I'll leave it like this... It's not a bad solution you have.

Tom

angelt’s picture

Hi,
when we can expect updating these features(I am in need for 'nomobile=true') to the official release version?

Angel

twom’s picture

I am finishing the new Readme and install files and will upload it today!

kittysunshine’s picture

Hello again! Sorry to disappear. It looks like you made good progress since I was last here! I just installed 6.x-1.11.

Everything is looking good, but I'm still hoping to solve the issue I raised in #9 above. Once the user clicks the full site (?nomobile=true) link, if they visit the full site URL again later they are not automatically redirected to the mobile site. I notice if I manually clear cookies from Safari on my iPhone, the automatic redirect works. So it looks like the cookies still aren't being cleared successfully. Ideally, I'd like to see the cookie expire after a relatively short time (30 minutes?) *and* I'd like to see the ?nomobile=false clear the cookie.

This is all happening in our development environment using the domain.com/mobile URL structure, so this is not an issue with cookie domain in settings.php.

Am I doing something wrong?

(And just to make it more confusing, we will also be using the m.domain.com structure in our live environment!)

tallsimon’s picture

for some reason this PHP does not work for me. I have enabled the block and put this code in the PHP condition box, the block disappears from all views whichever user agent I use!

EDIT i thought the PHP mode conditions was not working but this was a matter of block view permissions, the PHP code itself works well.

YK85’s picture

subscribing

Bright Web Design’s picture

Title: Switching between Desktop and Mobile » Switching between Desktop and Mobile works well on the dev version now!!!
Status: Needs review » Closed (fixed)

Thank you so much for this fix,

Now you can switch back to PC site from mobile site by adding
<a href="http://www.yoursite.com?nomobile=true">PC Site</a>

Thank you so much for this bug fix.