Written by Anonymous
//Facebookシェア数を取得する
if ( !function_exists( 'fetch_facebook_count' ) ):
function fetch_facebook_count($post_id = null) {
// URLを取得
$url = $post_id ? get_permalink($post_id) : get_the_permalink();
// キャッシュIDを投稿IDまたはget_share_cache_ID()で取得
$cache_id = $post_id ? $post_id : get_share_cache_ID();
$transient_id = TRANSIENT_SHARE_PREFIX . 'facebook_' . $cache_id;
//DBキャッシュからカウントの取得
if (is_sns_share_count_cache_enable()) {
$count = get_transient( $transient_id );
if ( is_numeric($count) ) {
return $count;
}
}
if (!$url) {
$url = get_the_permalink();
}
$res = fetch_facebook_count_raw($url);
//別スキームカウントの取得
if (is_sns_share_count_cache_enable() && is_another_scheme_sns_share_count()) {
$res = $res + fetch_facebook_count_raw(get_another_scheme_url($url));
}
//DBキャッシュへ保存
if (is_sns_share_count_cache_enable()) {
set_transient( $transient_id, $res, HOUR_IN_SECONDS * get_sns_share_count_cache_interval() );
}
return $res;
}
endif;
//Facebookカウントの取得
if ( !function_exists( 'get_facebook_count' ) ):
function get_facebook_count($post_id = null) {
if (!is_sns_share_buttons_count_visible())
return null;
if (is_scc_facebook_exists()) {
return scc_get_share_facebook();
} else {
return fetch_facebook_count($post_id);
}
}
endif;
if ( !function_exists( 'fetch_hatebu_count' ) ):
function fetch_hatebu_count($post_id = null) {
// URLを取得
$url = $post_id ? get_permalink($post_id) : get_the_permalink();
// キャッシュIDを投稿IDまたはget_share_cache_ID()で取得
$cache_id = $post_id ? $post_id : get_share_cache_ID();
$transient_id = TRANSIENT_SHARE_PREFIX.'hatebu_'.get_share_cache_ID();
//DBキャッシュからカウントの取得
if (is_sns_share_count_cache_enable()) {
$count = get_transient( $transient_id );
if ( is_numeric($count) ) {
return $count;
}
}
if (!$url) {
$url = get_the_permalink();
}
$res = fetch_hatebu_count_raw($url);
//別スキームカウントの取得
if (is_sns_share_count_cache_enable() && is_another_scheme_sns_share_count()) {
$res = $res + fetch_hatebu_count_raw(get_another_scheme_url($url));
}
//DBキャッシュへ保存
if (is_sns_share_count_cache_enable()) {
set_transient( $transient_id, $res, HOUR_IN_SECONDS * get_sns_share_count_cache_interval() );
}
return $res;
}
endif;
//はてブカウントの取得
if ( !function_exists( 'get_hatebu_count' ) ):
function get_hatebu_count($post_id = null) {
if (!is_sns_share_buttons_count_visible())
return null;
if (is_scc_hatebu_exists()) {
return scc_get_share_hatebu();
} else {
return fetch_hatebu_count($post_id);
}
}
endif;
//Pocketカウントの取得
if ( !function_exists( 'fetch_pocket_count' ) ):
function fetch_pocket_count($post_id = null) {
// URLを取得
$url = $post_id ? get_permalink($post_id) : get_the_permalink();
// キャッシュIDを投稿IDまたはget_share_cache_ID()で取得
$cache_id = $post_id ? $post_id : get_share_cache_ID();
$transient_id = TRANSIENT_SHARE_PREFIX.'pocket_'.get_share_cache_ID();
//DBキャッシュからカウントの取得
if (is_sns_share_count_cache_enable()) {
$count = get_transient( $transient_id );
if ( is_numeric($count) ) {
return $count;
}
}
$res = 0;
if (!$url) {
$url = get_the_permalink();
}
$res = fetch_pocket_count_raw($url);
//別スキームカウントの取得
if (is_sns_share_count_cache_enable() && is_another_scheme_sns_share_count()) {
$res = $res + fetch_pocket_count_raw(get_another_scheme_url($url));
}
//DBキャッシュへ保存
if (is_sns_share_count_cache_enable()) {
set_transient( $transient_id, $res, HOUR_IN_SECONDS * get_sns_share_count_cache_interval() );
}
return $res;
}
endif;
//Pocketカウントの取得
if ( !function_exists( 'get_pocket_count' ) ):
function get_pocket_count($post_id = null) {
if (!is_sns_share_buttons_count_visible())
return null;
if (is_scc_pocket_exists()) {
return scc_get_share_pocket();
} else {
return fetch_pocket_count($post_id);
}
}
endif;