Social Counter for WordPress – AccessPress Social Counter - Version 1.0.7

Version Description

  • Added Counter Format Option
Download this release

Release Info

Developer Access Keys
Plugin Icon 128x128 Social Counter for WordPress – AccessPress Social Counter
Version 1.0.7
Comparing to
See all releases

Code changes from version 1.0.6 to 1.0.7

accesspress-social-counter.php CHANGED
@@ -5,7 +5,7 @@ defined('ABSPATH') or die("No script kiddies please!");
5
  * Plugin Name: AccessPress Social Counter
6
  * Plugin URI: https://accesspressthemes.com/wordpress-plugins/accesspress-social-counter/
7
  * Description: A plugin to display your social accounts fans, subscribers and followers number on your website with handful of backend settings and interface.
8
- * Version: 1.0.6
9
  * Author: AccessPress Themes
10
  * Author URI: http://accesspressthemes.com
11
  * Text Domain: aps-counter
@@ -26,7 +26,7 @@ if (!defined('SC_CSS_DIR')) {
26
  define('SC_CSS_DIR', plugin_dir_url(__FILE__) . 'css');
27
  }
28
  if (!defined('SC_VERSION')) {
29
- define('SC_VERSION', '1.0.6');
30
  }
31
  /**
32
  * Register of widgets
@@ -160,6 +160,7 @@ if (!class_exists('SC_Class')) {
160
  ),
161
  'profile_order' => array('facebook', 'twitter', 'googlePlus', 'instagram', 'youtube', 'soundcloud', 'dribbble', 'posts', 'comments'),
162
  'social_profile_theme' => 'theme-1',
 
163
  'cache_period' => ''
164
  );
165
  return $apsc_settings;
@@ -313,6 +314,44 @@ if (!class_exists('SC_Class')) {
313
  }
314
  return $count;
315
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
316
 
317
  }
318
 
5
  * Plugin Name: AccessPress Social Counter
6
  * Plugin URI: https://accesspressthemes.com/wordpress-plugins/accesspress-social-counter/
7
  * Description: A plugin to display your social accounts fans, subscribers and followers number on your website with handful of backend settings and interface.
8
+ * Version: 1.0.7
9
  * Author: AccessPress Themes
10
  * Author URI: http://accesspressthemes.com
11
  * Text Domain: aps-counter
26
  define('SC_CSS_DIR', plugin_dir_url(__FILE__) . 'css');
27
  }
28
  if (!defined('SC_VERSION')) {
29
+ define('SC_VERSION', '1.0.7');
30
  }
31
  /**
32
  * Register of widgets
160
  ),
161
  'profile_order' => array('facebook', 'twitter', 'googlePlus', 'instagram', 'youtube', 'soundcloud', 'dribbble', 'posts', 'comments'),
162
  'social_profile_theme' => 'theme-1',
163
+ 'counter_format'=>'comma',
164
  'cache_period' => ''
165
  );
166
  return $apsc_settings;
314
  }
315
  return $count;
316
  }
317
+
318
+ /**
319
+ *
320
+ * @param int $count
321
+ * @param string $format
322
+ */
323
+ function get_formatted_count($count, $format) {
324
+ switch ($format) {
325
+ case 'comma':
326
+ $count = number_format($count);
327
+ break;
328
+ case 'short':
329
+ $count = $this->abreviateTotalCount($count);
330
+ break;
331
+ default:
332
+ break;
333
+ }
334
+ return $count;
335
+ }
336
+
337
+ /**
338
+ *
339
+ * @param integer $value
340
+ * @return string
341
+ */
342
+ function abreviateTotalCount($value) {
343
+
344
+ $abbreviations = array(12 => 'T', 9 => 'B', 6 => 'M', 3 => 'K', 0 => '');
345
+
346
+ foreach ($abbreviations as $exponent => $abbreviation) {
347
+
348
+ if ($value >= pow(10, $exponent)) {
349
+
350
+ return round(floatval($value / pow(10, $exponent)), 1) . $abbreviation;
351
+ }
352
+ }
353
+ }
354
+
355
 
