- <?php
- set_time_limit(0);
- mb_internal_encoding("cp1251");
- header('Content-Type: text/html; charset=utf-8', true);
- require_once 'class/simple_html_dom.php'; // библиотека для парсинга
- require_once 'class/safemysql.class.php';
- $db = new safeMysql();
- function check_http_status($url)
- {
- $user_agent = 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0)';
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_VERBOSE, false);
- curl_setopt($ch, CURLOPT_TIMEOUT, 10);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($ch, CURLOPT_SSLVERSION, 3);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
- $page = curl_exec($ch);
- $err = curl_error($ch);
- if (!empty($err))
- return $err;
- $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
- curl_close($ch);
- return $httpcode;
- }
- function tcy_yandex($url)
- {
- //$url = 'http://'.$url;
- $str=file('http://bar-navig.yandex.ru/u?ver=2&show=32&url='.$url);
- if ($str==false) {$ans=false;}
- else {$is_find=preg_match("/value=\"(.\d*)\"/", join("",$str), $tic); if ($is_find<1) {$ans=0;} else {$ans=$tic[1];} }
- return $ans;
- }
- function stripToDomainName($url)
- {
- $http = parse_url($url, PHP_URL_SCHEME);
- $domain = parse_url($url, PHP_URL_HOST);
- $url = $http . '://' .$domain;
- return $url;
- }
- function follow_checker($url_donor, $ancor_url)
- {
- $output = curl_init(); //подключаем курл
- curl_setopt($output, CURLOPT_URL, $url_donor); //отправляем адрес страницы
- curl_setopt($output, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($output, CURLOPT_HEADER, 0);
- $out .= curl_exec($output); //помещаем html-контент в строку
- curl_close($output); //закрываем подключение
- //Кодировочка
- $out1 = iconv("windows-1251","utf-8", $out);
- $html = new simple_html_dom(); //создаем объект
- $html->load($out); //помещаем наш контент
- // Ссылка есть но nofollow
- foreach ($html->find('a[rel=nofollow]') as &$article) {
- $nofollow_ancor .= stristr($article, $ancor_url);
- if ($nofollow_ancor > '') { $nofollow_ancor = '1'; }
- }
- unset($article);
- foreach ($html->find('a') as &$article) {
- $ancor .= stristr($article, $ancor_url);
- if ($ancor > '') { $ancor = '1'; }
- }
- unset($article);
- $state_ancor = $nofollow_ancor+$ancor;
- return $state_ancor;
- }
- $arr = $db->getCol('SELECT id FROM `ancors` where id>1202');
- Проверка тиц, код ответа
- foreach ($arr as &$value) {
- $url_db = $db->getOne('SELECT donor FROM `ancors` where id='.$value.'');
- $answer = check_http_status($url_db);
- $dom = stripToDomainName($url_db);
- $tcy = tcy_yandex($dom);
- $upd = $db->query('UPDATE `ancors` SET `responce`="'.$answer.'", `domain`="'.$dom.'" where id='.$value.' limit 1');
- }
- //Проверяем на noffolow если $follow=2 значит есть анкор и есть nofflow если 1 то анкор без noffolow
- foreach ($arr as &$value) {
- $url_db = $db->getOne('SELECT `donor` FROM `ancors` where id='.$value.'');
- $url_arcept = $db->getOne('SELECT `arcept` FROM `ancors` where id='.$value.'');
- $url_arcept = 'http://' .$url_arcept;
- $arcept = parse_url($url_arcept, PHP_URL_HOST);
- $follow = follow_checker($url_db, $arcept);
- $upd = $db->query('UPDATE `ancors` SET `nofollow`="'.$follow.'" where id='.$value.' limit 1');
- }
- ?>