Nakamura RTS Posted April 26, 2018 Posted April 26, 2018 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}}
newbie LAC Posted April 27, 2018 Posted April 27, 2018 Hello, Open \applications\portal\modules\front\portal\portal.php Add in manage method if (\IPS\Request::i()->game == 5) { \IPS\Theme::switchTheme(9); }
Nakamura RTS Posted April 29, 2018 Author Posted April 29, 2018 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?
bfarber Posted April 30, 2018 Posted April 30, 2018 You could create a plugin that overloads the \IPS\Theme::i() to control which theme gets loaded.
WP V0RT3X Posted September 23, 2018 Posted September 23, 2018 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
Daniel F Posted September 23, 2018 Posted September 23, 2018 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)
WP V0RT3X Posted September 23, 2018 Posted September 23, 2018 Thank you for the quick reply, Daniel :) Now I only have to find out how to create a "very simple custom plugin or app" at all 😄
WP V0RT3X Posted September 23, 2018 Posted September 23, 2018 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?
Daniel F Posted September 23, 2018 Posted September 23, 2018 Please try $member->skin = 5; $member->save();
WP V0RT3X Posted September 23, 2018 Posted September 23, 2018 Yes, seems to work, thank you very much :)
Mercury Forever Posted October 23, 2018 Posted October 23, 2018 Hello @newbie LAC How can I know the ID of a theme? Thanks.
Nathan Explosion Posted October 23, 2018 Posted October 23, 2018 Hover over the 'Edit HTML and CSS' button....
Brian A. Posted November 21, 2018 Posted November 21, 2018 How would I do this by creating a plugin? Do I have to extend a class by creating a code hook? Trying to make the URL to: theme.php?id={THEME ID}
Brian A. Posted November 25, 2018 Posted November 25, 2018 Anybody? Does anyone know on how to do this please?
Pete T Posted November 25, 2018 Posted November 25, 2018 2 hours ago, Brian A. said: Anybody? Does anyone know on how to do this please? is this so if clicked link go to correct theme ?
bfarber Posted November 26, 2018 Posted November 26, 2018 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.
Brian A. Posted December 17, 2018 Posted December 17, 2018 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?
bfarber Posted December 19, 2018 Posted December 19, 2018 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.
Brian A. Posted December 21, 2018 Posted December 21, 2018 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.
bfarber Posted December 21, 2018 Posted December 21, 2018 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.
Brian A. Posted December 23, 2018 Posted December 23, 2018 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?
Brian A. Posted December 24, 2018 Posted December 24, 2018 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.
newbie LAC Posted December 25, 2018 Posted December 25, 2018 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}}
Brian A. Posted December 25, 2018 Posted December 25, 2018 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.
newbie LAC Posted December 26, 2018 Posted December 26, 2018 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}
Recommended Posts
Archived
This topic is now archived and is closed to further replies.