Special Ops 2.50
[specialops2.git] / lib / User_Authenticated.php
blobe118a161e3ce817d4b2807bd8244e6b9fa4a09cb
1 <?php
2 /**
3 * Class for the current logged in user.
5 * @author Ant P <p@cpi.merseine.nu>
6 * @license file://../COPYING
7 * @version 2.15
8 */
9 class User_Authenticated extends User_Registered
11 public $cached = false;
13 function __construct($userid)
15 $this->sync($userid);
18 // Needed to stop memcache'd copy getting out of sync with the database
19 function __wakeup()
21 if ( $this->attrcache['last_passive_date'] < T_NOW - 30
22 || ! empty($_POST) ) {
23 $this->sync($this->attrcache['userid']);
24 } else {
25 $this->reload();
27 $this->cached = true;
30 private function sync($userid)
32 parent::__construct($userid);
34 /* Update last active thing */
35 if ( $this->getopt('alwaysonline') || ! empty($_POST) ) {
36 $qx = 'UPDATE LOW_PRIORITY users SET useragent = ?, last_ip = INET_ATON(?), '.
37 'last_passive_date = UNIX_TIMESTAMP(), last_active_date = last_passive_date WHERE userid = @userid';
38 } else {
39 $qx = 'UPDATE LOW_PRIORITY users SET useragent = ?, last_ip = INET_ATON(?), '.
40 'last_passive_date = UNIX_TIMESTAMP() WHERE userid = @userid';
42 SO2::$DB->q($qx, array(substr($_SERVER['HTTP_USER_AGENT'], 0, 130), $_SERVER['REMOTE_ADDR']));
43 $this->reload();
46 private function reload()
48 SO2::$Page->usernav = array (
49 $this->attrcache['alias'].' ('.$this->attrcache['points'].'ยค)' => 'user'