%tp_title% was uploaded by: %tp_author%
Duration: %tp_duration%
Rating: %tp_rating_img%'); define('DEFAULT_CONTENT', '%tp_player%

%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

'); return false; } elseif($gen_options['customfield'] && empty($gen_options['content']) && empty($gen_options['excerpt'])) { $warning .= __('

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 '
'; _e('

Imported Video List

'); echo '
'; if(isset($xml['feed']['entry'])) { foreach ($xml['feed']['entry'] as $video) { $video['id']['$t'] = extractID($video['id']['$t']); if(!tp_duplicate($video['id']['$t'])) { $status = 1; echo "{$video[ "; tp_write_post($video,$options); } } } else if(isset($xml['entry'])) { $xml['entry']['id']['$t'] = extractID($xml['entry']['id']['$t']); if(!tp_duplicate($xml['entry']['id']['$t'])) { $status = 1; echo "{$xml[ "; tp_write_post($xml['entry'],$options); } } else { $status = -1; } switch($status) { case -1: echo '

'.__('No Videos Found').$warning.'

'; break; case 0: echo '

'.__('Videos already imported').$warning.'

'; break; case 1: echo '

'.__('Videos imported successfully').$warning.'

'; break; default: if(!empty($warning)) { echo '

'.$warning.'

'; } break; } echo '
'; } function extractID($id) { return str_replace("http://gdata.youtube.com/feeds/api/videos/","",$id); } function tp_duplicate($id) { global $wpdb; $options = get_option('tp_options'); $post = $wpdb->get_results("SELECT ID FROM $wpdb->posts WHERE post_content like '%".$id."%' OR post_excerpt like '%".$id."%' LIMIT 1",ARRAY_A); $field = $wpdb->get_results("SELECT post_id FROM $wpdb->postmeta WHERE meta_value='".$id."' AND post_id NOT IN (SELECT post_id FROM $wpdb->postmeta where meta_key='_wp_trash_meta_status') LIMIT 1",ARRAY_A); return (bool) ((!empty($post) || !empty($field)) && $options['duplicate']); } function tp_player($id) { $opt = get_option('tp_options'); // color1 , color2, rel=0, border=1, width, height, autoplay=1 $pl = ''.$auto; $pl .= ''; if ($opt['color']==0) { $pl = '[wp-jw-player src="http://www.youtube.com/watch?v='.$id.'" image="http://i.ytimg.com/vi/'.$id.'/default.jpg"]'; } return $pl; } function tp_rating_c($r) { $img = ''; //$path = get_bloginfo('siteurl').'/wp-content/plugins/tubepress.net/images/'; $t = 0; for($i=0;$i'; } if($r > floor($r)) { $t = 1; $img .= ''; } 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 .= ''; $tf .= ' Category'; $tf .= ' '; $tf .= ' Add the imported videos to this category'; $tf .= ''; } return $tf; } function tp_order_form($options) { $orderoption = array("relevance"=>"Relevance","published"=>"Published","viewCount"=>"View Count","rating"=>"Rating"); $tf = 'Order By'; return $tf; } function tp_comment_form($options) { return ""; $tf .= ''; $tf .= ' Import Comments ?'; $tf .= ' '; $tf .= ' http://www.youtube.com/watch?v=ImtuJ-kzsAc

'Featured','featf'=>'top_rated', 'page'=>'1', 'per_page'=>'10'); if (isset($_POST['update_tp'])) { $options['featf'] = $_POST['featf']; $options['page'] = $_POST['page']; $options['per_page'] = $_POST['per_page']; $options['cat'] = $_POST['cat']; $options['orderby'] = $_POST['orderby']; $options['comments'] = $_POST['comments']; update_option('tp_options_feat', $options); tp_get_list($_POST,'featured'); } else { $opt = get_option('tp_options_feat'); $options = is_array($opt) ? array_merge($default,$opt) : $default; } ?>

'', 'page'=>'1', 'per_page'=>'10'); if (isset($_POST['update_tp'])) { $options['user'] = $_POST['user']; $options['page'] = $_POST['page']; $options['per_page'] = $_POST['per_page']; $options['cat'] = $_POST['cat']; $options['comments'] = $_POST['comments']; update_option('tp_options_fav', $options); tp_get_list($_POST,'favorite'); } else { $opt = get_option('tp_options_fav'); $options = is_array($opt) ? array_merge($default,$opt) : $default; } ?>

'', 'tag'=>'', 'page'=>'1', 'per_page'=>'10', 'orderby'=>'published'); if (isset($_POST['update_tp'])) { $options['user'] = $_POST['user']; $options['tag'] = $_POST['tag']; $options['page'] = $_POST['page']; $options['per_page'] = $_POST['per_page']; $options['orderby'] = $_POST['orderby']; $options['cat'] = $_POST['cat']; $options['comments'] = $_POST['comments']; update_option('tp_options_user', $options); tp_get_list($_POST,'user'); } else { $opt = get_option('tp_options_user'); $options = is_array($opt) ? array_merge($default,$opt) : $default; } ?>

