WordPress Social Tools, Related Posts, Monetization – Shareaholic - Version 7.0.8.0

Version Description

  • Miscellaneous bug fixes and performance enhancements
Download this release

Release Info

Developer shareaholic
Plugin Icon 128x128 WordPress Social Tools, Related Posts, Monetization – Shareaholic
Version 7.0.8.0
Comparing to
See all releases

Code changes from version 7.0.7.0 to 7.0.8.0

Files changed (8) hide show
  1. admin.php +4 -3
  2. curl.php +1 -1
  3. public.php +11 -0
  4. readme.txt +7 -1
  5. shareaholic.php +9 -11
  6. six_to_seven.php +47 -2
  7. templates/settings.php +7 -7
  8. utilities.php +116 -33
admin.php CHANGED
@@ -271,8 +271,9 @@ class ShareaholicAdmin {
271
  ));
272
  }
273
 
274
- if(isset($_POST['reset_settings']) && $_POST['reset_settings'] == 'Y' &&
275
- check_admin_referer($action, 'nonce_field')) {
 
276
  ShareaholicUtilities::destroy_settings();
277
  echo "<div class='updated settings_updated'><p><strong>"
278
  . sprintf(__('Settings successfully reset. Refresh this page to complete the reset.', 'shareaholic'))
@@ -368,4 +369,4 @@ class ShareaholicAdmin {
368
  }
369
  }
370
  }
371
- ?>
271
  ));
272
  }
273
 
274
+ if(isset($_POST['reset_settings'])
275
+ && $_POST['reset_settings'] == 'Y'
276
+ && check_admin_referer($action, 'nonce_field')) {
277
  ShareaholicUtilities::destroy_settings();
278
  echo "<div class='updated settings_updated'><p><strong>"
279
  . sprintf(__('Settings successfully reset. Refresh this page to complete the reset.', 'shareaholic'))
369
  }
370
  }
371
  }
372
+ ?>
curl.php CHANGED
@@ -207,4 +207,4 @@ class ShareaholicCurl {
207
  }
208
  }
209
 
210
- ?>
207
  }
208
  }
209
 
210
+ ?>
public.php CHANGED
@@ -93,6 +93,7 @@ class ShareaholicPublic {
93
  self::draw_url_meta_tag();
94
  self::draw_keywords_meta_tag();
95
  self::draw_article_meta_tag();
 
96
  self::draw_plugin_version_meta_tag();
97
  self::draw_image_meta_tag();
98
  echo "\n<!-- Shareaholic Content Tags End -->\n";
@@ -241,6 +242,16 @@ class ShareaholicPublic {
241
  }
242
  }
243
 
 
 
 
 
 
 
 
 
 
 
244
  /**
245
  * Draws Shareaholic image tag. Will only run on pages or posts.
246
  */
93
  self::draw_url_meta_tag();
94
  self::draw_keywords_meta_tag();
95
  self::draw_article_meta_tag();
96
+ self::draw_site_id_meta_tag();
97
  self::draw_plugin_version_meta_tag();
98
  self::draw_image_meta_tag();
99
  echo "\n<!-- Shareaholic Content Tags End -->\n";
242
  }
243
  }
244
 
245
+ /**
246
+ * Draws Shareaholic site_id meta tag.
247
+ */
248
+ private static function draw_site_id_meta_tag() {
249
+ $site_id = ShareaholicUtilities::get_option('api_key');
250
+ if (!empty($site_id)) {
251
+ echo "<meta name='shareaholic:site_id' content='" . $site_id . "' />\n";
252
+ }
253
+ }
254
+
255
  /**
256
  * Draws Shareaholic image tag. Will only run on pages or posts.
257
  */
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: shareaholic
3
  Tags: sexybookmarks, shareaholic, shareholic, facebook, twitter, linkedin, URL Shortener, bitly, tinyurl, Goo.gl, Google+1, Google Analytics, Google Plus, Google, Instapaper, Wish List, Digg, Gmail, Google Bookmarks, Translate, Tumblr, AIM, Yahoo Messenger, Delicious, StumbleUpon, mister wong, evernote, add this, addtoany, share this, sharethis, share and follow, share and enjoy, sharing is sexy, sharing is caring, yahoo, reddit, hackernews, tweet button, twitter button, fark, buffer, myspace, orkut, netlog, hubspot, weheartit, printfriendly, yammer, wanelo, pinterest, google translate, bookmarks, social, email button, social share, socialize, sociable, sharebar, bookmark button, share button, social bookmarking, bookmarks menu, bookmarking, share, seo, analytics, stats, sharing, facebook like, facebook recommend, WPMU, mutisite, shortcode, yaarp, yarpp, nrelate, outbrain, linkwithin, related content, related posts, related, popular posts, popular, thumbnails, recommendations
