Skip to content

Commit

Permalink
Merge branch 'master' of github.com:TheCraigHewitt/Seriously-Simple-P…
Browse files Browse the repository at this point in the history
…odcasting
  • Loading branch information
jonathanbossenger committed Sep 30, 2017
2 parents 98be36c + 7bbf476 commit a850071
Show file tree
Hide file tree
Showing 10 changed files with 593 additions and 266 deletions.
2 changes: 2 additions & 0 deletions assets/js/fileupload.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ jQuery( document ).ready( function ( $ ) {

// we're only expecting one file to be uploaded
var file = files[ 0 ];
var filesize_raw = file.size;
var file_size = plupload.formatSize(file.size);
var uploaded_file = 'https://s3.amazonaws.com/' + bucket + '/' + show_slug + '/' + file.name;
var episode_file = episodes_url + show_slug + '/' + file.name;
Expand All @@ -133,6 +134,7 @@ jQuery( document ).ready( function ( $ ) {
if ( response.status == 'success' ) {
notificationBar( 'Uploading file to Seriously Simple Hosting Complete.' );
$( "#podmotor_file_id" ).val( response.file_id );
$( "#filesize_raw" ).val( filesize_raw );
$( "#filesize" ).val( file_size );
$( "#duration" ).val( response.file_duration );
$( '#upload_audio_file' ).val( episode_file );
Expand Down
2 changes: 1 addition & 1 deletion assets/js/fileupload.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

72 changes: 68 additions & 4 deletions includes/class-podmotor-handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ public function validate_api_credentials( $podmotor_account_api_token = '', $pod
}

$api_url = SSP_PODMOTOR_APP_URL . 'api/users/validate';

ssp_debug( 'Validate Credentials : API URL', $api_url );

$app_response = wp_remote_get( $api_url, array(
'timeout' => 45,
'body' => array(
Expand All @@ -120,6 +123,8 @@ public function validate_api_credentials( $podmotor_account_api_token = '', $pod
)
);

ssp_debug( 'Validate Credentials : App Response', $app_response );

if ( ! is_wp_error( $app_response ) ) {

$response_object = json_decode( wp_remote_retrieve_body( $app_response ) );
Expand Down Expand Up @@ -390,8 +395,61 @@ public function upload_podcast_to_podmotor( $post ) {
}

/**
* Upload Podcast episode data to Seriously Simple Hosting
* Should only happen once the file has been uploaded to Seriously Simple Hosting Storage
* Upload Podcasts episode data to Seriously Simple Hosting
*
* @param $podcast_data array of post values
*
* @return bool
*/
public function upload_podcasts_to_podmotor( $podcast_data ) {

$this->setup_response();

if ( empty( $podcast_data ) ) {
$this->update_response( 'message', 'Invalid Podcast data' );

return $this->response;
}

$podcast_data_json = wp_json_encode( $podcast_data );

$podmotor_api_token = get_option( 'ss_podcasting_podmotor_account_api_token', '' );

$api_url = SSP_PODMOTOR_APP_URL . 'api/import_episodes';

$post_body = array(
'api_token' => $podmotor_api_token,
'podcast_data' => $podcast_data_json,
);

ssp_debug( $post_body );

$app_response = wp_remote_post( $api_url, array(
'timeout' => 45,
'body' => $post_body,
)
);

ssp_debug($app_response);

if ( ! is_wp_error( $app_response ) ) {
$responseObject = json_decode( wp_remote_retrieve_body( $app_response ) );
if ( 'success' == $responseObject->status ) {
$this->update_response( 'status', 'success' );
$this->update_response( 'message', 'Pocast episode data successfully uploaded to Seriously Simple Hosting' );
} else {
$this->update_response( 'message', 'An error occurred uploading the episode data to Seriously Simple Hosting' );
}
} else {
// $todo this should be logged somewhere
$this->update_response( 'message', 'An unknown error occurred: ' . $app_response->get_error_message() );
}

return $this->response;
}

/**
* Creates the podcast import queue with Seriously Simple Hosting
*
* @param $post
*
Expand All @@ -401,24 +459,30 @@ public function insert_podmotor_queue() {

$this->setup_response();

$podmotor_api_token = get_option( "ss_podcasting_podmotor_account_api_token", "" );
$podmotor_api_token = get_option( 'ss_podcasting_podmotor_account_api_token', '' );
ssp_debug($podmotor_api_token);

$api_url = SSP_PODMOTOR_APP_URL . 'api/insert_queue';
ssp_debug($api_url);

$post_body = array(
'api_token' => $podmotor_api_token,
'site_name' => get_bloginfo( 'name' ),
'site_action' => add_query_arg( 'podcast_importer', 'true', site_url() ),
'site_action' => add_query_arg( 'podcast_importer', 'true', trailingslashit( site_url() ) ),
);
ssp_debug($post_body);

$app_response = wp_remote_post( $api_url, array(
'timeout' => 45,
'body' => $post_body,
)
);
ssp_debug($app_response);

if ( ! is_wp_error( $app_response ) ) {
$responseObject = json_decode( wp_remote_retrieve_body( $app_response ) );
ssp_debug( $responseObject );

if ( 'success' == $responseObject->status ) {
$this->update_response( 'status', $responseObject->status );
$this->update_response( 'message', $responseObject->message );
Expand Down
130 changes: 111 additions & 19 deletions includes/class-ssp-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,18 @@ public function meta_box_content() {
$html .= '<span class="description">' . wp_kses_post( $v['description'] ) . '</span>
</p>' . "\n";
break;

case 'select':
$html .= '<p>
<span class="ssp-episode-details-label">' . wp_kses_post( $v['name'] ) . '</span><br/>';
$html .= '<select name="' . esc_attr( $k ) . '" class="' . esc_attr( $class ) . '" id="' . esc_attr( $k ) . '_' . esc_attr( $option ) . '">';
foreach ( $v['options'] as $option => $label ) {
$html .= '<option ' . selected( $option, $data, false ) . ' value="' . esc_attr( $option ) . '">' . esc_attr( $label ) . '</option>';
}
$html .= '</select>';
$html .= '<span class="description">' . wp_kses_post( $v['description'] ) . '</span>
</p>' . "\n";
break;

case 'datepicker':
$display_date = '';
Expand Down Expand Up @@ -626,6 +638,16 @@ public function meta_box_content() {
<input name="' . esc_attr( $k ) . '" type="hidden" id="' . esc_attr( $k ) . '" value="' . esc_attr( $data ) . '" />
</p>' . "\n";
break;

case 'number':
$html .= '<p>
<label class="ssp-episode-details-label" for="' . esc_attr( $k ) . '">' . wp_kses_post( $v['name'] ) . '</label>
<br/>
<input name="' . esc_attr( $k ) . '" type="number" min="0" id="' . esc_attr( $k ) . '" class="' . esc_attr( $class ) . '" value="' . esc_attr( $data ) . '" />
<br/>
<span class="description">' . wp_kses_post( $v['description'] ) . '</span>
</p>' . "\n";
break;

default:
$html .= '<p>
Expand Down Expand Up @@ -678,6 +700,9 @@ public function meta_box_save( $post_id ) {
}

$field_data = $this->custom_fields();

ssp_debug( 'Field Data', $field_data );

$enclosure = '';

foreach ( $field_data as $k => $field ) {
Expand All @@ -704,27 +729,31 @@ public function meta_box_save( $post_id ) {

if ( $enclosure ) {

// Get file duration
if ( get_post_meta( $post_id, 'duration', true ) == '' ) {
$duration = $ss_podcasting->get_file_duration( $enclosure );
if ( $duration ) {
update_post_meta( $post_id, 'duration', $duration );
}
}
ssp_debug( 'File Enclosure', $enclosure );

// Get file size
if ( get_post_meta( $post_id, 'filesize', true ) == '' ) {
$filesize = $ss_podcasting->get_file_size( $enclosure );
if ( $filesize ) {

if ( isset( $filesize['formatted'] ) ) {
update_post_meta( $post_id, 'filesize', $filesize['formatted'] );
if ( ! ssp_is_connected_to_podcastmotor() ) {
// Get file duration
if ( get_post_meta( $post_id, 'duration', true ) == '' ) {
$duration = $ss_podcasting->get_file_duration( $enclosure );
if ( $duration ) {
update_post_meta( $post_id, 'duration', $duration );
}

if ( isset( $filesize['raw'] ) ) {
update_post_meta( $post_id, 'filesize_raw', $filesize['raw'] );
}

// Get file size
if ( get_post_meta( $post_id, 'filesize', true ) == '' ) {
$filesize = $ss_podcasting->get_file_size( $enclosure );
if ( $filesize ) {

if ( isset( $filesize['formatted'] ) ) {
update_post_meta( $post_id, 'filesize', $filesize['formatted'] );
}

if ( isset( $filesize['raw'] ) ) {
update_post_meta( $post_id, 'filesize_raw', $filesize['raw'] );
}

}

}
}

Expand Down Expand Up @@ -755,6 +784,48 @@ public function custom_fields() {
'section' => 'info',
'meta_description' => __( 'The type of podcast episode - either Audio or Video', 'seriously-simple-podcasting' ),
);

/**
* New iTunes Tag Announced At WWDC 2017
*/
$fields['itunes_title'] = array(
'name' => __( 'iTunes Episode Title (Exclude Your Series / Show Number):', 'seriously-simple-podcasting' ),
'description' => __( 'The iTunes Episode Title. NO Series / Show Number Should Be Included.', 'seriously-simple-podcasting' ),
'type' => 'text',
'default' => '',
'section' => 'info',
'meta_description' => __( 'The iTunes Episode Title. NO Series / Show Number Should Be Included', 'seriously-simple-podcasting' ),
);

/**
* New iTunes Tag Announced At WWDC 2017
*/
$fields['itunes_season_number'] = array(
'name' => __( 'iTunes Season Number:', 'seriously-simple-podcasting' ),
'description' => __( 'The iTunes Season Number. Leave Blank If None.', 'seriously-simple-podcasting' ),
'type' => 'number',
'default' => '',
'section' => 'info',
'meta_description' => __( 'The iTunes Season Number. Leave Blank If None.', 'seriously-simple-podcasting' ),
);

/**
* New iTunes Tag Announced At WWDC 2017
*/
$fields['itunes_episode_type'] = array(
'name' => __( 'iTunes Episode Type:', 'seriously-simple-podcasting' ),
'description' => '',
'type' => 'select',
'default' => '',
'options' => array(
'' => __( 'Please Select', 'seriously-simple-podcasting' ),
'full' => __( 'Full: For Normal Episodes', 'seriously-simple-podcasting' ),
'trailer' => __( 'Trailer: Promote an Upcoming Show', 'seriously-simple-podcasting' ),
'bonus' => __( 'Bonus: For Extra Content Related To a Show', 'seriously-simple-podcasting' )
),
'section' => 'info',
'meta_description' => __( 'The iTunes Episode Type', 'seriously-simple-podcasting' ),
);

// In v1.14+ the `audio_file` field can actually be either audio or video, but we're keeping the field name here for backwards compatibility
$fields['audio_file'] = array(
Expand Down Expand Up @@ -793,6 +864,27 @@ public function custom_fields() {
'section' => 'info',
'meta_description' => __( 'The size of the podcast episode for display purposes.', 'seriously-simple-podcasting' ),
);

/**
* New iTunes Tag Announced At WWDC 2017
*/
$fields['itunes_episode_number'] = array(
'name' => __( 'iTunes Episode Number:', 'seriously-simple-podcasting' ),
'description' => __( 'The iTunes Episode Number. Leave Blank If None.', 'seriously-simple-podcasting' ),
'type' => 'number',
'default' => '',
'section' => 'info',
'meta_description' => __( 'The iTunes Episode Number. Leave Blank If None.', 'seriously-simple-podcasting' ),
);

if ( ssp_is_connected_to_podcastmotor() ) {
$fields['filesize_raw'] = array(
'type' => 'hidden',
'default' => '',
'section' => 'info',
'meta_description' => __( 'Raw size of the podcast episode.', 'seriously-simple-podcasting' ),
);
}

$fields['date_recorded'] = array(
'name' => __( 'Date recorded:', 'seriously-simple-podcasting' ),
Expand Down Expand Up @@ -1368,7 +1460,7 @@ public function check_existing_podcasts() {
}

// check if there is at least one podcast to import
$podcast_query = ssp_get_existing_podcast();
$podcast_query = ssp_get_existing_podcasts();
if ( $podcast_query->have_posts() ) {
add_action( 'admin_notices', array( $this, 'existing_podcasts_notice' ) );
}
Expand Down
Loading

0 comments on commit a850071

Please sign in to comment.