Exemplo n.º 1
0
function sw_email_button_html($array)
{
    if ($array['options']['email']) {
        // Collect the Title
        $title = SW_META_meta('nc_ogTitle');
        if (!$title) {
            $title = get_the_title();
        }
        // Collect the Description
        $description = SW_META_meta('nc_ogDescription');
        if (!$description) {
            $description = sw_get_excerpt_by_id($array['postID']);
        }
        $array['resource']['email'] = '<div class="nc_tweetContainer sw_email">';
        $link = urlencode(urldecode(sw_process_url($array['url'], 'email', $array['postID'])));
        $array['resource']['email'] .= '<a href="mailto:?subject=' . urlencode($title) . '&body=' . urlencode($description) . ' Read here: ' . $link . '" class="nc_tweet">';
        $array['resource']['email'] .= '<span class="sw_count sw_hide"><span class="iconFiller"><span class="spaceManWilly"><i class="sw sw-email"></i><span class="sw_share"> ' . $array['language']['email'] . '</span></span></span></span>';
        $array['resource']['email'] .= '</a>';
        $array['resource']['email'] .= '</div>';
        ++$array['count'];
    }
    return $array;
}
function sw_add_twitter_card($info)
{
    if (is_singular()) {
        // Check if Twitter Cards are Activated
        if ($info['sw_user_options']['sw_twitter_card']) {
            /*****************************************************************
             *                                                                *
             *     YOAST SEO: It rocks, so let's coordinate with it	         *
             *                                                                *
             ******************************************************************/
            // Check if Yoast Exists so we can coordinate output with their plugin accordingly
            if (defined('WPSEO_VERSION')) {
                // Collect their Social Descriptions as backups if they're not defined in ours
                $yoast_twitter_title = get_post_meta($info['postID'], '_yoast_wpseo_twitter-title', true);
                $yoast_twitter_description = get_post_meta($info['postID'], '_yoast_wpseo_twitter-description', true);
                $yoast_twitter_image = get_post_meta($info['postID'], '_yoast_wpseo_twitter-image', true);
                // Collect their SEO fields as 3rd string backups in case we need them
                $yoast_seo_title = get_post_meta($info['postID'], '_yoast_wpseo_title', true);
                $yoast_seo_description = get_post_meta($info['postID'], '_yoast_wpseo_metadesc', true);
                // Cancel their output if ours have been defined so we don't have two sets of tags
                remove_action('wpseo_head', array('WPSEO_Twitter', 'get_instance'), 40);
            }
            /*****************************************************************
             *                                                                *
             *     JET PACK: If ours are activated, disable theirs	         *
             *                                                                *
             ******************************************************************/
            if (class_exists('JetPack')) {
                add_filter('jetpack_disable_twitter_cards', '__return_true', 99);
            }
            /*****************************************************************
             *                                                                *
             *     TWITTER TITLE										         *
             *                                                                *
             ******************************************************************/
            // If the user defined a Social Media title, use it, otherwise check for Yoast's
            if (!$info['title'] && isset($yoast_twitter_title) && $yoast_twitter_title) {
                $info['title'] = $yoast_twitter_title;
                // If not title has been defined, let's check the SEO description as a 3rd string option
            } elseif (!$info['title'] && isset($yoast_seo_title) && $yoast_seo_title) {
                $info['title'] = $yoast_seo_title;
                // If not title has been defined, let's use the post title
            } elseif (!$info['title']) {
                $info['title'] = convert_smart_quotes(get_the_title());
            }
            /*****************************************************************
             *                                                                *
             *     TWITTER DESCRIPTION								         *
             *                                                                *
             ******************************************************************/
            // Open Graph Description
            if (!$info['description'] && isset($yoast_twitter_description) && $yoast_twitter_description) {
                $info['description'] = $yoast_twitter_description;
                // If not title has been defined, let's check the SEO description as a 3rd string option
            } elseif (!$info['description'] && isset($yoast_seo_description) && $yoast_seo_description) {
                $info['description'] = $yoast_seo_description;
                // If not, then let's use the excerpt
            } elseif (!$info['description']) {
                $info['description'] = htmlspecialchars(sw_get_excerpt_by_id($info['postID']));
            }
            /*****************************************************************
             *                                                                *
             *     TWITTER IMAGE								         *
             *                                                                *
             ******************************************************************/
            // Open Graph Description
            if (!$info['imageURL'] && isset($yoast_twitter_image) && $yoast_twitter_image) {
                $info['imageURL'] = $yoast_twitter_image;
            } else {
                // If nothing else is defined, let's use the post Thumbnail as long as we have the URL cached
                $twitter_image = get_post_meta($info['postID'], 'sw_open_thumbnail_url', true);
                if ($twitter_image) {
                    $info['imageURL'] = $twitter_image;
                }
            }
            /*****************************************************************
             *                                                                *
             *     PUT IT ALL TOGETHER						         		 *
             *                                                                *
             ******************************************************************/
            // Check if we have everything we need for a large image summary card
            if ($info['imageURL']) {
                $info['header_output'] .= PHP_EOL . '<meta name="twitter:card" content="summary_large_image">';
                $info['header_output'] .= PHP_EOL . '<meta name="twitter:title" content="' . $info['title'] . '">';
                $info['header_output'] .= PHP_EOL . '<meta name="twitter:description" content="' . $info['description'] . '">';
                $info['header_output'] .= PHP_EOL . '<meta name="twitter:image" content="' . $info['imageURL'] . '">';
                if ($info['sw_user_options']['twitterID']) {
                    $info['header_output'] .= PHP_EOL . '<meta name="twitter:site" content="@' . $info['sw_user_options']['twitterID'] . '">';
                }
                if ($info['user_twitter_handle']) {
                    $info['header_output'] .= PHP_EOL . '<meta name="twitter:creator" content="@' . str_replace('@', '', $info['user_twitter_handle']) . '">';
                }
                // Otherwise create a small summary card
            } else {
                $info['header_output'] .= PHP_EOL . '<meta name="twitter:card" content="summary">';
                $info['header_output'] .= PHP_EOL . '<meta name="twitter:title" content="' . str_replace('"', '\'', $info['title']) . '">';
                $info['header_output'] .= PHP_EOL . '<meta name="twitter:description" content="' . str_replace('"', '\'', $info['description']) . '">';
                if ($info['sw_user_options']['twitterID']) {
                    $info['header_output'] .= PHP_EOL . '<meta name="twitter:site" content="@' . $info['sw_user_options']['twitterID'] . '">';
                }
                if ($info['user_twitter_handle']) {
                    $info['header_output'] .= PHP_EOL . '<meta name="twitter:creator" content="@' . str_replace('@', '', $info['user_twitter_handle']) . '">';
                }
            }
        }
    }
    return $info;
}