Exemplo n.º 1
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));
     }
 }