Automatic Style Switch

  • Thread starter Thread starter Deleted member 2163
  • Start date Start date
D

Deleted member 2163

Guest
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?
 
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
 
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. :)
 
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?
 
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:

Rich (BB 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.webp
 

Attachments

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!
 
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.
 
Top Bottom