[wp-cvs] wordpress/wp-includes functions.php,1.195,1.196

Donncha O Caoimh donncha at users.sourceforge.net
Mon Oct 18 12:09:22 UTC 2004


Update of /cvsroot/cafelog/wordpress/wp-includes
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23115/wp-includes

Modified Files:
	functions.php 
Log Message:
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.


Index: functions.php
===================================================================
RCS file: /cvsroot/cafelog/wordpress/wp-includes/functions.php,v
retrieving revision 1.195
retrieving revision 1.196
diff -C2 -d -r1.195 -r1.196
*** functions.php	15 Oct 2004 03:16:01 -0000	1.195
--- functions.php	18 Oct 2004 12:09:20 -0000	1.196
***************
*** 758,761 ****
--- 758,844 ----
  }
  
+ 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;
***************
*** 809,812 ****
--- 892,896 ----
  
  		if ($pingback_server_url) {
+                         set_time_limit( 60 ); 
  			 // Now, the RPC call
  			debug_fwrite($log, "Page Linked To: $pagelinkedto \n");




More information about the cvs mailing list