@copyright Copyright 2010 Silvia Pfeiffer @license http://www.gnu.org/licenses/gpl.txt GPL 2.0 @version 0.1 @link http://www.gingertech.net/ */ global $features_3_0; $features_3_0 = false; if (version_compare($wp_version,"3.0",">=")) { $features_3_0 = true; } require_once(ABSPATH . 'wp-admin/includes/taxonomy.php'); require_once(WP_PLUGIN_DIR . '/external-videos/ev-helpers.php'); require_once(WP_PLUGIN_DIR . '/external-videos/ev-video_sites.php'); require_once(WP_PLUGIN_DIR . '/external-videos/ev-widget.php'); require_once(WP_PLUGIN_DIR . '/external-videos/ev-shortcode.php'); require_once(WP_PLUGIN_DIR . '/external-videos/simple_html_dom.php'); require_once(WP_PLUGIN_DIR . '/external-videos/vimeo_library.php'); if ($features_3_0) { require_once(WP_PLUGIN_DIR . '/external-videos/ev-media-gallery.php'); } /// *** Pulling Videos From Diverse Sites *** /// function save_video($video) { // See if video exists $the_query = new WP_Query(array( 'post_type' => 'external-videos', 'meta_key' => 'video_id', 'meta_value' => $video['video_id'] )); while($the_query->have_posts()) { $query_video = $the_query->next_post(); if (get_post_meta($query_video->ID, 'host_id', true)) { return false; } } // put content together $video_content .= "
".$video['videourl']; $video_content .= "\n

".$video['description']."

"; if ($video['category'] != '') { $video_content .= "

Category: ".$video['category']; $video_content .= "
"; } $video_content .= "Uploaded by: ".$video['authorname'].""; $video_content .= "
"; $video_content .= "Hosted: ".$video['host_id'].""; $video_content .= "

"; // prepare post $video_post = array(); $video_post['post_type'] = 'external-videos'; $video_post['post_title'] = $video['title']; $video_post['post_content'] = $video_content; $video_post['post_status'] = 'publish'; $video_post['post_author'] = 1; $video_post['post_date'] = $video['published']; $video_post['tags_input'] = $video['keywords']; $video_post['post_mime_type'] = 'import'; // save to DB $post_id = wp_insert_post($video_post); // add post meta add_post_meta($post_id, 'host_id', $video['host_id']); add_post_meta($post_id, 'author_id', $video['author_id']); add_post_meta($post_id, 'video_id', $video['video_id']); add_post_meta($post_id, 'duration', $video['duration']); add_post_meta($post_id, 'author_url', $video['author_url']); add_post_meta($post_id, 'video_url', $video['videourl']); add_post_meta($post_id, 'thumbnail_url', $video['thumbnail']); // Cheat here with a dummy image so we can show thumbnails properly add_post_meta($post_id, '_wp_attached_file', 'dummy.png'); add_post_meta($post_id, 'description', $video['description']); // category id & tag attribution $category_id = get_cat_ID('External Videos'); wp_set_post_categories($post_id, array($category_id)); wp_set_post_tags($post_id, $video['keywords'], 'post_tag'); return true; } // FIX for getting the custom post type posts when querying for posts with a certain tag add_filter('pre_get_posts', 'query_post_type'); function query_post_type($query) { if(is_category() || is_tag()) { $post_type = get_query_var('post_type'); if($post_type) $post_type = $post_type; else $post_type = array('post','external-videos'); $query->set('post_type',$post_type); return $query; } } function update_videos($authors) { $current_videos = get_all_videos($authors); if (!$current_videos) return 0; // save new videos & determine list of all current video_ids $num_videos = 0; $video_ids = array(); foreach ($current_videos as $video) { array_push($video_ids, $video['video_id']); $is_new = save_video($video); if ($is_new) { $num_videos++; } } // remove deleted videos $del_videos = 0; $all_videos = new WP_Query(array('post_type' => 'external-videos', 'nopaging' => 1)); while($all_videos->have_posts()) { $old_video = $all_videos->next_post(); $video_id = get_post_meta($old_video->ID, 'video_id', true); if (!in_array($video_id, $video_ids)) { wp_delete_post($old_video->ID, false); $del_videos += 1; } } if ($del_videos > 0) { echo "Note: $del_videos video(s) were deleted on external host and thus removed from this collection."; } return $num_videos; } function get_all_videos($authors) { $new_videos = array(); foreach ($authors as $author) { switch ($author['host_id']) { case 'youtube': $videos = fetch_youtube_videos($author['author_id']); break; case 'vimeo': $videos = fetch_vimeo_videos($author['author_id'], $author['developer_key'], $author['secret_key']); break; case 'dotsub': $videos = fetch_dotsub_videos($author['author_id']); break; } // append $videos to the end of $new_videos array_splice($new_videos, count($new_array), 0, $videos); } return $new_videos; } function delete_videos() { $del_videos = 0; // query all post types of external videos $ev_posts = new WP_Query(array('post_type' => 'external-videos', 'nopaging' => 1)); while ($ev_posts->have_posts()) : $ev_posts->the_post(); wp_delete_post(get_the_ID(), false); $del_videos += 1; endwhile; return $del_videos; } // ADDS POST TYPES TO RSS FEED add_filter('request', 'ev_feed_request'); function ev_feed_request($qv) { $raw_options = get_option('external_videos_options'); $options = $raw_options == "" ? array('version' => 1, 'authors' => array(), 'rss' => false) : $raw_options; if ($options['rss'] == true) { if (isset($qv['feed']) && !isset($qv['post_type'])) $qv['post_type'] = array('external-videos', 'post'); } return $qv; } /// *** Admin Settings Page *** /// function remote_author_exists($host_id, $author_id) { $url = null; switch ($host_id) { case 'youtube': $url = "http://www.youtube.com/$author_id"; break; case 'vimeo': $url = "http://www.vimeo.com/$author_id"; break; case 'dotsub': $url = "http://dotsub.com/view/user/$author_id"; break; } $headers = wp_remote_request($url); if( is_wp_error( $headers ) ) { // return false on error return false; } if (!$headers || preg_match('/^[45]/', $headers['response']['code']) ) { return false; } return true; } function local_author_exists($host_id, $author_id, $authors) { foreach ($authors as $author) { if ( $author['author_id'] == $author_id && $author['host_id'] == $host_id ) { return true; } } return false; } function authorization_exists($host_id, $developer_key, $secret_key) { switch ($host_id) { case 'youtube': return true; case 'vimeo': if ($developer_key == "" or $secret_key == "") { return false; } case 'dotsub': return true; } return true; } function settings_page() { // activate cron hook if not active ev_activation(); wp_enqueue_script('jquery'); ?>
" style="display: none">

