User.setup
From phpBB Development Wiki
user::setup –– Setup basic user-specific settings - style and language.
Contents |
Description
void setup ( [ mixed $lang_set [, int $style ]] )
Initialise user specific settings: common language file, date format, timezone, daylight savings time, optionally include additional language file(s), and optionally force a specific style for the page.
Parameters
| Parameter | Usage |
|---|---|
| lang_set | (optional) basename of language file(s) to include. Allows inclusion of a single language file or an array of language files. |
| style | (optional) force (override style settings) a specific style by style_id. If not set, the style chosen by the user will be used or Board default style will be used by guests. |
Return Values
This function always returns NULL
Examples
Example #1 A session setup example
In this example, we use the default language file (common.php) and for logged-in users, we use the style set in the user preferences, administrators can specify a &style=x URI param
// required to include function files
define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
// Start session management
$user->session_begin();
// Setup the auth/permissions for this user
$auth->acl($user->data);
// setup the user-specific settings, style and language
$user->setup();
Example #2 Define additional language files
Additional language files can be loaded via the call to the $user->setup() method. To do so, pass the name with the subdirectory but without extension as argument of setup.
// load search.php language file
$user->setup('search');
// load mods/mylangfile.php language file
$user->setup('mods/mylangfile');
// load mods/mylangfile.php AND search.php
$user->setup(array('mods/mylangfile', 'search'));
// trick/tip
// load mods/mylangfile.php language file board-wide in a shot..
// you'll simply use "user->setup()" there in the files where it is not defined, if needed.
// (suggested in the case your language file involves quite the entire board, IMHO)
//
// open includes/sessions.php
// FIND
$this->add_lang($lang_set);
unset($lang_set);
// AFTER, ADD
$this->add_lang('mods/mylangfile');
See Also

