Pingback excerpt fetching improvements and fixes. fixes #3495

git-svn-id: http://svn.automattic.com/wordpress/trunk@4667 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
markjaquith 2006-12-27 06:10:03 +00:00
parent eda5c27abf
commit 4577ba0f2d
1 changed files with 26 additions and 15 deletions

View File

@ -1213,25 +1213,36 @@ class wp_xmlrpc_server extends IXR_Server {
$p = explode( "\n\n", $linea ); $p = explode( "\n\n", $linea );
$sem_regexp_pb = "/(\\/|\\\|\*|\?|\+|\.|\^|\\$|\(|\)|\[|\]|\||\{|\})/"; $preg_target = preg_quote($pagelinkedto);
$sem_regexp_fix = "\\\\$1";
$link = preg_replace( $sem_regexp_pb, $sem_regexp_fix, $pagelinkedfrom );
$finished = false;
foreach ( $p as $para ) { foreach ( $p as $para ) {
if ( $finished ) if ( strpos($para, $pagelinkedto) !== false ) { // it exists, but is it a link?
continue; preg_match("|<a[^>]+?".$preg_target."[^>]*>([^>]+?)</a>|", $para, $context);
if ( strstr( $para, $pagelinkedto ) ) {
$context = preg_replace( "/.*<a[^>]+".$link."[^>]*>([^>]+)<\/a>.*/", "$1", $para ); // If the URL isn't in a link context, keep looking
$excerpt = strip_tags( $para ); if ( empty($context) )
$excerpt = trim( $excerpt ); continue;
$use = preg_quote( $context );
$excerpt = preg_replace("|.*?\s(.{0,100}$use.{0,100})\s|s", "$1", $excerpt); // We're going to use this fake tag to mark the context in a bit
$finished = true; // the marker is needed in case the link text appears more than once in the paragraph
$excerpt = preg_replace('|\</?wpcontext\>|', '', $para);
// prevent really long link text
if ( strlen($context[1]) > 100 )
$context[1] = substr($context[1], 0, 100) . '...';
$marker = '<wpcontext>'.$context[1].'</wpcontext>'; // set up our marker
$excerpt= str_replace($context[0], $marker, $excerpt); // swap out the link for our marker
$excerpt = strip_tags($excerpt, '<wpcontext>'); // strip all tags but our context marker
$excerpt = trim($excerpt);
$preg_marker = preg_quote($marker);
$excerpt = preg_replace("|.*?\s(.{0,100}$preg_marker.{0,100})\s.*|s", '$1', $excerpt);
$excerpt = strip_tags($excerpt); // YES, again, to remove the marker wrapper
break;
} }
} }
if ( empty($context) ) // URL pattern not found if ( empty($context) ) // Link to target not found
return new IXR_Error(17, 'The source URL does not contain a link to the target URL, and so cannot be used as a source.'); return new IXR_Error(17, 'The source URL does not contain a link to the target URL, and so cannot be used as a source.');
$pagelinkedfrom = preg_replace('#&([^amp\;])#is', '&amp;$1', $pagelinkedfrom); $pagelinkedfrom = preg_replace('#&([^amp\;])#is', '&amp;$1', $pagelinkedfrom);
@ -1301,4 +1312,4 @@ class wp_xmlrpc_server extends IXR_Server {
$wp_xmlrpc_server = new wp_xmlrpc_server(); $wp_xmlrpc_server = new wp_xmlrpc_server();
?> ?>