<?php
// - it will be possible to turn debug on/off
//DEBUG
function debugText($file, $function, $text = '')
{
if(!$function)
$function = '(load file)';
echo '<br /><b>' . $file . '</b> - <b>' . $function . '</b> <i>' . $text;
}
// -- DEBUG
class Errors
{
const TYPE_BOTH = 0; // parameter for some functions to return 'errors and notices'
const TYPE_NOTICE = 1; // show information for website user, for example 'this name contains illegal letters' [when create account]
const TYPE_ERROR = 2; // show important information about bug that administrator must fix, for example 'file ./logs/paypal_transactions.log does not exist'
const TYPE_CRITIC = 3; // show error information and block script execution
private $errors = array();
private $notices = array();
public function addNotice($id = null, $text = null)
{
$this->notices[] = new Error($id, $text, Errors::TYPE_NOTICE);
}
public function addError($id = null, $text = null)
{
$this->errors[] = new Error($id, $text, Errors::TYPE_ERROR);
}
public function addCriticError($id = null, $text = null, $errors = array())
{
throw new Error_Critic($id, $text, $errors);
}
public function addErrors($array)
{
$this->errors = array_merge($this->errors, $array);
}
public function addNotices($array)
{
$this->notices = array_merge($this->notices, $array);
}
public function getErrorsList($type = Errors::TYPE_BOTH)
{
if($type == Errors::TYPE_BOTH)
return array_merge($this->notices, $this->errors);
elseif($type == Errors::TYPE_NOTICE)
return $this->notices;
elseif($type == Errors::TYPE_ERROR)
return $this->errors;
else
return array();
}
public function getErrorsCount($type = Errors::TYPE_BOTH)
{
if($type == Errors::TYPE_BOTH)
return count($this->notices) + count($this->errors);
elseif($type == Errors::TYPE_NOTICE)
return count($this->notices);
elseif($type == Errors::TYPE_ERROR)
return count($this->errors);
else
return 0;
}
}
class Error
{
private $errorId = 'unknown';
private $errorText = 'no text';
private $errorType = Errors::TYPE_ERROR;
public function __construct($id = null, $text = null, $type = null)
{
if(isset($id))
$this->errorId = $id;
if(isset($text))
$this->errorText = $text;
if(isset($type))
$this->errorType = $type;
}
public function getId()
{
return $this->errorId;
}
public function getText()
{
return $this->errorText;
}
public function getType()
{
return $this->errorType;
}
}
class Error_Critic
{
public function __construct($id = '', $text = '', $errors = array())
{
echo '<h3>Error occured!</h3>';
echo 'Error ID: <b>' . $id . '</b><br />';
echo 'More info: <b>' . $text . '</b><br />';
if(count($errors) > 0)
{
echo 'Errors list:<br />';
foreach($errors as $error)
echo '<li>' . $error->getId() . ' - ' . $error->getText() . '</li>';
}
array_walk( debug_backtrace(), create_function( '$a,$b', 'print "<br />File: <b>". dirname( $a[\'file\'] ) . "/" .basename( $a[\'file\'] ). "</b> Line: <font color=\"red\">{$a[\'line\']}</font>";' ) );
exit;
}
}
class Functions // 90% to rewrites
{
public function generateURL($page, $params = array()) // to fix
{
if(Website::getInstance()->getWebsiteConfig()->getValue('useRewrite'))
{
return 'rew';
}
else
{
return 'not';
}
}
public function isValidFolderName($string)
{
$res = eregi_replace("([A-Z0-9]+)","",$string);
return empty($res);
}
public function isPremium($premdays, $lastday)
{
return ($premdays - (date("z", time()) + (365 * (date("Y", time()) - date("Y", $lastday))) - date("z", $lastday)) > 0);
}
public function checkAccountName($name)
{
if(strspn($name, "QWERTYUIOPASDFGHJKLZXCVBNM0123456789") != strlen($name))
return false;
if(strlen($name) > 32)
return false;
else
return true;
}
public function checkCharacterName($name)
{
$name_to_check = strtolower($name);
$names_blocked = array('gm','cm', 'god', 'tutor');
$first_words_blocked = array('gm ','cm ', 'god ','tutor ', "'", '-');
$words_blocked = array('gamemaster', 'game master', 'game-master', "game'master", '--', "''","' ", " '", '- ', ' -', "-'", "'-", 'fuck', 'sux', 'suck', 'noob', 'tutor');
foreach($first_words_blocked as $word)
if($word == substr($name_to_check, 0, strlen($word)))
return false;
if(substr($name_to_check, -1) == "'" || substr($name_to_check, -1) == "-")
return false;
if(substr($name_to_check, 1, 1) == ' ')
return false;
if(substr($name_to_check, -2, 1) == " ")
return false;
foreach($names_blocked as $word)
if($word == $name_to_check)
return false;/*
foreach($GLOBALS['config']['site']['monsters'] as $word)
if($word == $name_to_check)
return false;
foreach($GLOBALS['config']['site']['npc'] as $word)
if($word == $name_to_check)
return false;*/
for($i = 0; $i < strlen($name_to_check); $i++)
if($name_to_check[$i-1] == ' ' && $name_to_check[$i+1] == ' ')
return false;
foreach($words_blocked as $word)
if(!(strpos($name_to_check, $word) === false))
return false;
for($i = 0; $i < strlen($name_to_check); $i++)
if($name_to_check[$i] == $name_to_check[($i+1)] && $name_to_check[$i] == $name_to_check[($i+2)])
return false;
for($i = 0; $i < strlen($name_to_check); $i++)
if($name_to_check[$i-1] == ' ' && $name_to_check[$i+1] == ' ')
return false;
$temp = strspn($name, "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM- '");
if ($temp != strlen($name))
return false;
else
return (preg_match("/[a-zA-Z ']{1,25}/", $name))? true: false;
}
public function checkGuildRankName($name)
{
if(strspn($name, "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM0123456789-[ ] ") != strlen($name))
return false;
else
return (preg_match("/[a-zA-Z ]{1,60}/", $name))? true: false;
}
public function checkGuildName($name)
{
if(strspn($name, "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM0123456789- ") != strlen($name))
return false;
else
return (preg_match("/[a-zA-Z ]{1,60}/", $name))? true: false;
}
public function getBanReasonName($reasonId)
{
switch($reasonId)
{
case 0:
return "Offensive Name";
case 1:
return "Invalid Name Format";
case 2:
return "Unsuitable Name";
case 3:
return "Name Inciting Rule Violation";
case 4:
return "Offensive Statement";
case 5:
return "Spamming";
case 6:
return "Illegal Advertising";
case 7:
return "Off-Topic Public Statement";
case 8:
return "Non-English Public Statement";
case 9:
return "Inciting Rule Violation";
case 10:
return "Bug Abuse";
case 11:
return "Game Weakness Abuse";
case 12:
return "Using Unofficial Software to Play";
case 13:
return "Hacking";
case 14:
return "Multi-Clienting";
case 15:
return "Account Trading or Sharing";
case 16:
return "Threatening Gamemaster";
case 17:
return "Pretending to Have Influence on Rule Enforcement";
case 18:
return "False Report to Gamemaster";
case 19:
return "Destructive Behaviour";
case 20:
return "Excessive Unjustified Player Killing";
case 21:
return "Invalid Payment";
case 22:
return "Spoiling Auction";
default:
return "Unknown Reason";
}
}
public function limitTextLenght($text, $lenght_limit)
{
if(strlen($text) > $lenght_limit)
return substr($text, 0, strrpos(substr($text, 0, $lenght_limit), " ")).'...';
else
return $text;
}
public function isFileImage($path)
{
$txt = file_get_contents($path);
if(preg_match("#([a-z]*)=([\`\'\"]*)script:#iU", $txt))
return false;
if(preg_match("#([a-z]*)=([\`\'\"]*)javascript:#iU", $txt))
return false;
if(preg_match("#([a-z]*)=([\'\"]*)vbscript:#iU", $txt))
return false;
if(preg_match("#(<[^>]+)style=([\`\'\"]*).*expression\([^>]*>#iU", $txt))
return false;
if(preg_match("#(<[^>]+)style=([\`\'\"]*).*behaviour\([^>]*>#iU", $txt))
return false;
if(preg_match("#</*(applet|body|head|html|link|style|script|iframe|frame|frameset)[^>]*>#i", $txt))
return false;
return true;
}
public function getOrderSQL($arr, $order, $default)
{
$type = 'asc';
if(isset($_GET['order']))
{
$v = explode('_', strrev($_GET['order']), 2);
if(count($v) == 2)
if($orderBy = $arr[strrev($v[1])])
$default = $orderBy;
$type = (strrev($v[0]) == 'asc' ? 'desc' : 'asc');
}
return 'ORDER BY ' . $default . ' ' . $type;
}
public function getOrderParameter($arr, $order, $that)
{
$type = 'asc';
if($orderBy = $arr[$that])
if(isset($_GET[$order]))
{
$v = explode('_', strrev($_GET[$order]), 2);
if(strrev($v[1]) == $that)
$type = (strrev($v[0]) == 'asc' ? 'desc' : 'asc');
}
return $that . '_' . $type;
}
public function getPageViews()
{
return file_get_contents("./cache/pageviews.counter");
}
public function setPageViews($value)
{
file_put_contents("./cache/pageviews.counter", $value);
}
public function addPageView()
{
setPageViews(self::getPageViews()+1);
}
}
class Account
{
private $data = array();
public function setID($id){$this->id = $id;}
public function getID(){return $this->id;}
}
class Visitor
{
public $loginAccount;
public $loginPassword;
public $account;
public function getLoginAccount()
{
return $this->loginAccount;
}
public function setLoginAccount($value)
{
$this->loginAccount = $value;
}
public function getLoginPassword()
{
return $this->loginPassword;
}
public function setLoginPassword($value)
{
$this->loginPassword = $value;
}
public function getAccount()
{
if(!isset($this->account))
$this->loadAccount();
return $this->account;
}
public function loadAccount()
{
// try to load account
// need to finish
$this->account = new Account();
return true;
}
public function isLogged()
{
return $this->getAccount()->isLoaded();
}
}
class Database extends PDO
{
private $connected = false;
const DB_MYSQL = 1;
const DB_SQLITE = 2;
private $db_driver;
private $db_host = 'localhost';
private $db_port = '3306';
private $db_name;
private $db_username;
private $db_password;
private $db_file;
public function connect()
{
return false;
}
public function isConnected()
{
return $this->connected;
}
public function setConnected($value)
{
$this->connected = $value;
}
public function getDatabaseDriver()
{
return $this->db_driver;
}
public function getDatabaseHost()
{
return $this->db_host;
}
public function getDatabasePort()
{
return $this->db_port;
}
public function getDatabaseName()
{
return $this->db_name;
}
public function getDatabaseUsername()
{
return $this->db_username;
}
public function getDatabasePassword()
{
return $this->db_password;
}
public function getDatabaseFile()
{
return $this->db_file;
}
public function setDatabaseDriver($value)
{
$this->db_driver = $value;
}
public function setDatabaseHost($value)
{
$this->db_host = $value;
}
public function setDatabasePort($value)
{
$this->db_port = $value;
}
public function setDatabaseName($value)
{
$this->db_name = $value;
}
public function setDatabaseUsername($value)
{
$this->db_username = $value;
}
public function setDatabasePassword($value)
{
$this->db_password = $value;
}
public function setDatabaseFile($value)
{
$this->db_file = $value;
}
public function beginTransaction()
{
if($this->isConnected() || $this->connect())
return parent::beginTransaction();
else
throw new Exception('Website is not connected to database. Cannot execute "beginTransaction()"');
}
public function commit()
{
if($this->isConnected() || $this->connect())
return parent::commit();
else
throw new Exception('Website is not connected to database. Cannot execute "commit()"');
}
public function errorCode()
{
if($this->isConnected() || $this->connect())
return parent::errorCode();
else
throw new Exception('Website is not connected to database. Cannot execute "errorCode()"');
}
public function errorInfo()
{
if($this->isConnected() || $this->connect())
return parent::errorInfo();
else
throw new Exception('Website is not connected to database. Cannot execute errorInfo()');
}
public function exec($statement)
{
if($this->isConnected() || $this->connect())
return parent::exec($statement);
else
throw new Exception('Website is not connected to database. Cannot execute exec(\$statement)');
}
public function getAttribute($attribute)
{
if($this->isConnected() || $this->connect())
return parent::getAttribute($attribute);
else
throw new Exception('Website is not connected to database. Cannot execute getAttribute(\$attribute)');
}
public static function getAvailableDrivers()
{
if($this->isConnected() || $this->connect())
return parent::getAvailableDrivers();
else
throw new Exception('Website is not connected to database. Cannot execute getAvailableDrivers()');
}
public function inTransaction()
{
if($this->isConnected() || $this->connect())
return parent::inTransaction();
else
throw new Exception('Website is not connected to database. Cannot execute inTransaction()');
}
public function lastInsertId($name = NULL)
{
if($this->isConnected() || $this->connect())
return parent::lastInsertId($name);
else
throw new Exception('Website is not connected to database. Cannot execute ');
}
public function prepare($statement, $driver_options = array())
{
if($this->isConnected() || $this->connect())
return parent::prepare($statement, $driver_options);
else
throw new Exception('Website is not connected to database. Cannot execute lastInsertId(\$name)');
}
public function query($statement)
{
if($this->isConnected() || $this->connect())
return parent::query($statement);
else
throw new Exception('Website is not connected to database. Cannot execute query(\$statement)');
}
public function quote($string, $parameter_type)
{
if($this->isConnected() || $this->connect())
return parent::quote($string, $parameter_type);
else
throw new Exception('Website is not connected to database. Cannot execute quote(\$string, \$parameter_type)');
}
public function rollBack()
{
if($this->isConnected() || $this->connect())
return parent::rollBack();
else
throw new Exception('Website is not connected to database. Cannot execute rollBack()');
}
public function setAttribute($attribute, $value)
{
if($this->isConnected() || $this->connect())
return parent::setAttribute($attribute, $value);
else
throw new Exception('Website is not connected to database. Cannot execute setAttribute(\$attribute, \$value)');
}
}
class Database_MySQL extends Database
{
public function __construct()
{
$this->setDatabaseDriver(self::DB_MYSQL);
}
public function connect()
{
try
{
parent::__construct('mysql:host=' . $this->getDatabaseHost() . ';port=' . $this->getDatabasePort() . ';dbname=' . $this->getDatabaseName(), $this->getDatabaseUsername(), $this->getDatabasePassword());
$this->setConnected(true);
return true;
}
catch(PDOException $error)
{
return false;
}
}
public function fieldName($name)
{
return '`' . $name . '`';
}
}
class Database_SQLite extends Database
{
public function __construct()
{
$this->setDatabaseDriver(self::DB_SQLITE);
}
public function connect()
{
try
{
parent::__construct('sqlite:' . $this->getDatabaseFile());
$this->setConnected(true);
return true;
}
catch(PDOException $error)
{
return false;
}
}
public function fieldName($name)
{
return '"' . $name . '"';
}
}
class ConfigLUA extends Errors // NOT SAFE CLASS, LUA CONFIG CAN BE EXECUTED AS PHP CODE
{
private $config;
public function __construct($path = false)
{
if($path)
$this->loadFromFile($path);
}
public function loadFromFile($path)
{
if(file_exists($path))
{
$content = file_get_contents($path);
$this->loadFromString($content);
}
else
self::addError('#C-2', 'ERROR: <b>#C-2</b> : Class::ConfigLUA - LUA config file doesn\'t exist. Path: <b>' . $path . '</b>');
}
public function loadFromString($string)
{
$lines = explode("\n", $string);
if(count($lines) > 0)
foreach($lines as $ln => $line)
{
$tmp_exp = explode('=', $line);
if(count($tmp_exp) >= 2)
{
$key = trim($tmp_exp[0]);
if(substr($key, 0, 2) != '--')
{
unset($tmp_exp[0]);
$value = trim(implode('=', $tmp_exp)); // in MOTD/serverName can be =
if(is_numeric($value))
$this->config[ $key ] = (float) $value;
elseif(in_array(substr($value, 0 , 1), array("'", '"')) && in_array(substr($value, -1 , 1), array("'", '"')))
$this->config[ $key ] = (string) substr(substr($value, 1), 0, -1);
elseif(in_array($value, array('true', 'false')))
$this->config[ $key ] = ($value == 'true') ? true : false;
else
{
foreach($this->config as $tmp_key => $tmp_value)
$value = str_replace($tmp_key, $tmp_value, $value);
$ret = @eval("return $value;");
if((string) $ret == '') // = parser error
self::addError('#C-1', 'ERROR: <b>#C-1</b> : Class::ConfigLUA - Line <b>' . ($ln + 1) . '</b> of LUA config file is not valid [key: <b>' . $key . '</b>]');
$this->config[ $key ] = $ret;
}
}
}
}
}
public function getValue($key)
{
if(isset($this->config[ $key ]))
return $this->config[ $key ];
else
self::addError('#C-3', 'ERROR: <b>#C-3</b> : Class::ConfigLUA - Key <b>' . $key . '</b> doesn\'t exist.');
}
public function isSetKey($key)
{
return isset($this->config[ $key ]);
}
public function getConfig()
{
return $this->config;
}
}
class ConfigPHP extends Errors
{
private $config;
private $loadedFromPath;
public function __construct($path = false)
{
if($path)
$this->loadFromFile($path);
}
public function loadFromFile($path)
{
if(file_exists($path))
{
$content = file_get_contents($path);
$this->loadedFromPath = $path;
$lines = explode("\n", $content);
unset($lines[0]); // remove <?PHP
unset($lines[count($lines)]); // remove ? >
$this->loadFromString(implode("\n", $lines));
}
else
self::addError('#C-4', 'ERROR: <b>#C-4</b> : Class::ConfigPHP - PHP config file doesn\'t exist. Path: <b>' . $path . '</b>');
}
public function loadFromString($string)
{
eval('$_web_config = array();' . chr(0x0A) . $string . chr(0x0A) . '');
$this->config = $_web_config;
unset($_web_config);
}
private function parsePhpVariableToText($value)
{
if(is_bool($value))
return ($value) ? 'true' : 'false';
elseif(is_numeric($value))
return $value;
else
return '"' . str_replace('"', '\"' , $value) . '"';
}
public function arrayToPhpString(array $a, $d)
{
$s = '';
if(is_array($a) && count($a) > 0)
foreach($a as $k => $v)
{
if(is_array($v))
$s .= self::arrayToPhpString($v, $d . '["' . $k . '"]');
else
$s .= $d . '["' . $k . '"] = ' . self::parsePhpVariableToText($v) . ';' . chr(0x0A);
}
return $s;
}
public function getConfigAsString()
{
return self::arrayToPhpString($this->config, '$_web_config');
}
public function saveToFile($path = false)
{
if($path)
$savePath = $path;
else
$savePath = $this->loadedFromPath;
file_put_contents($savePath, '<?PHP' . chr(0x0A) . $this->getConfigAsString() . '?>');
}
public function getValue($key)
{
if(isset($this->config[ $key ]))
return $this->config[ $key ];
else
self::addError('#C-5', 'ERROR: <b>#C-5</b> : Class::ConfigPHP - Key <b>' . $key . '</b> doesn\'t exist.');
}
public function setValue($key, $value)
{
$this->config[ $key ] = $value;
}
public function removeKey($key)
{
if(isset($this->config[ $key ]))
unset($this->config[ $key ]);
}
public function isSetKey($key)
{
return isset($this->config[ $key ]);
}
public function getConfig()
{
return $this->config;
}
public function setConfig($value)
{
$this->config = $value;
}
}
class Website extends Errors
{
public $visitor;
public $SQL;
public $serverConfig;
public $websiteConfig;
public static $loadedSessionDataURL;
const PASSCRYPT_PLAIN = 0;
const PASSCRYPT_MD5 = 1;
const PASSCRYPT_SHA1 = 2;
const PASSCRYPT_SHA256 = 3;
const PASSCRYPT_SHA512 = 4;
const PASSCRYPT_VAHASH = 5;
public static $passwordsEncryptions = array(
'plain' => self::PASSCRYPT_PLAIN,
'md5' => self::PASSCRYPT_MD5,
'sha1' => self::PASSCRYPT_SHA1,
'sha256' => self::PASSCRYPT_SHA256,
'sha512' => self::PASSCRYPT_SHA512,
'vahash' => self::PASSCRYPT_VAHASH
);
private $passwordsEncryption;
function __construct($DBDriver = NULL)
{
if(isset($DBDriver))
$this->setDatabaseDriver($DBDriver);
}
public function setDatabaseDriver($value)
{
unset($this->SQL);
switch($value)
{
case Database::DB_MYSQL:
$this->SQL = new Database_MySQL();
break;
case Database::DB_SQLITE:
$this->SQL = new Database_SQLite();
break;
}
}
public function getDBHandle()
{
if(isset($this->SQL) && is_object($this->SQL))
return $this->SQL;
else
new Error_Critic('#C-9', 'ERROR: <b>#C-9</b> : Class::Website - getDBHandle(), database driver not set.');
}
public static function getInstance()
{
static $instance;
if(!isset($instance))
$instance = new self();
return $instance;
}
public function getVisitor()
{
if(!isset($this->visitor))
$this->visitor = new Visitor();
return $this->visitor;
}
public function loadWebsiteConfig()
{
if(file_exists('./config/serialized/config.php'))
{
try
{
$this->websiteConfig = unserialize(file_get_contents('./config/serialized/config.php'));
}
catch(Error $e)
{
$this->addError('#C-8', 'Website configuration unserialization failed <b>./config/serialized/config.php</b>');
}
}
else
{
$this->websiteConfig = new ConfigPHP('./config/config.php');
$this->addErrors($this->websiteConfig->getErrorsList(Errors::TYPE_ERROR));
$this->addErrors($this->websiteConfig->getErrorsList(Errors::TYPE_NOTICE));
}
}
public function getWebsiteConfig()
{
return $this->websiteConfig;
}
public function loadServerConfig()
{
if($this->getWebsiteConfig()->getValue('useServerConfigCache'))
{
if(file_exists('./config/serialized/config.server.php'))
{
try
{
$this->serverConfig = unserialize(file_get_contents('./config/serialized/config.server.php'));
}
catch(Error $e)
{
$this->addError('#C-9', 'Server configuration cache unserialization failed <b>./config/serialized/config.server.php</b>');
}
}
else
{
$this->serverConfig = new ConfigPHP('./config/config.server.php');
$this->addErrors($this->serverConfig->getErrorsList(Errors::TYPE_ERROR));
$this->addNotices($this->serverConfig->getErrorsList(Errors::TYPE_NOTICE));
}
}
else
{
$this->serverConfig = new ConfigLUA(self::getWebsiteConfig()->getValue('serverPath') . 'config.lua');
$this->addErrors($this->serverConfig->getErrorsList(Errors::TYPE_ERROR));
$this->addNotices($this->serverConfig->getErrorsList(Errors::TYPE_NOTICE));
}
}
public function getServerConfig()
{
return $this->serverConfig;
}
public function setPasswordsEncryption($encryption)
{
if(isset($this->passwordsEncryptions[strtolower($encryption)]))
$this->passwordsEncryption = $this->passwordsEncryptions[strtolower($encryption)];
else
throw new Exception('Invalid passwords encryption ( ' . htmlspecialchars($encryption) . '). Must be one of these: plain, md5, sha1');
}
public function getPasswordsEncryption()
{
return $this->passwordsEncryption;
}
public function validatePasswordsEncryption($encryption)
{
if(isset($this->passwordsEncryptions[strtolower($encryption)]))
return true;
else
return false;
}
public function encryptPassword($password)
{
if($this->getPasswordsEncryption() == PASSCRYPT_MD5)
return md5($password);
elseif($this->getPasswordsEncryption() == PASSCRYPT_SHA1)
return sha1($password);
elseif($this->getPasswordsEncryption() == PASSCRYPT_SHA256)
return hash("sha256", $password);
elseif($this->getPasswordsEncryption() == PASSCRYPT_SHA512)
return hash("sha512", $password);
elseif($this->getPasswordsEncryption() == PASSCRYPT_VAHASH)
return hash("vahash", $password);
else
return $password;
}
public function saveSessionData()
{
$get = explode('?',$GLOBALS['_SERVER']['REQUEST_URI']);
$data = array('post' => $GLOBALS['_POST'], 'get' => $GLOBALS['_GET'], 'url' => 'http://' . $GLOBALS['_SERVER']['SERVER_NAME'] . $get[0]);
$random_number = rand();
while(isset($_SESSION[$random_number]))
$random_number = rand();
$GLOBALS['_SESSION']['sessionData_' . $random_number] = serialize($data);
return $random_number;
}
public function loadSessionData($id)
{
if(isset(self::$loadedSessionDataURL))
return self::$loadedSessionDataURL;
if(!isset($GLOBALS['_SESSION']['sessionData_' . $id]))
{
$this->addError('#C-10', 'text');
return false;
}
$data = unserialize($GLOBALS['_SESSION']['sessionData_' . $id]);
unset($GLOBALS['_SESSION']['sessionData_' . $id]);
if(is_array($data))
{
foreach($data['post'] as $key => $value)
$GLOBALS['_POST'][$key] = $value;
foreach($data['get'] as $key => $value)
$GLOBALS['_GET'][$key] = $value;
self::$loadedSessionDataURL = $data['url'];
return self::$loadedSessionDataURL;
}
else
return false;
}
public function getSessionDataURL()
{
if(isset(self::$loadedSessionDataURL))
return self::$loadedSessionDataURL;
else
{
$this->addError('#C-11', 'text');
return false;
}
}
}
$timeStart = microtime(true);
//START START START START START START START START START START START START START
$WEB = Website::getInstance();
// CONFIG
$WEB->loadWebsiteConfig();
if($WEB->getErrorsCount() > 0)
new Error_Critic('#E-1', 'Errors while loading website config', $WEB->getErrorsList());
$configSite = $WEB->getWebsiteConfig();
$WEB->loadServerConfig();
if($WEB->getErrorsCount() > 0)
new Error_Critic('#E-2', 'Errors while loading server config', $WEB->getErrorsList());
$configServer = $WEB->getServerConfig();
// CONFIG - END
// DATABASE
if($configServer->isSetKey('mysqlHost'))
{
define('SERVERCONFIG_SQL_TYPE', 'sqlType');
define('SERVERCONFIG_SQL_HOST', 'mysqlHost');
define('SERVERCONFIG_SQL_PORT', 'mysqlPort');
define('SERVERCONFIG_SQL_USER', 'mysqlUser');
define('SERVERCONFIG_SQL_PASS', 'mysqlPass');
define('SERVERCONFIG_SQL_DATABASE', 'mysqlDatabase');
define('SERVERCONFIG_SQLITE_FILE', 'sqlFile');
}
elseif($configServer->isSetKey('sqlHost'))
{
define('SERVERCONFIG_SQL_TYPE', 'sqlType');
define('SERVERCONFIG_SQL_HOST', 'sqlHost');
define('SERVERCONFIG_SQL_PORT', 'sqlPort');
define('SERVERCONFIG_SQL_USER', 'sqlUser');
define('SERVERCONFIG_SQL_PASS', 'sqlPass');
define('SERVERCONFIG_SQL_DATABASE', 'sqlDatabase');
define('SERVERCONFIG_SQLITE_FILE', 'sqlFile');
}
else
new Error_Critic('#E-3', 'There is no key <b>sqlHost</b> or <b>mysqlHost</b> in server config', array(new Error('INFO', 'use server config cache: <b>' . ($configServer->getValue('useServerConfigCache') ? 'true' : 'false') . '</b>')));
if($configServer->getValue(SERVERCONFIG_SQL_TYPE) == 'mysql')
{
$WEB->setDatabaseDriver(Database::DB_MYSQL);
if($configServer->isSetKey(SERVERCONFIG_SQL_HOST))
$WEB->getDBHandle()->setDatabaseHost($configServer->getValue(SERVERCONFIG_SQL_HOST));
else
new Error_Critic('#E-7', 'There is no key <b>' . SERVERCONFIG_SQL_HOST . '</b> in server config file.');
if($configServer->isSetKey(SERVERCONFIG_SQL_PORT))
$WEB->getDBHandle()->setDatabasePort($configServer->getValue(SERVERCONFIG_SQL_PORT));
else
new Error_Critic('#E-7', 'There is no key <b>' . SERVERCONFIG_SQL_PORT . '</b> in server config file.');
if($configServer->isSetKey(SERVERCONFIG_SQL_DATABASE))
$WEB->getDBHandle()->setDatabaseName($configServer->getValue(SERVERCONFIG_SQL_DATABASE));
else
new Error_Critic('#E-7', 'There is no key <b>' . SERVERCONFIG_SQL_DATABASE . '</b> in server config file.');
if($configServer->isSetKey(SERVERCONFIG_SQL_USER))
$WEB->getDBHandle()->setDatabaseUsername($configServer->getValue(SERVERCONFIG_SQL_USER));
else
new Error_Critic('#E-7', 'There is no key <b>' . SERVERCONFIG_SQL_USER . '</b> in server config file.');
if($configServer->isSetKey(SERVERCONFIG_SQL_PASS))
$WEB->getDBHandle()->setDatabasePassword($configServer->getValue(SERVERCONFIG_SQL_PASS));
else
new Error_Critic('#E-7', 'There is no key <b>' . SERVERCONFIG_SQL_PASS . '</b> in server config file.');
}
elseif($configServer->getValue(SERVERCONFIG_SQL_TYPE) == 'sqlite')
{
$WEB->setDatabaseDriver(Database::DB_SQLITE);
if($configServer->isSetKey(SERVERCONFIG_SQLITE_FILE))
$WEB->getDBHandle()->setDatabaseFile($configServer->getValue(SERVERCONFIG_SQLITE_FILE));
else
new Error_Critic('#E-7', 'There is no key <b>' . SERVERCONFIG_SQLITE_FILE . '</b> in server config file.');
}
else
new Error_Critic('#E-6', 'Database error. Unknown database type in <b>' . $configSite->getValue('serverPath') . 'config.lua</b> . Must be equal to: "<b>mysql</b>" or "<b>sqlite</b>". Now is: "<b>' . $configServer->getValue(SERVERCONFIG_SQL_TYPE) . '</b>"');
$SQL = Website::getInstance()->getDBHandle();
// DATABASE END
//print_r($SQL->query('SELECT SHA1(1)')->fetchAll());
// LOAD SESSION DATA
if(isset($_REQUEST['loadSessionData']))
$WEB->loadSessionData($_REQUEST['loadSessionData']);
// LOAD SESSION DATA END
// LOGIN
$visitor = Website::getInstance()->getVisitor();
if(isset($_SESSION['account']))
$visitor->setLoginAccount($_SESSION['account']);
if(isset($_SESSION['password']))
$visitor->setLoginPassword($_SESSION['password']);
// LOGIN END
exit;
echo '<br>' . (microtime(true) - $timeStart) . '<br>';
echo '<br>' . (microtime(true) - $timeStart) . '<br>';
?>