<?
if ( $_SERVER['HTTP_X_REQUESTED_WITH'] != 'XMLHttpRequest' ) {
    exit();
}
if ($_GET['url'] == 'PR') {
    $q = $_POST['url'];
    $host = 'toolbarqueries.google.com';
    $context = NULL;
    $seed = "Mining PageRank is AGAINST GOOGLE'S TERMS OF SERVICE. Yes, I'm talking to you, scammer.";
    $result = 0x01020345;
    $len = strlen($q);
    for ($i=0; $i<$len; $i++) {
    $result ^= ord($seed{$i%strlen($seed)}) ^ ord($q{$i});
    $result = (($result >> 23) & 0x1ff) | $result << 9;
    }
    $ch=sprintf('8%x', $result);
    $url='http://%s/tbr?client=navclient-auto&ch=%s&features=Rank&q=info:%s';
    $url=sprintf($url,$host,$ch,$q);
    @$pr=file_get_contents($url,false,$context);
    echo $pr?substr(strrchr($pr, ':'), 1):false;
}

if ($_GET['url'] == 'TIC') {
    //считываем XML-файл с данными
  $xml = file_get_contents('http://bar-navig.yandex.ru/u?ver=2&show=32&url=http://'.$_POST['url']);
  echo $xml ? (int) substr(strstr($xml, 'value="'), 7) : 0;
}

/*if ($_GET['url'] == 'alexa') {
    $file = file_get_contents('http://data.alexa.com/data?cli=10&dat=snbamz&url='.$_POST['url']);
    preg_match('/\<popularity url\="(.*?)" TEXT\="([0-9]+)"\/\>/si', $file, $alexa);
    if ($alexa[2] == '') {
        echo 0;
    } else {
        echo $alexa[2];
    }
}*/
if ($_GET['url'] == 'alexa') {
    $url = 'http://data.alexa.com/data?cli=10&dat=snbamz&url=http://' . trim($_POST['url']);
     $xmldata = simplexml_load_file($url);
     if(isset($xmldata->SD[1]->POPULARITY['TEXT'])){
           echo number_format((string)$xmldata->SD[1]->POPULARITY['TEXT']);
     }
     else
    {
        echo 0;
    }
}
?>