Exemple #1
0
 /**
  * Actually sends the request to the notification API
  *
  * @param  array $notification an associative array of data
  *                             to send to the API
  * @return bool
  */
 private static function send_notification($notification)
 {
     $url = self::URL . '/notify';
     $response = ShareaholicCurl::post($url, $notification, 'json');
     if ($response && preg_match('/20*/', $response['response']['code'])) {
         return true;
     } else {
         return false;
     }
 }
Exemple #2
0
 /**
  * The updating function. This should create a whole configuration
  * object including share buttons and recommendations as well as
  * site name and domain to send back to us.
  */
 public static function update()
 {
     $version = ShareaholicUtilities::get_version();
     $sexybookmarks_configuration = get_option('SexyBookmarks');
     $classicbookmarks_configuration = get_option('ShareaholicClassicBookmarks');
     $recommendations_configuration = get_option('ShareaholicRecommendations');
     $top_bar_configuration = get_option('ShareaholicTopBar');
     $new_share_buttons_configuration = self::transform_sexybookmarks_configuration($sexybookmarks_configuration);
     $new_classicbookmarks_locations = self::transform_classicbookmarks_locations($classicbookmarks_configuration, $sexybookmarks_configuration);
     $new_top_bar_configuration = self::transform_top_bar_configuration($top_bar_configuration);
     $location_names = array_map(array('self', 'grab_location_iterator'), $new_share_buttons_configuration['locations_attributes']);
     // if sexybookmarks are off or not on the bottom
     if ($sexybookmarks_configuration['sexybookmark'] != '1' || !(bool) preg_grep('/below/', $location_names)) {
         // then merge in the classic bookmark locations
         $new_share_buttons_configuration = array_merge($new_share_buttons_configuration, $new_classicbookmarks_locations);
     } elseif ($sexybookmarks_configuration['sexybookmark'] != '1' || !(bool) preg_grep('/above/', $location_names)) {
         $new_share_buttons_configuration = array_merge($new_share_buttons_configuration, $new_top_bar_configuration);
     }
     $new_recommendations_configuration = array('locations_attributes' => self::transform_recommendations_configuration($recommendations_configuration));
     $new_recommendations_configuration = isset($new_recommendations_configuration) ? $new_recommendations_configuration : null;
     $verification_key = md5(mt_rand());
     list($turned_on_share_buttons_location_names, $turned_off_share_buttons_location_names) = self::pad_locations($new_share_buttons_configuration);
     list($turned_on_recommendations_location_names, $turned_off_recommendations_location_names) = self::pad_locations($new_recommendations_configuration);
     $new_configuration = array('configuration_publisher' => array('share_buttons_attributes' => $new_share_buttons_configuration, 'recommendations_attributes' => $new_recommendations_configuration, 'site_name' => ShareaholicUtilities::site_name(), 'domain' => ShareaholicUtilities::site_url(), 'verification_key' => $verification_key, 'platform_id' => '12', 'language_id' => ShareaholicUtilities::site_language()));
     $shortener_configuration = isset($sexybookmarks_configuration['shorty']) ? self::transform_shortener_configuration($sexybookmarks_configuration) : array();
     $new_configuration['configuration_publisher'] = array_merge($new_configuration['configuration_publisher'], $shortener_configuration);
     $response = ShareaholicCurl::post(Shareaholic::API_URL . '/publisher_tools/anonymous', $new_configuration, 'json');
     if ($response && preg_match('/20*/', $response['response']['code'])) {
         ShareaholicUtilities::log_event('6To7ConversionSuccess', array('the_posted_json' => $new_configuration, 'the_created_api_key' => $response['body']['api_key'], 'SexyBookmarks' => $sexybookmarks_configuration, 'ShareaholicClassicBookmarks' => $classicbookmarks_configuration, 'ShareaholicRecommendations' => $recommendations_configuration));
         ShareaholicUtilities::update_options(array('api_key' => $response['body']['api_key'], 'version' => Shareaholic::VERSION, 'verification_key' => $verification_key, 'location_name_ids' => $response['body']['location_name_ids']));
         ShareaholicUtilities::turn_on_locations(array('share_buttons' => array_flip($turned_on_share_buttons_location_names), 'recommendations' => array_flip($turned_on_recommendations_location_names)), array('share_buttons' => array_flip($turned_off_share_buttons_location_names), 'recommendations' => array_flip($turned_off_recommendations_location_names)));
         self::transform_wordpress_specific_settings();
         self::cleanup_v6_options();
     } else {
         ShareaholicUtilities::log_event('6To7ConversionFailed', array('the_posted_json' => $new_configuration, 'SexyBookmarks' => $sexybookmarks_configuration, 'ShareaholicClassicBookmarks' => $classicbookmarks_configuration, 'ShareaholicRecommendations' => $recommendations_configuration));
     }
 }
Exemple #3
0
 /**
  * Share Counts API Connectivity check
  *
  */
 public static function share_counts_api_connectivity_check()
 {
     // if we already checked and it is successful, then do not call the API again
     $share_counts_connect_check = self::get_option('share_counts_connect_check');
     if (isset($share_counts_connect_check) && $share_counts_connect_check == 'SUCCESS') {
         return $share_counts_connect_check;
     }
     $services_config = ShareaholicSeqShareCount::get_services_config();
     $services = array_keys($services_config);
     $param_string = implode('&services[]=', $services);
     $share_counts_api_url = admin_url('admin-ajax.php') . '?action=shareaholic_share_counts_api&url=https%3A%2F%2Fwww.google.com%2F&services[]=' . $param_string;
     $cache_key = 'share_counts_api_connectivity_check';
     $response = get_transient($cache_key);
     if (!$response) {
         $response = ShareaholicCurl::get($share_counts_api_url, array(), '', true);
     }
     $response_status = self::get_share_counts_api_status($response);
     // if this was the first time we are doing this and it failed, disable
     // the share counts API
     if (empty($share_counts_connect_check) && $response_status == 'FAIL') {
         self::update_options(array('disable_internal_share_counts_api' => 'on'));
     }
     if ($response_status == 'SUCCESS') {
         set_transient($cache_key, $response, SHARE_COUNTS_CHECK_CACHE_LENGTH);
     }
     self::update_options(array('share_counts_connect_check' => $response_status));
     return $response_status;
 }
Exemple #4
0
 /**
  * This is a wrapper for the Recommendations API
  *
  */
 public static function recommendations_status_check()
 {
     if (self::get_option('api_key') != NULL) {
         $recommendations_url = Shareaholic::REC_API_URL . "/v4/recommend?url=" . urlencode(get_bloginfo('url')) . "&internal=6&sponsored=0&api_key=" . self::get_option('api_key');
         $cache_key = 'recommendations_status_check-' . md5($recommendations_url);
         $response = get_transient($cache_key);
         if (!$response) {
             $response = ShareaholicCurl::get($recommendations_url);
             if (!is_wp_error($response)) {
                 set_transient($cache_key, $response, RECOMMENDATIONS_STATUS_CHECK_CACHE_LENGTH);
             }
         }
         if (is_array($response) && array_key_exists('response', $response)) {
             $body = $response['body'];
             if (is_array($body) && array_key_exists('internal', $body) && !empty($body['internal'])) {
                 return "ready";
             } else {
                 return "processing";
             }
         } else {
             return "unknown";
         }
     }
 }