/**
  * @covers WPSEO_Meta::get_value()
  */
 public function test_get_value()
 {
     // create and go to post
     $post_id = $this->factory->post->create();
     $this->go_to(get_permalink($post_id));
     update_post_meta($post_id, WPSEO_Meta::$meta_prefix . 'test_get_value_key', 'test_get_value_value');
     $this->assertEquals('test_get_value_value', WPSEO_Meta::get_value('test_get_value_key'));
     // TODO test for defaults
     // TODO test if non-existing keys return an empty string
 }
 /**
  * Helper function to check if the metabox functionality should be loaded
  *
  * @return bool
  */
 public function has_video()
 {
     if (isset($GLOBALS['post']->ID)) {
         $video = WPSEO_Meta::get_value('video_meta', $GLOBALS['post']->ID);
         if (is_array($video) && $video !== array()) {
             return true;
         }
     }
     return false;
 }
 /**
  * Output the Google+ specific description
  */
 public function description()
 {
     if (is_singular()) {
         $desc = WPSEO_Meta::get_value('google-plus-description');
         /**
          * Filter: 'wpseo_googleplus_desc' - Allow developers to change the Google+ specific description output
          *
          * @api string $desc The description string
          */
         $desc = apply_filters('wpseo_googleplus_desc', $desc);
         if (is_string($desc) && '' !== $desc) {
             echo '<meta itemprop="description" content="' . $desc . '">' . "\n";
         }
     }
 }
示例#4
0
/**
 * Display post description for Open Graph and Twitter card
 * 
 * @return string A description text of post
 *
 * @todo Sanitize $excerpt http://codex.wordpress.org/Function_Reference/sanitize_text_field
 */
function italystrap_open_graph_desc()
{
    global $post;
    if (function_exists('aioseop_load_modules')) {
        $excerpt = get_post_meta($post->ID, '_aioseop_description', true);
    } else {
        if (class_exists('WPSEO_Meta')) {
            $excerpt = WPSEO_Meta::get_value('metadesc');
        } else {
            if ($post->post_excerpt) {
                $excerpt = trim(str_replace(array("\n", "\r", "\t"), ' ', substr(strip_tags($post->post_excerpt), 0, 200)));
            } else {
                $excerpt = trim(str_replace(array("\n", "\r", "\t", "[", "]", "\""), ' ', substr(strip_tags($post->post_content), 0, 200))) . ' ...';
            }
        }
    }
    echo $excerpt;
}
 /**
  * Hooked into transition_post_status. Will initiate search engine pings
  * if the post is being published, is a post type that a sitemap is built for
  * and is a post that is included in sitemaps.
  */
 function status_transition($new_status, $old_status, $post)
 {
     if ($new_status != 'publish') {
         return;
     }
     wp_cache_delete('lastpostmodified:gmt:' . $post->post_type, 'timeinfo');
     // #17455
     $options = WPSEO_Options::get_all();
     if (isset($options['post_types-' . $post->post_type . '-not_in_sitemap']) && $options['post_types-' . $post->post_type . '-not_in_sitemap'] === true) {
         return;
     }
     if (WP_CACHE) {
         wp_schedule_single_event(time() + 300, 'wpseo_hit_sitemap_index');
     }
     // Allow the pinging to happen slightly after the hit sitemap index so the sitemap is fully regenerated when the ping happens.
     if (WPSEO_Meta::get_value('sitemap-include', $post->ID) !== 'never') {
         if (defined('YOAST_SEO_PING_IMMEDIATELY') && YOAST_SEO_PING_IMMEDIATELY) {
             wpseo_ping_search_engines();
         } else {
             wp_schedule_single_event(time() + 300, 'wpseo_ping_search_engines');
         }
     }
 }
