Guest User

Untitled

a guest
Mar 5th, 2016
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 34.21 KB | None | 0 0
  1. <?php
  2. /*================================================================+\
  3. || # PHPRetro - An extendable virtual hotel site and management
  4. |+==================================================================
  5. || # Copyright (C) 2009 Yifan Lu. All rights reserved.
  6. || # http://www.yifanlu.com
  7. || # Parts Copyright (C) 2009 Meth0d. All rights reserved.
  8. || # http://www.meth0d.org
  9. || # All images, scripts, and layouts
  10. || # Copyright (C) 2009 Sulake Ltd. All rights reserved.
  11. |+==================================================================
  12. || # PHPRetro is provided "as is" and comes without
  13. || # warrenty of any kind. PHPRetro is free software!
  14. || # License: GNU Public License 3.0
  15. || # http://opensource.org/licenses/gpl-license.php
  16. \+================================================================*/
  17.  
  18. if(!defined("IN_HOLOCMS")) { header("Location: ".PATH); exit; }
  19.  
  20. ######MYSQLI Function ##########
  21.  
  22. function mysqli_result($result,$row,$field=0) {
  23. if ($result===false) return false;
  24. if ($row>=mysqli_num_rows($result)) return false;
  25. if (is_string($field) && !(strpos($field,".")===false)) {
  26. $t_field=explode(".",$field);
  27. $field=-1;
  28. $t_fields=mysqli_fetch_fields($result);
  29. for ($id=0;$id<mysqli_num_fields($result);$id++) {
  30. if ($t_fields[$id]->table==$t_field[0] && $t_fields[$id]->name==$t_field[1]) {
  31. $field=$id;
  32. break;
  33. }
  34. }
  35. if ($field==-1) return false;
  36. }
  37. mysqli_data_seek($result,$row);
  38. $line=mysqli_fetch_array($result);
  39. return isset($line[$field])?$line[$field]:false;
  40. }
  41.  
  42. #####################################################
  43.  
  44. class HoloInput {
  45. function FilterText($str) {
  46. if(get_magic_quotes_gpc()){ $str = stripslashes($str); }
  47. $str = preg_replace(array('/\x{0001}/u','/\x{0002}/u','/\x{0003}/u','/\x{0005}/u','/\x{0009}/u'),' ',$str);
  48. #if($GLOBALS['conn']['main']['server'] == "mysql" || $GLOBALS['conn']['server']['server'] == "mysql"){ $str = mysqli_real_escape_string($str); }else{ $str = addslashes($str); }
  49.  
  50. return $str;
  51. }
  52.  
  53. function HoloText($str, $advanced=false) {
  54. $str = stripslashes($str);
  55. if($advanced != true){ $str = htmlspecialchars($str,ENT_COMPAT,"UTF-8"); }
  56. return $str;
  57. }
  58. function stringToURL($str,$lowercase=true,$spaces=false){
  59. $str = trim(preg_replace('/\s\s+/',' ',preg_replace("/[^A-Za-z0-9-]/", " ", $str)));
  60. if($lowercase == true){ $str = strtolower($str); }
  61. if($spaces == true){ $str = str_replace(" ", "-", $str); }else{ str_replace(" ", "", $str); }
  62. return $str;
  63. }
  64. function HoloHash($password, $username){
  65. $string = sha1($password.strtolower($username));
  66. return $string;
  67. }
  68. function IsEven($intNumber)
  69. {
  70. if($intNumber % 2 == 0){
  71. return true;
  72. } else {
  73. return false;
  74. }
  75. }
  76. function unicodeToImage($str){
  77. $search = array(
  78. //'/\x{007c}/u',
  79. '/\x{00a5}/u',
  80. '/\x{00aa}/u',
  81. '/\x{00ac}/u',
  82. '/\x{00b1}/u',
  83. '/\x{00b5}/u',
  84. '/\x{00b6}/u',
  85. '/\x{00ba}/u',
  86. '/\x{00bb}/u',
  87. //'/\x{00cc}/u',
  88. //'/\x{00cd}/u',
  89. '/\x{00d5}/u',
  90. '/\x{00f5}/u',
  91. '/\x{00f7}/u',
  92. '/\x{0192}/u',
  93. '/\x{2014}/u',
  94. //'/\x{2018}/'u,
  95. '/\x{2020}/u',
  96. '/\x{2021}/u',
  97. '/\x{2022}/u'
  98. );
  99. $replace = array(
  100. //'<img src="'.PATH.'/web-gallery/images/fonts/volter/white_heart.gif" class="vchar" />',
  101. '<img src="'.PATH.'/web-gallery/images/fonts/volter/165.gif" class="vchar" />',
  102. '<img src="'.PATH.'/web-gallery/images/fonts/volter/170.gif" class="vchar" />',
  103. '<img src="'.PATH.'/web-gallery/images/fonts/volter/172.gif" class="vchar" />',
  104. '<img src="'.PATH.'/web-gallery/images/fonts/volter/177.gif" class="vchar" />',
  105. '<img src="'.PATH.'/web-gallery/images/fonts/volter/181.gif" class="vchar" />',
  106. '<img src="'.PATH.'/web-gallery/images/fonts/volter/182.gif" class="vchar" />',
  107. '<img src="'.PATH.'/web-gallery/images/fonts/volter/186.gif" class="vchar" />',
  108. '<img src="'.PATH.'/web-gallery/images/fonts/volter/187.gif" class="vchar" />',
  109. //'<img src="'.PATH.'/web-gallery/images/fonts/volter/white_padlock.gif" class="vchar" />',
  110. //'<img src="'.PATH.'/web-gallery/images/fonts/volter/single_music_note.gif" class="vchar" />',
  111. '<img src="'.PATH.'/web-gallery/images/fonts/volter/213.gif" class="vchar" />',
  112. '<img src="'.PATH.'/web-gallery/images/fonts/volter/245.gif" class="vchar" />',
  113. '<img src="'.PATH.'/web-gallery/images/fonts/volter/247.gif" class="vchar" />',
  114. '<img src="'.PATH.'/web-gallery/images/fonts/volter/131.gif" class="vchar" />',
  115. '<img src="'.PATH.'/web-gallery/images/fonts/volter/151.gif" class="vchar" />',
  116. //'<img src="'.PATH.'/web-gallery/images/fonts/volter/black_padlock.gif" class="vchar" />',
  117. '<img src="'.PATH.'/web-gallery/images/fonts/volter/134.gif" class="vchar" />',
  118. '<img src="'.PATH.'/web-gallery/images/fonts/volter/135.gif" class="vchar" />',
  119. '<img src="'.PATH.'/web-gallery/images/fonts/volter/149.gif" class="vchar" />'
  120. );
  121. $str = preg_replace($search,$replace,$str);
  122. return $str;
  123. }
  124. function bbcode_format($str){
  125.  
  126. // Parse smilies
  127. $smilies = array(":)",";)",":P",";P",":p",";p","(L)","(l)",":o",":O");
  128. $smilies_replace = array(
  129. " <img src='".PATH."/web-gallery/smilies/smile.gif' alt='Smiley' title='Smiley' border='0'> ",
  130. " <img src='".PATH."/web-gallery/smilies/wink.gif' alt='Smiley' title='Smiley' border='0'> ",
  131. " <img src='".PATH."/web-gallery/smilies/tongue.gif' alt='Smiley' title='Smiley' border='0'> ",
  132. " <img src='".PATH."/web-gallery/smilies/winktongue.gif' alt='Smiley' title='Smiley' border='0'> ",
  133. " <img src='".PATH."/web-gallery/smilies/tongue.gif' alt='Smiley' title='Smiley' border='0'> ",
  134. " <img src='".PATH."/web-gallery/smilies/winktongue.gif' alt='Smiley' title='Smiley' border='0'> ",
  135. " <img src='".PATH."/web-gallery/smilies/heart.gif' alt='Smiley' title='Smiley' border='0'> ",
  136. " <img src='".PATH."/web-gallery/smilies/heart.gif' alt='Smiley' title='Smiley' border='0'> ",
  137. " <img src='".PATH."/web-gallery/smilies/shocked.gif' alt='Smiley' title='Smiley' border='0'> ",
  138. " <img src='".PATH."/web-gallery/smilies/shocked.gif' alt='Smiley' title='Smiley' border='0'> ");
  139. $str = str_replace($smilies,$smilies_replace,$str);
  140.  
  141. // Parse BB code
  142. $simple_search = array(
  143. '/\[b\](.*?)\[\/b\]/is',
  144. '/\[i\](.*?)\[\/i\]/is',
  145. '/\[u\](.*?)\[\/u\]/is',
  146. '/\[s\](.*?)\[\/s\]/is',
  147. '/\[quote\](.*?)\[\/quote\]/is',
  148. '/\[link\=(.*?)\](.*?)\[\/link\]/is',
  149. '/\[url\=(.*?)\](.*?)\[\/url\]/is',
  150. '/\[color\=(.*?)\](.*?)\[\/color\]/is',
  151. '/\[size=small\](.*?)\[\/size\]/is',
  152. '/\[size=large\](.*?)\[\/size\]/is',
  153. '/\[code\](.*?)\[\/code\]/is',
  154. '/\[habbo\=(.*?)\](.*?)\[\/habbo\]/is',
  155. '/\[room\=(.*?)\](.*?)\[\/room\]/is',
  156. '/\[group\=(.*?)\](.*?)\[\/group\]/is'
  157. );
  158.  
  159. $simple_replace = array(
  160. "<b>$1</b>",
  161. "<i>$1</i>",
  162. "<u>$1</u>",
  163. "<s>$1</s>",
  164. "<div class=\"bbcode-quote\">$1</div>",
  165. "<a href=\"$1\">$2</a>",
  166. "<a href=\"$1\">$2</a>",
  167. "<span style=\"color: $1;\">$2</span>",
  168. "<span style=\"font-size: 9px;\">$1</span>",
  169. "<span style=\"font-size: 14px;\">$1</span>",
  170. "<pre>$1</pre>",
  171. "<a href=\"".PATH."/home/$1/id\">$2</a>",
  172. "<a onclick=\"roomForward(this, '$1', 'private'); return false;\" target=\"client\" href=\"".PATH."/client?forwardId=2&roomId=$1\">$2</a>",
  173. "<a href=\"".PATH."/groups/$1/id\">$2</a>"
  174. );
  175.  
  176. $str = preg_replace ($simple_search, $simple_replace, $str);
  177.  
  178. return $str;
  179. }
  180. }
  181. class HoloUser {
  182. var $id = 0; var $name = "Guest"; var $password = null; var $logged_in = false; var $ip = null; var $time = null;
  183. var $error = 0; var $banned; var $user = array('0','Guest','null','0',null,null,null,null,null,null,null,null,null);
  184. function HoloUser($name,$password,$updateuser=false,$rememberme=null){
  185. $data = new index_sql;
  186. $date = HoloDate();
  187. if(empty($name) || empty($password)){
  188. $this->error = 1; return false;
  189. }
  190. if($GLOBALS['serverdb']->num_rows($data->select1($name, $password)) < 1){
  191. $this->error = 2; return false;
  192. }
  193. $id = $GLOBALS['serverdb']->result($data->select1($name, $password));
  194. if($this->IsUserBanned($id) == true){
  195. $row = $GLOBALS['serverdb']->fetch_row($GLOBALS['core']->select2($id));
  196. $this->banned['reason'] = $row[0];
  197. $this->banned['expire'] = $row[1];
  198. $this->error = 3; return false;
  199. }
  200. if($this->error == 0 && !is_array($this->banned)){
  201. $this->ip = $_SERVER['REMOTE_ADDR'];
  202. if($rememberme == "true"){
  203. $token = GenerateTicket("remember");
  204. $GLOBALS['serverdb']->query("UPDATE ".PREFIX."users SET remember_token = '".$token."' WHERE id = '".$id."' LIMIT 1");
  205. setcookie("rememberme", "true", time()+60*60*24*$GLOBALS['settings']->find("site_cookie_time"), "/");
  206. setcookie("rememberme_token", $token, time()+60*60*24*$GLOBALS['settings']->find("site_cookie_time"), "/");
  207. }
  208. if($updateuser == true){ $this->updateUser($id); }
  209. $this->user = $GLOBALS['serverdb']->fetch_row($GLOBALS['core']->select3($id)); $this->id = $id; $this->name = $this->user("name"); $this->figure = $this->user("figure"); $this->password = $password; $this->logged_in = true;
  210. }
  211. $this->time = time();
  212. return true;
  213. }
  214. function destroy(){
  215. @session_start();
  216. setcookie("rememberme", "", time()-60*60*24*100, "/"); setcookie("cookpass", "", time()-60*60*24*100, "/");
  217. setcookie("rememberme_token", "", time()-60*60*24*100, "/"); setcookie("cookpass", "", time()-60*60*24*100, "/");
  218. $_SESSION = array();
  219. if(isset($_COOKIE[session_name()])) { setcookie(session_name(), "", time()-60*60*24*100, "/"); }
  220. @session_destroy();
  221. return true;
  222. }
  223. function refresh(){
  224. $GLOBALS['user'] = new HoloUser($this->name,$this->password);
  225. $_SESSION['user'] = $GLOBALS['user'];
  226. return true;
  227. }
  228. function user($key){
  229. switch($key){
  230. case "id":
  231. $value = $this->user[0]; break;
  232. case "name":
  233. $value = $this->user[1]; break;
  234. case "password":
  235. $value = $this->user[2]; break;
  236. case "rank":
  237. $value = $this->user[3]; break;
  238. case "birth":
  239. $value = $this->user[5]; break;
  240. case "figure":
  241. $value = $this->user[6]; break;
  242. case "sex":
  243. $value = $this->user[7]; break;
  244. case "mission":
  245. $value = $this->user[8]; break;
  246. case "credits":
  247. $value = $this->user[9]; break;
  248. case "tickets":
  249. $value = $this->user[10]; break;
  250. case "ticket_sso":
  251. $value = $this->user[11]; break;
  252. case "pixels":
  253. $value = $this->user[12]; break;
  254. default:
  255. $value = $GLOBALS['serverdb']->result($GLOBALS['serverdb']->query("SELECT ".$key." FROM ".PREFIX."users WHERE id = '".$this->user[0]."' LIMIT 1")); break;
  256. }
  257. return $value;
  258. }
  259. function avatarURL($figure,$style,$return = 0){
  260. if($figure == "self"){ $figure = $this->figure; }
  261. $figure = $GLOBALS['input']->HoloText($figure);
  262. $hash = md5($figure.strtolower($style));
  263. $style = explode(",", $style);
  264. if($style[0] == "s"){ $style[6] = "1"; }else{ $style[6] = "0"; }
  265. if($style[3] == "sml"){ $style[7] = "1"; }else{ $style[7] = "0"; }
  266. $expandedstyle = "s-".$style[6].".g-".$style[7].".d-".$style[1].".h-".$style[2].".a-0";
  267. if($GLOBALS['settings']->find("site_cache_images") == "1" && file_exists("./cache/avatars/".$figure.",".$expandedstyle.",".$hash.".png")){
  268. $URL = PATH."/habbo-imaging/avatar/".$figure.",".$expandedstyle.",".$hash.".gif";
  269. }elseif($GLOBALS['settings']->find("site_cache_images") == "1" && !file_exists("./cache/avatars/".$figure.",".$expandedstyle.",".$hash.".png")){
  270. $URL = "http://habbo.de/habbo-imaging/avatarimage?figure=".$figure."&size=".$style[0]."&direction=".$style[1]."&head_direction=".$style[2]."&crr=".$style[5]."&gesture=".$style[3]."&frame=".$style[4];
  271. $i = file_get_contents($URL);
  272. $f = fopen("./cache/avatars/".$figure.",".$expandedstyle.",".$hash.".png","w+");
  273. fwrite($f,$i);
  274. fclose($f);
  275. $URL = PATH."/habbo-imaging/avatar/".$figure.",".$expandedstyle.",".$hash.".gif";
  276. }elseif($GLOBALS['settings']->find("site_cache_images") == "0"){
  277. $URL = "http://habbo.de/habbo-imaging/avatarimage?figure=".$figure."&size=".$style[0]."&direction=".$style[1]."&head_direction=".$style[2]."&crr=".$style[5]."&gesture=".$style[3]."&frame=".$style[4];
  278. }
  279. if($return == 0){ return $URL; }else{ return $hash; }
  280. }
  281. function updateUser($id){
  282. $lastvisit = $GLOBALS['db']->result($GLOBALS['db']->query("SELECT online FROM ".PREFIX."users WHERE id = '".$id."' LIMIT 1"));
  283. $GLOBALS['db']->query("UPDATE ".PREFIX."users SET lastvisit = '".$lastvisit."', online = '".time()."', ipaddress_last = '".$_SERVER['REMOTE_ADDR']."' WHERE id = '".$id."' LIMIT 1");
  284. $GLOBALS['core']->update5(GenerateTicket("sso"), $id);
  285. $GLOBALS['core']->update6($id, date('d-m-Y H:i:s'));
  286. }
  287. function GetUserBadge($id){
  288. if($id == "self"){ $id = $this->id; }
  289. $id = $GLOBALS['input']->FilterText($id);
  290. if($GLOBALS['serverdb']->num_rows($GLOBALS['core']->select5($id)) > 0){
  291. return $GLOBALS['serverdb']->result($GLOBALS['core']->select5($id));
  292. } else {
  293. return false;
  294. }
  295. }
  296. function GetUserGroup($id){
  297. if($id == "self"){ $id = $this->id; }
  298. if($GLOBALS['serverdb']->num_rows($GLOBALS['core']->select6($id)) > 0){
  299. return $GLOBALS['serverdb']->result($GLOBALS['core']->select6($id));
  300. } else {
  301. return false;
  302. }
  303. }
  304. function GetUserGroupBadge($id){
  305. if($id == "self"){ $id = $this->id; }
  306. if($GLOBALS['serverdb']->num_rows($GLOBALS['core']->select6($id)) > 0){
  307. return $GLOBALS['serverdb']->result($GLOBALS['core']->select7($GLOBALS['serverdb']->result($GLOBALS['core']->select6($id))));
  308. } else {
  309. return false;
  310. }
  311. }
  312. function HCDaysLeft($id){
  313. if($id == "self"){ $id = $this->id; }
  314. if($GLOBALS['serverdb']->num_rows($GLOBALS['core']->select8($id)) > 0){
  315. $days_left = $GLOBALS['serverdb']->result($GLOBALS['core']->select8($id)) * 31;
  316. $tmp = explode("-", $GLOBALS['serverdb']->result($GLOBALS['core']->select8($id), 0, 1));
  317. $day = $tmp[0];
  318. $month = $tmp[1];
  319. $year = $tmp[2];
  320. $then = mktime(0, 0, 0, $month, $day, $year, 0);
  321. $now = time();
  322. $difference = $now - $then;
  323. if ($difference < 0){
  324. $difference = 0;
  325. }
  326. $days_expired = floor($difference/60/60/24);
  327. $days_left = $days_left - $days_expired;
  328. return $days_left;
  329. } else {
  330. return 0;
  331. }
  332. }
  333. function IsHCMember($id){
  334. if($id == "self"){ $id = $this->id; }
  335. if($this->HCDaysLeft($id) > 0 ){
  336. return true;
  337. } else {
  338. if($GLOBALS['serverdb']->result($GLOBALS['core']->select9($id)) > 0){
  339. $GLOBALS['core']->update2($id);
  340. @SendMUSData('UPRS' . $id);
  341. }
  342. return false;
  343. }
  344. }
  345. function GiveHC($id, $months){
  346. if($id == "self"){ $id = $this->id; }
  347. if($GLOBALS['serverdb']->result($GLOBALS['core']->select9($id)) > 0){
  348. $GLOBALS['core']->update3($id, $months);
  349. if($GLOBALS['serverdb']->result($GLOBALS['core']->select11($id)) < 1){
  350. $GLOBALS['core']->update4($id);
  351. }
  352. } else {
  353. $m = date('m');
  354. $d = date('d');
  355. $Y = date('Y');
  356. $date = date('d-m-Y', mktime($m,$d,$Y));
  357. $GLOBALS['core']->insert1($id, $date);
  358. $this->GiveHC($id, $months);
  359. }
  360. @SendMUSData('UPRS' . $id);
  361. @SendMUSData('UPRC' . $id);
  362. }
  363. function IsUserOnline($id){
  364. if($id == "self"){ $id = $this->id; }
  365. $timeout = ((int) $GLOBALS['settings']->find("site_session_time")) * 60;
  366. $sql = $GLOBALS['db']->query("SELECT online,show_online FROM ".PREFIX."users WHERE id = '".$id."' LIMIT 1");
  367. if($GLOBALS['db']->result($sql, 0, 1) == 0){
  368. return false;
  369. }else{
  370. if($GLOBALS['db']->result($sql) + $timeout >= time()){
  371. return true;
  372. } else {
  373. return false;
  374. }
  375. }
  376. }
  377. function IsUserBanned($id){
  378. if($id == "self"){ $id = $this->id; }
  379. if(!is_numeric($id)){ return false; }
  380. if($GLOBALS['serverdb']->num_rows($GLOBALS['core']->select2($id)) > 0){
  381. $xbits = explode(" ", $GLOBALS['serverdb']->result($GLOBALS['core']->select2($id), 0, 1));
  382. $xtime = explode(":", $xbits[1]);
  383. $xdate = explode("-", $xbits[0]);
  384. $stamp_now = time();
  385. $stamp_expire = mktime((int) $xtime[0], (int) $xtime[1], (int) $xtime[2], (int) $xdate[0], (int) $xdate[1], (int) $xdate[2]);
  386. if($stamp_now < $stamp_expire){
  387. return true;
  388. } else {
  389. $GLOBALS['core']->delete1($id);
  390. return false;
  391. }
  392. } else {
  393. return false;
  394. }
  395. }
  396. }
  397. class HoloDatabase {
  398. var $connection;
  399. var $error;
  400. var $lastquery;
  401. function HoloDatabase($conn){
  402. switch($conn['server']){
  403. case "mysql":
  404. $this->connection = mysqli_connect($conn['host'],$conn['username'],$conn['password'],$conn['database']);
  405. $this->connection or $this->error = mysqli_error();
  406. break;
  407. case "pgsql":
  408. $this->connection = pg_connect("host=".$conn['host']." port=".$conn['port']." dbname=".$conn['database']." user=".$conn['username']." password=".$conn['password']);
  409. break;
  410. case "sqlite":
  411. $this->connection = sqlite_open($conn['host'], 0666, $this->error);
  412. break;
  413. case "mssql":
  414. $this->connection = mssql_connect($conn['host'].",".$conn['port'],$conn['username'],$conn['password'],true);
  415. break;
  416. }
  417. }
  418. }
  419. class mysql extends HoloDatabase {
  420.  
  421.  
  422. function query($query){
  423. if(defined('DEBUG')){ $this->lastquery = $query; }
  424. $query = mysqli_query($this->connection,$query);
  425. return $query;
  426. }
  427. function fetch_assoc($query){
  428. $result = mysqli_fetch_assoc($query);
  429. if(defined('DEBUG')){ $error = mysqli_error($this->connection); if($result == false && !empty($error)){ echo $error . "<br />Query that errored: ".$this->lastquery; } }
  430. return $result;
  431. }
  432. function fetch_row($query){
  433. $result = mysqli_fetch_row($query);
  434. //$result = mysqli_query($this->connection, $query);
  435. if(defined('DEBUG')){ $error = mysqli_error($this->connection); if($result == false && !empty($error)){ echo $error . "<br />Query that errored: ".$this->lastquery; } }
  436. return $result;
  437. }
  438. function fetch_array($result,$result_type=0){
  439. $result = mysqli_fetch_array($result,$result_type);
  440. if(defined('DEBUG')){ $error = mysqli_error($this->connection); if($result == false && !empty($error)){ echo $error . "<br />Query that errored: ".$this->lastquery; } }
  441. return $result;
  442. }
  443. function num_rows($query){
  444. $result = mysqli_num_rows($query);
  445. if(defined('DEBUG')){ $error = mysqli_error($this->connection); if($result == false && !empty($error)){ echo $error . "<br />Query that errored: ".$this->lastquery; } }
  446. return $result;
  447. }
  448. function result($query,$row=0,$column=0){
  449. $result = mysqli_result($query,$row,$column);
  450. if(defined('DEBUG')){ if($result == false){ echo mysqli_error($this->connection) . "<br />Query that errored: ".$this->lastquery; } }
  451. return $result;
  452. }
  453. function insert_id($query=null){
  454. return mysqli_insert_id($this->connection);
  455. }
  456. }
  457. class pgsql extends HoloDatabase {
  458. function query($query){
  459. if(defined('DEBUG')){ $this->lastquery = $query; }
  460. $query = pg_query($this->connection,$query);
  461. return $query;
  462. }
  463. function fetch_assoc($query){
  464. $result = pg_fetch_assoc($query);
  465. if(defined('DEBUG')){ $error = pg_last_error($this->connection); if($result == false && !empty($error)){ echo $error . "<br />Query that errored: ".$this->lastquery; } }
  466. return $result;
  467. }
  468. function fetch_row($query){
  469. $result = pg_fetch_row($query);
  470. if(defined('DEBUG')){ $error = pg_last_error($this->connection); if($result == false && !empty($error)){ echo $error . "<br />Query that errored: ".$this->lastquery; } }
  471. return $result;
  472. }
  473. function fetch_array($result,$result_type=0){
  474. $result = pg_fetch_array($result,null,$result_type);
  475. if(defined('DEBUG')){ $error = pg_last_error($this->connection); if($result == false && !empty($error)){ echo $error . "<br />Query that errored: ".$this->lastquery; } }
  476. return $result;
  477. }
  478. function num_rows($query){
  479. $result = pg_num_rows($query);
  480. if(defined('DEBUG')){ $error = pg_last_error($this->connection); if($result == false && !empty($error)){ echo $error . "<br />Query that errored: ".$this->lastquery; } }
  481. return $result;
  482. }
  483. function result($query,$row=0,$column=0){
  484. $result = pg_fetch_result($query,$row,$column);
  485. if(defined('DEBUG')){ if($result == false){ echo pg_last_error($this->connection) . "<br />Query that errored: ".$this->lastquery; } }
  486. return $result;
  487. }
  488. function insert_id($query){
  489. return pg_last_oid($query);
  490. }
  491. }
  492. class sqlite extends HoloDatabase {
  493. function query($query){
  494. if(defined('DEBUG')){ $this->lastquery = $query; }
  495. $query = sqlite_query($query,$this->connection);
  496. return $query;
  497. }
  498. function fetch_assoc($query){
  499. $result = sqlite_fetch_all($query);
  500. if(defined('DEBUG')){ $error = sqlite_last_error($this->connection); if($result == false && !empty($error)){ echo $error . "<br />Query that errored: ".$this->lastquery; } }
  501. return $result;
  502. }
  503. function fetch_row($query){
  504. $result = sqlite_fetch_all($query,SQLITE_NUM);
  505. if(defined('DEBUG')){ $error = sqlite_last_error($this->connection); if($result == false && !empty($error)){ echo $error . "<br />Query that errored: ".$this->lastquery; } }
  506. return $result;
  507. }
  508. function fetch_array($result,$result_type=0){
  509. $result = sqlite_fetch_array($result,$result_type);
  510. if(defined('DEBUG')){ $error = sqlite_last_error($this->connection); if($result == false && !empty($error)){ echo $error . "<br />Query that errored: ".$this->lastquery; } }
  511. return $result;
  512. }
  513. function num_rows($query){
  514. $result = sqlite_num_rows($query);
  515. if(defined('DEBUG')){ $error = sqlite_last_error($this->connection); if($result == false && !empty($error)){ echo $error . "<br />Query that errored: ".$this->lastquery; } }
  516. return $result;
  517. }
  518. function result($query,$row=0,$column=0){
  519. sqlite_seek($query,$row);
  520. $result = sqlite_fetch_array($query);
  521. $result = $result[$column];
  522. if(defined('DEBUG')){ if($result == false){ echo sqlite_last_error($this->connection) . "<br />Query that errored: ".$this->lastquery; } }
  523. return $result;
  524. }
  525. function insert_id($query){
  526. return sqlite_last_insert_rowid($this->connection);
  527. }
  528. }
  529. class mssql extends HoloDatabase {
  530. function query($query){
  531. if(defined('DEBUG')){ $this->lastquery = $query; }
  532. $query = mssql_query($query,$this->connection);
  533. return $query;
  534. }
  535. function fetch_assoc($query){
  536. $result = mssql_fetch_assoc($query);
  537. if(defined('DEBUG')){ $error = mssql_get_last_message(); if($result == false && !empty($error)){ echo $error . "<br />Query that errored: ".$this->lastquery; } }
  538. return $result;
  539. }
  540. function fetch_row($query){
  541. $result = mssql_fetch_row($query);
  542. if(defined('DEBUG')){ $error = mssql_get_last_message(); if($result == false && !empty($error)){ echo $error . "<br />Query that errored: ".$this->lastquery; } }
  543. return $result;
  544. }
  545. function fetch_array($result,$result_type=0){
  546. $result = mssql_fetch_array($result,$result_type);
  547. if(defined('DEBUG')){ $error = mssql_get_last_message(); if($result == false && !empty($error)){ echo $error . "<br />Query that errored: ".$this->lastquery; } }
  548. return $result;
  549. }
  550. function num_rows($query){
  551. $result = mssql_num_rows($query);
  552. if(defined('DEBUG')){ $error = mssql_get_last_message(); if($result == false && !empty($error)){ echo $error . "<br />Query that errored: ".$this->lastquery; } }
  553. return $result;
  554. }
  555. function result($query,$row=0,$column=0){
  556. $result = mssql_result($query,$row,$column);
  557. if(defined('DEBUG')){ if($result == false){ echo mssql_get_last_message() . "<br />Query that errored: ".$this->lastquery; } }
  558. return $result;
  559. }
  560. function insert_id($query){
  561. return mssql_result(mssql_query("SELECT @@identity"),0);
  562. }
  563. }
  564. class HoloLocale {
  565. var $loc = array();
  566. function addLocale($keys){
  567. if(is_array($keys)){
  568. foreach($keys as $key){
  569. require('./includes/languages/'.$GLOBALS['settings']->find("site_language").'.php');
  570. $this->loc = array_merge($this->loc,$loc);
  571. }
  572. }else{
  573. $key = $keys;
  574. require('./includes/languages/'.$GLOBALS['settings']->find("site_language").'.php');
  575. $this->loc = array_merge($this->loc,$loc);
  576. }
  577. return true;
  578. }
  579. function clearLocale($key){
  580. unset($this->loc);
  581. return true;
  582. }
  583. }
  584. class HoloFigureCheck {
  585. var $error = 0;
  586. function HoloFigureCheck($figure=null,$gender=null,$club=false){
  587. if(empty($figure)){ $this->error = 12; return false; }
  588. $xml = simplexml_load_file('./xml/figuredata.xml');
  589. $sets = explode(".",$figure);
  590. foreach($sets as $set){
  591. $valid = array(false,false,false,false);
  592. $parts = explode("-",$set);
  593. $havesets[] = $parts[0];
  594. foreach($xml->sets->settype as $settype){
  595. if((string) $settype['mandatory'] == "1"){ $mandatory[] = $settype['type']; }
  596. if((string) $settype['type'] == $parts[0]){
  597. $parts[3] = $settype['paletteid'];
  598. $valid[0] = true; $type = $settype;
  599. break;
  600. }
  601. }
  602. if($valid[0] != true){ $this->error = 1; return false; }
  603. foreach($type->set as $xset){
  604. if((string) $xset['id'] == $parts[1]){
  605. if($xset['selectable'] == "0"){ $this->error = 2; return false; }
  606. if($xset['colorable'] == "0"){ $nocolor = true; if($parts[2] != ""){ $this->error = 3; return false; } }else{ $nocolor = false; }
  607. if($xset['gender'] != $gender && $xset['gender'] != "U"){ $this->error = 4; return false; }
  608. if($xset['club'] == "1" && $club == false){ $this->error = 5; return false; }
  609. $valid[1] = true; $details = $xset;
  610. break;
  611. }
  612. }
  613. if($valid[1] != true){ $this->error = 6; return false; }
  614. if($nocolor != true){
  615. foreach($xml->colors->palette as $palette){
  616. if((string) $palette['id'] == (string) $parts[3]){
  617. $valid[2] = true; $pat = $palette;
  618. break;
  619. }
  620. }
  621. if($valid[2] != true){ $this->error = 7; return false; }
  622. foreach($pat->color as $color){
  623. if((string) $color['id'] == $parts[2]){
  624. if($color['club'] == "1" && $club == false){ $this->error = 8; return false; }
  625. if($color['selectable'] == "0"){ $this->error = 9; return false; }
  626. $valid[3] = true;
  627. break;
  628. }
  629. }
  630. if($valid[3] != true){ $this->error = 10; return false; }
  631. }
  632. }
  633. if(count($mandatory) != count(array_intersect($mandatory,$havesets))){ $this->error = 11; return false; }
  634. return true;
  635. }
  636. function generateFigure($club=true,$gender=null){
  637. if($gender == null){ if(rand(0,1) == 0){ $gender = "M"; }else{ $gender = "F"; } }
  638. if($club == true){ $club = (bool) rand(0,1); }
  639. $xml = simplexml_load_file('./xml/figuredata.xml');
  640. $figure = "";
  641. foreach($xml->sets->settype as $settype){
  642. if((string) $settype['mandatory'] == "1" || rand(0,1) == 1){
  643. $item['settype'] = $settype['type'];
  644. $palette = (int) $settype['paletteid'];
  645. $possible = array();
  646. foreach($settype->set as $xset){
  647. if($xset['gender'] != "U" && $xset['gender'] != $gender){ $fail = true; }
  648. if($xset['selectable'] == "0"){ $fail = true; }
  649. if($xset['colorable'] == "0"){ $color = false; }else{ $color = true; }
  650. if($xset['club'] == "1" && $club == false){ $fail = true; }
  651. if($fail != true){ $possible[] = array($xset['id'],$color); }
  652. $fail = false; $color = false;
  653. }
  654. $count = count($possible);
  655. $num = rand(0,$count-1);
  656. $item['set'] = $possible[$num][0];
  657. if($possible[$num][1] == false){ $item['color'] = ""; }else{
  658. $possible = array();
  659. foreach($xml->colors->palette[$palette-1]->color as $color){
  660. if($color['club'] == "1" && $club == false){ $fail = true; }
  661. if($color['selectable'] == "0"){ $fail = true; }
  662. if($fail != true){ $possible[] = $color['id']; }
  663. $fail = false;
  664. }
  665. $count = count($possible);
  666. $num = rand(0,$count-1);
  667. $item['color'] = $possible[$num];
  668. }
  669. $figure .= $item['settype']."-".$item['set']."-".$item['color'].".";
  670. }
  671. }
  672. $figure = substr($figure, 0, -1);
  673. return array($figure,$gender);
  674. }
  675. }
  676. class HoloSettings {
  677. var $cache;
  678. function HoloSettings(){
  679. include('./cache/settings.ret');
  680. if(isset($setting)){ $this->cache = $setting; }
  681. return true;
  682. }
  683. function generateCache(){
  684. if($this->find("cache_settings") == "1"){
  685. $fh = @fopen('./cache/settings.ret', 'w');
  686. @fwrite($fh, "<?php\n/*DO NOT EDIT THIS FILE, EDIT THE SETTINGS TABLE OR USE HOUSEKEEPING, THIS FILE IS JUST A CACHE*/\n");
  687. $sql = $GLOBALS['db']->query("SELECT id,value FROM ".PREFIX."settings");
  688. while($row = $GLOBALS['db']->fetch_assoc($sql)){
  689. @fwrite($fh, "$"."setting['".$row['id']."'] = \"".$GLOBALS['input']->FilterText($row['value'])."\";\n");
  690. }
  691. @fwrite($fh, "?>");
  692. @fclose($fh);
  693. }else{
  694. @unlink('./cache/settings.ret');
  695. }
  696. $this->HoloSettings();
  697. return true;
  698. }
  699. function find($key){
  700. if(!empty($this->cache)){
  701. return $GLOBALS['input']->HoloText($this->cache[$key],true);
  702. }else{
  703. $sql = $GLOBALS['db']->query("SELECT value FROM ".PREFIX."settings WHERE id = '".$key."' LIMIT 1");
  704. return $GLOBALS['input']->HoloText($GLOBALS['db']->result($sql),true);
  705. }
  706. }
  707. function checkCache(){
  708. if($this->find("cache_settings") == "1"){
  709. @require('./cache/settings.ret');
  710. $sql = $GLOBALS['db']->query("SELECT id,value FROM ".PREFIX."settings");
  711. while($row = $GLOBALS['db']->fetch_assoc($sql)){
  712. if(stripslashes($setting[$row['id']]) != stripslashes($row['value'])){ return true; }
  713. }
  714. return false;
  715. }else{
  716. @unlink('./cache/settings.ret');
  717. return false;
  718. }
  719. }
  720. }
  721. class HoloMail {
  722. var $plaintext;
  723. var $html;
  724. var $logo;
  725. var $boundary;
  726. var $email;
  727. var $subject;
  728. function sendSimpleMessage($to,$subject,$html,$plaintext=null){
  729. $this->logo = $this->generateLogo();
  730. $this->html = $this->htmlToMessage('./templates/email_header.php').$html.$this->htmlToMessage('./templates/email_footer.php');
  731. if($plaintext == null){ $this->plaintext = $this->generatePlainText($this->html); }else{ $this->plaintext = $plaintext; }
  732. $array = $this->generateHeaders($to,$subject); $header = $array[1];
  733. $message = $this->generateMessage();
  734. $success = mail($to,$subject,$message,$header);
  735. return $success;
  736. }
  737. function sendNewsletter($to,$subject,$html){
  738. $this->html = $html;
  739. $this->plaintext = $this->generatePlainText($html);
  740. $array = $this->generateHeaders($to,$subject); $header = $array[1];
  741. $message = $this->generateMessage();
  742. $success = mail($to,$subject,$message,$header);
  743. return $success;
  744. }
  745. function generatePlainText($html){
  746. return preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", "\n", strip_tags(str_replace("<br />", "\n", str_replace("%name%", $row['name'], $html))));
  747. }
  748. function generateHeaders($to,$subject){
  749. $this->boundary = time();
  750. $preheader = '';
  751. $preheader .= 'To: '.$to."\r\n";
  752. $preheader .= 'Subject: '.$subject;
  753. $header = '';
  754. $header .= 'Return-Path: <'.$GLOBALS['settings']->find("email_from").'>'."\r\n";
  755. $header .= 'Date: '.date('r (T)')."\r\n";
  756. $header .= 'From: "'.$GLOBALS['settings']->find("email_name").'" <'.$GLOBALS['settings']->find("email_from").'>'."\r\n";
  757. $header .= 'MIME-Version: 1.0'."\r\n";
  758. $header .= 'Content-Type: multipart/related; '."\r\n";
  759. $header .= ' boundary="----=_Part_402930_17237178.'.$this->boundary.'"';
  760. return array($preheader,$header);
  761. }
  762. function generateLogo($file=null){
  763. if($file == null){ $file = './web-gallery/email/images/habbologo.gif'; }
  764. $fh = fopen($file, "r");
  765. $image = fread ($fh, filesize($file));
  766. fclose($fh);
  767. $encodedimage = chunk_split(base64_encode($image));
  768. if($encodedimage == ""){
  769. $encodedimage =
  770. 'R0lGODlhoABCAJEDAP/OAAAAAP5jAf//ACH5BAEAAAMALAAAAACgAEIAAAL/nI+py+0Po5y02ouz
  771. 3rz7D4biSJbmiabqyrbuC8fyTNf2jef6zvf+D3QFhrih8YhMBhBK5KEJfUKVjClRsTRka1broHv8
  772. gp1jp3TMFC+3syHgDX+74/AknW6/6/N6vFFr1Cf3pyVWyBXQN3d3JOi36FgXGBnHF0m49qWJqJi4
  773. B0k5SSnpOToIenm1xdZW6tfpGoqaGis7KximVlQ72GlayZv6Kzl8ynpzmxzseMu8jPsMe5Wj7Ptp
  774. zRhcfc2dLUC4i/3aPZ4tDnxO/CnwPW2zbU6OLq8eb1/ux95+LAOPP38P4L96A3ut0weORjNo6QwG
  775. JCgwIkRJ+ti5a1UMgD+J/7IybqRYMWG/aPQcFnRG8lFDjQEqWuT3YuHKj9BE2aLJ0mW7dylP4vxk
  776. kxbOITovxpBZUtiwoLZmtnRpFAbShx2LTfWp7WlImEJ6clRKlaVTp0W5thjqdaLJr2g7leU51mrW
  777. uGGVveWUtG3euXvdQjXLQm9dvoPp5vsLt6/ipWnXjiKKGG/hxb+ufnV2VyFhrCtryrXMUitCwCsE
  778. c2bcuFFl0aMTT379mClK2UB17pR8Gvbsq0deLuxtO2rMMsSLT9lHfOsY2y95Gn9ufPTy4F2Yt3ZO
  779. nbXv7Nytd/du3Qj48KQDQ/6rfd935ePRt2cu/r10aufZl00f37189fvty10X3gp+9Um3HoH75Xcg
  780. cO2JhMyA291X4IMLKjghERRmV95R0G3IYXFnoPFDhyJ6oUYZC4ARRIoqrshiiy6+CGOMMs5IY402
  781. 3ohjjjruyGOPPv4IZJBCDklkkUYeWQAAOw==';
  782. }
  783. return $encodedimage;
  784. }
  785. function generateMessage(){
  786. $message = '';
  787. $message .=
  788. '------=_Part_402930_17237178.'.$this->boundary.'
  789. Content-Type: multipart/alternative;
  790. boundary="----=_Part_402931_29846152.'.$this->boundary.'"'."\r\n\r\n";
  791. if($this->plaintext != ""){ $message .=
  792. '------=_Part_402931_29846152.'.$this->boundary.'
  793. Content-Type: text/plain; charset=ISO-8859-1
  794. Content-Transfer-Encoding: 7bit
  795.  
  796. '.$this->plaintext."\r\n";
  797. }
  798. if($this->html != ""){ $message .=
  799. '------=_Part_402931_29846152.'.$this->boundary.'
  800. Content-Type: text/html;charset=ISO-8859-1
  801. Content-Transfer-Encoding: 7bit
  802.  
  803. '.$this->html.'
  804. ------=_Part_402931_29846152.'.$this->boundary.'--'."\r\n\r\n";
  805. }
  806. if($this->logo != ""){ $message .=
  807. '------=_Part_402930_17237178.'.$this->boundary.'
  808. Content-Type: image/gif
  809. Content-Transfer-Encoding: base64
  810. Content-Disposition: inline
  811. Content-ID: <habbologo>
  812.  
  813. '.$this->logo.'
  814. ------=_Part_402930_17237178.'.$this->boundary.'--';
  815. }
  816. return $message;
  817. }
  818. function htmlToMessage($file){
  819. global $lang;
  820. ob_start();
  821. include($file);
  822. $contents = ob_get_clean();
  823. ob_end_clean();
  824. return $contents;
  825. }
  826. }
  827. ?>
Add Comment
Please, Sign In to add comment