Exemplo n.º 1
0
 public function getSharesALL()
 {
     global $mashsb_options;
     $fb_mode = isset($mashsb_options['facebook_count_mode']) ? $mashsb_options['facebook_count_mode'] : '';
     $post_data = null;
     //$user_data = null;
     $headers = null;
     $options = array(CURLOPT_SSL_VERIFYPEER => FALSE, CURLOPT_SSL_VERIFYHOST => FALSE);
     $RollingCurlX = new RollingCurlX(8);
     // max 10 simultaneous downloads
     $RollingCurlX->setOptions($options);
     switch ($fb_mode) {
         case $fb_mode === 'likes':
             $RollingCurlX->addRequest("https://api.facebook.com/method/links.getStats?format=json&urls=" . $this->url, $post_data, array($this, 'getCount'), array('facebook_likes'), $headers);
             break;
         case $fb_mode === 'total':
             $RollingCurlX->addRequest("https://api.facebook.com/method/links.getStats?format=json&urls=" . $this->url, $post_data, array($this, 'getCount'), array('facebook_total'), $headers);
             break;
         default:
             $RollingCurlX->addRequest("https://api.facebook.com/method/links.getStats?format=json&urls=" . $this->url, $post_data, array($this, 'getCount'), array('facebook_shares'), $headers);
     }
     $RollingCurlX->addRequest("http://urls.api.twitter.com/1/urls/count.json?url=" . $this->url, $post_data, array($this, 'getCount'), array('twitter'), $headers);
     $RollingCurlX->addRequest("https://www.linkedin.com/countserv/count/share?format=json&url=" . $this->url, $post_data, array($this, 'getCount'), array('linkedin'), $headers);
     $RollingCurlX->addRequest("http://www.stumbleupon.com/services/1.01/badge.getinfo?url=" . $this->url, $post_data, array($this, 'getCount'), array('stumbleupon'), $headers);
     $RollingCurlX->addRequest("https://plusone.google.com/_/+1/fastbutton?url=" . $this->url, $post_data, array($this, 'getCount'), array('google'), $headers);
     $RollingCurlX->addRequest("http://api.pinterest.com/v1/urls/count.json?url=" . $this->url, $post_data, array($this, 'getCount'), array('pinterest'), $headers);
     //$RollingCurlX->addRequest("http://feeds.delicious.com/v2/json/urlinfo/data?url=" . $this->url, $post_data, array($this, 'getCount'),  array('delicious'), $headers);
     //$RollingCurlX->addRequest("http://www.reddit.com/api/info.json?&url=" . $this->url, $post_data, array($this, 'getCount'), array('reddit'), $headers);
     $RollingCurlX->addRequest("https://api.bufferapp.com/1/links/shares.json?url=" . $this->url, $post_data, array($this, 'getCount'), array('buffer'), $headers);
     $RollingCurlX->addRequest("https://vk.com/share.php?act=count&index=1&url=" . $this->url, $post_data, array($this, 'getCount'), array('vk'), $headers);
     $RollingCurlX->execute();
     //$data = json_encode($this->data); // This return an json string instead
     $data = $this->data;
     // return the total count
     //return $data->shares->total;
     return $data;
 }
