Created
September 23, 2013 08:51
-
-
Save da1nonly/6668055 to your computer and use it in GitHub Desktop.
youtube import wordpress
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if($type == 'youtube'){ | |
$playlist_id = $_POST['convert']; | |
if($old !== 'Data'){ | |
$url = "https://gdata.youtube.com/feeds/api/playlists/".$playlist_id."?v=2&alt=json&max-results=50"; | |
$data = json_decode(file_get_contents($url),true); | |
$info = $data["feed"]; | |
$video = $info["entry"]; | |
for($i=0;$i<count($video);$i++){ | |
if($video[$i]['link'][0]['href'] != ""){ | |
$text_title = str_replace("'", '', $video[$i]['title']['$t']); | |
$link .= $text_title.','; | |
parse_str( parse_url( $video[$i]['link'][0]['href'], PHP_URL_QUERY ), $my_array_of_vars ); | |
$link2 = "https://www.youtube.com/watch?v=".$my_array_of_vars['v']; | |
$link .= $link2.'$'; | |
} | |
} | |
$old = $link; | |
$new = array(); | |
$dataArrays = explode( "$", $old ); | |
// $dataArrays = ["name1, url1", "name2, url2", "name3, url3"]; | |
foreach( $dataArrays as $dataArray ) { | |
$separated = explode( ",", $dataArray ); | |
// $separated = ["name1", "url1"]; | |
array_push( $new, array( | |
'name' => trim($separated[0]), | |
'url' => trim($separated[1]) | |
) ); | |
} | |
if (empty($new) ) | |
add_post_meta($post_id, 'custom_video', $new, true); | |
elseif (!empty( $new ) && $new != $old ) | |
update_post_meta($post_id, 'custom_video', $new, true); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment