<?php
/**
 * Template name: Edit Post
 *
 * Learn more: http://codex.wordpress.org/Template_Hierarchy
 *
 * @package WordPress
 * @subpackage betube
 * @since betube 1.0
 */

if ( !is_user_logged_in() ) {
	wp_redirect( home_url() ); exit;
} else { 

}
$postContent = '';$caticoncolor="";
global $current_user;global $current_post;wp_get_current_user();$userID = $current_user->ID;$query = new WP_Query(array('post_type' => 'post', 'posts_per_page' =>'-1', 'p' => $_GET['post']) );
if ($query->have_posts()) : while ($query->have_posts()) : $query->the_post();
	if(isset($_GET['post'])) {	
		if($_GET['post'] == $post->ID)
		{
						$author = get_the_author_meta('ID');
			if($author != $userID) {
				wp_redirect( home_url() ); exit;
			}						$current_post = $post->ID;
			$title = get_the_title();
			$content = get_the_content();
			$posttags = get_the_tags($current_post);
			if ($posttags) {
			  foreach($posttags as $tag) {
				$tags_list = $tag->name . ' '; 
			  }
			}
			$postcategory = get_the_category( $current_post );			
			$category_id = $postcategory[0]->cat_ID;			
			$post_category_type = get_post_meta($post->ID, 'post_category_type', true);
			$betubeVideoLayout = get_post_meta($post->ID, 'jtheme_video_layout', true);						$videoCustomVideoLink = get_post_meta($post->ID, 'jtheme_video_file', true);			$betubeEmbedCode = get_post_meta($post->ID, 'jtheme_video_code', true);
			$betubeVideoLink = get_post_meta($post->ID, 'jtheme_video_url', true);
			$betubeVideoLink2 = get_post_meta($post->ID, 'single_video_link_second', true);
			$betubeVideoLink3 = get_post_meta($post->ID, 'single_video_link_third', true);						$betubePostTime = get_post_meta($post->ID, 'post_time', true);			$betubePostQuality = get_post_meta($post->ID, 'post_quality', true);			$betubeHDPost = get_post_meta($post->ID, 'hd_post', true);
			
			if ( has_post_thumbnail() ) {		
				$post_thumbnail = get_the_post_thumbnail($current_post, 'thumbnail');		
			} 
		}
	}