'funny clips', 'page'=>'1', 'per_page'=>'10', 'orderby'=>'relevance'); if (isset($_POST['update_tp'])) { $options['tag'] = $_POST['tag']; $options['page'] = $_POST['page']; $options['per_page'] = $_POST['per_page']; $options['orderby'] = $_POST['orderby']; $options['cat'] = $_POST['cat']; $options['comments'] = $_POST['comments']; update_option('tp_options_tag', $options); tp_get_list($_POST,'tag'); } else { $opt = get_option('tp_options_tag'); $options = is_array($opt) ? array_merge($default,$opt) : $default; } ?>

e.g. funny videos '); ?>

'425','height'=>'344','autoplay'=>'0','rel'=>'1','color'=>'1','border'=>'0', 'duplicate'=>'1', 'type'=>'post', 'status'=>'publish', 'customfield'=>'0', 'excerpt'=>'',//
%tp_title% was uploaded by: %tp_author%
Duration: %tp_duration%
Rating: %tp_rating_img%', 'content'=>'',//%tp_player%

%tp_description%

', 'upgraded'=>'0', 'show_link'=>'0'); $data = tp_fetch("http://www.tubepress.net/data.php"); $tp_l = empty($data) ? "TubePress" : $data; $data = array('link_name'=>$tp_l,'link_url'=>'http://www.tubepress.net/'); if (isset($_POST['update_tp'])) { $options['width'] = $_POST['width']; $options['height'] = $_POST['height']; $options['autoplay'] = (bool) $_POST['autoplay']; $options['status'] = $_POST['status']; $options['type'] = $_POST['type']; $options['duplicate'] = (bool) $_POST['duplicate']; $options['rel'] = (bool) $_POST['rel']; $options['color'] = $_POST['color']; if ($_POST['color'] == 1) { $options['color1'] = "0xd6d6d6"; $options['color2'] = "0xf0f0f0"; } else if ($_POST['color'] == 2) { $options['color1'] = "0x3a3a3a"; $options['color2'] = "0x999999"; } else if ($_POST['color'] == 3) { $options['color1'] = "0x2b405b"; $options['color2'] = "0x6b8ab6"; } else if ($_POST['color'] == 4) { $options['color1'] = "0x006699"; $options['color2'] = "0x54abd6"; } else if ($_POST['color'] == 5) { $options['color1'] = "0x234900"; $options['color2'] = "0x4e9e00"; } else if ($_POST['color'] == 6) { $options['color1'] = "0xe1600f"; $options['color2'] = "0xfebd01"; } else if ($_POST['color'] == 7) { $options['color1'] = "0xcc2550"; $options['color2'] = "0xe87a9f"; } else if ($_POST['color'] == 8) { $options['color1'] = "0x402061"; $options['color2'] = "0x9461ca"; } else if ($_POST['color'] == 9) { $options['color1'] = "0x5d1719"; $options['color2'] = "0xcd311b"; } $options['border'] = (bool) $_POST['border']; $options['customfield'] = (bool) $_POST['customfield']; $options['content'] = $_POST['content']; $options['excerpt'] = $_POST['excerpt']; $options['show_link'] = (bool) $_POST['show_link']; if($options['show_link']) { tp_insert_link($data); } else { tp_remove_link(); } update_option('tp_options', $options); if(!$options['customfield'] && (empty($options['content']) || empty($options['excerpt']))) { $warning .= __('

You have to customize the Content Template and/or Content Excerpt, otherwise your posts/pages will not show the imported videos

'); } elseif($options['customfield'] && empty($options['content']) && empty($options['excerpt'])) { $warning .= __('

Do not forget to edit your template to make use of these custom fields instead of the default the_content() and the_excerpt() calls

'); } ?>

>
/>
/>
/>
/>
> > > > > > > > >
> Download it here'); ?>
 
 
/>
/> Custom Fields: tp_player, tp_thumbnail, tp_title, tp_description, tp_duration, tp_author, tp_tags, tp_rating_num, tp_rating_img, tp_viewcount, tp_id, tp_url
Note: You need to modify your template to make use of these custom fields'); ?>
Use this code for example:').htmlentities(__(DEFAULT_CONTENT)); ?>
Use this code for example:').htmlentities(__(DEFAULT_EXCERPT)); ?>

  • %tp_player%: Displays the video player
  • %tp_thumbnail%: Displays the thumbnail image
  • %tp_title%: Displays the title of the video
  • %tp_description%: Displays the description of the video
  • %tp_duration%: Displays the length of the video
  • %tp_author%: Displays the username of the author
  • %tp_tags%: Displays the tags
  • %tp_rating_num%: Displays the video rating in numbers
  • %tp_rating_img%: Displays the video star rating images
  • %tp_viewcount%: Displays how many times the video was viewed
  • %tp_id%: Displays the video id
  • %tp_url%: Displays the youtube video url

