chaging style on the fly

All style (template, theme and imageset) related questions for the new release; advice, feedback here please.
Post Reply
tiger2kn5
Registered User
Posts: 49
Joined: Tue Jul 10, 2001 2:59 am
Location: US of A

chaging style on the fly

Post by tiger2kn5 »

I know its possible to have forums have different styles, what im trying to do is a bit different.

Any way change to a different style even if that style is not defined in the database, but you know that it exists locally.

HERE's The code im working with

Code: Select all

define('IN_PHPBB', true);
$phpbb_root_path = './foro/';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.'.$phpEx);
include('site_common.'.$phpEx); // site common definitions

// Start session management
$user->start();
$auth->acl($user->data);
$user->setup();

// get passed variables
$artist_url_name	= request_var('artist', '');
$page_id			= request_var('page', '');

// redirect back to the main page if no artist is picked
if (!$artist_url_name) {
	trigger_error('Direct Access to this file is not allowed');
}

// Grab the artists information
$sql = 'SELECT *
	FROM ' . ARTIST_TABLE . "
	WHERE url_name = '" . $artist_url_name . '\'';
$result = $db->sql_query($sql);

// store the info into an array or display an error that artist does not exists
if ($artist = $db->sql_fetchrow($result)) {
	$db->sql_freeresult($result);
} else {
	trigger_error('That artist does not exists');
}

// CHANGING TEMPLATES IN HERE

// set some default artist template values
$template->assign_vars(array(
	'A_DISPLAY_NAME'	=> $artist['display_name'],
	'A_SLOGAN'			=> $artist['slogan'],
	'A_URL_NAME'		=> $artist_url_name,
	'A_DISPLAY_NAME'	=> $artist['display_name'],
	'A_LOCATION'		=> $artist['location'],
	'A_CITY'			=> $artist['city'])
);

// display the tabs
$tabs = array(
	// page_id, display_name, link
	array('', 'Pagina', '/'.$artist_url_name),
	array('musica', 'Musica', '/'.$artist_url_name.'/musica'),
	array('fotos', 'Fotos', '/'.$artist_url_name.'/fotos'),
	array('contacto', 'Contacto', '/'.$artist_url_name.'/contacto')
);

// process each tab
foreach($tabs as $tab)
{
	// send each tab's information to the template
	$template->assign_block_vars('tab', array(
		'TAB_CLASS'  => ($tab[0] == $page_id) ? 'tab_sel' &#58 'tab',
		'TAB_TEXT'  => $tab[1],
		'TAB_LINK'  => $tab[2])
	);
}
unset($tabs); // not needed anymore, save some memeory

// get the information for the page we are in
switch ($page_id)&#58
case "musica"&#58
	$page_template = 'artist_templates/' . $artist['page_style'] . '_music.htm';
break;
default&#58
   $page_template = 'site_home_page.htm';
endswitch;

// Let the templates know that we are in the site, and not the forum
$template->assign_var('IN_SITE', true);

// Output page
page_header($artist['artist_display_name']);

$template->set_filenames(array(
	'body' => $page_template)
);

page_footer();
where it says // CHANGING TEMPLATES IN HERE thats where i want to have the code to changing the style, but the styles i want to change to will not be defined in the style database. I though i could use
$user->setup(); but apperently not.


NOT ASKING FOR SUPPORT ON PHPBB, SIMPLY SUGGESTION ON HOW YOU GUYS THINK I COULD GO ABOUT DOING THIS
Image

Spectral Dragon
Registered User
Posts: 208
Joined: Mon Feb 16, 2004 1:45 pm
Location: Milan, MI
Contact:

Re: chaging style on the fly

Post by Spectral Dragon »

not exactly sure what your doing here, but if your thinking of adding several styles to a board that is allready possible in both the 2 series and I believe in the upcoming 3 as well.

User avatar
Viperal2
Registered User
Posts: 223
Joined: Tue Jun 08, 2004 9:28 pm
Contact:

Re: chaging style on the fly

Post by Viperal2 »

