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

240 lines
7.3 KiB
PHP
Raw Normal View History

2014-09-17 22:09:05 -04: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_Output {
2014-09-30 14:19:47 -04:00
/**
* set parameters for scripts, etc. to run.
*
* @since 1.1.3
*/
public function manage_output() {
2015-01-05 11:04:44 -05:00
2014-11-04 21:14:33 -05:00
$displaysetting = get_option( 'displayfeaturedimagegenesis' );
2015-01-05 11:04:44 -05:00
$skip = $displaysetting['exclude_front'];
$post_types = array();
$post_types[] = 'attachment';
$post_types[] = 'revision';
$post_types[] = 'nav_menu_item';
if ( $skip ) $post_types[] = is_front_page();
$skipped_types = apply_filters( 'display_featured_image_genesis_skipped_posttypes', $post_types );
if ( is_admin() || ( in_array( get_post_type(), $skipped_types ) ) ) {
2014-09-30 14:19:47 -04:00
return;
}
2014-11-03 14:06:24 -05:00
add_action( 'wp_enqueue_scripts', array( $this, 'load_scripts' ) );
add_filter( 'body_class', array( $this, 'add_body_class' ) );
add_filter( 'genesis_attr_entry-title', array( $this, 'filter_entry_title' ) );
2014-11-03 14:06:24 -05:00
2014-09-30 14:19:47 -04:00
}
2014-10-21 18:16:00 -04:00
2014-09-17 22:09:05 -04:00
/**
* enqueue plugin styles and scripts.
* @return enqueue
*
* @since 1.0.0
*/
public function load_scripts() {
$version = Display_Featured_Image_Genesis_Common::$version;
$item = Display_Featured_Image_Genesis_Common::get_image_variables();
2014-09-17 22:09:05 -04:00
2014-12-08 13:25:52 -05:00
//* if there is no backstretch image set, or it is too small, die
2015-01-04 16:02:16 -05:00
if ( empty( $item->backstretch ) || $item->width <= $item->medium || is_paged() ) {
return;
}
2014-12-08 13:25:52 -05:00
//* if the featured image is not part of the content, or we're not on a singular page, carry on
if ( false === $item->content || ! is_singular() ) {
wp_enqueue_style( 'displayfeaturedimage-style', plugins_url( 'includes/css/display-featured-image-genesis.css', dirname( __FILE__ ) ), array(), $version );
2014-09-17 22:09:05 -04:00
2014-12-08 13:25:52 -05:00
//* check if the image is large enough for backstretch
if ( $item->width > $item->large ) {
2014-12-08 13:25:52 -05:00
wp_enqueue_script( 'displayfeaturedimage-backstretch', plugins_url( '/includes/js/backstretch.js', dirname( __FILE__ ) ), array( 'jquery' ), $version, true );
wp_enqueue_script( 'displayfeaturedimage-backstretch-set', plugins_url( '/includes/js/backstretch-set.js', dirname( __FILE__ ) ), array( 'jquery', 'displayfeaturedimage-backstretch' ), $version, true );
2014-09-17 22:09:05 -04:00
wp_localize_script( 'displayfeaturedimage-backstretch-set', 'BackStretchVars', array(
2014-11-06 15:56:48 -05:00
'src' => esc_url( $item->backstretch[0] ),
'height' => esc_attr( $item->reduce )
2014-10-21 18:16:00 -04:00
) );
2014-09-17 22:09:05 -04:00
2014-10-16 08:53:41 -04:00
add_action( 'genesis_after_header', array( $this, 'do_backstretch_image_title' ) );
}
2014-12-08 13:25:52 -05:00
//* otherwise it's a large image.
2014-11-18 19:47:20 -05:00
elseif ( $item->width <= $item->large ) {
2015-01-05 11:04:44 -05:00
remove_action( 'genesis_before_loop', 'genesis_do_cpt_archive_title_description' );
add_action( 'genesis_before_loop', 'genesis_do_cpt_archive_title_description', 15 );
2015-01-05 11:04:44 -05:00
$hook = 'genesis_before_loop';
if ( is_singular() && ! is_page_template( 'page_blog.php' ) ) {
$hook = apply_filters( 'display_featured_image_genesis_move_large_image', $hook );
}
add_action( $hook, array( $this, 'do_large_image' ), 12 ); // works for both HTML5 and XHTML
2014-09-17 22:09:05 -04:00
}
}
}
/**
* set body class if featured images are displayed using the plugin
* @param filter $classes body_class
*
* @since 1.0.0
*/
public function add_body_class( $classes ) {
2014-10-24 10:01:43 -04:00
$item = Display_Featured_Image_Genesis_Common::get_image_variables();
2014-09-17 22:09:05 -04:00
if ( empty( $item->backstretch ) || $item->width <= $item->medium ) {
return $classes;
}
if ( false === $item->content || ! is_singular() ) {
if ( $item->width > $item->large ) {
2014-09-17 22:09:05 -04:00
$classes[] = 'has-leader';
}
elseif ( $item->width <= $item->large ) {
2014-09-17 22:09:05 -04:00
$classes[] = 'large-featured';
}
}
return $classes;
}
/**
* backstretch image title ( for images which are larger than Media Settings > Large )
2014-09-17 22:09:05 -04:00
* @return image
*
* @since 1.0.0
*/
2014-10-16 08:53:41 -04:00
public function do_backstretch_image_title() {
2014-09-17 22:09:05 -04:00
$item = Display_Featured_Image_Genesis_Common::get_image_variables();
$displaysetting = get_option( 'displayfeaturedimagegenesis' );
$keep_titles = $displaysetting['keep_titles'];
2014-09-17 22:09:05 -04:00
if ( ! $keep_titles ) {
if ( is_singular() && ! is_front_page() && ! is_page_template( 'page_blog.php' ) ) {
remove_action( 'genesis_entry_header', 'genesis_do_post_title' ); // HTML5
remove_action( 'genesis_post_title', 'genesis_do_post_title' ); // XHTML
}
2014-09-17 22:09:05 -04:00
remove_action( 'genesis_before_loop', 'genesis_do_taxonomy_title_description', 15 );
remove_action( 'genesis_before_loop', 'genesis_do_author_title_description', 15 );
remove_action( 'genesis_before_loop', 'genesis_do_cpt_archive_title_description' );
}
2014-10-28 18:12:44 -04:00
echo '<div class="big-leader">';
echo '<div class="wrap">';
2014-10-28 18:12:44 -04:00
$move_excerpts = $displaysetting['move_excerpts'];
2015-01-05 11:04:44 -05:00
$post_types = array();
/**
* create a filter to not move excerpts if move excerpts is enabled
* @var filter
2015-01-10 10:45:16 -05:00
* @since 2.0.0 (deprecated old function from 1.3.3)
2015-01-05 11:04:44 -05:00
*/
$omit_excerpt = apply_filters( 'display_featured_image_genesis_omit_excerpt', $post_types );
2014-10-28 18:12:44 -04:00
//* if move excerpts is enabled
2015-01-05 11:04:44 -05:00
if ( $move_excerpts && ! in_array( get_post_type(), $omit_excerpt ) ) {
2014-10-28 18:12:44 -04:00
2014-11-01 20:06:54 -04:00
Display_Featured_Image_Genesis_Description::do_front_blog_excerpt();
Display_Featured_Image_Genesis_Description::do_excerpt();
genesis_do_taxonomy_title_description();
genesis_do_author_title_description();
genesis_do_cpt_archive_title_description();
2014-10-28 18:12:44 -04:00
2014-10-27 15:21:15 -04:00
}
2014-10-28 18:12:44 -04:00
elseif ( ! $keep_titles ) {
2014-11-03 14:06:24 -05:00
2014-11-01 20:06:54 -04:00
if ( ! empty( $item->title ) && ! is_front_page() ) {
if ( is_singular() ) {
genesis_do_post_title();
}
else {
echo '<h1 class="entry-title featured-image-overlay">' . $item->title . '</h1>';
}
2014-10-28 18:12:44 -04:00
}
remove_action( 'genesis_before_loop', 'genesis_do_cpt_archive_title_description' );
2014-10-27 15:21:15 -04:00
remove_action( 'genesis_before_loop', 'genesis_do_taxonomy_title_description', 15 );
remove_action( 'genesis_before_loop', 'genesis_do_author_title_description', 15 );
2014-11-03 14:06:24 -05:00
add_action( 'genesis_before_loop', array( $this, 'move_titles' ) );
2014-10-27 15:21:15 -04:00
}
//* close wrap
echo '</div>';
//* if javascript not enabled, do a fallback background image
2015-01-09 12:55:11 -05:00
$no_js = '<noscript><div class="backstretch no-js" style="background-image: url(' . esc_url( $item->backstretch[0] ) . '); }"></div></noscript>';
echo $no_js;
//* close big-leader
echo '</div>';
2014-09-17 22:09:05 -04:00
}
/**
* Large image, centered above content
* @return image
*
* @since 1.0.0
*/
public function do_large_image() {
2014-11-18 19:47:20 -05:00
$item = Display_Featured_Image_Genesis_Common::get_image_variables();
2014-11-18 21:01:25 -05:00
$image = sprintf( '<img src="%1$s" class="aligncenter featured" alt="%2$s" title="%2$s" />',
esc_url( $item->backstretch[0] ),
2015-01-09 12:55:11 -05:00
$item->title
2014-11-18 21:01:25 -05:00
);
echo $image;
2014-09-17 22:09:05 -04:00
}
2014-10-28 18:12:44 -04:00
/**
* Separate archive titles from descriptions. Titles show in leader image
* area; descriptions show before loop.
*
* @return descriptions
*
* @since 1.3.0
*
*/
public function move_titles() {
2014-11-03 14:06:24 -05:00
Display_Featured_Image_Genesis_Description::do_tax_description();
Display_Featured_Image_Genesis_Description::do_author_description();
Display_Featured_Image_Genesis_Description::do_cpt_archive_description();
2014-10-28 18:12:44 -04:00
}
public function filter_entry_title( $attributes ) {
$displaysetting = get_option( 'displayfeaturedimagegenesis' );
$keep_titles = $displaysetting['keep_titles'];
if ( ! $keep_titles && is_singular() ) {
$attributes['class'] = 'entry-title featured-image-overlay';
}
return $attributes;
}
}