示例#6
0
 /**
  * Build a sub-sitemap for a specific post type -- example.com/post_type-sitemap.xml
  *
  * @param string $post_type Registered post type's slug
  */
 function build_post_type_map($post_type)
 {
     global $wpdb;
     if (isset($this->options['post_types-' . $post_type . '-not_in_sitemap']) && $this->options['post_types-' . $post_type . '-not_in_sitemap'] === true || in_array($post_type, array('revision', 'nav_menu_item')) || apply_filters('wpseo_sitemap_exclude_post_type', false, $post_type)) {
         $this->bad_sitemap = true;
         return;
     }
     $output = '';
     $steps = 25 > $this->max_entries ? $this->max_entries : 25;
     $n = (int) $this->n;
     $offset = $n > 1 ? ($n - 1) * $this->max_entries : 0;
     $total = $offset + $this->max_entries;
     $join_filter = '';
     $join_filter = apply_filters('wpseo_typecount_join', $join_filter, $post_type);
     $where_filter = '';
     $where_filter = apply_filters('wpseo_typecount_where', $where_filter, $post_type);
     $query = $wpdb->prepare("SELECT COUNT(ID) FROM {$wpdb->posts} {$join_filter} WHERE post_status IN ('publish','inherit') AND post_password = '' AND post_type = %s " . $where_filter, $post_type);
     $typecount = $wpdb->get_var($query);
     if ($total > $typecount) {
         $total = $typecount;
     }
     if ($n == 1) {
         $front_id = get_option('page_on_front');
         if (!$front_id && ($post_type == 'post' || $post_type == 'page')) {
             $output .= $this->sitemap_url(array('loc' => $this->home_url, 'pri' => 1, 'chf' => $this->filter_frequency('homepage', 'daily', $this->home_url)));
         } else {
             if ($front_id && $post_type == 'post') {
                 $page_for_posts = get_option('page_for_posts');
                 if ($page_for_posts) {
                     $page_for_posts_url = get_permalink($page_for_posts);
                     $output .= $this->sitemap_url(array('loc' => $page_for_posts_url, 'pri' => 1, 'chf' => $change_freq = $this->filter_frequency('blogpage', 'daily', $page_for_posts_url)));
                 }
             }
         }
         $archive = get_post_type_archive_link($post_type);
         if ($archive) {
             $output .= $this->sitemap_url(array('loc' => $archive, 'pri' => 0.8, 'chf' => $this->filter_frequency($post_type . '_archive', 'weekly', $archive), 'mod' => $this->get_last_modified($post_type)));
         }
     }
     if ($typecount == 0 && empty($archive)) {
         $this->bad_sitemap = true;
         return;
     }
     $stackedurls = array();
     // Make sure you're wpdb->preparing everything you throw into this!!
     $join_filter = apply_filters('wpseo_posts_join', false, $post_type);
     $where_filter = apply_filters('wpseo_posts_where', false, $post_type);
     $status = $post_type == 'attachment' ? 'inherit' : 'publish';
     /**
      * We grab post_date, post_name, post_author and post_status too so we can throw these objects
      * into get_permalink, which saves a get_post call for each permalink.
      */
     while ($total > $offset) {
         // Optimized query per this thread: http://wordpress.org/support/topic/plugin-wordpress-seo-by-yoast-performance-suggestion
         // Also see http://explainextended.com/2009/10/23/mysql-order-by-limit-performance-late-row-lookups/
         $query = $wpdb->prepare("\n\t\t\t\t\tSELECT l.ID, post_content, post_name, post_author, post_parent, post_modified_gmt,\n\t\t\t\t\t\tpost_date, post_date_gmt\n\t\t\t\t\tFROM (\n\t\t\t\t\t\tSELECT ID FROM {$wpdb->posts} {$join_filter}\n\t\t\t\t\t\t\tWHERE post_status = '%s'\n\t\t\t\t\t\t\tAND\tpost_password = ''\n\t\t\t\t\t\t\tAND post_type = '%s'\n\t\t\t\t\t\t\t{$where_filter}\n\t\t\t\t\t\t\tORDER BY post_modified ASC\n\t\t\t\t\t\t\tLIMIT %d OFFSET %d ) o\n\t\t\t\t\t\tJOIN {$wpdb->posts} l\n\t\t\t\t\t\tON l.ID = o.ID\n\t\t\t\t\t\tORDER BY l.ID\n\t\t\t\t\t", $status, $post_type, $steps, $offset);
         $posts = $wpdb->get_results($query);
         $offset = $offset + $steps;
         if (is_array($posts) && $posts !== array()) {
             foreach ($posts as $p) {
                 $p->post_type = $post_type;
                 $p->post_status = 'publish';
                 $p->filter = 'sample';
                 if (WPSEO_Meta::get_value('meta-robots-noindex', $p->ID) === '1' && WPSEO_Meta::get_value('sitemap-include', $p->ID) !== 'always') {
                     continue;
                 }
                 if (WPSEO_Meta::get_value('sitemap-include', $p->ID) === 'never') {
                     continue;
                 }
                 if (WPSEO_Meta::get_value('redirect', $p->ID) !== '') {
                     continue;
                 }
                 $url = array();
                 $url['mod'] = isset($p->post_modified_gmt) && $p->post_modified_gmt != '0000-00-00 00:00:00' && $p->post_modified_gmt > $p->post_date_gmt ? $p->post_modified_gmt : $p->post_date_gmt;
                 $url['loc'] = get_permalink($p);
                 /**
                  * Filter: 'wpseo_xml_sitemap_post_url' - Allow changing the URL WordPress SEO uses in the XML sitemap.
                  *
                  * Note that only absolute local URLs are allowed as the check after this removes external URLs.
                  *
                  * @api string $url URL to use in the XML sitemap
                  *
                  * @param object $p Post object for the URL
                  */
                 $url['loc'] = apply_filters('wpseo_xml_sitemap_post_url', $url['loc'], $p);
                 $url['chf'] = $this->filter_frequency($post_type . '_single', 'weekly', $url['loc']);
                 /**
                  * Do not include external URLs.
                  * @see https://wordpress.org/plugins/page-links-to/ can rewrite permalinks to external URLs.
                  */
                 if (false === strpos($url['loc'], $this->home_url)) {
                     continue;
                 }
                 $canonical = WPSEO_Meta::get_value('canonical', $p->ID);
                 if ($canonical !== '' && $canonical !== $url['loc']) {
                     /* Let's assume that if a canonical is set for this page and it's different from
                        the URL of this post, that page is either already in the XML sitemap OR is on
                        an external site, either way, we shouldn't include it here. */
                     continue;
                 } else {
                     if ($this->options['trailingslash'] === true && $p->post_type != 'post') {
                         $url['loc'] = trailingslashit($url['loc']);
                     }
                 }
                 $pri = WPSEO_Meta::get_value('sitemap-prio', $p->ID);
                 if (is_numeric($pri)) {
                     $url['pri'] = (double) $pri;
                 } else {
                     if ($p->post_parent == 0 && $p->post_type == 'page') {
                         $url['pri'] = 0.8;
                     } else {
                         $url['pri'] = 0.6;
                     }
                 }
                 if (isset($front_id) && $p->ID == $front_id) {
                     $url['pri'] = 1.0;
                 }
                 $url['images'] = array();
                 $content = $p->post_content;
                 $content = '<p>' . get_the_post_thumbnail($p->ID, 'full') . '</p>' . $content;
                 $host = str_replace('www.', '', parse_url(get_bloginfo('url'), PHP_URL_HOST));
                 if (preg_match_all('`<img [^>]+>`', $content, $matches)) {
                     foreach ($matches[0] as $img) {
                         if (preg_match('`src=["\']([^"\']+)["\']`', $img, $match)) {
                             $src = $match[1];
                             if (strpos($src, 'http') !== 0) {
                                 if ($src[0] != '/') {
                                     continue;
                                 }
                                 $src = get_bloginfo('url') . $src;
                             }
                             if (strpos($src, $host) === false) {
                                 continue;
                             }
                             if ($src != esc_url($src)) {
                                 continue;
                             }
                             if (isset($url['images'][$src])) {
                                 continue;
                             }
                             $image = array('src' => apply_filters('wpseo_xml_sitemap_img_src', $src, $p));
                             if (preg_match('`title=["\']([^"\']+)["\']`', $img, $match)) {
                                 $image['title'] = str_replace(array('-', '_'), ' ', $match[1]);
                             }
                             if (preg_match('`alt=["\']([^"\']+)["\']`', $img, $match)) {
                                 $image['alt'] = str_replace(array('-', '_'), ' ', $match[1]);
                             }
                             $image = apply_filters('wpseo_xml_sitemap_img', $image, $p);
                             $url['images'][] = $image;
                         }
                     }
                 }
                 if (strpos($p->post_content, '[gallery') !== false) {
                     $attachments = get_children(array('post_parent' => $p->ID, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image'));
                     if (is_array($attachments) && $attachments !== array()) {
                         foreach ($attachments as $att_id => $attachment) {
                             $src = wp_get_attachment_image_src($att_id, 'large', false);
                             $image = array('src' => apply_filters('wpseo_xml_sitemap_img_src', $src[0], $p));
                             $alt = get_post_meta($att_id, '_wp_attachment_image_alt', true);
                             if ($alt !== '') {
                                 $image['alt'] = $alt;
                             }
                             unset($alt);
                             $image['title'] = $attachment->post_title;
                             $image = apply_filters('wpseo_xml_sitemap_img', $image, $p);
                             $url['images'][] = $image;
                         }
                     }
                     unset($attachments, $att_id, $attachment, $src, $image, $alt);
                 }
                 $url['images'] = apply_filters('wpseo_sitemap_urlimages', $url['images'], $p->ID);
                 if (!in_array($url['loc'], $stackedurls)) {
                     // Use this filter to adjust the entry before it gets added to the sitemap
                     $url = apply_filters('wpseo_sitemap_entry', $url, 'post', $p);
                     if (is_array($url) && $url !== array()) {
                         $output .= $this->sitemap_url($url);
                         $stackedurls[] = $url['loc'];
                     }
                 }
                 // Clear the post_meta and the term cache for the post, as we no longer need it now.
                 // wp_cache_delete( $p->ID, 'post_meta' );
                 // clean_object_term_cache( $p->ID, $post_type );
             }
         }
     }
     if (empty($output)) {
         $this->bad_sitemap = true;
         return;
     }
     $this->sitemap = '<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" ';
     $this->sitemap .= 'xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd" ';
     $this->sitemap .= 'xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' . "\n";
     $this->sitemap .= $output;
     // Filter to allow adding extra URLs, only do this on the first XML sitemap, not on all.
     if ($n == 0) {
         $this->sitemap .= apply_filters('wpseo_sitemap_' . $post_type . '_content', '');
     }
     $this->sitemap .= '</urlset>';
 }
 /**
  * Displays the image for Twitter
  *
  * Only used when OpenGraph is inactive or Summary Large Image card is chosen.
  */
 public function image()
 {
     global $post;
     if (is_singular()) {
         if (is_front_page()) {
             if ($this->options['og_frontpage_image'] !== '') {
                 $this->image_output($this->options['og_frontpage_image']);
             }
         }
         $twitter_img = WPSEO_Meta::get_value('twitter-image');
         if ($twitter_img !== '') {
             $this->image_output($twitter_img);
             return;
         } elseif (function_exists('has_post_thumbnail') && has_post_thumbnail($post->ID)) {
             /**
              * Filter: 'wpseo_twitter_image_size' - Allow changing the Twitter Card image size
              *
              * @api string $featured_img Image size string
              */
             $featured_img = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), apply_filters('wpseo_twitter_image_size', 'full'));
             if ($featured_img) {
                 $this->image_output($featured_img[0]);
             }
         } elseif (preg_match_all('`<img [^>]+>`', $post->post_content, $matches)) {
             foreach ($matches[0] as $img) {
                 if (preg_match('`src=(["\'])(.*?)\\1`', $img, $match)) {
                     $this->image_output($match[2]);
                 }
             }
         }
     }
     if (count($this->shown_images) == 0 && $this->options['og_default_image'] !== '') {
         $this->image_output($this->options['og_default_image']);
     }
 }
示例#8
0
bloginfo('template_directory');
?>
/favicon/apple-touch-icon-72x72.png">
	<link rel="apple-touch-icon" sizes="114x114" href="<?php 
bloginfo('template_directory');
?>
/favicon/apple-touch-icon-114x114.png">
	
	<!-- Facebook open graph tags -->
	<meta property="og:title" content="<?php 
the_title();
?>
"/>
	<meta property="og:description" content="<?php 
if (function_exists('WPSEO_Meta::get_value()')) {
    echo WPSEO_Meta::get_value('metadesc');
} else {
    echo $post->post_excerpt;
}
?>
"/>

	<?php 
