m_item_migrate_count; } function importCount() { return $this->m_item_inserted_count; } function skippedCount() { return $this->m_item_skipped_count; } function errorsExist() { return ( count($this->m_errors) > 0 ); } function getErrors() { return $this->m_errors; } function addError($msg) { $this->m_errors[] = $msg; } function header() { if (defined('WP_DEBUG')) { if (WP_DEBUG) { wp_enqueue_style('powerpress_onboarding_styles', plugin_dir_url(__FILE__) . 'css/onboarding.css', array(), POWERPRESS_VERSION); } else { wp_enqueue_style('powerpress_onboarding_styles', plugin_dir_url(__FILE__) . 'css/onboarding.min.css', array(), POWERPRESS_VERSION); } } else { wp_enqueue_style('powerpress_onboarding_styles', plugin_dir_url(__FILE__) . 'css/onboarding.min.css', array(), POWERPRESS_VERSION); } echo '
'; echo '
'; echo '

'.__('PowerPress', 'powerpress').'

'; } function greet() { $General = powerpress_get_settings('powerpress_general'); if (isset($_GET['from']) && ($_GET['from'] == 'gs' || $_GET['from'] == 'onboarding')) { $from_onboarding = true; } else { $from_onboarding = false; } if( !empty($_GET['import']) ) { switch($_GET['import'] ) { case 'powerpress-soundcloud-rss-podcast': echo '

'.__('Import Podcast from SoundCloud', 'powerpress').'

'; break; case 'powerpress-libsyn-rss-podcast': echo '

'.__('Import Podcast from LibSyn', 'powerpress').'

'; break; case 'powerpress-podbean-rss-podcast': echo '

'.__('Import Podcast from PodBean', 'powerpress').'

'; break; case 'powerpress-squarespace-rss-podcast': echo '

'.__('Import Podcast from Squarespace', 'powerpress').'

'; break; case 'powerpress-anchor-rss-podcast': echo '

'.__('Import Podcast from Anchor.fm', 'powerpress').'

'; break; case 'powerpress-rss-podcast': default: echo '

'.__('Import Podcast RSS Feed', 'powerpress').'

'; break; } } else { echo '

'.__('Podcast RSS Import', 'powerpress').'

'; } ?>

>



 
  ()

'; echo '

'.__('Import saved Feed', 'powerpress') .'

'; wp_import_upload_form("admin.php?import=rss-podcast&step=1"); echo '
'; } function _normalize_tag( $matches ) { return '<' . strtolower( $matches[1] ); } function import_program_info($channel, $overwrite=false, $download_itunes_image=false, $category_id = '', $feed_slug ='', $post_type = '', $ttid = '') { $Feed = get_option('powerpress_feed_podcast' ); if( empty($Feed) ) $Feed = get_option('powerpress_feed'); if( !empty($category_id) ) { $Feed = get_option('powerpress_cat_feed_'.$category_id); } else if( !empty($post_type) ) { // TODO } else if( !empty($feed_slug) ) { $Feed = get_option('powerpress_feed_'.$feed_slug); } else if( !empty($ttid) ) { $Feed = get_option('powerpress_taxonomy_'.$ttid); } if( empty($Feed) ) // Fix the situation where the empty value is not an array so we do not have notice messages $Feed = array(); $NewSettings = array(); $matches = array(); $program_title = false; if( preg_match('|(.*?)|is', $channel, $matches) ) { $program_title = $this->_sanatize_tag_value( $matches[1] ); if( $overwrite || empty($Feed['title']) ) $NewSettings['title'] = $program_title; } // language $language = false; if( preg_match('|(.*?)|is', $channel, $matches) ) { $language = $this->_sanatize_tag_value( $matches[1] ); if( $overwrite || empty($Feed['rss_language']) ) $NewSettings['rss_language'] = $language; } // copyright $copyright = false; if( preg_match('|(.*?)|is', $channel, $matches) ) { $copyright = $this->_sanatize_tag_value( $matches[1] ); if( $overwrite || empty($Feed['copyright']) ) $NewSettings['copyright'] = $copyright; } // description $description = false; if( preg_match('|(.*?)|is', $channel, $matches) ) { $description = $this->_sanatize_tag_value( $matches[1] ); if( $overwrite || empty($Feed['description']) ) $NewSettings['description'] = $description; } // itunes:subtitle $itunes_subtitle = false; if( preg_match('|(.*?)|is', $channel, $matches) ) { $itunes_subtitle = $this->_sanatize_tag_value( $matches[1] ); if( $overwrite || empty($Feed['itunes_subtitle']) ) $NewSettings['itunes_subtitle'] = $itunes_subtitle; } // itunes:summary $itunes_summary = false; if( preg_match('|(.*?)|is', $channel, $matches) ) { $itunes_summary = $this->_sanatize_tag_value( $matches[1] ); if( $overwrite || empty($Feed['itunes_summary']) ) $NewSettings['itunes_summary'] = $itunes_summary; } // itunes:email $itunes_email = false; if( preg_match('|(.*?)|is', $channel, $matches) ) { $itunes_email = $this->_sanatize_tag_value( $matches[1] ); if( $overwrite || empty($Feed['email']) ) $NewSettings['email'] = $itunes_email; } // itunes:author $itunes_talent_name = false; if( preg_match('|(.*?)|is', $channel, $matches) ) { $itunes_talent_name = $this->_sanatize_tag_value( $matches[1] ); if( $overwrite || empty($Feed['itunes_talent_name']) ) $NewSettings['itunes_talent_name'] = $itunes_talent_name; } // itunes:explicit if( preg_match('|(.*?)|is', $channel, $explicit) ) { $explicit_array = array('yes'=>1, 'clean'=>2); // No need to save 'no' $value = strtolower( trim( $explicit[1] ) ); if( !empty($explicit_array[ $value ]) ) { if( $overwrite || empty($Feed['itunes_explicit']) ) { $NewSettings['itunes_explicit'] = $explicit_array[ $value ]; } } } // itunes:image $itunes_image = ''; if( preg_match('/|>.*<\/itunes:image>)/i', $channel, $image) ) { $itunes_image = html_entity_decode( trim( $image[1] ) ); // Now we need to download and save the image locally... // download the image then save it locally... if( $download_itunes_image ) { echo '
'; echo '

