diff --git a/wp-admin/edit-form-advanced.php b/wp-admin/edit-form-advanced.php
index c9dc5b359d..672e37357c 100644
--- a/wp-admin/edit-form-advanced.php
+++ b/wp-admin/edit-form-advanced.php
@@ -37,9 +37,6 @@ if ('' != $pinged) {
$saveasdraft = '';
-$form_enclosure = '
' . __('(Separate multiple URIs with spaces.)') . '
-
';
-
if (empty($post_status)) $post_status = 'draft';
?>
diff --git a/wp-admin/post.php b/wp-admin/post.php
index 347eb539ae..2602ca17b6 100644
--- a/wp-admin/post.php
+++ b/wp-admin/post.php
@@ -386,7 +386,7 @@ case 'editpost':
if ($post_status == 'publish') {
do_action('publish_post', $post_ID);
do_trackbacks($post_ID);
- do_enclose( $content, $post_ID );
+ do_enclose( $content, $post_ID );
if ( get_option('default_pingback_flag') )
pingback($content, $post_ID);
}
diff --git a/wp-includes/functions-post.php b/wp-includes/functions-post.php
index 737fe19931..0b6ba30ba2 100644
--- a/wp-includes/functions-post.php
+++ b/wp-includes/functions-post.php
@@ -527,6 +527,25 @@ function get_pung($post_id) { // Get URIs already pung for a post
return $pung;
}
+function get_enclosed($post_id) { // Get enclosures already enclosed for a post
+ global $wpdb;
+ $custom_fields = get_post_custom( $post_id );
+ $pung = array();
+ if( is_array( $custom_fields ) ) {
+ while( list( $key, $val ) = each( $custom_fields ) ) {
+ if( $key == 'enclosure' ) {
+ if (is_array($val)) {
+ foreach($val as $enc) {
+ $enclosure = split( "\n", $enc );
+ $pung[] = trim( $enclosure[ 0 ] );
+ }
+ }
+ }
+ }
+ }
+ return $pung;
+}
+
function get_to_ping($post_id) { // Get any URIs in the todo list
global $wpdb;
$to_ping = $wpdb->get_var("SELECT to_ping FROM $wpdb->posts WHERE ID = $post_id");
diff --git a/wp-includes/functions.php b/wp-includes/functions.php
index ffb25914c6..6dbf142d66 100644
--- a/wp-includes/functions.php
+++ b/wp-includes/functions.php
@@ -731,37 +731,21 @@ function do_enclose( $content, $post_ID ) {
global $wp_version, $wpdb;
include_once (ABSPATH . WPINC . '/class-IXR.php');
- // original code by Mort (http://mort.mine.nu:8080)
- $log = debug_fopen(ABSPATH . '/pingback.log', 'a');
+ $log = debug_fopen(ABSPATH . '/enclosures.log', 'a');
$post_links = array();
debug_fwrite($log, 'BEGIN '.date('YmdHis', time())."\n");
- $pung = get_pung($post_ID);
+ $pung = get_enclosed( $post_ID );
- // Variables
$ltrs = '\w';
$gunk = '/#~:.?+=&%@!\-';
$punc = '.:?\-';
$any = $ltrs . $gunk . $punc;
- // Step 1
- // Parsing the post, external links (if any) are stored in the $post_links array
- // This regexp comes straight from phpfreaks.com
- // http://www.phpfreaks.com/quickcode/Extract_All_URLs_on_a_Page/15.php
preg_match_all("{\b http : [$any] +? (?= [$punc] * [^$any] | $)}x", $content, $post_links_temp);
- // Debug
debug_fwrite($log, 'Post contents:');
debug_fwrite($log, $content."\n");
-
- // Step 2.
- // Walking thru the links array
- // first we get rid of links pointing to sites, not to specific files
- // Example:
- // http://dummy-weblog.org
- // http://dummy-weblog.org/
- // http://dummy-weblog.org/post.php
- // We don't wanna ping first and second types, even if they have a valid
foreach($post_links_temp[0] as $link_test) :
if ( !in_array($link_test, $pung) ) : // If we haven't pung it already
@@ -797,13 +781,12 @@ function do_enclose( $content, $post_ID ) {
$len = substr( $len, 0, strpos( $len, "\n" ) );
$type = substr( $response, strpos( $response, "Content-Type:" ) + 14 );
$type = substr( $type, 0, strpos( $type, "\n" ) + 1 );
- $allowed_types = array( "video", "audio" );
+ $allowed_types = array( 'video', 'audio' );
if( in_array( substr( $type, 0, strpos( $type, "/" ) ), $allowed_types ) ) {
$meta_value = "$url\n$len\n$type\n";
$query = "INSERT INTO `".$wpdb->postmeta."` ( `meta_id` , `post_id` , `meta_key` , `meta_value` )
VALUES ( NULL, '$post_ID', 'enclosure' , '".$meta_value."')";
$wpdb->query( $query );
- add_ping( $post_ID, $url );
}
}
}
@@ -1021,9 +1004,8 @@ function update_post_caches($posts) {
}
// Get the categories for all the posts
- foreach ($posts as $post) {
+ foreach ($posts as $post)
$post_id_list[] = $post->ID;
- }
$post_id_list = implode(',', $post_id_list);
$dogs = $wpdb->get_results("SELECT DISTINCT
diff --git a/wp-includes/template-functions-post.php b/wp-includes/template-functions-post.php
index 246f5f689f..4d40d3a7dd 100644
--- a/wp-includes/template-functions-post.php
+++ b/wp-includes/template-functions-post.php
@@ -208,10 +208,34 @@ function link_pages($before='
', $after='
', $next_or_number='number',
* Post-meta: Custom per-post fields.
*/
-function get_post_custom() {
- global $id, $post_meta_cache;
-
- return $post_meta_cache[$id];
+function get_post_custom( $post_id = 0 ) {
+ global $id, $post_meta_cache, $wpdb;
+ if ( $post_id )
+ $id = $post_id;
+ if ( isset($post_meta_cache[$id]) ) {
+ return $post_meta_cache[$id];
+ } else {
+ if ( $meta_list = $wpdb->get_results("SELECT post_id, meta_key, meta_value FROM $wpdb->postmeta WHERE post_id = '$id' ORDER BY post_id, meta_key", ARRAY_A) ) {
+
+ // Change from flat structure to hierarchical:
+ $post_meta_cache = array();
+ foreach ($meta_list as $metarow) {
+ $mpid = $metarow['post_id'];
+ $mkey = $metarow['meta_key'];
+ $mval = $metarow['meta_value'];
+
+ // Force subkeys to be array type:
+ if (!isset($post_meta_cache[$mpid]) || !is_array($post_meta_cache[$mpid]))
+ $post_meta_cache[$mpid] = array();
+ if (!isset($post_meta_cache[$mpid]["$mkey"]) || !is_array($post_meta_cache[$mpid]["$mkey"]))
+ $post_meta_cache[$mpid]["$mkey"] = array();
+
+ // Add a value to the current pid/key:
+ $post_meta_cache[$mpid][$mkey][] = $mval;
+ }
+ return $post_meta_cache[$mpid];
+ }
+ }
}
function get_post_custom_keys() {