Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /* Copyright (C) 2011 Joopie
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- class User
- {
- private static $data;
- public static function LoggedIn()
- {
- return @$_SESSION['user']['loggedin'];
- }
- public static function Login($login, $password)
- {
- $result = MySQL::Query('SELECT `id` FROM `users` WHERE (`username` = "'.$login.'" OR `email` = "'.$login.'") AND `password` = "'.$password.'" ORDER BY `last_alive` DESC LIMIT 1');
- if ($result->num_rows >= 1)
- {
- $id = $result->Result();
- $_SESSION['user']['loggedin'] = true;
- $_SESSION['user']['login'] = $login;
- $_SESSION['user']['password'] = $password;
- $_SESSION['user']['id'] = $id;
- self::UpdateUserData($id);
- new MultiUser(true);
- return true;
- }
- return false;
- }
- public static function Logout()
- {
- unset($_SESSION['user']);
- Core::CleanSessions();
- }
- public static function UpdateSecure()
- {
- $_SESSION['user']['multi'][USER_ID]['last_update'] = time();
- }
- public static function NeedCheckSecure()
- {
- return (@$_SESSION['user']['multi'][USER_ID]['last_update'] +450 <= time()) ? true : false;
- }
- public static function UpdateUserData($id, $allowCache = false)
- {
- if ($allowCache && isset($_SESSION['user']['data']))
- {
- self::$data = $_SESSION['user']['data'];
- return;
- }
- self::$data = $_SESSION['user']['data'] = MySQL::Query('SELECT * FROM `users` WHERE `id` = "'.$id.'" LIMIT 1')->NextRecord();
- $_SESSION['user']['login'] = self::$data['username'];
- }
- public static function GetUserData($key, $id = 0)
- {
- if ($id == 0 || self::$data['id'] == $id)
- {
- return self::$data[$key];
- }
- return MySQL::Query('SELECT `'.$key.'` FROM `users` WHERE `id` = "'.$id.'" LIMIT 1')->Result();
- }
- public static function SetUserData($key, $value, $id = 0, $onlyCache = false)
- {
- if ($id == 0 || self::$data['id'] == $id)
- {
- $id = self::$data['id'];
- self::$data[$key] = $_SESSION['user']['data'][$key] = $value;
- }
- if ($onlyCache)
- {
- return 1;
- }
- return MySQL::Query('UPDATE `users` SET `'.$key.'` = "'.$value.'" WHERE `id` = "'.$id.'" LIMIT 1')->affected_rows;
- }
- public static function SSOTicket($id = 0)
- {
- if($id == 0 || self::$data['id'] == $id)
- {
- $id = self::$data['id'];
- }
- $username = self::GetUserData('username', $id);
- $userid = self::GetUserData('id', $id);
- $sso = 'BrickPHP-'.Core::Hash($username.rand(100, 999)).'-'.rand($userid, $userid + 100);
- self::SetUserData('sso_hash', $sso, $id);
- return $sso;
- }
- // if is
- public static function IsAdmin($id = 0)
- {
- return (self::GetUserData('rank', $id) >= 2) ? true : false;
- }
- //Habbo Club/VIP
- public static function IsBasicOrVip($id = 0)
- {
- if ($id == 0 || self::$data['id'] == $id)
- {
- $id = self::$data['id'];
- if (isset($_SESSION['user']['multi'][$id]['ismembership']))
- {
- return $_SESSION['user']['multi'][$id]['ismembership'];
- }
- }
- $_SESSION['user']['multi'][$id]['ismembership'] = $ismember = (MySQL::Query('SELECT null FROM `user_memberships` WHERE `user_id` = "'.$id.'" LIMIT 1')->num_rows >= 1) ? true : false;
- return $ismember;
- }
- public static function GetMemberShip($id = 0)
- {
- if ($id == 0 || self::$data['id'] == $id)
- {
- $id = self::$data['id'];
- if (isset($_SESSION['user']['multi'][$id]['membership']))
- {
- return $_SESSION['user']['multi'][$id]['membership'];
- }
- }
- $_SESSION['user']['multi'][$id]['membership'] = $membership = (MySQL::Query('SELECT `member_scaler` FROM `user_memberships` WHERE `user_id` = "'.$id.'" LIMIT 1')->Result() == 0) ? 'Habbo Club' : 'Habbo Vip';
- return $membership;
- }
- public static function DaysLeft($id = 0)
- {
- if ($id == 0 || self::$data['id'] == $id)
- {
- $id = self::$data['id'];
- if (isset($_SESSION['user']['multi'][$id]['daysleft']))
- {
- return $_SESSION['user']['multi'][$id]['daysleft'];
- }
- }
- $now = time();
- $result = MySQL::Query('SELECT `activated_datetime`,`month_amount` FROM `user_memberships` WHERE `user_id` = "'.$id.'" LIMIT 1');
- if ($result->num_rows < 1)
- {
- return 0;
- }
- $start = Core::DateToTime($result->Result());
- $ends = strtotime('+'.$result->Result(0, 1).' month', $start);
- $_SESSION['user']['multi'][$id]['daysleft'] = $days = ceil(($ends -$now) /60 /60 /24);
- return $days;
- }
- public static function ClubClean()
- {
- $id = self::$data['id'];
- unset($_SESSION['user']['multi'][$id]['ismembership']);
- unset($_SESSION['user']['multi'][$id]['membership']);
- unset($_SESSION['user']['multi'][$id]['daysleft']);
- }
- //Controle shit
- public static function ValidName($username)
- {
- if(preg_match('/^[a-zA-Z0-9._:,-]+$/i', $username) && !preg_match('/mod-/i', $username))
- {
- return true;
- }
- return false;
- }
- public static function NameTaken($username)
- {
- return (MySQL::Query("SELECT null FROM `users` WHERE `username` = '".$username."'")->num_rows > 0) ? true : false;
- }
- public static function ValidMail($mail)
- {
- return preg_match("/^[a-z0-9_\.-]+@([a-z0-9]+([\-]+[a-z0-9]+)*\.)+[a-z]{2,7}$/i", $mail);
- }
- public static function MailTaken($mail)
- {
- return (MySQL::Query("SELECT * FROM `users` WHERE `email` = '".$mail."' LIMIT 1")->num_rows > 0) ? true : false;
- }
- //Ban
- public static function AddBan($user_id, $user_ip, $ip_ban, $time, $reason)
- {
- return MySQL::Query('INSERT INTO `user_bans` (user_id, user_ip, ip_ban, given_datetime, end_datetime, given_mod_id, reason) VALUES ("'.$user_id.'", "'.$user_ip.'", "'.$ip_ban.'", "'.time().'", "'.time() +$time.'", "'.USER_ID.'", "'.$reason.'")')->affected_rows;
- }
- public static function IsBanned($id = 0)
- {
- if ($id == 0)
- {
- $id = self::$data['id'];
- }
- return (MySQL::Query("SELECT null FROM `user_bans` WHERE (`user_id` = '".$id."' OR (`user_ip` = '".USER_IP."' AND `ip_ban` = '1')) AND `end_datetime` > '".time()."' LIMIT 1")->num_rows >= 1) ? true : false;
- }
- //Converter blabla
- public static function Name2Id($username)
- {
- return MySQL::Query('SELECT `id` FROM `users` WHERE `username` = "'.$username.'" LIMIT 1')->Result();
- }
- public static function Id2Name($id)
- {
- return MySQL::Query('SELECT `username` FROM `users` WHERE `id` = "'.$id.'" LIMIT 1')->Result();
- }
- //Register
- public static function Register($username, $password, $email, $gender = 'm', $figure = 'hd-180-1.ch-210-66.lg-270-82.sh-290-91.hr-100', $no_activation = false)
- {
- $activate = ($no_activation) ? 1 : 0;
- $time = date("d-m-Y");
- $time2 = date("d-m-Y");
- MySQL::Query("INSERT INTO users (username, password, email, look, gender, user_hash, register_ip, activated_email, registered_datetime, last_alive) VALUES ('".$username."', '".$password."', '".$email."', '".$figure."', '".$gender."', '".md5($username)."', '".USER_IP."', '".$activate."', '".$time."', '".$time2."')");
- return mysql_insert_id(MySQL::$link);
- }
- }
- class MultiUser
- {
- public static $data;
- public static function IsValid($id = 0) //Safety control if it is right user
- {
- if (!User::LoggedIn())
- {
- return false;
- }
- foreach (self::$data as $value)
- {
- if ($value['id'] == $id)
- {
- return true;
- }
- }
- return false;
- }
- public static function Togo()
- {
- return 50 -count(self::$data);
- }
- public static function SwitchUser($id)
- {
- if (!self::IsValid($id))
- {
- return false;
- }
- User::UpdateUserData($id, false);
- return true;
- }
- function __Construct($allowCache = false)
- {
- if (!User::LoggedIn())
- {
- return;
- }
- if ($allowCache && isset($_SESSION['user']['multi']))
- {
- self::$data = $_SESSION['user']['multi'];
- return;
- }
- $result = MySQL::Query('SELECT `id`,`username`,`look`,`last_alive` FROM `users` WHERE `email` = "'.User::GetUserData('email').'"');
- while ($row = $result->NextRecord())
- {
- self::$data[$row['id']] = $row;
- }
- $_SESSION['user']['multi'] = self::$data;
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement