| 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; |