External Videos Settings

'YouTube', 'vimeo' => 'Vimeo', 'dotsub' => 'DotSub', ); $raw_options = get_option('external_videos_options'); $options = $raw_options == "" ? array('version' => 1, 'authors' => array(), 'rss' => false) : $raw_options; // clean up entered data from surplus white space $_POST['author_id'] = trim($_POST['author_id']); $_POST['secret_key'] = trim($_POST['secret_key']); $_POST['developer_key'] = trim($_POST['developer_key']); if ($_POST['external_videos'] == 'Y' ) { if ($_POST['action'] == 'add_author') { if (!array_key_exists($_POST['host_id'], $VIDEO_HOSTS)) { ?>

$_POST['host_id'], 'author_id' => $_POST['author_id'], 'developer_key' => $_POST['developer_key'], 'secret_key' => $_POST['secret_key']); update_option('external_videos_options', $options); ?>

$author) { if ($author['host_id'] == $_POST['host_id'] && $author['author_id'] == $_POST['author_id']) { unset($options['authors'][$key]); } } $options['authors'] = array_values($options['authors']); // also remove the author's videos from the posts table $del_videos = 0; $author_posts = new WP_Query(array('post_type' => 'external-videos', 'meta_key' => 'author_id', 'meta_value' => $_POST['author_id'], 'nopaging' => 1)); while($author_posts->have_posts()) { $query_video = $author_posts->next_post(); $host = get_post_meta($query_video->ID, 'host_id', true); if ($host == $_POST['host_id']) { wp_delete_post($query_video->ID, false); $del_videos += 1; } } update_option('external_videos_options', $options); ?>

Authors

Delete)
\n"; } ?>

Add Authors

">

Video Host:

Author ID:

Developer Key: (required for Vimeo, leave empty else)

Secret Key: (required for Vimeo, leave empty else)

Plugin Settings

">

/> Add video posts to Website RSS feed

Update Videos (newly added/deleted videos)

">

Next automatic update scheduled for:


Delete All Videos

Be careful with this option - you will lose all links you have built between blog posts and the video pages. This is really only meant as a reset option.

">

"", "title" => "Video Title", "thumbnail" => "Thumbnail", "host" => "Host", "duration" => "Duration", "published" => "Published", "parent" => "Attached to", "tags" => "Tags", "comments" => "Comments", ); return $columns; } add_action('manage_posts_custom_column', 'external_videos_custom_columns'); function external_videos_custom_columns($column_name) { global $post; $duration = get_post_meta($post->ID, 'duration'); $host = get_post_meta($post->ID, 'host_id'); $thumbnail = get_post_meta($post->ID, 'thumbnail_url'); switch($column_name) { case 'ID': echo $post->ID; break; case 'thumbnail': echo ""; break; case 'duration': echo $duration[0]; break; case 'published': echo $post->post_date; break; case 'host': echo $host[0]; break; case 'tags': echo $post->tags_input; break; case 'parent': if ( $post->post_parent > 0 ) { if ( get_post($post->post_parent) ) { $title =_draft_or_post_title($post->post_parent); } ?> ,
1, 'authors' => array(), 'rss' => false) : $raw_options; update_videos($options['authors']); } /// *** Setup of Plugin *** /// add_action('init', 'external_videos_init'); function external_videos_init() { // create a "video" category to store posts against wp_create_category('External Videos'); // create "external videos" post type register_post_type('external-videos', array( 'label' => __('External Videos'), 'singular_label' => __('External Video'), 'description' => ('pulls in videos from external hosting sites'), 'public' => true, 'publicly_queryable' => true, 'show_ui' => true, 'capability_type' => 'post', 'hierarchical' => false, 'rewrite' => false, 'query_var' => false, 'supports' => array('title', 'editor', 'author', 'thumbnail', 'excerpts', 'custom-fields', 'comments', 'revisions', 'excerpt'), 'taxonomies' => array('post_tag', 'category') )); // Oembed support for dotsub wp_oembed_add_provider('#http://(www\.)?dotsub\.com/view/.*#i', 'http://api.embed.ly/v1/api/oembed', true); // enable thickbox use for gallery wp_enqueue_style('thickbox'); wp_enqueue_script('thickbox'); } /// *** Setup of Videos Gallery: implemented in ev-media-gallery.php *** /// add_shortcode('external-videos', 'external_videos_gallery'); /// *** Setup of Widget: implemented in ev-widget.php file *** /// add_action('widgets_init', 'external_videos_load_widget');