Example #1
0
 /**
  * Parse short code.
  * @param $attr
  * @param string $content
  * @return string
  */
 public function parse_short_code($attr, $content)
 {
     $id = $attr['id'];
     if (!$id) {
         return '<div class="wpcf7-validation-errors">YouTube id attribute required.</div>';
     }
     $html = '<iframe width="640" height="480" src="https://www.youtube.com/embed/' . $id . '" frameborder="0" allowfullscreen></iframe>';
     $html = '<div class="youtube-frame">' . $html . "</div>";
     $url = 'https://www.googleapis.com/youtube/v3/videos?id=' . $id . '&part=snippet&key=' . MBInfoVideo::$KEY;
     $data = json_decode(MBInfoVideo::get_remote_data($url));
     $item = $data->items[0];
     if (!$item) {
         return '<div class="wpcf7-validation-errors">YouTube video id: ' . $id . ' not found.</div>';
     }
     $title = $item->snippet->title;
     if (isset($attr['title'])) {
         $title = $attr['title'];
     }
     if (!$content) {
         $content = $item->snippet->description;
     }
     $title = esc_html($title);
     $content = esc_html($content);
     $html .= '<div class="video-caption"><span class="video-title">Video. ' . $title . ': </span><span class="video-summary">' . $content . '</span></div>';
     return '<div class="video-box">' . $html . '</div>';
 }