Файл: system/sys.php
Строк: 284
<?
//error_reporting(0);
define ('DBHOST', 'localhost');
define ('DBPORT', '3306');
define ('DBNAME', 'sql1');
define ('DBUSER', 'root');
define ('DBPASS', '');
class PDO_ extends PDO {
function __construct($dsn, $username, $password){
parent :: __construct($dsn, $username, $password);
$this -> setAttribute(PDO :: ATTR_ERRMODE, PDO :: ERRMODE_EXCEPTION);
$this -> setAttribute(PDO :: ATTR_DEFAULT_FETCH_MODE, PDO :: FETCH_ASSOC);
}
function prepare($sql) {
$stmt = parent :: prepare($sql, array(
PDO :: ATTR_STATEMENT_CLASS => array('PDOStatement_')
));
return $stmt;
}
function query($sql, $params = array()) {
$stmt = $this -> prepare($sql);
$stmt -> execute($params);
return $stmt;
}
function querySingle($sql, $params = array()) {
$stmt = $this -> query($sql, $params);
$stmt -> execute($params);
return $stmt -> fetchColumn(0);
}
function queryFetch($sql, $params = array()) {
$stmt = $this -> query($sql, $params);
$stmt -> execute($params);
return $stmt -> fetch();
}
}
class PDOStatement_ extends PDOStatement {
function execute($params = array()) {
if (func_num_args() == 1) {
$params = func_get_arg(0);
} else {
$params = func_get_args();
}
if (!is_array($params)) {
$params = array($params);
}
parent :: execute($params);
return $this;
}
function fetchSingle() {
return $this -> fetchColumn(0);
}
function fetchAssoc() {
$this -> setFetchMode(PDO :: FETCH_NUM);
$data = array();
while ($row = $this -> fetch()) {
$data[$row[0]] = $row[1];
}
return $data;
}
}
class DB {
static $dbs;
public function __construct() {
try {
self :: $dbs = new PDO_('mysql:host=' . DBHOST . ';port=' . DBPORT . ';dbname=' . DBNAME, DBUSER, DBPASS);
self :: $dbs -> exec('SET CHARACTER SET utf8');
self :: $dbs -> exec('SET NAMES utf8');
}
catch (PDOException $e) {
die('Connection failed: ' . $e -> getMessage());
}
}
}
$array = explode(" ",microtime());
$gen = $array[1] + $array[0];
$db = new DB();
DB::$dbs->query("SET NAMES utf8");
class cms {
var $us;
}
function links_preg1($arr){
global $set;
if(ereg('^http://'.$_SERVER['HTTP_HOST'],$arr[1])){
return '<a href="'.$arr[1].'">'.$arr[2].'</a>';
}else{
return '<a href="'.$arr[1].'">'.$arr[2].'</a>';
}
}
function links_preg2($arr){
global $set;
if(ereg('^http://'.$_SERVER['HTTP_HOST'],$arr[2])){
return $arr[1].'<a href="'.$arr[2].'">'.$arr[2].'</a>'.$arr[4];
}else{
return $arr[1].'<a href="'.$arr[2].'">'.$arr[2].'</a>'.$arr[4];
}
}
function br($msg,$br='<br />')
{
$msg=preg_replace("((<br( ?/?)>)|n|r)",$br, $msg);
return $msg;
}
function bb($msg)
{
$bbcode = array(
'/[url](.+)[/url]/isU'=>'<a href="$1">$1</a>',
'/[url=(.+)](.+)[/url]/isU'=>'<a href="$1">$2</a>',
'/[i](.+)[/i]/isU' => '<em>$1</em>',
'/[b](.+)[/b]/isU' => '<strong>$1</strong>',
'/[u](.+)[/u]/isU' => '<span style="text-decoration:underline;">$1</span>',
'/[big](.+)[/big]/isU' => '<span style="font-size:large;">$1</span>',
'/[small](.+)[/small]/isU' => '<span style="font-size:xx-small;">$1</span>',
'/[code](.+)[/code]/isU' => '<code>$1</code>',
'/[red](.+)[/red]/isU' => '<span style="color:#ff0000;">$1</span>',
'/[green](.+)[/green]/isU' => '<span style="color:#00bb00;">$1</span>',
'/[blue](.+)[/blue]/isU' => '<span style="color:#0000bb;">$1</span>',
'/[white](.+)[/white]/isU' => '<span style="color:#ffffff;">$1</span>',
);
$msg= preg_replace(array_keys($bbcode), array_values($bbcode), $msg);
$msg=preg_replace('#[code](.*?)[/code]#si', '1', $msg);
$msg=str_replace('[br]','<br/>',$msg);
return $msg;
}
function smiles($text){
$smiles = DB::$dbs->query("SELECT * FROM `smile`");
while($smile = $smiles->fetch()){
$text=str_replace($smile['name'],'<img src="/design/smiles/'.$smile['img'].'" alt="'.$smile['name'].'"/>',$text);
}
return $text;
}
function links($msg){
$msg=preg_replace_callback('~[url=([a-z]+://[^ rnt`'"]+)](.*?)[/url]~iu', 'links_preg1', $msg);
$msg=preg_replace_callback('~(^|s)([a-z]+://([^ rnt`'"]+))(s|$)~iu', 'links_preg2', $msg);
return $msg;
}
function secure($mess){
$mess=htmlspecialchars(trim($mess));
return $mess;
}
if(DB::$dbs->querySingle("SELECT count(id) FROM `us` where `id` = ?",array(intval($_COOKIE['username'])))==1){
$password = secure($_COOKIE['password']);
$cms->us = DB::$dbs->queryFetch("SELECT * FROM `us` where `id` = ? and `pass` = ? limit 1",array(intval($_COOKIE['username']),$password));
if($cms->us['pass']==$password && $cms->us['id'] == intval($_COOKIE['username'])){
DB::$dbs->query("UPDATE `us` SET `last` = ?, `ip`=?, `soft` = ?, `online`=`online`+? WHERE `id` = ? limit 1",array(time(),$_SERVER['REMOTE_ADDR'],$_SERVER['HTTP_USER_AGENT'],(time()-$cms->us['last']),$cms->us['id']));
}
}
function slv($str,$msg1,$msg2,$msg3) {
$str = (int)$str;
$str1 = abs($str) % 100;
$str2 = $str % 10;
if ($str1 > 10 && $str1 < 20) return $str .' '. $msg3;
if ($str2 > 1 && $str2 < 5) return $str .' '. $msg2;
if ($str2 == 1) return $str .' '. $msg1;
return $str .' '. $msg3;
}
function t($times=NULL){
global $db;
$time = time();
if(($time-$times)<=60){
$timesp = slv((($time-$times)),'секунду','секунды','секунд').' назад';
return $timesp;
}else if(($time-$times)<=3600){$timesp = slv((($time-$times)/60),'минуту','минуты','минут').' назад';
return $timesp;
}else{
$today = date("j M Y", $time);
$today = date("j M Y", $time);
$yesterday = date("j M Y", strtotime("-1 day"));
$timesp=date("j M Y в H:i", $times);
$timesp = str_replace($today, 'Сегодня', $timesp);
$timesp = str_replace($yesterday, 'Вчера', $timesp);
$timesp = strtr($timesp, array ("Jan" => "Янв","Feb" => "Фев","Mar" => "Марта","May" => "Мая","Apr" => "Апр","Jun" => "Июня","Jul" => "Июля","Aug" => "Авг","Sep" => "Сент","Oct" => "Окт","Nov" => "Ноября","Dec" => "Дек",));
return $timesp;}
}
function times($time){
$d = floor($time/86400);
$h = floor(($time/3600)-($d*24));
$m = floor(($time-($h*3600)-($d*86400))/60);
$s = floor($time-(($m*60)+($h*3600)+($d*86400)));
return (($d > 0) ? slv($d,'день','дня','дней'):NULL).($d > 0 && $h > 0 ? ", ":NULL).(($h > 0)? slv($h,'час','часа','часов'):NULL).($h > 0 && $m > 0 || $d > 0 && $m > 0 ? ", ":NULL).(($m > 0) ? slv($m,'минуту','минуты','минут'):NULL).($m < 1 ? ($m > 0 && $s > 0 ? ", ":($h > 0 && $s > 0 ? ', ':($d > 0 && $s > 0 ? ', ':NULL))).(($s > 0) ? slv($s,'секунду','секунды','секунд'):NULL):NULL);
}
ini_set('magic_quotes_gpc', 0);
ini_set('magic_quotes_runtime', 0);
function niz()
{
global $gen,$func;
$end_array = explode(" ",microtime());
$end_time = $end_array[1] + $end_array[0];
$last = DB::$dbs->queryFetch("select `id` from `us` order by `reg` desc limit 1");
echo ($_SERVER['PHP_SELF']=='/index.php' ? NULL:'<div class="navg"> <img src="/images/homepage.gif" alt=""/> <a href="/">На главную</a></div>').'</div><div class="blk"><span style="color: #fff;">Онлайн: <a href="/online.php" style="color:white;">'.DB::$dbs->querySingle("SELECT count(`id`) from `us` where `last`>?",array(time()-3600)).'</a> из <a href="/masters.php" style="color:white;">'.DB::$dbs->querySingle("SELECT count(id) from `us`").'</a></span><br /> <span style="color: #fff;">Последний: '.$func->uNick($last['id']).'<br/>Ген. '.substr($end_time - $gen,0,6).' сек.</span></body></html>';
ob_end_flush();
}
function verh($page,$menu=null){
global $cms,$func;
ob_start();
$reg = DB::$dbs->queryFetch("select * from `reg` where `us`=? limit 1",array($cms->us['id']));
if($reg['id']) if($reg['ok'] == '0' or $reg['ok'] == '2') $page = 'Одобрение регистрации';
if(isSet($cms->us['id'])) $style = DB::$dbs->queryFetch("SELECT * from `styles` where `id` = ?",array($cms->us['style']));
$style = (isSet($cms->us['id']) ? ($style['id'] ? $style['css'].'|'.$style['logo']:'med/style.css|/med/logo.gif'):'med/style.css|/med/logo.gif');
$s = explode("|",$style);
echo'<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ru"><head><meta http-equiv="Content-Type" content="application/vnd.wap.xhtml+xml; charset=UTF-8" />
<meta name="name" content="ProfiWM.RU" />
<meta name="description" content="Помощь wap-мастерам" />
<meta name="keywords" content="WAP-мастер,скрипты,шаблоны" />
<meta name="author" content="3KZO" />
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
<link rel="stylesheet" href="http://'.$_SERVER['HTTP_HOST'].'/'.$s[0].'" type="text/css"/>
<link rel="stylesheet" href="/styles/ef.css" type="text/css"/>
<title>'.$page.'</title></head>';
if($cms->us['id'] && $_SERVER['REMOTE_ADDR']!=$cms->us['ip']){
echo '<div class="menu">Внимание!</div>
<div class="list1">Ваш IP-адрес изменился!</div>
<div class="lst">Предыдущая сессия: <b>'.$cms->us['ip'].'</b><br/>
Обновлённая сессия: <b>'.$_SERVER['REMOTE_ADDR'].'</b></div>';
}
# Гости
if(!$cms->us['id']){
if(DB::$dbs->querySingle("SELECT count(id) from `guest` where `ip`=?",array($_SERVER['REMOTE_ADDR']))==0){
DB::$dbs->query('insert into `guest` (`ip`,`ua`,`time`) values (?,?,?)',array($_SERVER['REMOTE_ADDR'],$_SERVER['HTTP_USER_AGENT'],time()));
}else{
DB::$dbs->query('update `guest` set `ua`=?,`time`=? where `ip`=?',array($_SERVER['HTTP_USER_AGENT'],time(),$_SERVER['REMOTE_ADDR']));
}
}
$_SERVER['PHP_SELF'] = strtolower($_SERVER['PHP_SELF']);
if($_SERVER['PHP_SELF']=='/index.php') echo '<div class="verx"><a href="/"><img src="http://'.$_SERVER['HTTP_HOST'].'/'.$s[1].'" alt="*"/></a></div>';
# Меню
if($menu) echo '<div class="menu">'.$menu.'</div>';
if($cms->us['id'] && $cms->us['panel']==1 && strpos($_SERVER['PHP_SELF'],"kab") == false && strpos($_SERVER['PHP_SELF'],"mail") == false && strpos($_SERVER['PHP_SELF'],"msg") == false && strpos($_SERVER['PHP_SELF'],"action") == false or $_SERVER['PHP_SELF']=='/index.php'){
echo '<div class="razd1">';
$rekls=DB::$dbs->query('select * from `rekl` where (`end`>?) order by RAND() LIMIT 3',array(time()));
while($rekl=$rekls->fetch()){
echo '<img src="/med/img/r.png" alt="*"/> <a href="http://'.$rekl['url'].'"'.($rekl['color']?' style="color:'.$rekl['color'].'"':NULL).'>'.($rekl['b']?'<b>':NULL).($rekl['u']?'<u>':NULL).$rekl['name'].($rekl['u']?'</u>':NULL).($rekl['b']?'</b>':NULL).'</a>';
}
echo '</div>';
}
if($cms->us['id']){
if(strpos($_SERVER['PHP_SELF'],"kab") == false && strpos($_SERVER['PHP_SELF'],"mail") == false && strpos($_SERVER['PHP_SELF'],"msg") == false && strpos($_SERVER['PHP_SELF'],"action") == false){
$na = DB::$dbs->querySingle("SELECT count(id) from `action` where `us` = ? and `see` = ?",array($cms->us['id'],1));
$nm = DB::$dbs->querySingle("SELECT count(id) from `msg` where `us` = ? and `see` = ?",array($cms->us['id'],1));
if($cms->us['panel']==1){
echo '<div class="rega" style="border-bottom:none;">
<table style="width:100%" cellspacing="0" cellpadding="0"><tbody><tr>
<td style="vertical-align:top;width:10%;"><center></a> <a href="/kab" title="Кабинет"><img class="ico" align="middle" src="/images/vcard.png" alt="*"></a></center>
</td><td style="vertical-align:top;width:10%;"><center><a href="/mail.php" title="Почта"><img class="ico" align="middle" src="/images/mail2.png" alt="*">'.($nm>0?' '.$nm:NULL).'</a></center></td>
<td style="vertical-align:top;width:10%;"><center><a href="/action.php" title="Оповещения"><img class="ico" align="middle" src="/images/warning.png" alt="*">'.($na>0?' '.$na:NULL).'</a></center></td>
<td style="vertical-align:top;width:10%;"><center><a href="/feeds.php" title="Новости"><img class="ico" align="middle" src="/images/rss2.png" alt="*"></a></center>
</td></tr></tbody></table></div>';
}else{
if($na > 0) echo '<div class="lst"><a href="/action.php">Оповещения</a> (+'.$na.')</div>';
if($nm > 0) echo '<div class="lst"><a href="/mail.php">Сообщения</a> (+'.$nm.')</div>';
}
}
}
$ban = DB::$dbs->queryFetch("select * from `ban` where `us`=? and `end` > ?limit 1",array($cms->us['id'],time()));
if($ban != 0 && $_SERVER['PHP_SELF'] != '/ban.php'){
header('location: /ban.php');
exit;
}
if($reg['id']){
if($reg['ok'] == '0' or $reg['ok'] == '2'){
if($reg['ok'] == '0') echo '<div class="menu2">Дождитесь одобрения вашей регистрации.</div>'; elseif($reg['ok'] == '2') echo '<div class="menu2">Вы небыли допущены на сайт.</div>';
niz(); exit;
}
}
}
?>