From c4d87e33d1c72e3e400c1f9b6da867650f349acb Mon Sep 17 00:00:00 2001 From: Jonathan Bossenger Date: Mon, 29 May 2017 13:23:19 +0200 Subject: [PATCH 01/10] Create directories for Offsite uploads --- includes/class-ssp-admin.php | 520 ++++++++++++++++++----------------- 1 file changed, 264 insertions(+), 256 deletions(-) diff --git a/includes/class-ssp-admin.php b/includes/class-ssp-admin.php index 728bb988..259333f3 100644 --- a/includes/class-ssp-admin.php +++ b/includes/class-ssp-admin.php @@ -23,16 +23,16 @@ class SSP_Admin { private $token; private $home_url; private $script_suffix; - + /** * Constructor * * @param string $file Plugin base file */ public function __construct( $file, $version ) { - + $this->version = $version; - + $this->dir = dirname( $file ); $this->file = $file; $this->assets_dir = trailingslashit( $this->dir ) . 'assets'; @@ -40,71 +40,71 @@ public function __construct( $file, $version ) { $this->template_path = trailingslashit( $this->dir ) . 'templates/'; $this->home_url = trailingslashit( home_url() ); $this->token = 'podcast'; - + $this->script_suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; - + // Handle localisation. $this->load_plugin_textdomain(); add_action( 'init', array( $this, 'load_localisation' ), 0 ); - + // Regsiter podcast post type, taxonomies and meta fields. add_action( 'init', array( $this, 'register_post_type' ), 1 ); - + // Register podcast feed. add_action( 'init', array( $this, 'add_feed' ), 1 ); - + // Hide WP SEO footer text for podcast RSS feed. add_filter( 'wpseo_include_rss_footer', array( $this, 'hide_wp_seo_rss_footer' ) ); - + // Handle v1.x feed URL as well as feed URLs for default permalinks. add_action( 'init', array( $this, 'redirect_old_feed' ) ); - + // Setup custom permalink structures. add_action( 'init', array( $this, 'setup_permastruct' ), 10 ); - + if ( is_admin() ) { - + add_action( 'admin_init', array( $this, 'update_enclosures' ) ); - + // Episode meta box. add_action( 'admin_init', array( $this, 'register_meta_boxes' ) ); add_action( 'save_post', array( $this, 'meta_box_save' ), 10, 1 ); - + // Update podcast details to Seriously Simple Hosting. add_action( 'post_updated', array( $this, 'update_podcast_details' ), 10, 2 ); add_action( 'save_post', array( $this, 'update_podcast_details' ), 10, 2 ); - + // Episode edit screen. add_filter( 'enter_title_here', array( $this, 'enter_title_here' ) ); add_filter( 'post_updated_messages', array( $this, 'updated_messages' ) ); - + // Admin JS & CSS. add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_styles' ), 10 ); add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_scripts' ), 10 ); - + // Episodes list table. add_filter( 'manage_edit-' . $this->token . '_columns', array( $this, 'register_custom_column_headings', ), 10, 1 ); add_action( 'manage_posts_custom_column', array( $this, 'register_custom_columns' ), 10, 2 ); - + // Series list table. add_filter( 'manage_edit-series_columns', array( $this, 'edit_series_columns' ) ); add_filter( 'manage_series_custom_column', array( $this, 'add_series_columns' ), 1, 3 ); - + // Dashboard widgets. add_filter( 'dashboard_glance_items', array( $this, 'glance_items' ), 10, 1 ); - + // Appreciation links. add_filter( 'plugin_row_meta', array( $this, 'plugin_row_meta' ), 10, 4 ); - + // Add footer text to dashboard. add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ), 1 ); - + // Clear the cache on post save. add_action( 'save_post', array( $this, 'invalidate_cache' ), 10, 2 ); - + // Check for, setup or ignore import of existing podcasts. add_action( 'admin_init', array( $this, 'ignore_importing_existing_podcasts' ) ); add_action( 'admin_init', array( $this, 'start_importing_existing_podcasts' ) ); @@ -113,32 +113,32 @@ public function __construct( $file, $version ) { // Show upgrade screen add_action( 'current_screen', array( $this, 'show_upgrade_screen' ), 12 ); - + // Check if a valid permalink structure is set and show a message add_action( 'admin_init', array( $this, 'check_valid_permalink' ) ); } // End if(). - + // Add ajax action for plugin rating add_action( 'wp_ajax_ssp_rated', array( $this, 'rated' ) ); - + // Add ajax action for uploading to Seriously Simple Hosting add_action( 'wp_ajax_ssp_upload_to_podmotor', array( $this, 'upload_file_to_podmotor' ) ); - + // Add ajax action for customising episode embed code add_action( 'wp_ajax_update_episode_embed_code', array( $this, 'update_episode_embed_code' ) ); - + // Setup activation and deactivation hooks register_activation_hook( $file, array( $this, 'activate' ) ); register_deactivation_hook( $file, array( $this, 'deactivate' ) ); - + add_action( 'init', array( $this, 'update' ), 11 ); // Dismiss the upgrade screen and redirect to the last screen the user was on add_action( 'init', array( $this, 'dismiss_upgrade_screen' ) ); } - + /** * Setup the PodcastMotor Uploads directory */ @@ -147,34 +147,34 @@ public function setup_directories() { wp_mkdir_p( SSP_UPLOADS_DIR ); } } - + /** * Setup custom permalink structures * @return void */ public function setup_permastruct() { - + // Episode download & player URLs add_rewrite_rule( '^podcast-download/([^/]*)/([^/]*)/?', 'index.php?podcast_episode=$matches[1]', 'top' ); add_rewrite_rule( '^podcast-player/([^/]*)/([^/]*)/?', 'index.php?podcast_episode=$matches[1]&podcast_ref=player', 'top' ); - + // Custom query variables add_rewrite_tag( '%podcast_episode%', '([^&]+)' ); add_rewrite_tag( '%podcast_ref%', '([^&]+)' ); - + // Series feed URLs $feed_slug = apply_filters( 'ssp_feed_slug', $this->token ); add_rewrite_rule( '^feed/' . $feed_slug . '/([^/]*)/?', 'index.php?feed=podcast&podcast_series=$matches[1]', 'top' ); add_rewrite_tag( '%podcast_series%', '([^&]+)' ); } - + /** * Register 'podcast' post type * * @return void */ public function register_post_type() { - + $labels = array( 'name' => _x( 'Podcast', 'post type general name', 'seriously-simple-podcasting' ), 'singular_name' => _x( 'Podcast', 'post type singular name', 'seriously-simple-podcasting' ), @@ -193,9 +193,9 @@ public function register_post_type() { 'items_list_navigation' => sprintf( __( '%s list navigation', 'seriously-simple-podcasting' ), __( 'Episode', 'seriously-simple-podcasting' ) ), 'items_list' => sprintf( __( '%s list', 'seriously-simple-podcasting' ), __( 'Episode', 'seriously-simple-podcasting' ) ), ); - + $slug = apply_filters( 'ssp_archive_slug', __( 'podcast', 'seriously-simple-podcasting' ) ); - + $args = array( 'labels' => $labels, 'public' => true, @@ -225,23 +225,23 @@ public function register_post_type() { 'menu_icon' => 'dashicons-microphone', 'show_in_rest' => true, ); - + $args = apply_filters( 'ssp_register_post_type_args', $args ); - + register_post_type( $this->token, $args ); - + $this->register_taxonomies(); $this->register_meta(); } - + /** * Register taxonomies * @return void */ private function register_taxonomies() { - + $podcast_post_types = ssp_post_types( true ); - + $series_labels = array( 'name' => __( 'Podcast Series', 'seriously-simple-podcasting' ), 'singular_name' => __( 'Series', 'seriously-simple-podcasting' ), @@ -263,7 +263,7 @@ private function register_taxonomies() { 'items_list_navigation' => __( 'Series list navigation', 'seriously-simple-podcasting' ), 'items_list' => __( 'Series list', 'seriously-simple-podcasting' ), ); - + $series_args = array( 'public' => true, 'hierarchical' => true, @@ -271,47 +271,47 @@ private function register_taxonomies() { 'labels' => $series_labels, 'show_in_rest' => true, ); - + $series_args = apply_filters( 'ssp_register_taxonomy_args', $series_args, 'series' ); - + register_taxonomy( 'series', $podcast_post_types, $series_args ); - + // Add Tags to podcast post type if ( apply_filters( 'ssp_use_post_tags', true ) ) { register_taxonomy_for_object_type( 'post_tag', $this->token ); } } - + public function register_meta() { global $wp_version; - + // The enhanced register_meta function is only available for WordPress 4.6+ if ( version_compare( $wp_version, '4.6', '<' ) ) { return; } - + // Get all displayed custom fields $fields = $this->custom_fields(); - + // Add 'filesize_raw' as this is not included in the displayed field options $fields['filesize_raw'] = array( 'meta_description' => __( 'The raw file size of the podcast episode media file in bytes.', 'seriously-simple-podcasting' ), ); - + foreach ( $fields as $key => $data ) { - + $args = array( 'type' => 'string', 'description' => $data['meta_description'], 'single' => true, 'show_in_rest' => true, ); - + register_meta( 'post', $key, $args ); } - + } - + /** * Register columns for podcast list table * @@ -324,16 +324,16 @@ public function register_custom_column_headings( $defaults ) { 'series' => __( 'Series', 'seriously-simple-podcasting' ), 'image' => __( 'Image', 'seriously-simple-podcasting' ), ) ); - + // remove date column unset( $defaults['date'] ); - + // add new columns before last default one $columns = array_slice( $defaults, 0, - 1 ) + $new_columns + array_slice( $defaults, - 1 ); - + return $columns; } - + /** * Display column data in podcast list table * @@ -344,26 +344,26 @@ public function register_custom_column_headings( $defaults ) { */ public function register_custom_columns( $column_name, $id ) { global $ss_podcasting; - + switch ( $column_name ) { - + case 'series': $terms = wp_get_post_terms( $id, 'series' ); $term_names = wp_list_pluck( $terms, 'name' ); echo join( ', ', $term_names ); break; - + case 'image': $value = $ss_podcasting->get_image( $id, 40 ); echo $value; break; - + default: break; - + } } - + /** * Register solumns for series list table * @@ -372,18 +372,18 @@ public function register_custom_columns( $column_name, $id ) { * @return array Modified columns */ public function edit_series_columns( $columns ) { - + unset( $columns['description'] ); unset( $columns['posts'] ); - + $columns['series_feed_url'] = __( 'Series feed URL', 'seriously-simple-podcasting' ); $columns['posts'] = __( 'Episodes', 'seriously-simple-podcasting' ); - + $columns = apply_filters( 'ssp_admin_columns_series', $columns ); - + return $columns; } - + /** * Display column data in series list table * @@ -394,12 +394,12 @@ public function edit_series_columns( $columns ) { * @return string */ public function add_series_columns( $column_data, $column_name, $term_id ) { - + switch ( $column_name ) { case 'series_feed_url': $series = get_term( $term_id, 'series' ); $series_slug = $series->slug; - + if ( get_option( 'permalink_structure' ) ) { $feed_slug = apply_filters( 'ssp_feed_slug', $this->token ); $feed_url = $this->home_url . 'feed/' . $feed_slug . '/' . $series_slug; @@ -412,14 +412,14 @@ public function add_series_columns( $column_data, $column_name, $term_id ) { $this->home_url ); } - + $column_data = '' . esc_html( $feed_url ) . ''; break; } - + return $column_data; } - + /** * Create custom dashboard message * @@ -429,7 +429,7 @@ public function add_series_columns( $column_data, $column_name, $term_id ) { */ public function updated_messages( $messages ) { global $post, $post_ID; - + $messages[ $this->token ] = array( 0 => '', 1 => sprintf( __( 'Episode updated. %sView episode%s.', 'seriously-simple-podcasting' ), '', '' ), @@ -443,49 +443,49 @@ public function updated_messages( $messages ) { 9 => sprintf( __( 'Episode scheduled for: %1$s. %2$sPreview episode%3$s.', 'seriously-simple-podcasting' ), '' . date_i18n( __( 'M j, Y @ G:i', 'seriously-simple-podcasting' ), strtotime( $post->post_date ) ) . '', '', '' ), 10 => sprintf( __( 'Episode draft updated. %sPreview episode%s.', 'seriously-simple-podcasting' ), '', '' ), ); - + return $messages; } - + /** * Register podcast episode details meta boxes * @return void */ public function register_meta_boxes() { - + // Get all podcast post types $podcast_post_types = ssp_post_types( true ); - + // Add meta box to each post type foreach ( (array) $podcast_post_types as $post_type ) { add_action( 'add_meta_boxes_' . $post_type, array( $this, 'meta_box_setup' ), 10, 1 ); } } - + /** * Create meta box on episode edit screen * @return void */ public function meta_box_setup( $post ) { global $pagenow; - + add_meta_box( 'podcast-episode-data', __( 'Podcast Episode Details', 'seriously-simple-podcasting' ), array( $this, 'meta_box_content' ), $post->post_type, 'normal', 'high' ); - + if ( 'post.php' == $pagenow && 'publish' == $post->post_status && function_exists( 'get_post_embed_html' ) ) { add_meta_box( 'episode-embed-code', __( 'Episode Embed Code', 'seriously-simple-podcasting' ), array( $this, 'embed_code_meta_box_content' ), $post->post_type, 'side', 'low' ); } - + // Allow more metaboxes to be added do_action( 'ssp_meta_boxes', $post ); - + } - + /** * Get content for episode embed code meta box * @@ -494,84 +494,84 @@ public function meta_box_setup( $post ) { * @return void */ public function embed_code_meta_box_content( $post ) { - + // Get post embed code $embed_code = get_post_embed_html( 500, 350, $post ); - + // Generate markup for meta box $html = '

' . __( 'Customise the size of your episode embed below, then copy the HTML to your clipboard.', 'seriously-simple-podcasting' ) . '

'; $html .= '

    

'; $html .= '

'; - + echo $html; } - + /** * Update the epiaode embed code via ajax * @return void */ public function update_episode_embed_code() { - + // Make sure we have a valid post ID if ( empty( $_POST['post_id'] ) ) { return; } - + // Get info for embed code $post_id = (int) $_POST['post_id']; $width = (int) $_POST['width']; $height = (int) $_POST['height']; - + // Generate embed code echo get_post_embed_html( $width, $height, $post_id ); - + // Exit after ajax request exit; } - + /** * Load content for episode meta box * @return void */ public function meta_box_content() { global $post_id; - + $field_data = $this->custom_fields(); - + $html = ''; - + $html .= ''; - + if ( 0 < count( $field_data ) ) { - + $html .= ''; - + foreach ( $field_data as $k => $v ) { $data = $v['default']; $saved = get_post_meta( $post_id, $k, true ); if ( $saved ) { $data = $saved; } - + $class = ''; if ( isset( $v['class'] ) ) { $class = $v['class']; } - + $disabled = false; if ( isset( $v['disabled'] ) && $v['disabled'] ) { $disabled = true; } - + switch ( $v['type'] ) { case 'file': - + $upload_button = ''; if ( ssp_is_connected_to_podcastmotor() ) { $upload_button = ''; - + } - + $html .= '


@@ -580,13 +580,13 @@ public function meta_box_content() {
' . wp_kses_post( $v['description'] ) . '

' . "\n"; - + break; - + case 'checkbox': $html .= '

' . "\n"; break; - + case 'radio': $html .= '

' . wp_kses_post( $v['name'] ) . '
'; @@ -597,7 +597,7 @@ public function meta_box_content() { $html .= '' . wp_kses_post( $v['description'] ) . '

' . "\n"; break; - + case 'datepicker': $display_date = ''; if ( $data ) { @@ -612,22 +612,22 @@ public function meta_box_content() { ' . wp_kses_post( $v['description'] ) . '

' . "\n"; break; - + case 'textarea': ob_start(); echo '


'; wp_editor( $data, $k, array( 'editor_class' => esc_attr( $class ) ) ); echo '
' . wp_kses_post( $v['description'] ) . '

' . "\n"; $html .= ob_get_clean(); - + break; - + case 'hidden': $html .= '

' . "\n"; break; - + default: $html .= '

@@ -638,13 +638,13 @@ public function meta_box_content() {

' . "\n"; break; } - + } } - + echo $html; } - + /** * Save episode meta box content * @@ -654,19 +654,19 @@ public function meta_box_content() { */ public function meta_box_save( $post_id ) { global $ss_podcasting; - + $podcast_post_types = ssp_post_types( true ); - + // Post type check if ( ! in_array( get_post_type(), $podcast_post_types ) ) { return false; } - + // Security check if ( ! isset( $_POST[ 'seriouslysimple_' . $this->token . '_nonce' ] ) || ! ( isset( $_POST[ 'seriouslysimple_' . $this->token . '_nonce' ] ) && wp_verify_nonce( $_POST[ 'seriouslysimple_' . $this->token . '_nonce' ], plugin_basename( $this->dir ) ) ) ) { return $post_id; } - + // User capability check if ( 'page' == $_POST['post_type'] ) { if ( ! current_user_can( 'edit_page', $post_id ) ) { @@ -677,16 +677,16 @@ public function meta_box_save( $post_id ) { return $post_id; } } - + $field_data = $this->custom_fields(); $enclosure = ''; - + foreach ( $field_data as $k => $field ) { - + if ( 'embed_code' == $k ) { continue; } - + $val = ''; if ( isset( $_POST[ $k ] ) ) { if ( isset( $field['callback'] ) ) { @@ -695,16 +695,16 @@ public function meta_box_save( $post_id ) { $val = strip_tags( trim( $_POST[ $k ] ) ); } } - + if ( $k == 'audio_file' ) { $enclosure = $val; } - + update_post_meta( $post_id, $k, $val ); } - + if ( $enclosure ) { - + // Get file duration if ( get_post_meta( $post_id, 'duration', true ) == '' ) { $duration = $ss_podcasting->get_file_duration( $enclosure ); @@ -712,30 +712,30 @@ public function meta_box_save( $post_id ) { update_post_meta( $post_id, 'duration', $duration ); } } - + // 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'] ); } - + } } - + // Save podcast file to 'enclosure' meta field for standards-sake update_post_meta( $post_id, 'enclosure', $enclosure ); - + } - + } - + /** * Setup custom fields for episodes * @return array Custom fields @@ -743,7 +743,7 @@ public function meta_box_save( $post_id ) { public function custom_fields() { global $pagenow; $fields = array(); - + $fields['episode_type'] = array( 'name' => __( 'Episode type:', 'seriously-simple-podcasting' ), 'description' => '', @@ -756,7 +756,7 @@ public function custom_fields() { 'section' => 'info', 'meta_description' => __( 'The type of podcast episode - either Audio or Video', '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( 'name' => __( 'Podcast file:', 'seriously-simple-podcasting' ), @@ -766,7 +766,7 @@ public function custom_fields() { 'section' => 'info', 'meta_description' => __( 'The full URL for the podcast episode media file.', 'seriously-simple-podcasting' ), ); - + // if ( ssp_is_connected_to_podcastmotor() ) { $fields['podmotor_file_id'] = array( @@ -776,7 +776,7 @@ public function custom_fields() { 'meta_description' => __( 'Seriously Simple Hosting file id.', 'seriously-simple-podcasting' ), ); } - + $fields['duration'] = array( 'name' => __( 'Duration:', 'seriously-simple-podcasting' ), 'description' => __( 'Duration of podcast file for display (calculated automatically if possible).', 'seriously-simple-podcasting' ), @@ -785,7 +785,7 @@ public function custom_fields() { 'section' => 'info', 'meta_description' => __( 'The duration of the file for display purposes.', 'seriously-simple-podcasting' ), ); - + $fields['filesize'] = array( 'name' => __( 'File size:', 'seriously-simple-podcasting' ), 'description' => __( 'Size of the podcast file for display (calculated automatically if possible).', 'seriously-simple-podcasting' ), @@ -794,7 +794,7 @@ public function custom_fields() { 'section' => 'info', 'meta_description' => __( 'The size of the podcast episode for display purposes.', 'seriously-simple-podcasting' ), ); - + $fields['date_recorded'] = array( 'name' => __( 'Date recorded:', 'seriously-simple-podcasting' ), 'description' => __( 'The date on which this episode was recorded.', 'seriously-simple-podcasting' ), @@ -803,7 +803,7 @@ public function custom_fields() { 'section' => 'info', 'meta_description' => __( 'The date on which the podcast episode was recorded.', 'seriously-simple-podcasting' ), ); - + $fields['explicit'] = array( 'name' => __( 'Explicit:', 'seriously-simple-podcasting' ), 'description' => __( 'Mark this episode as explicit.', 'seriously-simple-podcasting' ), @@ -812,7 +812,7 @@ public function custom_fields() { 'section' => 'info', 'meta_description' => __( 'Indicates whether the episode is explicit or not.', 'seriously-simple-podcasting' ), ); - + $fields['block'] = array( 'name' => __( 'Block:', 'seriously-simple-podcasting' ), 'description' => __( 'Block this episode from appearing in the iTunes & Google Play podcast libraries.', 'seriously-simple-podcasting' ), @@ -821,10 +821,10 @@ public function custom_fields() { 'section' => 'info', 'meta_description' => __( 'Indicates whether this specific episode should be blocked from the iTunes and Google Play Podcast libraries.', 'seriously-simple-podcasting' ), ); - + return apply_filters( 'ssp_episode_fields', $fields ); } - + /** * Adding podcast episodes to 'At a glance' dashboard widget * @@ -833,23 +833,23 @@ public function custom_fields() { * @return array Updated items */ public function glance_items( $items = array() ) { - + $num_posts = count( ssp_episodes( - 1, '', false, 'glance' ) ); - + $post_type_object = get_post_type_object( $this->token ); - + $text = _n( '%s Episode', '%s Episodes', $num_posts, 'seriously-simple-podcasting' ); $text = sprintf( $text, number_format_i18n( $num_posts ) ); - + if ( $post_type_object && current_user_can( $post_type_object->cap->edit_posts ) ) { $items[] = sprintf( '%2$s', $this->token, $text ) . "\n"; } else { $items[] = sprintf( '%2$s', $this->token, $text ) . "\n"; } - + return $items; } - + /** * Adding appreciation links to the SSP record in the plugin list table * @@ -861,18 +861,18 @@ public function glance_items( $items = array() ) { * @return array Modified plugin meta links */ public function plugin_row_meta( $plugin_meta = array(), $plugin_file = '', $plugin_data = array(), $status = '' ) { - + if ( ! isset( $plugin_data['slug'] ) || 'seriously-simple-podcasting' != $plugin_data['slug'] ) { return $plugin_meta; } - + $plugin_meta['docs'] = '' . __( 'Documentation', 'seriously-simple-podcasting' ) . ''; $plugin_meta['addons'] = '' . __( 'Add-ons', 'seriously-simple-podcasting' ) . ''; $plugin_meta['review'] = '' . __( 'Write a review', 'seriously-simple-podcasting' ) . ''; - + return $plugin_meta; } - + /** * Modify the 'enter title here' text * @@ -884,10 +884,10 @@ public function enter_title_here( $title ) { if ( get_post_type() == $this->token ) { $title = __( 'Enter episode title here', 'seriously-simple-podcasting' ); } - + return $title; } - + /** * Load admin CSS * @return void @@ -895,60 +895,60 @@ public function enter_title_here( $title ) { public function enqueue_admin_styles() { wp_register_style( 'ssp-admin', esc_url( $this->assets_url . 'css/admin.css' ), array(), $this->version ); wp_enqueue_style( 'ssp-admin' ); - + wp_register_style( 'ssp-fileupload', esc_url( $this->assets_url . 'css/jquery.fileupload.css' ), array(), $this->version ); wp_enqueue_style( 'ssp-fileupload' ); - + wp_register_style( 'jquery-peekabar', esc_url( $this->assets_url . 'css/jquery.peekabar.css' ), array(), $this->version ); wp_enqueue_style( 'jquery-peekabar' ); - + // Datepicker wp_enqueue_style( 'jquery-ui-datepicker', '//ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/themes/smoothness/jquery-ui.css' ); - + } - + /** * Load admin JS * @return void */ public function enqueue_admin_scripts() { - + wp_register_script( 'ssp-admin', esc_url( $this->assets_url . 'js/admin' . $this->script_suffix . '.js' ), array( 'jquery', 'jquery-ui-core', 'jquery-ui-datepicker' ), $this->version ); wp_enqueue_script( 'ssp-admin' ); - + wp_register_script( 'ssp-settings', esc_url( $this->assets_url . 'js/settings' . $this->script_suffix . '.js' ), array( 'jquery' ), $this->version ); wp_enqueue_script( 'ssp-settings' ); - + wp_register_script( 'jquery-iframe-transport', esc_url( $this->assets_url . 'js/jquery-file-upload/jquery.iframe-transport' . $this->script_suffix . '.js' ), array( 'jquery', 'jquery-ui-core', 'jquery-ui-widget' ), $this->version ); wp_enqueue_script( 'jquery-iframe-transport' ); - + wp_register_script( 'jquery-fileupload', esc_url( $this->assets_url . 'js/jquery-file-upload/jquery.fileupload' . $this->script_suffix . '.js' ), array( 'jquery', 'jquery-ui-core', 'jquery-ui-widget' ), $this->version ); wp_enqueue_script( 'jquery-fileupload' ); - + wp_register_script( 'ssp-fileupload', esc_url( $this->assets_url . 'js/fileupload' . $this->script_suffix . '.js' ), array( 'jquery', 'jquery-fileupload' ), $this->version ); wp_enqueue_script( 'ssp-fileupload' ); - + wp_register_script( 'jquery-peekabar', esc_url( $this->assets_url . 'js/jquery.peekabar' . $this->script_suffix . '.js' ), array( 'jquery' ), $this->version ); wp_enqueue_script( 'jquery-peekabar' ); - - + + } - + /** * Ensure thumbnail support on site * @return void @@ -958,7 +958,7 @@ public function ensure_post_thumbnails_support() { add_theme_support( 'post-thumbnails' ); } } - + /** * Load plugin text domain * @return void @@ -966,7 +966,7 @@ public function ensure_post_thumbnails_support() { public function load_localisation() { load_plugin_textdomain( 'seriously-simple-podcasting', false, dirname( plugin_basename( $this->file ) ) . '/lang/' ); } - + /** * Load localisation * @return void @@ -975,11 +975,11 @@ public function load_plugin_textdomain() { $domain = 'seriously-simple-podcasting'; // The "plugin_locale" filter is also used in load_plugin_textdomain() $locale = apply_filters( 'plugin_locale', get_locale(), $domain ); - + load_textdomain( $domain, WP_LANG_DIR . '/' . $domain . '/' . $domain . '-' . $locale . '.mo' ); load_plugin_textdomain( $domain, false, dirname( plugin_basename( $this->file ) ) . '/lang/' ); } - + /** * Register podcast feed * @return void @@ -988,7 +988,7 @@ public function add_feed() { $feed_slug = apply_filters( 'ssp_feed_slug', $this->token ); add_feed( $feed_slug, array( $this, 'feed_template' ) ); } - + /** * Hide RSS footer created by WordPress SEO from podcast RSS feed * @@ -997,45 +997,45 @@ public function add_feed() { * @return boolean Modified inclusion value */ public function hide_wp_seo_rss_footer( $include_footer = true ) { - + if ( is_feed( 'podcast' ) ) { $include_footer = false; } - + return $include_footer; } - + /** * Load feed template * @return void */ public function feed_template() { global $wp_query; - + // Prevent 404 on feed $wp_query->is_404 = false; status_header( 200 ); - + $file_name = 'feed-podcast.php'; - + $user_template_file = apply_filters( 'ssp_feed_template_file', trailingslashit( get_stylesheet_directory() ) . $file_name ); - + // Any functions hooked in here must NOT output any data or else feed will break do_action( 'ssp_before_feed' ); - + // Load user feed template if it exists, otherwise use plugin template if ( file_exists( $user_template_file ) ) { require( $user_template_file ); } else { require( $this->template_path . $file_name ); } - + // Any functions hooked in here must NOT output any data or else feed will break do_action( 'ssp_after_feed' ); - + exit; } - + /** * Redirect feed URLs created prior to v1.8 to ensure backwards compatibility * @return void @@ -1046,23 +1046,24 @@ public function redirect_old_feed() { exit; } } - + /** * Flush rewrite rules on plugin acivation * @return void */ public function activate() { - + // Setup all custom URL rules $this->register_post_type(); $this->add_feed(); $this->setup_permastruct(); - + $this->setup_directories(); + // Flush permalinks flush_rewrite_rules( true ); } - + /** * Flush rewrite rules on plugin deacivation * @return void @@ -1070,41 +1071,45 @@ public function activate() { public function deactivate() { flush_rewrite_rules(); } - + /** * Run functions on plugin update/activation * @return void */ public function update() { - + $previous_version = get_option( 'ssp_version', '1.0' ); - + if ( version_compare( $previous_version, '1.13.1', '<' ) ) { flush_rewrite_rules(); } - + + if ( version_compare( $previous_version, '1.16.3', '<' ) ) { + $this->setup_directories(); + } + update_option( 'ssp_version', $this->version ); - + } - + /** * Update 'enclosure' meta field to 'audio_file' meta field * @return void */ public function update_enclosures() { - + // Allow forced re-run of update if necessary if ( isset( $_GET['ssp_update_enclosures'] ) ) { delete_option( 'ssp_update_enclosures' ); } - + // Check if update has been run $update_run = get_option( 'ssp_update_enclosures', false ); - + if ( $update_run ) { return; } - + // Get IDs of all posts with enclosures $args = array( 'post_type' => 'any', @@ -1119,30 +1124,30 @@ public function update_enclosures() { ), 'fields' => 'ids', ); - + $posts_with_enclosures = get_posts( $args ); - + if ( 0 == count( $posts_with_enclosures ) ) { return; } - + // Add `audio_file` meta field to all posts with enclosures foreach ( (array) $posts_with_enclosures as $post_id ) { - + // Get existing enclosure $enclosure = get_post_meta( $post_id, 'enclosure', true ); - + // Add audio_file field if ( $enclosure ) { update_post_meta( $post_id, 'audio_file', $enclosure ); } - + } - + // Mark update as having been run update_option( 'ssp_update_enclosures', 'run' ); } - + /** * Add rating link to admin footer on SSP settings pages * @@ -1151,10 +1156,10 @@ public function update_enclosures() { * @return string Modified footer text */ public function admin_footer_text( $footer_text ) { - + // Check to make sure we're on a SSP settings page if ( ( isset( $_GET['page'] ) && 'podcast_settings' == esc_attr( $_GET['page'] ) ) && apply_filters( 'ssp_display_admin_footer_text', true ) ) { - + // Change the footer text if ( ! get_option( 'ssp_admin_footer_text_rated' ) ) { $footer_text = sprintf( __( 'If you like %1$sSeriously Simple Podcasting%2$s please leave a %3$s★★★★★%4$s rating. A huge thank you in advance!', 'seriously-simple-podcasting' ), '', '', '', '' ); @@ -1167,12 +1172,12 @@ public function admin_footer_text( $footer_text ) { } else { $footer_text = sprintf( __( '%1$sThank you for publishing with %2$sSeriously Simple Podcasting%3$s.%4$s', 'seriously-simple-podcasting' ), '', '', '', '' ); } - + } - + return $footer_text; } - + /** * Indicate that plugin has been rated * @return void @@ -1181,7 +1186,7 @@ public function rated() { update_option( 'ssp_admin_footer_text_rated', 1 ); die(); } - + /** * Clear the cache on post save. * @@ -1191,14 +1196,14 @@ public function rated() { * @return void */ public function invalidate_cache( $id, $post ) { - + if ( in_array( $post->post_type, ssp_post_types( true ) ) ) { wp_cache_delete( 'episodes', 'ssp' ); wp_cache_delete( 'episode_ids', 'ssp' ); } - + } - + /** * Send the podcast details to Seriously Simple Hosting * @@ -1206,68 +1211,68 @@ public function invalidate_cache( $id, $post ) { * @param $post */ public function update_podcast_details( $id, $post ) { - + /** * Only trigger this when the post type is podcast */ if ( ! in_array( $post->post_type, ssp_post_types( true ) ) ) { return; } - + /** * Only trigger this if the post is actually saved */ if ( isset( $post->post_status ) && 'auto-draft' == $post->post_status ) { return; } - + /** * Don't trigger this when the post is trashed */ if ( 'trash' == $post->post_status ) { return; } - + /** * Don't trigger this if we're not connected to Podcast Motor */ if ( ! ssp_is_connected_to_podcastmotor() ) { return; } - + $podmotor_handler = new Podmotor_Handler(); - + $response = $podmotor_handler->upload_podcast_to_podmotor( $post ); - + if ( 'success' == $response['status'] ) { $podmotor_episode_id = $response['episode_id']; if ( $podmotor_episode_id ) { update_post_meta( $post->ID, 'podmotor_episode_id', $podmotor_episode_id ); } } - + } - + /** * Upload file to PodcastMotor */ public function upload_file_to_podmotor() { - + $file_type = $_FILES["file"]["type"]; $file_type_array = explode( '/', $file_type ); - + if ( 'audio' == $file_type_array[0] || 'video' == $file_type_array[0] ) { - + $file_name = $_FILES["file"]["name"]; $uploaded_file = SSP_UPLOADS_DIR . $file_name; $tmp_name = $_FILES["file"]["tmp_name"]; - + $file_uploaded_locally = move_uploaded_file( $tmp_name, $uploaded_file ); - + if ( $file_uploaded_locally ) { - + $response = array( 'file_upload' => 'true' ); - + try { $podmotor_handler = new Podmotor_Handler(); $podmotor_response = $podmotor_handler->upload_file_to_podmotor_storage( $uploaded_file ); @@ -1276,10 +1281,10 @@ public function upload_file_to_podmotor() { $response['message'] = 'An unknown error occurred: ' . $e->getMessage(); wp_send_json( $response ); } - + if ( 'success' == $podmotor_response['status'] ) { - $duration = $podmotor_response['podmotor_file_duration']; - $response = $podmotor_handler->upload_podmotor_storage_file_data_to_podmotor( $podmotor_response['podmotor_file'] ); + $duration = $podmotor_response['podmotor_file_duration']; + $response = $podmotor_handler->upload_podmotor_storage_file_data_to_podmotor( $podmotor_response['podmotor_file'] ); $response['duration'] = $duration; wp_send_json( $response ); } else { @@ -1296,15 +1301,15 @@ public function upload_file_to_podmotor() { 'uploaded_file' => $uploaded_file, ) ); } - + } else { $response['status'] = 'error'; $response['message'] = 'Please upload a valid audio or video file.'; wp_send_json( $response ); } - + } - + /** * Check if there are existing podcasts to be uploaded to Seriously Simple Hosting */ @@ -1338,7 +1343,7 @@ public function check_existing_podcasts() { add_action( 'admin_notices', array( $this, 'existing_podcasts_notice' ) ); } } - + /** * Setup podcast import */ @@ -1354,7 +1359,7 @@ public function start_importing_existing_podcasts() { add_action( 'admin_notices', array( $this, 'importing_podcasts_notice' ) ); } } - + /** * Ignore podcast import */ @@ -1363,7 +1368,7 @@ public function ignore_importing_existing_podcasts() { update_option( 'ss_podcasting_podmotor_import_podcasts', 'false' ); } } - + /** * Show 'existing podcast' notice */ @@ -1371,9 +1376,9 @@ public function existing_podcasts_notice() { $podcast_import_url = add_query_arg( array( 'podcast_import_action' => 'start' ) ); $ignore_message_url = add_query_arg( array( 'podcast_import_action' => 'ignore' ) ); $message = ''; - $message .= '

