From cce5e7710295021b41d9aaecc503a60fb99256be Mon Sep 17 00:00:00 2001 From: deva Date: Sat, 4 Oct 2008 10:38:03 +0000 Subject: Initial revision --- forum/utils/users.php | 136 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 136 insertions(+) create mode 100644 forum/utils/users.php (limited to 'forum/utils/users.php') diff --git a/forum/utils/users.php b/forum/utils/users.php new file mode 100644 index 0000000..99aaffc --- /dev/null +++ b/forum/utils/users.php @@ -0,0 +1,136 @@ +password == sha1(md5($password)); + } + + public function write($fp) + { + fwrite($fp, " enabled . "\"\n"); + fwrite($fp, " uid=\"" . $this->uid . "\"\n"); + fwrite($fp, " gid=\"" . $this->gid . "\"\n"); + fwrite($fp, " notified=\"" . $this->notified . "\"\n"); + fwrite($fp, " username=\"" . htmlspecialchars($this->username, ENT_QUOTES, "UTF-8") . "\"\n"); + fwrite($fp, " password=\"" . $this->password . "\"\n"); + fwrite($fp, " name=\"" . htmlspecialchars($this->name, ENT_QUOTES, "UTF-8") . "\"\n"); + fwrite($fp, " avatar=\"" . htmlspecialchars($this->avatar, ENT_QUOTES, "UTF-8") . "\"\n"); + fwrite($fp, " email=\"" . htmlspecialchars($this->email, ENT_QUOTES, "UTF-8") . "\">\n"); + fwrite($fp, " \n"); + } + + public function User($enabled, $uid, $gid, $username, $password, $name, $email, $avatar, $notified) + { + $this->enabled = $enabled; + $this->gid = $gid; + $this->uid = $uid; + $this->username = $username; + $this->password = $password; + $this->email = $email; + $this->name = $name; + $this->avatar = $avatar; + if($notified == "") $notified = 0; + $this->notified = $notified; + } +} + +class Users { + + private $file; + public $users = array(); + + public function add($user) { + $key = $user->uid; + $this->users[$key] = $user; + } + + public function write() + { + $fp = fopen($this->file, "w"); + + $block = TRUE; + flock($fp, LOCK_EX, $block); // do an exclusive lock + + fwrite($fp, "\n"); + + fwrite($fp, "\n"); + foreach($this->users as $user) { + $user->write($fp); + } + fwrite($fp, "\n"); + + fclose($fp); + } + + /* + public function deleteForumUser($id) + { + if($this->members[$id]) { + unset($this->members[$id]); + // $this->write(); + } else { + echo "

ERROR: User! ".$id." does not exist!

\n"; + return false; + } + return true; + } + */ + + public function getUserID($username) + { + foreach($this->users as $user) { + if($user->username == $username) return $user->uid; + } + return false; + } + + public function getUser($uid) + { + $user = $this->users[$uid]; + return $user; + } + + private function read() + { + $dom = new DomDocument; + $dom->preserveWhiteSpace = FALSE; + $dom->load($this->file); + $users = $dom->getElementsByTagName('user'); + + foreach ($users as $u) { + $user = new User($u->getAttribute('enabled'), + $u->getAttribute('uid'), + $u->getAttribute('gid'), + $u->getAttribute('username'), + $u->getAttribute('password'), + $u->getAttribute('name'), + $u->getAttribute('email'), + $u->getAttribute('avatar'), + $u->getAttribute('notified')); + + $this->add($user); + } + + } + + public function Users($file) + { + $this->file = $file; + $this->read(); + } + +} +?> \ No newline at end of file -- cgit v1.2.3