dogs and things Board Member
Joined: 18 Nov 2008
Posts: 628 Location: Spain
|
Posted: Wed Feb 12, 2014 7:28 pm Post subject: Change style on index |
|
|
Hello,
I've spent a whole day trying to figure out why this MOD works fine for logged in users but not for guests.
If I understand the intention of the MOD correctly it should store the template choice for logged in users in the database. This works fine.
And it should store the template choice for guests in a cookie. This part does not work.
Anybody able to figure out what might be wrong with this code?
Code: | ## EasyMod 0.0.10 compliant
########################################################
## Mod Title: change style on index / counts users mod
## Mod Version: 1.1.5
## Author: Tom Cioffe Jr < gwyd at cioffe.com >
## MOD Description: Allows the user / guest to change the style on the index page
## Lots of credits to: Cees-Jan Kiewiet < webmaster at iceblow.zzn.com >
##
## This mod is based on Cess-Jan Kiewiet's change guest template mod. If a user is logged in,
## their choice of template is stored in a cookie for 6 hours. Otherwise,
## the logged in user's choice in inputted directly into the database.
##
## Version 1.1 adds a security fix. Thanks to Smartor of smartor.is-root.com for finding this
## fix and alerting me to it.
##
## Version 1.1.5 updates the MOD's compliance with later versions of phpBB and also EasyMod.
## Thanks goes to gurukast for these changes.
##
## This mod is for phpBB2 ver. 2.x
##
## Installation rated: easy-medium
## Installation time: aprox 5-10 min (for editing templates)
##
## Files to edit: 5
## common.php
## index.php
## includes/functions_selects.php
## language/lang_main.php
## templates/Subsilver/index_body.tpl
##
##
#################################################################
##
## Installation Notes:
##
## The most important thing to keep in mind is, take your time, make
## sure you are finding the correct lines to modify, then take care to paste the new code.
## Please also keep in mind, if you are using more than one language file or theme at your
## site, you will need to edit the corrosponding files for each occurrence. Good Luck!
#################################################################
## Before Adding This MOD To Your Forum, You Should Back Up All Files Related To This MOD
#################################################################
#
#-----[ OPEN ]------------------------------------------
#
common.php
#
#-----[ FIND ]------------------------------------------
#
message_die(GENERAL_MESSAGE, 'Board_disable', 'Information');
}
#
#-----[ AFTER, ADD ]------------------------------------------
#
if ($template)
{
$board_config['default_style'] = $template;
setcookie('default_style',$template , (time()+21600), $board_config['cookie_path'], $board_config['cookie_domain'], $board_config['cookie_secure']);
} else if (isset($HTTP_COOKIE_VARS['default_style']) )
$board_config['default_style']=$HTTP_COOKIE_VARS['default_style'];
#
#-----[ OPEN ]------------------------------------------
#
index.php
#
#-----[ FIND ]------------------------------------------
#
include($phpbb_root_path . 'common.'.$phpEx);
#
#-----[ AFTER, ADD ]------------------------------------------
#
include($phpbb_root_path . 'includes/functions_selects.'.$phpEx);
#
#-----[ FIND ]------------------------------------------
#
//
// Handle marking posts
//
#
#-----[ BEFORE, ADD ]------------------------------------------
#
//change theme on index - new code by Smartor (smartor.is-root.com)
$fpage_style = $userdata['user_style'];
if(isset($HTTP_POST_VARS['fpage_theme']))
{
$fpage_theme = intval($HTTP_POST_VARS['fpage_theme']);
$fpuser_id = $userdata['user_id'];
$fp_sql = "UPDATE " . USERS_TABLE . " SET user_style = '$fpage_theme' WHERE
user_id = $fpuser_id";
if ( !($fp_result = $db->sql_query($fp_sql)) )
{
message_die(GENERAL_ERROR, 'Could not update users table ' . "$user_id
$fpage_theme", '', __LINE__, __FILE__, $sql);
}
else
{
$fp_message = $lang['Profile_updated'] . '<br /><br />' .
sprintf($lang['Click_return_index'], '<a href="' .
append_sid("index.$phpEx") . '">', '</a>');
message_die(GENERAL_MESSAGE, $fp_message);
}
}
#
#-----[ FIND ]------------------------------------------
#
'FORUM_LOCKED_IMG' => $images['forum_locked'],
#
#-----[ AFTER, ADD ]------------------------------------------
#
'TEMPLATE_SELECT' => style_select($board_config['default_style'], 'template'),
'L_SELECT_STYLE' => $lang['Change_style'],
'L_CHANGE_NOW' => $lang['Go'],
'FPAGE_STYLE' => style_select($fpage_style, 'fpage_theme'),
#
#-----[ OPEN ]------------------------------------------
#
language/lang_english/lang_main.php
#
#-----[ FIND ]------------------------------------------
#
//
// That's all, Folks!
#
#-----[ BEFORE, ADD ]------------------------------------------
#
$lang['Change_style'] = "Change Style";
# (THIS ADDS THE NUMBER OF USERS WITH THIS STYLE TO THE DROP DOWN.
# SKIP TO THE NEXT FILE IF YOU DO NOT WISH TO ADD THIS FEATURE)
#-----[ OPEN ]------------------------------------------
#
includes/functions_selects.php
#
#-----[ FIND ]------------------------------------------
#
$selected = ( $row['themes_id'] == $default_style ) ? ' selected="selected"' : '';
$style_select .= '<option value="' . $row['themes_id'] . '"' . $selected . '>' . $row['style_name'] . '</option>';
#
#-----[ REPLACE WITH ]------------------------------------------
#
//begin theme count
$tcount=0;
$t_id = $row['themes_id'];
$tsql = "SELECT user_style FROM " . USERS_TABLE . " WHERE user_style = $t_id";
if ( !($tresult = $db->sql_query($tsql)) ){
message_die(GENERAL_ERROR, "Couldn't query user table", "", __LINE__, __FILE__, $sql);}
while ( $trow = $db->sql_fetchrow($tresult) ) {
$tcount++; }
$selected = ( $row['themes_id'] == $default_style ) ? ' selected="selected"' : '';
$style_select .= '<option value="' . $row['themes_id'] . '"' . $selected . '>' . $row['style_name'] . ' [users: ' . $tcount . ']</option>';
#
#-----[ OPEN ]------------------------------------------
#
templates/subSilver/index_body.tpl
#
#-----[ FIND ]------------------------------------------
#
{CURRENT_TIME}
#
#-----[ IN-LINE FIND ]------------------------------------------
#
</td>
#
#-----[ AFTER, ADD ]------------------------------------------
#
<td align=center valign=middle><span class="gensmall">
<!-- BEGIN switch_user_logged_out -->
<form method="post" action="{U_INDEX}"><b>{L_SELECT_STYLE}:</b>
<br>{TEMPLATE_SELECT} <input type="submit" class="mainoption" name="cangenow" value="{L_CHANGE_NOW}" />
</form>
<!-- END switch_user_logged_out -->
<!-- BEGIN switch_user_logged_in -->
<form method="post" action="{U_INDEX}"><b>{L_SELECT_STYLE}:</b>
<br>{FPAGE_STYLE} <input type="submit" class="mainoption" name="fpcangenow" value="{L_CHANGE_NOW}" />
</form>
<!-- END switch_user_logged_in -->
</span></td>
#
#-----[ SAVE/CLOSE ALL FILES ]------------------------------------------
#
# EoM |
_________________ phpBB2 will never die, I hope! |
|