if (have_posts()) {
    while (have_posts()) {
        the_post();
    }
}
?>
		<meta property="fb:app_id" content="496408310403833" />
	<?php 
 function etm_wpseo_replace_vars($string, $args, $omit = array())
 {
     $args = (array) $args;
     $string = strip_tags($string);
     // Let's see if we can bail super early.
     if (strpos($string, '%%') === false) {
         return trim(preg_replace('`\\s+`u', ' ', $string));
     }
     global $sep;
     if (!isset($sep) || empty($sep)) {
         $sep = '-';
     }
     $simple_replacements = array('%%sep%%' => $sep, '%%sitename%%' => get_bloginfo('name'), '%%sitedesc%%' => get_bloginfo('description'), '%%currenttime%%' => date(get_option('time_format')), '%%currentdate%%' => date(get_option('date_format')), '%%currentday%%' => date('j'), '%%currentmonth%%' => date('F'), '%%currentyear%%' => date('Y'));
     foreach ($simple_replacements as $var => $repl) {
         $string = str_replace($var, $repl, $string);
     }
     // Let's see if we can bail early.
     if (strpos($string, '%%') === false) {
         return trim(preg_replace('`\\s+`u', ' ', $string));
     }
     global $wp_query;
     $defaults = array('ID' => '', 'name' => '', 'post_author' => '', 'post_content' => '', 'post_date' => '', 'post_excerpt' => '', 'post_modified' => '', 'post_title' => '', 'taxonomy' => '', 'term_id' => '', 'term404' => '');
     if (isset($args['post_content'])) {
         $args['post_content'] = wpseo_strip_shortcode($args['post_content']);
     }
     if (isset($args['post_excerpt'])) {
         $args['post_excerpt'] = wpseo_strip_shortcode($args['post_excerpt']);
     }
     $r = (object) wp_parse_args($args, $defaults);
     $max_num_pages = 1;
     if (!is_singular()) {
         $pagenum = get_query_var('paged');
         if ($pagenum === 0) {
             $pagenum = 1;
         }
         if (isset($wp_query->max_num_pages) && $wp_query->max_num_pages != '' && $wp_query->max_num_pages != 0) {
             $max_num_pages = $wp_query->max_num_pages;
         }
     } else {
         global $post;
         $pagenum = get_query_var('page');
         $max_num_pages = isset($post->post_content) ? substr_count($post->post_content, '<!--nextpage-->') : 1;
         if ($max_num_pages >= 1) {
             $max_num_pages++;
         }
     }
     // Let's do date first as it's a bit more work to get right.
     if ($r->post_date != '') {
         $date = mysql2date(get_option('date_format'), $r->post_date);
     } else {
         if (get_query_var('day') && get_query_var('day') != '') {
             $date = get_the_date();
         } else {
             if (single_month_title(' ', false) && single_month_title(' ', false) != '') {
                 $date = single_month_title(' ', false);
             } elseif (get_query_var('year') != '') {
                 $date = get_query_var('year');
             } else {
                 $date = '';
             }
         }
     }
     $replacements = array('%%date%%' => $date, '%%searchphrase%%' => esc_html(get_query_var('s')), '%%page%%' => $max_num_pages > 1 && $pagenum > 1 ? sprintf($sep . ' ' . __('Page %d of %d', 'wordpress-seo'), $pagenum, $max_num_pages) : '', '%%pagetotal%%' => $max_num_pages, '%%pagenumber%%' => $pagenum, '%%term404%%' => sanitize_text_field(str_replace('-', ' ', $r->term404)));
     if (isset($r->ID)) {
         $translatede_title = get_post_meta($r->ID, 'ect_tran_title_' . $this->selectede_lang, true);
         if (empty($translatede_title)) {
             $translatede_title = $r->post_title;
         }
         $replacements = array_merge($replacements, array('%%caption%%' => $r->post_excerpt, '%%category%%' => wpseo_get_terms($r->ID, 'category'), '%%excerpt%%' => !empty($r->post_excerpt) ? strip_tags($r->post_excerpt) : wp_html_excerpt(strip_shortcodes($r->post_content), 155), '%%excerpt_only%%' => strip_tags($r->post_excerpt), '%%focuskw%%' => WPSEO_Meta::get_value('focuskw', $r->ID), '%%id%%' => $r->ID, '%%modified%%' => mysql2date(get_option('date_format'), $r->post_modified), '%%name%%' => get_the_author_meta('display_name', !empty($r->post_author) ? $r->post_author : get_query_var('author')), '%%tag%%' => wpseo_get_terms($r->ID, 'post_tag'), '%%title%%' => stripslashes($translatede_title), '%%userid%%' => !empty($r->post_author) ? $r->post_author : get_query_var('author')));
     }
     if (!empty($r->taxonomy)) {
         $replacements = array_merge($replacements, array('%%category_description%%' => trim(strip_tags(get_term_field('description', $r->term_id, $r->taxonomy))), '%%tag_description%%' => trim(strip_tags(get_term_field('description', $r->term_id, $r->taxonomy))), '%%term_description%%' => trim(strip_tags(get_term_field('description', $r->term_id, $r->taxonomy))), '%%term_title%%' => $r->name));
     }
     /**
      * Filter: 'wpseo_replacements' - Allow customization of the replacements before they are applied
      *
      * @api array $replacements The replacements
      */
     $replacements = apply_filters("wpseo_replacements", $replacements);
     foreach ($replacements as $var => $repl) {
         if (!in_array($var, $omit)) {
             $string = str_replace($var, $repl, $string);
         }
     }
     if (strpos($string, '%%') === false) {
         $string = preg_replace('`\\s+`u', ' ', $string);
         return trim($string);
     }
     if (isset($wp_query->query_vars['post_type']) && preg_match_all('`%%pt_([^%]+)%%`u', $string, $matches, PREG_SET_ORDER)) {
         $pt = get_post_type_object($wp_query->query_vars['post_type']);
         $pt_plural = $pt_singular = $pt->name;
         if (isset($pt->labels->singular_name)) {
             $pt_singular = $pt->labels->singular_name;
         }
         if (isset($pt->labels->name)) {
             $pt_plural = $pt->labels->name;
         }
         $string = str_replace('%%pt_single%%', $pt_singular, $string);
         $string = str_replace('%%pt_plural%%', $pt_plural, $string);
     }
     if (is_singular() && preg_match_all('`%%cf_([^%]+)%%`u', $string, $matches, PREG_SET_ORDER)) {
         global $post;
         foreach ($matches as $match) {
             $string = str_replace($match[0], get_post_meta($post->ID, $match[1], true), $string);
         }
     }
     if (preg_match_all('`%%ct_desc_([^%]+)?%%`u', $string, $matches, PREG_SET_ORDER)) {
         global $post;
         foreach ($matches as $match) {
             $terms = get_the_terms($post->ID, $match[1]);
             if (is_array($terms) && $terms !== array()) {
                 $term = current($terms);
                 $string = str_replace($match[0], get_term_field('description', $term->term_id, $match[1]), $string);
             } else {
                 // Make sure that the variable is removed ?
                 $string = str_replace($match[0], '', $string);
                 /* Check for WP_Error object (=invalid taxonomy entered) and if it's an error,
                 		 notify in admin dashboard */
                 if (is_wp_error($terms) && is_admin()) {
                     add_action('admin_notices', 'wpseo_invalid_custom_taxonomy');
                 }
             }
         }
     }
     if (preg_match_all('`%%ct_([^%]+)%%(single%%)?`u', $string, $matches, PREG_SET_ORDER)) {
         foreach ($matches as $match) {
             $single = false;
             if (isset($match[2]) && $match[2] == 'single%%') {
                 $single = true;
             }
             $ct_terms = wpseo_get_terms($r->ID, $match[1], $single);
             $string = str_replace($match[0], $ct_terms, $string);
         }
     }
     $string = preg_replace('`\\s+`u', ' ', $string);
     return trim($string);
 }
/**
 * Returns the content score element for the adminbar.
 *
 * @return string
 */
function wpseo_adminbar_content_score()
{
    $rating = WPSEO_Meta::get_value('content_score', get_the_ID());
    return wpseo_adminbar_score($rating);
}
示例#11
0
 /**
  * Counting the number of given keyword used for other posts than given post_id
  *
  * @return array
  */
 private function get_focus_keyword_usage()
 {
     $post = $this->get_metabox_post();
     if (is_object($post)) {
         $keyword = WPSEO_Meta::get_value('focuskw', $post->ID);
         return array($keyword => WPSEO_Meta::keyword_usage($keyword, $post->ID));
     }
     return array();
 }
/**
 * Adds an SEO admin bar menu with several options. If the current user is an admin he can also go straight to several settings menu's from here.
 */
