Browse the code
| Differences between 86 and 87 on /trunk. | |||||||
|---|---|---|---|---|---|---|---|
| Number of edited files: | 5 (0 added, 0 deleted and 5 modified) | ||||||
| Author: | sebseb01 | ||||||
| Log message: | Del Global var + Optimize class user | ||||||
| Date: | 2007-07-22 19:49:06 | ||||||
|
|||||||
| Old | New | Code |
|---|---|---|
| 72 | 72 | |
| 73 | 73 |
// Class: mysql |
| 74 | 74 |
require(dirname(__FILE__).'/../db/mysql.php'); |
| 75 |
global $ct_db; | |
| 76 | 75 |
$ct_db = new mysql($this->mysql_hostname, $this->mysql_database, $this->mysql_username, $this->mysql_password); |
| 77 | 76 | |
| 78 | 77 |
// Class: Session |
| 79 | 78 |
require(dirname(__FILE__).'/session.php'); |
| 80 |
global $ct_session; | |
| 81 | 79 |
$ct_session = new Session(); |
| 82 |
$ct_session->init($_SERVER['REMOTE_ADDR'], $this->auth_method, date('d/m/Y'), date('H:i:s'));
| |
| 80 |
$ct_session->init($ct_db,$_SERVER['REMOTE_ADDR'], $this->auth_method, date('d/m/Y'), date('H:i:s'));
| |
| 83 | 81 | |
| 84 | 82 |
// Get request, data and show the page ! |
| 85 | 83 |
$pagetag = explode('/', $_SERVER['REQUEST_URI']);
|
| 127 | 125 |
switch($tag[2]) |
| 128 | 126 |
{
|
| 129 | 127 |
case 'index.html': |
| 130 |
$ct_view = new View(dirname(__FILE__).'/../templates/default/index.tpl', $_SERVER['REQUEST_URI']); | |
| 128 |
$ct_view = new View(dirname(__FILE__).'/../templates/default/index.tpl', $_SERVER['REQUEST_URI'],$ct_session,$ct_db);
| |
| 131 | 129 |
break; |
| 132 | 130 |
|
| 133 | 131 |
|
| 134 | 132 |
| Old | New | Code |
|---|---|---|
| 23 | 23 |
{
|
| 24 | 24 |
private $ip, $method, $date, $hour; |
| 25 | 25 |
public $pseudo, $passe; |
| 26 |
| |
| 27 |
function __construct() | |
| 26 | ||
| 27 |
function init($ct_db,$ip, $method, $date, $hour)
| |
| 28 | 28 |
{
|
| 29 |
global $ct_db; | |
| 30 |
} | |
| 31 |
| |
| 32 |
function init($ip, $method, $date, $hour) | |
| 33 |
{
| |
| 29 |
| |
| 34 | 30 |
// Construct session |
| 35 | 31 |
session_start(); |
| 36 | 32 |
$_SESSION['ip'] = $ip; |
| 46 | 42 | |
| 47 | 43 |
// Auto log in registered user if the cookie exist |
| 48 | 44 |
if(isset($_COOKIE['CTAutoConnectv3'])) |
| 49 |
$this->autologin(); | |
| 45 |
$this->autologin($ct_db);
| |
| 50 | 46 |
} |
| 51 | 47 | |
| 52 | 48 |
function logout() |
| 58 | 54 |
setcookie('CTAutoConnectv3','',0,'/','',0);
|
| 59 | 55 |
} |
| 60 | 56 |
|
| 61 |
function autologin() | |
| 57 |
function autologin($ct_db)
| |
| 62 | 58 |
{
|
| 59 |
| |
| 63 | 60 |
// Get cookie data and parse them |
| 64 | 61 |
$cookie = explode('-', $_COOKIE['CTAutoConnectv3']);
|
| 65 | 62 |
$cookiea = $cookie[0]; |
| 91 | 88 |
exit('Cookie Error.');
|
| 92 | 89 |
} |
| 93 | 90 |
|
| 94 |
function login($nick, $pass, $autoconnect=0) | |
| 91 |
function login($ct_db,$nick, $pass, $autoconnect=0)
| |
| 95 | 92 |
{
|
| 93 |
| |
| 96 | 94 |
$hash = md5($pass); |
| 97 | 95 | |
| 98 | 96 |
$req = $ct_db->select('member', array('pseudo' => $nick, 'passe' => $hash), 'passe, pseudo, niveau, id', 'LIMIT 1');
|
| 117 | 115 |
} |
| 118 | 116 |
} |
| 119 | 117 |
|
| 120 |
function isLogged() | |
| 118 |
function isLogged($ct_db)
| |
| 121 | 119 |
{
|
| 122 | 120 |
//Check if the user is logged |
| 123 | 121 |
if(empty($_SESSION['pseudo']) || empty($_SESSION['passe'])) |
| 124 | 122 |
| Old | New | Code |
|---|---|---|
| 23 | 23 |
protected $nick, $id, $jid, $avatar, $email, $email_conf, $name, $surname, $url, |
| 24 | 24 |
$date_ins, $signature, $description, $sex, $city, $country, $level, $loaded; |
| 25 | 25 |
private $pass; |
| 26 | ||
| 27 |
static function newUserById($id) {
| |
| 28 |
$u = new User; | |
| 29 |
$u->id = $id; | |
| 30 |
return $u; | |
| 26 |
private $db;
| |
| 27 |
| |
| 28 |
| |
| 29 |
function __construct($db) | |
| 30 |
{
| |
| 31 |
$this->db = $db; | |
| 31 | 32 |
} |
| 32 | ||
| 33 |
static function newUserByNick($nick) {
| |
| 34 |
$u = new User; | |
| 35 |
$u->nick = $nick; | |
| 36 |
return $u; | |
| 37 |
} | |
| 38 | ||
| 33 |
| |
| 39 | 34 |
function removeUser() {
|
| 40 |
$db = getDB(); | |
| 41 | 35 |
if (isset($this->id)) |
| 42 |
$db->delete('member', array('id' => $this->id));
| |
| 36 |
$this->db->delete('member', array('id' => $this->id)); | |
| 43 | 37 |
elseif (isset($this->nick)) |
| 44 |
$db->delete('member', array('nick' => $this->nick));
| |
| 38 |
$this->db->delete('member', array('nick' => $this->nick)); | |
| 45 | 39 | |
| 46 | 40 |
} |
| 47 | 41 | |
| 48 | 42 |
function load() {
|
| 49 | 43 |
if (isset($this->loaded)) return true; |
| 50 |
$db = getDB(); | |
| 51 | 44 |
if (isset($this->id)) {
|
| 52 |
$req = $db->select('member', array('id' => $this->id), '*');
| |
| 45 |
$req = $this->db->select('member', array('id' => $this->id), '*'); | |
| 53 | 46 |
if (count($req) == 0) {
|
| 54 | 47 |
return false; |
| 55 | 48 |
} |
| 56 | 49 |
} |
| 57 | 50 |
elseif(isset($this->nick)) {
|
| 58 |
$req = $db->select('member', array('nick' => $this->nick), '*');
| |
| 51 |
$req = $this->db->select('member', array('nick' => $this->nick), '*'); | |
| 59 | 52 |
if (count($req) == 0) {
|
| 60 | 53 |
return false; |
| 61 | 54 |
} |
| 102 | 95 |
return $this->checkHashedPass(md5($pass)); |
| 103 | 96 |
} |
| 104 | 97 | |
| 105 |
static function createUser($nick, $pass, $surname='', $name='', $email='', $jid='', $url='', $avatar='', $signature='', $description='', $sex='', $city='', $country='', $level = 'member') {
| |
| 106 |
$db = getDB(); | |
| 107 |
return $db->insert('member', array('nick' => $nick,
| |
| 98 |
static function createUser($db, $nick, $pass, $surname='', $name='', $email='', $jid='', $url='', $avatar='', $signature='', $description='', $sex='', $city='', $country='', $level = 'member') {
| |
| 99 |
return $this->db->insert('member', array('nick' => $nick,
| |
| 108 | 100 |
'pass' => md5($pass), |
| 109 | 101 |
'date_ins' => date('Y-m-d H:i:s'),
|
| 110 | 102 |
'surname' => $surname, |
| 123 | 115 | |
| 124 | 116 | |
| 125 | 117 |
function _updateField($field, $value) {
|
| 126 |
$db = getDB(); | |
| 127 | 118 |
if (isset($this->id)) |
| 128 |
return $db->update('member', array($field => $value), array('id' => $this->id));
| |
| 119 |
return $this->db->update('member', array($field => $value), array('id' => $this->id)); | |
| 129 | 120 |
elseif (isset($this->nick)) |
| 130 |
return $db->update('member', array($field => $value), array('nick' => $this->nick));
| |
| 131 |
| |
| 121 |
return $this->db->update('member', array($field => $value), array('nick' => $this->nick));
| |
| 132 | 122 |
} |
| 133 | 123 | |
| 134 |
function getEmail() {
| |
| 135 |
$this->load(); | |
| 136 |
return $this->email; | |
| 124 |
function getParam($Name) {
| |
| 125 |
// if parameter is wrong | |
| 126 |
if (!$this->load()) return false; //error | |
| 127 |
| |
| 128 |
return $this->$$Name; | |
| 137 | 129 |
} |
| 138 | 130 | |
| 139 |
function setEmail($email) {
| |
| 140 |
$this->_updateField('email', $email);
| |
| 141 |
$this->email = $email; | |
| 131 |
function setParam($Name,$Value) {
| |
| 132 |
//Read only parameter | |
| 133 |
$ReadOnly = array('nick','id','date_ins');
| |
| 134 |
| |
| 135 |
// if parameter is wrong | |
| 136 |
if (!isset($this->$name) || (in_array($Name,$ReadOnly))) return false; //error | |
| 137 |
| |
| 138 |
//Update | |
| 139 |
$this->_updateField($Name, $Value); | |
| 140 |
$this->$Name = $Value; | |
| 142 | 141 |
} |
| 142 |
} | |
| 143 | 143 | |
| 144 |
function getJid() {
| |
| 145 |
$this->load(); | |
| 146 |
return $this->jid; | |
| 147 |
} | |
| 144 |
function newUserById($id) {
| |
| 145 |
$u = new User; | |
| 146 |
$u->id = $id; | |
| 147 |
return $u; | |
| 148 |
} | |
| 148 | 149 | |
| 149 |
function setJid($jid) {
| |
| 150 |
$this->_updateField('jid', $jid);
| |
| 151 |
$this->jid = $jid; | |
| 152 |
} | |
| 153 | ||
| 154 |
function getNick() {
| |
| 155 |
$this->load(); | |
| 156 |
return $this->nick; | |
| 157 |
} | |
| 158 | ||
| 159 |
function getId() {
| |
| 160 |
$this->load(); | |
| 161 |
return $this->id; | |
| 162 |
} | |
| 163 | ||
| 164 |
function getSurname() {
| |
| 165 |
$this->load(); | |
| 166 |
return $this->surname; | |
| 167 |
} | |
| 168 | ||
| 169 |
function setSurname($surname) {
| |
| 170 |
$this->_updateField('surname', $surname);
| |
| 171 |
$this->surname = $surname; | |
| 172 |
} | |
| 173 | ||
| 174 |
function getName() {
| |
| 175 |
$this->load(); | |
| 176 |
return $this->name; | |
| 177 |
} | |
| 178 | ||
| 179 |
function setName($name) {
| |
| 180 |
$this->_updateField('name', $name);
| |
| 181 |
$this->name = $name; | |
| 182 |
} | |
| 183 | ||
| 184 |
function getDateIns() {
| |
| 185 |
$this->load(); | |
| 186 |
return $this->date_ins; | |
| 187 |
} | |
| 188 | ||
| 189 |
function getUrl() {
| |
| 190 |
$this->load(); | |
| 191 |
return $this->url; | |
| 192 |
} | |
| 193 | ||
| 194 |
function setUrl($url) {
| |
| 195 |
$this->_updateField('url', $url);
| |
| 196 |
$this->url = $url; | |
| 197 |
} | |
| 198 | ||
| 199 |
function getAvatar() {
| |
| 200 |
$this->load(); | |
| 201 |
return $this->url; | |
| 202 |
} | |
| 203 | ||
| 204 |
function setAvatar($avatar) {
| |
| 205 |
$this->_updateField('avatar', $avatar);
| |
| 206 |
$this->avatar = $avatar; | |
| 207 |
} | |
| 208 | ||
| 209 |
function getSignature() {
| |
| 210 |
$this->load(); | |
| 211 |
return $this->signature; | |
| 212 |
} | |
| 213 | ||
| 214 |
function setSignature($signature) {
| |
| 215 |
$this->_updateField('signature', $signature);
| |
| 216 |
$this->signature = $signature; | |
| 217 |
} | |
| 218 | ||
| 219 |
function getDescription() {
| |
| 220 |
$this->load(); | |
| 221 |
return $this->url; | |
| 222 |
} | |
| 223 | ||
| 224 |
function setDescription($description) {
| |
| 225 |
$this->_updateField('description', $description);
| |
| 226 |
$this->description = $description; | |
| 227 |
} | |
| 228 | ||
| 229 |
function getSex() {
| |
| 230 |
$this->load(); | |
| 231 |
return $this->sex; | |
| 232 |
} | |
| 233 | ||
| 234 |
function setSex($sex) {
| |
| 235 |
$this->_updateField('sex', $sex);
| |
| 236 |
$this->sex = $sex; | |
| 237 |
} | |
| 238 | ||
| 239 |
function getCity() {
| |
| 240 |
$this->load(); | |
| 241 |
return $this->city; | |
| 242 |
} | |
| 243 | ||
| 244 |
function setCity($city) {
| |
| 245 |
$this->_updateField('city', $city);
| |
| 246 |
$this->city = $city; | |
| 247 |
} | |
| 248 | ||
| 249 |
function getCountry() {
| |
| 250 |
$this->load(); | |
| 251 |
return $this->country; | |
| 252 |
} | |
| 253 | ||
| 254 |
function setCountry($country) {
| |
| 255 |
$this->_updateField('country', $country);
| |
| 256 |
$this->country = $country; | |
| 257 |
} | |
| 258 | ||
| 259 | ||
| 260 |
function setLevel($level) {
| |
| 261 |
$this->_updateField('level', $level);
| |
| 262 |
$this->level = $level; | |
| 263 |
} | |
| 264 | ||
| 265 |
function isLevel($level) {
| |
| 266 |
$this->load(); | |
| 267 |
return $this->level == $level; | |
| 268 |
} | |
| 269 | ||
| 150 |
function newUserByNick($nick) {
| |
| 151 |
$u = new User; | |
| 152 |
$u->nick = $nick; | |
| 153 |
return $u; | |
| 270 | 154 |
} |
| 271 | 155 | |
| 272 | ||
| 273 | ||
| 274 | 156 |
?> |
| 275 | 157 |
| Old | New | Code |
|---|---|---|
| 22 | 22 |
class View {
|
| 23 | 23 |
private $page, $file; |
| 24 | 24 | |
| 25 |
function __construct ($page, $file) | |
| 25 |
function __construct ($page, $file, $ct_session,$ct_db)
| |
| 26 | 26 |
{
|
| 27 |
// Globals | |
| 28 |
global $ct_session; | |
| 29 | 27 | |
| 30 | 28 |
// Cache |
| 31 | 29 |
require(dirname(__FILE__).'/cache.php'); |
| 39 | 37 |
$ct_tpl->staticview(); |
| 40 | 38 | |
| 41 | 39 |
// Start the view |
| 42 |
if ($ct_session->isLogged()) | |
| 40 |
if ($ct_session->isLogged($ct_db))
| |
| 43 | 41 |
{
|
| 44 | 42 |
echo 'DEBUG ----- '.$page.' ----- '.$file.' ----- 0: NO CACHE -----<br /><br />'; |
| 45 | 43 |
$ct_tpl->parse($page); |
| 46 | 44 |
| Old | New | Code |
|---|---|---|
| 19 | 19 |
# |
| 20 | 20 |
# ***** END LICENSE BLOCK ***** |
| 21 | 21 | |
| 22 |
function getDB() {
| |
| 23 |
global $ct_db; | |
| 24 |
return $ct_db; | |
| 25 |
} | |
| 26 | 22 | |
| 27 | 23 |
?> |
| 28 | 24 |

CodingTeam