Optimised a bunch of code, removed circular references
[specialops2.git] / lib / class.authuser.php
blobd6000238c302b41271a3d45d35a54d75b8cc6143
1 <?php
2 // $Id$
4 /* Registered user, logged in (i.e. yourself) */
5 class authuser extends reguser
7 public $userid;
9 function __construct($userid, $prefetch = null)
11 $fields = array('`alias`', '`level`', '`language`', '`timezone`', '`theme`', '`date_format`');
12 if ( $prefetch )
13 $fields = array_merge($fields, $prefetch);
15 $this->userid = $userid;
16 $this->attrcache = array();
18 parent::__construct($userid, $fields);
20 $this->namecache[$userid] = $this->alias;
22 $this->userlinks = array(
23 $this->alias.' ('.( $this->level == LVL_DEV ? '∞' : $this->level ).')' => 'user?id='.$this->userid
26 if ( $this->level >= LVL_ADMIN )
27 $this->userlinks['Admin Stuff'] = 'admin';
29 //hack to get localized $page->title values
30 setlocale(LC_ALL, explode(', ', $this->language));
32 // Update user info
33 $GLOBALS['DB']->query('UPDATE `users` SET
34 `useragent` = \''.$GLOBALS['DB']->escape_string(substr($_SERVER['HTTP_USER_AGENT'], 0, 130)).'\',
35 `last_active_date` = UNIX_TIMESTAMP(),
36 `last_ip` = INET_ATON(\''.$_SERVER['REMOTE_ADDR'].'\')
37 WHERE `userid` = '.$this->userid);
40 // getUsernameByID()
41 function namelink($id, $name = null)
43 if ( empty($this->namecache[$id]) ) {
44 if ( $name === null )
45 $this->namecache[$id] = $GLOBALS['DB']->query('SELECT `alias` FROM `users`
46 WHERE `userid` = '.$id)->fetch_object()->alias;
47 else
48 $this->namecache[$id] = $name;
50 return '<a href="user?id='.$id.'">'.$this->namecache[$id].'</a>';
53 // the "f" stands for fish
54 function fdate($timestamp)
56 return ( $timestamp == 0 ? 'N/A' : date($this->date_format, $timestamp) );