[ Index ]

PHP Cross Reference of Joomla 2.5.4 DE

title

Body

[close]

/administrator/components/com_login/models/ -> login.php (source)

   1  <?php
   2  /**
   3   * @copyright    Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
   4   * @license        GNU General Public License, see LICENSE.php
   5   */
   6  
   7  // No direct access.
   8  defined('_JEXEC') or die;
   9  
  10  jimport( 'joomla.application.component.model' );
  11  
  12  /**
  13   * Login Model
  14   *
  15   * @package        Joomla.Administrator
  16   * @subpackage    com_login
  17   * @since        1.5
  18   */
  19  class LoginModelLogin extends JModel
  20  {
  21      /**
  22       * Method to auto-populate the model state.
  23       *
  24       * Note. Calling getState in this method will result in recursion.
  25       *
  26       * @since    1.6
  27       */
  28  	protected function populateState()
  29      {
  30          $credentials = array(
  31              'username' => JRequest::getVar('username', '', 'method', 'username'),
  32              'password' => JRequest::getVar('passwd', '', 'post', 'string', JREQUEST_ALLOWRAW)
  33          );
  34          $this->setState('credentials', $credentials);
  35  
  36          // check for return URL from the request first
  37          if ($return = JRequest::getVar('return', '', 'method', 'base64')) {
  38              $return = base64_decode($return);
  39              if (!JURI::isInternal($return)) {
  40                  $return = '';
  41              }
  42          }
  43  
  44          // Set the return URL if empty.
  45          if (empty($return)) {
  46              $return = 'index.php';
  47          }
  48  
  49          $this->setState('return', $return);
  50      }
  51  
  52      /**
  53       * Get the administrator login module by name (real, eg 'login' or folder, eg 'mod_login')
  54       *
  55       * @param   string  $name   The name of the module
  56       * @param   string  $title  The title of the module, optional
  57       *
  58       * @return  object  The Module object
  59       *
  60       * @since   11.1
  61       */
  62  	public static function getLoginModule($name = 'mod_login', $title = null)
  63      {
  64          $result        = null;
  65          $modules    = LoginModelLogin::_load($name);
  66          $total        = count($modules);
  67  
  68          for ($i = 0; $i < $total; $i++)
  69          {
  70              // Match the title if we're looking for a specific instance of the module
  71              if (!$title || $modules[$i]->title == $title) {
  72                  $result = $modules[$i];
  73                  break;    // Found it
  74              }
  75          }
  76  
  77          // If we didn't find it, and the name is mod_something, create a dummy object
  78          if (is_null($result) && substr($name, 0, 4) == 'mod_') {
  79              $result                = new stdClass;
  80              $result->id            = 0;
  81              $result->title        = '';
  82              $result->module        = $name;
  83              $result->position    = '';
  84              $result->content    = '';
  85              $result->showtitle    = 0;
  86              $result->control    = '';
  87              $result->params        = '';
  88              $result->user        = 0;
  89          }
  90  
  91          return $result;
  92      }
  93      /**
  94       * Load login modules.
  95       *
  96       * Note that we load regardless of state or access level since access
  97       * for public is the only thing that makes sense since users are not logged in
  98       * and the module lets them log in.
  99       * This is put in as a failsafe to avoid super user lock out caused by an unpublished
 100       * login module or by a module set to have a viewing access level that is not Public.
 101       *
 102       * @param   string  $name   The name of the module
 103       *
 104       * @return  array
 105       *
 106       * @since   11.1
 107       */
 108  	protected static function _load($module)
 109      {
 110          static $clean;
 111  
 112          if (isset($clean)) {
 113              return $clean;
 114          }
 115  
 116          $app        = JFactory::getApplication();
 117          $lang         = JFactory::getLanguage()->getTag();
 118          $clientId     = (int) $app->getClientId();
 119  
 120          $cache         = JFactory::getCache ('com_modules', '');
 121          $cacheid     = md5(serialize(array( $clientId, $lang)));
 122          $loginmodule = array();
 123  
 124          if (!($clean = $cache->get($cacheid))) {
 125              $db    = JFactory::getDbo();
 126  
 127              $query = $db->getQuery(true);
 128              $query->select('m.id, m.title, m.module, m.position, m.showtitle, m.params');
 129              $query->from('#__modules AS m');
 130              $query->where('m.module =' . $db->Quote($module) .' AND m.client_id = 1');
 131  
 132              $query->join('LEFT', '#__extensions AS e ON e.element = m.module AND e.client_id = m.client_id');
 133              $query->where('e.enabled = 1');
 134  
 135              // Filter by language
 136              if ($app->isSite() && $app->getLanguageFilter()) {
 137                  $query->where('m.language IN (' . $db->Quote($lang) . ',' . $db->Quote('*') . ')');
 138              }
 139  
 140              $query->order('m.position, m.ordering');
 141  
 142              // Set the query
 143              $db->setQuery($query);
 144              $modules = $db->loadObjectList();
 145  
 146              if ($db->getErrorNum()){
 147                  JError::raiseWarning(500, JText::sprintf('JLIB_APPLICATION_ERROR_MODULE_LOAD', $db->getErrorMsg()));
 148                  return $loginmodule;
 149              }
 150  
 151  
 152              // Return to simple indexing that matches the query order.
 153              $loginmodule = $modules;
 154  
 155              $cache->store($loginmodule, $cacheid);
 156          }
 157  
 158          return $loginmodule;
 159      }
 160  }


Generated: Tue Apr 3 11:40:28 2012 Cross-referenced by PHPXref 0.7.1