'. __('Program iTunes image', 'powerpress') .'

'; echo ''; } else if( $overwrite || empty($Feed['itunes_image']) ) { $NewSettings['itunes_image'] = $itunes_image; $NewSettings['rss2_image'] = $itunes_image; } } if( preg_match('|(.*?)|is', $channel, $matches) ) { $itunes_talent_name = $this->_sanatize_tag_value( $matches[1] ); if( $overwrite || empty($Feed['itunes_talent_name']) ) $NewSettings['itunes_talent_name'] = $itunes_talent_name; } // itunes:category (up to 3) $itunes_categories = false; if( preg_match_all('| $category ) { $category = str_replace('&', '&', $category); $category = strtolower($category); if( !empty($cats_by_title[ $category ] ) ) $FoundCategories[] = $cats_by_title[ $category ]; } // Now walk trouigh found categories and stack them correctly... // this logic rebuilds the categorires in the correct order no matter what method the service stacked them $FinalCats = array(1=>'', 2=>'', 3=>''); $last_category_index = 1; foreach( $FoundCategories as $index => $cat_id ) { if( !empty($FinalCats[$last_category_index]) ) // Do we need to increment to the next category position { if( intval(substr($FinalCats[$last_category_index], 3)) > 0 ) { $last_category_index++; } else if( intval(substr($FinalCats[$last_category_index],0, 2)) != intval(substr($cat_id,0, 2)) ) { $last_category_index++; } // else we can overwrite this category with subcategory } if( $last_category_index > 3 ) break; // We are at the max cats available... $FinalCats[ $last_category_index ] = $cat_id; } foreach( $FinalCats as $field_no => $cat_id ) { if( empty( $cat_id) ) continue; $field = sprintf('apple_cat_%d', $field_no); if( $overwrite || empty($Feed[ $field ]) ) { $NewSettings[ $field ] = $cat_id; } } } if( !empty($NewSettings) ) { if( empty($category_id) && empty($feed_slug) && empty($post_type) && empty($ttid) ) { // Save here.. if( get_option('powerpress_feed_podcast') ) { // If the settings were moved to the podcast channels feature... powerpress_save_settings($NewSettings, 'powerpress_feed_podcast' ); // save a copy here if that is the case. } else { powerpress_save_settings($NewSettings, 'powerpress_feed' ); } } else if( !empty($category_id) ) { // First save the new settings into the specified options row... powerpress_save_settings($NewSettings, 'powerpress_cat_feed_'.$category_id ); // save a copy here if that is the case. // Then add the category id to the global array... $CurrentSettings = powerpress_get_settings('powerpress_general'); if( !in_array($category_id, $CurrentSettings['custom_cat_feeds']) ) { $NewSettings = array(); if( !empty($CurrentSettings['custom_cat_feeds']) ) $NewSettings['custom_cat_feeds'] = $CurrentSettings['custom_cat_feeds']; $NewSettings['custom_cat_feeds'][] = $category_id; if( empty($CurrentSettings['cat_casting']) ) { $NewSettings['cat_casting'] = 1; // Turn on category podcasting if not enabled $NewSettings['cat_casting_podcast_feeds'] = 1; $NewSettings['cat_casting_strict'] = 1; } powerpress_save_settings($NewSettings); } } else if ( !empty($post_type) ) { // TODO } else if ( !empty($feed_slug) ) { powerpress_save_settings($NewSettings, 'powerpress_feed_'.$feed_slug ); } else if ( !empty($ttid) ) { powerpress_save_settings($NewSettings, 'powerpress_taxonomy_'. $ttid ); } echo '
'; echo '

'. __('Program information imported', 'powerpress') .'

'; echo ''; } } function import_item($post, $MatchFilter, $import_blog_posts=false, $category_strict='', $feed_slug='', $post_type = '', $taxonomy = '', $term = '', $remove_query_string = false, $post_status = 'publish') { global $wpdb; $this->m_item_pos++; $matches = array(); $post_title = false; if( !preg_match('|(.*?)|is', $post, $matches) ) { echo sprintf(__('Empty episode title for item %d', 'powerpress'), $this->m_item_pos); $this->m_item_skipped_count++; return false; } $post_title = $this->_sanatize_tag_value($matches[1]); // Look for an enclosure, if not found skip it... $enclosure_data = false; if( !preg_match('#|)#is', $post, $enclosure_data) ) { echo sprintf(__('No Media found for item %d', 'powerpress'), $this->m_item_pos); //echo '
'.htmlspecialchars($post).'
'; // Uncomment for debugging if( empty($import_blog_posts) ) { $this->m_item_skipped_count++; return false; } echo ' - '; } if( !empty($enclosure_data[1]) ) { $enclosure = $this->_parse_enclosure( '', $post, $category_strict ); if( empty($enclosure) ) { if( empty($import_blog_posts) ) { echo sprintf(__('No Media found for item %d', 'powerpress'), $this->m_item_pos); $this->m_item_skipped_count++; return false; } } } // GUID has to be last, as we will use the media URL as the guid as a last resort $guid = false; if( preg_match('|(.*?)|is', $post, $matches) ) $guid = $this->_sanatize_tag_value( $matches[1] ); else if( !empty($enclosure['url']) ) $guid = $enclosure['url']; $media_url = ''; if( !empty($enclosure['url']) ) { if( !empty($remove_query_string) && !empty($enclosure['url']) && strstr($enclosure['url'], '?') ) { $enclosure['url'] = strtok($enclosure['url'],'?'); //Tund3r: added for libsyn } $media_url = $enclosure['url']; } if(preg_match('/https?:\/\/(www\.)?media\.blubrry\.com\//m', $media_url)) { $this->isHostedOnBlubrry = true; } $post_date_gmt = false; if( preg_match('|(.*?)|is', $post, $matches) ) { $post_date_gmt = strtotime($matches[1]); } else { // if we don't already have something from pubDate if( preg_match('|(.*?)|is', $post, $matches) ) { $post_date_gmt = preg_replace('|([-+])([0-9]+):([0-9]+)$|', '\1\2\3', $matches[1]); $post_date_gmt = str_replace('T', ' ', $post_date_gmt); $post_date_gmt = strtotime($post_date_gmt); } } $post_date_gmt = gmdate('Y-m-d H:i:s', $post_date_gmt); $post_date = get_date_from_gmt( $post_date_gmt ); // Before we go any further, lets see if we have imported this one already... $exists = $this->_find_post( (empty($MatchFilter['match_guid'])?'':$guid), (empty($MatchFilter['match_title'])?'':$post_title), (empty($MatchFilter['match_date'])?'':$post_date), (empty($MatchFilter['match_filename'])?'':$media_url), $feed_slug ); if( !empty($exists) ) { ?> Episode Already Imported ❌ m_item_skipped_count++; return false; } // Okay awesome, lets dig through the rest... $categories = array(); if( preg_match_all('|(.*?)|is', $post, $matches) ) $categories = $matches[1]; if ( empty($categories) ) { if( preg_match_all('|(.*?)|is', $post, $matches) ) $categories = $matches[1]; } $cat_index = 0; foreach ($categories as $category) { $categories[$cat_index] = $this->_sanatize_tag_value( $category ); $cat_index++; } $post_content = ''; if( preg_match('|(.*?)|is', $post, $matches) ) $post_content = $this->_sanatize_tag_value( $matches[1] ); if ( empty($post_content) ) { // This is for feeds that put content in description if( preg_match('|(.*?)|is', $post, $matches) ) $post_content = $this->_sanatize_tag_value( $matches[1] ); } if ( empty($post_content) && !empty($enclosure['summary']) ) { // Last case situation lets used the itunes:summary if no description was available $post_content = $enclosure['summary']; } // Clean up content $post_content = preg_replace_callback('|<(/?[A-Z]+)|', array( &$this, '_normalize_tag' ), $post_content); $post_content = str_replace('
', '
', $post_content); $post_content = str_replace('
', '
', $post_content); $post_author = get_current_user_id(); // Save this episode to the database... $post_to_save = compact('post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_title', 'post_status', 'guid', 'categories', 'enclosure'); if( !empty($post_type) ) // If the post should go into a custom post type... { $post_to_save['post_type'] = $post_type; } $this->m_item_inserted_count++; $post_id = $this->_import_post_to_db($post_to_save, $feed_slug); if( empty($post_id) || is_wp_error($post_id) ) { ?> Import Failed ❌ " . esc_html($post_title) . "" ?> ✔️ '; // Category strict if( !empty($category_strict) ) { wp_set_post_categories( $post_id, array($category_strict), true ); } // Set specific taxonomy term to this post if( !empty($taxonomy) && !empty($term) ) { wp_set_post_terms( $post_id, array($term), $taxonomy, true ); } return ( $post_id > 0 ); } function _sanatize_tag_value($value) { if( !is_string($value) ) return ''; $value = trim($value); if( preg_match('/^$/is', $value, $matches) ) { $value = $matches[1]; } else { $value = html_entity_decode($value); } return $value; } function import_episodes($MatchFilter, $import_blog_posts=false, $import_item_limit=0, $category='', $feed_slug='', $post_type = '', $ttid = '', $remove_query_string = false, $post_status='publish') { global $wpdb; @set_time_limit(60*15); // Give it 15 minutes $this->m_item_pos = 0; $taxonomy = ''; $term = ''; if( $ttid ) { $TaxTermObj = get_term_by('term_taxonomy_id', $ttid); if( $TaxTermObj ) { $term = $TaxTermObj->name; $taxonomy = $TaxTermObj->taxonomy; // Now get the post type if the taxonomy, which may not be "post"... $TaxonomyObj = get_taxonomy($taxonomy); // Set the post type to import into if( !empty($TaxonomyObj->object_type[0]) && $TaxonomyObj->object_type[0] != 'post' ) { $post_type = $TaxonomyObj->object_type[0]; } // We should use the term's ID rather than it's name if( !empty($TaxonomyObj->hierarchical) ) { $term = intval($TaxTermObj->term_id); } } else { // Do not go any further, there is an error here! echo '

'; echo __('Error, unable to locate term taxonomy.', 'powerpress'); echo '

'; return; } } $item_count = substr_count( $this->m_content, ''); $item_count += substr_count( $this->m_content, ''); echo '
'; echo '
'; echo '

Diagnostic information

'; echo '
    '; if( !empty($ttid) ) echo sprintf( '
  • Taxonomy Term ID: %s
  • ', $ttid); if( !empty($taxonomy) ) echo sprintf( '
  • Taxonomy: %s
  • ', $taxonomy); if( !empty($term) ) echo sprintf( '
  • Taxonomy Term: %s
  • ', $term); if( !empty($post_type) ) echo sprintf( '
  • Post Type: %s
  • ', $post_type); if( !empty($feed_slug) ) echo sprintf( '
  • Feed Slug: %s
  • ', $feed_slug); if( !empty($category) ) echo sprintf( '
  • Category: %s
  • ', $category); echo sprintf( '
  • Remove query string: %s
  • ', ( !empty($remove_query_string)?'true':'false') ); echo '
' /* echo ''; echo '
'; echo '

'; echo __('Importing Episodes...', 'powerpress'); echo '

'; echo '

'; echo sprintf( __('Items Found: %d', 'powerpress'), $item_count); echo '

';*/ ?>
Imported Episodes
m_content, '', $item_start_pos):stripos($this->m_content, '', $item_start_pos) ); $item_end_pos = $item_start_pos; $item_end_pos = (function_exists('mb_stripos')?mb_stripos($this->m_content, '', $item_end_pos):stripos($this->m_content, '', $item_end_pos) ); $count = 0; while( $item_start_pos !== false && $item_end_pos !== false ) // If one were to return false, we stap! { $count++; // check item limit at the beginning of each iteration if( $import_item_limit > 0 && $this->m_item_pos >= $import_item_limit ) { break; // Item limit reached, stop! } echo ""; $new_start = $item_start_pos + mb_strlen(''); $item_content = mb_substr($this->m_content, $new_start, $item_end_pos - $new_start); $item_content = str_replace('', "\n", $item_content); $this->import_item($item_content, $MatchFilter, $import_blog_posts, $category, $feed_slug, $post_type, $taxonomy, $term, $remove_query_string, $post_status); echo ''; // Extra stop just in case... if( $count > 3000 ) break; if( $count % 25 == 0 ) @flush(); $item_start_pos = (function_exists('mb_stripos')?mb_stripos($this->m_content, '', $item_end_pos):stripos($this->m_content, '', $item_end_pos) ); $item_end_pos = (function_exists('mb_stripos')?mb_stripos($this->m_content, '', $item_start_pos):stripos($this->m_content, '', $item_start_pos) ); } } function import() { ?>
_import_handle_upload(); } else { ?>_import_handle_url(); } if( $result == false ) { $this->addError( __('Error occurred importing podcast.', 'powerpress') ); return; } // Match posts by: $MatchFilter = array('match_guid'=>true); $MatchFilter['match_date'] = (!empty($_POST['match_date'])?true:false); $MatchFilter['match_title'] = (!empty($_POST['match_title'])?true:false); $MatchFilter['match_filename'] = (!empty($_POST['match_filename'])?true:false); $import_blog_posts = (!empty($_POST['import_blog_posts'])?true:false); $import_item_limit = (!empty($_POST['import_item_limit'])?intval($_POST['import_item_limit']):0); $remove_query_string = (!empty($_POST['remove_query_string'])?true:false); $post_status = ( !empty($_POST['import_post_status']) ? $_POST['import_post_status']: 'publish' ); $category = (!empty($_POST['category'])?intval($_POST['category']):''); $feed_slug = (!empty($_POST['feed_slug'])?($_POST['feed_slug']):''); $post_type = (!empty($_POST['post_type'])?($_POST['post_type']):''); $post_type_feed_slug = (!empty($_POST['post_type_feed_slug'])?($_POST['post_type_feed_slug']):''); $ttid = (!empty($_POST['podcast_ttid'])?intval($_POST['podcast_ttid']):''); //$import_ = (!empty($_POST['import_item_limit'])?intval($_POST['import_item_limit']):0); $import_to = 'default'; if( !empty($_POST['import_to']) && $_POST['import_to'] != 'default' ) $import_to = $_POST['import_to']; if( !empty($_REQUEST['import']) && $_REQUEST['import'] == 'powerpress-libsyn-rss-podcast' ) $remove_query_string = true; // Set the correct parameters going in... switch( $import_to ) { case 'category': { $feed_slug = ''; $post_type = ''; $ttid = ''; if( empty($category) ) { echo '

No category selected.

'; return; } }; break; case 'channel': { $category = ''; $post_type = ''; $ttid = ''; if( empty($feed_slug) ) { echo '

No podcast channel selected.

'; return; } }; break; case 'post_type': { $category = ''; $feed_slug = $post_type_feed_slug; $ttid = ''; if( empty($feed_slug) ) { echo '

No feed slug specified.

'; return; } if( empty($post_type) ) { echo '

No post type specified.

'; return; } }; break; case 'taxonomy': { $category = ''; $feed_slug = ''; $post_type = ''; if( empty($ttid) ) { echo '

No taxonomy podcast selected.

'; return; } }; break; case 'default': default: { $category = ''; $feed_slug = ''; $post_type = ''; $ttid = ''; }; break; } // First import program info... if( preg_match('/^(.*)/is', $this->m_content, $matches) ) { if( $import_to == 'default' ) { $overwrite_program_info = (!empty($_POST['import_overwrite_program_info'])?true:false); $import_itunes_image = (!empty($_POST['import_itunes_image'])?true:false); if( $overwrite_program_info || $import_itunes_image ) $this->import_program_info($matches[1], $overwrite_program_info, $import_itunes_image); } else if( $import_to == 'category' ) { $overwrite_program_info = (!empty($_POST['import_overwrite_program_info_category'])?true:false); $import_itunes_image = (!empty($_POST['import_itunes_image_category'])?true:false); if( $overwrite_program_info || $import_itunes_image ) $this->import_program_info($matches[1], $overwrite_program_info, $import_itunes_image, $category); } else if( $import_to == 'channel' ) { $overwrite_program_info = (!empty($_POST['import_overwrite_program_info_channel'])?true:false); $import_itunes_image = (!empty($_POST['import_itunes_image_channel'])?true:false); if( $overwrite_program_info || $import_itunes_image ) $this->import_program_info($matches[1], $overwrite_program_info, $import_itunes_image, false, $feed_slug); } else if( $import_to == 'post_type' ) { $overwrite_program_info = (!empty($_POST['import_overwrite_program_info_post_type'])?true:false); $import_itunes_image = (!empty($_POST['import_itunes_image_post_type'])?true:false); if( $overwrite_program_info || $import_itunes_image ) $this->import_program_info($matches[1], $overwrite_program_info, $import_itunes_image, false, $feed_slug, $post_type); } else if( $import_to == 'taxonomy' ) { $overwrite_program_info = (!empty($_POST['import_overwrite_program_info_taxonomy'])?true:false); $import_itunes_image = (!empty($_POST['import_itunes_image_taxonomy'])?true:false); if( $overwrite_program_info || $import_itunes_image ) $this->import_program_info($matches[1], $overwrite_program_info, $import_itunes_image, false, false, false, $ttid); } } $this->import_episodes($MatchFilter, $import_blog_posts, $import_item_limit, $category, $feed_slug, $post_type, $ttid, $remove_query_string, $post_status); $migrated_to_blubrry = false; if( !empty($_POST['migrate_to_blubrry']) && !empty($GLOBALS['pp_migrate_media_urls']) ) { require_once( POWERPRESS_ABSPATH .'/powerpressadmin-migrate.php'); $migrated_to_blubrry = true; $update_option = true; $QueuedFiles = get_option('powerpress_migrate_queued'); if( !is_array($QueuedFiles) ) { $QueuedFiles = array(); $update_option = false; } $add_urls = ''; foreach( $GLOBALS['pp_migrate_media_urls'] as $meta_id => $url ) { if( empty($QueuedFiles[ $meta_id ]) ) { // Add to the array if not already added $QueuedFiles[ $meta_id ] = $url; if( !empty($add_urls) ) { $add_urls .= "\n"; } $this->m_item_migrate_count++; $add_urls .= $url; } } if (!isset($_GET['from']) || ($_GET['from'] != 'gs' || $_GET['from'] != 'onboarding')) { echo '

'; echo __('Migration request...', 'powerpress'); echo '

'; echo '
';
                echo $add_urls;
                echo '
'; } $UpdateResults = powepress_admin_migrate_add_urls($add_urls); if( !empty($UpdateResults) ) { echo '

Migration queued successfully.

'; // Queued ok... if( $update_option ) update_option('powerpress_migrate_queued', $QueuedFiles); else add_option('powerpress_migrate_queued', $QueuedFiles, '', 'no'); } else { echo '

Failed to request migration.

