/** * 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; } }
/** * 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)); } }
/** * This is a wrapper for the Event API * * @param string $event_name the name of the event * @param array $extra_params any extra data points to be included */ public static function log_event($event_name = 'Default', $extra_params = false) { global $wpdb; $event_metadata = array('plugin_version' => Shareaholic::VERSION, 'api_key' => self::get_option('api_key'), 'domain' => get_bloginfo('url'), 'language' => get_bloginfo('language'), 'stats' => array('posts_total' => $wpdb->get_var("SELECT count(ID) FROM {$wpdb->posts} where post_type = 'post' AND post_status = 'publish'"), 'pages_total' => $wpdb->get_var("SELECT count(ID) FROM {$wpdb->posts} where post_type = 'page' AND post_status = 'publish'"), 'comments_total' => wp_count_comments()->approved, 'users_total' => $wpdb->get_var("SELECT count(ID) FROM {$wpdb->users}")), 'diagnostics' => array('php_version' => phpversion(), 'wp_version' => get_bloginfo('version'), 'theme' => get_option('template'), 'active_plugins' => get_option('active_plugins', array()), 'multisite' => is_multisite()), 'features' => array('share_buttons' => self::get_option('share_buttons'), 'recommendations' => self::get_option('recommendations'))); if ($extra_params) { $event_metadata = array_merge($event_metadata, $extra_params); } $event_api_url = Shareaholic::API_URL . '/api/events'; $event_params = array('name' => "WordPress:" . $event_name, 'data' => json_encode($event_metadata)); $response = ShareaholicCurl::post($event_api_url, $event_params, '', true); }