ucp.php
author indvdum (gotoindvdum[at]gmail[dot]com)
Sat, 10 Mar 2012 02:39:20 +0400
changeset 18 36b05a593b41
parent 0 ceef6d64c21d
permissions -rw-r--r--
Fix username allowed characters (like Cubometry game)
indvdum@0
     1
<?php
indvdum@0
     2
/**
indvdum@0
     3
*
indvdum@0
     4
* @package ucp
indvdum@0
     5
* @version $Id$
indvdum@0
     6
* @copyright (c) 2005 phpBB Group
indvdum@0
     7
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
indvdum@0
     8
*
indvdum@0
     9
*/
indvdum@0
    10
indvdum@0
    11
/**
indvdum@0
    12
* @ignore
indvdum@0
    13
*/
indvdum@0
    14
define('IN_PHPBB', true);
indvdum@0
    15
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
indvdum@0
    16
$phpEx = substr(strrchr(__FILE__, '.'), 1);
indvdum@0
    17
require($phpbb_root_path . 'common.' . $phpEx);
indvdum@0
    18
require($phpbb_root_path . 'includes/functions_user.' . $phpEx);
indvdum@0
    19
require($phpbb_root_path . 'includes/functions_module.' . $phpEx);
indvdum@0
    20
indvdum@0
    21
// Basic parameter data
indvdum@0
    22
$id 	= request_var('i', '');
indvdum@0
    23
$mode	= request_var('mode', '');
indvdum@0
    24
indvdum@0
    25
if (in_array($mode, array('login', 'logout', 'confirm', 'sendpassword', 'activate')))
indvdum@0
    26
{
indvdum@0
    27
	define('IN_LOGIN', true);
indvdum@0
    28
}
indvdum@0
    29
indvdum@0
    30
// Start session management
indvdum@0
    31
$user->session_begin();
indvdum@0
    32
$auth->acl($user->data);
indvdum@0
    33
$user->setup('ucp');
indvdum@0
    34
indvdum@0
    35
// Setting a variable to let the style designer know where he is...
indvdum@0
    36
$template->assign_var('S_IN_UCP', true);
indvdum@0
    37
indvdum@0
    38
$module = new p_master();
indvdum@0
    39
$default = false;
indvdum@0
    40
indvdum@0
    41
// Basic "global" modes
indvdum@0
    42
