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

Sessions, Logins and Themes for Mobile Users

edited January 2011 in Vanilla 2.0 - 2.8
I'm trying to set the theme based on the HTTP_USER_AGENT string.

I have a plug-in that works as long as the user is logged-in. The constructor is below. Unfortunately if the user isn't logged in I can't set the Preview Theme. Does anyone know how to set this or if there is any other way to change the theme for a specific user session. When I changed the theme with the EnabledTheme method it changed it for all users.

public function __construct() { /** * Set the theme temporarily to a mobile theme if the browser matches or it is forced */ $Session = Gdn::Session(); $PreviewThemeName = $Session->GetPreference('PreviewThemeName', 'default'); if ( $PreviewThemeName == 'mobile' && $_GET['mobile'] == "false" ) { $Session->SetPreference('PreviewThemeName', 'vanilla'); $Session->SetPreference('PreviewThemeFolder', 'vanilla'); } elseif ( $this->checkmobile() || $_GET['mobile'] == "true" || $PreviewThemeName == 'mobile' ) { $PreviewThemeName = $Session->SetPreference('PreviewThemeName', 'mobile'); $PreviewThemeFolder = $Session->SetPreference('PreviewThemeFolder', 'mobile'); } }

Comments

  • Options
    Looking through bootstrap.php and some of the classes that are called, the global Gdn::Session()->UserID is set after the authenticator is called. I am not clear yet when the theme gets chosen (looks like before the session is setup but I have not tested it) but you could try testing against:

    Gdn::Session()->UserID

    Something like:

    if(Gdn::Session()->UserID>0) { // do logged in stuff } else { // do not logged in stuff }

    If that does not fire, it is likely due to the order of things in bootstrap.php. They support a custom post bootstrap so you may be able to recall your constructor there after the session has been setup.

    Cheers
  • Options
    Thanks,

    But clearly I'm an idiot. Adding this to the config file solved my problem:

    $Configuration['Garden']['MobileTheme'] = 'mobile';
Sign In or Register to comment.