コード例 #1
0
    public function template()
    {
        // load already migrated posts
        $migrated_posts_cache = get_option('podlove_migrated_posts_cache', array());
        // then begin to migrate
        $migration_settings = get_option('podlove_migration', array());
        // Basic Podcast Settings
        $podcast = Model\Podcast::get();
        $podcast->title = $migration_settings['podcast']['title'];
        $podcast->subtitle = $migration_settings['podcast']['subtitle'];
        $podcast->summary = $migration_settings['podcast']['summary'];
        $podcast->media_file_base_uri = \Podlove\Modules\Migration\get_media_file_base_url();
        // harvest low hanging podPress fruits
        if ($podPress_config = get_option('podPress_config')) {
            if (isset($podPress_config['iTunes']['image']) && !$podcast->cover_image) {
                $podcast->cover_image = $podPress_config['iTunes']['image'];
            }
        }
        // harvest low hanging PowerPress fruits
        if ($powerPress_config = get_option('powerpress_feed')) {
            if (isset($powerPress_config['itunes_image']) && !$podcast->cover_image) {
                $podcast->cover_image = $powerPress_config['itunes_image'];
            }
            if (isset($powerPress_config['itunes_cat_1']) && !$podcast->category_1) {
                $podcast->category_1 = $powerPress_config['itunes_cat_1'];
            }
            if (isset($powerPress_config['itunes_cat_2']) && !$podcast->category_2) {
                $podcast->category_2 = $powerPress_config['itunes_cat_2'];
            }
            if (isset($powerPress_config['itunes_cat_3']) && !$podcast->category_3) {
                $podcast->category_3 = $powerPress_config['itunes_cat_3'];
            }
        }
        $podcast->save();
        // Create Template
        $template = Model\Template::find_one_by_title('default');
        if (!$template) {
            $template = new Model\Template();
            $template->title = 'default';
            $template->content = <<<EOT
{{ episode.player }}
[podlove-episode-downloads]
EOT;
            $template->save();
        }
        $template_assignment = Model\TemplateAssignment::get_instance();
        if ($template_assignment->has_property($migration_settings['cleanup']['template'])) {
            $template_assignment->{$migration_settings}['cleanup']['template'] = $template->id;
            $template_assignment->save();
        }
        // Create Assets
        $assets = array();
        foreach ($migration_settings['file_types'] as $file_type_id => $_) {
            $file_type = Model\FileType::find_one_by_id($file_type_id);
            $is_image = in_array($file_type->extension, array('png', 'jpg', 'jpeg', 'gif'));
            $asset = Model\EpisodeAsset::find_one_by_file_type_id($file_type_id);
            if (!$asset) {
                $asset = new Model\EpisodeAsset();
                $asset->title = $file_type->name;
                $asset->file_type_id = $file_type_id;
                $asset->downloadable = !$is_image;
                $asset->save();
            }
            $assets[] = $asset;
            if ($is_image) {
                $asset_assignments = get_option('podlove_asset_assignment', array());
                if (!$asset_assignments['image']) {
                    $asset_assignments['image'] = $asset->id;
                    update_option('podlove_asset_assignment', $asset_assignments);
                }
            }
            // create feeds
            if (stripos($file_type->mime_type, 'audio') !== false) {
                $feed = Model\Feed::find_one_by_episode_asset_id($asset->id);
                if (!$feed) {
                    $feed = new Model\Feed();
                    $feed->episode_asset_id = $asset->id;
                    $feed->name = $file_type->name;
                    $feed->title = $file_type->name;
                    $feed->slug = $file_type->extension;
                    $feed->format = 'rss';
                    $feed->enable = true;
                    $feed->discoverable = true;
                    $feed->limit_items = -1;
                    $feed->save();
                }
            }
            // set web player settings
            $webplayer_formats = get_option('podlove_webplayer_formats', array());
            if (!isset($webplayer_formats['audio'])) {
                $webplayer_formats['audio'] = array();
            }
            if (stripos($file_type->mime_type, 'audio/mpeg') !== false) {
                $webplayer_formats['audio']['mp3'] = $asset->id;
            } elseif (stripos($file_type->mime_type, 'audio/mp4') !== false) {
                $webplayer_formats['audio']['mp4'] = $asset->id;
            } elseif (stripos($file_type->mime_type, 'audio/ogg') !== false) {
                $webplayer_formats['audio']['ogg'] = $asset->id;
            } elseif (stripos($file_type->mime_type, 'audio/opus') !== false) {
                $webplayer_formats['audio']['opus'] = $asset->id;
            }
            update_option('podlove_webplayer_formats', $webplayer_formats);
        }
        // flush rules after migration
        set_transient('podlove_needs_to_flush_rewrite_rules', true);
        ?>
		
		<form action="" method="POST">
			<input type="submit" name="prev" class="btn" value="<?php 
        echo __('Back', 'podlove');
        ?>
">
			<input type="submit" name="next" id="continue_to_finish_button" class="btn btn-primary disabled pull-right" value="<?php 
        echo __('Continue to last step', 'podlove');
        ?>
">
		</form>

		<div class="row-fluid">
			<div class="span12">
				<h3 id="migration-header">Migrating <small></small></h3>
			</div>
		</div>

		<div class="progress progress-striped active" id="migration_progress">
			<div class="bar" style="width:0%"></div>
		</div>

		<p>
			<input type="button" id="start_migration_button" class="btn btn-primary" value="<?php 
        echo __('Start Migration', 'podlove');
        ?>
">
			Starting the migration creates the actual episodes one by one.			
		</p>

		<table class="table table-condensed" id="posts_to_migrate">
			<thead>
				<tr>
					<th>Status</th>
					<th>Episode</th>
				</tr>
			</thead>
			<tbody>
				<?php 
        $migrated_post_ids = array_keys($migrated_posts_cache);
        ?>
				<?php 
        foreach ($migration_settings['episodes'] as $post_id => $_) {
            ?>
					<?php 
            $done = in_array($post_id, $migrated_post_ids);
            ?>
					<tr data-post-id="<?php 
            echo $post_id;
            ?>
" <?php 
            echo $done ? 'class="done"' : '';
            ?>
>
						<td class="status">
							<span class="waiting" <?php 
            echo !$done ? '' : 'style="display:none"';
            ?>
>not yet migrated</span>
							<span class="migrating" style="display:none"><i class="podlove-icon-spinner rotate"></i></span>
							<span class="done" <?php 
            echo $done ? '' : 'style="display:none"';
            ?>
><i class="podlove-icon-ok"></i></span>
						</td>
						<td class="episode">
							<?php 
            if ($done) {
                ?>
								<a href="<?php 
                echo get_edit_post_link($migrated_posts_cache[$post_id]);
                ?>
" target="_blank">
									<?php 
                echo get_the_title($post_id);
                ?>
								</a>
							<?php 
            } else {
                ?>
								<?php 
                echo get_the_title($post_id);
                ?>
							<?php 
            }
            ?>
						</td>
					</tr>
				<?php 
        }
        ?>
			</tbody>
		</table>

		<script type="text/javascript">
		jQuery(function($) {
			var posts_to_migrate = $("#posts_to_migrate tbody tr").length;

			$("#continue_to_finish_button").hide();

			function update_migration_progress_bar() {
				var posts_done = $("#posts_to_migrate tbody tr.done").length;
				progress = Math.round(posts_done / posts_to_migrate * 100)
				$("#migration_progress .bar")
					.css("width", progress + "%")
					.html(posts_done + " / " + posts_to_migrate);

				if ( progress == 100 ) {
					$("#migration_progress")
						.removeClass("active")
						.addClass("progress-success")
						.find(".bar").html("Done! Whoop whoop!");

					$("#migration-header small").html('');
					$("#start_migration_button").addClass("disabled");
					$("#continue_to_finish_button").removeClass("disabled").show();
				}
			};

			function podlove_migrate_one_post() {
				$("#posts_to_migrate tbody tr:not(.done):first").each(function() {
					var post_id = $(this).data("post-id")
					    that = $(this),
					    episode_title = $(".episode", that).html();

					$("#migration-header small").html(episode_title);

					var data = {
						action: 'podlove-migrate-post',
						post_id: post_id
					};

					$.ajax({
						url: ajaxurl,
						data: data,
						dataType: 'json',
						beforeSend: function(jqXHR, settings) {
							$(".waiting, .done", that).hide();
							$(".migrating", that).show();
						},
						success: function(result) {
							var episode_url = result.url;

							$(".waiting, .migrating", that).hide();
							$(".done", that).show();
							that.addClass("done");

							// add link
							$(".episode", that).html('<a href="' + episode_url + '" target="_blank">' + episode_title + '</a>')

							// update progress bar
							update_migration_progress_bar();

							// continue
							podlove_migrate_one_post();
						}
					});
				});
			}

			$("#start_migration_button").on("click", function(){
				if (!$(this).hasClass("disabled")) {
					$(this).addClass("disabled");
					podlove_migrate_one_post();
				}
			});
			update_migration_progress_bar();
		});
		</script>
		<?php 
    }
