[2.0.20] Random Style for Guests

All new MODs released in our MOD Database will be announced in here. All support for released MODs needs to take place in here. No new MODs will be accepted into the MOD Database for phpBB2
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

On February 1, 2009 this forum will be set to read only as part of retiring of phpBB2.

Rating:

Excellent!
4
100%
Very Good
0
No votes
Good
0
No votes
Fair
0
No votes
Poor
0
No votes
 
Total votes: 4

Extensions Robot
Extensions Robot
Extensions Robot
Posts: 29056
Joined: Sat Aug 16, 2003 7:36 am

[2.0.20] Random Style for Guests

Post by Extensions Robot »

MOD Name: Random Style for Guests
Author: DavidIQ
MOD Description: Selects a random style from the ones installed on the board for guests viewing the forum. Cookie is expired after 15 minutes.


MOD Version: 1.0.1

Download File: Random_Style_for_Guests_1.mod
mods overview page: View
File Size: 2833 Bytes

Security Score: 0

Support for this MOD needs to be asked within this topic. The phpBB Teams are not responsible or required to give anyone support for this MOD. By installing this MOD, the phpBB Support Team or phpBB MODifications Team may not be able to provide support.

This MOD has only been tested by the phpBB MOD Team with the phpBB version in the topic title. It may not work in any other versions of phpBB.
Last edited by Extensions Robot on Mon Apr 30, 2007 12:28 am, edited 1 time in total.
(this is a non-active account manager for the phpBB Extension Customisations Team)
ycl6
Translator
Posts: 5696
Joined: Sat Feb 15, 2003 10:35 am
Location: Taiwan
Contact:

Post by ycl6 »

MOD Validated/Released

Notes:
This MOD apply random forum styles for guests.
User avatar
DavidIQ
Customisations Team Leader
Customisations Team Leader
Posts: 18034
Joined: Thu Jan 06, 2005 1:30 pm
Location: Fishkill, NY
Name: David Colón
Contact:

Post by DavidIQ »

Awesome...I can add another item to my signature :lol:

Well just to let those interested know, I'm working on another version that will also allow registered users to set this up for themselves as well.
Apply to become a Jr. Extension Validator
My extensions | In need of phpBB services? | Was I helpful today?
No unsolicited PMs unless you're planning on asking for paid help.
mariocaz
Registered User
Posts: 87
Joined: Tue Jun 07, 2005 6:49 am
Location: Mexico, D.F.
Contact:

Post by mariocaz »

Very very nice, little and useful mod my friend congratulations! :P

I installed in my forum and I am very happy with it. :wink:

Cheers. :D
abramelin
Registered User
Posts: 79
Joined: Sat Apr 08, 2006 6:31 pm

Post by abramelin »

can i make this for registered users?
User avatar
DavidIQ
Customisations Team Leader
Customisations Team Leader
Posts: 18034
Joined: Thu Jan 06, 2005 1:30 pm
Location: Fishkill, NY
Name: David Colón
Contact:

Post by DavidIQ »

abramelin wrote: can i make this for registered users?

Well you could make it hard coded for registered users but I don't know that all of your users would be very appreciative of it if you did that.
Apply to become a Jr. Extension Validator
My extensions | In need of phpBB services? | Was I helpful today?
No unsolicited PMs unless you're planning on asking for paid help.
abramelin
Registered User
Posts: 79
Joined: Sat Apr 08, 2006 6:31 pm

Post by abramelin »

how can i make it?can you give some example codes?
User avatar
DavidIQ
Customisations Team Leader
Customisations Team Leader
Posts: 18034
Joined: Thu Jan 06, 2005 1:30 pm
Location: Fishkill, NY
Name: David Colón
Contact:

Post by DavidIQ »

abramelin wrote: how can i make it?can you give some example codes?

Make a backup of includes/functions.php in case this doesn't work:

Code: Select all

#
#-----[ FIND ]------------------------------------------
#
			if ( $theme = setup_style($userdata['user_style']) )
			{
				return;
			}

#
#-----[ REPLACE WITH ]------------------------------------------
#
	//BEGIN Random Styles for Guests MOD
	if (isset($HTTP_COOKIE_VARS[$board_config['cookie_name'].'_rand_style']))
	{
		$rand_style = $HTTP_COOKIE_VARS[$board_config['cookie_name'].'_rand_style'];
		$theme = setup_style($rand_style);
	}
	else
	{
		global $db;
		$sql = "SELECT *
			FROM " . THEMES_TABLE . "
			ORDER BY RAND() LIMIT 1";
		
		if ( !($result = $db->sql_query($sql)) )
		{
			message_die(CRITICAL_ERROR, 'Could not query database for theme info');
		}
		
		if ( !($row = $db->sql_fetchrow($result)) )
		{
			message_die(CRITICAL_ERROR, "Could not get theme data for themes_id [$style]");
		}
		$rand_style = $row['themes_id'];
		$theme = setup_style($rand_style);
		setcookie($board_config['cookie_name'].'_rand_style', $rand_style, (time()+900), $board_config['cookie_path'], $board_config['cookie_domain'], $board_config['cookie_secure']); 
	}
        return;
	//END Random Styles for Guests MOD
