<?php
include('../inc/conf.php');
ini_set('session.use_cookies', 'On');
ini_set('session.use_trans_sid', 'Off');
session_set_cookie_params(604800000, "/", SITE, false, false);
session_start();
if (!isset($_SESSION["uid"])){
echo "2";
exit;
}
if(isset($_POST['id']) && isset($_POST['url']) && isset($_POST['ti']) && isset($_POST['lvl1']) && isset($_POST['lvl2']) && isset($_POST['lvl3']) && isset($_POST['lvl4']) && isset($_POST['cat'])){
if(!empty($_POST['id']) && !empty($_POST['url']) && !empty($_POST['ti']) && !empty($_POST['lvl1']) && !empty($_POST['lvl2']) && !empty($_POST['lvl3']) && !empty($_POST['lvl4']) && !empty($_POST['cat'])){
$id = intval($_POST["id"]);
$uid = intval($_SESSION["uid"]);
$dt = time();
$ns = mysqli_fetch_assoc(mysqli_query($connect_db, "SELECT id,usr,url,ho,thumb FROM t_site WHERE id='$id'"));
if ($ns['usr'] != $uid) { echo '3'; exit; }
if($ns['ho'] > 0) { echo '5'; exit; }
$url = mysqli_real_escape_string($connect_db, $_POST["url"]);
$lr = stripos($url , "http");
if ($lr === false) { echo '4'; exit; }
$purln = parse_url($url);
$eurl = $purln['host'];
$purle = parse_url($ns['url']);
$eurle = $purle['host'];
if ($eurl != $eurle) {
$hs = mysqli_num_rows(mysqli_query($connect_db, "SELECT id FROM `t_site` WHERE url LIKE '%$eurl%'"));
if($hs > 0) { echo '7'; exit; }
}
$ti = mysqli_real_escape_string($connect_db, $_POST["ti"]);
$lvl1 = intval($_POST["lvl1"]);
$lvl2 = intval($_POST["lvl2"]);
$lvl3 = intval($_POST["lvl3"]);
$lvl4 = intval($_POST["lvl4"]);
$cat = intval($_POST["cat"]);
$www = file_get_contents("http://bar-navig.yandex.ru/u?url=$url&show=1");
preg_match('#value="(\d+)"/>#i',$www,$ar);
$tic = $ar[1];
function StrToNum($Str, $Check, $Magic) {
$Int32Unit = 4294967296;
$length = strlen($Str);
for ($i = 0; $i < $length; $i++) {
$Check *= $Magic;
if ($Check >= $Int32Unit) {
$Check = ($Check - $Int32Unit * (int) ($Check / $Int32Unit));
$Check = ($Check < -2147483648) ? ($Check + $Int32Unit) : $Check;
}
$Check += ord($Str{$i});
}
return $Check;
}
function HashURL($String) {
$Check1 = StrToNum($String, 0x1505, 0x21);
$Check2 = StrToNum($String, 0, 0x1003F);
$Check1 >>= 2;
$Check1 = (($Check1 >> 4) & 0x3FFFFC0 ) | ($Check1 & 0x3F);
$Check1 = (($Check1 >> 4) & 0x3FFC00 ) | ($Check1 & 0x3FF);
$Check1 = (($Check1 >> 4) & 0x3C000 ) | ($Check1 & 0x3FFF);
$T1 = (((($Check1 & 0x3C0) << 4) | ($Check1 & 0x3C)) <<2 ) | ($Check2 & 0xF0F );
$T2 = (((($Check1 & 0xFFFFC000) << 4) | ($Check1 & 0x3C00)) << 0xA) | ($Check2 & 0xF0F0000 );
return ($T1 | $T2);
}
function CheckHash($Hashnum) {
$CheckByte = 0;
$Flag = 0;
$HashStr = sprintf('%u', $Hashnum) ;
$length = strlen($HashStr);
for ($i = $length - 1; $i >= 0; $i --) {
$Re = $HashStr{$i};
if (1 === ($Flag % 2)) {
$Re += $Re;
$Re = (int)($Re / 10) + ($Re % 10);
}
$CheckByte += $Re;
$Flag ++;
}
$CheckByte %= 10;
if (0 !== $CheckByte) {
$CheckByte = 10 - $CheckByte;
if (1 === ($Flag % 2) ) {
if (1 === ($CheckByte % 2)) {
$CheckByte += 9;
}
$CheckByte >>= 1;
}
}
return '7'.$CheckByte.$HashStr;
}
function getch($url) { return CheckHash(HashURL($url)); }
function urlpr($url){
$ch = getch($url);
$main_url = "http://toolbarqueries.google.com/tbr?client=navclient-auto&hl=en&ch=$ch&ie=UTF-8&oe=UTF-8&features=Rank&q=info:$url";
$content = file_get_contents($main_url);
$pr = explode(":",$content);
return $pr[2];
}
$pr = urlpr($eurl);
$xml=simplexml_load_file("http://bar-navig.yandex.ru/u?ver=2&url=http://".$eurl."/&show=1");
if(!$xml->topics->topic['title'] and !$xml->topics->topic['url']){
$ya = '0';
}else{
$ya = '1';
}
function get_dmoz_count($host){
$ret = 0;
if ($s = file_get_contents('http://www.dmoz.org/search/?q='.$host)) {
if (preg_match('/<small>\(\d+\-\d+ of (\d+)\)<\/small>/siU', $s, $a) ){
$ret = $a[1];
}
}
return $ret;
}
$dmp = get_dmoz_count($eurl);
if ($dmp == 0)
{ $dm = '0'; }
else if ($dmp >= 1)
{ $dm = '1'; }
$toli = file_get_contents("http://pr-cy.ru/a/$eurl");
preg_match('/Страна(.*?)Дата регистрации/s',$toli,$ar);
preg_match('/<b>(.*?)</s',$ar[1],$arl);
$li = $arl[1];
preg_match('/Индекс Яндекса(.*?)Проиндексировано/s',$toli,$ar2);
preg_match('/rel="nofollow">(.*?)</s',$ar2[1],$arl2);
$inya = preg_replace("#[^\-0-9]+#i",'',$arl2[1]);
function getGoogleCount($domain) {
$content = file_get_contents('http://ajax.googleapis.com/ajax/services/search/web?v=1.0&filter=0&q=site:'.urlencode($domain));
$data = json_decode($content);
return intval($data->responseData->cursor->estimatedResultCount);
}
$ingo = getGoogleCount($eurl);
$file = '../thumbs/'.$ns['thumb'];
$surl = "http://mini.s-shot.ru/1024x768/800/jpeg/?$url";
$content = file_get_contents($surl);
file_put_contents($file, $content);
mysqli_query($connect_db, "UPDATE `t_site` SET `url` = '$url', `ti` = '$ti', `cat` = '$cat', `lvl1` = '$lvl1', `lvl2` = '$lvl2', `lvl3` = '$lvl3', `lvl4` = '$lvl4', `tic` = '$tic', `pr` = '$pr', `ya` = '$ya', `dm` = '$dm', `li` = '$li', `inya` = '$inya', `ingo` = '$ingo', `st` = '1' WHERE id='$id' LIMIT 1");
echo '1'; exit;
} else { echo '0'; }
} else { echo '3'; }
?>