/** * Saves a user's profile * * @access private * @param none */ private function _saveProfile() { $model = $this->getModel('profile'); $usermodel = $this->getModel('user'); $document = JFactory::getDocument(); $my = CFactory::getUser(); $mainframe = JFactory::getApplication(); $jinput = $mainframe->input; $input = CFactory::getInput(); if ($my->id == 0) { return $this->blockUnregister(); } $appsLib = CAppPlugins::getInstance(); $saveSuccess = $appsLib->triggerEvent('onFormSave', array('jsform-profile-edit')); if (empty($saveSuccess) || !in_array(false, $saveSuccess)) { $values = array(); $profiles = $model->getEditableProfile($my->id, $my->getProfileType()); foreach ($profiles['fields'] as $group => $fields) { foreach ($fields as $data) { $fieldValue = new stdClass(); // Get value from posted data and map it to the field. // Here we need to prepend the 'field' before the id because in the form, the 'field' is prepended to the id. // Grab raw, unfiltered data $postData = $input->post->get('field' . $data['id'], '', 'RAW'); // // Retrieve the privacy data for this particular field. $fieldValue->access = JRequest::getInt('privacy' . $data['id'], 0, 'POST'); $fieldValue->value = CProfileLibrary::formatData($data['type'], $postData); if (get_magic_quotes_gpc()) { $fieldValue->value = stripslashes($fieldValue->value); } $values[$data['id']] = $fieldValue; // @rule: Validate custom profile if necessary if (!CProfileLibrary::validateField($data['id'], $data['type'], $values[$data['id']]->value, $data['required'], $data['visible'])) { // If there are errors on the form, display to the user. // If it is a drop down selection, use a different message $message = ''; switch ($data['type']) { case 'select': $message = JText::sprintf('COM_COMMUNITY_FIELD_SELECT_EMPTY', $data['name']); break; case 'url': $message = JText::sprintf('COM_COMMUNITY_FIELD_INVALID_URL', $data['name']); break; default: $data['value'] = $values[$data['id']]->value; $message = CProfileLibrary::getErrorMessage($data); } $mainframe->enqueueMessage(CTemplate::quote($message), 'error'); return false; } } } // Rebuild new $values with field code $valuesCode = array(); foreach ($values as $key => $val) { $fieldCode = $model->getFieldCode($key); if ($fieldCode) { // For backward compatibility, we can't pass in an object. We need it to behave // like 1.8.x where we only pass values. $valuesCode[$fieldCode] = $val->value; } } $saveSuccess = false; $appsLib = CAppPlugins::getInstance(); $appsLib->loadApplications(); // Trigger before onBeforeUserProfileUpdate $args = array(); $args[] = $my->id; $args[] = $valuesCode; $result = $appsLib->triggerEvent('onBeforeProfileUpdate', $args); $optionList = $model->getAllList(); foreach ($optionList as $list) { // $optionList return all the list, even if the field is disabled // So, need to check if we're using it or not first if (isset($values[$list['id']]) && is_array($list['options'])) { $option = $values[$list['id']]->value; $option = str_replace('&', '&', $option); if (JString::strlen(JString::trim($option)) != 0 && !in_array($option, $list['options'])) { if (!in_array($option, CProfile::getCountryList())) { $result[] = false; } } } } // make sure none of the $result is false if (!$result || !in_array(false, $result)) { $saveSuccess = true; $model->saveProfile($my->id, $values); } } // Trigger before onAfterUserProfileUpdate $args = array(); $args[] = $my->id; $args[] = $saveSuccess; $result = $appsLib->triggerEvent('onAfterProfileUpdate', $args); if ($saveSuccess) { CUserPoints::assignPoint('profile.save'); return true; } else { $mainframe->enqueueMessage(JText::_('COM_COMMUNITY_PROFILE_NOT_SAVED'), 'error'); return false; } }