Ejemplo n.º 1
0
 /**
  * Class constructor.
  */
 public function __construct()
 {
     $this->options = get_wpseo_options();
     global $fb_ver;
     if (isset($fb_ver) || class_exists('Facebook_Loader')) {
         add_filter('fb_meta_tags', array($this, 'facebook_filter'), 10, 1);
     } else {
         add_filter('language_attributes', array($this, 'add_opengraph_namespace'));
         add_action('wpseo_opengraph', array($this, 'locale'), 1);
         add_action('wpseo_opengraph', array($this, 'type'), 5);
         add_action('wpseo_opengraph', array($this, 'og_title'), 10);
         add_action('wpseo_opengraph', array($this, 'site_owner'), 20);
         add_action('wpseo_opengraph', array($this, 'description'), 11);
         add_action('wpseo_opengraph', array($this, 'url'), 12);
         add_action('wpseo_opengraph', array($this, 'site_name'), 13);
         add_action('wpseo_opengraph', array($this, 'website_facebook'), 14);
         add_action('wpseo_opengraph', array($this, 'article_author_facebook'), 15);
         add_action('wpseo_opengraph', array($this, 'tags'), 16);
         add_action('wpseo_opengraph', array($this, 'category'), 17);
         add_action('wpseo_opengraph', array($this, 'publish_date'), 19);
         add_action('wpseo_opengraph', array($this, 'image'), 30);
     }
     remove_action('wp_head', 'jetpack_og_tags');
     add_action('wpseo_head', array($this, 'opengraph'), 30);
 }
 public function __construct()
 {
     $options = get_wpseo_options();
     add_action('wpseo_tab_header', array(&$this, 'tab_header'), 60);
     add_action('wpseo_tab_content', array(&$this, 'tab_content'));
     add_filter('wpseo_save_metaboxes', array(&$this, 'save_meta_boxes'), 10, 1);
 }
Ejemplo n.º 3
0
 /**
  * Update the query vars with the redirect var when stripcategorybase is active
  *
  * @param $query_vars
  * @return array
  */
 function query_vars($query_vars)
 {
     $options = get_wpseo_options();
     if (isset($options['stripcategorybase']) && $options['stripcategorybase']) {
         $query_vars[] = 'wpseo_category_redirect';
     }
     return $query_vars;
 }
 public function __construct()
 {
     $this->options = get_wpseo_options();
     add_action('wpseo_head', array(&$this, 'opengraph'));
     if (isset($this->options['opengraph']) && $this->options['opengraph']) {
         add_filter('language_attributes', array(&$this, 'add_opengraph_namespace'));
     }
 }
Ejemplo n.º 5
0
 function WPSEO_Widgets()
 {
     $options = get_wpseo_options();
     if (isset($options['replacemetawidget']) && $options['replacemetawidget'] == "on") {
         add_action('plugins_loaded', array(&$this, 'load_widgets'), 10);
         add_action('widgets_init', array(&$this, 'widgets_init'), 99);
     }
 }
Ejemplo n.º 6
0
 function __construct()
 {
     if (!defined('ENT_XML1')) {
         define("ENT_XML1", 16);
     }
     add_action('init', array($this, 'init'), 1);
     add_action('template_redirect', array($this, 'redirect'));
     add_filter('redirect_canonical', array($this, 'canonical'));
     add_action('wpseo_hit_sitemap_index', array($this, 'hit_sitemap_index'));
     // default stylesheet
     $this->stylesheet = '<?xml-stylesheet type="text/xsl" href="' . home_url('main-sitemap.xsl') . '"?>';
     $this->options = get_wpseo_options();
 }
Ejemplo n.º 7
0
 /**
  * Adds active languages sitemap links to sitemap_index.xml 
  * @param type $str
  */
 function add_to_index($str)
 {
     global $sitepress, $sitepress_settings, $wpdb;
     $options = get_wpseo_options();
     $default_language = $sitepress->get_default_language();
     $current_language = $sitepress->get_current_language();
     foreach ($sitepress->get_active_languages() as $lang_code => $array) {
         if (isset($sitepress_settings['language_domains'][$lang_code])) {
             $home_url = $sitepress_settings['language_domains'][$lang_code];
         } else {
             $home_url = home_url();
         }
         foreach (get_post_types(array('public' => true)) as $post_type) {
             $sitepress->switch_lang($lang_code);
             $count = get_posts(array('post_type' => $post_type, 'post_status' => 'publish', 'suppress_filters' => 0));
             $sitepress->switch_lang($current_language);
             if (count($count) > 0 && $sitepress->is_translated_post_type($post_type)) {
                 if (!isset($options['post_types-' . $post_type . '-not_in_sitemap']) && $lang_code !== $default_language) {
                     $filename = $post_type . '-' . $lang_code . '-sitemap.xml';
                     $date = $this->get_last_mod_date($post_type, $lang_code);
                     $str .= '<sitemap>' . "\n";
                     $str .= '<loc>' . $home_url . '/' . $filename . '</loc>' . "\n";
                     $str .= '<lastmod>' . $date . '</lastmod>' . "\n";
                     $str .= '</sitemap>' . "\n";
                 }
             }
         }
         foreach (get_taxonomies(array('public' => true)) as $tax) {
             $sitepress->switch_lang($lang_code);
             $count = get_terms($tax, array('suppress_filters' => 0));
             $sitepress->switch_lang($current_language);
             if (count($count) > 0 && $sitepress->is_translated_taxonomy($tax)) {
                 if (!isset($options['taxonomies-' . $tax . '-not_in_sitemap']) && $lang_code !== $default_language) {
                     $filename = $tax . '-' . $lang_code . '-sitemap.xml';
                     $date = $this->get_last_mod_date('post', $lang_code);
                     $str .= '<sitemap>' . "\n";
                     $str .= '<loc>' . $home_url . '/' . $filename . '</loc>' . "\n";
                     $str .= '<lastmod>' . $date . '</lastmod>' . "\n";
                     $str .= '</sitemap>' . "\n";
                 }
             }
         }
     }
     return $str;
 }
Ejemplo n.º 8
0
 /**
  * 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 = get_wpseo_options();
     if (isset($options['post_types-' . $post->post_type . '-not_in_sitemap']) && $options['post_types-' . $post->post_type . '-not_in_sitemap']) {
         return;
     }
     if (WP_CACHE) {
         wp_schedule_single_event(time(), '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_get_value('sitemap-include', $post->ID) != 'never') {
         wp_schedule_single_event(time() + 60, 'wpseo_ping_search_engines');
     }
 }
 /**
  * This function modifies the output for a single breadcrumb.
  * 
  * The default output is not modified, instead a completely new output is generated.
  * If the default link output contains a rel attribute with the value 'v:url' (which is added by WordPress SEO for every but the last link), URL and text are output.
  * Otherwise it is the current page for which only the text is printed out.
  * 
  * In this method the Schema.org markup for a single breadcrumb is added, and the link counter (class variable) is increased by 1 (for each link).
  * 
  * @param string $link_output the default output created by the WordPress SEO plugin
  * @param array $link an array containing data for the breadcrumb link (with fields 'url' and 'text')
  * @return string the output for a single breadcrumb link
  */
 public function modify_breadcrumb_element($link_output, $link)
 {
     $output = '';
     if (isset($link['url']) && substr_count($link_output, 'rel="v:url"') > 0) {
         $output .= '<a href="' . esc_attr($link['url']) . '"><span itemprop="itemListElement">' . $link['text'] . '</span></a>';
     } else {
         $opt = array();
         if (class_exists('WPSEO_Options')) {
             $opt = WPSEO_Options::get_all();
         } else {
             $opt = get_wpseo_options();
         }
         if (isset($opt['breadcrumbs-boldlast']) && $opt['breadcrumbs-boldlast']) {
             $output .= '<strong class="breadcrumb_last" itemprop="itemListElement">' . $link['text'] . '</strong>';
         } else {
             $output .= '<span class="breadcrumb_last" itemprop="itemListElement">' . $link['text'] . '</span>';
         }
     }
     $this->breadcrumb_link_counter++;
     return $output;
 }