コード例 #2
0
    public function template()
    {
        $args = array('posts_per_page' => -1);
        $episodes = array();
        $file_types = array();
        $errors = array();
        $query = new \WP_Query($args);
        while ($query->have_posts()) {
            $query->next_post();
            // look for the cover
            $metas = get_post_meta($query->post->ID, '', true);
            $metas = array_map(function ($m) {
                return $m[0];
            }, $metas);
            foreach ($metas as $key => $value) {
                if (filter_var($value, FILTER_VALIDATE_URL) === false) {
                    continue;
                }
                $enclosure = Enclosure::from_url($value, $query->post->ID);
                if (!in_array($enclosure->extension, array('gif', 'jpg', 'jpeg', 'png'))) {
                    continue;
                }
                if ($enclosure->errors) {
                    $errors = array_merge($enclosure->errors, $errors);
                } elseif (isset($file_types[$enclosure->file_type->id])) {
                    $file_types[$enclosure->file_type->id]['count'] += 1;
                } else {
                    $file_types[$enclosure->file_type->id] = array('file_type' => $enclosure->file_type, 'count' => 1);
                }
            }
            $enclosures = Enclosure::all_for_post($query->post->ID);
            foreach ($enclosures as $enclosure) {
                if ($enclosure->errors) {
                    $errors = array_merge($enclosure->errors, $errors);
                } elseif (isset($file_types[$enclosure->file_type->id])) {
                    $file_types[$enclosure->file_type->id]['count'] += 1;
                } else {
                    $file_types[$enclosure->file_type->id] = array('file_type' => $enclosure->file_type, 'count' => 1);
                }
            }
            if (count($enclosures)) {
                foreach ($enclosures as $enclosure) {
                    if (empty($enclosure->errors)) {
                        $episodes[] = $query->post;
                        break;
                    }
                }
            }
        }
        if (!count($episodes)) {
            $errors[] = __('<strong>No Episodes Found!</strong> You can only migrate posts with enclosures. However, there don\'t seem to be any. Sorry!', 'podlove');
        }
        $migration_settings = get_option('podlove_migration', array());
        // educated guess: activate all audio files by default
        if (!isset($migration_settings['file_types'])) {
            $migration_settings['file_types'] = array();
            foreach ($file_types as $file_type) {
                if (stripos($file_type['file_type']->mime_type, 'audio') !== false) {
                    $migration_settings['file_types'][$file_type['file_type']->id] = 'on';
                }
            }
        }
        $slug_type = 'file';
        if (!isset($migration_settings['post_slug']) || !($post_slug_type = $migration_settings['post_slug'])) {
            $post_slug_type = 'wordpress';
        }
        if (!isset($migration_settings['cleanup'])) {
            $migration_settings['cleanup'] = array();
        }
        $migration_settings['cleanup'] = wp_parse_args($migration_settings['cleanup'], array('enclosures' => 1, 'player' => 1, 'template' => 'bottom'));
        $validation_cache = get_option('podlove_migration_validation_cache', array());
        ?>

		<div class="row-fluid">
			<div class="span12">
				<form action="" method="POST" class="pull-left" style="margin-right: 15px">
					<input type="hidden" name="page" value="podlove_settings_migration_handle">
					<input type="submit" name="prev" class="btn" value="<?php 
        echo __('Back', 'podlove');
        ?>
">
					<input type="submit" name="next" class="btn btn-primary pull-right" value="<?php 
        echo __('Continue to Migration', 'podlove');
        ?>
">

					<div class="clearfix"></div>

					<div class="row-fluid">
						<div class="span12">
							<h3>About Episodes and Assets</h3>
							<p>
								A single podcast recording is called <em>episode</em>. Below are all posts identified as episodes. Please check that the results match your expectations.
								Podlove knows about the <em>assets</em> you distribute for each episode. Assets are audio/video files but also images, chapter files, subtitle files etc.
							</p>
							<p>
								When everything looks good and the verification bar is green (and maybe yellow, but not red), <em>continue to migration</em>.
							</p>
						</div>
					</div>

					<div class="clearfix"></div>

					<?php 
        if (count($errors)) {
            ?>
						<h3>Warnings</h3>
						<?php 
            foreach ($errors as $error) {
                ?>
							<div class="alert">
								<?php 
                echo $error;
                ?>
							</div>
						<?php 
            }
            ?>
					<?php 
        }
        ?>

					<h3><?php 
        echo __('Episode Assets', 'podlove');
        ?>
 <small>choose assets to use in your podcast</small></h3>
					<p>
						These are all detected assets. Please choose those that you want to use in your podcast.
						For each asset, a feed will be created and users will be able to download those files (you can change this after the migration).
					</p>
					<table class="table table-striped">
						<thead>
							<tr>
						 		<th>
						 			<?php 
        echo __('Use', 'podlove');
        ?>
						 		</th>
						 		<th>
						 			<?php 
        echo __('Title', 'podlove');
        ?>
						 		</th>
						 		<th>
						 			<?php 
        echo __('Mime Type', 'podlove');
        ?>
						 		</th>
						 		<th>
						 			<?php 
        echo __('Extension', 'podlove');
        ?>
						 		</th>
						 		<th>
						 			<?php 
        echo __('Matching Episodes', 'podlove');
        ?>
						 		</th>
							</tr>
						</thead>
						<tbody>
							<?php 
        foreach ($file_types as $file_type) {
            ?>
								<tr>
									<td>
										<input type="checkbox"
											data-filetype-id="<?php 
            echo $file_type['file_type']->id;
            ?>
"
											<?php 
            checked(isset($migration_settings['file_types'][$file_type['file_type']->id]) && $migration_settings['file_types'][$file_type['file_type']->id] == 'on');
            ?>
											name="podlove_migration[file_types][<?php 
            echo $file_type['file_type']->id;
            ?>
]"
											class="asset_checkbox"
										>
									</td>
									<td>
										<?php 
            echo $file_type['file_type']->name;
            ?>
									</td>
									<td>
										<?php 
            echo $file_type['file_type']->mime_type;
            ?>
									</td>
									<td>
										<?php 
            echo $file_type['file_type']->extension;
            ?>
									</td>
									<td>
										<?php 
            echo $file_type['count'];
            ?>
									</td>
								</tr>
							<?php 
        }
        ?>
						</tbody>
					</table>

					<input type="hidden" name="podlove_migration[slug]" value="file"/>

					<div class="row-fluid">

						<div class="span6" id="post_slug_select">
							<h3><?php 
        echo __('WordPress Post Slug', 'podlove');
        ?>
 <small>Url slug for the WordPress page</small></h3>
							<label class="radio">
								<input type="radio" name="podlove_migration[post_slug]" value="wordpress" <?php 
        checked($post_slug_type == 'wordpress');
        ?>