356
  }
357
 
inc/backend/boards/display-settings.php CHANGED
@@ -53,5 +53,19 @@
53
  </label>
54
  </div>
55
  </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
  </div>
57
  </div>
53
  </label>
54
  </div>
55
  </div>
56
+ <div class="apsc-option-inner-wrapper">
57
+ <label><?php _e('Counter Format','aps-counter');?></label>
58
+ <div class="apsc-option-field">
59
+ <label>
60
+ <input type="radio" name="counter_format" value="default" <?php if(isset($apsc_settings['counter_format'])){checked($apsc_settings['counter_format'],'default');}?> checked="checked"/>12200
61
+ </label>
62
+ <label>
63
+ <input type="radio" name="counter_format" value="comma" <?php if(isset($apsc_settings['counter_format'])){ checked($apsc_settings['counter_format'],'comma');}?>/>12,200
64
+ </label>
65
+ <label>
66
+ <input type="radio" name="counter_format" value="short" <?php if(isset($apsc_settings['counter_format'])){ checked($apsc_settings['counter_format'],'short');}?>/>12.2K
67
+ </label>
68
+ </div>
69
+ </div>
70
  </div>
71
  </div>
inc/backend/save-settings.php CHANGED
@@ -81,6 +81,7 @@ $apsc_settings['social_profile'] = $social_profile;
81
  $apsc_settings['profile_order'] = $profile_order;
82
  $apsc_settings['cache_period'] = $cache_period;
83
  $apsc_settings['social_profile_theme'] = $social_profile_theme;
 
84
  update_option('apsc_settings', $apsc_settings);
85
  $_SESSION['apsc_message'] = __('Settings Saved Successfully');
86
  wp_redirect(admin_url().'admin.php?page=ap-social-counter');
81
  $apsc_settings['profile_order'] = $profile_order;
82
  $apsc_settings['cache_period'] = $cache_period;
83
  $apsc_settings['social_profile_theme'] = $social_profile_theme;
84
+ $apsc_settings['counter_format'] = $counter_format;
85
  update_option('apsc_settings', $apsc_settings);
86
  $_SESSION['apsc_message'] = __('Settings Saved Successfully');
87
  wp_redirect(admin_url().'admin.php?page=ap-social-counter');
inc/frontend/shortcode.php CHANGED
@@ -4,6 +4,7 @@ defined('ABSPATH') or die("No script kiddies please!");
4
  $apsc_settings = $this->apsc_settings;
5
  $cache_period = ($apsc_settings['cache_period'] != '') ? $apsc_settings['cache_period']*60*60 : 24 * 60 * 60;
6
  $apsc_settings['social_profile_theme'] = isset($atts['theme'])?$atts['theme']:$apsc_settings['social_profile_theme'];
 
7
  ?>
8
  <div class="apsc-icons-wrapper clearfix apsc-<?php echo $apsc_settings['social_profile_theme']; ?>" >
9
  <?php
@@ -31,12 +32,13 @@ $apsc_settings['social_profile_theme'] = isset($atts['theme'])?$atts['theme']:$a
31
  $count = 0;
32
  } else {
33
  $body = json_decode($connection['body']);
34
- $count = number_format($body->likes);
35
  set_transient('apsc_facebook', $count, $cache_period);
36
  }
37
  } else {
38
  $count = $facebook_count;
39
  }
 
40
  ?><span class="apsc-count"><?php echo $count; ?></span><span class="apsc-media-type">Fans</span></div></a>
41
  <?php
42
  break;
@@ -46,11 +48,12 @@ $apsc_settings['social_profile_theme'] = isset($atts['theme'])?$atts['theme']:$a
46
  <?php
47
  $twitter_count = get_transient('apsc_twitter');
48
  if (false === $twitter_count) {
49
- $count = number_format($this->get_twitter_count());
50
  set_transient('apsc_twitter', $count, $cache_period);
51
  } else {
52
  $count = $twitter_count;
53
  }
 