'; } } powerpress_page_message_print(); ?>
{$count}
m_item_inserted_count != 0) { echo $this->m_item_inserted_count . " Episodes Imported"; } if ($this->m_item_skipped_count != 0) { if($this->m_item_inserted_count != 0) { echo ' / '; } echo $this->m_item_skipped_count . " Episodes Skipped"; } ?>
'; if( !empty( $this->m_item_migrate_count ) ) echo '

'. sprintf(__('Media files queued for migration: %d', 'powerpress'), $this->m_item_migrate_count).'

'; echo ''; if( $migrated_to_blubrry ) { echo '

'. sprintf(__('Visit %s to monitor the migration process.','powerpress'), ''. __('Migrate Media', 'powerpress') .'' ). '

'; } else { echo '

'. sprintf(__('You may now migrate your media manually or use the %s tool.','powerpress'), ''. __('Migrate Media', 'powerpress') .'' ). '

'; } $nextUrl = ''; $GeneralSettings = powerpress_get_settings('powerpress_general'); if(!empty($_GET['from']) && $_GET['from'] == 'onboarding') { if (isset($GeneralSettings['blubrry_hosting']) && $GeneralSettings['blubrry_hosting'] != null) { $nextUrl = admin_url("admin.php?page=powerpressadmin_basic&step=createEpisode&import=true&migrate=true"); } else { if ($this->isHostedOnBlubrry) { $nextUrl = admin_url("admin.php?page=powerpressadmin_basic&step=blubrrySignin&import=true"); } else { $nextUrl = admin_url("admin.php?page=powerpressadmin_basic&step=nohost&import=true&from=import"); } } } else if (!empty($_GET['from']) && $_GET['from'] == 'gs') { if (isset($GeneralSettings['blubrry_hosting']) && $GeneralSettings['blubrry_hosting'] != null) { $nextUrl = admin_url("admin.php?page=powerpressadmin_onboarding.php&step=createEpisode&import=true&migrate=true"); } else { if ($this->isHostedOnBlubrry) { $nextUrl = admin_url("admin.php?page=powerpressadmin_onboarding.php&step=blubrrySignin&import=true"); } else { $nextUrl = admin_url("admin.php?page=powerpressadmin_onboarding.php&step=nohost&import=true&from=import"); } } } if(!empty($_GET['from'])) { ?> m_step = 0; if( !empty($_POST['step']) ) $this->m_step = intval($_POST['step']); else if( !empty($_GET['step']) ) $this->m_step = intval($_GET['step']); // Drop back down a step if not setup for hosting... if( !empty($_POST['migrate_to_blubrry']) ) { $Settings = get_option('powerpress_general'); if( empty($Settings['blubrry_auth']) ) { echo '

'. sprintf(__('You must have a blubrry Podcast Hosting account to continue.', 'powerpress')) .' '. ''. __('Learn More', 'powerpress') .''. '

