diff --git a/e107_admin/image.php b/e107_admin/image.php index 6bcca31d8..2fff8fc3a 100644 --- a/e107_admin/image.php +++ b/e107_admin/image.php @@ -744,7 +744,8 @@ class media_admin_ui extends e_admin_ui 'watermark_opacity' => array('title'=> 'Watermark Opacity', 'tab'=>1, 'type' => 'number', 'data' => 'int', 'help'=>'Enter a number between 1 and 100'), // 'validate' => 'regex', 'rule' => '#^[\d]+$#i', 'help' => 'allowed characters are a-zA-Z and underscore')), // https://developers.google.com/youtube/player_parameters - + 'youtube_default_account' => array('title'=> "Default YouTube account", 'tab'=>2, 'type' => 'text', 'data'=>'str', 'help'=>'Used by the Media-Manager Youtube browser. Enter account name. eg. e107inc'), + 'youtube_rel' => array('title'=> "Show Related Videos", 'tab'=>2, 'type' => 'boolean', 'data'=>'int', 'help'=>''), 'youtube_showinfo' => array('title'=> "Show Video Info", 'tab'=>2, 'type' => 'boolean', 'data'=>'int', 'help'=>''), 'youtube_cc_load_policy' => array('title'=> "Show Closed-Captions by default", 'tab'=>2, 'type' => 'boolean', 'data'=>'int', 'help'=>''), @@ -1372,7 +1373,14 @@ class media_admin_ui extends e_admin_ui return e107::getMedia()->browserCarousel($items, $parms); } - + function getYouTubeCode($url) + { + list($url,$qry) = explode("?",$url); + parse_str($qry,$opt); + + return $opt['v']; + + } function videoTab($parm='') @@ -1381,20 +1389,70 @@ class media_admin_ui extends e_admin_ui // $feed = "https://gdata.youtube.com/feeds/base/users/e107inc/uploads"; // @see https://developers.google.com/youtube/2.0/developers_guide_protocol_api_query_parameters - - if($search = vartrue($this->getQuery('search'))) + + $searchQry = $this->getQuery('search'); + + + if(!empty($searchQry)) { - $feed = "http://gdata.youtube.com/feeds/api/videos?orderby=relevance&vq=".urlencode($search)."&max-results=50"; // maximum is 50. + if(substr($searchQry,0,6) == 'video:') // YouTube video code? + { + // return "video: ".$searchQry; + $searchQry = trim(substr($searchQry,6)); + $data = array(); + $data['entry'][0]['id'] = $searchQry; + $data['entry'][0]['title'] = "Specified Video"; + $extension = 'youtube'; + // return print_a($parm,true); + } + elseif(substr($searchQry,0,9) == 'playlist:') // playlist + { + $searchQry = trim(substr($searchQry,9)); + $feed = "http://gdata.youtube.com/feeds/api/playlists/".urlencode($searchQry); + $plData = e107::getXml()->loadXMLfile($feed,true); + unset($feed); + // return print_a($plData,true); + + $code = $this->getYouTubeCode( $plData['entry'][0]['link'][0]['@attributes']['href']); + + + // return print_a($searchQry,true); + + if(!empty($plData)) + { + $data = array(); + $data['entry'][0]['id'] = $searchQry; + $data['entry'][0]['title'] = "Playlist: ". $plData['title']; + $data['entry'][0]['thumb'] = "http://i1.ytimg.com/vi/".$code."/maxresdefault.jpg"; + $extension = 'youtubepl'; + + e107::getMedia()->saveThumb("http://i1.ytimg.com/vi/".$code."/maxresdefault.jpg", $searchQry); + } + + } + else + { + $feed = "http://gdata.youtube.com/feeds/api/videos?orderby=relevance&vq=".urlencode($searchQry)."&max-results=50"; // maximum is 50. + $extension = 'youtube'; + } + } else { - $feed = "https://gdata.youtube.com/feeds/api/users/e107inc/uploads"; - } - - $data = e107::getXml()->loadXMLfile($feed,true); - + + $defaultAccount = e107::pref('core','youtube_default_account','e107inc'); + $feed = "https://gdata.youtube.com/feeds/api/users/".$defaultAccount."/uploads"; + $extension = 'youtube'; + } + + + + if(!empty($feed) && empty($data)) + { + $data = e107::getXml()->loadXMLfile($feed,true); + } // $text .= "

".$data['title']."

