示例#1
0
 public function update($iUserId, $aVals, $aSpecial = array(), $bIsAccount = false)
 {
     if (!defined('PHPFOX_IS_CUSTOM_FIELD_UPDATE') && Phpfox::getParam('user.split_full_name')) {
         if (empty($aVals['first_name']) || empty($aVals['last_name'])) {
             return Phpfox_Error::set(Phpfox::getPhrase('user.please_fill_in_both_your_first_and_last_name'));
         }
         $aVals['full_name'] = $aVals['first_name'] . ' ' . $aVals['last_name'];
     }
     if (!empty($aVals['city_location'])) {
         if (!Phpfox::getLib('validator')->check($aVals['city_location'], array('html', 'url'))) {
             return Phpfox_Error::set(Phpfox::getPhrase('user.not_a_valid_city'));
         }
     }
     if (isset($aVals['full_name']) && Phpfox::getParam('user.validate_full_name')) {
         if (!Phpfox::getLib('validator')->check($aVals['full_name'], array('html', 'url'))) {
             return Phpfox_Error::set(Phpfox::getPhrase('user.not_a_valid_name'));
         }
         //d(Phpfox::getParam('user.maximum_length_for_full_name'));			d(strlen($aVals['full_name']));			d($aVals);die();
         if (Phpfox::getParam('user.maximum_length_for_full_name') > 0 && strlen($aVals['full_name']) > Phpfox::getParam('user.maximum_length_for_full_name')) {
             $aChange = array('iMax' => Phpfox::getParam('user.maximum_length_for_full_name'));
             $sPhrase = Phpfox::getParam('user.display_or_full_name') == 'full_name' ? Phpfox::getPhrase('user.please_shorten_full_name', $aChange) : Phpfox::getPhrase('user.please_shorten_display_name', $aChange);
             return Phpfox_Error::set($sPhrase);
         }
     }
     if (!defined('PHPFOX_INSTALLER') && isset($aVals['full_name']) && $aVals['full_name'] == '­') {
         return Phpfox_Error::set(Phpfox::getPhrase('user.not_a_valid_name'));
     }
     if (!$bIsAccount && Phpfox::getUserParam('user.can_edit_dob') && (empty($aVals['day']) || empty($aVals['month']) || empty($aVals['year']))) {
         return Phpfox_Error::set(Phpfox::getPhrase('user.please_enter_your_date_of_birth'));
     }
     if (isset($aVals['relation']) && Phpfox::getUserParam('custom.can_have_relationship') && ($aVals['relation'] != $aVals['previous_relation_type'] || $aVals['relation_with'] != $aVals['previous_relation_with'])) {
         if (isset($_POST['null']) && empty($_POST['null'])) {
             $aVals['relation_with'] = null;
         }
         /* has the user defined another user to share this relationship with? */
         Phpfox::getService('custom.relation.process')->updateRelationship($aVals['relation'], isset($aVals['relation_with']) ? $aVals['relation_with'] : null);
     }
     $oParseInput = Phpfox::getLib('parse.input');
     $aInsert = array('dst_check' => isset($aVals['dst_check']) ? '1' : '0', 'language_id' => $aVals['language_id']);
     if (!$bIsAccount) {
         if (isset($aVals['country_iso'])) {
             $aInsert['country_iso'] = $aVals['country_iso'];
             // http://www.phpfox.com/tracker/view/15297/
             $aCountryChildren = Phpfox::getService('core.country')->getChildren($aVals['country_iso']);
             $bHasCountryChildren = !empty($aCountryChildren);
         }
         //$aInsert['birthday'] = (Phpfox::getUserParam('user.can_edit_dob') && isset($aVals['day']) && isset($aVals['month']) && isset($aVals['year']) ? Phpfox::getService('user')->buildAge($aVals['day'], $aVals['month'], $aVals['year']) : null);
         $aInsert['birthday_search'] = Phpfox::getUserParam('user.can_edit_dob') && isset($aVals['day']) && isset($aVals['month']) && isset($aVals['year']) ? Phpfox::getLib('date')->mktime(0, 0, 0, $aVals['month'], $aVals['day'], $aVals['year']) : 0;
         // http://www.phpfox.com/tracker/view/14726/
         // if ($aInsert['birthday_search'] > 0)
         if (isset($aInsert['birthday_search'])) {
             $aInsert['birthday'] = date('mdY', $aInsert['birthday_search']);
         }
         if (Phpfox::getUserParam('user.can_edit_gender_setting') && isset($aVals['gender'])) {
             $aInsert['gender'] = (int) $aVals['gender'];
         }
     }
     if (isset($aVals['time_zone'])) {
         $aInsert['time_zone'] = $aVals['time_zone'];
     }
     ($sPlugin = Phpfox_Plugin::get('user.service_process_update_start')) ? eval($sPlugin) : false;
     if (isset($aSpecial['changes_allowed']) && $aSpecial['changes_allowed'] > $aSpecial['total_user_change'] && Phpfox::getUserParam('user.can_change_own_user_name') && !Phpfox::getParam('user.profile_use_id') && isset($aVals['old_user_name']) && $aVals['user_name'] != $aVals['old_user_name']) {
         // http://www.phpfox.com/tracker/view/15155/
         $aVals['user_name'] = str_replace(' ', '-', $aVals['user_name']);
         $aVals['user_name'] = str_replace('_', '-', $aVals['user_name']);
         Phpfox::getService('user.validate')->user($aVals['user_name']);
         if (!Phpfox_Error::isPassed()) {
             return false;
         }
         $aInsert['user_name'] = $aVals['user_name'];
         $this->database()->updateCounter('user_field', 'total_user_change', 'user_id', $iUserId);
     }
     // updating the full name
     if (isset($aSpecial['full_name_changes_allowed']) && ($aSpecial['full_name_changes_allowed'] > $aSpecial['total_full_name_change'] || $aSpecial['full_name_changes_allowed'] == 0) && Phpfox::getUserParam('user.can_change_own_full_name') && $aSpecial['current_full_name'] != $aVals['full_name']) {
         if (Phpfox::getLib('parse.format')->isEmpty($aVals['full_name'])) {
             Phpfox_Error::set(Phpfox::getPhrase('user.provide_a_name_that_is_not_representing_an_empty_name'));
         }
         if (!Phpfox::getService('ban')->check('display_name', $aVals['full_name'])) {
             Phpfox_Error::set(Phpfox::getPhrase('user.this_display_name_is_not_allowed_to_be_used'));
         }
         if (!Phpfox_Error::isPassed()) {
             return false;
         }
         $aInsert['full_name'] = $oParseInput->clean($aVals['full_name'], 255);
         if ($aSpecial['full_name_changes_allowed'] > 0) {
             $this->database()->updateCounter('user_field', 'total_full_name_change', 'user_id', $iUserId);
         }
     }
     $sFullName = Phpfox::getUserBy('full_name');
     $this->database()->update($this->_sTable, $aInsert, 'user_id = ' . (int) $iUserId);
     $aInsert['prev_full_name'] = $sFullName;
     Phpfox::masscallback('onUserUpdate', $aInsert);
     if ($sPlugin = Phpfox_Plugin::get('user.service_process_update_1')) {
         eval($sPlugin);
         if (isset($mPluginReturn)) {
             return $mPluginReturn;
         }
     }
     if (!$bIsAccount) {
         if ($bHasCountryChildren && isset($aVals['country_child_id'])) {
             Phpfox::getService('user.field.process')->update($iUserId, 'country_child_id', $aVals['country_child_id']);
         } else {
             Phpfox::getService('user.field.process')->update($iUserId, 'country_child_id', 0);
         }
         if (isset($aVals['city_location'])) {
             Phpfox::getService('user.field.process')->update($iUserId, 'city_location', empty($aVals['city_location']) ? null : Phpfox::getLib('parse.input')->clean($aVals['city_location'], 100));
         }
         if (isset($aVals['postal_code'])) {
             Phpfox::getService('user.field.process')->update($iUserId, 'postal_code', empty($aVals['postal_code']) ? null : Phpfox::getLib('parse.input')->clean($aVals['postal_code'], 20));
         }
         if (isset($aVals['signature'])) {
             Phpfox::getService('user.field.process')->update($iUserId, 'signature', empty($aVals['signature']) ? null : Phpfox::getLib('parse.input')->prepare($aVals['signature']));
             Phpfox::getService('user.field.process')->update($iUserId, 'signature_clean', empty($aVals['signature']) ? null : Phpfox::getLib('parse.input')->clean($aVals['signature']));
         }
     }
     if (isset($aVals['default_currency'])) {
         Phpfox::getService('user.field.process')->update($iUserId, 'default_currency', empty($aVals['default_currency']) ? null : $aVals['default_currency']);
         $this->cache()->remove(array('currency', $iUserId));
     }
     if (isset($aVals['use_timeline'])) {
         Phpfox::getService('user.field.process')->update($iUserId, 'use_timeline', empty($aVals['use_timeline']) ? 0 : $aVals['use_timeline']);
     }
     if (isset($aVals['landing_page'])) {
         Phpfox::getService('user.field.process')->update($iUserId, 'landing_page', empty($aVals['landing_page']) ? 0 : $aVals['landing_page']);
     }
     if (Phpfox::getParam('user.split_full_name')) {
         Phpfox::getService('user.field.process')->update($iUserId, 'first_name', empty($aVals['first_name']) ? null : $aVals['first_name']);
         Phpfox::getService('user.field.process')->update($iUserId, 'last_name', empty($aVals['last_name']) ? null : $aVals['last_name']);
     }
     if (!$bIsAccount) {
         if (isset($aVals['day']) && isset($aVals['month'])) {
             $this->database()->update(Phpfox::getT('user_field'), array('birthday_range' => '\'' . Phpfox::getService('user')->buildAge($aVals['day'], $aVals['month']) . '\''), 'user_id = ' . $iUserId, false);
         }
     }
     if (isset($aVals['gateway_detail']) && is_array($aVals['gateway_detail'])) {
         $aGateways = array();
         $this->database()->delete(Phpfox::getT('user_gateway'), 'user_id = ' . (int) $iUserId);
         foreach ($aVals['gateway_detail'] as $sGateway => $mValue) {
             $this->database()->insert(Phpfox::getT('user_gateway'), array('user_id' => $iUserId, 'gateway_id' => $sGateway, 'gateway_detail' => serialize($mValue)));
         }
     }
     $this->database()->insert(Phpfox::getT('user_ip'), array('user_id' => $iUserId, 'type_id' => 'update_account', 'ip_address' => Phpfox::getIp(), 'time_stamp' => PHPFOX_TIME));
     ($sPlugin = Phpfox_Plugin::get('user.service_process_update_end')) ? eval($sPlugin) : false;
     return true;
 }