function wpseo_admin_bar_menu()
{
    // If the current user can't write posts, this is all of no use, so let's not output an admin menu.
    if (!current_user_can('edit_posts')) {
        return;
    }
    global $wp_admin_bar, $post;
    $focuskw = '';
    $score = '';
    $seo_url = get_admin_url(null, 'admin.php?page=wpseo_dashboard');
    if ((is_singular() || is_admin() && in_array($GLOBALS['pagenow'], array('post.php', 'post-new.php'), true)) && isset($post) && is_object($post) && apply_filters('wpseo_use_page_analysis', true) === true) {
        $focuskw = WPSEO_Meta::get_value('focuskw', $post->ID);
        $perc_score = WPSEO_Meta::get_value('linkdex', $post->ID);
        $txtscore = WPSEO_Utils::translate_score($perc_score);
        $title = WPSEO_Utils::translate_score($perc_score, false);
        $score = '<div title="' . esc_attr($title) . '" class="' . esc_attr('wpseo-score-icon ' . $txtscore . ' ' . $perc_score) . ' adminbar-seo-score' . '"></div>';
        $seo_url = get_edit_post_link($post->ID);
    }
    $wp_admin_bar->add_menu(array('id' => 'wpseo-menu', 'title' => __('SEO', 'wordpress-seo') . $score, 'href' => $seo_url));
    $wp_admin_bar->add_menu(array('parent' => 'wpseo-menu', 'id' => 'wpseo-kwresearch', 'title' => __('Keyword Research', 'wordpress-seo'), '#'));
    $wp_admin_bar->add_menu(array('parent' => 'wpseo-kwresearch', 'id' => 'wpseo-adwordsexternal', 'title' => __('AdWords External', 'wordpress-seo'), 'href' => 'http://adwords.google.com/keywordplanner', 'meta' => array('target' => '_blank')));
    $wp_admin_bar->add_menu(array('parent' => 'wpseo-kwresearch', 'id' => 'wpseo-googleinsights', 'title' => __('Google Insights', 'wordpress-seo'), 'href' => 'http://www.google.com/insights/search/#q=' . urlencode($focuskw) . '&cmpt=q', 'meta' => array('target' => '_blank')));
    $wp_admin_bar->add_menu(array('parent' => 'wpseo-kwresearch', 'id' => 'wpseo-wordtracker', 'title' => __('SEO Book', 'wordpress-seo'), 'href' => 'http://tools.seobook.com/keyword-tools/seobook/?keyword=' . urlencode($focuskw), 'meta' => array('target' => '_blank')));
    if (!is_admin()) {
        $url = WPSEO_Frontend::get_instance()->canonical(false);
        if (is_string($url)) {
            $wp_admin_bar->add_menu(array('parent' => 'wpseo-menu', 'id' => 'wpseo-analysis', 'title' => __('Analyze this page', 'wordpress-seo'), '#'));
            $wp_admin_bar->add_menu(array('parent' => 'wpseo-analysis', 'id' => 'wpseo-inlinks-ose', 'title' => __('Check Inlinks (OSE)', 'wordpress-seo'), 'href' => '//moz.com/researchtools/ose/links?site=' . urlencode($url), 'meta' => array('target' => '_blank')));
            $wp_admin_bar->add_menu(array('parent' => 'wpseo-analysis', 'id' => 'wpseo-kwdensity', 'title' => __('Check Keyword Density', 'wordpress-seo'), 'href' => '//www.zippy.co.uk/keyworddensity/index.php?url=' . urlencode($url) . '&keyword=' . urlencode($focuskw), 'meta' => array('target' => '_blank')));
            $wp_admin_bar->add_menu(array('parent' => 'wpseo-analysis', 'id' => 'wpseo-cache', 'title' => __('Check Google Cache', 'wordpress-seo'), 'href' => '//webcache.googleusercontent.com/search?strip=1&q=cache:' . urlencode($url), 'meta' => array('target' => '_blank')));
            $wp_admin_bar->add_menu(array('parent' => 'wpseo-analysis', 'id' => 'wpseo-header', 'title' => __('Check Headers', 'wordpress-seo'), 'href' => '//quixapp.com/headers/?r=' . urlencode($url), 'meta' => array('target' => '_blank')));
            $wp_admin_bar->add_menu(array('parent' => 'wpseo-analysis', 'id' => 'wpseo-richsnippets', 'title' => __('Check Rich Snippets', 'wordpress-seo'), 'href' => '//www.google.com/webmasters/tools/richsnippets?q=' . urlencode($url), 'meta' => array('target' => '_blank')));
            $wp_admin_bar->add_menu(array('parent' => 'wpseo-analysis', 'id' => 'wpseo-facebookdebug', 'title' => __('Facebook Debugger', 'wordpress-seo'), 'href' => '//developers.facebook.com/tools/debug/og/object?q=' . urlencode($url), 'meta' => array('target' => '_blank')));
            $wp_admin_bar->add_menu(array('parent' => 'wpseo-analysis', 'id' => 'wpseo-pinterestvalidator', 'title' => __('Pinterest Rich Pins Validator', 'wordpress-seo'), 'href' => '//developers.pinterest.com/rich_pins/validator/?link=' . urlencode($url), 'meta' => array('target' => '_blank')));
            $wp_admin_bar->add_menu(array('parent' => 'wpseo-analysis', 'id' => 'wpseo-htmlvalidation', 'title' => __('HTML Validator', 'wordpress-seo'), 'href' => '//validator.w3.org/check?uri=' . urlencode($url), 'meta' => array('target' => '_blank')));
            $wp_admin_bar->add_menu(array('parent' => 'wpseo-analysis', 'id' => 'wpseo-cssvalidation', 'title' => __('CSS Validator', 'wordpress-seo'), 'href' => '//jigsaw.w3.org/css-validator/validator?uri=' . urlencode($url), 'meta' => array('target' => '_blank')));
            $wp_admin_bar->add_menu(array('parent' => 'wpseo-analysis', 'id' => 'wpseo-pagespeed', 'title' => __('Google Page Speed Test', 'wordpress-seo'), 'href' => '//developers.google.com/speed/pagespeed/insights/?url=' . urlencode($url), 'meta' => array('target' => '_blank')));
            $wp_admin_bar->add_menu(array('parent' => 'wpseo-analysis', 'id' => 'wpseo-modernie', 'title' => __('Modern IE Site Scan', 'wordpress-seo'), 'href' => '//www.modern.ie/en-us/report#' . urlencode($url), 'meta' => array('target' => '_blank')));
            $wp_admin_bar->add_menu(array('parent' => 'wpseo-analysis', 'id' => 'wpseo-google-mobile-friendly', 'title' => __('Mobile-Friendly Test', 'wordpress-seo'), 'href' => 'https://www.google.com/webmasters/tools/mobile-friendly/?url=' . urlencode($url), 'meta' => array('target' => '_blank')));
        }
    }
    $admin_menu = current_user_can('manage_options');
    if (!$admin_menu && is_multisite()) {
        $options = get_site_option('wpseo_ms');
        $admin_menu = $options['access'] === 'superadmin' && is_super_admin();
    }
    // @todo: add links to bulk title and bulk description edit pages.
    if ($admin_menu) {
        $wp_admin_bar->add_menu(array('parent' => 'wpseo-menu', 'id' => 'wpseo-settings', 'title' => __('SEO Settings', 'wordpress-seo')));
        $wp_admin_bar->add_menu(array('parent' => 'wpseo-settings', 'id' => 'wpseo-general', 'title' => __('General', 'wordpress-seo'), 'href' => admin_url('admin.php?page=wpseo_dashboard')));
        $wp_admin_bar->add_menu(array('parent' => 'wpseo-settings', 'id' => 'wpseo-titles', 'title' => __('Titles &amp; Metas', 'wordpress-seo'), 'href' => admin_url('admin.php?page=wpseo_titles')));
        $wp_admin_bar->add_menu(array('parent' => 'wpseo-settings', 'id' => 'wpseo-social', 'title' => __('Social', 'wordpress-seo'), 'href' => admin_url('admin.php?page=wpseo_social')));
        $wp_admin_bar->add_menu(array('parent' => 'wpseo-settings', 'id' => 'wpseo-xml', 'title' => __('XML Sitemaps', 'wordpress-seo'), 'href' => admin_url('admin.php?page=wpseo_xml')));
        $wp_admin_bar->add_menu(array('parent' => 'wpseo-settings', 'id' => 'wpseo-wpseo-advanced', 'title' => __('Advanced', 'wordpress-seo'), 'href' => admin_url('admin.php?page=wpseo_advanced')));
        $wp_admin_bar->add_menu(array('parent' => 'wpseo-settings', 'id' => 'wpseo-tools', 'title' => __('Tools', 'wordpress-seo'), 'href' => admin_url('admin.php?page=wpseo_tools')));
        $wp_admin_bar->add_menu(array('parent' => 'wpseo-settings', 'id' => 'wpseo-search-console', 'title' => __('Search Console', 'wordpress-seo'), 'href' => admin_url('admin.php?page=wpseo_search_console')));
        $wp_admin_bar->add_menu(array('parent' => 'wpseo-settings', 'id' => 'wpseo-licenses', 'title' => '<span style="color:#f18500">' . __('Extensions', 'wordpress-seo') . '</span>', 'href' => admin_url('admin.php?page=wpseo_licenses')));
    }
}
 /**
  * Getting the keywords
  *
  * @param WP_Post $post The post object with the values.
  *
  * @return string
  */
 private function get_keywords($post)
 {
     $keywords = WPSEO_Meta::get_value('metakeywords', $post->ID);
     $option_meta_key = 'metakey-' . $post->post_type;
     if ($keywords === '' && (is_object($post) && (isset($this->options[$option_meta_key]) && $this->options[$option_meta_key] !== ''))) {
         $keywords = wpseo_replace_vars($this->options[$option_meta_key], $post);
     }
     return $keywords;
 }
 /**
  * Calculate the page analysis results for post.
  *
  * @internal Unfortunately there isn't a filter available to hook into before returning the results
  * for get_post_meta(), get_post_custom() and the likes. That would have been the preferred solution.
  *
  * @see function calculate_results() in wordpress-seo\admin\class-metabox.php
  * @scope admin
  * @since 1.2.2
  *
  * @param array $results
  * @param string $post_content
  * @param array $job, 
  * @param WP_Post object $post Post to calculate the results for.
  *
  * @return  array
  */
 public static function calculate_results($results, $post_content, $job, $post)
 {
     $WPSEO_Metabox = new WPSEO_Metabox();
     $dom = new domDocument();
     $dom->strictErrorChecking = false;
     $dom->preserveWhiteSpace = false;
     // Check if the post content is not empty.
     if (!empty($post_content)) {
         @$dom->loadHTML($post_content);
     }
     unset($post_content);
     $xpath = new DOMXPath($dom);
     // Check if this focus keyword has been used already.
     $WPSEO_Metabox->check_double_focus_keyword($job, $results);
     // Keyword.
     $WPSEO_Metabox->score_keyword($job['keyword'], $results);
     // Title.
     $title = WPSEO_Meta::get_value('title', $post->ID);
     if ($title !== '') {
         $job['title'] = $title;
     } else {
         if (isset($options['title-' . $post->post_type]) && $options['title-' . $post->post_type] !== '') {
             $title_template = $options['title-' . $post->post_type];
         } else {
             $title_template = '%%title%% - %%sitename%%';
         }
         $job['title'] = wpseo_replace_vars($title_template, $post);
     }
     unset($title);
     $WPSEO_Metabox->score_title($job, $results);
     // Meta description.
     $description = '';
     // $desc_meta   = WPSEO_Meta::get_value( 'metadesc', $post->ID );
     $desc_meta = WPGlobus_Core::text_filter(WPSEO_Meta::get_value('metadesc', $post->ID), WPGlobus::Config()->default_language);
     if ($desc_meta !== '') {
         $description = $desc_meta;
     } elseif (isset($options['metadesc-' . $post->post_type]) && $options['metadesc-' . $post->post_type] !== '') {
         $description = wpseo_replace_vars($options['metadesc-' . $post->post_type], $post);
     }
     unset($desc_meta);
     WPSEO_Meta::$meta_length = apply_filters('wpseo_metadesc_length', WPSEO_Meta::$meta_length, $post);
     $WPSEO_Metabox->score_description($job, $results, $description, WPSEO_Meta::$meta_length);
     unset($description);
     // Body.
     // $body   = $WPSEO_Metabox->get_body( $post );
     $body = WPGlobus_Core::text_filter($WPSEO_Metabox->get_body($post), WPGlobus::Config()->default_language);
     $firstp = $WPSEO_Metabox->get_first_paragraph($body);
     $WPSEO_Metabox->score_body($job, $results, $body, $firstp);
     unset($firstp);
     // URL.
     $WPSEO_Metabox->score_url($job, $results);
     // Headings.
     $headings = $WPSEO_Metabox->get_headings($body);
     $WPSEO_Metabox->score_headings($job, $results, $headings);
     unset($headings);
     // Images.
     $imgs = array();
     $imgs['count'] = substr_count($body, '<img');
     $imgs = $WPSEO_Metabox->get_images_alt_text($post->ID, $body, $imgs);
     // Check featured image.
     if (function_exists('has_post_thumbnail') && has_post_thumbnail()) {
         $imgs['count'] += 1;
         if (empty($imgs['alts'])) {
             $imgs['alts'] = array();
         }
         $imgs['alts'][] = $WPSEO_Metabox->strtolower_utf8(get_post_meta(get_post_thumbnail_id($post->ID), '_wp_attachment_image_alt', true));
     }
     $WPSEO_Metabox->score_images_alt_text($job, $results, $imgs);
     unset($imgs);
     unset($body);
     // Anchors.
     $anchors = $WPSEO_Metabox->get_anchor_texts($xpath);
     $count = $WPSEO_Metabox->get_anchor_count($xpath);
     $WPSEO_Metabox->score_anchor_texts($job, $results, $anchors, $count);
     unset($anchors, $count, $dom);
     return $results;
 }
