コード例 #1
0
 public static function update_counters($post_id, $url, $full_url, $networks = array(), $recover_mode = false)
 {
     global $essb_options;
     $twitter_counter = ESSBOptionValuesHelper::options_value($essb_options, 'twitter_counters');
     if ($twitter_counter == "") {
         $twitter_counter = "api";
     }
     $cached_counters = array();
     $cached_counters['total'] = 0;
     foreach ($networks as $k) {
         switch ($k) {
             case "facebook":
                 $cached_counters[$k] = ESSBCountersHelper::get_facebook_count($url);
                 break;
             case "twitter":
                 if ($twitter_counter == "api") {
                     $cached_counters[$k] = ESSBCountersHelper::get_tweets($full_url);
                 } else {
                     if ($twitter_counter == "newsc") {
                         $cached_counters[$k] = ESSBCountersHelper::get_tweets_newsc($full_url);
                     } else {
                         if ($twitter_counter == "self") {
                             if (!$recover_mode) {
                                 $cached_counters[$k] = ESSBCountersHelper::getSelfPostCount($post_id, $k);
                             } else {
                                 $cached_counters[$k] = 0;
                             }
                         }
                     }
                 }
                 break;
             case "linkedin":
                 $cached_counters[$k] = ESSBCountersHelper::get_linkedin($url);
                 break;
             case "pinterest":
                 $cached_counters[$k] = ESSBCountersHelper::get_pinterest($url);
                 break;
             case "google":
                 $cached_counters[$k] = ESSBCountersHelper::getGplusShares($url);
                 break;
             case "stumbleupon":
                 $cached_counters[$k] = ESSBCountersHelper::get_stumbleupon($url);
                 break;
             case "vk":
                 $cached_counters[$k] = ESSBCountersHelper::get_counter_number__vk($url);
                 break;
             case "reddit":
                 $cached_counters[$k] = ESSBCountersHelper::getRedditScore($url);
                 break;
             case "buffer":
                 $cached_counters[$k] = ESSBCountersHelper::get_buffer($url);
                 break;
             case "love":
                 if (!$recover_mode) {
                     $cached_counters[$k] = ESSBCountersHelper::getLoveCount($post_id);
                 } else {
                     $cached_counters[$k] = 0;
                 }
                 break;
             case "ok":
                 $cached_counters[$k] = ESSBCountersHelper::get_counter_number_odnoklassniki($url);
                 break;
             case "mwp":
                 $cached_counters[$k] = ESSBCountersHelper::getManagedWPUpVote($url);
                 break;
             case "xing":
                 $cached_counters[$k] = ESSBCountersHelper::getXingCount($url);
                 break;
             case "pocket":
                 $cached_counters[$k] = ESSBCountersHelper::getPocketCount($url);
                 break;
             case "comments":
                 if (!$recover_mode) {
                     $cached_counters[$k] = ESSBCountersHelper::get_comments_count($post_id);
                 } else {
                     $cached_counters[$k] = 0;
                 }
                 break;
             case "yummly":
                 $cached_counters[$k] = ESSBCountersHelper::get_yummly($url);
                 break;
             default:
                 if (!$recover_mode) {
                     $cached_counters[$k] = ESSBCountersHelper::getSelfPostCount($post_id, $k);
                 } else {
                     $cached_counters[$k] = 0;
                 }
                 break;
         }
         $cached_counters['total'] += intval($cached_counters[$k]);
     }
     if (!$recover_mode) {
         $time = floor(date('U') / 60 / 60);
         update_post_meta($post_id, 'essb_cache_timestamp', $time);
     }
     return $cached_counters;
 }
コード例 #2
0
 function actions_get_share_counts()
 {
     $networks = isset($_REQUEST['nw']) ? $_REQUEST['nw'] : '';
     $url = isset($_REQUEST['url']) ? $_REQUEST['url'] : '';
     $instance = isset($_REQUEST['instance']) ? $_REQUEST['instance'] : '';
     $post = isset($_REQUEST['post']) ? $_REQUEST['post'] : '';
     $networks = sanitize_text_field($networks);
     header('content-type: application/json');
     // check if cache is present
     //print_r($this->general_options);
     $is_active_cache = $this->general_options['admin_ajax_cache'];
     $cache_ttl = intval($this->general_options['admin_ajax_cache_time']);
     if ($cache_ttl == 0) {
         $cache_ttl = 600;
     }
     $list = explode(',', $networks);
     $output = array();
     $output['url'] = $url;
     $output['instance'] = $instance;
     $output['post'] = $post;
     $output['network'] = $networks;
     foreach ($list as $nw) {
         $transient_key = 'essb_' . $nw . '_' . $url;
         $exist_in_cache = false;
         if ($is_active_cache) {
             $cached_value = get_transient($transient_key);
             if ($cached_value) {
                 $output[$nw] = $cached_value;
                 $exist_in_cache = true;
             }
         }
         if (!$exist_in_cache) {
             $count = ESSBCountersHelper::get_shared_counter($nw, $url, $post);
             $output[$nw] = $count;
             if ($is_active_cache) {
                 delete_transient($transient_key);
                 set_transient($transient_key, $count, $cache_ttl);
             }
         }
     }
     echo str_replace('\\/', '/', json_encode($output));
     die;
 }