| 324 | | // Find URLs that are on their own line. |
| 325 | | return preg_replace_callback( '|^(\s*)(https?://[^\s"]+)(\s*)$|im', array( $this, 'autoembed_callback' ), $content ); |
| | 325 | foreach ( $contentarr as $piece ) { |
| | 326 | $last_piece = $piece; |
| | 327 | |
| | 328 | if ( empty( $piece ) || $piece[0] === '<' ) { |
| | 329 | $in_link = ( 0 === stripos( $piece, '<a' ) ); |
| | 330 | $r .= $piece; |
| | 331 | continue; |
| | 332 | } |
| | 333 | |
| | 334 | if ( false !== stripos( $piece, 'http' ) ) { |
| | 335 | // If an URL is wrapped in a link, skip it |
| | 336 | if ( $in_link && false !== stripos( $last_piece, trim( $piece ) ) ) { |
| | 337 | $r .= $piece; |
| | 338 | continue; |
| | 339 | } |
| | 340 | |
| | 341 | $r .= preg_replace_callback( '|^(\s*)(https?://[^\s"]+)(\s*)$|im', array( $this, 'autoembed_callback' ), $piece ); |
| | 342 | } else { |
| | 343 | $r .= $piece; |
| | 344 | } |
| | 345 | } |
| | 346 | |
| | 347 | return $r; |