Completed
Push — update/podcast-header-ss-rende... ( d453fc )
by
unknown
162:54 queued 155:50
created

podcast-header.php ➔ render_podcast_title()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
nc 3
nop 2
dl 0
loc 21
rs 9.584
c 0
b 0
f 0
1
<?php
2
/**
3
 * Podcast Header template.
4
 *
5
 * @package Jetpack
6
 */
7
8
namespace Automattic\Jetpack\Extensions\Podcast_Player;
9
10
/**
11
 * Block attributes
12
 */
13
$attributes = (array) $data['attributes'];
14
15
/**
16
 * Player data.
17
 */
18
19
$player_id                = (string) $data['playerId'];
20
$title                    = (string) $data['title'];
21
$cover                    = (string) $data['cover'];
22
$link                     = (string) $data['link'];
23
$track                    = ! empty( $data['tracks'] ) ? $data['tracks'][0] : array();
24
$show_cover_art           = (bool) $attributes['showCoverArt'];
25
$show_episode_description = (bool) $attributes['showEpisodeDescription'];
26
?>
27
28
29
<?php
30
function render_podcast_title( $title, $link ) {
31
	if ( ! isset( $title ) ) {
32
		return;
33
	}
34
	?>
35
36
	<?php if ( isset( $link ) ) : ?>
37
		<a
38
			class="jetpack-podcast-player__podcast-title"
39
			href="<?php echo esc_url( $link ); ?>"
40
			target="_blank"
41
			rel="noopener noreferrer nofollow"
42
		>
43
			<?php echo esc_attr( $title ); ?>
44
		</a>
45
	<?php else : ?>
46
		<span class="jetpack-podcast-player__podcast-title">
47
			<?php echo esc_attr( $title ); ?>
48
		</span>;
49
	<?php endif; ?>
50
<?php } ?>
51
52
<?php
53
function render_title( $player_id, $title, $link, $track ) {
54
	if ( ! isset( $title ) && empty( $track ) && ! isset( $track['title'] ) ) {
55
		return;
56
	}
57
	?>
58
	<h2 id=<?php echo esc_attr( $player_id ); ?>__title" class="jetpack-podcast-player__title">
59
		<?php if ( ! empty( $track ) && isset( $track['title'] ) ) : ?>
60
			<span class="jetpack-podcast-player__current-track-title">
61
				<?php echo $track['title']; ?>
62
			</span>
63
		<?php endif; ?>
64
65
		<?php if ( ! empty( $track ) && isset( $track['title'] ) && isset( $title ) ) : ?>
66
			<span class="jetpack-podcast-player--visually-hidden"> - </span>
67
		<?php endif; ?>
68
69
		<?php if ( isset( $title ) ) : ?>
70
			<?php render_podcast_title( $title, $link ); ?>
71
		<?php endif; ?>
72
	</h2>
73
<?php } ?>
74
75
<div class="jetpack-podcast-player__header">
76
	<div class="jetpack-podcast-player__current-track-info" aria-live="polite">
77
		<?php if ( $show_cover_art && isset( $cover ) ) : ?>
78
		<div class="jetpack-podcast-player__cover">
79
			<img class="jetpack-podcast-player__cover-image" src=<?php echo esc_url( $cover ); ?>alt="" />
80
		</div>
81
82
			<?php render_title( $player_id, $title, $link, $track ); ?>
83
		<?php endif; ?>
84
	</div>
85
86
	<?php
87
	if ( $show_episode_description && ! empty( $track ) && isset( $track['description'] ) ) :
88
		?>
89
	<div
90
		id="<?php echo esc_attr( $player_id ); ?>__track-description"
91
		class="jetpack-podcast-player__track-description"
92
	>
93
		<?php echo esc_attr( $track['description'] ); ?>
94
	</div>
95
	<?php endif; ?>
96
</div>
97