Ejemplo n.º 10
0
 function term_additions_form($term, $taxonomy)
 {
     $tax_meta = get_option('wpseo_taxonomy_meta');
     $options = get_wpseo_options();
     if (isset($tax_meta[$taxonomy][$term->term_id])) {
         $tax_meta = $tax_meta[$taxonomy][$term->term_id];
     }
     echo '<h3>Yoast WordPress SEO Settings</h3>';
     echo '<table class="form-table">';
     $this->form_row('wpseo_title', 'SEO Title', 'The SEO title is used on the archive page for this term.', $tax_meta);
     $this->form_row('wpseo_desc', 'SEO Description', 'The SEO description is used for the meta description on the archive page for this term.', $tax_meta);
     if (isset($options['usemetakeywords']) && $options['usemetakeywords']) {
         $this->form_row('wpseo_metakey', 'Meta Keywords', 'Meta keywords used on the archive page for this term.', $tax_meta);
     }
     $this->form_row('wpseo_canonical', 'Canonical', 'The canonical link is shown on the archive page for this term.', $tax_meta);
     $this->form_row('wpseo_bctitle', 'Breadcrumbs Title', 'The Breadcrumbs title is used in the breadcrumbs where this ' . $taxonomy . ' appears.', $tax_meta);
     $this->form_row('wpseo_noindex', 'Noindex this ' . $taxonomy, '', $tax_meta, 'checkbox');
     $this->form_row('wpseo_nofollow', 'Nofollow this ' . $taxonomy, '', $tax_meta, 'checkbox');
     $this->form_row('wpseo_sitemap_include', 'Include in sitemap?', '', $tax_meta, 'select', array("-" => __("Auto detect"), "always" => __("Always include"), "never" => __("Never include")));
     echo '</table>';
 }
Ejemplo n.º 11
0
 /**
  * Outputs the Twitter Card code on singular pages.
  *
  * @return false Only shows on singular pages, false on non-singular pages.
  */
 public function twitter()
 {
     if (!is_singular()) {
         return false;
     }
     wp_reset_query();
     $this->type();
     $this->site_twitter();
     $this->site_domain();
     $this->author_twitter();
     // No need to show these when OpenGraph is also showing, as it'd be the same contents and Twitter
     // would fallback to OpenGraph anyway.
     $this->image();
     $options = get_wpseo_options();
     if (!isset($options['opengraph']) || !$options['opengraph']) {
         $this->twitter_description();
         $this->twitter_title();
         $this->twitter_url();
     }
     do_action('wpseo_twitter');
 }
