Advertisement
MrPauloeN

Czyste Spalanie YouTube Gallery SHC

Jun 20th, 2020
1,622
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.31 KB | None | 0 0
  1. /* UWAGA! Nie usuwaj tego komentarza!
  2.  *
  3.  * Kod znacznika przeniesion do wtyczki a zaczep dezaktywowano.
  4.  * Patrz folder: plugins, wtyczka o nazwie: znacznik-YouTube
  5.  * @see: https://czystespalanie.info/bibliografia/filmy
  6.  */
  7.  
  8. //add_shortcode( 'youtube', 'czystespalanie__youtube' );
  9. function czystespalanie__youtube( $atts, $content = null ){
  10.  
  11.     wp_enqueue_script('lity');
  12.     wp_enqueue_style('lity');
  13.  
  14.     $url = get_stylesheet_directory_uri();
  15.  
  16.         $a = shortcode_atts( array(
  17.         'link' => '',
  18.                 'col' => '4',
  19.                 'float'=> ''
  20.  
  21.     ), $atts );
  22.  
  23.     $float = ( $a['float'] ) ? ' float-' . $a['float'] : '';
  24.  
  25.     $liczba = $a['col'] + 2;
  26.  
  27.     $classes = array (
  28.         'd-inline-block',
  29.         'col-' . $liczba,
  30.         'col-sm-' . $a['col'],
  31.         'col-md-' . $a['col'],
  32.         $float,
  33.     );
  34.  
  35.     $classes = implode( ' ', $classes);
  36.  
  37.     $film_id = preg_match( "/(?<=v=|v\/|vi=|vi\/|youtu.be\/)[a-zA-Z0-9_-]{11}/", $a['link'], $match );
  38.  
  39.     #sprawdzam czy film jest dostępny na podstawie miniaturki
  40.     $headers = @get_headers( 'https://img.youtube.com/vi/' . $match[0] . '/mqdefault.jpg' );
  41.  
  42.  
  43.     if ( strpos( $headers[0], '200') ) {
  44.     $img = '<img src="' . $url . '/images/play.png" class="card-title">';
  45.     } else {
  46.     $img = '<span class="badge badge-danger ml-1 mt-1 p-1">⚠ Film niedostępny</span>';
  47.     }
  48.  
  49.     $output = '<figure class="col-6 col-sm-4 col-md-3 ' . esc_attr( $float ) . '">' . "\r";
  50.     $output .= '<div class="shadow card mb-4 box-shadow rounded-0">' . "\r";;
  51.     $output .= '<a href="' . esc_url( $a['link'] ) . '" data-lity><img class="card-img-top img-fluid rounded-0"  src="https://img.youtube.com/vi/' . $match[0] . '/mqdefault.jpg"/></a>' . "\r";;
  52.     $output .= '<div class="card-img-overlay p-0 '. esc_attr( ( strpos( $headers[0], '200') ) ? '' : ' w-100 text-center' ) . '">';
  53.     $output .= '<a href="' . esc_url( $a['link'] ) .'" data-lity>' . $img . '</a>' . "\r";;
  54.     $output .= '</div>' . "\r";;
  55.     $output .= '<figcaption class="card-body text-center bg-light py-2 px-2">' . "\r";;
  56.     $output .= '<h6 class="h6 card-text font-weight-normal">' . trim( $content ) . '<a title="Link bezpośredni do YouTube" target="_blank" class="external-link float-right mt-3 pt-2" href="' . esc_url( $a['link'] ) . '"></a></h6>' . "\r";;
  57.     $output .= '</figcaption>' . "\r";;
  58.     $output .= '</div>' . "\r";;
  59.     $output .= '</figure>' . "\r";;
  60.  
  61.     return $output;
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement