Enclosure support moved to functions.php - it now scans the content

and encloses file of mime type "video", "audio" and "image".
Fixed a bug in upgrade.php - extra character at the start of file.


git-svn-id: http://svn.automattic.com/wordpress/trunk@1812 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
donncha 2004-10-18 12:09:20 +00:00
parent 3bfe668183
commit 9f62c48cf9
4 changed files with 90 additions and 42 deletions

View File

@ -132,9 +132,6 @@ if ('publish' != $post_status || 0 == $post_ID) {
?>
<input name="referredby" type="hidden" id="referredby" value="<?php echo htmlspecialchars($_SERVER['HTTP_REFERER']); ?>" />
</p>
<?php echo $form_enclosure; ?>
<?php
if ('' != $pinged) {
echo $pings;

View File

@ -166,6 +166,7 @@ case 'post':
if ('publish' == $post_status) {
if ($post_pingback)
pingback($content, $post_ID);
do_enclose( $content, $post_ID );
do_trackbacks($post_ID);
do_action('publish_post', $post_ID);
}
@ -320,8 +321,8 @@ case 'editpost':
}
header ('Location: ' . $location); // Send user on their way while we keep working
$now = current_time('mysql');
$now_gmt = current_time('mysql', 1);
$now = current_time('mysql');
$now_gmt = current_time('mysql', 1);
$result = $wpdb->query("
UPDATE $wpdb->posts SET
@ -338,7 +339,7 @@ $now_gmt = current_time('mysql', 1);
to_ping = '$trackback',
post_modified = '$now',
post_modified_gmt = '$now_gmt',
post_parent = '$post_parent'
post_parent = '$post_parent'
WHERE ID = $post_ID ");
// Meta Stuff
@ -372,47 +373,13 @@ $now_gmt = current_time('mysql', 1);
$wpdb->query("INSERT INTO $wpdb->post2cat (post_id, category_id) VALUES ($post_ID, $new_cat)");
}
// Enclosures
$enclosures = split( " ", $enclosure_url );
if( is_array( $enclosures ) ) {
while( list( $key, $url ) = each( $enclosures ) ) {
if( $url != '' ) {
// READ INFO FROM REMOTE HOST
$file = str_replace( "http://", "", $url );
$host = substr( $file, 0, strpos( $file, "/" ) );
$file = substr( $file, strpos( $file, "/" ) );
$headers = "HEAD $file HTTP/1.1\r\nHOST: $host\r\n\r\n";
$port = 80;
$timeout = 3;
$fp = fsockopen($host, $port, $errno, $errstr, $timeout);
if( $fp ) {
fputs($fp, $headers );
$response = '';
while (!feof($fp))
$response .= fgets($fp, 2048);
} else {
$response = '';
}
if( $response != '' ) {
$len = substr( $response, strpos( $response, "Content-Length:" ) + 16 );
$len = substr( $len, 0, strpos( $len, "\n" ) );
$type = substr( $response, strpos( $response, "Content-Type:" ) + 14 );
$type = substr( $type, 0, strpos( $type, "\n" ) + 1 );
$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 );
}
}
}
}
if ($prev_status != 'publish' && $post_status == 'publish')
do_action('private_to_published', $post_ID);
if ($post_status == 'publish') {
do_action('publish_post', $post_ID);
do_trackbacks($post_ID);
do_enclose( $content, $post_ID );
if ( get_option('default_pingback_flag') )
pingback($content, $post_ID);
}

View File

@ -1,4 +1,4 @@
l<?php
<?php
$_wp_installing = 1;
if (!file_exists('../wp-config.php')) die("There doesn't seem to be a wp-config.php file. Double check that you updated wp-config-sample.php with the proper database connection information and renamed it to wp-config.php.");
require('../wp-config.php');

View File

@ -757,6 +757,89 @@ function debug_fclose($fp) {
}
}
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');
$post_links = array();
debug_fwrite($log, 'BEGIN '.date('YmdHis', time())."\n");
$pung = get_pung($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
$test = parse_url($link_test);
if (isset($test['query']))
$post_links[] = $link_test;
elseif(($test['path'] != '/') && ($test['path'] != ''))
$post_links[] = $link_test;
endif;
endforeach;
foreach ($post_links as $url){
if( $url != '' && in_array($url, $pung) == false ) {
set_time_limit( 60 );
$file = str_replace( "http://", "", $url );
$host = substr( $file, 0, strpos( $file, "/" ) );
$file = substr( $file, strpos( $file, "/" ) );
$headers = "HEAD $file HTTP/1.1\r\nHOST: $host\r\n\r\n";
$port = 80;
$timeout = 3;
$fp = fsockopen($host, $port, $err_num, $err_msg, $timeout);
if( $fp ) {
fputs($fp, $headers );
$response = '';
while (!feof($fp))
$response .= fgets($fp, 2048);
fclose( $fp );
} else {
$response = '';
}
if( $response != '' ) {
$len = substr( $response, strpos( $response, "Content-Length:" ) + 16 );
$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", "image" );
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 );
}
}
}
}
}
function pingback($content, $post_ID) {
global $wp_version, $wpdb;
include_once (ABSPATH . WPINC . '/class-IXR.php');
@ -808,6 +891,7 @@ function pingback($content, $post_ID) {
$pingback_server_url = discover_pingback_server_uri($pagelinkedto, 2048);
if ($pingback_server_url) {
set_time_limit( 60 );
// Now, the RPC call
debug_fwrite($log, "Page Linked To: $pagelinkedto \n");
debug_fwrite($log, 'Page Linked From: ');