Files
display-featured-image-genesis/includes/class-displayfeaturedimagegenesis-rss.php
T

128 lines
3.9 KiB
PHP
Raw Normal View History

2014-12-12 10:08:00 -05:00
<?php
/**
* @package DisplayFeaturedImageGenesis
* @author Robin Cornett <hello@robincornett.com>
* @license GPL-2.0+
* @link http://robincornett.com
* @copyright 2014 Robin Cornett Creative, LLC
*/
class Display_Featured_Image_Genesis_RSS {
/**
* Decide whether or not to add the featured image to the feed or the feed excerpt
*
* @return filter the_excerpt_rss (if summaries) or the_content_feed (full text)
2014-12-13 10:03:55 -05:00
* @since 1.5.0
2014-12-12 10:08:00 -05:00
*/
public function maybe_do_feed() {
$displaysetting = get_option( 'displayfeaturedimagegenesis' );
$feed_image = $displaysetting['feed_image'];
$rss_option = get_option( 'rss_use_excerpt' );
$post_types = array();
$skipped_types = apply_filters( 'display_featured_image_genesis_skipped_posttypes', $post_types );
2014-12-12 10:08:00 -05:00
// if the user isn't sending images to the feed, we're done
if ( ! $feed_image || ( in_array( get_post_type(), $skipped_types ) ) ) {
2014-12-12 10:08:00 -05:00
return;
}
2015-04-09 22:46:15 -04:00
// if the feed is summary, filter the excerpt
$which_filter = 'the_excerpt_rss';
$priority = 1000;
// if the feed is full text, filter the content
2014-12-12 14:05:58 -05:00
if ( '0' === $rss_option ) {
2015-04-09 22:46:15 -04:00
$which_filter = 'the_content_feed';
$priority = 15;
2014-12-12 10:08:00 -05:00
}
2015-04-09 22:46:15 -04:00
add_filter( $which_filter, array( $this, 'add_image_to_feed' ), $priority );
2014-12-12 10:08:00 -05:00
}
/**
* add the featured image to the feed, unless it already exists
* includes allowances for Send Images to RSS plugin, which processes before this
*
* @param return $content
2014-12-13 10:03:55 -05:00
* @since 1.5.0
2014-12-12 10:08:00 -05:00
*/
public function add_image_to_feed( $content ) {
2015-04-05 21:19:14 -04:00
// if the post doesn't have a thumbnail, we're done here
2015-05-23 15:42:47 -04:00
if ( ! has_post_thumbnail() && ! is_feed() ) {
2014-12-12 10:08:00 -05:00
return $content;
}
$rss_option = get_option( 'rss_use_excerpt' );
2015-04-05 21:19:14 -04:00
// first check: see if the featured image already exists in full in the content
2014-12-12 14:05:58 -05:00
$size = 'original';
2014-12-12 10:08:00 -05:00
if ( class_exists( 'SendImagesRSS' ) ) {
// Original Send Images RSS Settings
$simplify = get_option( 'sendimagesrss_simplify_feed', 0 );
$alternate_feed = get_option( 'sendimagesrss_alternate_feed', 0 );
$defaults = array(
'simplify_feed' => $simplify ? $simplify : 0,
'alternate_feed' => $alternate_feed ? $alternate_feed : 0,
);
$rss_setting = get_option( 'sendimagesrss', $defaults );
if ( '1' === $rss_option && $rss_setting['excerpt_length'] ) {
// if the newer version of Send Images to RSS is installed, bail here because it's better.
return $content;
}
2014-12-12 14:05:58 -05:00
if ( ! $rss_setting['simplify_feed'] && ( ( $rss_setting['alternate_feed'] && is_feed( 'email' ) ) || ! $rss_setting['alternate_feed'] ) ) {
$size = 'mailchimp';
2014-12-12 14:05:58 -05:00
}
2014-12-12 10:08:00 -05:00
}
2014-12-12 14:05:58 -05:00
$post_thumbnail = wp_get_attachment_image_src( get_post_thumbnail_id(), $size );
2014-12-12 10:08:00 -05:00
$image_content = strpos( $content, 'src="' . $post_thumbnail[0] );
2015-04-05 21:19:14 -04:00
// if the featured image already exists in all its glory in the content, we're done here
2014-12-12 14:05:58 -05:00
if ( false !== $image_content && '0' === $rss_option ) {
2014-12-12 10:08:00 -05:00
return $content;
}
2015-04-05 21:19:14 -04:00
// reset size to large so we don't send huge files to the feed
2014-12-12 14:05:58 -05:00
$size = 'large';
if ( class_exists( 'SendImagesRSS' ) ) {
2015-04-05 21:19:14 -04:00
// if the user is using Send Images to RSS, send the right images to the right feeds
if ( ! $rss_setting['simplify_feed'] && ( ( $rss_setting['alternate_feed'] && is_feed( 'email' ) ) || ! $rss_setting['alternate_feed'] ) ) {
2014-12-12 14:05:58 -05:00
$size = 'mailchimp';
$class = 'rss-mailchimp';
}
}
2015-04-05 21:19:14 -04:00
$align = '';
$style = 'display:block;margin:10px auto;';
$class = 'rss-featured-image';
2014-12-12 10:08:00 -05:00
2015-04-05 21:19:14 -04:00
// if the feed output is descriptions only, change image size to thumbnail with small alignment
2014-12-12 10:08:00 -05:00
if ( '1' === $rss_option ) {
$size = 'thumbnail';
$align = 'left';
2015-07-12 11:38:11 -04:00
$style = 'margin:0px 20px 20px 0px;';
2014-12-12 10:08:00 -05:00
$class = 'rss-small';
}
2015-04-05 21:19:14 -04:00
// whew. build the image!
$image = get_the_post_thumbnail(
get_the_ID(),
$size,
array(
'align' => $align,
'style' => $style,
'class' => $class,
)
);
2015-05-23 15:42:47 -04:00
$image = apply_filters( 'display_featured_image_genesis_modify_rss_image', $image );
2014-12-12 10:08:00 -05:00
2015-04-20 17:09:13 -04:00
return $image . $content;
2014-12-12 14:05:58 -05:00
2014-12-12 10:08:00 -05:00
}
2015-04-10 08:38:43 -04:00
}