Make WordPress Core

Changeset 10383


Ignore:
Timestamp:
01/19/2009 10:19:45 PM (16 years ago)
Author:
westi
Message:

Don't duplicate enclosures on edit. See #7773 props redsweater.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/xmlrpc.php

    r10382 r10383  
    22322232
    22332233        // Handle enclosures
    2234         $enclosure = $content_struct['enclosure'];
     2234        $this->add_enclosure_if_new($post_ID, $content_struct['enclosure']);
     2235
     2236        $this->attach_uploads( $post_ID, $post_content );
     2237
     2238        logIO('O', "Posted ! ID: $post_ID");
     2239
     2240        return strval($post_ID);
     2241    }
     2242
     2243    function add_enclosure_if_new($post_ID, $enclosure) {
    22352244        if( is_array( $enclosure ) && isset( $enclosure['url'] ) && isset( $enclosure['length'] ) && isset( $enclosure['type'] ) ) {
    2236             add_post_meta( $post_ID, 'enclosure', $enclosure['url'] . "\n" . $enclosure['length'] . "\n" . $enclosure['type'] );
    2237         }
    2238 
    2239         $this->attach_uploads( $post_ID, $post_content );
    2240 
    2241         logIO('O', "Posted ! ID: $post_ID");
    2242 
    2243         return strval($post_ID);
    2244     }
    2245 
     2245       
     2246            $encstring = $enclosure['url'] . "\n" . $enclosure['length'] . "\n" . $enclosure['type'];
     2247            $found = false;
     2248            foreach ( (array) get_post_custom($post_ID) as $key => $val) {
     2249                if ($key == 'enclosure') {
     2250                    foreach ( (array) $val as $enc ) {
     2251                        if ($enc == $encstring) {
     2252                            $found = true;
     2253                            break 2;
     2254                        }
     2255                    }
     2256                }
     2257            }
     2258            if (!$found) {
     2259                add_post_meta( $post_ID, 'enclosure', $encstring );
     2260            }
     2261        }
     2262    }
     2263   
    22462264    /**
    22472265     * Attach upload to a post.
     
    25222540
    25232541        // Handle enclosures
    2524         $enclosure = $content_struct['enclosure'];
    2525         if( is_array( $enclosure ) && isset( $enclosure['url'] ) && isset( $enclosure['length'] ) && isset( $enclosure['type'] ) ) {
    2526             add_post_meta( $post_ID, 'enclosure', $enclosure['url'] . "\n" . $enclosure['length'] . "\n" . $enclosure['type'] );
    2527         }
     2542        $this->add_enclosure_if_new($post_ID, $content_struct['enclosure']);
    25282543
    25292544        $this->attach_uploads( $ID, $post_content );
Note: See TracChangeset for help on using the changeset viewer.