1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Automatic Style Switch

Discussion in 'XenForo Questions and Support' started by brendanc, Dec 13, 2011.

  1. brendanc

    brendanc Active Member

    Hi all,

    Is there a way I can automatically switch the theme via the URL? For example, let's say I have two domains, websiteA.com and websiteB.com. I want websiteA.com to have one theme, and websiteB.com to have a different theme, but both point to the same directory on the server (and hence the same installation of XenForo).

    I know you can use /misc/style?style_id={insert style id # here}, but it gives you a page that asks you to confirm use of the theme.

    Is there a way I can automatically switch the style, either via URL/htaccess or plugin?
     
  2. Brogan

    Brogan XenForo Moderator Staff Member

    Not for logged in members.

    They have to confirm the style switch.
     
  3. brendanc

    brendanc Active Member

    Is there a really good reason for this?
     
  4. Brogan

    Brogan XenForo Moderator Staff Member

    To stop members being spoofed.
     
  5. brendanc

    brendanc Active Member

    Spoofed by whom, though? Their own site administrator?

    I'm going to see if I can't make a modification that gets around this issue, because in my case, it's just an unnecessary precaution against nothing. I have two themes that are identical except for graphic and color changes. You can't even link to a thread and change the style simultaneously, so it seems a little overboard.

    At the very least I think it should be an option... i.e. [checkbox] Users must confirm style change
     
  6. Mike

    Mike XenForo Developer Staff Member

    It's really just following a standard HTTP approach: things that change values should be done only over POST. Otherwise, I can just stick an image in my signature (for example) that would go randomly changing visitors' styles every time they viewed it. :)
     
    Darkimmortal likes this.
  7. brendanc

    brendanc Active Member

    I see your point. I haven't looked into it yet, but might there be a way to change it via the XenForo developer api? I think there is a modification already that switches the theme based on browser agent (for mobile themes). Maybe I could modify that to check the URL?
     
  8. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    I made this simple addon for you. But you need to edit the library/StyleOverride/Listen.php file to specify the domains and their style_ids:

    Code:
    <?php
    
    class StyleOverride_Listen
    {
    	public static function listen(XenForo_Controller $controller, $action)
    	{
    		$visitor = XenForo_Visitor::getInstance();
    		$host = $controller->getRequest()->getServer('HTTP_HOST');
    
    		if ($host == 'www.domain1.com')
    		{
    			$visitor['style_id'] = 3;
    		}
    		else if ($host == 'www.domain2.com')
    		{
    			$visitor['style_id'] = 2;
    		}
    		// DEFAULT STYLEID, IF NONE OF THE DOMAINS MATCH
    		else
    		{
    			$visitor['style_id'] = 3;
    		}
    	}
    }
    
    Also, all of the style_ids you set must be user-selectable:

    Screen shot 2011-12-13 at 9.09.39 PM.png
     

    Attached Files:

    Digital Doctor and brendanc like this.
  9. brendanc

    brendanc Active Member

    Awesome. I'm going to make some modifications to this and make it admin panel friendly.

    It may not be readily apparent, but I'm actually a full time developer. I've been so busy with work that I haven't had a decent chance to learn XF addon development. I still don't really have time :p but this will be a start :) Thanks again for the code!
     
  10. thebush

    thebush Member

    This is what I'm searching :)
    Any updates with this script @Jake ?
     
  11. thebush

    thebush Member

    Any tutorials on how to set 2 domains (different directory inside a single server) using the same database ?
     
  12. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    XF can only reside in one directory. But if you have multiple domains pointing to the same directory then you can use this addon.
     
    alexD likes this.
  13. thebush

    thebush Member

    How to point 2 domains to a single directory ?
     
  14. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    It's called domain parking. You can park another domain on an existing web site. You can ask your host to do this.
     
    thebush likes this.
  15. thebush

    thebush Member

    Thank you!
    I'm on a shared hosting, i've seen this option on cpanel.
    Is it OK if i will do this myself?
    Is it possible to do this also in my localhost?
    xampp installation.
     
  16. thebush

    thebush Member

  17. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    Yes. CPanel has a section called "Parked Domains".

    Nope. They need to be different host names which is the "localhost" part.
     
    thebush likes this.
  18. thebush

    thebush Member

    Not working on my localhost with 2 directory :(
     
  19. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    thebush likes this.
  20. thebush

    thebush Member

    What about the cookies? Login isue ?
     

Share This Page