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

Automatic Style Switch

brendanc

Active member
#1
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?
 

brendanc

Active member
#5
To stop members being spoofed.
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
 

Mike

XenForo developer
Staff member
#6
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. :)
 

brendanc

Active member
#7
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. :)
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?
 

Jake Bunce

XenForo moderator
Staff member
#8
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?
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
 

Attachments

brendanc

Active member
#9
I made this simple addon for you.
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!
 
#15
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.
 

Jake Bunce

XenForo moderator
Staff member
#17