← All changes
|
jetpack_vendor/automattic/jetpack-videopress/src/class-initializer.php
+93
-25
16.3-a.5
→
16.3
View file →
| @@ -203,9 +203,11 @@ | ||
| 203 | 203 | Caption_Tracks::init(); |
| 204 | 204 | Initial_State::init(); |
| 205 | 205 | XMLRPC::init(); |
| 206 | 206 | Block_Editor_Content::init(); |
| 207 | + Channel::init(); | |
| 207 | 208 | Playlist_Index::init(); |
| 209 | + Analytics_Dashboard::init(); | |
| 208 | 210 | |
| 209 | 211 | /* |
| 210 | 212 | * These endpoints only add their routes on REST init, so defer calling |
| 211 | 213 | * init() (and autoloading the endpoint classes) until a REST request is |
| @@ -725,9 +727,12 @@ | ||
| 725 | 727 | $count = max( self::LATEST_VIDEOS_PLAYLIST_MIN_COUNT, min( self::LATEST_VIDEOS_PLAYLIST_MAX_COUNT, $count ) ); |
| 726 | 728 | |
| 727 | 729 | $block_attributes['videos'] = Data::get_latest_videopress_playlist_entries( $count ); |
| 728 | 730 | |
| 729 | - return self::render_videopress_playlist_block( $block_attributes, $content, $block ); | |
| 731 | + // Dynamic playlists have no title of their own, so no heading either. | |
| 732 | + unset( $block_attributes['playlistTitle'], $block_attributes['showPlaylistTitle'] ); | |
| 733 | + | |
| 734 | + return self::render_videopress_playlist_block( $block_attributes, '', $block ); | |
| 730 | 735 | } |
| 731 | 736 | |
| 732 | 737 | /** |
| 733 | 738 | * Sanitize the playlist block's videos attribute into rendering-ready entries. |
| @@ -864,9 +869,9 @@ | ||
| 864 | 869 | /** |
| 865 | 870 | * Video Playlist block render callback. |
| 866 | 871 | * |
| 867 | 872 | * @param array $block_attributes Block attributes. |
| 868 | - * @param string $content Current block markup. | |
| 873 | + * @param string $content Rendered inner blocks: the title heading, when there is one. | |
| 869 | 874 | * @param \WP_Block|null $block Current block. |
| 870 | 875 | * |
| 871 | 876 | * @return string Block markup, or an empty string when the playlist has no playable entries. |
| 872 | 877 | */ |
| @@ -892,8 +897,14 @@ | ||
| 892 | 897 | $layout = isset( $block_attributes['layout'] ) && in_array( $block_attributes['layout'], array( 'side-rail', 'grid', 'strip' ), true ) |
| 893 | 898 | ? $block_attributes['layout'] |
| 894 | 899 | : 'side-rail'; |
| 895 | 900 | |
| 901 | + $show_player = $enabled( 'showPlayer' ); | |
| 902 | + // A hidden player can still be revealed by the first click on an entry. | |
| 903 | + $reveal_player = ! $show_player | |
| 904 | + && isset( $block_attributes['entryClickAction'] ) | |
| 905 | + && 'show-player' === $block_attributes['entryClickAction']; | |
| 906 | + $has_player = $show_player || $reveal_player; | |
| 896 | 907 | $show_thumbnail = $enabled( 'showThumbnail' ); |
| 897 | 908 | $show_title = $enabled( 'showTitle' ); |
| 898 | 909 | $show_res = $enabled( 'showResolution' ); |
| 899 | 910 | $show_duration = $enabled( 'showDuration' ); |
| @@ -904,8 +915,11 @@ | ||
| 904 | 915 | $classes = array( 'videopress-playlist', 'is-layout-' . $layout ); |
| 905 | 916 | if ( $enabled( 'darkPlayer', false ) ) { |
| 906 | 917 | $classes[] = 'is-dark'; |
| 907 | 918 | } |
| 919 | + if ( ! $show_player ) { | |
| 920 | + $classes[] = 'hide-player'; | |
| 921 | + } | |
| 908 | 922 | if ( ! $show_thumbnail ) { |
| 909 | 923 | $classes[] = 'hide-thumbnails'; |
| 910 | 924 | } |
| 911 | 925 | if ( ! $show_title ) { |
| @@ -981,28 +995,57 @@ | ||
| 981 | 995 | $duration_markup = '' !== $timecode |
| 982 | 996 | ? sprintf( '<span class="videopress-playlist__entry-duration">%s</span>', esc_html( $timecode ) ) |
| 983 | 997 | : ''; |
| 984 | 998 | |
| 999 | + if ( $has_player ) { | |
| 1000 | + $is_current = $show_player && 0 === $index; | |
| 1001 | + $entry_open = sprintf( | |
| 1002 | + '<button type="button" class="videopress-playlist__select%1$s"%2$s data-guid="%3$s" data-embed-url="%4$s" data-title="%5$s" data-position="%6$s" data-details="%7$s" data-progress="%8$s">', | |
| 1003 | + $is_current ? ' is-current' : '', | |
| 1004 | + $is_current ? ' aria-current="true"' : '', | |
| 1005 | + esc_attr( $entry['guid'] ), | |
| 1006 | + esc_url( self::playlist_embed_url( $entry['guid'], true, $muted ) ), | |
| 1007 | + esc_attr( $title ), | |
| 1008 | + esc_attr( $position ), | |
| 1009 | + esc_attr( $details ), | |
| 1010 | + esc_attr( $progress ) | |
| 1011 | + ); | |
| 1012 | + $entry_close = '</button>'; | |
| 1013 | + } else { | |
| 1014 | + // No player to load the video into: the entry opens its VideoPress page instead. | |
| 1015 | + $entry_open = sprintf( | |
| 1016 | + '<a class="videopress-playlist__select" href="%1$s" target="_blank" rel="noopener noreferrer" data-guid="%2$s" data-title="%3$s" data-position="%4$s" data-details="%5$s">', | |
| 1017 | + /** | |
| 1018 | + * Filters where a playlist entry opens when the block has no player. | |
| 1019 | + * | |
| 1020 | + * @since 0.55.0 | |
| 1021 | + * | |
| 1022 | + * @param string $url The video's page on videopress.com. | |
| 1023 | + * @param string $guid The video GUID. | |
| 1024 | + */ | |
| 1025 | + esc_url( apply_filters( 'videopress_playlist_entry_url', 'https://videopress.com/v/' . $entry['guid'], $entry['guid'] ) ), | |
| 1026 | + esc_attr( $entry['guid'] ), | |
| 1027 | + esc_attr( $title ), | |
| 1028 | + esc_attr( $position ), | |
| 1029 | + esc_attr( $details ) | |
| 1030 | + ); | |
| 1031 | + $entry_close = '</a>'; | |
| 1032 | + } | |
| 1033 | + | |
| 985 | 1034 | $items .= sprintf( |
| 986 | - '<li class="videopress-playlist__entry"><button type="button" class="videopress-playlist__select%1$s"%2$s data-guid="%3$s" data-embed-url="%4$s" data-title="%5$s" data-position="%6$s" data-details="%7$s" data-progress="%8$s">' . | |
| 987 | - '%9$s<span class="videopress-playlist__entry-thumb"><span class="videopress-playlist__entry-flag">%10$s</span>%15$s%11$s</span>' . | |
| 988 | - '<span class="videopress-playlist__entry-body"><span class="videopress-playlist__entry-title">%12$s</span><span class="videopress-playlist__entry-meta">%13$s%14$s</span></span>' . | |
| 989 | - '</button></li>', | |
| 990 | - 0 === $index ? ' is-current' : '', | |
| 991 | - 0 === $index ? ' aria-current="true"' : '', | |
| 992 | - esc_attr( $entry['guid'] ), | |
| 993 | - esc_url( self::playlist_embed_url( $entry['guid'], true, $muted ) ), | |
| 994 | - esc_attr( $title ), | |
| 995 | - esc_attr( $position ), | |
| 996 | - esc_attr( $details ), | |
| 997 | - esc_attr( $progress ), | |
| 1035 | + '<li class="videopress-playlist__entry">%1$s' . | |
| 1036 | + '%2$s<span class="videopress-playlist__entry-thumb"><span class="videopress-playlist__entry-flag">%3$s</span>%4$s%5$s</span>' . | |
| 1037 | + '<span class="videopress-playlist__entry-body"><span class="videopress-playlist__entry-title">%6$s</span><span class="videopress-playlist__entry-meta">%7$s%8$s</span></span>' . | |
| 1038 | + '%9$s</li>', | |
| 1039 | + $entry_open, | |
| 998 | 1040 | $number_markup, |
| 999 | 1041 | esc_html__( 'Playing', 'jetpack-videopress-pkg' ), |
| 1042 | + $lock_markup, | |
| 1000 | 1043 | $time_markup, |
| 1001 | 1044 | esc_html( $title ), |
| 1002 | 1045 | $resolution_markup, |
| 1003 | 1046 | $duration_markup, |
| 1004 | - $lock_markup | |
| 1047 | + $entry_close | |
| 1005 | 1048 | ); |
| 1006 | 1049 | } |
| 1007 | 1050 | |
| 1008 | 1051 | $first = $entries[0]; |
| @@ -1029,17 +1072,30 @@ | ||
| 1029 | 1072 | esc_html( $count_label . ' · ' . $runtime_label ) |
| 1030 | 1073 | ) |
| 1031 | 1074 | : ''; |
| 1032 | 1075 | |
| 1033 | - $stage_markup = sprintf( | |
| 1034 | - '<div class="videopress-playlist__stage">' . | |
| 1035 | - '<div class="videopress-playlist__player"><iframe class="videopress-playlist__iframe" title="%1$s" src="%2$s" allowfullscreen allow="clipboard-write"></iframe></div>%3$s</div>', | |
| 1036 | - esc_attr( $first_title ), | |
| 1037 | - esc_url( self::playlist_embed_url( $first['guid'], false, $muted ) ), | |
| 1038 | - $now_markup | |
| 1039 | - ); | |
| 1076 | + if ( $show_player ) { | |
| 1077 | + $stage_markup = sprintf( | |
| 1078 | + '<div class="videopress-playlist__stage">' . | |
| 1079 | + '<div class="videopress-playlist__player"><iframe class="videopress-playlist__iframe" title="%1$s" src="%2$s" allowfullscreen allow="clipboard-write"></iframe></div>%3$s</div>', | |
| 1080 | + esc_attr( $first_title ), | |
| 1081 | + esc_url( self::playlist_embed_url( $first['guid'], false, $muted ) ), | |
| 1082 | + $now_markup | |
| 1083 | + ); | |
| 1084 | + } elseif ( $reveal_player ) { | |
| 1085 | + // No src: nothing loads until the view script reveals the stage on a click. | |
| 1086 | + $stage_markup = sprintf( | |
| 1087 | + '<div class="videopress-playlist__stage" hidden>' . | |
| 1088 | + '<div class="videopress-playlist__player"><iframe class="videopress-playlist__iframe" title="%1$s" allowfullscreen allow="clipboard-write"></iframe></div></div>%2$s', | |
| 1089 | + esc_attr( $first_title ), | |
| 1090 | + $now_markup | |
| 1091 | + ); | |
| 1092 | + } else { | |
| 1093 | + // Without a player only the grid layout's runtime line remains of the stage. | |
| 1094 | + $stage_markup = $now_markup; | |
| 1095 | + } | |
| 1040 | 1096 | |
| 1041 | - $progress_markup = '' !== $total_timecode | |
| 1097 | + $progress_markup = $has_player && '' !== $total_timecode | |
| 1042 | 1098 | ? sprintf( |
| 1043 | 1099 | '<span class="videopress-playlist__list-progress">%s</span>', |
| 1044 | 1100 | /* translators: 1: position of the current video. 2: number of videos. 3: total playlist timecode. */ |
| 1045 | 1101 | esc_html( sprintf( __( '%1$d / %2$d · %3$s total', 'jetpack-videopress-pkg' ), 1, $count, $total_timecode ) ) |
| @@ -1051,9 +1107,11 @@ | ||
| 1051 | 1107 | '<div class="videopress-playlist__list-header">' . |
| 1052 | 1108 | '<span class="videopress-playlist__list-label videopress-playlist__list-label--rail">%1$s</span>' . |
| 1053 | 1109 | '<span class="videopress-playlist__list-label videopress-playlist__list-label--strip">%2$s</span>%3$s%4$s</div>' . |
| 1054 | 1110 | '<ol class="videopress-playlist__entries">%5$s</ol></div>', |
| 1055 | - esc_html__( 'Up next', 'jetpack-videopress-pkg' ), | |
| 1111 | + $show_player | |
| 1112 | + ? esc_html__( 'Up next', 'jetpack-videopress-pkg' ) | |
| 1113 | + : esc_html__( 'Playlist', 'jetpack-videopress-pkg' ), | |
| 1056 | 1114 | /* translators: %s: number of videos in the playlist, e.g. "5 videos". */ |
| 1057 | 1115 | esc_html( sprintf( __( 'Playlist — %s', 'jetpack-videopress-pkg' ), $count_label ) ), |
| 1058 | 1116 | $list_meta_markup, |
| 1059 | 1117 | $progress_markup, |
| @@ -1090,11 +1148,21 @@ | ||
| 1090 | 1148 | } |
| 1091 | 1149 | |
| 1092 | 1150 | $wrapper_attributes = get_block_wrapper_attributes( $wrapper_extra_attributes ); |
| 1093 | 1151 | |
| 1152 | + // The Heading inner block saved with the post; an empty title renders none. | |
| 1153 | + $playlist_title = isset( $block_attributes['playlistTitle'] ) && is_string( $block_attributes['playlistTitle'] ) | |
| 1154 | + ? trim( $block_attributes['playlistTitle'] ) | |
| 1155 | + : ''; | |
| 1156 | + $content = is_string( $content ) ? trim( $content ) : ''; | |
| 1157 | + $heading_markup = $enabled( 'showPlaylistTitle' ) && '' !== $playlist_title && '' !== $content | |
| 1158 | + ? '<div class="videopress-playlist__heading">' . $content . '</div>' | |
| 1159 | + : ''; | |
| 1160 | + | |
| 1094 | 1161 | return sprintf( |
| 1095 | - '<figure %1$s><div class="videopress-playlist__body">%2$s%3$s</div></figure>', | |
| 1162 | + '<figure %1$s>%2$s<div class="videopress-playlist__body">%3$s%4$s</div></figure>', | |
| 1096 | 1163 | $wrapper_attributes, |
| 1164 | + $heading_markup, | |
| 1097 | 1165 | $stage_markup, |
| 1098 | 1166 | $list_markup |
| 1099 | 1167 | ); |
| 1100 | 1168 | } |