Source for file user.ext.php

Documentation is available at user.ext.php

  1. <?php
  2.  
  3.     /***********************************************\
  4.      * N2F Yverdon v0                              *
  5.      * Copyright (c) 2009 Zibings Incorporated     *
  6.      *                                             *
  7.      * You should have received a copy of the      *
  8.      * Microsoft Reciprocal License along with     *
  9.      * this program.  If not, see:                 *
  10.      * <http://opensource.org/licenses/ms-rl.html> *
  11.     \***********************************************/
  12.  
  13.     /*
  14.      * $Id: user.ext.php 56 2009-12-23 20:34:50Z amale $
  15.      */
  16.  
  17.     // Pull in our globals
  18.     global $n2f$user$strings;
  19.  
  20.     // Register the extension
  21.     $n2f->registerExtension(
  22.         'n2f_user',
  23.         0.2,
  24.         'Andrew Male',
  25.         'http://n2framework.com/'
  26.     );
  27.  
  28.     // Hook the N2F_EVT_CORE_LOADED event
  29.     $n2f->hookEvent(N2F_EVT_CORE_LOADED'init_user');
  30.  
  31.     // Create the user extension warning constant
  32.     define('N2F_WARN_USER_TIMEOUT',                'U001');
  33.  
  34.     // Create the user extension notice constant
  35.     define('N2F_NOTICE_USER_INIT',                'U001');
  36.  
  37.     // English warning strings
  38.     $strings['en']['N2F_WARN_USER_TIMEOUT']            "The user has timed out.";
  39.  
  40.     // German warning strings
  41.     $strings['de']['N2F_WARN_USER_TIMEOUT']            "The user has timed out.";
  42.  
  43.     // Spanish warning strings
  44.     $strings['es']['N2F_WARN_USER_TIMEOUT']            "The user has timed out.";
  45.  
  46.     // Swedish warning strings
  47.     $strings['se']['N2F_WARN_USER_TIMEOUT']            "The user has timed out.";
  48.  
  49.     // English notice strings
  50.     $strings['en']['N2F_NOTICE_USER_INIT']            "The user object has been initialized.";
  51.  
  52.     // German notice strings
  53.     $strings['de']['N2F_NOTICE_USER_INIT']            "The user object has been initialized.";
  54.  
  55.     // Spanish notice strings
  56.     $strings['es']['N2F_NOTICE_USER_INIT']            "The user object has been initialized.";
  57.  
  58.     // Swedish notice strings
  59.     $strings['se']['N2F_NOTICE_USER_INIT']            "The user object has been initialized.";
  60.  
  61.     /**
  62.      * Function that tries to initialize the $user global.
  63.      *
  64.      * @param n2f_cls $n2f        The object who is calling this function
  65.      * @param mixed $results        The results returned from the system loading its core
  66.      * @return null 
  67.      */
  68.     function init_user(n2f_cls &$n2f$results{
  69.         // Check if there was a massive failure or if the session extension isn't loaded
  70.         if ($results === false || $n2f->hasExtension('session'=== false{
  71.             // And if either is the case, just stop here
  72.             return(null);
  73.         }
  74.  
  75.         // Pull in global variable(s)
  76.         global $user$sess;
  77.  
  78.         // Initialize the timeout stamp
  79.         $timeout (time(300);
  80.  
  81.         // Check if there is a session user
  82.         if ($sess->exists('n2f_sess_user')) {
  83.             // There is, so pull them out
  84.             $user $sess->get('n2f_sess_user');
  85.  
  86.             // Just check if they've timed out
  87.             if ($user->lasttime $timeout{
  88.                 // And if so, reset their properties
  89.                 $user->user_id 0;
  90.                 $user->lasttime time();
  91.  
  92.                 // If we're supposed to track warnings..
  93.                 if ($n2f->debug->showLevel(N2F_DEBUG_WARN)) {
  94.                     // Throw a warning to the main debug object
  95.                     $n2f->debug->throwWarning(N2F_WARN_USER_TIMEOUTS('N2F_WARN_USER_TIMEOUT')'system/extensions/user.ext.php');
  96.                 }
  97.             }
  98.         else {
  99.             // Otherwise, initialize a new user and add them to the session
  100.             $user new n2f_user();
  101.             $sess->set('n2f_sess_user'$user);
  102.         }
  103.  
  104.         // If we're supposed to track notices..
  105.         if ($n2f->debug->showLevel(N2F_DEBUG_NOTICE)) {
  106.             // Throw a notice to the main debug object
  107.             $n2f->debug->throwNotice(N2F_NOTICE_USER_INITS('N2F_NOTICE_USER_INIT')'system/extensions/user.ext.php');
  108.         }
  109.  
  110.         // And stop processing, we've got nothing left to do!
  111.         return(null);
  112.     }
  113.  
  114.     /**
  115.      * Example n2f_user class.
  116.      *
  117.      */
  118.     class n2f_user {
  119.         /**
  120.          * User identifier property.
  121.          *
  122.          * @var integer 
  123.          */
  124.         public $user_id;
  125.         /**
  126.          * Last timestamp when user was active.
  127.          *
  128.          * @var integer 
  129.          */
  130.         public $lasttime;
  131.  
  132.         /**
  133.          * Initializes a new n2f_user object.
  134.          *
  135.          * @return n2f_user 
  136.          */
  137.         public function __construct({
  138.             // Initialize the properties
  139.             $this->user_id = 0;
  140.             $this->lasttime = time();
  141.  
  142.             // Return ourself for chaining
  143.             return($this);
  144.         }
  145.     }
  146.  
  147. ?>

Documentation generated on Sat, 23 Jan 2010 11:13:51 -0500 by phpDocumentor 1.4.1