| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  * Helper to massage Podcast data to be used in the Podcast block. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * @package automattic/jetpack | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * Class Jetpack_Podcast_Helper | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | class Jetpack_Podcast_Helper { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | 	 * The RSS feed of the podcast. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | 	 * @var string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | 	protected $feed = null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | 	 * Initialize class. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | 	 * @param string $feed The RSS feed of the podcast. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | 	public function __construct( $feed ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | 		$this->feed = esc_url_raw( $feed ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  | 	 * Gets podcast data formatted to be used by the Podcast Player block in both server-side | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  | 	 * block rendering and in API `WPCOM_REST_API_V2_Endpoint_Podcast_Player`. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  | 	 * The result is cached for one hour. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  | 	 * @param array $args { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  | 	 *    Optional array of arguments. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  | 	 *    @type string|int $guid  The ID of a specific episode to return rather than a list. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  | 	 * } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  | 	 * @return array|WP_Error  The player data or a error object. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  | 	public function get_player_data( $args = array() ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  | 		$guids           = isset( $args['guids'] ) && $args['guids'] ? $args['guids'] : array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  | 		$episode_options = isset( $args['episode-options'] ) && $args['episode-options']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  | 		// Try loading data from the cache. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  | 		$transient_key = 'jetpack_podcast_' . md5( $this->feed . implode( ',', $guids ) . "-$episode_options" ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  | 		$player_data   = get_transient( $transient_key ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  | 		// Fetch data if we don't have any cached. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  | 		if ( false === $player_data || ( defined( 'WP_DEBUG' ) && WP_DEBUG ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  | 			// Load feed. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  | 			$rss = $this->load_feed(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  | 			if ( is_wp_error( $rss ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  | 				return $rss; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  | 			// Get a list of episodes by guid or all tracks in feed. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  | 			if ( count( $guids ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  | 				$tracks = array_map( array( $this, 'get_track_data' ), $guids ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  | 				$tracks = array_filter( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  | 					$tracks, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  | 					function ( $track ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  | 						return ! is_wp_error( $track ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  | 					} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  | 				); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  | 			} else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  | 				$tracks = $this->get_track_list(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  | 			if ( empty( $tracks ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  | 				return new WP_Error( 'no_tracks', __( 'Your Podcast couldn\'t be embedded as it doesn\'t contain any tracks. Please double check your URL.', 'jetpack' ) ); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  | 			// Get podcast meta. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  | 			$title = $rss->get_title(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  | 			$title = $this->get_plain_text( $title ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  | 			$cover = $rss->get_image_url(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  | 			$cover = ! empty( $cover ) ? esc_url( $cover ) : null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  | 			$link = $rss->get_link(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  | 			$link = ! empty( $link ) ? esc_url( $link ) : null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  | 			$player_data = array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  | 				'title'  => $title, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  | 				'link'   => $link, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  | 				'cover'  => $cover, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  | 				'tracks' => $tracks, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  | 			); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  | 			if ( $episode_options ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  | 				$player_data['options'] = array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  | 				foreach ( $rss->get_items() as $episode ) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  | 					$enclosure = $this->get_audio_enclosure( $episode ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  | 					// If the episode doesn't have playable audio, then don't include it. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  | 					if ( is_wp_error( $enclosure ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  | 						continue; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  | 					} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  | 					$player_data['options'][] = array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  | 						'label' => $this->get_plain_text( $episode->get_title() ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  | 						'value' => $episode->get_id(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  | 					); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  | 				} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  | 			// Cache for 1 hour. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  | 			set_transient( $transient_key, $player_data, HOUR_IN_SECONDS ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  | 		return $player_data; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  | 	 * Gets a specific track from the supplied feed URL. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  | 	 * @param string  $guid          The GUID of the track. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  | 	 * @param boolean $force_refresh Clear the feed cache. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  | 	 * @return array|WP_Error The track object or an error object. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  | 	public function get_track_data( $guid, $force_refresh = false ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  | 		// Get the cache key. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  | 		$transient_key = 'jetpack_podcast_' . md5( "$this->feed::$guid" ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  | 		// Clear the cache if force_refresh param is true. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  | 		if ( true === $force_refresh ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  | 			delete_transient( $transient_key ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  | 		// Try loading track data from the cache. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  | 		$track_data = get_transient( $transient_key ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  | 		// Fetch data if we don't have any cached. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  | 		if ( false === $track_data || ( defined( 'WP_DEBUG' ) && WP_DEBUG ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  | 			// Load feed. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  | 			$rss = $this->load_feed( $force_refresh ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  | 			if ( is_wp_error( $rss ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  | 				return $rss; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  | 			// Loop over all tracks to find the one. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  | 			foreach ( $rss->get_items() as $track ) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  | 				if ( $guid === $track->get_id() ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  | 					$track_data = $this->setup_tracks_callback( $track ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  | 					break; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  | 				} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  | 			if ( false === $track_data ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  | 				return new WP_Error( 'no_track', __( 'The track was not found.', 'jetpack' ) ); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  | 			// Cache for 1 hour. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  | 			set_transient( $transient_key, $track_data, HOUR_IN_SECONDS ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  | 		return $track_data; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 |  |  | 	 * Gets a list of tracks for the supplied RSS feed. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 164 |  |  | 	 * @return array|WP_Error The feed's tracks or a error object. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 |  |  | 	public function get_track_list() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 167 |  |  | 		$rss = $this->load_feed(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 168 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 169 |  |  | 		if ( is_wp_error( $rss ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 170 |  |  | 			return $rss; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 171 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 172 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 173 |  |  | 		// Get first ten items and format them. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 174 |  |  | 		$track_list = array_map( array( __CLASS__, 'setup_tracks_callback' ), $rss->get_items( 0, 10 ) ); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 175 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 176 |  |  | 		// Filter out any tracks that are empty. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 177 |  |  | 		// Reset the array indicies. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 178 |  |  | 		return array_values( array_filter( $track_list ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 179 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 180 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 181 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 182 |  |  | 	 * Formats string as pure plaintext, with no HTML tags or entities present. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 183 |  |  | 	 * This is ready to be used in React, innerText but needs to be escaped | 
            
                                                                                                            
                            
            
                                    
            
            
                | 184 |  |  | 	 * using standard `esc_html` when generating markup on server. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 185 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 186 |  |  | 	 * @param string $str Input string. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 187 |  |  | 	 * @return string Plain text string. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 188 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 189 |  |  | 	protected function get_plain_text( $str ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 190 |  |  | 		return $this->sanitize_and_decode_text( $str, true ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 191 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 192 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 193 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 194 |  |  | 	 * Formats strings as safe HTML. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 195 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 196 |  |  | 	 * @param string $str Input string. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 197 |  |  | 	 * @return string HTML text string safe for post_content. | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 198 |  |  | 	 */ | 
            
                                                                        
                            
            
                                    
            
            
                | 199 |  |  | 	protected function get_html_text( $str ) { | 
            
                                                                        
                            
            
                                    
            
            
                | 200 |  |  | 		return $this->sanitize_and_decode_text( $str, false ); | 
            
                                                                        
                            
            
                                    
            
            
                | 201 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 202 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 203 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 204 |  |  | 	 * Strip unallowed html tags and decode entities. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 205 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 206 |  |  | 	 * @param string  $str Input string. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 207 |  |  | 	 * @param boolean $strip_all_tags Strip all tags, otherwise allow post_content safe tags. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 208 |  |  | 	 * @return string Sanitized and decoded text. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 209 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 210 |  |  | 	protected function sanitize_and_decode_text( $str, $strip_all_tags = true ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 211 |  |  | 		// Trim string and return if empty. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 212 |  |  | 		$str = trim( (string) $str ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 213 |  |  | 		if ( empty( $str ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 214 |  |  | 			return ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 215 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 216 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 217 |  |  | 		if ( $strip_all_tags ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 218 |  |  | 			// Make sure there are no tags. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 219 |  |  | 			$str = wp_strip_all_tags( $str ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 220 |  |  | 		} else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 221 |  |  | 			$str = wp_kses_post( $str ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 222 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 223 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 224 |  |  | 		// Replace all entities with their characters, including all types of quotes. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 225 |  |  | 		$str = html_entity_decode( $str, ENT_QUOTES ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 226 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 227 |  |  | 		return $str; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 228 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 229 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 230 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 231 |  |  | 	 * Loads an RSS feed using `fetch_feed`. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 232 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 233 |  |  | 	 * @param boolean $force_refresh Clear the feed cache. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 234 |  |  | 	 * @return SimplePie|WP_Error The RSS object or error. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 235 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 236 |  |  | 	public function load_feed( $force_refresh = false ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 237 |  |  | 		// Add action: clear the SimplePie Cache if $force_refresh param is true. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 238 |  |  | 		if ( true === $force_refresh ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 239 |  |  | 			add_action( 'wp_feed_options', array( __CLASS__, 'reset_simplepie_cache' ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 240 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 241 |  |  | 		// Add action: detect the podcast feed from the provided feed URL. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 242 |  |  | 		add_action( 'wp_feed_options', array( __CLASS__, 'set_podcast_locator' ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 243 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 244 |  |  | 		// Fetch the feed. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 245 |  |  | 		$rss = fetch_feed( $this->feed ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 246 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 247 |  |  | 		// Remove added actions from wp_feed_options hook. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 248 |  |  | 		remove_action( 'wp_feed_options', array( __CLASS__, 'set_podcast_locator' ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 249 |  |  | 		if ( true === $force_refresh ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 250 |  |  | 			remove_action( 'wp_feed_options', array( __CLASS__, 'reset_simplepie_cache' ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 251 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 252 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 253 |  |  | 		if ( is_wp_error( $rss ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 254 |  |  | 			return new WP_Error( 'invalid_url', __( 'Your podcast couldn\'t be embedded. Please double check your URL.', 'jetpack' ) ); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 255 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 256 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 257 |  |  | 		if ( ! $rss->get_item_quantity() ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 258 |  |  | 			return new WP_Error( 'no_tracks', __( 'Podcast audio RSS feed has no tracks.', 'jetpack' ) ); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 259 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 260 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 261 |  |  | 		return $rss; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 262 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 263 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 264 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 265 |  |  | 	 * Action handler to set our podcast specific feed locator class on the SimplePie object. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 266 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 267 |  |  | 	 * @param SimplePie $feed The SimplePie object, passed by reference. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 268 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 269 |  |  | 	public static function set_podcast_locator( &$feed ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 270 |  |  | 		if ( ! class_exists( 'Jetpack_Podcast_Feed_Locator' ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 271 |  |  | 			jetpack_require_lib( 'class-jetpack-podcast-feed-locator' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 272 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 273 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 274 |  |  | 		$feed->set_locator_class( 'Jetpack_Podcast_Feed_Locator' ); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 275 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 276 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 277 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 278 |  |  | 	 * Action handler to reset the SimplePie cache for the podcast feed. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 279 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 280 |  |  | 	 * Note this only resets the cache for the specified url. If the feed locator finds the podcast feed | 
            
                                                                                                            
                            
            
                                    
            
            
                | 281 |  |  | 	 * within the markup of the that url, that feed itself may still be cached. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 282 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 283 |  |  | 	 * @param SimplePie $feed The SimplePie object, passed by reference. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 284 |  |  | 	 * @return void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 285 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 286 |  |  | 	public static function reset_simplepie_cache( &$feed ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 287 |  |  | 		// Retrieve the cache object for a feed url. Based on: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 288 |  |  | 		// https://github.com/WordPress/WordPress/blob/fd1c2cb4011845ceb7244a062b09b2506082b1c9/wp-includes/class-simplepie.php#L1412. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 289 |  |  | 		$cache = $feed->registry->call( 'Cache', 'get_handler', array( $feed->cache_location, call_user_func( $feed->cache_name_function, $feed->feed_url ), 'spc' ) ); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                            
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 290 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 291 |  |  | 		if ( method_exists( $cache, 'unlink' ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 292 |  |  | 			$cache->unlink(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 293 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 294 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 295 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 296 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 297 |  |  | 	 * Prepares Episode data to be used by the Podcast Player block. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 298 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 299 |  |  | 	 * @param SimplePie_Item $episode SimplePie_Item object, representing a podcast episode. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 300 |  |  | 	 * @return array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 301 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 302 |  |  | 	protected function setup_tracks_callback( SimplePie_Item $episode ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 303 |  |  | 		$enclosure = $this->get_audio_enclosure( $episode ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 304 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 305 |  |  | 		// If the audio enclosure is empty then it is not playable. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 306 |  |  | 		// We therefore return an empty array for this track. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 307 |  |  | 		// It will be filtered out later. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 308 |  |  | 		if ( is_wp_error( $enclosure ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 309 |  |  | 			return array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 310 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 311 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 312 |  |  | 		// If there is no link return an empty array. We will filter out later. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 313 |  |  | 		if ( empty( $enclosure->link ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 314 |  |  | 			return array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 315 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 316 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 317 |  |  | 		// Build track data. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 318 |  |  | 		$track = array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 319 |  |  | 			'id'               => wp_unique_id( 'podcast-track-' ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 320 |  |  | 			'link'             => esc_url( $episode->get_link() ), | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 321 |  |  | 			'src'              => esc_url( $enclosure->link ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 322 |  |  | 			'type'             => esc_attr( $enclosure->type ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 323 |  |  | 			'description'      => $this->get_plain_text( $episode->get_description() ), | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 324 |  |  | 			'description_html' => $this->get_html_text( $episode->get_description() ), | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 325 |  |  | 			'title'            => $this->get_plain_text( $episode->get_title() ), | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 326 |  |  | 			'image'            => esc_url( $this->get_episode_image_url( $episode ) ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 327 |  |  | 			'guid'             => $this->get_plain_text( $episode->get_id() ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 328 |  |  | 		); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 329 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 330 |  |  | 		if ( empty( $track['title'] ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 331 |  |  | 			$track['title'] = esc_html__( '(no title)', 'jetpack' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 332 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 333 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 334 |  |  | 		if ( ! empty( $enclosure->duration ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 335 |  |  | 			$track['duration'] = esc_html( $this->format_track_duration( $enclosure->duration ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 336 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 337 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 338 |  |  | 		return $track; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 339 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 340 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 341 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 342 |  |  | 	 * Retrieves an episode's image URL, if it's available. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 343 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 344 |  |  | 	 * @param SimplePie_Item $episode SimplePie_Item object, representing a podcast episode. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 345 |  |  | 	 * @param string         $itunes_ns The itunes namespace, defaulted to the standard 1.0 version. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 346 |  |  | 	 * @return string|null The image URL or null if not found. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 347 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 348 |  |  | 	protected function get_episode_image_url( SimplePie_Item $episode, $itunes_ns = 'http://www.itunes.com/dtds/podcast-1.0.dtd' ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 349 |  |  | 		$image = $episode->get_item_tags( $itunes_ns, 'image' ); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 350 |  |  | 		if ( isset( $image[0]['attribs']['']['href'] ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 351 |  |  | 			return $image[0]['attribs']['']['href']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 352 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 353 |  |  | 		return null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 354 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 355 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 356 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 357 |  |  | 	 * Retrieves an audio enclosure. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 358 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 359 |  |  | 	 * @param SimplePie_Item $episode SimplePie_Item object, representing a podcast episode. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 360 |  |  | 	 * @return SimplePie_Enclosure|null | 
            
                                                                                                            
                            
            
                                    
            
            
                | 361 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 362 |  |  | 	protected function get_audio_enclosure( SimplePie_Item $episode ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 363 |  |  | 		foreach ( (array) $episode->get_enclosures() as $enclosure ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 364 |  |  | 			if ( 0 === strpos( $enclosure->type, 'audio/' ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 365 |  |  | 				return $enclosure; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 366 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 367 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 368 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 369 |  |  | 		return new WP_Error( 'invalid_audio', __( 'Podcast audio is an invalid type.', 'jetpack' ) ); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 370 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 371 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 372 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 373 |  |  | 	 * Returns the track duration as a formatted string. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 374 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 375 |  |  | 	 * @param number $duration of the track in seconds. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 376 |  |  | 	 * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 377 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 378 |  |  | 	protected function format_track_duration( $duration ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 379 |  |  | 		$format = $duration > HOUR_IN_SECONDS ? 'H:i:s' : 'i:s'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 380 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 381 |  |  | 		return date_i18n( $format, $duration ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 382 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 383 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 384 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 385 |  |  | 	 * Gets podcast player data schema. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 386 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 387 |  |  | 	 * Useful for json schema in REST API endpoints. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 388 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 389 |  |  | 	 * @return array Player data json schema. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 390 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 391 |  |  | 	public static function get_player_data_schema() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 392 |  |  | 		return array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 393 |  |  | 			'$schema'    => 'http://json-schema.org/draft-04/schema#', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 394 |  |  | 			'title'      => 'jetpack-podcast-player-data', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 395 |  |  | 			'type'       => 'object', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 396 |  |  | 			'properties' => array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 397 |  |  | 				'title'   => array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 398 |  |  | 					'description' => __( 'The title of the podcast.', 'jetpack' ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 399 |  |  | 					'type'        => 'string', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 400 |  |  | 				), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 401 |  |  | 				'link'    => array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 402 |  |  | 					'description' => __( 'The URL of the podcast website.', 'jetpack' ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 403 |  |  | 					'type'        => 'string', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 404 |  |  | 					'format'      => 'uri', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 405 |  |  | 				), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 406 |  |  | 				'cover'   => array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 407 |  |  | 					'description' => __( 'The URL of the podcast cover image.', 'jetpack' ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 408 |  |  | 					'type'        => 'string', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 409 |  |  | 					'format'      => 'uri', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 410 |  |  | 				), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 411 |  |  | 				'tracks'  => self::get_tracks_schema(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 412 |  |  | 				'options' => self::get_options_schema(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 413 |  |  | 			), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 414 |  |  | 		); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 415 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 416 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 417 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 418 |  |  | 	 * Gets tracks data schema. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 419 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 420 |  |  | 	 * Useful for json schema in REST API endpoints. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 421 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 422 |  |  | 	 * @return array Tracks json schema. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 423 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 424 |  |  | 	public static function get_tracks_schema() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 425 |  |  | 		return array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 426 |  |  | 			'description' => __( 'Latest episodes of the podcast.', 'jetpack' ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 427 |  |  | 			'type'        => 'array', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 428 |  |  | 			'items'       => array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 429 |  |  | 				'type'       => 'object', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 430 |  |  | 				'properties' => array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 431 |  |  | 					'id'               => array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 432 |  |  | 						'description' => __( 'The episode id. Generated per request, not globally unique.', 'jetpack' ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 433 |  |  | 						'type'        => 'string', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 434 |  |  | 					), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 435 |  |  | 					'link'             => array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 436 |  |  | 						'description' => __( 'The external link for the episode.', 'jetpack' ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 437 |  |  | 						'type'        => 'string', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 438 |  |  | 						'format'      => 'uri', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 439 |  |  | 					), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 440 |  |  | 					'src'              => array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 441 |  |  | 						'description' => __( 'The audio file URL of the episode.', 'jetpack' ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 442 |  |  | 						'type'        => 'string', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 443 |  |  | 						'format'      => 'uri', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 444 |  |  | 					), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 445 |  |  | 					'type'             => array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 446 |  |  | 						'description' => __( 'The mime type of the episode.', 'jetpack' ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 447 |  |  | 						'type'        => 'string', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 448 |  |  | 					), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 449 |  |  | 					'description'      => array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 450 |  |  | 						'description' => __( 'The episode description, in plaintext.', 'jetpack' ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 451 |  |  | 						'type'        => 'string', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 452 |  |  | 					), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 453 |  |  | 					'description_html' => array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 454 |  |  | 						'description' => __( 'The episode description with allowed html tags.', 'jetpack' ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 455 |  |  | 						'type'        => 'string', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 456 |  |  | 					), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 457 |  |  | 					'title'            => array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 458 |  |  | 						'description' => __( 'The episode title.', 'jetpack' ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 459 |  |  | 						'type'        => 'string', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 460 |  |  | 					), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 461 |  |  | 				), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 462 |  |  | 			), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 463 |  |  | 		); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 464 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 465 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 466 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 467 |  |  | 	 * Gets the episode options schema. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 468 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 469 |  |  | 	 * Useful for json schema in REST API endpoints. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 470 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 471 |  |  | 	 * @return array Tracks json schema. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 472 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 473 |  |  | 	public static function get_options_schema() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 474 |  |  | 		return array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 475 |  |  | 			'description' => __( 'The options that will be displayed in the episode selection UI', 'jetpack' ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 476 |  |  | 			'type'        => 'array', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 477 |  |  | 			'items'       => array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 478 |  |  | 				'type'       => 'object', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 479 |  |  | 				'properties' => array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 480 |  |  | 					'label' => array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 481 |  |  | 						'description' => __( 'The display label of the option, the episode title.', 'jetpack' ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 482 |  |  | 						'type'        => 'string', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 483 |  |  | 					), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 484 |  |  | 					'value' => array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 485 |  |  | 						'description' => __( 'The value used for that option, the episode GUID', 'jetpack' ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 486 |  |  | 						'type'        => 'string', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 487 |  |  | 					), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 488 |  |  | 				), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 489 |  |  | 			), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 490 |  |  | 		); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 491 |  |  | 	} | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 492 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 493 |  |  |  | 
            
                        
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignorePhpDoc annotation to the duplicate definition and it will be ignored.