public function testGooglePlusPrepareRequest()
 {
     $config = ShareaholicSeqShareCount::get_services_config();
     // check that the function sets the post body in the $config object
     $this->share_count->google_plus_prepare_request($this->url, $config);
     $this->assertNotNull($config['google_plus']['body'], 'The post body for google plus should not be null');
     // mock the ip address and check that the userIp is set
     $mockIp = 'mockIp';
     $_SERVER['REMOTE_ADDR'] = $mockIp;
     $this->share_count->google_plus_prepare_request($this->url, $config);
     $this->assertEquals($mockIp, $config['google_plus']['body'][0]['params']['userIp']);
 }
예제 #2
0
파일: public.php 프로젝트: antoninab/t2c
 /**
  * Helper method to parse the list of social services to get share counts
  */
 public static function parse_services($services)
 {
     $result = array();
     if (empty($services) || !is_array($services)) {
         return $result;
     }
     // make the set of services unique
     $services = array_unique($services);
     // only get the services we can get share counts for
     $social_services = array_keys(ShareaholicSeqShareCount::get_services_config());
     foreach ($services as $service) {
         if (in_array($service, $social_services)) {
             array_push($result, $service);
         }
     }
     return $result;
 }
예제 #3
0
 public function testGooglePlusPrepareRequest()
 {
     $count = new ShareaholicSeqShareCount($this->url, $this->services);
     $config = ShareaholicSeqShareCount::get_services_config();
     // check that the function sets the post body in the $config object
     $count->google_plus_prepare_request($this->url, $config);
     $this->assertNotNull($config['google_plus']['body'], 'The post body for google plus should not be null');
 }
예제 #4
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;
 }
예제 #5
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 = url('shareaholic/api/share_counts/v1', array('absolute' => TRUE)) . '?action=shareaholic_share_counts_api&url=https%3A%2F%2Fwww.google.com%2F&services[]=' . $param_string;
     $cache_key = 'share_counts_api_connectivity_check';
     // fetch cached response if it exists or has not expired
     $response = ShareaholicCache::get($cache_key);
     if (!$response) {
         $response = ShareaholicHttp::send($share_counts_api_url, array('method' => 'GET'), 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') {
         ShareaholicCache::set($cache_key, $response, SHARE_COUNTS_CHECK_CACHE_LENGTH);
     }
     self::update_options(array('share_counts_connect_check' => $response_status));
     return $response_status;
 }