54
  ?><span class="apsc-count"><?php echo $count; ?></span><span class="apsc-media-type">Followers</span></div></a><?php
55
  break;
56
  case 'googlePlus':
@@ -73,7 +76,7 @@ $apsc_settings['social_profile_theme'] = isset($atts['theme'])?$atts['theme']:$a
73
  $_data = json_decode($connection['body'], true);
74
 
75
  if (isset($_data['circledByCount'])) {
76
- $count = number_format(intval($_data['circledByCount']));
77
  set_transient('apsc_googlePlus', $count,$cache_period);
78
  } else {
79
  $count = 0;
@@ -82,6 +85,7 @@ $apsc_settings['social_profile_theme'] = isset($atts['theme'])?$atts['theme']:$a
82
  } else {
83
  $count = $googlePlus_count;
84
  }
 
85
  ?><span class="apsc-count"><?php echo $count; ?></span><span class="apsc-media-type">Followers</span></div></a><?php
86
  break;
87
  case 'instagram':
@@ -108,7 +112,7 @@ $apsc_settings['social_profile_theme'] = isset($atts['theme'])?$atts['theme']:$a
108
  if (
109
  isset($response['meta']['code']) && 200 == $response['meta']['code'] && isset($response['data']['counts']['followed_by'])
110
  ) {
111
- $count = number_format(intval($response['data']['counts']['followed_by']));
112
  set_transient('apsc_instagram',$count,$cache_period);
113
  } else {
114
  $count = 0;
@@ -117,6 +121,7 @@ $apsc_settings['social_profile_theme'] = isset($atts['theme'])?$atts['theme']:$a
117
  } else {
118
  $count = $instagram_count;
119
  }
 
120
  ?>
121
  <span class="apsc-count"><?php echo $count; ?></span><span class="apsc-media-type">Followers</span></div></a>
122
  <?php
@@ -140,7 +145,7 @@ $apsc_settings['social_profile_theme'] = isset($atts['theme'])?$atts['theme']:$a
140
  try {
141
  $body = str_replace('yt:', '', $connection['body']);
142
  $xml = @new SimpleXmlElement($body, LIBXML_NOCDATA);
143
- $count = number_format(intval($xml->statistics['subscriberCount']));
144
  set_transient('apsc_youtube',$count,$cache_period);
145
  } catch (Exception $e) {
146
  $count = 0;
@@ -149,6 +154,7 @@ $apsc_settings['social_profile_theme'] = isset($atts['theme'])?$atts['theme']:$a
149
  } else {
150
  $count = $youtube_count;
151
  }
 
152
  ?><span class="apsc-count"><?php echo $count; ?></span><span class="apsc-media-type">Subscriber</span></div></a><?php
153
  break;
154
  case 'soundcloud':
@@ -172,7 +178,7 @@ $apsc_settings['social_profile_theme'] = isset($atts['theme'])?$atts['theme']:$a
172
  $response = json_decode($connection['body'], true);
173
 
174
  if (isset($response['followers_count'])) {
175
- $count = number_format(intval($response['followers_count']));
176
  set_transient( 'apsc_soundcloud',$count,$cache_period );
177
  } else {
178
  $count = 0;
@@ -181,6 +187,7 @@ $apsc_settings['social_profile_theme'] = isset($atts['theme'])?$atts['theme']:$a
181
  } else {
182
  $count = $soundcloud_count;
183
  }
 
184
  ?><span class="apsc-count"><?php echo $count; ?></span><span class="apsc-media-type">Followers</span></div></a><?php
185
  break;
186
  case 'dribbble':
