Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Plugin Name: Znacznik YouTube
- Plugin URI: https://www.facebook.com/WPSolucje/
- Description: Dodawanie filmu z YouTube. Prosty sposób na "optymalizację" osadzonych treści. Wstawienie znacznika [youtube] spowoduje wygenerowanie kontenera dla miniaturki filmu z YouTube, link bezpośredni i krótki opis. W przypadku większej ilości wstawionych filmików (galeria) ten zabieg może znacząco przyspieszyć ładowanie się strony.
- Version: 1.0
- Author: Paweł Nowak
- Author URI: https://czystespalanie.info
- */
- add_shortcode( 'youtube', 'czystespalanie__youtube' );
- function czystespalanie__youtube( $atts, $content = null ){
- wp_enqueue_script('lity');
- wp_enqueue_style('lity');
- $url = get_stylesheet_directory_uri();
- $a = shortcode_atts( array(
- 'link' => '',
- 'float'=> ''
- ), $atts );
- $float = ( $a['float'] ) ? ' float-' . $a['float'] : '';
- );
- $film_id = preg_match( "/(?<=v=|v\/|vi=|vi\/|youtu.be\/)[a-zA-Z0-9_-]{11}/", $a['link'], $match );
- #sprawdzam czy film jest dostępny na podstawie miniaturki
- $headers = @get_headers( 'https://img.youtube.com/vi/' . $match[0] . '/mqdefault.jpg' );
- if ( strpos( $headers[0], '200') ) {
- $img = '<img src="' . $url . '/images/play.png" class="card-title">';
- } else {
- $img = '<span class="badge badge-danger ml-1 mt-1 p-1">⚠ Film niedostępny</span>';
- }
- $output = '<figure class="col-6 col-sm-4 col-md-3 ' . esc_attr( $float ) . '">' . "\r";
- $output .= '<div class="shadow card mb-4 box-shadow rounded-0">' . "\r";;
- $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";;
- $output .= '<div class="card-img-overlay p-0 '. esc_attr( ( strpos( $headers[0], '200') ) ? '' : ' w-100 text-center' ) . '">';
- $output .= '<a href="' . esc_url( $a['link'] ) .'" data-lity>' . $img . '</a>' . "\r";;
- $output .= '</div>' . "\r";;
- $output .= '<figcaption class="card-body text-center bg-light py-2 px-2">' . "\r";;
- $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";;
- $output .= '</figcaption>' . "\r";;
- $output .= '</div>' . "\r";;
- $output .= '</figure>' . "\r";;
- return $output;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement