0byt3m1n1-V2
Path:
/
home
/
a
/
c
/
a
/
academiac
/
www
/
[
Home
]
File: profile.php.tar
home/academiac/www/administrator/components/com_admin/models/profile.php 0000644 00000007461 15137241223 0022646 0 ustar 00 <?php /** * @copyright Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ // No direct access. defined('_JEXEC') or die; require_once JPATH_ADMINISTRATOR.'/components/com_users/models/user.php'; /** * User model. * * @package Joomla.Administrator * @subpackage com_admin * @since 1.6 */ class AdminModelProfile extends UsersModelUser { /** * Method to get the record form. * * @param array $data An optional array of data for the form to interogate. * @param boolean $loadData True if the form is to load its own data (default case), false if not. * @return JForm A JForm object on success, false on failure * @since 1.6 */ public function getForm($data = array(), $loadData = true) { // Initialise variables. $app = JFactory::getApplication(); // Get the form. $form = $this->loadForm('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.php 0000644 00000004253 15137374405 0023736 0 ustar 00 <?php /** * @package Joomla.Administrator * @subpackage com_admin * @copyright Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ // No direct access. defined('_JEXEC') or die; jimport('joomla.application.component.controllerform'); /** * User profile controller class. * * @package Joomla.Administrator * @subpackage com_admin * @since 1.6 */ class AdminControllerProfile extends JControllerForm { /** * Method to check if you can add a new record. * * Extended classes can override this if necessary. * * @param array An array of input data. * @param string The name of the key for the primary key. * * @return boolean * @since 1.6 */ protected function allowEdit($data = array(), $key = 'id') { return isset($data['id']) && $data['id'] == JFactory::getUser()->id; } /** * 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.php 0000644 00000017111 15137433724 0016471 0 ustar 00 <?php /** * @copyright Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ defined('JPATH_BASE') or die; jimport('joomla.utilities.date'); /** * An example custom profile plugin. * * @package Joomla.Plugin * @subpackage User.profile * @version 1.6 */ class plgUserProfile extends JPlugin { /** * Constructor * * @access protected * @param object $subject The object to observe * @param array $config An array that holds the plugin configuration * @since 1.5 */ public function __construct(& $subject, $config) { parent::__construct($subject, $config); $this->loadLanguage(); 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 '<a href="'.$value.'">'.$value.'</a>'; } else { return '<a href="http://'.$value.'">'.$value.'</a>'; } } } 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; } } home/academiac/www/components/com_users/controllers/profile.php 0000644 00000011471 15140044617 0021120 0 ustar 00 <?php /** * @package Joomla.Site * @subpackage com_users * @copyright Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ defined('_JEXEC') or die; require_once JPATH_COMPONENT.'/controller.php'; /** * Profile controller class for Users. * * @package Joomla.Site * @subpackage com_users * @since 1.6 */ class UsersControllerProfile extends UsersController { /** * Method to check out a user for editing and redirect to the edit form. * * @since 1.6 */ public function edit() { $app = JFactory::getApplication(); $user = JFactory::getUser(); $loginUserId = (int) $user->get('id'); // Get the previous user id (if any) and the current user id. $previousId = (int) $app->getUserState('com_users.edit.profile.id'); $userId = (int) JRequest::getInt('user_id', null, '', 'array'); // Check if the user is trying to edit another users profile. if ($userId != $loginUserId) { JError::raiseError(403, JText::_('JERROR_ALERTNOAUTHOR')); return false; } // Set the user id for the user to edit in the session. $app->setUserState('com_users.edit.profile.id', $userId); // Get the model. $model = $this->getModel('Profile', 'UsersModel'); // Check out the user. if ($userId) { $model->checkout($userId); } // Check in the previous user. if ($previousId) { $model->checkin($previousId); } // Redirect to the edit screen. $this->setRedirect(JRoute::_('index.php?option=com_users&view=profile&layout=edit', false)); } /** * Method to save a user's profile data. * * @return void * @since 1.6 */ public function save() { // Check for request forgeries. JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN')); // Initialise variables. $app = JFactory::getApplication(); $model = $this->getModel('Profile', 'UsersModel'); $user = JFactory::getUser(); $userId = (int) $user->get('id'); // Get the user data. $data = JRequest::getVar('jform', array(), 'post', 'array'); // Force the ID to this user. $data['id'] = $userId; // Validate the posted data. $form = $model->getForm(); if (!$form) { JError::raiseError(500, $model->getError()); return false; } // Validate the posted data. $data = $model->validate($form, $data); // Check for errors. if ($data === false) { // Get the validation messages. $errors = $model->getErrors(); // Push up to three validation messages out to the user. for ($i = 0, $n = count($errors); $i < $n && $i < 3; $i++) { if ($errors[$i] instanceof Exception) { $app->enqueueMessage($errors[$i]->getMessage(), 'warning'); } else { $app->enqueueMessage($errors[$i], 'warning'); } } // Save the data in the session. $app->setUserState('com_users.edit.profile.data', $data); // Redirect back to the edit screen. $userId = (int) $app->getUserState('com_users.edit.profile.id'); $this->setRedirect(JRoute::_('index.php?option=com_users&view=profile&layout=edit&user_id='.$userId, false)); return false; } // Attempt to save the data. $return = $model->save($data); // Check for errors. if ($return === false) { // Save the data in the session. $app->setUserState('com_users.edit.profile.data', $data); // Redirect back to the edit screen. $userId = (int)$app->getUserState('com_users.edit.profile.id'); $this->setMessage(JText::sprintf('COM_USERS_PROFILE_SAVE_FAILED', $model->getError()), 'warning'); $this->setRedirect(JRoute::_('index.php?option=com_users&view=profile&layout=edit&user_id='.$userId, false)); return false; } // Redirect the user and adjust session state based on the chosen task. switch ($this->getTask()) { case 'apply': // Check out the profile. $app->setUserState('com_users.edit.profile.id', $return); $model->checkout($return); // Redirect back to the edit screen. $this->setMessage(JText::_('COM_USERS_PROFILE_SAVE_SUCCESS')); $this->setRedirect(JRoute::_(($redirect = $app->getUserState('com_users.edit.profile.redirect')) ? $redirect : 'index.php?option=com_users&view=profile&layout=edit&hidemainmenu=1', false)); break; default: // Check in the profile. $userId = (int)$app->getUserState('com_users.edit.profile.id'); if ($userId) { $model->checkin($userId); } // Clear the profile id from the session. $app->setUserState('com_users.edit.profile.id', null); // Redirect to the list screen. $this->setMessage(JText::_('COM_USERS_PROFILE_SAVE_SUCCESS')); $this->setRedirect(JRoute::_(($redirect = $app->getUserState('com_users.edit.profile.redirect')) ? $redirect : 'index.php?option=com_users&view=profile&user_id='.$return, false)); break; } // Flush the data from the session. $app->setUserState('com_users.edit.profile.data', null); } } home/academiac/www/components/com_users/models/profile.php 0000644 00000017027 15140275025 0020037 0 ustar 00 <?php /** * @package Joomla.Site * @subpackage com_users * @copyright Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ defined('_JEXEC') or die; jimport('joomla.application.component.modelform'); jimport('joomla.event.dispatcher'); /** * Profile model class for Users. * * @package Joomla.Site * @subpackage com_users * @since 1.6 */ class UsersModelProfile extends JModelForm { /** * @var object The user profile data. * @since 1.6 */ protected $data; /** * Method to check in a user. * * @param integer The id of the row to check out. * @return boolean True on success, false on failure. * @since 1.6 */ public function checkin($userId = null) { // Get the user id. $userId = (!empty($userId)) ? $userId : (int)$this->getState('user.id'); if ($userId) { // Initialise the table with JUser. $table = JTable::getInstance('User'); // Attempt to check the row in. if (!$table->checkin($userId)) { $this->setError($table->getError()); return false; } } return true; } /** * Method to check out a user for editing. * * @param integer The id of the row to check out. * @return boolean True on success, false on failure. * @since 1.6 */ public function checkout($userId = null) { // Get the user id. $userId = (!empty($userId)) ? $userId : (int)$this->getState('user.id'); if ($userId) { // Initialise the table with JUser. $table = JTable::getInstance('User'); // Get the current user object. $user = JFactory::getUser(); // Attempt to check the row out. if (!$table->checkout($user->get('id'), $userId)) { $this->setError($table->getError()); return false; } } return true; } /** * Method to get the profile form data. * * The base form data is loaded and then an event is fired * for users plugins to extend the data. * * @return mixed Data object on success, false on failure. * @since 1.6 */ public function getData() { if ($this->data === null) { $userId = $this->getState('user.id'); // Initialise the table with JUser. $this->data = new JUser($userId); // Set the base user data. $this->data->email1 = $this->data->get('email'); $this->data->email2 = $this->data->get('email'); // Override the base user data with any data in the session. $temp = (array)JFactory::getApplication()->getUserState('com_users.edit.profile.data', array()); foreach ($temp as $k => $v) { $this->data->$k = $v; } // Unset the passwords. unset($this->data->password1); unset($this->data->password2); $registry = new JRegistry($this->data->params); $this->data->params = $registry->toArray(); // 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_users.profile', $this->data)); // Check for errors encountered while preparing the data. if (count($results) && in_array(false, $results, true)) { $this->setError($dispatcher->getError()); $this->data = false; } } return $this->data; } /** * Method to get the profile form. * * The base form is loaded from XML and then an event is fired * for users plugins to extend the form with extra fields. * * @param array $data An optional array of data for the form to interogate. * @param boolean $loadData True if the form is to load its own data (default case), false if not. * @return JForm A JForm object on success, false on failure * @since 1.6 */ public function getForm($data = array(), $loadData = true) { // Get the form. $form = $this->loadForm('com_users.profile', 'profile', array('control' => 'jform', 'load_data' => $loadData)); if (empty($form)) { return false; } // Check for username compliance and parameter set $isUsernameCompliant = 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', 'class', ''); $form->setFieldAttribute('username', 'filter', ''); $form->setFieldAttribute('username', 'description', 'COM_USERS_PROFILE_NOCHANGE_USERNAME_DESC'); $form->setFieldAttribute('username', 'validate', ''); $form->setFieldAttribute('username', 'message', ''); $form->setFieldAttribute('username', 'readonly', 'true'); $form->setFieldAttribute('username', 'required', 'false'); } 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() { return $this->getData(); } /** * Override preprocessForm to load the user plugin group instead of content. * * @param object A form object. * @param mixed The data expected for the form. * @throws Exception if there is an error in the form event. * @since 1.6 */ protected function preprocessForm(JForm $form, $data, $group = 'user') { if (JComponentHelper::getParams('com_users')->get('frontend_userparams')) { $form->loadFile('frontend', false); if (JFactory::getUser()->authorise('core.login.admin')) { $form->loadFile('frontend_admin', false); } } parent::preprocessForm($form, $data, $group); } /** * Method to auto-populate the model state. * * Note. Calling getState in this method will result in recursion. * * @since 1.6 */ protected function populateState() { // Get the application object. $params = JFactory::getApplication()->getParams('com_users'); // Get the user id. $userId = JFactory::getApplication()->getUserState('com_users.edit.profile.id'); $userId = !empty($userId) ? $userId : (int)JFactory::getUser()->get('id'); // Set the user id. $this->setState('user.id', $userId); // Load the parameters. $this->setState('params', $params); } /** * Method to save the form data. * * @param array The form data. * @return mixed The user id on success, false on failure. * @since 1.6 */ public function save($data) { $userId = (!empty($data['id'])) ? $data['id'] : (int)$this->getState('user.id'); $user = new JUser($userId); // Prepare the data for the user object. $data['email'] = $data['email1']; $data['password'] = $data['password1']; // 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']); } // Unset the block so it does not get overwritten unset($data['block']); // Unset the sendEmail so it does not get overwritten unset($data['sendEmail']); // Bind the data. if (!$user->bind($data)) { $this->setError(JText::sprintf('COM_USERS_PROFILE_BIND_FAILED', $user->getError())); return false; } // Load the users plugin group. JPluginHelper::importPlugin('user'); // Null the user groups so they don't get overwritten $user->groups = null; // Store the data. if (!$user->save()) { $this->setError($user->getError()); return false; } return $user->id; } }
©
2018.