Source for file profile.php

Documentation is available at profile.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Administrator
  4.  * @subpackage  com_admin
  5.  *
  6.  * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
  7.  * @license     GNU General Public License version 2 or later; see LICENSE.txt
  8.  */
  9.  
  10. defined('_JEXEC'or die;
  11.  
  12. require_once JPATH_ADMINISTRATOR '/components/com_users/models/user.php';
  13.  
  14. /**
  15.  * User model.
  16.  *
  17.  * @package     Joomla.Administrator
  18.  * @subpackage  com_admin
  19.  * @since       1.6
  20.  */
  21. {
  22.     /**
  23.      * Method to get the record form.
  24.      *
  25.      * @param   array    $data      An optional array of data for the form to interogate.
  26.      * @param   boolean  $loadData  True if the form is to load its own data (default case), false if not.
  27.      *
  28.      * @return  JForm    A JForm object on success, false on failure
  29.      *
  30.      * @since   1.6
  31.      */
  32.     public function getForm($data array()$loadData true)
  33.     {
  34.         // Get the form.
  35.         $form $this->loadForm('com_admin.profile''profile'array('control' => 'jform''load_data' => $loadData));
  36.  
  37.         if (empty($form))
  38.         {
  39.             return false;
  40.         }
  41.  
  42.         // Check for username compliance and parameter set
  43.         $usernameCompliant true;
  44.  
  45.         if ($this->loadFormData()->username)
  46.         {
  47.             $username $this->loadFormData()->username;
  48.             $isUsernameCompliant  !(preg_match('#[<>"\'%;()&\\s\\\\]|\\.\\./#'$username|| strlen(utf8_decode($username)) 2);
  49.         }
  50.  
  51.         $this->setState('user.username.compliant'$isUsernameCompliant);
  52.  
  53.         if (!JComponentHelper::getParams('com_users')->get('change_login_name'&& $isUsernameCompliant)
  54.         {
  55.             $form->setFieldAttribute('username''required''false');
  56.             $form->setFieldAttribute('username''readonly''true');
  57.             $form->setFieldAttribute('username''description''COM_ADMIN_USER_FIELD_NOCHANGE_USERNAME_DESC');
  58.         }
  59.  
  60.         return $form;
  61.     }
  62.  
  63.     /**
  64.      * Method to get the data that should be injected in the form.
  65.      *
  66.      * @return  mixed  The data for the form.
  67.      *
  68.      * @since   1.6
  69.      */
  70.     protected function loadFormData()
  71.     {
  72.         // Check the session for previously entered form data.
  73.         $data JFactory::getApplication()->getUserState('com_users.edit.user.data'array());
  74.  
  75.         if (empty($data))
  76.         {
  77.             $data $this->getItem();
  78.         }
  79.  
  80.         // Load the users plugins.
  81.         JPluginHelper::importPlugin('user');
  82.  
  83.         $this->preprocessData('com_admin.profile'$data);
  84.  
  85.         return $data;
  86.     }
  87.  
  88.     /**
  89.      * Method to get a single record.
  90.      *
  91.      * @param   integer  $pk  The id of the primary key.
  92.      *
  93.      * @return  mixed  Object on success, false on failure.
  94.      *
  95.      * @since   1.6
  96.      */
  97.     public function getItem($pk null)
  98.     {
  99.         $user JFactory::getUser();
  100.  
  101.         return parent::getItem($user->get('id'));
  102.     }
  103.  
  104.     /**
  105.      * Method to save the form data.
  106.      *
  107.      * @param   array  $data  The form data.
  108.      *
  109.      * @return  boolean  True on success.
  110.      *
  111.      * @since   1.6
  112.      */
  113.     public function save($data)
  114.     {
  115.         $user JFactory::getUser();
  116.  
  117.         unset($data['id']);
  118.         unset($data['groups']);
  119.         unset($data['sendEmail']);
  120.         unset($data['block']);
  121.  
  122.         // Unset the username if it should not be overwritten
  123.         $username $data['username'];
  124.         $isUsernameCompliant $this->getState('user.username.compliant');
  125.  
  126.         if (!JComponentHelper::getParams('com_users')->get('change_login_name'&& $isUsernameCompliant)
  127.         {
  128.             unset($data['username']);
  129.         }
  130.  
  131.         // Bind the data.
  132.         if (!$user->bind($data))
  133.         {
  134.             $this->setError($user->getError());
  135.  
  136.             return false;
  137.         }
  138.  
  139.         $user->groups null;
  140.  
  141.         // Store the data.
  142.         if (!$user->save())
  143.         {
  144.             $this->setError($user->getError());
  145.  
  146.             return false;
  147.         }
  148.  
  149.         $this->setState('user.id'$user->id);
  150.  
  151.         return true;
  152.     }
  153. }

Documentation generated on Tue, 19 Nov 2013 15:11:18 +0100 by phpDocumentor 1.4.3