video-playlist-for-youtube
Last commit date
includes
6 years ago
index.php
6 years ago
readme.txt
6 years ago
video-playlist-ytb-plugin.php
6 years ago
vpfy-api-playlist-shortcode.php
6 years ago
vpfy-settings-pg.php
6 years ago
vpfy-vplaylist-functions.php
6 years 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="http://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='http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js'></script> |
| 12 | <?php |
| 13 | //wp_enqueue_script('jquery'); |
| 14 | wp_enqueue_script('vpfy-playlist-min'); |
| 15 | wp_enqueue_script('vpfy-playlist-video'); |
| 16 | |
| 17 | wp_enqueue_style('vpfy-vplay-galcss'); |
| 18 | wp_enqueue_style('vpfy-playlist-ryt-no-thumb'); |
| 19 | wp_enqueue_style('vpfy-playlist-ryt-thumb'); |
| 20 | wp_enqueue_style('vpfy-playlist-ryt-ttl-only'); |
| 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 $videoList->error->errors[0]->message; |
| 36 | } |
| 37 | else{ |
| 38 | if(isset($videoList->items)){ |
| 39 | echo '<div id="gallery'.$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 $ytvidTitle; ?>" |
| 51 | data-description="<?php echo substr($item->snippet->description, 0, 80); ?>" |
| 52 | data-thumb="https://i.ytimg.com/vi/<?php echo $item->id->videoId; ?>/mqdefault.jpg" |
| 53 | data-image="https://i.ytimg.com/vi/<?php echo $item->id->videoId; ?>/sddefault.jpg" |
| 54 | data-videoid="<?php echo $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 $channelID; ?>").unitegallery({ |
| 70 | gallery_theme: "video", |
| 71 | gallery_width: <?php echo $arry_arg['width']; ?>, |
| 72 | gallery_height: <?php echo $arry_arg['height']; ?>, |
| 73 | theme_autoplay: <?php echo $autoply; ?>, |
| 74 | }); |
| 75 | }); |
| 76 | </script> |
| 77 | <?php |
| 78 | } |
| 79 | } |
| 80 | } |
| 81 | $output = ob_get_clean(); |
| 82 | return $output; |
| 83 | } |