Example #1
0
    /**
     * Adds Meta box html
     * 
     * @param <WP_Post> $object 
     * @param <mixed> $box 
     * 
     * @return <mixed>
     */
    public static function addLibsynPostMeta($object, $box)
    {
        wp_nonce_field(basename(__FILE__), 'libsyn_post_episode_nonce');
        echo "<link type='text/css' rel='stylesheet' href='" . plugins_url(LIBSYN_DIR . '/lib/css/libsyn_meta_form.css') . "' />";
        $plugin = new Service();
        $api = $plugin->getApis();
        /* Handle saved api */
        $render = false;
        //default rendering to false
        $refreshTokenProblem = false;
        if ($api instanceof \Libsyn\Api && !$api->isRefreshExpired()) {
            $render = true;
            if (!current_user_can('upload_files') || !current_user_can('edit_posts')) {
                $render = false;
            }
            //check logged in user privileges.
            $refreshApi = $api->refreshToken();
            if ($refreshApi) {
                //successfully refreshed
                $api = $api->retrieveApiById($api->getPluginApiId());
            } else {
                $render = false;
                $refreshTokenProblem = true;
            }
        } elseif ($api->isRefreshExpired()) {
            $render = false;
        }
        if ($api instanceof Libsyn\Api) {
            $render = true;
        }
        $isPowerpress = \Libsyn\Service\Integration::getInstance()->checkPlugin('powerpress');
        ?>
		<?php 
        wp_enqueue_script('jquery-ui-dialog', array('jquery-ui'));
        ?>
		<?php 
        wp_enqueue_style('wp-jquery-ui-dialog');
        ?>
		<?php 
        //wp_enqueue_script( 'libsyn-playlist-post-page', plugins_url(LIBSYN_DIR.'/lib/js/libsyn_playlist_post_page.js'));
        ?>
		<?php 
        wp_enqueue_script('libsyn-player-settings-post-page', plugins_url(LIBSYN_DIR . '/lib/js/libsyn_player_settings_post_page.js'));
        ?>
		<?php 
        if ($render) {
            ?>
		<?php 
            wp_enqueue_script('jquery-filestyle', plugins_url(LIBSYN_DIR . '/lib/js/jquery-filestyle.min.js'));
            ?>
		<?php 
            wp_enqueue_style('jquery-filestyle', plugins_url(LIBSYN_DIR . '/lib/css/jquery-filestyle.css'));
            ?>
		<?php 
            wp_enqueue_style('jquery-simplecombobox', plugins_url(LIBSYN_DIR . '/lib/css/jquery.libsyn-scombobox.min.css'));
            ?>
		<?php 
            wp_enqueue_script('jquery-simplecombobox', plugins_url(LIBSYN_DIR . '/lib/js/jquery.libsyn-scombobox.min.js'));
            ?>
		<?php 
            wp_enqueue_style('metaForm', '/wp-content/plugins/' . LIBSYN_DIR . '/lib/css/libsyn_meta_boxes.css');
            ?>

		<div id="libsyn-playlist-page-dialog" class="hidden" title="Create Podcast Playlist">
			<p>
				<span style="font-weight:bold;">Playlist Type:</span><br>
				<input type="radio" name="playlist-media-type" value="audio" id="playlist-media-type-audio" checked="checked">Audio
				<input type="radio" name="playlist-media-type" value="video" id="playlist-media-type-video">Video
				<div style="padding:5px;display:none;" id="playlist-dimensions-div">
					<label for="playlist-video-width">Width </label>
					<input name="playlist-video-width" id="playlist-video-width" type="text" value="640">
					<br>
					<label for="playlist-video-height">Height</label>
					<input name="playlist-video-height" id="playlist-video-height" type="text" value="360">
				</div>
				<br><span style="font-weight:bold;">Playlist Source:</span><br>
				<input type="radio" name="playlist-feed-type" value="<?php 
            if (isset($api) && $api !== false) {
                _e("libsyn-podcast-" . $api->getShowId());
            } else {
                _e("my-podcast");
            }
            ?>
" id="my-podcast" checked="checked">My Libsyn Podcast
				<br>
				<input type="radio" name="playlist-feed-type" value="other-podcast" id="other-podcast">Other Podcast
				<label for="<?php 
            _e('podcast-url', 'playlist-dialog');
            ?>
"><?php 
            _e('Podcast Url:');
            ?>
</label>
				<input class="widefat" id="<?php 
            _e("podcast-url", 'playlist-dialog');
            ?>
" name="<?php 
            _e("podcast-url", 'playlist-dialog');
            ?>
" type="text" value="<?php 
            _e(esc_attr(get_post_meta($object->ID, 'playlist-podcast-url', true)));
            ?>
" type="url" style="display:none;" class="other-url" placeholder="http://www.your-wordpress-site.com/rss">
			</p>
		</div>
		<div id="libsyn-player-settings-page-dialog" class="hidden" title="Playlist Settings"></div>
		<?php 
            //handle post error message
            //remove post error if any
            $error = get_post_meta($object->ID, 'libsyn-post-error', true);
            if ($error == 'true') {
                add_filter('post_updated_messages', function ($messages) {
                    $messages['post'][2] = "There was an error posting content, please check settings and try again.";
                    return $messages;
                });
            }
            delete_post_meta($object->ID, 'libsyn-post-error', 'true', true);
            ?>
		<script type="text/javascript">
			(function ($){
				$(document).ready(function() {
					
					window.libsyn_site_url = "<?php 
            _e(get_site_url());
            ?>
";
					window.libsyn_data_id =  '<?php 
            _e($object->ID);
            ?>
';
					
					if("<?php 
            _e($refreshTokenProblem);
            ?>
" == "true") {
						$('.api-problem-box').fadeIn('normal');
						$('.libsyn-post-form').hide();
					}
					var data = '<?php 
            _e($object->ID);
            ?>
';
					$('.loading-libsyn-form').fadeIn('normal');
					$('.libsyn-post-form').hide();
					$.ajax({
						url: '<?php 
            _e(get_site_url() . '/?load_libsyn_media=1');
            ?>
',
						type: 'POST',
						data: data,
						cache: false,
						dataType: 'json',
						processData: false, // Don't process the files
						contentType: false, // Set content type to false as jQuery will tell the server its a query string request
						success: function(data, textStatus, jqXHR) {
							 if(!data) {
								//Handle errors here
								$('.loading-libsyn-form').hide();
								$('.api-problem-box').fadeIn('normal');
							 } else if(typeof data.error == 'undefined') { //Successful response
								
								//remove ftp/unreleased
								$.ajax({
									url : window.libsyn_site_url + "/?remove_ftp_unreleased=1",
									type: 'POST',
									data: data,
									cache: false,
									dataType: 'json',
									processData: false, // Don't process the files
									contentType: false, // Set content type to false as jQuery will tell the server its a query string request
									success : function(data) {          
										console.log('remove fired! ' + data);
									},
									error : function(request,error)
									{
										//error
										//alert("Request: "+JSON.stringify(request));
									}
								});
								
								//show div & hide spinner
								$('.loading-libsyn-form').hide();
								$('.libsyn-post-form').fadeIn('normal');								
								$("#libsyn-categories").empty();
								
								
								//handle categories section
								for(i = 0; i < data.length; i++) {
									if(i==0) { var firstValue = data[i]; }
									$("#libsyn-categories").append("<option value=\"" + data[i] + "\">" + data[i] + "</option>");
								}

								var savedCategory = "<?php 
            echo esc_attr(get_post_meta($object->ID, 'libsyn-post-episode-category-selection', true));
            ?>
";
								if(savedCategory.length > 0) var firstValue = savedCategory;
								//$("#libsyn-post-episode-category-selection").val(firstValue);
								$("#libsyn-categories").scombobox({
									highlight: true,
									highlightInvalid: false
								});
								$("#libsyn-post-episode-category-selection").attr({'class': 'scombobox-value'}).appendTo($("#libsyn-categories"));
								$("input.scombobox-display").val(firstValue);
								$('.scombobox-value[name=libsyn-post-episode-category]').val(firstValue);
								
								
								$("#libsyn-categories").scombobox('change', function() {
									<?php 
            /*
            $("#libsyn-categories .scombobox-value").val($("#libsyn-categories .scombobox-display").val());
            console.log("change fired");
            console.log("whole val: " + $("#libsyn-categories").scombobox("val"));
            console.log("text val: " + $("#libsyn-categories .scombobox-display").val());
            */
            ?>
									$("#libsyn-post-episode-category-selection").val($("#libsyn-categories .scombobox-display").val());
									
								/*	$("#libsyn-post-episode-category-selection").val($("#libsyn-categories .scombobox-display").val());
									//console.log($("#libsyn-categories").scombobox('val'), $(this).val(), $("#libsyn-post-episode-category-selection").val(), $('#libsyn-categories').children('.scombobox-display').val()); */
								});
																
								$('#libsyn-categories').children('.scombobox-display').focus(function(){
									$(this).css({'border': '1px solid #60a135'});
									$('.scombobox-dropdown-background').css({'border-color': '#60a135 #60a135 #60a135 -moz-use-text-color', 'border': '1px solid #60a135'});
								}).on("blur", function() {
									$(this).css({'border': '1px solid #CCC'});
									$('.scombobox-dropdown-background').css({'border': '1px solid #CCC', 'border-color': '#ccc #ccc #ccc -moz-use-text-color'});
									var currVal = $("#libsyn-categories .scombobox-display").val();
									var sel = $('#libsyn-categories select');
									var opt = $('<option>').attr('value', currVal).html(currVal);
									sel.append(opt);
								});

							 } else {
								//Handle errors here
								$('.loading-libsyn-form').hide();
								$('.libsyn-post-form').fadeIn('normal');
								$('.options-error').fadeIn('normal');
								//$('.api-problem-box').fadeIn('normal');
							 }
						},
						error: function(jqXHR, textStatus, errorThrown) {
							// Handle errors here
							$('.loading-libsyn-form').hide();
							$('.configuration-problem').fadeIn('normal');
						}
					});
										
					//Load Player Settings
					$("#libsyn-player-settings-page-dialog").load("<?php 
            _e(get_site_url());
            ?>
/wp-content/plugins/<?php 
            _e(LIBSYN_DIR);
            ?>
/admin/views/box_playersettings.php", function() {
						//add stuff to ajax box
						$("#player_use_theme_standard_image").append('<img src="<?php 
            _e(get_site_url());
            ?>
/wp-content/plugins/<?php 
            _e(LIBSYN_DIR);
            ?>
/lib/images/player-preview-standard.jpg">');
						$("#player_use_theme_mini_image").append('<img src="<?php 
            _e(get_site_url());
            ?>
/wp-content/plugins/<?php 
            _e(LIBSYN_DIR);
            ?>
/lib/images/player-preview-standard-mini.jpg">');
						$(".post-position-shape-top").append('<img src="<?php 
            _e(get_site_url());
            ?>
/wp-content/plugins/<?php 
            _e(LIBSYN_DIR);
            ?>
/lib/images/player_position.png" style="vertical-align:top;">');
						$(".post-position-shape-bottom").append('<img src="<?php 
            _e(get_site_url());
            ?>
/wp-content/plugins/<?php 
            _e(LIBSYN_DIR);
            ?>
/lib/images/player_position.png" style="vertical-align:top;">');
						
						//validate button
						$('<a>').text('Validate').attr({
							class: 'button'
						}).click( function() {
							var current_feed_redirect_input = validator_url + encodeURIComponent($("#feed_redirect_input").attr('value'));
							window.open(current_feed_redirect_input);
						}).insertAfter("#feed_redirect_input");
						
						//set default value for player use thumbnail
						<?php 
            $postPlayerUseThumbnail = get_post_meta($object->ID, 'libsyn-post-episode-player_use_thumbnail', true);
            $playerUseThumbnail = !is_null($postPlayerUseThumbnail) && !empty($postPlayerUseThumbnail) ? $postPlayerUseThumbnail : get_option('libsyn-podcasting-player_use_thumbnail');
            ?>
						var playerUseThumbnail = '<?php 
            _e($playerUseThumbnail);
            ?>
';
						if(playerUseThumbnail == 'use_thumbnail') {
							$('#player_use_thumbnail').attr('checked', true);
						}
						
						//set default value of player theme
						<?php 
            $postPlayerTheme = get_post_meta($object->ID, 'libsyn-post-episode-player_use_theme', true);
            $playerTheme = !is_null($postPlayerTheme) && !empty($postPlayerTheme) ? $postPlayerTheme : get_option('libsyn-podcasting-player_use_theme');
            ?>
						var playerTheme = '<?php 
            _e($playerTheme);
            ?>
';
						if(playerTheme == 'standard') {
							$('#player_use_theme_standard').attr('checked', true);	
							//check if player_use_thumbnail is checked
							if($('#player_use_thumbnail').is(':checked')) {
								if(parseInt($('#player_height').val()) < 200) $('#player_height').val(200);
							} else {
								$('#player_height').attr({"min": "45"});
								if(parseInt($('#player_height').val()) < 45) $('#player_height').val(45);
							}						
						} else if(playerTheme == 'mini') {
							$('#player_use_theme_mini').attr('checked', true);	
							//check if player_use_thumbnail is checked
							if($('#player_use_thumbnail').is(':checked')) {
								if(parseInt($('#player_height').val()) < 200) $('#player_height').val(200);
							} else {
								$('#player_height').attr({"min": "26"});
								if(parseInt($('#player_height').val()) < 26) $('#player_height').val(26);
							}						
						} else { //default: getPlayerTheme is not set
							//set default value of player theme to standard if not saved
							$('#player_use_theme_standard').attr('checked', true);						
							//check if player_use_thumbnail is checked
							if($('#player_use_thumbnail').is(':checked')) {
								if(parseInt($('#player_height').val()) < 200) $('#player_height').val(200);
							} else {
								$('#player_height').attr({"min": "45"});
								if(parseInt($('#player_height').val()) < 45) $('#player_height').val(45);
							}
						}
						
						//player theme checkbox settings
						$('#player_use_theme_standard').change(function() {
							if($('#player_use_theme_standard').is(':checked')) {
								//check if player_use_thumbnail is checked
								if($('#player_use_thumbnail').is(':checked')) {
									if(parseInt($('#player_height').val()) < 200) $('#player_height').val(200);
								} else {
									$('#player_height').attr({"min": "45"});
									if(parseInt($('#player_height').val()) < 45) $('#player_height').val(45);
								}							
							} else if($('#player_use_theme_mini').is(':checked')) {
								//check if player_use_thumbnail is checked
								if($('#player_use_thumbnail').is(':checked')) {
									if(parseInt($('#player_height').val()) < 200) $('#player_height').val(200);
								} else {
									$('#player_height').attr({"min": "26"});
									if(parseInt($('#player_height').val()) < 26) $('#player_height').val(26);
								}
							}
						});
						$('#player_use_theme_mini').change(function() {
							if($('#player_use_theme_standard').is(':checked')) {
								//check if player_use_thumbnail is checked
								if($('#player_use_thumbnail').is(':checked')) {
									if(parseInt($('#player_height').val()) < 200) $('#player_height').val(200);
								} else {
									$('#player_height').attr({"min": "45"});
									if(parseInt($('#player_height').val()) < 45) $('#player_height').val(45);
								}							
							} else if($('#player_use_theme_mini').is(':checked')) {
								//check if player_use_thumbnail is checked
								if($('#player_use_thumbnail').is(':checked')) {
									if(parseInt($('#player_height').val()) < 200) $('#player_height').val(200);
								} else {
									$('#player_height').attr({"min": "26"});
									if(parseInt($('#player_height').val()) < 26) $('#player_height').val(26);
								}
							}
						});
						
						//player values height & width
						<?php 
            $postPlayerHeight = get_post_meta($object->ID, 'libsyn-post-episode-player_height', true);
            $playerHeight = !is_null($postPlayerHeight) && !empty($postPlayerHeight) ? $postPlayerHeight : get_option('libsyn-podcasting-player_height');
            ?>
						<?php 
            $postPlayerWidth = get_post_meta($object->ID, 'libsyn-post-episode-player_width', true);
            $playerWidth = !is_null($postPlayerWidth) && !empty($postPlayerWidth) ? $postPlayerWidth : get_option('libsyn-podcasting-player_width');
            ?>
						var playerHeight = parseInt('<?php 
            _e($playerHeight);
            ?>
');
						var playerWidth = parseInt('<?php 
            _e($playerWidth);
            ?>
');
						
						//height
						if(isNaN(playerHeight)) {
							$('#player_height').val(360);
						} else {
							if($('#player_use_theme_standard').is(':checked')) {
								if(playerHeight >= 45) $('#player_height').val(playerHeight);
									else $('#player_height').val(45);
							} else if($('#player_use_theme_mini').is(':checked')) {
								if(playerHeight >= 26) $('#player_height').val(playerHeight);
									else $('#player_height').val(26);
							} else {
								$('#player_height').val(360);
							}
						}
						
						//width
						if(isNaN(playerWidth)) {
							$('#player_width').val(480);
						} else {
							if($('#player_use_theme_standard').is(':checked')) {
								if(playerWidth >= 200) $('#player_width').val(playerWidth);
									else $('#player_width').val(200);
							} else if($('#player_use_theme_mini').is(':checked')) {
								if(playerWidth >= 100) $('#player_width').val(playerWidth);
									else $('#player_width').val(100);
							} else {
								$('#player_width').val(480);
							}
						}
						
						//player use thumbnail checkbox settings
						$('#player_use_thumbnail').change(function() {
							if($(this).is(':checked')) {
								if($('#player_height').val() == '' || parseInt($('#player_height').val()) <= 200) { //below min height
									$('#player_height').val("200");
									$('#player_height').attr({"min": "200"});
								}
							} else {
								if($('#player_use_theme_standard').is(':checked')) {
									$('#player_height').attr({"min": "45"});
								} else if($('#player_use_theme_mini').is(':checked')){
									$('#player_height').attr({"min": "26"});
								}
								
							}
						});
						
						//player placement checkbox settings
						<?php 
            $postPlayerPlacement = get_post_meta($object->ID, 'libsyn-post-episode-player_placement', true);
            $playerPlacement = !is_null($postPlayerPlacement) && !empty($postPlayerPlacement) ? $postPlayerPlacement : get_option('libsyn-podcasting-player_placement');
            ?>
						var playerPlacement = '<?php 
            _e($playerPlacement);
            ?>
';
						if(playerPlacement == 'top') {
							$('#player_placement_top').attr('checked', true);
						} else if(playerPlacement == 'bottom') {
							$('#player_placement_bottom').attr('checked', true);
						} else { //player placement is not set
							$('#player_placement_top').attr('checked', true);
						}
						
						
					});
		
					$( "#libsyn-upload-media-dialog" ).dialog({
						autoOpen: false,
						draggable: false,
						height: 'auto',
						width: 500,
						modal: true,
						resizable: false,
						open: function(){
							$('.ui-widget-overlay').bind('click',function(){
								$('#libsyn-upload-media-dialog').dialog('close');
							})
						},
						buttons: [
							{
								id: "dialog-button-cancel",
								text: "Cancel",
								click: function(){
									$('#libsyn-upload-media-dialog').dialog('close');
								}
							},
							{
								id: "dialog-button-upload",
								text: "Upload",
								class: "button-primary",
								click: function(){
									$('#dialog-button-upload').attr("disabled", true);
									$('.upload-error-dialog').empty().append('<img id="upload-dialog-spinner" src="<?php 
            _e(plugins_url(LIBSYN_DIR . '/lib/images/upload-spinner.gif'));
            ?>
"></img>').fadeIn('normal');
									var dlg = $(this);
									var url = "<?php 
            _e($plugin->getApiBaseUri() . '/media');
            ?>
";
									var mediaUploadForm = new FormData();
									mediaUploadForm.append('show_id', '<?php 
            if (isset($api)) {
                _e($api->getShowId());
            }
            ?>
');
									mediaUploadForm.append('form_access_token', '<?php 
            if (isset($api)) {
                _e($api->getAccessToken());
            }
            ?>
');
									mediaUploadForm.append('upload', $('#libsyn-media-file-upload')[0].files[0]);
									$.ajax({
										url: url,
										type: 'POST',
										data: mediaUploadForm,
										processData: false,
										contentType: false,
										success: function (response, textStatus, xhr) {
												$("#libsyn-new-media-media").val("libsyn-upload-" + response._embedded.media.content_id).attr("readonly", true);
												dlg.dialog('close');
												//dlg.empty();
										},
										 error: function (xhr, status, error) {
											if(xhr.responseJSON.validation_messages.upload.length >= 0) {
												var stringError = xhr.responseJSON.validation_messages.upload;
												$('.upload-error-dialog').empty().append(
													"Error Uploading:  " + xhr.responseJSON.validation_messages.upload
												);
											} else {
												$('.upload-error-dialog').empty().append("Error Uploading:  " + error);
											}
											//$('.upload-error').fadeIn('normal');
											
											$('#upload-dialog-spinner').hide();
											$('#dialog-button-upload').attr("disabled", false);
											$('.upload-error-dialog').fadeIn('normal');
										}
									});
								}
							}
						]
					});	
					$( "#libsyn-upload-asset-dialog" ).dialog({
						autoOpen: false,
						draggable: false,
						height: 'auto',
						width: 'auto',
						modal: true,
						resizable: false,
						open: function(){
							$('.ui-widget-overlay').bind('click',function(){
								$('#libsyn-upload-asset-dialog').dialog('close');
							})
						},
						buttons: [
							{
								id: "dialog-button-cancel",
								text: "Cancel",
								click: function(){
									$('#libsyn-upload-asset-dialog').dialog('close');
								}
							}
						]
					});

					$('#libsyn-upload-media').click(function(event) {
						event.preventDefault();
						$("#libsyn-upload-media-dialog").dialog( "open" );
					});
					
					$('#libsyn-clear-media-button').click(function(event) {
						event.preventDefault();
						$("#libsyn-new-media-media").val('').attr('readonly', false);
					});
					
					$('#libsyn-clear-image-button').click(function(event) {
						event.preventDefault();
						$("#libsyn-new-media-image").val('').attr('readonly', false);
					});
					
					//set tvrating
					if("<?php 
            _e(esc_attr(get_post_meta($object->ID, 'libsyn-post-episode-tvrating', true)));
            ?>
" != "")
						$("#libsyn-post-episode-tvrating").val("<?php 
            _e(esc_attr(get_post_meta($object->ID, 'libsyn-post-episode-tvrating', true)));
            ?>
");
					if("<?php 
            _e(esc_attr(get_post_meta($object->ID, 'libsyn-post-episode-itunes', true)));
            ?>
" != "")
						$("#libsyn-post-episode-itunes").val("<?php 
            _e(esc_attr(get_post_meta($object->ID, 'libsyn-post-episode-itunes', true)));
            ?>
");
					if("<?php 
            _e(esc_attr(get_post_meta($object->ID, 'libsyn-post-episode', true)));
            ?>
" == "isLibsynPost")
						$("#libsyn-post-episode").prop("checked", true);
					

		
				});
			}) (jQuery);		
		</script>
		<?php 
        }
        ?>
		<div class="loading-libsyn-form" style="background: url(<?php 
        _e(plugins_url(LIBSYN_DIR . '/lib/images/spinner.gif'));
        ?>
);background-repeat: no-repeat;background-position: left center;display: none;"><br><br><br><br>Loading...</div>
		<div class="configuration-problem" style="display: none;">
			<p>Please configure your <a href="<?php 
        _e(get_site_url());
        ?>
/wp-admin/admin.php?page=<?php 
        _e(LIBSYN_DIR);
        ?>
/admin/settings.php">Libsyn Podcast Plugin</a> with your Libsyn Hosting account to use this feature.</p>
		</div>
		<?php 
        if ($isPowerpress) {
            ?>
		<div class="configuration-problem-powerpress" style="border: 1px solid red;">
			<p style="color:red;font-weight:bold;padding-left:10px;">You Currently have 'Powerpress Plugin' installed.
			<br>Please visit the <a href="<?php 
            _e(get_site_url());
            ?>
/wp-admin/admin.php?page=<?php 
            _e(LIBSYN_DIR);
            ?>
/admin/settings.php">settings</a> and make any configuration changes before posting.  (note: The Libsyn plugin will conflict with this plugin)</p>
		</div>		
		<?php 
        }
        ?>
		<div class="api-problem-box" style="display: none;">
			<p> We encountered a problem with the Libsyn API.  Please Check your <a href="<?php 
        _e(get_site_url());
        ?>
/wp-admin/admin.php?page=<?php 
        _e(LIBSYN_DIR);
        ?>
/admin/settings.php">settings</a> and try again.</p>
		</div>
		<div class="libsyn-post-form">
			<table class="form-table">
				<tr valign="top">
					<p><strong><?php 
        echo __('The post title and post body above will be used for your podcast episode.', 'libsyn-nmp');
        ?>
</strong></p>
				</tr>
				<tr valign="top">
					  <?php 
        $isLibsynPostChecked = get_post_meta($object->ID, '_isLibsynPost', true) ? ' checked="checked"' : '';
        ?>
					  <th><label for="libsyn-post-episode"><?php 
        _e("Post Libsyn Episode", 'example');
        ?>
</label></th>
					  <td>
						<input type="checkbox" name="libsyn-post-episode" id="libsyn-post-episode" value="isLibsynPost" <?php 
        echo $isLibsynPostChecked;
        ?>
/>
					  </td>
				</tr>
				<tr valign="top">
					  <th><?php 
        _e("Episode Media*", 'libsyn-post-episode-media');
        ?>
</th>
					  <td>
						<div id="libsyn-primary-media-settings">
							<div id="libsyn-new-media-settings">
								<div class="upload-error" style="display:none;color:red;font-weight:bold;">There was an error uploading media, please check settings and try again.</div>
								<p><?php 
        echo __('Select Primary Media for Episode by clicking the button below.', 'libsyn-nmp');
        ?>
</p>
								<p>
									<button class="button button-primary" id="libsyn-upload-media" title="<?php 
        echo esc_attr__('Click here to upload media for episode', 'libsyn-nmp');
        ?>
"><?php 
        echo __('Upload Media', 'libsyn-nmp');
        ?>
</button>
									<a href="#" class="libsyn-open-media button button-primary" title="<?php 
        echo esc_attr__('Click Here to Open the Media Manager', 'libsyn-nmp');
        ?>
"><?php 
        echo __('Select Wordpress Media', 'libsyn-nmp');
        ?>
</a>
									<a href="#" class="libsyn-open-ftp_unreleased button button-primary" title="<?php 
        echo esc_attr__('Click Here to Open the Media Manager', 'libsyn-nmp');
        ?>
"><?php 
        echo __('Select ftp/unreleased', 'libsyn-nmp');
        ?>
</a>
								</p>
								<p>
								<?php 
        $libsyn_media_media = get_post_meta($object->ID, 'libsyn-new-media-media', true);
        ?>
								<label for="libsyn-new-media-media"><?php 
        echo __('Media Url', 'libsyn-nmp');
        ?>
</label> <input type="url" id="libsyn-new-media-media" name="libsyn-new-media-media" size="70" value="<?php 
        echo esc_attr($libsyn_media_media);
        ?>
" pattern="https?://.+" <?php 
        if (isset($libsyn_media_media) && !empty($libsyn_media_media)) {
            echo 'readonly';
        }
        ?>
/>
								<button class="button" id="libsyn-clear-media-button" title="<?php 
        echo esc_attr__('Clear primary media', 'libsyn-nmp');
        ?>
"><?php 
        echo __('Clear', 'libsyn-nmp');
        ?>
</button>
								</p>
							</div>
							<div id="libsyn-upload-media-dialog" class="hidden" title="Upload Media">
								<h3>Select Media to upload:</h3>
								<input id="libsyn-media-file-upload" type="file" name="upload" class="jfilestyle" data-buttonText="Choose Media" data-size="300px">
								<div class="upload-error-dialog" style="display:none;color:red;font-weight:bold;"></div>
							</div>
						</div>
					  </td>
				</tr>
				<tr valign="top">
					  <th><?php 
        _e("Episode Subtitle", 'libsyn-post-episode-subtitle');
        ?>
</th>
					  <td>
						<div id="titlediv">
							<div id="titlewrap">
								<input id="libsyn-post-episode-subtitle" type="text" autocomplete="off" value="<?php 
        echo get_post_meta($object->ID, 'libsyn-post-episode-subtitle', true);
        ?>
" size="30" name="libsyn-post-episode-subtitle" style="width:100%;" maxlength="255">
							</div>
						</div>
					  </td>
				</tr>
				<tr valign="top">
					  <th><?php 
        _e("Episode Category*", 'libsyn-post-episode-category-selection');
        ?>
</th>
					  <td>
						<div id="titlediv">
							<div id="titlewrap">
								<!-- TODO: Change to selectable text for list of show's categories refer datalist-->
								<div class="options-error" style="display:none;color:red;font-weight:bold;">Could not populate categories, manually enter category.</div>
								<select id="libsyn-categories" name="libsyn-post-episode-category">
									<option value="general">general</option>
								</select>
								<input type="hidden" value="<?php 
        echo get_post_meta($object->ID, 'libsyn-post-episode-category-selection', true);
        ?>
" name="libsyn-post-episode-category-selection" id="libsyn-post-episode-category-selection" />
							</div>
						</div>
					  </td>
				</tr>		
				<tr valign="top">
					  <th><?php 
        _e("Episode Thumbnail", 'libsyn-post-episode-media');
        ?>
</th>
					  <td>
						<div id="libsyn-primary-media-settings">
							<div id="libsyn-new-media-settings">
								<p><?php 
        echo __('Select image for episode thumbnail by clicking the button below.', 'libsyn-nmp');
        ?>
</p>
								<p>
								<?php 
        $libsyn_episode_thumbnail = esc_attr(get_post_meta($object->ID, 'libsyn-new-media-image', true));
        ?>
								<a href="#" class="libsyn-open-image button button-primary" title="<?php 
        echo esc_attr__('Click Here to Open the Image Manager', 'libsyn-nmp');
        ?>
"><?php 
        echo __('Select Episode Thumbnail', 'libsyn-nmp');
        ?>
</a></p>
								<p><label for="libsyn-new-media-image"><?php 
        echo __('Media Url', 'libsyn-nmp');
        ?>
</label> <input type="url" id="libsyn-new-media-image" name="libsyn-new-media-image" size="70" value="<?php 
        echo !empty($libsyn_episode_thumbnail) ? $libsyn_episode_thumbnail : '';
        ?>
" pattern="https?://.+" <?php 
        if (isset($libsyn_episode_thumbnail) && !empty($libsyn_episode_thumbnail)) {
            echo 'readonly';
        }
        ?>
/>
								<button class="button" id="libsyn-clear-image-button" title="<?php 
        echo esc_attr__('Clear image url', 'libsyn-nmp');
        ?>
"><?php 
        echo __('Clear', 'libsyn-nmp');
        ?>
</button>
								</p>
							</div>
							<div id="libsyn-upload-asset-dialog" class="hidden" title="Upload Image">
								<p>Select Image to upload:</p>
								<br>
							</div>
						</div>
					  </td>	
				</tr>
				<tr valign="top">
					  <th><?php 
        _e("Tags/Keywords", 'libsyn-post-episode-keywords');
        ?>
</th>
					  <td>
						<div id="titlediv">
							<div id="titlewrap">
								<input id="libsyn-post-episode-keywords" type="text" autocomplete="off" value="<?php 
        echo get_post_meta($object->ID, 'libsyn-post-episode-keywords', true);
        ?>
" size="30" name="libsyn-post-episode-keywords" style="width:100%;" maxlength="255" placeholder="keyword1, keyword2, keyword3">
							</div>
						</div>
					  </td>
				</tr>
				<tr valign="top">
					  <th><?php 
        _e("Rating", 'libsyn-post-episode-rating');
        ?>
</th>
					  <td>
						<div id="titlediv">
							<div id="titlewrap">
								<select id="libsyn-post-episode-itunes" name="libsyn-post-episode-itunes">
									<option value="no">Not Set</option>
									<option value="clean">Clean</option>
									<option value="yes">Explicit</option>
								</select>	
							</div>
						</div>
					  </td>
				</tr>
				<tr valign="top">
					  <th><?php 
        _e("TV Rating", 'libsyn-post-episode-rating');
        ?>
</th>
					  <td>
						<div id="titlediv">
							<div id="titlewrap">
								<select id="libsyn-post-episode-tvrating" name="libsyn-post-episode-tvrating">
									<option value="no">Not Set</option>
									<option value="TV-Y">TV-Y</option>
									<option value="TV-Y7">TV-Y7</option>
									<option value="TV-14">TV-14</option>
									<option value="TV-G">TV-G</option>
									<option value="TV-PG">TV-PG</option>
									<option value="TV-MA">TV-MA</option>
								</select>									
							</div>
						</div>
					  </td>
				</tr>
				<tr valign="top">
					  <th><?php 
        _e("TV Rating Contains", 'libsyn-post-episode-rating');
        ?>
</th>
					  <td>
						<div id="titlediv">
							<div id="titlewrap">
								
								<input type="checkbox" id="libsyn-post-episode-tvrating-contains-courseLanguage" name="libsyn-post-episode-tvrating-contains-courseLanguage" value="Course Language" <?php 
        if (self::checkFormItem($object->ID, 'tvrating-contains', 'courseLanguage')) {
            echo 'checked="checked"';
        }
        ?>
>Course Language<br>
								<input type="checkbox" id="libsyn-post-episode-tvrating-contains-sexualContent" name="libsyn-post-episode-tvrating-contains-sexualContent" value="Sexual Content" <?php 
        if (self::checkFormItem($object->ID, 'tvrating-contains', 'sexualContent')) {
            echo 'checked="checked"';
        }
        ?>
>Sexual Content<br>
								<input type="checkbox" id="libsyn-post-episode-tvrating-contains-suggestiveDialogue" name="libsyn-post-episode-tvrating-contains-suggestiveDialogue" value="Suggestive Dialogue" <?php 
        if (self::checkFormItem($object->ID, 'tvrating-contains', 'suggestiveDialogue')) {
            echo 'checked="checked"';
        }
        ?>
>Suggestive Dialogue<br>
								<input type="checkbox" id="libsyn-post-episode-tvrating-contains-violence" name="libsyn-post-episode-tvrating-contains-violence" value="Violence" <?php 
        if (self::checkFormItem($object->ID, 'tvrating-contains', 'violence')) {
            echo 'checked="checked"';
        }
        ?>
>Violence
							</div>
						</div>	
					  </td>
				</tr>
			
			</table>
		</div>
		</p>
		<?php 
    }
    /* Declare Plugin */
    $plugin = new \Libsyn\Service();
    $hasApi = $plugin->getApis();
    if ($hasApi !== false) {
        add_action('add_meta_boxes_post', 'add_libsyn_post_meta');
        add_action('save_post', '\\Libsyn\\Post::handlePost', 10, 2);
        add_filter('show_post_locked_dialog', '__return_false');
        \Libsyn\Post::actionsAndFilters();
    }
    //playlist
    // add_action( 'widgets_init', function(){
    // register_widget( 'Libsyn\PlaylistWidget' );
    // });
    //playlist ajax
    // add_filter('query_vars','Libsyn\\Playlist::plugin_add_trigger_load_libsyn_playlist');
    // add_action('template_redirect', 'Libsyn\\Playlist::loadLibsynPlaylist');
    // add_filter('query_vars','Libsyn\\Playlist::plugin_add_trigger_load_playlist');
    // add_action('template_redirect', 'Libsyn\\Playlist::loadPlaylist');
    //post form ajax
    add_filter('query_vars', 'Libsyn\\Post::plugin_add_trigger_load_form_data');
    add_action('template_redirect', 'Libsyn\\Post::loadFormData');
    //post form ajax
    add_filter('query_vars', 'Libsyn\\Post::plugin_add_trigger_remove_ftp_unreleased');
    add_action('template_redirect', 'Libsyn\\Post::removeFTPUnreleased');
    //shortcode embedding
    add_action('save_post', '\\Libsyn\\Playlist::playlistInit', 10, 2);
    add_shortcode('libsyn-playlist', '\\Libsyn\\Playlist::embedShortcode');
    /* Check Dependencies */
    \Libsyn\Service\Integration::getInstance()->checkPhpVersion();
    \Libsyn\Service\Integration::getInstance()->checkPlugin('powerpress');
}