define DR _SERVER DOCUMENT_ROOT define SMARTY_DIR DR system Smarty req

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<?
define('DR', $_SERVER['DOCUMENT_ROOT']);
define('SMARTY_DIR', DR . '/system/Smarty/');
require_once SMARTY_DIR . 'Smarty.class.php';
class Engine {
private $mysqli, $config, $smarty, $ua = 'WAPPUS.RU Bot';
public function __construct(){
$this->config = parse_ini_file('settings.ini', true);
$this->mysqli = @new mysqli($this->config['MySQL']['HOST'], $this->config['MySQL']['USER'], $this->config['MySQL']['PASSWORD'], $this->config['MySQL']['DATABASE']);
if($this->mysqli->connect_errno)
die('Error connect to MySQL server. Try again later. ' . $this->mysqli->connect_error);
session_start();
$this->smarty = new Smarty();
$this->smarty->setTemplateDir(DR . '/style/templates/PDA/');
$this->smarty->setCompileDir(DR . '/style/templates/PDA/compile/');
$this->smarty->setCacheDir(DR . '/style/templates/PDA/cache/');
//$this->smarty->assign('request', microtime(true) - $_SERVER['REQUEST_TIME_FLOAT']);
$this->smarty->assign('keywords', $this->config['Site']['keywords']);
$this->smarty->assign('link', $this->config['Site']['link']);
$this->smarty->assign('mobtop', (!isset($_GET['razd']) && !isset($_GET['file']) && !isset($_GET['sogl']) ? '<script type="text/javascript" src="http://mobtop.ru/c/84414.js"></script><noscript><a href="http://mobtop.ru/in/84414"><img src="http://mobtop.ru/84414.gif" alt="MobTop.Ru - Рейтинг и статистика мобильных сайтов"/></a></noscript>' : '<script type="text/javascript" src="http://mobtop.ru/c/84415.js"></script><noscript><a href="http://mobtop.ru/in/84415"><img src="http://mobtop.ru/84415.gif" alt="MobTop.Ru - Рейтинг и статистика мобильных сайтов"/></a></noscript>'));
}
public function showGames(){
$vip = false;
if(isset($_GET['phone']) && preg_match('/^[0-9X]+$/', $_GET['phone']) && isset($_GET['key']) && preg_match('/^\d{6}$/', $_GET['key'])){
$q = $this->mysqli->query("SELECT COUNT(*) AS count FROM users WHERE phone = '$_GET[phone]' AND password = '$_GET[key]'");
$q = $q->fetch_assoc();
if($q['count'] > 0){
$_SESSION['phone'] = $_GET['phone'];
$_SESSION['password'] = $_GET['key'];
}
}
if(isset($_SESSION['phone']) && isset($_SESSION['password'])){
$this->smarty->assign('phone', $_SESSION['phone']);
$q = $this->mysqli->query("SELECT COUNT(*) AS count FROM users WHERE phone = '$_SESSION[phone]' AND password = '$_SESSION[password]'");
$q = $q->fetch_assoc();
if($q['count'] > 0){
$w = $this->mysqli->query("SELECT time FROM users WHERE phone = '$_SESSION[phone]'");
$w = $w->fetch_assoc();
$dostup = $w['time'] - time();
if($dostup > 0){
$vip = true;
$days = intval($dostup / 60 / 60 / 24);
$hours = intval(($dostup - ($days * 60 * 60 * 24)) / 60 / 60);
$minutes = intval(($dostup - ($days * 60 * 60 * 24) - ($hours * 60 * 60))/60);
$seconds = intval($dostup - ($days * 60 * 60 * 24) - ($hours * 60 * 60) - ($minutes * 60));
$str = ($days > 0 ? $days.' дней ' : '').($hours > 0 ? $hours.' часов ' : '').($minutes > 0 ? $minutes.' минут ' : '').$seconds.' секунд';
$this->smarty->assign('dostup', $str);
}
}else
session_unset();
}
$this->smarty->assign('vip', $vip);
if(!isset($_GET['sogl'])){
if(isset($_GET['download']) && intval($_GET['download']) > 0 && !isset($_GET['razd']) && !isset($_GET['file'])){
if($vip){
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_USERAGENT => $this->ua,
CURLOPT_HEADER => true,
CURLOPT_RETURNTRANSFER => true
));
curl_setopt($ch, CURLOPT_URL, 'http://android.zaycu.ru/download.php?id='.$_GET['download']);
$res = curl_exec($ch);
preg_match("/Location\:\s(.*?)\n/", $res, $loc);
header('Location: '.$loc[1]);
}else
header('Location: '.$this->config['Site']['link']);
}else{
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_USERAGENT => $this->ua,
CURLOPT_RETURNTRANSFER => true
));
curl_setopt($ch, CURLOPT_URL, 'http://android.zaycu.ru/'.(isset($_GET['razd']) && intval($_GET['razd']) > 0 ? intval($_GET['razd']).'/' : (isset($_GET['file']) && intval($_GET['file']) > 0 ? 'file/'.intval($_GET['file']).'/' : '')).(isset($_GET['page']) && intval($_GET['page']) > 0 ? '?p='.intval($_GET['page']) : ''));
$res = curl_exec($ch);
$res = preg_replace('/<\?xml.*?<div class="main">\s+/i', '', $res);
$res = preg_replace('/<b>Сортировка(.*?)<br\/>\s+/', '', $res);
preg_match('/^<b>(.*?)<\/b>/', $res, $razd);
$razd = preg_replace('/\:$/', '', $razd[1]);
$res = preg_replace('/<\/div> <div class="t">(.*?)$/', '', $res);
$res = preg_replace('/<img src=\'http\:\/\/zaycu\.ru\/img\/za\.gif\'( alt="")?\/><a href="http\:\/\/zaycu\.ru">Главная<\/a>(\s+)?&raquo; /', '', $res);
$res = str_replace('<div class="navigation">Android </div>', '', $res);
$res = preg_replace('/^(.*?)Поиск<\/a><br\/>/', '', $res);
$res = preg_replace('/\s+<br\/>\s+<br\/>\s+$/', '', $res);
$res = preg_replace('/(\s+)?(<br\/>)?<img src =\'http\:\/\/zaycu\.ru\/img\/dir\.gif\' alt="" \/>/', '', $res);
$res = preg_replace('/<span style="color\: (.*?);">\+\d+<\/span>/', '', $res);
$res = preg_replace('/<a href="\/(\d+)\/"> (.*?)<\/a> <b>\((\d+)\)<\/b>/', "<a href=\"/?razd=$1\" class=\"li\"><img src=\"/style/templates/PDA/images/icon.png\" alt=\"\"/> $2<span class=\"number\">$3</span></a>\n", $res);
$res = str_replace(' <br/> <br/> <div', '<div', $res);
$res = str_replace('<div class="navigation">', '<div class="menu">', $res);
$res = preg_replace('/<a href="\/(\d+)\/">/', '<a href="/?razd=$1">', $res);
$res = preg_replace('/^<b>(.*?)<\/b><br\/>(<br\/>)?\s+/', '', $res);
$res = str_replace('<img src=\'http://zaycu.ru/img/zv.gif\' class="ic" alt="" />', '', $res);
$res = preg_replace('/<a href="\/file\/(\d+)\/"> (.*?)<\/a> <b>\((\d+)\)<\/b><br\/>(\s+)?/', "<a href=\"/?file=$1\" class=\"li\"><img src=\"/style/templates/PDA/images/icon.png\" alt=\"\"/> $2 <span class=\"number\">$3</span></a>\n", $res);
$res = preg_replace('/<form(.*?)<\/form>/', '', $res);
$res = str_replace('<br/> <div class="smarty_pages">', '<div class="menu">', $res);
$res = preg_replace('/<span class="current_page">(\d+)<\/span>/', '$1', $res);
$res = str_replace(' class="paginator_link"', '', $res);
$res = preg_replace('/<span>(.*?)<\/span>/', '$1', $res);
$res = str_replace(' <br/> ', '', $res);
$res = preg_replace('/<a href="\/(\d+)\/name\/\?p=(\d+)">/', '<a href="/?razd=$1&page=$2">', $res);
$res = preg_replace('/<br\/><br\/> <br\/><br\/> <img src=\'http\:\/\/zaycu\.ru\/img\/s\.gif\'\/>(.*?)$/', '<br/><br/><center><a href="/?download='.intval(@$_GET['file']).'"><img src="/style/templates/PDA/images/dl.png" /></a></center></div>', $res);
$res = preg_replace('/<a href="\/comments(.*?)<\/a><br\/>/', '', $res);
$res = preg_replace('/^<img/', '<div class="news"><img', $res);
$res = preg_replace('/<div class="news">(.*?)<br\/>/', '<div class="news"><center>$1</center><br/>', $res);
$res = preg_replace('/<a href="\/vendor\/(.*?)\/">(.*?)<\/a>/', '$2', $res);
$this->smarty->assign('content', $res);
$this->smarty->assign('title', 'WAPPUS.RU / '.$razd);
$this->smarty->assign('razd', $razd);
}
}else{
$this->smarty->assign('title', 'WAPPUS.RU / Соглашение');
$this->smarty->assign('razd', 'Соглашение');
$this->smarty->assign('sogl', true);
}
$this->smarty->display('index.tpl');
}
public function addUser($phone, $num){
if($num == '1212')
$days = 5;
else
$days = 3;
$q = $this->mysqli->query("SELECT COUNT(*) AS count FROM users WHERE phone = '$phone'");
$q = $q->fetch_assoc();
if($q['count'] > 0){
$w = $this->mysqli->query("SELECT time FROM users WHERE phone = '$phone'");
$w = $w->fetch_assoc();
$e = $w['time'] - time();
$sec = $days * 24 * 60 * 60;
$sec2 = time() + $days * 24 * 60 * 60;
if($e > 0)
$this->mysqli->query("UPDATE users SET time = time + $sec WHERE phone = '$phone'");
else
$this->mysqli->query("UPDATE users SET time = $sec2 WHERE phone = '$phone'");
$r = $this->mysqli->query("SELECT password FROM users WHERE phone = '$phone'");
$r = $r->fetch_assoc();
return 'Доступ продлён на '.$days.' дней. Ссылка для входа: http://wappus.ru/?phone='.$phone.'&key='.$r['password'];
}else{
$pass = $this->randomCode(6);
$sec = time() + $days * 24 * 60 * 60;
$this->mysqli->query("INSERT INTO users (phone, password, time) VALUES ('$phone', '$pass', '$sec')");
return 'Активирован доступ на '.$days.' дней! Ссылка для входа: http://wappus.ru/?phone='.$phone.'&key='.$pass;
}
}
public function randomCode($count){
$code = '';
for($i = 0; $i < $count; $i++)
$code .= rand(0,9);
return $code;
}
public function __destruct(){
if($this->mysqli)
@$this->mysqli->close();
}
}
?>