/** * DT master get image function. * * @param $opts array * * @return string */ function dt_get_thumb_img( $opts = array() ) { global $post; $default_image = presscore_get_default_image(); $defaults = array( 'wrap' => '<a %HREF% %CLASS% %TITLE% %CUSTOM%><img %SRC% %IMG_CLASS% %SIZE% %ALT% %IMG_TITLE% /></a>', 'class' => '', 'alt' => '', 'title' => '', 'custom' => '', 'img_class' => '', 'img_title' => '', 'img_description' => '', 'img_caption' => '', 'href' => '', 'img_meta' => array(), 'img_id' => 0, 'options' => array(), 'default_img' => $default_image, 'prop' => false, 'echo' => true ); $opts = wp_parse_args( $opts, $defaults ); $opts = apply_filters('dt_get_thumb_img-args', $opts); $original_image = null; if ( $opts['img_meta'] ) { $original_image = $opts['img_meta']; } elseif ( $opts['img_id'] ) { $original_image = wp_get_attachment_image_src( $opts['img_id'], 'full' ); } if ( !$original_image ) { $original_image = $opts['default_img']; } // proportion if ( $original_image && !empty($opts['prop']) && ( empty($opts['options']['h']) || empty($opts['options']['w']) ) ) { $_prop = $opts['prop']; $_img_meta = $original_image; if ( $_prop > 1 ) { $h = intval(floor($_img_meta[1] / $_prop)); $w = intval(floor($_prop * $h)); } else if ( $_prop < 1 ) { $w = intval(floor($_prop * $_img_meta[2])); $h = intval(floor($w / $_prop)); } else { $w = $h = min($_img_meta[1], $_img_meta[2]); } if ( !empty($opts['options']['w']) ) { $__prop = $h / $w; $w = intval($opts['options']['w']); $h = intval(floor($__prop * $w)); } else if ( !empty($opts['options']['h']) ) { $__prop = $w / $h; $h = intval($opts['options']['h']); $w = intval(floor($__prop * $h)); } $opts['options']['w'] = $w; $opts['options']['h'] = $h; } if ( $opts['options'] ) { $resized_image = dt_get_resized_img( $original_image, $opts['options'] ); } else { $resized_image = $original_image; } if ( $img_id = absint( $opts['img_id'] ) ) { if ( '' === $opts['alt'] ) { $opts['alt'] = get_post_meta( $img_id, '_wp_attachment_image_alt', true ); } if ( '' === $opts['img_title'] ) { $opts['img_title'] = get_the_title( $img_id ); } } $class = empty( $opts['class'] ) ? '' : 'class="' . esc_attr( trim($opts['class']) ) . '"'; $title = empty( $opts['title'] ) ? '' : 'title="' . esc_attr( trim($opts['title']) ) . '"'; $img_title = empty( $opts['img_title'] ) ? '' : 'title="' . esc_attr( trim($opts['img_title']) ) . '"'; $img_class = empty( $opts['img_class'] ) ? '' : 'class="' . esc_attr( trim($opts['img_class']) ) . '"'; $href = $opts['href']; if ( !$href ) { $href = $original_image[0]; } $src = $resized_image[0]; if ( empty($resized_image[3]) || !is_string($resized_image[3]) ) { $size = image_hwstring($resized_image[1], $resized_image[2]); } else { $size = $resized_image[3]; } // $src = dt_make_image_src_ssl_friendly( $src ); $src = str_replace( array(' '), array('%20'), $src ); $output = str_replace( array( '%HREF%', '%CLASS%', '%TITLE%', '%CUSTOM%', '%SRC%', '%IMG_CLASS%', '%SIZE%', '%ALT%', '%IMG_TITLE%', '%RAW_TITLE%', '%RAW_ALT%', '%RAW_IMG_TITLE%', '%RAW_IMG_DESCRIPTION%', '%RAW_IMG_CAPTION' ), array( 'href="' . esc_url( $href ) . '"', $class, $title, strip_tags( $opts['custom'] ), 'src="' . esc_url( $src ) . '"', $img_class, $size, 'alt="' . esc_attr( $opts['alt'] ) . '"', $img_title, esc_attr( $opts['title'] ), esc_attr( $opts['alt'] ), esc_attr( $opts['img_title'] ), esc_attr( $opts['img_description'] ), esc_attr( $opts['img_caption'] ) ), $opts['wrap'] ); if ( $opts['echo'] ) { echo $output; return ''; } return $output; }
public function shortcode($atts, $content = null) { $default_atts = array('type' => '', 'style' => '1', 'image' => '', 'image_alt' => '', 'image_id' => '', 'image_width' => '', 'image_height' => '', 'misc_link' => '', 'target' => 'blank', 'media' => '', 'background' => 'plain', 'lightbox' => '0', 'content_size' => 'big', 'text_align' => 'left', 'animation' => 'none'); $attributes = shortcode_atts($default_atts, $atts); $attributes['type'] = sanitize_key($attributes['type']); $attributes['target'] = sanitize_key($attributes['target']); $attributes['style'] = sanitize_key($attributes['style']); $attributes['background'] = sanitize_key($attributes['background']); $attributes['content_size'] = sanitize_key($attributes['content_size']); $attributes['text_align'] = sanitize_key($attributes['text_align']); $attributes['image_id'] = absint($attributes['image_id']); $attributes['image_alt'] = esc_attr($attributes['image_alt']); $attributes['image_width'] = absint($attributes['image_width']); $attributes['image_height'] = absint($attributes['image_height']); $attributes['misc_link'] = esc_url($attributes['misc_link']); $attributes['lightbox'] = apply_filters('dt_sanitize_flag', $attributes['lightbox']); $attributes['media'] = esc_url($attributes['media']); $container_classes = array('shortcode-teaser'); $content_classes = array('shortcode-teaser-content'); $media = ''; // container classes if ('1' == $attributes['style']) { $container_classes[] = 'img-full'; } switch ($attributes['background']) { case 'fancy': $container_classes[] = 'frame-fancy'; case 'plain': $container_classes[] = 'frame-on'; } if (in_array($attributes['text_align'], array('center', 'centre'))) { $container_classes[] = 'text-centered'; } // content classes switch ($attributes['content_size']) { case 'small': $content_classes[] = 'text-small'; break; case 'normal': $content_classes[] = 'text-normal'; break; case 'big': default: $content_classes[] = 'text-big'; } if (presscore_shortcode_animation_on($attributes['animation'])) { $container_classes[] = presscore_get_shortcode_animation_html_class($attributes['animation']); } if ('uploaded_image' == $attributes['type']) { $attributes['image'] = $attributes['image_id']; $attributes['media'] = ''; } else { if ('image' == $attributes['type']) { $attributes['media'] = ''; } else { if ('video' == $attributes['type']) { $attributes['image'] = ''; } } } // if media url is set - do some stuff if ($attributes['media']) { $container_classes[] = 'shortcode-single-video'; $media = sprintf('<div class="shortcode-teaser-img"><div class="shortcode-teaser-video">%s</div></div>', dt_get_embed($attributes['media'])); // if image is set } elseif ($attributes['image']) { if (is_numeric($attributes['image'])) { $image_id = absint($attributes['image']); $image_info = wp_get_attachment_image_src($image_id, 'full'); // get image src if (!$image_info) { $image_info = presscore_get_default_image(); } $image_src = $image_info[0]; // get image alt if (empty($attributes['image_alt'])) { $attributes['image_alt'] = esc_attr(get_post_meta($image_id, '_wp_attachment_image_alt', true)); } // get image dimensions $attributes['image_width'] = $image_info[1]; $attributes['image_height'] = $image_info[2]; } else { $image_src = esc_url($attributes['image']); } // format image dimesions $image_dimension_attrs = ''; if ($attributes['image_width'] > 0 && $attributes['image_height'] > 0) { $image_dimension_attrs .= ' width="' . $attributes['image_width'] . '"'; $image_dimension_attrs .= ' height="' . $attributes['image_height'] . '"'; } $media = sprintf('<img src="%s" alt="%s"%s />', $image_src, $attributes['image_alt'], $image_dimension_attrs); if ($attributes['lightbox']) { $media = sprintf('<a class="rollover rollover-zoom dt-single-mfp-popup dt-mfp-item mfp-image" href="%s" title="%s" data-dt-img-description="%s">%s</a>', $image_src, esc_attr($attributes['image_alt']), '', $media); } else { if ($attributes['misc_link']) { $media = sprintf('<a class="rollover" href="%s"%s>%s</a>', $attributes['misc_link'], 'blank' == $attributes['target'] ? ' target="_blank"' : '', $media); } } $media = sprintf('<div class="shortcode-teaser-img">%s</div>', $media); } $output = sprintf('<section class="%s">%s<div class="%s">%s</div></section>', esc_attr(implode(' ', $container_classes)), $media, esc_attr(implode(' ', $content_classes)), presscore_remove_wpautop($content, true)); return $output; }
public function shortcode($atts, $content = null) { $default_atts = array('type' => '', 'style' => '1', 'image' => '', 'image_alt' => '', 'misc_link' => '', 'target' => 'blank', 'media' => '', 'background' => 'plain', 'lightbox' => '0', 'content_size' => 'normal', 'text_align' => 'left', 'animation' => 'none'); $attributes = shortcode_atts($default_atts, $atts); $attributes['type'] = in_array($attributes['type'], array('image', 'video')) ? $attributes['type'] : $default_atts['type']; $attributes['animation'] = in_array($attributes['animation'], array('none', 'scale', 'fade', 'left', 'right', 'bottom', 'top')) ? $attributes['animation'] : $default_atts['animation']; $attributes['style'] = in_array($attributes['style'], array('1', '2')) ? $attributes['style'] : $default_atts['style']; $attributes['background'] = in_array($attributes['background'], array('no', 'plain', 'fancy')) ? $attributes['background'] : $default_atts['background']; $attributes['target'] = in_array($attributes['target'], array('blank', 'self')) ? $attributes['target'] : $default_atts['target']; $attributes['image_alt'] = esc_attr($attributes['image_alt']); $attributes['misc_link'] = esc_url($attributes['misc_link']); $attributes['media'] = esc_url($attributes['media']); $attributes['content_size'] = in_array($attributes['content_size'], array('normal', 'small', 'big')) ? $attributes['content_size'] : $default_atts['content_size']; $attributes['text_align'] = in_array($attributes['text_align'], array('left', 'center', 'centre')) ? $attributes['text_align'] : $default_atts['text_align']; $attributes['lightbox'] = apply_filters('dt_sanitize_flag', $attributes['lightbox']); $container_classes = array('shortcode-teaser'); $content_classes = array('shortcode-teaser-content'); $media = ''; // container classes if ('1' == $attributes['style']) { $container_classes[] = 'img-full'; } switch ($attributes['background']) { case 'fancy': $container_classes[] = 'frame-fancy'; case 'plain': $container_classes[] = 'frame-on'; } if (in_array($attributes['text_align'], array('center', 'centre'))) { $container_classes[] = 'text-centered'; } // content classes switch ($attributes['content_size']) { case 'small': $content_classes[] = 'text-small'; break; case 'big': $content_classes[] = 'text-big'; } if ('none' != $attributes['animation']) { switch ($attributes['animation']) { case 'scale': $container_classes[] = 'scale-up'; break; case 'fade': $container_classes[] = 'fade-in'; break; case 'left': $container_classes[] = 'right-to-left'; break; case 'right': $container_classes[] = 'left-to-right'; break; case 'bottom': $container_classes[] = 'top-to-bottom'; break; case 'top': $container_classes[] = 'bottom-to-top'; break; } $container_classes[] = 'animate-element'; } if ('image' == $attributes['type']) { $attributes['media'] = ''; } elseif ('video' == $attributes['type']) { $attributes['image'] = ''; } // if media url is set - do some stuff if ($attributes['media']) { $container_classes[] = 'shortcode-single-video'; $media = sprintf('<div class="shortcode-teaser-img"><div class="shortcode-teaser-video">%s</div></div>', dt_get_embed($attributes['media'])); // if image is set } elseif ($attributes['image']) { if (is_numeric($attributes['image'])) { $image_id = absint($attributes['image']); $image_info = wp_get_attachment_image_src($image_id, 'full'); if (!$image_info) { $image_info = presscore_get_default_image(); } $image_src = $image_info[0]; if (empty($attributes['image_alt'])) { $attributes['image_alt'] = esc_attr(get_post_meta($image_id, '_wp_attachment_image_alt', true)); } } else { $image_src = esc_url($attributes['image']); } $media = sprintf('<img src="%s" alt="%s" />', $image_src, $attributes['image_alt']); if ($attributes['lightbox']) { $media = sprintf('<a class="rollover rollover-zoom dt-single-mfp-popup dt-mfp-item mfp-image" href="%s" title="%s" data-dt-img-description="%s">%s</a>', $image_src, esc_attr($attributes['image_alt']), '', $media); } else { if ($attributes['misc_link']) { $media = sprintf('<a class="rollover rollover-zoom" href="%s"%s>%s</a>', $attributes['misc_link'], 'blank' == $attributes['target'] ? ' target="_blank"' : '', $media); } } $media = sprintf('<div class="shortcode-teaser-img">%s</div>', $media); } $output = sprintf('<section class="%s">%s<div class="%s">%s</div></section>', esc_attr(implode(' ', $container_classes)), $media, esc_attr(implode(' ', $content_classes)), do_shortcode($content)); return $output; }
<?php $media = ''; $is_pass_protected = post_password_required(); if (!$is_pass_protected || $desc_on_hover) { if ('slideshow' != $previw_type || $desc_on_hover) { if (has_post_thumbnail()) { $thumb_id = get_post_thumbnail_id(); $thumb_meta = wp_get_attachment_image_src($thumb_id, 'full'); $attachment_post = get_post($thumb_id); $video_url = esc_url(get_post_meta($thumb_id, 'dt-video-url', true)); $hide_title = presscore_imagee_title_is_hidden($thumb_id); $zoom_link = sprintf('<a href="%s" class="project-zoom dt-single-mfp-popup dt-mfp-item %s" title="%s" data-dt-img-description="%s">%s</a>', $video_url ? esc_url($video_url) : esc_url($thumb_meta[0]), ($video_url ? 'mfp-iframe' : 'mfp-image') . ('under_image' == $description ? ' btn-zoom' : ''), $hide_title ? '' : esc_attr($attachment_post->post_title), esc_attr($attachment_post->post_content), __('Zoom', LANGUAGE_ZONE)); } else { $thumb_id = 0; $thumb_meta = presscore_get_default_image(); } $thumb_args = array('img_meta' => $thumb_meta, 'img_id' => $thumb_id, 'img_class' => 'preload-me', 'class' => $link_classes, 'href' => get_permalink($post->ID), 'echo' => false); $thumb_args['wrap'] = '<a %HREF% %CLASS% %TITLE% %CUSTOM%><img %IMG_CLASS% %SRC% %ALT% %SIZE% /></a>'; if ($video_url && $show_video_hoover) { $thumb_args['class'] = 'alignnone rollover'; $thumb_args['wrap'] = '<div %CLASS% %CUSTOM%><img %IMG_CLASS% %SRC% %ALT% %IMG_TITLE% %SIZE% /><a %HREF% class="video-icon"></a></div>'; } if ($config->get('justified_grid')) { $thumb_args['options'] = array('h' => round($config->get('target_height') * 1.3), 'z' => 0); } else { if ('wide' == $post_preview && !$config->get('all_the_same_width')) { $target_image_width = $config->get('target_width') * 3; $thumb_args['options'] = array('w' => round($target_image_width), 'z' => 0, 'hd_convert' => false); } else { $target_image_width = $config->get('target_width') * 1.5;
/** * Get related posts attachments data slightly modified. * * @return array Attachments data. */ function presscore_get_related_posts($options = array()) { $default_options = array('select' => 'only', 'exclude_current' => true, 'args' => array()); $options = wp_parse_args($options, $default_options); // exclude current post if in the loop if (in_the_loop() && $options['exclude_current']) { $options['args'] = array_merge($options['args'], array('post__not_in' => array(get_the_ID()))); } $posts = presscore_get_posts_in_categories($options); $attachments_ids = array(); $attachments_data_override = array(); $posts_data = array(); // get posts attachments id if ($posts->have_posts()) { while ($posts->have_posts()) { $posts->the_post(); // thumbnail or first attachment id if (has_post_thumbnail()) { $attachments_ids[] = get_post_thumbnail_id(); } else { if ($attachment = presscore_get_first_image()) { $attachments_ids[] = $attachment->ID; } else { $attachments_ids[] = 0; } } switch (get_post_type()) { case 'post': $post_meta = presscore_new_posted_on('post'); break; case 'dt_portfolio': $post_meta = presscore_new_posted_on('dt_portfolio'); break; default: $post_meta = presscore_new_posted_on(); } $attachments_data_override[] = array('permalink' => get_permalink(), 'link' => presscore_get_project_link('project-link'), 'title' => get_the_title(), 'description' => get_the_excerpt(), 'alt' => get_the_title(), 'parent_id' => get_the_ID(), 'meta' => $post_meta); } wp_reset_postdata(); } if ($attachments_ids) { // what we want $attachments_data = presscore_get_attachment_post_data($attachments_ids); // what we get $attachments_data_ids = array(); if ($attachments_data) { $attachments_data_ids = wp_list_pluck($attachments_data, 'ID'); } $default_image = presscore_get_default_image(); foreach ($attachments_ids as $key => $id) { $attachments_data_key = array_search($id, $attachments_data_ids); // if there are image - add it to array if (false !== $attachments_data_key) { $posts_data[$key] = $attachments_data[$attachments_data_key]; // or add noimage } else { $posts_data[$key] = array('full' => $default_image[0], 'width' => $default_image[1], 'height' => $default_image[2]); } if (isset($attachments_data_override[$key])) { $posts_data[$key] = array_merge($posts_data[$key], $attachments_data_override[$key]); } } } return $posts_data; }