Skip to content

Commit

Permalink
Merge pull request #1278 from semperfiwebdesign/development
Browse files Browse the repository at this point in the history
Development to master for 2.4.2
  • Loading branch information
michaeltorbert authored Oct 4, 2017
2 parents 763b064 + 876047d commit 5f978e3
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 26 deletions.
6 changes: 3 additions & 3 deletions all_in_one_seo_pack.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Plugin Name: All In One SEO Pack
Plugin URI: https://semperplugins.com/all-in-one-seo-pack-pro-version/
Description: Out-of-the-box SEO for your WordPress blog. Features like XML Sitemaps, SEO for custom post types, SEO for blogs or business sites, SEO for ecommerce sites, and much more. More than 30 million downloads since 2007.
Version: 2.4.1.1
Version: 2.4.2
Author: Michael Torbert
Author URI: https://semperplugins.com/all-in-one-seo-pack-pro-version/
Text Domain: all-in-one-seo-pack
Expand Down Expand Up @@ -31,14 +31,14 @@
* The original WordPress SEO plugin.
*
* @package All-in-One-SEO-Pack
* @version 2.4.1.1
* @version 2.4.2
*/

if ( ! defined( 'AIOSEOPPRO' ) ) {
define( 'AIOSEOPPRO', false );
}
if ( ! defined( 'AIOSEOP_VERSION' ) ) {
define( 'AIOSEOP_VERSION', '2.4.1.1' );
define( 'AIOSEOP_VERSION', '2.4.2' );
}
global $aioseop_plugin_name;
$aioseop_plugin_name = 'All in One SEO Pack';
Expand Down
21 changes: 21 additions & 0 deletions inc/aioseop_functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -978,3 +978,24 @@ function aioseop_home_url( $path = '/' ) {
$url = apply_filters( 'aioseop_home_url', $path );
return $path === $url ? home_url( $path ) : $url;
}


