Enclosure cleanups

git-svn-id: http://svn.automattic.com/wordpress/trunk@2288 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
saxmatt 2005-02-12 08:58:10 +00:00
parent bf51ef9896
commit 553e41cf73
5 changed files with 52 additions and 30 deletions

View File

@ -37,9 +37,6 @@ if ('' != $pinged) {
$saveasdraft = '<input name="save" type="submit" id="save" tabindex="6" value="' . __('Save and Continue Editing') . '" />';
$form_enclosure = '<p><label for="enclosure"><a href="http://www.thetwowayweb.com/payloadsforrss" title="' . __('Help on enclosures') . '">' . __('<strong>Enclosures</strong></a>') . '</label> ' . __('(Separate multiple <abbr title="Universal Resource Identifier">URI</abbr>s with spaces.)') . '<br />
<input type="text" name="enclosure_url" style="width: 415px" id="enclosure" tabindex="8" value="'. str_replace("\n", ' ', $enclosure_url) .'" /></p>';
if (empty($post_status)) $post_status = 'draft';
?>

View File

@ -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);
}

View File

@ -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");

View File

@ -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 <link/>
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

View File

@ -208,10 +208,34 @@ function link_pages($before='<br />', $after='<br />', $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() {