| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217 |
- <?php
- class Vamtam_Gallery {
- public function __construct() {
- add_shortcode( 'vamtam_gallery', array( __CLASS__, 'gallery' ) );
- add_shortcode( 'vamtam_gallery_lightbox', array( __CLASS__, 'gallery_lightbox' ) );
- }
- public static function gallery( $attr ) {
- // Allow plugins/child themes to override the default gallery template.
- $output = apply_filters( 'vamtam_post_gallery', '', $attr );
- if ( '' != $output ) {
- return $output;
- }
- $attachments = self::get_attachments( $attr );
- if ( empty( $attachments ) )
- return '';
- if ( is_feed() ) {
- $output = "\n";
- foreach ( $attachments as $att_id => $attachment )
- $output .= wp_get_attachment_link( $att_id, $size, true ) . "\n";
- return $output;
- }
- $inside_cube = isset( $GLOBALS['vamtam_inside_cube'] ) && $GLOBALS['vamtam_inside_cube'];
- if ( $inside_cube ) {
- $output .= '<div class="cbp-slider-inline">';
- $output .= '<div class="cbp-slider-wrapper">';
- VamtamOverrides::unlimited_image_sizes(); // check for matching VamtamOverrides::limit_image_sizes(); below
- } else {
- if ( VamtamTemplates::early_cube_load() ) {
- wp_enqueue_script( 'cubeportfolio' );
- }
- wp_enqueue_style( 'cubeportfolio' );
- $slider_options = array(
- 'layoutMode' => 'slider',
- 'drag' => true,
- 'auto' => false,
- 'autoTimeout' => 5000,
- 'autoPauseOnHover' => true,
- 'showNavigation' => true,
- 'showPagination' => true,
- 'rewindNav' => true,
- 'gridAdjustment' => 'responsive',
- 'mediaQueries' => array(
- array(
- 'width' => 1,
- 'cols' => 1,
- ),
- ),
- 'gapHorizontal' => 0,
- 'gapVertical' => 0,
- 'caption' => '',
- 'displayType' => 'default',
- );
- $output .= '<div class="vamtam-cubeportfolio cbp cbp-slider-edge" data-options="' . esc_attr( json_encode( $slider_options ) ) . '">';
- }
- foreach ( $attachments as $id => $attachment ) {
- $image = wp_get_attachment_image( $id, $attr['size'] );
- if ( ! empty( $image ) ) {
- if ( $inside_cube ) {
- $output .= '<div class="cbp-slider-item cbp-slider-item--active">';
- $output .= '<a href="' . esc_url( get_permalink() ) . '" title="' . the_title_attribute( array(
- 'echo' => false,
- ) ) . '">';
- $output .= $image;
- $output .= '</a>';
- $output .= '</div>';
- } else {
- $output .= '<div class="cbp-item">';
- $output .= $image;
- $output .= '</div>';
- }
- }
- }
- if ( $inside_cube ) {
- VamtamOverrides::limit_image_sizes();
- $output .= '</div>
- <div class="cbp-slider-controls">
- <div class="cbp-slider-prev"></div>
- <div class="cbp-slider-next"></div>
- </div>
- </div>';
- } else {
- $output .= '</div>';
- }
- return $output;
- }
- public static function gallery_lightbox( $attr ) {
- // Allow plugins/child themes to override the default gallery template.
- $output = apply_filters( 'vamtam_post_gallery_lightbox', '', $attr );
- if ( '' != $output ) {
- return $output;
- }
- $attachments = self::get_attachments( $attr );
- if ( empty( $attachments ) )
- return '';
- if ( is_feed() ) {
- return '';
- }
- foreach ( $attachments as $id => $attachment ) {
- $image_src = wp_get_attachment_image_src( $id, 'full' );
- if ( ! empty( $image_src ) && ! empty( $image_src[0] ) ) {
- $output .= '<a href="' . esc_url( $image_src[0] ) . '" title="' . esc_attr__( 'View Gallery Item', 'wpv' ) . '" class="cbp-lightbox vamtam-lightbox-gallery" data-title="' . esc_attr( get_the_title() ) . '"></a>';
- }
- }
- return $output;
- }
- public static function get_attachments( $attr ) {
- extract( self::process_atts( $attr ) );
- $id = intval( $id );
- if ( 'RAND' == $order ) {
- $orderby = 'none';
- }
- if ( ! empty( $include ) ) {
- $_attachments = get_posts( array(
- 'include' => $include,
- 'post_status' => 'inherit',
- 'post_type' => 'attachment',
- 'post_mime_type' => 'image',
- 'order' => $order,
- 'orderby' => $orderby,
- ) );
- $attachments = array();
- foreach ( $_attachments as $key => $val ) {
- $attachments[ $val->ID ] = $_attachments[ $key ];
- }
- } elseif ( ! empty( $exclude ) ) {
- $attachments = get_children( array(
- 'post_parent' => $id,
- 'exclude' => $exclude,
- 'post_status' => 'inherit',
- 'post_type' => 'attachment',
- 'post_mime_type' => 'image',
- 'order' => $order,
- 'orderby' => $orderby,
- ) );
- } else {
- $attachments = get_children( array(
- 'post_parent' => $id,
- 'post_status' => 'inherit',
- 'post_type' => 'attachment',
- 'post_mime_type' => 'image',
- 'order' => $order,
- 'orderby' => $orderby,
- ) );
- }
- return $attachments;
- }
- public static function process_atts( $attr ) {
- $post = get_post();
- if ( ! empty( $attr['ids'] ) ) {
- // 'ids' is explicitly ordered, unless you specify otherwise.
- if ( empty( $attr['orderby'] ) ) {
- $attr['orderby'] = 'post__in';
- }
- $attr['include'] = $attr['ids'];
- }
- // We're trusting author input, so let's at least make sure it looks like a valid orderby statement
- if ( isset( $attr['orderby'] ) ) {
- $attr['orderby'] = sanitize_sql_orderby( $attr['orderby'] );
- if ( ! $attr['orderby'] ) {
- unset( $attr['orderby'] );
- }
- }
- return shortcode_atts(array(
- 'order' => 'ASC',
- 'orderby' => 'menu_order ID',
- 'id' => $post->ID,
- 'itemtag' => 'dl',
- 'icontag' => 'dt',
- 'captiontag' => 'dd',
- 'columns' => 3,
- 'size' => 'thumbnail',
- 'include' => '',
- 'exclude' => '',
- 'pausetime' => 3000,
- 'direction' => 'none',
- 'where' => 'single',
- ), $attr, 'gallery');
- }
- }
- new Vamtam_Gallery;
|