If you like the plugin and find it useful, show your support with a PayPal donation
'; return '

If you like the plugin and find it useful, show your support with a PayPal donation

'; } function tp_insert_link($data) { global $wpdb; $link_id = $wpdb->get_var("SELECT link_id FROM $wpdb->links WHERE link_url='".$data['link_url']."'"); if($link_id == null) { $link_id = wp_insert_link($data); } update_option('tp_link_id',$link_id); } function tp_remove_link() { global $wpdb; if($link_id = get_option('tp_link_id')) { wp_delete_link($link_id); } } function tp_patch() { global $wpdb; $posts = $wpdb->get_results("SELECT ID,post_content,post_excerpt FROM $wpdb->posts WHERE post_excerpt like '
'.$autoplay_code.$rel_code.''.$href_code.''; $content = $display.$content; $postarr = array('ID'=>$post_id,'post_content'=>$content,'post_excerpt'=>$excerpt); wp_update_post($postarr); } } function tp_upgrade() { global $wpdb; $options = get_option('tp_options'); $posts = $wpdb->get_results("SELECT ID,post_content FROM $wpdb->posts WHERE post_content like '%[/ID]%'",ARRAY_A); if(!is_array($posts)) return false; foreach($posts as $post) { $post_id = $post['ID']; $content = $post['post_content']; if (preg_match_all("|\[[A-Z]+\](.*)\[\/[A-Z]+\]|sU",$content,$match)) { //Convert the average rating into image $post_rating = ""; if ($match[1][4] == 0) { $post_rating .= ""; } elseif (($match[1][4] > 0)&&($match[1][4] < 1)) { $post_rating .= ""; } elseif (($match[1][4] > 1)&&($match[1][4] < 2)) { $post_rating .= ""; } elseif (($match[1][4] > 2)&&($match[1][4] < 3)) { $post_rating .= ""; } elseif (($match[1][4] > 3)&&($match[1][4] < 4)) { $post_rating .= ""; } elseif (($match[1][4] > 4)&&($match[1][4] < 5)) { $post_rating .= ""; } elseif ($match[1][4] == 5) { $post_rating .= ""; } //end convert average rating $excerpt = ''; $ytimg = (empty($match[1][3])) ? "http://i.ytimg.com/vi/".$match[1][1]."/default.jpg" : $match[1][3]; $excerpt .= '
'; $excerpt .= ''; $excerpt .= '
'; $excerpt .= "

".$match[1][0]."

"; if ($options['is_autoplay'] || $options['autoplay']) { $autoplay_code = ''; $autoplay_kode = '&autoplay=1'; } else { $autoplay_code= ''; $autoplay_kode = ''; } if ($options['is_rel'] || $options['rel']) { $rel_code = ''; $rel_kode = '&rel=0'; $href_code = ''; $href_kode = 'enablehref="false" allownetworking="internal"'; } else { $rel_code = ''; $rel_kode = ''; $href_code = ''; $href_kode = ''; } $display = ''.$autoplay_code.$rel_code.''.$href_code.''; $display .= '

'.$match[1][0].'

'; if($options['is_author'] && !empty($match[1][2])) { $display .= "

Author: ".$match[1][2]."

"; } if($options['is_rating'] && !empty($match[1][4])) { $display .= "

Rating: ".$post_rating."

"; } if($options['is_viewed'] && !empty($match[1][5])) { $display .= "

Viewed: ".$match[1][5]." times

"; } if($options['is_tags'] && !empty($match[1][6])) { $display .= "

Tags: ".$match[1][6]."

"; } if($options['is_upload'] && !empty($match[1][7])) { $display .= "

Uploaded ".date('F j, Y',$match[1][7])."

"; } if($options['is_length'] && !empty($match[1][8])) { $display .= "

Duration: 0".floor($match[1][8]/60).":".($match[1][8] % 60)."

"; } $postarr = array('ID'=>$post_id,'post_content'=>$display,'post_excerpt'=>$excerpt); wp_update_post($postarr); } } } function tp_add_options_page() { add_menu_page('TubePress', 'TubePress', 8, __FILE__, 'tp_manage_options'); add_submenu_page(__FILE__, 'Setup', 'Setup', 8, __FILE__, 'tp_manage_options'); add_submenu_page(__FILE__, 'Import By Tag', 'Import By Tag', 8, 'tubepress-tag.php', 'tp_import_tag'); add_submenu_page(__FILE__, 'My Videos', 'My Videos', 8, 'tubepress-user.php', 'tp_import_user'); add_submenu_page(__FILE__, 'My Favorite Videos', 'My Favorite Videos', 8, 'tubepress-favorite.php', 'tp_import_favorite'); add_submenu_page(__FILE__, 'Featured Videos', 'Featured Videos', 8, 'tubepress-featured.php', 'tp_import_featured'); add_submenu_page(__FILE__, 'Import By ID', 'Import By ID', 8, 'tubepress-id.php', 'tp_import_id'); } add_action('admin_menu', 'tp_add_options_page'); ?>