function swp_linkedIn_button_html($array) { // If we've already generated this button, just use our existing html if (isset($_GLOBALS['sw']['buttons'][$array['postID']]['linkedIn'])) { $array['resource']['linkedIn'] = $_GLOBALS['sw']['buttons'][$array['postID']]['linkedIn']; // If not, let's check if Facebook is activated and create the button HTML } elseif (isset($array['options']['newOrderOfIcons']['linkedIn']) && !isset($array['buttons']) || isset($array['buttons']) && isset($array['buttons']['linkedIn'])) { $array['totes'] += $array['shares']['linkedIn']; ++$array['count']; $array['resource']['linkedIn'] = '<div class="nc_tweetContainer linkedIn" data-id="' . $array['count'] . '" data-network="linked_in">'; $link = urlencode(urldecode(swp_process_url($array['url'], 'linkedIn', $array['postID']))); $array['resource']['linkedIn'] .= '<a target="_blank" href="https://www.linkedin.com/cws/share?url=' . $link . '" data-link="https://www.linkedin.com/cws/share?url=' . $link . '" class="nc_tweet">'; if ($array['options']['totesEach'] && $array['shares']['totes'] >= $array['options']['minTotes'] && $array['shares']['linkedIn'] > 0) { $array['resource']['linkedIn'] .= '<span class="iconFiller">'; $array['resource']['linkedIn'] .= '<span class="spaceManWilly">'; $array['resource']['linkedIn'] .= '<i class="sw sw-linkedin"></i>'; $array['resource']['linkedIn'] .= '<span class="swp_share"> ' . __('Share', 'social-warfare') . '</span>'; $array['resource']['linkedIn'] .= '</span></span>'; $array['resource']['linkedIn'] .= '<span class="swp_count">' . swp_kilomega($array['shares']['linkedIn']) . '</span>'; } else { $array['resource']['linkedIn'] .= '<span class="swp_count swp_hide"><span class="iconFiller"><span class="spaceManWilly"><i class="sw sw-linkedin"></i><span class="swp_share"> ' . __('Share', 'social-warfare') . '</span></span></span></span>'; } $array['resource']['linkedIn'] .= '</a>'; $array['resource']['linkedIn'] .= '</div>'; // Store these buttons so that we don't have to generate them for each set $_GLOBALS['sw']['buttons'][$array['postID']]['linkedIn'] = $array['resource']['linkedIn']; } return $array; }
function swp_buffer_button_html($array) { // If we've already generated this button, just use our existing html if (isset($_GLOBALS['sw']['buttons'][$array['postID']]['buffer'])) { $array['resource']['buffer'] = $_GLOBALS['sw']['buttons'][$array['postID']]['buffer']; // If not, let's check if Buffer is activated and create the button HTML } elseif (isset($array['options']['newOrderOfIcons']['buffer']) && !isset($array['buttons']) || isset($array['buttons']) && isset($array['buttons']['buffer'])) { // Collect the Title $title = get_post_meta($array['postID'], 'nc_ogTitle', true); if (!$title) { $title = get_the_title(); } $array['totes'] += $array['shares']['buffer']; ++$array['count']; $array['resource']['buffer'] = '<div class="nc_tweetContainer swp_buffer" data-id="' . $array['count'] . '" data-network="buffer">'; $link = urlencode(urldecode(swp_process_url($array['url'], 'buffer', $array['postID']))); $array['resource']['buffer'] .= '<a target="_blank" href="http://bufferapp.com/add?url=' . $link . '&text=' . urlencode(html_entity_decode($title, ENT_COMPAT, 'UTF-8')) . '" data-link="http://bufferapp.com/add?url=' . $link . '&text=' . urlencode(html_entity_decode($title, ENT_COMPAT, 'UTF-8')) . '" class="nc_tweet buffer_link">'; if ($array['options']['totesEach'] && $array['shares']['totes'] >= $array['options']['minTotes'] && $array['shares']['buffer'] > 0) { $array['resource']['buffer'] .= '<span class="iconFiller">'; $array['resource']['buffer'] .= '<span class="spaceManWilly">'; $array['resource']['buffer'] .= '<i class="sw sw-buffer"></i>'; $array['resource']['buffer'] .= '<span class="swp_share"> ' . __('Buffer', 'social-warfare') . '</span>'; $array['resource']['buffer'] .= '</span></span>'; $array['resource']['buffer'] .= '<span class="swp_count">' . swp_kilomega($array['shares']['buffer']) . '</span>'; } else { $array['resource']['buffer'] .= '<span class="swp_count swp_hide"><span class="iconFiller"><span class="spaceManWilly"><i class="sw sw-buffer"></i><span class="swp_share"> ' . __('Buffer', 'social-warfare') . '</span></span></span></span>'; } $array['resource']['buffer'] .= '</a>'; $array['resource']['buffer'] .= '</div>'; // Store these buttons so that we don't have to generate them for each set $_GLOBALS['sw']['buttons'][$array['postID']]['buffer'] = $array['resource']['buffer']; } return $array; }
function swp_hacker_news_button_html($array) { if (isset($array['options']['newOrderOfIcons']['hacker_news']) && !isset($array['buttons']) || isset($array['buttons']) && isset($array['buttons']['hacker_news'])) { // Collect the Title $title = get_post_meta($array['postID'], 'nc_ogTitle', true); if (!$title) { $title = get_the_title(); } ++$array['count']; $array['resource']['hacker_news'] = '<div class="nc_tweetContainer swp_hacker_news" data-id="' . $array['count'] . '" data-network="hacker_news">'; $link = urlencode(urldecode(swp_process_url($array['url'], 'email', $array['postID']))); $array['resource']['hacker_news'] .= '<a rel="nofollow" target="_blank" href="http://news.ycombinator.com/submitlink?u=' . $link . '&t=' . urlencode($title) . '" data-link="http://news.ycombinator.com/submitlink?u=' . $link . '&t=' . urlencode($title) . '" class="nc_tweet">'; if ($array['options']['totesEach'] && $array['shares']['totes'] >= $array['options']['minTotes'] && $array['shares']['hacker_news'] > 0) { $array['resource']['hacker_news'] .= '<span class="iconFiller">'; $array['resource']['hacker_news'] .= '<span class="spaceManWilly">'; $array['resource']['hacker_news'] .= '<i class="sw sw-hacker_news"></i>'; $array['resource']['hacker_news'] .= '<span class="swp_share"> ' . __('Vote', 'social-warfare') . '</span>'; $array['resource']['hacker_news'] .= '</span></span>'; $array['resource']['hacker_news'] .= '<span class="swp_count">' . swp_kilomega($array['shares']['hacker_news']) . '</span>'; } else { $array['resource']['hacker_news'] .= '<span class="swp_count swp_hide"><span class="iconFiller"><span class="spaceManWilly"><i class="sw sw-hacker_news"></i><span class="swp_share"> ' . __('Vote', 'social-warfare') . '</span></span></span></span>'; } $array['resource']['hacker_news'] .= '</a>'; $array['resource']['hacker_news'] .= '</div>'; } return $array; }
function swp_pocket_button_html($array) { if (isset($array['options']['newOrderOfIcons']['pocket']) && !isset($array['buttons']) || isset($array['buttons']) && isset($array['buttons']['pocket'])) { // Collect the Title $title = get_post_meta($array['postID'], 'nc_ogTitle', true); if (!$title) { $title = get_the_title(); } ++$array['count']; $array['resource']['pocket'] = '<div class="nc_tweetContainer swp_pocket" data-id="' . $array['count'] . '" data-network="pocket">'; $link = urlencode(urldecode(swp_process_url($array['url'], 'pocket', $array['postID']))); $array['resource']['pocket'] .= '<a href="https://getpocket.com/save?url=' . $link . '&title=' . $title . '" data-link="https://getpocket.com/save?url=' . $link . '&title=' . $title . '" class="nc_tweet">'; $array['resource']['pocket'] .= '<span class="swp_count swp_hide"><span class="iconFiller"><span class="spaceManWilly"><i class="sw sw-pocket"></i><span class="swp_share"> ' . __('Pocket', 'social-warfare') . '</span></span></span></span>'; $array['resource']['pocket'] .= '</a>'; $array['resource']['pocket'] .= '</div>'; } return $array; }
function clickToTweetShortcode($atts) { $url = swp_process_url(get_permalink(), 'twitter', get_the_ID()); strpos($atts['tweet'], 'http') !== false ? $urlParam = '&url=/' : ($urlParam = '&url=' . $url); $atts['tweet'] = rtrim($atts['tweet']); $options = swp_get_user_options(); $user_twitter_handle = get_post_meta(get_the_ID(), 'swp_twitter_username', true); if (!$user_twitter_handle) { $user_twitter_handle = $options['twitterID']; } if (isset($atts['theme']) && $atts['theme'] != 'default') { $theme = $atts['theme']; } else { $theme = $options['cttTheme']; } return ' <div class="sw-tweet-clear"></div> <a class="swp_CTT ' . $theme . '" href="https://twitter.com/share?text=' . urlencode(html_entity_decode($atts['tweet'], ENT_COMPAT, 'UTF-8')) . $urlParam . '' . ($user_twitter_handle ? '&via=' . str_replace('@', '', $user_twitter_handle) : '') . '" data-link="https://twitter.com/share?text=' . urlencode(html_entity_decode($atts['tweet'], ENT_COMPAT, 'UTF-8')) . $urlParam . '' . ($user_twitter_handle ? '&via=' . str_replace('@', '', $user_twitter_handle) : '') . '" target="_blank"><span class="sw-click-to-tweet"><span class="sw-ctt-text">' . $atts['quote'] . '</span><span class="sw-ctt-btn">' . __('Click To Tweet', 'social-warfare') . '<i class="sw sw-twitter"></i></span></span></a>'; }
function swp_flipboard_button_html($array) { if (isset($array['options']['newOrderOfIcons']['flipboard']) && !isset($array['buttons']) || isset($array['buttons']) && isset($array['buttons']['flipboard'])) { // Collect the Title $title = get_post_meta($array['postID'], 'nc_ogTitle', true); if (!$title) { $title = get_the_title(); } // Collect the Description $description = get_post_meta($array['postID'], 'nc_ogDescription', true); if (!$description) { $description = swp_get_excerpt_by_id($array['postID']); } ++$array['count']; $array['resource']['flipboard'] = '<div class="nc_tweetContainer swp_flipboard" data-id="' . $array['count'] . '" data-network="flipboard">'; $link = urlencode(urldecode(swp_process_url($array['url'], 'flipboard', $array['postID']))); $array['resource']['flipboard'] .= '<a rel="nofollow" href="https://share.flipboard.com/bookmarklet/popout?v=2&title=Tools%20-%20Flipboard&url=' . $link . '" data-link="https://share.flipboard.com/bookmarklet/popout?v=2&title=Tools%20-%20Flipboard&url=' . $link . '" class="nc_tweet flipboard">'; $array['resource']['flipboard'] .= '<span class="swp_count swp_hide"><span class="iconFiller"><span class="spaceManWilly"><i class="sw sw-flipboard"></i><span class="swp_share"> ' . __('Flip', 'social-warfare') . '</span></span></span></span>'; $array['resource']['flipboard'] .= '</a>'; $array['resource']['flipboard'] .= '</div>'; } return $array; }
function swp_email_button_html($array) { if (isset($array['options']['newOrderOfIcons']['email']) && !isset($array['buttons']) || isset($array['buttons']) && isset($array['buttons']['email'])) { // Collect the Title $title = get_post_meta($array['postID'], 'nc_ogTitle', true); if (!$title) { $title = get_the_title(); } // Collect the Description $description = get_post_meta($array['postID'], 'nc_ogDescription', true); if (!$description) { $description = swp_get_excerpt_by_id($array['postID']); } ++$array['count']; $array['resource']['email'] = '<div class="nc_tweetContainer swp_email" data-id="' . $array['count'] . '" data-network="email">'; $link = urlencode(urldecode(swp_process_url($array['url'], 'email', $array['postID']))); $array['resource']['email'] .= '<a rel="nofollow" href="mailto:?subject=' . str_replace('&', '%26', rawurlencode(html_entity_decode($title, ENT_COMPAT, 'UTF-8'))) . '&body=' . str_replace('&', '%26', rawurlencode(html_entity_decode($description, ENT_COMPAT, 'UTF-8'))) . rawurlencode(' Read here: ') . $link . '" class="nc_tweet">'; $array['resource']['email'] .= '<span class="swp_count swp_hide"><span class="iconFiller"><span class="spaceManWilly"><i class="sw sw-email"></i><span class="swp_share"> ' . __('Email', 'social-warfare') . '</span></span></span></span>'; $array['resource']['email'] .= '</a>'; $array['resource']['email'] .= '</div>'; } return $array; }
function swp_tumblr_button_html($array) { // If we've already generated this button, just use our existing html if (isset($_GLOBALS['sw']['buttons'][$array['postID']]['tumblr'])) { $array['resource']['tumblr'] = $_GLOBALS['sw']['buttons'][$array['postID']]['tumblr']; // If not, let's check if Facebook is activated and create the button HTML } elseif (isset($array['options']['newOrderOfIcons']['tumblr']) && !isset($array['buttons']) || isset($array['buttons']) && isset($array['buttons']['tumblr'])) { $array['totes'] += $array['shares']['tumblr']; ++$array['count']; // Collect the Title $title = get_post_meta($array['postID'], 'nc_ogTitle', true); if (!$title) { $title = get_the_title(); } // Collect the Description $description = get_post_meta($array['postID'], 'nc_ogDescription', true); $array['resource']['tumblr'] = '<div class="nc_tweetContainer swp_tumblr" data-id="' . $array['count'] . '" data-network="tumblr">'; $link = urlencode(urldecode(swp_process_url($array['url'], 'tumblr', $array['postID']))); $array['resource']['tumblr'] .= '<a rel="nofollow" target="_blank" href="http://www.tumblr.com/share/link?url=' . $link . '&name=' . urlencode($title) . ($description ? '&description=' : '') . urlencode($description) . '" data-link="http://www.tumblr.com/share/link?url=' . $link . '&name=' . urlencode($title) . ($description ? '&description=' : '') . urlencode($description) . '" class="nc_tweet">'; if ($array['options']['totesEach'] && $array['shares']['totes'] >= $array['options']['minTotes'] && $array['shares']['tumblr'] > 0) { $array['resource']['tumblr'] .= '<span class="iconFiller">'; $array['resource']['tumblr'] .= '<span class="spaceManWilly">'; $array['resource']['tumblr'] .= '<i class="sw sw-tumblr"></i>'; $array['resource']['tumblr'] .= '<span class="swp_share"> ' . __('Share', 'social-warfare') . '</span>'; $array['resource']['tumblr'] .= '</span></span>'; $array['resource']['tumblr'] .= '<span class="swp_count">' . swp_kilomega($array['shares']['tumblr']) . '</span>'; } else { $array['resource']['tumblr'] .= '<span class="swp_count swp_hide"><span class="iconFiller"><span class="spaceManWilly"><i class="sw sw-tumblr"></i><span class="swp_share"> ' . __('Share', 'social-warfare') . '</span></span></span></span>'; } $array['resource']['tumblr'] .= '</a>'; $array['resource']['tumblr'] .= '</div>'; // Store these buttons so that we don't have to generate them for each set $_GLOBALS['sw']['buttons'][$array['postID']]['tumblr'] = $array['resource']['tumblr']; } return $array; }
function swp_twitter_button_html($array) { // If we've already generated this button, just use our existing html if (isset($_GLOBALS['sw']['buttons'][$array['postID']]['twitter'])) { $array['resource']['twitter'] = $_GLOBALS['sw']['buttons'][$array['postID']]['twitter']; // If not, let's check if Facebook is activated and create the button HTML } elseif (isset($array['options']['newOrderOfIcons']['twitter']) && !isset($array['buttons']) || isset($array['buttons']) && isset($array['buttons']['twitter'])) { $array['totes'] += $array['shares']['twitter']; ++$array['count']; $title = strip_tags(get_the_title($array['postID'])); $title = str_replace('|', '', $title); $ct = get_post_meta($array['postID'], 'nc_customTweet', true); $ct = $ct != '' ? urlencode(html_entity_decode($ct, ENT_COMPAT, 'UTF-8')) : urlencode(html_entity_decode($title, ENT_COMPAT, 'UTF-8')); $twitterLink = swp_process_url($array['url'], 'twitter', $array['postID']); if (strpos($ct, 'http') !== false) { $urlParam = '&url=/'; } else { $urlParam = '&url=' . $twitterLink; } if (swp_is_cache_fresh($array['postID']) == false) { $user_twitter_handle = get_the_author_meta('swp_twitter', swp_get_author($array['postID'])); if ($user_twitter_handle) { delete_post_meta($array['postID'], 'swp_twitter_username'); update_post_meta($array['postID'], 'swp_twitter_username', $user_twitter_handle); } else { delete_post_meta($array['postID'], 'swp_twitter_username'); } } else { $user_twitter_handle = get_post_meta($array['postID'], 'swp_twitter_username', true); } if ($user_twitter_handle) { $viaText = '&via=' . str_replace('@', '', $user_twitter_handle); } elseif ($array['options']['twitterID']) { $viaText = '&via=' . str_replace('@', '', $array['options']['twitterID']); } else { $viaText = ''; } $array['resource']['twitter'] = '<div class="nc_tweetContainer twitter" data-id="' . $array['count'] . '" data-network="twitter">'; $array['resource']['twitter'] .= '<a rel="nofollow" target="_blank" href="https://twitter.com/share?original_referer=/&text=' . $ct . '' . $urlParam . '' . $viaText . '" data-link="https://twitter.com/share?original_referer=/&text=' . $ct . '' . $urlParam . '' . $viaText . '" class="nc_tweet">'; if ($array['options']['totesEach'] && $array['shares']['totes'] >= $array['options']['minTotes'] && $array['shares']['twitter'] > 0) { $array['resource']['twitter'] .= '<span class="iconFiller">'; $array['resource']['twitter'] .= '<span class="spaceManWilly">'; $array['resource']['twitter'] .= '<i class="sw sw-twitter"></i>'; $array['resource']['twitter'] .= '<span class="swp_share"> ' . __('Tweet', 'social-warfare') . '</span>'; $array['resource']['twitter'] .= '</span></span>'; $array['resource']['twitter'] .= '<span class="swp_count">' . swp_kilomega($array['shares']['twitter']) . '</span>'; } else { $array['resource']['twitter'] .= '<span class="swp_count swp_hide"><span class="iconFiller"><span class="spaceManWilly"><i class="sw sw-twitter"></i><span class="swp_share"> ' . __('Tweet', 'social-warfare') . '</span></span></span></span>'; } $array['resource']['twitter'] .= '</a>'; $array['resource']['twitter'] .= '</div>'; // Store these buttons so that we don't have to generate them for each set $_GLOBALS['sw']['buttons'][$array['postID']]['twitter'] = $array['resource']['twitter']; } return $array; }
/** * Rebuild the share cache. * * @since unkown * @global $wpdb * @return void */ function swp_cache_rebuild() { global $wpdb; $post_id = absint($_POST['post_id']); // Bail if we already have fresh cache. if (swp_is_cache_fresh($post_id, true, true)) { wp_send_json_error(); die; } // Force the cache trigger on. set_query_var('swp_cache', 'rebuild'); // Fetch new shares $shares = get_social_warfare_shares($post_id); // Update Bitly links foreach ($shares as $key => $value) { swp_process_url(get_permalink($post_id), $key, $post_id); } // Update the Pinterest image $array['imageID'] = get_post_meta($post_id, 'nc_pinterestImage', true); if ($array['imageID']) { $array['imageURL'] = wp_get_attachment_url($array['imageID']); delete_post_meta($post_id, 'swp_pinterest_image_url'); update_post_meta($post_id, 'swp_pinterest_image_url', $array['imageURL']); } // Update the Twitter username $user_twitter_handle = get_the_author_meta('swp_twitter', swp_get_author($post_id)); if ($user_twitter_handle) { delete_post_meta($post_id, 'swp_twitter_username'); update_post_meta($post_id, 'swp_twitter_username', $user_twitter_handle); } else { delete_post_meta($post_id, 'swp_twitter_username'); } // Update the cache timestamp delete_post_meta($post_id, 'swp_cache_timestamp'); update_post_meta($post_id, 'swp_cache_timestamp', floor(date('U') / 60 / 60)); // Return the share count wp_send_json($shares); // Kill off all the WordPress functions wp_die(); }
function swp_whatsapp_button_html($array) { // If we've already generated this button, just use our existing html if (isset($_GLOBALS['sw']['buttons'][$array['postID']]['whatsapp'])) { $array['resource']['whatsapp'] = $_GLOBALS['sw']['buttons'][$array['postID']]['whatsapp']; // If not, let's check if WhatsApp is activated and create the button HTML } elseif (isset($array['options']['newOrderOfIcons']['whatsapp']) && swp_mobile_detection() && !isset($array['buttons']) || isset($array['buttons']) && isset($array['buttons']['whatsapp'])) { $array['totes'] += $array['shares']['whatsapp']; ++$array['count']; $array['resource']['whatsapp'] = '<div class="nc_tweetContainer swp_whatsapp" data-id="' . $array['count'] . '" data-network="whatsapp">'; $link = urlencode(urldecode(swp_process_url($array['url'], 'whatsapp', $array['postID']))); $array['resource']['whatsapp'] .= '<a target="_blank" href="whatsapp://send?text=' . $link . '" class="nc_tweet" data-action="share/whatsapp/share">'; if ($array['options']['totesEach'] && $array['shares']['totes'] >= $array['options']['minTotes'] && $array['shares']['whatsapp'] > 0) { $array['resource']['whatsapp'] .= '<span class="iconFiller">'; $array['resource']['whatsapp'] .= '<span class="spaceManWilly">'; $array['resource']['whatsapp'] .= '<i class="sw sw-whatsapp"></i>'; $array['resource']['whatsapp'] .= '<span class="swp_share"> ' . __('WhatsApp', 'social-warfare') . '</span>'; $array['resource']['whatsapp'] .= '</span></span>'; $array['resource']['whatsapp'] .= '<span class="swp_count">' . swp_kilomega($array['shares']['whatsapp']) . '</span>'; } else { $array['resource']['whatsapp'] .= '<span class="swp_count swp_hide"><span class="iconFiller"><span class="spaceManWilly"><i class="sw sw-whatsapp"></i><span class="swp_share"> ' . __('WhatsApp', 'social-warfare') . '</span></span></span></span>'; } $array['resource']['whatsapp'] .= '</a>'; $array['resource']['whatsapp'] .= '</div>'; // Store these buttons so that we don't have to generate them for each set $_GLOBALS['sw']['buttons'][$array['postID']]['whatsapp'] = $array['resource']['whatsapp']; } return $array; }
function swp_cache_rebuild() { // Gain access to the database global $wpdb; // Fetch the Post ID $post_id = $_POST['post_id']; // Ensure that the cache for this post is actually expired if (swp_is_cache_fresh($post_id, true, true) == false) { // Force the cache trigger on $_GET['swp_cache'] = 'rebuild'; // Fetch new shares $shares = get_social_warfare_shares($post_id); // Update Bitly links foreach ($shares as $key => $value) { swp_process_url(get_permalink($post_id), $key, $post_id); } // Update the Pinterest image $array['imageID'] = get_post_meta($post_id, 'nc_pinterestImage', true); if ($array['imageID']) { $array['imageURL'] = wp_get_attachment_url($array['imageID']); delete_post_meta($post_id, 'swp_pinterest_image_url'); update_post_meta($post_id, 'swp_pinterest_image_url', $array['imageURL']); } // Update the Twitter username $user_twitter_handle = get_the_author_meta('swp_twitter', swp_get_author($post_id)); if ($user_twitter_handle) { delete_post_meta($post_id, 'swp_twitter_username'); update_post_meta($post_id, 'swp_twitter_username', $user_twitter_handle); } else { delete_post_meta($post_id, 'swp_twitter_username'); } // Update the cache timestamp delete_post_meta($post_id, 'swp_cache_timestamp'); update_post_meta($post_id, 'swp_cache_timestamp', floor(date('U') / 60 / 60)); // Return the share count wp_send_json($shares); } // Kill off all the WordPress functions wp_die(); }