PluginProbe ʕ •ᴥ•ʔ
Video Playlist for YouTube / 6.5
Video Playlist for YouTube v6.5
trunk 1.0 2.0 3.0 4.0 6.0 6.1 6.2 6.3 6.4 6.5 6.6 6.7 6.7.1 6.8 6.9
video-playlist-for-youtube / vpfy-api-playlist-shortcode.php
video-playlist-for-youtube Last commit date
includes 1 year ago index.php 1 year ago readme.txt 1 year ago video-playlist-ytb-plugin.php 1 year ago vpfy-api-playlist-shortcode.php 1 year ago vpfy-settings-pg.php 1 year ago vpfy-vplaylist-functions.php 1 year ago
vpfy-api-playlist-shortcode.php
83 lines
1 <?php
2 if (!defined('ABSPATH')) exit; // Exit if accessed directly
3 /*Display playlist*/
4 add_shortcode('channel4Youtube','vpfy_vplaylist_display_channel_playlist');
5 function vpfy_vplaylist_display_channel_playlist($atts){
6 $arry_arg = shortcode_atts(array('channelid'=>'1', 'maxresults'=>'10', 'width'=>'1260', 'height'=>'533'),$atts);
7
8 $output = '';
9 ob_start(); ?>
10 <link href="https://fonts.googleapis.com/css?family=Open+Sans:300,400,600,700,800%7CShadows+Into+Light" rel="stylesheet" type="text/css">
11 <script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js'></script>
12 <?php
13 wp_enqueue_script('vpfy-playlist-min');
14 wp_enqueue_script('vpfy-playlist-video');
15 wp_enqueue_script('vpfy-unitegallery-video');
16 wp_enqueue_style('vpfy-vplay-galcss');
17 wp_enqueue_style('vpfy-playlist-ryt-no-thumb');
18 wp_enqueue_style('vpfy-playlist-ryt-thumb');
19 wp_enqueue_style('vpfy-playlist-ryt-ttl-only');
20 wp_enqueue_style('vpfy-unite-gallery');
21
22
23 //Get videos from channel by YouTube Data API
24 $apikyyoutb = get_option('vpfy_reg_ytubapi_key');
25 $API_key = $apikyyoutb[0]; //'AIzaSyAldZXc1fKqllZc1UmuS86MloVmWe0rXHs';
26 $channelID = $arry_arg['channelid'];
27 $maxResults = $arry_arg['maxresults'];
28 $getRespon = wp_remote_get(esc_url_raw('https://www.googleapis.com/youtube/v3/search?order=date&part=snippet&channelId='.$channelID.'&maxResults='.$maxResults.'&key='.$API_key.''));
29 if( is_wp_error( $getRespon ) ) {
30 return false;
31 }
32 $videoList = json_decode( wp_remote_retrieve_body( $getRespon ) );
33 if( ! empty( $videoList ) ) {
34 if(!empty($videoList->error)){
35 echo esc_attr($videoList->error->errors[0]->message);
36 }
37 else{
38 if(isset($videoList->items)){
39 echo ('<div id="gallery'.esc_attr($channelID).'" style="margin:0px auto;display:none;">');
40 foreach($videoList->items as $item){
41 if(!empty($item->id->videoId)){
42 if(strlen($item->snippet->title) > 25){
43 $ytvidTitle = substr($item->snippet->title, 0, 25)."...";
44 }
45 else{
46 $ytvidTitle = $item->snippet->title;
47 }
48 ?>
49 <div data-type="youtube"
50 data-title="<?php echo esc_attr($ytvidTitle); ?>"
51 data-description="<?php echo esc_attr(substr($item->snippet->description, 0, 80)); ?>"
52 data-thumb="https://i.ytimg.com/vi/<?php echo esc_attr($item->id->videoId); ?>/mqdefault.jpg"
53 data-image="https://i.ytimg.com/vi/<?php echo esc_attr($item->id->videoId); ?>/sddefault.jpg"
54 data-videoid="<?php echo esc_attr($item->id->videoId); ?>" ></div>
55 <?php
56 }
57 }
58 echo ('</div>');
59 ?>
60 <?php if (!empty(get_option('vpfy_vid_autoply')) && get_option('vpfy_vid_autoply') == 1){
61 $autoply = 'true';
62 }
63 else{
64 $autoply = 'false';
65 }
66 ?>
67 <script>
68 jQuery(document).ready(function() {
69 jQuery("#gallery<?php echo esc_attr($channelID); ?>").unitegallery({
70 gallery_theme: "video",
71 gallery_width: <?php echo esc_attr($arry_arg['width']); ?>,
72 gallery_height: <?php echo esc_attr($arry_arg['height']); ?>,
73 theme_autoplay: <?php echo esc_attr($autoply); ?>,
74 });
75 });
76 </script>
77 <?php
78 }
79 }
80 }
81 $output = ob_get_clean();
82 return $output;
83 }