public function shortcode($atts, $content = null) { extract(shortcode_atts(array('posts' => '', 'width' => '800', 'height' => '450', 'autoplay' => 'false', 'interval' => '5000'), $atts)); // sanitize attributes $width = absint($width); $height = absint($height); $interval = absint($interval); $autoplay = apply_filters('dt_sanitize_flag', $autoplay); $posts = array_map('trim', explode(',', $posts)); $attachments_id = array(); $selected_posts_titles = array(); if ($posts) { // get posts by slug foreach ($posts as $post_slug) { $args = array('no_found_rows' => 1, 'ignore_sticky_posts' => 1, 'posts_per_page' => 1, 'post_type' => 'dt_slideshow', 'post_status' => 'publish', 'name' => $post_slug); $dt_query = new WP_Query($args); if ($dt_query->have_posts()) { $dt_post = $dt_query->posts[0]; $selected_posts_titles[] = get_the_title($dt_post); $slides_id = get_post_meta($dt_post->ID, '_dt_slider_media_items', true); if ($slides_id) { $attachments_id = array_merge($attachments_id, $slides_id); } } } // get fresh one } else { $args = array('no_found_rows' => 1, 'ignore_sticky_posts' => 1, 'posts_per_page' => 1, 'post_type' => 'dt_slideshow', 'post_status' => 'publish', 'orderby' => 'date', 'order' => 'DESC'); $dt_query = new WP_Query($args); if ($dt_query->have_posts()) { $dt_post = $dt_query->posts[0]; $selected_posts_titles[] = get_the_title($dt_post); $slides_id = get_post_meta($dt_post->ID, '_dt_slider_media_items', true); if ($slides_id) { $attachments_id = array_merge($attachments_id, $slides_id); } } } if (function_exists('vc_is_inline') && vc_is_inline()) { if (empty($selected_posts_titles)) { $dummy_posts_titles = __('No posts selected', 'the7mk2'); } else { $dummy_posts_titles = esc_html(join(', ', $selected_posts_titles)); } $output = ' <div class="dt_vc-shortcode_dummy dt_vc-royal_slider" style="height: 250px;"> <h5>Royal slider</h4> <p class="text-small"><strong>Display slider(s):</strong> ' . $dummy_posts_titles . '</p> </div> '; } else { $attachments_data = presscore_get_attachment_post_data($attachments_id); $output = presscore_get_royal_slider($attachments_data, array('width' => $width, 'height' => $height, 'autoplay' => $autoplay, 'interval' => $interval, 'class' => array('slider-simple', 'shortcode-royal-slider'), 'style' => ' style="width: 100%"')); } return $output; }
/** * Portfolio media slider. * * Based on royal slider. Properly works only in the loop. * * @param array $class * @return string */ function presscore_get_project_media_slider($class = array()) { global $post; // slideshow dimensions $slider_proportions = get_post_meta($post->ID, '_dt_project_options_slider_proportions', true); $slider_proportions = wp_parse_args($slider_proportions, array('width' => '', 'height' => '')); $width = $slider_proportions['width']; $height = $slider_proportions['height']; // get slideshow $media_items = get_post_meta($post->ID, '_dt_project_media_items', true); $slideshow = ''; if (!$media_items) { $media_items = array(); } // if we have post thumbnail and it's not hidden if (has_post_thumbnail()) { if (is_single()) { if (!get_post_meta($post->ID, '_dt_project_options_hide_thumbnail', true)) { array_unshift($media_items, get_post_thumbnail_id()); } } else { array_unshift($media_items, get_post_thumbnail_id()); } } $attachments_data = presscore_get_attachment_post_data($media_items); // TODO: make it clean and simple if (count($attachments_data) > 1) { $slideshow = presscore_get_royal_slider($attachments_data, array('width' => $width, 'height' => $height, 'class' => $class, 'style' => ' style="width: 100%"')); } elseif (!empty($attachments_data)) { $image = current($attachments_data); $thumb_id = $image['ID']; $thumb_meta = array($image['full'], $image['width'], $image['height']); $video_url = esc_url(get_post_meta($thumb_id, 'dt-video-url', true)); $thumb_args = array('img_meta' => $thumb_meta, 'img_id' => $thumb_id, 'img_class' => 'preload-me', 'class' => 'alignnone rollover', 'href' => get_permalink($post->ID), 'wrap' => '<a %CLASS% %HREF% %TITLE% %CUSTOM%><img %IMG_CLASS% %SRC% %ALT% %SIZE% /></a>', 'echo' => false); if ($video_url) { $thumb_args['class'] = 'alignnone rollover-video'; } $thumb_args = apply_filters('dt_portfolio_thumbnail_args', $thumb_args); $slideshow = dt_get_thumb_img($thumb_args); } return $slideshow; }
public function shortcode($atts, $content = null) { extract(shortcode_atts(array('posts' => '', 'width' => '1200', 'height' => '500'), $atts)); // sanitize attributes $width = absint($width); $height = absint($height); $posts = array_map('trim', explode(',', $posts)); $attachments_id = array(); if ($posts) { // get posts by slug foreach ($posts as $post_slug) { $args = array('no_found_rows' => 1, 'ignore_sticky_posts' => 1, 'posts_per_page' => 1, 'post_type' => 'dt_slideshow', 'post_status' => 'publish', 'name' => $post_slug); $dt_query = new WP_Query($args); if ($dt_query->have_posts()) { $dt_post = $dt_query->posts[0]; $slides_id = get_post_meta($dt_post->ID, '_dt_slider_media_items', true); if ($slides_id) { $attachments_id = array_merge($attachments_id, $slides_id); } } } // get fresh one } else { $args = array('no_found_rows' => 1, 'ignore_sticky_posts' => 1, 'posts_per_page' => 1, 'post_type' => 'dt_slideshow', 'post_status' => 'publish', 'orderby' => 'date', 'order' => 'DESC'); $dt_query = new WP_Query($args); if ($dt_query->have_posts()) { $dt_post = $dt_query->posts[0]; $slides_id = get_post_meta($dt_post->ID, '_dt_slider_media_items', true); if ($slides_id) { $attachments_id = array_merge($attachments_id, $slides_id); } } } $attachments_data = presscore_get_attachment_post_data($attachments_id); $output = presscore_get_royal_slider($attachments_data, array('width' => $width, 'height' => $height, 'class' => array('slider-simple'), 'style' => ' style="width: 100%"')); return $output; }
case 'gallery': $gallery_columns = absint($config->get('post.media.gallery.columns')); $gallery_columns = $gallery_columns ? $gallery_columns : 4; $media_html = presscore_get_images_gallery_1($attachments_data, array('columns' => $gallery_columns, 'first_big' => $config->get('post.media.gallery.first_iamge_is_large'))); break; case 'list': $media_html = presscore_get_images_list($attachments_data, array('open_in_lightbox' => $open_thumbnail_in_lightbox)); break; default: // slideshow dimensions $slider_proportions = $config->get('post.media.slider.proportion'); if (!is_array($slider_proportions)) { $slider_proportions = array('width' => '', 'height' => ''); } $slider_proportions = wp_parse_args($slider_proportions, array('width' => '', 'height' => '')); $media_html = presscore_get_royal_slider($attachments_data, array('class' => array('slider-post'), 'width' => absint($slider_proportions['width']), 'height' => absint($slider_proportions['height']), 'style' => ' style="width: 100%;"')); } if ($media_html && in_array($media_type, array('list', 'gallery'))) { $media_html = sprintf('<div class="images-container">%s</div>', $media_html); } } else { $one_image_params = array(); if (!$open_thumbnail_in_lightbox) { $one_image_params['wrap'] = '<img %IMG_CLASS% %SRC% %IMG_TITLE% %ALT% %SIZE% />'; } $media_html = presscore_get_post_attachment_html(current($attachments_data), $one_image_params); if ($media_html) { $media_html = sprintf('<div class="images-container">%s</div>', $media_html); } } echo $media_html;
/** * Post media slider. * * Based on royal slider. Properly works only in the loop. * * @since 1.0.0 * * @return string HTML. */ function presscore_get_post_media_slider($attachments_data, $options = array()) { if (!$attachments_data) { return ''; } $default_options = array('class' => array(), 'style' => ' style="width: 100%"', 'proportions' => array('width' => '', 'height' => '')); $options = wp_parse_args($options, $default_options); $width = $options['proportions']['width']; $height = $options['proportions']['height']; $slideshow = presscore_get_royal_slider($attachments_data, array('width' => $width, 'height' => $height, 'class' => $options['class'], 'style' => $options['style'], 'show_info' => array())); return $slideshow; }
/** * Post media slider. * * Based on royal slider. Properly works only in the loop. * * @return string HTML. */ function presscore_get_post_media_slider($attachments_data, $options = array()) { global $post; if (!$attachments_data) { return ''; } $default_options = array('class' => array(), 'style' => ' style="width: 100%"'); $options = wp_parse_args($options, $default_options); // slideshow dimensions $slider_proportions = get_post_meta($post->ID, '_dt_post_options_slider_proportions', true); $slider_proportions = wp_parse_args($slider_proportions, array('width' => '', 'height' => '')); $width = $slider_proportions['width']; $height = $slider_proportions['height']; $slideshow = presscore_get_royal_slider($attachments_data, array('width' => $width, 'height' => $height, 'class' => $options['class'], 'style' => $options['style'])); return $slideshow; }
case 'gallery': $gallery_columns = absint($config->get('post.media.gallery.columns')); $gallery_columns = $gallery_columns ? $gallery_columns : 4; $media_html = presscore_get_images_gallery_1($attachments_data, array('columns' => $gallery_columns, 'first_big' => $config->get('post.media.gallery.first_iamge_is_large'), 'style' => presscore_get_share_buttons_for_prettyphoto('photo'))); break; case 'list': $media_html = presscore_get_images_list($attachments_data, array('open_in_lightbox' => $open_thumbnail_in_lightbox, 'show_share_buttons' => true)); break; default: // slideshow dimensions $slider_proportions = $config->get('post.media.slider.proportion'); if (!is_array($slider_proportions)) { $slider_proportions = array('width' => '', 'height' => ''); } $slider_proportions = wp_parse_args($slider_proportions, array('width' => '', 'height' => '')); $media_html = presscore_get_royal_slider($attachments_data, array('class' => array('slider-post'), 'width' => absint($slider_proportions['width']), 'height' => absint($slider_proportions['height']), 'style' => ' style="width: 100%;"', 'show_info' => array('title', 'link', 'description', 'share_buttons'))); } if ($media_html && in_array($media_type, array('list', 'gallery'))) { $media_html = sprintf('<div class="images-container">%s</div>', $media_html); } } else { $one_image_params = array(); if (!$open_thumbnail_in_lightbox) { $one_image_params['wrap'] = '<img %IMG_CLASS% %SRC% %IMG_TITLE% %ALT% %SIZE% />'; } $media_html = presscore_get_post_attachment_html(current($attachments_data), $one_image_params); if ($media_html) { $media_html = sprintf('<div class="images-container">%s</div>', $media_html); } } echo $media_html;
public function shortcode($content = '', $attr = array()) { static $shortcode_instance = 0; // return if this is standard mode or gallery alredy modified if (!empty($content)) { return $content; } if (class_exists('Jetpack', false)) { $jetpack_active_modules = get_option('jetpack_active_modules'); if ($jetpack_active_modules && (in_array('carousel', $jetpack_active_modules) || in_array('tiled-gallery', $jetpack_active_modules))) { return $content; } } $shortcode_instance++; if (empty($attr['mode']) || 'standard' == $attr['mode']) { // retrun slightly modified gallery with preatty photo return $this->wp_gallery_with_lightbox($attr, $shortcode_instance); } $post = get_post(); if (isset($attr['orderby'])) { $attr['orderby'] = sanitize_sql_orderby($attr['orderby']); if (!$attr['orderby']) { unset($attr['orderby']); } } extract(shortcode_atts(array('mode' => 'metro', 'width' => 1200, 'height' => 500, 'order' => 'ASC', 'orderby' => 'menu_order ID', 'id' => $post ? $post->ID : 0, 'size' => 'thumbnail', 'include' => '', 'exclude' => '', 'columns' => 3, 'first_big' => true), $attr, 'gallery')); $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)); } 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; } $mode = in_array($mode, array('slideshow', 'metro')) ? $mode : 'metro'; $width = absint($width); $height = absint($height); $attachments_data = array(); foreach ($attachments as $id => $attachment) { $data = array(); // attachment meta $data['full'] = $data['width'] = $data['height'] = ''; $meta = wp_get_attachment_image_src($id, 'full'); if (!empty($meta)) { $data['full'] = esc_url($meta[0]); $data['width'] = absint($meta[1]); $data['height'] = absint($meta[2]); } $data['thumbnail'] = wp_get_attachment_image_src($id, 'thumbnail'); $data['alt'] = esc_attr(get_post_meta($id, '_wp_attachment_image_alt', true)); $data['caption'] = $attachment->post_excerpt; $data['description'] = $attachment->post_content; $data['title'] = get_the_title($id); $data['video_url'] = esc_url(get_post_meta($id, 'dt-video-url', true)); $data['link'] = esc_url(get_post_meta($id, 'dt-img-link', true)); $data['mime_type_full'] = get_post_mime_type($id); $data['mime_type'] = dt_get_short_post_myme_type($id); $data['ID'] = $id; if (!empty($attr['link']) && 'file' === $attr['link']) { $data['permalink'] = $data['full']; } elseif (!empty($attr['link']) && 'none' === $attr['link']) { $data['permalink'] = ''; } else { $data['permalink'] = get_permalink($id); } $attachments_data[] = apply_filters('presscore_get_attachment_post_data-attachment_data', $data, array_keys($attachments)); } $style = ' style="width: 100%;"'; if ('slideshow' == $mode) { $output = presscore_get_royal_slider($attachments_data, array('width' => $width, 'height' => $height, 'class' => array('slider-simple'), 'style' => $style)); } elseif ('metro' == $mode) { $metro_classes = array('shortcode-gallery'); if (!$first_big) { $metro_classes[] = 'shortcode-gallery-standard'; } $output = presscore_get_images_gallery_1($attachments_data, array('class' => $metro_classes, 'style' => $style, 'columns' => $columns, 'first_big' => apply_filters('dt_sanitize_flag', $first_big))); } return $output; }
$gallery_make_first_big = 1; } else { $gallery_make_first_big = absint($gallery_make_first_big); } $media_html = presscore_get_images_gallery_1($attachments_data, array('columns' => $gallery_columns, 'first_big' => $gallery_make_first_big)); break; case 'list': $media_html = presscore_get_images_list($attachments_data, $open_thumbnail_in_lightbox); break; default: // slideshow dimensions $slider_proportions = get_post_meta($post->ID, '_dt_project_media_options_slider_proportions', true); $slider_proportions = wp_parse_args($slider_proportions, array('width' => '', 'height' => '')); $width = $slider_proportions['width']; $height = $slider_proportions['height']; $media_html = presscore_get_royal_slider($attachments_data, array('class' => array('slider-post'), 'width' => $width, 'height' => $height, 'style' => ' style="width: 100%;"')); } } else { $one_image_params = array(); if (!$open_thumbnail_in_lightbox) { $one_image_params['wrap'] = '<img %IMG_CLASS% %SRC% %IMG_TITLE% %ALT% %SIZE% />'; } $media_html = presscore_get_post_attachment_html(current($attachments_data), $one_image_params); if ($media_html) { $media_html = sprintf('<div class="images-container">%s</div>', $media_html); } } $content_container_class = 'wf-1'; $media_html_with_wrap = ''; if ($media_html && in_array($media_type, array('list', 'gallery'))) { $media_html = sprintf('<div class="images-container">%s</div>', $media_html);