Skip to content

Commit

Permalink
Merge pull request #674 from CastosHQ/release/2.6.3
Browse files Browse the repository at this point in the history
Release/2.6.3
  • Loading branch information
zahardev authored Apr 19, 2021
2 parents 775bc0e + ffbee37 commit 6705eb4
Show file tree
Hide file tree
Showing 25 changed files with 850 additions and 539 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "seriously-simple-podcasting",
"version": "2.6.2",
"version": "2.6.3",
"main": "build/index.js",
"author": "CastosHQ",
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion php/classes/blocks/class-castos-blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function podcast_list_render_callback( $attributes ) {
protected function bootstrap() {
if ( ! file_exists( SSP_PLUGIN_PATH . 'build/index.asset.php' ) ) {
if ( is_admin() ) {
$this->admin_notices_handler = new Admin_Notifications_Handler( 'podcast' );
$this->admin_notices_handler = new Admin_Notifications_Handler( SSP_CPT_PODCAST );
add_action( 'admin_notices', array( $this->admin_notices_handler, 'blocks_error_notice' ) );
}

Expand Down
373 changes: 22 additions & 351 deletions php/classes/controllers/class-admin-controller.php

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion php/classes/controllers/class-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public function __construct( $file, $version ) {
$this->template_url = esc_url( trailingslashit( plugins_url( '/templates/', $file ) ) );
$this->home_url = trailingslashit( home_url() );
$this->site_url = trailingslashit( site_url() );
$this->token = 'podcast';
$this->token = SSP_CPT_PODCAST;
$this->plugin_slug = 'seriously-simple-podcasting';
$this->script_suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';

Expand Down
66 changes: 13 additions & 53 deletions php/classes/controllers/class-episode-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,50 +118,13 @@ private function get_no_album_art_image_array() {
return compact( 'src', 'width', 'height' );
}

/**
* Convert the array returned from wp_get_attachment_image_src into a human readable version
*
* @param $image_data_array
*
* @return mixed
* @todo check if there is a WordPress function for this
*
*/
private function return_renamed_image_array_keys( $image_data_array ) {
$new_image_data_array = array();
if ( $image_data_array && ! empty( $image_data_array ) ) {
$new_image_data_array['src'] = isset( $image_data_array[0] ) ? $image_data_array[0] : '';
$new_image_data_array['width'] = isset( $image_data_array[1] ) ? $image_data_array[1] : '';
$new_image_data_array['height'] = isset( $image_data_array[2] ) ? $image_data_array[2] : '';
}

return $new_image_data_array;
}

/**
* Check if the image in the formatted image_data_array is a square image
*
* @param array $image_data_array
*
* @return bool
*/
private function check_image_is_square( $image_data_array = array() ) {
if ( isset( $image_data_array['width'] ) && isset( $image_data_array['height'] ) ) {
if ( ( $image_data_array['width'] / $image_data_array['height'] ) === 1 ) {
return true;
}
}

return false;
}

/**
* Get Album Art for Player
*
* Iteratively tries to find the correct album art based on whether the desired image is of square aspect ratio.
* Falls back to default album art if it can not find the correct ones.
*
* @param $episode_id ID of the episode being loaded into the player
* @param int $episode_id ID of the episode being loaded into the player
*
* @return array [ $src, $width, $height ]
*
Expand All @@ -181,8 +144,8 @@ public function get_album_art( $episode_id = false ) {
*/
$thumb_id = get_post_meta( $episode_id, 'cover_image_id', true );
if ( ! empty( $thumb_id ) ) {
$image_data_array = $this->return_renamed_image_array_keys( wp_get_attachment_image_src( $thumb_id, 'medium' ) );
if ( $this->check_image_is_square( $image_data_array ) ) {
$image_data_array = ssp_get_attachment_image_src( $thumb_id );
if ( ssp_is_image_square( $image_data_array ) ) {
return $image_data_array;
}
}
Expand All @@ -192,8 +155,8 @@ public function get_album_art( $episode_id = false ) {
*/
$thumb_id = get_post_thumbnail_id( $episode_id );
if ( ! empty( $thumb_id ) ) {
$image_data_array = $this->return_renamed_image_array_keys( wp_get_attachment_image_src( $thumb_id, 'medium' ) );
if ( $this->check_image_is_square( $image_data_array ) ) {
$image_data_array = ssp_get_attachment_image_src( $thumb_id );
if ( ssp_is_image_square( $image_data_array ) ) {
return $image_data_array;
}
}
Expand All @@ -202,8 +165,6 @@ public function get_album_art( $episode_id = false ) {
* Option 3: if the episode belongs to a series, which has an image that is square, then use that
*/
$series_id = false;
$series_image = '';

$series = get_the_terms( $episode_id, 'series' );

/**
Expand All @@ -214,13 +175,12 @@ public function get_album_art( $episode_id = false ) {
}

if ( $series_id ) {
$series_image = get_option( "ss_podcasting_data_image_{$series_id}", false );
$series_image_attachment_id = get_term_meta( $series_id, $this->token . '_series_image_settings', true );
}

if ( $series_image ) {
$series_image_attachment_id = ssp_get_image_id_from_url( $series_image );
$image_data_array = $this->return_renamed_image_array_keys( wp_get_attachment_image_src( $series_image_attachment_id, 'medium' ) );
if ( $this->check_image_is_square( $image_data_array ) ) {
if ( ! empty( $series_image_attachment_id ) ) {
$image_data_array = ssp_get_attachment_image_src( $series_image_attachment_id );
if ( ssp_is_image_square( $image_data_array ) ) {
return $image_data_array;
}
}
Expand All @@ -231,8 +191,8 @@ public function get_album_art( $episode_id = false ) {
$feed_image = get_option( 'ss_podcasting_data_image', false );
if ( $feed_image ) {
$feed_image_attachment_id = ssp_get_image_id_from_url( $feed_image );
$image_data_array = $this->return_renamed_image_array_keys( wp_get_attachment_image_src( $feed_image_attachment_id, 'medium' ) );
if ( $this->check_image_is_square( $image_data_array ) ) {
$image_data_array = ssp_get_attachment_image_src( $feed_image_attachment_id );
if ( ssp_is_image_square( $image_data_array ) ) {
return $image_data_array;
}
}
Expand Down Expand Up @@ -262,7 +222,7 @@ public function episode_list( $episode_ids, $include_title = false, $include_exc
if ( ! empty( $episode_ids ) ) {
$args = array(
'include' => array_values( $episode_ids ),
'post_type' => 'podcast',
'post_type' => SSP_CPT_PODCAST,
'numberposts' => -1
);

Expand All @@ -289,7 +249,7 @@ public function episode_list( $episode_ids, $include_title = false, $include_exc
public function render_episodes($settings) {
$player = new Players_Controller( $this->file, $this->version );
$args = array(
'post_type' => 'podcast',
'post_type' => SSP_CPT_PODCAST,
'posts_per_page' => 10,
);

Expand Down
28 changes: 16 additions & 12 deletions php/classes/controllers/class-feed-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -336,14 +336,22 @@ public function load_feed_template() {
$complete = '';
}

// Podcast cover image
$image = get_option( 'ss_podcasting_data_image', '' );
if ( $podcast_series ) {
$series_image = get_option( 'ss_podcasting_data_image_' . $series_id, 'no-image' );
if ( 'no-image' !== $series_image ) {
$image = $series_image;
// If it's series feed, try first to show its own image
if ( $series_id ) {
$series_image_attachment_id = get_term_meta( $series_id, $this->token . '_series_image_settings', true );

$size = "full";
if ( $series_image_attachment_id && ssp_is_feed_image_valid( $series_image_attachment_id, $size ) ) {
$image = wp_get_attachment_image_url( $series_image_attachment_id, $size );
}
}

// If couldn't show the series image, or if it's global feed, lets show the the global cover image
if ( empty( $image ) ) {
$image = get_option( 'ss_podcasting_data_image', '' );
}

// Here we'll sanitize the image once again, if it's not valid - it will be just empty string
$image = apply_filters( 'ssp_feed_image', $image, $series_id );

// Podcast category and subcategory (all levels) - can be filtered with `ssp_feed_category_output`
Expand Down Expand Up @@ -389,7 +397,7 @@ public function load_feed_template() {
}

// Set RSS content type and charset headers
header( 'Content-Type: ' . feed_content_type( 'podcast' ) . '; charset=' . get_option( 'blog_charset' ), true );
header( 'Content-Type: ' . feed_content_type( SSP_CPT_PODCAST ) . '; charset=' . get_option( 'blog_charset' ), true );


// Load user feed template if it exists, otherwise use plugin template
Expand All @@ -409,15 +417,11 @@ public function load_feed_template() {
* @param string $image_url
*
* @return string
*
* @todo: Get rid of global, use dependency injection
* @var Frontend_Controller $ss_podcasting
*/
public function sanitize_image( $image_url ) {
global $ss_podcasting;
$image_id = attachment_url_to_postid( $image_url );

if ( $image_id && ! $ss_podcasting->is_image_valid( $image_id ) ) {
if ( $image_id && ! ssp_is_feed_image_valid( $image_id ) ) {
$image_url = '';
}

Expand Down
32 changes: 7 additions & 25 deletions php/classes/controllers/class-frontend-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,7 @@ public function add_to_home_query( $query ) {
$include_in_main_query = get_option('ss_podcasting_include_in_main_query');
if ( $include_in_main_query && $include_in_main_query == 'on' ) {
if ( $query->is_home() && $query->is_main_query() ) {
$query->set( 'post_type', array( 'post', 'podcast' ) );
$query->set( 'post_type', array( 'post', SSP_CPT_PODCAST ) );
}
}
}
Expand All @@ -799,7 +799,7 @@ public function add_all_post_types ( $query ) {
return;
}

if ( is_post_type_archive( 'podcast' ) || is_tax( 'series' ) ) {
if ( is_post_type_archive( SSP_CPT_PODCAST ) || is_tax( 'series' ) ) {

$podcast_post_types = ssp_post_types( false );

Expand All @@ -812,7 +812,7 @@ public function add_all_post_types ( $query ) {

$query->set( 'post__in', $episode_ids );

$podcast_post_types[] = 'podcast';
$podcast_post_types[] = SSP_CPT_PODCAST;
$query->set( 'post_type', $podcast_post_types );

}
Expand All @@ -835,7 +835,7 @@ public function add_all_post_types_for_tag_archive( $query ) {
return;
}

$tag_archive_post_types = apply_filters( 'ssp_tag_archive_post_types', array('post', 'podcast') ) ;
$tag_archive_post_types = apply_filters( 'ssp_tag_archive_post_types', array('post', SSP_CPT_PODCAST) ) ;
$query->set( 'post_type', $tag_archive_post_types );

}
Expand Down Expand Up @@ -933,11 +933,11 @@ public function get_image( $post_id = 0, $size = 'full' ) {
public function get_episode_image_url( $post_id = 0, $size = 'full' ) {
$image_url = '';
$image_id = get_post_meta( $post_id, 'cover_image_id', true );
$is_valid = $this->is_image_valid( $image_id, $size );
$is_valid = ssp_is_feed_image_valid( $image_id, $size );

if ( ! $is_valid ) {
$image_id = get_post_thumbnail_id( $post_id );
$is_valid = $this->is_image_valid( $image_id, $size );
$is_valid = ssp_is_feed_image_valid( $image_id, $size );
}

if ( $is_valid ) {
Expand All @@ -948,24 +948,6 @@ public function get_episode_image_url( $post_id = 0, $size = 'full' ) {
return apply_filters( 'ssp_episode_image_url', $image_url, $post_id );
}

/**
* @param int $image_id
* @param string $size
*
* @return bool
*/
public function is_image_valid( $image_id, $size = 'full' ) {
$image_att = $image_id ? wp_get_attachment_image_src( $image_id, $size ) : null;
$min_size = apply_filters( 'ssp_episode_min_image_size', 1400 );
$max_size = apply_filters( 'ssp_episode_min_image_size', 3000 );
if ( empty( $image_att ) ) {
return false;
}
$width = isset( $image_att[1] ) ? $image_att[1] : 0;
$height = isset( $image_att[2] ) ? $image_att[2] : 0;

return $width === $height && $width >= $min_size && $width <= $max_size;
}

/**
* Get podcast
Expand Down Expand Up @@ -1418,7 +1400,7 @@ public function register_shortcodes () {
*/
public function feed_content_type ( $content_type = '', $type = '' ) {

if( 'podcast' == $type ) {
if( SSP_CPT_PODCAST == $type ) {
$content_type = 'text/xml';
}

Expand Down
6 changes: 3 additions & 3 deletions php/classes/controllers/class-options-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function download_existing_options() {
return;
}
$post_type = ( isset( $_GET['post_type'] ) ? sanitize_text_field( $_GET['post_type'] ) : '' );
if ( 'podcast' !== $post_type ) {
if ( SSP_CPT_PODCAST !== $post_type ) {
return;
}
$page = ( isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : '' );
Expand Down Expand Up @@ -110,7 +110,7 @@ public function upgrade_existing_options() {
return;
}
$post_type = ( isset( $_GET['post_type'] ) ? sanitize_text_field( $_GET['post_type'] ) : '' );
if ( 'podcast' !== $post_type ) {
if ( SSP_CPT_PODCAST !== $post_type ) {
return;
}
$page = ( isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : '' );
Expand Down Expand Up @@ -605,7 +605,7 @@ public function display_field( $args ) {
$html .= esc_url( $url ) . "\n";
break;
case 'podcast_url':
$slug = apply_filters( 'ssp_archive_slug', _x( 'podcast', 'Podcast URL slug', 'seriously-simple-podcasting' ) );
$slug = apply_filters( 'ssp_archive_slug', _x( SSP_CPT_PODCAST, 'Podcast URL slug', 'seriously-simple-podcasting' ) );
$podcast_url = $this->home_url . $slug;

$html .= '<a href="' . esc_url( $podcast_url ) . '" target="_blank">' . $podcast_url . '</a>';
Expand Down
4 changes: 2 additions & 2 deletions php/classes/controllers/class-players-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function get_latest_episode_id() {
*
* @return array
*/
public function html_player( $id ) {
public function get_html_player_data( $id ) {
$audio_file = get_post_meta( $id, 'audio_file', true );
if ( empty( $audio_file ) ) {
return apply_filters( 'ssp_html_player_data', array() );
Expand Down Expand Up @@ -117,7 +117,7 @@ public function html_player( $id ) {
* @return string
*/
public function render_html_player( $episode_id ) {
$template_data = $this->html_player( $episode_id );
$template_data = $this->get_html_player_data( $episode_id );
if ( ! array_key_exists( 'audio_file', $template_data ) ) {
return '';
}
Expand Down
Loading

0 comments on commit 6705eb4

Please sign in to comment.