4
  Requires at least: 2.7
5
  Tested up to: 3.7.1
6
- Stable tag: 7.0.7.0
7
 
8
  Adds an attractive social bookmarking menu and related content widget to your posts, pages, index, or any combination of the three.
9
 
@@ -148,6 +148,9 @@ Please see here: [Usage & Installation Instructions](https://shareaholic.com/too
148
 
149
  == Changelog ==
150
 
 
 
 
151
  = 7.0.7.0 =
152
  * Related Content
153
  * Deleted posts are now automatically removed from your Shareaholic Content Index within an hour!
@@ -982,6 +985,9 @@ Please see here: [Usage & Installation Instructions](https://shareaholic.com/too
982
 
983
  == Upgrade Notice ==
984
 
 
 
 
985
  = 7.0.7.0 =
986
  Deleted posts are now automatically removed from your Shareaholic Content Index within an hour!
987
 
3
  Tags: sexybookmarks, shareaholic, shareholic, facebook, twitter, linkedin, URL Shortener, bitly, tinyurl, Goo.gl, Google+1, Google Analytics, Google Plus, Google, Instapaper, Wish List, Digg, Gmail, Google Bookmarks, Translate, Tumblr, AIM, Yahoo Messenger, Delicious, StumbleUpon, mister wong, evernote, add this, addtoany, share this, sharethis, share and follow, share and enjoy, sharing is sexy, sharing is caring, yahoo, reddit, hackernews, tweet button, twitter button, fark, buffer, myspace, orkut, netlog, hubspot, weheartit, printfriendly, yammer, wanelo, pinterest, google translate, bookmarks, social, email button, social share, socialize, sociable, sharebar, bookmark button, share button, social bookmarking, bookmarks menu, bookmarking, share, seo, analytics, stats, sharing, facebook like, facebook recommend, WPMU, mutisite, shortcode, yaarp, yarpp, nrelate, outbrain, linkwithin, related content, related posts, related, popular posts, popular, thumbnails, recommendations
4
  Requires at least: 2.7
5
  Tested up to: 3.7.1
6
+ Stable tag: 7.0.8.0
7
 
8
  Adds an attractive social bookmarking menu and related content widget to your posts, pages, index, or any combination of the three.
9
 
148
 
149
  == Changelog ==
150
 
151
+ = 7.0.8.0 =
152
+ * Miscellaneous bug fixes and performance enhancements
153
+
154
  = 7.0.7.0 =
155
  * Related Content
156
  * Deleted posts are now automatically removed from your Shareaholic Content Index within an hour!
985
 
986
  == Upgrade Notice ==
987
 
988
+ = 7.0.8.0 =
989
+ Miscellaneous bug fixes and performance enhancements
990
+
991
  = 7.0.7.0 =
992
  Deleted posts are now automatically removed from your Shareaholic Content Index within an hour!
993
 
shareaholic.php CHANGED
@@ -3,14 +3,14 @@
3
  * The main file!
4
  *
5
  * @package shareaholic
6
- * @version 7.0.7.0
7
  */
8
 
9
  /*
10
  Plugin Name: Shareaholic | share buttons, analytics, related content
11
  Plugin URI: https://shareaholic.com/publishers/
12
  Description: Whether you want to get people sharing, grow your fans, make money, or know who's reading your content, Shareaholic will help you get it done. See <a href="admin.php?page=shareaholic-settings">configuration panel</a> for more settings.
13
- Version: 7.0.7.0
14
  Author: Shareaholic
15
  Author URI: https://shareaholic.com
16
  Text Domain: shareaholic
@@ -54,14 +54,14 @@ require_once(SHAREAHOLIC_DIR . '/deprecation.php');
54
  class Shareaholic {
55
  const URL = 'https://shareaholic.com';
56
  const URL_CM = 'https://cm.shareaholic.com';
57
- const VERSION = '7.0.7.0';
58
-
59
  /**
60
  * Starts off as false so that ::get_instance() returns
61
  * a new instance.
62
  */
63
  private static $instance = false;
64
-
65
  /**
66
  * The constructor registers all the wordpress actions.
67
  */
@@ -72,7 +72,7 @@ class Shareaholic {
72
  add_action('the_content', array('ShareaholicPublic', 'draw_canvases'));
73
  add_action('wp_head', array('ShareaholicPublic', 'wp_head'));
74
  add_shortcode('shareaholic', array('ShareaholicPublic', 'shortcode'));
75
-
76
  add_action('plugins_loaded', array($this, 'shareaholic_init'));
77
 
78
  add_action('admin_init', array('ShareaholicAdmin', 'admin_init'));
@@ -86,18 +86,16 @@ class Shareaholic {
86
  if (!ShareaholicUtilities::has_accepted_terms_of_service()) {
87
  add_action('admin_notices', array('ShareaholicAdmin', 'show_terms_of_service'));
88
  }
89
-
90
  // add_action('publish_post', array('ShareaholicNotifier', 'post_notify'));
91
  // add_action('publish_page', array('ShareaholicNotifier', 'post_notify'));
92
-
93
  // Check if at least one Related Content location is enabled, if so, notify CM when a new post is published
94
  if (ShareaholicUtilities::should_notify_cm()) {
95
  add_action('publish_post', array('ShareaholicUtilities', 'notify_content_manager'));
96
  add_action('publish_page', array('ShareaholicUtilities', 'notify_content_manager'));
97
  }
98
-
99
  add_action('trashed_post', array('ShareaholicUtilities', 'notify_content_manager'));
100
-
101
  register_activation_hook(__FILE__, array($this, 'after_activation'));
102
  register_deactivation_hook( __FILE__, array($this, 'deactivate'));
103
  register_uninstall_hook(__FILE__, array('Shareaholic', 'uninstall'));
@@ -189,7 +187,7 @@ class Shareaholic {
189
  public function deactivate() {
190
  ShareaholicUtilities::log_event("Deactivate");
191
  }
192
-
193
  /**
194
  * This function fires when the plugin is uninstalled.
195
  */
3
  * The main file!
4
  *
5
  * @package shareaholic
6
+ * @version 7.0.8.0
7
  */
8
 
9
  /*
10
  Plugin Name: Shareaholic | share buttons, analytics, related content
11
  Plugin URI: https://shareaholic.com/publishers/
12
  Description: Whether you want to get people sharing, grow your fans, make money, or know who's reading your content, Shareaholic will help you get it done. See <a href="admin.php?page=shareaholic-settings">configuration panel</a> for more settings.
13
+ Version: 7.0.8.0
14
  Author: Shareaholic
15
  Author URI: https://shareaholic.com
16
  Text Domain: shareaholic
54
  class Shareaholic {
55
  const URL = 'https://shareaholic.com';
56
  const URL_CM = 'https://cm.shareaholic.com';
57
+ const VERSION = '7.0.8.0';
58
+
59
  /**
60
  * Starts off as false so that ::get_instance() returns
61
  * a new instance.
62
  */
63
  private static $instance = false;
64
+
65
  /**
66
  * The constructor registers all the wordpress actions.
67
  */
72
  add_action('the_content', array('ShareaholicPublic', 'draw_canvases'));
73
  add_action('wp_head', array('ShareaholicPublic', 'wp_head'));
74
  add_shortcode('shareaholic', array('ShareaholicPublic', 'shortcode'));
75
+
76
  add_action('plugins_loaded', array($this, 'shareaholic_init'));
77
 
78
  add_action('admin_init', array('ShareaholicAdmin', 'admin_init'));
86
  if (!ShareaholicUtilities::has_accepted_terms_of_service()) {
87
  add_action('admin_notices', array('ShareaholicAdmin', 'show_terms_of_service'));
88
  }
89
+
90
  // add_action('publish_post', array('ShareaholicNotifier', 'post_notify'));
91
  // add_action('publish_page', array('ShareaholicNotifier', 'post_notify'));
92
+
93
  // Check if at least one Related Content location is enabled, if so, notify CM when a new post is published
94
  if (ShareaholicUtilities::should_notify_cm()) {
95
  add_action('publish_post', array('ShareaholicUtilities', 'notify_content_manager'));
96
  add_action('publish_page', array('ShareaholicUtilities', 'notify_content_manager'));
97
  }
 
98
  add_action('trashed_post', array('ShareaholicUtilities', 'notify_content_manager'));
 
99
  register_activation_hook(__FILE__, array($this, 'after_activation'));
100
  register_deactivation_hook( __FILE__, array($this, 'deactivate'));
101
  register_uninstall_hook(__FILE__, array('Shareaholic', 'uninstall'));
187
  public function deactivate() {
188
  ShareaholicUtilities::log_event("Deactivate");
189
  }
190
+
191
  /**
192
  * This function fires when the plugin is uninstalled.
193
  */
six_to_seven.php CHANGED
@@ -60,7 +60,13 @@ class ShareaholicSixToSeven {
60
  );
61
  }
62
 
 
 
 
 
63
  $verification_key = md5(mt_rand());
 
 
64
  $new_configuration = array(
65
  'configuration_publisher' => array(
66
  'share_buttons_attributes' => $new_share_buttons_configuration,
@@ -73,11 +79,15 @@ class ShareaholicSixToSeven {
73
  ),
74
  );
75
 
 
 
 
76
  $shortener_configuration = (isset($sexybookmarks_configuration['shorty']) ?
77
  self::transform_shortener_configuration($sexybookmarks_configuration) : array());
78
  $new_configuration = array_merge($new_configuration, $shortener_configuration);
79
 
80
  $response = ShareaholicCurl::post(Shareaholic::URL . '/publisher_tools/anonymous', $new_configuration, 'json');
 
81
  if ($response && preg_match('/20*/', $response['response']['code'])) {
82
  ShareaholicUtilities::log_event('6To7ConversionSuccess', array(
83
  'the_posted_json' => $new_configuration,
@@ -94,7 +104,10 @@ class ShareaholicSixToSeven {
94
  'location_name_ids' => $response['body']['location_name_ids']
95
  ));
96
 
97
- ShareaholicUtilities::turn_on_locations($response['body']['location_name_ids']);
 
 
 
98
 
99
  self::transform_wordpress_specific_settings();
100
  } else {
@@ -107,6 +120,33 @@ class ShareaholicSixToSeven {
107
  }
108
  }
109
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
110
  private static function grab_location_iterator($location) {
111
  return $location['name'];
112
  }
@@ -365,6 +405,11 @@ class ShareaholicSixToSeven {
365
  // now we use google_plus
366
  return 'google_plus';
367
  }
 
 
 
 
 
368
  if (preg_match('/mail/', $value)) {
369
  // it's stored as mail in wordpress, but
370
  // now we use email_this
@@ -418,4 +463,4 @@ class ShareaholicSixToSeven {
418
  }
419
  }
420
 
421
- ?>
60
  );
61
  }
62
 
63
+ $new_recommendations_configuration = isset($new_recommendations_configuration) ?
64
+ $new_recommendations_configuration :
65
+ null;
66
+
67
  $verification_key = md5(mt_rand());
68
+ list($turned_on_share_buttons_locations, $turned_off_share_buttons_locations) = self::pad_locations($new_share_buttons_configuration);
69
+ list($turned_on_recommendations_locations, $turned_off_recommendations_locations) = self::pad_locations($new_recommendations_configuration);
70
  $new_configuration = array(
71
  'configuration_publisher' => array(
72
  'share_buttons_attributes' => $new_share_buttons_configuration,
79
  ),
80
  );
81
 
82
+ ShareaholicUtilities::log($turned_off_share_buttons_locations);
83
+ ShareaholicUtilities::log($turned_off_recommendations_locations);
84
+
85
  $shortener_configuration = (isset($sexybookmarks_configuration['shorty']) ?
86
  self::transform_shortener_configuration($sexybookmarks_configuration) : array());
87
  $new_configuration = array_merge($new_configuration, $shortener_configuration);
88
 
89
  $response = ShareaholicCurl::post(Shareaholic::URL . '/publisher_tools/anonymous', $new_configuration, 'json');
90
+
91
  if ($response && preg_match('/20*/', $response['response']['code'])) {
92
  ShareaholicUtilities::log_event('6To7ConversionSuccess', array(
93
  'the_posted_json' => $new_configuration,
104
  'location_name_ids' => $response['body']['location_name_ids']
105
  ));
106
 
107
+ ShareaholicUtilities::turn_on_locations(
108
+ array('share_buttons' => $turned_on_share_buttons_locations, 'recommendations' => $turned_on_recommendations_locations),
109
+ array('share_buttons' => $turned_off_share_buttons_locations, 'recommendations' => $turned_off_recommendations_locations)
110
+ );
111
 
112
  self::transform_wordpress_specific_settings();
113
  } else {
120
  }
121
  }
122
 
123
+ private static function pad_locations(&$configuration) {
124
+ $all_names = array();
125
+ foreach (array('post', 'page', 'index', 'category') as $page_type) {
126
+ foreach (array('above', 'below') as $location) {
127
+ $all_names[] = "{$page_type}_{$location}_content";
128
+ }
129
+ }
130
+
131
+ $already_set_names = array();
132
+ foreach($configuration['locations_attributes'] as $attrs) {
133
+ $already_set_names[] = $attrs['name'];
134
+ }
135
+
136
+ $names_to_pad = array_diff($all_names, $already_set_names);
137
+ foreach($names_to_pad as $name) {
138
+ $configuration['locations_attributes'][] = array('name' => $name);
139
+ }
140
+ if (isset($configuration['location_name_ids'])) {
141
+ return array(
142
+ ShareaholicUtilities::associative_array_slice($configuration['location_name_ids'], $already_set_names),
143
+ ShareaholicUtilities::associative_array_slice($configuration['location_name_ids'], $names_to_pad)
144
+ );
145
+ } else {
146
+ return array();
147
+ }
148
+ }
149
+
150
  private static function grab_location_iterator($location) {
151
  return $location['name'];
152
  }
405
  // now we use google_plus
406
  return 'google_plus';
407
  }
408
+ if (preg_match('/googlebookmarks/', $value)) {
409
+ // it's stored as googlebookmarks in wordpress, but
410
+ // now we use google_bookmarks
411
+ return 'google_bookmarks';
412
+ }
413
  if (preg_match('/mail/', $value)) {
414
  // it's stored as mail in wordpress, but
415
  // now we use email_this
463
  }
464
  }
465
 
466
+ ?>
templates/settings.php CHANGED
@@ -18,10 +18,10 @@ window.verification_key = '<?php echo $settings['verification_key'] ?>'
18
  <input type="hidden" name="already_submitted" value="Y">
19
 
20
  <div id='app_settings'>
21
-
22
  <fieldset class="app" style="line-height:18px;"><?php echo sprintf(__('First time here? Read %sUnderstanding the new Shareaholic for WordPress interface and configuration settings.%s', 'shareaholic'), '<a href="https://blog.shareaholic.com/understanding-the-new-shareaholic-for-wordpress-interface-and-configuration-settings/" target="_blank">','</a>'); ?> <?php echo sprintf(__('If you are upgrading from an earlier version of Shareaholic for WordPress and need help, have a question or have a bug to report, please %slet us know%s.', 'shareaholic'), '<a href="#" onclick="SnapEngage.startLink();">','</a>'); ?>
23
  </fieldset>
24
-
25
  <fieldset class="app"><legend><h2><img src="<?php echo SHAREAHOLIC_ASSET_DIR; ?>img/sharebuttons@2x.png" height=32 width=32 /> <?php echo sprintf(__('Share Buttons', 'shareaholic')); ?></h2></legend>
26
  <span class="helper"><i class="icon-star"></i> <?php echo sprintf(__('Pick where you want your buttons to be displayed. Click "Customize" to customize look & feel, themes, share counters, alignment, etc.', 'shareaholic')); ?></span>
27
 
@@ -73,11 +73,11 @@ window.verification_key = '<?php echo $settings['verification_key'] ?>'
73
  </div>
74
  </fieldset>
75
  <?php } ?>