>
								Reuse previous WordPress post slug.
							</label>
							<label class="radio">
								<input type="radio" name="podlove_migration[post_slug]" value="file" <?php 
        checked($post_slug_type == 'file');
        ?>
>
								Extract slug from file name. Use file basename.
							</label>
							<label class="radio">
								<input type="radio" name="podlove_migration[post_slug]" value="number" <?php 
        checked($post_slug_type == 'number');
        ?>
>
								Number Slug: This is the number of your episode with leading zeros.
							</label>
						</div>

						<div class="span6">
							<h3><?php 
        echo __('Clean up migrated Episodes', 'podlove');
        ?>
</h3>

							<div class="form-horizontal" id="cleanup_settings">

								<div class="control-group enclosures">
									<label class="control-label" data-toggle="tooltip" title="You probably want to remove all enclosures stored in custom post meta. The Podlove Publisher imports and stores them separately.">
										Enclosures
									</label>
									<div class="controls">
										<label class="radio">
											<input type="radio" name="podlove_migration[cleanup][enclosures]" value="1" <?php 
        checked($migration_settings['cleanup']['enclosures'], 1);
        ?>
>
											remove all enclosure custom fields
										</label>
										<label class="radio">
											<input type="radio" name="podlove_migration[cleanup][enclosures]" value="0" <?php 
        checked($migration_settings['cleanup']['enclosures'], 0);
        ?>
