piterskiy

API mail.ru

Feb 10th, 2017
25,227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // API mail.ru
  2. <?php
  3.  
  4. $id = "ID";
  5. $password = "PASSWORD";
  6.  
  7. $url = "http://top.mail.ru/json/srchlanding?id=$id&action=json&password=$password&pp=50000&rettype=all";
  8.  
  9. $data = json_decode(file_get_contents($url));
  10.  
  11. $domains = [];
  12. $se = [];
  13.  
  14. foreach($data->elements as $hit):
  15.     $domains[$hit->sign][parse_url($hit->url, PHP_URL_HOST)] += $hit->hits;
  16.     $se[$hit->sign] += $hit->hits;
  17. endforeach;
  18.  
  19. foreach($se as $name => $value):
  20.     echo "<h2>$name = $value</h2>";
  21.     echo "<table>";
  22.     foreach($domains[$name] as $domain => $hits):
  23.         echo "<tr><td><i>$domain</i></td><td><b>$hits</b></td></tr>";
  24.     endforeach;
  25.     echo "</table>";
  26. endforeach;
  27. ?>
  28. // API mail.ru
  29.  
  30.  
  31. // API mail.ru - навигация по дням в стиле «туда-сюда»
  32. <?php
  33.  
  34. $id = "ID";
  35. $password = "PASSWORD";
  36.  
  37. $offset = isset($_GET['day']) ? $_GET['day'] : 0;
  38.  
  39. $date = date('Y-m-d', time() - $offset * 24 * 60 * 60);
  40. $yesterday = date('Y-m-d', time() - ($offset + 1) * 24 * 60 * 60);
  41. $tomorrow = date('Y-m-d', time() - ($offset - 1) * 24 * 60 * 60);
  42.  
  43. $url = "http://top.mail.ru/json/srchlanding?id=$id&action=json&password=$password&pp=50000&rettype=all&date=$date";
  44.  
  45. $data = json_decode(file_get_contents($url));
  46.  
  47. $domains = [];
  48. $se = [];
  49.  
  50. foreach ($data->elements as $hit):
  51.     $domains[$hit->sign][parse_url($hit->url, PHP_URL_HOST)] += $hit->hits;
  52.     $se[$hit->sign] += $hit->hits;
  53. endforeach;
  54.  
  55. echo "<h1>Дата: $date Всего: " . array_sum($se) . "</h1>";
  56.  
  57. echo "<div><a href='?day=" . ($offset + 1) . "'>$yesterday</a>";
  58. if ($offset):
  59.     echo " <a href='?day=" . ($offset - 1) . "'>$tomorrow</a>";
  60. endif;
  61. echo "</div>";
  62.  
  63. foreach ($se as $name => $value):
  64.     echo "<div style='float:left; margin-right: 1em; padding: 0 1em; border: 1px solid black;'><h2>$name: $value</h2>";
  65.     echo "<table>";
  66.     foreach ($domains[$name] as $domain => $hits):
  67.         echo "<tr><td><i>$domain</i></td><td><b>$hits</b></td></tr>";
  68.     endforeach;
  69.     echo "</table></div>";
  70. endforeach;
  71.  
  72. ?>
  73. // API mail.ru - навигация по дням в стиле «туда-сюда»
Advertisement
Add Comment
Please, Sign In to add comment