function tie_dribbble_count($page_link)
{
    $dribbble_link = @parse_url($page_link);
    if ($dribbble_link['host'] == 'www.dribbble.com' || $dribbble_link['host'] == 'dribbble.com') {
        $dribbble = get_transient('dribbble_count');
        if (empty($dribbble)) {
            try {
                $page_name = substr(@parse_url($page_link, PHP_URL_PATH), 1);
                @($data = @json_decode(tie_remote_get('http://api.dribbble.com/' . $page_name)));
                $dribbble = $data->followers_count;
            } catch (Exception $e) {
                $dribbble = 0;
            }
            if (!empty($dribbble)) {
                set_transient('dribbble_count', $dribbble, 1200);
                if (get_option('dribbble_count') != $dribbble) {
                    update_option('dribbble_count', $dribbble);
                }
            }
            if ($dribbble == 0 && get_option('dribbble_count')) {
                $dribbble = get_option('dribbble_count');
            } elseif ($dribbble == 0 && !get_option('dribbble_count')) {
                $dribbble = 0;
            }
        }
        return $dribbble;
    }
}
Example #2
0
function tie_instagram_count($page_link, $api)
{
    $instagram_link = @parse_url($page_link);
    if ($instagram_link['host'] == 'www.instagram.com' || $instagram_link['host'] == 'instagram.com') {
        $instagram = get_transient('instagram_count');
        if (empty($instagram)) {
            try {
                $username = explode(".", $api);
                $data = @json_decode(tie_remote_get("https://api.instagram.com/v1/users/{$username['0']}/?access_token={$api}"), true);
                $instagram = (int) $data['data']['counts']['followed_by'];
            } catch (Exception $e) {
                $instagram = 0;
            }
            if (!empty($instagram)) {
                set_transient('instagram_count', $instagram, 1200);
                if (get_option('instagram_count') != $instagram) {
                    update_option('instagram_count', $instagram);
                }
            }
            if ($instagram == 0 && get_option('instagram_count')) {
                $instagram = get_option('instagram_count');
            } elseif ($instagram == 0 && !get_option('instagram_count')) {
                $instagram = 0;
            }
        }
        return $instagram;
    }
}