'; $this->m_step = 0; // Drop back a step } } $this->header(); switch ($this->m_step) { case 0 : $this->greet(); break; case 1 : check_admin_referer('import-powerpress-rss'); $result = $this->import(); if ( is_wp_error( $result ) ) echo $result->get_error_message(); break; } } function get_step() { return $this->m_step; } function _find_post_by_guid($guid) { global $wpdb; $post_guid = wp_unslash( sanitize_post_field( 'guid', $guid, 0, 'db' ) ); $query = "SELECT ID FROM $wpdb->posts WHERE 1=1 "; $args = array(); if ( !empty ( $post_guid ) ) { $query .= 'AND guid = %s'; $args[] = $post_guid; } if ( !empty ( $args ) ) { $found = intval( $wpdb->get_var( $wpdb->prepare($query, $args) ) ); if( $found > 0 ) return $found; } return 0; } function _find_post_by_title($title) { global $wpdb; $post_guid = wp_unslash( sanitize_post_field( 'post_title', $title, 0, 'db' ) ); $query = "SELECT ID FROM $wpdb->posts WHERE 1=1 "; $args = array(); if ( !empty ( $post_guid ) ) { $query .= 'AND post_title = %s'; $args[] = $title; } if ( !empty ( $args ) ) { $found = intval( $wpdb->get_var( $wpdb->prepare($query, $args) ) ); if( $found > 0 ) return $found; } return 0; } function _find_post_by_date($date) { global $wpdb; $post_guid = wp_unslash( sanitize_post_field( 'post_date', $date, 0, 'db' ) ); $query = "SELECT ID FROM $wpdb->posts WHERE 1=1 "; $args = array(); if ( !empty ( $post_guid ) ) { $query .= 'AND post_date = %s'; $args[] = $date; } if ( !empty ( $args ) ) { $found = intval( $wpdb->get_var( $wpdb->prepare($query, $args) ) ); if( $found > 0 ) return $found; } return 0; } function _find_post_by_enclosure_filename($filename, $feed_slug = '') { global $wpdb; $meta_key = 'enclosure'; if( !empty($feed_slug) && $feed_slug != 'podcast' ) $meta_key = '_'. $feed_slug .':enclosure'; $meta_value = $filename; $query = "SELECT p.ID "; $query .= "FROM {$wpdb->posts} AS p "; $query .= "INNER JOIN {$wpdb->postmeta} AS pm ON p.ID = pm.post_id "; $query .= "WHERE pm.meta_key = %s "; $query .= "AND pm.meta_value LIKE '%%%s%%' "; $query .= "AND p.post_type != 'revision' "; $query .= "GROUP BY p.ID "; $query .= "ORDER BY p.post_date DESC LIMIT 1 "; // Make sure we use the oldest date $query = $wpdb->prepare($query, $meta_key, $meta_value ); $results = $wpdb->get_results($query, ARRAY_A); if( !empty($results) ) { foreach( $results as $null => $row ) { return $row['ID']; } } return 0; } function _find_post($guid = '', $title = '', $date = '', $media_url = '', $feed_slug='') { global $wpdb; if( !empty($guid) ) { $found = $this->_find_post_by_guid($guid); if( $found ) return $found; } if( !empty($media_url) ) { $filename = basename($media_url); if( !empty($filename) ) { $found = $this->_find_post_by_enclosure_filename($filename, $feed_slug); if( $found ) return $found; } } if( !empty($title) ) { $found = $this->_find_post_by_title($title); if( $found ) return $found; } if( !empty($date) ) { $found = $this->_find_post_by_date($date); return $found; } return 0; } function _import_post_to_db($post, $feed_slug = '') { global $wpdb; extract($post); $post_id = wp_insert_post($post); //Update the post to overwrite wordpress's guid $query = $wpdb->prepare("UPDATE {$wpdb->posts} SET guid=%s WHERE ID='{$post_id}'", $post['guid']); $return = $wpdb->query($query); // If the GUID does not start with a http or https protocol, lets also save it to this custom field so it gets picked up as it was from the original source. if( preg_match('/^https?:\/\//i', $post['guid']) == false ) { add_post_meta($post_id, '_powerpress_guid', $post['guid'], true); } if ( is_wp_error( $post_id ) ) return $post_id; if (!$post_id) { _e('Couldn’t get post ID', 'powerpress'); return false; } if (0 != count($categories)) wp_create_categories($categories, $post_id); if( !empty($enclosure['url']) ) { $encstring = $enclosure['url'] . "\n" . $enclosure['length'] . "\n" . $enclosure['type']; $serialize = array(); if( !empty($enclosure['duration']) && function_exists('powerpress_raw_duration') ) $serialize['duration'] = powerpress_raw_duration($enclosure['duration']); if( !empty($enclosure['keywords']) ) $serialize['keywords'] = $enclosure['keywords']; if( !empty($enclosure['summary']) ) $serialize['summary'] = $enclosure['summary']; if( !empty($enclosure['subtitle']) ) $serialize['subtitle'] = $enclosure['subtitle']; if( !empty($enclosure['author']) ) $serialize['author'] = $enclosure['author']; if( !empty($enclosure['itunes_image']) ) $serialize['itunes_image'] = $enclosure['itunes_image']; if( !empty($enclosure['block']) ) $serialize['block'] = $enclosure['block']; if( !empty($enclosure['cc']) ) $serialize['cc'] = $enclosure['cc']; if( !empty($enclosure['order']) ) $serialize['order'] = $enclosure['order']; if( !empty($enclosure['explicit']) ) $serialize['explicit'] = $enclosure['explicit']; if( !empty($enclosure['category']) ) $serialize['category'] = $enclosure['category']; if( !empty($serialize) ) $encstring .= "\n". serialize( $serialize ); if( empty($feed_slug) || $feed_slug == 'podcast' ) // 'podcast' == $feed_slug || '' == $feed_slug $meta_id = add_post_meta($post_id, 'enclosure', $encstring, true); else $meta_id = add_post_meta($post_id, '_'. $feed_slug .':enclosure', $encstring, true); if( $meta_id ) { if( empty($GLOBALS['pp_migrate_media_urls']) ) $GLOBALS['pp_migrate_media_urls'] = array(); $GLOBALS['pp_migrate_media_urls'][ $meta_id ] = $enclosure['url']; } } return $post_id; } function _parse_enclosure($string, $post, $category_strict='') { global $wpdb; // Create an XML parser if ( ! function_exists( 'xml_parser_create' ) ) { // These are WordPress strings, no need to use our namespace for these messages. trigger_error( __( "PHP's XML extension is not available. Please contact your hosting provider to enable PHP's XML extension." ) ); wp_die( __( "PHP's XML extension is not available. Please contact your hosting provider to enable PHP's XML extension." ) ); } $p = xml_parser_create(); xml_parse_into_struct($p, $string, $vals, $index); xml_parser_free($p); if( !empty($vals[0]['attributes']['URL']) ) { $enclosure = array('url'=>trim($vals[0]['attributes']['URL']),'length'=>1, 'type'=>''); if( !empty($vals[0]['attributes']['LENGTH']) ) $enclosure['length'] = trim($vals[0]['attributes']['LENGTH']); if( !empty($vals[0]['attributes']['TYPE']) ) $enclosure['type'] = trim($vals[0]['attributes']['TYPE']); if( empty($enclosure['type']) ) $enclosure['type'] = powerpress_get_contenttype($enclosure['url']); $matches = array(); if( preg_match('|(.*?)|i', $post, $matches) ) { $enclosure['duration'] = $this->_sanatize_tag_value( $matches[1] ); } // keywords No longer supported by iTunes: if( preg_match('|(.*?)|i', $post, $matches) ) { $enclosure['keywords'] = $this->_sanatize_tag_value( $matches[1] ); } if( preg_match('|(.*?)|is', $post, $matches) ) { $enclosure['summary'] = $this->_sanatize_tag_value( $matches[1] ); } if( preg_match('|(.*?)|i', $post, $matches) ) { $enclosure['subtitle'] = $this->_sanatize_tag_value( $matches[1] ); } if( preg_match('|(.*?)|i', $post, $matches) ) { $enclosure['author'] = $this->_sanatize_tag_value( $matches[1] ); } if( preg_match('|(.*?)|i', $post, $matches) ) { $value = strtolower(trim( $matches[1] )); if( $value == 'yes' ) $enclosure['block'] = 1; } if( preg_match('/|>.*<\/itunes:image>)/i', $post, $matches) ) { $enclosure['itunes_image'] = html_entity_decode( trim( $matches[1] ) ); } if( preg_match('|(.*?)|i', $post, $matches) ) { $value = strtolower(trim( $matches[1] )); if( $value == 'yes' ) $enclosure['cc'] = 1; } if( preg_match('|(.*?)|i', $post, $matches) ) { $value = trim( $matches[1] ); if( !empty($value) ) $enclosure['order'] = intval($value); } if( preg_match('|(.*?)|i', $post, $matches) ) { $explicit_array = array('yes'=>1, 'clean'=>2); // No need to save 'no' $value = strtolower( trim( $matches[1] ) ); if( !empty($explicit_array[ $value ]) ) $enclosure['explicit'] = $explicit_array[ $value ]; } if( !empty($category_strict) ) { $enclosure['category'] = $category_strict; } return $enclosure; } return ''; } function _import_handle_url() { if( empty($_POST['podcast_feed_url']) ) { echo '

