Tarea #928 -> Habilitar dedicatorias con videos Vimeo
git-svn-id: https://192.168.0.254/svn/Proyectos.ASong2U_Web/trunk@34 cd1a4ea2-8c7f-e448-aada-19d1fee9e1d6
This commit is contained in:
parent
8056c57123
commit
271ea08e86
@ -68,18 +68,36 @@ function bp_dedication_create_new_dedication() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$videoData = array();
|
$videoData = array();
|
||||||
$videoID = getVideoID($video_url);
|
|
||||||
|
if (isYoutubeVideo($video_url)) {
|
||||||
if (checkYoutubeId($videoID) == 1) {
|
$videoID = getYouTubeVideoID($video_url);
|
||||||
$xml = getVideoDetails($videoID);
|
|
||||||
if ($xml->title != 'YouTube Videos') {
|
if (checkYoutubeId($videoID) == 1) {
|
||||||
$videoData['videoURL'] = $video_url;
|
$xml = getYouTubeVideoDetails($videoID);
|
||||||
$videoData['title'] = $xml->title;
|
if ($xml->title != 'YouTube Videos') {
|
||||||
$videoData['description'] = $xml->content;
|
$videoData['videoURL'] = $video_url;
|
||||||
$videoData['thumbnail'] = "http://i.ytimg.com/vi/" . $videoID . "/hqdefault.jpg";
|
$videoData['title'] = $xml->title;
|
||||||
|
$videoData['description'] = $xml->content;
|
||||||
|
$videoData['thumbnail'] = "http://i.ytimg.com/vi/" . $videoID . "/hqdefault.jpg";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isVimeoVideo($video_url)) {
|
||||||
|
$videoID = getVimeoVideoID($video_url);
|
||||||
|
|
||||||
|
if (checkVimeoId($videoID) == 1) {
|
||||||
|
$xml = getVimeoVideoDetails($videoID);
|
||||||
|
if ($xml) {
|
||||||
|
$videoData['videoURL'] = $video_url;
|
||||||
|
$videoData['title'] = $xml->video->title;
|
||||||
|
$videoData['description'] = $xml->video->description;
|
||||||
|
$videoData['thumbnail'] = $xml->video->thumbnail_large;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
$category = get_category_by_slug(DEDICATION_CATEGORY_SLUG);
|
$category = get_category_by_slug(DEDICATION_CATEGORY_SLUG);
|
||||||
|
|
||||||
$new_post = array(
|
$new_post = array(
|
||||||
|
|||||||
@ -1,10 +1,32 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
function getVideoID($url) {
|
function isYoutubeVideo($url) {
|
||||||
$url = trim($url);
|
$yt1 = strpos($url, "youtube.com");
|
||||||
|
$yt2 = strpos($url, "youtu.be");
|
||||||
|
|
||||||
preg_match('#(\.be/|/embed/|/v/|/watch\?v=)([A-Za-z0-9_-]{5,11})#', $url, $matches);
|
return (($yt1) OR ($yt2));
|
||||||
if(isset($matches[2]) && $matches[2] != '') {
|
}
|
||||||
|
|
||||||
|
function isVimeoVideo($url) {
|
||||||
|
return strpos($url, "vimeo.com");
|
||||||
|
}
|
||||||
|
|
||||||
|
function getVimeoVideoID($url) {
|
||||||
|
$url = trim($url);
|
||||||
|
$matches = array();
|
||||||
|
|
||||||
|
$result = preg_match('/(\d+)/', $url, $matches);
|
||||||
|
if($result && isset($matches[0]) && $matches[0] != '') {
|
||||||
|
return $matches[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function getYouTubeVideoID($url) {
|
||||||
|
$url = trim($url);
|
||||||
|
$matches = array();
|
||||||
|
|
||||||
|
$result = preg_match('#(\.be/|/embed/|/v/|/watch\?v=)([A-Za-z0-9_-]{5,11})#', $url, $matches);
|
||||||
|
if($result && isset($matches[2]) && $matches[2] != '') {
|
||||||
return $matches[2];
|
return $matches[2];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -17,16 +39,30 @@ function checkYoutubeId($id) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getVideoDetails($id) {
|
function checkVimeoId($id) {
|
||||||
// create an array to return
|
if (!$data = @file_get_contents("http://vimeo.com/api/v2/video/" . $id . ".json"))
|
||||||
$videoDetails = Array();
|
return 0;
|
||||||
|
if ($data == "Video not found")
|
||||||
|
return 0;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function getYouTubeVideoDetails($id) {
|
||||||
// get the xml data from youtube
|
// get the xml data from youtube
|
||||||
$url = "http://gdata.youtube.com/feeds/api/videos/" . $id;
|
$url = "http://gdata.youtube.com/feeds/api/videos/" . $id;
|
||||||
$xml = simplexml_load_file($url);
|
$xml = simplexml_load_file($url);
|
||||||
return $xml;
|
return $xml;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getVimeoVideoDetails($id) {
|
||||||
|
// get the xml data from youtube
|
||||||
|
$url = "http://vimeo.com/api/v2/video/" . $id . ".xml";
|
||||||
|
$xml = simplexml_load_file($url);
|
||||||
|
return $xml;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function fetch_image($url) {
|
function fetch_image($url) {
|
||||||
if (function_exists("curl_init")) {
|
if (function_exists("curl_init")) {
|
||||||
return curl_fetch_image($url);
|
return curl_fetch_image($url);
|
||||||
|
|||||||
@ -18,6 +18,15 @@ form.standard-form ul.acfb-holder li {
|
|||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#youtube_vimeo_links {
|
||||||
|
float: right;
|
||||||
|
margin-right: 30px;
|
||||||
|
}
|
||||||
|
#youtube_vimeo_links a {
|
||||||
|
display: inline-block;
|
||||||
|
margin-left: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
#thumbs {
|
#thumbs {
|
||||||
background: #ccc url(img/thumbnail.jpg) center no-repeat;
|
background: #ccc url(img/thumbnail.jpg) center no-repeat;
|
||||||
width: 320px;
|
width: 320px;
|
||||||
|
|||||||
@ -72,25 +72,13 @@ jQuery(document).ready(function(){
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
var url = '';
|
|
||||||
|
|
||||||
j('#video_url').change(function(){
|
j('#video_url').change(function(){
|
||||||
// Check for empty input field
|
// Check for empty input field
|
||||||
if(j('#video_url').val() != ''){
|
if(j('#video_url').val() != ''){
|
||||||
// Get youtube video's thumbnail url
|
processVideoURL(j('#video_url').val());
|
||||||
// using jYoutube jQuery plugin
|
|
||||||
url = j.jYoutube(j('#video_url').val());
|
|
||||||
title = getYouTubeInfo(j('#video_url').val(),
|
|
||||||
function(artist, song){
|
|
||||||
j('#artist_name').val(artist);
|
|
||||||
j('#song_name').val(song);
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
// Now append this image to <div id="thumbs">
|
|
||||||
j('#thumbs').html(j('<img src="'+url+'" />'));
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
j('#video_url').keyup(function() { // works immediately when user press button inside of the input
|
j('#video_url').keyup(function() { // works immediately when user press button inside of the input
|
||||||
if( j('#video_url').val() != j('#video_url').data('val') ){ // check if value changed
|
if( j('#video_url').val() != j('#video_url').data('val') ){ // check if value changed
|
||||||
j('#video_url').data('val', j('#video_url').val() ); // save new value
|
j('#video_url').data('val', j('#video_url').val() ); // save new value
|
||||||
@ -129,6 +117,56 @@ jQuery(document).ready(function(){
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function processVideoURL(url){
|
||||||
|
var id;
|
||||||
|
var imgurl = '';
|
||||||
|
var j = jQuery;
|
||||||
|
|
||||||
|
if ((url.indexOf('youtube.com') > -1) || (url.indexOf('youtu.be') > -1)) {
|
||||||
|
imgurl = j.jYoutube(url);
|
||||||
|
j('#thumbs').html(j('<img src="'+imgurl+'" />'));
|
||||||
|
|
||||||
|
getYouTubeInfo(j('#video_url').val(),
|
||||||
|
function(artist, song){
|
||||||
|
j('#artist_name').val(artist);
|
||||||
|
j('#song_name').val(song);
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
} else if (url.indexOf('vimeo.com') > -1) {
|
||||||
|
if (url.match(/http:\/\/(www\.)?vimeo.com\/(\d+)($|\/)/)) {
|
||||||
|
id = url.split('/')[3];
|
||||||
|
} else if (url.match(/^vimeo.com\/channels\/[\d\w]+#[0-9]+/)) {
|
||||||
|
id = url.split('#')[1];
|
||||||
|
} else if (url.match(/vimeo.com\/groups\/[\d\w]+\/videos\/[0-9]+/)) {
|
||||||
|
id = url.split('/')[6];
|
||||||
|
} else {
|
||||||
|
j('#thumbs').html('');
|
||||||
|
}
|
||||||
|
|
||||||
|
j.ajax({
|
||||||
|
url: 'http://vimeo.com/api/v2/video/' + id + '.json',
|
||||||
|
dataType: 'jsonp',
|
||||||
|
success: function(data) {
|
||||||
|
imgurl = data[0].thumbnail_medium;
|
||||||
|
j('#thumbs').html(j('<img src="'+imgurl+'" />'));
|
||||||
|
|
||||||
|
var otitle = data[0].title;
|
||||||
|
var ntitle = otitle.match('^(.*) - (.*)$');
|
||||||
|
var song = (ntitle && (ntitle[2].length > 0 )) ? ntitle[2] : "";
|
||||||
|
var artist = (ntitle && (ntitle[1].length > 0 )) ? ntitle[1] : otitle;
|
||||||
|
j('#artist_name').val(artist);
|
||||||
|
j('#song_name').val(song);
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
j('#thumbs').html('');
|
||||||
|
}
|
||||||
|
return imgurl;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function ia_on_autocomplete_select( value, data ) {
|
function ia_on_autocomplete_select( value, data ) {
|
||||||
var j = jQuery;
|
var j = jQuery;
|
||||||
var friendIDs;
|
var friendIDs;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user