>
											keep all enclosures custom fields
										</label>
									</div>
								</div>

								<div class="control-group player">
									<label class="control-label" data-toggle="tooltip" title="You probably want to get rid of your old players.">
										Web Player Shortcodes
									</label>
									<div class="controls">
										<label class="radio">
											<input type="radio" name="podlove_migration[cleanup][player]" value="1" <?php 
        checked($migration_settings['cleanup']['player'], 1);
        ?>
>
											remove all player codes
										</label>
										<label class="radio">
											<input type="radio" name="podlove_migration[cleanup][player]" value="0" <?php 
        checked($migration_settings['cleanup']['player'], 0);
        ?>
>
											keep all player codes
										</label>
									</div>
								</div>

								<div class="control-group template">
									<label class="control-label">Add template containing web player and download buttons</label>
									<div class="controls">
										<label class="radio">
											<input type="radio" name="podlove_migration[cleanup][template]" value="bottom" <?php 
        checked($migration_settings['cleanup']['template'], "bottom");
        ?>
>
											insert at the end of the content
										</label>
										<label class="radio">
											<input type="radio" name="podlove_migration[cleanup][template]" value="top" <?php 
        checked($migration_settings['cleanup']['template'], "top");
        ?>
>
											insert at the beginning of the content
										</label>
										<label class="radio">
											<input type="radio" name="podlove_migration[cleanup][template]" value="manually" <?php 
        checked($migration_settings['cleanup']['template'], "manually");
        ?>