'. __( 'URL is empty.', 'powerpress' ) .'

'; return false; } $options = array(); $options['user-agent'] = 'Blubrry PowerPress/'.POWERPRESS_VERSION; if( !empty($_GET['import']) && $_GET['import'] == 'powerpress-squarespace-rss-podcast' ) $options['user-agent'] = 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.111 Safari/537.36'; else if( !empty($_GET['import']) && $_GET['import'] == 'powerpress-podbean-rss-podcast' ) $options['user-agent'] = 'iTunes/12.2.2 (Macintosh; OS X 10.10.5) AppleWebKit/600.8.9'; // Common user agent // 'gPodder/3.8.4 (+http://gpodder.org/)'; $options['timeout'] = 10; $response = wp_safe_remote_get($_POST['podcast_feed_url'], $options); if ( is_wp_error( $response ) ) { echo '

'. $response->get_error_message() .'

'; return false; } $this->m_content = wp_remote_retrieve_body( $response ); return true; } function _import_handle_upload() { if ( ! isset( $_FILES['podcast_feed_file'] ) || empty($_FILES['podcast_feed_file']['tmp_name']) ) { echo '

'. __( 'Upload failed.', 'powerpress' ).'

'; return false; } $this->m_content = file_get_contents($_FILES['podcast_feed_file']['tmp_name']); return true; } } // end PowerPress_RSS_Podcast_Import class $powerpress_rss_podcast_import = new PowerPress_RSS_Podcast_Import(); register_importer('powerpress-soundcloud-rss-podcast', __('Podcast from SoundCloud', 'powerpress'), __('Import episodes from a SoundCloud podcast feed.', 'powerpress'), array ($powerpress_rss_podcast_import, 'dispatch')); register_importer('powerpress-libsyn-rss-podcast', __('Podcast from LibSyn', 'powerpress'), __('Import episodes from a LibSyn podcast feed.', 'powerpress'), array ($powerpress_rss_podcast_import, 'dispatch')); register_importer('powerpress-podbean-rss-podcast', __('Podcast from PodBean ', 'powerpress'), __('Import episodes from a PodBean podcast feed.', 'powerpress'), array ($powerpress_rss_podcast_import, 'dispatch')); register_importer('powerpress-squarespace-rss-podcast', __('Podcast from Squarespace', 'powerpress'), __('Import episodes from a Squarespace podcast feed.', 'powerpress'), array ($powerpress_rss_podcast_import, 'dispatch')); register_importer('powerpress-anchor-rss-podcast', __('Podcast from Anchor.fm', 'powerpress'), __('Import episodes from an Anchor.fm podcast feed.', 'powerpress'), array ($powerpress_rss_podcast_import, 'dispatch')); register_importer('powerpress-rss-podcast', __('Podcast RSS Feed', 'powerpress'), __('Import episodes from a RSS podcast feed.', 'powerpress'), array ($powerpress_rss_podcast_import, 'dispatch')); }; // end if WP_Importer exists // eof