/** * Print video code. * * ## OPTIONS * * <id> * * YouTube id. * * ## EXAMPLES * * wp mbinfo-video info --id=7RrrIBHAbXE * * @synopsis [--id] */ function info($args, $assoc_args) { $video = new MBInfoVideo(); $content = $args[0]; $html = $video->parse_short_code($assoc_args, $content); echo $html; }
/** * 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>'; }
function mbinfo_video($attr, $content) { $pinfo = new MBInfoVideo(); return $pinfo->parse_short_code($attr, $content); }