Форуми / Cotonti / Extensions / Social followers counter

lukgoh
#1 18.01.2012 12:12

I have made a small plugin to show the number of followers from various different social sites including: Twitter, Facebook and Feedburner. I hope to add others, for example Google+. You can download the plugin here!

Here is an example of it in use on my sites footer: socialcounter_1089.png

It is currently a standalone page, however if you edit the main php file (subscribecount.php), line 4:

Hooks=standalone

You can change that to suit your needs, for example if you want to display this in the footer you can change to Hooks=footer.tags and use the following tags: {TWITTER_COUNT} {FACEBOOK_COUNT} and {FEEDBURNER_COUNT}

You currently have to also input your data into the same php file for this to load your data...

I am knew to php and plugin development and would like improve this and make it easier for people to use and was wondering if someone could help me develope it further.

Here is the code:

<?php
/* ====================
[BEGIN_COT_EXT]
Hooks=standalone
[END_COT_EXT]
==================== */

/**
 * business Plugin for Cotonti CMF
 *
 * @package subscribecount
 * @version 1.0
 * @author DesignLizard
 * @copyright (c) 2012
 * @license BSD
 */

defined('COT_CODE') or die('Wrong URL');

// Get Twitter Follower Count

$screenName = 'YOUR TWITTER NAME IN HERE';
$getData = 'followers_count';
 
$xml = file_get_contents('http://twitter.com/users/show.xml?screen_name=' . $screenName);
 
if(preg_match('/' . $getData . '>(.*)</', $xml, $match) !=0)
$twittercount =	$match[1];


// Get Facebook like count

$fbcount = file_get_contents("https://graph.facebook.com/YOUR FACEBOOK PAGE ID IN HERE");
$fbcount1 = json_decode($fbcount,true);
 
$facebookcount =  $fbcount1["likes"];

// Get Feedburner Subscribers count

//feedburner api url
$url = "http://feedburner.google.com/api/awareness/1.0/GetFeedData?uri=YOUR FEEDBURNER RSS FEED NAME HERE";
 
//Initialize the Curl
$ch = curl_init();  
 
//Set curl to return the data instead of printing it to the browser.
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,2); 
 
//Set the URL
curl_setopt($ch, CURLOPT_URL, $url);  
 
//Execute the fetch
$data = curl_exec($ch);  
 
//Close the connection
curl_close($ch);  
 
$xml = new SimpleXMLElement($data);
$subscribers = $xml->feed->entry['circulation']; 
 
if ($subscribers == "") {
	
	$feedburnercount = '0';
} else {
 
$feedburnercount = $subscribers;

}

	$t->assign(array(
				'TWITTER_COUNT' => $twittercount,
				'FACEBOOK_COUNT' => $facebookcount,
				'FEEDBURNER_COUNT' => $feedburnercount,
			));

?>

I guess if you could enter the values in the admin panel that could be better...


Відредаговано: lukgoh (18.01.2012 12:20, 12 років тому)
Kingsley
#2 18.01.2012 12:24

:) Very nice Mr. Skywalker (very lame, very far fetched joke .. I know) xD

lukgoh
#3 18.01.2012 12:26

lol, Yeah I get that a lot :P

Kingsley
#4 18.01.2012 12:41

Well, maybe it's a hint.. adopt the name dude.. Sounds fancy too, Mr. Skywalker..

lukgoh
#5 19.01.2012 23:52

I was wondering if someone could better explain the use of the $cfg variable for extensions. For example, do you have to store the contents in the database? Also how would you add an input box when a user clicks add, like they do for pages, etc. If that makes sense :D

GHengeveld
#6 20.01.2012 03:53
For info about plugin config, have a look here. You can simply put the fields you need in yourplugin.setup.php and it will automatically make the config screen and store the values in the database. You can then use it like $cfg['plugin']['yourplugin']['configname']
lukgoh
#7 20.01.2012 10:04

Thanks.