He taking about changing the style for inside his script.

just do

Code: Select all

$user->setup(false, $style);
where you have

Code: Select all

// CHANGING TEMPLATES IN HERE
you can remove both $user->setup(); from on top of your script, since it you don't need any of the user function before you comment // CHANGING TEMPLATES IN HERE, not the mention you doing the same processing over again ;)

Edit: add bbcode, code[/c ode];
What is The Viperal ?

http://developer.berlios.de/projects/viperals/" target="_blank

tiger2kn5
Registered User
Posts: 49
Joined: Tue Jul 10, 2001 2:59 am
Location: US of A

Re: chaging style on the fly

Post by tiger2kn5 »

[quote="Viperal2"]
He taking about changing the style for inside his script.

just do

Code: Select all

$user->setup(false, $style);
where you have

Code: Select all

// CHANGING TEMPLATES IN HERE
you can remove both $user->setup(); from on top of your script, since it you don't need any of the user function before you comment // CHANGING TEMPLATES IN HERE, not the mention you doing the same processing over again ;)

Edit: add bbcode, code[/c ode];
[/quote]


Thanks man, that worked like a charm :mrgreen:

The funny thing was that i tried that, but it didn't work before. I think it was because i was calling $user->setup(); twice, with regular, and the other with the optional arguments.
Image

tiger2kn5
Registered User
Posts: 49
Joined: Tue Jul 10, 2001 2:59 am
Location: US of A

Re: chaging style on the fly

Post by tiger2kn5 »

I take it back, it doesnt work. It was working from the cache, when i emptied the cache directory, then it started giving the error again. I even tried copying the SubSilver style folder and renaming it to my style folder, and for some reason its still looking in subSilver

Code: Select all

template->_tpl_load_file()&#58 File styles/subSilver/template/musica.htm does not exist or is empty

I think is a bug, I think ill just put everything in the subsilver style until beta :(
Image

User avatar
Viperal2
Registered User
Posts: 223
Joined: Tue Jun 08, 2004 9:28 pm
Contact:

Re: chaging style on the fly

Post by Viperal2 »

tiger2kn5 wrote: I take it back, it doesnt work. It was working from the cache, when i emptied the cache directory, then it started giving the error again. I even tried copying the SubSilver style folder and renaming it to my style folder, and for some reason its still looking in subSilver

Code: Select all

template->_tpl_load_file()&#58 File styles/subSilver/template/musica.htm does not exist or is empty

I think is a bug, I think ill just put everything in the subsilver style until beta :(
opps forgot about this post.

First did you install the new theme, also from looking at the coding it looks for a style_id not style name; so you'll have to get that from the database.

I'll install phpBB3 tomorrow and test it, will tell you what I find unless it's a bug ( you know the policy ) ;) ....
What is The Viperal ?

http://developer.berlios.de/projects/viperals/" target="_blank

tiger2kn5
Registered User
Posts: 49
Joined: Tue Jul 10, 2001 2:59 am
Location: US of A

Re: chaging style on the fly

Post by tiger2kn5 »

I got it working now. The problem was that i was installign the styles manually, (just putting the information into the style & template tables, the style uses the same theme as subSilver). And i guess theres some extra step then just add the info to those tables in the databse. So when I installed the styles using phpBB's admin panel it worked fine.

Guess i have to study how the styles are installed some more. Eventually Im going to have my own script installing styles, Because i want the users to be able to install styles. I know this screams security problems but the styles are not going to be for the forum. If you notice by the script its for artist, Each artist is going to have their own mini-site, and thats what the styles they create will be used for. So the styles they will be able to upload will simply have at the most 10 templates which are just used for the mini-sites, so hopefully that won't cause any problems ;)

Another problem that was trowing it off was that the mini-site styles only have the templates necessary for the mini-site and doesn't have the templates requiered by phpBB, so everytime it called trigger_error(); it was calling for message_body.html which isn't in the style. So what i did was edit trigger_error function to revert back to the main style (subSilver) if it has to display an error.
Image

Post Reply