switch ($mode)
indvdum@0
    43
{
indvdum@0
    44
	case 'activate':
indvdum@0
    45
		$module->load('ucp', 'activate');
indvdum@0
    46
		$module->display($user->lang['UCP_ACTIVATE']);
indvdum@0
    47
indvdum@0
    48
		redirect(append_sid("{$phpbb_root_path}index.$phpEx"));
indvdum@0
    49
	break;
indvdum@0
    50
indvdum@0
    51
	case 'resend_act':
indvdum@0
    52
		$module->load('ucp', 'resend');
indvdum@0
    53
		$module->display($user->lang['UCP_RESEND']);
indvdum@0
    54
	break;
indvdum@0
    55
indvdum@0
    56
	case 'sendpassword':
indvdum@0
    57
		$module->load('ucp', 'remind');
indvdum@0
    58
		$module->display($user->lang['UCP_REMIND']);
indvdum@0
    59
	break;
indvdum@0
    60
indvdum@0
    61
	case 'register':
indvdum@0
    62
		if ($user->data['is_registered'] || isset($_REQUEST['not_agreed']))
indvdum@0
    63
		{
indvdum@0
    64
			redirect(append_sid("{$phpbb_root_path}index.$phpEx"));
indvdum@0
    65
		}
indvdum@0
    66
indvdum@0
    67
		$module->load('ucp', 'register');
indvdum@0
    68
		$module->display($user->lang['REGISTER']);
indvdum@0
    69
	break;
indvdum@0
    70
indvdum@0
    71
	case 'confirm':
indvdum@0
    72
		$module->load('ucp', 'confirm');
indvdum@0
    73
	break;
indvdum@0
    74
indvdum@0
    75
	case 'login':
indvdum@0
    76
		if ($user->data['is_registered'])
indvdum@0
    77
		{
indvdum@0
    78
			redirect(append_sid("{$phpbb_root_path}index.$phpEx"));
indvdum@0
    79
		}
indvdum@0
    80
indvdum@0
    81
		login_box(request_var('redirect', "index.$phpEx"));
indvdum@0
    82
	break;
indvdum@0
    83
indvdum@0
    84
	case 'logout':
indvdum@0
    85
		if ($user->data['user_id'] != ANONYMOUS && isset($_GET['sid']) && !is_array($_GET['sid']) && $_GET['sid'] === $user->session_id)
indvdum@0
    86
		{
indvdum@0
    87
			$user->session_kill();
indvdum@0
    88
			$user->session_begin();
indvdum@0
    89
			$message = $user->lang['LOGOUT_REDIRECT'];
indvdum@0
    90
		}
indvdum@0
    91
		else
indvdum@0
    92
		{
indvdum@0
    93
			$message = ($user->data['user_id'] == ANONYMOUS) ? $user->lang['LOGOUT_REDIRECT'] : $user->lang['LOGOUT_FAILED'];
indvdum@0
    94
		}
indvdum@0
    95
		meta_refresh(3, append_sid("{$phpbb_root_path}index.$phpEx"));
indvdum@0
    96
indvdum@0
    97
		$message = $message . '<br /><br />' . sprintf($user->lang['RETURN_INDEX'], '<a href="' . append_sid("{$phpbb_root_path}index.$phpEx") . '">', '</a> ');
indvdum@0
    98
		trigger_error($message);
indvdum@0
    99
indvdum@0
   100
	break;
indvdum@0
   101
indvdum@0
   102
	case 'terms':
indvdum@0
   103
	case 'privacy':
indvdum@0
   104
indvdum@0
   105
		$message = ($mode == 'terms') ? 'TERMS_OF_USE_CONTENT' : 'PRIVACY_POLICY';
indvdum@0
   106
		$title = ($mode == 'terms') ? 'TERMS_USE' : 'PRIVACY';
indvdum@0
   107
indvdum@0
   108
		if (empty($user->lang[$message]))
indvdum@0
   109
		{
indvdum@0
   110
			if ($user->data['is_registered'])
indvdum@0
   111
			{
indvdum@0
   112
				redirect(append_sid("{$phpbb_root_path}index.$phpEx"));
indvdum@0
   113
			}
indvdum@0
   114
indvdum@0
   115
			login_box();
indvdum@0
   116
		}
indvdum@0
   117
indvdum@0
   118
		$template->set_filenames(array(
indvdum@0
   119
			'body'		=> 'ucp_agreement.html')
indvdum@0
   120
		);
indvdum@0
   121
indvdum@0
   122
		// Disable online list
indvdum@0
   123
		page_header($user->lang[$title], false);
indvdum@0
   124
indvdum@0
   125
		$template->assign_vars(array(
indvdum@0
   126
			'S_AGREEMENT'			=> true,
indvdum@0
   127
			'AGREEMENT_TITLE'		=> $user->lang[$title],
indvdum@0
   128
			'AGREEMENT_TEXT'		=> sprintf($user->lang[$message], $config['sitename'], generate_board_url()),
indvdum@0
   129
			'U_BACK'				=> append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=login'),
indvdum@0
   130
			'L_BACK'				=> $user->lang['BACK_TO_LOGIN'],
indvdum@0
   131
		));
indvdum@0
   132
indvdum@0
   133
		page_footer();
indvdum@0
   134
indvdum@0
   135
	break;
indvdum@0
   136
indvdum@0
   137
	case 'delete_cookies':
indvdum@0
   138
indvdum@0
   139
		// Delete Cookies with dynamic names (do NOT delete poll cookies)
indvdum@0
   140
		if (confirm_box(true))
indvdum@0
   141
		{
indvdum@0
   142
			$set_time = time() - 31536000;
indvdum@0
   143
indvdum@0
   144
			foreach ($_COOKIE as $cookie_name => $cookie_data)
indvdum@0
   145
			{
indvdum@0
   146
				// Only delete board cookies, no other ones...
indvdum@0
   147
				if (strpos($cookie_name, $config['cookie_name'] . '_') !== 0)
indvdum@0
   148
				{
indvdum@0
   149
					continue;
indvdum@0
   150
				}
indvdum@0
   151
indvdum@0
   152
				$cookie_name = str_replace($config['cookie_name'] . '_', '', $cookie_name);
indvdum@0
   153
indvdum@0
   154
				// Polls are stored as {cookie_name}_poll_{topic_id}, cookie_name_ got removed, therefore checking for poll_
indvdum@0
   155
				if (strpos($cookie_name, 'poll_') !== 0)
indvdum@0
   156
				{
indvdum@0
   157
					$user->set_cookie($cookie_name, '', $set_time);
indvdum@0
   158
				}
indvdum@0
   159
			}
indvdum@0
   160
indvdum@0
   161
			$user->set_cookie('track', '', $set_time);
indvdum@0
   162
			$user->set_cookie('u', '', $set_time);
indvdum@0
   163
			$user->set_cookie('k', '', $set_time);
indvdum@0
   164
			$user->set_cookie('sid', '', $set_time);
indvdum@0
   165
indvdum@0
   166
			// We destroy the session here, the user will be logged out nevertheless
indvdum@0
   167
			$user->session_kill();
indvdum@0
   168
			$user->session_begin();
indvdum@0
   169
indvdum@0
   170
			meta_refresh(3, append_sid("{$phpbb_root_path}index.$phpEx"));
indvdum@0
   171
indvdum@0
   172
			$message = $user->lang['COOKIES_DELETED'] . '<br /><br />' . sprintf($user->lang['RETURN_INDEX'], '<a href="' . append_sid("{$phpbb_root_path}index.$phpEx") . '">', '</a>');
indvdum@0
   173
			trigger_error($message);
indvdum@0
   174
		}
indvdum@0
   175
		else
indvdum@0
   176
		{
indvdum@0
   177
			confirm_box(false, 'DELETE_COOKIES', '');
indvdum@0
   178
		}
indvdum@0
   179
indvdum@0
   180
		redirect(append_sid("{$phpbb_root_path}index.$phpEx"));
indvdum@0
   181
indvdum@0
   182
	break;
indvdum@0
   183
indvdum@0
   184
	case 'switch_perm':
indvdum@0
   185
indvdum@0
   186
		$user_id = request_var('u', 0);
indvdum@0
   187
indvdum@0
   188
		$sql = 'SELECT *
indvdum@0
   189
			FROM ' . USERS_TABLE . '
indvdum@0
   190
			WHERE user_id = ' . (int) $user_id;
indvdum@0
   191
		$result = $db->sql_query($sql);
indvdum@0
   192
		$user_row = $db->sql_fetchrow($result);
indvdum@0
   193
		$db->sql_freeresult($result);
indvdum@0
   194
indvdum@0
   195
		if (!$auth->acl_get('a_switchperm') || !$user_row || $user_id == $user->data['user_id'] || !check_link_hash(request_var('hash', ''), 'switchperm'))
indvdum@0
   196
		{
indvdum@0
   197
			redirect(append_sid("{$phpbb_root_path}index.$phpEx"));
indvdum@0
   198
		}
indvdum@0
   199
indvdum@0
   200
		include($phpbb_root_path . 'includes/acp/auth.' . $phpEx);
indvdum@0
   201
indvdum@0
   202
		$auth_admin = new auth_admin();
indvdum@0
   203
		if (!$auth_admin->ghost_permissions($user_id, $user->data['user_id']))
indvdum@0
   204
		{
indvdum@0
   205
			redirect(append_sid("{$phpbb_root_path}index.$phpEx"));
indvdum@0
   206
		}
indvdum@0
   207
indvdum@0
   208
		add_log('admin', 'LOG_ACL_TRANSFER_PERMISSIONS', $user_row['username']);
indvdum@0
   209
indvdum@0
   210
		$message = sprintf($user->lang['PERMISSIONS_TRANSFERRED'], $user_row['username']) . '<br /><br />' . sprintf($user->lang['RETURN_INDEX'], '<a href="' . append_sid("{$phpbb_root_path}index.$phpEx") . '">', '</a>');
indvdum@0
   211
		trigger_error($message);
indvdum@0
   212
indvdum@0
   213
	break;
indvdum@0
   214
indvdum@0
   215
	case 'restore_perm':
indvdum@0
   216
indvdum@0
   217
		if (!$user->data['user_perm_from'] || !$auth->acl_get('a_switchperm'))
indvdum@0
   218
		{
indvdum@0
   219
			redirect(append_sid("{$phpbb_root_path}index.$phpEx"));
indvdum@0
   220
		}
indvdum@0
   221
indvdum@0
   222
		$auth->acl_cache($user->data);
indvdum@0
   223
indvdum@0
   224
		$sql = 'SELECT username
indvdum@0
   225
			FROM ' . USERS_TABLE . '
indvdum@0
   226
			WHERE user_id = ' . $user->data['user_perm_from'];
indvdum@0
   227
		$result = $db->sql_query($sql);
indvdum@0
   228
		$username = $db->sql_fetchfield('username');
indvdum@0
   229
		$db->sql_freeresult($result);
indvdum@0
   230
indvdum@0
   231
		add_log('admin', 'LOG_ACL_RESTORE_PERMISSIONS', $username);
indvdum@0
   232
indvdum@0
   233
		$message = $user->lang['PERMISSIONS_RESTORED'] . '<br /><br />' . sprintf($user->lang['RETURN_INDEX'], '<a href="' . append_sid("{$phpbb_root_path}index.$phpEx") . '">', '</a>');
indvdum@0
   234
		trigger_error($message);
indvdum@0
   235
indvdum@0
   236
	break;
indvdum@0
   237
indvdum@0
   238
	default:
indvdum@0
   239
		$default = true;
indvdum@0
   240
	break;
indvdum@0
   241
}
indvdum@0
   242