if ( ! function_exists('aiosp_include_images') ) {
function aiosp_include_images() {
if ( false === apply_filters( 'aioseo_include_images_in_sitemap', true ) ) {
return false;
}

global $aioseop_options;

if( isset( $aioseop_options['modules'] ) &&
isset( $aioseop_options['modules']['aiosp_sitemap_options'] ) &&
isset( $aioseop_options['modules']['aiosp_sitemap_options']['aiosp_sitemap_images'] ) &&
'on' === $aioseop_options['modules']['aiosp_sitemap_options']['aiosp_sitemap_images']
){
return false;
}

return true;
}
}
15 changes: 15 additions & 0 deletions inc/aiosp_common.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,19 @@ static function get_upgrade_hyperlink( $location = '', $title = '', $anchor = ''
static function get_upgrade_url() {
//put build URL stuff in here
}

/**
* Check whether a url is relative and if it is, make it absolute.
*
* @param string $url URL to check.
*
* @return string
*/
static function absolutize_url( $url ) {
if ( strpos( $url, 'http' ) !== 0 && strpos( $url, '//' ) !== 0 && $url != '/' ) {
$url = home_url( $url );
}
return $url;
}

}
12 changes: 12 additions & 0 deletions inc/sitemap-xsl.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,13 @@
<thead>
<tr>
<th width="50%">URL</th>
<?php
if ( aiosp_include_images() ) {
?>
<th>Images</th>
<?php
}
?>
<th>Priority</th>
<th>Change Frequency</th>
<th>Last Change</th>
Expand Down Expand Up @@ -176,9 +182,15 @@
</xsl:if>
</xsl:for-each>
</td>
<?php
if ( aiosp_include_images() ) {
?>
<td>
<xsl:value-of select="count(image:image)"/>
</td>
<?php
}
?>
<td>
<xsl:if test="string(number(sitemap:priority))!='NaN'">
<xsl:value-of select="concat(sitemap:priority*100,'%')"/>
Expand Down
58 changes: 36 additions & 22 deletions modules/aioseop_sitemap.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ function __construct() {
'taxonomies' => __( 'Select which taxonomy archives appear in your sitemap', 'all-in-one-seo-pack' ),
'archive' => __( 'Include Date Archives in your sitemap.', 'all-in-one-seo-pack' ),
'author' => __( 'Include Author Archives in your sitemap.', 'all-in-one-seo-pack' ),
'images' => __( 'Exclude Images in your sitemap.', 'all-in-one-seo-pack' ),
'gzipped' => __( 'Create a compressed sitemap file in .xml.gz format.', 'all-in-one-seo-pack' ),
'robots' => __( 'Places a link to your Sitemap.xml into your virtual Robots.txt file.', 'all-in-one-seo-pack' ),
'rewrite' => __( 'Dynamically creates the XML sitemap instead of using a static file.', 'all-in-one-seo-pack' ),
Expand All @@ -82,6 +83,7 @@ function __construct() {
'taxonomies' => '#post-types-and-taxonomies',
'archive' => '#include-archive-pages',
'author' => '#include-archive-pages',
'images' => '#exclude-images',
'gzipped' => '#create-compressed-sitemap',
'robots' => '#link-from-virtual-robots',
'rewrite' => '#dynamically-generate-sitemap',
Expand Down Expand Up @@ -130,6 +132,7 @@ function __construct() {
),
'archive' => array( 'name' => __( 'Include Date Archive Pages', 'all-in-one-seo-pack' ) ),
'author' => array( 'name' => __( 'Include Author Pages', 'all-in-one-seo-pack' ) ),
'images' => array( 'name' => __( 'Exclude Images', 'all-in-one-seo-pack' ) ),
'gzipped' => array(
'name' => __( 'Create Compressed Sitemap', 'all-in-one-seo-pack' ),
'default' => 'On',
Expand Down Expand Up @@ -331,7 +334,6 @@ function sitemap_notices() {
return;
}

global $options;
$options = $this->options;

if ( isset( $options["{$this->prefix}indexes"] ) && 'on ' !== $options["{$this->prefix}indexes"] &&
Expand Down Expand Up @@ -2687,7 +2689,7 @@ function get_prio_from_posts( $posts, $prio_override = false, $freq_override = f
*/
private function get_images_from_term( $term ) {

if ( false === apply_filters( 'aioseo_include_images_in_sitemap', true ) ) {
if ( ! aiosp_include_images() ) {
return array();
}

Expand Down Expand Up @@ -2716,7 +2718,7 @@ private function get_images_from_term( $term ) {
*/
private function get_images_from_post( $post ) {

if ( false === apply_filters( 'aioseo_include_images_in_sitemap', true ) ) {
if ( ! aiosp_include_images() ) {
return array();
}

Expand All @@ -2737,7 +2739,7 @@ private function get_images_from_post( $post ) {
$attributes = wp_get_attachment_image_src( $post->ID );
if ( $attributes ) {
$images[] = array(
'image:loc' => $attributes[0],
'image:loc' => $this->clean_url( $attributes[0] ),
);
}

Expand All @@ -2763,23 +2765,7 @@ private function get_images_from_post( $post ) {
}
}

$total = substr_count( $content, '<img ' ) + substr_count( $content, '<IMG ' );
if ( $total > 0 ) {
$dom = new domDocument();
// Non-compliant HTML might give errors, so ignore them.
libxml_use_internal_errors( true );
$dom->loadHTML( $content );
libxml_clear_errors();
// @codingStandardsIgnoreStart
$dom->preserveWhiteSpace = false;
// @codingStandardsIgnoreEnd
$matches = $dom->getElementsByTagName( 'img' );
foreach ( $matches as $match ) {
$images[] = $match->getAttribute( 'src' );
}
}

$this->parse_content_for_images( $content, $images );
$this->parse_content_for_images( $content, $images );

if ( $images ) {
$tmp = $images;
Expand All @@ -2792,14 +2778,32 @@ private function get_images_from_post( $post ) {
$images = array();
foreach ( $tmp as $image ) {
$images[] = array(
'image:loc' => $image,
'image:loc' => $this->clean_url( $image ),
);
}
}

return $images;
}

/**
* Cleans the URL so that its acceptable in the sitemap.
*
* @param string $url The image url.
*
* @since 2.4.1
*
* @return string
*/
function clean_url( $url ) {
// remove the query string.
$url = strtok( $url, '?' );
// make the url XML-safe.
$url = htmlspecialchars( $url );
// Make the url absolute, if its relative.
$url = aiosp_common::absolutize_url( $url );
return apply_filters( 'aioseop_clean_url', $url );
}

/**
* Validate the image.
Expand All @@ -2816,13 +2820,23 @@ function is_image_valid( $image ) {
return false;
}

// make the url absolute, if its relative.
$image = aiosp_common::absolutize_url( $image );

$extn = pathinfo( wp_parse_url( $image, PHP_URL_PATH ), PATHINFO_EXTENSION );
$allowed = apply_filters( 'aioseop_allowed_image_extensions', self::$image_extensions );
// Bail if image does not refer to an image file otherwise google webmaster tools might reject the sitemap.
if ( ! in_array( $extn, $allowed, true ) ) {
return false;
}

// Bail if image refers to an external URL.
$image_host = wp_parse_url( $image, PHP_URL_HOST );
$wp_host = wp_parse_url( home_url(), PHP_URL_HOST );
if ( $image_host !== $wp_host ) {
return false;
}

return true;
}

Expand Down
2 changes: 1 addition & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=mrtor
Tags: SEO, all in one seo, WordPress SEO, Google Search Console, XML Sitemap, image seo
Requires at least: 4.0
Tested up to: 4.8
Stable tag: 2.4.1.1
Stable tag: 2.4.2
License: GPLv2 or later
Requires PHP: 5.2.4

Expand Down

0 comments on commit 5f978e3

Please sign in to comment.