function sw_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']['twitter']) && $array['options']['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 = sw_process_url($array['url'], 'twitter', $array['postID']); if (strpos($ct, 'http') !== false) { $urlParam = '&url=/'; } else { $urlParam = '&url=' . $twitterLink; } if (sw_is_cache_fresh($array['postID']) == false) { $user_twitter_handle = get_the_author_meta('sw_twitter', sw_get_author($array['postID'])); if ($user_twitter_handle) { delete_post_meta($array['postID'], 'sw_twitter_username'); update_post_meta($array['postID'], 'sw_twitter_username', $user_twitter_handle); } else { delete_post_meta($array['postID'], 'sw_twitter_username'); } } else { $user_twitter_handle = get_post_meta($array['postID'], 'sw_twitter_username', true); } if ($user_twitter_handle) { $viaText = '&via=' . $user_twitter_handle; } elseif ($array['options']['twitterID']) { $viaText = '&via=' . $array['options']['twitterID']; } else { $viaText = ''; } $array['resource']['twitter'] = '<div class="nc_tweetContainer twitter" data-id="' . $array['count'] . '">'; $array['resource']['twitter'] .= '<a 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['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="sw_share"> ' . $array['language']['twitter'] . '</span>'; $array['resource']['twitter'] .= '</span></span>'; $array['resource']['twitter'] .= '<span class="sw_count">' . kilomega($array['shares']['twitter']) . '</span>'; } else { $array['resource']['twitter'] .= '<span class="sw_count sw_hide"><span class="iconFiller"><span class="spaceManWilly"><i class="sw sw-twitter"></i><span class="sw_share"> ' . $array['language']['twitter'] . '</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; }
function sw_add_header_meta() { $info['postID'] = get_the_ID(); // Cache some resource for fewer queries on subsequent page loads if (sw_is_cache_fresh($info['postID']) == false) { // Check if an image ID has been provided $info['imageID'] = get_post_meta($info['postID'], 'nc_ogImage', true); if ($info['imageID']) { $info['imageURL'] = wp_get_attachment_url($info['imageID']); delete_post_meta($info['postID'], 'sw_open_graph_image_url'); update_post_meta($info['postID'], 'sw_open_graph_image_url', $info['imageURL']); } else { $info['imageURL'] = wp_get_attachment_url(get_post_thumbnail_id($info['postID'])); delete_post_meta($info['postID'], 'sw_open_thumbnail_url'); update_post_meta($info['postID'], 'sw_open_thumbnail_url', $info['imageURL']); delete_post_meta($info['postID'], 'sw_open_graph_image_url'); } $user_twitter_handle = get_the_author_meta('sw_twitter', sw_get_author($info['postID'])); if ($user_twitter_handle) { delete_post_meta($info['postID'], 'sw_twitter_username'); update_post_meta($info['postID'], 'sw_twitter_username', $user_twitter_handle); } else { delete_post_meta($info['postID'], 'sw_twitter_username'); } } else { // Check if we have a cached Open Graph Image URL $info['imageURL'] = get_post_meta($info['postID'], 'sw_open_graph_image_url', true); // If not, let's check to see if we have an ID to generate one if (!$info['imageURL']) { // Check for an Open Graph Image ID $info['imageID'] = get_post_meta($info['postID'], 'nc_ogImage', true); if ($info['imageID']) { // If we find one, let's convert it to a link and cache it for next time $info['imageURL'] = wp_get_attachment_url($info['imageID']); delete_post_meta($info['postID'], 'sw_open_graph_image_url'); update_post_meta($info['postID'], 'sw_open_graph_image_url', $info['imageURL']); } else { // If we don't find one, let's save the URL of the thumbnail in case we need it $thumbnail_image = get_post_meta($info['postID'], 'sw_open_thumbnail_url', true); } } $user_twitter_handle = get_post_meta($info['postID'], 'sw_twitter_username', true); } // Create the image Open Graph Meta Tag $info['postID'] = get_the_ID(); $info['title'] = htmlspecialchars(get_post_meta($info['postID'], 'nc_ogTitle', true)); $info['description'] = htmlspecialchars(get_post_meta($info['postID'], 'nc_ogDescription', true)); $info['sw_user_options'] = sw_get_user_options(); $info['user_twitter_handle'] = $user_twitter_handle; $info['header_output'] = ''; $info = apply_filters('sw_meta_tags', $info); if ($info['header_output']) { echo PHP_EOL . '<!-- Open Graph Meta Tags & Twitter Card generated by Social Warfare v' . SW_VERSION . ' http://warfareplugins.com -->'; echo $info['header_output']; echo PHP_EOL . '<!-- Open Graph Meta Tags & Twitter Card generated by Social Warfare v' . SW_VERSION . ' http://warfareplugins.com -->' . PHP_EOL . PHP_EOL; } }