HEX
Server: Apache/2.4.41 (Ubuntu)
System: Linux vmi1674223.contaboserver.net 5.4.0-182-generic #202-Ubuntu SMP Fri Apr 26 12:29:36 UTC 2024 x86_64
User: root (0)
PHP: 7.4.3-4ubuntu2.22
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/html/onlineshopold/wp-content/plugins/engotheme/widgets/social_counter.php
<?php
/**
 * Plugin Name: BK-Ninja: Social Counter Widget
 * Plugin URI: http://bk-ninja.com
 * Description: Displays social counters.
 * Version: 1.0
 * Author: BK-Ninja
 * Author URI: http://bk-ninja.com
 *
 */
 
/**
 * Include required files
 */
require_once dirname(__FILE__) . '/lib/twitteroauth.php';

 /**
 * Add function to widgets_init that'll load our widget.
 */
add_action('widgets_init','bk_register_social_counters_widget');

function bk_register_social_counters_widget() {
	register_widget('bk_social_counter');
	}

/**
 * This class handles everything that needs to be handled with the widget:
 * the settings, form, display, and update.  Nice!
 *
 */
class bk_social_counter extends WP_Widget {
    private $connection;

	private $consumer_key;
	private $consumer_secret;
	private $access_token;
	private $access_token_secret;	
	/**
	 * Widget setup.
	 */
	function bk_social_counter() {
		
		/* Widget settings. */
		$widget_ops = array('classname' => 'widget-social-counter','description' => __('[Sidebar widget] Displays social counters in sidebar.', 'bkninja'));
		
		/* Create the widget. */
		$this->WP_Widget('bk_social_counter',__('*BK: Widget Social Counters', 'bkninja'),$widget_ops);

	}
	
