Advertisement
Decker82

Yandex XML Position Checker Script v1.0a (c) Decker

Nov 10th, 2013
5,521
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.59 KB | None | 0 0
  1. <?php
  2.  
  3. /*
  4.  
  5. Yandex XML Position Checker Script v1.0a (c) Decker, decker(at)compkaluga.ru
  6. ----------------------------------------------------------------------------
  7.  
  8. */
  9.  
  10.     function curl_file_get_contents($fp_url) {
  11.     $ch = curl_init();
  12.         curl_setopt($ch, CURLOPT_URL, $fp_url);
  13.         curl_setopt($ch, CURLOPT_HEADER, 0);
  14.         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  15.         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  16.         $fp = curl_exec($ch);
  17.         curl_close($ch);
  18.     return $fp;
  19.     }
  20.  
  21. $our_domain = "compkaluga.ru";
  22.  
  23. $keywords = 'создание сайтов калуга
  24. создание сайтов в калуге
  25. продвижение сайтов в калуге
  26. продвижение сайтов калуга
  27. seo оптимизация в калуге
  28. seo в калуге
  29. контекстная реклама в калуге
  30. купить сайт в калуге
  31. сайт-визитка калуга
  32. создание сайта визитки в калуге';
  33.  
  34. $keywords = explode("\r\n",$keywords);
  35. $res = Array();
  36.  
  37. echo '<h2 align="center">Наши позиции</h2>';
  38.  
  39. echo '<table border="1" cellpadding="4" cellspacing="0">';
  40. foreach ($keywords as $keyword) {
  41.  
  42.    $params = array(
  43.         'user' => 'yandex_user', // логин
  44.         'key' => '00.0000000000000000000000000000000000000000', // ключ Яндекс.XML
  45.     'filter' => 'none',
  46.     'groupby' => 'attr=d.mode=deep.groups-on-page=100', // attr=<служебный атрибут>.mode=<тип группировки>.groups-on-page=<количество групп на одной странице>.docs-in-group=<количество документов в каждой группе>
  47.         'query' => urlencode($keyword),
  48.         'lr' => 6
  49.     );
  50.    
  51.  
  52.     $url = "http://xmlsearch.yandex.ru/xmlsearch" . '?' . urldecode(http_build_query($params));
  53.  
  54. $fp = curl_file_get_contents($url); // для CURL
  55. // $fp = file_get_contents($url); // если CURL не установлен
  56.  
  57. $xml = @simplexml_load_string($fp,'SimpleXMLElement', LIBXML_NOCDATA);
  58.  
  59. $results = Array(); $i=0; $found = false; $found_index = "";
  60. foreach ($xml->response->results->grouping->group as $group) {
  61.     $results[] = Array('domain' => trim($group->doc->domain), 'url' => trim($group->doc->url),'title' => $group->doc->title);
  62.     if ($results[$i]['domain'] == $our_domain) { $found = true; $found_index = $i; }
  63.     $i++;
  64. }
  65. $res[] = $results;
  66.  
  67. echo '<tr>';
  68. if ($found) {
  69. echo '<td><a href="'.$results[$found_index]['url'].'">'.urldecode($params['query'])."</a></td><td>" . (($found) ? ($found_index+1) : ">100") ."</td>";
  70. $title = preg_replace("!<hlword>(.*?)</hlword>!si","<b>\\1</b>",$results[$found_index]['title']->asXML());
  71. $title = preg_replace("!<title>(.*?)</title>!si","\\1",$title);
  72. echo '<td>'.iconv("UTF-8","CP1251",$title).'</td>';
  73.  
  74. }
  75. else {
  76. echo '<td>'.urldecode($params['query'])."</td><td>" . (($found) ? ($found_index+1) : ">100") ."</td>";
  77. echo '<td>&nbsp;</td>';
  78. }
  79.  
  80. echo '</tr>';
  81. echo "\r\n";
  82.  
  83. }
  84. echo '</table><p>';
  85.  
  86. $i=0;
  87. foreach ($keywords as $keyword) {
  88. echo '<h2 align="center">'.$keyword.'</h2>';
  89. echo "\r\n";
  90. echo '<table border="1" cellpadding="4" cellspacing="0">';
  91.  
  92. $j=0;
  93. foreach ($res[$i] as $r) {
  94.     echo '<tr>';
  95. echo '<td><a href="'.$r['url'].'">'.$r['domain']."</a></td><td>" . intval($j+1) ."</td>";
  96. $title = preg_replace("!<hlword>(.*?)</hlword>!si","<b>\\1</b>",$r['title']->asXML());
  97. $title = preg_replace("!<title>(.*?)</title>!si","\\1",$title);
  98. echo '<td>'.iconv("UTF-8","CP1251",$title).'</td>';
  99.         $j++;
  100. echo '</tr>';
  101. echo "\r\n";
  102.    
  103.     }
  104. $i++;
  105. echo '</table><p>';
  106. }
  107. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement