You are here

class ShareaholicSeqShareCount in Share Buttons, Related Posts, Content Analytics - Shareaholic 7.3

Same name and namespace in other branches
  1. 8 lib/social-share-counts/seq_share_count.php \ShareaholicSeqShareCount

A class that implements ShareaholicShareCounts This class will get the share counts by calling the social services sequentially

@package shareaholic

Hierarchy

Expanded class hierarchy of ShareaholicSeqShareCount

File

lib/social-share-counts/seq_share_count.php, line 19

View source
class ShareaholicSeqShareCount extends ShareaholicShareCount {

  /**
   * This function should get all the counts for the
   * supported services
   *
   * It should return an associative array with the services as
   * the keys and the counts as the value.
   *
   * Example:
   * array('facebook' => 12, 'pinterest' => 0, 'twitter' => 14, ...);
   *
   * @return Array an associative array of service => counts
   */
  public function get_counts() {
    $services_length = count($this->services);
    $config = self::get_services_config();
    $response = array();
    $response['status'] = 200;
    for ($i = 0; $i < $services_length; $i++) {
      $service = $this->services[$i];
      if (!isset($config[$service])) {
        continue;
      }
      if (isset($config[$service]['prepare'])) {
        $this
          ->{$config[$service]['prepare']}($this->url, $config);
      }
      $timeout = isset($config[$service]['timeout']) ? $config[$service]['timeout'] : 1;
      $timeout = isset($this->options['timeout']) ? $this->options['timeout'] : $timeout;
      $options = array(
        'method' => $config[$service]['method'],
        'timeout' => $timeout,
        'headers' => isset($config[$service]['headers']) ? $config[$service]['headers'] : array(),
        'body' => isset($config[$service]['body']) ? $config[$service]['body'] : NULL,
      );
      $result = ShareaholicHttp::send(str_replace('%s', $this->url, $config[$service]['url']), $options);
      if (!$result) {
        $response['status'] = 500;
      }
      $callback = $config[$service]['callback'];
      $counts = $this
        ->{$callback}($result);
      if (is_numeric($counts)) {
        $response['data'][$service] = $counts;
      }
      $this->raw_response[$service] = $result;
    }
    return $response;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ShareaholicSeqShareCount::get_counts public function This function should get all the counts for the supported services Overrides ShareaholicShareCount::get_counts
ShareaholicShareCount::$options protected property
ShareaholicShareCount::$raw_response public property
ShareaholicShareCount::$services protected property
ShareaholicShareCount::$url protected property
ShareaholicShareCount::buffer_count_callback public function Callback function for buffer count API Gets the buffer share counts from response
ShareaholicShareCount::facebook_count_callback public function Callback function for facebook count API Gets the facebook counts from response
ShareaholicShareCount::fancy_count_callback public function Callback function for Fancy count API Gets the Fancy counts from response
ShareaholicShareCount::get_client_ip public function Get the client's ip address
ShareaholicShareCount::get_services_config public static function
ShareaholicShareCount::has_http_error public function Check if calling the service returned any type of error
ShareaholicShareCount::is_url_encoded public function Check if the url is encoded
ShareaholicShareCount::odnoklassniki_count_callback public function Callback function for odnoklassniki count API Gets the odnoklassniki counts from response
ShareaholicShareCount::pinterest_count_callback public function Callback function for pinterest count API Gets the pinterest counts from response
ShareaholicShareCount::reddit_count_callback public function Callback function for reddit count API Gets the reddit counts from response
ShareaholicShareCount::tumblr_count_callback public function Callback function for Tumblr count API Gets the Tumblr counts from response
ShareaholicShareCount::vk_count_callback public function Callback function for vk count API Gets the vk counts from response
ShareaholicShareCount::yummly_count_callback public function Callback function for Yummly count API Gets the Yummly counts from response
ShareaholicShareCount::__construct public function