????

Your IP : 216.73.216.174


Current Path : /home2/morganrand/www/wp-content/plugins/pinwheel-slider/includes/addons/
Upload File :
Current File : /home2/morganrand/www/wp-content/plugins/pinwheel-slider/includes/addons/youtube.php

<?php
function pinwheel_carousel_videos_on_slider_youtube($max='3', $offset=0, $out_echo = '1', $set='',$type='',$val,$key, $data=array() ) {
    	$r_array=array();
	$default_pinwheel_slider_settings=get_pinwheel_slider_default_settings();
	$pinwheel_slider_options='pinwheel_slider_options'.$set;
	$pinwheel_slider_curr=get_option($pinwheel_slider_options);
	$pinwheel_slider = get_option('pinwheel_slider_options');
	if(!isset($pinwheel_slider_curr) or !is_array($pinwheel_slider_curr) or empty($pinwheel_slider_curr)){$pinwheel_slider_curr=$pinwheel_slider;$set='';}
	$pinwheel_slider_curr= populate_pinwheel_current($pinwheel_slider_curr);
	$slides = array();
	if($type == "playlist") {
		$playlist_url = "https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&playlistId=$val&key=$key&maxResults=$max";
	
		$json_source = @file_get_contents($playlist_url);
		$fx = json_decode($json_source);
		if(isset($fx->items)) {
			$listcnt = count($fx->items);
			if($listcnt > $max) $listcnt = $max;
			if($offset == '') $offset = 0;
			for($i=$offset;$i<$listcnt;$i++) {
				$id = isset($fx->items[$i]->snippet->resourceId->videoId)?$fx->items[$i]->snippet->resourceId->videoId:'';
				$playlistid = isset($fx->items[$i]->snippet->playlistId)?$fx->items[$i]->snippet->playlistId:'';
				$pubDate = isset($fx->items[$i]->snippet->publishedAt)?$fx->items[$i]->snippet->publishedAt:'';
				$title = isset($fx->items[$i]->snippet->title)?$fx->items[$i]->snippet->title:'';
				$content = isset($fx->items[$i]->snippet->description)?$fx->items[$i]->snippet->description:'';
				$author = isset($fx->items[$i]->snippet->channelTitle)?$fx->items[$i]->snippet->channelTitle:'';
				$url = "https://www.youtube.com/watch?v=$id&list=$playlistid";
				$default = 'high';
				$playlistimg = isset($fx->items[$i]->snippet->thumbnails->$default->url)?$fx->items[$i]->snippet->thumbnails->$default->url:'';
				$pinwheel_eshortcode = '<iframe src="https://www.youtube.com/embed/'.$id.'?list='.$playlistid.'" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>';
				$slide=array();
				$slide['post_title'] = $title;
				$slide['ID'] = 0;
				$slide['post_excerpt'] = '';
				$slide['post_content'] = $content;
				$slide['content_for_image'] = '';
				$slide['redirect_url'] = $url;
				$slide['nolink'] = '1';
				$slide['pubDate'] = $pubDate;
				$slide['author'] = $author;
				$slide['category'] = '';
				$slide['media_image']= $playlistimg;
				$slide['eshortcode'] = $pinwheel_eshortcode;
				$slide=(object) $slide;
				$slides[]=$slide;
			}
		} else {
			_e('Please Enter the correct playlist','pinwheel-slider');
		}
	} elseif($type == "search") {
		$val = str_replace(' ','+',$val);
		$search_url = "https://www.googleapis.com/youtube/v3/search?part=snippet&q=".$val."&key=$key&maxResults=$max&type=video";
		$searchjson_source = @file_get_contents($search_url);
		$searchfx = json_decode($searchjson_source);
		if(isset($searchfx->items) && count($searchfx->items) > 0) {
			$listcnt = count($searchfx->items);
			if($listcnt > $max) $listcnt = $max;
			if($offset == '') $offset = 0;
			$slides = array();
			for($i=$offset;$i<$listcnt;$i++) {
				$kind = isset($searchfx->items[$i]->id->kind)?$searchfx->items[$i]->id->kind:'';
				$videoId = isset($searchfx->items[$i]->id->videoId)?$searchfx->items[$i]->id->videoId:'';
				$pubDate = isset($searchfx->items[$i]->snippet->publishedAt)?$searchfx->items[$i]->snippet->publishedAt:'';
				$title = isset($searchfx->items[$i]->snippet->title)?$searchfx->items[$i]->snippet->title:'';
				$content = isset($searchfx->items[$i]->snippet->description)?$searchfx->items[$i]->snippet->description:'';
				$author = isset($searchfx->items[$i]->snippet->channelTitle)?$searchfx->items[$i]->snippet->channelTitle:'';
				$url = "https://www.youtube.com/watch?v=$videoId";
				$pinwheel_eshortcode = '<iframe src="https://www.youtube.com/embed/'.$videoId.'" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>';
				$default = 'high';
				$playlistimg = $searchfx->items[$i]->snippet->thumbnails->$default->url;
				$slide=array();
				$slide['post_title'] = $title;
				$slide['ID'] = 0;
				$slide['post_excerpt'] = '';
				$slide['post_content'] = $content;
				$slide['content_for_image'] = '';
				$slide['redirect_url'] = $url;
				$slide['nolink'] = '1';
				$slide['pubDate'] = $pubDate;
				$slide['author'] = $author;
				$slide['category'] = '';
				$slide['media_image']= $playlistimg;
				$slide['eshortcode'] = $pinwheel_eshortcode;
				$slide=(object) $slide;
				$slides[]=$slide;
			}
		} else {
			_e('No videos found for this search term','pinwheel-slider');
		}
	}
		$r_array=pinwheel_global_data_processor( $slides, $pinwheel_slider_curr, $out_echo, $set, $data );
		return $r_array;
}
function get_pinwheel_youtube_slider( $args = '' ) { 
	$defaults=array('type'=>'','val'=>'', 'set'=>'', 'offset'=>'0');
	$args = wp_parse_args( $args, $defaults );
	extract( $args );
	$gpinwheel_slider = get_option('pinwheel_slider_global_options');
	$key = isset($gpinwheel_slider['youtube_app_id'])?$gpinwheel_slider['youtube_app_id']:'';
	if( $key !='' ) {
		$default_pinwheel_slider_settings=get_pinwheel_slider_default_settings();
		// If setting set is 1 then set to blank	
		if($set == '1') $set = '';
		$pinwheel_slider_css = pinwheel_get_inline_css($set);
		$pinwheel_slider_options='pinwheel_slider_options'.$set;
		$pinwheel_slider_curr=get_option($pinwheel_slider_options);
		$pinwheel_slider = get_option('pinwheel_slider_options');
		if(!isset($pinwheel_slider_curr) or !is_array($pinwheel_slider_curr) or empty($pinwheel_slider_curr)){$pinwheel_slider_curr=$pinwheel_slider;$set='';}
		$pinwheel_slider_curr= populate_pinwheel_current($pinwheel_slider_curr);
		$handleval = str_replace(array("-","@"," ","+"),'_',$val);
		$slider_handle='pinwheel_slider_'.$handleval;
		$data['slider_handle']=$slider_handle;
		$data['media']=1;
		$data['vtype'] = 'youtube';
		$r_array = pinwheel_carousel_videos_on_slider_youtube($pinwheel_slider_curr['no_posts'], $offset, '0', $set, $type,$val,$key,$data); 
		get_global_pinwheel_slider($slider_handle,$r_array,$pinwheel_slider_curr,$set,$echo='1',$data);
	} else {
		_e("Please Enter The YouTube API Key on Global Settings!","pinwheel-slider");
	}
}
function return_pinwheel_slider_youtube($type='',$val='',$set='',$offset='0') {
	$gpinwheel_slider = get_option('pinwheel_slider_global_options');
	$key = isset($gpinwheel_slider['youtube_app_id'])?$gpinwheel_slider['youtube_app_id']:'';
	if( $key !='' ) {
		$slider_html='';
		$default_pinwheel_slider_settings=get_pinwheel_slider_default_settings();
		// If setting set is 1 then set to blank	
		if($set == '1') $set = '';
		$pinwheel_slider_options='pinwheel_slider_options'.$set;
		$pinwheel_slider_curr=get_option($pinwheel_slider_options);
		$pinwheel_slider = get_option('pinwheel_slider_options');
		if(!isset($pinwheel_slider_curr) or !is_array($pinwheel_slider_curr) or empty($pinwheel_slider_curr)){$pinwheel_slider_curr=$pinwheel_slider;$set='';}
		$pinwheel_slider_curr= populate_pinwheel_current($pinwheel_slider_curr);
		$handleval = str_replace(array("-","@"," ","+"),'_',$val);
		$slider_handle='pinwheel_slider_'.$handleval;
		$data['slider_handle']=$slider_handle;
		$data['media']=1;
		$data['vtype'] = 'youtube';
		$r_array = pinwheel_carousel_videos_on_slider_youtube($pinwheel_slider_curr['no_posts'], $offset, '0', $set, $type,$val,$key,$data); 
		//get slider 
		$output_function='return_global_pinwheel_slider';
		$slider_html=$output_function($slider_handle,$r_array,$pinwheel_slider_curr,$set,$echo='0',$data);
		return $slider_html;
	} else {
		_e("Please Enter The YouTube API Key on Global Settings!","pinwheel-slider");
	}
}

function pinwheel_slider_youtube_shortcode($atts) {
	extract(shortcode_atts(array(
		'type'=>'',
		'val'=>'',
		'set'=>'',
		'offset'=>'0'
	), $atts));

	return return_pinwheel_slider_youtube($type,$val,$set,$offset);
}
add_shortcode('pinwheelyoutube', 'pinwheel_slider_youtube_shortcode');
?>