Jump to content

Theme override at URL?


Nakamura RTS

Recommended Posts

Posted

Hi all,

Would be great if someone could help. I'm trying to override the theme on my site at a certain set of URLs. The site for reference: https://meta-plays.com/landing/

Note how when you choose a game from the landing page, a "game ID" (e.g 5 or 60) gets appended to everything you visit, until you go back to the landing page and pick another game. This is how we filter the content on the site to only display what we want on a per game basis. For example, the Age of Mythology link will lead to the portal app, but because we are on game=5, only content that matches that ID is shown.

I'd like each of the games to have a different theme, it's not enough to change it for the forum sections, as the other "page" apps (portal, youtube, twitch) will not be changable correctly. 

I think the solution lies in forcing a theme override at a URL. My question is, how would I set up such a script, and what file would I put that in? Below is a proto script to display what I am trying to accomplish:

{{if(location.href.split("&game=")[1] == 5)}}
 {{ \IPS\Theme::switchTheme(9);}}
{{endif}}
Posted
On 4/27/2018 at 2:08 PM, newbie LAC said:

Hello,

Open \applications\portal\modules\front\portal\portal.php

Add in manage method


if (\IPS\Request::i()->game == 5)
{
	\IPS\Theme::switchTheme(9);
}

 

Thanks, this works for the portal app, but how can it be changed globally? Eg the downloads/leaderboards etc apps remain unaffected. Also, is there a way to override user preference, or to hide the theme picker?

  • 4 months later...
Posted
On 4/27/2018 at 3:08 PM, newbie LAC said:

Hello,

Open \applications\portal\modules\front\portal\portal.php

Add in manage method


if (\IPS\Request::i()->game == 5)
{
	\IPS\Theme::switchTheme(9);
}

 

 

Hello,

this is very interresting, would this work with usergroups too? I'm new to this software and already have seen that themes can be made availiable for specific usergroups. But not to set a theme as a kind of "default" theme for a group, am I right?

My idea is...

- Guests visit the page and see theme one.

- After signup the member automatically uses theme two (without selecting it manually).

- A member upgrades to premium (different usergroup) and automatically has a premium theme selected.

There is no need that they can change the theme anymore, only that every group uses automatically it's own theme without selecting it.

I have searched this forum and this was the closest topic I have found. It would be great if somebody could help me with this :)

Best regards

Posted

It's possible but would require a very simple custom plugin or app to accomplish this, just use the MemberSync extension to change the skin.

Guests => get only the default theme
Once they register ( MemberSync::onCreateAccount ) set the theme ( $member->skin = $newSkinID;) and the same on account upgrade( MemberSync::onProfileUpdate) 

Posted

OK, so now I created an application and in the php file the system created for me I have tried the following code...

 

	/**
	 * Member account has been updated
	 *
	 * @param	$member		\IPS\Member	Member updating profile
	 * @param	$changes	array		The changes
	 * @return	void
	 */
	public function onProfileUpdate( $member, $changes )
	{
			$member->skin = $5;
	}

I only added the $member->skin  = $5; but that doesn't seem to work?

  • 5 weeks later...
  • 5 weeks later...
Posted

I assume you want the URL theme.php?theme=X to set that theme ID for the user?

If so, you would need to create a theme.php file, load the Invision Suite framework within it, look for the theme ID in the URL, and set it for the member. Roughly, that would look like

<?php

require 'init.php';
\IPS\Dispatcher\External::i();
\IPS\Session\Front::i();

if( \IPS\Member::loggedIn()->member_id )
{
	\IPS\Member::loggedIn()->skin = (int) \IPS\Request::i()->theme;
	\IPS\Member::loggedIn()->save();
}

// Then what do you want to do? Redirect perhaps?
\IPS\Output::i()->redirect( \IPS\Http\Url::internal('') );

The above code doesn't check the validity of the theme ID being passed (or indeed that one is even present) so you should work on it further to ensure the code is secure to your liking, but hopefully this gives you an idea of what you'll need to look at doing.

  • 3 weeks later...
Posted
On 11/26/2018 at 10:40 AM, bfarber said:

I assume you want the URL theme.php?theme=X to set that theme ID for the user?

Actually, yes.

On 11/26/2018 at 10:40 AM, bfarber said:

If so, you would need to create a theme.php file, load the Invision Suite framework within it, look for the theme ID in the URL, and set it for the member. Roughly, that would look like

How would I go about this on running this script by creating a plugin? Or application?

Posted
On 12/19/2018 at 7:31 AM, bfarber said:

If you create an application, you can use the FURL system to route "theme.php" to a controller in your application which can do this. This might be the cleanest approach.

Okay.

I created the app, with a new module called "themes", and named the controller "theme.php".

How would go about this putting the code inside the theme.php file?

/**
 * theme
 */
class _theme extends \IPS\Dispatcher\Controller
{
	/**
	 * Execute
	 *
	 * @return	void
	 */
	public function execute()
	{

		parent::execute();
	}

	/**
	 * ...
	 *
	 * @return	void
	 */
	protected function theme()
	{
		
	}
}

I read the docs on the controllers and routing & urls, but I'm having a hard time understanding it.

Posted

If you want visiting "theme.php" to reach this controller, you will need to define a friendly URL (furl) rule for the URL. Create a furl.json in your application's data directory, and then copy over the structure from another app and set the rule as appropriate to route to this controller (which will be at app=(yourapp)&module=themes&controller=theme based on what you've said). Then in the manage() method you'll check for the incoming ID and set the viewing member's theme as appropriate.

Posted
On 12/21/2018 at 7:43 AM, bfarber said:

Create a furl.json in your application's data directory, and then copy over the structure from another app and set the rule as appropriate to route to this controller (which will be at app=(yourapp)&module=themes&controller=theme based on what you've said).

Okay. Is this correct?

{
	"topLevel": "",
	"pages": {
		"theme_theme": {
    		"friendly": "theme.php?theme={#id}",
    		"real": "app=themetreethemeid&module=theme&controller=theme"
		}
	}
}

The URL will be http://example.com/index.php?/theme.php?theme=X, right?

Posted

I'm still trying to wrap this around my head by updating the JSON file in my previous post.

When I do this new change, it throws an error at me saying, "Cannot declare class IPS\IPS, because the name is already in use".

I know I'm doing something wrong here because I'm new to this.

Posted

Not sure why you want to create an app and don't use inbuilt methods

{{if $themes = \IPS\Theme::getThemesWithAccessPermission() and count($themes) > 1}}
	<ul class='ipsList_inline'>
		{{foreach $themes as $id => $theme}}
			<li>
				<a href="{url="app=core&module=system&controller=theme&id={$id}" csrf="true" seoTemplate="theme"}">
					{$theme->_title}
				</a>
			</li>
		{{endforeach}}
		</ul>
{{endif}}

 

Posted
11 hours ago, newbie LAC said:

Not sure why you want to create an app and don't use inbuilt methods

By creating an app, I can get the theme ID in the URL. The inbuilt method as you stated doesn't do this specifically for calling the theme ID's.

That's why I'm trying to understand on how to do this.

Posted
12 hours ago, Brian A. said:

By creating an app, I can get the theme ID in the URL. The inbuilt method as you stated doesn't do this specifically for calling the theme ID's.

That's why I'm trying to understand on how to do this.

Have you tested my code?

Each link contain theme ID

&id={$id}

 

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...