From 36eb914596b29ff303f499b27d35615b4a7adace Mon Sep 17 00:00:00 2001 From: Anthony Parsons Date: Wed, 22 Mar 2006 21:45:30 +0000 Subject: [PATCH] * Delete `users`.`admin`, use `things` for it instead * Get rid of retarded code in User_*::__get() * Some other stuff --- lib/class.User_Authenticated.php | 17 ++++++++++++----- lib/class.User_Registered.php | 16 +++++++++++----- res/structure.sql | 13 +++++++++---- 3 files changed, 32 insertions(+), 14 deletions(-) diff --git a/lib/class.User_Authenticated.php b/lib/class.User_Authenticated.php index 9d3d03b..314edcf 100644 --- a/lib/class.User_Authenticated.php +++ b/lib/class.User_Authenticated.php @@ -52,17 +52,23 @@ class User_Authenticated extends User_Registered $fieldname = "INET_NTOA(`$varname`)"; break; case 'password': $fieldname = 'AES_DECRYPT(`password`, `reg_ip`)'; break; - case 'posts': // Really nasty hack - $fieldname = 'COUNT(*) AS `posts` FROM `messages` WHERE `userid` = @userid #'; break; + case 'posts': + list($this->attrcache['posts']) = + $DB->query('SELECT COUNT(*) FROM `messages` WHERE `userid` = @userid')->fetch_row(); + return $this->attrcache['posts']; + case 'admin': + list($this->attrcache['admin']) = + $DB->query('SELECT COUNT(*) FROM `things` WHERE `what` = "admin" AND `userid` = @userid')->fetch_row(); + return $this->attrcache['admin']; default: $fieldname = "`$varname`"; } - $q = $DB->query('SELECT '.$fieldname.' FROM `users` WHERE `userid` = @userid'); + $tmp = $DB->query('SELECT '.$fieldname.' FROM `users` WHERE `userid` = @userid'); if ( $DB->error ) { throw new OutOfBoundsException('MySQL error in authuser::__get('.$varname.'): '.$DB->error); } else { - list($this->attrcache[$varname]) = $q->fetch_row(); + list($this->attrcache[$varname]) = $tmp->fetch_row(); } } @@ -83,6 +89,7 @@ class User_Authenticated extends User_Registered switch ( $varname ) { case 'userid': case 'alias': + case 'admin': throw new Exception('Attempted to do a authuser::__set('.$varname.').'); case 'reg_ip': case 'last_ip': @@ -201,7 +208,7 @@ class User_Authenticated extends User_Registered case 'moderate': return ($this->points >= 1); case 'admin': - return (defined('DEVELOPER') || $this->admin); + return $this->admin; case 'viewboard': case 'postmessage': return ($this->admin || func_get_arg(1) != 'admin'); diff --git a/lib/class.User_Registered.php b/lib/class.User_Registered.php index f102f78..cb7ba08 100644 --- a/lib/class.User_Registered.php +++ b/lib/class.User_Registered.php @@ -35,19 +35,25 @@ class User_Registered extends User_Anonymous $column = "INET_NTOA(`$varname`)"; break; case 'password': $column = "AES_DECRYPT(`$varname`, `reg_ip`)"; break; - case 'posts': // Even nastier hack than the authuser one. Don't ask how it works or it'll break. - $column = 'COUNT(*) AS `posts` FROM `messages` #'; break; + case 'posts': + list($this->attrcache['posts']) = + $DB->query('SELECT COUNT(*) FROM `messages` WHERE `userid` = '.$this->attrcache['userid'])->fetch_row(); + return $this->attrcache['posts']; + case 'admin': + list($this->attrcache['admin']) = + $DB->query('SELECT COUNT(*) FROM `things` + WHERE `what` = "admin" AND `userid` = '.$this->attrcache['userid'])->fetch_row(); + return $this->attrcache['admin']; default: $column = "`$varname`"; } - $q = $DB->query('SELECT '.$column.' AS `'.$varname.'` FROM `users` - WHERE `userid` = '.$this->attrcache['userid']); + $tmp = $DB->query('SELECT '.$column.' AS `'.$varname.'` FROM `users` WHERE `userid` = '.$this->attrcache['userid']); if ( $DB->error ) { throw new OutOfBoundsException('MySQL error in reguser::_get('.$varname.'): '.$DB->error); } else { - $this->attrcache[$varname] = $q->fetch_object()->$varname; + list($this->attrcache[$varname]) = $tmp->fetch_row(); } } diff --git a/res/structure.sql b/res/structure.sql index 528af76..81b7b50 100644 --- a/res/structure.sql +++ b/res/structure.sql @@ -1,11 +1,15 @@ -- phpMyAdmin SQL Dump --- version 2.8.0 +-- version 2.8.0.2 -- http://www.phpmyadmin.net -- -- Host: localhost --- Generation Time: Mar 20, 2006 at 09:42 PM +-- Generation Time: Mar 22, 2006 at 09:39 PM -- Server version: 5.0.19 -- PHP Version: 5.1.2-gentoo + +SET AUTOCOMMIT=0; +START TRANSACTION; + -- -- Database: `so2-dev` -- @@ -108,7 +112,7 @@ CREATE TABLE `themes` ( CREATE TABLE `things` ( `id` smallint(5) unsigned NOT NULL auto_increment, `userid` smallint(5) unsigned NOT NULL, - `what` enum('invite') NOT NULL, + `what` enum('invite','admin') NOT NULL, `data` varchar(36) default NULL, PRIMARY KEY (`id`), KEY `userid` (`userid`), @@ -149,7 +153,6 @@ CREATE TABLE `users` ( `invites` tinyint(3) unsigned NOT NULL default '0', `referrer` smallint(5) unsigned default NULL, `options` set('namelinks','alwaysonline','javascript') NOT NULL default 'alwaysonline', - `admin` tinyint(1) NOT NULL default '0', `boardlist_layout` tinyint(1) unsigned NOT NULL default '0', `topiclist_layout` tinyint(1) unsigned NOT NULL default '0', `msglist_layout` tinyint(1) unsigned NOT NULL default '0', @@ -213,3 +216,5 @@ ALTER TABLE `topics` -- ALTER TABLE `users` ADD CONSTRAINT `users_ibfk_1` FOREIGN KEY (`referrer`) REFERENCES `users` (`userid`) ON DELETE CASCADE; + +COMMIT; -- 2.11.4.GIT