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() {
|
2014-11-04 21:14:33 -05:00
|
|
|
$displaysetting = get_option( 'displayfeaturedimagegenesis' );
|
|
|
|
|
$fallback = $displaysetting['default'];
|
2014-11-06 16:23:41 -05:00
|
|
|
if ( is_admin() || ( empty( $fallback ) && ! is_home() && ! is_singular() ) || ( in_array( get_post_type(), Display_Featured_Image_Genesis_Common::get_skipped_posttypes() ) ) ) {
|
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() {
|
|
|
|
|
|
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
|
|
|
|
2014-11-17 13:54:12 -05:00
|
|
|
// if there is no backstretch image set, or it is too small, die
|
|
|
|
|
if ( empty( $item->backstretch ) || $item->backstretch[1] <= $item->medium ) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// 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(), '1.4.2' );
|
2014-09-17 22:09:05 -04:00
|
|
|
|
2014-11-17 13:54:12 -05:00
|
|
|
//check if the image is large enough for backstretch
|
2014-11-06 15:56:48 -05:00
|
|
|
if ( $item->backstretch[1] > $item->large ) {
|
2014-11-17 13:54:12 -05:00
|
|
|
wp_enqueue_script( 'displayfeaturedimage-backstretch', plugins_url( '/includes/js/backstretch.js', dirname( __FILE__ ) ), array( 'jquery' ), '1.4.2' );
|
|
|
|
|
wp_enqueue_script( 'displayfeaturedimage-backstretch-set', plugins_url( '/includes/js/backstretch-set.js', dirname( __FILE__ ) ), array( 'jquery', 'displayfeaturedimage-backstretch' ), '1.4.2' );
|
2014-09-17 22:09:05 -04:00
|
|
|
|
2014-09-18 08:09:26 -04:00
|
|
|
wp_localize_script( 'displayfeaturedimage-backstretch-set', 'BackStretchVars', array(
|
2014-11-06 15:56:48 -05:00
|
|
|
'src' => esc_url( $item->backstretch[0] ),
|
2014-09-18 08:09:26 -04:00
|
|
|
'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-11-17 13:54:12 -05:00
|
|
|
// otherwise it's a large image.
|
|
|
|
|
elseif ( $item->backstretch[1] <= $item->large ) {
|
2014-10-16 08:53:41 -04:00
|
|
|
add_action( 'genesis_before_entry', array( $this, 'do_large_image' ) ); // HTML5
|
|
|
|
|
add_action( 'genesis_before_post', array( $this, 'do_large_image' ) ); // 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
|
|
|
|
2014-11-17 13:54:12 -05:00
|
|
|
if ( empty( $item->backstretch ) || $item->backstretch[1] <= $item->medium ) {
|
|
|
|
|
return $classes;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( false === $item->content || ! is_singular() ) {
|
2014-11-06 15:56:48 -05:00
|
|
|
if ( $item->backstretch[1] > $item->large ) {
|
2014-09-17 22:09:05 -04:00
|
|
|
$classes[] = 'has-leader';
|
|
|
|
|
}
|
2014-11-17 13:54:12 -05:00
|
|
|
elseif ( $item->backstretch[1] <= $item->large ) {
|
2014-09-17 22:09:05 -04:00
|
|
|
$classes[] = 'large-featured';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return $classes;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2014-10-16 08:53:41 -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
|
|
|
|
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
|
|
|
|
2014-11-11 16:59:09 -05:00
|
|
|
if ( is_singular() && ! is_front_page() && ! is_page_template( 'page_blog.php' ) ) {
|
2014-09-23 15:43:24 -04:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2014-10-28 18:12:44 -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-09-17 22:09:05 -04:00
|
|
|
echo '<div class="big-leader"><div class="wrap">';
|
2014-11-04 21:14:33 -05:00
|
|
|
$displaysetting = get_option( 'displayfeaturedimagegenesis' );
|
|
|
|
|
$move_excerpts = $displaysetting['move_excerpts'];
|
2014-10-28 18:12:44 -04:00
|
|
|
|
2014-11-01 20:06:54 -04:00
|
|
|
// if move excerpts is enabled
|
|
|
|
|
if ( $move_excerpts && ! in_array( get_post_type(), Display_Featured_Image_Genesis_Common::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
|
|
|
|
|
|
|
|
else {
|
2014-11-03 14:06:24 -05:00
|
|
|
|
2014-11-01 20:06:54 -04:00
|
|
|
if ( ! empty( $item->title ) && ! is_front_page() ) {
|
2014-10-31 16:28:47 -04:00
|
|
|
echo '<h1 class="entry-title featured-image-overlay">' . esc_attr( $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
|
|
|
}
|
2014-09-17 22:09:05 -04:00
|
|
|
echo '</div></div>';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Large image, centered above content
|
|
|
|
|
* @return image
|
|
|
|
|
*
|
|
|
|
|
* @since 1.0.0
|
|
|
|
|
*/
|
|
|
|
|
public function do_large_image() {
|
|
|
|
|
global $post;
|
2014-10-31 16:28:47 -04:00
|
|
|
$image = get_the_post_thumbnail( $post->ID, 'large', array( 'class' => 'aligncenter featured', 'alt' => the_title_attribute( 'echo=0' ) ) );
|
|
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2014-09-18 08:09:26 -04:00
|
|
|
}
|