diff --git a/e107_core/shortcodes/batch/usersettings_shortcodes.php b/e107_core/shortcodes/batch/usersettings_shortcodes.php index e0b6bbd67..628504b27 100755 --- a/e107_core/shortcodes/batch/usersettings_shortcodes.php +++ b/e107_core/shortcodes/batch/usersettings_shortcodes.php @@ -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 "
".e107::getForm()->radio_switch("hideemail", $this->var['user_hideemail'],LAN_YES,LAN_NO,$options)."
"; + + return "
" . e107::getForm()->radio_switch("hideemail", $this->var['user_hideemail'], LAN_YES, LAN_NO, $options) . "
"; } } - - - - 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 = "
"; - $ret .= $e_userclass->vetted_tree('class',array($e_userclass,'checkbox_desc'),$inclass,'editable, no-excludes'); - // $ret .= "
\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 = "
"; + $ret .= $e_userclass->vetted_tree('class', array($e_userclass, 'checkbox_desc'), $inclass, 'editable, no-excludes'); + + // $ret .= "
\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 ""; 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 .= "
"; $text .= e107::getForm()->checkbox('user_delete_photo', 1, false, LAN_USET_16); - $text .= "
"; - - - // $text .= "".LAN_USET_16."
\n"; - $text .= "

\n"; + $text .= ""; + + + // $text .= "".LAN_USET_16."
\n"; + $text .= "

\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 ""; - + + return ""; + } - 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 { diff --git a/e107_handlers/user_extended_class.php b/e107_handlers/user_extended_class.php index cbb9d36be..9abc804fa 100644 --- a/e107_handlers/user_extended_class.php +++ b/e107_handlers/user_extended_class.php @@ -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; diff --git a/e107_tests/tests/unit/e107_user_extendedTest.php b/e107_tests/tests/unit/e107_user_extendedTest.php index 1b6a43e12..11d38333a 100644 --- a/e107_tests/tests/unit/e107_user_extendedTest.php +++ b/e107_tests/tests/unit/e107_user_extendedTest.php @@ -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('

Category Name

', $result); + $this->assertStringContainsString("