@@ -202,7 +209,7 @@ $apsc_settings['social_profile_theme'] = isset($atts['theme'])?$atts['theme']:$a
202
  } else {
203
  $response = json_decode($connection['body'], true);
204
  if (isset($response['followers_count'])) {
205
- $count = number_format(intval($response['followers_count']));
206
  set_transient('apsc_dribbble',$count,$cache_period );
207
  } else {
208
  $count = 0;
@@ -211,6 +218,7 @@ $apsc_settings['social_profile_theme'] = isset($atts['theme'])?$atts['theme']:$a
211
  } else {
212
  $count = $dribbble_count;
213
  }
 
214
  ?><span class="apsc-count"><?php echo $count; ?></span><span class="apsc-media-type">Followers</span></div></a><?php
215
  break;
216
  case 'posts':
@@ -225,6 +233,7 @@ $apsc_settings['social_profile_theme'] = isset($atts['theme'])?$atts['theme']:$a
225
  } else {
226
  $count = $posts_count;
227
  }
 
228
  ?><span class="apsc-count"><?php echo $count; ?></span><span class="apsc-media-type">Post</span></div></a><?php
229
  break;
230
  case 'comments':
@@ -234,11 +243,12 @@ $apsc_settings['social_profile_theme'] = isset($atts['theme'])?$atts['theme']:$a
234
  $comments_count = get_transient('apsc_comments');
235
  if (false === $comments_count) {
236
  $data = wp_count_comments();
237
- $count = number_format($data->approved);
238
  set_transient('apsc_comments', $count, $cache_period);
239
  } else {
240
  $count = $comments_count;
241
  }
 
242
  ?><span class="apsc-count"><?php echo $count; ?></span><span class="apsc-media-type">Comments</span></div></a><?php
243
  break;
244
  default:
4
  $apsc_settings = $this->apsc_settings;
5
  $cache_period = ($apsc_settings['cache_period'] != '') ? $apsc_settings['cache_period']*60*60 : 24 * 60 * 60;
6
  $apsc_settings['social_profile_theme'] = isset($atts['theme'])?$atts['theme']:$apsc_settings['social_profile_theme'];
7
+ $format = isset($apsc_settings['counter_format'])?$apsc_settings['counter_format']:'comma';
8
  ?>
9
  <div class="apsc-icons-wrapper clearfix apsc-<?php echo $apsc_settings['social_profile_theme']; ?>" >
10
  <?php
32
  $count = 0;
33
  } else {
34
  $body = json_decode($connection['body']);
35
+ $count = ($body->likes);
36
  set_transient('apsc_facebook', $count, $cache_period);
37
  }
38
  } else {
39
  $count = $facebook_count;
40
  }
41
+ $count = $this->get_formatted_count($count,$format);
42
  ?><span class="apsc-count"><?php echo $count; ?></span><span class="apsc-media-type">Fans</span></div></a>
43
  <?php
44
  break;
48
  <?php
49
  $twitter_count = get_transient('apsc_twitter');
50
  if (false === $twitter_count) {
51
+ $count = ($this->get_twitter_count());
52
  set_transient('apsc_twitter', $count, $cache_period);
53
  } else {
54
  $count = $twitter_count;
55
  }
56
+ $count = $this->get_formatted_count($count,$format);
57
  ?><span class="apsc-count"><?php echo $count; ?></span><span class="apsc-media-type">Followers</span></div></a><?php
58
  break;
59
  case 'googlePlus':
76
  $_data = json_decode($connection['body'], true);
77
 
78
  if (isset($_data['circledByCount'])) {
79
+ $count = (intval($_data['circledByCount']));
80
  set_transient('apsc_googlePlus', $count,$cache_period);
81
  } else {
82
  $count = 0;
85
  } else {
86
  $count = $googlePlus_count;
87
  }
88
+ $count = $this->get_formatted_count($count,$format);
89
  ?><span class="apsc-count"><?php echo $count; ?></span><span class="apsc-media-type">Followers</span></div></a><?php
90
  break;
91
  case 'instagram':
112
  if (
113
  isset($response['meta']['code']) && 200 == $response['meta']['code'] && isset($response['data']['counts']['followed_by'])
114
  ) {
115
+ $count = (intval($response['data']['counts']['followed_by']));
116
  set_transient('apsc_instagram',$count,$cache_period);
117
  } else {
118
  $count = 0;
121
  } else {
122
  $count = $instagram_count;
123
  }