>
											don't insert automatically
										</label>
									</div>
								</div>

							</div>
						</div>
						
					</div>

					<h3><?php 
        echo __('Episode Verification Status', 'podlove');
        ?>
</h3>
					<div class="progress progress-striped" id="verification-status">
					  <div class="bar bar-success" style="width:0%;display:none" data-toggle="tooltip" title="All media files for these episodes are valid."></div>
					  <div class="bar bar-warning" style="width:0%;display:none" data-toggle="tooltip" title="Some, but not all media files for these episodes are missing. You can add them later, so not necessarily a dealbreaker."></div>
					  <div class="bar bar-danger" style="width:0%;display:none" data-toggle="tooltip" title="No media files for these episodes exist!"></div>
					</div>

					<ul>
						<li>
							<span style="color: #00CE62">Green:</span> All media files for these episodes are valid.
						</li>
						<li>
							<span style="color: #FDB339">Yellow:</span> Some, but not all media files for these episodes are missing. You can add them later, so not necessarily a dealbreaker.
						</li>
						<li>
							<span style="color: #FF484C">Red:</span> No media for these episodes exist!
						</li>
					</ul>

					<h3><?php 
        echo __('Episodes', 'podlove');
        ?>
</h3>
					<p>
						Select the episodes to migrate. Use the rest of the displayed data to verify the extracted data.
					</p>
					<table class="table table-striped">
						<thead>
							<tr>
								<th>
									<input type="checkbox" checked="checked" id="toggle_all_episodes">
								</th>
								<th>#</th>
								<th>
									<?php 
        echo __('Detected Episode', 'podlove');
        ?>
								</th>
							</tr>
						</thead>
						<tbody id="episodes_to_migrate">
							<?php 
        foreach ($episodes as $episode_post) {
            ?>
								<?php 
            $post_data = new Legacy_Post_Parser($episode_post->ID);
            ?>
								<tr>
									<td>
										<input type="checkbox" class="episode_checkbox" <?php 
            checked(isset($migration_settings['episodes'][$episode_post->ID]) || !isset($migration_settings['episodes']));
            ?>
 name="podlove_migration[episodes][<?php 
            echo $episode_post->ID;
            ?>
]">
									</td>
									<td>
										<?php 
            echo $episode_post->ID;
            ?>
									</td>
									<td>
										<a href="<?php 
            echo get_edit_post_link($episode_post->ID);
            ?>
" target="_blank">
							 				<?php 
            echo get_the_title($episode_post->ID);
            ?>
										</a>
									</td>
								</tr>
								<tr>
									<td colspan="2"></td>
									<td>
										<table class="table table-condensed table-bordered">
											<tr>
												<th>Post Slug</th>
												<td class="slug">
													<?php 
            $slugs = array('wordpress' => $episode_post->post_name, 'file' => Assistant::get_file_slug($episode_post), 'number' => Assistant::get_number_slug($episode_post));
            foreach ($slugs as $slug_key => $slug_value) {
                $class = $post_slug_type == $slug_key ? '' : 'hidden';
                echo "<span class='{$slug_key} {$class}'>" . $slug_value . "</span>";
            }
            ?>
												</td>
											</tr>
											<tr>
												<th>Subtitle</th>
												<td><?php 
            echo $post_data->get_subtitle();
            ?>
</td>
											</tr>
											<tr>
												<th>Summary</th>
												<td><?php 
            echo $post_data->get_summary();
            ?>
</td>
											</tr>
											<tr>
												<th>Duration</th>
												<td><?php 
            echo $post_data->get_duration();
            ?>
</td>
											</tr>
											<tr>
												<th>Episode Media File Slug</th>
												<td><?php 
            echo Assistant::get_file_slug($episode_post);
            ?>
