| 2070 | | $count = 1; |
| 2071 | | |
| 2072 | | if ( has_post_format( $type, $post ) ) { |
| 2073 | | $meta = get_post_format_meta( $post->ID ); |
| 2074 | | if ( ! empty( $meta[$type . '_embed'] ) ) { |
| 2075 | | $value = $meta[$type . '_embed']; |
| 2076 | | if ( is_integer( $value ) ) { |
| 2077 | | $url = wp_get_attachment_url( $value ); |
| 2078 | | $shortcode = sprintf( '[%s src="%s"]', $type, $url ); |
| 2079 | | } elseif ( preg_match( '/' . get_shortcode_regex() . '/s', $value ) ) { |
| 2080 | | $shortcode = $value; |
| 2081 | | } elseif ( preg_match( '#<[^>]+>#', $value ) ) { |
| 2082 | | $post->format_content[ $cache_key ] = $value; |
| 2083 | | return $post->format_content[ $cache_key ]; |
| 2084 | | } elseif ( 0 === strpos( $value, 'http' ) ) { |
| 2085 | | $post->split_content = str_replace( $value, '', $post->post_content, $count ); |
| 2086 | | if ( strstr( $value, home_url() ) ) { |
| 2087 | | $shortcode = sprintf( '[%s src="%s"]', $type, $value ); |
| 2088 | | } else { |
| 2089 | | $post->format_content[ $cache_key ] = $wp_embed->autoembed( $value ); |
| 2090 | | return $post->format_content[ $cache_key ]; |
| 2091 | | } |
| 2092 | | } |
| 2093 | | |
| 2094 | | if ( ! empty( $shortcode ) ) { |
| 2095 | | $post->format_content[ $cache_key ] = do_shortcode( $shortcode ); |
| 2096 | | return $post->format_content[ $cache_key ]; |
| 2097 | | } |
| 2098 | | } |
| 2099 | | } |
| 2100 | | |
| 2443 | | $link_fmt = '%s'; |
| 2444 | | if ( ! empty( $meta['url'] ) ) |
| 2445 | | $link_fmt = '<a href="' . esc_url( $meta['url'] ) . '">%s</a>'; |
| 2446 | | |
| 2447 | | if ( ! empty( $meta['image'] ) ) { |
| 2448 | | if ( is_numeric( $meta['image'] ) ) { |
| 2449 | | $image = wp_get_attachment_image( absint( $meta['image'] ), $attached_size ); |
| 2450 | | // wrap image in <a> |
| 2451 | | if ( ! empty( $meta['url'] ) ) |
| 2452 | | $image = sprintf( $link_fmt, $image ); |
| 2453 | | } elseif ( has_shortcode( $meta['image'], 'caption' ) ) { |
| 2454 | | // wrap <img> in <a> |
| 2455 | | if ( ! empty( $meta['url'] ) && false === strpos( $meta['image'], '<a ' ) ) { |
| 2456 | | $meta['image'] = preg_replace( |
| 2457 | | '#(<img[^>]+>)#', |
| 2458 | | sprintf( '<a href="%s">$1</a>', esc_url( $meta['url'] ) ), |
| 2459 | | $meta['image'] |
| 2460 | | ); |
| 2461 | | } |
| 2462 | | |
| 2463 | | $attachment_id = img_html_to_post_id( $meta['image'], $matched_html ); |
| 2464 | | if ( $attachment_id && $matched_html ) { |
| 2465 | | $meta['image'] = str_replace( $matched_html, wp_get_attachment_image( $attachment_id, $attached_size ), $meta['image'] ); |
| 2466 | | $attachment = wp_get_attachment_image_src( $attachment_id, $attached_size ); |
| 2467 | | $attachment_width = ( ! empty( $attachment[1] ) ) ? $attachment[1] : 0; |
| 2468 | | |
| 2469 | | if ( $attachment_width && preg_match_all( '#width=([\'"])(.+?)\1#is', $meta['image'], $matches ) && ! empty( $matches ) ) |
| 2470 | | foreach ( $matches[2] as $width ) |
| 2471 | | if ( $width != $attachment_width ) |
| 2472 | | $meta['image'] = str_replace( $matches[0], sprintf( 'width="%d"', $attachment_width ), $meta['image'] ); |
| 2473 | | } |
| 2474 | | |
| 2475 | | $image = do_shortcode( $meta['image'] ); |
| 2476 | | } elseif ( ! preg_match( '#<[^>]+>#', $meta['image'] ) ) { |
| 2477 | | // not HTML, assume URL |
| 2478 | | $attachment_id = attachment_url_to_postid( $meta['image'] ); |
| 2479 | | if ( $attachment_id ) |
| 2480 | | $image = wp_get_attachment_image( $attachment_id, $attached_size ); |
| 2481 | | else |
| 2482 | | $image = sprintf( '<img src="%s" alt="" />', esc_url( $meta['image'] ) ); |
| 2483 | | } else { |
| 2484 | | // assume HTML |
| 2485 | | $image = $meta['image']; |
| 2486 | | $attachment_id = img_html_to_post_id( $image, $matched_html ); |
| 2487 | | if ( $attachment_id && $matched_html ) |
| 2488 | | $image = str_replace( $matched_html, wp_get_attachment_image( $attachment_id, $attached_size ), $image ); |
| 2489 | | } |
| 2490 | | |
| 2491 | | if ( false === strpos( $image, '<a ' ) ) |
| 2492 | | $post->format_content[ $cache_key ] = sprintf( $link_fmt, $image ); |
| 2493 | | else |
| 2494 | | $post->format_content[ $cache_key ] = $image; |
| 2495 | | return $post->format_content[ $cache_key ]; |
| 2496 | | } |
| 2497 | | |