%tp_description%
'); class youtube { var $url; function users_list_favorite_videos($user, $page=1, $results=10) { $functionName = "/feeds/api/users/".$user."/favorites"; $payload = array("start-index"=>$page,"max-results"=>$results); $results = $this->getGdataRsp($functionName, $payload); return $results; } function videos_get_details($video_id) { $functionName = "/feeds/api/videos/".$video_id; $payload = ""; $results = $this->getGdataRsp($functionName, $payload); return $results; } function videos_list_by_tag($tag, $page=1, $results=10, $order="relevance") { $functionName = "/feeds/api/videos"; $tag = urlencode($tag); $payload = array("vq"=>$tag,"start-index"=>$page,"max-results"=>$results,"orderby"=>$order); $results = $this->getGdataRsp($functionName, $payload); return $results; } function videos_list_by_user($user, $tag="", $page=1, $results=10, $order="published") { $functionName = "/feeds/api/users/".$user."/uploads"; $payload = array("start-index"=>$page,"max-results"=>$results,"orderby"=>$order); if(!empty($tag)) { $payload["vq"] = $tag; } $results = $this->getGdataRsp($functionName, $payload); return $results; } function videos_list_featured($feat, $page=1, $results=10, $order="published") { $functionName = "/feeds/api/standardfeeds/".$feat; $payload = array("start-index"=>$page,"max-results"=>$results,"orderby"=>$order); $results = $this->getGdataRsp($functionName, $payload); return $results; } function getGdataRsp($functionName, $payload) { $this->url = $this->buildQuery($functionName, $payload); $response = json_decode(tp_fetch($this->url),true); return $response; } function buildQuery($functionName, $payload) { $payloadString = ""; if ($payload != "") { foreach ($payload as $name => $value) { $payloadString .= '&'.$name.'='.$value; } } $url = 'http://gdata.youtube.com'.$functionName.'?alt=json'.$payloadString; return $url; } } if(!function_exists('json_decode') ){ function json_decode($content, $assoc=false){ require_once('JSON.php'); if ( $assoc ){ $json = new Services_JSON(SERVICES_JSON_LOOSE_TYPE); } else { $json = new Services_JSON; } return $json->decode($content); } } function tp_fetch($url) { if(!class_exists('Snoopy')) { require_once( ABSPATH . WPINC . '/class-snoopy.php'); } $client = new Snoopy(); $client->fetch($url); return $client->results; } $yt = new youtube(); function tp_get_list($options,$action='tag') { global $yt; //$options = get_option('tp_options_user'); $warning = ''; $status = 0; $gen_options = get_option('tp_options'); if(!$gen_options['customfield'] && (empty($gen_options['content']) || empty($gen_options['excerpt']))) { _e('You have to customize the Content Template and/or Content Excerpt, otherwise your posts/pages will not show the imported videos
Do not forget to edit your template to make use of these custom fields instead of the default the_content() and the_excerpt() calls
'); } if(!is_array($options)) return false; switch($action) { case 'id': $xml = $yt->videos_get_details($options['video_id']); break; case 'user': $xml = $yt->videos_list_by_user($options['user'], $options['tag'], $options['page'], $options['per_page'], $options['orderby']); break; case 'featured': $xml = $yt->videos_list_featured($options['featf'], $options['page'], $options['per_page'], $options['orderby']); break; case 'favorite': $xml = $yt->users_list_favorite_videos($options['user'], $options['page'], $options['per_page']); break; case 'tag': $xml = $yt->videos_list_by_tag($options['tag'], $options['page'], $options['per_page'], $options['orderby']); break; } echo ''.__('No Videos Found').$warning.'
'.__('Videos already imported').$warning.'
'.__('Videos imported successfully').$warning.'
'.$warning.'
'; }
for($i=0;$i<5-floor($r)-$t;$i++) { $img .= '
'; }
return $img;
}
function tp_write_post($v,$opt) {
$tpo = get_option('tp_options');
$post_template_excerpt = $tpo['excerpt'];
$post_template_content = $tpo['content'];
$post_status = !empty($tpo['status']) ? $tpo['status'] : 'publish';
$vid = (!empty($v['id']['$t'])) ? $v['id']['$t'] : $opt['video_id'];
$tp_tags = array("%tp_player%","%tp_id%","%tp_title%","%tp_thumbnail%","%tp_description%","%tp_duration%","%tp_rating_num%","%tp_rating_img%","%tp_viewcount%","%tp_author%","%tp_tags%","%tp_url%");
$tag_values = array(tp_player($vid),$vid,$v['title']['$t'],$v['media$group']['media$thumbnail'][0]['url'],$v['content']['$t'],$v['media$group']['yt$duration']['seconds'],$v['gd$rating']['average'],tp_rating_c($v['gd$rating']['average']),$v['yt$statistics']['viewCount'],$v['author'][0]['name']['$t'],$v['media$group']['media$keywords']['$t'],$v['media$group']['media$player'][0]['url']);
$post_template_excerpt = str_replace($tp_tags,$tag_values,$post_template_excerpt);
$post_template_content = str_replace($tp_tags,$tag_values,$post_template_content);
$post_category = explode(',', trim($opt['cat'], " \n\t\r\0\x0B,"));
$post_tags = explode(', ', trim($v['media$group']['media$keywords']['$t']," \n\t\r\0\x0B,"));
$tp_post = array('post_title' => $v['title']['$t'],
'post_content' => nl2br($post_template_content),
'post_status' => $post_status,
'post_type' => $tpo['type'],
'post_name' => sanitize_title($v['title']['$t']),
'post_category' => $post_category,
'tags_input' => $post_tags,
'post_excerpt' => nl2br($post_template_excerpt));
$post_id = wp_insert_post($tp_post);
if($tpo['customfield']) {
foreach($tp_tags as $k=>$meta_key) {
add_post_meta($post_id, str_replace("%","",$meta_key), $tag_values[$k]);
}
}
wp_create_categories($post_category,$post_id);
}
function tp_category_form($options) {
$tpo = get_option('tp_options');
$tf = '';
if($tpo['type'] == 'post') {
$tf .= '