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

274 lines
9.5 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';
$skipped_types = apply_filters( 'display_featured_image_genesis_skipped_posttypes', $post_types );
2015-04-07 12:07:20 -04:00
if ( is_admin() || ( in_array( get_post_type(), $skipped_types ) ) || ( $skip && is_front_page() ) ) {
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' ) );
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();
2015-03-22 16:34:25 -04:00
$large = Display_Featured_Image_Genesis_Common::minimum_backstretch_width();
2015-02-27 09:10:06 -05:00
$medium = absint( get_option( 'medium_size_w' ) );
2015-02-27 10:13:13 -05:00
$width = absint( $item->backstretch[1] );
2014-09-17 22:09:05 -04:00
2015-04-09 22:16:36 -04:00
// check if they have enabled display on subsequent pages
$displaysetting = get_option( 'displayfeaturedimagegenesis' );
2015-04-21 14:39:26 -04:00
$is_paged = ! empty( $displaysetting['is_paged'] ) ? $displaysetting['is_paged'] : 0;
2015-04-09 22:16:36 -04:00
// if there is no backstretch image set, or it is too small, or it's page 2+ and they didn't change the setting, die
if ( empty( $item->backstretch ) || $width <= $medium || ( is_paged() && ! $is_paged ) ) {
return;
}
2015-04-09 22:16:36 -04: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() ) {
2015-02-10 17:32:13 -05:00
$css_file = apply_filters( 'display_featured_image_genesis_css_file', plugin_dir_url( __FILE__ ) . 'css/display-featured-image-genesis.css' );
wp_enqueue_style( 'displayfeaturedimage-style', esc_url( $css_file ), array(), $version );
2014-09-17 22:09:05 -04:00
2015-03-14 11:36:21 -04:00
$post_types = array();
$force_backstretch = apply_filters( 'display_featured_image_genesis_force_backstretch', $post_types );
2015-04-09 22:16:36 -04:00
// check if the image is large enough for backstretch
2015-03-14 11:36:21 -04:00
if ( $width > $large || in_array( get_post_type(), $force_backstretch ) ) {
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
2015-02-10 16:54:40 -05:00
$hook = apply_filters( 'display_featured_image_move_backstretch_image', 'genesis_after_header' );
add_action( $hook, array( $this, 'do_backstretch_image_title' ) );
2014-10-16 08:53:41 -04:00
}
2015-04-09 22:16:36 -04:00
// otherwise it's a large image.
2015-02-27 09:10:06 -05:00
elseif ( $width <= $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 ) {
2015-02-27 09:10:06 -05:00
$item = Display_Featured_Image_Genesis_Common::get_image_variables();
2015-03-22 16:34:25 -04:00
$large = Display_Featured_Image_Genesis_Common::minimum_backstretch_width();
2015-02-27 09:10:06 -05:00
$medium = absint( get_option( 'medium_size_w' ) );
2015-02-27 10:13:13 -05:00
$width = absint( $item->backstretch[1] );
2014-09-17 22:09:05 -04:00
2015-04-09 22:16:36 -04:00
// check if they have enabled display on subsequent pages
$displaysetting = get_option( 'displayfeaturedimagegenesis' );
2015-04-21 14:39:26 -04:00
$is_paged = ! empty( $displaysetting['is_paged'] ) ? $displaysetting['is_paged'] : 0;
2015-04-09 22:16:36 -04:00
// if there is no backstretch image set, or it is too small, or it's page 2+ and they didn't change the setting, die
if ( empty( $item->backstretch ) || $width <= $medium || ( is_paged() && ! $is_paged ) ) {
return $classes;
}
if ( false === $item->content || ! is_singular() ) {
2015-02-27 09:10:06 -05:00
if ( $width > $large ) {
2014-09-17 22:09:05 -04:00
$classes[] = 'has-leader';
}
2015-02-27 09:10:06 -05:00
elseif ( $width <= $large ) {
2014-09-17 22:09:05 -04:00
$classes[] = 'large-featured';
}
}
2015-02-12 19:18:11 -05:00
return apply_filters( 'display_featured_image_genesis_classes', $classes );
2014-09-17 22:09:05 -04:00
}
/**
* 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
2015-02-13 14:54:25 -05:00
// backstretch settings from plugin/featured image settings
$backstretch_settings = array(
2015-02-10 16:54:13 -05:00
'src' => esc_url( $item->backstretch[0] ),
2015-04-20 17:01:47 -04:00
'height' => absint( $displaysetting['less_header'] ),
2015-02-13 14:54:25 -05:00
);
// backstretch settings which can be filtered
$backstretch_variables = array(
'centeredX' => true,
'centeredY' => true,
'fade' => 750,
);
$backstretch_variables = apply_filters( 'display_featured_image_genesis_backstretch_variables', $backstretch_variables );
$output = array_merge( $backstretch_settings, $backstretch_variables );
wp_localize_script( 'displayfeaturedimage-backstretch-set', 'BackStretchVars', $output );
2015-02-10 16:54:13 -05:00
2015-04-18 09:00:26 -04:00
/**
* filter to maybe move titles, or not
* @var filter
* @since 2.2.0
*/
$post_types = array();
$do_not_move_title = apply_filters( 'display_featured_image_genesis_do_not_move_titles', $post_types );
2015-02-13 17:03:32 -05:00
// if titles will be moved to overlay backstretch image
2015-04-18 09:00:26 -04:00
if ( ! $keep_titles && ! in_array( get_post_type(), $do_not_move_title ) ) {
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
*/
2015-04-18 09:00:26 -04: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
2015-02-13 17:03:32 -05:00
// if titles are not being moved to overlay the image
2015-04-18 09:00:26 -04:00
elseif ( ! $keep_titles && ! in_array( get_post_type(), $do_not_move_title ) ) {
2014-11-03 14:06:24 -05:00
2014-11-01 20:06:54 -04:00
if ( ! empty( $item->title ) && ! is_front_page() ) {
2015-02-05 18:35:10 -05:00
$class = 'archive-title';
if ( is_singular() ) {
2015-02-05 18:35:10 -05:00
$class = 'entry-title';
}
2015-02-05 18:35:10 -05:00
$itemprop = '';
if ( genesis_html5() ) {
$itemprop = 'itemprop="headline"';
}
2015-03-14 11:37:32 -04:00
$title = $item->title;
$title_output = sprintf( '<h1 class="%s featured-image-overlay" %s>%s</h1>', $class, $itemprop, $title );
echo apply_filters( 'display_featured_image_genesis_modify_title_overlay', $title_output, $class, $itemprop, $title );
2015-02-05 18:35:10 -05:00
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();
$image = sprintf( '<img src="%1$s" class="aligncenter featured" alt="%2$s" />',
2014-11-18 21:01:25 -05:00
esc_url( $item->backstretch[0] ),
2015-04-20 17:01:47 -04:00
esc_attr( $item->title )
2014-11-18 21:01:25 -05:00
);
2015-02-10 14:59:15 -05:00
echo apply_filters( 'display_featured_image_genesis_large_image_output', $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
}
}