| 1186 | | if ( $finished ) |
| 1187 | | continue; |
| 1188 | | if ( strstr( $para, $pagelinkedto ) ) { |
| 1189 | | $context = preg_replace( "/.*<a[^>]+".$link."[^>]*>([^>]+)<\/a>.*/", "$1", $para ); |
| 1190 | | $excerpt = strip_tags( $para ); |
| 1191 | | $excerpt = trim( $excerpt ); |
| 1192 | | $use = preg_quote( $context ); |
| 1193 | | $excerpt = preg_replace("|.*?\s(.{0,100}$use.{0,100})\s|s", "$1", $excerpt); |
| 1194 | | $finished = true; |
| | 1183 | if ( strpos($para, $pagelinkedto) !== false ) { // it exists, but is it a link? |
| | 1184 | preg_match("|<a[^>]+?".$preg_target."[^>]*>([^>]+?)</a>|", $para, $context); |
| | 1185 | |
| | 1186 | // If the URL isn't in a link context, keep looking |
| | 1187 | if ( empty($context) ) |
| | 1188 | continue; |
| | 1189 | |
| | 1190 | // We're going to use this fake tag to mark the context in a bit |
| | 1191 | // the marker is needed in case the link text appears more than once in the paragraph |
| | 1192 | $excerpt = preg_replace('|\</?wpcontext\>|', '', $para); |
| | 1193 | |
| | 1194 | // prevent really long link text |
| | 1195 | if ( strlen($context[1]) > 100 ) |
| | 1196 | $context[1] = substr($context[1], 0, 100) . '...'; |
| | 1197 | |
| | 1198 | $marker = '<wpcontext>'.$context[1].'</wpcontext>'; // set up our marker |
| | 1199 | $excerpt= str_replace($context[0], $marker, $excerpt); // swap out the link for our marker |
| | 1200 | $excerpt = strip_tags($excerpt, '<wpcontext>'); // strip all tags but our context marker |
| | 1201 | $excerpt = trim($excerpt); |
| | 1202 | $preg_marker = preg_quote($marker); |
| | 1203 | $excerpt = preg_replace("|.*?\s(.{0,100}$preg_marker.{0,100})\s.*|s", '$1', $excerpt); |
| | 1204 | $excerpt = strip_tags($excerpt); // YES, again, to remove the marker wrapper |
| | 1205 | break; |