124
+ $count = $this->get_formatted_count($count,$format);
125
  ?>
126
  <span class="apsc-count"><?php echo $count; ?></span><span class="apsc-media-type">Followers</span></div></a>
127
  <?php
145
  try {
146
  $body = str_replace('yt:', '', $connection['body']);
147
  $xml = @new SimpleXmlElement($body, LIBXML_NOCDATA);
148
+ $count = (intval($xml->statistics['subscriberCount']));
149
  set_transient('apsc_youtube',$count,$cache_period);
150
  } catch (Exception $e) {
151
  $count = 0;
154
  } else {
155
  $count = $youtube_count;
156
  }
157
+ $count = $this->get_formatted_count($count,$format);
158
  ?><span class="apsc-count"><?php echo $count; ?></span><span class="apsc-media-type">Subscriber</span></div></a><?php
159
  break;
160
  case 'soundcloud':
178
  $response = json_decode($connection['body'], true);
179
 
180
  if (isset($response['followers_count'])) {
181
+ $count = (intval($response['followers_count']));
182
  set_transient( 'apsc_soundcloud',$count,$cache_period );
183
  } else {
184
  $count = 0;
187
  } else {
188
  $count = $soundcloud_count;
189
  }
190
+ $count = $this->get_formatted_count($count,$format);
191
  ?><span class="apsc-count"><?php echo $count; ?></span><span class="apsc-media-type">Followers</span></div></a><?php
192
  break;
193
  case 'dribbble':
209
  } else {
210
  $response = json_decode($connection['body'], true);
211
  if (isset($response['followers_count'])) {
212
+ $count = (intval($response['followers_count']));
213
  set_transient('apsc_dribbble',$count,$cache_period );
214
  } else {
215
  $count = 0;
218
  } else {
219
  $count = $dribbble_count;
220
  }
221
+ $count = $this->get_formatted_count($count,$format);
222
  ?><span class="apsc-count"><?php echo $count; ?></span><span class="apsc-media-type">Followers</span></div></a><?php
223
  break;
224
  case 'posts':
233
  } else {
234
  $count = $posts_count;
235
  }
236
+ $count = $this->get_formatted_count($count,$format);
237
  ?><span class="apsc-count"><?php echo $count; ?></span><span class="apsc-media-type">Post</span></div></a><?php
238
  break;
239
  case 'comments':
243
  $comments_count = get_transient('apsc_comments');
244
  if (false === $comments_count) {
245
  $data = wp_count_comments();
246
+ $count = ($data->approved);
247
  set_transient('apsc_comments', $count, $cache_period);
248
  } else {
249
  $count = $comments_count;
250
  }
251
+ $count = $this->get_formatted_count($count,$format);
252
  ?><span class="apsc-count"><?php echo $count; ?></span><span class="apsc-media-type">Comments</span></div></a><?php
253
  break;
254
  default:
readme.txt CHANGED
@@ -4,7 +4,7 @@ Tags: social count, social counter, social counters, social media counters, soci
4
  Donate link: http://accesspressthemes.com/donation/
5
  Requires at least: 3.8
6
  Tested up to: 4.1
7
- Stable tag: 1.0.6
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -118,6 +118,9 @@ Once you install the plugin , you can check some general documentation about how
118
  5. Backend Cache Settings Section
119
 
120
  == Changelog ==
 
 
 
121
  = 1.0.6 =
122
  * Done few changes in backend social profiles
123
 
4
  Donate link: http://accesspressthemes.com/donation/
5
  Requires at least: 3.8
6
  Tested up to: 4.1
7
+ Stable tag: 1.0.7
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
118
  5. Backend Cache Settings Section
119
 
120
  == Changelog ==
121
+ = 1.0.7 =
122
+ * Added Counter Format Option
123
+
124
  = 1.0.6 =
125
  * Done few changes in backend social profiles
126