WordPress.org

Make WordPress Core

Changeset 4667


Ignore:
Timestamp:
12/27/2006 06:10:03 AM (11 years ago)
Author:
markjaquith
Message:

Pingback excerpt fetching improvements and fixes. fixes #3495

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/xmlrpc.php

    r4650 r4667  
    12141214        $p = explode( "\n\n", $linea );
    12151215
    1216         $sem_regexp_pb = "/(\\/|\\\|\*|\?|\+|\.|\^|\\$|\(|\)|\[|\]|\||\{|\})/";
    1217         $sem_regexp_fix = "\\\\$1";
    1218         $link = preg_replace( $sem_regexp_pb, $sem_regexp_fix, $pagelinkedfrom );
    1219 
    1220         $finished = false;
     1216        $preg_target = preg_quote($pagelinkedto);
     1217
    12211218        foreach ( $p as $para ) {
    1222             if ( $finished )
    1223                 continue;
    1224             if ( strstr( $para, $pagelinkedto ) ) {
    1225                 $context = preg_replace( "/.*<a[^>]+".$link."[^>]*>([^>]+)<\/a>.*/", "$1", $para );
    1226                 $excerpt = strip_tags( $para );
    1227                 $excerpt = trim( $excerpt );
    1228                 $use     = preg_quote( $context );
    1229                 $excerpt = preg_replace("|.*?\s(.{0,100}$use.{0,100})\s|s", "$1", $excerpt);
    1230                 $finished = true;
     1219            if ( strpos($para, $pagelinkedto) !== false ) { // it exists, but is it a link?
     1220                preg_match("|<a[^>]+?".$preg_target."[^>]*>([^>]+?)</a>|", $para, $context);
     1221
     1222                // If the URL isn't in a link context, keep looking
     1223                if ( empty($context) )
     1224                    continue;
     1225
     1226                // We're going to use this fake tag to mark the context in a bit
     1227                // the marker is needed in case the link text appears more than once in the paragraph
     1228                $excerpt = preg_replace('|\</?wpcontext\>|', '', $para);
     1229
     1230                // prevent really long link text
     1231                if ( strlen($context[1]) > 100 )
     1232                    $context[1] = substr($context[1], 0, 100) . '...';
     1233
     1234                $marker = '<wpcontext>'.$context[1].'</wpcontext>';    // set up our marker
     1235                $excerpt= str_replace($context[0], $marker, $excerpt); // swap out the link for our marker
     1236                $excerpt = strip_tags($excerpt, '<wpcontext>');        // strip all tags but our context marker
     1237                $excerpt = trim($excerpt);
     1238                $preg_marker = preg_quote($marker);
     1239                $excerpt = preg_replace("|.*?\s(.{0,100}$preg_marker.{0,100})\s.*|s", '$1', $excerpt);
     1240                $excerpt = strip_tags($excerpt); // YES, again, to remove the marker wrapper
     1241                break;
    12311242            }
    12321243        }
    12331244
    1234         if ( empty($context) ) // URL pattern not found
     1245        if ( empty($context) ) // Link to target not found
    12351246            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.');
    12361247
Note: See TracChangeset for help on using the changeset viewer.