<?php
/*
*	Euthemians Post Items
*
* 	@author		Euthemians Team
* 	@URI		http://euthemians.com
*/

	add_action( 'add_meta_boxes', 'engic_eutf_post_options_add_custom_boxes' );
	add_action( 'save_post', 'engic_eutf_post_options_save_postdata', 10, 2 );

	$engic_eutf_post_options = array (

		array(
			'name' => 'Post Layout',
			'id' => '_engic_eutf_layout',
		),
		array(
			'name' => 'Post Sidebar',
			'id' => '_engic_eutf_sidebar',
		),
		array(
			'name' => 'Sidebar Style',
			'id' => '_engic_eutf_sidebar_style',
		),
		array(
			'name' => 'Fixed Sidebar',
			'id' => '_engic_eutf_fixed_sidebar',
		),
		array(
			'name' => 'Disable Title',
			'id' => '_engic_eutf_disable_title',
		),
		array(
			'name' => 'Disable Meta Fields',
			'id' => '_engic_eutf_disable_meta_fields',
		),
		array(
			'name' => 'Disable Side Area',
			'id' => '_engic_eutf_disable_sidearea',
		),
		array(
			'name' => 'Disable Footer',
			'id' => '_engic_eutf_disable_footer',
		),
		array(
			'name' => 'Disable Media Area',
			'id' => '_engic_eutf_disable_media',
		),

		//Gallery Format
		array(
			'name' => 'Media Mode',
			'id' => '_engic_eutf_post_type_gallery_mode',
		),
		array(
			'name' => 'Media Image Mode',
			'id' => '_engic_eutf_post_type_gallery_image_mode',
		),
		//Link Format
		array(
			'name' => 'Link URL',
			'id' => '_engic_eutf_post_link_url',
		),
		array(
			'name' => 'Open Link in a new window',
			'id' => '_engic_eutf_post_link_new_window',
		),
		//Audio Format
		array(
			'name' => 'Audio mp3 format',
			'id' => '_engic_eutf_post_audio_mp3',
		),
		array(
			'name' => 'Audio ogg format',
			'id' => '_engic_eutf_post_audio_ogg',
		),
		array(
			'name' => 'Audio wav format',
			'id' => '_engic_eutf_post_audio_wav',
		),
		array(
			'name' => 'Audio embed',
			'id' => '_engic_eutf_post_audio_embed',
		),
		//Video Format
		array(
			'name' => 'Video Mode',
			'id' => '_engic_eutf_post_type_video_mode',
		),
		array(
			'name' => 'Video webm format',
			'id' => '_engic_eutf_post_video_webm',
		),
		array(
			'name' => 'Video mp4 format',
			'id' => '_engic_eutf_post_video_mp4',
		),
		array(
			'name' => 'Video ogv format',
			'id' => '_engic_eutf_post_video_ogv',
		),
		array(
			'name' => 'Video Poster',
			'id' => '_engic_eutf_post_video_poster',
		),
		array(
			'name' => 'Video embed Vimeo/Youtube',
			'id' => '_engic_eutf_post_video_embed',
		),

		//Feature Section
		array(
			'name' => 'Feature Element',
			'id' => '_engic_eutf_feature_element',
		),
		array(
			'name' => 'Feature Size',
			'id' => '_engic_eutf_feature_size',
		),
		array(
			'name' => 'Feature Height',
			'id' => '_engic_eutf_feature_height',
		),
		array(
			'name' => 'Feature Header Integration',
			'id' => '_engic_eutf_feature_header_integration',
		),
		array(
			'name' => 'Feature Header Position',
			'id' => '_engic_eutf_feature_header_position',
		),
		array(
			'name' => 'Feature Header Style',
			'id' => '_engic_eutf_feature_header_style',
		),
		array(
			'name' => 'Feature effect',
			'id' => '_engic_eutf_feature_effect',
		),
		array(
			'name' => 'Feature go to section',
			'id' => '_engic_eutf_feature_go_to_section',
		),
		array(
			'name' => 'Feature Revslider',
			'id' => '_engic_eutf_feature_revslider',
		),

	);

	function engic_eutf_post_options_add_custom_boxes() {

		if ( function_exists( 'vc_is_inline' ) && vc_is_inline() ) {
			return;
		}

		add_meta_box(
			'eut-meta-box-post-format-gallery',
			esc_html__( 'Gallery Format Options', 'engic' ),
			'engic_eutf_meta_box_post_format_gallery',
			'post'
		);
		add_meta_box(
			'eut-meta-box-post-format-link',
			esc_html__( 'Link Format Options', 'engic' ),
			'engic_eutf_meta_box_post_format_link',
			'post'
		);
		add_meta_box(
			'eut-meta-box-post-format-quote',
			esc_html__( 'Quote Format Options', 'engic' ),
			'engic_eutf_meta_box_post_format_quote',
			'post'
		);
		add_meta_box(
			'eut-meta-box-post-format-video',
			esc_html__( 'Video Format Options', 'engic' ),
			'engic_eutf_meta_box_post_format_video',
			'post'
		);
		add_meta_box(
			'eut-meta-box-post-format-audio',
			esc_html__( 'Audio Format Options', 'engic' ),
			'engic_eutf_meta_box_post_format_audio',
			'post'
		);

		add_meta_box(
			'eut-meta-box-post-options',
			esc_html__( 'Post Options', 'engic' ),
			'engic_eutf_post_options_box',
			'post'
		);

		add_meta_box(
			'post_feature_section',
			esc_html__( 'Feature Section', 'engic' ),
			'engic_eutf_post_feature_section_box',
			'post'
		);


	}

	function engic_eutf_post_options_box( $post ) {

		wp_nonce_field( 'engic_eutf_nonce_post_save', '_engic_eutf_nonce_post_save' );

		$post_layout = get_post_meta( $post->ID, '_engic_eutf_layout', true );
		$post_sidebar = get_post_meta( $post->ID, '_engic_eutf_sidebar', true );
		$fixed_sidebar = get_post_meta( $post->ID, '_engic_eutf_fixed_sidebar', true );
		$disable_title = get_post_meta( $post->ID, '_engic_eutf_disable_title', true );
		$engic_eutf_disable_meta_fields = get_post_meta( $post->ID, '_engic_eutf_disable_meta_fields', true );
		$disable_media = get_post_meta( $post->ID, '_engic_eutf_disable_media', true );
		$sidebar_style = get_post_meta( $post->ID, '_engic_eutf_sidebar_style', true );
		$disable_sidearea = get_post_meta( $post->ID, '_engic_eutf_disable_sidearea', true );
		$disable_footer = get_post_meta( $post->ID, '_engic_eutf_disable_footer', true );

	?>
		<table class="form-table eut-metabox">
			<tbody>
				<tr>
					<th>
						<label for="eut-post-layout">
							<strong><?php esc_html_e( 'Layout', 'engic' ); ?></strong>
							<span>
								<?php esc_html_e( 'Select post content and sidebar alignment.', 'engic' ); ?>
								<br/>
								<strong><?php esc_html_e( 'Default is configured in Theme Options - Blog Options - Single Post.', 'engic' ); ?></strong>
							</span>
						</label>
					</th>
					<td>
						<?php engic_eutf_print_layout_selection( $post_layout, 'eut-post-layout', '_engic_eutf_layout' ); ?>
					</td>
				</tr>
				<tr>
					<th>
						<label for="eut-post-sidebar">
							<strong><?php esc_html_e( 'Sidebar', 'engic' ); ?></strong>
							<span>
								<?php esc_html_e( 'Select post sidebar.', 'engic' ); ?>
								<br/>
								<strong><?php esc_html_e( 'Default is configured in Theme Options - Blog Options - Single Post.', 'engic' ); ?></strong>
							</span>
						</label>
					</th>
					<td>
						<?php engic_eutf_print_sidebar_selection( $post_sidebar, 'eut-post-sidebar', '_engic_eutf_sidebar' ); ?>
					</td>
				</tr>
				<tr>
					<th>
						<label for="eut-sidebar-style">
							<strong><?php esc_html_e( 'Sidebar Style', 'engic' ); ?></strong>
							<span>
								<?php esc_html_e( 'Select sidebar style.', 'engic' ); ?>
								<br/>
								<strong><?php esc_html_e( 'Default is configured in Theme Options - Blog Options - Single Post.', 'engic' ); ?></strong>
							</span>
						</label>
					</th>
					<td>
						<select id="eut-sidebar-style" name="_engic_eutf_sidebar_style">
							<option value="" <?php selected( '', $sidebar_style ); ?>><?php esc_html_e( 'Default', 'engic' ); ?></option>
							<option value="simple" <?php selected( 'simple', $sidebar_style ); ?>><?php esc_html_e( 'Simple', 'engic' ); ?></option>
							<option value="box" <?php selected( 'box', $sidebar_style ); ?>><?php esc_html_e( 'Box', 'engic' ); ?></option>

						</select>
					</td>
				</tr>
				<tr>
					<th>
						<label for="eut-fixed-sidebar">
							<strong><?php esc_html_e( 'Fixed Sidebar', 'engic' ); ?></strong>
							<span>
								<?php esc_html_e( 'If selected, sidebar will be fixed.', 'engic' ); ?>
							</span>
						</label>
					</th>
					<td>
						<input type="checkbox" id="eut-fixed-sidebar" name="_engic_eutf_fixed_sidebar" value="yes" <?php checked( $fixed_sidebar, 'yes' ); ?>/>
					</td>
				</tr>
				<tr>
					<th>
						<label for="eut-disable-title">
							<strong><?php esc_html_e( 'Disable Title', 'engic' ); ?></strong>
							<span>
								<?php esc_html_e( 'If selected, title will be hidden.', 'engic' ); ?>
							</span>
						</label>
					</th>
					<td>
						<input type="checkbox" id="eut-disable-title" name="_engic_eutf_disable_title" value="yes" <?php checked( $disable_title, 'yes' ); ?>/>
					</td>
				</tr>
				<tr>
					<th>
						<label for="eut-disable-meta-fields">
							<strong><?php esc_html_e( 'Disable Meta Fields', 'engic' ); ?></strong>
							<span>
								<?php esc_html_e( 'If selected, meta fields will be hidden.', 'engic' ); ?>
							</span>
						</label>
					</th>
					<td>
						<input type="checkbox" id="eut-disable-meta-fields" name="_engic_eutf_disable_meta_fields" value="yes" <?php checked( $engic_eutf_disable_meta_fields, 'yes' ); ?>/>
					</td>
				</tr>
				<tr>
					<th>
						<label for="eut-disable-media">
							<strong><?php esc_html_e( 'Disable Media Area', 'engic' ); ?></strong>
							<span>
								<?php esc_html_e( 'If selected, media area will be hidden in single post.', 'engic' ); ?>
							</span>
						</label>
					</th>
					<td>
						<input type="checkbox" id="eut-disable-media" name="_engic_eutf_disable_media" value="yes" <?php checked( $disable_media, 'yes' ); ?>/>
					</td>
				</tr>
				<tr>
					<th>
						<label for="eut-disable-sidearea">
							<strong><?php esc_html_e( 'Disable Smart Button', 'engic' ); ?></strong>
							<span>
								<?php esc_html_e( 'If selected, Smart Button Side Area will be hidden.', 'engic' ); ?>
							</span>
						</label>
					</th>
					<td>
						<input type="checkbox" id="eut-disable-sidearea" name="_engic_eutf_disable_sidearea" value="yes" <?php checked( $disable_sidearea, 'yes' ); ?>/>
					</td>
				</tr>
				<tr>
					<th>
						<label for="eut-disable-footer">
							<strong><?php esc_html_e( 'Disable Footer Widgets', 'engic' ); ?></strong>
							<span>
								<?php esc_html_e( 'If selected, footer widgets will be hidden.', 'engic' ); ?>
							</span>
						</label>
					</th>
					<td>
						<input type="checkbox" id="eut-disable-footer" name="_engic_eutf_disable_footer" value="yes" <?php checked( $disable_footer, 'yes' ); ?>/>
					</td>
				</tr>
			</tbody>
		</table>


	<?php
	}


	function engic_eutf_meta_box_post_format_gallery( $post ) {

		$gallery_mode = get_post_meta( $post->ID, '_engic_eutf_post_type_gallery_mode', true );
		$gallery_image_mode = get_post_meta( $post->ID, '_engic_eutf_post_type_gallery_image_mode', true );

		$slider_items = get_post_meta( $post->ID, '_engic_eutf_post_slider_items', true );
		$media_slider_settings = get_post_meta( $post->ID, '_engic_eutf_post_slider_settings', true );
		$media_slider_speed = engic_eutf_array_value( $media_slider_settings, 'slideshow_speed', '3500' );
		$media_slider_dir_nav = engic_eutf_array_value( $media_slider_settings, 'direction_nav', '2' );

	?>
			<table class="form-table eut-metabox">
				<tbody>
					<tr class="eut-border-bottom">
						<th>
							<label for="eut-post-gallery-mode">
								<strong><?php esc_html_e( 'Gallery Mode', 'engic' ); ?></strong>
								<span>
									<?php esc_html_e( 'Select Gallery mode.', 'engic' ); ?>
								</span>
							</label>
						</th>
						<td>
							<select id="eut-post-gallery-mode" name="_engic_eutf_post_type_gallery_mode">
								<option value="" <?php selected( '', $gallery_mode ); ?>><?php esc_html_e( 'Gallery', 'engic' ); ?></option>
								<option value="slider" <?php selected( 'slider', $gallery_mode ); ?>><?php esc_html_e( 'Slider', 'engic' ); ?></option>
							</select>
						</td>
					</tr>
					<tr id="eut-post-gallery-image-mode-section" class="eut-post-media-item" <?php if ( "" == $gallery_mode ) { ?> style="display:none;" <?php } ?>>
						<th>
							<label for="eut-post-gallery-image-mode">
								<strong><?php esc_html_e( 'Image Mode', 'engic' ); ?></strong>
								<span>
									<?php esc_html_e( 'Select image mode.', 'engic' ); ?>
								</span>
							</label>
						</th>
						<td>
							<select id="eut-post-gallery-image-mode" name="_engic_eutf_post_type_gallery_image_mode">
								<option value="" <?php selected( '', $gallery_image_mode ); ?>><?php esc_html_e( 'Auto Crop', 'engic' ); ?></option>
								<option value="resize" <?php selected( 'resize', $gallery_image_mode ); ?>><?php esc_html_e( 'Resize', 'engic' ); ?></option>
							</select>
						</td>
					</tr>
					<tr id="eut-post-media-slider-speed" class="eut-post-media-item" <?php if ( "" == $gallery_mode ) { ?> style="display:none;" <?php } ?>>
						<th>
							<label for="eut-post-slider-speed">
								<strong><?php esc_html_e( 'Slideshow Speed', 'engic' ); ?></strong>
							</label>
						</th>
						<td>
							<input type="text" id="eut-post-slider-speed" name="_engic_eutf_post_slider_settings_speed" value="<?php echo esc_attr( $media_slider_speed ); ?>" /> ms
						</td>
					</tr>
					<tr id="eut-post-media-slider-direction-nav" class="eut-post-media-item" <?php if ( "" == $gallery_mode ) { ?> style="display:none;" <?php } ?>>
						<th>
							<label for="eut-post-slider-direction-nav">
								<strong><?php esc_html_e( 'Navigation Buttons', 'engic' ); ?></strong>
							</label>
						</th>
						<td>
							<select id="eut-post-slider-direction-nav" name="_engic_eutf_post_slider_settings_direction_nav">
								<option value="1" <?php selected( "1", $media_slider_dir_nav ); ?>><?php esc_html_e( 'Style 1', 'engic' ); ?></option>
								<option value="2" <?php selected( "2", $media_slider_dir_nav ); ?>><?php esc_html_e( 'Style 2', 'engic' ); ?></option>
								<option value="3" <?php selected( "3", $media_slider_dir_nav ); ?>><?php esc_html_e( 'Style 3', 'engic' ); ?></option>
								<option value="4" <?php selected( "4", $media_slider_dir_nav ); ?>><?php esc_html_e( 'Style 4', 'engic' ); ?></option>
								<option value="0" <?php selected( "0", $media_slider_dir_nav ); ?>><?php esc_html_e( 'No Navigation', 'engic' ); ?></option>
							</select>
						</td>
					</tr>
					<tr>
						<th>
							<label><?php esc_html_e( 'Images', 'engic' ); ?></label>
						</th>
						<td>
							<input type="button" class="eut-upload-slider-button button-primary" value="<?php esc_attr_e( 'Insert Images to Gallery/Slider', 'engic' ); ?>"/>
							<span id="eut-upload-slider-button-spinner" class="eut-action-spinner"></span>
						</td>
					</tr>
				</tbody>
			</table>
			<div id="eut-slider-container" class="eut-slider-container-minimal" data-mode="minimal">
				<?php
					if( !empty( $slider_items ) ) {
						engic_eutf_print_admin_media_slider_items( $slider_items );
					}
				?>
			</div>
	<?php
	}


	function engic_eutf_meta_box_post_format_link( $post ) {
		$link_url = get_post_meta( $post->ID, '_engic_eutf_post_link_url', true );
		$new_window = get_post_meta( $post->ID, '_engic_eutf_post_link_new_window', true );
	?>
		<table class="form-table eut-metabox">
			<tbody>
				<tr>
					<td colspan="2">
						<p class="howto"><?php esc_html_e( 'Add your text in the content area. The text will be wrapped with a link.', 'engic' ); ?></p>
					</td>
				</tr>
				<tr class="eut-border-bottom">
					<th>
						<label for="eut-post-link-url">
							<strong><?php esc_html_e( 'Link URL', 'engic' ); ?></strong>
							<span>
								<?php esc_html_e( 'Enter the full URL of your link.', 'engic' ); ?>
							</span>
						</label>
					</th>
					<td>
						<input type="text" id="eut-post-link-url" class="eut-meta-text" name="_engic_eutf_post_link_url" value="<?php echo esc_attr( $link_url ); ?>" />
					</td>
				</tr>
				<tr>
					<th>
						<label for="eut-post-link-new-window">
							<strong><?php esc_html_e( 'Open Link in new window', 'engic' ); ?></strong>
							<span>
								<?php esc_html_e( 'If selected, link will open in a new window.', 'engic' ); ?>
							</span>
						</label>
					</th>
					<td>
						<input type="checkbox" id="eut-post-link-new-window" name="_engic_eutf_post_link_new_window" value="yes" <?php checked( $new_window, 'yes' ); ?>/>
					</td>
				</tr>
			</tbody>
		</table>


	<?php
	}

	function engic_eutf_meta_box_post_format_quote( $post ) {
	?>
		<table class="form-table eut-metabox">
			<tbody>
				<tr>
					<td colspan="2">
						<p class="howto"><?php esc_html_e( 'Simply add some text in the content area. This text will automatically displayed as quote.', 'engic' ); ?></p>
					</td>
				</tr>
			</tbody>
		</table>

	<?php
	}

	function engic_eutf_meta_box_post_format_video( $post ) {

		$video_mode = get_post_meta( $post->ID, '_engic_eutf_post_type_video_mode', true );
		$post_video_webm = get_post_meta( $post->ID, '_engic_eutf_post_video_webm', true );
		$post_video_mp4 = get_post_meta( $post->ID, '_engic_eutf_post_video_mp4', true );
		$post_video_ogv = get_post_meta( $post->ID, '_engic_eutf_post_video_ogv', true );
		$post_video_poster = get_post_meta( $post->ID, '_engic_eutf_post_video_poster', true );
		$post_video_embed = get_post_meta( $post->ID, '_engic_eutf_post_video_embed', true );

	?>
		<table class="form-table eut-metabox">
			<tbody>
				<tr>
					<td colspan="2">
						<p class="howto"><?php esc_html_e( 'Select one of the choices below for the featured video.', 'engic' ); ?></p>
					</td>
				</tr>
				<tr class="eut-border-bottom">
					<th>
						<label for="eut-post-type-video-mode">
							<strong><?php esc_html_e( 'Video Mode', 'engic' ); ?></strong>
							<span>
								<?php esc_html_e( 'Select your Video Mode', 'engic' ); ?>
							</span>
						</label>
					</th>
					<td>
						<select id="eut-post-type-video-mode" name="_engic_eutf_post_type_video_mode">
							<option value="" <?php selected( "", $video_mode ); ?>><?php esc_html_e( 'YouTube/Vimeo Video', 'engic' ); ?></option>
							<option value="html5" <?php selected( "html5", $video_mode ); ?>><?php esc_html_e( 'HTML5 Video', 'engic' ); ?></option>
						</select>
					</td>
				</tr>
				<tr class="eut-post-video-html5"<?php if ( "" == $video_mode ) { ?> style="display:none;" <?php } ?>>
					<th>
						<label for="eut-post-video-webm">
							<strong><?php esc_html_e( 'WebM File URL', 'engic' ); ?></strong>
							<span>
								<?php esc_html_e( 'Upload the .webm video file.', 'engic' ); ?>
								<br/>
								<strong><?php esc_html_e( 'This Format must be included for HTML5 Video.', 'engic' ); ?></strong>
							</span>
						</label>
					</th>
					<td>
						<input type="text" id="eut-post-video-webm" class="eut-upload-simple-media-field eut-meta-text" name="_engic_eutf_post_video_webm" value="<?php echo esc_attr( $post_video_webm ); ?>"/>
						<input type="button" data-media-type="video" class="eut-upload-simple-media-button button" value="<?php esc_attr_e( 'Upload Media', 'engic' ); ?>"/>
						<input type="button" class="eut-remove-simple-media-button button" value="<?php esc_attr_e( 'Remove', 'engic' ); ?>"/>
					</td>
				</tr>
				<tr class="eut-post-video-html5"<?php if ( "" == $video_mode ) { ?> style="display:none;" <?php } ?>>
					<th>
						<label for="eut-post-video-mp4">
							<strong><?php esc_html_e( 'MP4 File URL', 'engic' ); ?></strong>
							<span>
								<?php esc_html_e( 'Upload the .mp4 video file.', 'engic' ); ?>
								<br/>
								<strong><?php esc_html_e( 'This Format must be included for HTML5 Video.', 'engic' ); ?></strong>
							</span>
						</label>
					</th>
					<td>
						<input type="text" id="eut-post-video-mp4" class="eut-upload-simple-media-field eut-meta-text" name="_engic_eutf_post_video_mp4" value="<?php echo esc_attr( $post_video_mp4 ); ?>"/>
						<input type="button" data-media-type="video" class="eut-upload-simple-media-button button" value="<?php esc_attr_e( 'Upload Media', 'engic' ); ?>"/>
						<input type="button" class="eut-remove-simple-media-button button" value="<?php esc_attr_e( 'Remove', 'engic' ); ?>"/>
					</td>
				</tr>
				<tr class="eut-post-video-html5"<?php if ( "" == $video_mode ) { ?> style="display:none;" <?php } ?>>
					<th>
						<label for="eut-post-video-ogv">
							<strong><?php esc_html_e( 'OGV File URL', 'engic' ); ?></strong>
							<span>
								<?php esc_html_e( 'Upload the .ogv video file (optional).', 'engic' ); ?>
							</span>
						</label>
					</th>
					<td>
						<input type="text" id="eut-post-video-ogv" class="eut-upload-simple-media-field eut-meta-text" name="_engic_eutf_post_video_ogv" value="<?php echo esc_attr( $post_video_ogv ); ?>"/>
						<input type="button" data-media-type="video" class="eut-upload-simple-media-button button" value="<?php esc_attr_e( 'Upload Media', 'engic' ); ?>"/>
						<input type="button" class="eut-remove-simple-media-button button" value="<?php esc_attr_e( 'Remove', 'engic' ); ?>"/>
					</td>
				</tr>
				<tr class="eut-post-video-html5"<?php if ( "" == $video_mode ) { ?> style="display:none;" <?php } ?>>
					<th>
						<label for="eut-post-video-poster">
							<strong><?php esc_html_e( 'Poster Image', 'engic' ); ?></strong>
							<span>
								<?php esc_html_e( 'Use same resolution as video.', 'engic' ); ?>
							</span>
						</label>
					</th>
					<td>
						<input type="text" id="eut-post-video-poster" class="eut-upload-simple-media-field eut-meta-text" name="_engic_eutf_post_video_poster" value="<?php echo esc_attr( $post_video_poster ); ?>"/>
						<input type="button" data-media-type="image" class="eut-upload-simple-media-button button" value="<?php esc_attr_e( 'Upload Media', 'engic' ); ?>"/>
						<input type="button" class="eut-remove-simple-media-button button" value="<?php esc_attr_e( 'Remove', 'engic' ); ?>"/>
					</td>
				</tr>
				<tr class="eut-post-video-embed"<?php if ( "html5" == $video_mode ) { ?> style="display:none;" <?php } ?>>
					<th>
						<label for="eut-post-video-embed">
							<strong><?php esc_html_e( 'Vimeo/YouTube URL', 'engic' ); ?></strong>
							<span>
								<?php esc_html_e( 'Enter the full URL of your video from Vimeo or YouTube.', 'engic' ); ?>
							</span>
						</label>
					</th>
					<td>
						<input type="text" id="eut-post-video-embed" class="eut-meta-text" name="_engic_eutf_post_video_embed" value="<?php echo esc_attr( $post_video_embed ); ?>"/>
					</td>
				</tr>
			</tbody>
		</table>

	<?php
	}

	function engic_eutf_meta_box_post_format_audio( $post ) {

		$audio_mode = get_post_meta( $post->ID, '_engic_eutf_post_type_audio_mode', true );
		$post_audio_mp3 = get_post_meta( $post->ID, '_engic_eutf_post_audio_mp3', true );
		$post_audio_ogg = get_post_meta( $post->ID, '_engic_eutf_post_audio_ogg', true );
		$post_audio_wav = get_post_meta( $post->ID, '_engic_eutf_post_audio_wav', true );
		$post_audio_embed = get_post_meta( $post->ID, '_engic_eutf_post_audio_embed', true );

	?>
		<table class="form-table eut-metabox">
			<tbody>
				<tr>
					<td colspan="2">
						<p class="howto"><?php esc_html_e( 'Select one of the choices below for the featured audio.', 'engic' ); ?></p>
					</td>
				</tr>
				<tr class="eut-border-bottom">
					<th>
						<label for="eut-post-type-audio-mode">
							<strong><?php esc_html_e( 'Audio Mode', 'engic' ); ?></strong>
							<span>
								<?php esc_html_e( 'Select your Audio Mode', 'engic' ); ?>
							</span>
						</label>
					</th>
					<td>
						<select id="eut-post-type-audio-mode" name="_engic_eutf_post_type_audio_mode">
							<option value="" <?php selected( "", $audio_mode ); ?>><?php esc_html_e( 'Embed Audio', 'engic' ); ?></option>
							<option value="html5" <?php selected( "html5", $audio_mode ); ?>><?php esc_html_e( 'HTML5 Audio', 'engic' ); ?></option>
						</select>
					</td>
				</tr>
				<tr class="eut-post-audio-html5"<?php if ( "" == $audio_mode ) { ?> style="display:none;" <?php } ?>>
					<th>
						<label for="eut-post-audio-mp3">
							<strong><?php esc_html_e( 'MP3 File URL', 'engic' ); ?></strong>
							<span>
								<?php esc_html_e( 'Upload the .mp3 audio file.', 'engic' ); ?>
							</span>
						</label>
					</th>
					<td>
						<input type="text" id="eut-post-audio-mp3" class="eut-upload-simple-media-field eut-meta-text" name="_engic_eutf_post_audio_mp3" value="<?php echo esc_attr( $post_audio_mp3 ); ?>"/>
						<input type="button" data-media-type="audio" class="eut-upload-simple-media-button button" value="<?php esc_attr_e( 'Upload Media', 'engic' ); ?>"/>
						<input type="button" class="eut-remove-simple-media-button button" value="<?php esc_attr_e( 'Remove', 'engic' ); ?>"/>
					</td>
				</tr>
				<tr class="eut-post-audio-html5"<?php if ( "" == $audio_mode ) { ?> style="display:none;" <?php } ?>>
					<th>
						<label for="eut-post-audio-ogg">
							<strong><?php esc_html_e( 'OGG File URL', 'engic' ); ?></strong>
							<span>
								<?php esc_html_e( 'Upload the .ogg audio file.', 'engic' ); ?>
							</span>
						</label>
					</th>
					<td>
						<input type="text" id="eut-post-audio-ogg" class="eut-upload-simple-media-field eut-meta-text" name="_engic_eutf_post_audio_ogg" value="<?php echo esc_attr( $post_audio_ogg ); ?>"/>
						<input type="button" data-media-type="audio" class="eut-upload-simple-media-button button" value="<?php esc_attr_e( 'Upload Media', 'engic' ); ?>"/>
						<input type="button" class="eut-remove-simple-media-button button" value="<?php esc_attr_e( 'Remove', 'engic' ); ?>"/>
					</td>
				</tr>
				<tr class="eut-post-audio-html5"<?php if ( "" == $audio_mode ) { ?> style="display:none;" <?php } ?>>
					<th>
						<label for="eut-post-audio-wav">
							<strong><?php esc_html_e( 'WAV File URL', 'engic' ); ?></strong>
							<span>
								<?php esc_html_e( 'Upload the .wav audio file (optional).', 'engic' ); ?>
							</span>
						</label>
					</th>
					<td>
						<input type="text" id="eut-post-audio-wav" class="eut-upload-simple-media-field eut-meta-text" name="_engic_eutf_post_audio_wav" value="<?php echo esc_attr( $post_audio_wav ); ?>"/>
						<input type="button" data-media-type="audio" class="eut-upload-simple-media-button button" value="<?php esc_attr_e( 'Upload Media', 'engic' ); ?>"/>
						<input type="button" class="eut-remove-simple-media-button button" value="<?php esc_attr_e( 'Remove', 'engic' ); ?>"/>
					</td>
				</tr>
				<tr class="eut-post-audio-embed"<?php if ( "html5" == $audio_mode ) { ?> style="display:none;" <?php } ?>>
					<th>
						<label for="eut-post-audio-embed">
							<strong><?php esc_html_e( 'Audio embed code', 'engic' ); ?></strong>
							<span>
								<?php esc_html_e( 'Type your audio embed code.', 'engic' ); ?>
							</span>
						</label>
					</th>
					<td>
						<textarea id="eut-post-audio-embed" name="_engic_eutf_post_audio_embed" cols="40" rows="5"><?php echo esc_html( $post_audio_embed ); ?></textarea>
					</td>
				</tr>
			</tbody>
		</table>

	<?php
	}

	function engic_eutf_post_feature_section_box( $post ) {

		wp_nonce_field( 'engic_eutf_nonce_feature_save', '_engic_eutf_nonce_feature_save' );

		$post_id = $post->ID;
		engic_eutf_admin_get_feature_section( $post_id );

	}

	function engic_eutf_post_options_save_postdata( $post_id , $post ) {
		global $engic_eutf_post_options;

		if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
			return;
		}
		if ( ! isset( $_POST['_engic_eutf_nonce_post_save'] ) || !wp_verify_nonce( $_POST['_engic_eutf_nonce_post_save'], 'engic_eutf_nonce_post_save' ) ) {
			return;
		}

		// Check permissions
		if ( 'post' == $_POST['post_type'] )
		{
			if ( !current_user_can( 'edit_post', $post_id ) ) {
				return;
			}
		}

		foreach ( $engic_eutf_post_options as $value ) {
			$new_meta_value = ( isset( $_POST[$value['id']] ) ? $_POST[$value['id']] : '' );
			$meta_key = $value['id'];


			$meta_value = get_post_meta( $post_id, $meta_key, true );

			if ( $new_meta_value && '' == $meta_value ) {
				add_post_meta( $post_id, $meta_key, $new_meta_value, true );
			} elseif ( $new_meta_value && $new_meta_value != $meta_value ) {
				update_post_meta( $post_id, $meta_key, $new_meta_value );
			} elseif ( '' == $new_meta_value && $meta_value ) {
				delete_post_meta( $post_id, $meta_key, $meta_value );
			}
		}


		//Post Slider Items
		$slider_items = array();
		if ( isset( $_POST['_engic_eutf_media_slider_item_id'] ) ) {

			$num_of_images = sizeof( $_POST['_engic_eutf_media_slider_item_id'] );
			for ( $i=0; $i < $num_of_images; $i++ ) {

				$this_image = array (
					'id' => $_POST['_engic_eutf_media_slider_item_id'][ $i ],
				);
				array_push( $slider_items, $this_image );
			}

		}

		if( empty( $slider_items ) ) {
			delete_post_meta( $post->ID, '_engic_eutf_post_slider_items' );
			delete_post_meta( $post->ID, '_engic_eutf_post_slider_settings' );
		} else{
			update_post_meta( $post->ID, '_engic_eutf_post_slider_items', $slider_items );
			$media_slider_speed = 3500;
			$media_slider_direction_nav = '1';
			if ( isset( $_POST['_engic_eutf_post_slider_settings_speed'] ) ) {
				$media_slider_speed = $_POST['_engic_eutf_post_slider_settings_speed'];
			}
			if ( isset( $_POST['_engic_eutf_post_slider_settings_direction_nav'] ) ) {
				$media_slider_direction_nav = $_POST['_engic_eutf_post_slider_settings_direction_nav'];
			}
			$media_slider_settings = array (
				'slideshow_speed' => $media_slider_speed,
				'direction_nav' => $media_slider_direction_nav,
			);
			update_post_meta( $post->ID, '_engic_eutf_post_slider_settings', $media_slider_settings );
		}

		if ( isset( $_POST['_engic_eutf_nonce_feature_save'] ) && wp_verify_nonce( $_POST['_engic_eutf_nonce_feature_save'], 'engic_eutf_nonce_feature_save' ) ) {

			engic_eutf_admin_save_feature_section( $post_id );

		}

	}

//Omit closing PHP tag to avoid accidental whitespace output errors.