</td>
											</tr>
											<tr>
												<th>Assets</th>
												<td>
													<table class="table table-condensed table-bordered migration_assets" style="margin-bottom:0">
														<?php 
            foreach ($file_types as $file_type) {
                ?>
															<?php 
                $is_asset_active = isset($migration_settings['file_types'][$file_type['file_type']->id]);
                $asset_name = $file_type['file_type']->name;
                $asset_url = sprintf("%s%s.%s", \Podlove\Modules\Migration\get_media_file_base_url(), Assistant::get_episode_slug($episode_post, $slug_type), $file_type['file_type']->extension);
                $status = 'unknown';
                if (isset($validation_cache[$asset_url])) {
                    $status = $validation_cache[$asset_url] ? 'success' : 'failure';
                }
                ?>
															<tr data-filetype-id="<?php 
                echo $file_type['file_type']->id;
                ?>
" <?php 
                echo !$is_asset_active ? 'class="hidden"' : '';
                ?>
>
																<td>
																	<?php 
                echo $asset_name;
                ?>
																</td>
																<td>
																	<?php 
                echo sprintf('<a href="%s" target="_blank">%s</a>', $asset_url, Assistant::get_episode_slug($episode_post, $slug_type) . '.' . $file_type['file_type']->extension);
                ?>
																	<div class="update pull-right">
																		<div style="display: none">
																			updating ...
																		</div>
																		<div>
																			<button class="button verify_migration_asset <?php 
                echo $status != 'unknown' ? 'visited' : '';
                ?>
">verify</button>
																		</div>
																	</div>
																	<div class="status pull-right">
																		<div class="success" <?php 
                echo $status == 'success' ? '' : 'style="display: none"';
                ?>
>
																			<i class="podlove-icon-ok"></i>
																		</div>
																		<div class="failure" <?php 
                echo $status == 'failure' ? '' : 'style="display: none"';
                ?>
>
																			<i class="podlove-icon-remove"></i>
																		</div>
																	</div>
																</td>
															</tr>
														<?php 
            }
            ?>
													</table>
												</td>
											</tr>
										</table>
									</td>
								</tr>
							<?php 
        }
        ?>
						</tbody>
					</table>

					<style type="text/css">
					.migration_assets .update, .migration_assets .status {
						margin-left: 10px;
					}
					</style>

					<script type="text/javascript">
					jQuery(function($) {
						var episodes_to_check = $(".migration_assets").length;

						$("#toggle_all_episodes").on("click", function() {
							var checked = $(this).attr("checked") == "checked";
							$("#episodes_to_migrate input[type='checkbox']").attr("checked", checked);
							podlove_migration_update_progress_bar();
						});

						$(".verify_migration_asset").on("click", function(e) {
							e.preventDefault();
							podlove_validate_one_asset($(this), false);
							return false;
						});

						$(".episode_checkbox").on("click", function() {
							podlove_migration_update_progress_bar();
						});

						$(".asset_checkbox").on("click", function(){
							var checked = $(this).prop("checked"),
							    filetype_id = $(this).data("filetype-id");

							if (checked) {
								$('.migration_assets tr[data-filetype-id="' + filetype_id + '"]').removeClass("hidden");
							} else {
								$('.migration_assets tr[data-filetype-id="' + filetype_id + '"]').addClass("hidden");
							}

							$.ajax({
								url: ajaxurl,
								data: {
									action: 'podlove-update-migration-settings',
									file_types: [ filetype_id, checked ]
								},
								dataType: 'json'
							});

							podlove_migration_update_progress_bar();
						});

						$("#post_slug_select input").on("click", function(){
							var slug_type = $(this).val();

							$(".slug span." + slug_type).removeClass("hidden");
							$(".slug span:not(." + slug_type + ")").addClass("hidden");

							$.ajax({
								url: ajaxurl,
								data: {
									action: 'podlove-update-migration-settings',
									post_slug: slug_type
								},
								dataType: 'json'
							});
						});

						$("#cleanup_settings .enclosures input").on("click", function(){
							$.ajax({
								url: ajaxurl,
								data: {
									action: 'podlove-update-migration-settings',
									cleanup: [ 'enclosures', $(this).val() ]
								},
								dataType: 'json'
							});
						});

						$("#cleanup_settings .player input").on("click", function(){
							$.ajax({
								url: ajaxurl,
								data: {
									action: 'podlove-update-migration-settings',
									cleanup: [ 'player', $(this).val() ]
								},
								dataType: 'json'
							});
						});

						$("#cleanup_settings .template input").on("click", function(){
							$.ajax({
								url: ajaxurl,
								data: {
									action: 'podlove-update-migration-settings',
									cleanup: [ 'template', $(this).val() ]
								},
								dataType: 'json'
							});
						});

						function podlove_validate_one_asset(button, continue_validation) {

							var container = button.closest("tr"),
							    file_url  = container.find("a").attr("href");

							if (!file_url) 
								return;

							var data = {
								action: 'podlove-validate-url',
								file_url: file_url
							};

							// toggle status
							container.find('.update div').toggle();

							// mark button as once clicked
							button.addClass("visited");

							$.ajax({
								url: ajaxurl,
								data: data,
								dataType: 'json',
								success: function(result) {
									if ( result.file_size > 0) {
										$('.success', container).show();
										$('.failure', container).hide();
									} else {
										$('.success', container).hide();
										$('.failure', container).show();
									}
									container.find('.update div').toggle();
									podlove_migration_update_progress_bar();

									if (continue_validation) {
										podlove_validate_one_asset($(".verify_migration_asset:not(.visited):first"), true);
									}
								}
							});
						}

						$(document).ready(function(){
							podlove_validate_one_asset($(".verify_migration_asset:not(.visited):first"), true);
						});

						function podlove_migration_update_progress_bar() {

							var all_valid = 0,
							    some_valid = 0,
							    none_valid = 0;

							$('.episode_checkbox').filter(":checked").closest("tr").next().find(".migration_assets")
								.each(function(){
								var visible_tr = $("tr:not(.hidden)", this),
									successes  = $(".success", visible_tr).filter(":visible").length,
								    failures   = $(".failure", visible_tr).filter(":visible").length;

								if (successes + failures === $(".status", visible_tr).length) {
									if (successes > 0 && failures > 0) {
										some_valid++;
									} else if (failures > 0) {
										none_valid++;
									} else if (successes > 0) {
										all_valid++;
									}
								}
							});

							console.log(all_valid,some_valid,none_valid);

							var success_percent = Math.round(all_valid / episodes_to_check * 10000) / 100,
							    warning_percent = Math.round(some_valid / episodes_to_check * 10000) / 100,
							    failed_percent = Math.round(none_valid / episodes_to_check * 10000) / 100;

							if (success_percent + warning_percent + failed_percent > 100) {
								success_percent -= 0.01;
								warning_percent -= 0.01;
								failed_percent  -= 0.01;
							}

							if (success_percent > 0) {
							    $("#verification-status .bar-success")
							    	.css("width", success_percent + "%")
							    	.html(all_valid)
							    	.show();
							} else {
								$("#verification-status .bar-success").hide();
							}

							if (warning_percent > 0) {
						    	$("#verification-status .bar-warning")
							    	.css("width", warning_percent + "%")
							    	.html(some_valid)
							    	.show();
							} else {
								$("#verification-status .bar-warning").hide();
							}

							if (failed_percent > 0) {
						    	$("#verification-status .bar-danger")
							    	.css("width", failed_percent + "%")
							    	.html(none_valid)
							    	.show();
							} else {
								$("#verification-status .bar-danger").hide();
							}

							if (!success_percent && !warning_percent && !failed_percent) {
						    	$("#verification-status .bar-danger")
							    	.css("width", "100%").html(episodes_to_check).show();
							}
						};
						
						podlove_migration_update_progress_bar();
					});
					</script>

					<input type="submit" name="prev" class="btn" value="<?php 
        echo __('Back', 'podlove');
        ?>
">
					<input type="submit" name="next" class="btn btn-primary pull-right" value="<?php 
        echo __('Continue to Migration', 'podlove');
        ?>
">
					
				</form>
			</div>
		</div>
		<?php 
        // Restore original Query & Post Data
        wp_reset_query();
        wp_reset_postdata();
    }