If you want to help out you can do so over at the GitHub page:
https://github.com/bhadaway/SocialStats-WordPress-Plugin
A plugin to collect, combine and display FeedBurner, Facebook and Twitter subscriber/fan/follower stats.
Download and test plugin from here.
I'm working on the plugin version of the following script:
http://www.problogdesign.com/wordpress/how-to-get-facebook-twitter-and-rss-counts-wp/
(with permission of its writer of course)
As you'll find out quickly I'm not a programmer myself, only a web and graphic designer. So when it comes to programming it's experimental and I usually need help.
So if anyone agrees that this would make a great plugin and would like to collaborate (and receive an added credit of course) take a look at the code I have so far below.
From a PHP programmers perspective you can probably see the basic concept of my attempt;
- Settings page and option saving is working and in place
- The code is being delivered to the front-end (perhaps in the wrong place)
- However I'm sure there are some logic and syntax errors
- The main problem I'm sure is that the attempted delivery of:
<?php echo ss_feedburner; ?>
<?php echo ss_facebook; ?>
<?php echo ss_twitter; ?>
to the front-end is incorrect for a number of reasons.
The second main part see below main plugin code.
<?php
/*
Plugin Name: SocialStats
Version: 1.0
Plugin URI: http://bryanhadaway.com/socialstats/
Description: Allows you to collect and combine your FeedBurner Subscribers, Facebook Fans and Twitter Followers into one plain text number for you to place anywhere and style however you like. This plugin is created from the script written by Michael Martin of <a href="http://www.problogdesign.com/" target="_blank">http://www.problogdesign.com/</a>.
Author: Bryan Hadaway
Author URI: http://bryanhadaway.com/
This code is completely free and open source. Original script written by Michael Martin.
*/
function ss_get_transient($name = 'twitter') {
$transName = "ss-transient-$name";
$cacheTime = 24;
if(false === ($trans = get_transient($transName) ) ) :
$func = "ss_get_$name";
if(function_exists($func) ) {
$trans = $func();
} else {
$trans = 'Function not found.';
}
if(!absint($trans) > 0)
$trans = get_transient($transName . '-old');
set_transient($transName, $trans, 60 * 60 * $cacheTime);
set_transient($transName.'-old', $trans, 3 * 60 * 60 * $cacheTime);
endif;
return $trans;
}
function ss_get_rss() {
$xml = wp_remote_get('http://feedburner.google.com/api/awareness/1.0/GetFeedData?uri=<?php echo ss_feedburner; ?>');
if(is_wp_error($xml))
return false;
$sxe = new SimpleXMLElement($xml['body']);
return intval($sxe->feed->entry['circulation']);
}
function ss_get_facebook() {
$json = wp_remote_get("http://graph.facebook.com/<?php echo ss_facebook; ?>");
if(is_wp_error($json))
return false;
$fbData = json_decode($json['body'], true);
return intval($fbData['likes']);
}
function ss_get_twitter() {
$json = wp_remote_get("http://api.twitter.com/1/users/show.json?screen_name=<?php echo ss_twitter; ?>");
if(is_wp_error($json))
return false;
$twitterData = json_decode($json['body'], true);
return intval($twitterData['followers_count']);
}
add_action('admin_menu', 'ss_create_menu');
function ss_create_menu() {
add_options_page('SocialStats Settings', 'SocialStats', 'administrator', __FILE__, 'ss_settings_page',plugins_url('wp-admin/images/marker.png', __FILE__));
add_action( 'admin_init', 'register_mysettings' );
}
function register_mysettings() {
register_setting( 'ss-settings-group', 'ss_feedburner' );
register_setting( 'ss-settings-group', 'ss_facebook' );
register_setting( 'ss-settings-group', 'ss_twitter' );
}
function ss_settings_page() {
?>
<div class="wrap">
<h2>SocialStats Settings</h2>
<em>Note: This doesn't work for personal Facebook profiles, only pages. To convert your profile to a page you can use <a href="https://www.facebook.com/pages/create.php?migrate" target="_blank">this tool</a>.</em>
<form method="post" action="options.php">
<?php settings_fields( 'ss-settings-group' ); ?>
<?php do_settings_sections( 'ss-settings-group' ); ?>
<table class="form-table">
<tr valign="top">
<th scope="row">FeedBurner<br /> <small>(<em><a href="http://feeds.feedburner.com/bryanhadawaysblog" target="_blank">feeds.feedburner.com/<strong>bryanhadawaysblog</strong></a></em>)</small></th>
<td><input type="text" name="ss_feedburner" value="<?php echo get_option('ss_feedburner'); ?>" /></td>
</tr>
<tr valign="top">
<th scope="row">Facebook<br /> <small>(<em><a href="http://www.facebook.com/calmestghost" target="_blank">facebook.com/<strong>calmestghost</strong></a></em>)</small></th>
<td><input type="text" name="ss_facebook" value="<?php echo get_option('ss_facebook'); ?>" /></td>
</tr>
<tr valign="top">
<th scope="row">Twitter<br /> <small>(<em><a href="http://twitter.com/calmestghost" target="_blank">twitter.com/<strong>calmestghost</strong></a></em>)</small></th>
<td><input type="text" name="ss_twitter" value="<?php echo get_option('ss_twitter'); ?>" /></td>
</tr>
</table>
<p class="submit">
<input type="submit" id="submit" class="button-primary" value="<?php esc_attr_e('Save Changes'); ?>" />
</p>
</form>
</div>
<?php } ?>
Now the PHP delivery of this code to front-end would be:
<?php
$sum = ss_get_transient('rss') + ss_get_transient('facebook') + ss_get_transient('twitter');
echo $sum;
?>
If I spent a little time on that I'm sure I could figure out the code to make it usable as a shortcode. But, if someone would like to collaborate that would save a lot of time.
Also, if you think we should add LinkedIn, Google+, YouTube, MySpace etc support let me know.
Thanks, Bryan
bhadaway@gmail.com
Design: http://calmestghost.com/ | Blog: http://bryanhadaway.com/