76
-
77
  <div class='clear'></div>
78
-
79
  <strong><?php echo sprintf(__('Data Status:', 'shareaholic')); ?></strong>
80
- <?php
81
  $status = ShareaholicUtilities::recommendations_status_check();
82
  if ($status == "processing" || $status == 'unknown'){
83
  echo '<img class="shrsb_health_icon" align="top" src="'.SHAREAHOLIC_ASSET_DIR.'img/circle_yellow.png" />'. sprintf(__('Processing', 'shareaholic'));
@@ -85,9 +85,9 @@ window.verification_key = '<?php echo $settings['verification_key'] ?>'
85
  echo '<img class="shrsb_health_icon" align="top" src="'.SHAREAHOLIC_ASSET_DIR.'img/circle_green.png" />'. sprintf(__('Ready', 'shareaholic'));
86
  }
87
  ?>
88
-
89
  </fieldset>
90
- </div>
91
 
92
  <div class='clear'></div>
93
  <div class="row" style="padding-top:20px; padding-bottom:35px;">
18
  <input type="hidden" name="already_submitted" value="Y">
19
 
20
  <div id='app_settings'>
21
+
22
  <fieldset class="app" style="line-height:18px;"><?php echo sprintf(__('First time here? Read %sUnderstanding the new Shareaholic for WordPress interface and configuration settings.%s', 'shareaholic'), '<a href="https://blog.shareaholic.com/understanding-the-new-shareaholic-for-wordpress-interface-and-configuration-settings/" target="_blank">','</a>'); ?> <?php echo sprintf(__('If you are upgrading from an earlier version of Shareaholic for WordPress and need help, have a question or have a bug to report, please %slet us know%s.', 'shareaholic'), '<a href="#" onclick="SnapEngage.startLink();">','</a>'); ?>
