/** * Front-end display of widget. * * @see WP_Widget::widget() * * @param array $args Widget arguments. * @param array $instance Saved values from database. */ public function widget($args, $instance) { extract($args); $youtube_playlist_title = $instance['youtube_list_title']; $youtube_video_ids = $instance['youtube_videos_ids']; echo $before_widget; ?> <div class="apmag-youtube-lists-wrapper clearfix fullwidth-content"> <div class="apmag-youtube-list video-playlist-wrapper"> <h1 class="widget-title"><span><?php echo esc_attr($youtube_playlist_title); ?> </span></h1> <div class="list-conent-wrapper clearfix"> <?php if (!empty($youtube_video_ids)) { $http = !empty($_SERVER['HTTPS']) ? "https" : "http"; $seperate_id = explode(', ', $youtube_video_ids); $video_counter = 0; foreach ($seperate_id as $key => $value) { $video_counter++; $video_url = $http . '://www.youtube.com/watch?v=' . $value; $show_option = $video_counter == 1 ? "block" : "none"; ?> <div class="apmag-youtube-video-play ytvideo_<?php echo esc_attr($value); ?> video-wrap" style="display: <?php echo esc_attr($show_option); ?> "> <?php echo wp_oembed_get($video_url); ?> </div> <?php } ?> <div class="apmag-playlist-container"> <div class="apmag-video-control"> </div> <div class="apmag-video-playlist-wrapper"> <?php foreach ($seperate_id as $key => $value) { $response = wp_remote_get('https://www.googleapis.com/youtube/v3/videos?id=' . $value . '&part=id,contentDetails,snippet&key=AIzaSyA_Ze-UVGvIN6t94Glex1rYUM3SFB7Kz8o', array('sslverify' => false)); if (is_wp_error($response)) { break; } $data = wp_remote_retrieve_body($response); if (is_wp_error($data)) { break; } $obj = json_decode($data, true); $video_thumb = $obj['items'][0]['snippet']['thumbnails']['default']['url']; $video_title = $obj['items'][0]['snippet']['title']; $video_duration = covtime($obj['items'][0]['contentDetails']['duration']); ?> <div class="apmag-click-video-thumb" data-id="apmag_<?php echo esc_attr($value); ?> "> <figure class="list-thumb-figure"> <img src="<?php echo esc_url($video_thumb); ?> " alt="<?php echo esc_attr($video_title); ?> " title="<?php echo esc_attr($video_title); ?> " /> </figure> <div class="list-thumb-details"> <span class="thumb-title"><?php echo esc_attr($video_title); ?> </span> <span class="thumb-time"><?php echo $video_duration; ?> </span> </div> </div> <?php } ?> </div> </div> <?php } ?> </div> </div> </div> <?php echo $after_widget; }
} //The nfo files $xml = ' <?xml version="1.0" encoding="utf-8" standalone="yes"?> <episodedetails> <title>' . $title . '</title> <year>' . $year . '</year> <aired>' . $date . '</aired> <runtime>' . covtime($duration, 's') . '</runtime> <season>' . $year . '</season> <episode>' . $j . '</episode> <fileinfo> <streamdetails> <video> <duration>' . covtime($duration, 's') . '</duration> <durationinseconds>' . covtime($duration, 's') . '</durationinseconds> </video> </streamdetails> </fileinfo> </episodedetails> '; $folder = 'files/' . $username . '/' . $channel . '/' . $year; $filename = $folder . '/[S' . $year . 'E' . $j . '] ' . $title; if (!file_exists($filename . '.strm')) { if (!file_exists($folder)) { mkdir($folder, 0777, true); } //Create folder if it doesn't exist file_write($filename . '.strm', $API_DIRECTLINK . $videoId); file_write($filename . '.nfo', $xml); file_put_contents($filename . '-thumb.jpg', file_get_contents($img, false, stream_context_create($arrContextOptions)));