/** * Returns social buttons. * * @since 1.0.0 * * @return buttons */ public static function buttons($sharetext = '', $networks = array(), $url = '', $align = "center", $count = true, $native = false, $skin = 'default') { UltimateSocialDeux::enqueue_stuff(); if ($url) { $url = $url; $text = ''; $post_id = url_to_postid($url); } elseif (is_singular()) { $text = get_the_title(); $url = get_permalink(); $post_id = get_the_ID(); } elseif (in_the_loop()) { $text = get_the_title(); $url = get_permalink(); $post_id = get_the_ID(); } elseif (is_home()) { $text = get_bloginfo('name'); $url = get_bloginfo('url'); $post_id = url_to_postid($url); } elseif (is_tax() || is_category()) { global $wp_query; $term = $wp_query->get_queried_object(); $text = $term->name; $url = "http://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"; $post_id = 0; } else { $text = get_bloginfo('name'); $url = "http://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"; $post_id = url_to_postid($url); } if ($align == 'left') { $align = " us_tal"; } elseif ($align == 'right') { $align = " us_tar"; } else { $align = " us_tac"; } $skin = $skin ? sprintf(' us_skin_%s', $skin) : ' us_skin_default'; $networks = str_replace(' ', '', $networks); $networks = is_array($networks) ? $networks : explode(',', $networks); $networks = array_filter($networks); $count = filter_var($count, FILTER_VALIDATE_BOOLEAN); $native = filter_var($native, FILTER_VALIDATE_BOOLEAN); global $us_share_counts; $us_share_counts = !isset($us_share_counts) ? maybe_unserialize(get_option('us_share_counts', array())) : $us_share_counts; $ajaxnetworks = ''; $us_share_counts[$url] = isset($us_share_counts[$url]) ? $us_share_counts[$url] : array(); foreach ($networks as $network) { $network = strpos($network, 'facebook') === 0 ? 'facebook' : $network; $network = strpos($network, 'google') === 0 ? 'google' : $network; $network = strpos($network, 'vkontakte') === 0 ? 'vkontakte' : $network; if (array_key_exists($network, self::ajax_count()) && (!array_key_exists($network, $us_share_counts[$url]) || isset($us_share_counts[$url][$network]['timestamp']) && $us_share_counts[$url][$network]['timestamp'] + intval(UltimateSocialDeux::opt('us_counts_transient', 600)) < time())) { $ajaxnetworks .= $network . ','; } } $ajaxnetworks = $ajaxnetworks ? sprintf(' data-ajaxnetworks="%s"', substr($ajaxnetworks, 0, -1)) : ''; if ($url) { $output = sprintf('<div class="us_wrapper us_share_buttons%s%s" data-text="%s" data-url="%s"%s>', $align, $skin, strip_tags($text), $url, $ajaxnetworks); $more = ''; $names = ''; if ($sharetext) { $output .= sprintf('<div class="us_button us_share_text"><span class="us_share_text_span">%s</span></div>', $sharetext); } foreach ($networks as $button) { $native = substr($button, -7) == '_native' ? true : $native; $button = strpos($button, 'facebook') === 0 ? 'facebook' : $button; $button = strpos($button, 'google') === 0 ? 'google' : $button; $button = strpos($button, 'vkontakte') === 0 ? 'vkontakte' : $button; $count_number = !array_key_exists($button, self::ajax_count()) && !array_key_exists($button, self::internal_count()) || $count == false ? false : $count; $number = isset($us_share_counts[$url][$button]['count']) ? UltimateSocialDeux::number_format($us_share_counts[$url][$button]['count']) : ''; $name = $names ? UltimateSocialDeux::opt('us_' . $button . '_name', '') : ''; switch ($button) { case 'total': $output .= self::total_button($url, $networks, $more, $us_share_counts, $post_id); break; case 'pinterest': $output .= self::pinterest_button($url, $text, $count_number, $more, $number, $name, $post_id); break; case 'buffer': $media = UltimateSocialDeux::catch_first_image($url, $post_id); $output .= self::button($button, $url, $count_number, false, $more, $media, $number, $name); break; case 'mail': $output .= self::mail_button($url, $more, $name); break; case 'comments': $output .= self::comments_button($url, $count_number, $more, $name, $post_id); break; case 'love': $output .= self::love_button($url, $count_number, $more, $name, $post_id); break; case 'print': $output .= self::print_button($more, $name); break; case 'whatsapp': $output .= self::whatsapp_button($more, $name); break; case 'more': wp_enqueue_script('jquery-magnific-popup'); $random_string = UltimateSocialDeux::random_string(5); $more = ' us_after_more'; $output .= '<div class="us_more us_button us_no_count"><a class="us_box" href="#us-modal-' . $random_string . '"><div class="us_share"><i class="us-icon-plus"></i></div></a></div>'; $output .= sprintf('<div class="us_wrapper us_modal mfp-hide%s" id="us-modal-%s">', $skin, $random_string); $output .= '<div class="us_heading">'; $output .= __('More share buttons', 'ultimate-social-deux'); $output .= '</div>'; $output .= sprintf('<div class="us_modal_button_wrapper us_tac" data-text="%s" data-url="%s">', strip_tags($text), $url); break; case 'more_end': if (in_array('more', $networks) && $more != '') { $output .= '</div></div>'; $more = ''; } break; case 'names': $names = true; break; case 'names_end': $names = false; break; default: $output .= self::button($button, $url, $count_number, $native, $more, false, $number, $name); break; } $native = ''; } if (in_array('more', $networks) && (!in_array('more_end', $networks) || $more != '')) { $output .= '</div></div>'; } $output .= '</div>'; return $output; } }
/** * Return fan counters * * @since 1.0.0 * * @return count */ public static function fan_count_output($networks = '', $rows = '1', $skin = '') { wp_enqueue_script('jquery-fittext'); UltimateSocialDeux::enqueue_stuff(); global $us_fan_count_data; $skin = $skin ? sprintf(' us_skin_%s', $skin) : ' us_skin_default'; $networks = str_replace(' ', '', $networks); $networks = explode(',', $networks); global $us_fan_counts; $us_fan_counts = !isset($us_fan_counts) ? maybe_unserialize(get_option('us_fan_counts', array())) : $us_fan_counts; $ajaxnetworks = ''; foreach ($networks as $network) { if (array_key_exists($network, self::ajax_count()) && (!array_key_exists($network, $us_fan_counts) || isset($us_fan_counts[$network]['timestamp']) && $us_fan_counts[$network]['timestamp'] + intval(UltimateSocialDeux::opt('us_cache', 2)) * 3600 < time())) { $ajaxnetworks .= $network . ','; } } $ajaxnetworks = $ajaxnetworks ? sprintf(' data-ajaxnetworks="%s"', substr($ajaxnetworks, 0, -1)) : ''; $output = sprintf('<div class="us_wrapper us_fan_count_wrapper%s"%s>', $skin, $ajaxnetworks); foreach ($networks as &$network) { $count = isset($us_fan_counts[$network]['count']) ? UltimateSocialDeux::number_format($us_fan_counts[$network]['count']) : 0; switch ($network) { case "facebook": $desc = __('Fans', 'ultimate-social-deux'); $link = sprintf('https://facebook.com/%s', UltimateSocialDeux::opt('us_facebook_id', '')); $output .= self::counter($network, $count, $desc, $rows, $link); break; case "twitter": $desc = __('Followers', 'ultimate-social-deux'); $link = sprintf('https://twitter.com/%s', UltimateSocialDeux::opt('us_twitter_id', '')); $output .= self::counter($network, $count, $desc, $rows, $link); break; case "google": $desc = __('Followers', 'ultimate-social-deux'); $link = sprintf('https://plus.google.com/%s/', UltimateSocialDeux::opt('us_google_id', '')); $output .= self::counter($network, $count, $desc, $rows, $link); break; case "youtube": $desc = __('Subscribers', 'ultimate-social-deux'); $youtube_type = UltimateSocialDeux::opt('youtube_type', 'user'); if ($youtube_type == 'user') { $link = sprintf('https://www.youtube.com/user/%s/', UltimateSocialDeux::opt('us_youtube_id', '')); } else { $link = sprintf('https://www.youtube.com/channel/%s/', UltimateSocialDeux::opt('us_youtube_id', '')); } $output .= self::counter($network, $count, $desc, $rows, $link); break; case "love": $count = UltimateSocialDeux::number_format(self::love_count()); $desc = __('Total loves', 'ultimate-social-deux'); $link = ''; $output .= self::counter($network, $count, $desc, $rows, $link, ''); break; case "delicious": $desc = __('Followers', 'ultimate-social-deux'); $link = sprintf('https://delicious.com/%s/', UltimateSocialDeux::opt('us_delicious_id', '')); $output .= self::counter($network, $count, $desc, $rows, $link); break; case "linkedin": $desc = __('Followers', 'ultimate-social-deux'); $link = sprintf('https://linkedin.com/company/%s', UltimateSocialDeux::opt('us_linkedin_id', '')); $output .= self::counter($network, $count, $desc, $rows, $link); break; case "behance": $desc = __('Followers', 'ultimate-social-deux'); $link = sprintf('https://www.behance.net/%s', UltimateSocialDeux::opt('us_behance_id', '')); $output .= self::counter($network, $count, $desc, $rows, $link); break; case "vimeo": $desc = __('Subscribers', 'ultimate-social-deux'); $link = sprintf('http://vimeo.com/channels/%s', UltimateSocialDeux::opt('us_vimeo_id', '')); $output .= self::counter($network, $count, $desc, $rows, $link); break; case "dribbble": $desc = __('Followers', 'ultimate-social-deux'); $link = sprintf('https://dribbble.com/%s', UltimateSocialDeux::opt('us_dribbble_id', '')); $output .= self::counter($network, $count, $desc, $rows, $link); break; case "envato": $desc = __('Followers', 'ultimate-social-deux'); $link = sprintf('http://codecanyon.net/user/%s/follow', UltimateSocialDeux::opt('us_envato_id', '')); $output .= self::counter($network, $count, $desc, $rows, $link); break; case "github": $desc = __('Followers', 'ultimate-social-deux'); $link = sprintf('https://github.com/%s', UltimateSocialDeux::opt('us_github_id', '')); $output .= self::counter($network, $count, $desc, $rows, $link); break; case "soundcloud": $desc = __('Followers', 'ultimate-social-deux'); $link = sprintf('https://soundcloud.com/%s', UltimateSocialDeux::opt('us_soundcloud_username', '')); $output .= self::counter($network, $count, $desc, $rows, $link); break; case "instagram": $desc = __('Followers', 'ultimate-social-deux'); $link = sprintf('http://instagram.com/%s', UltimateSocialDeux::opt('us_instagram_username', '')); $output .= self::counter($network, $count, $desc, $rows, $link); break; case "vkontakte": $desc = __('Members', 'ultimate-social-deux'); $link = sprintf('http://vk.com/%s', UltimateSocialDeux::opt('us_vkontakte_id', '')); $output .= self::counter($network, $count, $desc, $rows, $link); break; case "feedpress": $desc = __('Subscribers', 'ultimate-social-deux'); $link = sprintf('%s', UltimateSocialDeux::opt('us_feedpress_url', '')); $output .= self::counter($network, $count, $desc, $rows, $link); break; case "pinterest": $desc = __('Followers', 'ultimate-social-deux'); $link = sprintf('http://www.pinterest.com/%s', UltimateSocialDeux::opt('us_pinterest_username', '')); $output .= self::counter($network, $count, $desc, $rows, $link); break; case "mailchimp": $desc = __('Subscribers', 'ultimate-social-deux'); $link = sprintf('%s', UltimateSocialDeux::opt('us_mailchimp_link', '')); $output .= self::counter($network, $count, $desc, $rows, $link); break; case "flickr": $desc = __('Members', 'ultimate-social-deux'); $link = sprintf('https://www.flickr.com/groups/%s/', UltimateSocialDeux::opt('us_flickr_id', '')); $output .= self::counter($network, $count, $desc, $rows, $link); break; case "members": $count = UltimateSocialDeux::number_format(self::members_count()); $desc = __('Members', 'ultimate-social-deux'); $link = sprintf('%s', UltimateSocialDeux::opt('us_members_link', '')); $output .= self::counter($network, $count, $desc, $rows, $link, 'false'); break; case "posts": $count = UltimateSocialDeux::number_format(self::posts_count()); $desc = __('Posts', 'ultimate-social-deux'); $link = sprintf('%s', UltimateSocialDeux::opt('us_posts_link', '')); $output .= self::counter($network, $count, $desc, $rows, $link, 'false'); break; case "comments": $count = UltimateSocialDeux::number_format(self::comments_count()); $desc = __('Comments', 'ultimate-social-deux'); $link = ''; $output .= self::counter($network, $count, $desc, $rows, $link, 'false'); break; } } $output .= '</div>'; if ($us_fan_count_data) { self::update_count($us_fan_count_data); } return $output; }