first commit

This commit is contained in:
alazhar
2020-01-02 23:15:16 +07:00
commit eda9661806
3433 changed files with 595883 additions and 0 deletions

View File

@ -0,0 +1,95 @@
<?php
function get_url_contents($url){
$crl = curl_init();
$timeout = 5;
curl_setopt ($crl, CURLOPT_URL,$url);
curl_setopt ($crl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($crl, CURLOPT_CONNECTTIMEOUT, $timeout);
$ret = curl_exec($crl);
curl_close($crl);
return $ret;
}
class SubscriberStats{
public $twitter, $rss, $facebook;
public $services = array();
public function __construct($arr){
$this->services = $arr;
if(trim($arr['twitterName'])) {
$connection = getConnectionWithAccessToken($arr['consumer_key'], $arr['consumer_secret'], $arr['access_token'], $arr['access_token_secret']);
$tweets = $connection->get('http://api.twitter.com/1.1/users/show.json?screen_name='.$arr['twitterName']) or die('Couldn\'t retrieve tweets! Wrong username?');
if(!empty($tweets->errors)){
if($tweets->errors[0]->message == 'Invalid or expired token'){
echo '<strong>'.$tweets->errors[0]->message.'!</strong><br />You\'ll need to regenerate it <a href="https://dev.twitter.com/apps" target="_blank">here</a>!' . $after_widget;
}else{
echo '<strong>'.$tweets->errors[0]->message.'</strong>' . $after_widget;
}
return;
}
$new_twitter = $tweets->followers_count;
if( empty($new_twitter) || $new_twitter == 0 || $new_twitter == '0' ){
$this->twitter = $arr['twitter'];
}else{
$this->twitter = $new_twitter;
}
}
if(trim($arr['facebookFanPageURL'])) {
$fb_id = basename($arr['facebookFanPageURL']);
$query = 'http://graph.facebook.com/'.urlencode($fb_id);
$result = json_decode(get_url_contents($query));
$new_facebook = $result->likes;
if( empty($new_facebook) || $new_facebook == 0 || $new_facebook == '0' ){
$this->facebook = $arr['facebook'];
}else{
$this->facebook = $new_facebook;
}
}
}
public function generate(){
$gdl_icon_type = get_option(THEME_SHORT_NAME.'_icon_type','dark');
?>
<div class="social-counter-widget-wrapper">
<?php if($this->services['twitterName']) { ?>
<a class="social-counter-widget facebook" href="http://twitter.com/<?php echo $this->services['twitterName']?>" target="_blank">
<span class="icon"><img class="gdl-no-preload" src="<?php echo GOODLAYERS_PATH . '/images/icon/' . $gdl_icon_type . '/social-widget-twitter.png'; ?>" alt="" /></span>
<span class="count"><?php echo number_format($this->twitter); ?></span>
<span class="title"><?php _e('Followers', 'gdl_front_end'); ?></span>
</a>
<?php } ?>
<?php if($this->services['facebookFanPageURL']) { ?>
<a class="social-counter-widget twitter" href="<?php echo $this->services['facebookFanPageURL']?>" target="_blank" >
<span class="icon"><img class="gdl-no-preload" src="<?php echo GOODLAYERS_PATH . '/images/icon/' . $gdl_icon_type . '/social-widget-facebook.png'; ?>" alt="" /></span>
<span class="count"><?php echo number_format($this->facebook); ?></span>
<span class="title"><?php _e('Fans', 'gdl_front_end'); ?></span>
</a>
<?php } ?>
<?php if($this->services['feedBurnerURL']) { ?>
<a class="social-counter-widget rss" href="<?php echo $this->services['feedBurnerURL']; ?>" target="_blank">
<span class="icon"><img class="gdl-no-preload" src="<?php echo GOODLAYERS_PATH . '/images/icon/' . $gdl_icon_type . '/social-widget-rss.png'; ?>" alt="" /></span>
<span class="count"><?php _e('RSS', 'gdl_front_end'); ?></span>
<span class="title"><?php _e('Subscribers', 'gdl_front_end'); ?></span>
</a>
<?php } ?>
<div class="clear"></div>
</div>
<?php
}
}
?>

View File

@ -0,0 +1,165 @@
<?php
/**
* Plugin Name: Social Counter Widget
* Plugin URI: http://goodlayers.com/
* Description: This widget will display your RSS subscribers, Twitter followers and Facebook fans in one nice looking box.
* Version: 1.0
* Author: Goodlayers
* Author URI: http://www.goodlayers.com
*
*/
require "scw_stats.class.php";
add_action('widgets_init', 'gdl_social_widget');
function gdl_social_widget() {
register_widget( 'SC_widget' );
}
class SC_widget extends WP_Widget {
// Initialize the widget
function SC_widget() {
parent::WP_Widget(false, $name = 'Social Counter Widget');
$this->cacheFileName = WP_CONTENT_DIR."/sc_cache.txt";
}
// Output of the widget
function widget($args, $instance) {
extract( $args );
$title = apply_filters( 'widget_title', $instance['title'] );
$facebook_id = $instance['facebook_id'];
$twitter_id = $instance['twitter_id'];
$feedburner_id = $instance['feedburner_id'];
$consumer_key = $instance[ 'consumer_key' ];
$consumer_secret = $instance[ 'consumer_secret' ];
$access_token = $instance[ 'access_token' ];
$access_token_secret = $instance[ 'access_token_secret' ];
$cacheFileName = $this->cacheFileName;
if( file_exists($cacheFileName) && ((time() - filemtime($cacheFileName)) < 30*60) ){
$stats = unserialize(file_get_contents($cacheFileName));
}else if( file_exists($cacheFileName) ){
$old_stats = unserialize(file_get_contents($cacheFileName));
}
if(!$stats){
$stats = new SubscriberStats(array(
'facebookFanPageURL' => $facebook_id,
'feedBurnerURL' => $feedburner_id,
'twitterName' => $twitter_id,
'consumer_key' => $consumer_key,
'consumer_secret' => $consumer_secret,
'access_token' => $access_token,
'access_token_secret' => $access_token_secret,
'rss' => $old_stats->rss,
'twitter' => $old_stats->twitter,
'facebook' => $old_stats->facebook
));
file_put_contents($cacheFileName, serialize($stats));
}
if ( $title ){
echo '<div class="gdl-social-counter-title">';
echo $before_title . $title . $after_title;
echo '</div>';
}
echo '<div class="gdl-social-counter-widget-wrapper">';
echo $before_widget;
echo '<div class="gdl-social-counter-widget">';
echo '<div class="clear"></div>';
$stats->generate();
echo '<div class="clear"></div>';
echo '</div>';
echo $after_widget;
echo '</div>'; // gdl-social-counter-widget-wrapper
}
// Widget Form
function form($instance) {
$title = esc_attr( $instance[ 'title' ] );
$twitter_id = esc_attr($instance['twitter_id']);
$facebook_id = esc_attr($instance['facebook_id']);
$feedburner_id = esc_attr($instance['feedburner_id']);
$consumer_key = esc_attr( $instance[ 'consumer_key' ] );
$consumer_secret = esc_attr( $instance[ 'consumer_secret' ] );
$access_token = esc_attr( $instance[ 'access_token' ] );
$access_token_secret = esc_attr( $instance[ 'access_token_secret' ] );
?>
<!-- Text Input -->
<p>
<label for="<?php echo $this->get_field_id('title'); ?>"><?php _e( 'Title :', 'gdl_back_office' ); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" />
</p>
<p>
<label for="<?php echo $this->get_field_id('facebook_id'); ?>"><?php _e('Facebook page URL (not ID !):', 'gdl_back_office'); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id('facebook_id'); ?>" name="<?php echo $this->get_field_name('facebook_id'); ?>" type="text" value="<?php echo $facebook_id; ?>" />
</p>
<p>
<label for="<?php echo $this->get_field_id('feedburner_id'); ?>"><?php _e('Feedburner URL (not ID !):', 'gdl_back_office'); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id('feedburner_id'); ?>" name="<?php echo $this->get_field_name('feedburner_id'); ?>" type="text" value="<?php echo $feedburner_id; ?>" />
</p>
<p>
<label for="<?php echo $this->get_field_id('twitter_id'); ?>"><?php _e('Twitter ID:', 'gdl_back_office'); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id('twitter_id'); ?>" name="<?php echo $this->get_field_name('twitter_id'); ?>" type="text" value="<?php echo $twitter_id; ?>" />
</p>
<!-- Consumer Key -->
<p>
<label for="<?php echo $this->get_field_id( 'consumer_key' ); ?>"><?php _e('Consumer Key :', 'gdl_back_office'); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id( 'consumer_key' ); ?>" name="<?php echo $this->get_field_name( 'consumer_key' ); ?>" type="text" value="<?php echo $consumer_key; ?>" />
</p>
<!-- Consumer Secret -->
<p>
<label for="<?php echo $this->get_field_id( 'consumer_secret' ); ?>"><?php _e('Consumer Secret :', 'gdl_back_office'); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id( 'consumer_secret' ); ?>" name="<?php echo $this->get_field_name( 'consumer_secret' ); ?>" type="text" value="<?php echo $consumer_secret; ?>" />
</p>
<!-- Access Token -->
<p>
<label for="<?php echo $this->get_field_id( 'access_token' ); ?>"><?php _e('Access Token :', 'gdl_back_office'); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id( 'access_token' ); ?>" name="<?php echo $this->get_field_name( 'access_token' ); ?>" type="text" value="<?php echo $access_token; ?>" />
</p>
<!-- Access Token Secret -->
<p>
<label for="<?php echo $this->get_field_id( 'access_token_secret' ); ?>"><?php _e('Access Token Secret :', 'gdl_back_office'); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id( 'access_token_secret' ); ?>" name="<?php echo $this->get_field_name( 'access_token_secret' ); ?>" type="text" value="<?php echo $access_token_secret; ?>" />
</p>
<?php
}
// Update the widget
function update($new_instance, $old_instance) {
if($new_instance != $old_instance) unlink($this->cacheFileName);
$instance = $old_instance;
$instance['title'] = strip_tags($new_instance['title']);
$instance['twitter_id'] = strip_tags($new_instance['twitter_id']);
$instance['facebook_id'] = strip_tags($new_instance['facebook_id']);
$instance['feedburner_id'] = strip_tags($new_instance['feedburner_id']);
$instance['consumer_key'] = strip_tags( $new_instance['consumer_key'] );
$instance['consumer_secret'] = strip_tags( $new_instance['consumer_secret'] );
$instance['access_token'] = strip_tags( $new_instance['access_token'] );
$instance['access_token_secret'] = strip_tags( $new_instance['access_token_secret'] );
return $instance;
}
} // SC_widget
?>