Exemplo n.º 2
0
 public function getSharesALL()
 {
     global $mashsb_options;
     $fb_mode = isset($mashsb_options['facebook_count_mode']) ? $mashsb_options['facebook_count_mode'] : 'total';
     $post_data = null;
     $headers = null;
     $options = array(CURLOPT_SSL_VERIFYPEER => FALSE, CURLOPT_SSL_VERIFYHOST => FALSE);
     $RollingCurlX = new RollingCurlX(10);
     // max 10 simultaneous downloads
     $RollingCurlX->setOptions($options);
     switch ($fb_mode) {
         case $fb_mode === 'likes':
             if (isset($mashsb_options['cumulate_http_https'])) {
                 $RollingCurlX->addRequest("http://graph.facebook.com/?id=" . $this->https_scheme_url, $post_data, array($this, 'getCount'), array('facebook_likes'), $headers);
                 $RollingCurlX->addRequest("http://graph.facebook.com/?id=" . $this->http_scheme_url, $post_data, array($this, 'getCount'), array('facebook_likes'), $headers);
             } else {
             }
             $RollingCurlX->addRequest("http://graph.facebook.com/?id=" . $this->url, $post_data, array($this, 'getCount'), array('facebook_likes'), $headers);
             break;
         case $fb_mode === 'total':
             if (isset($mashsb_options['cumulate_http_https'])) {
                 $RollingCurlX->addRequest("http://graph.facebook.com/?id=" . $this->https_scheme_url, $post_data, array($this, 'getCount'), array('facebook_total'), $headers);
                 $RollingCurlX->addRequest("http://graph.facebook.com/?id=" . $this->http_scheme_url, $post_data, array($this, 'getCount'), array('facebook_total'), $headers);
             } else {
                 $RollingCurlX->addRequest("http://graph.facebook.com/?id=" . $this->url, $post_data, array($this, 'getCount'), array('facebook_total'), $headers);
             }
             break;
         default:
             if (isset($mashsb_options['cumulate_http_https'])) {
                 $RollingCurlX->addRequest("http://graph.facebook.com/?id=" . $this->https_scheme_url, $post_data, array($this, 'getCount'), array('facebook_shares'), $headers);
                 $RollingCurlX->addRequest("http://graph.facebook.com/?id=" . $this->http_scheme_url, $post_data, array($this, 'getCount'), array('facebook_shares'), $headers);
             } else {
                 $RollingCurlX->addRequest("http://graph.facebook.com/?id=" . $this->url, $post_data, array($this, 'getCount'), array('facebook_shares'), $headers);
             }
     }
     if (isset($mashsb_options['cumulate_http_https'])) {
         $RollingCurlX->addRequest("http://public.newsharecounts.com/count.json?url=" . $this->https_scheme_url, $post_data, array($this, 'getCount'), array('twitter'), $headers);
         $RollingCurlX->addRequest("http://public.newsharecounts.com/count.json?url=" . $this->http_scheme_url, $post_data, array($this, 'getCount'), array('twitter'), $headers);
     } else {
         $RollingCurlX->addRequest("http://public.newsharecounts.com/count.json?url=" . $this->url, $post_data, array($this, 'getCount'), array('twitter'), $headers);
     }
     $RollingCurlX->addRequest("https://www.linkedin.com/countserv/count/share?format=json&url=" . $this->http_scheme_url, $post_data, array($this, 'getCount'), array('linkedin'), $headers);
     $RollingCurlX->addRequest("http://www.stumbleupon.com/services/1.01/badge.getinfo?url=" . $this->http_scheme_url, $post_data, array($this, 'getCount'), array('stumbleupon'), $headers);
     $RollingCurlX->addRequest("https://plusone.google.com/_/+1/fastbutton?url=" . $this->http_scheme_url, $post_data, array($this, 'getCount'), array('google'), $headers);
     $RollingCurlX->addRequest("http://api.pinterest.com/v1/urls/count.json?url=" . $this->http_scheme_url, $post_data, array($this, 'getCount'), array('pinterest'), $headers);
     $RollingCurlX->addRequest("https://api.bufferapp.com/1/links/shares.json?url=" . $this->http_scheme_url, $post_data, array($this, 'getCount'), array('buffer'), $headers);
     $RollingCurlX->addRequest("https://vk.com/share.php?act=count&index=1&url=" . $this->http_scheme_url, $post_data, array($this, 'getCount'), array('vk'), $headers);
     $RollingCurlX->execute();
     //$data = json_encode($this->data); // This return an json string instead
     $data = $this->data;
     // return the total count
     //return $data->shares->total;
     return $data;
 }
Exemplo n.º 3
0
}
$data = json_decode(file_get_contents($data_file));
if (json_last_error()) {
    exit("Data file {$data_file} parsing failed\n");
}
$RCX = new RollingCurlX(10);
$RCX->setCallback('cb');
foreach ($data as $id => $post) {
    if (!isset($post->full_picture)) {
        $photos[$post->id] = 'post has no image';
        continue;
    }
    $file_name = getFileNameFromURL($post->full_picture);
    $file_path = $assetsFolder . "/photos/{$file_name}";
    if (!file_exists($file_path)) {
        $RCX->addRequest($post->full_picture, NULL, NULL, array('id' => $id, 'path' => $file_path));
        $photos[$post->id] = 'image download intitiated';
    } else {
        $photos[$post->id] = 'image exists on disk';
    }
}
$RCX->execute();
print_r($photos);
function cb($response, $url, $request_info, $user_data, $time)
{
    global $photos;
    if ($request_info['http_code'] == 200) {
        if (file_put_contents($user_data['path'], $response) !== FALSE) {
            $photos[$user_data['id']] = 'image downloaded';
        } else {
            $photos[$user_data['id']] = 'image save failed';