23
  </fieldset>
24
+
25
  <fieldset class="app"><legend><h2><img src="<?php echo SHAREAHOLIC_ASSET_DIR; ?>img/sharebuttons@2x.png" height=32 width=32 /> <?php echo sprintf(__('Share Buttons', 'shareaholic')); ?></h2></legend>
26
  <span class="helper"><i class="icon-star"></i> <?php echo sprintf(__('Pick where you want your buttons to be displayed. Click "Customize" to customize look & feel, themes, share counters, alignment, etc.', 'shareaholic')); ?></span>
27
 
73
  </div>
74
  </fieldset>
75
  <?php } ?>
76
+
77
  <div class='clear'></div>
78
+
79
  <strong><?php echo sprintf(__('Data Status:', 'shareaholic')); ?></strong>
80
+ <?php
81
  $status = ShareaholicUtilities::recommendations_status_check();
82
  if ($status == "processing" || $status == 'unknown'){
83
  echo '<img class="shrsb_health_icon" align="top" src="'.SHAREAHOLIC_ASSET_DIR.'img/circle_yellow.png" />'. sprintf(__('Processing', 'shareaholic'));
85
  echo '<img class="shrsb_health_icon" align="top" src="'.SHAREAHOLIC_ASSET_DIR.'img/circle_green.png" />'. sprintf(__('Ready', 'shareaholic'));
86
  }
