HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Please upgrade here. These earlier versions are no longer being updated and have security issues.

some mobile devices loads up full-site view how to avoid this?

Hi Guys, so it came to a point where my self-hosted forum is now having lots of mobile users and most complaint is that their mobile is loading up full-site view. is there a way to avoid this kind of problem .?

or is there a way to redirect the user forcefully to mobile view ex. mywebsite.com?view=mobile ?

Best Answers

  • vrijvlindervrijvlinder Papillon-Sauvage MVP
    edited December 2012 Accepted Answer

    If peregrine's solution is not the cause of the problem (which I doubt coz he is always right), look in the file /forum/applications/dashboard/controllers/class.profilecontroller.php

    check this out

     /**
        * Set 'NoMobile' cookie for current user to prevent use of mobile theme.
        *
        * @since 2.0.?
        * @access public
        */
       public function NoMobile() {
          $Expiration = time() + 172800;
          $Expire = 0;
          $UserID = ((Gdn::Session()->IsValid()) ? Gdn::Session()->UserID : 0);
          $KeyData = $UserID."-{$Expiration}";
          Gdn_CookieIdentity::SetCookie('VanillaNoMobile', $KeyData, array($UserID, $Expiration, 'force'), $Expire);
          Redirect("/", 302);
       }
    

    add this

       public function Mobile() { 
           $Expiration = time() - 172800;
           $Expire = 0; 
           $UserID = ((Gdn::Session()->IsValid()) ? Gdn::Session()->UserID : 0); 
           $KeyData = $UserID."-{$Expiration}";
           Gdn_CookieIdentity::SetCookie('VanillaNoMobile', $KeyData, array($UserID, $Expiration, 'force'), $Expire);  Redirect("/", 302);
    
    }
    

    After adding this code you can put a link to the mobile version on the full site so people can go back to mobile version from full site. http://www.yoursite.com/forum/profile/mobile

    peregrinefr3em1ndUnderDog
  • peregrineperegrine MVP
    edited December 2012 Accepted Answer

    since no one is posting their useragents - I'm guessing what the useragents are for the mobile devices are.

    try adding these lines before line 1285  if you want mobile for the following:
       vanilla/library/core/functions.general.php  
    
    do the same thing for the useragent corresponding to nokia c3
    
    
     if(strpos($UserAgent,'android') > 0 && strpos($UserAgent,'mobile') > 0)
             $Mobile++;
    
    // try inserting  these  lines below -------------------------------------
    
      if(strpos($UserAgent,'android') > 0
            $Mobile++;
    
        if(strpos($UserAgent,'meego') > 0
            $Mobile++;
    
          if(strpos($UserAgent,'blackberry') > 0
            $Mobile++;
    // end of inserted code
    // original code below ------------------------------------------------------
    
          $MobileUserAgent = substr($UserAgent, 0, 4);
          $MobileUserAgents = array(
    

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

    fr3em1ndUnderDog
  • vrijvlindervrijvlinder Papillon-Sauvage MVP
    edited June 2013 Accepted Answer

    @UberLucas forget about codes and hacking the core and get the addon go back mobile

    http://vanillaforums.org/addon/gobackmobile-plugin

    UnderDog
«1

Answers

  • KasperKasper Scholar of the Bits Copenhagen Vanilla Staff

    Which version of Vanilla are you using and could you perhaps provide a link to your site?

    Kasper Kronborg Isager (kasperisager) | Freelance Developer @Vanilla | Hit me up: Google Mail or Vanilla Mail | Find me on GitHub

  • http://www.txtmyt.com <- this one , i can view the mobile page using iphone devices but when i use nokia it gives a fullsite view. ex nokia C3 cellphones

  • KasperKasper Scholar of the Bits Copenhagen Vanilla Staff

    I can verify this - tried accessing your site using the MeeGo and Blackberry user agents; the site didn't switch to the mobile theme.

    Kasper Kronborg Isager (kasperisager) | Freelance Developer @Vanilla | Hit me up: Google Mail or Vanilla Mail | Find me on GitHub

  • vrijvlindervrijvlinder Papillon-Sauvage MVP

    You need to change some stuff in application dashboard profile controller php there is a part about mobile /nomobile the time the page is catched must be changed to a negative number

  • @vrijvlinder can you please elaborate ?

  • vrijvlindervrijvlinder Papillon-Sauvage MVP

    Yea iPhone mobile shows ok here must be an a droid problem :(

  • @peregrine i need your magic here :D

  • vrijvlindervrijvlinder Papillon-Sauvage MVP

    I'm mobile at the moment. But there is info about this here that is how I solved the eternal cache problem where you can't get rid of the full site cache on mobile. But I am not sure this applies to you. Please ask your iPhone users to cclick the full site link to see if they can't go back to mobile after dumping cache. If they can't and only get full site then my solution applies. If they can then the problem is not what I think it is As soon as I get home I will post the code .

  • vrijvlindervrijvlinder Papillon-Sauvage MVP

    I just tried to do that I am now certain that my solution can apply the problem is the cache takes too long to get a new version of the page btw the full site works fine too as far as how it looks .

  • peregrineperegrine MVP
    edited December 2012

    @fr3333333x said:
    peregrine i need your magic here :D

    Maybe this discussion will help and this comment in particular to "debug".
    http://vanillaforums.org/discussion/comment/168834/#Comment_168834

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • vrijvlindervrijvlinder Papillon-Sauvage MVP
    edited December 2012 Accepted Answer

    If peregrine's solution is not the cause of the problem (which I doubt coz he is always right), look in the file /forum/applications/dashboard/controllers/class.profilecontroller.php

    check this out

     /**
        * Set 'NoMobile' cookie for current user to prevent use of mobile theme.
        *
        * @since 2.0.?
        * @access public
        */
       public function NoMobile() {
          $Expiration = time() + 172800;
          $Expire = 0;
          $UserID = ((Gdn::Session()->IsValid()) ? Gdn::Session()->UserID : 0);
          $KeyData = $UserID."-{$Expiration}";
          Gdn_CookieIdentity::SetCookie('VanillaNoMobile', $KeyData, array($UserID, $Expiration, 'force'), $Expire);
          Redirect("/", 302);
       }
    

    add this

       public function Mobile() { 
           $Expiration = time() - 172800;
           $Expire = 0; 
           $UserID = ((Gdn::Session()->IsValid()) ? Gdn::Session()->UserID : 0); 
           $KeyData = $UserID."-{$Expiration}";
           Gdn_CookieIdentity::SetCookie('VanillaNoMobile', $KeyData, array($UserID, $Expiration, 'force'), $Expire);  Redirect("/", 302);
    
    }
    

    After adding this code you can put a link to the mobile version on the full site so people can go back to mobile version from full site. http://www.yoursite.com/forum/profile/mobile

    peregrinefr3em1ndUnderDog
  • peregrineperegrine MVP
    edited December 2012 Accepted Answer

    since no one is posting their useragents - I'm guessing what the useragents are for the mobile devices are.

    try adding these lines before line 1285  if you want mobile for the following:
       vanilla/library/core/functions.general.php  
    
    do the same thing for the useragent corresponding to nokia c3
    
    
     if(strpos($UserAgent,'android') > 0 && strpos($UserAgent,'mobile') > 0)
             $Mobile++;
    
    // try inserting  these  lines below -------------------------------------
    
      if(strpos($UserAgent,'android') > 0
            $Mobile++;
    
        if(strpos($UserAgent,'meego') > 0
            $Mobile++;
    
          if(strpos($UserAgent,'blackberry') > 0
            $Mobile++;
    // end of inserted code
    // original code below ------------------------------------------------------
    
          $MobileUserAgent = substr($UserAgent, 0, 4);
          $MobileUserAgents = array(
    

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

    fr3em1ndUnderDog
  • vrijvlindervrijvlinder Papillon-Sauvage MVP

    on firefox with mobile user agents including those the mobile theme works....to the OP try this add on to your browser so you can test this personally it is very handy and helps a lot.You can get any user agent for any device, even windows....lol
    http://chrispederick.com/work/user-agent-switcher/

    peregrine
  • peregrineperegrine MVP
    edited December 2012

    I had been using this

    https://addons.mozilla.org/en-US/firefox/addon/user-agent-rg

    but I like the one by Chris better once you import the other agents.
    that @vrijvlinder posted above.

    looks like this will make most nokia devices mobile theme.

     if(strpos($UserAgent,'symbian') > 0
    $Mobile++;
    

    although one would think the symb in the array would trap it. assuming it was the first four character in the useragent string.

    same with the blac for blackberry

    meeg - however is not in the array - you could add that if you wanted.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • fr3em1ndfr3em1nd ✭✭
    edited December 2012

    hi @peregrine and @vrijvlinder thanks for leading me to the right path.

    after researching and questioning my users, i somehow found out that the user is using UC browser which is not added on the list, my code is:

    if (strpos($AllHttp, 'operamini') > 0 || strpos($UserAgent,'meego') > 0 || strpos($UserAgent,'android') >0  || strpos($UserAgent,'blackberry') >0 || strpos($UserAgent,'nokia') >0 || strpos($UserAgent,'c3') >0 || strpos($UserAgent,'Android') >0 || strpos($UserAgent,'uc') >0)
             $Mobile++;
    

    thanks to you guys now the mobile view is now working on their browsers

    here are the lists of all mobile browsers around
    http://www.webuseragents.com/mobile-browser/

    peregrinevrijvlinder
  • peregrineperegrine MVP
    edited December 2012

    Glad it worked for you @fr3333333x

    A friendly reminder - a little known feature on this forum - is clicking on the insightful button once in a while for people who helped you. Purely optional, but a good forum etiquette - I see hundred of posts where folks received help and the insightful or other button was not clicked. It helps developers and others get points to get "so-called rep" if you occasionally click on those buttons.

    as an aside - if x00 had the insightful button clicked each time he helped with a problem that no one else could solve - he'd have a billion points.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

    vrijvlinder
  • vrijvlindervrijvlinder Papillon-Sauvage MVP

    Glad to know you got it squared away , peregrine is a total expert, I was only telling the truth p ! :)

  • you can predefine functions, to override them. This not related to how you override some controller methods.

    So you could carefully override the IsMobile function by placing it in a conf/boostrap.before.php file, you could put it before the class in a plugin file.

    I would broach this issue on github, really the best way to do this would be a config option to set agents.

    grep is your friend.

    peregrine
  • @x00

    So you could carefully override the IsMobile function by placing it in a conf/boostrap.before.php file,

    I follow the above conf/boostrap.before.php file idea.

    you could put it before the class in a plugin file.

    but what do you mean by "before the class"

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • hbfhbf wiki guy? MVP

    @vrijvlinder said:
    If peregrine's solution is not the cause of the problem (which I doubt coz he is always right), look in the file /forum/applications/dashboard/controllers/class.profilecontroller.php

    check this out

     /**
        * Set 'NoMobile' cookie for current user to prevent use of mobile theme.
        *
        * since 2.0.?
        * access public
        */
       public function NoMobile() {
          $Expiration = time() + 172800;
          $Expire = 0;
          $UserID = ((Gdn::Session()->IsValid()) ? Gdn::Session()->UserID : 0);
          $KeyData = $UserID."-{$Expiration}";
          Gdn_CookieIdentity::SetCookie('VanillaNoMobile', $KeyData, array($UserID, $Expiration, 'force'), $Expire);
          Redirect("/", 302);
       }
    

    add this

       public function Mobile() { 
           $Expiration = time() - 172800;
           $Expire = 0; 
           $UserID = ((Gdn::Session()->IsValid()) ? Gdn::Session()->UserID : 0); 
           $KeyData = $UserID."-{$Expiration}";
           Gdn_CookieIdentity::SetCookie('VanillaNoMobile', $KeyData, array($UserID, $Expiration, 'force'), $Expire);  Redirect("/", 302);
    
    }
    

    After adding this code you can put a link to the mobile version on the full site so people can go back to mobile version from full site. http://www.yoursite.com/forum/profile/mobile

    why not just remove the 'vanillanomobile' cookie instead of setting it with an expiry in the past? sure that works but it's not really the cleanest way to go about it.

Sign In or Register to comment.