1
0
mirror of https://github.com/e107inc/e107.git synced 2025-07-31 03:40:37 +02:00

Removed all SQL queries from usersettings_shortcodes.

This commit is contained in:
Cameron
2021-01-20 12:03:52 -08:00
parent b19f9ffbc3
commit 17dfe4149e
4 changed files with 567 additions and 352 deletions

View File

@@ -12,25 +12,44 @@
* $Id$
*/
if (!defined('e107_INIT')) { exit; }
if(!defined('e107_INIT'))
{
exit;
}
e107::coreLan('user');
e107::coreLan('usersettings');
class usersettings_shortcodes extends e_shortcode
{
private $extendedTabs = false;
public $legacyTemplate = array();
private $pref;
private $extendedShown = array();
private $catInfo = array(); // user's extended-field category list data;
private $fieldInfo = array(); // user's extended-field field list data;
function __construct()
{
$this->pref = e107::getPref();
}
function sc_username($parm=null) // This is the 'display name'
// Reset so that extended field data is reloaded.
public function reset()
{
$this->extendedShown = array();
$this->fieldInfo = array();
$this->catInfo = array();
$this->extendedTabs = false;
}
function sc_username($parm = null) // This is the 'display name'
{
$pref = $this->pref;
$dis_name_len = varset($pref['displayname_maxlength'], 15);
@@ -60,7 +79,7 @@ class usersettings_shortcodes extends e_shortcode
}
function sc_loginname($parm=null)
function sc_loginname($parm = null)
{
if($this->pref['allowEmailLogin'] == 1) // email/password login only.
@@ -82,29 +101,31 @@ class usersettings_shortcodes extends e_shortcode
// No write permission.
$options['readonly'] = true;
return e107::getForm()->text('loginname', $this->var['user_loginname'], $log_name_length, $options);
}
function sc_customtitle($parm=null)
{
if ($this->pref['signup_option_customtitle'])
{
function sc_customtitle($parm = null)
{
if($this->pref['signup_option_customtitle'])
{
$options = array(
'title'=> '',
'size' => 40,
'title' => '',
'size' => 40,
'required' => ($this->pref['signup_option_customtitle'] == 2));
return e107::getForm()->text('customtitle', $this->var['user_customtitle'], 100, $options);
}
}
function sc_realname($parm=null)
{
if ($this->pref['signup_option_realname'])
{
function sc_realname($parm = null)
{
if($this->pref['signup_option_realname'])
{
$sc = e107::getScBatch('usersettings');
$options = array(
'title' => '',
@@ -120,87 +141,92 @@ class usersettings_shortcodes extends e_shortcode
}
}
/*
function sc_realname2($parm=null)
/*
function sc_realname2($parm=null)
{
$sc = e107::getScBatch('usersettings');
$options = array(
'title' => '',
'size' => 40,
'required' => $pref['signup_option_realname'],
);
if(!empty($sc->var['user_login']) && !empty($sc->var['user_xup'])) // social login active.
{
$options['readonly'] = true;
}
return e107::getForm()->text('realname', $sc->var['user_login'], 100, $options);
}
*/
function sc_password1($parm = null)
{
$sc = e107::getScBatch('usersettings');
$options = array(
'title' => '',
'size' => 40,
'required' => $pref['signup_option_realname'],
);
if(!empty($sc->var['user_login']) && !empty($sc->var['user_xup'])) // social login active.
{
$options['readonly'] = true;
}
return e107::getForm()->text('realname', $sc->var['user_login'], 100, $options);
}
*/
function sc_password1($parm=null)
{
if(!empty($this->var['user_xup'])) // social login active.
{
return null;
}
if(!isset($pref['auth_method']) || $pref['auth_method'] == '' || $pref['auth_method'] == 'e107' || $pref['auth_method'] == '>e107')
{
$options = array('size' => 40,'title'=>LAN_USET_23, 'required'=>0,'autocomplete'=>'off');
return e107::getForm()->password('password1', '', 20, $options);
$options = array('size' => 40, 'title' => LAN_USET_23, 'required' => 0, 'autocomplete' => 'off');
return e107::getForm()->password('password1', '', 20, $options);
}
return "";
}
function sc_password2($parm=null)
{
function sc_password2($parm = null)
{
if(!empty($this->var['user_xup'])) // social login active.
{
return null;
}
if(!isset($this->pref['auth_method']) || $this->pref['auth_method'] == '' || $this->pref['auth_method'] == 'e107' || $this->pref['auth_method'] == '>e107')
{
$options = array('size' => 40,'title'=>LAN_USET_23, 'required'=>0);
return e107::getForm()->password('password2', '', 20, $options);
$options = array('size' => 40, 'title' => LAN_USET_23, 'required' => 0);
return e107::getForm()->password('password2', '', 20, $options);
}
return "";
}
function sc_password_len($parm=null)
{
function sc_password_len($parm = null)
{
if(!isset($this->pref['auth_method']) || ($this->pref['auth_method'] != 'e107' && $this->pref['auth_method'] != '>e107'))
{
return "";
}
return $this->pref['signup_pass_len'];
}
function sc_email($parm=null)
function sc_email($parm = null)
{
$sc = $this;
$options = array(
'size' => 40,
'title' => '',
'size' => 40,
'title' => '',
);
if (e107::getPref('disable_emailcheck') == 0) $options['required'] = true;
if(e107::getPref('disable_emailcheck') == 0)
{
$options['required'] = true;
}
if(!empty($sc->var['user_email']) && !empty($sc->var['user_xup'])) // social login active.
{
@@ -209,75 +235,87 @@ class usersettings_shortcodes extends e_shortcode
return e107::getForm()->email('email', $sc->var['user_email'], 100, $options);
}
function sc_hideemail($parm=null)
{
function sc_hideemail($parm = null)
{
if($parm == 'radio')
{
$options['enabled'] = array('title' => LAN_USER_84);
return "<div class='radio'>".e107::getForm()->radio_switch("hideemail", $this->var['user_hideemail'],LAN_YES,LAN_NO,$options)."</div>";
return "<div class='radio'>" . e107::getForm()->radio_switch("hideemail", $this->var['user_hideemail'], LAN_YES, LAN_NO, $options) . "</div>";
}
}
function sc_userclasses($parm=null)
{
function sc_userclasses($parm = null)
{
global $e_userclass;
$tp = e107::getParser();
$tp = e107::getParser();
$ret = "";
if(ADMIN && $this->var['user_id'] != USERID)
{
return "";
}
if (!is_object($e_userclass)) $e_userclass = new user_class;
$ucList = $e_userclass->get_editable_classes(USERCLASS_LIST, TRUE); // List of classes which this user can edit (as array)
if(!is_object($e_userclass))
{
$e_userclass = new user_class;
}
$ucList = $e_userclass->get_editable_classes(USERCLASS_LIST, true); // List of classes which this user can edit (as array)
$ret = '';
if(!count($ucList)) return;
$is_checked = array();
foreach ($ucList as $cid)
{
if (check_class($cid, $this->var['user_class'])) $is_checked[$cid] = $cid;
// if(isset($_POST['class']))
// {
// $is_checked[$cid] = in_array($cid, $_POST['class']);
// }
}
$inclass = implode(',',$is_checked);
// $ret = "<table style='width:95%;margin-left:0px'><tr><td class='defaulttext'>";
$ret .= $e_userclass->vetted_tree('class',array($e_userclass,'checkbox_desc'),$inclass,'editable, no-excludes');
// $ret .= "</td></tr></table>\n";
if(!count($ucList))
{
return;
}
$is_checked = array();
foreach($ucList as $cid)
{
if(check_class($cid, $this->var['user_class']))
{
$is_checked[$cid] = $cid;
}
// if(isset($_POST['class']))
// {
// $is_checked[$cid] = in_array($cid, $_POST['class']);
// }
}
$inclass = implode(',', $is_checked);
// $ret = "<table style='width:95%;margin-left:0px'><tr><td class='defaulttext'>";
$ret .= $e_userclass->vetted_tree('class', array($e_userclass, 'checkbox_desc'), $inclass, 'editable, no-excludes');
// $ret .= "</td></tr></table>\n";
return $ret;
}
function sc_signature($parm=null)
function sc_signature($parm = null)
{
if(!check_class(varset($this->pref['signature_access'],0)))
if(!check_class(varset($this->pref['signature_access'], 0)))
{
return;
}
return;
}
//parse_str($parm);
//$cols = (isset($cols) ? $cols : 58);
//$rows = (isset($rows) ? $rows : 4);
//return "<textarea class='tbox signature' name='signature' cols='{$cols}' rows='{$rows}' onselect='storeCaret(this);' onclick='storeCaret(this);' onkeyup='storeCaret(this);'>".$this->var['user_signature']."</textarea>";
return e107::getForm()->bbarea('signature', $this->var['user_signature'], '', '', 'small');
}
/**
* @DEPRECATED - it is integreated with sc_signature now.
* @DEPRECATED - it is integreated with sc_signature now.
*/
function sc_signature_help($parm=null)
function sc_signature_help($parm = null)
{
return;
/*
$pref = e107::getPref();
@@ -288,131 +326,117 @@ class usersettings_shortcodes extends e_shortcode
return display_help("", 2);
*/
}
function sc_avatar_upload($parm=null) // deprecated and combined into avatarpicker() (see sc_avatar_remote)
function sc_avatar_upload($parm = null) // deprecated and combined into avatarpicker() (see sc_avatar_remote)
{
return;
return;
}
function sc_avatar_remote($parm=null)
function sc_avatar_remote($parm = null)
{
if(!empty($this->var['user_xup'])) // social login active.
{
// return $this->var['user_image'];
// return $this->var['user_image'];
return e107::getParser()->toAvatar($this->var);
}
return e107::getForm()->avatarpicker('image',$this->var['user_image'],array('upload'=>1));
return e107::getForm()->avatarpicker('image', $this->var['user_image'], array('upload' => 1));
}
function sc_avatar_choose($parm=null) // deprecated
function sc_avatar_choose($parm = null) // deprecated
{
return false;
}
function sc_photo_upload($parm=null)
{
$diz = LAN_USET_27.". ".LAN_USET_28.".";
function sc_photo_upload($parm = null)
{
$diz = LAN_USET_27 . ". " . LAN_USET_28 . ".";
$text = '';
if(defset('USERPHOTO'))
{
$text .= e107::getParser()->parseTemplate("{PICTURE}",true);
$text .= e107::getParser()->parseTemplate("{PICTURE}", true);
}
if (e107::getPref('photo_upload') && FILE_UPLOADS)
if(e107::getPref('photo_upload') && FILE_UPLOADS)
{
$text .= "<div class='checkbox form-check'>";
$text .= e107::getForm()->checkbox('user_delete_photo', 1, false, LAN_USET_16);
$text .= "</div>";
// $text .= "<input type='checkbox' name='user_delete_photo' value='1' />".LAN_USET_16."<br />\n";
$text .= "<p><input class='tbox' name='file_userfile[photo]' type='file' size='47' title=\"".$diz."\" /></p>\n";
$text .= "</div>";
// $text .= "<input type='checkbox' name='user_delete_photo' value='1' />".LAN_USET_16."<br />\n";
$text .= "<p><input class='tbox' name='file_userfile[photo]' type='file' size='47' title=\"" . $diz . "\" /></p>\n";
}
return $text;
}
function sc_userextended_all($parm='')
function sc_userextended_all($parm = '')
{
$sql = e107::getDb();
$tp = e107::getParser();
$frm = e107::getForm();
if(empty($this->var['userclass_list']) && ADMIN)
$this->reset();
if(empty($this->catInfo))
{
return '$this->var[\'userclass_list\'] is empty';
$this->loadUECatData();
}
$qry = "
SELECT * FROM #user_extended_struct
WHERE user_extended_struct_applicable IN (".$tp -> toDB($this->var['userclass_list'], true).")
AND user_extended_struct_write IN (".USERCLASS_LIST.")
AND user_extended_struct_type = 0
ORDER BY user_extended_struct_order ASC";
$ret="";
if($sql->gen($qry))
{
$catList = $sql->db_getList();
}
else
{
e107::getMessage()->addDebug("No extended fields found");
$catList = array();
}
$catList[] = array("user_extended_struct_id" => 0, "user_extended_struct_name" => LAN_USET_7);
$catList = $this->catInfo;
$tabs = array();
if($parm == 'tabs' && deftrue('BOOTSTRAP'))
if($parm === 'tabs' && deftrue('BOOTSTRAP'))
{
$this->extendedTabs = true;
$this->extendedTabs = true;
}
$ret = '';
foreach($catList as $cat)
{
e107::setRegistry("core/shortcodes/usersettings/userextended/cat_".$cat['user_extended_struct_id'], $cat);
$this->catInfo[$cat['user_extended_struct_id']] = $cat;
$text = $this->sc_userextended_cat($cat['user_extended_struct_id']);
$ret .= $text;
$catName = vartrue($cat['user_extended_struct_text'], $cat['user_extended_struct_name']);
if(!empty($text))
{
$tabs[] = array('caption'=>$catName, 'text'=>$text);
$tabs[] = array('caption' => $catName, 'text' => $text);
}
}
if(($parm == 'tabs') && !empty($tabs) && deftrue('BOOTSTRAP'))
{
return e107::getForm()->tabs($tabs);
return e107::getForm()->tabs($tabs);
}
return $ret;
}
function sc_userextended_cat($parm = 0)
public function sc_userextended_cat($parm = 0)
{
global $extended_showed;
$parm = (int) $parm;
if(empty($this->catInfo))
{
$this->loadUECatData('write');
}
if(THEME_LEGACY === true)
{
$USER_EXTENDED_CAT = $this->legacyTemplate['USER_EXTENDED_CAT'];
@@ -422,98 +446,140 @@ class usersettings_shortcodes extends e_shortcode
$USER_EXTENDED_CAT = e107::getCoreTemplate('usersettings', 'extended-category');
}
if(empty($USER_EXTENDED_CAT))
{
trigger_error('User settings template key "extended-category" was empty', E_USER_NOTICE);
}
$sql = e107::getDb();
$tp = e107::getParser();
if(isset($extended_showed['cat'][$parm]))
if(!empty($this->extendedShown['cat'][$parm]))
{
trigger_error('Category already shown. Use ->reset()', E_USER_NOTICE);
return "";
}
$ret = "";
$catInfo = e107::getRegistry("core/shortcodes/usersettings/userextended/cat_{$parm}");
if(!$catInfo)
$catInfo = varset($this->catInfo[$parm]);
if(empty($catInfo))
{
$qry = "
SELECT * FROM #user_extended_struct
WHERE user_extended_struct_applicable IN (" . $tp->toDB($this->var['userclass_list'], true) . ")
AND user_extended_struct_write IN (" . USERCLASS_LIST . ")
AND user_extended_struct_id = " . (int) $parm . "
";
if($sql->gen($qry))
return null;
}
$ret = '';
if($fieldList = $this->loadUEFieldData('write', $parm))
{
foreach($fieldList as $field => $row)
{
$catInfo = $sql->fetch();
$ret .= $this->sc_userextended_field($field);
}
}
else
{
trigger_error(__METHOD__ . ' -- $fieldList is empty. Line: ' . __LINE__, E_USER_NOTICE);
}
if($catInfo)
{
$qry = "
SELECT * FROM #user_extended_struct
WHERE user_extended_struct_applicable IN (" . $tp->toDB($this->var['userclass_list'], true) . ")
AND user_extended_struct_write IN (" . USERCLASS_LIST . ")
AND user_extended_struct_parent = " . (int) $parm . "
AND user_extended_struct_type != 0
ORDER BY user_extended_struct_order ASC
";
if($sql->gen($qry))
{
$fieldList = $sql->db_getList();
foreach($fieldList as $field)
{
e107::setRegistry("core/shortcodes/usersettings/userextended/{$field['user_extended_struct_name']}", $field);
$ret .= $this->sc_userextended_field($field['user_extended_struct_name']);
}
}
}
if($ret && $this->extendedTabs == false)
if(!empty($ret) && ($this->extendedTabs === false))
{
$catName = !empty($catInfo['user_extended_struct_text']) ? $catInfo['user_extended_struct_text'] : $catInfo['user_extended_struct_name'];
if(defined($catName))
{
$catName = constant($catName);
}
$ret = str_replace("{CATNAME}", $tp->toHTML($catName, false, 'emotes_off,defs'), $USER_EXTENDED_CAT) . $ret;
$ret = str_replace("{CATNAME}", $tp->toHTML($catName, false, 'TITLE'), $USER_EXTENDED_CAT) . $ret;
}
$extended_showed['cat'][$parm] = 1;
if(empty($ret))
{
trigger_error(__METHOD__ . ' returned nothing. Line: ' . __LINE__, E_USER_NOTICE);
}
$this->extendedShown['cat'][$parm] = true;
return $ret;
}
public function getUserExtendedFieldData($name)
/**
* Return a list of User-Extended categories based on the logged in user permissions.
* For Internal Use Only
* @param string $perm read|write|applicable
*/
public function loadUECatData($perm = 'read')
{
$tp = e107::getParser();
$sql = e107::getDb();
$fInfo = array();
$ue = e107::getUserExt();
$data = (array) $ue->getCategories();
$uclass = !empty($this->var['userclass_list']) ? $this->var['userclass_list'] : USERCLASS_LIST;
$qry = "
SELECT * FROM #user_extended_struct
WHERE user_extended_struct_applicable IN (" . $tp->toDB($this->var['userclass_list'], true) . ")
AND user_extended_struct_write IN (" . USERCLASS_LIST . ")
AND user_extended_struct_name = '" . $tp->toDB($name, true) . "'
";
if($sql->gen($qry))
$this->catInfo = [];
foreach($data as $id => $row)
{
$userclass = (int) $row['user_extended_struct_' . $perm];
if(check_class($userclass, $uclass))
{
$fInfo = $sql->fetch();
$this->catInfo[$id] = $row;
}
return $fInfo;
}
$this->catInfo[0] = array("user_extended_struct_id" => 0, "user_extended_struct_name" => LAN_USET_7);
return $this->catInfo;
}
/**
* Get Fields by category ID and perms v2.3.1 for the current user. ie. respecting userclass permissionss.
* For Internal Use Only
* @param string $perm
* @return array
*/
public function loadUEFieldData($perm = 'read', $cat = null)
{
$uclass = !empty($this->var['userclass_list']) ? $this->var['userclass_list'] : USERCLASS_LIST;
$ue = e107::getUserExt();
$data = (array) $ue->getFields($cat);
if(empty($data))
{
trigger_error('$data was empty', E_USER_NOTICE);
}
$this->fieldInfo = [];
foreach($data as $k => $row)
{
$fieldname = 'user_' . $row['user_extended_struct_name'];
if($ue->hasPermission($fieldname, $perm, $uclass) && $ue->hasPermission($fieldname, 'applicable', $uclass))
{
$key = $row['user_extended_struct_name'];
$this->fieldInfo[$key] = $row;
}
}
return $this->fieldInfo;
}
/**
* @param string $parm extended field name without the 'user_' prefix.
* @return string|string[]
*/
function sc_userextended_field($parm = null)
{
global $extended_showed;
if(empty($parm))
if(empty($parm) || !empty($this->extendedShown['field'][$parm]))
{
$parm = '';
return '';
}
if(empty($this->fieldInfo))
{
$this->loadUEFieldData('write');
}
$ue = e107::getUserExt();
@@ -531,85 +597,77 @@ class usersettings_shortcodes extends e_shortcode
}
if(isset($extended_showed['field'][$parm]))
{
return "";
}
$sql = e107::getDb();
$tp = e107::getParser();
$ret = "";
$fInfo = e107::getRegistry("extendeddata_{$parm}");
$fInfo = varset($this->fieldInfo[$parm]);
if(!$fInfo)
if(empty($fInfo))
{
$fInfo = $this->getUserExtendedFieldData($parm);
trigger_error('$fInfo was empty', E_USER_NOTICE);
return null;
}
if($fInfo)
$fname = $fInfo['user_extended_struct_text'];
if(defined($fname))
{
$fname = $fInfo['user_extended_struct_text'];
if(defined($fname))
{
$fname = constant($fname);
}
$fname = $tp->toHTML($fname, "", "emotes_off, defs");
if($fInfo['user_extended_struct_required'] == 1 && !deftrue('BOOTSTRAP'))
{
$fname = str_replace("{FIELDNAME}", $fname, $REQUIRED_FIELD);
}
$parms = explode("^,^", $fInfo['user_extended_struct_parms']);
$fhide = "";
if(varset($parms[3]))
{
$chk = (strpos($this->var['user_hidden_fields'], "^user_" . $parm . "^") === false) ? false : true;
if(isset($_POST['updatesettings']))
{
$chk = isset($_POST['hide']['user_' . $parm]);
}
$fhide = $ue->user_extended_hide($fInfo, $chk);
}
$uVal = str_replace(chr(1), "", varset($this->var['user_' . $parm]));
$fval = $ue->user_extended_edit($fInfo, $uVal);
$rVal = !empty($fInfo['user_extended_struct_required']) ;
$ret = $USEREXTENDED_FIELD;
$ret = str_replace("{FIELDNAME}", $fname, $ret);
$ret = str_replace("{FIELDVAL}", $fval, $ret);
$ret = str_replace("{HIDEFIELD}", $fhide, $ret);
$ret = str_replace("{REQUIRED}", $this->required($rVal), $ret);
$fname = constant($fname);
}
$extended_showed['field'][$parm] = 1;
$fname = $tp->toHTML($fname, "", "emotes_off, defs");
if($fInfo['user_extended_struct_required'] == 1 && !deftrue('BOOTSTRAP'))
{
$fname = str_replace("{FIELDNAME}", $fname, $REQUIRED_FIELD);
}
$parms = explode("^,^", $fInfo['user_extended_struct_parms']);
$fhide = "";
if(varset($parms[3]))
{
$chk = (strpos($this->var['user_hidden_fields'], "^user_" . $parm . "^") === false) ? false : true;
if(isset($_POST['updatesettings']))
{
$chk = isset($_POST['hide']['user_' . $parm]);
}
$fhide = $ue->user_extended_hide($fInfo, $chk);
}
$uVal = str_replace(chr(1), "", varset($this->var['user_' . $parm]));
$fval = $ue->user_extended_edit($fInfo, $uVal);
$rVal = !empty($fInfo['user_extended_struct_required']);
$ret = $USEREXTENDED_FIELD;
$ret = str_replace("{FIELDNAME}", $fname, $ret);
$ret = str_replace("{FIELDVAL}", $fval, $ret);
$ret = str_replace("{HIDEFIELD}", $fhide, $ret);
$ret = str_replace("{REQUIRED}", $this->required($rVal), $ret);
$this->extendedShown['field'][$parm] = true;
return $ret;
}
function sc_updatesettingsbutton($parm='')
function sc_updatesettingsbutton($parm = '')
{
return "<input class='button btn btn-primary' type='submit' name='updatesettings' value='".LAN_USET_37."' />";
return "<input class='button btn btn-primary' type='submit' name='updatesettings' value='" . LAN_USET_37 . "' />";
}
private function required($val=null)
private function required($val = null)
{
if(empty($val))
{
return '';
@@ -619,9 +677,10 @@ class usersettings_shortcodes extends e_shortcode
}
function sc_required($parm=null)
function sc_required($parm = null)
{
if(empty($parm) || !isset($this->pref['signup_option_'.$parm]))
if(empty($parm) || !isset($this->pref['signup_option_' . $parm]))
{
return null;
}
@@ -631,30 +690,30 @@ class usersettings_shortcodes extends e_shortcode
return $this->required(true);
}
if ((int) $this->pref['signup_option_'.$parm] === 2)
if((int) $this->pref['signup_option_' . $parm] === 2)
{
return $this->required(true);
}
}
function sc_deleteaccountbutton($parm=array())
function sc_deleteaccountbutton($parm = array())
{
if(!empty($_GET['id']) && (int) $_GET['id'] !== USERID)
{
return null;
}
if($this->pref['del_accu'] == 1)
{
$confirm = defset("LAN_USET_51", "Are you sure? This procedure cannot be reversed! Once completed all personal data that you have entered on this site will be permanently lost and you will no longer be able to login.");
$label = defset('LAN_USET_50', "Delete All Account Information");
$confirm = defset("LAN_USET_51", "Are you sure? This procedure cannot be reversed! Once completed all personal data that you have entered on this site will be permanently lost and you will no longer be able to login.");
$label = defset('LAN_USET_50', "Delete All Account Information");
$parm['confirm'] = $confirm;
return e107::getForm()->button('delete_account',1, 'delete', $label, $parm);
return e107::getForm()->button('delete_account', 1, 'delete', $label, $parm);
}
else
{

View File

@@ -127,7 +127,7 @@ class e107_user_extended
public function init()
{
$sql = e107::getDb();
$sql = e107::getDb('ue');
// 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
@@ -195,13 +195,23 @@ class e107_user_extended
/**
* Check read/write access on extended user-fields
* @param string $field eg. user_something
* @param string $type read|write
* @param string $type read|write|applicable
* @return boolean true if
*/
public function hasPermission($field, $type='read')
public function hasPermission($field, $type='read', $classList=null)
{
$class = ($type == 'read') ? $this->fieldAttributes[$field]['read'] : $this->fieldAttributes[$field]['write'];
return check_class($class);
if($classList === null)
{
$classList = USERCLASS_LIST;
}
if(!isset($this->fieldAttributes[$field][$type]))
{
trigger_error('$this->fieldAttributes['.$field.']['.$type.'] was not set', E_USER_NOTICE);
}
$class = $this->fieldAttributes[$field][$type];
return check_class($class, $classList);
}
@@ -552,10 +562,9 @@ class e107_user_extended
/**
* alias of user_extended_get_categories();
*
* @param bool $byID
* @return array
*/
function getCategories($byID = TRUE)
function getCategories()
{
return $this->catDefinitions;
}
@@ -591,13 +600,14 @@ class e107_user_extended
/**
* BC Alias of getFields();
* Returns an array of fields for the selected category.
* The keys are the field name, minus the 'user_'.
* @param string $cat
* @return mixed
* @return array
*/
public function getFields($cat = "")
public function getFields($cat = null)
{
return $this->user_extended_get_fieldList($cat);
return $this->user_extended_get_fieldList($cat, 'user_extended_struct_name');
}
@@ -885,7 +895,7 @@ class e107_user_extended
function user_extended_field_exist($name)
{
$sql = e107::getDb('sql2');
$sql = e107::getDb('ue');
$tp = e107::getParser();
return $sql->count('user_extended_struct','(*)', "WHERE user_extended_struct_name = '".$tp -> toDB($name, true)."'");
}
@@ -985,7 +995,6 @@ class e107_user_extended
if(!$this->user_extended_field_exist($name))
{
$nid = $sql->insert('user_extended_struct', $extStructInsert);
$this->init(); // rebuild the list.
@@ -1580,7 +1589,7 @@ class e107_user_extended
*/
function user_extended_setvalue($uid, $field_name, $newvalue, $fieldType = 'todb')
{
$sql = e107::getDb();
$sql = e107::getDb('ue');
$tp = e107::getParser();
$uid = (int)$uid;

View File

@@ -26,15 +26,13 @@
try
{
$this->ue = $this->make('e107_user_extended');
$this->ue = e107::getUserExt(); // $this->make('e107_user_extended');
}
catch(Exception $e)
{
$this->assertTrue(false, "Couldn't load e107_user_extended object");
}
$this->ue->__construct();
$this->structTypes = array(
'text' => EUF_TEXT,
@@ -120,9 +118,13 @@
// clear the table.
$sql = e107::getDb();
if($sql->select('user_extended_struct', 'user_extended_struct_id', "user_extended_struct_text = '_system_'"))
$fieldCount = (int) $sql->count('user_extended_struct');
if($fieldCount > 17)
{
codecept_debug("Truncating user_extended_struct");
$sql->truncate('user_extended_struct');
$this->ue->init(); // reload the extended fields from db.
}
@@ -140,6 +142,9 @@
'default' => (isset($this->structDefault[$k])) ? $this->structDefault[$k] : null,
'parent' => (isset($this->structParent[$k])) ? $this->structParent[$k] : 0,
'required' => (isset($this->structRequired[$k])) ? $this->structRequired[$k] : 0,
'read' => e_UC_MEMBER,
'write' => e_UC_ADMIN,
'applicable' => e_UC_MAINADMIN,
);
// simulate data from e_user.php 'settings' method.
@@ -220,6 +225,44 @@
}
public function testUserextendedCatShortcode()
{
$sc = e107::getScBatch('usersettings');
$sc->reset();
$perms = array(e_UC_PUBLIC, e_UC_MEMBER, e_UC_ADMIN, e_UC_MAINADMIN);
$sc->setVars(array('userclass_list' => implode(',',$perms)));
$cat = (int) e107::getDb()->retrieve('user_extended_struct', 'user_extended_struct_id', "user_extended_struct_name = 'mycategory' LIMIT 1");
$result = $sc->sc_userextended_cat($cat);
$this->assertStringContainsString('<h3>Category Name</h3>', $result);
$this->assertStringContainsString("<label class='col-sm-3 control-label'>Radio <span class='required'>", $result);
$this->assertStringContainsString("<textarea id='ue-user-textarea'", $result);
$this->assertStringContainsString("<select id='ue-user-list'", $result);
$result = $sc->sc_userextended_cat(0);
$this->assertStringContainsString('<h3>Miscellaneous</h3>', $result);
$this->assertStringContainsString("<label class='col-sm-3 control-label'>Dropdown", $result);
}
public function testUserExtendedFieldShortcode()
{
$sc = e107::getScBatch('usersettings');
$sc->reset();
$perms = array(e_UC_PUBLIC, e_UC_MEMBER, e_UC_ADMIN, e_UC_MAINADMIN);
$sc->setVars(array('userclass_list' => implode(',',$perms)));
$result = $sc->sc_userextended_field('radio');
$this->assertStringContainsString("Radio <span class='required'", $result);
}
/**
* Test the {USER_EXTENDED} shortcode.
*/
@@ -338,6 +381,8 @@
{
$sc = e107::getScBatch('usersettings');
$sc->wrapper('not-a-real-wrapper');
$sc->reset();
$sc->setVars(array('userclass_list' => '253,251,0,254,250'));
@@ -349,6 +394,65 @@
}
public function testloadUECatData()
{
/** @var usersettings_shortcodes $sc */
$sc = e107::getScBatch('usersettings');
$data = $sc->loadUECatData('write');
$this->assertCount(3, $data); // 3 categories including "Misc"
}
public function testloadUEFieldData()
{
/**
* All fields have been created with the following.
* 'read' => e_UC_MEMBER,
'write' => e_UC_ADMIN,
'applicable' => e_UC_MAINADMIN,
*
* $this->structParent = array(
'list' => 16,
'radio' => 16,
'textarea' => 16,
'country' => 17,
);
*/
$sc = e107::getScBatch('usersettings');
$GLOBALS['_E107']['phpunit'] = true; // disable universal CLI access in check_class()
$perms = array(e_UC_PUBLIC, e_UC_MEMBER, e_UC_ADMIN, e_UC_MAINADMIN);
$sc->setVars(array('userclass_list' => implode(',',$perms)));
// Load Fields from parent = 0
$data = $sc->loadUEFieldData('write', 0);
$this->assertArrayHasKey('text', $data);
$this->assertArrayHasKey('homepage', $data);
$this->assertArrayNotHasKey('radio', $data);
// Load Fields from parent = 16
$data = $sc->loadUEFieldData('write', 16);
$this->assertArrayHasKey('radio', $data);
$this->assertArrayHasKey('list', $data);
$this->assertArrayHasKey('textarea', $data);
// Load Fields from parent = 17
$data = $sc->loadUEFieldData('write', 17);
$this->assertArrayHasKey('country', $data);
$perms = array(e_UC_GUEST); // ie USERCLASS_LIST
$sc->setVars(array('userclass_list' => implode(',',$perms)));
$data = $sc->loadUEFieldData('write', 16);
$this->assertCount(0, $data); // should be empty
$GLOBALS['_E107']['phpunit'] = false; // fix check_class()
}
public function testSignupExtendedUserFieldsShortcode()
{
$this->fixRegistry('before');
@@ -407,6 +511,7 @@
private function fixRegistry($mode)
{
return null;
$regID = 'core/e107/singleton/e107_user_extended';
static $originalRegistry;
@@ -424,7 +529,7 @@
}
/*
public function testGetUserExtendedFieldData()
{
$sc = e107::getScBatch('usersettings');
@@ -439,11 +544,11 @@
'user_extended_struct_parms' => '',
'user_extended_struct_values' => 'M =&gt; UE_LAN_MALE,F =&gt; UE_LAN_FEMALE',
'user_extended_struct_default' => 'F',
'user_extended_struct_read' => '0',
'user_extended_struct_write' => '0',
'user_extended_struct_read' => '253',
'user_extended_struct_write' => '254',
'user_extended_struct_required' => '1',
'user_extended_struct_signup' => '0',
'user_extended_struct_applicable' => '0',
'user_extended_struct_applicable' => '250',
'user_extended_struct_order' => '2',
'user_extended_struct_parent' => '16',
);
@@ -452,7 +557,7 @@
$this->assertEquals($result, $expected);
}
*/
public function testGetStructure()
{
@@ -525,12 +630,47 @@
{
}
*/
public function testHasPermission()
{
/**
* All fields have been createad with the following.
* 'read' => e_UC_MEMBER,
'write' => e_UC_ADMIN,
'applicable' => e_UC_MAINADMIN,
*/
$GLOBALS['_E107']['phpunit'] = true; // fix check_class()
// $_E107['phpunit'] = true;
$ret = [];
foreach($this->structTypes as $field => $name)
{
$fid = 'user_'.$field;
// test public access against read = member.
$result = $this->ue->hasPermission($fid,'read', e_UC_PUBLIC);
$this->assertFalse($result);
// test member against write = admin.
$result = $this->ue->hasPermission($fid,'write', e_UC_MEMBER);
$this->assertFalse($result);
// test member against write = admin.
$result = $this->ue->hasPermission($fid,'applicable', e_UC_ADMIN);
$this->assertFalse($result);
// test member against write = admin.
$result = $this->ue->hasPermission($fid,'applicable', e_UC_MAINADMIN);
$this->assertTrue($result);
}
$GLOBALS['_E107']['phpunit'] = false;
}
*/
public function testGetFieldTypes()
{
$result = $this->ue->getFieldTypes();
@@ -864,11 +1004,11 @@
'user_extended_struct_parms' => '',
'user_extended_struct_values' => 'M =&gt; UE_LAN_MALE,F =&gt; UE_LAN_FEMALE',
'user_extended_struct_default' => 'F',
'user_extended_struct_read' => '0',
'user_extended_struct_write' => '0',
'user_extended_struct_read' => '253',
'user_extended_struct_write' => '254',
'user_extended_struct_required' => '1',
'user_extended_struct_signup' => '0',
'user_extended_struct_applicable' => '0',
'user_extended_struct_applicable' => '250',
'user_extended_struct_order' => '2',
'user_extended_struct_parent' => '16',
),
@@ -881,11 +1021,11 @@
'user_extended_struct_parms' => '',
'user_extended_struct_values' => '',
'user_extended_struct_default' => '',
'user_extended_struct_read' => '0',
'user_extended_struct_write' => '0',
'user_extended_struct_read' => '253',
'user_extended_struct_write' => '254',
'user_extended_struct_required' => '0',
'user_extended_struct_signup' => '0',
'user_extended_struct_applicable' => '0',
'user_extended_struct_applicable' => '250',
'user_extended_struct_order' => '5',
'user_extended_struct_parent' => '16',
),
@@ -898,11 +1038,11 @@
'user_extended_struct_parms' => '',
'user_extended_struct_values' => 'timezones',
'user_extended_struct_default' => '',
'user_extended_struct_read' => '0',
'user_extended_struct_write' => '0',
'user_extended_struct_read' => '253',
'user_extended_struct_write' => '254',
'user_extended_struct_required' => '1',
'user_extended_struct_signup' => '0',
'user_extended_struct_applicable' => '0',
'user_extended_struct_applicable' => '250',
'user_extended_struct_order' => '9',
'user_extended_struct_parent' => '16',
),
@@ -961,16 +1101,23 @@
{
}
*/
public function testGetFields()
{
$data = $this->ue->getFields();
$this->assertArrayHasKey('text', $data);
// var_dump($data);
// $this->assertCount(15, $data);
$data = $this->ue->getFields(16);
$this->assertArrayHasKey('radio', $data);
// $this->assertCount(3, $data);
$data = $this->ue->getFields(17);
$this->assertArrayHasKey('country', $data);
// $this->assertCount(1, $data);
}
public function testGet()
{
}
/*
public function testUser_extended_field_exist()
{
@@ -1029,11 +1176,11 @@
'user_extended_struct_parms' => '',
'user_extended_struct_values' => 'M =&gt; UE_LAN_MALE,F =&gt; UE_LAN_FEMALE',
'user_extended_struct_default' => 'F',
'user_extended_struct_read' => '0',
'user_extended_struct_write' => '0',
'user_extended_struct_read' => '253',
'user_extended_struct_write' => '254',
'user_extended_struct_required' => '1',
'user_extended_struct_signup' => '0',
'user_extended_struct_applicable' => '0',
'user_extended_struct_applicable' => '250',
'user_extended_struct_order' => '2',
'user_extended_struct_parent' => 16,
),
@@ -1046,11 +1193,11 @@
'user_extended_struct_parms' => '',
'user_extended_struct_values' => '',
'user_extended_struct_default' => '',
'user_extended_struct_read' => '0',
'user_extended_struct_write' => '0',
'user_extended_struct_read' => '253',
'user_extended_struct_write' => '254',
'user_extended_struct_required' => '0',
'user_extended_struct_signup' => '0',
'user_extended_struct_applicable' => '0',
'user_extended_struct_applicable' => '250',
'user_extended_struct_order' => '5',
'user_extended_struct_parent' => 16,
),
@@ -1063,11 +1210,11 @@
'user_extended_struct_parms' => '',
'user_extended_struct_values' => 'timezones',
'user_extended_struct_default' => '',
'user_extended_struct_read' => '0',
'user_extended_struct_write' => '0',
'user_extended_struct_read' => '253',
'user_extended_struct_write' => '254',
'user_extended_struct_required' => '1',
'user_extended_struct_signup' => '0',
'user_extended_struct_applicable' => '0',
'user_extended_struct_applicable' => '250',
'user_extended_struct_order' => '9',
'user_extended_struct_parent' => 16,
),

View File

@@ -1093,7 +1093,7 @@ class usersettings_front // Begin Usersettings rewrite.
}
// e107::scStyle($sc_style);
e107::getScBatch('usersettings')->setVars($curVal);
e107::getScBatch('usersettings')->setVars($curVal)->reset();
$USERSETTINGS_EDIT = $this->getTemplate('edit');
$USERSETTINGS_EDIT_CAPTION = $this->getTemplate('edit_caption');