Advertisement
Neolot

Feedburner counter #2

Feb 2nd, 2012
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.95 KB | None | 0 0
  1. // Feedburner counter
  2.  
  3. function nlt_getFeedCounter($feedid='medicsovet'){
  4.     $output = get_transient('rss_counter');
  5.     if (!isset($output['lastcheck'])) $output['lastcheck'] = 0;
  6.     if (!isset($output['count'])) $output['count'] = 0;
  7.     if (!isset($output['feedid'])) $output['feedid'] = '';
  8.     if ($output['lastcheck'] < (mktime() - 3600) || $output['feedid'] != $feedid) {
  9.         $url = 'http://feedburner.google.com/api/awareness/1.0/GetFeedData?uri=' . $feedid;
  10.         $headers = get_headers($url);
  11.         if (strpos($headers[0], '200')) {
  12.             $xml = file_get_contents($url);
  13.             preg_match('/circulation="(\d+)"/', $xml, $match);
  14.             if ($match[1] != 0) {
  15.                 $output['count'] = $match[1];
  16.                 $output['lastcheck'] = mktime();
  17.                 $output['feedid'] = $feedid;
  18.                 set_transient('rss_counter', $output, 60*10 );
  19.             }
  20.         }
  21.     }
  22.     echo $output['count'];
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement