Файл: sys/functions.php
Строк: 388
<?php
Class Core{
public function url_get_contents($Url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $Url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_REFERER, 'http://vk.com/');
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2 GTB5');
$output = curl_exec($ch);
curl_close($ch);
return $output;
//return file_get_contents($url);
}
public function MysqlConnect($a){
mysql_connect($a['hostname'],$a['username'],$a['password']) OR DIE("Не могу создать соединение ");
mysql_select_db($a['dbname']) or die(mysql_error());
mysql_query("SET NAMES utf8");
}
public function LoadModule($orr){
return "<?php include('./modules/$orr/index.php');?>";
}
public function LoadPlugin($orr){
return "<?php include('./plugins/$orr/index.php');?>";
}
public function GetUser($uid){
$uid = mysql_real_escape_string($uid);
$query = 'SELECT `id`,`login`,`name`,`lastname`,`email`,`bday`,`bmonth`,`byear`,`confirm`,`balance`,`money`,`photo`,`social:vk` FROM `users` WHERE `id` = ''.$uid.''';
$query = mysql_query($query);
while ($row = mysql_fetch_array($query, MYSQL_ASSOC)) {
$out[] = $row;
}
$userdata = $out[0];
if(is_array($userdata)){
return $userdata;
} else {
return array('id'=>'0');
}
}
//Далее идут функции работы с бд
public function MysqlSelect($table,$rows='*',$where=0,$other=0){
$query = 'SELECT '.$rows.' FROM `'.$table.'`';
if(is_array($where)){
$query .= ' WHERE ';
foreach($where as $w=>$z){
$query .= '`'.$w.'`=''.$z.'' AND ';
}
$query = substr($query,0,-5);
}
if($other){
$query .= ' '.$other;
}
//echo $query;
$query = mysql_query($query);
while ($row = mysql_fetch_array($query, MYSQL_ASSOC)) {
$out[] = $row;
}
return $out;
}
//Конец функций работы с БД
}
Class Templater{
public $Module = 0;
public $tmpl = 0;
public function Exec(){
$orr = $this->ucodes($this->tmpl);
//print_r($orr);
$orr = $this->ob_eval($orr);
echo $orr;
}
public function ucodes($u){
extract($GLOBALS, EXTR_REFS);
foreach($this->vars as $b=>$c){
$u = str_replace('{'.$b.'}',$c,$u);
}
foreach($CONFIG['Globals'] as $b=>$c){
$u = str_replace('{'.$b.'}',$c,$u);
}
if($this->ModuleData){
include('./modules/'.$this->ModuleData.'/module.php');
foreach($Module as $b=>$c){
$u = str_replace('{'.$b.'}',$c,$u);
}
}
$u = preg_replace('#{{if((.+))}}#isU','<?if(\1):?>',$u);
$u = preg_replace('#{{elseif((.+))}}#isU','<?elseif(\1):?>',$u);
$u = str_replace('{{else}}','<?else:?>',$u);
$u = str_replace('{{endif}}','<?endif;?>',$u);
$u = preg_replace('#{{foreach((.+))}}#isU','<?foreach(\1):?>',$u);
$u = str_replace('{{endforeach}}','<?endforeach;?>',$u);
$u = preg_replace('#{{echo((.+))}}#isU','<?echo(\1);?>',$u);
$u = preg_replace('#{{set((.+),(.+))}}#isU','<?$SET[\1] = \2;?>',$u);
//echo '<div style="display:none;">';
//print_r($u);
//echo '</div>';
return $u;
}
private function ob_eval($orr){
ob_start();
extract($GLOBALS, EXTR_REFS);
eval('?>'.$orr.'<?');
$content = ob_get_clean();
return $content;
}
public function GetTmpl($a){
if($this->Module){
$this->tmpl = file_get_contents('./modules/'.$this->Module.'/tmpls/'.$a.'.html');
} else {
$this->tmpl = file_get_contents('./tmpls/'.$a.'.html');
}
}
}
Class Ajax{
public function Exec(){
if(file_exists('./modules/'.$this->Module.'/ajax.php')){
extract($GLOBALS, EXTR_REFS);
include('./modules/'.$this->Module.'/ajax.php');
}
}
public function Responce($a){
echo json_encode(array('responce'=>$a));
}
public function Error($a){
echo json_encode(array('error'=>$a));
}
}
Class Confirm{
public function GenKey($login,$type='register'){
return md5($login.$CONFIG['salt'].$type);
}
public function SendMail($mail,$login,$name){
$subject = 'Подтверждение email';
$key = $this->GenKey($login);
$message = '
<html>
<head>
<title>SeoMaxVip</title>
</head>
<body>
<p>Здравствуйте, {name}. Вам нужно подтвердить свою регистрацию на SeoMaxVip <br />
<a href="http://seomaxvip.ru/ajax/profile/confirm?login={login}&key={key}">Подтвердить</a></p>
<p><br />Если кнопка "Подтвердить" не работает, скопируйте следующую ссылку и откройте в своём браузере: http://seomaxvip.ru/ajax/profile/confirm?login={login}&key={key}</p>
</body>
</html>
';
$message = str_replace('{key}',$key,$message);
$message = str_replace('{name}',$name,$message);
$message = str_replace('{login}',$login,$message);
$m= new Mail("utf-8"); // начинаем
$m->From( "onlinesentr@mail.ru" ); // от кого отправляется почта
$m->To( $mail ); // кому адресованно
$m->Subject( "Подтверждение регистрации" );
$m->Body( $message , "html" );
$m->Send(); // а теперь пошла отправка
}
}
Class Tasks{
public function ChangeBal($id,$bal){
if(is_numeric($bal)){
mysql_query("UPDATE `tasks` SET `bal` = '$bal' WHERE `id` = '$id';");
} else {
return false;
}
}
public function GetMine(){
extract($GLOBALS, EXTR_REFS);
return Core::MysqlSelect('tasks','`id`,`social`,`type`,`url`,`uid`,`pay`,`bal`',array('uid'=>$CONFIG['uid']),'ORDER BY `date` DESC');
}
public function GetAll($page=false,$social=false,$type=false){
extract($GLOBALS, EXTR_REFS);
$social = mysql_real_escape_string($social);
$type = explode(',',$type);
foreach($type as $t){
$t = mysql_real_escape_string($t);
if($t && $t!='') $tp .= ",'$t'";
}
$tp = substr($tp,1);
$ye = '';
if($social && $social!='') $ye .= "WHERE `bal`>'0' AND `social` = '$social' ";
if($tp) $ye .= 'AND `type` IN('.$tp.') ';
if(!$social && !$tp) $ye .= "WHERE `bal`>'0' ";
$ye .= ' ORDER BY `pay` DESC ';
if($page){
$query = "SELECT COUNT(*) FROM `tasks` ".$ye;
$res = mysql_query($query);
$count_records = mysql_fetch_row($res);
$count_records = $count_records[0];
$on_page = 8;
$num_pages = ceil($count_records / $on_page);
$next_page = 0;
if($num_pages>$page) $next_page = $page+1;
$start_from = ($page - 1) * $on_page;
$ye .= 'LIMIT '.$start_from.', '.$on_page;
}
//print_r($ye);
return array('responce'=>Core::MysqlSelect('tasks','`id`,`social`,`type`,`pay`,`bal`',null,$ye),'next_page'=>$next_page);
}
/*public function GetRand($social,$type){
extract($GLOBALS, EXTR_REFS);
$social = mysql_real_escape_string($social);
$type = mysql_real_escape_string($type);
$Done = Core::MysqlSelect('done',array('uid'=>$CONFIG['uid']));
foreach($Done as $ut){
$DList .= $ut['tid'].',';
}
if(strlen($DList)>0){
$DList = substr($DList,0,-1);
} else {
$DList = 0;
}
$Row_count = mysql_num_rows(mysql_query("SELECT * FROM tasks WHERE `id` NOT IN($DList) AND type = '$type' AND social = '$social' AND bal>0;"));
$rand = rand(0, $Row_count-1);
$Random = Core::MysqlSelect('tasks',null,"WHERE `id` NOT IN($DList) AND type = '$type' AND social = '$social' AND bal>0 LIMIT $rand, 1");
$Array = $Random[0];
if($Array['uid']){
$uData = Core::GetUser($Array['uid']);
$Array['uname'] = $uData['name'].' '.$uData['lastname'];
$Array['photo'] = $uData['photo'];
}
$Array['done'] = mysql_num_rows(mysql_query("SELECT * FROM done WHERE `uid` = ".$CONFIG['uid']));
$Array['count'] = $Row_count;
if(!$Array['id']) $Array['id']=0;
return $Array;
}*/
public function GetRand($social,$type){
extract($GLOBALS, EXTR_REFS);
$types['vk'] = array('like','repost','friend','group');
$social = mysql_real_escape_string($social);
$type = explode(',',$type);
foreach($type as $t){
$t = mysql_real_escape_string($t);
if($t && $t!='' && in_array($t,$types[$social])) $tp .= ",'$t'";
}
$type = substr($tp,1);
//echo $type;
if($type!=''){
$Done = Core::MysqlSelect('done','tid',array('uid'=>$CONFIG['uid'],'social'=>$social)," AND `type` IN($type)");
if(is_array($Done)){
foreach($Done as $ut){
$DList .= $ut['tid'].',';
}
} else {
$DList .= '';
}
if(strlen($DList)>0){
$DList = substr($DList,0,-1);
} else {
$DList = 0;
}
$res = mysql_query("SELECT COUNT(`id`) AS `count` FROM tasks WHERE `id` NOT IN($DList) AND `uid` NOT IN('".$CONFIG['uid']."') AND type IN($type) AND social = '$social' AND `bal`>0;");
$data = mysql_fetch_assoc($res);
$All_Row_count = $data['count'];
unset($res);
unset($data);
$res = mysql_query("SELECT COUNT(`id`) AS `count` FROM tasks WHERE `id` NOT IN($DList) AND `uid` NOT IN('".$CONFIG['uid']."') AND type IN($type) AND social = '$social' AND `bal`>0");
$data = mysql_fetch_assoc($res);
if($data['count']>0) $Row_count = $data['count']; $FromPr = 0; $ToPr = 10;
unset($res);
unset($data);
$from = rand(0,$Row_count-1);
$Random = Core::MysqlSelect('tasks','`id`,`social`,`type`,`url`,`uid`,`pay`,`bal`,`date`',null,"WHERE `id` NOT IN($DList) AND `uid` NOT IN('".$CONFIG['uid']."') AND `type` IN($type) AND `social` = '$social' AND `bal`>0 AND `pay` >$FromPr AND `pay` <$ToPr ORDER BY `pay` DESC LIMIT $from, 1;");
$Array = $Random[0];
//echo "WHERE `id` NOT IN($DList) AND `uid` NOT IN('".$CONFIG['uid']."') AND `type` = '$type' AND `social` = '$social' AND `bal`>0 AND `pay` >$FromPr AND `pay` <$ToPr ORDER BY `pay` DESC LIMIT $from, 1;";
if($Array['uid'] && $Array['uid']!=0){
$uData = Core::GetUser($Array['uid']);
$Array['uname'] = $uData['name'].' '.$uData['lastname'];
$Array['photo'] = $uData['photo'];
} elseif($Array['uid']==0) {
$Array['uname'] = 'Оплаченный заказ';
$Array['photo'] = '/img/av.jpg';
}
$res = mysql_query("SELECT COUNT(`tid`) AS `count` FROM done WHERE `uid` = ".$CONFIG['uid']." AND `social`='$social' AND `type` IN($type)");
$data = mysql_fetch_assoc($res);
$Array['done'] = $data['count'];
unset($res);
unset($data);
$Array['count'] = $All_Row_count;
if(!$Array['id']) $Array['id']=0;
return $Array;
} //yeah bitch
}
public function GetTask($id){
extract($GLOBALS, EXTR_REFS);
if(is_numeric($id)){
$Task = Core::MysqlSelect('tasks','`id`,`social`,`type`,`url`,`uid`,`pay`,`bal`,`date`',array('id'=>$id));
$Task = $Task[0];
$res = mysql_query("SELECT COUNT(`tid`) AS `count` FROM done WHERE `tid`='$id' AND `mode`='done';");
$data = mysql_fetch_assoc($res);
$Task['done'] = $data['count'];
unset($res);
unset($data);
$res = mysql_query("SELECT COUNT(`tid`) AS `count` FROM done WHERE `tid`='$id' AND `uid`='".$CONFIG['uid']."';");
//echo "SELECT COUNT(*) AS `count` FROM done WHERE `tid`='$id' AND `uid`='".$CONFIG['uid']."';";
$data = mysql_fetch_assoc($res);
$Task['isdone'] = '0';
if($data['count']>0){
$Task['isdone'] = '1';
}
unset($res);
unset($data);
$Task['count'] = $Task['bal']/$Task['pay'];
//print_r($Task);
return $Task;
} else {
return array('err');
}
}
/*public function FilterVkLike($a){
$aa = parse_url($a);
if($aa['host']=='vk.com' || $aa['host']=='www.vk.com'){
$b = substr($aa['path'], 0, 5);
if($b=='/wall') $type = 'post';
if($b=='/phot') $type = 'photo';
$values = substr($aa['path'],strlen($type)+1);
$values = explode('_',$values);
$res = file_get_contents('https://api.vk.com/method/likes.getList?type='.$type.'&owner_id='.$values[0].'&item_id='.$values[1]);
$resp = json_decode($res, true);
if(is_numeric($resp['response']['count'])):
return $aa['scheme'].'://'.$aa['host'].$aa['path'];
else: return 0;
endif;
} else {
return 0;
}
}
public function FilterVkRepost($a){
$aa = parse_url($a);
if($aa['host']=='vk.com' || $aa['host']=='www.vk.com'){
$b = substr($aa['path'], 0, 5);
if($b=='/wall') $type = 'post';
//if($b=='/phot') $type = 'photo';
$values = substr($aa['path'],strlen($type)+1);
$values = explode('_',$values);
$res = file_get_contents('https://api.vk.com/method/likes.getList?type='.$type.'&owner_id='.$values[0].'&item_id='.$values[1]);
$resp = json_decode($res, true);
if(is_numeric($resp['response']['count'])):
return $aa['scheme'].'://'.$aa['host'].$aa['path'];
else: return 0;
endif;
} else {
return 0;
}
}*/
public function FilterVkLike($a){
$aa = parse_url($a);
if($aa['host']=='vk.com' || $aa['host']=='www.vk.com'){
$path = $aa['path'];
if($aa['query']) $path .= '?'.$aa['query'];
preg_match_all('#(photo|wall|video)(-?[0-9]+)_([0-9]+)#',$path,$bb);
if($bb[1][0]=='photo') $type = 'photo';
if($bb[1][0]=='wall') $type = 'post';
if($bb[1][0]=='video') $type = 'video';
$res = Core::url_get_contents('https://api.vk.com/method/likes.getList?type='.$type.'&owner_id='.$bb[2][0].'&item_id='.$bb[3][0]);
$resp = json_decode($res, true);
if(is_numeric($resp['response']['count'])):
return $aa['scheme'].'://'.$aa['host'].'/'.$bb[0][0];
else: return 0;
endif;
} else {
return 0;
}
}
public function FilterVkRepost($a){
$aa = parse_url($a);
if($aa['host']=='vk.com' || $aa['host']=='www.vk.com'){
$path = $aa['path'];
if($aa['query']) $path .= '?'.$aa['query'];
preg_match_all('#(photo|wall|video)(-?[0-9]+)_([0-9]+)#',$path,$bb);
if($bb[1][0]=='photo') $type = 'photo';
if($bb[1][0]=='wall') $type = 'post';
if($bb[1][0]=='video') $type = 'video';
$res = Core::url_get_contents('https://api.vk.com/method/likes.getList?type='.$type.'&owner_id='.$bb[2][0].'&item_id='.$bb[3][0]);
$resp = json_decode($res, true);
if(is_numeric($resp['response']['count'])):
return $aa['scheme'].'://'.$aa['host'].'/'.$bb[0][0];
else: return 0;
endif;
} else {
return 0;
}
}
public function FilterVkGroup($a){
$aa = parse_url($a);
if($aa['host']=='vk.com' || $aa['host']=='www.vk.com'){
$path = $aa['path'];
if($aa['query']) $path .= '?'.$aa['query'];
preg_match_all('#(group|public)([0-9]+)#',$path,$bb);
if($bb[1][0]=='group' || $bb[1][0]=='public') $groupid = $bb[2][0];
if(is_numeric($groupid)){
$res = Core::url_get_contents('http://api.vk.com/method/groups.getById?&gids='.$groupid);
$resp = json_decode($res, true);
if($resp['response'][0]['is_closed'] == '1'){
return 0;
} elseif($resp['response'][0]['is_closed'] == '0') {
return 'http://'.$aa['host'].'/'.$bb[0][0];
} else {
return 0;
}
} else {
$groupid = substr($path,1);
$res = Core::url_get_contents('http://api.vk.com/method/groups.getById?&gids='.$groupid);
$resp = json_decode($res, true);
if($resp['response'][0]['is_closed'] == '1'){
return 0;
} elseif($resp['response'][0]['is_closed'] == '0') {
return 'http://'.$aa['host'].'/'.$groupid;
} else {
return 0;
}
}
} else {
return 0;
}
}
public function FilterTwFollow($a){
$aa = parse_url($a);
if($aa['host']=='twitter.com' || $aa['host']=='www.twitter.com'){
$path = $aa['path'];
$userid = substr($path,1);
$res = Core::url_get_contents('https://api.twitter.com/1/users/show.json?screen_name='.$userid);
$resp = json_decode($res, true);
$userid = $resp['id'];
if(is_numeric($userid)){
return 'http://'.$aa['host'].$aa['path'];
} else {
return 0;
}
} else {
return 0;
}
}
public function FilterTwitterTwite($a){
$aa = parse_url($a);
if($aa['host']=='twitter.com' || $aa['host']=='www.twitter.com'){
$path = $aa['path'];
if($aa['query']) $path .= '?'.$aa['query'];
preg_match_all('#/status/([0-9]+)#',$path,$bb);
$res = Core::url_get_contents('https://api.twitter.com/1/statuses/show.json?id='.$bb[1][0].'&include_entities=false&trim_user=false');
$resp = json_decode($res, true);
if(is_numeric($resp['id'])):
return $aa['scheme'].'://'.$aa['host'].'/'.$resp['user']['screen_name'].$bb[0][0];
else: return 0;
endif;
} else {
return 0;
}
}
public function FilterVkFriend($a){
$aa = parse_url($a);
if($aa['host']=='vk.com' || $aa['host']=='www.vk.com'){
$path = $aa['path'];
preg_match_all('#id([0-9]+)#',$path,$bb);
if($bb[1][0]){
$userid = $bb[1][0];
} else {
$userid = substr($path,1);
}
if(preg_match('#^[w-]+$#i',$userid)){
$res = Core::url_get_contents('https://api.vk.com/method/users.get?uids='.$userid.'&fields=uid');
$resp = json_decode($res, true);
if(is_numeric($resp['response'][0]['uid'])):
return $aa['scheme'].'://'.$aa['host'].$aa['path'];
else: return 0;
endif;
} else {
return 0;
}
} else {
return 0;
}
}
public function FilterFbLike($a){
$aa = parse_url($a);
if($aa['host']=='facebook.com' || $aa['host']=='www.facebook.com'){
$path = $aa['path'];
if($aa['query']) $path .= '?'.$aa['query'];
preg_match_all('#(photo.php?fbid=|/posts/)([0-9]+)#',$path,$bb);
//print_r($bb);
if($bb[1][0]=='photo.php?fbid=') $type = 'photo';
if($bb[1][0]=='/posts/') $type = 'post';
if($type){
$postid = $bb[2][0];
$tokens = array(
'AAACfBWptfEkBAK9kA80Cd1Cezzoi44ZB3lcCfspCuB1sKpvzDL9ui1dvzCJtpwN0G9oaDMqeecyCNTK2vUUINCZAMFNAzOZAAibQIG2BgZDZD'
);
$token = $tokens[rand(0,count($tokens)-1)];
//echo 'https://graph.facebook.com/'.$postid.'?fields=id&access_token='.$token;
$res = Core::url_get_contents('https://graph.facebook.com/'.$postid.'?fields=id&access_token='.$token);
$resp = json_decode($res, true);
if($resp['id']==$postid):
return $aa['scheme'].'://'.$aa['host'].$aa['path'];
else: return 0;
endif;
} else {
return 0;
}
} else {
return 0;
}
}
/* Конец фильтров */
public function fbGetToken(){
$tokens = array(
'AAACfBWptfEkBAK9kA80Cd1Cezzoi44ZB3lcCfspCuB1sKpvzDL9ui1dvzCJtpwN0G9oaDMqeecyCNTK2vUUINCZAMFNAzOZAAibQIG2BgZDZD'
);
$token = $tokens[rand(0,count($tokens)-1)];
return $token;
}
}