| 1369 | |
| 1370 | function meta_enclosure( $post_ID, $enclosure_struct ) { |
| 1371 | global $wpdb; |
| 1372 | |
| 1373 | // Build the meta_value string for wordpress enclosure meta_value, |
| 1374 | // the first line is the URL, second is the length in bytes, and |
| 1375 | // the 3rd line is the content type |
| 1376 | |
| 1377 | $meta = array('key'=>'enclosure','value'=>'' ); |
| 1378 | if( isset($enclosure_struct['url']) ) |
| 1379 | { |
| 1380 | $meta['value'] = $enclosure_struct['url']; |
| 1381 | if( isset($enclosure_struct['length']) ) |
| 1382 | { |
| 1383 | $meta['value'] .= "\n" . $enclosure_struct['length']; |
| 1384 | if( isset($enclosure_struct['type']) ) |
| 1385 | $meta['value'] .= "\n" . $enclosure_struct['type']; |
| 1386 | } |
| 1387 | } |
| 1388 | |
| 1389 | // See if a previous enclosure exists... |
| 1390 | $meta_prev = $wpdb->get_row("SELECT meta_id, meta_value FROM {$wpdb->postmeta} WHERE post_id = '$post_ID' AND meta_key = 'enclosure'"); |
| 1391 | |
| 1392 | // Check to see if anything changed, if it's the same value, save a query |
| 1393 | if( $meta_prev && $meta_prev->meta_value == $meta['meta_value'] ) { |
| 1394 | return; |
| 1395 | } |
| 1396 | |
| 1397 | // If it exists we need to deal with it... |
| 1398 | if( $meta_prev && $meta_prev->meta_id ) { |
| 1399 | $meta['id'] = $meta_prev->meta_id; |
| 1400 | if( $meta['value'] == '' ) |
| 1401 | unset($meta['key']); // Unset the key so we delete the enclosure |
| 1402 | } |
| 1403 | |
| 1404 | // Doesn't exist in the database and it's been marked for deletion, so do nothing |
| 1405 | if( !isset($meta['id']) && !isset($meta['key']) ) |
| 1406 | return; |
| 1407 | |
| 1408 | // Update the custom field in the database |
| 1409 | $this->set_custom_fields($post_ID, array($meta) ); |
| 1410 | } |