indvdum@0
   243
// We use this approach because it does not impose large code changes
indvdum@0
   244
if (!$default)
indvdum@0
   245
{
indvdum@0
   246
	return true;
indvdum@0
   247
}
indvdum@0
   248
indvdum@0
   249
// Only registered users can go beyond this point
indvdum@0
   250
if (!$user->data['is_registered'])
indvdum@0
   251
{
indvdum@0
   252
	if ($user->data['is_bot'])
indvdum@0
   253
	{
indvdum@0
   254
		redirect(append_sid("{$phpbb_root_path}index.$phpEx"));
indvdum@0
   255
	}
indvdum@0
   256
indvdum@0
   257
	if ($id == 'pm' && $mode == 'view' && isset($_GET['p']))
indvdum@0
   258
	{
indvdum@0
   259
		$redirect_url = append_sid("{$phpbb_root_path}ucp.$phpEx?i=pm&p=" . request_var('p', 0));
indvdum@0
   260
		login_box($redirect_url, $user->lang['LOGIN_EXPLAIN_UCP']);
indvdum@0
   261
	}
indvdum@0
   262
indvdum@0
   263
	login_box('', $user->lang['LOGIN_EXPLAIN_UCP']);
indvdum@0
   264
}
indvdum@0
   265
indvdum@0
   266
