Index: branches/5.2.x/core/units/user_profile/user_profile_tp.php =================================================================== diff -u -N -r13840 -r14092 --- branches/5.2.x/core/units/user_profile/user_profile_tp.php (.../user_profile_tp.php) (revision 13840) +++ branches/5.2.x/core/units/user_profile/user_profile_tp.php (.../user_profile_tp.php) (revision 14092) @@ -1,6 +1,6 @@ getProfileMapping(); $field = $this->SelectParam($params, 'name,field'); + $profile_mapping = $this->Application->getUnitOption('u', 'UserProfileMapping'); + $user_field = array_key_exists($field, $profile_mapping) ? $profile_mapping[$field] : false; - if (isset($params['profile_field']) && $params['profile_field']) { - $params['name'] = $profile_mapping[$field]; + if (array_key_exists('profile_field', $params) && $params['profile_field']) { + // get variable from mapping + $params['name'] = $user_field; $value = $this->Application->ProcessParsedTag('u.profile', 'Field', $params); } + elseif ($user_field) { + // old style variable for displaying fields in public profile (named "pp_*") + $block_params = Array ('name' => 'DisplayToPublic', 'value' => $user_field); + $value = $this->Application->ProcessParsedTag($this->getUserPrefixSpecial(), 'Selected', $block_params); + } else { + // get variable by name $value = $this->recallUserProfileVar($field); } @@ -38,19 +46,13 @@ } /** - * Returns user_id to view profile from (same as u:getPassedID) + * Returns prefix and special of user to operate with * - * @return int + * @return string */ - function getProfileUserID() + function getUserPrefixSpecial() { - $profile_user_id = $this->Application->GetVar('user_id'); - if (!$profile_user_id) { - // if none user_id given use current user id - $profile_user_id = $this->Application->RecallVar('user_id'); - } - - return $profile_user_id; + return $this->Application->GetVar('user_id') ? 'u.profile' : 'u.current'; } /** @@ -60,28 +62,28 @@ * @param string $var_name * @return mixed */ - function recallUserProfileVar($var_name, $user_id = null) + function recallUserProfileVar($var_name) { - static $cached_vars = null; + static $cache = null; - if (!isset($cached_vars)) { - if (!isset($user_id)) { - $user_id = $this->getProfileUserID(); - } + if (!isset($cache)) { + $user =& $this->Application->recallObject( $this->getUserPrefixSpecial() ); + /* @var $user kDBItem */ $sql = 'SELECT VariableValue, VariableName - FROM '.TABLE_PREFIX.'PersistantSessionData - WHERE (PortalUserId = '.$user_id.')'; - $cached_vars = $this->Conn->GetCol($sql, 'VariableName'); + FROM ' . TABLE_PREFIX . 'PersistantSessionData + WHERE (PortalUserId = ' . $user->GetID() . ')'; + $cache = $this->Conn->GetCol($sql, 'VariableName'); } - if (isset($cached_vars[$var_name])) { + if (array_key_exists($var_name, $cache)) { // get variable value from persistent session - return $cached_vars[$var_name]; + return $cache[$var_name]; } else { // not found in persistent session -> get default value from config variable with same name $config_value = $this->Application->ConfigValue($var_name); + if ($config_value !== false) { return $config_value; } @@ -90,28 +92,7 @@ return false; } - /** - * Returns mapping between persistent var name and user profile field - * - * @return Array - */ - function getProfileMapping() - { - $profile_mapping = Array ( - 'pp_firstname' => 'FirstName', - 'pp_lastname' => 'LastName', - 'pp_dob' => 'dob', - 'pp_email' => 'Email', - 'pp_phone' => 'Phone', - 'pp_street' => 'Street', - 'pp_city' => 'City', - 'pp_state' => 'State', - 'pp_zip' => 'Zip', - 'pp_country' => 'Country', - ); - return $profile_mapping; - } /** * Returns visible field count in user profile @@ -124,13 +105,11 @@ static $field_count = null; if (!isset($field_count)) { - $profile_mapping = $this->getProfileMapping(); - $field_count = 0; - foreach ($profile_mapping as $var_name => $field_name) { - if ($this->recallUserProfileVar($var_name) == 1) { - $field_count++; - } - } + $user =& $this->Application->recallObject( $this->getUserPrefixSpecial() ); + /* @var $user kDBItem */ + + $display_to_public = $user->GetDBField('DisplayToPublic'); + $field_count = $display_to_public ? substr_count($display_to_public, '|') - 1 : 0; } return $field_count; @@ -158,10 +137,9 @@ */ function prepareInputName($params) { - list ($id, $field) = parent::prepareInputName($params); - $id = $this->Application->RecallVar('user_id'); + $params['force_id'] = $this->Application->RecallVar('user_id'); - return Array($id, $field); + return parent::prepareInputName($params); } } \ No newline at end of file