AAAAhome/academiac/www/administrator/components/com_admin/models/profile.php000064400000007461151372412230022646 0ustar00loadForm('com_admin.profile', 'profile', array('control' => 'jform', 'load_data' => $loadData)); if (empty($form)) { return false; } // Check for username compliance and parameter set $usernameCompliant = true; if ($this->loadFormData()->username) { $username = $this->loadFormData()->username; $isUsernameCompliant = !(preg_match('#[<>"\'%;()&\\\\]|\\.\\./#', $username) || strlen(utf8_decode($username)) < 2 || trim($username) != $username); } $this->setState('user.username.compliant', $isUsernameCompliant); if (!JComponentHelper::getParams('com_users')->get('change_login_name') && $isUsernameCompliant) { $form->setFieldAttribute('username', 'required', 'false'); $form->setFieldAttribute('username', 'readonly', 'true'); $form->setFieldAttribute('username', 'description', 'COM_ADMIN_USER_FIELD_NOCHANGE_USERNAME_DESC'); } return $form; } /** * Method to get the data that should be injected in the form. * * @return mixed The data for the form. * @since 1.6 */ protected function loadFormData() { // Check the session for previously entered form data. $data = JFactory::getApplication()->getUserState('com_users.edit.user.data', array()); if (empty($data)) { $data = $this->getItem(); } // TODO: Maybe this can go into the parent model somehow? // Get the dispatcher and load the users plugins. $dispatcher = JDispatcher::getInstance(); JPluginHelper::importPlugin('user'); // Trigger the data preparation event. $results = $dispatcher->trigger('onContentPrepareData', array('com_admin.profile', $data)); // Check for errors encountered while preparing the data. if (count($results) && in_array(false, $results, true)) { $this->setError($dispatcher->getError()); } return $data; } /** * Method to get a single record. * * @return mixed Object on success, false on failure. * @since 1.6 */ public function getItem($pk = null) { $user = JFactory::getUser(); return parent::getItem($user->get('id')); } /** * Method to save the form data. * * @param array $data The form data. * * @return boolean True on success. * @since 1.6 */ public function save($data) { // Initialise variables; $user = JFactory::getUser(); unset($data['id']); unset($data['groups']); unset($data['sendEmail']); unset($data['block']); // Unset the username if it should not be overwritten $username = $data['username']; $isUsernameCompliant = $this->getState('user.username.compliant'); if (!JComponentHelper::getParams('com_users')->get('change_login_name') && $isUsernameCompliant) { unset($data['username']); } // Bind the data. if (!$user->bind($data)) { $this->setError($user->getError()); return false; } $user->groups = null; // Store the data. if (!$user->save()) { $this->setError($user->getError()); return false; } $this->setState('user.id', $user->id); return true; } } home/academiac/www/administrator/components/com_admin/controllers/profile.php000064400000004253151373744050023736 0ustar00id; } /** * Overrides parent save method to check the submitted passwords match. * * @return mixed Boolean or JError. * @since 1.6 */ public function save($key = null, $urlVar = null) { $data = JRequest::getVar('jform', array(), 'post', 'array'); // TODO: JForm should really have a validation handler for this. if (isset($data['password']) && isset($data['password2'])) { // Check the passwords match. if ($data['password'] != $data['password2']) { $this->setMessage(JText::_('JLIB_USER_ERROR_PASSWORD_NOT_MATCH'), 'warning'); $this->setRedirect(JRoute::_('index.php?option=com_admin&view=profile&layout=edit&id='.JFactory::getUser()->id, false)); return false; } unset($data['password2']); } $return = parent::save(); if ($this->getTask() != 'apply') { // Redirect to the main page. $this->setRedirect(JRoute::_('index.php', false)); } return $return; } /** * Method to cancel an edit. * * @param string $key The name of the primary key of the URL variable. * * @return Boolean True if access level checks pass, false otherwise. * @since 1.6 */ public function cancel($key = null) { $return = parent::cancel($key); // Redirect to the main page. $this->setRedirect(JRoute::_('index.php', false)); return $return; } } home/academiac/www/plugins/user/profile/profile.php000064400000017111151374337240016471 0ustar00loadLanguage(); JFormHelper::addFieldPath(dirname(__FILE__) . '/fields'); } /** * @param string $context The context for the data * @param int $data The user id * @param object * * @return boolean * @since 1.6 */ function onContentPrepareData($context, $data) { // Check we are manipulating a valid form. if (!in_array($context, array('com_users.profile', 'com_users.user', 'com_users.registration', 'com_admin.profile'))) { return true; } if (is_object($data)) { $userId = isset($data->id) ? $data->id : 0; if (!isset($data->profile) and $userId > 0) { // Load the profile data from the database. $db = JFactory::getDbo(); $db->setQuery( 'SELECT profile_key, profile_value FROM #__user_profiles' . ' WHERE user_id = '.(int) $userId." AND profile_key LIKE 'profile.%'" . ' ORDER BY ordering' ); $results = $db->loadRowList(); // Check for a database error. if ($db->getErrorNum()) { $this->_subject->setError($db->getErrorMsg()); return false; } // Merge the profile data. $data->profile = array(); foreach ($results as $v) { $k = str_replace('profile.', '', $v[0]); $data->profile[$k] = json_decode($v[1], true); if ($data->profile[$k] === null) { $data->profile[$k] = $v[1]; } } } if (!JHtml::isRegistered('users.url')) { JHtml::register('users.url', array(__CLASS__, 'url')); } if (!JHtml::isRegistered('users.calendar')) { JHtml::register('users.calendar', array(__CLASS__, 'calendar')); } if (!JHtml::isRegistered('users.tos')) { JHtml::register('users.tos', array(__CLASS__, 'tos')); } } return true; } public static function url($value) { if (empty($value)) { return JHtml::_('users.value', $value); } else { $value = htmlspecialchars($value); if (substr ($value, 0, 4) == "http") { return ''.$value.''; } else { return ''.$value.''; } } } public static function calendar($value) { if (empty($value)) { return JHtml::_('users.value', $value); } else { return JHtml::_('date', $value, null, null); } } public static function tos($value) { if ($value) { return JText::_('JYES'); } else { return JText::_('JNO'); } } /** * @param JForm $form The form to be altered. * @param array $data The associated data for the form. * * @return boolean * @since 1.6 */ function onContentPrepareForm($form, $data) { if (!($form instanceof JForm)) { $this->_subject->setError('JERROR_NOT_A_FORM'); return false; } // Check we are manipulating a valid form. $name = $form->getName(); if (!in_array($name, array('com_admin.profile', 'com_users.user', 'com_users.profile', 'com_users.registration'))) { return true; } // Add the registration fields to the form. JForm::addFormPath(dirname(__FILE__) . '/profiles'); $form->loadFile('profile', false); $fields = array( 'address1', 'address2', 'city', 'region', 'country', 'postal_code', 'phone', 'website', 'favoritebook', 'aboutme', 'dob', 'tos', ); $tosarticle = $this->params->get('register_tos_article'); $tosenabled = $this->params->get('register-require_tos', 0); // We need to be in the registration form, field needs to be enabled and we need an article ID if ($name != 'com_users.registration' || !$tosenabled || !$tosarticle) { // We only want the TOS in the registration form $form->removeField('tos', 'profile'); } else { // Push the TOS article ID into the TOS field. $form->setFieldAttribute('tos', 'article', $tosarticle, 'profile'); } foreach ($fields as $field) { // Case using the users manager in admin if ($name == 'com_users.user') { // Remove the field if it is disabled in registration and profile if ($this->params->get('register-require_' . $field, 1) == 0 && $this->params->get('profile-require_' . $field, 1) == 0) { $form->removeField($field, 'profile'); } } // Case registration elseif ($name == 'com_users.registration') { // Toggle whether the field is required. if ($this->params->get('register-require_' . $field, 1) > 0) { $form->setFieldAttribute($field, 'required', ($this->params->get('register-require_' . $field) == 2) ? 'required' : '', 'profile'); } else { $form->removeField($field, 'profile'); } } // Case profile in site or admin elseif ($name == 'com_users.profile' || $name == 'com_admin.profile') { // Toggle whether the field is required. if ($this->params->get('profile-require_' . $field, 1) > 0) { $form->setFieldAttribute($field, 'required', ($this->params->get('profile-require_' . $field) == 2) ? 'required' : '', 'profile'); } else { $form->removeField($field, 'profile'); } } } return true; } function onUserAfterSave($data, $isNew, $result, $error) { $userId = JArrayHelper::getValue($data, 'id', 0, 'int'); if ($userId && $result && isset($data['profile']) && (count($data['profile']))) { try { //Sanitize the date if (!empty($data['profile']['dob'])) { $date = new JDate($data['profile']['dob']); $data['profile']['dob'] = $date->format('Y-m-d'); } $db = JFactory::getDbo(); $db->setQuery( 'DELETE FROM #__user_profiles WHERE user_id = '.$userId . " AND profile_key LIKE 'profile.%'" ); if (!$db->query()) { throw new Exception($db->getErrorMsg()); } $tuples = array(); $order = 1; foreach ($data['profile'] as $k => $v) { $tuples[] = '('.$userId.', '.$db->quote('profile.'.$k).', '.$db->quote(json_encode($v)).', '.$order++.')'; } $db->setQuery('INSERT INTO #__user_profiles VALUES '.implode(', ', $tuples)); if (!$db->query()) { throw new Exception($db->getErrorMsg()); } } catch (JException $e) { $this->_subject->setError($e->getMessage()); return false; } } return true; } /** * Remove all user profile information for the given user ID * * Method is called after user data is deleted from the database * * @param array $user Holds the user data * @param boolean $success True if user was succesfully stored in the database * @param string $msg Message */ function onUserAfterDelete($user, $success, $msg) { if (!$success) { return false; } $userId = JArrayHelper::getValue($user, 'id', 0, 'int'); if ($userId) { try { $db = JFactory::getDbo(); $db->setQuery( 'DELETE FROM #__user_profiles WHERE user_id = '.$userId . " AND profile_key LIKE 'profile.%'" ); if (!$db->query()) { throw new Exception($db->getErrorMsg()); } } catch (JException $e) { $this->_subject->setError($e->getMessage()); return false; } } return true; } }