attributes = $attributes; $this->options = $options; // Set source of entry. $this->source = $attributes['source']; } /** * Init Entry */ public function init() { $this->set_object_id(); $this->set_object_link(); $this->set_attachment_id(); $this->set_attachment_lightbox(); $this->set_attachment_lightbox_icon(); $this->set_attachment_link(); $this->set_attachment_link_to(); $this->set_attachment_full_link(); $this->set_attachment_view_more(); $this->set_attachment_view_more_label(); $this->set_attachment_html(); $this->set_attachment_title(); $this->set_attachment_title_tag(); $this->set_attachment_meta(); $this->set_attachment_caption(); $this->set_attachment_orientation(); } /** * Set Object Id */ public function set_object_id() { if ( 'projects' === $this->source ) { $this->object_id = get_the_ID(); } if ( 'categories' === $this->source ) { $this->object_id = intval( $this->object_id ); } if ( 'post' === $this->source ) { $this->object_id = intval( $this->attachment_id ); } if ( 'custom' === $this->source ) { $this->object_id = intval( $this->attachment_id ); } } /** * Set Object Link */ public function set_object_link() { if ( 'projects' === $this->source ) { $this->object_link = get_permalink( get_the_ID() ); } if ( 'categories' === $this->source ) { $this->object_link = get_term_link( $this->object_id ); if ( empty( sight_is_archive() ) ) { $this->object_link = null; } } if ( 'post' === $this->source ) { $this->object_link = get_attachment_link( $this->attachment_id ); } if ( 'custom' === $this->source ) { $this->object_link = get_attachment_link( $this->attachment_id ); } } /** * Set Attachment Id */ public function set_attachment_id() { if ( 'projects' === $this->source ) { $this->attachment_id = get_post_thumbnail_id(); } } /** * Set Attachment Lightbox */ public function set_attachment_lightbox() { if ( ! isset( $this->attributes['attachment_lightbox'] ) || ! $this->attributes['attachment_lightbox'] ) { return; } $this->attachment_lightbox = true; } /** * Set Attachment Lightbox Icon */ public function set_attachment_lightbox_icon() { if ( ! isset( $this->attributes['attachment_lightbox'] ) || ! $this->attributes['attachment_lightbox'] ) { return; } if ( ! isset( $this->attributes['attachment_lightbox_icon'] ) || ! $this->attributes['attachment_lightbox_icon'] ) { return; } $this->attachment_lightbox_icon = true; } /** * Set Attachment Link */ public function set_attachment_link() { $this->attachment_link = wp_get_attachment_image_url( $this->attachment_id, $this->attributes['attachment_size'] ); } /** * Set Attachment Full Link */ public function set_attachment_full_link() { $this->attachment_full_link = wp_get_attachment_image_url( $this->attachment_id, 'full' ); } /** * Set Attachment Html */ public function set_attachment_html() { $attrs = apply_filters( 'sight_portfolio_attachment_attrs', array(), $this->attributes ); $this->attachment_html = wp_get_attachment_image( $this->attachment_id, $this->attributes['attachment_size'], false, $attrs ); } /** * Set Attachment Link To */ public function set_attachment_link_to() { if ( isset( $this->attributes['attachment_link_to'] ) && $this->attributes['attachment_link_to'] ) { $this->attachment_link_to = $this->attributes['attachment_link_to']; } } /** * Set Attachment View More */ public function set_attachment_view_more() { if ( isset( $this->attributes['attachment_view_more'] ) && $this->attributes['attachment_view_more'] ) { $this->attachment_view_more = $this->attributes['attachment_view_more']; } } /** * Set Attachment View More Label */ public function set_attachment_view_more_label() { switch ( $this->attachment_link_to ) { case 'media': $this->attachment_view_more_label = apply_filters( 'sight_portfolio_view_more', esc_html__( 'View Media', 'sight' ), $this ); break; case 'page': $this->attachment_view_more_label = apply_filters( 'sight_portfolio_view_more', esc_html__( 'View Project', 'sight' ), $this ); break; } } /** * Set Attachment Title */ public function set_attachment_title() { if ( ! isset( $this->attributes['meta_title'] ) || ! $this->attributes['meta_title'] ) { return; } if ( 'projects' === $this->source ) { $this->attachment_title = get_the_title( $this->object_id ); } if ( 'categories' === $this->source ) { $this->attachment_title = get_term( $this->object_id, 'sight-categories' )->name; } } /** * Set Attachment Title Tag */ public function set_attachment_title_tag() { if ( ! isset( $this->attributes['meta_title'] ) || ! $this->attributes['meta_title'] ) { return; } if ( isset( $this->attributes['typography_heading_tag'] ) && $this->attributes['typography_heading_tag'] ) { $this->attachment_title_tag = $this->attributes['typography_heading_tag']; } } /** * Set Attachment Meta */ public function set_attachment_meta() { ob_start(); // Meta Category. if ( isset( $this->attributes['meta_category'] ) && $this->attributes['meta_category'] ) { if ( 'projects' === $this->source ) { $terms_list = array(); $terms = get_the_terms( $this->object_id, 'sight-categories' ); foreach ( $terms as $term ) { if ( sight_is_archive() ) { $link = get_term_link( $term ); if ( ! is_wp_error( $link ) ) { $terms_list[] = '' . $term->name . ''; } } else { $terms_list[] = ''; } } if ( $terms_list ) { ?>
attributes['meta_date'] ) && $this->attributes['meta_date'] ) { ?> attachment_meta = ob_get_clean(); } /** * Set Attachment Caption */ public function set_attachment_caption() { if ( ! isset( $this->attributes['meta_caption'] ) || ! $this->attributes['meta_caption'] ) { return; } if ( 'projects' === $this->source ) { $this->attachment_caption = sight_get_the_excerpt( $this->attributes['meta_caption_length'] ); } if ( 'categories' === $this->source ) { $this->attachment_caption = sight_str_truncate( term_description( $this->object_id ), $this->attributes['meta_caption_length'] ); } if ( 'custom' === $this->source ) { $this->attachment_caption = sight_str_truncate( wp_get_attachment_caption( $this->attachment_id ), $this->attributes['meta_caption_length'] ); } if ( 'post' === $this->source ) { $this->attachment_caption = sight_str_truncate( wp_get_attachment_caption( $this->attachment_id ), $this->attributes['meta_caption_length'] ); } } /** * Set Attachment Orientation */ public function set_attachment_orientation() { if ( isset( $this->attributes['attachment_orientation'] ) && $this->attributes['attachment_orientation'] ) { $this->attachment_orientation = sprintf( 'sight-portfolio-overlay-ratio sight-portfolio-ratio-%s', $this->attributes['attachment_orientation'] ); } } /** * Has Item Content */ public function has_item_content() { $has_item_content = false; if ( $this->attachment_title ) { $has_item_content = true; } if ( $this->attachment_meta ) { $has_item_content = true; } if ( $this->attachment_caption ) { $has_item_content = true; } return apply_filters( 'sight_entry_has_item_content', $has_item_content, $this ); } /** * Compile Item Class * * @param string $class The class of entry. */ public function item_class( $class = array() ) { $classes = array(); if ( $class ) { if ( ! is_array( $class ) ) { $class = preg_split( '#\s+#', $class ); } $classes = array_map( 'esc_attr', $class ); } else { // Ensure that we always coerce class to being an array. $class = array(); } // Set individual class. $classes[] = 'sight-portfolio-entry sight-portfolio-video-wrap'; // Set entry source. if ( $this->source ) { $classes[] = 'sight-portfolio-entry-' . $this->source; } // Set entry object id. if ( $this->object_id ) { $classes[] = 'sight-portfolio-entry-' . $this->object_id; } // Set entry link to. if ( $this->attachment_link_to ) { $classes[] = 'sight-portfolio-entry-link-' . $this->attachment_link_to; } // Set entry request class. if ( 'standard' === $this->attributes['layout'] ) { if ( isset( $_REQUEST['action'] ) && 'sight_portfolio_ajax_load_more' === $_REQUEST['action'] ) { $classes[] = 'sight-portfolio-entry-request'; } } // For projects. if ( 'projects' === $this->source ) { $post = get_post( get_the_ID() ); $classes[] = 'type-' . $post->post_type; $classes[] = 'status-' . $post->post_status; // Post thumbnails. if ( current_theme_supports( 'post-thumbnails' ) && has_post_thumbnail( $post->ID ) && ! is_attachment( $post ) ) { $classes[] = 'has-post-thumbnail'; } } call_user_func( 'printf', 'class="%s"', join( ' ', $classes ) ); } /** * Compile Item Outer Class * * @param string $class The class of entry. */ public function item_outer_class( $class = array() ) { $classes = array(); if ( $class ) { if ( ! is_array( $class ) ) { $class = preg_split( '#\s+#', $class ); } $classes = array_map( 'esc_attr', $class ); } else { // Ensure that we always coerce class to being an array. $class = array(); } // Set individual class. $classes[] = 'sight-portfolio-entry-outer'; call_user_func( 'printf', 'class="%s"', join( ' ', $classes ) ); } /** * Compile Item Attachment */ public function item_attachment() { if ( ! $this->attachment_html ) { return; } switch ( $this->attachment_link_to ) { case 'media': $attachment_link = $this->attachment_full_link; break; case 'page': $attachment_link = $this->object_link; break; } if ( $this->attachment_lightbox ) { $attachment_link = $this->attachment_full_link; } ?> has_item_content() ) { ?>