/**
 * Adds an SEO admin bar menu with several options. If the current user is an admin he can also go straight to several settings menu's from here.
 */
function wpseo_admin_bar_menu() {
	// If the current user can't write posts, this is all of no use, so let's not output an admin menu
	if ( ! current_user_can( 'edit_posts' ) ) {
		return;
	}

	global $wp_admin_bar, $wpseo_front, $post;

	$url = '';
	if ( is_object( $wpseo_front ) ) {
		$url = $wpseo_front->canonical( false );
	}

	$focuskw = '';
	$score   = '';
	$seo_url = get_admin_url( null, 'admin.php?page=wpseo_dashboard' );

	if ( ( is_singular() || ( is_admin() && in_array( $GLOBALS['pagenow'], array( 'post.php', 'post-new.php' ), true ) ) ) && isset( $post ) && is_object( $post ) && apply_filters( 'wpseo_use_page_analysis', true ) === true ) {
		$focuskw    = WPSEO_Meta::get_value( 'focuskw', $post->ID );
		$perc_score = WPSEO_Meta::get_value( 'linkdex', $post->ID );
		$calc_score = wpseo_calc( $perc_score, '/', 10, true );
		$txtscore   = wpseo_translate_score( $calc_score );
		$title      = wpseo_translate_score( $calc_score, false );
		$score      = '<div title="' . esc_attr( $title ) . '" class="' . esc_attr( 'wpseo_score_img ' . $txtscore . ' ' . $perc_score ) . '"></div>';

		$seo_url = get_edit_post_link( $post->ID );
		if ( $txtscore !== 'na' ) {
			$seo_url .= '#wpseo_linkdex';
		}
	}

	$wp_admin_bar->add_menu( array( 'id' => 'wpseo-menu', 'title' => __( 'SEO', 'wordpress-seo' ) . $score, 'href' => $seo_url, ) );
	$wp_admin_bar->add_menu( array( 'parent' => 'wpseo-menu', 'id' => 'wpseo-kwresearch', 'title' => __( 'Keyword Research', 'wordpress-seo' ), '#', ) );
	$wp_admin_bar->add_menu( array( 'parent' => 'wpseo-kwresearch', 'id' => 'wpseo-adwordsexternal', 'title' => __( 'AdWords External', 'wordpress-seo' ), 'href' => 'http://adwords.google.com/keywordplanner', 'meta' => array( 'target' => '_blank' ) ) );
	$wp_admin_bar->add_menu( array( 'parent' => 'wpseo-kwresearch', 'id' => 'wpseo-googleinsights', 'title' => __( 'Google Insights', 'wordpress-seo' ), 'href' => 'http://www.google.com/insights/search/#q=' . urlencode( $focuskw ) . '&cmpt=q', 'meta' => array( 'target' => '_blank' ) ) );
	$wp_admin_bar->add_menu( array( 'parent' => 'wpseo-kwresearch', 'id' => 'wpseo-wordtracker', 'title' => __( 'SEO Book', 'wordpress-seo' ), 'href' => 'http://tools.seobook.com/keyword-tools/seobook/?keyword=' . urlencode( $focuskw ), 'meta' => array( 'target' => '_blank' ) ) );

	if ( ! is_admin() ) {
		$wp_admin_bar->add_menu( array( 'parent' => 'wpseo-menu', 'id' => 'wpseo-analysis', 'title' => __( 'Analyze this page', 'wordpress-seo' ), '#', ) );
		if ( is_string( $url ) ) {
			// @todo [JRF => whomever] check if this url shouldn't be encoded either with urlencode or with esc_url or something
			$wp_admin_bar->add_menu( array( 'parent' => 'wpseo-analysis', 'id' => 'wpseo-inlinks-ose', 'title' => __( 'Check Inlinks (OSE)', 'wordpress-seo' ), 'href' => 'http://www.opensiteexplorer.org/' . str_replace( '/', '%252F', preg_replace( '`^http[s]?://`', '', $url ) ) . '/a!links', 'meta' => array( 'target' => '_blank' ) ) );
			$wp_admin_bar->add_menu( array( 'parent' => 'wpseo-analysis', 'id' => 'wpseo-kwdensity', 'title' => __( 'Check Keyword Density', 'wordpress-seo' ), 'href' => 'http://www.zippy.co.uk/keyworddensity/index.php?url=' . urlencode( $url ) . '&keyword=' . urlencode( $focuskw ), 'meta' => array( 'target' => '_blank' ) ) );
			$wp_admin_bar->add_menu( array( 'parent' => 'wpseo-analysis', 'id' => 'wpseo-cache', 'title' => __( 'Check Google Cache', 'wordpress-seo' ), 'href' => 'http://webcache.googleusercontent.com/search?strip=1&q=cache:' . urlencode( $url ), 'meta' => array( 'target' => '_blank' ) ) );
			$wp_admin_bar->add_menu( array( 'parent' => 'wpseo-analysis', 'id' => 'wpseo-header', 'title' => __( 'Check Headers', 'wordpress-seo' ), 'href' => 'http://quixapp.com/headers/?r=' . urlencode( $url ), 'meta' => array( 'target' => '_blank' ) ) );
			$wp_admin_bar->add_menu( array( 'parent' => 'wpseo-analysis', 'id' => 'wpseo-richsnippets', 'title' => __( 'Check Rich Snippets', 'wordpress-seo' ), 'href' => 'http://www.google.com/webmasters/tools/richsnippets?q=' . urlencode( $url ), 'meta' => array( 'target' => '_blank' ) ) );
			$wp_admin_bar->add_menu( array( 'parent' => 'wpseo-analysis', 'id' => 'wpseo-facebookdebug', 'title' => __( 'Facebook Debugger', 'wordpress-seo' ), 'href' => 'https://developers.facebook.com/tools/debug/og/object?q=' . urlencode( $url ), 'meta' => array( 'target' => '_blank' ) ) );
		}
	}

	$admin_menu = false;
	if ( function_exists( 'is_multisite' ) && is_multisite() ) {
		$options = get_site_option( 'wpseo_ms' );
		if ( $options['access'] === 'superadmin' ) {
			if ( is_super_admin() ) {
				$admin_menu = true;
			}
			else {
				$admin_menu = false;
			}
		}
		else {
			if ( current_user_can( 'manage_options' ) ) {
				$admin_menu = true;
			}
			else {
				$admin_menu = false;
			}
		}
	}
	else {
		if ( current_user_can( 'manage_options' ) ) {
			$admin_menu = true;
		}
	}

	// @todo: add links to bulk title and bulk description edit pages
	if ( $admin_menu ) {
		$wp_admin_bar->add_menu( array( 'parent' => 'wpseo-menu', 'id' => 'wpseo-settings', 'title' => __( 'SEO Settings', 'wordpress-seo' ), 'href' => admin_url( 'admin.php?page=wpseo_titles' ), ) );
		$wp_admin_bar->add_menu( array( 'parent' => 'wpseo-settings', 'id' => 'wpseo-titles', 'title' => __( 'Titles &amp; Metas', 'wordpress-seo' ), 'href' => admin_url( 'admin.php?page=wpseo_titles' ), ) );
		$wp_admin_bar->add_menu( array( 'parent' => 'wpseo-settings', 'id' => 'wpseo-social', 'title' => __( 'Social', 'wordpress-seo' ), 'href' => admin_url( 'admin.php?page=wpseo_social' ), ) );
		$wp_admin_bar->add_menu( array( 'parent' => 'wpseo-settings', 'id' => 'wpseo-xml', 'title' => __( 'XML Sitemaps', 'wordpress-seo' ), 'href' => admin_url( 'admin.php?page=wpseo_xml' ), ) );
		$wp_admin_bar->add_menu( array( 'parent' => 'wpseo-settings', 'id' => 'wpseo-permalinks', 'title' => __( 'Permalinks', 'wordpress-seo' ), 'href' => admin_url( 'admin.php?page=wpseo_permalinks' ), ) );
		$wp_admin_bar->add_menu( array( 'parent' => 'wpseo-settings', 'id' => 'wpseo-internal-links', 'title' => __( 'Internal Links', 'wordpress-seo' ), 'href' => admin_url( 'admin.php?page=wpseo_internal-links' ), ) );
		$wp_admin_bar->add_menu( array( 'parent' => 'wpseo-settings', 'id' => 'wpseo-rss', 'title' => __( 'RSS', 'wordpress-seo' ), 'href' => admin_url( 'admin.php?page=wpseo_rss' ), ) );
		$wp_admin_bar->add_menu( array( 'parent' => 'wpseo-settings', 'id' => 'wpseo-import', 'title' => __( 'Import & Export', 'wordpress-seo' ), 'href' => admin_url( 'admin.php?page=wpseo_import' ), ) );
		
		// Check where to add the edit files page
		if ( ! ( defined( 'DISALLOW_FILE_EDIT' ) && DISALLOW_FILE_EDIT ) && ! ( defined( 'DISALLOW_FILE_MODS' ) && DISALLOW_FILE_MODS ) ) {
			$wp_admin_bar->add_menu( array( 'parent' => 'wpseo-settings', 'id' => 'wpseo-files', 'title' => __( 'Edit Files', 'wordpress-seo'), 'href' => admin_url( 'admin.php?page=wpseo_files' ), ) );
		}	

		$wp_admin_bar->add_menu( array( 'parent' => 'wpseo-settings', 'id' => 'wpseo-licenses', 'title' => __( 'Extensions', 'wordpress-seo'), 'href' => admin_url( 'admin.php?page=wpseo_licenses' ), ) );	
	}
}
 /**
  * Getting the meta description for given post
  *
  * @param integer $post_id The ID of the post for which to get the meta description.
  * @param string  $post_type The post type.
  *
  * @return bool|string
  */
 private function get_meta_description($post_id, $post_type)
 {
     if (($meta_description = WPSEO_Meta::get_value('metadesc', $post_id)) !== '') {
         return $meta_description;
     }
     if ($default_from_options = $this->default_from_options('metadesc', $post_type)) {
         return $default_from_options;
     }
     return '';
 }
 /**
  * Produce array of URL parts for given post object.
  *
  * @param object $post Post object to get URL parts for.
  *
  * @return array|bool
  */
 protected function get_url($post)
 {
     $url = array();
     /**
      * Filter the URL Yoast SEO uses in the XML sitemap.
      *
      * Note that only absolute local URLs are allowed as the check after this removes external URLs.
      *
      * @param string $url  URL to use in the XML sitemap
      * @param object $post Post object for the URL.
      */
     $url['loc'] = apply_filters('wpseo_xml_sitemap_post_url', get_permalink($post), $post);
     /**
      * Do not include external URLs.
      *
      * @see https://wordpress.org/plugins/page-links-to/ can rewrite permalinks to external URLs.
      */
     if (false === strpos($url['loc'], $this->get_home_url())) {
         return false;
     }
     $modified = max($post->post_modified_gmt, $post->post_date_gmt);
     if ($modified !== '0000-00-00 00:00:00') {
         $url['mod'] = $modified;
     }
     $url['chf'] = 'daily';
     // Deprecated, kept for backwards data compat. R.
     $canonical = WPSEO_Meta::get_value('canonical', $post->ID);
     if ($canonical !== '' && $canonical !== $url['loc']) {
         /*
         Let's assume that if a canonical is set for this page and it's different from
            the URL of this post, that page is either already in the XML sitemap OR is on
            an external site, either way, we shouldn't include it here.
         */
         return false;
     }
     unset($canonical);
     $options = $this->get_options();
     if ($options['trailingslash'] === true && $post->post_type !== 'post') {
         $url['loc'] = trailingslashit($url['loc']);
     }
     $url['pri'] = 1;
     // Deprecated, kept for backwards data compat. R.
     $url['images'] = $this->get_image_parser()->get_images($post);
     return $url;
 }
