Location: PHPKode > scripts > FeedBurner subscriber counter with Feedburner Awareness API > feedburner-subscriber-counter-with-feedburner-awareness-api/feedburner_subscribers.php
<?PHP
/**
Copyright (C) 2008 ionix Limited
http://www.ionix.ltd.uk/

This script was written by ionix Limited, and was distributed
via the OpenCrypt.com Blog.

Subscriber counter with Addicted to Feedburner PHP class and
Feedburner Awareness API
http://www.OpenCrypt.com/blog.php?a=24

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of
the License, or any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

GNU GPL License
http://www.opensource.org/licenses/gpl-license.php
*/

ini_set('error_reporting', E_ALL | E_STRICT);
ini_set('display_errors', 'Off');

function feedburner_stats($feedburner_username, $show_change = "1") {

require_once 'class.feedburner.php';
# Load 'Addicted to Feedburner' class by John Nunemaker
# http://addictedtonew.com/examples/feedburner/

$output = "";
$fb =& new feedburner($feedburner_username);

$date_str = date('Y-m-d', strtotime('-2 days', time())) . ',' . date('Y-m-d', time());

$info = $fb->getFeedData(array('dates'=>$date_str));
if ($fb->isError()) {
    $output = $fb->getErrorMsg();
} else {
    $entries = $info['entries'];
    if (count($entries) > 0) {

		$entry_count = 0;

        foreach($entries as $entry) {

			if ("$entry_count"=="0") {

				$circulation_yesterday = $entry['circulation'];

			} elseif ("$entry_count"=="1") {

				$circulation_today = $entry['circulation'];
				$circulation_hits = $entry['hits'];

			}

			$entry_count++;

        }
    }

	#$circulation_today = "9420";
	#$circulation_yesterday = "9012";

	$circulation_new = $circulation_today - $circulation_yesterday;

	if ("$show_change"=="1") {

		$circulation_change = $circulation_yesterday / $circulation_new;
		$circulation_change = 100 / $circulation_change;
		$circulation_change = sprintf("%01.1f", $circulation_change);

		$circulation_change_decimal = explode(".", $circulation_change);
		if ("$circulation_change_decimal[1]"=="0") {

			$circulation_change = $circulation_change_decimal[0];

		}

		$circulation_change_indicator = substr($circulation_change,0,1);
		if ("$circulation_change"=="0") {

			$circulation_change_indicator = "";

		} elseif ("$circulation_change_indicator"=="-") {

			$circulation_change_indicator = "<td bgcolor=\"#eeeeee\"><img src=\"down.gif\" hspace=1></td>";

		} else {

			$circulation_change_indicator = "<td bgcolor=\"#eeeeee\"><img src=\"up.gif\" hspace=1></td>";

		}

		$output .= <<<END

<div id="circulation-new" style="display:none; position: absolute; z-index: 1; font: bold 11px Verdana; color: #000000;">
<table cellpadding=15 cellspacing=0 border=0 class="circulation_change_rounded">
<tr>
	<td bgcolor="#f7f7f7">
	<span class="circulation_new">$circulation_new new subscibers</span>
	</td>
</tr>
</table>
</div>

END;

	}

	$output .= <<<END
<table cellpadding=10 cellspacing=0 border=0>
<tr>
	<td align=center>
	<span class="circulation_today"><a href="http://feeds.feedburner.com/$feedburner_username/" class="circulation_today" title="Subscribe to $feedburner_username RSS Feed">$circulation_today</a></span>
	<span class="circulation_subscribers"><br><a href="http://feeds.feedburner.com/$feedburner_username/" class="circulation_subscribers" title="Subscribe to $feedburner_username RSS Feed">subscribers</a></span>
	</td>
END;

	if ("$show_change"=="1") {
	$output .= <<<END
	<td>

		<table cellpadding=10 cellspacing=0 border=0 class="circulation_change_rounded">
		<tr>
			<td bgcolor="#eeeeee" onmouseover="ShowContent('circulation-new'); return true;" onmouseout="HideContent('circulation-new'); return true;">

			<table cellpadding=4 cellspacing=0 border=0>
			<tr>
				$circulation_change_indicator
				<td bgcolor="#eeeeee">
				<span class="circulation_change">$circulation_change%</span>
				</td>
			</tr>
			</table>

			</td>
		</tr>
		</table>
	</td>
END;
	}

	$output .= <<<END

</tr>
</table>
END;

}

return $output;

}

?>
Return current item: FeedBurner subscriber counter with Feedburner Awareness API