Ejemplo n.º 12
0
 /**
  * Calculate the page analysis results for post.
  *
  * @param object $post Post to calculate the results for.
  * @return array
  */
 function calculate_results($post)
 {
     $options = get_wpseo_options();
     if (!class_exists('DOMDocument')) {
         $result = new WP_Error('no-domdocument', sprintf(__("Your hosting environment does not support PHP's %sDocument Object Model%s.", 'wordpress-seo'), '<a href="http://php.net/manual/en/book.dom.php">', '</a>') . ' ' . __("To enjoy all the benefits of the page analysis feature, you'll need to (get your host to) install it.", 'wordpress-seo'));
         return $result;
     }
     if (!wpseo_get_value('focuskw', $post->ID)) {
         $result = new WP_Error('no-focuskw', sprintf(__('No focus keyword was set for this %s. If you do not set a focus keyword, no score can be calculated.', 'wordpress-seo'), $post->post_type));
         wpseo_set_value('linkdex', 0, $post->ID);
         return $result;
     }
     $results = array();
     $job = array();
     $sampleurl = get_sample_permalink($post);
     $job["pageUrl"] = preg_replace('/%(post|page)name%/', $sampleurl[1], $sampleurl[0]);
     $job["pageSlug"] = urldecode($post->post_name);
     $job["keyword"] = trim(wpseo_get_value('focuskw'));
     $job["keyword_folded"] = $this->strip_separators_and_fold($job["keyword"]);
     $job["post_id"] = $post->ID;
     $dom = new domDocument();
     $dom->strictErrorChecking = false;
     $dom->preserveWhiteSpace = false;
     @$dom->loadHTML($post->post_content);
     $xpath = new DOMXPath($dom);
     $statistics = new Yoast_TextStatistics();
     // Check if this focus keyword has been used already.
     $this->check_double_focus_keyword($job, $results);
     // Keyword
     $this->score_keyword($job['keyword'], $results);
     // Title
     if (wpseo_get_value('title')) {
         $job['title'] = wpseo_get_value('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, (array) $post);
     }
     $this->score_title($job, $results, $statistics);
     // Meta description
     $description = '';
     if (wpseo_get_value('metadesc')) {
         $description = wpseo_get_value('metadesc');
     } else {
         if (isset($options['metadesc-' . $post->post_type]) && !empty($options['metadesc-' . $post->post_type])) {
             $description = wpseo_replace_vars($options['metadesc-' . $post->post_type], (array) $post);
         }
     }
     $meta_length = apply_filters('wpseo_metadesc_length', 156, $post);
     $this->score_description($job, $results, $description, $statistics, $meta_length);
     unset($description);
     // Body
     $body = $this->get_body($post);
     $firstp = $this->get_first_paragraph($post);
     $this->score_body($job, $results, $body, $firstp, $statistics);
     unset($body);
     unset($firstp);
     // URL
     $this->score_url($job, $results, $statistics);
     // Headings
     $headings = $this->get_headings($post->post_content);
     $this->score_headings($job, $results, $headings);
     unset($headings);
     // Images
     $imgs = array();
     $imgs['count'] = substr_count($post->post_content, '<img');
     $imgs = $this->get_images_alt_text($post, $imgs);
     $this->score_images_alt_text($job, $results, $imgs);
     unset($imgs);
     // Anchors
     $anchors = $this->get_anchor_texts($xpath);
     $count = $this->get_anchor_count($xpath);
     $this->score_anchor_texts($job, $results, $anchors, $count);
     unset($anchors, $count, $dom);
     $results = apply_filters('wpseo_linkdex_results', $results, $job, $post);
     $this->aasort($results, 'val');
     $overall = 0;
     $overall_max = 0;
     foreach ($results as $result) {
         $overall += $result['val'];
         $overall_max += 9;
     }
     if ($overall < 1) {
         $overall = 1;
     }
     $score = round($overall / $overall_max * 100);
     wpseo_set_value('linkdex', absint($score), $post->ID);
     return $results;
 }
Ejemplo n.º 13
0
 /**
  * Class constructor
  *
  * Adds and removes a lot of filters.
  */
 function __construct()
 {
     $this->options = get_wpseo_options();
     add_action('wp_head', array($this, 'head'), 1);
     // The head function here calls action wpseo_head, to which we hook all our functionality
     add_action('wpseo_head', array($this, 'debug_marker'), 2);
     add_action('wpseo_head', array($this, 'robots'), 6);
     add_action('wpseo_head', array($this, 'metadesc'), 10);
     add_action('wpseo_head', array($this, 'metakeywords'), 11);
     add_action('wpseo_head', array($this, 'canonical'), 20);
     add_action('wpseo_head', array($this, 'adjacent_rel_links'), 21);
     add_action('wpseo_head', array($this, 'author'), 22);
     add_action('wpseo_head', array($this, 'publisher'), 23);
     add_action('wpseo_head', array($this, 'webmaster_tools_authentication'), 90);
     // Remove actions that we will handle through our wpseo_head call, and probably change the output of
     remove_action('wp_head', 'rel_canonical');
     remove_action('wp_head', 'index_rel_link');
     remove_action('wp_head', 'start_post_rel_link');
     remove_action('wp_head', 'adjacent_posts_rel_link_wp_head');
     add_filter('wp_title', array($this, 'title'), 15, 3);
     add_filter('thematic_doctitle', array($this, 'title'), 15);
     add_action('wp', array($this, 'page_redirect'), 99, 1);
     add_action('template_redirect', array($this, 'noindex_feed'));
     add_filter('loginout', array($this, 'nofollow_link'));
     add_filter('register', array($this, 'nofollow_link'));
     if (isset($this->options['hide-rsdlink']) && $this->options['hide-rsdlink']) {
         remove_action('wp_head', 'rsd_link');
     }
     if (isset($this->options['hide-wlwmanifest']) && $this->options['hide-wlwmanifest']) {
         remove_action('wp_head', 'wlwmanifest_link');
     }
     if (isset($this->options['hide-shortlink']) && $this->options['hide-shortlink']) {
         remove_action('wp_head', 'wp_shortlink_wp_head');
         remove_action('template_redirect', 'wp_shortlink_header');
     }
     if (isset($this->options['hide-feedlinks']) && $this->options['hide-feedlinks']) {
         // @todo: add option to display just normal feed and hide comment feed.
         remove_action('wp_head', 'feed_links', 2);
         remove_action('wp_head', 'feed_links_extra', 3);
     }
     if (isset($this->options['disable-date']) && $this->options['disable-date'] || isset($this->options['disable-author']) && $this->options['disable-author'] || isset($this->options['disable-post_formats']) && $this->options['disable-post_formats']) {
         add_action('wp', array($this, 'archive_redirect'));
     }
     if (isset($this->options['redirectattachment']) && $this->options['redirectattachment']) {
         add_action('template_redirect', array($this, 'attachment_redirect'), 1);
     }
     if (isset($this->options['trailingslash']) && $this->options['trailingslash']) {
         add_filter('user_trailingslashit', array($this, 'add_trailingslash'), 10, 2);
     }
     if (isset($this->options['cleanpermalinks']) && $this->options['cleanpermalinks']) {
         add_action('template_redirect', array($this, 'clean_permalink'), 1);
     }
     if (isset($this->options['cleanreplytocom']) && $this->options['cleanreplytocom']) {
         add_filter('comment_reply_link', array($this, 'remove_reply_to_com'));
     }
     add_filter('the_content_feed', array($this, 'embed_rssfooter'));
     add_filter('the_excerpt_rss', array($this, 'embed_rssfooter_excerpt'));
     if (isset($this->options['forcerewritetitle']) && $this->options['forcerewritetitle']) {
         add_action('get_header', array($this, 'force_rewrite_output_buffer'));
         add_action('wp_footer', array($this, 'flush_cache'));
     }
     if (isset($this->options['title_test']) && $this->options['title_test']) {
         add_filter('wpseo_title', array($this, 'title_test_helper'));
     }
     if (isset($_GET['replytocom'])) {
         remove_action('wp_head', 'wp_no_robots');
         add_action('template_redirect', array($this, 'replytocom_redirect'), 1);
     }
 }
Ejemplo n.º 14
0
<?php

/**
 * @package Admin
 */
if (!defined('WPSEO_VERSION')) {
    header('HTTP/1.0 403 Forbidden');
    die;
}
global $wpseo_admin_pages;
$options = get_wpseo_options();
?>
<div class="wrap">
<?php 
if (isset($_GET['updated']) && $_GET['updated'] == 'true' || isset($_GET['settings-updated']) && $_GET['settings-updated'] == 'true') {
    $msg = __('Settings updated', 'wordpress-seo');
    echo '<div id="message" style="width:94%;" class="message updated"><p><strong>' . $msg . '.</strong></p></div>';
}
?>
<a href="http://yoast.com/">
	<div id="top yoast-icon" style="background: url('<?php 
echo WPSEO_URL;
?>
images/wordpress-SEO-32x32.png') no-repeat;"
		 class="icon32"><br/></div>
</a>

<h2 id="wpseo-title"><?php 
_e("Yoast WordPress SEO: Titles &amp; Metas", 'wordpress-seo');
?>
</h2>
Ejemplo n.º 15
0
 /**
  * Build a sub-sitemap for a specific taxonomy -- example.com/tax-sitemap.xml
  *
  * @param string $taxonomy Registered taxonomy's slug
  */
 function build_tax_map($taxonomy)
 {
     $options = get_wpseo_options();
     if (isset($options['taxonomies-' . $taxonomy->name . '-not_in_sitemap']) && $options['taxonomies-' . $taxonomy->name . '-not_in_sitemap'] || in_array($taxonomy, array('link_category', 'nav_menu', 'post_format')) || apply_filters('wpseo_sitemap_exclude_taxonomy', false, $taxonomy->name)) {
         $this->bad_sitemap = true;
         return;
     }
     global $wpdb;
     $output = '';
     $steps = 25;
     $n = (int) get_query_var('sitemap_n');
     $offset = $n > 1 ? ($n - 1) * $this->max_entries : 0;
     $total = $offset + $this->max_entries;
     $terms = get_terms($taxonomy->name, array('hide_empty' => true));
     $terms = array_splice($terms, $offset, $steps);
     foreach ($terms as $c) {
         $url = array();
         if (wpseo_get_term_meta($c, $c->taxonomy, 'noindex') && !in_array(wpseo_get_term_meta($c, $c->taxonomy, 'sitemap_include'), array('always', '-'))) {
             continue;
         }
         if (wpseo_get_term_meta($c, $c->taxonomy, 'sitemap_include') == 'never') {
             continue;
         }
         $url['loc'] = wpseo_get_term_meta($c, $c->taxonomy, 'canonical');
         if (!$url['loc']) {
             $url['loc'] = get_term_link($c, $c->taxonomy);
             if (isset($options['trailingslash']) && $options['trailingslash']) {
                 $url['loc'] = trailingslashit($url['loc']);
             }
         }
         if ($c->count > 10) {
             $url['pri'] = 0.6;
         } else {
             if ($c->count > 3) {
                 $url['pri'] = 0.4;
             } else {
                 $url['pri'] = 0.2;
             }
         }
         // Grab last modified date
         $sql = $wpdb->prepare("SELECT MAX(p.post_modified_gmt) AS lastmod\n\t\t\t\t\tFROM\t{$wpdb->posts} AS p\n\t\t\t\t\tINNER JOIN {$wpdb->term_relationships} AS term_rel\n\t\t\t\t\tON\t\tterm_rel.object_id = p.ID\n\t\t\t\t\tINNER JOIN {$wpdb->term_taxonomy} AS term_tax\n\t\t\t\t\tON\t\tterm_tax.term_taxonomy_id = term_rel.term_taxonomy_id\n\t\t\t\t\tAND\t\tterm_tax.taxonomy = %s\n\t\t\t\t\tAND\t\tterm_tax.term_id = %d\n\t\t\t\t\tWHERE\tp.post_status IN ('publish','inherit')\n\t\t\t\t\tAND\t\tp.post_password = ''", $c->taxonomy, $c->term_id);
         $url['mod'] = $wpdb->get_var($sql);
         $url['chf'] = 'weekly';
         $output .= $this->sitemap_url($url);
     }
     if (empty($output)) {
         $this->bad_sitemap = true;
         return;
     }
     $this->sitemap = '<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ';
     $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 . '</urlset>';
 }
Ejemplo n.º 16
0
 /**
  * Take the links array and return a full breadcrumb string.
  *
  * Each element of the links array can either have one of these keys:
  *       "id"            for post types;
  *    "ptarchive"  for a post type archive;
  *    "term"         for a taxonomy term.
  * If either of these 3 are set, the url and text are retrieved. If not, url and text have to be set.
  *
  * @link http://support.google.com/webmasters/bin/answer.py?hl=en&answer=185417 Google documentation on RDFA
  *
  * @param array  $links   The links that should be contained in the breadcrumb.
  * @param string $wrapper The wrapping element for the entire breadcrumb path.
  * @param string $element The wrapping element for each individual link.
  * @return string
  */
 function create_breadcrumbs_string($links, $wrapper = 'span', $element = 'span')
 {
     global $paged;
     $opt = get_wpseo_options();
     $sep = isset($opt['breadcrumbs-sep']) && $opt['breadcrumbs-sep'] != '' ? $opt['breadcrumbs-sep'] : '&raquo;';
     $output = '';
     foreach ($links as $i => $link) {
         if (!empty($output)) {
             $output .= " {$sep} ";
         }
         if (isset($link['id'])) {
             $link['url'] = get_permalink($link['id']);
             $link['text'] = wpseo_get_value('bctitle', $link['id']);
             if (empty($link['text'])) {
                 $link['text'] = strip_tags(get_the_title($link['id']));
             }
             $link['text'] = apply_filters('wp_seo_get_bc_title', $link['text'], $link['id']);
         }
         if (isset($link['term'])) {
             $bctitle = wpseo_get_term_meta($link['term'], $link['term']->taxonomy, 'bctitle');
             if (!$bctitle) {
                 $bctitle = $link['term']->name;
             }
             $link['url'] = get_term_link($link['term']);
             $link['text'] = $bctitle;
         }
         if (isset($link['ptarchive'])) {
             if (isset($opt['bctitle-ptarchive-' . $link['ptarchive']]) && '' != $opt['bctitle-ptarchive-' . $link['ptarchive']]) {
                 $archive_title = $opt['bctitle-ptarchive-' . $link['ptarchive']];
             } else {
                 $post_type_obj = get_post_type_object($link['ptarchive']);
                 $archive_title = $post_type_obj->labels->menu_name;
             }
             $link['url'] = get_post_type_archive_link($link['ptarchive']);
             $link['text'] = $archive_title;
         }
         $element = apply_filters('wpseo_breadcrumb_single_link_wrapper', $element);
         $link_output = '<' . $element . ' typeof="v:Breadcrumb">';
         if (isset($link['url']) && ($i < count($links) - 1 || $paged)) {
             $link_output .= '<a href="' . esc_attr($link['url']) . '" rel="v:url" property="v:title">' . $link['text'] . '</a>';
         } else {
             if (isset($opt['breadcrumbs-boldlast']) && $opt['breadcrumbs-boldlast']) {
                 $link_output .= '<strong class="breadcrumb_last" property="v:title">' . $link['text'] . '</strong>';
             } else {
                 $link_output .= '<span class="breadcrumb_last" property="v:title">' . $link['text'] . '</span>';
             }
         }
         $link_output .= '</' . $element . '>';
         $output .= apply_filters('wpseo_breadcrumb_single_link', $link_output, $link);
     }
     $id = apply_filters('wpseo_breadcrumb_output_id', false);
     if (!empty($id)) {
         $id = ' id="' . $id . '"';
     }
     $class = apply_filters('wpseo_breadcrumb_output_class', false);
     if (!empty($class)) {
         $class = ' class="' . $class . '"';
     }
     $wrapper = apply_filters('wpseo_breadcrumb_output_wrapper', $wrapper);
     return apply_filters('wpseo_breadcrumb_output', '<' . $wrapper . $id . $class . ' xmlns:v="http://rdf.data-vocabulary.org/#">' . $output . '</' . $wrapper . '>');
 }
Ejemplo n.º 17
0
/**
 * Generate an HTML sitemap
 *
 * @param array $atts The attributes passed to the shortcode.
 *
 * @return string
 */
function wpseo_sitemap_handler($atts)
{
    global $wpdb;
    $atts = shortcode_atts(array('authors' => true, 'pages' => true, 'posts' => true, 'archives' => true), $atts);
    $display_authors = $atts['authors'] === 'no' ? false : true;
    $display_pages = $atts['pages'] === 'no' ? false : true;
    $display_posts = $atts['posts'] === 'no' ? false : true;
    $display_archives = $atts['archives'] === 'no' ? false : true;
    $options = get_wpseo_options();
    // Delete the transient if any of these are no
    if ($display_authors === 'no' || $display_pages === 'no' || $display_posts === 'no') {
        delete_transient('html-sitemap');
    }
    // Get any existing copy of our transient data
    if (false !== ($output = get_transient('html-sitemap'))) {
        // $output .= 'CACHE'; // debug
        // return $output;
    }
    $output = '';
    // create author list
    if ($display_authors) {
        $output .= '<h2 id="authors">' . __('Authors', 'wordpress-seo') . '</h2><ul>';
        // use echo => false b/c shortcode format screws up
        $author_list = wp_list_authors(array('exclude_admin' => false, 'echo' => false));
        $output .= $author_list;
        $output .= '</ul>';
    }
    // create page list
    if ($display_pages) {
        $output .= '<h2 id="pages">' . __('Pages', 'wordpress-seo') . '</h2><ul>';
        // Some query magic to retrieve all pages that should be excluded, while preventing noindex pages that are set to
        // "always" include in HTML sitemap from being excluded.
        $exclude_query = "SELECT DISTINCT( post_id ) FROM {$wpdb->postmeta}\n\t\t\t\t\t\t\t\t\t\t\t\tWHERE ( ( meta_key = '_yoast_wpseo_sitemap-html-include' AND meta_value = 'never' )\n\t\t\t\t\t\t\t\t\t\t\t\t  OR ( meta_key = '_yoast_wpseo_meta-robots-noindex' AND meta_value = 1 ) )\n\t\t\t\t\t\t\t\t\t\t\t\tAND post_id NOT IN\n\t\t\t\t\t\t\t\t\t\t\t\t\t( SELECT pm2.post_id FROM {$wpdb->postmeta} pm2\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE pm2.meta_key = '_yoast_wpseo_sitemap-html-include' AND pm2.meta_value = 'always')\n\t\t\t\t\t\t\t\t\t\t\t\tORDER BY post_id ASC";
        $excluded_pages = $wpdb->get_results($exclude_query);
        $exclude = array();
        foreach ($excluded_pages as $page) {
            $exclude[] = $page->post_id;
        }
        unset($excluded_pages, $page);
        /**
         * This filter allows excluding more pages should you wish to from the HTML sitemap.
         */
        $exclude = implode(',', apply_filters('wpseo_html_sitemap_page_exclude', $exclude));
        $page_list = wp_list_pages(array('exclude' => $exclude, 'title_li' => '', 'echo' => false));
        $output .= $page_list;
        $output .= '</ul>';
    }
    // create post list
    if ($display_posts) {
        $output .= '<h2 id="posts">' . __('Posts', 'wordpress-seo') . '</h2><ul>';
        // Add categories you'd like to exclude in the exclude here
        // possibly have this controlled by shortcode params
        $cats = get_categories('exclude=');
        foreach ($cats as $cat) {
            $output .= "<li><h3>" . $cat->cat_name . "</h3>";
            $output .= "<ul>";
            $args = array('post_type' => 'post', 'post_status' => 'publish', 'posts_per_page' => -1, 'cat' => $cat->cat_ID, 'meta_query' => array('relation' => 'OR', array('key' => '_yoast_wpseo_meta-robots-noindex', 'value' => '', 'compare' => 'NOT EXISTS'), array('key' => '_yoast_wpseo_meta-robots-noindex', 'value' => 1, 'compare' => '!='), array('key' => '_yoast_wpseo_sitemap-html-include', 'value' => 'always', 'compare' => '=')));
            $posts = get_posts($args);
            foreach ($posts as $post) {
                $category = get_the_category($post->ID);
                // Only display a post link once, even if it's in multiple categories
                if ($category[0]->cat_ID == $cat->cat_ID) {
                    $output .= '<li><a href="' . get_permalink($post->ID) . '">' . get_the_title($post->ID) . '</a></li>';
                }
            }
            $output .= "</ul>";
            $output .= "</li>";
        }
    }
    $output .= '</ul>';
    // get all public non-builtin post types
    $args = array('public' => true, '_builtin' => false);
    $post_types = get_post_types($args, 'object');
    // create an noindex array of post types and taxonomies
    $noindex = array();
    foreach ($options as $key => $value) {
        if (strpos($key, 'noindex-') === 0 && $value == 'on') {
            $noindex[] = $key;
        }
    }
    // create custom post type list
    foreach ($post_types as $post_type) {
        if (!in_array('noindex-' . $post_type->name, $noindex)) {
            $output .= '<h2 id="' . $post_type->name . '">' . __($post_type->label, 'wordpress-seo') . '</h2><ul>';
            $output .= create_type_sitemap_template($post_type);
            $output .= '</ul>';
        }
    }
    // $output = '';
    // create archives list
    if ($display_archives) {
        $output .= '<h2 id="archives">' . __('Archives', 'wordpress-seo') . '</h2><ul>';
        foreach ($post_types as $post_type) {
            if ($post_type->has_archive && !in_array('noindex-ptarchive-' . $post_type->name, $noindex)) {
                $output .= '<a href="' . get_post_type_archive_link($post_type->name) . '">' . $post_type->labels->name . '</a>';
                $output .= create_type_sitemap_template($post_type);
            }
        }
        $output .= '</ul>';
    }
    set_transient('html-sitemap', $output, 60);
    return $output;
}
Ejemplo n.º 18
0
 private function title()
 {
     global $post, $wp_query;
     if (empty($post) && is_singular()) {
         $post = $wp_query->get_queried_object();
     }
     $options = get_wpseo_options();
     if (is_home() && 'posts' == get_option('show_on_front')) {
         if (isset($options['title-home']) && $options['title-home'] != '') {
             $title = wpseo_replace_vars($options['title-home'], array());
         } else {
             $title = get_bloginfo('name');
         }
     } else {
         if (is_home() && 'posts' != get_option('show_on_front')) {
             // For some reason, in some instances is_home returns true for the front page when page_for_posts is not set.
             if (get_option('page_for_posts') == 0) {
                 $post = get_post(get_option('page_on_front'));
             } else {
                 $post = get_post(get_option('page_for_posts'));
             }
             $fixed_title = wpseo_get_value('title');
             if ($fixed_title) {
                 $title = $fixed_title;
             } else {
                 if (isset($options['title-' . $post->post_type]) && !empty($options['title-' . $post->post_type])) {
                     $title = wpseo_replace_vars($options['title-' . $post->post_type], (array) $post);
                 } else {
                     $title = get_bloginfo('name');
                 }
             }
         } else {
             if (is_singular()) {
                 $fixed_title = wpseo_get_value('title');
                 if ($fixed_title) {
                     $title = $fixed_title;
                 } else {
                     if (isset($options['title-' . $post->post_type]) && !empty($options['title-' . $post->post_type])) {
                         $title = wpseo_replace_vars($options['title-' . $post->post_type], (array) $post);
                     } else {
                         $title = get_the_title();
                         $title = apply_filters('single_post_title', $title);
                     }
                 }
             } else {
                 if (is_category() || is_tag() || is_tax()) {
                     $term = $wp_query->get_queried_object();
                     $title = trim(wpseo_get_term_meta($term, $term->taxonomy, 'title'));
                     if (!$title || empty($title)) {
                         if (isset($options['title-' . $term->taxonomy]) && !empty($options['title-' . $term->taxonomy])) {
                             $title = wpseo_replace_vars($options['title-' . $term->taxonomy], (array) $term);
                         } else {
                             if (is_category()) {
                                 $title = single_cat_title('', false);
                             } else {
                                 if (is_tag()) {
                                     $title = single_tag_title('', false);
                                 } else {
                                     if (is_tax()) {
                                         if (function_exists('single_term_title')) {
                                             $title = single_term_title('', false);
                                         } else {
                                             $term = $wp_query->get_queried_object();
                                             $title = $term->name;
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 } else {
                     if (is_search()) {
                         if (isset($options['title-search']) && !empty($options['title-search'])) {
                             $title = wpseo_replace_vars($options['title-search'], (array) $wp_query->get_queried_object());
                         } else {
                             $title = __('Search for "') . get_search_query() . '"';
                         }
                     } else {
                         if (is_author()) {
                             $author_id = get_query_var('author');
                             $title = get_the_author_meta('wpseo_title', $author_id);
                             if (empty($title)) {
                                 if (isset($options['title-author']) && !empty($options['title-author'])) {
                                     $title = wpseo_replace_vars($options['title-author'], array());
                                 } else {
                                     $title = get_the_author_meta('display_name', $author_id);
                                 }
                             }
                         } else {
                             if (is_post_type_archive()) {
                                 $post_type = get_post_type();
                                 if (isset($options['title-ptarchive-' . $post_type]) && '' != $options['title-ptarchive-' . $post_type]) {
                                     return $options['title-ptarchive-' . $post_type];
                                 } else {
                                     $post_type_obj = get_post_type_object($post_type);
                                     $title = $post_type_obj->labels->menu_name;
                                 }
                             } else {
                                 if (is_archive()) {
                                     if (isset($options['title-archive']) && !empty($options['title-archive'])) {
                                         $title = wpseo_replace_vars($options['title-archive'], array('post_title' => $title));
                                     } else {
                                         if (is_month()) {
                                             $title = single_month_title(' ', false) . ' ' . __('Archives');
                                         } else {
                                             if (is_year()) {
                                                 $title = get_query_var('year') . ' ' . __('Archives');
                                             }
                                         }
                                     }
                                 } else {
                                     if (is_404()) {
                                         if (isset($options['title-404']) && !empty($options['title-404'])) {
                                             $title = wpseo_replace_vars($options['title-404'], array('post_title' => $title));
                                         } else {
                                             $title = __('Page not found');
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     echo "<meta property='og:title' content='" . esc_attr(strip_tags(stripslashes($title))) . "'/>\n";
 }
Ejemplo n.º 19
0
 function metadesc($echo = true)
 {
     if (get_query_var('paged') && get_query_var('paged') > 1) {
         return;
     }
     global $post, $wp_query, $wpseo_front;
     $options = get_wpseo_options();
     $metadesc = '';
     if (is_singular()) {
         $metadesc = wpseo_get_value('metadesc_' . $this->selectede_lang);
         if ($metadesc == '' || !$metadesc) {
             if (isset($options['metadesc-' . $post->post_type]) && $options['metadesc-' . $post->post_type] != '') {
                 $metadesc = $this->etm_wpseo_replace_vars($options['metadesc-' . $post->post_type], (array) $post);
             }
         }
     } else {
         if (is_search()) {
             $metadesc = '';
         } else {
             if ($wpseo_front->is_home_posts_page() && isset($options['metadesc-home'])) {
                 $metadesc = $this->etm_wpseo_replace_vars($options['metadesc-home'], array());
             } else {
                 if ($wpseo_front->is_posts_page()) {
                     $metadesc = $this->etm_wpseo_replace_vars('metadesc_' . $this->selectede_lang, get_option('page_for_posts'));
                     if (($metadesc == '' || !$metadesc) && isset($options['metadesc-' . $page->post_type])) {
                         $page = get_post(get_option('page_for_posts'));
                         $metadesc = $this->etm_wpseo_replace_vars($options['metadesc-' . $page->post_type], (array) $page);
                     }
                 } else {
                     if ($wpseo_front->is_home_static_page()) {
                         global $post;
                         $metadesc = wpseo_get_value('metadesc_' . $this->selectede_lang);
                         if (($metadesc == '' || !$metadesc) && isset($options['metadesc-' . $post->post_type])) {
                             $metadesc = $this->etm_wpseo_replace_vars($options['metadesc-' . $post->post_type], (array) $post);
                         }
                     } else {
                         if (is_category() || is_tag() || is_tax()) {
                             $term = $wp_query->get_queried_object();
                             $metadesc = wpseo_get_term_meta($term, $term->taxonomy, 'desc');
                             if (!$metadesc && isset($options['metadesc-' . $term->taxonomy])) {
                                 $metadesc = wpseo_replace_vars($options['metadesc-' . $term->taxonomy], (array) $term);
                             }
                         } else {
                             if (is_author()) {
                                 $author_id = get_query_var('author');
                                 $metadesc = get_the_author_meta('wpseo_metadesc', $author_id);
                                 if (!$metadesc && isset($options['metadesc-author'])) {
                                     $metadesc = wpseo_replace_vars($options['metadesc-author'], (array) $wp_query->get_queried_object());
                                 }
                             } else {
                                 if (function_exists('is_post_type_archive') && is_post_type_archive()) {
                                     $post_type = get_post_type();
                                     if (isset($options['metadesc-ptarchive-' . $post_type]) && '' != $options['metadesc-ptarchive-' . $post_type]) {
                                         $metadesc = $options['metadesc-ptarchive-' . $post_type];
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     $metadesc = apply_filters('wpseo_metadesc', trim($metadesc));
     if ($echo) {
         if (!empty($metadesc)) {
             echo '<meta name="description" content="' . esc_attr(strip_tags(stripslashes($metadesc))) . '"/>' . "\n";
         } else {
             if (current_user_can('manage_options') && is_singular()) {
                 echo '<!-- ' . __('Admin only notice: this page doesn\'t show a meta description because it doesn\'t have one, either write it for this page specifically or go into the SEO -> Titles menu and set up a template.', 'wordpress-seo') . ' -->' . "\n";
             }
         }
     } else {
         return $metadesc;
     }
 }
Ejemplo n.º 20
0
/**
 * Used to load the required files on the plugins_loaded hook, instead of immediately.
 */
function wpseo_admin_init()
{
    $options = get_wpseo_options();
    if (isset($_GET['wpseo_restart_tour'])) {
        unset($options['ignore_tour']);
        update_option('wpseo', $options);
    }
    if (isset($options['yoast_tracking']) && $options['yoast_tracking']) {
        require WPSEO_PATH . 'admin/class-tracking.php';
    }
    require WPSEO_PATH . 'admin/class-admin.php';
    global $pagenow;
    if (in_array($pagenow, array('edit.php', 'post.php', 'post-new.php'))) {
        require WPSEO_PATH . 'admin/class-metabox.php';
        if (isset($options['opengraph']) && $options['opengraph']) {
            require WPSEO_PATH . 'admin/class-opengraph-admin.php';
        }
    }
    if (in_array($pagenow, array('edit-tags.php'))) {
        require WPSEO_PATH . 'admin/class-taxonomy.php';
    }
    if (in_array($pagenow, array('admin.php'))) {
        require WPSEO_PATH . 'admin/class-config.php';
    }
    if (!isset($options['yoast_tracking']) || (!isset($options['ignore_tour']) || !$options['ignore_tour'])) {
        require WPSEO_PATH . 'admin/class-pointers.php';
    }
    if (isset($options['enablexmlsitemap']) && $options['enablexmlsitemap']) {
        require WPSEO_PATH . 'admin/class-sitemaps-admin.php';
    }
}
Ejemplo n.º 21
0
 function page_title($postid)
 {
     $fixed_title = wpseo_get_value('title', $postid);
     if ($fixed_title) {
         return $fixed_title;
     } else {
         $post = get_post($postid);
         $options = get_wpseo_options();
         if (isset($options['title-' . $post->post_type]) && !empty($options['title-' . $post->post_type])) {
             return wpseo_replace_vars($options['title-' . $post->post_type], (array) $post);
         } else {
             return wpseo_replace_vars('%%title%%', (array) $post);
         }
     }
 }
Ejemplo n.º 22
0
 /**
  * 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.
  *
  * @todo Potentially schedule a cron event instead so that pinging runs in the background.
  */
 function status_transition($new_status, $old_status, $post)
 {
     if ($new_status != 'publish') {
         return;
     }
     wp_cache_delete('lastpostmodified:gmt:' . $post->post_type, 'timeinfo');
     // #17455
     $options = get_wpseo_options();
     if (isset($options['post_types-' . $post->post_type . '-not_in_sitemap']) && $options['post_types-' . $post->post_type . '-not_in_sitemap']) {
         return;
     }
     if (WP_CACHE) {
         wp_schedule_single_event(time(), 'wpseo_hit_sitemap_index');
     }
     if (wpseo_get_value('sitemap-include', $post->ID) != 'never') {
         $this->ping_search_engines();
     }
 }
Ejemplo n.º 23
0
 /**
  * Displays the image for Twitter
  *
  * Only used when OpenGraph is inactive.
  */
 public function image()
 {
     global $post;
     if (function_exists('has_post_thumbnail') && has_post_thumbnail($post->ID)) {
         $featured_img = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), apply_filters('wpseo_opengraph_image_size', 'medium'));
         if ($featured_img) {
             $img = apply_filters('wpseo_opengraph_image', $featured_img[0]);
             echo "<meta name='twitter:image' content='" . esc_attr($img) . "'/>\n";
         }
     } else {
         $options = get_wpseo_options();
         if (isset($options['og_frontpage_image']) && !empty($options['og_frontpage_image'])) {
             echo "<meta name='twitter:image' content='" . esc_attr($options['og_frontpage_image']) . "'/>\n";
         }
     }
 }
 /**
  * Create a hidden input field
  */
 function hidden($id, $option = '')
 {
     if ($option == '') {
         $options = get_wpseo_options();
         $option = !empty($option) ? $option : $this->currentoption;
     } else {
         if (function_exists('is_network_admin') && is_network_admin()) {
             $options = get_site_option($option);
         } else {
             $options = get_option($option);
         }
     }
     if (!isset($options[$id])) {
         $options[$id] = '';
     }
     return '<input type="hidden" id="hidden_' . $id . '" name="' . $option . '[' . $id . ']" value="' . $options[$id] . '"/>';
 }
Ejemplo n.º 25
0
 /**
  * Adds the RSS footer (or header) to the excerpt RSS feed item.
  *
  * @param string $content Feed item excerpt.
  * @return string
  */
 function embed_rssfooter_excerpt($content)
 {
     if (is_feed()) {
         $options = get_wpseo_options();
         if (isset($options['rssbefore']) && !empty($options['rssbefore'])) {
             $content = "<p>" . $this->rss_replace_vars($options['rssbefore']) . "</p><p>" . $content . "</p>";
         }
         if (isset($options['rssafter']) && !empty($options['rssafter'])) {
             $content = "<p>" . $content . "</p><p>" . $this->rss_replace_vars($options['rssafter']) . "</p>";
         }
     }
     return $content;
 }
Ejemplo n.º 26
0
/**
 * Adds tracking parameters for WP SEO settings. Outside of the main class as the class could also be in use in other plugins.
 *
 * @param array $options
 * @return array
 */
function wpseo_tracking_additions($options)
{
    $opt = get_wpseo_options();
    $options['wpseo'] = array('xml_sitemaps' => isset($opt['enablexmlsitemap']) ? 1 : 0, 'force_rewrite' => isset($opt['forcerewritetitle']) ? 1 : 0, 'opengraph' => isset($opt['opengraph']) ? 1 : 0, 'twitter' => isset($opt['twitter']) ? 1 : 0, 'strip_category_base' => isset($opt['stripcategorybase']) ? 1 : 0, 'on_front' => get_option('show_on_front'));
    return $options;
}
Ejemplo n.º 27
0
        function wpseo_user_profile($user)
        {
            if (!current_user_can('edit_users')) {
                return;
            }
            $options = get_wpseo_options();
            ?>
				<h3 id="wordpress-seo">WordPress SEO settings</h3>
				<table class="form-table">
					<tr>
						<th>Title to use for Author page</th>
						<td><input class="regular-text" type="text" name="wpseo_author_title" value="<?php 
            echo esc_attr(get_the_author_meta('wpseo_title', $user->ID));
            ?>
"/></td>
					</tr>
					<tr>
						<th>Meta description to use for Author page</th>
						<td><textarea rows="3" cols="30" name="wpseo_author_metadesc"><?php 
            echo esc_html(get_the_author_meta('wpseo_metadesc', $user->ID));
            ?>
</textarea></td>
					</tr>
			<?php 
            if (isset($options['usemetakeywords']) && $options['usemetakeywords']) {
                ?>
					<tr>
						<th>Meta keywords to use for Author page</th>
						<td><input class="regular-text" type="text" name="wpseo_author_metakey" value="<?php 
                echo esc_attr(get_the_author_meta('wpseo_metakey', $user->ID));
                ?>
"/></td>
					</tr>
			<?php 
            }
            ?>
				</table>
				<br/><br/>
			<?php 
        }
/**
 * Generate an HTML sitemap
 *
 * @param array $atts The attributes passed to the shortcode.
 *
 * @return string
 */
function wpseo_sitemap_handler($atts)
{
    $atts = shortcode_atts(array('authors' => true, 'pages' => true, 'posts' => true, 'archives' => true), $atts);
    $display_authors = $atts['authors'] === 'no' ? false : true;
    $display_pages = $atts['pages'] === 'no' ? false : true;
    $display_posts = $atts['posts'] === 'no' ? false : true;
    $display_archives = $atts['archives'] === 'no' ? false : true;
    $options = get_wpseo_options();
    // Delete the transient if any of these are no
    if ($display_authors === 'no' || $display_pages === 'no' || $display_posts === 'no') {
        delete_transient('html-sitemap');
    }
    // Get any existing copy of our transient data
    if (false !== ($output = get_transient('html-sitemap'))) {
        // $output .= 'CACHE'; // debug
        // return $output;
    }
    $output = '';
    // create author list
    if ($display_authors) {
        $output .= '<h2 id="authors">' . __('Authors', 'wordpress-seo') . '</h2><ul>';
        // use echo => false b/c shortcode format screws up
        $author_list = wp_list_authors(array('exclude_admin' => false, 'echo' => false));
        $output .= $author_list;
        $output .= '</ul>';
    }
    // create page list
    if ($display_pages) {
        $output .= '<h2 id="pages">' . __('Pages', 'wordpress-seo') . '</h2><ul>';
        // Add pages you'd like to exclude in the exclude here
        // possibly have this controlled by shortcode params
        $page_list = wp_list_pages(array('exclude' => '', 'title_li' => '', 'echo' => false));
        $output .= $page_list;
        $output .= '</ul>';
    }
    // create post list
    if ($display_posts) {
        $output .= '<h2 id="posts">' . __('Posts', 'wordpress-seo') . '</h2><ul>';
        // Add categories you'd like to exclude in the exclude here
        // possibly have this controlled by shortcode params
        $cats = get_categories('exclude=');
        foreach ($cats as $cat) {
            $output .= "<li>" . $cat->cat_name;
            $output .= "<ul>";
            $args = array('post_type' => 'post', 'post_status' => 'publish', 'posts_per_page' => -1, 'cat' => $cat->cat_ID, 'meta_query' => array('relation' => 'OR', array('key' => '_yoast_wpseo_meta-robots-noindex', 'value' => '', 'compare' => 'NOT EXISTS'), array('key' => '_yoast_wpseo_meta-robots-noindex', 'value' => '1', 'compare' => '!='), array('key' => '_yoast_wpseo_sitemap-html-include', 'value' => 'always', 'compare' => '=')));
            $posts = get_posts($args);
            foreach ($posts as $post) {
                $category = get_the_category($post->ID);
                // Only display a post link once, even if it's in multiple categories
                if ($category[0]->cat_ID == $cat->cat_ID) {
                    $output .= '<li><a href="' . get_permalink($post->ID) . '">' . get_the_title($post->ID) . '</a></li>';
                }
            }
            $output .= "</ul>";
            $output .= "</li>";
        }
    }
    $output .= '</ul>';
    // get all public non-builtin post types
    $args = array('public' => true, '_builtin' => false);
    $post_types = get_post_types($args, 'object');
    // create an noindex array of post types and taxonomies
    $noindex = array();
    foreach ($options as $key => $value) {
        if (strpos($key, 'noindex-') === 0 && $value == 'on') {
            $noindex[] = $key;
        }
    }
    // create custom post type list
    foreach ($post_types as $post_type) {
        if (!in_array('noindex-' . $post_type->name, $noindex)) {
            $output .= '<h2 id="' . $post_type->name . '">' . __($post_type->label, 'wordpress-seo') . '</h2><ul>';
            $output .= create_type_sitemap_template($post_type);
            $output .= '</ul>';
        }
    }
    // $output = '';
    // create archives list
    if ($display_archives) {
        $output .= '<h2 id="archives">' . __('Archives', 'wordpress-seo') . '</h2><ul>';
        foreach ($post_types as $post_type) {
            if ($post_type->has_archive && !in_array('noindex-ptarchive-' . $post_type->name, $noindex)) {
                $output .= '<a href="' . get_post_type_archive_link($post_type->name) . '">' . $post_type->labels->name . '</a>';
                $output .= create_type_sitemap_template($post_type);
            }
        }
        $output .= '</ul>';
    }
    set_transient('html-sitemap', $output, 60);
    return $output;
}
Ejemplo n.º 29
0
 /**
  * Build a sub-sitemap for a specific taxonomy -- example.com/tax-sitemap.xml
  *
  * @param string $taxonomy Registered taxonomy's slug
  */
 function build_tax_map($taxonomy)
 {
     $options = get_wpseo_options();
     if (isset($options['taxonomies-' . $taxonomy->name . '-not_in_sitemap']) && $options['taxonomies-' . $taxonomy->name . '-not_in_sitemap'] || in_array($taxonomy, array('link_category', 'nav_menu', 'post_format'))) {
         $this->bad_sitemap = true;
         return;
     }
     $terms = get_terms($taxonomy->name, array('hide_empty' => true));
     global $wpdb;
     $output = '';
     foreach ($terms as $c) {
         $url = array();
         if (wpseo_get_term_meta($c, $c->taxonomy, 'noindex') && wpseo_get_term_meta($c, $c->taxonomy, 'sitemap_include') != 'always') {
             continue;
         }
         if (wpseo_get_term_meta($c, $c->taxonomy, 'sitemap_include') == 'never') {
             continue;
         }
         $url['loc'] = wpseo_get_term_meta($c, $c->taxonomy, 'canonical');
         if (!$url['loc']) {
             $url['loc'] = get_term_link($c, $c->taxonomy);
             if (isset($options['trailingslash']) && $options['trailingslash']) {
                 $url['loc'] = trailingslashit($url['loc']);
             }
         }
         if ($c->count > 10) {
             $url['pri'] = 0.6;
         } else {
             if ($c->count > 3) {
                 $url['pri'] = 0.4;
             } else {
                 $url['pri'] = 0.2;
             }
         }
         // Grab last modified date
         $sql = "SELECT MAX(p.post_date) AS lastmod\n\t\t\t\t\tFROM\t{$wpdb->posts} AS p\n\t\t\t\t\tINNER JOIN {$wpdb->term_relationships} AS term_rel\n\t\t\t\t\tON\t\tterm_rel.object_id = p.ID\n\t\t\t\t\tINNER JOIN {$wpdb->term_taxonomy} AS term_tax\n\t\t\t\t\tON\t\tterm_tax.term_taxonomy_id = term_rel.term_taxonomy_id\n\t\t\t\t\tAND\t\tterm_tax.taxonomy = '{$c->taxonomy}'\n\t\t\t\t\tAND\t\tterm_tax.term_id = {$c->term_id}\n\t\t\t\t\tWHERE\tp.post_status = 'publish'\n\t\t\t\t\tAND\t\tp.post_password = ''";
         $url['mod'] = $wpdb->get_var($sql);
         $url['chf'] = 'weekly';
         $output .= $this->sitemap_url($url);
     }
     if (empty($output)) {
         $this->bad_sitemap = true;
         return;
     }
     $this->sitemap = '<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ';
     $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 . '</urlset>';
 }
Ejemplo n.º 30
0
 function output($post)
 {
     global $wpseo_metabox;
     $options = get_wpseo_options();
     if (is_int($post)) {
         $post = get_post($post);
     }
     if (!$post) {
         return;
     }
     if (!class_exists('DOMDocument')) {
         $output = '<div class="wpseo_msg"><p><strong>' . __('Error') . ':</strong> ' . sprintf(__("your hosting environment does not support PHP's %sDocument Object Model%s."), '<a href="http://php.net/manual/en/book.dom.php">', '</a>') . ' ' . __("To enjoy all the benefits of the page analysis feature, you'll need to (get your host to) install it.") . '</p></div>';
         return $output;
     }
     if (!wpseo_get_value('focuskw')) {
         $output = '<div class="wpseo_msg"><p><strong>' . __('Error') . ':</strong> ' . __("you have not specified a focus keyword, you'll have to enter one, then save or update this post, before this report works.") . '</p></div>';
         return $output;
     }
     $output = '<div class="wpseo_msg"><p><strong>' . __('Note') . ':</strong> ' . __('to update this page analysis, save as draft or update and check this tab again') . '.</p></div>';
     $results = '';
     $job = array();
     $sampleurl = get_sample_permalink($post->ID);
     $job["pageUrl"] = str_replace('%postname%', $sampleurl[1], $sampleurl[0]);
     $job["pageSlug"] = urldecode($post->post_name);
     $job["keyword"] = wpseo_get_value('focuskw');
     $job["keyword_folded"] = $this->strip_separators_and_fold($job["keyword"]);
     $dom = new domDocument();
     $dom->strictErrorChecking = false;
     $dom->preserveWhiteSpace = false;
     @$dom->loadHTML($post->post_content);
     $xpath = new DOMXPath($dom);
     $statistics = new TextStatistics();
     // Keyword
     $this->ScoreKeyword($job, $results);
     // Title
     if (wpseo_get_value('title')) {
         $title = wpseo_get_value('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%%';
         }
         $title = wpseo_replace_vars($title_template, (array) $post);
     }
     $this->ScoreTitle($job, $results, $title, $statistics);
     unset($title);
     // Meta description
     $description = '';
     if (wpseo_get_value('metadesc')) {
         $description = wpseo_get_value('metadesc');
     } else {
         if (isset($options['metadesc-' . $post->post_type]) && $options['metadesc-' . $post->post_type] != '') {
             $description = wpseo_replace_vars($options['metadesc-' . $post->post_type], (array) $post);
         }
     }
     $this->ScoreDescription($job, $results, $description, $wpseo_metabox->wpseo_meta_length, $statistics);
     unset($description);
     // Body
     $body = $this->GetBody($post);
     $firstp = $this->GetFirstParagraph($post);
     $this->ScoreBody($job, $results, $body, $firstp, $statistics);
     unset($body);
     unset($firstp);
     // URL
     $this->ScoreUrl($job, $results, $statistics);
     // Headings
     $headings = $this->GetHeadings($post->post_content);
     $this->ScoreHeadings($job, $results, $headings);
     unset($headings);
     // Images
     $alts = $this->GetImagesAltText($post->post_content);
     $imgs = $this->GetImageCount($dom, $xpath);
     $this->ScoreImagesAltText($job, $results, $alts, $imgs);
     unset($alts);
     unset($imgs);
     // Anchors
     $anchors = $this->GetAnchorTexts($dom, $xpath);
     $count = $this->GetAnchorCount($dom, $xpath);
     $this->ScoreAnchorTexts($job, $results, $anchors, $count);
     unset($anchors);
     unset($count);
     unset($dom);
     asort($results);
     $output .= '<table class="wpseoanalysis">';
     foreach ($results as $result) {
         $scoreval = substr($result, 0, 1);
         switch ($scoreval) {
             case 1:
             case 2:
             case 3:
                 $score = 'poor';
                 break;
             case 4:
             case 5:
             case 6:
                 $score = 'ok';
                 break;
             case 7:
             case 8:
             case 9:
                 $score = 'good';
                 break;
         }
         $analysis = substr($result, 2, strlen($result));
         $output .= '<tr><td class="score"><img alt="' . $score . '" src="' . WPSEO_URL . 'images/score_' . $score . '.png"/></td><td>' . $analysis . '</td></tr>';
     }
     $output .= '</table>';
     $output .= '<hr/>';
     $output .= '<p style="font-size: 13px;"><a href="http://yoa.st/linkdex"><img class="alignleft" style="margin: 0 10px 5px 0;" src="' . WPSEO_URL . 'images/linkdex-logo.png" alt="Linkdex"/></a>' . 'This page analysis brought to you by the collaboration of Yoast and <a href="http://yoa.st/linkdex">Linkdex</a>. <a href="http://yoa.st/linkdex">Linkdex</a> is an SEO suite that helps you optimize your site and offers you all the SEO tools you\'ll need. Yoast uses <a href="http://yoa.st/linkdex">Linkdex</a> and highly recommends you do too!' . '</p>';
     unset($results);
     unset($job);
     return $output;
 }