MyBB Community Forums

Full Version: Theme change with URL ?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I know there's a theme-changer by Ryan, but that's not what I'm after. Toungue

Is this possible with some modifications / plug in for the MyBB code structure. ?

Example: s=?? is the style id in the Db. Wink

http://php.esperanzadata.se/EasyPhoenix/forum.php?s=10
http://php.esperanzadata.se/EasyPhoenix/forum.php?s=8

Of course - If it is possible as a plug-in, it would be nice if it wasn't done by anyone who would not make it freely available here at MyBB. Sad
Quick theme with a few changes...

<?php

// Disallow direct access to this file for security reasons
if(!defined("IN_MYBB"))
{
	die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
}

$plugins->add_hook("pre_output_page", "quicktheme_run");
$plugins->add_hook("index_start", "quicktheme_update");
$plugins->add_hook("global_start", "quicktheme_global");

function quicktheme_info()
{
	return array(
		"name"			=> "Quick Theme!",
		"description"	=> "A plugin that allows users to quickly change their theme!",
		"website"		=> "http://mods.mybboard.net/view/quick-theme",
		"author"		=> "Tikitiki",
		"authorsite"	=> "http://thetikitiki.com",
		"version"		=> "1.1.2",
		"compatibility" => "14*",
		"guid" 			=> "a60f0c103e0e4d4468e10604a76fe570",
	);
}

function quicktheme_activate()
{
}

function quicktheme_deactivate()
{
}

function quicktheme_run($page)
{
	global $mybb, $db, $lang;
	
	$lang->load("usercp");
	
	$theme_select = build_theme_select("style", $mybb->user['style']);
		
	if(strpos($theme_select, '</select>') === false)
	{
		$theme_select .= '</select>';
	}
		
	$data = "<form method=\"get\" action=\"./index.php?action=quicktheme\">\n<span class=\"trow2\" style=\"float: right; border: 1px solid #000000; padding: 1px;\">\n";
	$data .= "<input type=\"hidden\" name=\"uid\" value=\"{$mybb->user['uid']}\" />";
	$data .= "<span class=\"smalltext\"><strong>&nbsp;Quick Theme:</strong> ".$theme_select;
	$data .= "</span>\n<input type=\"submit\" value=\"Change Theme\" />\n";
	$data .= "</span>\n</form>\n<br />";		
	
	preg_match('#'.preg_quote('<!-- start: footer -->').'#i', $page, $matches);
	if($matches[0])
	{
		$page = str_replace($matches[0], "<br />".$data."\n<!-- start: footer -->", $page);
	}
	
	return $page;
}

function quicktheme_update()
{
	global $mybb, $db, $lang;

	if(!empty($mybb->input['style']))
	{
		$lang->load('usercp');

		if($mybb->user['uid'])
		{ 
			$db->update_query("users", array('style' => intval($mybb->input['style'])), "uid='{$mybb->user['uid']}'");
		}
		else
		{
			if(intval($mybb->input['style']) == 0)
			{
				my_unsetcookie('quicktheme');
			}
			else
			{
				my_setcookie('quicktheme', intval($mybb->input['style']));
			}
		}
		
		redirect('index.php', $lang->redirect_optionsupdated);
	}
}

function quicktheme_global()
{
	global $mybb;
	
	if($mybb->user['uid'] == 0 && intval($mybb->cookies['quicktheme']) > 0)
	{
		$mybb->user['style'] = intval($mybb->cookies['quicktheme']);
	}
}

?>

Example: index.php?style=2
No! That's not going to work unfortunately, and the whole concept behind the proposal is to be able to also add images to the url within a template or javascript function.

e.g.
<tr>
<td>
<a href="http://whatever/index.php?style=1"><img src="whatever-style-pic.png" alt="" />Default</a>

<a href="http://whatever/index.php?style=6"><img src="whatever-style-pic.png" alt="" />Another Style</a>
</td>
</tr>

Edit:

It really needs an extension switch to action index.php to query the database for the style, and then load it. Wink
*Bump!*

I'm quickly losing interest in this through lack of any response from the "Powers that be" Toungue
Learn to wait.
Yeah! terrific response to the question - I dont think so. Sad

16 days between post and bump would not indicate that one runs out of patience. Toungue

Maybe I'll forget the whole idea and let you people get on with it.
http://mods.mybb.com/view/mytheme

URLs are generated like so:

http://example.com/index.php?action=mytheme&style=1

Whereas 1 is the number ID of the theme.
Did no one notice this thread is 2 years old