示例#18
0
 /**
  * Getting the keywords for current item
  */
 private function item_keywords()
 {
     $this->add_keywords(WPSEO_Meta::get_value('newssitemap-keywords', $this->item_id));
 }
示例#19
0
 /**
  * If opengraph-image is set, call add_image and return true
  *
  * @return bool
  */
 private function get_opengraph_image()
 {
     $ogimg = WPSEO_Meta::get_value('opengraph-image');
     if ($ogimg !== '') {
         $this->add_image($ogimg);
         return true;
     }
 }
 /**
  * Add OpenGraph video info if present
  *
  * @since 0.1
  */
 public function opengraph()
 {
     $options = get_option('wpseo_video');
     if ($options['facebook_embed'] !== true) {
         return false;
     }
     if (is_singular()) {
         global $post;
         if (is_object($post)) {
             $video = WPSEO_Meta::get_value('video_meta', $post->ID);
             if (is_array($video) && $video !== array()) {
                 $disable = WPSEO_Meta::get_value('videositemap-disable', $post->ID);
                 if ($disable !== 'on') {
                     $video = $this->get_video_image($post->ID, $video);
                 }
             }
         }
     } else {
         if (is_tax() || is_category() || is_tag()) {
             $term = get_queried_object();
             if (is_array($options['videositemap_taxonomies']) && in_array($term->taxonomy, $options['videositemap_taxonomies'])) {
                 $tax_meta = get_option('wpseo_taxonomy_meta');
                 if (isset($tax_meta[$term->taxonomy]['_video'][$term->term_id])) {
                     $video = $tax_meta[$term->taxonomy]['_video'][$term->term_id];
                 }
             }
         }
     }
     if (!isset($video) || !is_array($video) || !isset($video['player_loc'])) {
         return false;
     }
     echo '<meta property="og:video" content="' . esc_attr($video['player_loc']) . '" />' . "\n";
     echo '<meta property="og:video:type" content="application/x-shockwave-flash" />' . "\n";
     if (isset($video['width']) && isset($video['height'])) {
         echo '<meta property="og:video:width" content="' . esc_attr($video['width']) . '" />' . "\n";
         echo '<meta property="og:video:height" content="' . esc_attr($video['height']) . '" />' . "\n";
     }
     $GLOBALS['wpseo_og']->image_output($video['thumbnail_loc']);
 }