"; - // $text .= print_a($data,true); + // return print_a($data,true); $items = array(); @@ -1404,14 +1462,17 @@ class media_admin_ui extends e_admin_ui $thumbnail = "https://i1.ytimg.com/vi/".$id."/0.jpg"; $items[] = array( - 'previewUrl' => $thumbnail, - 'saveValue' => $id.".youtube", - 'thumbUrl' => $thumbnail, + 'previewUrl' => ($value['thumb']) ? $value['thumb'] : $thumbnail, + 'saveValue' => $id.".".$extension, // youtube", + 'thumbUrl' => ($value['thumb']) ? $value['thumb'] : $thumbnail, 'title' => $value['title'] ); } - - $parms = array('width' => 200, 'height'=>113, 'type'=>'image', 'bbcode'=>'video', 'tagid'=> $this->getQuery('tagid'), 'action'=>'youtube','searchPlaceholder'=>'Search Youtube'); + + // return print_a($items,true); + // return print_a($data,true); + + $parms = array('width' => 200, 'height'=>113, 'type'=>'image', 'bbcode'=>'video', 'tagid'=> $this->getQuery('tagid'), 'action'=>'youtube','searchPlaceholder'=>'Search Youtube. Use video: or playlist: prefixes if you know the code.' ); $text = e107::getMedia()->browserCarousel($items, $parms); diff --git a/e107_admin/newspost.php b/e107_admin/newspost.php index 139d350da..8dcdc1398 100644 --- a/e107_admin/newspost.php +++ b/e107_admin/newspost.php @@ -2405,7 +2405,7 @@ class admin_newspost ".$frm->help(LAN_NEWS_23)." "; - if(vartrue($_POST['news_thumbnail']) && (strpos($_POST['news_thumbnail'], ",") == false) && $_POST['news_thumbnail'][0] != "{" && substr($_POST['news_thumbnail'],-8) !== '.youtube')//BC compat + if(vartrue($_POST['news_thumbnail']) && (strpos($_POST['news_thumbnail'], ",") == false) && $_POST['news_thumbnail'][0] != "{" && $tp->isVideo($_POST['news_thumbnail']) === false )//BC compat { $_POST['news_thumbnail'] = "{e_IMAGE}newspost_images/".$_POST['news_thumbnail']; } diff --git a/e107_handlers/e107_class.php b/e107_handlers/e107_class.php index 937b3cdc1..5672eb8d3 100644 --- a/e107_handlers/e107_class.php +++ b/e107_handlers/e107_class.php @@ -2647,8 +2647,10 @@ class e107 } - e107::getMessage()->addDebug("e_url.php in ".e_PLUGIN.$plugin." is missing the key: ".$key.". Or, you may need to scan your plugin directories to register e_url.php"); - + if(!empty($plugin)) + { + e107::getMessage()->addDebug("e_url.php in ".e_PLUGIN.$plugin." is missing the key: ".$key.". Or, you may need to scan your plugin directories to register e_url.php"); + } return false; /* diff --git a/e107_handlers/e_parse_class.php b/e107_handlers/e_parse_class.php index 5ac234f66..01ae5c912 100644 --- a/e107_handlers/e_parse_class.php +++ b/e107_handlers/e_parse_class.php @@ -2972,7 +2972,7 @@ class e_parser { $ext = pathinfo($file,PATHINFO_EXTENSION); - return ($ext == 'youtube') ? true : false; + return ($ext == 'youtube' || $ext == 'youtubepl') ? true : false; } @@ -3041,6 +3041,26 @@ class e_parser return '
'.$video.'
'; } + + + if($type =='youtubepl') + { + + if($thumb == 'tag') + { + $thumbSrc = e107::getMedia()->getThumb($id); + return "Youtube Video Playlist"; + + } + + if($thumb == 'src') + { + return e107::getMedia()->getThumb($id); + } + + $video = ''; + return '
'.$video.'
'; + } if($type == 'mp4') //TODO FIXME { diff --git a/e107_handlers/form_handler.php b/e107_handlers/form_handler.php index 97b9b5c00..488656dff 100644 --- a/e107_handlers/form_handler.php +++ b/e107_handlers/form_handler.php @@ -698,7 +698,8 @@ class e_form if(strpos($sc_parameters, '=') === false) $sc_parameters = 'media='.$sc_parameters; parse_str($sc_parameters, $sc_parameters); } - + + // print_a($sc_parameters); if(empty($sc_parameters['media'])) diff --git a/e107_handlers/media_class.php b/e107_handlers/media_class.php index 43465f5c5..592d8f086 100644 --- a/e107_handlers/media_class.php +++ b/e107_handlers/media_class.php @@ -1155,7 +1155,60 @@ class e_media return $indicators; } - + + + + + /** + * Retriveve a Media-Manager thumbnail which was saved from a remote location. . + * @param $id + * @return bool|string + */ + function getThumb($id) + { + $id = trim($id); + $filename = 'temp/thumb-'.md5($id).".jpg"; + $filepath = e_MEDIA.$filename; + + if(file_exists($filepath)) + { + return e107::getParser()->createConstants($filepath); + } + + e107::getMessage()->addDebug("Couldn't find ".$filepath); + return false; + } + + + + /** + * Save a Media-Manager thumbnail from remote location. + * @param string $imageUrl + * @param string $id + * @return bool|string + */ + function saveThumb($imageUrl='',$id='') + { + + if(empty($id) || empty($imageUrl)) + { + return false; + } + + $filename = 'temp/thumb-'.md5($id).".jpg"; + $filepath = e_MEDIA.$filename; + + if(!file_exists($filepath)) + { + e107::getFile()->getRemoteFile($imageUrl, $filename,'media'); + } + + return $filepath; + } + + + + function browserCarousel($data,$parm=null) { @@ -1176,7 +1229,7 @@ class e_media $data_src = $this->mediaSelectNav($category,$parm['tagid'], $parm); $carouselID = 'myCarousel-'.$parm['action']; - + $searchToolttip = (empty($parm['searchTooltip'])) ? "Enter some text to filter results" : $parm['searchTooltip']; //$text = "