1. <?php
  2. set_time_limit(0);
  3. mb_internal_encoding("cp1251");
  4. header('Content-Type: text/html; charset=utf-8', true);
  5. require_once 'class/simple_html_dom.php'; // библиотека для парсинга
  6. require_once 'class/safemysql.class.php';
  7. $db = new safeMysql();
  8. function check_http_status($url)
  9. {
  10. $user_agent = 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0)';
  11. $ch = curl_init();
  12. curl_setopt($ch, CURLOPT_URL, $url);
  13. curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
  14. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  15. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  16. curl_setopt($ch, CURLOPT_VERBOSE, false);
  17. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  18. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  19. curl_setopt($ch, CURLOPT_SSLVERSION, 3);
  20. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  21. $page = curl_exec($ch);
  22. $err = curl_error($ch);
  23. if (!empty($err))
  24. return $err;
  25. $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  26. curl_close($ch);
  27. return $httpcode;
  28. }
  29. function tcy_yandex($url)
  30. {
  31. //$url = 'http://'.$url;
  32. $str=file('http://bar-navig.yandex.ru/u?ver=2&show=32&url='.$url);
  33. if ($str==false) {$ans=false;}
  34. else {$is_find=preg_match("/value=\"(.\d*)\"/", join("",$str), $tic); if ($is_find<1) {$ans=0;} else {$ans=$tic[1];} }
  35. return $ans;
  36. }
  37. function stripToDomainName($url)
  38. {
  39. $http = parse_url($url, PHP_URL_SCHEME);
  40. $domain = parse_url($url, PHP_URL_HOST);
  41. $url = $http . '://' .$domain;
  42. return $url;
  43. }
  44. function follow_checker($url_donor, $ancor_url)
  45. {
  46. $output = curl_init(); //подключаем курл
  47. curl_setopt($output, CURLOPT_URL, $url_donor); //отправляем адрес страницы
  48. curl_setopt($output, CURLOPT_RETURNTRANSFER, 1);
  49. curl_setopt($output, CURLOPT_HEADER, 0);
  50. $out .= curl_exec($output); //помещаем html-контент в строку
  51. curl_close($output); //закрываем подключение
  52. //Кодировочка
  53. $out1 = iconv("windows-1251","utf-8", $out);
  54. $html = new simple_html_dom(); //создаем объект
  55. $html->load($out); //помещаем наш контент
  56. // Ссылка есть но nofollow
  57. foreach ($html->find('a[rel=nofollow]') as &$article) {
  58. $nofollow_ancor .= stristr($article, $ancor_url);
  59. if ($nofollow_ancor > '') { $nofollow_ancor = '1'; }
  60. }
  61. unset($article);
  62. foreach ($html->find('a') as &$article) {
  63. $ancor .= stristr($article, $ancor_url);
  64. if ($ancor > '') { $ancor = '1'; }
  65. }
  66. unset($article);
  67. $state_ancor = $nofollow_ancor+$ancor;
  68. return $state_ancor;
  69. }
  70. $arr = $db->getCol('SELECT id FROM `ancors` where id>1202');
  71. Проверка тиц, код ответа
  72. foreach ($arr as &$value) {
  73. $url_db = $db->getOne('SELECT donor FROM `ancors` where id='.$value.'');
  74. $answer = check_http_status($url_db);
  75. $dom = stripToDomainName($url_db);
  76. $tcy = tcy_yandex($dom);
  77. $upd = $db->query('UPDATE `ancors` SET `responce`="'.$answer.'", `domain`="'.$dom.'" where id='.$value.' limit 1');
  78. }
  79. //Проверяем на noffolow если $follow=2 значит есть анкор и есть nofflow если 1 то анкор без noffolow
  80. foreach ($arr as &$value) {
  81. $url_db = $db->getOne('SELECT `donor` FROM `ancors` where id='.$value.'');
  82. $url_arcept = $db->getOne('SELECT `arcept` FROM `ancors` where id='.$value.'');
  83. $url_arcept = 'http://' .$url_arcept;
  84. $arcept = parse_url($url_arcept, PHP_URL_HOST);
  85. $follow = follow_checker($url_db, $arcept);
  86. $upd = $db->query('UPDATE `ancors` SET `nofollow`="'.$follow.'" where id='.$value.' limit 1');
  87. }
  88. ?>