[ Index ]

PHP Cross Reference of Joomla 1.5.26 DE

title

Body

[close]

/plugins/user/ -> example.php (source)

   1  <?php
   2  /**
   3   * @version        $Id: example.php 14401 2010-01-26 14:10:00Z louis $
   4   * @package        Joomla
   5   * @subpackage    JFramework
   6   * @copyright    Copyright (C) 2005 - 2010 Open Source Matters. All rights reserved.
   7   * @license        GNU/GPL, see LICENSE.php
   8   * Joomla! is free software. This version may have been modified pursuant
   9   * to the GNU General Public License, and as distributed it includes or
  10   * is derivative of works licensed under the GNU General Public License or
  11   * other free or open source software licenses.
  12   * See COPYRIGHT.php for copyright notices and details.
  13   */
  14  
  15  // Check to ensure this file is included in Joomla!
  16  defined('_JEXEC') or die( 'Restricted access' );
  17  
  18  jimport('joomla.plugin.plugin');
  19  
  20  /**
  21   * Example User Plugin
  22   *
  23   * @package        Joomla
  24   * @subpackage    JFramework
  25   * @since         1.5
  26   */
  27  class plgUserExample extends JPlugin {
  28  
  29      /**
  30       * Constructor
  31       *
  32       * For php4 compatability we must not use the __constructor as a constructor for plugins
  33       * because func_get_args ( void ) returns a copy of all passed arguments NOT references.
  34       * This causes problems with cross-referencing necessary for the observer design pattern.
  35       *
  36       * @param object $subject The object to observe
  37       * @param     array  $config  An array that holds the plugin configuration
  38       * @since 1.5
  39       */
  40  	function plgUserExample(& $subject, $config)
  41      {
  42          parent::__construct($subject, $config);
  43      }
  44  
  45      /**
  46       * Example store user method
  47       *
  48       * Method is called before user data is stored in the database
  49       *
  50       * @param     array        holds the old user data
  51       * @param     boolean        true if a new user is stored
  52       */
  53  	function onBeforeStoreUser($user, $isnew)
  54      {
  55          global $mainframe;
  56      }
  57  
  58      /**
  59       * Example store user method
  60       *
  61       * Method is called after user data is stored in the database
  62       *
  63       * @param     array        holds the new user data
  64       * @param     boolean        true if a new user is stored
  65       * @param    boolean        true if user was succesfully stored in the database
  66       * @param    string        message
  67       */
  68  	function onAfterStoreUser($user, $isnew, $success, $msg)
  69      {
  70          global $mainframe;
  71  
  72          // convert the user parameters passed to the event
  73          // to a format the external application
  74  
  75          $args = array();
  76          $args['username']    = $user['username'];
  77          $args['email']         = $user['email'];
  78          $args['fullname']    = $user['name'];
  79          $args['password']    = $user['password'];
  80  
  81          if ($isnew)
  82          {
  83              // Call a function in the external app to create the user
  84              // ThirdPartyApp::createUser($user['id'], $args);
  85          }
  86          else
  87          {
  88              // Call a function in the external app to update the user
  89              // ThirdPartyApp::updateUser($user['id'], $args);
  90          }
  91      }
  92  
  93      /**
  94       * Example store user method
  95       *
  96       * Method is called before user data is deleted from the database
  97       *
  98       * @param     array        holds the user data
  99       */
 100  	function onBeforeDeleteUser($user)
 101      {
 102          global $mainframe;
 103      }
 104  
 105      /**
 106       * Example store user method
 107       *
 108       * Method is called after user data is deleted from the database
 109       *
 110       * @param     array        holds the user data
 111       * @param    boolean        true if user was succesfully stored in the database
 112       * @param    string        message
 113       */
 114  	function onAfterDeleteUser($user, $succes, $msg)
 115      {
 116          global $mainframe;
 117  
 118           // only the $user['id'] exists and carries valid information
 119  
 120          // Call a function in the external app to delete the user
 121          // ThirdPartyApp::deleteUser($user['id']);
 122      }
 123  
 124      /**
 125       * This method should handle any login logic and report back to the subject
 126       *
 127       * @access    public
 128       * @param     array     holds the user data
 129       * @param     array    extra options
 130       * @return    boolean    True on success
 131       * @since    1.5
 132       */
 133  	function onLoginUser($user, $options)
 134      {
 135          // Initialize variables
 136          $success = false;
 137  
 138          // Here you would do whatever you need for a login routine with the credentials
 139          //
 140          // Remember, this is not the authentication routine as that is done separately.
 141          // The most common use of this routine would be logging the user into a third party
 142          // application.
 143          //
 144          // In this example the boolean variable $success would be set to true
 145          // if the login routine succeeds
 146  
 147          // ThirdPartyApp::loginUser($user['username'], $user['password']);
 148  
 149          return $success;
 150      }
 151  
 152      /**
 153       * This method should handle any logout logic and report back to the subject
 154       *
 155       * @access public
 156       * @param array holds the user data
 157       * @return boolean True on success
 158       * @since 1.5
 159       */
 160  	function onLogoutUser($user)
 161      {
 162          // Initialize variables
 163          $success = false;
 164  
 165          // Here you would do whatever you need for a logout routine with the credentials
 166          //
 167          // In this example the boolean variable $success would be set to true
 168          // if the logout routine succeeds
 169  
 170          // ThirdPartyApp::loginUser($user['username'], $user['password']);
 171  
 172          return $success;
 173      }
 174  }


Generated: Wed Mar 28 15:54:07 2012 Cross-referenced by PHPXref 0.7.1