Simple Machines Community Forum

Customizing SMF => Tips and Tricks => Topic started by: Mick. on June 21, 2012, 08:02:04 AM

Title: [TUT] How To Display Facebook, Twitter & Feedburner Subscriber Count In Text
Post by: Mick. on June 21, 2012, 08:02:04 AM
Subscriber Count In Text in a PHP block
I believe you've seen websites and blogs that uses the text-based Feedburner subscriber count instead of the chicklet. I hope you are not getting the idea the these guys update their feed count manually. Instead, it can be done easily with scripts, and the reason why you want to do is – it gives you total flexibility in terms of design, styling and display.

Create a PHP block using your favorite portal and insert this code.  Make sure you replace all ID's and modify the code to suit your needs. ie, color, background, size.

Have fun ;)

//Social Text Counter v.1 by

//Begin Twitter Counter
$twit = file_get_contents(' ID.xml');
$begin = '<followers_count>'; $end = '</followers_count>';
$page = $twit;
$parts = explode($begin,$page);
$page = $parts[1];
$parts = explode($end,$page);
$tcount = $parts[0];
if($tcount == '') { $tcount = '0'; }
//End Twitter Counter

//Begin Feedburner Counter
//get cool feedburner count
$whaturl=" ID";

//Initialize the Curl session
$ch = curl_init();

//Set curl to return the data instead of printing it to the browser.
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

//Set the URL
curl_setopt($ch, CURLOPT_URL, $whaturl);

//Execute the fetch
$data = curl_exec($ch);

//Close the connection
$xml = new SimpleXMLElement($data);
$fb = $xml->feed->entry['circulation'];
//End Feedburner Counter

//Begin Facebook Counter
   $facebook = new Facebook(array(
   'appId'  => 'FACEBOOK APP ID',
   'secret' => 'FACEBOOK SECRET ID',
   'cookie' => true,
   $result = $facebook->api(array(
   'method' => 'fql.query',
   'query' => 'select fan_count from page where page_id =FACEBOOK FAN PAGE ID #;'
   $fb_fans = $result[0]['fan_count'];
//End Facebook Counter

echo '
<table width="275px" height="40px" bordercolor="#dcdcdc" bgcolor="#f7f7f7" cellpadding="2" cellspacing="5">
<tr valign="top">
<font size="1" color="#d97b33">Facebook Fans</font><br /><font color="#346" size="2"><strong><center>'.$fb_fans.'</center></strong></font>
<font size="1" color="#d97b33">Twitter Followers</font><br /><font color="#346" size="2"><strong><center>'.$tcount.'</center></strong></font>
<font size="1" color="#d97b33">RSS Subscribers</font><br /><font color="#346" size="2"><strong><center>'.$fb.'</center></strong></font>

   //End of Social Text Counter v.1

Title: Re: [TUT] How To Display Facebook, Twitter & Feedburner Subscriber Count In Text
Post by: sachinvermarip on June 24, 2012, 04:07:00 AM
Exactly what I was looking for, Thanks a lot :)