Apply to become a Jr. Extension Validator
My extensions | In need of phpBB services? | Was I helpful today?
No unsolicited PMs unless you're planning on asking for paid help.
User avatar
DavidIQ
Customisations Team Leader
Customisations Team Leader
Posts: 18034
Joined: Thu Jan 06, 2005 1:30 pm
Location: Fishkill, NY
Name: David Colón
Contact:

Post by DavidIQ »

Just an FYI the registered user version which is configurable by the user has been submitted to the Mods database. Waiting to see if it gets approved 8)
Apply to become a Jr. Extension Validator
My extensions | In need of phpBB services? | Was I helpful today?
No unsolicited PMs unless you're planning on asking for paid help.
abramelin
Registered User
Posts: 79
Joined: Sat Apr 08, 2006 6:31 pm

Post by abramelin »

DavidIQ wrote:
abramelin wrote:how can i make it?can you give some example codes?

Make a backup of includes/functions.php in case this doesn't work:

Code: Select all

#
#-----[ FIND ]------------------------------------------
#
			if ( $theme = setup_style($userdata['user_style']) )
			{
				return;
			}

#
#-----[ REPLACE WITH ]------------------------------------------
#
	//BEGIN Random Styles for Guests MOD
	if (isset($HTTP_COOKIE_VARS[$board_config['cookie_name'].'_rand_style']))
	{
		$rand_style = $HTTP_COOKIE_VARS[$board_config['cookie_name'].'_rand_style'];
		$theme = setup_style($rand_style);
	}
	else
	{
		global $db;
		$sql = "SELECT *
			FROM " . THEMES_TABLE . "
			ORDER BY RAND() LIMIT 1";
		
		if ( !($result = $db->sql_query($sql)) )
		{
			message_die(CRITICAL_ERROR, 'Could not query database for theme info');
		}
		
		if ( !($row = $db->sql_fetchrow($result)) )
		{
			message_die(CRITICAL_ERROR, "Could not get theme data for themes_id [$style]");
		}
		$rand_style = $row['themes_id'];
		$theme = setup_style($rand_style);
		setcookie($board_config['cookie_name'].'_rand_style', $rand_style, (time()+900), $board_config['cookie_path'], $board_config['cookie_domain'], $board_config['cookie_secure']); 
	}
        return;
	//END Random Styles for Guests MOD

why do you use cookies?i want it with registered users. cant it be with sessions?
User avatar
DavidIQ
Customisations Team Leader
Customisations Team Leader
Posts: 18034
Joined: Thu Jan 06, 2005 1:30 pm
Location: Fishkill, NY
Name: David Colón
Contact:

Post by DavidIQ »

The phpBB software itself uses cookies so I didn't see anything wrong with using a cookie to set this up. I didn't want to have to edit the database for this mod is the main reason I have this like that. If I was to use the sessions table I would have had to add a new column to it.
Apply to become a Jr. Extension Validator
My extensions | In need of phpBB services? | Was I helpful today?
No unsolicited PMs unless you're planning on asking for paid help.
User avatar
Cardcaptor Stacey
Registered User
Posts: 89
Joined: Thu Jan 12, 2006 12:04 pm
Location: England
Name: Stacey
Contact:

Post by Cardcaptor Stacey »

I've just this minute installed it and I love it!

How would I do it so that it doesn't randomise all skins? I have two skins I don't want to be included.
Call me Stacey.
-SV-
Registered User
Posts: 39
Joined: Tue Aug 23, 2005 9:41 am

Post by -SV- »

Cardcaptor Stacey wrote: I've just this minute installed it and I love it!

How would I do it so that it doesn't randomise all skins? I have two skins I don't want to be included.


If you know the theme id's you could probably do something like (replacing 1 and 2 with the theme id's):

Code: Select all

#
#-----[ FIND ]------------------------------------------
#
		$sql = "SELECT *
			FROM " . THEMES_TABLE . "
			ORDER BY RAND() LIMIT 1";

#
#-----[ REPLACE WITH ]----------------------------------
#
		$sql = "SELECT *
			FROM " . THEMES_TABLE . "
			WHERE themes_id != 1 AND themes_id != 2
			ORDER BY RAND() LIMIT 1";

User avatar
DavidIQ
Customisations Team Leader
Customisations Team Leader
Posts: 18034
Joined: Thu Jan 06, 2005 1:30 pm
Location: Fishkill, NY
Name: David Colón
Contact:

Post by DavidIQ »

Exactly as -SV- graciously answered 8) Thanks by the way.

You'll need to look at the phpbb_themes table in the database to find out the theme's ID.

P.S. Glad you liked it :D
Apply to become a Jr. Extension Validator
My extensions | In need of phpBB services? | Was I helpful today?
No unsolicited PMs unless you're planning on asking for paid help.
User avatar
Cardcaptor Stacey
Registered User
Posts: 89
Joined: Thu Jan 12, 2006 12:04 pm
Location: England
Name: Stacey
Contact:

Post by Cardcaptor Stacey »

Excellent! Thanks for replying so quickly :) I tried it out earlier today and it seems to be working :)

Thanks :)
Call me Stacey.
Post Reply

Return to “[2.0.x] MOD Database Releases”