// Instantiate module system and generate list of available modules
indvdum@0
   267
$module->list_modules('ucp');
indvdum@0
   268
indvdum@0
   269
// Check if the zebra module is set
indvdum@0
   270
if ($module->is_active('zebra', 'friends'))
indvdum@0
   271
{
indvdum@0
   272
	// Output listing of friends online
indvdum@0
   273
	$update_time = $config['load_online_time'] * 60;
indvdum@0
   274
indvdum@0
   275
	$sql = $db->sql_build_query('SELECT_DISTINCT', array(
indvdum@0
   276
		'SELECT'	=> 'u.user_id, u.username, u.username_clean, u.user_colour, MAX(s.session_time) as online_time, MIN(s.session_viewonline) AS viewonline',
indvdum@0
   277
indvdum@0
   278
		'FROM'		=> array(
indvdum@0
   279
			USERS_TABLE		=> 'u',
indvdum@0
   280
			ZEBRA_TABLE		=> 'z'
indvdum@0
   281
		),
indvdum@0
   282
indvdum@0
   283
		'LEFT_JOIN'	=> array(
indvdum@0
   284
			array(
indvdum@0
   285
				'FROM'	=> array(SESSIONS_TABLE => 's'),
indvdum@0
   286
				'ON'	=> 's.session_user_id = z.zebra_id'
indvdum@0
   287
			)
indvdum@0
   288
		),
indvdum@0
   289
indvdum@0
   290
		'WHERE'		=> 'z.user_id = ' . $user->data['user_id'] . '
indvdum@0
   291
			AND z.friend = 1
indvdum@0
   292
			AND u.user_id = z.zebra_id',
indvdum@0
   293
indvdum@0
   294
		'GROUP_BY'	=> 'z.zebra_id, u.user_id, u.username_clean, u.user_colour, u.username',
indvdum@0
   295
indvdum@0
   296
		'ORDER_BY'	=> 'u.username_clean ASC',
indvdum@0
   297
	));
indvdum@0
   298
indvdum@0
   299
	$result = $db->sql_query($sql);
indvdum@0
   300
indvdum@0
   301
	while ($row = $db->sql_fetchrow($result))
indvdum@0
   302
	{
indvdum@0
   303
		$which = (time() - $update_time < $row['online_time'] && ($row['viewonline'] || $auth->acl_get('u_viewonline'))) ? 'online' : 'offline';
indvdum@0
   304
indvdum@0
   305
		$template->assign_block_vars("friends_{$which}", array(
indvdum@0
   306
			'USER_ID'		=> $row['user_id'],
indvdum@0
   307
indvdum@0
   308
			'U_PROFILE'		=> get_username_string('profile', $row['user_id'], $row['username'], $row['user_colour']),
indvdum@0
   309
			'USER_COLOUR'	=> get_username_string('colour', $row['user_id'], $row['username'], $row['user_colour']),
indvdum@0
   310
			'USERNAME'		=> get_username_string('username', $row['user_id'], $row['username'], $row['user_colour']),
indvdum@0
   311
			'USERNAME_FULL'	=> get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']))
indvdum@0
   312
		);
indvdum@0
   313
	}
indvdum@0
   314
	$db->sql_freeresult($result);
indvdum@0
   315
}
indvdum@0
   316
indvdum@0
   317
// Do not display subscribed topics/forums if not allowed
indvdum@0
   318
if (!$config['allow_topic_notify'] && !$config['allow_forum_notify'])
indvdum@0
   319
{
indvdum@0
   320
	$module->set_display('main', 'subscribed', false);
indvdum@0
   321
}
indvdum@0
   322
indvdum@0
   323
// Do not display signature panel if not authed to do so
indvdum@0
   324
if (!$auth->acl_get('u_sig'))
indvdum@0
   325
{
indvdum@0
   326
	$module->set_display('profile', 'signature', false);
indvdum@0
   327
}
indvdum@0
   328
indvdum@0
   329
// Select the active module
indvdum@0
   330
$module->set_active($id, $mode);
indvdum@0
   331
indvdum@0
   332
// Load and execute the relevant module
indvdum@0
   333
$module->load_active();
indvdum@0
   334
indvdum@0
   335
// Assign data to the template engine for the list of modules
indvdum@0
   336
$module->assign_tpl_vars(append_sid("{$phpbb_root_path}ucp.$phpEx"));
indvdum@0
   337
indvdum@0
   338
// Generate the page, do not display/query online list
indvdum@0
   339
$module->display($module->get_page_title(), false);
indvdum@0
   340
indvdum@0
   341
/**
indvdum@0
   342
* Function for assigning a template var if the zebra module got included
indvdum@0
   343
*/
indvdum@0
   344
function _module_zebra($mode, &$module_row)
indvdum@0
   345
{
indvdum@0
   346
	global $template;
indvdum@0
   347
indvdum@0
   348
	$template->assign_var('S_ZEBRA_ENABLED', true);
indvdum@0
   349
indvdum@0
   350
	if ($mode == 'friends')
indvdum@0
   351
	{
indvdum@0
   352
		$template->assign_var('S_ZEBRA_FRIENDS_ENABLED', true);
indvdum@0
   353
	}
indvdum@0
   354
indvdum@0
   355
	if ($mode == 'foes')
indvdum@0
   356
	{
indvdum@0
   357
		$template->assign_var('S_ZEBRA_FOES_ENABLED', true);
indvdum@0
   358
	}
indvdum@0
   359
}
indvdum@0
   360
indvdum@0
   361
?>