示例#21
0
 /**
  * Output the OpenGraph description, specific OG description first, if not, grab the meta description.
  *
  * @param bool $echo Whether to echo or return the description
  *
  * @return string $ogdesc
  */
 public function description($echo = true)
 {
     $ogdesc = '';
     if (is_front_page()) {
         $ogdesc = $this->options['og_frontpage_desc'] !== '' ? $this->options['og_frontpage_desc'] : $this->metadesc(false);
     }
     if (is_singular()) {
         $ogdesc = WPSEO_Meta::get_value('opengraph-description');
         // Replace WP SEO Variables
         $ogdesc = wpseo_replace_vars($ogdesc, get_post());
         // Use metadesc if $ogdesc is empty
         if ($ogdesc === '') {
             $ogdesc = $this->metadesc(false);
         }
         // og:description is still blank so grab it from get_the_excerpt()
         if (!is_string($ogdesc) || is_string($ogdesc) && $ogdesc === '') {
             $ogdesc = str_replace('[&hellip;]', '&hellip;', strip_tags(get_the_excerpt()));
         }
     }
     if (is_category() || is_tag() || is_tax()) {
         $ogdesc = trim(strip_tags(term_description()));
     }
     // Strip shortcodes if any
     $ogdesc = strip_shortcodes($ogdesc);
     /**
      * Filter: 'wpseo_opengraph_desc' - Allow changing the OpenGraph description
      *
      * @api string $ogdesc The description string.
      */
     $ogdesc = apply_filters('wpseo_opengraph_desc', $ogdesc);
     if (is_string($ogdesc) && $ogdesc !== '') {
         if ($echo !== false) {
             $this->og_tag('og:description', $ogdesc);
         }
     }
     return $ogdesc;
 }
 /**
  * WP SEO meta key.
  *
  * Hooked into wpseo_ hook already, so no need for function_exist.
  *
  * @access public
  * @return string
  */
 public function wpseo_metakey()
 {
     return WPSEO_Meta::get_value('metakey', wc_get_page_id('shop'));
 }
示例#23
0
/**
 * Get the value from the post custom values
 *
 * @deprecated 1.5.0
 * @deprecated use WPSEO_Meta::get_value()
 * @see        WPSEO_Meta::get_value()
 *
 * @param    string $val    internal name of the value to get
 * @param    int    $postid post ID of the post to get the value for
 *
 * @return    string
 */
function wpseo_get_value($val, $postid = 0)
{
    _deprecated_function(__FUNCTION__, 'WPSEO 1.5.0', 'WPSEO_Meta::get_value()');
    return WPSEO_Meta::get_value($val, $postid);
}
示例#24
0
 /**
  * Calculate the priority of the post
  *
  * @param stdobject $post
  *
  * @return float|mixed
  */
 private function calculate_priority($post)
 {
     $front_id = get_option('page_on_front');
     $pri = WPSEO_Meta::get_value('sitemap-prio', $post->ID);
     if (is_numeric($pri)) {
         $return = (double) $pri;
     } else {
         if ($post->post_parent == 0 && $post->post_type == 'page') {
             $return = 0.8;
         } else {
             $return = 0.6;
         }
     }
     if (isset($front_id) && $post->ID == $front_id) {
         $return = 1.0;
     }
     /**
      * Filter: 'wpseo_xml_post_type_archive_priority' - Allow changing the priority of the URL WordPress SEO uses in the XML sitemap.
      *
      * @api float $priority The priority for this URL, ranging from 0 to 1
      *
      * @param string $post_type The post type this archive is for
      * @param object $p         The post object
      */
     $return = apply_filters('wpseo_xml_sitemap_post_priority', $return, $post->post_type, $post);
     return $return;
 }
 /**
  * Retrieve link url and text based on post id
  *
  * @param	int		$id		Post id
  *
  * @return	array	$link	Array of link text and url
  */
 private function get_link_info_for_id($id)
 {
     $link = array();
     $link['url'] = get_permalink($id);
     $link['text'] = WPSEO_Meta::get_value('bctitle', $id);
     if ($link['text'] === '') {
         $link['text'] = strip_tags(get_the_title($id));
     }
     /**
      * Filter: 'wp_seo_get_bc_title' - Allow developer to filter the WP SEO Breadcrumb title.
      *
      * @api string $link_text The Breadcrumb title text
      *
      * @param int $link_id The post ID
      */
     $link['text'] = apply_filters('wp_seo_get_bc_title', $link['text'], $id);
     return $link;
 }
/**
 * Adds an SEO admin bar menu with several options. If the current user is an admin he can also go straight to several settings menu's from here.
 */
