$_POST['pod_format_new_slug']) : ''; $format = wp_insert_term($_POST['pod_format_new_name'], 'podcast_format', $args); $format = get_term($format['term_id'], 'podcast_format'); $pod_explicits = unserialize(get_option('pod_formats')); $pod_explicits[$format->slug] = $_POST['pod_format_new_explicit']; update_option('pod_formats', serialize($pod_explicits)); } // Update formats if ( isset($_POST['term_ids']) ) { foreach ( $term_ids as $term_id ) { $term_id = (int) $term_id; $format = get_term($term_id, 'podcast_format'); if ( isset($_POST["delete_pod_format_$term_id"]) ) wp_delete_term($term_id, 'podcast_format'); // Update taxonomy $args = array( 'name' => $_POST["pod_format_name_$term_id"], 'slug' => $_POST["pod_format_slug_$term_id"] ); wp_update_term($term_id, 'podcast_format', $args); // Update explicit $pod_explicits[$format->slug] = $_POST["pod_format_explicit_$term_id"]; update_option('pod_formats', serialize($pod_explicits)); } } // Clear used variables unset($term_ids); } // iTunes category options $pod_itunes_cats = array( 'Arts', 'Arts||Design', 'Arts||Fashion & Beauty', 'Arts||Food', 'Arts||Literature', 'Arts||Performing Arts', 'Arts||Visual Arts', 'Business', 'Business||Business News', 'Business||Careers', 'Business||Investing', 'Business||Management & Marketing', 'Business||Shopping', 'Comedy', 'Education', 'Education||Education Technology', 'Education||Higher Education', 'Education||K-12', 'Education||Language Courses', 'Education||Training', 'Games & Hobbies', 'Games & Hobbies||Automotive', 'Games & Hobbies||Aviation', 'Games & Hobbies||Hobbies', 'Games & Hobbies||Other Games', 'Games & Hobbies||Video Games', 'Government & Organizations', 'Government & Organizations||Local', 'Government & Organizations||National', 'Government & Organizations||Non-Profit', 'Government & Organizations||Regional', 'Health', 'Health||Alternative Health', 'Health||Fitness & Nutrition', 'Health||Self-Help', 'Health||Sexuality', 'Kids & Family', 'Music', 'News & Politics', 'Religion & Spirituality', 'Religion & Spirituality||Buddhism', 'Religion & Spirituality||Christianity', 'Religion & Spirituality||Hinduism', 'Religion & Spirituality||Islam', 'Religion & Spirituality||Judaism', 'Religion & Spirituality||Other', 'Religion & Spirituality||Spirituality', 'Science & Medicine', 'Science & Medicine||Medicine', 'Science & Medicine||Natural Sciences', 'Science & Medicine||Social Sciences', 'Society & Culture', 'Society & Culture||History', 'Society & Culture||Personal Journals', 'Society & Culture||Philosophy', 'Society & Culture||Places & Travel', 'Sports & Recreation', 'Sports & Recreation||Amateur', 'Sports & Recreation||College & High School', 'Sports & Recreation||Outdoor', 'Sports & Recreation||Professional', 'Technology', 'Technology||Gadgets', 'Technology||Tech News', 'Technology||Podcasting', 'Technology||Software How-To', 'TV & Film' ); $pod_formats = get_terms('podcast_format', 'get=all'); ?>
'; } // Podcasting post form function podcasting_edit_form() { global $wpdb, $post; if ($post->ID) $enclosures = $wpdb->get_results("SELECT meta_id, meta_value FROM {$wpdb->postmeta} WHERE post_id = {$post->ID} AND meta_key = 'enclosure' ORDER BY meta_id", ARRAY_A); $pod_formats = get_terms('podcast_format', 'get=all'); ?> $_POST['pod_format_' . $enclosure_id], 'keywords' => $_POST['pod_keywords_' . $enclosure_id], 'author' => $_POST['pod_author_' . $enclosure_id], 'length' => $_POST['pod_length_' . $enclosure_id], 'explicit' => $_POST['pod_explicit_' . $enclosure_id] )); // Update format wp_set_object_terms($enclosure_id, $_POST['pod_format_' . $enclosure_id], 'podcast_format', false); // Update enclsoure $enclosure = explode("\n", $enclosures[$i]); $enclosure[3] = $itunes; update_post_meta($postID, 'enclosure', implode("\n", $enclosure), $enclosures[$i]); $i++; // Delete enclosure if (isset($_POST['delete_pod_' . $enclosure_id])) { // Remove format wp_delete_object_term_relationships($enclosure_id, 'podcast_format'); // Remove enclosure delete_meta($enclosure_id); // Fake a save $_POST['save'] = 'Update'; } } // Add new enclosures if ( (isset($_POST['pod_new_file'])) && ('' != $_POST['pod_new_file']) ) { $content = $_POST['pod_new_file']; $enclosed = get_enclosed($postID); do_enclose($content, $postID); // Add relationship if new enclosure if ( !in_array($content, $enclosed) ) { $enclosure_id = $wpdb->get_var("SELECT meta_id FROM {$wpdb->postmeta} WHERE post_id = {$postID} AND meta_key = 'enclosure' ORDER BY meta_id DESC"); // Find the enclosure we just added wp_set_object_terms($enclosure_id, 'default-format', 'podcast_format', false); } } return $postID; } // podcasting_save_form() // Cleanup a deleted post function podcasting_delete_form($postID) { $enclosure_ids = explode(',', $_POST['enclosure_ids']); foreach ($enclosure_ids as $enclosure_id) { $enclosure_id = (int) $enclosure_id; wp_delete_object_term_relationships($enclosure_id, 'podcast_format'); } return $postID; } /* ------------------------------------- WORK -------------------------------------- */ // Create a custom feed function do_feed_podcast() { global $wp_query; $wp_query->get_posts(); load_template(ABSPATH . 'wp-rss2.php'); } // Pretty permalinks for the custom feed function podcasting_rewrite_rules($wp_rewrite) { // Rewrite rules are manually entered as there is no hook for adding addition feed queries $feed_rules = array( 'podcast/(.+)/?$' => 'index.php?feed=podcast&format=' . $wp_rewrite->preg_index(1), 'feed/podcast/(.+)/?$' => 'index.php?feed=podcast&format=' . $wp_rewrite->preg_index(1), 'search/(.+)/podcast/(.+)/?$' => 'index.php?s=' . $wp_rewrite->preg_index(1) . '&feed=podcast&format=' . $wp_rewrite->preg_index(2), 'search/(.+)/feed/podcast/(.+)/?$' => 'index.php?s=' . $wp_rewrite->preg_index(1) . '&feed=podcast&format=' . $wp_rewrite->preg_index(2), 'category/(.+?)/podcast/(.+)/?$' => 'index.php?category_name=' . $wp_rewrite->preg_index(1) . '&feed=podcast&format=' . $wp_rewrite->preg_index(2), 'category/(.+?)/feed/podcast/(.+)/?$' => 'index.php?category_name=' . $wp_rewrite->preg_index(1) . '&feed=podcast&format=' . $wp_rewrite->preg_index(2), 'tag/(.+?)/podcast/(.+)/?$' => 'index.php?tag=' . $wp_rewrite->preg_index(1) . '&feed=podcast&format=' . $wp_rewrite->preg_index(2), 'tag/(.+?)/feed/podcast/(.+)/?$' => 'index.php?tag=' . $wp_rewrite->preg_index(1) . '&feed=podcast&format=' . $wp_rewrite->preg_index(2), 'author/([^/]+)/podcast/(.+)/?$' => 'index.php?author_name=' . $wp_rewrite->preg_index(1) . '&feed=podcast&format=' . $wp_rewrite->preg_index(2), 'author/([^/]+)/feed/podcast/(.+)/?$' => 'index.php?author_name=' . $wp_rewrite->preg_index(1) . '&feed=podcast&format=' . $wp_rewrite->preg_index(2), '([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/podcast/(.+)/?$' => 'index.php?year=' . $wp_rewrite->preg_index(1) . '&monthnum=' . $wp_rewrite->preg_index(2) . '&day=' . $wp_rewrite->preg_index(3) . '&feed=podcast&format=' . $wp_rewrite->preg_index(4), '([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/feed/podcast/(.+)/?$' => 'index.php?year=' . $wp_rewrite->preg_index(1) . '&monthnum=' . $wp_rewrite->preg_index(2) . '&day=' . $wp_rewrite->preg_index(3) . '&feed=podcast&format=' . $wp_rewrite->preg_index(4), '([0-9]{4})/([0-9]{1,2})/podcast/(.+)/?$' => 'index.php?year=' . $wp_rewrite->preg_index(1) . '&monthnum=' . $wp_rewrite->preg_index(2) . '&feed=podcast&format=' . $wp_rewrite->preg_index(3), '([0-9]{4})/([0-9]{1,2})/feed/podcast/(.+)/?$' => 'index.php?year=' . $wp_rewrite->preg_index(1) . '&monthnum=' . $wp_rewrite->preg_index(2) . '&feed=podcast&format=' . $wp_rewrite->preg_index(3), '([0-9]{4})/podcast/(.+)/?$' => 'index.php?year=' . $wp_rewrite->preg_index(1) . '&feed=podcast&format=' . $wp_rewrite->preg_index(2), '([0-9]{4})/feed/podcast/(.+)/?$' => 'index.php?year=' . $wp_rewrite->preg_index(1) . '&feed=podcast&format=' . $wp_rewrite->preg_index(2), '([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/([^/]+)/podcast/(.+)/?$' => 'index.php?year=' . $wp_rewrite->preg_index(1) . '&monthnum=' . $wp_rewrite->preg_index(2) . '&day=' . $wp_rewrite->preg_index(3) . '&name=' . $wp_rewrite->preg_index(4) . '&feed=podcast&format=' . $wp_rewrite->preg_index(5), '([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/([^/]+)/feed/podcast/(.+)/?$' => 'index.php?year=' . $wp_rewrite->preg_index(1) . '&monthnum=' . $wp_rewrite->preg_index(2) . '&day=' . $wp_rewrite->preg_index(3) . '&name=' . $wp_rewrite->preg_index(4) . '&feed=podcast&format=' . $wp_rewrite->preg_index(5) ); $wp_rewrite->rules = $feed_rules + $wp_rewrite->rules; } // podcasting_rewrite_rules() // Adds variable to select format for podcasting function podcasting_query_vars($vars) { $vars[] = 'format'; return $vars; } // Add the join needed for enclosures only function podcasting_feed_join($join) { global $wpdb; if ( 'podcast' == get_query_var('feed') ) { $join .= " INNER JOIN {$wpdb->postmeta} pod_meta ON {$wpdb->posts}.ID = pod_meta.post_id"; $join .= " INNER JOIN {$wpdb->term_relationships} pod_rel ON (pod_meta.meta_id = pod_rel.object_id)"; $join .= " INNER JOIN {$wpdb->term_taxonomy} pod_tax ON (pod_rel.term_taxonomy_id = pod_tax.term_taxonomy_id)"; $join .= " INNER JOIN {$wpdb->terms} pod_terms ON (pod_tax.term_id = pod_terms.term_id)"; } return $join; } // Add the where needed for enclosures only function podcasting_feed_where($where) { global $wpdb; if ( 'podcast' == get_query_var('feed') ) { $podcast_format = ( '' == get_query_var('format') ) ? 'default-format' : get_query_var('format'); $where .= " AND pod_meta.meta_key = 'enclosure'"; $where .= " AND pod_terms.slug = '{$podcast_format}'"; } return $where; } // Add the groupby needed for enclosures only function podcasting_feed_groupby($groupby) { global $wpdb; if ( 'podcast' == get_query_var('feed') ) $groupby = "{$wpdb->posts}.ID"; return $groupby; } // Add the feed autodiscovery links to section function podcasting_add_feed_discovery() { global $wp_rewrite; $podcast_url = ($wp_rewrite->using_permalinks()) ? '/feed/podcast/' : '/?feed=podcast'; $podcast_url = get_option('home') . $podcast_url; echo ' ' . "\n"; // Formats $pod_formats = get_terms('podcast_format', 'get=all'); foreach ($pod_formats as $pod_format) { if ( 'default-format' != $pod_format->slug ) { $podcast_format_url = ($wp_rewrite->using_permalinks()) ? $podcast_url . "$pod_format->slug/" : $podcast_url . "&format=$pod_format->slug"; echo ' name)" . '" href="' . $podcast_format_url . '" />' . "\n"; } } } // Add the iTunes xml information function podcasting_add_itunes_xml() { if ( 'podcast' == get_query_var('feed') ) { echo 'xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"'; } } // Change the podcast title function podcasting_blogname_filter($title) { if ( 'podcast' == get_query_var('feed') ) { $podcast_format = get_term_by('slug', get_query_var('format'), 'podcast_format'); $title = stripslashes(get_option('pod_title')); if ( 'default-format' != get_query_var('format') && '' != get_query_var('format') && !empty($podcast_format) ) $title .= " ($podcast_format->name)"; } return $title; } // Change the podcast tagline function podcasting_blogdescription_filter($tagline) { if ( 'podcast' == get_query_var('feed') ) $tagline = stripslashes(get_option('pod_tagline')); return $tagline; } // Add the special iTunes information to channel function podcasting_add_itunes_feed() { if ( 'podcast' == get_query_var('feed') ) { // iTunes summary if ( '' != get_option('pod_itunes_summary') ) echo '