require_once './params.php';
class Obj extends Params{
private $dbc;
protected $ip;
protected $country='Neverland';
protected $countryId=0;
public $time;
protected $total = false;
private $Request = array();
protected $CUserChanges = array();
protected $ItemChanges = array('user'=>array(),'band'=>array(),'chat'=>array(),'item'=>array());
protected $Countries=array();
protected $Regions=array();
protected $Cities=array();
protected $Tags=array();
protected $SuperAdmin=false;
protected $cache=array();
public $test=false;
public $cron=false;
protected $parent=false;
public $lArr=array('u'=>'user','b'=>'band','c'=>'chat','i'=>'item','f'=>'user');
public $arrL=array('user'=>'u','band'=>'b','chat'=>'c','item'=>'i','p2pIdFingList'=>'u','p2pIdFedList'=>'u','p2pIdBList'=>'b','p2pIdCList'=>'c','p2pIdIList'=>'i');
protected $linkLevels=array('l'=>0,'user'=>1,'band'=>1,'chat'=>1,'item'=>1,'global'=>1,/*'audioalbums'=>2,'videoalbums'=>2,'photoalbums'=>2,*/'mediaalbums'=>2,'yard'=>2,'people'=>2,'bands'=>2,'chats'=>2,'items'=>2,'info'=>2,/*'audioalbum'=>3,'videoalbum'=>3,'photoalbum'=>3,'audio'=>4,'video'=>4,'photo'=>4,*/'mediaalbum'=>3,'media'=>4,'comments'=>5,'comment'=>6,'l_l_count'=>7,'reply_to_p_id'=>8,'last_id'=>9,'last_id'=>10,'i_t'=>10);
public function __construct(){
$this->time = time()+$this->utc;
$this->startTime = strtotime("11 July 2019");
$this->getRequestString();
if(count($_REQUEST) > 100)$this->index();
try{
$this->dbc = new PDO($this->db, $this->dbUser, $this->dbPass, array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'UTF8\''));
}
catch(PDOException $e){var_dump($e);exit;}
if(isset($_REQUEST['create_tables'])){
$this->createTables();
exit;
}
if(isset($_REQUEST['closed'])&&is_string($_REQUEST['closed']))try{
$_POST['closed']=$_REQUEST['closed']=(array)json_decode($_REQUEST['closed']);
}
catch(Exception $e){}
else if(isset($_REQUEST['item_additional_data'])&&is_string($_REQUEST['item_additional_data']))try{
$_POST['item_additional_data']=$_REQUEST['item_additional_data']=(array)json_decode($_REQUEST['item_additional_data']);
}
catch(Exception $e){}
$this->filter();
}
private function getRequestString(){
$this->Request=array('get'=>$_GET,'post'=>$_POST,'cookie'=>$_COOKIE,'server'=>$_SERVER);
@file_put_contents('./log/'.date('dmY',$this->time).'.log', json_encode($this->Request)."\r\n\r\n", FILE_APPEND);
}
public function filter(){
$_REQUEST = $this->checkReq($_REQUEST);
$_POST = $this->checkReq($_POST);
$_GET = $this->checkReq($_GET,true);
$_COOKIE = $this->checkReq($_COOKIE,true);
$this->checkForSpam();
$this->checkForAppeal();
}
public function object_to_array($obj) {
if(is_object($obj)) $obj = (array) $obj;
if(is_array($obj)) {
$new = array();
foreach($obj as $key => $val) {
$new[$key] = $this->object_to_array($val);
}
}
else $new = $obj;
return $new;
}
public function checkReq($arr = array(),$nd = false){
foreach($arr as $key => $val){
if(preg_match("/^video([0-9]+)_thumbnails$/iu",$key))$arr[$key] = $val;
else if(is_array($key) || is_array($val) || is_object($val)){
if($key != 'closed')unset($arr[$key]);
else $arr[$key] = $this->object_to_array($val);
}
else if(preg_match("/_id/i",$key)&&!preg_match("/^[0-9:]+(\s*,\s*[0-9:]+)*$/",$val))unset($arr[$key]);
else{
$l=mb_strlen($val,'UTF-8');
if(trim($val)){
if(($key=='story'||$key=='chain')||$key=='val'&&isset($_REQUEST['name'])&&$_REQUEST['name']=='story'){
if($l > 64000)$val=mb_substr($val,0,64000);
}
else if($l > 1024)$val=mb_substr($val,0,1024);
if($key!='ads')$arr[$key] = $this->clearVal($val);
if($val==='false')unset($arr[$key]);
}
else if(!$nd&&$key!='people'&&$key!='likes'&&$key!='shares'&&$key!='comments'){
unset($arr[$key]);
}
else $arr[$key] = trim($val);
}
}
return $arr;
}
private function checkForSpam(){
if(isset($_REQUEST['user'])&&$_REQUEST['user']>0)if(isset($_REQUEST['val'])&&(isset($_REQUEST['message'])&&$_REQUEST['message']=='add'||isset($_REQUEST['comment'])&&$_REQUEST['comment']=='add')){
$time=mb_substr($this->time."",-4);
$tag='';
$query='';
$i=0;
$sTags=array();
$t=preg_split("/[^a-z0-9а-я]+/iu",$this->getSLetters($this->getLetters($_REQUEST['val'],true)));
foreach($t as $v)if($v&&$i++<50){
$sv=$this->getSLetters($v);
if(!isset($sTags[$sv])){
$tag.='"'.$sv.'",';
$sTags[$sv]=true;
$query.='('.$_REQUEST['user'].',"'.$sv.'",'.$time.'),';
}
}
if($tag)$tags=$this->findList('select *','antispam','u_id = '.$_REQUEST['user'].' and time > '.($time-1200).' and tag in ('.mb_substr($tag,0,-1).')');
else $tags=array();
$uId=0;$j=0;$c=0;
foreach($tags as $tag){
if($tag['u_id']!=$uId){
if($j>0&&$j>$i*0.66)$c++;
$j=0;
$uId=$tag['u_id'];
}
if(isset($sTags[$tag['tag']]))$j++;
}
if($i==0)$i=1;
if($c>5||$j/$i>5)$this->toJson(array('error'=>'wsn'));
else if($query)$this->insertString('insert into antispam (`u_id`,`tag`,`time`) values '.mb_substr($query,0,-1));
}
}
private function checkForAppeal(){
if(isset($_REQUEST['appeal'])&&isset($_REQUEST['user'])&&$_REQUEST['user']>0){
$this->insert('insert into','appeals',array('u_id'=>$_REQUEST['user'],'page'=>$_REQUEST['appeal'],'comment'=>isset($_REQUEST['acomment'])?$_REQUEST['acomment']:''));
$this->toJson(array('done'),0,0,0);
}
}
private function clearVal($val){
return $this->myhtmlspecialchars(trim($val," \t\n\r\0\x0b,"));
}
protected function myhtmlspecialchars($str){
return str_replace('-', '-', str_replace('>', '>', str_replace('<', '<', str_replace('"', '"', str_replace("'", ''', str_replace(":", ':', str_replace(",", ',', str_replace('*', '*', str_replace('#', '#', $str)))))))));
}
public function mydehtmlspecialchars($str){
return str_replace('-', '-', str_replace('*', '*', str_replace('>', '>', str_replace('<', '<', str_replace('"', '"', str_replace("'", "'", str_replace(":", ':', str_replace(",", ',', str_replace('#', '#', $str)))))))));
}
/**
*
* @param string $start
* @param string $table
* @param string/array $queryArr
* @param array $order
* @param int/array $limit
* @param int $i
* @param string $asId
* @param string $group
* @param function $func
*/
public function findList($start,$table,$queryArr=array(),$order=array(),$limit=0,$i=0,$asId=false,$group=false,$func=false){
$ci=is_array($queryArr)?http_build_query($queryArr).(is_array($asId)?implode($asId):$asId):http_build_query(array($queryArr)).(is_array($asId)?implode($asId):$asId);
if(isset($this->cache[$table][$ci]))return $this->cache[$table][$ci];
$result = array();
$query = $start.' from '.$table;
if(is_string($queryArr))$query.=' where '.$queryArr;
else if(!$this->isEmpty($queryArr)){
$query.=' where ';
foreach($queryArr as $key => $val)$query.=$key.'="'.$val.'" and ';
$query = mb_substr($query,0,-5,'UTF-8');
}
if($group)$query.=' group by '.$group;
if(!$this->isEmpty($order)){
$query.=' order by ';
foreach($order as $key => $val)$query.=$key.' '.$val.', ';
$query = mb_substr($query,0,-2,'UTF-8');
}
else if($order)$query.=' order by '.$order;
if($limit)if(is_array($limit)&&count($limit)==2)$query.=' limit '.$limit[0].', '.$limit[1];
else $query.=/*$limit;//*/' limit 0, '.$limit;
if($this->test)
echo '\r\n";//
try{
$a=microtime(1);
$q=$this->dbc->query($query);
if(!is_array($q)&&!is_object($q)||!$q){
echo 'Error: '.$query."
\r\n";
}
if($func){
foreach($q as $row){
foreach($row as $key => $value)if(is_numeric($key))unset($row[$key]);
$func($row);
}
}
else if(!$asId){
foreach($q as $row){
foreach($row as $key => $value)if(is_numeric($key))unset($row[$key]);
$result[$i] = $row;
$i++;
}
}
else if(is_array($asId)){
foreach($this->dbc->query($query) as $row){
$ak='';
foreach($row as $key => $value)if(is_numeric($key))unset($row[$key]);
else if(in_array($key,$asId))$ak.=$row[$key];
$result[$ak] = $row;
}
}
else{
foreach($q as $row){
foreach($row as $key => $value)if(is_numeric($key))unset($row[$key]);
if(isset($row[$asId]))$result[$row[$asId]] = $row;
}
}
$b=microtime(1);
if($b-$a>0.05){
$d=debug_backtrace();
$this->insert('insert ignore into','overload',array('table'=>$table,'query'=>preg_replace("/\"/iu","\\\"",$query),'time'=>$b-$a,'fn'=>isset($d[1]['function'])?$d[1]['function']:''));
}
}
catch(Exception $e){}
if(!$this->cron)$this->cache[$table][$ci]=$result;
return $result;
}
public function insert($start,$table,$queryArr,$whereArr=array(),$order=array(),$limit=0){
if(!preg_match("/delete/i",$start))$query = ' set ';
else $query='';
if(!preg_match("/insert/i",$start))$where = ' where ';
else $where='';
if(!$this->isEmpty($queryArr)){
foreach($queryArr as $key => $val)$query.='`'.$key.'`="'.$val.'", ';
$query=mb_substr($query,0,-2,'UTF-8');
}
else if(is_string($queryArr))$query.=$queryArr;
if($where)if(!$this->isEmpty($whereArr)){
foreach($whereArr as $key => $val)$where .= $key.'="'.$val.'" and ';
$where = mb_substr($where,0,-5,'UTF-8');
}
else if(is_string($whereArr))$where.=$whereArr;
if(!$this->isEmpty($order)){
$where.=' order by ';
foreach($order as $key => $val)$where.=$key.' '.$val.', ';
$where = mb_substr($where,0,-2,'UTF-8');
}
if($limit)if(preg_match("/delete/iu",$start))$where.=' limit '.$limit;
else $where.=' limit 0, '.$limit;
return $this->insertString($start.' '.$table.$query.$where);
}
protected function insertString($query){
if($this->test)
echo "\r\n";
$e = $this->dbc->prepare($query);
if($e->execute())return true;
else {
echo 'Error: '.$query."
\r\n";
}
return false;
}
public function getPlural($str){
if(substr($str, -1) == 'y')return substr($str, 0, -1).'ies';
else if(preg_match("/[sx][h]?$/iu",$str))return $str.'es';
else if($str=='people')return 'people';
else return $str.'s';
}
protected function getRandom($num = 1988){
return md5((($this->time / rand(1, 1000)) + $this->time + $num + microtime(1)).'hello amigo!) this is sparta!');
}
protected function getNumRandom($min,$max,$b=false){
$r=rand($min, $max);
$m=(microtime(1)-$_REQUEST['a'])+"";
$m=(int)preg_replace("/[^0-9]+/","",substr($m,strlen($m)-strlen($max)-strlen($max)/2));
$res=$r+(int)($m>$max?$m/$max:$m);
if($b&&$res>$max)return $r;
return $res;
}
public function validMail($email){
if(!preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/", $email)) return false;
return true;
}
public function sendMail($to,$subject,$text,$from_mail=false,$from_name=false,$replyto=false,$files=array()){
if(!$replyto)$replyto=$this->email;
if(!$from_mail)$from_mail=$this->email;
if(!$from_name)$from_name=t('pin');
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
$headers="From: ".$from_name." <".$from_mail.">\nReply-To: ".$replyto."\nX-Mailer: PHP/".phpversion()."\nMIME-Version: 1.0\nContent-Type: multipart/mixed;\n boundary=\"{$mime_boundary}\"";
$message = "This is a multi-part message in MIME format.\n\n--{$mime_boundary}\nContent-Type:text/html; charset=\"utf-8\"\nContent-Transfer-Encoding: 7bit\n\n".$text."\n\n";
foreach($files as $filename){
$file = fopen($filename,'rb');
$data = fread($file,filesize($filename));
fclose($file);
$data = chunk_split(base64_encode($data));
$message .= "--{$mime_boundary}\nContent-Type: application/octet-stream;\n name=\"order.xls\"\nContent-Transfer-Encoding: base64\n\n".$data."\n\n";
}
$message .= "--{$mime_boundary}--\n";
mail($to,$subject,$message,$headers);
}
public function lastInsertId(){
return $this->dbc->lastInsertId();
}
protected function rowCount(){
return $this->dbc->rowCount();
}
protected function saveCUserChanges(){
$query = array();
if(count($this->CUserChanges) > 0 && isset($this->CUser[0]['id']) && !isset($this->CUser[0]['unreg'])){
foreach($this->CUserChanges as $row => $val)$query[$row] = $this->CUser[0][$row];
$this->insert('update','u_'.$this->getTI($this->CUser[0]['id']),$query,array('id'=>$this->CUser[0]['id']));
}
}
public function saveItemsChanges(){
foreach($this->ItemChanges as $ubcKey=>$ItemsChange){
foreach($ItemsChange as $iId=>$ItemChange){
$l=$this->getS($ubcKey);
if(count($ItemChange) > 0 && isset($this->Item[0]['id']) && $iId==$this->Item[0]['id']){
foreach($ItemChange as $row => $val)$query[$row] = $this->Item[0][$row];
$this->insert('update',$l.'_'.$this->getTI($this->Item[0]['id'],$this->getPlural($ubcKey)),$query,array('id'=>$this->Item[0]['id']));
}
}
}
}
public function checkIfClosedSInfoRemains(){
if(!isset($_REQUEST['closed']))return true;
$_REQUEST=array('closed'=>$_REQUEST['closed']);
if($this->isLU()){
foreach(array('user','band','chat','item') as $p)if(isset($_REQUEST['closed'][$p]))foreach($_REQUEST['closed'][$p] as $iId=>$SInfoArr){
if($p!='user')$allow=$this->findList('select *','u_'.$this->getTI($this->CUser[0]['id']).'_'.$this->getPlural($p).'_fs',array('u_id'=>$this->CUser[0]['id'],$this->getS($p).'_id'=>$iId));
else if($iId==$this->CUser[0]['id'])$allow=array(array('admin'=>1));
if(isset($allow[0]['admin'])&&$allow[0]['admin']==1){
$_REQUEST[$p]=$iId;
$this->getI($p);
$this->saveItemsChanges();
}
}
}
}
public function pageToId($page){
return ceil($page) * $this->limit - $this->limit;
}
public function idToPage($id){
return floor($id/$this->limit)+1;
}
protected function getIns($arr,$id,$n=true,$conditionParam=false,$conditionValue=1,$conditionParam2=false,$conditionValue2=4){
$ins=array();
$ids=array();
if($n){
foreach($arr as $a)if(!$conditionParam||(isset($a[$conditionParam])&&$a[$conditionParam]==$conditionValue||!isset($a[$conditionParam])&&!$conditionValue)||$conditionParam2&&$a[$conditionParam2]<$conditionValue2){
$ti=$this->TI($a[$id]);
if(isset($ins[$ti]))$ins[$ti].=$a[$id].',';
else $ins[$ti]=$a[$id].',';
}
}
else if($n==null)if(!$conditionParam||isset($a[$conditionParam])&&$a[$conditionParam]==$conditionValue){
foreach($arr as $a){
$ti=$this->TI($a[$id]);
$ins[$ti][]=$a[$id];
}
}
else{
foreach($arr as $a)if(!$conditionParam||isset($a[$conditionParam])&&$a[$conditionParam]==$conditionValue){
$ti=$this->getS($a[$id]);
if(isset($ins[$ti]))$ins[$ti].=$a[$id].',';
else $ins[$ti]=$a[$id].',';
}
}
return $ins;
}
public function firstUp($str){
return mb_strtoupper(mb_substr($str, 0, 1, 'UTF-8'), 'UTF-8').mb_substr($str, 1, mb_strlen($str, 'UTF-8'), 'UTF-8');
}
public function getPast($str){
$s=substr($str, -1);
if($s == 'y')return substr($str, 0, -1).'ied';
else if($s == 'e')return substr($str, 0, -1).'ed';
else return $str.'ed';
}
public function isPlural($str){
return preg_match("/s$/iu",$str);
}
public function getLink($arr, $link = '/#', $end = ''){
if($link!='/#'&&!isset($arr['l'])&&isset($_GET['l']))$arr['l']=$_REQUEST['l'];
$i=0;
$c=count($arr);
$linkArr=array();
$m=10;
foreach($arr as $key => $val){
$i++;
$k=isset($this->linkLevels[$key])?$this->linkLevels[$key]:$m++;
$linkArr[$k] = '/'.$key.(trim($val)?'/'.$val:($i==$c?'':'/all'));
}
for($i=0;$i<11;$i++)if(isset($linkArr[$i]))$link.=$linkArr[$i];
return $link.$end.(isset($_REQUEST['no_script'])?'?no_script=true':'');
}
public function checkSlashes($str){
if(preg_match('/["]/', $str)){
if(preg_match('/(\\\")/', $str))return $str;
else return addslashes($str);
}
else return $str;
}
protected function myDecode(){
if(isset($_COOKIE['capcha_kyka']) && strlen($_COOKIE['capcha_kyka']) == 32 && isset($_COOKIE['capcha']) && $_COOKIE['capcha'] > 0 && isset($_COOKIE['alert_double_request'])){
$val = $this->findList('select *','capcha','id = "'.$_COOKIE['capcha'].'" or alert_double_request = "'.$_COOKIE['alert_double_request'].'"',array('time'=>'desc'),1);
if(isset($val[0]['id']) && $val[0]['kyka'] == $_COOKIE['capcha_kyka']){
$this->insert('delete from','capcha',array(),array('id' => $val[0]['id']));
return $val[0]['capcha'];
}
else{
$this->mysetcookie('alert_double_request','');
$this->mysetcookie('capcha','');
$this->mysetcookie('capcha_kyka','');
}
}
return false;
}
public function isEmpty($arr){
if(!is_array($arr))return true;
foreach($arr as $val)return false;
return true;
}
protected function my_array_merge($arr1, $arr2, $addMinusOnDuplicateKey = false){
foreach($arr2 as $key => $val)if(!isset($arr1[$key]))$arr1[$key] = $arr2[$key];
else if($addMinusOnDuplicateKey&&is_numeric($key)&&!isset($arr1[-$key]))$arr1[-$key] = $arr2[$key];
return $arr1;
}
public function mysetcookie($key, $val, $time=false, $domain=false){
if(!$time)$time=$this->time+86400*30;
if(!$domain)$domain='localhost:4488';//$this->domain;
if(preg_match("/^\/*$/iu",$_SERVER['REQUEST_URI'])||preg_match("/^\/+[^\/]*$/iu",$_SERVER['REQUEST_URI'])){
setcookie($key, '', 0);
if($val)setcookie($key, $val, $time);
}
else{
setcookie($key, '', 0, '/', $domain);
if($val)setcookie($key, $val, $time, '/; SameSite=None', $domain);
}
}
protected function testURL($url){
if(!preg_match('/^(http|https|ftp):\/\/([A-Z0-9][A-Z0-9_-]*(?:.[A-Z0-9][A-Z0-9_-]*)+):?(d+)?\/?/i', $url))return false;
$f = @fopen($url, 'r');
if($f){
$r = fread($f,10);
if(strlen($r)>1)return true;
fclose($f);
}
return false;
}
protected function mkStartEnd($d_m_y, $hm = '00:00'){
$hm = preg_split('/[^0-9]+/iu', $hm);
if(count($hm) != 2)$hm = array(0,0);
$dmy = preg_split('/((\&\#[0-9]{2,5};)|[^0-9])+/iu', $d_m_y);
if(count($dmy) != 3)return 0;
if((int)$dmy[0] > 31){
$dmy[4]=$dmy[0];
$dmy[0]=$dmy[2];
$dmy[2]=$dmy[4];
}
if($dmy[0] > 0 && $dmy[1] > 0 && $dmy[2] > 0)return mktime((int)$hm[0], (int)$hm[1], 0, (int)$dmy[1], (int)$dmy[0], (int)$dmy[2]);// + $utc;
else return 0;
}
protected function mkHour($hm = '00:00'){
$hm = preg_split('/[^0-9]+/iu', $hm);
if(count($hm) != 2)$hm = array(0,0);
return (int)$hm[1]*60+(int)$hm[0]*3600;
}
public function uc2html($str){//return $str;
$ret = '';
for($i=0; $i 0)$this->toJson(0);
if(!is_array($this->Countries)||count($this->Countries)==0)$this->getCountryAndSetLang();
include './html/blank.html';
exit;
}
public function cap4unya(){
if(!isset($_REQUEST['capcha']) || strtolower($_REQUEST['capcha']) !== strtolower($this->myDecode()))return false;
return true;
}
public function getBlank(){
$message = t('badbrowser',array('domain'=>$this->domain));
include './html/blank.html';
}
public function getS($str,$e=true){
if(!$str)return '';
$s = mb_strtolower(mb_substr($str, 0, 1,'utf-8'),'utf-8');
if(preg_match("/^[а-я]$/iu", $s))$s = $this->getLetters($s,$e);
else if(!preg_match("/^[a-z]$/iu", $s))$s = '_';
return $s;
}
protected function getAge($time){
if(!$time)return 0;
return date('Y',$this->time)-date('Y',$time);
}
protected function getLetters($str,$e=false,$n=false,$space=false){
$letters = array('а','б','в','г','д','е','ё','ж','з','и','й','к','л','м','н','о','п','р','с','т','у','ф','х','ц','ч',"ь","ъ","ы",'ш','щ','э','ю','я','ț','і','ї','æ','ø','Æ','å','é','ô','è','ā','ß','ö','ü','ä','ò','ĺ','\'','ї','є');
if(!$e)$engLetters = array('a','b','v','g','d','ye','ye','zh','z','i','y','k','l','m','n','o','p','r','s','t','u','f','h','c','ch',"","","y",'sh','shy','e','yu','ya','t','і','i','ae','o','ae','a','e','o','e','a','b','o','u','a','o','l','','yi','ye');
else $engLetters = array('a','b','v','g','d','e','e','z','z','i','y','k','l','m','n','o','p','r','s','t','u','f','h','c','c',"_","_","y",'s','s','e','u','a','t','i','i','a','o','a','a','e','o','e','a','b','o','u','a','o','l','','i','e');
$newWord = '';
$str = trim(mb_strtolower($str,'UTF-8'));
for($i = 0; $i < mb_strlen($str,'UTF-8'); $i++){
$l = mb_substr($str,$i,1,'UTF-8');
$key = array_keys($letters, $l);
if(isset($key[0]))$newWord .= $engLetters[$key[0]];
else{
if(preg_match("/[a-z]/i", $l)||$n&&preg_match("/[0-9]/i", $l))$newWord .= $l;
else if($space&&$l==' ')$newWord .= $l;
else if($space&&($l=='`'||$l=='\''))$newWord .= '';
else $newWord .= '_';
}
}
return $newWord;
}
protected function getSLetters($str,$vovels=true){
$letters = array('а','в','е','ё','з','к','м','н','о','o','р','с','т','у','х','ч',"ь","ъ","ы",'э','є','i','ї','l','o');
$sLetters = array('a','b','e','e','3','k','m','h','0','0','p','c','t','y','x','4','b','b','bi','3','e','1','1','1','0');
$newWord = '';
$str = trim(mb_strtolower($str,'UTF-8'));
for($i = 0; $i < mb_strlen($str,'UTF-8'); $i++){
$l = mb_substr($str,$i,1,'UTF-8');
$key = array_keys($letters, $l);
if(isset($key[0]))$newWord .= $sLetters[$key[0]];
else{
if(preg_match("/[a-z]/i", $l)||preg_match("/[0-9]/i", $l))$newWord .= $l;
else $newWord .= '_';
}
}
return $vovels?$newWord:preg_replace("/[aeijgouy]+/iu","",$newWord);
}
public function getTI($id, $i = 'users'){
if(is_numeric($id) && $id <= $this->total[0][$i])return $this->TI($id);
else $this->toJson(array('error' => 'no'.substr($i, 0, -1)));
}
protected function getItemCurrentRate($item=array(),$n=0){
$itemTime=isset($item['time'])?$item['time']:$this->time;
$t=((isset($item['likes_count'])?$item['likes_count']:0)+(isset($item['shares_count'])?$item['shares_count']:0)+(isset($item['comments_count'])?$item['comments_count']:0)+$n);
if($t==0)$t=1;
return (int)($t*1000000/($this->time-$itemTime+$this->defaultRateTimeGap));
}
protected function getRI($rate/*,$p='users'*/){
if($rate<1)return 43;
else if($rate<10)return 42;
else if($rate<50)return 41;
else if($rate<100)return 40;
else if($rate<200)return 39;
else if($rate<300)return 38;
else if($rate<400)return 37;
else if($rate<500)return 36;
else if($rate<600)return 35;
else if($rate<700)return 34;
else if($rate<800)return 33;
else if($rate<900)return 32;
else if($rate<1000)return 31;
else if($rate<2000)return 30;
else if($rate<3000)return 29;
else if($rate<4000)return 28;
else if($rate<5000)return 27;
else if($rate<6000)return 26;
else if($rate<7000)return 25;
else if($rate<8000)return 24;
else if($rate<9000)return 23;
else if($rate<10000)return 22;
else if($rate<20000)return 21;
else if($rate<30000)return 20;
else if($rate<40000)return 19;
else if($rate<50000)return 18;
else if($rate<60000)return 17;
else if($rate<70000)return 16;
else if($rate<80000)return 15;
else if($rate<90000)return 14;
else if($rate<100000)return 13;
else if($rate<200000)return 12;
else if($rate<300000)return 11;
else if($rate<400000)return 10;
else if($rate<500000)return 9;
else if($rate<600000)return 8;
else if($rate<700000)return 7;
else if($rate<800000)return 6;
else if($rate<900000)return 5;
else if($rate<1000000)return 4;
else if($rate<2000000)return 3;
else if($rate<3000000)return 2;
else return 1;
}
protected function isJson($string) {
json_decode($string);
return json_last_error() === JSON_ERROR_NONE;
}
protected function setUSInfo($param, $n, &$Item=false, $sii='s_info', $forced=false){
if($Item === false)if(isset($this->CUser[0]['id'])){
$Item = &$this->CUser;
$this->CUserChanges[$sii] = true;
}
else return false;
if($n==0)return $Item[0][$sii];
preg_match('/(^|[^a-z0-9])'.$param.':([0-9-]+)/', $Item[0][$sii], $m);
if(isset($m[2])&&is_numeric($m[2])){
if($m[2]<0)$m[2]=0;
if($n<0&&$m[2]==0)return $Item[0][$sii];
if(!$forced)$Item[0][$sii] = preg_replace('#(^|[^a-z0-9])'.$param.':[0-9-]+#', '$1'.$param.':'.($m[2] + $n), $Item[0][$sii]);/*$func = create_function('$match', 'return $match[0] + '.$n.';');$this->CUser[0]['s_info'] = preg_replace_callback('#(?<='.$param.':)([0-9]*)#', $func, $this->CUser[0]['s_info']);*/
else $Item[0][$sii]=preg_replace('/(^|[^a-z0-9])'.$param.':[0-9-]+/', "$1".$param.":".$n, $Item[0][$sii]);
}
else if($n<0)return $Item[0][$sii];
else $Item[0][$sii] .= $param.':'.$n.',';
return $Item[0][$sii];
}
public function getUSInfo($str, $param){
if(!$str)return 0;
preg_match('/(^|[^a-z0-9])'.$param.':([0-9]+)/i', $str, $m);
if(isset($m[1]) && is_numeric($m[2]) && $m[2] > 0)return $m[2];
else return 0;
}
protected function getTII($time, $i='m',$iId=0,$c=true,$l='u'){//3333 echo $id.'/'.$this->total[0][$i].'/'.$i.'\n';//check image.php for changing something in this func
$tii=ceil(($time-$this->startTime)/(3600*24*30));
if($c){
$ti=$this->getTI($iId,$this->getPlural($this->lArr[$l]));
if($i=='m'){
if($this->isLU()&&!$this->checkTiiTable($tii,$ti))$this->createTables('m',$iId,$tii);
}
else{
if(!$this->checkTiiTable($tii,$ti,$i,$l))$this->createTables($l.'_news',$iId,$tii,'news');//
}
}
return $tii;
}
protected function checkTiiTable($tii,$ti,$tni='m',$l='u',$tableName=false){
if($tableName)$t=$this->findList('select *','information_schema.tables',array('table_schema'=>$this->dbName,'table_name'=>$tableName));
else $t=$this->findList('select *','information_schema.tables',array('table_schema'=>$this->dbName,'table_name'=>$l.'_'.$ti.'_'.$tni.'_'.($tni=='m'?'':'fs_').$tii));
if(!isset($t[0]['table_name'])&&!isset($t[0]['TABLE_NAME']))return false;
return true;
}
protected function TI($id){
return ceil($id/1000);
}
public function getFromUrl($url, $post = '', $loop = 0){
$ch = curl_init();
$host = preg_replace("/^http[s]?:\/\/([^\/\?\&\=]+)[\s\S]*/iu","$1",$url);
$http = preg_replace("/^(http[s]?).*$/iu","$1",$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
$headers = array(
'Host: '.$host,
'User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13',
'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Language: ru-ru,ru;q=0.8,en-us;q=0.5,en;q=0.3',
'Accept-Encoding: gzip,deflate',
'Accept-Charset: windows-1251,utf-8;q=0.7,*;q=0.7',
'Keep-Alive:115',
'Connection: keep-alive'
);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_ENCODING, 1);
if($post){
curl_setopt($ch, CURLOPT_POST, $post?true:false);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
}
if(preg_match("/^https/iu",$url))curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);
$response = curl_exec($ch);
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$headers = mb_substr($response, 0, $header_size, 'UTF-8');
$full = mb_substr($response, $header_size, mb_strlen($response,'UTF-8'), 'UTF-8');
curl_close($ch);
if(preg_match("/location\s*\:/iu",$headers)){
$location = trim(preg_replace("/^[\s\S]*?location\s*\:\s*([^\r\n]+)[\s\S]*$/iu","$1",$headers));
if(!preg_match("/^http/iu",$location))$location=preg_replace("/^\/?/iu",$http."://".$host."/",$location);
if($location!=$url&&$loop<5)return $this->getFromUrl($location,'',++$loop);
}
return $full;
}
public function getListQueryNameParamStr($val,$aliases=true){
if($aliases)$aliases=' or aliases like "%'.$val.'%"';
return '(name like "'.$val.'%" or name_ru like "'.$val.'%" or name_ua like "'.$val.'%"'.$aliases.')';
}
public function getList(){
if($_REQUEST['list']=='country'&&isset($_REQUEST['val'])&&(isset($_POST['main'])||mb_strlen(trim($_REQUEST['val']),'UTF-8')%3==0)){echo 111;
$this->toJson(array($this->Countries));
}
else if($_REQUEST['list']=='region'&&isset($_REQUEST['i'])&&isset($_REQUEST['val'])&&($_REQUEST['i']>0||preg_match("/^[0-9,\s]+$/iu",$_REQUEST['i']))&&(isset($_POST['main'])||mb_strlen(trim($_REQUEST['val']),'UTF-8')%3==0)){
$_REQUEST['i']=preg_replace("/[^0-9]+/iu",", ",preg_replace("/(^[^0-9]+)|([^0-9]+$)/iu","",$_REQUEST['i']));
$list = $this->findList('select id'.$this->getCRCNameColumnName().', u, country_id, CONCAT_WS(\', \', name, name_ru, name_ua, aliases) AS aliases','regions','country_id in ('.$_REQUEST['i'].') and is_active = 1 and '.$this->getListQueryNameParamStr($_REQUEST['val']),array('country_id'=>'asc','name'=>'asc'),20,0,'id');
$this->toJson(array($list));
}
else if($_REQUEST['list']=='city'&&isset($_REQUEST['i'])&&isset($_REQUEST['val'])&&($_REQUEST['i']>0||preg_match("/^[0-9,\s]+$/iu",$_REQUEST['i']))&&(isset($_POST['main'])||mb_strlen(trim($_REQUEST['val']),'UTF-8')%3==0)){
$_REQUEST['i']=preg_replace("/[^0-9]+/iu",", ",preg_replace("/^([0-9,\s]+)(-|-)+([0-9,\s]+)/iu","$3",preg_replace("/(^[^0-9]+)|([^0-9]+$)/iu","",$_REQUEST['i'])));
//$this->test=1;
$list = $this->findList('select id'.$this->getCRCNameColumnName().', u, region_id, CONCAT_WS(\', \', name, name_ru, name_ua, aliases) AS aliases','cities','region_id in ('.$_REQUEST['i'].') and is_active = 1 and '.$this->getListQueryNameParamStr($_REQUEST['val']),array('region_id'=>'asc','name'=>'asc'),20,0,'id');
//$this->test=0;
$this->toJson(array($list));
}
else if(preg_match("/^p[0-9]+$/iu",$_REQUEST['list'])&&isset($_REQUEST['i'])&&($_REQUEST['i']>0||preg_match("/^[0-9,\s]+$/iu",$_REQUEST['i']))){
$_REQUEST['i']=preg_replace("/[^0-9]+/iu",", ",preg_replace("/(^[^0-9]+)|([^0-9]+$)/iu","",$_REQUEST['i']));
$_REQUEST['list']=preg_replace("/^p([0-9]+)$/iu","$1",$_REQUEST['list']);
//$this->test=1;
if(isset($_REQUEST['val']))$list = $this->findList('select id'.$this->getCRCNameColumnName().', subd_id, CONCAT_WS(\', \', name, name_ru, name_ua, aliases) AS aliases','subdivision_values','subd_id in ('.$_REQUEST['i'].') and param_id = '.$_REQUEST['list'].' and '.$this->getListQueryNameParamStr($_REQUEST['val']),array('name'=>'asc'),20,0,'id');
else $list = $this->findList('select id'.$this->getCRCNameColumnName().', subd_id, CONCAT_WS(\', \', name, name_ru, name_ua, aliases) AS aliases','subdivision_values','subd_id in ('.$_REQUEST['i'].') and param_id = '.$_REQUEST['list'],array('name'=>'asc'),20,0,'id');
$this->toJson(array($list));
}
else if($_REQUEST['list']=='subd'){
if(isset($_REQUEST['val']))$list = $this->findList('select id'.$this->getCRCNameColumnName().', CONCAT_WS(\', \', name, name_ru, name_ua, aliases) AS aliases','subdivisions',$this->getListQueryNameParamStr($_REQUEST['val'],false),array('name'=>'asc'),20,0,'id');
else $list = $this->findList('select id'.$this->getCRCNameColumnName().', CONCAT_WS(\', \', name, name_ru, name_ua, aliases) AS aliases','subdivisions',array(),array('name'=>'asc'),20,0,'id');
$this->toJson(array($list));
}
else if($_REQUEST['list']=='subdivision_param'&&isset($_REQUEST['i'])&&($_REQUEST['i']>0||preg_match("/^[0-9,\s]+$/iu",$_REQUEST['i']))){
$_REQUEST['i']=preg_replace("/[^0-9]+/iu",", ",preg_replace("/(^[^0-9]+)|([^0-9]+$)/iu","",$_REQUEST['i']));
if(isset($_REQUEST['val']))$list = $this->findList('select id'.$this->getCRCNameColumnName().', subd_id, CONCAT_WS(\', \', name, name_ru, name_ua, aliases) AS aliases','subdivision_params','subd_id in ('.$_REQUEST['i'].') and '.$this->getListQueryNameParamStr($_REQUEST['val']),array('name'=>'asc'),20,0,'id');
else $list = $this->findList('select id'.$this->getCRCNameColumnName().', subd_id, CONCAT_WS(\', \', name, name_ru, name_ua, aliases) AS aliases','subdivision_params','subd_id in ('.$_REQUEST['i'].')',array('name'=>'asc'),20,0,'id');
$this->toJson(array($list));
}
else if($_REQUEST['list']=='band'){
if(isset($_REQUEST['val']))$list = $this->findList('select b_id as id'.$this->getCRCNameColumnName().', CONCAT_WS(\', \', name, name_ru, name_ua, aliases) AS aliases','bands',$this->getListQueryNameParamStr($_REQUEST['val']),array('name'=>'asc'),20,0,'id');
else $list = $this->findList('select b_id as id'.$this->getCRCNameColumnName().', CONCAT_WS(\', \', name, name_ru, name_ua, aliases) AS aliases','bands',array(),array('name'=>'asc'),20,0,'id');
$this->toJson(array($list));
}
else if($_REQUEST['list']=='sex'&&isset($_REQUEST['i'])&&preg_match("/^[0-9,]*?(-|-)+[0-9,]*?(-|-)+[0-9,]*$/iu",$_REQUEST['i'])){
$_REQUEST['i']=$this->mydehtmlspecialchars($_REQUEST['i']);
$_REQUEST['i']=preg_split("/(-|-)+/iu",$_REQUEST['i']);
$_REQUEST['i'][0]=preg_split("/(,|,)/iu",$_REQUEST['i'][0]);
if(count($_REQUEST['i'])!=3)$this->toJson(array(array()));
$list=array();
$arr=array('country_id','region_id','city_id');
$group_concat='';
$_REQUEST['val']=isset($_REQUEST['val'])?preg_replace("/[^0-9]/iu","",$_REQUEST['val']):'';
$s=(!$_REQUEST['val']?'':' and sex_id = '.$_REQUEST['val']);
foreach($arr as $av)$group_concat.=', group_concat(DISTINCT CAST('.$av.' as CHAR) SEPARATOR \',\') as '.$av;
foreach($_REQUEST['i'][0] as $countryId){
//$this->test=true;
$tags=$this->findList('select sex_id as id, sum(u) as u'.$group_concat,'tags_'.$this->getTagsTableCountryInd($countryId),'region_id in ('.$_REQUEST['i'][1].') and city_id in ('.$_REQUEST['i'][2].') and name="" and age = 0'.$s,false,20,0,'id','sex_id');
//$this->test=false;
foreach($tags as $name=>$tag)if(isset($list[$tag['id']])){
//$list[$name]['id'].=','.$tag['id'];
$list[$tag['id']]['u']+=$tag['u'];
foreach($arr as $cap)$list[$tag['id']][$cap].=','.$tag[$cap];
}
else $list[$tag['id']]=$tag;
}
$this->toJson(array($list));
}
else if(($_REQUEST['list']=='age_max'||$_REQUEST['list']=='age_min')&&isset($_REQUEST['val'])&&isset($_REQUEST['i'])&&preg_match("/^[0-9,]*?(-|-)+[0-9,]*?(-|-)+[0-9,]*?(-|-)+[0-9,]*?(-|-)+[0-9,]*$/iu",$_REQUEST['i'])){
$_REQUEST['i']=$this->mydehtmlspecialchars($_REQUEST['i']);
$_REQUEST['i']=preg_split("/(-|-)+/iu",$_REQUEST['i']);
$_REQUEST['i'][0]=preg_split("/(,|,)/iu",$_REQUEST['i'][0]);
if(count($_REQUEST['i'])!=5)$this->toJson(array(array()));
$_REQUEST['val']=preg_replace("/[^0-9]/iu","",$_REQUEST['val']);
if((int)$_REQUEST['i'][4]>0)$am=' and age '.($_REQUEST['list']=='age_max'?'>':'<').$_REQUEST['i'][4];
else $am='';
if((int)$_REQUEST['val']>0)$an=' and age '.($_REQUEST['list']=='age_max'?'<':'>').$_REQUEST['val'];
else $an='';
$list=array(array('u'=>0,'country_id'=>'','region_id'=>'','city_id'=>''));
$arr=array('country_id','region_id','city_id','age');
$group_concat='';
foreach($_REQUEST['i'][0] as $countryId){
$tags=$this->findList('select sum(u) as u'.$group_concat,'tags_'.$this->getTagsTableCountryInd($countryId),'name="" and region_id in ('.$_REQUEST['i'][1].') and city_id in ('.$_REQUEST['i'][2].') and sex_id in ('.$_REQUEST['i'][3].')'.$am.$an,false,20,0,false,false);
$list[0]['id']=$list[0]['name']=$_REQUEST['val'];
$list[0]['u']+=$tags[0]['u'];
$list[0]['country_id'].=','.$countryId;
}
$list[0]['region_id']=$_REQUEST['i'][1];
$list[0]['city_id']=$_REQUEST['i'][2];
$list[0]['sex_id']=$_REQUEST['i'][3];
$list[0]['country_id']=preg_replace("/^[^0-9]+/iu","",$list[0]['country_id']);
if(!isset($list[0]['u'])||!$list[0]['u'])$list=array();
$this->toJson(array($list));
}
else if($_REQUEST['list']=='tag'&&isset($_REQUEST['val'])&&isset($_REQUEST['i'])&&preg_match("/^[0-9,]+?(-|-)+[0-9,]+?(-|-)+[0-9,]+(-|-)+[0-9,]+(-|-)+[0-9,]+(-|-)+[0-9,]+$/iu",$_REQUEST['i'])){
$_REQUEST['i']=$this->mydehtmlspecialchars($_REQUEST['i']);
$_REQUEST['i']=preg_split("/(-|-)+/iu",$_REQUEST['i']);
$_REQUEST['i'][0]=preg_split("/(,|,)/iu",$_REQUEST['i'][0]);
if(count($_REQUEST['i'])!=6)$this->toJson(array(array()));
if((int)$_REQUEST['i'][4]>0)$am=' and age > '.$_REQUEST['i'][4];
else $am='';
if((int)$_REQUEST['i'][5]>0)$an=' and age < '.$_REQUEST['i'][5];
else $an='';
if(!($an.$am))$an.=' and age = 0';
else if($an&&!$am)$am.=' and age > 0';
$list=array();
$arr=array('country_id','region_id','city_id','sex_id');
$group_concat='';
foreach($_REQUEST['i'][0] as $countryId){
$tags=$this->findList('select group_concat(CAST(id as CHAR) SEPARATOR \',\') as id, name, sum(u) as u'.$group_concat,'tags_'.$this->getTagsTableCountryInd($countryId),'name like "'.$_REQUEST['val'].'%" and region_id in ('.$_REQUEST['i'][1].') and city_id in ('.$_REQUEST['i'][2].') and sex_id in ('.$_REQUEST['i'][3].')'.$am.$an,false,20,0,'name','name');
foreach($tags as $name=>$tag){
$tag['age_max']=$_REQUEST['i'][5];
$tag['age_min']=$_REQUEST['i'][4];
$tag['sex_id']=$_REQUEST['i'][3];
$tag['city_id']=$_REQUEST['i'][2];
$tag['region_id']=$_REQUEST['i'][1];
$tag['country_id']=implode(",",$_REQUEST['i'][0]);
$tag['id']=$countryId.":".implode(",".$countryId.":",preg_split("/[^0-9]+/iu",$tag['id']));
if(isset($list[$name])){
$list[$name]['id'].=','.$tag['id'];
$list[$name]['u']+=$tag['u'];
foreach($arr as $cap)$list[$name][$cap].=','.$tag[$cap];
}
else $list[$name]=$tag;
}
}
$this->toJson(array($list));
}
}
public function getItemParamsBySubdId(){
if(isset($_REQUEST['subd_id'])&&$_REQUEST['subd_id']>0)$this->toJson(array('params'=>$this->getAllItemParams($_REQUEST['subd_id']/*,false,'param_'*/)),false,false,false);
}
protected function getAllItemParams($subdId,$raw=false/*,$useParamIdAsId='param_'*/){
$res=array();
if(!isset($useParamIdAsId))$useParamIdAsId='param_';
$params=$this->findList('select /*id*/name'.$this->getCRCNameColumnName().', param_id, CONCAT_WS(\', \', name, name_ru, name_ua, aliases) AS aliases','subdivision_params',array('subd_id'=>$subdId));
if($raw)return $params;
foreach($params as $param){
if($param['name'])$res[$param['name']]=$param[$useParamIdAsId.'id'];
else $res[preg_replace("/^[\s,]*([a-z0-9_ -]+)?[\s\S]*$/iu","$1",$param['aliases'])]=$param[$useParamIdAsId.'id'];
}
return $res;
}
protected function getCountryByName($name,$like="$"){
$nameRE=preg_replace("/([^a-z0-9])/iu","\\\\$1",$name);
foreach($this->Countries as $key => $country)if(preg_match("/^".$nameRE.$like."/iu",$country['name']))return $key;
return 0;
}
protected function getCountryById($id,$i='name'){
return isset($this->Countries[$id][$i])?$this->Countries[$id][$i]:'';
}
protected function getRegionById($id,$i='name'){
if(!$id)return '';
if(isset($this->Regions[$id][$i]))return $this->Regions[$id][$i];
$region = $this->findList('select id'.$this->getCRCNameColumnName().', u, country_id','regions',array('id'=>$id,'is_active'=>1));
if(isset($region[0]))$this->Regions[$id]=$region[0];
else $this->Regions[$id][$i]='';
return $this->Regions[$id][$i];
}
protected function getRegionByName($r,$cId){
if(!$r||!$cId)return 0;
$region=$this->findList('select id'.$this->getCRCNameColumnName().', u, country_id','regions',array('name'=>$r,'country_id'=>$cId,'is_active'=>1));
if(isset($region[0]))$this->Regions[$region[0]['id']]=$region[0];
else{
$this->insert('insert','regions',array('name'=>$r,'country_id'=>$cId,'is_active'=>1,'u'=>0));
$rId = $this->lastInsertId();
$this->Regions[$rId]=array('id'=>$rId,'name'=>$r,'country_id'=>$cId,'u'=>0,'is_active'=>1);
return $this->Regions[$rId]['id'];
}
return $this->Regions[$region[0]['id']]['id'];
}
protected function getCityByName($c,$rId,$cId){
if(!$c||!$rId||!$cId)return 0;
$city=$this->findList('select id'.$this->getCRCNameColumnName().', u, region_id, country_id','cities',array('name'=>$c,'region_id'=>$rId,'is_active'=>1));
if(isset($city[0]))return $city[0]['id'];
else{
$this->insert('insert','cities',array('name'=>$c,'region_id'=>$rId,'country_id'=>$cId,'is_active'=>1,'u'=>0));
$cId = $this->lastInsertId();
return $cId;
}
}
protected function getCountryByRId($id){
if(!$id)return '';
$regions=$this->findList('select id'.$this->getCRCNameColumnName().', u, country_id','regions',array('id'=>$id));
if(isset($regions[0]['country_id']))return $this->getCountryById($regions[0]['country_id']);
return 0;
}
protected function getCountryByCId($id){
if(!$id)return '';
$cities=$this->findList('select id'.$this->getCRCNameColumnName().', u, country_id,region_id','cities',array('id'=>$id));
if(isset($cities[0]['country_id']))return $this->getCountryById($cities[0]['country_id']);
return 0;
}
protected function getCityById($id,$i='name'){
if(!$id)return '';
if(isset($this->Cities[$id][$i]))return $this->Cities[$id][$i];
$city = $this->findList('select id'.$this->getCRCNameColumnName().', u, country_id,region_id','cities',array('id'=>$id));
if(isset($city[0]))$this->Cities[$id]=$city[0];
else $this->Cities[$id][$i]='';
return $this->Cities[$id][$i];
}
protected function getSubdivisionOrBandNames(&$items,$key='subd_id',$table='subdivisions',$id='id'){
$subdNamesArr=array();
$subdIdsStr='';
foreach($items as $k=>$item)if($item[$key]>0&&!preg_match("/(^|,)".$item[$key].",/iu",$subdIdsStr))$subdIdsStr.=$item[$key].',';
if($subdIdsStr){
$subdNamesArr=$this->findList('select '.$id.$this->getCRCNameColumnName().', CONCAT_WS(\', \', name, name_ru, name_ua, aliases) AS aliases',$table,($key=='b_id'?'b_':'').'id in ('.preg_replace("/,+$/","",$subdIdsStr).')',array(),0,0,'id');
foreach($subdNamesArr as $k=>$subdNames)if(!trim($subdNames['name'])&&$subdNames['native_name'])$subdNamesArr[$k]['name']=$subdNames['native_name'];
foreach($items as $k=>$item)if($item[$key]>0&&isset($subdNamesArr[$item[$key]]))$items[$k][$key]=$subdNamesArr[$item[$key]];
}
}
protected function getCRCNames(&$items){
foreach($items as $k=>$man){
if($man['country_id']>0)$items[$k]['country']=$this->getCountryById($man['country_id']);
else $items[$k]['country']='';
if($man['region_id']>0)$items[$k]['region']=$this->getRegionById($man['region_id']);
else $items[$k]['region']='';
if($man['city_id']>0)$items[$k]['city']=$this->getCityById($man['city_id']);
else $items[$k]['city']='';
}
}
protected function getTagById($id,$i='name'){
if(!$id)return '';
if(isset($this->Tags[$id][$i]))return $this->Tags[$id][$i];
$idArr=preg_split("/[^0-9]+/iu",$id);
if(count($idArr)<2){
$idArr[1]=$idArr[0];
$idArr[0]=0;
}
$tag = $this->findList('select *','tags_'.$this->getTagsTableCountryInd($idArr[0]),array('id'=>$idArr[1]));
if(isset($tag[0]))$this->Tags[$id]=$tag[0];
else $this->Tags[$id][$i]='';
return $this->Tags[$id][$i];
}
protected function getTagIdsArr($ta,$loop=false,$doNotAdd=false){
$tIds=array();
$cInd=$this->getTagsTableCountryInd($ta['country_id']);
$limit=$this->limit;
$this->limit=9999;
if(!$doNotAdd){
$qFields='(';
foreach($ta as $k=>$v)$qFields.='`'.$k.'`,';
$qFields=preg_replace("/[,]+$/iu","",$qFields).')';
$q=preg_replace("/[,]+$/iu","",$this->getQueryToAddTags($ta,$loop));
$r=$this->findList('select *','tags_'.$cInd,preg_replace("/\s*or\s*$/iu","",$this->getQueryToSelectTags($ta,$loop)),array(),0,0,'id');
foreach($r as $id=>$v){
if(!$v['age']&&!$v['sex_id']&&!$v['city_id']&&!$v['region_id']&&!$v['country_id'])$r['default']=$id;
$r[$id]=$cInd;
}
if($ta['country_id']!=0){
$ta['country_id']=0;
$ta['region_id']=0;
$ta['city_id']=0;
$q=preg_replace("/[,]+$/iu","",$this->getQueryToAddTags($ta,$loop));
$r=$this->my_array_merge($r,$this->findList('select *','tags_0',preg_replace("/\s*or\s*$/iu","",$this->getQueryToSelectTags($ta,$loop)),array(),0,0,'id'),true);
foreach($r as $id=>$v)if(is_array($v)){
if(!$v['age']&&!$v['sex_id']&&!$v['city_id']&&!$v['region_id']&&!$v['country_id'])$r['default']=$id;
$r[$id]=!is_array($v)||$v['country_id']>0?$cInd:0;
}
}
}
else{
$r=$this->findList('select *','tags_'.$cInd,preg_replace("/\s*or\s*$/iu","",$this->getQueryToSelectTags($ta,$loop)),array(),0,0,'id');
foreach($r as $id=>$v){
if(!$v['age']&&!$v['sex_id']&&!$v['city_id']&&!$v['region_id']&&!$v['country_id'])$r['default']=$id;
$r[$id]=$cInd;
}
if($ta['country_id']!=0){
$ta['country_id']=0;
$ta['region_id']=0;
$ta['city_id']=0;
$r=$this->my_array_merge($r,$this->findList('select *','tags_0',preg_replace("/\s*or\s*$/iu","",$this->getQueryToSelectTags($ta,$loop)),array(),0,0,'id'),true);
foreach($r as $id=>$v){
if(!$v['age']&&!$v['sex_id']&&!$v['city_id']&&!$v['region_id']&&!$v['country_id'])$r['default']=$id;
$r[$id]=!is_array($v)||$v['country_id']>0?$cInd:0;
}
}
}
$this->limit=$limit;
return $r;
}
protected function getQueryToSelectTags($ta,$loop){
if(isset($ta['u']))unset($ta['u']);
$q='(';
foreach($ta as $k=>$v)$q.=$k.'="'.mb_substr($v,0,8,'utf-8').'" and ';
$q=preg_replace("/\s*and\s*$/iu","",$q).') or ';
if(!$loop){
$tac=$ta;
foreach(array('age','sex_id','city_id','region_id') as $k)if($tac[$k]){
$tac[$k]=0;
$q.=$this->getQueryToSelectTags($tac,1);
}
if($ta['age']){
$tac=$ta;
foreach(array('sex_id','city_id','region_id') as $k)if($tac[$k]){
$tac[$k]=0;
$q.=$this->getQueryToSelectTags($tac,1);
}
}
if($ta['sex_id']){
$tac=$ta;
foreach(array('age','city_id','region_id') as $k)if($tac[$k]){
$tac[$k]=0;
$q.=$this->getQueryToSelectTags($tac,1);
}
}
if($ta['age']&&$ta['sex_id']){
$tac=$ta;
$tac['city_id']=$tac['region_id']=0;
$q.=$this->getQueryToSelectTags($tac,1);
}
}
return $q;
}
protected function getQueryToAddTags($ta,$loop){
$q='(';
foreach($ta as $v)$q.='\''.mb_substr(preg_replace("/[']/iu","\\'",$v),0,8,'utf-8').'\',';
$q=preg_replace("/[,]+$/iu","",$q).'),';
if(!$loop){
$tac=$ta;
foreach(array('age','sex_id','city_id','region_id') as $k)if($tac[$k]){
$tac[$k]=0;
$q.=$this->getQueryToAddTags($tac,1);
}
if($ta['age']){
$tac=$ta;
foreach(array('sex_id','city_id','region_id') as $k)if($tac[$k]){
$tac[$k]=0;
$q.=$this->getQueryToAddTags($tac,1);
}
}
if($ta['sex_id']){
$tac=$ta;
foreach(array('age','city_id','region_id') as $k)if($tac[$k]){
$tac[$k]=0;
$q.=$this->getQueryToAddTags($tac,1);
}
}
if($ta['age']&&$ta['sex_id']){
$tac=$ta;
$tac['city_id']=$tac['region_id']=0;
$q.=$this->getQueryToAddTags($tac,1);
}
}
return $q;
}
public function deleteExpiredTags(){
$time=$this->time-(60*60*24*30);
foreach(array('u','b','c','i') as $ubcL)for($i=$this->getRI(0);$i>=$this->getRI(/*$this->total[0]['max_rate_'.$ubcL]*/pow(2,31));$i--){
if($ubcL=='u'){
$tags=$this->findList('select tag,alias_tag_ids,c',$ubcL.'_tag_'.$i,'c<7 and time < '.$time);
$this->insert('delete from',$ubcL.'_tag_'.$i,array(),'c<7 and time < '.$time);//was upside previous row
$this->updateTagsUCount($tags,0,'u=u-1');
}
else $this->insert('delete from',$ubcL.'_tag_'.$i,array(),'time < '.$time);
}
}
function formatLink($link){
$link=trim($this->mydehtmlspecialchars($link));
if(!trim($link))return '#';
else if(preg_match('/^(http|ftp|\/)/iu',$link))return $link;
else if(preg_match('/^[a-z0-9_-]+\.[a-z0-9_-]+/iu',$link))return 'http://'.$link;
else return $link;
}
protected function fillItemsFSData(&$items,$l='u',$key='u_id',$p2pChainsNeeded=false){
$uIns=false;
if($l=='u'){
$ins=$this->getIns($items,$key,true,'unreg',0);
$uIns=$this->getIns($items,$key,true,'unreg');
}
else $ins=$this->getIns($items,$key);
$Items=array();
foreach($ins as $ti=>$in)if($ti>0)$Items=$this->my_array_merge($Items,$this->findList('select *',$l.'_'.$ti,'id in ('.preg_replace("/,+$/iu","",$in).')',array(),0,0,'id'));
if($uIns)foreach($uIns as $ti=>$in)$Items=$this->my_array_merge($Items,$this->findList('select *',$l.'_u','u_id in ('.preg_replace("/,+$/iu","",$in).')',array(),0,0,'id'));
foreach($items as $k=>$item)if(isset($Items[$item[$key]]))$items[$k]=array_merge($item,$this->getItemFSArr($Items[$item[$key]],array_merge(array('name'=>$Items[$item[$key]]['name'],'seriename'=>isset($Items[$item[$key]]['seriename'])?$Items[$item[$key]]['seriename']:'','url'=>$Items[$item[$key]]['url'],'priv'=>$Items[$item[$key]]['priv'],'pd'=>isset($Items[$item[$key]]['pd'])?$Items[$item[$key]]['pd']:0),isset($Items[$item[$key]]['nickname'])?array('nickname'=>$Items[$item[$key]]['nickname'],'surname'=>$Items[$item[$key]]['surname']):array())));
if(!$this->affectedItemType)$this->affectedItemType=$this->lArr[$l];
foreach($Items as $k=>$item)$this->updateItemRateInOriginalTable($this->updateItemRatesInGlobalTables($item,0),$l.'_'.$this->getTI($item['id'],$this->getPlural($this->lArr[$l])),$item['id']);
if($l=='u'){
$this->getCRCNames($items);//7.0 &$items
foreach($items as $k=>$item){
if(isset($item['unreg']))$items[$k]['priv']=1;
}
}
else if($l=='i'){
$this->getSubdivisionOrBandNames($items);//7.0 &$items
$this->getSubdivisionOrBandNames($items,'b_id','bands','b_id as id');//7.0 &$items
}
}
protected function getTagsTableCountryInd($cId){
return ceil($cId/10);
}
protected function getTagsTableCountryQueryRageFromInd($ind,$l='u'){
if($l!='u')return 1;
$min=$ind*10-10;
$max=$ind*10+1;
return 'country_id > '.$min.' and country_id < '.$max;
}
/**
* Generates string containing ids of tags separated with "," for further usage in sql queries
*
* array $tagIds - array of tag ids of this structure array(array('alias_tag_ids','c'))
* int $c - border value. If $tagId['c'] less than $c than this object will not be used during generating resulting $tagIdsStr
* boolean $simple - if set to false than tag ids can be repeated into resulting $tagIdsStr
*/
protected function getTagIdsStr($tagIds,$c=0,$simple=false){
$tagIdsStr='';
$tagIdsArr=array();
if($simple){
if(!$c)foreach($tagIds as $tagId)$tagIdsStr.=$tagId['alias_tag_ids'].',';
else foreach($tagIds as $tagId)if($tagId['c']>$c)$tagIdsStr.=$tagId['alias_tag_ids'].',';
return $tagIdsStr;
}
else foreach($tagIds as $tagId)if($tagId['c']>$c){
$arr=preg_split("/^[0-9]+/iu",$tagId['alias_tag_ids']);
$arr=array_flip($arr);
$tagIdsArr=array_merge($tagIdsArr,$arr);
}
$tagIdsArr=array_flip($tagIdsArr);
return preg_replace("/[^0-9]+$/iu","",implode(",",$tagIdsArr));
}
protected function getTagFirstCase($tag){
return $tag;
}
protected function getZ_I_T_Q($S,$asChat=false){
$_REQUEST['query']='1';
if($asChat)$_REQUEST['query'].=' and time > '.($this->time-self::UPDATE_TIME*1.2);
}
protected function getTagQuery($val,$tagRowName='tag'){
$ss='';
$val=preg_split("/[^a-z0-9а-я]+/iu",$val);
$i=0;
foreach($val as $v)if($v){
$ss.='name like "'.$v.'%" or ';
if($i++>3)break;
}
$tags=$this->findList('select id,name','tags_0','region_id = 0 and city_id = 0 and age = 0 and sex_id = 0 '.($ss?'and ('.mb_substr($ss, 0, -4,'utf-8').')':""));
$ss='';
if(isset($tags[0]['id']))foreach($val as $v){
foreach($tags as $tag){
if(preg_match("/^".substr($v,0,8)."/iu",$tag['name'])){
$ss.=$tagRowName.' like "'.$v.'%" or ';
break;
}
}
}
return $ss?mb_substr($ss, 0, -4,'utf-8'):'1';
}
protected function getRequestPostIndex($index){
if(isset($_REQUEST['val']))$index='post_'.$index.'_'.$_REQUEST['val'];
if(isset($_REQUEST['country_id'])&&$_REQUEST['country_id'])$index.='_c'.$_REQUEST['country_id'];
if(isset($_REQUEST['region_id'])&&$_REQUEST['region_id'])$index.='_r'.$_REQUEST['region_id'];
if(isset($_REQUEST['city_id'])&&$_REQUEST['city_id'])$index.='_cit'.$_REQUEST['city_id'];
if(isset($_REQUEST['age_min'])&&$_REQUEST['age_min'])$index.='_an'.$_REQUEST['age_min'];
if(isset($_REQUEST['age_max'])&&$_REQUEST['age_max'])$index.='_ax'.$_REQUEST['age_max'];
if(isset($_REQUEST['sex_id'])&&$_REQUEST['sex_id'])$index.='_s'.$_REQUEST['sex_id'];
if(isset($_REQUEST['subd_id'])&&$_REQUEST['subd_id'])$index.='_subd'.$_REQUEST['subd_id'];
if(isset($_REQUEST['band_id'])&&$_REQUEST['band_id'])$index.='_band'.$_REQUEST['band_id'];
for($i=1;$i0)$index.='_p'.$i.'id'.$_REQUEST['p'.$i.'_id'];
return $index;
}
protected function getRequestPostQuery($query,$c=1,$val=false,$t=true,$tagRowName='tag'){
if(!$val&&isset($_REQUEST['val']))$val=$_REQUEST['val'];
if($val&&(!$t||mb_strlen($val)%3==0))$query.=' and ('.$this->getTagQuery($val,$tagRowName).')'.($t?' and time > '.(pow(2,31)-3):'');
if(isset($_REQUEST['sex_id'])&&$_REQUEST['sex_id']>0)$query.=' and sex_id = '.$_REQUEST['sex_id'];
if($c&&isset($_REQUEST['country_id'])&&$_REQUEST['country_id']>0)$query.=' and country_id = '.$_REQUEST['country_id'];
if(isset($_REQUEST['region_id'])&&$_REQUEST['region_id']>0)$query.=' and region_id = '.$_REQUEST['region_id'];
if(isset($_REQUEST['city_id'])&&$_REQUEST['city_id']>0)$query.=' and city_id = '.$_REQUEST['city_id'];
if(isset($_REQUEST['age_min'])&&$_REQUEST['age_min']>0){
$ud=($this->time-31556926*$_REQUEST['age_min']);
if($ud>0)$query.=' and birthdate < '.$ud;
}
if(isset($_REQUEST['age_max'])&&$_REQUEST['age_max']>0){
$ud=($this->time-31556926*$_REQUEST['age_max']);
if($ud>0)$query.=' and birthdate > '.$ud;
}
if(isset($_REQUEST['subd_id'])&&$_REQUEST['subd_id']>0)$query.=' and subd_id = '.$_REQUEST['subd_id'];
if(isset($_REQUEST['band_id'])&&$_REQUEST['band_id']>0)$query.=' and b_id = '.$_REQUEST['band_id'];
for($i=1;$i0){
$query.=' and `'.$i.'p` = "'.$_REQUEST['p'.$i.'_id'].'"';
}
if(isset($_REQUEST['unapproved_people']))$query.=' and approved = 0';
return $query;
}
protected function putListToG($index,$arr,$a_p=false,$a_v=false,$global=false){
if(!isset($GLOBALS['G']['CUser'])){
if($this->isLU())if(isset($_REQUEST['CUser']))$GLOBALS['G']['CUser']=$this->CUser[0];
else $GLOBALS['G']['CUser']=array('id'=>$this->CUser[0]['id'],'url'=>$this->CUser[0]['url'],'s_info'=>$this->CUser[0]['s_info']);
}
if(!isset($this->Item[0]['id'])&&isset($this->CUser[0]['id'])/*||isset($this->parent)&&$this->parent=='user'&&$this->Item[0]['id']=$this->CUser[0]['id']*/)$this->Item=&$this->CUser;
if($global)$GLOBALS['G']['global'][$index]=$arr;
else if(isset($this->Item[0]['id'])){
if(isset($this->parent))$parent=$this->parent;
else $parent = 'user';
if($parent=='user'&&$this->isLU()&&$this->Item[0]['id']==$this->CUser[0]['id']){
if(isset($_REQUEST['fullitem']))$this->getJVCU($this->CUser[0],'CUser');
$GLOBALS['G']['CUser'][$index]=$arr;
if($a_p)$GLOBALS['G']['CUser'][$a_p]=$a_v;
}
else{
if(isset($_REQUEST['fullitem'])){
$this->Item[0][$index]=$arr;
if($parent=='user'){
if($this->Item[0]['priv']<4||$this->isFriend($this->Item[0]['id'],$this->CUser[0]['id'])&&$this->Item[0]['priv']<6)$this->getJVCU($this->Item[0],'user');//7.0 &$this->Item[0]
else $this->getJVPU($this->Item[0]);//7.0 &$this->Item[0]
}
else if($parent=='band'){
if($this->Item[0]['priv']<4||$this->approvedInto($this->Item[0]['id'],$this->CUser[0]['id'],$parent)&&$this->Item[0]['priv']<6||$this->isAdmin)$this->getJVCB($this->Item[0]);//7.0 &$this->Item[0]
else $this->getJVPU($this->Item[0],'band');//7.0 &$this->Item[0]
}
else if($parent=='chat'){
if($this->Item[0]['priv']<4||$this->approvedInto($this->Item[0]['id'],$this->CUser[0]['id'],$parent)&&$this->Item[0]['priv']<6||$this->isAdmin)$this->getJVCB($this->Item[0],'chat');//7.0 &$this->Item[0]
else $this->getJVPU($this->Item[0],'chat');//7.0 &$this->Item[0]
}
else if($parent=='item'){
if($this->Item[0]['priv']<4||$this->approvedInto($this->Item[0]['id'],$this->CUser[0]['id'],$parent)&&$this->Item[0]['priv']<6||$this->isAdmin)$this->getJVCB($this->Item[0],'item');//7.0 &$this->Item[0]
else $this->getJVPU($this->Item[0],'item');//7.0 &$this->Item[0]
}
}
else{
$GLOBALS['G'][$parent][$_REQUEST[$parent]]['id']=$this->Item[0]['id'];
$GLOBALS['G'][$parent][$_REQUEST[$parent]]['url']=$this->Item[0]['url'];
$GLOBALS['G'][$parent][$_REQUEST[$parent]][$index]=$arr;
}
if($a_p&&($this->parent!='user'&&$this->isLU()&&$this->approvedInto($this->Item[0]['id'],$this->CUser[0]['id'],$parent)&&isset($this->isAdmin)&&$this->isAdmin||$parent=='user'&&$this->isLU()&&$this->Item[0]['id']==$this->CUser[0]['id'])){
$GLOBALS['G'][$parent][$_REQUEST[$parent]][$a_p]=$a_v;
}
}
}
}
/**
* Generates fsArr from $Item and ads to it params from $seviceVals array. Excludes
*
* @param array $Item
* @param array $seviceVals array('name'=>val,'nickname'=>val,'surname'=>val,'url'=>val,'attendance'=>val,'pd'=>val,'slogan'=>val,'priv'=>val,'p2pId'=>val,'last_m'=>val,'unreg'=>val,'mutual'=>val,'admin'=>val,'approved'=>val,'u_id'=>val,'b_id'=>val,'c_id'=>val,'i_id'=>val,'man_id'=>val,'unread_count'=>val,'messages_count'=>val,'to'=>val,'g'=>val,'path_id'=>val,'p_id'=>val,'l'=>val,'from_name'=>val,'from_id'=>val,'from_url'=>val)
* @param string $idIndex man|u|b|c|i
* @param int $time
* @return array fsArr
*/
protected function getItemFSArr($Item,$seviceVals=false,$idIndex=false,$time=false){
//do not change sequence, news_fs has special sequence
//`name`,`nickname`,`surname`,`country_id`,`region_id`,`city_id`,`sex`,`priv`,`likes_count`,`url`
$arr=array('subd_id','b_id','country_id','region_id','city_id','sex_id','birthdate');
$serviceKeys=array('name','nickname','surname','seriename','url','attendance','slogan','priv'/*,'p2pId'*/,'pd','last_m','unreg','mutual','admin','approved','u_id','i_id','b_id','c_id','man_id','unread_count','messages_count','to','g','path_id','p_id','l','from_name','from_id','from_url');
if(!$time)$time=$this->time;
$item=array();
foreach($arr as $val)if(isset($Item[$val]))$item[$val]=$Item[$val];
if(isset($seviceVals['likes_count'])&&isset($Item['likes_count'])){
if(isset($Item['likes_count'])&&isset($Item['id']))$item['likes_count']=!preg_match("/\./iu",$Item['likes_count'])?$Item['likes_count'].'.'.$Item['id']:$Item['likes_count'];
else $item['likes_count']=$seviceVals['likes_count'];
unset($seviceVals['likes_count']);
}
if(isset($seviceVals['rate'])&&isset($Item['rate'])){
if(isset($Item['rate']))$item['rate']=$Item['rate'];
else $item['rate']=$seviceVals['rate'];
unset($seviceVals['rate']);
}
$item['time']=$time;
if($seviceVals)foreach($serviceKeys as $val)if(isset($seviceVals[$val]))$item[$val]=$seviceVals[$val];
if($idIndex)$item[$idIndex.'_id']=$Item['id'];
return $item;
}
protected function getItemFSArrInsertQuery($table,$SupItemId,$SubItem,$supL,$subL,$itemIds=array()){
if(preg_match('/_bls_/iu',$table))$serviceVals=array('attendance'=>1);
else if(preg_match('/_musers_/iu',$table))$serviceVals=array('priv'=>$SubItem['priv'],'last_m'=>$SubItem['last_m'],'unread_count'=>$SubItem['unread_count'],'messages_count'=>$SubItem['messages_count'],'to'=>$SubItem['to'],'g'=>$SubItem['g']);
else if(preg_match('/_news_fs_/iu',$table))$serviceVals=array('i_id'=>$SubItem['i_id'],'l'=>$SubItem['l'],'p_id'=>$SubItem['p_id'],'path_id'=>$SubItem['path_id']);
else if($supL=='u'){
$serviceVals=array('attendance'=>1,'name'=>$SubItem['name'],'priv'=>$SubItem['priv'],'pd'=>$SubItem['pd'],'url'=>$SubItem['url']);
if($subL=='u'){
$serviceVals=array_merge($serviceVals,array('nickname'=>$SubItem['nickname'],'surname'=>$SubItem['surname']/*,'p2pId'=>isset($SubItem['mutual'])&&$SubItem['mutual']?$SubItem['p2pId']:''*/));
if(isset($SubItem['mutual']))$serviceVals['mutual']=$SubItem['mutual'];
}
else{
if($subL=='i')$serviceVals['seriename']=1;
$serviceVals=array_merge($serviceVals,array('admin'=>$SubItem['admin'],'approved'=>$SubItem['approved']));
}
}
else if($supL=='b'||$supL=='c'||$supL=='i'){
if($subL=='u'){
$serviceVals=array('attendance'=>1);
if($SubItem['id']>$this->total[0]['users'])$serviceVals['unreg']=1;
else $serviceVals=isset($SubItem['admin'])&&isset($SubItem['approved'])?array_merge($serviceVals,array('admin'=>$SubItem['admin'],'approved'=>$SubItem['approved'])):$serviceVals;
}
else $serviceVals=array('rate'=>$SubItem['rate']);
}
$fsArr=$this->getItemFSArr($SubItem,$serviceVals);
if(isset($fsArr[$supL.'_id']))unset($fsArr[$supL.'_id']);
$name=count($SubItem)>0?trim((isset($SubItem['seriename'])?$SubItem['seriename'].' ':'').(isset($SubItem['name'])?$SubItem['name']:'').' '.(isset($SubItem['nickname'])?$SubItem['nickname'].' ':'').(isset($SubItem['surname'])?$SubItem['surname']:'')):'';
$tags=$this->updateItemTag(1,false,array($SubItem),$subL,preg_split("/[^a-z0-9а-яїє]+/iu",$name),false,1,0,true);
if(!$tags||count($tags)==0)return false;
$keys='(`tag`,`tag_id`';
if(!is_array($itemIds)||!count($itemIds))$keys='(`tag`,`tag_id`,`'.$supL.'_id`,`'.($subL==$supL&&$subL=='u'?'man':$subL).'_id`';
else foreach($itemIds as $k=>$v){
if(isset($fsArr[$k]))unset($fsArr[$k]);
$keys.=',`'.$k.'`';
}
$vals='';
$valsStr='';
foreach($fsArr as $key=>$val){
$valsStr.=',"'.$val.'"';
$keys.=',`'.$key.'`';
}
$keys.=')';
if(!is_array($itemIds)||!count($itemIds))foreach($tags as $tId=>$tag)$vals.='("'.$tag.'",'.$tId.','.$SupItemId.','.$SubItem['id'].$valsStr.'),';
else foreach($itemIds as $k=>$a)foreach($a as $itemId)foreach($tags as $tId=>$tag)$vals.='("'.$tag.'",'.$tId.','.$itemId.$valsStr.'),';
return 'insert into '.$table.' '.$keys.' values '.mb_substr($vals,0,-1,'utf-8');
}
protected function getSubItemFSArrInserQuery($table,$ParentId,$SubItem,$tags=false){
$priv=isset($SubItem['priv'])?'`priv`,':'';
$set='insert into '.$table.' (`p_id`,`id`,'.$priv.'`tag`,`tag_id`,`likes_count`) values ';
if(!$tags)$tags=$this->updateItemTag(1,$this->CUser,$this->Item,$this->parentL,preg_split("/[^a-z0-9а-яїє]+/iu",trim($SubItem['name'].' '.$SubItem['description'])));
if(!isset($SubItem['likes_count']))$SubItem['likes_count']=0;
foreach($tags as $tId=>$tag)$set.='('.$ParentId.','.$SubItem['id'].','.(isset($SubItem['priv'])?$SubItem['priv'].',':'').'"'.$tag.'","'.$tId.'",'.$SubItem['likes_count'].'),';
return mb_substr($set,0,-1,'utf-8');
}
protected function getUnregUId(){
return rand($this->total[0]['users']*2+1000000, ($this->total[0]['users']*2+1000000)*2);
}
protected function createMail($val='',$index='reg'){
if($index == 'reg')$message = t('reg',array('link'=>$this->getLink(array('conf' => $this->rn, 'user' => $this->CUser[0]['id']),'http://'.$this->domain.'/#')));
else if($index == 'ce')$message = t('ce',array('email'=>$val));
else if($index == 'cp')$message = t('cp');
else if($index == 'd')$message = t('d');
else if($index == 'rp')$message = t('rp',array('link'=>$this->getLink(array('reset'=>$this->rn,'user'=>$val),'http://'.$this->domain.'/#')));
ob_start();
include './html/blank.html';
$content = ob_get_clean();
return $content;
}
private function setLang($cId){
if(isset($_COOKIE['l']))$_REQUEST['l'] = $_COOKIE['l'];
if(isset($_GET['l'])&&trim($_GET['l']))$_REQUEST['l'] = $_GET['l'];
if(!isset($_REQUEST['l'])){
if($cId==45)$_REQUEST['l'] = 'ua';
else if($cId==153)$_REQUEST['l'] = 'ru';
else $_REQUEST['l'] = 'en';
$this->mysetcookie('l',$_REQUEST['l']);
}
else if(isset($_REQUEST['l']) && $_REQUEST['l'] != 'ua' && $_REQUEST['l'] != 'ru')$_REQUEST['l'] = 'en';
}
public function changeLang(){
if(isset($_REQUEST['ch_l'])){
if($this->isLU()){
$this->CUserChanges['l']=true;
$this->CUser[0]['l']=$_REQUEST['ch_l'];
$this->mysetcookie('l',$_REQUEST['ch_l']);
}
else $this->mysetcookie('l',$_REQUEST['ch_l']);
$this->toJson(array('done'));
}
else $this->toJson(array('err'=>'error'));
}
protected function setKyka(){
$this->CUserChanges['kyka'] = true;
$this->CUser[0]['kyka'] = $this->rn = $this->getRandom($this->time / rand(1, 1000));
$this->mysetcookie('kyka', $this->rn);
$this->mysetcookie('user', $this->CUser[0]['id']);
$this->mysetcookie('url', $this->CUser[0]['url']);
}
protected function getSexId($sex){
if(preg_match("/female/iu",$sex))return 2;
else if(preg_match("/male/iu",$sex))return 1;
else if(preg_match("/2/iu",$sex))return 1;
else return 0;
}
protected function getSexById($sex){
if(((int)$sex)==2)return 'female';
else if(((int)$sex)==1)return 'male';
else if(((int)$sex)==0)return '';
else return '';
}
public function toJson($a = '', $u=false, $priv = false, $onClose=true){
$res = 0;
$this->saveCUserChanges();
$this->saveItemsChanges();
if(is_array($a)){
if($u&&$priv!==false&&isset($_REQUEST['fullitem'])&&isset($_REQUEST[$u])&&!isset($GLOBALS['G'][$u][$_REQUEST[$u]])){
if($u=='user'&&isset($this->Item[0]['id'])){
if($priv<4)$this->getJVCU($this->Item[0]);
else $this->getJVPU($this->Item[0]);
}
}
else if(isset($_REQUEST['fullitem'])){
foreach($this->lArr as $k)if(isset($_REQUEST['fullitem'])&&isset($this->Item[0]['id'])&&isset($_REQUEST[$k])&&!isset($GLOBALS['G'][$k][$_REQUEST[$k]])){
if($this->Item[0]['priv']<2||$this->isLU()&&$this->Item[0]['priv']<4)$this->getJVCU($this->Item[0]);
else if(!$this->isLU()||($this->Item[0]['priv'] > 5 || ($this->Item[0]['priv'] == 4 || $this->Item[0]['priv'] == 5) && ($k=='user'&&!$this->isFriend($this->Item[0]['id'],$this->CUser[0]['id'])||$k!='user'&&!$this->approvedInto($this->Item[0]['id'],$this->CUser[0]['id'],$k)))&&$this->Item[0]['priv']!=7)$this->getJVPU($this->Item[0]);
break;
}
}
$res = $this->my_array_merge($a, isset($GLOBALS['G'])&&is_array($GLOBALS['G'])?$GLOBALS['G']:array());
}
if(isset($GLOBALS['page'])){
if(isset($a['error']))$message=t($a['error']);
if($this->parent&&method_exists($this,'isLU')&&isset($this->CUser[0]['id'])&&!isset($this->CUser[0]['unreg'])&&(!isset($this->Item[0]['id'])||$this->CUser[0]['id']==$this->Item[0]['id'])){
if(isset($GLOBALS['G']['CUser']['id']))$GLOBALS['G']['user'][$GLOBALS['G']['CUser']['id']]=$GLOBALS['G']['CUser'];
else $GLOBALS['G']['user'][$this->CUser[0]['id']]=$this->CUser[0];
if($this->CUser[0]['url'])$GLOBALS['G']['user'][$this->CUser[0]['url']]=&$this->CUser[0];
}
setGlobalPath(isset($this->parent)?$this->parent:false,$this);
if(isset($_REQUEST['comments'])&&isset($_REQUEST['reply_to_p_id'])&&isset($a['comments'])){
$L=&$GLOBALS['G'];
for($i=0;$iisset($GLOBALS['path'][$i+1])&&$GLOBALS['path'][$i+1]>0?$GLOBALS['path'][$i+1]:0);
$L=&$L[$GLOBALS['path'][$i]];
}
}
include "./html/blank.html";
}
else echo json_encode($res);
if(isset($res['error']))exit;
if($onClose)$this->checkIfClosedSInfoRemains();
exit;
}
}
$smallLang = array(
'en' => array(
'404' => 'Error 404 - page doesn\'t exist!',
'acountries' => 'All countries',
'any' => 'Any',
'adr' => 'Account deleting report',
'badbrowser' => 'Oops, it seems your javascript disabled or you have a very old web browser the same one as ancient egyptians used to build pyramids! You can use one of this -
,
,
,
',
'ce' => 'You have successfully changed your e-mail to ---pin-email-pin---. Now you should use it to login!',
'copy' => 'PAPARAZZIINNEED © 2011',
'cp' => 'Your password has been successfully changed.',
'cpr' => 'Changing password report',
'd' => 'Your account has been successfully deleted.',
'ecr' => 'E-mail changing report',
'pin' => 'PAPARAZZIINNEED - first and only star factory in the world',
'prt' => 'Password reseting on PAPARAZZIINNEED',
'reg' => 'Hi! Few minutes ago you\'ve created a new account on paparazziinneed.com. Follow this link ---pin-link-pin--- to confirm your e-mail.
If it wasn\'t you then don\'t pay attention on this message...',
'registrationonpin' => 'Registration on PAPARAZZIINNEED',
'rp' => 'You were requesting for password recovery. Follow this link ---pin-link-pin--- to reset your password.
If it wasn\'t you then somebody else is interested of your account pass:)',
'rpt' => 'Password reset report on PAPARAZZIINNEED',
'sb' => 'Somebody',
'sitemap' => 'Sitemap PAPARAZZIINNEED.COM',
'yecs' => 'Your email has been successfully changed to ---pin-email-pin---! Now you should use it for your login!'
),
'ru' => array(
'404' => 'Ошибка 404 - страница не существует!',
'acountries' => 'Все страны',
'any' => 'Любой',
'adr' => 'Отчет об удалении акаунта',
'badbrowser' => 'Упс, кажется javascript не работает или у Вас очень старый браузер, настолько старый что им пользовались еще древние египтяне для постройки пирамид! Скачайте один из этих -
,
,
,
',
'ce' => 'Вы успешно поменяли Ваш email ---pin-email-pin---. Теперь используйте его для входа на сайт!',
'copy' => 'PAPARAZZIINNEED © 2011',
'cp' => 'Ваш пароль успешно изменен.',
'cpr' => 'Отчет об изменении пароля',
'd' => 'Ваш акаунт был успешно удален.',
'ecr' => 'Отчет об изменении e-mail',
'pin' => 'PAPARAZZIINNEED - просто круто',
'prt' => 'Изменение пароля на PAPARAZZIINNEED',
'reg' => 'Здраствуйте! Пару минут назад Вы создали новый аккаунт на сайте paparazziinneed.com. Кликните по этой ссылке ---pin-link-pin--- для подтверждения e-mail.
Если же Вы ничего не создавали, тогда не обращайте внимания на это сообщение...',
'registrationonpin' => 'Регистрация на PAPARAZZIINNEED',
'rp' => 'Вы попосили о восстановлении Вашего пароля. Следуйте по этой ссылке ---pin-link-pin--- что бы восстановит Ваш пароль.
Если это были не Вы, знасит кто то плохой заинтересовался Вашим аккаунтом:)',
'rpt' => 'Отчет о восстановлении пароля на PAPARAZZIINNEED',
'sb' => 'Кто-то',
'sitemap' => 'Карта сайта PAPARAZZIINNEED.COM',
'yecs' => 'Ваш email был успешно изменен на ---pin-email-pin---! Теперь используйте его для входа на сайт!'
),
'ua' => array(
'404' => 'Помилка 404 - сторінки не існує!',
'acountries' => 'Всі країни',
'any' => 'Будь який',
'adr' => 'Звіт про видалення акаунта',
'badbrowser' => 'Упс, здається javascript не працює або у Вас дуже старий браузер, настільки старий що їм користувалися древні єгіптяне для констроювання пірамід! Завантажте один из цих -
,
,
,
',
'ce' => 'Ви успішно змінили Ваш email ---pin-email-pin---.Тепер використовуйте його для входу на сайт!',
'copy' => 'PAPARAZZIINNEED © 2011',
'cp' => 'Ваш пароль успішно змінений.',
'cpr' => 'Звіт про зміну пароля',
'd' => 'Ваш аккаунт був успішно видалений.',
'ecr' => 'Звіт про зміну e-mail',
'pin' => 'PAPARAZZIINNEED - просто круто',
'prt' => 'Зміна пароля на PAPARAZZIINNEED',
'reg' => 'Здрастуйте! Пару хвилин тому Ви створили новий акаунт на сайті paparazziindeed.com. Клацніть по цьому посиланню ---pin-link-pin--- для підтвердження e-mail.
Якщо ж Ви нічого не створювали, тоді не звертайте уваги на це повідомлення...',
'registrationonpin' => 'Реєстрация на PAPARAZZIINNEED',
'rp' => 'Ви попросили про відновлення паролю. Слідуйте за цим посиланням ---pin-link-pin--- щоб відновити Ваш пароль.
Якщо це були не Ви, значить хтось поганий зацікавився Вашим акаунтом:)',
'rpt' => 'Звіт про відновлення пароля на PAPARAZZIINNEED',
'sb' => 'Хтось',
'sitemap' => 'Мапа сайту PAPARAZZIINNEED.COM',
'yecs' => 'Ваш e-mail був успішно змінений на ---pin-email-pin---! Тепер використовуйте його для входу на сайт!'
)
);
if(isset($lang))$smallLang=my_array_merge_recursive($smallLang,$lang);
function my_array_merge_recursive($arr1,$arr2){
foreach($arr2 as $k2=>$v2){
if(isset($arr1[$k2])&&is_array($arr1[$k2])){
$arr1[$k2]=my_array_merge_recursive($arr1[$k2],$v2);
}
else $arr1[$k2]=$v2;
}
return $arr1;
}
function t($i,$vals=array()){
global $smallLang;
$i = strtolower($i);
$d=debug_backtrace();
if($i==''||!isset($_REQUEST['l']))return '';
if(isset($smallLang[$_REQUEST['l']][$i])&&is_array($vals)){
foreach($vals as $key => $val){
$smallLang[$_REQUEST['l']][$i]=preg_replace("/---pin-".$key."-pin---/iu",$val,$smallLang[$_REQUEST['l']][$i]);
}
}
return isset($smallLang[$_REQUEST['l']][$i]) ? $smallLang[$_REQUEST['l']][$i] : '**'.$i;
}
error_reporting(E_ALL);
require_once './object.php';
class Capcha extends Obj{
private $im;
private $tmpimg;
private $image_width = 150;
private $image_height = 30;
private $iscale = 5;
private $num_lines = 5;
private $gdbgcolor;
private $image_bg_color = array('r' => 255, 'g' => 255, 'b' => 255);
private $text_color = array('r' => 61, 'g' => 61, 'b' => 61);
private $gdtextcolor;
private $line_color = array('r' => 61, 'g' => 61, 'b' => 61);
private $gdlinecolor;
private $code;
private $ttf_file = __DIR__ . '/AHGBold.ttf';
private $text_angle_minimum = 10;
private $text_angle_maximum = 20;
private $perturbation = 0.7;
private $image_type = 'jpg';
private $charset = 'abcdefghijklmnopqrstuvwxyz123456789';//look to object myDecode($charset=5)
private $code_length = 5;
private $ec=null;
public function getImage(){
$this->checkIfCapchaExists();
$this->im = imagecreate($this->image_width, $this->image_height);
$this->tmpimg = imagecreate($this->image_width * $this->iscale, $this->image_height * $this->iscale);
$this->allocateColors();
imagepalettecopy($this->tmpimg, $this->im);//???
$this->setBackground();
$this->code = $this->createCode();
$this->saveData($this->code);
$this->drawWord();
$this->distortedCopy();
$this->drawLines();
$this->output();
}
private function checkIfCapchaExists(){
if(!isset($_COOKIE['alert_double_request'])){
$_COOKIE['alert_double_request']=$this->getRandom($this->time);
$this->mysetcookie('alert_double_request',$_COOKIE['alert_double_request']);
$this->ec=false;
}
else{
$this->ec=$this->findList('select *','capcha','alert_double_request = "'.$_COOKIE['alert_double_request'].'" and time > '.($this->time-5),array('time'=>'desc'),1);
}
}
private function allocateColors(){
$this->gdbgcolor = imagecolorallocate($this->im, $this->image_bg_color['r'], $this->image_bg_color['g'], $this->image_bg_color['b']);
$this->gdtextcolor = imagecolorallocate($this->im, $this->text_color['r'], $this->text_color['g'], $this->text_color['b']);
$this->gdlinecolor = imagecolorallocate($this->im, $this->line_color['r'], $this->line_color['g'], $this->line_color['b']);
}
private function setBackground(){
imagefilledrectangle($this->im, 0, 0, $this->image_width * $this->iscale, $this->image_height * $this->iscale, $this->gdbgcolor);
imagefilledrectangle($this->tmpimg, 0, 0, $this->image_width * $this->iscale, $this->image_height * $this->iscale, $this->gdbgcolor);
}
private function saveData($code){
if(isset($this->ec[0]['capcha']))return false;
$code = $this->myEncode($code);
if(!isset($code['capcha']))return false;
$this->mysetcookie('capcha', $code['capcha']);
$this->mysetcookie('capcha_kyka', $code['capcha_kyka']);
}
private function drawWord(){
$strlen = strlen($this->code);
for($i = 0; $i < $strlen; $i++){
$r = rand(1, 2);
if($r%2 == 0)$this->code[$i] = strtoupper($this->code[$i]);
}
$width2 = $this->image_width * $this->iscale;
$height2 = $this->image_height * $this->iscale;
$font_size = $height2 * 0.6;
$bb = imagettfbbox($font_size, 0, $this->ttf_file, $this->code);
$tx = $bb[4] - $bb[0];
$ty = $bb[5] - $bb[1];
$x = floor($width2 / 2 - $tx / 1.5 - $bb[0]);
$y = round($height2 / 2 - $ty / 2 - $bb[1]);
if($this->text_angle_minimum == 0 && $this->text_angle_maximum == 0)imagettftext($this->tmpimg, $font_size, 0, $x, $y, $this->gdtextcolor, $this->ttf_file, $this->code);
else for($i = 0; $i < $strlen; ++$i) {
$angle = rand($this->text_angle_minimum, $this->text_angle_maximum);
$y = rand($y - 5, $y + 5);
$font_color = $this->gdtextcolor;
$ch = $this->code[$i];
imagettftext($this->tmpimg, $font_size, $angle, $x, $y, $font_color, $this->ttf_file, $ch);
$min_x = $font_size + ($this->iscale * 2);
$max_x = $font_size + ($this->iscale * 5);
$x += rand($min_x, $max_x);
}
}
private function distortedCopy(){
$numpoles = 2; // distortion factor
for($i = 0; $i < $numpoles; ++$i){
$px[$i] = rand($this->image_width * 0.3, $this->image_width * 0.7);
$py[$i] = rand($this->image_height * 0.3, $this->image_height * 0.7);
$rad[$i] = rand($this->image_width * 0.4, $this->image_width * 0.7);
$tmp = -$this->frand() * 0.15 - 0.15;
$amp[$i] = $this->perturbation * $tmp;
}
$bgCol = imagecolorat($this->tmpimg, 0, 0);
$width2 = $this->iscale * $this->image_width;
$height2 = $this->iscale * $this->image_height;
imagepalettecopy($this->im, $this->tmpimg); // copy palette to final image so text colors come across
for($ix = 0; $ix < $this->image_width; ++$ix){
for($iy = 0; $iy < $this->image_height; ++$iy){
$x = $ix;
$y = $iy;
for($i = 0; $i < $numpoles; ++$i){
$dx = $ix - $px[$i];
$dy = $iy - $py[$i];
if($dx == 0 && $dy == 0)continue;
$r = sqrt($dx * $dx + $dy * $dy);
if($r > $rad[$i])continue;
$rscale = $amp[$i] * sin(3.14 * $r / $rad[$i]);
$x += $dx * $rscale;
$y += $dy * $rscale;
}
$c = $bgCol;
$x *= $this->iscale;
$y *= $this->iscale;
if($x >= 0 && $x < $width2 && $y >= 0 && $y < $height2)$c = imagecolorat($this->tmpimg, (int)$x, (int)$y);
if($c != $bgCol)imagesetpixel($this->im, $ix, $iy, $c);
}
}
}
private function drawLines(){
for($line = 0; $line < $this->num_lines; ++$line){
$x = $this->image_width * (1 + $line) / ($this->num_lines + 1);
$x += (0.5 - 0.0001*rand(0,9999)) * $this->image_width / $this->num_lines;
$y = rand($this->image_height * 0.1, $this->image_height * 0.9);
$theta = (0.0001*rand(0,9999)-0.5) * M_PI * 0.7;
$w = $this->image_width;
$len = rand($w * 0.4, $w * 0.7);
$lwid = rand(0, 1);
$k = 0.0001 * rand(0,9999) * 0.6 + 0.2;
$k = $k * $k * 0.5;
$phi = 0.0001*rand(0,9999) * 6.28;
$step = 0.5;
$dx = $step * cos($theta);
$dy = $step * sin($theta);
$n = $len / $step;
$amp = 1.5 * 0.0001*rand(0,9999) / ($k + 5.0 / $len);
$x0 = $x - 0.5 * $len * cos($theta);
$y0 = $y - 0.5 * $len * sin($theta);
$ldx = round(-$dy * $lwid);
$ldy = round($dx * $lwid);
for($i = 0; $i < $n; ++$i){
$x = $x0 + $i * $dx + $amp * $dy * sin($k * $i * $step + $phi);
$y = $y0 + $i * $dy - $amp * $dx * sin($k * $i * $step + $phi);
imagefilledrectangle($this->im, (int)$x, (int)$y, (int)($x + $lwid), (int)($y + $lwid), $this->gdlinecolor);
}
}
}
private function output(){
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: ".gmdate("D, d M Y H:i:s")."GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
ob_start();
switch($this->image_type){
case 'jpg':
header("Content-Type: image/jpeg");
imagejpeg($this->im, null, 70);
break;
case 'gif':
header("Content-Type: image/gif");
imagegif($this->im);
break;
default:
header("Content-Type: image/png");
imagepng($this->im);
break;
}
imagedestroy($this->im);
//$img = ob_get_clean();
//ob_end_clean();
//echo 'data:image/jpeg;base64,'.base64_encode($img);
exit;
}
private function frand(){
return 0.0001*rand(0,9999);
}
public function play(){
header('Content-type: audio/mpeg'); // default to mp3
$ext = 'mp3';
header("Content-Disposition: attachment; filename=\"securimage_audio.{$ext}\"");
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Expires: Sun, 1 Jan 2000 12:00:00 GMT');
header('Last-Modified: '.gmdate('D, d M Y H:i:s').'GMT');
$audio = $this->getAudibleCode();
header('Content-Length: '.strlen($audio));
echo $audio;
exit;
}
private function getAudibleCode(){
$letters = array();
$code = $this->getCode();
if($code == ''){
$this->createCode();
$this->saveData();
$code = $this->getCode();
}
for($i = 0; $i < strlen($code); ++$i)$letters[] = $code[$i];
return $this->generateMP3($letters);
}
private function getCode(){
return $this->myDecode();
}
private function generateMP3($letters){
$data_len = 0;
$files = array();
$out_data = '';
foreach($letters as $letter){
$filename = './frontend/audio/'.strtoupper($letter).'.mp3';
$fp = fopen($filename, 'rb');
$data = fread($fp, filesize($filename)); // read file in
$this->scrambleAudioData($data, 'mp3');
$out_data .= $data;
fclose($fp);
}
return $out_data;
}
private function scrambleAudioData(&$data, $format){
$start = 4; // 4 byte (32 bit) frame header
$start += rand(1, 64); // randomize starting offset
$datalen = strlen($data) - $start - 256; // leave last 256 bytes unchanged
for($i = $start; $i < $datalen; $i += 64){
$ch = ord($data[$i]);
if($ch < 9 || $ch > 119)continue;
$data[$i] = chr($ch + rand(-8, 8));
}
}
protected function createCode(){
if(isset($this->ec[0]['capcha']))return $this->ec[0]['capcha'];
$code = '';
for($i = 1, $cslen = strlen($this->charset)-1; $i <= $this->code_length; ++$i)$code .= $this->charset[rand(0, $cslen)];
return $code;
}
protected function myEncode($code){
$rn = $this->getRandom(5798330201);
$this->insert('insert into', 'capcha', array('kyka' => $rn, 'capcha' => $code, 'time' => $this->time, 'alert_double_request'=>$_COOKIE['alert_double_request']));
$lii = $this->lastInsertId();
return array('capcha' => $lii, 'capcha_kyka' => $rn);
}
}
Fatal error: Uncaught Error: Class "Obj" not found in /var/www/ob/index.php:16
Stack trace:
#0 {main}
thrown in /var/www/ob/index.php on line 16