Advertisement
rdusnr

Untitled

Aug 11th, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.75 KB | None | 0 0
  1.  
  2. if ( ! function_exists( 'kleo_get_post_media' ) ) {
  3. /**
  4. * Return post media by format
  5. *
  6. * @param $post_format
  7. * @param $options
  8. *
  9. * @return string
  10. *
  11. * @since 3.0
  12. */
  13. function kleo_get_post_media( $post_format = 'standard', $options = array() ) {
  14.  
  15. global $kleo_config;
  16.  
  17. if ( isset( $options['icons'] ) && $options['icons'] ) {
  18. $icons = true;
  19. } else {
  20. $icons = false;
  21. }
  22.  
  23. if ( isset( $options['media_width'] ) && isset( $options['media_height'] ) ) {
  24. $media_width = $options['media_width'];
  25. $media_height = $options['media_height'];
  26. } else {
  27. $media_width = $kleo_config['post_gallery_img_width'];
  28. $media_height = $kleo_config['post_gallery_img_height'];
  29. }
  30.  
  31. $output = '';
  32.  
  33. switch ( $post_format ) {
  34.  
  35. case 'video':
  36.  
  37. //oEmbed video
  38. $video = get_cfield( 'embed' );
  39. // video bg self hosted
  40. $bg_video_args = array();
  41. $k_video = '';
  42.  
  43. if ( get_cfield( 'video_mp4' ) ) {
  44. $bg_video_args['mp4'] = get_cfield( 'video_mp4' );
  45. }
  46. if ( get_cfield( 'video_ogv' ) ) {
  47. $bg_video_args['ogv'] = get_cfield( 'video_ogv' );
  48. }
  49. if ( get_cfield( 'video_webm' ) ) {
  50. $bg_video_args['webm'] = get_cfield( 'video_webm' );
  51. }
  52.  
  53. if ( ! empty( $bg_video_args ) ) {
  54. $attr_strings = array(
  55. 'preload="none"'
  56. );
  57.  
  58. if ( get_cfield( 'video_poster' ) ) {
  59. $attr_strings[] = 'poster="' . get_cfield( 'video_poster' ) . '"';
  60. }
  61.  
  62. $k_video .= '<div class="kleo-video-wrap"><video ' . join( ' ', $attr_strings ) . ' controls="controls" class="kleo-video" style="width: 100%; height: 100%;">';
  63.  
  64. $source = '<source type="%s" src="%s" />';
  65. foreach ( $bg_video_args as $video_type => $video_src ) {
  66. $video_type = wp_check_filetype( $video_src, wp_get_mime_types() );
  67. $k_video .= sprintf( $source, $video_type['type'], esc_url( $video_src ) );
  68. }
  69.  
  70. $k_video .= '</video></div>';
  71.  
  72. $output .= $k_video;
  73. } // oEmbed
  74. elseif ( ! empty( $video ) ) {
  75. global $wp_embed;
  76. $output .= apply_filters( 'kleo_oembed_video', $video );
  77. }
  78.  
  79. break;
  80.  
  81. case 'audio':
  82.  
  83. $audio = get_cfield( 'audio' );
  84.  
  85. if ( ! empty( $audio ) ) {
  86. $output .=
  87. '<div class="post-audio">' .
  88. '<audio preload="none" class="kleo-audio" id="audio_' . get_the_ID() . '" style="width:100%;" src="' . $audio . '"></audio>' .
  89. '</div>';
  90. }
  91. break;
  92.  
  93. case 'gallery':
  94.  
  95. $slides = get_cfield( 'slider' );
  96.  
  97. $output .= '<div class="kleo-banner-slider">'
  98. . '<div class="kleo-banner-items" >';
  99.  
  100. if ( $slides ) {
  101. foreach ( $slides as $slide ) {
  102. if ( $slide ) {
  103. $image = aq_resize( $slide, $media_width, $media_height, true, true, true );
  104. //small hack for non-hosted images
  105. if ( ! $image ) {
  106. $image = $slide;
  107. }
  108. $output .= '<article>
  109. <a href="' . $slide . '" data-rel="modalPhoto[inner-gallery]">
  110. <img src="' . $image . '" alt="' . get_the_title() . '">'
  111. . kleo_get_img_overlay()
  112. . '</a>
  113. </article>';
  114. }
  115. }
  116. }
  117.  
  118. $output .= '</div>'
  119. . '<a href="#" class="kleo-banner-prev"><i class="icon-angle-left"></i></a>'
  120. . '<a href="#" class="kleo-banner-next"><i class="icon-angle-right"></i></a>'
  121. . '<div class="kleo-banner-features-pager carousel-pager"></div>'
  122. . '</div>';
  123.  
  124. break;
  125.  
  126.  
  127. case 'aside':
  128. if ( $icons ) {
  129. $output .= '<div class="post-format-icon"><i class="icon icon-doc"></i></div>';
  130. }
  131. break;
  132.  
  133. case 'link':
  134. if ( $icons ) {
  135. $output .= '<div class="post-format-icon"><i class="icon icon-link"></i></div>';
  136. }
  137. break;
  138.  
  139. case 'quote':
  140. if ( $icons ) {
  141. $output .= '<div class="post-format-icon"><i class="icon icon-quote-right"></i></div>';
  142. }
  143. break;
  144.  
  145. case 'image':
  146. default:
  147. if ( kleo_get_post_thumbnail_url() != '' ) {
  148. $output .= '<div class="post-image 9999">';
  149.  
  150. $img_url = kleo_get_post_thumbnail_url();
  151. //$image = aq_resize( $img_url, $media_width, $media_height, true, true, true );
  152. if ( ! $image ) {
  153. $image = $img_url;
  154. }
  155. $output .= '<a href="' . get_permalink() . '" class="element-wrap">'
  156. . '<img src="' . $image . '" alt="' . get_the_title() . '">'
  157. . kleo_get_img_overlay()
  158. . '</a>';
  159.  
  160. $output .= '</div><!--end post-image-->';
  161. } elseif ( $icons ) {
  162. $post_icon = $post_format == 'image' ? 'picture' : 'doc';
  163. $output .= '<div class="post-format-icon"><i class="icon icon-' . $post_icon . '"></i></div>';
  164. }
  165.  
  166. break;
  167. }
  168.  
  169. return $output;
  170. }
  171. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement