mirror of
https://github.com/phpbb/phpbb.git
synced 2025-08-09 10:16:36 +02:00
Move certain methods out of ucp class, move ucp class into ucp, break half a dozen other features, introduce x hundred new, exciting bugs
git-svn-id: file:///svn/phpbb/trunk@4213 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
259
phpBB/ucp.php
259
phpBB/ucp.php
@@ -56,12 +56,243 @@ include($phpbb_root_path . 'common.'.$phpEx);
|
||||
include($phpbb_root_path . '/includes/functions_user.'.$phpEx);
|
||||
|
||||
|
||||
// ---------
|
||||
// FUNCTIONS
|
||||
//
|
||||
|
||||
// Handles manipulation of user data. Primary used in registration
|
||||
// and user profile manipulation
|
||||
class ucp extends user
|
||||
{
|
||||
var $modules = array();
|
||||
var $error = array();
|
||||
|
||||
// Loads a given module (if it isn't already available), instantiates
|
||||
// a new object, and where appropriate calls the modules init method
|
||||
function load_module($module_name)
|
||||
{
|
||||
if (!class_exists('ucp_' . $module_name))
|
||||
{
|
||||
global $phpbb_root_path, $phpEx;
|
||||
|
||||
require_once($phpbb_root_path . 'includes/ucp/ucp_' . $module_name . '.'.$phpEx);
|
||||
eval('$this->module = new ucp_' . $module_name . '();');
|
||||
|
||||
if (method_exists($this->module, 'init'))
|
||||
{
|
||||
$this->module->init();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// This is replaced by the loaded module
|
||||
function main($module_id = false)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// This generates the block template variable for outputting the list
|
||||
// of submodules, should be called with an associative array of modules
|
||||
// in the form 'LANG_STRING' => 'LINK'
|
||||
function menu(&$id, &$module_ary, &$selected_module)
|
||||
{
|
||||
global $template, $user, $phpEx, $SID, $s_modules;
|
||||
|
||||
foreach ($s_modules as $module_id => $section_data)
|
||||
{
|
||||
$template->assign_block_vars('ucp_section', array(
|
||||
'L_TITLE' => $section_data['title'],
|
||||
|
||||
'S_SELECTED'=> $section_data['selected'],
|
||||
|
||||
'U_TITLE' => $section_data['url'])
|
||||
);
|
||||
|
||||
if ($module_id == $id)
|
||||
{
|
||||
foreach ($module_ary as $section_title => $module_link)
|
||||
{
|
||||
$template->assign_block_vars('ucp_section.ucp_subsection', array(
|
||||
'L_TITLE' => $user->lang['UCP_' . $section_title],
|
||||
|
||||
'S_SELECTED'=> ($section_title == strtoupper($selected_module)) ? true : false,
|
||||
|
||||
'U_TITLE' => "ucp.$phpEx$SID&$module_link")
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($module_ary as $section_title => $module_link)
|
||||
{
|
||||
$template->assign_block_vars('ucp_subsection', array(
|
||||
'L_TITLE' => $user->lang['UCP_' . $section_title],
|
||||
|
||||
'S_SELECTED'=> ($section_title == strtoupper($selected_module)) ? true : false,
|
||||
|
||||
'U_TITLE' => "ucp.$phpEx$SID&$module_link")
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Displays the appropriate template with the given title
|
||||
function display(&$page_title, $tpl_name)
|
||||
{
|
||||
global $template, $phpEx;
|
||||
|
||||
page_header($page_title);
|
||||
|
||||
$template->set_filenames(array(
|
||||
'body' => $tpl_name)
|
||||
);
|
||||
make_jumpbox('viewforum.'.$phpEx);
|
||||
|
||||
page_footer();
|
||||
}
|
||||
|
||||
// Normalises supplied data dependant on required type/length, errors
|
||||
// on incorrect data
|
||||
function normalise_data(&$data, &$normalise)
|
||||
{
|
||||
$valid_data = array();
|
||||
foreach ($normalise as $var_type => $var_ary)
|
||||
{
|
||||
foreach ($var_ary as $var_name => $var_limits)
|
||||
{
|
||||
$var_name = (is_string($var_name)) ? $var_name : $var_limits;
|
||||
|
||||
if (isset($data[$var_name]))
|
||||
{
|
||||
switch ($var_type)
|
||||
{
|
||||
case 'int':
|
||||
$valid_data[$var_name] = (int) $data[$var_name];
|
||||
break;
|
||||
|
||||
case 'float':
|
||||
$valid_data[$var_name] = (double) $data[$var_name];
|
||||
break;
|
||||
|
||||
case 'bool':
|
||||
$valid_data[$var_name] = ($data[$var_name] <= 0) ? 0 : 1;
|
||||
break;
|
||||
|
||||
case 'string':
|
||||
// Cleanup data, remove excess spaces, run entites
|
||||
$valid_data[$var_name] = htmlentities(trim(preg_replace('#\s{2,}#s', ' ', strtr((string) $data[$var_name], array_flip(get_html_translation_table(HTML_ENTITIES))))));
|
||||
|
||||
// How should we check this data?
|
||||
if (!is_array($var_limits))
|
||||
{
|
||||
// Is the match a string? If it is, process it further, else we'll
|
||||
// assume it's a maximum length
|
||||
if (is_string($var_limits))
|
||||
{
|
||||
if (strstr($var_limits, ','))
|
||||
{
|
||||
list($min_value, $max_value) = explode(',', $var_limits);
|
||||
if (!empty($valid_data[$var_name]) && strlen($valid_data[$var_name]) < $min_value)
|
||||
{
|
||||
$this->error[] = strtoupper($var_name) . '_TOO_SHORT';
|
||||
}
|
||||
|
||||
if (strlen($valid_data[$var_name]) > $max_value)
|
||||
{
|
||||
$this->error[] = strtoupper($var_name) . '_TOO_LONG';
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (strlen($valid_data[$var_name]) > $var_limits)
|
||||
{
|
||||
$this->error[] = strtoupper($var_name) . '_TOO_LONG';
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $valid_data;
|
||||
}
|
||||
|
||||
// Validates data subject to supplied requirements, errors appropriately
|
||||
function validate_data(&$data, &$validate)
|
||||
{
|
||||
global $db, $user, $config;
|
||||
|
||||
foreach ($validate as $operation => $var_ary)
|
||||
{
|
||||
foreach ($var_ary as $var_name => $compare)
|
||||
{
|
||||
if (!empty($compare))
|
||||
{
|
||||
switch ($operation)
|
||||
{
|
||||
case 'match':
|
||||
if (is_array($compare))
|
||||
{
|
||||
foreach ($compare as $match)
|
||||
{
|
||||
if (!preg_match($match, $data[$var_name]))
|
||||
{
|
||||
$this->error[] = strtoupper($var_name) . '_WRONG_DATA';
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (!preg_match($compare, $data[$var_name]))
|
||||
{
|
||||
$this->error[] = strtoupper($var_name) . '_WRONG_DATA';
|
||||
}
|
||||
break;
|
||||
|
||||
case 'compare':
|
||||
if (is_array($compare))
|
||||
{
|
||||
if (!in_array($data[$var_name], $compare))
|
||||
{
|
||||
$this->error[] = strtoupper($var_name) . '_MISMATCH';
|
||||
}
|
||||
}
|
||||
else if ($data[$var_name] != $compare)
|
||||
{
|
||||
$this->error[] = strtoupper($var_name) . '_MISMATCH';
|
||||
}
|
||||
break;
|
||||
|
||||
case 'function':
|
||||
if ($result = $compare($data[$var_name]))
|
||||
{
|
||||
$this->error[] = $result;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 'reqd':
|
||||
if (!isset($data[$compare]) || (is_string($data[$compare]) && $data[$compare] === ''))
|
||||
{
|
||||
$this->error[] = strtoupper($compare) . '_MISSING_DATA';
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//
|
||||
// FUNCTIONS
|
||||
// ---------
|
||||
|
||||
|
||||
// Start session management
|
||||
$user->start();
|
||||
$user->setup();
|
||||
$auth->acl($user->data);
|
||||
|
||||
|
||||
// Basic parameter data
|
||||
$mode = (!empty($_REQUEST['mode'])) ? htmlspecialchars($_REQUEST['mode']) : '';
|
||||
$module = (!empty($_REQUEST['i'])) ? intval($_REQUEST['i']) : 1;
|
||||
@@ -76,15 +307,14 @@ switch ($mode)
|
||||
{
|
||||
case 'activate':
|
||||
$ucp->load_module('activate');
|
||||
$ucp->module['activate']->main();
|
||||
$ucp->module->main();
|
||||
break;
|
||||
|
||||
case 'remind':
|
||||
$ucp->load_module('remind');
|
||||
$ucp->module['remind']->main();
|
||||
$ucp->module->main();
|
||||
break;
|
||||
|
||||
|
||||
case 'register':
|
||||
if ($user->data['user_id'] != ANONYMOUS)
|
||||
{
|
||||
@@ -92,12 +322,12 @@ switch ($mode)
|
||||
}
|
||||
|
||||
$ucp->load_module('register');
|
||||
$ucp->module['register']->main();
|
||||
$ucp->module->main();
|
||||
break;
|
||||
|
||||
case 'confirm':
|
||||
$ucp->load_module('confirm');
|
||||
$ucp->module['confirm']->main();
|
||||
$ucp->module->main();
|
||||
break;
|
||||
|
||||
case 'login':
|
||||
@@ -135,11 +365,12 @@ obtain_word_list($censors);
|
||||
|
||||
|
||||
// Grab the other enabled UCP modules
|
||||
$sql = "SELECT module_id, module_title, module_filename
|
||||
FROM " . UCP_MODULES_TABLE . "
|
||||
ORDER BY module_order ASC";
|
||||
$sql = 'SELECT module_id, module_title, module_filename
|
||||
FROM ' . UCP_MODULES_TABLE . '
|
||||
ORDER BY module_order ASC';
|
||||
$result = $db->sql_query($sql);
|
||||
|
||||
$s_modules = array();
|
||||
while ($row = $db->sql_fetchrow($result))
|
||||
{
|
||||
$template->assign_block_vars('ucp_sections', array(
|
||||
@@ -149,7 +380,11 @@ while ($row = $db->sql_fetchrow($result))
|
||||
|
||||
'S_IS_TAB' => ($row['module_id'] == $module) ? true : false)
|
||||
);
|
||||
|
||||
|
||||
$s_modules[$row['module_id']]['title'] = $user->lang['UCP_' . $row['module_title']];
|
||||
$s_modules[$row['module_id']]['url'] = "ucp.$phpEx$SID&i=" . $row['module_id'];
|
||||
$s_modules[$row['module_id']]['selected'] = ($row['module_id'] == $module) ? true : false;
|
||||
|
||||
if ($row['module_id'] == $module)
|
||||
{
|
||||
$selected_module = $row['module_filename'];
|
||||
@@ -161,9 +396,7 @@ $db->sql_freeresult($result);
|
||||
if ($selected_module)
|
||||
{
|
||||
$ucp->load_module($selected_module);
|
||||
$ucp->module[$selected_module]->main($selected_id);
|
||||
$ucp->module->main($selected_id);
|
||||
}
|
||||
|
||||
exit;
|
||||
|
||||
?>
|
Reference in New Issue
Block a user