87
  ?>
88
+
89
  </fieldset>
90
+ </div>
91
 
92
  <div class='clear'></div>
93
  <div class="row" style="padding-top:20px; padding-bottom:35px;">
utilities.php CHANGED
@@ -101,7 +101,7 @@ class ShareaholicUtilities {
101
  public static function has_accepted_terms_of_service() {
102
  return get_option('shareaholic_has_accepted_tos');
103
  }
104
-
105
  /**
106
  * Accepts the terms of service.
107
  */
@@ -403,7 +403,7 @@ class ShareaholicUtilities {
403
  *
404
  * @param array $array
405
  */
406
- public static function turn_on_locations($array) {
407
  foreach($array as $app => $ids) {
408
  foreach($ids as $name => $id) {
409
  self::update_options(array(
@@ -411,6 +411,38 @@ class ShareaholicUtilities {
411
  ));
412
  }
413
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
414
  }
415
 
416
  /**
@@ -480,7 +512,31 @@ class ShareaholicUtilities {
480
  delete_option('shareaholic_settings');
481
 
482
  $verification_key = md5(mt_rand());
483
- $response = ShareaholicCurl::post(Shareaholic::URL . '/publisher_tools/anonymous', array(
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
484
  'configuration_publisher' => array(
485
  'verification_key' => $verification_key,
486
  'site_name' => self::site_name(),
@@ -489,21 +545,19 @@ class ShareaholicUtilities {
489
  'language_id' => self::site_language(),
490
  'shortener' => 'shrlc',
491
  'recommendations_attributes' => array(
492
- 'locations_attributes' => array(
493
- array('name' => 'post_below_content'),
494
- array('name' => 'page_below_content'),
495
- )
496
  ),
497
  'share_buttons_attributes' => array(
498
- 'locations_attributes' => array(
499
- array('name' => 'post_below_content', 'counter' => 'badge-counter'),
500
- array('name' => 'page_below_content', 'counter' => 'badge-counter'),
501
- array('name' => 'index_below_content', 'counter' => 'badge-counter'),
502
- array('name' => 'category_below_content', 'counter' => 'badge-counter')
503
- )
504
  )
505
  )
506
- ));
 
 
 
 
 
 
507
 
508
  if ($response && preg_match('/20*/', $response['response']['code'])) {
509
  self::update_options(array(
@@ -513,7 +567,38 @@ class ShareaholicUtilities {
513
  ));
514
 
515
  if (isset($response['body']['location_name_ids']) && is_array($response['body']['location_name_ids'])) {
516
- ShareaholicUtilities::turn_on_locations($response['body']['location_name_ids']);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
517
  } else {
518
  ShareaholicUtilities::log_bad_response('FailedToCreateApiKey', $response);
519
  }
@@ -573,7 +658,7 @@ class ShareaholicUtilities {
573
  */
574
  public static function site_language() {
575
  $site_language = strtolower(get_bloginfo('language'));
576
-
577
  if (strpos($site_language, 'en-') !== false) {
578
  $language_id = 9; // English
579
  } elseif (strpos($site_language, 'da-') !== false) {
@@ -615,7 +700,7 @@ class ShareaholicUtilities {
615
  }
616
  return $language_id;
617
  }
618
-
619
  /**
620
  * Shockingly the built in PHP array_merge_recursive function is stupid.
621
  * this is stolen from the PHP docs and will overwrite existing keys instead
@@ -682,13 +767,11 @@ class ShareaholicUtilities {
682
  * @return bool
683
  */
684
  public static function should_notify_cm() {
685
- $settings = array();
686
- $recommendations_settings = array();
687
  $settings = ShareaholicUtilities::get_settings();
688
- if (isset($settings["recommendations"])){
689
- $recommendations_settings = $settings["recommendations"];
690
- }
691
-
692
  if (is_array($recommendations_settings)) {
693
  if (in_array("on", $recommendations_settings)) {
694
  return true;
@@ -699,15 +782,15 @@ class ShareaholicUtilities {
699
  return false;
700
  }
701
  }
702
-
703
  /**
704
  * This is a wrapper for Shareaholic Content Manager API's
705
  *
706
  * @param string $post_id
707
  */
708
- public static function notify_content_manager($post_id = NULL) {
709
  $post_permalink = get_permalink($post_id);
710
-
711
  if ($post_permalink != NULL) {
712
  $cm_single_page_job_url = Shareaholic::URL_CM . '/jobs/uber_single_page';
713
  $payload = array (
@@ -719,7 +802,7 @@ class ShareaholicUtilities {
719
  $response = ShareaholicCurl::post($cm_single_page_job_url, $payload, 'json');
720
  }
721
  }
722
-
723
  /**
724
  * This is a wrapper for the Event API
725
  *
@@ -763,7 +846,7 @@ class ShareaholicUtilities {
763
 
764
  $response = ShareaholicCurl::post($event_api_url, $event_params, '', true);
765
  }
766
-
767
  /**
768
  * This loads the locales
769
  *
@@ -771,7 +854,7 @@ class ShareaholicUtilities {
771
  public static function localize() {
772
  load_plugin_textdomain('shareaholic', false, basename(dirname(__FILE__)) . '/languages/');
773
  }
774
-
775
  /*
776
  * Adds a xua response header
777
  *
@@ -784,16 +867,16 @@ class ShareaholicUtilities {
784
  }
785
  return $headers;
786
  }
787
-
788
  /*
789
  * Draws xua meta tag
790
  *
791
  */
792
  public function draw_meta_xua()
793
- {
794
  echo '<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">';
795
  }
796
-
797
  /**
798
  * Server Connectivity check
799
  *
@@ -835,4 +918,4 @@ class ShareaholicUtilities {
835
  }
836
 
837
  }
838
- ?>
101
  public static function has_accepted_terms_of_service() {
102
  return get_option('shareaholic_has_accepted_tos');
103
  }
104
+
105
  /**
106
  * Accepts the terms of service.
107
  */
403
  *
404
  * @param array $array
405
  */
406
+ public static function turn_on_locations($array, $turn_off_array = array()) {
407
  foreach($array as $app => $ids) {
408
  foreach($ids as $name => $id) {
409
  self::update_options(array(
411
  ));
412
  }
413
  }
414
+
415
+ foreach($turn_off_array as $app => $ids) {
416
+ foreach($ids as $name => $id) {
417
+ self::update_options(array(
418
+ $app => array($name => 'off')
419
+ ));
420
+ }
421
+ }
422
+ }
423
+
424
+ /**
425
+ * Give back only the request keys from an array. The first
426
+ * argument is the array to be sliced, and after that it can
427
+ * either be a variable-length list of keys or one array of keys.
428
+ *
429
+ * @param array $array
430
+ * @param Mixed ... can be either one array or many keys
431
+ * @return array
432
+ */
433
+ public static function associative_array_slice($array) {
434
+ $keys = array_slice(func_get_args(), 1);
435
+ if (func_num_args() == 2 && is_array($keys[0])) {
436
+ $keys = $keys[0];
437
+ }
438
+
439
+ $result = array();
440
+
441
+ foreach($keys as $key) {
442
+ $result[$key] = $array[$key];
443
+ }
444
+
445
+ return $result;
446
  }
447
 
448
  /**
512
  delete_option('shareaholic_settings');
513
 
514
  $verification_key = md5(mt_rand());
515
+ $turned_on_share_buttons_locations = array(
516
+ array('name' => 'post_below_content', 'counter' => 'badge-counter'),
517
+ array('name' => 'page_below_content', 'counter' => 'badge-counter'),
518
+ array('name' => 'index_below_content', 'counter' => 'badge-counter'),
519
+ array('name' => 'category_below_content', 'counter' => 'badge-counter')
520
+ );
521
+ $turned_off_share_buttons_locations = array(
522
+ array('name' => 'post_above_content', 'counter' => 'badge-counter'),
523
+ array('name' => 'page_above_content', 'counter' => 'badge-counter'),
524
+ array('name' => 'index_above_content', 'counter' => 'badge-counter'),
525
+ array('name' => 'category_above_content', 'counter' => 'badge-counter')
526
+ );
527
+
528
+ $turned_on_recommendations_locations = array(
529
+ array('name' => 'post_below_content'),
530
+ array('name' => 'page_below_content'),
531
+ );
532
+ $turned_off_recommendations_locations = array(
533
+ array('name' => 'index_below_content'),
534
+ array('name' => 'category_below_content'),
535
+ );
536
+
537
+ $share_buttons_attributes = array_merge($turned_on_share_buttons_locations, $turned_off_share_buttons_locations);
538
+ $recommendations_attributes = array_merge($turned_on_recommendations_locations, $turned_off_recommendations_locations);
539
+ $data = array(
540
  'configuration_publisher' => array(
541
  'verification_key' => $verification_key,
542
  'site_name' => self::site_name(),
545
  'language_id' => self::site_language(),
546
  'shortener' => 'shrlc',
547
  'recommendations_attributes' => array(
548
+ 'locations_attributes' => $recommendations_attributes
 
 
 
549
  ),
550
  'share_buttons_attributes' => array(
551
+ 'locations_attributes' => $share_buttons_attributes
 
 
 
 
 
552
  )
553
  )
554
+ );
555
+
556
+ $response = ShareaholicCurl::post(
557
+ Shareaholic::URL . '/publisher_tools/anonymous',
558
+ $data,
559
+ 'json'
560
+ );
561
 
562
  if ($response && preg_match('/20*/', $response['response']['code'])) {
563
  self::update_options(array(
567
  ));
568
 
569
  if (isset($response['body']['location_name_ids']) && is_array($response['body']['location_name_ids'])) {
570
+
571
+ $turned_on_share_buttons_keys = array();
572
+ foreach($turned_on_share_buttons_locations as $loc) {
573
+ $turned_on_share_buttons_keys[] = $loc['name'];
574
+ }
575
+
576
+ $turned_on_recommendations_keys = array();
577
+ foreach($turned_on_recommendations_locations as $loc) {
578
+ $turned_on_recommendations_keys[] = $loc['name'];
579
+ }
580
+
581
+ $turned_off_share_buttons_keys = array();
582
+ foreach($turned_off_share_buttons_locations as $loc) {
583
+ $turned_off_share_buttons_keys[] = $loc['name'];
584
+ }
585
+
586
+ $turned_off_recommendations_keys = array();
587
+ foreach($turned_off_recommendations_locations as $loc) {
588
+ $turned_off_recommendations_keys[] = $loc['name'];
589
+ }
590
+
591
+ $turn_on = array(
592
+ 'share_buttons' => self::associative_array_slice($response['body']['location_name_ids']['share_buttons'], $turned_on_share_buttons_keys),
593
+ 'recommendations' => self::associative_array_slice($response['body']['location_name_ids']['recommendations'], $turned_on_recommendations_keys)
594
+ );
595
+
596
+ $turn_off = array(
597
+ 'share_buttons' => self::associative_array_slice($response['body']['location_name_ids']['share_buttons'], $turned_off_share_buttons_keys),
598
+ 'recommendations' => self::associative_array_slice($response['body']['location_name_ids']['recommendations'], $turned_off_recommendations_keys)
599
+ );
600
+
601
+ ShareaholicUtilities::turn_on_locations($turn_on, $turn_off);
602
  } else {
603
  ShareaholicUtilities::log_bad_response('FailedToCreateApiKey', $response);
604
  }
658
  */
659
  public static function site_language() {
660
  $site_language = strtolower(get_bloginfo('language'));
661
+
662
  if (strpos($site_language, 'en-') !== false) {
663
  $language_id = 9; // English
664
  } elseif (strpos($site_language, 'da-') !== false) {
700
  }
701
  return $language_id;
702
  }
703
+
704
  /**
705
  * Shockingly the built in PHP array_merge_recursive function is stupid.
706
  * this is stolen from the PHP docs and will overwrite existing keys instead
767
  * @return bool
768
  */
769
  public static function should_notify_cm() {
 
 
770
  $settings = ShareaholicUtilities::get_settings();
771
+ $recommendations_settings = isset($settings['recommendations']) ?
772
+ $settings["recommendations"] :
773
+ null;
774
+
775
  if (is_array($recommendations_settings)) {
776
  if (in_array("on", $recommendations_settings)) {
777
  return true;
782
  return false;
783
  }
784
  }
785
+
786
  /**
787
  * This is a wrapper for Shareaholic Content Manager API's
788
  *
789
  * @param string $post_id
790
  */
791
+ public static function notify_content_manager($post_id = NULL) {
792
  $post_permalink = get_permalink($post_id);
793
+
794
  if ($post_permalink != NULL) {
795
  $cm_single_page_job_url = Shareaholic::URL_CM . '/jobs/uber_single_page';
796
  $payload = array (
802
  $response = ShareaholicCurl::post($cm_single_page_job_url, $payload, 'json');
803
  }
804
  }
805
+
806
  /**
807
  * This is a wrapper for the Event API
808
  *
846
 
847
  $response = ShareaholicCurl::post($event_api_url, $event_params, '', true);
848
  }
849
+
850
  /**
851
  * This loads the locales
852
  *
854
  public static function localize() {
855
  load_plugin_textdomain('shareaholic', false, basename(dirname(__FILE__)) . '/languages/');
856
  }
857
+
858
  /*
859
  * Adds a xua response header
860
  *
867
  }
868
  return $headers;
869
  }
870
+
871
  /*
872
  * Draws xua meta tag
873
  *
874
  */
875
  public function draw_meta_xua()
876
+ {
877
  echo '<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">';
878
  }
879
+
880
  /**
881
  * Server Connectivity check
882
  *
918
  }
919
 
920
  }
921
+ ?>