mirror of
https://github.com/e107inc/e107.git
synced 2025-08-05 06:07:32 +02:00
EONE-19 (bug/improvement): Start of restructuring of EUF handling to fix bugs and cache more information
This commit is contained in:
@@ -1,43 +1,54 @@
|
|||||||
<?php
|
<?php
|
||||||
/*
|
/*
|
||||||
+ ----------------------------------------------------------------------------+
|
* e107 website system
|
||||||
| e107 website system
|
*
|
||||||
|
|
* Copyright (C) 2008-2010 e107 Inc (e107.org)
|
||||||
| Copyright (C) 2008-2009 e107 Inc (e107.org)
|
* Released under the terms and conditions of the
|
||||||
| http://e107.org
|
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
|
||||||
|
|
*
|
||||||
|
|
* Extended user field handler
|
||||||
| Released under the terms and conditions of the
|
*
|
||||||
| GNU General Public License (http://gnu.org).
|
* $URL$
|
||||||
|
|
* $Id$
|
||||||
| $Source: /cvs_backup/e107_0.8/e107_handlers/user_extended_class.php,v $
|
*
|
||||||
| $Revision$
|
|
||||||
| $Date$
|
|
||||||
| $Author$
|
|
||||||
+----------------------------------------------------------------------------+
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (!defined('e107_INIT')) { exit; }
|
if (!defined('e107_INIT')) { exit; }
|
||||||
|
|
||||||
/*
|
/**
|
||||||
|
* @package e107
|
||||||
|
* @subpackage e107_handlers
|
||||||
|
* @version $Id$;
|
||||||
|
*
|
||||||
|
* Extended user field handler
|
||||||
|
*
|
||||||
|
* @todo: - change some routines to access the cached variables rather than DB
|
||||||
|
* @todo: Remove setting up of _FIELD_TYPES array (may be necessary, since UEF data structure not fixed)
|
||||||
|
* @todo: Consider changing field type constants to class constants
|
||||||
|
* @todo - cache field structure (already done in a different way in get_user_data() in class2.php line 1387 or so)
|
||||||
|
* @todo - class variables - confirm whether public/protected assignments are correct
|
||||||
|
* @todo - consider whether to split system and non-system fields
|
||||||
|
|
||||||
Code uses two tables:
|
Code uses two tables:
|
||||||
user_extended_struct - individual field definitions, one record per field
|
user_extended_struct - individual field definitions, one record per field
|
||||||
user_extended - actual field data, one record per user
|
user_extended - actual field data, one record per user
|
||||||
|
|
||||||
//TODO: Should user_extended_validate_entry() ckech DB for DB-type fields?
|
@todo: Should user_extended_validate_entry() check DB for DB-type fields?
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
include_lan(e_LANGUAGEDIR.e_LANGUAGE.'/lan_user_extended.php');
|
include_lan(e_LANGUAGEDIR.e_LANGUAGE.'/lan_user_extended.php');
|
||||||
|
|
||||||
|
|
||||||
class e107_user_extended
|
class e107_user_extended
|
||||||
{
|
{
|
||||||
var $user_extended_types; // Text description corresponding to each field type
|
public $user_extended_types; // Text description corresponding to each field type
|
||||||
var $extended_xml;
|
private $extended_xml = FALSE;
|
||||||
var $typeArray; // Cross-reference between names of field types, and numeric ID
|
private $typeArray; // Cross-reference between names of field types, and numeric ID
|
||||||
var $reserved_names; // List of field names used in main user DB - not allowed in extended DB
|
private $reserved_names; // List of field names used in main user DB - not allowed in extended DB
|
||||||
var $fieldDefinitions; // Array initialised from DB by constructor - currently non-system fields only
|
public $fieldDefinitions; // Array initialised from DB by constructor - currently all fields
|
||||||
var $nameIndex; // Array for field name lookup - initialised by constructor
|
public $catDefinitions; // Categories
|
||||||
|
private $nameIndex; // Array for field name lookup - initialised by constructor
|
||||||
public $systemCount = 0; // Count of system fields - always zero ATM
|
public $systemCount = 0; // Count of system fields - always zero ATM
|
||||||
public $userCount = 0; // Count of non-system fields
|
public $userCount = 0; // Count of non-system fields
|
||||||
|
|
||||||
@@ -91,31 +102,58 @@ class e107_user_extended
|
|||||||
'xup'
|
'xup'
|
||||||
);
|
);
|
||||||
|
|
||||||
// At present we only load non-system fields - may want to change this
|
$sql = e107::getDB();
|
||||||
$this->fieldDefinitions = $this->user_extended_get_fieldList(); // Assume that we'll need these if an object has been instantiated
|
|
||||||
$this->nameIndex = array();
|
// Read in all the field and category fields
|
||||||
|
// At present we load all fields into common array - may want to split system and non-system
|
||||||
|
$this ->catDefinitions = array(); // Categories array
|
||||||
|
$this->fieldDefinitions = array(); // Field definitions array
|
||||||
|
$this->nameIndex = array(); // Index of names => field IDs
|
||||||
$this->systemCount = 0;
|
$this->systemCount = 0;
|
||||||
$this->userCount = 0;
|
$this->userCount = 0;
|
||||||
foreach ($this->fieldDefinitions as $k => $v)
|
|
||||||
|
if($sql->db_Select('user_extended_struct', '*', "user_extended_struct_text != '_system_' ORDER BY user_extended_struct_order ASC"))
|
||||||
{
|
{
|
||||||
$this->nameIndex['user_'.$v['user_extended_struct_name']] = $k; // Create name to ID index
|
while($row = $sql->db_Fetch(MYSQL_ASSOC))
|
||||||
if ($v['user_extended_struct_text'] == '_system_')
|
|
||||||
{
|
{
|
||||||
$this->systemCount++;
|
if ($row['user_extended_struct_type'] == 0)
|
||||||
}
|
{ // Its a category
|
||||||
else
|
$this->catDefinitions[$row['user_extended_struct_id']] = $row;
|
||||||
{
|
}
|
||||||
$this->userCount++;
|
else
|
||||||
|
{ // Its a field definition
|
||||||
|
$this->fieldDefinitions[$row['user_extended_struct_id']] = $row;
|
||||||
|
$this->nameIndex['user_'.$row['user_extended_struct_name']] = $row['user_extended_struct_id']; // Create name to ID index
|
||||||
|
if ($row['user_extended_struct_text'] == '_system_')
|
||||||
|
{
|
||||||
|
$this->systemCount++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$this->userCount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function user_extended_reserved($name)
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check for reserved field names.
|
||||||
|
* (Names which clash with the 'normal' user table aren't allowed)
|
||||||
|
*
|
||||||
|
* @param string $name - name of field bweing checked (no 'user_' prefix)
|
||||||
|
*
|
||||||
|
* @return boolean TRUE if disallowed name
|
||||||
|
*/
|
||||||
|
public function user_extended_reserved($name)
|
||||||
{
|
{
|
||||||
return (in_array($name, $this->reserved_names));
|
return (in_array($name, $this->reserved_names));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Adds the _FIELD_TYPES array to the data, ready for saving in the DB.
|
// Adds the _FIELD_TYPES array to the data, ready for saving in the DB.
|
||||||
function addFieldTypes(&$target)
|
function addFieldTypes(&$target)
|
||||||
{
|
{
|
||||||
@@ -146,15 +184,20 @@ class e107_user_extended
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// For all UEFs not in the target array, adds the default value
|
|
||||||
// Also updates the _FIELD_TYPES array, so call this last thing before writing to the DB
|
/**
|
||||||
function addDefaultFields(&$target)
|
* For all UEFs not in the target array, adds the default value
|
||||||
|
* Also updates the _FIELD_TYPES array, so call this last thing before writing to the DB
|
||||||
|
*
|
||||||
|
* @param $target - pointer to data array
|
||||||
|
*/
|
||||||
|
public function addDefaultFields(&$target)
|
||||||
{
|
{
|
||||||
$target['_FIELD_TYPES'] = array(); // We should always want to recreate the array, even if it exists
|
//$target['_FIELD_TYPES'] = array(); // We should always want to recreate the array, even if it exists
|
||||||
foreach ($this->fieldDefinitions as $k => $defs)
|
foreach ($this->fieldDefinitions as $k => $defs)
|
||||||
{
|
{
|
||||||
$f = 'user_'.$defs['user_extended_struct_name'];
|
$f = 'user_'.$defs['user_extended_struct_name'];
|
||||||
if (!isset($target['data'][$f]))
|
if (!isset($target['data'][$f]) && $this->fieldDefinitions[$k]['user_extended_struct_default'])
|
||||||
{
|
{
|
||||||
switch ($this->fieldDefinitions[$k]['user_extended_struct_type'])
|
switch ($this->fieldDefinitions[$k]['user_extended_struct_type'])
|
||||||
{
|
{
|
||||||
@@ -212,49 +255,67 @@ class e107_user_extended
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Validate all user-modifable extended user fields which are presented.
|
|
||||||
// $inArray is the input data (usually from $_POST or $_POST['ue'], although doesn't have to be) - may have 'surplus' values
|
/**
|
||||||
// $hideArray is a set of possible 'hide' flags
|
* Validate all user-modifable extended user fields which are presented.
|
||||||
// $isSignup TRUE causes required fields to be specifically checked, else only data passed is checked
|
* Primarily intended to validate data entered by a user or admin
|
||||||
function userExtendedValidateAll($inArray, $hideArray, $isSignup=FALSE)
|
*
|
||||||
|
* @param array $inArray is the input data (usually from $_POST or $_POST['ue'], although doesn't have to be) - may have 'surplus' values
|
||||||
|
* @param array $hideArray is a set of possible 'hide' flags
|
||||||
|
* @param boolean $isSignup TRUE causes required fields to be specifically checked, else only data passed is checked
|
||||||
|
*
|
||||||
|
* @return array with three potential subkeys:
|
||||||
|
* 'data' - valid data values (key is field name)
|
||||||
|
* ['data']['user_hidden_fields'] is the hidden fields
|
||||||
|
* 'errors' - data values in error
|
||||||
|
* 'errortext' - error message corresponding to erroneous value
|
||||||
|
*
|
||||||
|
* @todo - does $hidden_fields need to be merged with values for fields not processed? (Probably not - should only relate to fields current user can see)
|
||||||
|
* @todo - make sure admin can edit fields of other users
|
||||||
|
*/
|
||||||
|
public function userExtendedValidateAll($inArray, $hideArray, $isSignup=FALSE)
|
||||||
{
|
{
|
||||||
global $tp;
|
global $tp;
|
||||||
$eufVals = array(); // 'Answer' array
|
$eufVals = array(); // 'Answer' array
|
||||||
$hideFlags = array();
|
$hideFlags = array();
|
||||||
foreach ($this->fieldDefinitions as $k => $defs)
|
foreach ($this->fieldDefinitions as $k => $defs)
|
||||||
{
|
{
|
||||||
if ($defs['user_extended_struct_applicable'] != e_UC_NOBODY)
|
$category = $defs['user_extended_struct_parent'];
|
||||||
{
|
if (($category == 0) || (check_class($this->catDefinitions[$category]['user_extended_struct_applicable']) && check_class($this->catDefinitions[$category]['user_extended_struct_write'])))
|
||||||
$f = 'user_'.$defs['user_extended_struct_name'];
|
{ // Category applicable to user
|
||||||
if (isset($inArray[$f]) || ($isSignup && ($defs['user_extended_struct_required'] == 1)))
|
if (check_class($defs['user_extended_struct_applicable']) && check_class($defs['user_extended_struct_write']))
|
||||||
{ // Only allow valid keys
|
{ // User can also update field
|
||||||
$val = varset($inArray[$f], FALSE);
|
$f = 'user_'.$defs['user_extended_struct_name'];
|
||||||
$err = $this->user_extended_validate_entry($val, $defs);
|
if (isset($inArray[$f]) || ($isSignup && ($defs['user_extended_struct_required'] == 1)))
|
||||||
if ($err === true)
|
{ // Only allow valid keys
|
||||||
{ // General error - usually empty field; could be unacceptable value, or regex fail and no error message defined
|
$val = varset($inArray[$f], FALSE);
|
||||||
$eufVals['errortext'][$f] = str_replace('--SOMETHING--',$tp->toHtml($defs['user_extended_struct_text'],FALSE,'defs'),LAN_USER_75);
|
$err = $this->user_extended_validate_entry($val, $defs);
|
||||||
$eufVals['errors'][$f] = ERR_GENERIC;
|
if ($err === true)
|
||||||
}
|
{ // General error - usually empty field; could be unacceptable value, or regex fail and no error message defined
|
||||||
elseif ($err)
|
$eufVals['errortext'][$f] = str_replace('--SOMETHING--',$tp->toHtml($defs['user_extended_struct_text'],FALSE,'defs'),LAN_USER_75);
|
||||||
{ // Specific error message returned - usually regex fail
|
$eufVals['errors'][$f] = ERR_GENERIC;
|
||||||
$eufVals['errortext'][$f] = $err;
|
}
|
||||||
$eufVals['errors'][$f] = ERR_GENERIC;
|
elseif ($err)
|
||||||
}
|
{ // Specific error message returned - usually regex fail
|
||||||
elseif (!$err)
|
$eufVals['errortext'][$f] = $err;
|
||||||
{
|
$eufVals['errors'][$f] = ERR_GENERIC;
|
||||||
$eufVals['data'][$f] = $tp->toDB($val);
|
}
|
||||||
}
|
elseif (!$err)
|
||||||
if (isset($hideArray[$f]))
|
{
|
||||||
{
|
$eufVals['data'][$f] = $tp->toDB($val);
|
||||||
$hideFlags[] = $f;
|
}
|
||||||
|
if (isset($hideArray[$f]))
|
||||||
|
{
|
||||||
|
$hideFlags[] = $f;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$hidden_fields = implode("^", $hideFlags);
|
$hidden_fields = implode('^', $hideFlags);
|
||||||
if ($hidden_fields != "")
|
if ($hidden_fields != '')
|
||||||
{
|
{
|
||||||
$hidden_fields = "^".$hidden_fields."^";
|
$hidden_fields = '^'.$hidden_fields.'^';
|
||||||
}
|
}
|
||||||
$eufVals['data']['user_hidden_fields'] = $hidden_fields;
|
$eufVals['data']['user_hidden_fields'] = $hidden_fields;
|
||||||
|
|
||||||
@@ -262,6 +323,8 @@ class e107_user_extended
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function user_extended_get_categories($byID = TRUE)
|
function user_extended_get_categories($byID = TRUE)
|
||||||
{
|
{
|
||||||
$ret = array();
|
$ret = array();
|
||||||
|
Reference in New Issue
Block a user