You\'ve connected to your Seriously Simple Hosting account and you have existing podcasts that can be imported.

'; - $message .= '

You can import your existing podcasts to Seriously Simple Hosting.

'; - $message .= '

Alternatively you can dismiss this message.

'; + $message .= '

You\'ve connected to your Seriously Simple Hosting account and you have existing podcasts that can be imported.

'; + $message .= '

You can import your existing podcasts to Seriously Simple Hosting.

'; + $message .= '

Alternatively you can dismiss this message.

'; ?>
@@ -1381,7 +1386,7 @@ public function existing_podcasts_notice() {
'podcast', 'page' => 'upgrade', 'ssp_redirect' => $current_url ), admin_url( 'edit.php' ) ); + $url = add_query_arg( array( 'post_type' => 'podcast', + 'page' => 'upgrade', + 'ssp_redirect' => $current_url + ), admin_url( 'edit.php' ) ); wp_redirect( $url ); exit; } @@ -1459,7 +1467,7 @@ public function show_upgrade_screen() { /** * Dismiss upgrade screen when user clicks 'Dismiss' link */ - public function dismiss_upgrade_screen(){ + public function dismiss_upgrade_screen() { // Check if the ssp_dismiss_upgrade variable exists $ssp_dismiss_upgrade = ( isset( $_GET['ssp_dismiss_upgrade'] ) ? filter_var( $_GET['ssp_dismiss_upgrade'], FILTER_SANITIZE_STRING ) : '' ); if ( empty( $ssp_dismiss_upgrade ) ) { From 67f1b42f1317f7c08299413bdabd76b4354c1baf Mon Sep 17 00:00:00 2001 From: Jonathan Bossenger Date: Mon, 29 May 2017 14:20:57 +0200 Subject: [PATCH 02/10] Fixing an error with the api decryption on older versions of PHP --- assets/js/fileupload.js | 2 +- includes/class-podmotor-handler.php | 15 ++++++++------- includes/class-ssp-admin.php | 7 +++++++ readme.txt | 6 ++++++ seriously-simple-podcasting.php | 6 +++--- 5 files changed, 25 insertions(+), 11 deletions(-) diff --git a/assets/js/fileupload.js b/assets/js/fileupload.js index 5edfea8c..80c6c44a 100644 --- a/assets/js/fileupload.js +++ b/assets/js/fileupload.js @@ -41,7 +41,7 @@ jQuery(document).ready(function($) { $('#upload_audio_file').siblings('span.description').html('Your media file has been successfully uploaded.'); $('.peek-a-bar').fadeOut(5000); }else { - var notification_message = 'An error occurred, please try again.' + close_anchor; + var notification_message = 'An error occurred, please try again. ' + close_anchor; if ( result.message !== ''){ notification_message = result.message + close_anchor; } diff --git a/includes/class-podmotor-handler.php b/includes/class-podmotor-handler.php index 6f02c356..7c2cf24d 100644 --- a/includes/class-podmotor-handler.php +++ b/includes/class-podmotor-handler.php @@ -41,6 +41,7 @@ private function init_podmotor_client() { $this->podmotor_bucket = $response['bucket']; $this->podmotor_show_slug = $response['show_slug']; $this->podmotor_client = S3Client::factory( $this->podmotor_config ); + } /** @@ -185,10 +186,8 @@ public function upload_file_from_external_source( $remote_file = '' ) { if ( empty( $remote_file ) ) { $this->update_response( 'message', 'The remote file url is empty' ); } - ssp_debug( 'Download remote file ' . $remote_file ); $downloaded_file = ssp_download_remote_file( $remote_file ); if ( $downloaded_file ) { - ssp_debug( 'Uploading downloaded file to S3 ' . $downloaded_file ); $podmotor_response = $this->upload_file_to_podmotor_storage( $downloaded_file ); if ( 'success' === $podmotor_response['status'] ) { $this->update_response( 'status', 'success' ); @@ -197,7 +196,6 @@ public function upload_file_from_external_source( $remote_file = '' ) { } else { $this->update_response( 'message', 'An error occurred uploading the file to Seriously Simple Hosting' ); } - ssp_debug( 'Clearing local download file ' . $downloaded_file ); @unlink( $downloaded_file ); } else { $this->update_response( 'message', 'An error occurred downloading the remote file' ); @@ -222,13 +220,13 @@ public function upload_file_to_podmotor_storage( $file, $podcast_id = 0 ) { $file_info = pathinfo( $file ); $base_file_name = $file_info['basename']; try { - $result = $this->podmotor_client->putObject( [ + $result = $this->podmotor_client->putObject( array( 'Bucket' => $this->podmotor_bucket, 'Key' => $this->podmotor_show_slug . '/' . sanitize_file_name( $base_file_name ), 'Body' => fopen( $file, 'r' ), 'ACL' => 'public-read', 'StorageClass' => 'REDUCED_REDUNDANCY', - ] ); + ) ); $podmotor_uploaded_file = $result['ObjectURL']; if ( ! empty( $podmotor_uploaded_file ) ) { $this->update_response( 'status', 'success' ); @@ -290,7 +288,6 @@ public function upload_podmotor_storage_file_data_to_podmotor( $podmotor_file_pa $this->update_response( 'file_id', $responseObject->file_id ); $this->update_response( 'file_path', $responseObject->file_path ); } else { - ssp_debug( $responseObject ); $this->update_response( 'message', 'An error occurred uploading the file data to Seriously Simple Hosting' ); } } else { @@ -445,7 +442,11 @@ public function podmotor_decrypt_config( $encrypted_string, $unique_key ) { list( $original_string, $encrypted_string, $encoding_iv ) = $regs; $encoding_method = 'AES-128-CTR'; $encoding_key = crypt( $unique_key, sha1( $unique_key ) ); - $decrypted_token = openssl_decrypt( $encrypted_string, $encoding_method, $encoding_key, 0, hex2bin( $encoding_iv ) ); + if ( version_compare( PHP_VERSION, '5.4.0', '<' ) ) { + $decrypted_token = openssl_decrypt( $encrypted_string, $encoding_method, $encoding_key, 0, pack( 'H*', $encoding_iv ) ); + } else { + $decrypted_token = openssl_decrypt( $encrypted_string, $encoding_method, $encoding_key, 0, hex2bin( $encoding_iv ) ); + } $config = unserialize( $decrypted_token ); return $config; } else { diff --git a/includes/class-ssp-admin.php b/includes/class-ssp-admin.php index 259333f3..9bb35ae2 100644 --- a/includes/class-ssp-admin.php +++ b/includes/class-ssp-admin.php @@ -1258,6 +1258,13 @@ public function update_podcast_details( $id, $post ) { */ public function upload_file_to_podmotor() { + if ( ! is_dir( SSP_UPLOADS_DIR ) ) { + wp_send_json( array( + 'status' => 'error', + 'message' => 'An error occurred uploading your file, please contact hello@seriouslysimplepodcasting.com for assistance.', + ) ); + } + $file_type = $_FILES["file"]["type"]; $file_type_array = explode( '/', $file_type ); diff --git a/readme.txt b/readme.txt index 1a93dbe6..a9163f46 100644 --- a/readme.txt +++ b/readme.txt @@ -86,6 +86,12 @@ You can find complete user and developer documentation (along with the FAQs) on == Changelog == += 1.16.3 = +* 2017-05-29 +* UPDATE SUMMARY: Bugfix release for older versions of PHP 5.3.3 +* [FIX] Fixed a parse error causing the plugin not to be activated +* [FIX] Fixed an error with the plugin upgrade process + = 1.16.2 = * 2017-05-22 * UPDATE SUMMARY: Adding backwards compatibility to PHP 5.3.3 and improving Feed Details functionality when Series are being used. diff --git a/seriously-simple-podcasting.php b/seriously-simple-podcasting.php index c340d673..4a0acf04 100644 --- a/seriously-simple-podcasting.php +++ b/seriously-simple-podcasting.php @@ -1,7 +1,7 @@ Date: Mon, 29 May 2017 14:54:04 +0200 Subject: [PATCH 03/10] Turning debug off --- readme.txt | 2 +- seriously-simple-podcasting.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/readme.txt b/readme.txt index a9163f46..0f25f4c7 100644 --- a/readme.txt +++ b/readme.txt @@ -88,7 +88,7 @@ You can find complete user and developer documentation (along with the FAQs) on = 1.16.3 = * 2017-05-29 -* UPDATE SUMMARY: Bugfix release for older versions of PHP 5.3.3 +* UPDATE SUMMARY: Bugfix release for backward compatibility * [FIX] Fixed a parse error causing the plugin not to be activated * [FIX] Fixed an error with the plugin upgrade process diff --git a/seriously-simple-podcasting.php b/seriously-simple-podcasting.php index 4a0acf04..de195318 100644 --- a/seriously-simple-podcasting.php +++ b/seriously-simple-podcasting.php @@ -38,7 +38,7 @@ return; } -define( 'SSP_DEBUG', true ); +define( 'SSP_DEBUG', false ); define( 'SSP_VERSION', '1.16.3' ); define( 'SSP_PLUGIN_URL', plugin_dir_url( __FILE__ ) ); From 9a12af096d5d79cab07e5ba542e66183427bf11f Mon Sep 17 00:00:00 2001 From: Jonathan Bossenger Date: Mon, 29 May 2017 15:21:33 +0200 Subject: [PATCH 04/10] Updating minified resource --- assets/js/fileupload.min.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets/js/fileupload.min.js b/assets/js/fileupload.min.js index 13fa16f5..b4bb9776 100644 --- a/assets/js/fileupload.min.js +++ b/assets/js/fileupload.min.js @@ -1 +1 @@ -jQuery(document).ready(function(a){function b(d){a(".peek-a-bar").hide().remove();var c=new a.peekABar({padding:"1em",animation:{type:"fade",duration:1000},cssClass:"ssp-notification-bar",backgroundColor:"#4aa3df"});c.show({html:d})}a("#fileupload").fileupload({url:ajaxurl,formData:{action:"ssp_upload_to_podmotor"},dataType:"json",start:function(){b("Uploading file to Seriously Simple Hosting. You can continue editing this post while the file uploads.")},done:function(h,g){var d=g.result;var f=" x";if(d.status==="success"){b("Uploading file to Seriously Simple Hosting Complete."+f);a("#upload_audio_file").val(d.file_path);a("#podmotor_file_id").val(d.file_id);a("#duration").val(d.duration);a("#upload_audio_file").siblings("span.description").html("Your media file has been successfully uploaded.");a(".peek-a-bar").fadeOut(5000)}else{var c="An error occurred, please try again."+f;if(d.message!==""){c=d.message+f}b(c)}}});a("body").on("click","a.close-ssp-notification",function(){a(".peek-a-bar").hide().remove()})}); \ No newline at end of file +jQuery(document).ready(function(a){function b(d){a(".peek-a-bar").hide().remove();var c=new a.peekABar({padding:"1em",animation:{type:"fade",duration:1000},cssClass:"ssp-notification-bar",backgroundColor:"#4aa3df"});c.show({html:d})}a("#fileupload").fileupload({url:ajaxurl,formData:{action:"ssp_upload_to_podmotor"},dataType:"json",start:function(){b("Uploading file to Seriously Simple Hosting. You can continue editing this post while the file uploads.")},done:function(h,g){var d=g.result;var f=" x";if(d.status==="success"){b("Uploading file to Seriously Simple Hosting Complete."+f);a("#upload_audio_file").val(d.file_path);a("#podmotor_file_id").val(d.file_id);a("#duration").val(d.duration);a("#upload_audio_file").siblings("span.description").html("Your media file has been successfully uploaded.");a(".peek-a-bar").fadeOut(5000)}else{var c="An error occurred, please try again. "+f;if(d.message!==""){c=d.message+f}b(c)}}});a("body").on("click","a.close-ssp-notification",function(){a(".peek-a-bar").hide().remove()})}); \ No newline at end of file From b247db3e8d722035e298f1762b296fdc43c9b0d4 Mon Sep 17 00:00:00 2001 From: Jonathan Bossenger Date: Wed, 14 Jun 2017 15:45:53 +0200 Subject: [PATCH 05/10] Reverting get_episode_download_link method Fixed a bug in the Import Podcast form (PHP 5.3 bug) --- includes/class-ssp-frontend.php | 24 ++++++++++-------------- includes/class-ssp-settings.php | 8 ++++---- seriously-simple-podcasting.php | 4 ++-- 3 files changed, 16 insertions(+), 20 deletions(-) diff --git a/includes/class-ssp-frontend.php b/includes/class-ssp-frontend.php index 5a8a11a8..cade9e0b 100644 --- a/includes/class-ssp-frontend.php +++ b/includes/class-ssp-frontend.php @@ -103,21 +103,17 @@ public function get_episode_download_link( $episode_id, $referrer = '' ) { return; } - if ( ssp_is_connected_to_podcastmotor() ) { - $link = $file; - } else { - // Get download link based on permalink structure - if ( get_option( 'permalink_structure' ) ) { - $episode = get_post( $episode_id ); - // Get file extension - default to MP3 to prevent empty extension strings - $ext = pathinfo( $file, PATHINFO_EXTENSION ); - if ( ! $ext ) { - $ext = 'mp3'; - } - $link = $this->home_url . 'podcast-download/' . $episode_id . '/' . $episode->post_name . '.' . $ext; - } else { - $link = add_query_arg( array( 'podcast_episode' => $episode_id ), $this->home_url ); + // Get download link based on permalink structure + if ( get_option( 'permalink_structure' ) ) { + $episode = get_post( $episode_id ); + // Get file extension - default to MP3 to prevent empty extension strings + $ext = pathinfo( $file, PATHINFO_EXTENSION ); + if ( ! $ext ) { + $ext = 'mp3'; } + $link = $this->home_url . 'podcast-download/' . $episode_id . '/' . $episode->post_name . '.' . $ext; + } else { + $link = add_query_arg( array( 'podcast_episode' => $episode_id ), $this->home_url ); } // Allow for dyamic referrer diff --git a/includes/class-ssp-settings.php b/includes/class-ssp-settings.php index e5ce3a53..42b51603 100644 --- a/includes/class-ssp-settings.php +++ b/includes/class-ssp-settings.php @@ -1662,10 +1662,10 @@ public function submit_import_form() { if ( ! empty( $action ) && 'post_import_form' === $action ) { check_admin_referer( 'ss_podcasting-import' ); - $name = filter_input( $_POST['name'], FILTER_SANITIZE_STRING ); - $website = filter_input( $_POST['website'], FILTER_SANITIZE_STRING ); - $email = filter_input( $_POST['email'], FILTER_SANITIZE_EMAIL ); - $podcast_url = filter_input( $_POST['podcast_url'], FILTER_SANITIZE_URL ); + $name = filter_var( $_POST['name'], FILTER_SANITIZE_STRING ); + $website = filter_var( $_POST['website'], FILTER_SANITIZE_STRING ); + $email = filter_var( $_POST['email'], FILTER_SANITIZE_EMAIL ); + $podcast_url = filter_var( $_POST['podcast_url'], FILTER_SANITIZE_URL ); $new_line = "\n"; $site_name = $name; diff --git a/seriously-simple-podcasting.php b/seriously-simple-podcasting.php index de195318..77934ddf 100644 --- a/seriously-simple-podcasting.php +++ b/seriously-simple-podcasting.php @@ -1,7 +1,7 @@ Date: Wed, 14 Jun 2017 15:56:33 +0200 Subject: [PATCH 06/10] Open Seriously Simple Hosting extension url in a new window --- includes/class-ssp-settings.php | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/includes/class-ssp-settings.php b/includes/class-ssp-settings.php index 42b51603..f873d550 100644 --- a/includes/class-ssp-settings.php +++ b/includes/class-ssp-settings.php @@ -1698,8 +1698,9 @@ public function render_seriously_simple_extensions() { 'connect' => array( 'title' => 'NEW - ***Premium*** Seriously Simple Hosting', 'image' => $image_dir . 'ssp-PM-connect.jpg', - 'url' => SSP_PODMOTOR_APP_URL . '?TB_iframe=true&width=772&height=859', + 'url' => SSP_PODMOTOR_APP_URL, 'description' => 'Host your podcast media files safely and securely in a CDN-powered cloud platform designed specifically to connect beautifully with Seriously Simple Podcasting. Faster downloads, better live streaming, and take back security for your web server with Seriously Simple Hosting.', + 'new_window' => true, ), 'stats' => array( 'title' => 'Seriously Simple Podcasting Stats', @@ -1729,13 +1730,21 @@ public function render_seriously_simple_extensions() { $html = '
'; foreach ( $extensions as $extension ) { - $html .= '

' . $extension['title'] . '

- -

-

' . $extension['description'] . '

-

- Get this Extension -
'; + $html .= '

' . $extension['title'] . '

'; + if (isset($extension['new_window']) && $extension['new_window']){ + $html .= ''; + }else { + $html .= ''; + } + $html .= '

'; + $html .= '

' . $extension['description'] . '

'; + $html .= '

'; + if (isset($extension['new_window']) && $extension['new_window']){ + $html .= 'Get this Extension'; + }else { + $html .= 'Get this Extension'; + } + $html .= '
'; } $html .= '
'; From bd674d56b1b0d26773f78a2676e9b74968378804 Mon Sep 17 00:00:00 2001 From: Jonathan Bossenger Date: Wed, 14 Jun 2017 21:12:13 +0200 Subject: [PATCH 07/10] Adding check for correct folder permissions Fixed a bug where the temporary file was not being deleted --- includes/class-podmotor-handler.php | 4 ++- includes/class-ssp-admin.php | 17 ++++------- includes/class-ssp-settings.php | 11 ++++--- includes/ssp-functions.php | 47 ++++++++++++++++++++++++++++- seriously-simple-podcasting.php | 2 -- 5 files changed, 61 insertions(+), 20 deletions(-) diff --git a/includes/class-podmotor-handler.php b/includes/class-podmotor-handler.php index 7c2cf24d..92d74274 100644 --- a/includes/class-podmotor-handler.php +++ b/includes/class-podmotor-handler.php @@ -241,6 +241,7 @@ public function upload_file_to_podmotor_storage( $file, $podcast_id = 0 ) { update_post_meta( $podcast_id, 'duration', $duration ); } } + $this->clear_local_podmotor_file( $file ); } else { $this->update_response( 'message', 'An error occured uploading the file to Seriously Simple Hosting' ); } @@ -307,7 +308,8 @@ public function upload_podmotor_storage_file_data_to_podmotor( $podmotor_file_pa */ public function clear_local_podmotor_file( $podmotor_file_path = '' ) { $file_info = pathinfo( $podmotor_file_path ); - $file_to_be_deleted = SSP_UPLOADS_DIR . $file_info['basename']; + $file_to_be_deleted = ssp_get_upload_directory() . $file_info['basename']; + ssp_debug( $file_to_be_deleted ); if ( is_file( $file_to_be_deleted ) ) { unlink( $file_to_be_deleted ); } diff --git a/includes/class-ssp-admin.php b/includes/class-ssp-admin.php index 9bb35ae2..fffe2dee 100644 --- a/includes/class-ssp-admin.php +++ b/includes/class-ssp-admin.php @@ -143,9 +143,7 @@ public function __construct( $file, $version ) { * Setup the PodcastMotor Uploads directory */ public function setup_directories() { - if ( ! is_dir( SSP_UPLOADS_DIR ) ) { - wp_mkdir_p( SSP_UPLOADS_DIR ); - } + $ssp_upload_dir = ssp_get_upload_directory(); } /** @@ -1058,8 +1056,6 @@ public function activate() { $this->add_feed(); $this->setup_permastruct(); - $this->setup_directories(); - // Flush permalinks flush_rewrite_rules( true ); } @@ -1084,9 +1080,7 @@ public function update() { flush_rewrite_rules(); } - if ( version_compare( $previous_version, '1.16.3', '<' ) ) { - $this->setup_directories(); - } + ssp_get_upload_directory(); update_option( 'ssp_version', $this->version ); @@ -1258,7 +1252,9 @@ public function update_podcast_details( $id, $post ) { */ public function upload_file_to_podmotor() { - if ( ! is_dir( SSP_UPLOADS_DIR ) ) { + $ssp_uploads_dir = ssp_get_upload_directory(); + + if ( ! is_dir( $ssp_uploads_dir ) ) { wp_send_json( array( 'status' => 'error', 'message' => 'An error occurred uploading your file, please contact hello@seriouslysimplepodcasting.com for assistance.', @@ -1271,7 +1267,7 @@ public function upload_file_to_podmotor() { if ( 'audio' == $file_type_array[0] || 'video' == $file_type_array[0] ) { $file_name = $_FILES["file"]["name"]; - $uploaded_file = SSP_UPLOADS_DIR . $file_name; + $uploaded_file = ssp_get_upload_directory() . $file_name; $tmp_name = $_FILES["file"]["tmp_name"]; $file_uploaded_locally = move_uploaded_file( $tmp_name, $uploaded_file ); @@ -1288,7 +1284,6 @@ public function upload_file_to_podmotor() { $response['message'] = 'An unknown error occurred: ' . $e->getMessage(); wp_send_json( $response ); } - if ( 'success' == $podmotor_response['status'] ) { $duration = $podmotor_response['podmotor_file_duration']; $response = $podmotor_handler->upload_podmotor_storage_file_data_to_podmotor( $podmotor_response['podmotor_file'] ); diff --git a/includes/class-ssp-settings.php b/includes/class-ssp-settings.php index f873d550..56ee319f 100644 --- a/includes/class-ssp-settings.php +++ b/includes/class-ssp-settings.php @@ -158,21 +158,22 @@ public function add_menu_item() { ) ); // @todo remove this on launch - add_submenu_page( null, __( 'Development', 'seriously-simple-podcasting' ), __( 'Development', 'seriously-simple-podcasting' ), 'manage_podcast', 'reset', array( + add_submenu_page( 'edit.php?post_type=podcast', __( 'Development', 'seriously-simple-podcasting' ), __( 'Development', 'seriously-simple-podcasting' ), 'manage_podcast', 'reset', array( $this, - 'reset_development_settings', + 'development_settings', ) ); } // @todo remove this on launch /** - * Reset development settings + * Development settings */ - public function reset_development_settings() { + public function development_settings() { + echo '
'; echo '

Development settings

'; - + $dev_reset = ( isset( $_GET['dev_reset'] ) ? filter_var( $_GET['dev_reset'], FILTER_SANITIZE_STRING ) : '' ); if ( 'reset' === $dev_reset ) { diff --git a/includes/ssp-functions.php b/includes/ssp-functions.php index 17ff3089..d4d612b4 100644 --- a/includes/ssp-functions.php +++ b/includes/ssp-functions.php @@ -32,6 +32,51 @@ function ssp_debug_clear() { file_put_contents( $file, '' ); } +if ( ! function_exists( 'ssp_get_upload_directory' ) ) { + /** + * Gets the temporary Seriously Simple Podcasting upload directory + * Typically ../wp-content/uploads/ssp + * If it does not already exist, attempts to create it + * + * @return bool|string + */ + function ssp_get_upload_directory() { + $time = current_time( 'mysql' ); + if ( ! ( ( $uploads = wp_upload_dir( $time ) ) && false === $uploads['error'] ) ) { + add_action( 'admin_notices', 'ssp_cannot_write_uploads_dir_error' ); + } else { + $ssp_upload_dir = trailingslashit( $uploads['basedir'] ) . trailingslashit( 'ssp' ); + $ssp_upload_dir_exists = true; + if ( ! is_dir( $ssp_upload_dir ) ) { + $ssp_upload_dir_exists = wp_mkdir_p( $ssp_upload_dir ); + } + if ( ! $ssp_upload_dir_exists ) { + return false; + } + return $ssp_upload_dir; + } + } +} + +if ( ! function_exists( 'ssp_cannot_write_uploads_dir_error' ) ) { + function ssp_cannot_write_uploads_dir_error() { + $time = current_time( 'mysql' ); + $uploads = wp_upload_dir( $time ); + if ( 0 === strpos( $uploads['basedir'], ABSPATH ) ) { + $error_path = str_replace( ABSPATH, '', $uploads['basedir'] ); + } else { + $error_path = basename( $uploads['basedir'] ); + } + $class = 'notice notice-error'; + $message = sprintf( + /* translators: %s: Error path */ + __( 'Unable to create directory %s. Is its parent directory writable by the server?' ), + esc_html( $error_path ) + ); + printf( '

%2$s

', esc_attr( $class ), esc_html( $message ) ); + } +} + if ( ! function_exists( 'is_podcast_download' ) ) { /** * Check if podcast file is being downloaded @@ -687,7 +732,7 @@ function ssp_download_remote_file( $remote_file = '', $extension_override = '' ) $response = false; if ( ! empty( $remote_file ) ) { $remote_file_info = pathinfo( $remote_file ); - $file_path = SSP_UPLOADS_DIR . $remote_file_info['basename']; + $file_path = ssp_get_upload_directory() . $remote_file_info['basename']; if ( ! empty( $extension_override ) ) { $file_path = $file_path . '.' . $extension_override; } diff --git a/seriously-simple-podcasting.php b/seriously-simple-podcasting.php index 77934ddf..d6fc6636 100644 --- a/seriously-simple-podcasting.php +++ b/seriously-simple-podcasting.php @@ -44,8 +44,6 @@ define( 'SSP_PLUGIN_URL', plugin_dir_url( __FILE__ ) ); define( 'SSP_PLUGIN_PATH', plugin_dir_path( __FILE__ ) ); -define( 'SSP_UPLOADS_DIR', ABSPATH . 'wp-content/ssp/' ); - define( 'SSP_LOG_PATH', SSP_PLUGIN_PATH . 'log/ssp.log.' . date( 'd-m-y' ) . '.txt' ); define( 'SSP_LOG_URL', SSP_PLUGIN_URL . 'log/ssp.log.' . date( 'd-m-y' ) . '.txt' ); From b96140f0a1b32695a86e428a93e680fb72c8a42e Mon Sep 17 00:00:00 2001 From: Jonathan Bossenger Date: Wed, 14 Jun 2017 21:21:16 +0200 Subject: [PATCH 08/10] Removed development functions Some cleanup --- includes/class-ssp-admin.php | 10 ++---- includes/class-ssp-settings.php | 61 ++------------------------------- includes/ssp-functions.php | 21 +++++++----- seriously-simple-podcasting.php | 4 +-- 4 files changed, 18 insertions(+), 78 deletions(-) diff --git a/includes/class-ssp-admin.php b/includes/class-ssp-admin.php index fffe2dee..4140608c 100644 --- a/includes/class-ssp-admin.php +++ b/includes/class-ssp-admin.php @@ -139,13 +139,6 @@ public function __construct( $file, $version ) { } - /** - * Setup the PodcastMotor Uploads directory - */ - public function setup_directories() { - $ssp_upload_dir = ssp_get_upload_directory(); - } - /** * Setup custom permalink structures * @return void @@ -1080,7 +1073,8 @@ public function update() { flush_rewrite_rules(); } - ssp_get_upload_directory(); + // always just check if the directory is ok + ssp_get_upload_directory( false ); update_option( 'ssp_version', $this->version ); diff --git a/includes/class-ssp-settings.php b/includes/class-ssp-settings.php index 56ee319f..81bfe2a8 100644 --- a/includes/class-ssp-settings.php +++ b/includes/class-ssp-settings.php @@ -156,72 +156,15 @@ public function add_menu_item() { $this, 'show_upgrade_page', ) ); - - // @todo remove this on launch - add_submenu_page( 'edit.php?post_type=podcast', __( 'Development', 'seriously-simple-podcasting' ), __( 'Development', 'seriously-simple-podcasting' ), 'manage_podcast', 'reset', array( - $this, - 'development_settings', - ) ); - } - - // @todo remove this on launch + /** - * Development settings + * Show the upgrade page */ - public function development_settings() { - - echo '
'; - echo '

Development settings

'; - - $dev_reset = ( isset( $_GET['dev_reset'] ) ? filter_var( $_GET['dev_reset'], FILTER_SANITIZE_STRING ) : '' ); - - if ( 'reset' === $dev_reset ) { - global $wpdb; - $options = $wpdb->prefix . 'options'; - $postmeta = $wpdb->prefix . 'postmeta'; - // clear out podcast options. - $sql = "DELETE FROM `$postmeta` WHERE `meta_key` = 'podmotor_episode_id'"; - $wpdb->query( $sql ); - $wpdb->flush(); - // clear out episode meta. - $sql = "DELETE FROM `$options` WHERE `option_name` LIKE '%podmotor%'"; - $wpdb->query( $sql ); - $wpdb->flush(); - update_option( 'ssp_upgrade_page_visited', '' ); - echo '

Database settings reset.

'; - } - - $dev_email = ( isset( $_GET['dev_email'] ) ? filter_var( $_GET['dev_email'], FILTER_SANITIZE_STRING ) : '' ); - if ( 'email' === $dev_email ) { - $mailed = ssp_email_podcasts_imported(); - if ( $mailed ) { - echo '

Mail sent.

'; - } else { - echo '

Mail not sent.

'; - } - } - - $email_url = add_query_arg( 'dev_email', 'email' ); - echo '

Send email test

'; - - $reset_url = add_query_arg( 'dev_reset', 'reset' ); - echo '

Reset database settings

'; - - if ( is_file( SSP_LOG_PATH ) ) { - $log_url = SSP_LOG_URL; - echo '

Download current log file

'; - } - - echo '
'; - } - public function show_upgrade_page() { - //ob_start(); $ssp_redirect = ( isset( $_GET['ssp_redirect'] ) ? filter_var( $_GET['ssp_redirect'], FILTER_SANITIZE_STRING ) : '' ); $ssp_dismiss_url = add_query_arg( array( 'ssp_dismiss_upgrade' => 'dismiss', 'ssp_redirect' => rawurlencode( $ssp_redirect ) ), admin_url( 'index.php' ) ); include( $this->templates_dir . DIRECTORY_SEPARATOR . 'settings-upgrade-page.php' ); - //return ob_get_clean(); } /** diff --git a/includes/ssp-functions.php b/includes/ssp-functions.php index d4d612b4..c33768a9 100644 --- a/includes/ssp-functions.php +++ b/includes/ssp-functions.php @@ -38,27 +38,30 @@ function ssp_debug_clear() { * Typically ../wp-content/uploads/ssp * If it does not already exist, attempts to create it * + * @param bool $return Whether to return the path or not + * * @return bool|string */ - function ssp_get_upload_directory() { + function ssp_get_upload_directory( $return = true ) { $time = current_time( 'mysql' ); if ( ! ( ( $uploads = wp_upload_dir( $time ) ) && false === $uploads['error'] ) ) { add_action( 'admin_notices', 'ssp_cannot_write_uploads_dir_error' ); } else { - $ssp_upload_dir = trailingslashit( $uploads['basedir'] ) . trailingslashit( 'ssp' ); - $ssp_upload_dir_exists = true; - if ( ! is_dir( $ssp_upload_dir ) ) { - $ssp_upload_dir_exists = wp_mkdir_p( $ssp_upload_dir ); - } - if ( ! $ssp_upload_dir_exists ) { - return false; + if ( $return ) { + $ssp_upload_dir = trailingslashit( $uploads['basedir'] ) . trailingslashit( 'ssp' ); + if ( ! is_dir( $ssp_upload_dir ) ) { + wp_mkdir_p( $ssp_upload_dir ); + } + return $ssp_upload_dir; } - return $ssp_upload_dir; } } } if ( ! function_exists( 'ssp_cannot_write_uploads_dir_error' ) ) { + /** + * Displays an admin error of the wp-content folder permissions are incorrect + */ function ssp_cannot_write_uploads_dir_error() { $time = current_time( 'mysql' ); $uploads = wp_upload_dir( $time ); diff --git a/seriously-simple-podcasting.php b/seriously-simple-podcasting.php index d6fc6636..31d087be 100644 --- a/seriously-simple-podcasting.php +++ b/seriously-simple-podcasting.php @@ -1,7 +1,7 @@ Date: Wed, 21 Jun 2017 12:41:18 +0200 Subject: [PATCH 09/10] Version bump Getting ready to release --- readme.txt | 9 +++++++-- seriously-simple-podcasting.php | 8 ++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/readme.txt b/readme.txt index 0f25f4c7..a244d0d8 100644 --- a/readme.txt +++ b/readme.txt @@ -2,8 +2,8 @@ Contributors: hlashbrooke, whyisjake, psykro, PodcastMotor, simondowdles Tags: podcast, audio, video, vodcast, rss, mp3, mp4, feed, itunes, podcasting, media, stitcher, google play, playlist Requires at least: 4.4 -Tested up to: 4.7.3 -Stable tag: 1.16.2 +Tested up to: 4.8 +Stable tag: 1.16.4 License: GPLv2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html @@ -86,6 +86,11 @@ You can find complete user and developer documentation (along with the FAQs) on == Changelog == += 1.16.4 = +* 2017-06-21 +* [FIX] Fixed a bug causing issues with file uploads for [Seriously Simple Hosting](http://app.seriouslysimplepodcasting.com/) +* [FIX] Fixed a bug causing problems with tracking stats [Seriously Simple Stats](https://en-za.wordpress.org/plugins/seriously-simple-stats/) + = 1.16.3 = * 2017-05-29 * UPDATE SUMMARY: Bugfix release for backward compatibility diff --git a/seriously-simple-podcasting.php b/seriously-simple-podcasting.php index 31d087be..eda93a8e 100644 --- a/seriously-simple-podcasting.php +++ b/seriously-simple-podcasting.php @@ -1,14 +1,14 @@ Date: Wed, 21 Jun 2017 12:46:23 +0200 Subject: [PATCH 10/10] Changelog improvement --- readme.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.txt b/readme.txt index a244d0d8..302ae806 100644 --- a/readme.txt +++ b/readme.txt @@ -88,7 +88,7 @@ You can find complete user and developer documentation (along with the FAQs) on = 1.16.4 = * 2017-06-21 -* [FIX] Fixed a bug causing issues with file uploads for [Seriously Simple Hosting](http://app.seriouslysimplepodcasting.com/) +* [FIX] Improved file uploads for [Seriously Simple Hosting](http://app.seriouslysimplepodcasting.com/) * [FIX] Fixed a bug causing problems with tracking stats [Seriously Simple Stats](https://en-za.wordpress.org/plugins/seriously-simple-stats/) = 1.16.3 =