get_row("SELECT * FROM {$wpdb->posts}, {$wpdb->postmeta} WHERE {$wpdb->posts}.ID = {$wpdb->postmeta}.post_id AND {$wpdb->postmeta}.meta_key = '_pingme' LIMIT 1")) { $wpdb->query("DELETE FROM {$wpdb->postmeta} WHERE post_id = {$ping->ID} AND meta_key = '_pingme';"); pingback($ping->post_content, $ping->ID); } # Do enclosures if enabled, and if doing enclosures, use our custom method if ( get_option('pod_disable_enclose') != 'yes' ) { // Do Enclosures while ($enclosure = $wpdb->get_row("SELECT * FROM {$wpdb->posts}, {$wpdb->postmeta} WHERE {$wpdb->posts}.ID = {$wpdb->postmeta}.post_id AND {$wpdb->postmeta}.meta_key = '_encloseme' LIMIT 1")) { $wpdb->query( $wpdb->prepare("DELETE FROM {$wpdb->postmeta} WHERE post_id = %d AND meta_key = '_encloseme';", $enclosure->ID) ); $this->do_enclose($enclosure->post_content, $enclosure->ID); } } // Do Trackbacks $trackbacks = $wpdb->get_col("SELECT ID FROM $wpdb->posts WHERE to_ping <> '' AND post_status = 'publish'"); if ( is_array($trackbacks) ) foreach ( $trackbacks as $trackback ) do_trackbacks($trackback); //Do Update Services/Generic Pings generic_ping(); } /** * The do_enclose method without the removing of enclosures that was causing issues for many users * This method has last been updated in WordPress 2.8 */ function do_enclose( $content, $post_ID ) { global $wpdb; include_once( ABSPATH . WPINC . '/class-IXR.php' ); $log = debug_fopen( ABSPATH . 'enclosures.log', 'a' ); $post_links = array(); debug_fwrite( $log, 'BEGIN ' . date( 'YmdHis', time() ) . "\n" ); $pung = get_enclosed( $post_ID ); $ltrs = '\w'; $gunk = '/#~:.?+=&%@!\-'; $punc = '.:?\-'; $any = $ltrs . $gunk . $punc; preg_match_all( "{\b http : [$any] +? (?= [$punc] * [^$any] | $)}x", $content, $post_links_temp ); debug_fwrite( $log, 'Post contents:' ); debug_fwrite( $log, $content . "\n" ); foreach ( (array) $post_links_temp[0] as $link_test ) { if ( !in_array( $link_test, $pung ) ) { // If we haven't pung it already $test = parse_url( $link_test ); if ( isset( $test['query'] ) ) $post_links[] = $link_test; elseif ( $test['path'] != '/' && $test['path'] != '' ) $post_links[] = $link_test; } } foreach ( (array) $post_links as $url ) { if ( $url != '' && !$wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE post_id = %d AND meta_key = 'enclosure' AND meta_value LIKE (%s)", $post_ID, $url . '%' ) ) ) { if ( $headers = wp_get_http_headers( $url) ) { $len = (int) $headers['content-length']; $type = $headers['content-type']; $allowed_types = array( 'video', 'audio' ); if ( in_array( substr( $type, 0, strpos( $type, "/" ) ), $allowed_types ) ) { $meta_value = "$url\n$len\n$type\n"; $wpdb->insert($wpdb->postmeta, array('post_id' => $post_ID, 'meta_key' => 'enclosure', 'meta_value' => $meta_value) ); } } } } } /** * The edit form used by Podcasting */ function editForm() { global $wpdb, $post; # If this is a valid post, grab a list of the enclosures for this 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); # Grab a list of all the podcasting formats $pod_formats = get_terms('podcast_format', 'get=all'); ?>
0 ) $pod_enclosure_ids .= ','; $enclosure_count++; # Append the current enclosure id to a list of enclosure ids $pod_enclosure_ids .= $enclosure['meta_id']; # Grab the contents of the enclosure $enclosure_value = explode("\n", $enclosure['meta_value']); # Grab and extract the iTunes specific data from the enclosure $enclosure_itunes = unserialize($enclosure_value[3]); # Determine the type of enclosure and mark the enclosure for a player button if necessary $podcast_player = ( 'mp3' == strtolower(substr(trim($enclosure_value[0]), -3)) ) ? true : false; $podcast_video_player_formats = array('m4v', 'mp4', 'mov', 'flv', 'm4a'); $podcast_video_player = ( in_array(strtolower(substr(trim($enclosure_value[0]), -3)), $podcast_video_player_formats) ) ? true : false; ### START THE ENCLOSURE HTML ### ?>
File
Format Keywords
Author Length Explicit
File URL
prepareEnclosure($_POST['pod_new_file_' . $pod_enclosure_id]); $pod_format = $_POST['pod_new_format_' . $pod_enclosure_id]; $enclosed = get_enclosed($postID); // Enclose the file using a custom method $headers = $this->getHttpHeaders($pod_content); # Check if the headers processed the file correctly, if they didn't try to clean up the file if ( $headers['response'] != '200' ) { $pod_content = podcasting_urlencode($pod_content); $headers = $this->getHttpHeaders($pod_content); } $length = (int) $headers['content-length']; $type = addslashes( $headers['content-type'] ); if ( $headers['response'] != '404' && is_array($headers) ) { add_post_meta($postID, 'enclosure', "$pod_content\n$length\n$type\n"); // Add relationship if new enclosure if ( !in_array($pod_content, $enclosed) ) { $pod_enclosure_id2 = $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($pod_enclosure_id2, $pod_format, 'podcast_format', false); } $added_enclosure_ids[] = $pod_enclosure_id; } } } } // Update enclosures if ( isset($_POST['pod_enclosure_ids']) ) { $pod_enclosure_ids = explode(',', $_POST['pod_enclosure_ids']); $pod_new_enclosure_ids = explode(',', substr($_POST['pod_new_enclosure_ids'], 0, -1)); $pod_ignore_enclosure_ids = explode(',', substr($_POST['pod_ignore_enclosure_ids'], 0, -1)); $pod_delete_enclosure_ids = explode(',', substr($_POST['pod_delete_enclosure_ids'], 0, -1)); $enclosures = $wpdb->get_results("SELECT meta_id, meta_value FROM {$wpdb->postmeta} WHERE post_id = {$postID} AND meta_key = 'enclosure' ORDER BY meta_id", ARRAY_A); $i = 0; if ( $_POST['pod_enclosure_ids'] != '' ) { foreach ($pod_enclosure_ids as $pod_enclosure_id) { // Ensure we're dealing with an ID $pod_enclosure_id = (int) $pod_enclosure_id; $itunes = serialize(array( 'format' => $_POST['pod_format_' . $pod_enclosure_id], 'keywords' => $_POST['pod_keywords_' . $pod_enclosure_id], 'author' => $_POST['pod_author_' . $pod_enclosure_id], 'length' => $_POST['pod_length_' . $pod_enclosure_id], 'explicit' => $_POST['pod_explicit_' . $pod_enclosure_id] )); // Update format wp_set_object_terms($pod_enclosure_id, $_POST['pod_format_' . $pod_enclosure_id], 'podcast_format', false); // Update enclsoure $enclosure = explode("\n", $enclosures[$i]['meta_value']); $enclosure[3] = $itunes; // Check that we have the full enclosure before updating it if ( is_array($enclosures) ) { update_post_meta($postID, 'enclosure', implode("\n", $enclosure), $enclosures[$i]['meta_value']); } $i++; // Delete enclosure if ( in_array($pod_enclosure_id, $pod_delete_enclosure_ids) ) { // Remove format wp_delete_object_term_relationships($pod_enclosure_id, 'podcast_format'); // Remove enclosure delete_meta($pod_enclosure_id); } } } if ( count($added_enclosure_ids) > 0 ) { foreach ($added_enclosure_ids as $pod_enclosure_id) { // Ensure we're dealing with an ID $pod_enclosure_id = (int) $pod_enclosure_id; // Check if the enclosure is on the ignore list if ( !in_array($pod_enclosure_id, $pod_ignore_enclosure_ids) ) { $itunes = serialize(array( 'format' => $_POST['pod_new_format_' . $pod_enclosure_id], 'keywords' => $_POST['pod_new_keywords_' . $pod_enclosure_id], 'author' => $_POST['pod_new_author_' . $pod_enclosure_id], 'length' => $_POST['pod_new_length_' . $pod_enclosure_id], 'explicit' => $_POST['pod_new_explicit_' . $pod_enclosure_id] )); // Update format $meta_id = $enclosures[$i]['meta_id']; wp_set_object_terms($meta_id, $_POST['pod_new_format_' . $pod_enclosure_id], 'podcast_format', false); // Update enclsoure $enclosure = explode("\n", $enclosures[$i]['meta_value']); $enclosure[3] = $itunes; $enclosure_insert = implode("\n", $enclosure); $wpdb->query("UPDATE {$wpdb->postmeta} SET meta_value = '$enclosure_insert' WHERE meta_id = '$meta_id'"); $i++; } } } } return $postID; } // podcasting_save_form() /** * Create a box for enclosure editing use */ function newEnclosureBox() { # Check AJAX referer check_ajax_referer('podcasting'); # Get the required variables $id = $_POST['pod_id']; $url = $_POST['pod_url']; $format = $_POST['pod_format']; # Grab a list of all the podcasting formats $pod_formats = get_terms('podcast_format', 'get=all'); # Determine the type of enclosure and mark the enclosure for a player button if necessary $podcast_player = ( 'mp3' == strtolower(substr(trim($url), -3)) ) ? true : false; $podcast_video_player_formats = array('m4v', 'mp4', 'mov', 'flv', 'm4a'); $podcast_video_player = ( in_array(strtolower(substr(trim($url), -3)), $podcast_video_player_formats) ) ? true : false; ?>
File
Format Keywords
Author Length Explicit
prepareEnclosure($_POST['file']); $headers = $this->getHttpHeaders($pod_content); # Check if the headers processed the file correctly, if they didn't try to clean up the file if ( $headers['response'] != '200' ) { $pod_content = podcasting_urlencode($pod_content); $headers = $this->getHttpHeaders($pod_content); } if ( $headers['response'] == '404' ) echo 'File not found on server (404). Verify the file exists and try again.'; elseif ( is_numeric($headers['response']) && $headers['response'] != '200' ) echo 'Server responded with http error code ' . $headers['response'] . '.'; elseif ( $headers['response'] != '200' ) echo 'Server failed to respond to remote request and did not provided error information.'; exit; } /** * Retrieves information about a given podcast through several different methods * @param - the URL of the file * @return an array containing file information */ function getHttpHeaders($url) { # Don't attempt to get enclosure information since we're accepting failure if ( get_option('pod_accept_fail') == 'yes' ) { $headers = array( 'response' => 200, 'content-length' => '1048576', 'content-type' => $this->getMimeType($url) ); return $headers; } # Try using wp_remote_head if ( function_exists('wp_remote_head') ) { $wp_head = wp_remote_head($url); # Check if the returned type is a WP_Error, if so, return nothing if ( is_wp_error($wp_head) ) return array('response' => '404'); $headers = array( 'response' => $wp_head['response']['code'], 'content-length' => $wp_head['headers']['content-length'], 'content-type' => $this->getMimeType($url) ); } else { # Try using wp_get_http_headers $wp_head = wp_get_http_headers($url); $headers = array( 'response' => '200', 'content-length' => $wp_head['content-length'], 'content-type' => $this->getMimeType($url) ); } # Try to get the headers locally if external URLs fail if ( $headers['response'] == '' || $headers['response'] == '404' ) { $local_host = $_SERVER['SERVER_NAME']; $file_parse_url = parse_url($url); $file_host = $file_parse_url['host']; $file_path = $_SERVER['DOCUMENT_ROOT'] . $file_parse_url['path']; # Double check we have a local file if ( $local_host == $file_host ) { if ( file_exists($file_path) ) { $headers['response'] = '200'; $headers['content-type'] = mime_content_type($file_path); $headers['content-length'] = filesize($file_path); } else { $headers['response'] = '404'; } } } return $headers; } /** * Retrieve the mime type of a file * * @param file - the file URL * @return the mime type **/ function getMimeType($file) { $parts = pathinfo($file); switch( strtolower($parts['extension']) ) { // Audio formats case 'mp3': // most common case 'mpga': case 'mp2': case 'mp2a': case 'm2a': case 'm3a': return 'audio/mpeg'; case 'm4a': return 'audio/x-m4a'; case 'ogg': return 'audio/ogg'; case 'wma': return 'audio/x-ms-wma'; case 'wax': return 'audio/x-ms-wax'; case 'ra': case 'ram': return 'audio/x-pn-realaudio'; case 'mp4a': return 'audio/mp4'; // Video formats case 'm4v': return 'video/x-m4v'; case 'mpeg': case 'mpg': case 'mpe': case 'm1v': case 'm2v': return 'video/mpeg'; case 'mp4': case 'mp4v': case 'mpg4': return 'video/mp4'; case 'asf': case 'asx': return 'video/x-ms-asf'; case 'wmx': return 'video/x-ms-wmx'; case 'avi': return 'video/x-msvideo'; case 'wmv': return 'video/x-ms-wmv'; // Check this case 'flv': return 'video/x-flv'; case 'swf': return 'application/x-shockwave-flash'; case 'mov': case 'qt': return 'video/quicktime'; case 'divx': return 'video/divx'; case '3gp': return 'video/3gpp'; // rarely used case 'mid': case 'midi': return'audio/midi'; case 'wav': return 'audio/wav'; case 'aa': return 'audio/audible'; case 'pdf': return 'application/pdf'; case 'torrent': return 'application/x-bittorrent'; default: // Let it fall through } // Last case let wordpress detect it: return wp_check_filetype($file); } /** * Cleans up after a deleted enclosure */ function deleteForm($postID) { $pod_enclosure_ids = explode(',', $_POST['pod_enclosure_ids']); foreach ($pod_enclosure_ids as $pod_enclosure_id) { $pod_enclosure_id = (int) $pod_enclosure_id; wp_delete_object_term_relationships($pod_enclosure_id, 'podcast_format'); } return $postID; } /** * Clean up a URL or file for entering into Podcasting * @param url - the url of the file * @return the cleaned up information */ function prepareEnclosure($url) { $url = trim($url); # Add the domain if given a relative URL if ( substr($url, 0, 4) != 'http' ) if ( substr($url, 0, 1) != '/' ) $url = get_option('home') . '/' . $url; else $url = get_option('home') . $url; return $url; } /** * Add the Javascript needed to edit enclosure information */ function addJavascript() { ?>