anchor.
*
* @param string $link The comment link as a string.
* @return string
*/
public function remove_reply_to_com( $link ) {
return preg_replace( '/href=\'(.*(\?|&)replytocom=(\d+)#respond)/', 'href=\'#comment-$3', $link );
}
/**
* Removes unneeded query variables from the URL.
*/
public function clean_permalink() {
if ( is_robots() || get_query_var( 'sitemap' ) )
return;
global $wp_query;
$options = get_wpseo_options();
// Recreate current URL
$cururl = 'http';
if ( isset( $_SERVER["HTTPS"] ) && $_SERVER["HTTPS"] == "on" ) {
$cururl .= "s";
}
$cururl .= "://";
if ( $_SERVER["SERVER_PORT"] != "80" )
$cururl .= $_SERVER["SERVER_NAME"] . ":" . $_SERVER["SERVER_PORT"] . $_SERVER["REQUEST_URI"];
else
$cururl .= $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];
$properurl = '';
if ( is_singular() ) {
global $post;
if ( empty( $post ) )
$post = $wp_query->get_queried_object();
$properurl = get_permalink( $post->ID );
$page = get_query_var( 'page' );
if ( $page && $page != 1 ) {
$post = get_post( $post->ID );
$page_count = substr_count( $post->post_content, '' );
if ( $page > ( $page_count + 1 ) )
$properurl = user_trailingslashit( trailingslashit( $properurl ) . ( $page_count + 1 ) );
else
$properurl = user_trailingslashit( trailingslashit( $properurl ) . $page );
}
// Fix reply to comment links, whoever decided this should be a GET variable?
$result = preg_match( '/(\?replytocom=[^&]+)/', $_SERVER["REQUEST_URI"], $matches );
if ( $result )
$properurl .= str_replace( '?replytocom=', '#comment-', $matches[0] );
// Prevent cleaning out posts & page previews for people capable of viewing them
if ( isset( $_GET['preview'] ) && isset( $_GET['preview_nonce'] ) && current_user_can( 'edit_post' ) )
$properurl = '';
} else if ( is_front_page() ) {
if ( $this->is_home_posts_page() ) {
$properurl = get_bloginfo( 'url' ) . '/';
} elseif ( $this->is_home_static_page() ) {
global $post;
$properurl = get_permalink( $post->ID );
}
} else if ( is_category() || is_tag() || is_tax() ) {
$term = $wp_query->get_queried_object();
if ( is_feed() )
$properurl = get_term_feed_link( $term->term_id, $term->taxonomy );
else
$properurl = get_term_link( $term, $term->taxonomy );
} else if ( is_search() ) {
$s = preg_replace( '/(%20|\+)/', ' ', get_search_query() );
$properurl = get_bloginfo( 'url' ) . '/?s=' . rawurlencode( $s );
} else if ( is_404() ) {
if ( function_exists( 'is_multisite' ) && is_multisite() && !is_subdomain_install() && is_main_site() ) {
if ( $cururl == get_bloginfo( 'url' ) . '/blog/' || $cururl == get_bloginfo( 'url' ) . '/blog' ) {
if ( $this->is_home_static_page() )
$properurl = get_permalink( get_option( 'page_for_posts' ) );
else
$properurl = get_bloginfo( 'url' ) . '/';
}
}
}
if ( !empty( $properurl ) && $wp_query->query_vars['paged'] != 0 && $wp_query->post_count != 0 ) {
if ( is_search() ) {
$properurl = get_bloginfo( 'url' ) . '/page/' . $wp_query->query_vars['paged'] . '/?s=' . rawurlencode( get_search_query() );
} else {
$properurl = user_trailingslashit( trailingslashit( $properurl ) . 'page/' . $wp_query->query_vars['paged'] );
}
}
// Prevent cleaning out the WP Subscription managers interface for everyone
foreach ( array( 'wp-subscription-manager' ) as $get ) {
if ( isset( $_GET[$get] ) ) {
$properurl = '';
}
}
// Allow plugins to register their own variables not to clean
$whitelisted_extravars = apply_filters( 'wpseo_whitelist_permalink_vars', array() );
if ( isset( $options['cleanpermalink-googlesitesearch'] ) && $options['cleanpermalink-googlesitesearch'] ) {
// Prevent cleaning out Google Site searches
$whitelisted_extravars = array_merge( $whitelisted_extravars, array( 'q', 'cx', 'debug', 'cof', 'ie', 'sa' ) );
}
if ( isset( $options['cleanpermalink-googlecampaign'] ) && $options['cleanpermalink-googlecampaign'] ) {
// Prevent cleaning out Google Analytics campaign variables
$whitelisted_extravars = array_merge( $whitelisted_extravars, array( 'utm_campaign', 'utm_medium', 'utm_source', 'utm_content', 'utm_term' ) );
}
if ( isset( $options['cleanpermalink-extravars'] ) && strlen( $options['cleanpermalink-extravars'] ) > 0 ) {
$whitelisted_extravars = array_merge( $whitelisted_extravars, explode( ',', $options['cleanpermalink-extravars'] ) );
}
foreach ( $whitelisted_extravars as $get ) {
if ( isset( $_GET[trim( $get )] ) ) {
$properurl = '';
}
}
if ( !empty( $properurl ) && $cururl != $properurl ) {
wp_redirect( $properurl, 301 );
exit;
}
}
/**
* Replaces the possible RSS variables with their actual values.
*
* @param string $content The RSS content that should have the variables replaced.
* @return string
*/
function rss_replace_vars( $content ) {
global $post;
$authorlink = '' . get_the_author() . '';
$postlink = '' . get_the_title() . "";
$bloglink = '' . get_bloginfo( 'name' ) . '';
$blogdesclink = '' . get_bloginfo( 'name' ) . ' - ' . get_bloginfo( 'description' ) . '';
$content = stripslashes( $content );
$content = str_replace( "%%AUTHORLINK%%", $authorlink, $content );
$content = str_replace( "%%POSTLINK%%", $postlink, $content );
$content = str_replace( "%%BLOGLINK%%", $bloglink, $content );
$content = str_replace( "%%BLOGDESCLINK%%", $blogdesclink, $content );
return $content;
}
/**
* Adds the RSS footer (or header) to the full RSS feed item.
*
* @param string $content Feed item content.
* @return string
*/
function embed_rssfooter( $content ) {
if ( is_feed() ) {
$options = get_wpseo_options();
if ( isset( $options['rssbefore'] ) && !empty( $options['rssbefore'] ) ) {
$content = "" . $this->rss_replace_vars( $options['rssbefore'] ) . "
" . $content;
}
if ( isset( $options['rssafter'] ) && !empty( $options['rssafter'] ) ) {
$content .= "" . $this->rss_replace_vars( $options['rssafter'] ) . "
";
}
}
return $content;
}
/**
* 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 = "" . $this->rss_replace_vars( $options['rssbefore'] ) . "
" . $content . "
";
}
if ( isset( $options['rssafter'] ) && !empty( $options['rssafter'] ) ) {
$content = "" . $content . "
" . $this->rss_replace_vars( $options['rssafter'] ) . "
";
}
}
return $content;
}
/**
* Used in the force rewrite functionality this retrieves the output, replaces the title with the proper SEO
* title and then flushes the output.
*/
function flush_cache() {
global $wp_query, $wpseo_ob, $sep;
if ( !$wpseo_ob )
return;
$content = ob_get_contents();
$old_wp_query = $wp_query;
wp_reset_query();
$title = $this->title( '', $sep );
// Find all titles, strip them out and add the new one in within the debug marker, so it's easily identified whether a site uses force rewrite.
if ( preg_match_all( '/(.*)?<\/title>/i', $content, $matches ) ) {
$count = count( $matches[0] );
if ( $count > 0 ) {
$i = 0;
while ( $count > $i ) {
$content = str_replace( $matches[0][$i], '', $content );
$i++;
}
}
}
$content = str_replace( $this->debug_marker( false ), $this->debug_marker( false ) . "\n" . '' . $title . '', $content );
ob_end_clean();
$GLOBALS['wp_query'] = $old_wp_query;
echo $content;
}
/**
* Starts the output buffer so it can later be fixed by flush_cache()
*/
function force_rewrite_output_buffer() {
global $wpseo_ob;
$wpseo_ob = true;
ob_start();
}
/**
* Function used in testing whether the title should be force rewritten or not.
*
* @param string $title
* @return string
*/
function title_test_helper( $title ) {
global $wp_version;
if ( $_SERVER['HTTP_USER_AGENT'] == "WordPress/${wp_version}; " . get_site_url() . " - Yoast" )
return 'This is a Yoast Test Title';
return $title;
}
}
global $wpseo_front;
$wpseo_front = new WPSEO_Frontend;