	/**
	 * display the widget on the screen.
	 */	
	function widget( $args, $instance ) {
		extract( $args );
		//user settings	
        $title = $instance['title'];   	
		$bk_youtube_username = $instance['bk_youtube_username'];
		$bk_dribbble_username = $instance['bk_dribbble_username'];
        $bk_rss_url = $instance['bk_rss_url'];
		$bk_facebook_username = $instance['bk_facebook_username'];
		$bk_twitter_id = $instance['bk_twitter_id'];

		$this->consumer_key = isset( $instance['bk_consumer_key'] ) ? $instance['bk_consumer_key'] : '';
		$this->consumer_secret = isset( $instance['bk_consumer_secret'] ) ? $instance['bk_consumer_secret'] : '';
		$this->access_token = isset( $instance['bk_access_token'] ) ? $instance['bk_access_token'] : '';
		$this->access_token_secret = isset( $instance['bk_access_secret'] ) ? $instance['bk_access_secret'] : '';	
		

		echo esc_attr($before_widget;
		if ( $title )
			echo esc_attr($before_title . $title . $after_title;

		//twitter
		if (isset($bk_twitter_id)&&($bk_twitter_id != NULL)){
			$interval = 600;				
			$follower_count = 0;
			
			if(time() > get_option('bk_twitter_cache_time')) {
				

      		    if ($this->pre_validate_keys() === true) {
        			$this->connection = new TwitterOAuth( $this->consumer_key, $this->consumer_secret, $this->access_token, $this->access_token_secret );
        		} else {
        			echo '<p>Twitter Widget not configured</p>';
        		}
                $this->connection->get('account/verify_credentials');
			
				if ($this->connection->http_code == 200 ) {
				    $userInfo = $this->connection->get('users/show',array('screen_name' => $bk_twitter_id));
					$follower_count = $userInfo->followers_count;
					if ($follower_count > 0 ) {
						update_option('bk_twitter_cache_time', time() + $interval);
						update_option('bk_twitter_followers', $follower_count);
					}
				}			
			}	 
		}
		
		//facebook
		if (isset($bk_facebook_username)&&($bk_facebook_username != NULL)){
			$interval = 600;
			$fb_likes = 0;
			
			if(time() > get_option('bk_facebook_cache_time')) {
				
				$api = wp_remote_get('http://graph.facebook.com/' . $bk_facebook_username);
				
				if (!is_wp_error($api)) {
					
					$json = json_decode($api['body']);
					$fb_likes = $json->likes;
					
					if ($fb_likes > 0 ) {
						update_option('bk_facebook_cache_time', time() + $interval);
						update_option('bk_facebook_followers', $fb_likes);
						update_option('bk_facebook_link', $json->link);
					}
				
				}				
				
			}
		}
		
		//dribbble
		if (isset($bk_dribbble_username)&&($bk_dribbble_username != NULL)){
			$interval = 600;
			$followers_count = 0;
			if(time() > get_option('bk_dribbble_cache_time')) {
				
				$api = wp_remote_get('http://api.dribbble.com/' . $bk_dribbble_username);
				
				if (!is_wp_error($api)) {
					$json = json_decode($api['body']);
					$followers_count = $json->followers_count;
					
					if ($followers_count > 0 ) {
						update_option('bk_dribbble_cache_time', time() + $interval);
						update_option('bk_dribbble_followers', $followers_count );
					}
				}
			}
		}
        
        if(isset($bk_youtube_username)&&($bk_youtube_username != NULL)){
            $interval = 600;
            $data = file_get_contents('http://gdata.youtube.com/feeds/api/users/'.$bk_youtube_username);
            if(time() > get_option('bk_youtube_cache_time')) {                
                if($data != null){
                    $xml = new SimpleXMLElement($data);
                    $stats_data = (array)$xml->children('yt', true)->statistics->attributes();
                    $stats_data = $stats_data['@attributes'];
                    $subscriberCount = $stats_data['subscriberCount'];
                }
                if ($subscriberCount > 0 ){
                    update_option('bk_youtube_cache_time', time() + $interval);
                    update_option('bk_youtube_subscribers', $subscriberCount );
                }
            }
                      
        }
		?>
		<div class="wrap">
			<ul>
											
				<?php if (isset($bk_twitter_id)&&($bk_twitter_id != NULL)){ ?>
					<li class="twitter clear-fix">
                        <a target="_blank" href="http://twitter.com/<?php echo esc_attr( $bk_twitter_id ); ?>">
    						<div class="icon"><i class="fa fa-twitter"></i></div>
    						<div class="left">
    							<div class="count"><h4><?php echo get_option('bk_twitter_followers'); ?></h4></div>
    							<div class="text"><?php _e('Followers', 'engotheme');?></div>
    						</div>
                        </a>
					</li> <!-- /twitter -->
				<?php } ?>
				
				<?php if (isset($bk_facebook_username) && ($bk_facebook_username != NULL)){ ?>
					<li class="facebook clear-fix">
                        <a target="_blank" href="<?php echo get_option('bk_facebook_link'); ?>">
    						<div class="icon"><i class="fa fa-facebook"></i></div>
    						<div class="left">				
    							<div class="count"><h4><?php echo get_option('bk_facebook_followers'); ?></h4></div>
    							<div class="text"><?php _e('Likes', 'engotheme');?></div>
    						</div>
                        </a>
					</li><!-- /facebook -->
				<?php } ?>
                
				<?php if (isset($bk_dribbble_username)&&($bk_dribbble_username != NULL)){ ?>
					<li class="dribbble clear-fix">
                        <a target="_blank" href="http://dribbble.com/<?php echo esc_attr( $bk_dribbble_username ); ?>">
    						<div class="icon"><i class="fa fa-dribbble"></i></div>
    						<div class="left">
    							<div class="count"><h4><?php echo get_option('bk_dribbble_followers'); ?></h4></div>
    							<div class="text"><?php _e('Followers', 'engotheme'); ?></div>
    						</div>
                        </a>				
					</li>
				<?php } ?>
				
				<?php if (isset($bk_youtube_username)&&($bk_youtube_username != NULL)){ ?>
					<li class="youtube clear-fix">
                        <a target="_blank" href="http://www.youtube.com/user/<?php echo esc_attr( $bk_youtube_username ) ;?>">
    						<div class="icon"><i class="fa fa-youtube"></i></div>
    						<div class="left">
    							<div class="subscribe"><h4><?php echo get_option('bk_youtube_subscribers'); ?></h4></div>
    							<div class="text"><?php _e('Subscribe', 'engotheme'); ?></div>
    						</div>
                        </a>				
					</li>
				<?php } ?>
                
                <?php if (isset($bk_rss_url)){ ?>
					<li class="rss clear-fix">
                        <a target="_blank" href="<?php echo esc_url( $bk_rss_url ); ?>">
    						<div class="icon"><i class="fa fa-rss"></i></div>
    						<div class="left">
    							<div class="subscribe"><h4><?php _e('Subscribe', 'engotheme'); ?></h4></div>
    							<div class="text"><?php _e('RSS Feeds', 'engotheme'); ?></div>
    						</div>	
                        </a>			
					</li>
				<?php } ?>
				
			</ul>
				
		</div><!-- /wrap -->			
		<?php 
		echo esc_attr($after_widget;
	}
	
	/**
	 * update widget settings
	 */
	function update( $new_instance, $old_instance ) {
		$instance = $old_instance;		
		$instance['title'] = strip_tags($new_instance['title']); 
		$instance['bk_youtube_username'] = $new_instance['bk_youtube_username'];
		$instance['bk_dribbble_username'] = $new_instance['bk_dribbble_username'];
		$instance['bk_facebtook_username'] = $new_instance['bk_facebook_username'];
        $instance['bk_rss_url'] = $new_instance['bk_rss_url'];
        $instance['bk_twitter_id'] = $new_instance['bk_twitter_id'];
		$instance['bk_consumer_key'] = $new_instance['bk_consumer_key'];	
		$instance['bk_consumer_secret'] = $new_instance['bk_consumer_secret'];	
		$instance['bk_access_token'] = $new_instance['bk_access_token'];	
		$instance['bk_access_secret'] = $new_instance['bk_access_secret'];
		return $instance;
	}
	
	/**
	 * Displays the widget settings controls on the widget panel.
	 * Make use of the get_field_id() and get_field_name() function
	 * when creating your form elements. This handles the confusing stuff.
	 */
	 
	function form( $instance ) {

		/* Set up some default widget settings. */
		$defaults = array(
        	'title' => '',		
			'youtube_username' => '',
			'dribbble_username' => '',
			'twitter_id' => '',
			'facebook_username' => '',
            'rss_url' => '',
			'consumer_key' => 'XZYM8uHmu0lXtx8xVjCuxQ',	
			'consumer_secret' => 'B8FsIfDysKsop5g3BKWKgLD4r7bU3XJIIUYtwd3TQDQ',	
			'access_token' => '2280855410-aCtdy5vTBDMcLdwvRfapewVcJqJpqDVJSOS3IbG',	
			'access_secret' => 'MfP0i6CaratjHwkznBNrSQnIaBHrexb6HE2njOTNuiZUX'
 		);
		$instance = wp_parse_args( (array) $instance, $defaults ); ?>
		<!-- Title: Text Input -->     
		<p>
			<label for="<?php echo esc_attr($this->get_field_id( 'title' )); ?>"><strong><?php _e('Title:', 'engotheme');?></strong></label>
            <input type="text" id="<?php echo esc_attr($this->get_field_id( 'title' )); ?>" name="<?php echo esc_attr($this->get_field_name( 'title' )); ?>" value="<?php echo esc_attr( $instance['title'] )); ?>" class="widefat" />
		</p>
                
		<p>
			<label for="<?php echo esc_attr($this->get_field_id( 'bk_facebook_username' )); ?>"><strong><?php _e('Facebook Username:', 'engotheme');?></strong></label>
			<input type="text" id="<?php echo esc_attr($this->get_field_id( 'bk_facebook_username' )); ?>" name="<?php echo esc_attr($this->get_field_name( 'bk_facebook_username' )); ?>" value="<?php echo esc_attr( $instance['bk_facebook_username'] ); ?>" class="widefat" />
		</p>

        <p>
			<label for="<?php echo esc_attr($this->get_field_id( 'bk_dribbble_username' ); ?>"><strong><?php _e('Dribbble Username', 'engotheme');?></strong></label>
			<input type="text" id="<?php echo esc_attr($this->get_field_id( 'bk_dribbble_username' )); ?>" name="<?php echo esc_attr($this->get_field_name( 'bk_dribbble_username' )); ?>" value="<?php echo esc_attr( $instance['bk_dribbble_username'] ); ?>" class="widefat" />
        </p>
        
        <p>
			<label for="<?php echo esc_attr($this->get_field_id( 'bk_youtube_username' ); ?>"><strong><?php _e('Youtube username', 'engotheme');?></strong></label>
			<input type="text" id="<?php echo esc_attr($this->get_field_id( 'bk_youtube_username' )); ?>" name="<?php echo esc_attr($this->get_field_name( 'bk_youtube_username' )); ?>" value="<?php echo esc_attr( $instance['bk_youtube_username'] ); ?>" class="widefat" />
		</p>

		<p>
			<label for="<?php echo esc_attr($this->get_field_id( 'bk_rss_url' )); ?>"><strong><?php _e('RSS URL', 'engotheme');?></strong></label>
			<input type="text" id="<?php echo esc_attr($this->get_field_id( 'bk_rss_url' ); ?>" name="<?php echo esc_attr($this->get_field_name( 'bk_rss_url' )); ?>" value="<?php echo esc_url( $instance['bk_rss_url'] ); ?>" class="widefat" />
		</p>

		<p>
			<label for="<?php echo esc_attr($this->get_field_id( 'bk_twitter_id' )); ?>"><strong><?php _e('Twitter Name', 'engotheme');?></strong></label>
			<input type="text" id="<?php echo esc_attr($this->get_field_id( 'bk_twitter_id' ); ?>" name="<?php echo esc_attr($this->get_field_name( 'bk_twitter_id' )); ?>" value="<?php echo esc_attr( $instance['bk_twitter_id'] ); ?>" class="widefat" />
        </p>

		<p>
			<label for="<?php echo esc_attr($this->get_field_id( 'bk_consumer_key' )); ?>"><strong><?php _e('Consumer key', 'engotheme') ?></strong></label>
			<input type="text" class="widefat" id="<?php echo esc_attr($this->get_field_id( 'bk_consumer_key' ); ?>" name="<?php echo esc_attr($this->get_field_name( 'bk_consumer_key' )); ?>" value="<?php echo esc_attr($instance['bk_consumer_key']); ?>" />			
		</p>
		
		<p>
			<label for="<?php echo esc_attr($this->get_field_id( 'bk_consumer_secret') ); ?>"><strong><?php _e('Consumer secret', 'engotheme') ?></strong></label>
			<input type="text" class="widefat" id="<?php echo esc_attr($this->get_field_id( 'bk_consumer_secret' ); ?>" name="<?php echo esc_attr($this->get_field_name( 'bk_consumer_secret' )); ?>" value="<?php echo esc_attr($instance['bk_consumer_secret']); ?>" />			
		</p>
		
		<p>
			<label for="<?php echo esc_attr($this->get_field_id( 'bk_access_token' )); ?>"><strong><?php _e('Access token', 'bkninja');?></strong></label>
			<input type="text" class="widefat" id="<?php echo esc_attr($this->get_field_id( 'bk_access_token' )); ?>" name="<?php echo esc_attr($this->get_field_name( 'bk_access_token' )); ?>" value="<?php echo esc_attr($instance['bk_access_token']); ?>" />			
		</p>
		
		<p>
			<label for="<?php echo esc_attr($this->get_field_id( 'bk_access_secret' )); ?>"><strong><?php _e('Access token secret', 'bkninja');?></strong></label>
			<input type="text" class="widefat" id="<?php echo esc_attr($this->get_field_id( 'bk_access_secret' )); ?>" name="<?php echo esc_attr($this->get_field_name( 'bk_access_secret' )); ?>" value="<?php echo esc_attr($instance['bk_access_secret']); ?>" />			
		</p>


	<?php 
	}
    	function pre_validate_keys() {
    	if ( ! $this->consumer_key        ) return false;
    	if ( ! $this->consumer_secret     ) return false;
    	if ( ! $this->access_token        ) return false;
    	if ( ! $this->access_token_secret ) return false;
    
    	return true;
	}
} //end class