Location: PHPKode > scripts > Noostr > _engine/classes/User.php
<?php defined('SYSPATH') OR die('No direct access to this file is allowed.');
/**
 * User class handles all user-related functions outside of the admin area.
 *
 * @package Noostr
 * @subpackage Classes
 */

class User {
	private $data = array();	// array holding all user info
	public $loggedin = false;	// are we currently logged in?

	public function __construct() {
		$this->data['nick'] = null;
		$this->data['karma'] = null;
		$this->data['uid'] = null;
		$this->data['roleid'] = null;
	}
	private function _load($array) {
		if (isset($array[0])) {
			$this->data = $array[0];
		}
	}
	public function __set($name, $value = '') {
		$this->data[$name] = $value;
	}

	public function __get($name) {
		$return = '';
		if (is_array($this->data)) {
			if (array_key_exists($name, $this->data)) {
				$return = $this->data[$name];
			}
		}
		return $return;
	}
	private function _bakecookies($check1, $check2, $timeout) {
		$time = time() + $timeout;
		bake("check1", $check1, $time);
		bake("check2", $check2, $time);
	}
	private function _loginhash($check1, $check2) {
		// returns 64 character hash
		global $site;
		$return = '';
		$return = md5($check1.$check2.'/'.$site->uid.'/'.$site->loginid.'/'.$site->siteid);
		$return .= md5($site->siteid.'/'.$site->loginid.'/'.$site->uid.'/'.$check2.$check1);
		return $return;
	}
	public function loadfromlogin($login, $password, $check1, $check2) {
		global $db, $site;
		$return = false;
		$this->_load($db->query('select * from '.PREFIX.'users where lower(nick) = ? and password = ?', array(strtolower($login), sha1($password))));
		if ($this->uid != '' && $this->uid != 'NaN') {
			$this->loginhash = $this->_loginhash($check1, $check2);
			$db->query('update '.PREFIX.'users set loginhash = ?, checkin = ? where uid = ?', array($this->loginhash, date('Y-m-d H:i:s'), $this->uid));
			$this->_bakecookies($check1, $check2, $site->timeout_login);
			$return = true;
		}
		return $return;
	}
	public function loadfromhash($check1, $check2) {
		global $db, $site;
		$return = false;
		$this->loginhash = $this->_loginhash($check1, $check2);
		$this->_load($db->query('select * from '.PREFIX.'users where loginhash = ?', $this->loginhash));
		if ($this->uid != '' && $this->uid != 'NaN' && time() - strtotime($this->checkin) <= $site->timeout_login) {
			$db->query('update '.PREFIX.'users set checkin = ? where uid = ?', array(date('Y-m-d H:i:s'), $this->uid));
			$this->_bakecookies($check1, $check2, $site->timeout_login);
			$return = true;
		}
		return $return;
	}
	public function logout($currenturi = '') {
		if ($this->loggedin) {
			$this->_bakecookies('', '', 0);
		}
		locate(HTTP.URL.PORT.'/'.$currenturi);
	}

	public function show($item) {
		echo $this->get($item);
	}
	public function get($item) {
		$return = '';
		if (is_array($this->data)) {
			if (array_key_exists($item, $this->data)) {
				$return = $this->data[$item];
				if (strtolower($item) == 'nick' && $this->data['nick'] == '') {
					// If "nickname" is blank, send "firstname" instead
					$return = $this->data['firstname'];
				}
			}
		}
		return $return;
	}

	public function tpl_getinfo() {
		return $this->data;
	}
}
Return current item: Noostr