function wpseo_admin_bar_menu()
{
    // If the current user can't write posts, this is all of no use, so let's not output an admin menu
    if (!current_user_can('edit_posts')) {
        return;
    }
    global $wp_admin_bar, $post;
    $url = WPSEO_Frontend::get_instance()->canonical(false);
    $focuskw = '';
    $score = '';
    $seo_url = get_admin_url(null, 'admin.php?page=wpseo_dashboard');
    if ((is_singular() || is_admin() && in_array($GLOBALS['pagenow'], array('post.php', 'post-new.php'), true)) && isset($post) && is_object($post) && apply_filters('wpseo_use_page_analysis', true) === true) {
        $focuskw = WPSEO_Meta::get_value('focuskw', $post->ID);
        $perc_score = WPSEO_Meta::get_value('linkdex', $post->ID);
        $calc_score = WPSEO_Utils::calc($perc_score, '/', 10, true);
        $txtscore = WPSEO_Utils::translate_score($calc_score);
        $title = WPSEO_Utils::translate_score($calc_score, false);
        $score = '<div title="' . esc_attr($title) . '" class="' . esc_attr('wpseo-score-icon ' . $txtscore . ' ' . $perc_score) . '"></div>';
        $seo_url = get_edit_post_link($post->ID);
        if ($txtscore !== 'na') {
            $seo_url .= '#wpseo_linkdex';
        }
    }
    $wp_admin_bar->add_menu(array('id' => 'wpseo-menu', 'title' => __('SEO', 'wordpress-seo') . $score, 'href' => $seo_url));
    $wp_admin_bar->add_menu(array('parent' => 'wpseo-menu', 'id' => 'wpseo-kwresearch', 'title' => __('Keyword Research', 'wordpress-seo'), '#'));
    $wp_admin_bar->add_menu(array('parent' => 'wpseo-kwresearch', 'id' => 'wpseo-adwordsexternal', 'title' => __('AdWords External', 'wordpress-seo'), 'href' => 'http://adwords.google.com/keywordplanner', 'meta' => array('target' => '_blank')));
    $wp_admin_bar->add_menu(array('parent' => 'wpseo-kwresearch', 'id' => 'wpseo-googleinsights', 'title' => __('Google Insights', 'wordpress-seo'), 'href' => 'http://www.google.com/insights/search/#q=' . urlencode($focuskw) . '&cmpt=q', 'meta' => array('target' => '_blank')));
    $wp_admin_bar->add_menu(array('parent' => 'wpseo-kwresearch', 'id' => 'wpseo-wordtracker', 'title' => __('SEO Book', 'wordpress-seo'), 'href' => 'http://tools.seobook.com/keyword-tools/seobook/?keyword=' . urlencode($focuskw), 'meta' => array('target' => '_blank')));
    if (!is_admin()) {
        $wp_admin_bar->add_menu(array('parent' => 'wpseo-menu', 'id' => 'wpseo-analysis', 'title' => __('Analyze this page', 'wordpress-seo'), '#'));
        if (is_string($url)) {
            // @todo [JRF => whomever] check if this url shouldn't be encoded either with urlencode or with esc_url or something
            $wp_admin_bar->add_menu(array('parent' => 'wpseo-analysis', 'id' => 'wpseo-inlinks-ose', 'title' => __('Check Inlinks (OSE)', 'wordpress-seo'), 'href' => '//moz.com/researchtools/ose/links?site=' . urlencode($url), 'meta' => array('target' => '_blank')));
            $wp_admin_bar->add_menu(array('parent' => 'wpseo-analysis', 'id' => 'wpseo-kwdensity', 'title' => __('Check Keyword Density', 'wordpress-seo'), 'href' => '//www.zippy.co.uk/keyworddensity/index.php?url=' . urlencode($url) . '&keyword=' . urlencode($focuskw), 'meta' => array('target' => '_blank')));
            $wp_admin_bar->add_menu(array('parent' => 'wpseo-analysis', 'id' => 'wpseo-cache', 'title' => __('Check Google Cache', 'wordpress-seo'), 'href' => '//webcache.googleusercontent.com/search?strip=1&q=cache:' . urlencode($url), 'meta' => array('target' => '_blank')));
            $wp_admin_bar->add_menu(array('parent' => 'wpseo-analysis', 'id' => 'wpseo-header', 'title' => __('Check Headers', 'wordpress-seo'), 'href' => '//quixapp.com/headers/?r=' . urlencode($url), 'meta' => array('target' => '_blank')));
            $wp_admin_bar->add_menu(array('parent' => 'wpseo-analysis', 'id' => 'wpseo-richsnippets', 'title' => __('Check Rich Snippets', 'wordpress-seo'), 'href' => '//www.google.com/webmasters/tools/richsnippets?q=' . urlencode($url), 'meta' => array('target' => '_blank')));
            $wp_admin_bar->add_menu(array('parent' => 'wpseo-analysis', 'id' => 'wpseo-facebookdebug', 'title' => __('Facebook Debugger', 'wordpress-seo'), 'href' => '//developers.facebook.com/tools/debug/og/object?q=' . urlencode($url), 'meta' => array('target' => '_blank')));
            $wp_admin_bar->add_menu(array('parent' => 'wpseo-analysis', 'id' => 'wpseo-pinterestvalidator', 'title' => __('Pinterest Rich Pins Validator', 'wordpress-seo'), 'href' => '//developers.pinterest.com/rich_pins/validator/?link=' . urlencode($url), 'meta' => array('target' => '_blank')));
            $wp_admin_bar->add_menu(array('parent' => 'wpseo-analysis', 'id' => 'wpseo-htmlvalidation', 'title' => __('HTML Validator', 'wordpress-seo'), 'href' => '//validator.w3.org/check?uri=' . urlencode($url), 'meta' => array('target' => '_blank')));
            $wp_admin_bar->add_menu(array('parent' => 'wpseo-analysis', 'id' => 'wpseo-cssvalidation', 'title' => __('CSS Validator', 'wordpress-seo'), 'href' => '//jigsaw.w3.org/css-validator/validator?uri=' . urlencode($url), 'meta' => array('target' => '_blank')));
            $wp_admin_bar->add_menu(array('parent' => 'wpseo-analysis', 'id' => 'wpseo-pagespeed', 'title' => __('Google Page Speed Test', 'wordpress-seo'), 'href' => '//developers.google.com/speed/pagespeed/insights/?url=' . urlencode($url), 'meta' => array('target' => '_blank')));
            $wp_admin_bar->add_menu(array('parent' => 'wpseo-analysis', 'id' => 'wpseo-modernie', 'title' => __('Modern IE Site Scan', 'wordpress-seo'), 'href' => '//www.modern.ie/en-us/report#' . urlencode($url), 'meta' => array('target' => '_blank')));
        }
    }
    $admin_menu = false;
    if (is_multisite()) {
        $options = get_site_option('wpseo_ms');
        if ($options['access'] === 'superadmin' && is_super_admin()) {
            $admin_menu = true;
        } elseif (current_user_can('manage_options')) {
            $admin_menu = true;
        }
    } elseif (current_user_can('manage_options')) {
        $admin_menu = true;
    }
    // @todo: add links to bulk title and bulk description edit pages
    if ($admin_menu) {
        $wp_admin_bar->add_menu(array('parent' => 'wpseo-menu', 'id' => 'wpseo-settings', 'title' => __('SEO Settings', 'wordpress-seo'), 'href' => admin_url('admin.php?page=wpseo_titles')));
        $wp_admin_bar->add_menu(array('parent' => 'wpseo-settings', 'id' => 'wpseo-titles', 'title' => __('Titles &amp; Metas', 'wordpress-seo'), 'href' => admin_url('admin.php?page=wpseo_titles')));
        $wp_admin_bar->add_menu(array('parent' => 'wpseo-settings', 'id' => 'wpseo-social', 'title' => __('Social', 'wordpress-seo'), 'href' => admin_url('admin.php?page=wpseo_social')));
        $wp_admin_bar->add_menu(array('parent' => 'wpseo-settings', 'id' => 'wpseo-xml', 'title' => __('XML Sitemaps', 'wordpress-seo'), 'href' => admin_url('admin.php?page=wpseo_xml')));
        $wp_admin_bar->add_menu(array('parent' => 'wpseo-settings', 'id' => 'wpseo-permalinks', 'title' => __('Permalinks', 'wordpress-seo'), 'href' => admin_url('admin.php?page=wpseo_permalinks')));
        $wp_admin_bar->add_menu(array('parent' => 'wpseo-settings', 'id' => 'wpseo-internal-links', 'title' => __('Internal Links', 'wordpress-seo'), 'href' => admin_url('admin.php?page=wpseo_internal-links')));
        $wp_admin_bar->add_menu(array('parent' => 'wpseo-settings', 'id' => 'wpseo-rss', 'title' => __('RSS', 'wordpress-seo'), 'href' => admin_url('admin.php?page=wpseo_rss')));
        $wp_admin_bar->add_menu(array('parent' => 'wpseo-settings', 'id' => 'wpseo-import', 'title' => esc_html__('Import & Export', 'wordpress-seo'), 'href' => admin_url('admin.php?page=wpseo_import')));
        $wp_admin_bar->add_menu(array('parent' => 'wpseo-settings', 'id' => 'wpseo_bulk-editor', 'title' => __('Bulk Editor', 'wordpress-seo'), 'href' => admin_url('admin.php?page=wpseo_bulk-editor')));
        // Check where to add the edit files page
        if (WPSEO_Utils::allow_system_file_edit() === true) {
            $wp_admin_bar->add_menu(array('parent' => 'wpseo-settings', 'id' => 'wpseo-files', 'title' => __('Edit Files', 'wordpress-seo'), 'href' => network_admin_url('admin.php?page=wpseo_files')));
            // will auto-use admin_url if not in multi-site
        }
        $wp_admin_bar->add_menu(array('parent' => 'wpseo-settings', 'id' => 'wpseo-licenses', 'title' => __('Extensions', 'wordpress-seo'), 'href' => admin_url('admin.php?page=wpseo_licenses')));
    }
}
 /**
  * Retrieve images from the post meta values
  *
  * @return bool
  */
 private function image_from_meta_values_output()
 {
     foreach (array('twitter-image', 'opengraph-image') as $tag) {
         $img = WPSEO_Meta::get_value($tag);
         if ($img !== '') {
             $this->image_output($img);
             return true;
         }
     }
     return false;
 }
示例#28
0
 /**
  * If opengraph-image is set, call add_image and return true.
  *
  * @param int $post_id Optional post ID to use.
  *
  * @return bool
  */
 private function get_opengraph_image_post($post_id = 0)
 {
     $ogimg = WPSEO_Meta::get_value('opengraph-image', $post_id);
     if ($ogimg !== '') {
         $this->add_image($ogimg);
         return true;
     }
     return false;
 }
示例#29
0
 /**
  * Based on the redirect meta value, this function determines whether it should redirect the current post / page.
  *
  * @return boolean
  */
 function page_redirect()
 {
     if (is_singular()) {
         global $post;
         if (!isset($post) || !is_object($post)) {
             return false;
         }
         $redir = WPSEO_Meta::get_value('redirect', $post->ID);
         if ($redir !== '') {
             wp_redirect($redir, 301);
             exit;
         }
     }
     return false;
 }
 /**
  * Retrieve the post/page/cpt's focus keyword for use as replacement string.
  *
  * @return string|null
  */
 private function retrieve_focuskw()
 {
     $replacement = null;
     if (!empty($this->args->ID)) {
         $focus_kw = WPSEO_Meta::get_value('focuskw', $this->args->ID);
         if ($focus_kw !== '') {
             $replacement = $focus_kw;
         }
     }
     return $replacement;
 }