Changeset 13893 for trunk/src/bp-core/classes/class-bp-media-extractor.php
- Timestamp:
- 06/02/2024 02:07:21 AM (4 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-core/classes/class-bp-media-extractor.php
r13793 r13893 6 6 * @subpackage Core 7 7 * @since 2.3.0 8 * 9 * @phpcs:disable Squiz.PHP.CommentedOutCode.Found 8 10 */ 9 11 … … 40 42 */ 41 43 class BP_Media_Extractor { 44 42 45 /** 43 46 * Media type. … … 54 57 const AUDIO = 32; 55 58 const VIDEOS = 64; 56 57 59 58 60 /** … … 132 134 $plaintext = $this->strip_markup( $richtext ); 133 135 134 135 136 // Extract links. 136 137 if ( self::LINKS & $what_to_extract ) { … … 181 182 return apply_filters( 'bp_media_extractor_extract', $media, $richtext, $what_to_extract, $extra_args, $plaintext ); 182 183 } 183 184 184 185 185 /** … … 209 209 */ 210 210 protected function extract_links( $richtext, $plaintext, $extra_args = array() ) { 211 $data = array( 'has' => array( 'links' => 0 ), 'links' => array() ); 211 $data = array( 212 'has' => array( 'links' => 0 ), 213 'links' => array(), 214 ); 212 215 213 216 // Matches: href="text" and href='text'. … … 269 272 */ 270 273 protected function extract_mentions( $richtext, $plaintext, $extra_args = array() ) { 271 $data = array( 'has' => array( 'mentions' => 0 ), 'mentions' => array() ); 274 $data = array( 275 'has' => array( 'mentions' => 0 ), 276 'mentions' => array(), 277 ); 272 278 $mentions = array(); 273 279 … … 279 285 } 280 286 281 // If the Activity component is disabled, instead do a basic parse. 282 } else { 283 if ( strpos( $plaintext, '@' ) !== false ) { 287 // If the Activity component is disabled, instead do a basic parse. 288 } elseif ( strpos( $plaintext, '@' ) !== false ) { 284 289 preg_match_all( '/[@]+([A-Za-z0-9-_\.@]+)\b/', $plaintext, $matches ); 285 290 286 if ( ! empty( $matches[1] ) ) { 287 $mentions = array_unique( array_map( 'strtolower', $matches[1] ) ); 288 } 291 if ( ! empty( $matches[1] ) ) { 292 $mentions = array_unique( array_map( 'strtolower', $matches[1] ) ); 289 293 } 290 294 } … … 343 347 */ 344 348 protected function extract_images( $richtext, $plaintext, $extra_args = array() ) { 345 $media = array( 'has' => array( 'images' => 0 ), 'images' => array() ); 349 $media = array( 350 'has' => array( 'images' => 0 ), 351 'images' => array(), 352 ); 346 353 347 354 $featured_image = $this->extract_images_from_featured_images( $richtext, $plaintext, $extra_args ); 348 355 $galleries = $this->extract_images_from_galleries( $richtext, $plaintext, $extra_args ); 349 350 356 351 357 // `<img src>` tags. … … 421 427 $media['has']['images'] = count( $media['images'] ); 422 428 423 424 429 /** 425 430 * Filters images extracted from text. … … 461 466 */ 462 467 protected function extract_shortcodes( $richtext, $plaintext, $extra_args = array() ) { 463 $data = array( 'has' => array( 'shortcodes' => 0 ), 'shortcodes' => array() ); 468 $data = array( 469 'has' => array( 'shortcodes' => 0 ), 470 'shortcodes' => array(), 471 ); 464 472 465 473 // Match any registered WordPress shortcodes. … … 519 527 */ 520 528 protected function extract_embeds( $richtext, $plaintext, $extra_args = array() ) { 521 $data = array( 'has' => array( 'embeds' => 0 ), 'embeds' => array() ); 529 $data = array( 530 'has' => array( 'embeds' => 0 ), 531 'embeds' => array(), 532 ); 522 533 523 534 if ( ! function_exists( '_wp_oembed_get_object' ) ) { 524 require( ABSPATH . WPINC . '/class-oembed.php' ); 525 } 526 535 require ABSPATH . WPINC . '/class-oembed.php'; 536 } 527 537 528 538 // Matches any links on their own lines. They may be oEmbeds. … … 599 609 */ 600 610 protected function extract_audio( $richtext, $plaintext, $extra_args = array() ) { 601 $data = array( 'has' => array( 'audio' => 0 ), 'audio' => array() ); 611 $data = array( 612 'has' => array( 'audio' => 0 ), 613 'audio' => array(), 614 ); 602 615 $audios = $this->extract_shortcodes( $richtext, $plaintext, $extra_args ); 603 616 $links = $this->extract_links( $richtext, $plaintext, $extra_args ); 604 617 605 618 $audio_types = wp_get_audio_extensions(); 606 607 619 608 620 // [audio] … … 695 707 */ 696 708 protected function extract_video( $richtext, $plaintext, $extra_args = array() ) { 697 $data = array( 'has' => array( 'videos' => 0 ), 'videos' => array() ); 709 $data = array( 710 'has' => array( 'videos' => 0 ), 711 'videos' => array(), 712 ); 698 713 $videos = $this->extract_shortcodes( $richtext, $plaintext, $extra_args ); 699 714 700 715 $video_types = wp_get_video_extensions(); 701 716 702 703 // [video] 717 // [video]. 704 718 $videos = wp_list_filter( $videos['shortcodes'], array( 'type' => 'video' ) ); 705 719 foreach ( $videos as $video ) { … … 787 801 $image_size = $extra_args['width']; // E.g. "thumb", "medium". 788 802 } 789 790 803 } else { 791 804 $image_size = 'full'; … … 807 820 $images = wp_parse_id_list( $gallery['ids'] ); 808 821 809 // Gallery post_parent variant.822 // Gallery post_parent variant. 810 823 } elseif ( isset( $extra_args['post'] ) ) { 811 824 $images = wp_parse_id_list( 812 get_children( array( 813 'fields' => 'ids', 814 'order' => 'ASC', 815 'orderby' => 'menu_order ID', 816 'post_mime_type' => 'image', 817 'post_parent' => $extra_args['post']->ID, 818 'post_status' => 'inherit', 819 'post_type' => 'attachment', 820 ) ) 825 get_children( 826 array( 827 'fields' => 'ids', 828 'order' => 'ASC', 829 'orderby' => 'menu_order ID', 830 'post_mime_type' => 'image', 831 'post_parent' => $extra_args['post']->ID, 832 'post_status' => 'inherit', 833 'post_type' => 'attachment', 834 ) 835 ) 821 836 ); 822 837 } … … 824 839 // Extract the data we need from each image in this gallery. 825 840 foreach ( $images as $image_id ) { 826 $image 841 $image = wp_get_attachment_image_src( $image_id, $image_size ); 827 842 828 843 $image_url = isset( $image[0] ) ? $image[0] : ''; … … 831 846 832 847 $data[] = array( 833 'url' => $image_url,834 'width' => $image_width,835 'height' => $image_height,848 'url' => $image_url, 849 'width' => $image_width, 850 'height' => $image_height, 836 851 837 852 'gallery_id' => 1 + $gallery_id,
Note: See TracChangeset
for help on using the changeset viewer.