· 9 years ago · Sep 22, 2016, 07:44 AM
1<?php
2/**
3 * @package SJ Social Media Counter
4 * @version 1.0.1
5 * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
6 * @copyright (c) 2014 YouTech Company. All Rights Reserved.
7 * @author YouTech Company http://www.smartaddons.com
8 */
9
10defined('_JEXEC') or die ();
11
12abstract class SjSocialMediaCountsHelper
13{
14 public static function getList(&$params)
15 {
16 $return = array();
17 if ((int)$params->get('display_sfacebook', 0)) {
18 $return['count_facebook_like'] = self::getFacebookLike($params);
19 }
20
21 if ((int)$params->get('display_stwitter', 0)) {
22 $return['count_followers_twitter'] = self::getFollowersTwitter($params);
23 }
24
25 if ((int)$params->get('display_slinkedin', 0)) {
26 $return['count_followers_linkedin'] = self::getFollowersLinkedin($params);
27 }
28
29 if ((int)$params->get('display_svimeo', 0)) {
30 $return['count_followers_vimeo'] = self::getFollowersVimeo($params);
31 }
32
33 if ((int)$params->get('display_ssoundcloud', 0)) {
34 $return['count_followers_soundcloud'] = self::getFollowersSoundCloud($params);
35 }
36
37 if ((int)$params->get('display_sdribbble', 0)) {
38 $return['count_followers_dribbble'] = self::getFollowersDribbble($params);
39 }
40
41 if ((int)$params->get('display_syoutube', 0)) {
42 $return['count_subscribers_youtube'] = self::getSubscribersYoutube($params);
43 }
44
45 if ((int)$params->get('display_sgplus', 0)) {
46 $return['count_followers_gplus'] = self::getFollowersGplus($params);
47 }
48
49 if ((int)$params->get('display_sinstagram', 0)) {
50 $return['count_followers_instagram'] = self::getFollowersInstagram($params);
51 }
52
53 if ((int)$params->get('display_rss', 0)) {
54 $return['rss_url'] = $params->get('rss_url', '#');
55 }
56 return $return;
57 }
58
59 // Facebook //
60 private static function getFacebookLike1($params)
61 {
62 $url = $params->get('facebook_url');
63 $url = urlencode($url);
64 $json_string = @file_get_contents('http://api.facebook.com/restserver.php?method=links.getStats&format=json&urls=' . $url);
65 $json = json_decode($json_string, true);
66 $like_count = isset($json['0']) && $json['0']['like_count'] ? $json['0']['like_count'] : 0;
67 return $like_count;
68 }
69 private static function getFacebookLike($params){
70 $id = $params->get('facebook_url');
71 $appid = $params->get('appid');
72 $appsecret = $params->get('appsecret');
73 $json_url ='https://graph.facebook.com/'.$id.'?access_token='.$appid.'|'.$appsecret.'&fields=fan_count';
74 $json = @file_get_contents($json_url);
75 $json_output = json_decode($json);
76 //Extract the likes count from the JSON object
77 $like_count = isset($json_output->fan_count) ? $json_output->fan_count : 0;
78 return $like_count;
79 }
80
81 // Twitter //
82 private static function getFollowersTwitter($params)
83 {
84 if(!class_exists('TwitterOAuth')){
85
86 require_once dirname( __FILE__ ).'/twitteroauth.php';
87
88 }
89 $consumerKey = $params->get('consumekey','kGeoSxX3i60oXODNAlOCw');
90 $consumerSecret = $params->get('consumersecret','EqvsqEwoeYMMITJ3fSYaVjSuv7w6ORwt5sADuuNYcs');
91 $oAuthToken = null;
92 $oAuthSecret = null;
93 $screenName = $params->get('screenname','smartaddons');
94 $Tweet = new TwitterOAuth($consumerKey, $consumerSecret, $oAuthToken, $oAuthSecret);
95 $foll = $Tweet->get("https://api.twitter.com/1.1/users/lookup.json?screen_name=" . $screenName);
96 $items = json_decode($foll);
97 $followers_count = isset($items[0]->followers_count)?$items[0]->followers_count:0;
98 return $followers_count;
99
100 }
101
102 // Linkedin //
103 private static function getFollowersLinkedin($params)
104 {
105 $url = $params->get('linkedin_url','http://www.linkedin.com/in/smartaddons');
106 $url = urlencode($url);
107 $json_string = @file_get_contents("http://www.linkedin.com/countserv/count/share?url=$url&format=json");
108 $json = json_decode($json_string, true);
109 $followers_count = isset($json['fCntPlusOne'])?$json['fCntPlusOne']:0;
110 return $followers_count;
111 }
112
113 // Vimeo //
114 private static function getFollowersVimeo($params)
115 {
116 $url = $params->get('vimeo_username', 'royalhandmadecustoms');
117 $url = urlencode($url);
118 $json_string = @file_get_contents('http://vimeo.com/api/v2/' . $url . '/info.json');
119 $json = json_decode($json_string, true);
120 $followers_count = isset($json['total_contacts']) ? $json['total_contacts'] : 0;
121 return $followers_count;
122 }
123
124 // SoundCloud //
125 private static function getFollowersSoundCloud($params)
126 {
127 $soundc_un = $params->get('soundc_un', null);
128 $soundc_id = $params->get('soundc_id', null);
129 $json_string = @file_get_contents('http://api.soundcloud.com/users/' . $soundc_un . '.json?client_id=' . $soundc_id);
130 $json = json_decode($json_string, true);
131 $followers_count = isset($json['followers_count']) ? $json['followers_count'] : 0;
132 return $followers_count;
133 }
134
135
136 // Dirbbble //
137 private static function getFollowersDribbble( $params ){
138 $dr_token = $params->get('access_token');
139 $data_all = "https://api.dribbble.com/v1/user?access_token=".$dr_token;
140 $data_count = @file_get_contents($data_all);
141 $d_data = json_decode( $data_count, true );
142 $dribbble_count = $d_data['followers_count'];
143 return $dribbble_count;
144 }
145
146 // Subscribers Youtube //
147 private static function getSubscribersYoutube($params)
148 {
149 global $social_counter_settings;
150 $settings = $social_counter_settings;
151 $count = -1;
152 $youtubeUrl = "https://www.googleapis.com/youtube/v3/channels?part=statistics&id=".$params->get('youtube_channel_id')."&key=".$params->get('google_api_key');
153 $response = @file_get_contents($youtubeUrl);
154 $fb = json_decode($response);
155 if ( isset( $fb->items[0])) {
156 $count = intval( $fb->items[0]->statistics -> subscriberCount);
157 }
158 return $count ;
159 }
160
161 // Google Plus //
162 private static function getFollowersGplus($params)
163 {
164 $gplus_id = $params->get('gplus_id');
165 $gplus_key = $params->get('gplus_key');
166 $json_string = @file_get_contents('https://www.googleapis.com/plus/v1/people/' . $gplus_id . '?key=' . $gplus_key);
167 $json = json_decode($json_string, true);
168 $followers_count = isset($json['circledByCount']) ? $json['circledByCount'] : 0;
169 return $followers_count;
170 }
171
172 // Instagram //
173 private static function getFollowersInstagram($params)
174 {
175 $userID = $params->get('inst_userid', null);
176 $access_token = $params->get('inst_access_token', null);
177 $json_string = @file_get_contents('https://api.instagram.com/v1/users/' . $userID . '?access_token=' . $access_token);
178 $json = json_decode($json_string, true);
179 $followers_count = isset($json['data']['counts']['followed_by']) ? $json['data']['counts']['followed_by'] : 0;
180 return $followers_count;
181 }
182}