Resource icon

Different style per domain (code example) 1.x

No permission to download
how to get the same but for a different style if guest or member?

Rich (BB code):
<?php

class StyleOverride_Listen
{
	public static function listen(XenForo_Controller $controller, $action)
	{
		$visitor = XenForo_Visitor::getInstance();

		// STYLE FOR MEMBERS
		if ($visitor['user_id'])
		{
			$visitor['style_id'] = 3;
		}
		// STYLE FOR GUESTS
		else
		{
			$visitor['style_id'] = 2;
		}
	}
}
 
Is it possible to adapt this code so it redirects based on the request headers instead of host? Something like this (non-functional) example:
Code:
<?php
 
class StyleOverride_Listen
{
    public static function listen(XenForo_Controller $controller, $action)
    {
        $visitor = XenForo_Visitor::getInstance();
        $headers = $controller->getRequest()->getallheaders();  // No idea how these two lines would go
        if(($headers['X-PJAX'] == 'true'))
        {
            $visitor['style_id'] = 1;
        }
 
        else
        {
            $visitor['style_id'] = 7;
        }
    }
}

Any assistance is greatly appreciated :) Thanks!
 
It's always "possible."

This returns the specified key:

Code:
$host = $controller->getRequest()->getServer('HTTP_HOST');

Just use a different key.

Or this will return the whole $_SERVER array:

Code:
$host = $controller->getRequest()->getServer();
 
Thank you Jake.

That helps. I've tried a few variations and combinations on this, but I'm still unclear on where the X-PJAX header is actually being set and how it can be tested against with getServer().

The client side JS making the page request looks like the following:
Code:
xmlhttp.open("GET", location + ((!/[?&]/.test(location)) ? '?_pjax' : '&_pjax'), true);
//Add headers so things can tell the request is being performed via AJAX.
xmlhttp.setRequestHeader('X-PJAX', 'true'); //PJAX header
xmlhttp.setRequestHeader('X-Requested-With', 'XMLHttpRequest');//Standard AJAX header.

I've tried testing against HTTP_USER_AGENT and other headers with no luck. I'm not a PHP guy by any stretch, so I'm not getting anywhere fast.

If you can see a solution here, I'd be quite happy to pay for your time. I'd much rather get back to design work :)

I've been testing variations like:
Code:
<?php
 
class StyleOverride_Listen
{
    public static function listen(XenForo_Controller $controller, $action)
    {
        $visitor = XenForo_Visitor::getInstance();
 
        // $host = $controller->getRequest()->getServer('HTTP_HOST');
        $host = $controller->getRequest()->getServer('X-PJAX');
 
        // if(($host['X-PJAX'] == 'true'))
        if ($host == 'true')
        {
            $visitor['style_id'] = 9;
        }
    }
}
 
I've started reading through the docs, but haven't come across anything that seems relevant just yet.

I'll put a $50USD bounty on this to start with, for anyone that can provide a working conditional to test for the header set in the ajax page request. It must be something fairly trivial.

To be honest, this PHP is well within the realm of things I don't know and don't want to know :) If I can provide a working proof of concept here, I'll have proper help for any PHP moving forward.

This is all for an interesting side project that's a new interface for thread_list+thread_view.
Thread_list is in the left column, and the thread_view "view" is the right column (populated by pjax). I'm using pjax (ajax plus push-state, etc), so the browser history and address-bar stays functional too. It's working better than I expected, already tests well on iPad. The biggest issue is that ajax container is still receiving a bulky full-sized Xenforo page. I've created a stripped down child-style that only returns this content, which I'm hoping to return whenever the source request has an X-PJAX header set.



Screen%20Shot%202013-05-09%20at%2015.40.51.png
 
I think we're close to a solution here. The following is likely correct, but it's our nginx config which is dropping the X-PJAX header before it gets to PHP.
Code:
<?php
 
class StyleOverride_Listen
{
    public static function listen(XenForo_Controller $controller, $action)
    {
        $visitor = XenForo_Visitor::getInstance();
        $host = $controller->getRequest()->getServer('X-PJAX');
        if ($host == 'true')
        {
            $visitor['style_id'] = 9;
        }
    }
}
 
Im wanting to have force a different style for guests use xenforo 1.2.x. hope this works
 
Last edited:
Rich (BB code):
<?php

class StyleOverride_Listen
{
public static function listen(XenForo_Controller $controller, $action)
{
$visitor = XenForo_Visitor::getInstance();

// STYLE FOR MEMBERS
if ($visitor['user_id'])
{
$visitor['style_id'] = 3;
}
// STYLE FOR GUESTS
else
{
$visitor['style_id'] = 2;
}
}
}

How can I do this so that members can still select a style once logged in. I just want to to show a style for guests while members either get the default style (different to guests style) or the one previously selected

ie im just wanting to force a different style for guests
 
Guests don't have a user_id, so you can check for guests that way.

Code:
if (!$visitor['user_id'])
{
$visitor['style_id'] = 3;
}
 
Has there been any work done expanding this so that you could set the board title & board meta description per domain as well.
I'd also like to see the emails that are sent out to link back to the domain the user came in on. As it is if they register on domain 2 they get an email from the primary board's info and receive the email from the primary board to confirm the registration. I think that's confusing to the user, so for now I disabled email verification.
 
Are additional Xenforo licenses needed for this?

In particular i would use this to give each sub-domain style its own logo image, change home link to point to sub-domain and change some custom sidebar templates.
 
Last edited:
I'd like to use this to have different set of styles available per subforum. Would something like that be possible?
 
Yes, but it's only one style and it's enforced. I wanted it to limit the style choice. Or just for example basing on the nodes name - change the background and title of forum.
 
I'd like to code it myself. Could you poke me in the right direction? If you think that we should PM about it to not derail the thread further - just message me there.
 
Top Bottom