endwhile; endif;
wp_reset_query();global $current_post;global $redux_demo;
$postTitleError = '';
$post_priceError = '';
$catError = '';
if(isset($_POST['submitted']) && isset($_POST['post_nonce_field']) && wp_verify_nonce($_POST['post_nonce_field'], 'post_nonce')) {
	if(trim($_POST['postTitle']) === '') {
		$postTitleError = 'Please enter a title.';
		$hasError = true;
	} else {
		$postTitle = trim($_POST['postTitle']);
	}
	if(trim($_POST['cat']) === '-1') {
		$catError = 'Please select a category.';
		$hasError = true;
	} 		
	if($hasError != true) {
		if(is_super_admin() ){
			$beTubepostStatus = 'publish';
		}elseif(!is_super_admin()){		
			if($redux_demo['post-options-edit-on'] == 1){
				$beTubepostStatus = 'pending';
			}else{
				$beTubepostStatus = 'publish';
			}
		}				$mCatID = $_POST['cat'];				
		$post_information = array(
			'ID' => $current_post,
			'post_title' => esc_attr(strip_tags($_POST['postTitle'])),
			'post_content' => strip_tags($_POST['video-body'], '<a><h1><h2><h3><strong><b><ul><li><i><a>'),
			'post-type' => 'post',
			'post_category' => array($mCatID),
	        'tags_input'    => explode(',', $_POST['post_tags']),
	        'comment_status' => 'open',
	        'ping_status' => 'open',
			'post_status' => $beTubepostStatus
		);
		$post_id = wp_insert_post($post_information);				$betubeVideoLink = $_POST['video_link'];		$betubeVideoLink2 = $_POST['video_link2'];		$betubeVideoLink3 = $_POST['video_link3'];		$videoCustomVideoLink = $_POST['video_custom_link'];		$betubeEmbedCode = $_POST['video_embed_code'];		$betubeVideoLayout = $_POST['radio-btns-sprite'];		$betubeFeaturedIMGURL = $_POST['featured-image-url'];		$betubeIMGIDURL = $_POST['criteria-image-id'];		$betubePostTime = $_POST['post_time'];		$betubePostQuality = $_POST['post_quality'];		$hd_post = $_POST['hd_post'];		if(isset($hd_post)){			$betubeHDPost = '1';		}else{			$betubeHDPost = '2';		}
		update_post_meta($post_id, 'post_category_type', esc_attr( $_POST['post_category_type'] ) );
		update_post_meta($post_id, 'jtheme_video_layout', $betubeVideoLayout, $allowed);					if(!empty($videoCustomVideoLink)){			update_post_meta($post_id, 'jtheme_video_file', $videoCustomVideoLink, $allowed);		}		if(!empty($betubeEmbedCode)){			update_post_meta($post_id, 'jtheme_video_code', $betubeEmbedCode, $allowed);		}		if(!empty($betubeVideoLink)){			update_post_meta($post_id, 'jtheme_video_url', $betubeVideoLink, $allowed);		}		/*Extra Video Links*/		if(!empty($betubeVideoLink2)){			update_post_meta($post_id, 'single_video_link_second', $betubeVideoLink2, $allowed);		}		if(!empty($betubeVideoLink3)){			update_post_meta($post_id, 'single_video_link_third', $betubeVideoLink3, $allowed);		}
		/*Duration*/		if(!empty($betubeVideoLink3)){			update_post_meta($post_id, 'post_time', $betubePostTime, $allowed);		}		/*Duration*/		/*Quality*/		if(!empty($betubePostQuality)){			update_post_meta($post_id, 'post_quality', $betubePostQuality, $allowed);		}		/*Quality*/		/*HD*/		if(!empty($betubeHDPost)){			update_post_meta($post_id, 'hd_post', $betubeHDPost, $allowed);		}		/*HD*/
		$permalink = get_permalink( $post_id );		
		global $post;		/*Video Uploading*/			if ( isset($_FILES['upload_attachment']) ) {				$count = '0';				$files = $_FILES['upload_attachment'];				foreach ($files['name'] as $key => $value) {					if ($files['name'][$key]) {						$file = array(							'name'     => $files['name'][$key],							'type'     => $files['type'][$key],							'tmp_name' => $files['tmp_name'][$key],							'error'    => $files['error'][$key],							'size'     => $files['size'][$key]						);						$_FILES = array("upload_attachment" => $file);												foreach ($_FILES as $file => $array) {														$fileType = $array['type'];							$newupload = betube_insert_attachment($file, $post->ID);							$attachvideo = wp_get_attachment_url( $newupload);							if($fileType == 'image/jpeg' || $fileType == 'image/png' || $fileType == 'image/jpg'){								//add_post_meta($post_id, '_video_thumbnail', $newupload);								set_post_thumbnail( $post_id, $newupload );							}else{								add_post_meta($post_id, 'jtheme_video_file', $attachvideo);							}							$count++;						}					}				}							}			/*Video Uploading*/		//set_post_thumbnail( $post_id, $betubeIMGIDURL );
		if (isset($_POST['att_remove'])) {
			foreach ($_POST['att_remove'] as $att_id){
				wp_delete_attachment($att_id);
			}
		}
		wp_redirect( $permalink ); exit;
	}
} 
get_header();betube_breadcrumbs();?><?php 	global $post;	$page = get_page($post->ID);	$current_page_id = $page->ID;	wp_get_current_user();		$betubeProfileIMG = get_user_meta($user_ID, "betube_author_profile_bg", true);	if(!empty($betubeProfileIMG)){		$betubeProfileIMG = betube_get_image_url($betubeProfileIMG);	}?>	<?php while ( have_posts() ) : the_post(); ?>
<div class="row">	<!--left sidebar-->	<div class="large-4 columns">		<aside class="secBg sidebar">			<div class="row">				<!-- profile overview -->				<div class="large-12 columns">					<div class="widgetBox">						<div class="widgetTitle">							<h5><?php esc_html_e("Profile OVERVIEW", 'betube') ?></h5>						</div>						<div class="widgetContent">						<?php 						global $redux_demo;												$betubeProfile = betube_get_template_url('template-profile.php');												$betubeVideoSingleUser = betube_get_template_url('template-user-all-video.php');						$betubeFavourite = betube_get_template_url('template-favorite.php');						$beTubeAddPost =  betube_get_template_url('template-submit-video.php');						$beTubefollowers = betube_get_template_url('template-followers.php');						$beTubeEditProfile = betube_get_template_url('template-edit-profile.php');						?>							<ul class="profile-overview">								<li class="clearfix">									<a class="active" href="<?php echo esc_url($betubeProfile); ?>">										<i class="fa fa-user"></i><?php esc_html_e("About Me", 'betube') ?>									</a>								</li><!--AboutMe-->								<li class="clearfix">									<a href="<?php echo esc_url($betubeVideoSingleUser); ?>">										<i class="fa fa-video-camera"></i><?php esc_html_e("Videos", 'betube') ?> 										<span class="float-right"><?php echo count_user_posts($user_ID);?></span>									</a>								</li><!--Videos-->								<li class="clearfix">									<a href="<?php echo esc_url($betubeFavourite); ?>">										<i class="fa fa-heart"></i><?php esc_html_e("Favorite Videos", 'betube') ?>										<span class="float-right">											<?php 												global $current_user;												wp_get_current_user();												$user_id = $current_user->ID;												echo betubeFavoriteCount($user_id);												?>										</span>									</a>								</li><!--Favorite Videos-->								<li class="clearfix">									<a href="#">										<i class="fa fa-users"></i><?php esc_html_e("Followers", 'betube') ?>										<span class="float-right">										<?php echo betubeFollowerCount($user_id);?>										</span>									</a>								</li><!--Followers-->								<li class="clearfix">								<?php 																	$args = array(									'user_id' => get_current_user_id(), // use user_id									'count' => true, //return only the count									'status' => 'approve'								);								$betubeUsercomments = get_comments($args);								?>									<a href="#">										<i class="fa fa-comments-o"></i><?php esc_html_e("comments", 'betube') ?>										<span class="float-right">										<?php echo esc_attr($betubeUsercomments); ?></span>									</a>								</li><!--comments-->								<li class="clearfix">									<a href="<?php echo esc_url($beTubeEditProfile); ?>">										<i class="fa fa-gears"></i><?php esc_html_e("Profile Settings", 'betube') ?>									</a>								</li><!--Profile Settings-->								<li class="clearfix">									<a href="<?php echo wp_logout_url(get_option('siteurl')); ?>">										<i class="fa fa-sign-out"></i><?php esc_html_e("Logout", 'betube') ?>									</a>								</li><!--Logout-->								<a href="<?php echo esc_url($beTubeAddPost); ?>" class="button">									<i class="fa fa-plus-circle"></i><?php esc_html_e("Submit Video", 'betube') ?>								</a><!--Submit Video-->							</ul><!--UL-->						</div><!--widgetContent -->					</div><!--widgetBox -->				</div><!--Large12 -->			</div><!--row-->		</aside><!--aside-->	</div><!--Large4-->	<!--left sidebar-->	<!-- right side content area -->	<div class="large-8 columns profile-inner">		<section class="submit-post">			<div class="row secBg">				<div class="large-12 columns">					<div class="heading">						<i class="fa fa-pencil-square-o"></i>						<h4><?php esc_html_e("Edit video Post", 'betube');?></h4>					</div><!--heading-->					<div class="row">						<div class="large-12 columns">							<form data-abide novalidate method="POST" id="editPostForm" enctype="multipart/form-data">								<div data-abide-error class="alert callout" style="display: none;">									<p>										<i class="fa fa-exclamation-triangle"></i>										<?php if($postTitleError != '') {echo esc_html($postTitleError); }?>										<?php esc_html_e("There are some errors in your form.", 'betube') ?>									</p>								</div><!--alert callout-->								<div class="row">									<div class="large-12 columns">										<label><?php esc_html_e("Title", 'betube') ?>:											<input type="text" value="<?php echo esc_html($title); ?>" id="postTitle" name="postTitle" placeholder="<?php esc_html_e("Enter your Video Title", 'betube') ?>..." required>											<span class="form-error">												<?php esc_html_e("Yo, you had better fill this out, it's required.", 'betube') ?>											</span>										</label>									</div><!--End Title-->									<div class="large-12 columns">										<label><?php esc_html_e("Description", 'betube') ?>:											<textarea name="video-body" id="video-body"><?php echo esc_html($content); ?></textarea>										</label>									</div><!--End Description-->									<?php 									global $redux_demo;									$betubeCustomUpload = $redux_demo['betube-custom-uploading'];									if($betubeCustomUpload == 1){									?>									<div class="large-12 columns">										<h6 class="borderBottom"><?php esc_html_e("Choose Video Method", 'betube') ?>:</h6>										<p><strong><?php esc_html_e("Note", 'betube') ?>:</strong> <?php esc_html_e("Please choose one of the following ways to embed the video into your post, the video is determined in the order: Video Code > Video URL > Video File.", 'betube') ?></p>									</div><!--Choose Method-->									<div class="large-12 columns">										<div class="radio trigger">										   <input type="radio" value="check" name="videolink" id="videolink1" <?php if(!empty($betubeVideoLink)){echo "checked";}?>>										   <label class="customLabel" for="videolink1"><?php esc_html_e("Video Link From Youtube/Vimeo etc", 'betube') ?>..</label>										   <input type="radio" value="check" name="videolink" id="videolink2" <?php if(!empty($videoCustomVideoLink)){echo "checked";}?>>										   <label class="customLabel" for="videolink2"><?php esc_html_e("Custom Video Upload / Put custom Video URL", 'betube') ?> </label>										   <input type="radio" value="check" name="videolink" id="videolink3" <?php if(!empty($betubeEmbedCode)){echo "checked";}?>>										   <label class="customLabel" for="videolink3"><?php esc_html_e("Embed/Object Code", 'betube') ?></label>										</div>									</div><!--Choose Option-->									<div class="large-12 columns radio-video-links">										<div data-id="videolink1" style="display: block">											<label><?php esc_html_e("Put here your video Link from youtube/vimeo/dailymotion etc..", 'betube') ?>:												<input type="url" name="video_link" value="<?php echo esc_url($betubeVideoLink);?>" placeholder="<?php esc_html_e("http://youtube.com/xkijkbh", 'betube') ?>">												<?php 												$betubeMultiPlayer = $redux_demo['betube-multi-player'];												if($betubeMultiPlayer == 1){												?>												<input type="url" name="video_link2" value="<?php echo esc_url($betubeVideoLink2);?>" placeholder="<?php esc_html_e("http://youtube.com/xkijkbh", 'betube') ?>">												<input type="url" name="video_link3" value="<?php echo esc_url($betubeVideoLink3);?>" placeholder="<?php esc_html_e("http://youtube.com/xkijkbh", 'betube') ?>">												<?php } ?>											</label>										</div>										<div data-id="videolink2">																					<label><?php esc_html_e("Put here your video url with proper extension", 'betube') ?>:												<input type="text" value="<?php echo esc_url($videoCustomVideoLink); ?>" name="video_custom_link" placeholder="<?php esc_html_e("http://yoursite.com/sample-video.mp4", 'betube') ?>">											</label>											<p class="extraMargin"><?php esc_html_e("Paste your video file url to here. Supported Video Formats: mp4, m4v, webmv, webm, ogv and flv. About Cross-platform and Cross-browser Support. If you want your video works in all platforms and browsers(HTML5 and Flash), you should provide various video formats for same video, if the video files are ready, enter one url per line. For Example: http://yousite.com/sample-video.m4v http://yousite.com/sample-video.ogv Recommended Format Solution: webmv + m4v + ogv", 'betube') ?>.</p>											<h6><?php esc_html_e("OR", 'betube') ?></h6>											<div class="video">																								<input type="file" id="videoUpload" name="upload_attachment[]" multiple="false">											</div>										</div><!--videolink2-->										<div data-id="videolink3">											<textarea name="video_embed_code" placeholder="<?php esc_html_e("Paste your embed code here", 'betube') ?>"><?php echo esc_html($betubeEmbedCode); ?></textarea>										</div><!--videolink3-->									</div><!--End Video Code Options-->									<?php }else{ ?>										<div class="large-12 columns">											<label><?php esc_html_e("Put Your Video Link from YouTube, Vimeo etc", 'betube') ?>:												<input type="text" name="video_link" value="<?php echo esc_url($betubeVideoLink);?>" placeholder="<?php esc_html_e("http://youtube.com/xkijkbh", 'betube') ?>">											</label>										</div>									<?php } ?>									<div class="large-12 columns">																			<div class="post-category">											<label><?php esc_html_e("Choose Video Category", 'betube') ?>:											<?php 												$currCatID = $category_id;											$args = array(												'show_option_none' => esc_html__( 'Select category', 'betube' ),												'selected' => $category_id,											  );											  $currCatID = $category_id;											?>											<?php wp_dropdown_categories($args); ?>											</label>										</div>										<?php 										/*==========================										 beTube: Display attachment										===========================*/										$args = array(											'post_parent' => $current_post,											'post_status' => 'inherit',											'post_type' => 'attachment',											'post_mime_type' => 'image',											'order' => 'ASC',											'numberposts' => -1,										);										$attachments = get_children($args);										if($attachments){										?>										<fieldset class="input-title">											<label for="edit-field-category-und" class="control-label">												<?php esc_html_e('Images', 'betube') ?>											</label>											<div id="edit-post-images-block">											<?php											foreach($attachments as $att_id => $attachment) {												$attachment_ID = $attachment->ID;												$full_img_url = wp_get_attachment_url($attachment->ID);												$split_pos = strpos($full_img_url, 'wp-content');												$split_len = (strlen($full_img_url) - $split_pos);												$abs_img_url = substr($full_img_url, $split_pos, $split_len);												$full_info = @getimagesize(ABSPATH.$abs_img_url);											?>												<div id="<?php echo esc_attr($attachment_ID); ?>" class="edit-post-image-block">													<img class="edit-post-image" src="<?php echo esc_url($full_img_url); ?>" />													<div class="remove-edit-post-image">														<i class="fa fa-minus-square-o"></i>														<span class="remImage"><?php _e('Remove', 'betube');?></span> 														<input type="hidden" name="" value="<?php echo esc_attr($attachment_ID); ?>">													</div>												</div>											<?php } ?>											</div>										</fieldset>										<?php 										}										$betubeCustomUpload = $redux_demo['betube-custom-uploading'];										if($betubeCustomUpload == 1){										?>										<div class="upload-video">											<label for="imgfileupload" class="btn-upload">												<i class="fa fa-camera"></i>												<span class="">													<?php esc_html_e("Upload Featured Image (Optional for YouTube, Vimeo)", 'betube') ?>												</span>											</label>											<input type="file" id="imgfileupload" name="upload_attachment[]" multiple="false" accept="image/png, image/jpeg">										</div>										<p><?php esc_html_e("Upload image Only if you want to set any Featured Image, Otherwise leave it.", 'betube') ?></p>										<?php }?>									</div><!--End SEO Meta, Images, Category-->													<div class="large-12 columns">										<div class="video-sprite clearfix">											<div class="video-layout">												<input type="radio" id="radio-img-1" name="radio-btns-sprite" value="fullwidth">												<label for="radio-img-1" class="fullwidth"><?php esc_html_e("FullWidth", 'betube') ?></label>												<span><?php esc_html_e("FullWidth", 'betube') ?></span>											</div><!--video-layout-Full-width-->											<div class="video-layout">												<input type="radio" id="radio-img-2" value="standarad" name="radio-btns-sprite" checked>												<label for="radio-img-2" class="standard"><?php esc_html_e("Standarad", 'betube') ?></label>												<span><?php esc_html_e("Standarad", 'betube') ?></span>											</div><!--video-layout-Standarad-->										</div><!--video-sprite-->									</div><!--Choose Layout-->									<!--Videotime-->									<div class="large-12 columns">										<label><?php esc_html_e("Duration", 'betube') ?>:											<input type="text" name="post_time" id="post_time" value="<?php echo esc_attr($betubePostTime); ?>" placeholder="<?php esc_html_e("Enter Video Duration Time like 15:20", 'betube') ?>">										</label>									</div>									<!--Videotime-->									<!--Quality-->									<div class="large-12 columns">										<label><?php esc_html_e("Quality", 'betube') ?>:											<input type="text" name="post_quality" id="post_quality" value="<?php echo esc_attr($betubePostQuality); ?>" placeholder="<?php esc_html_e("Enter Video Quality like HD, 720p, 320p", 'betube') ?>">										</label>									</div>									<!--Quality-->									<!--HDPOST-->									<div class="large-12 columns">										<div class="checkbox">											<input type="checkbox" name="hd_post" id="hd_post" value="<?php echo esc_attr($betubeHDPost); ?>" <?php if($betubeHDPost == 1){ echo 'checked';}?>>											<label class="customLabel" for="hd_post"><?php esc_html_e("Is this HD Video? Check this if its HD Video", 'betube') ?>	</label>										</div>									</div>									<!--HDPOST-->									<?php $betubeTags = $redux_demo['betube-tags-on']; ?>									<?php if($betubeTags == 1){?>									<div class="large-12 columns">									<label><?php esc_html_e("Tags", 'betube') ?>:									<?php									echo "<input type='text' id='post_tags' name='post_tags' value='";										$posttags = get_the_tags($current_post);										if ($posttags) {										  foreach($posttags as $tag) {											$tags_list = $tag->name . ', '; 											echo esc_html($tags_list);										  }										}										echo "' size='12' maxlength='110'>"; 									 ?>									 </label>																			</div><!--End Tags-->									<?php } ?>									<div class="large-12 columns">										<?php wp_nonce_field('post_nonce', 'post_nonce_field'); ?>										<input type="hidden" name="submitted" id="submitted" value="true" />										<button class="button expanded" type="submit" name="submit"><?php esc_html_e("Publish Now", 'betube') ?></button>									</div><!--Publish Button-->									</div><!--Row-->							</form><!--End Form-->						</div><!--large-12 columns-->					</div><!--End Row-->				</div><!--large-12-->			</div><!--row secBg-->		</section><!--submit-post-->	</div><!--Large8-->	<!-- right side content area --></div><!--row--><?php endwhile; ?>
<?php get_footer(); ?>