Sindbad~EG File Manager

Current Path : /var/www/html/wordpress_alg24news/wp-content/themes/newsbt-mobile/panel/core/
Upload File :
Current File : /var/www/html/wordpress_alg24news/wp-content/themes/newsbt-mobile/panel/core/video.php

<?php
/*
 * Security 	: blocking direct access
 * Source		: http://codex.wordpress.org/Theme_Development#Template_Files
*/
defined('ABSPATH') or die("Access Restricted");

/**
 * is_edit_page 
 * function to check if the current page is a post edit page
 * 
 * @author Ohad Raz <[email protected]>
 * 
 * @param  string  $new_edit what page to check for accepts new - new post page ,edit - edit post page, null for either
 * @return boolean
 */
function is_edit_page($new_edit = null){
    global $pagenow;
    //make sure we are on the backend
    if (!is_admin()) return false;
    if($new_edit == "edit")
        return in_array( $pagenow, array( 'post.php',  ) );
    elseif($new_edit == "new") //check for new post page
        return in_array( $pagenow, array( 'post-new.php' ) );
    else //check for either new or edit
        return in_array( $pagenow, array( 'post.php', 'post-new.php' ) );
}

/*
	Description		: Get video id from old shortcodes ( only youtube & vimeo & dailymotion)
					  and make old shortcodes still working
	Source			: http://stackoverflow.com/a/18196595/2535061
	Developed by	: Mouad achemli -> just to work with theme ;)
	Note			: this function is important do not remove from here
*/
function get_shortcode_vsw($postid) {
	global $params_vid;
	$data_content_vsw = get_post($postid);
	$data = $data_content_vsw->post_content;
	$dat = array();
	preg_match("/\[vsw (.+?)\]/", $data, $dat);

	$dat 	= array_pop($dat);
	$dat	= explode(" ", $dat);
	$params_vid = array();
	foreach ($dat as $d){
		list($opt, $val) = array_pad(explode('=', $d, 2), -2, null);
		$params_vid[$opt] = trim($val, '"');
	}	
	return $params_vid;
}
/*
	Description		: Get video id from New shortcodes (only youtube & vimeo & dailymotion)
	Source			: http://stackoverflow.com/a/18196595/2535061
	Developed by	: Mouad achemli -> just to work with theme ;)
	Note			: this function is important do not remove from here
*/
function get_new_shortcode($postid) {
	global $params_vid;
	$data_content_new = get_post($postid);
	$data = $data_content_new->post_content;
	$dat = array();
	preg_match("/\[vid (.+?)\]/", $data, $dat);
	$dat = array_pop($dat);
	$dat = explode(" ", $dat);
	$params_vid = array();
	foreach ($dat as $d){
		list($opt, $val) = array_pad(explode('=', $d, 2), -2, null);
		$params_vid[$opt] = trim($val, '"');
	}	
	return $params_vid;
}

/*
  Function Description	: Get Youtube video id from wordpress post content
  Author Name			: tazo todua (http://stackoverflow.com/users/2165415/tazo-todua)
  Devlopped By			: Mouad Achemli (just integrate with wordpress) :p
  Function Source		: http://stackoverflow.com/a/20614061/2535061
  Note					: this function is important do not remove from here
*/
function get_youtube_id($postid) {
	$data = get_post($postid);
	$list = wp_extract_urls($data->post_content);
	$id = false;
	foreach ($list as $urls => $url) {
		if (preg_match("/^(?:http(?:s)?:\/\/)?(?:www\.)?(?:m\.)?(?:youtu\.be\/|youtube\.com\/(?:(?:watch)?\?(?:.*&)?v(?:i)?=|(?:embed|v|vi|user)\/))([^\?&\"'>]+)/", $url, $matches)) {
			$id = $matches[1];
			break;
		}
		return $id;
	}
	return $id;
}

/*
  Function Description	: Get Vimeo video id from wordpress post content
  Author Name			: Patrick Talmadge
  Devlopped By			: Mouad Achemli (just integrate with wordpress) :p
  Function Source		: https://gist.github.com/wwdboer/4943672
  Note					: this function is important do not remove from here
*/
function get_vimeo_id($postid) {
	$data = get_post($postid);
	$regex = '~
	# Match Vimeo link and embed code
	(?:<iframe [^>]*src=")? # If iframe match up to first quote of src
	(?: # Group vimeo url
	https?:\/\/ # Either http or https
	(?:[\w]+\.)* # Optional subdomains
	vimeo\.com # Match vimeo.com
	(?:[\/\w]*\/?)? # Optional video sub directory this handles groups links also
	\/ # Slash before Id
	([0-9]+) # $1: VIDEO_ID is numeric
	[^\s]* # Not a space
	) # End group
	"? # Match end quote if part of src
	(?:[^>]*></iframe>)? # Match the end of the iframe
	(?:<p>.*</p>)? # Match any title information stuff
	~ix';
	if (preg_match($regex, $data->post_content, $matches)) {
        return $matches[1];
    } else {
        return null;
    }
}

/*
  Function Description	: Get dailymotion video id from wordpress post content
  Author Name			: Laurent MOREL
  Devlopped By			: Mouad Achemli (just integrate with wordpress) :p
  Function Source		: http://lmorel3.fr/?p=524
  Note					: this function is important do not remove from here
*/
function get_dailymotion_id($postid) {
	$data = get_post($postid);
	$post_content = $data->post_content;
	$media_url = "";
	
	preg_match('#<object[^>]+>.+?http://www.dailymotion.com/swf/video/([A-Za-z0-9]+).+?</object>#s', $post_content, $matches);
	
	if(!isset($matches[1])) {
		
		preg_match('#http://www.dailymotion.com/video/([A-Za-z0-9]+)#s', $post_content, $matches);
		if(!isset($matches[1])) {
			
			if (preg_match('#http://www.dailymotion.com/embed/video/([A-Za-z0-9]+)#s', $post_content, $matches)) :
				$media_url = $matches[1];
			endif;
			
		} elseif(strlen($matches[1])) {
			$media_url = $matches[1];
		}
		
	} elseif(strlen($matches[1])) {
		if(strlen($matches[1])) { 
			$media_url = $matches[1]; 
		}
	}
	return $media_url;
}

/*
	Description		: check if custom field have full URL Youtube and return id
	Author			: Fluffy & user3078359
	Source 			: http://stackoverflow.com/a/20614061/2535061
					: http://stackoverflow.com/a/21788898/2535061
	Developed by	: Mouad achemli (make it for check full url) :p
	Note			: this function is important do not remove from here
*/
function mwp_ytcheck_url($url) {
	
	if(filter_var($url, FILTER_VALIDATE_URL)){
		if (preg_match('/youtube\.com\/watch\?v=([^\&\?\/]+)/', $url, $id)) {
			return $id[1];
		} elseif (preg_match('/youtube\.com\/embed\/([^\&\?\/]+)/', $url, $id)) {
			return $id[1];
		} elseif (preg_match('/youtube\.com\/v\/([^\&\?\/]+)/', $url, $id)) {
			return $id[1];
		} elseif (preg_match('/youtu\.be\/([^\&\?\/]+)/', $url, $id)) {
			return $id[1];
		} elseif (preg_match('/youtube\.com\/verify_age\?next_url=\/watch%3Fv%3D([^\&\?\/]+)/', $url, $id)) {
			return $id[1];
		}
	}
}
/*
  Function Description	: check if custom field have full URL Vimeo and return id
  Author Name			: Patrick Talmadge
  Devlopped By			: Mouad Achemli (make it for check full url) :p
  Function Source		: https://gist.github.com/wwdboer/4943672
  Note					: this function is important do not remove from here
*/
function mwp_vicheck_url($url) {
	
	if(filter_var($url, FILTER_VALIDATE_URL)){
	$regex = '~
	# Match Vimeo link and embed code
	(?:<iframe [^>]*src=")? # If iframe match up to first quote of src
	(?: # Group vimeo url
	https?:\/\/ # Either http or https
	(?:[\w]+\.)* # Optional subdomains
	vimeo\.com # Match vimeo.com
	(?:[\/\w]*\/?)? # Optional video sub directory this handles groups links also
	\/ # Slash before Id
	([0-9]+) # $1: VIDEO_ID is numeric
	[^\s]* # Not a space
	) # End group
	"? # Match end quote if part of src
	(?:[^>]*></iframe>)? # Match the end of the iframe
	(?:<p>.*</p>)? # Match any title information stuff
	~ix';
	if (preg_match($regex, $url, $matches)) {
        return $matches[1];
    } else {
        return null;
    }
	}
}
/*
  Function Description	: check if custom field have full URL Dailymotion and return id
  Author Name			: Laurent MOREL
  Devlopped By			: Mouad Achemli (make it for check full url) :p
  Function Source		: http://lmorel3.fr/?p=524
  Note					: this function is important do not remove from here
*/
function mwp_dmcheck_url($url) {
	
	if(filter_var($url, FILTER_VALIDATE_URL)){
		$media_url = "";
		preg_match('#<object[^>]+>.+?http://www.dailymotion.com/swf/video/([A-Za-z0-9]+).+?</object>#s', $url, $matches);
		if(!isset($matches[1])) {
			preg_match('#http://www.dailymotion.com/video/([A-Za-z0-9]+)#s', $url, $matches);
			if(!isset($matches[1])) {
				preg_match('#http://www.dailymotion.com/embed/video/([A-Za-z0-9]+)#s', $url, $matches);
				if(strlen($matches[1])) { 
					$media_url = $matches[1]; 
				}
			} elseif(strlen($matches[1])) {
				$media_url = $matches[1];
			}
		} elseif(strlen($matches[1])) {
			if(strlen($matches[1])) { 
				$media_url = $matches[1]; 
			}
		}
		return $media_url;
	}
}

if(!function_exists('file_get_html')) {
	require_once( get_template_directory() . '/panel/core/simple_html_dom.php' );
}

/*
	Description	: Convert seconds to timecode
	source 		: http://stackoverflow.com/q/8273804
	found 		: http://wordpress.stackexchange.com/a/88758/40961
	Note		: this function is important do not remove from here
*/
function secondsToTime($inputSeconds) {

    $secondsInAMinute = 60;
    $secondsInAnHour  = 60 * $secondsInAMinute;
    $secondsInADay    = 24 * $secondsInAnHour;
    $days = floor($inputSeconds / $secondsInADay);
    $hourSeconds = $inputSeconds % $secondsInADay;
    $hours = floor($hourSeconds / $secondsInAnHour);
    $minuteSeconds = $hourSeconds % $secondsInAnHour;
    $minutes = floor($minuteSeconds / $secondsInAMinute);
    $remainingSeconds = $minuteSeconds % $secondsInAMinute;
    $seconds = ceil($remainingSeconds);
    if( (int)$days == 0 )
        $days = '';
    elseif( (int)$days < 10 )
        $days = '0' . (int)$days . ':';
    else
        $days = (int)$days . ':';
    if( (int)$hours == 0 )
        $hours = '';
    elseif( (int)$hours < 10 )
        $hours = '0' . (int)$hours . ':';
    else 
        $hours = (int)$hours . ':';
    if( (int)$minutes == 0 )
        $minutes = '00:';
    elseif( (int)$minutes < 10 )
        $minutes = '0' . (int)$minutes . ':';
    else 
        $minutes = (int)$minutes . ':';
    if( (int)$seconds == 0 )
        $seconds = '00';
    elseif( (int)$seconds < 10 )
        $seconds = '0' . (int)$seconds;

    return $days . $hours . $minutes . $seconds;
}

/*
	Description		: Get Youtube video duration
	Developed by	: Mouad achemli
	Note			: this function is important do not remove from here
*/
function youtube_duration($id){
	$link = 'https://www.youtube.com/watch?v='.$id;
	$link_body = wp_remote_retrieve_body(wp_remote_get($link));
	$link_body = str_get_html($link_body);
	$html = new simple_html_dom();
	$html->load($link_body );
	foreach($html->find('meta[itemprop="duration"]') as $element)
    $time =  $element->content;
	if (!empty($time)) {
		$duration = new DateInterval($time);
		$str_time = $duration->format('%H:%I:%S');
		$time = explode(':', $str_time);
		$print = ($time[0]*3600) + ($time[1]*60) + $time[2];
		return $print;
	} else {
		return false;
	}
}

/*
	Description		: Get Vimeo video duration
	Author			: Fluffy (http://stackoverflow.com/users/123927/fluffy)
	Source			: http://stackoverflow.com/a/1361192/2535061
	Developed by	: Mouad achemli (just to get duration instead of thumbnail) :p
	Note			: this function is important do not remove from here
*/
function vimeo_duration($id) {
	if (!is_array($id)) {
		$url      = sprintf( 'http://vimeo.com/api/v2/video/%s.php', $id );
		$response = wp_remote_get( $url,  array( 'timeout' => 15 ) );
		if( ! is_wp_error( $response ) && isset( $response['response']['code'] ) && 200 === $response['response']['code'] ) {
			$body	= unserialize(wp_remote_retrieve_body( $response ));
			return $body[0]['duration'];
		}
	}
}

/*
	Description		: Get Dailymotion video duration
	Author			: Anass El Fakir
	Source			: http://stackoverflow.com/a/22579177/2535061
	Developed by	: Mouad achemli
	Note			: this function is important do not remove from here
*/
function dailymotion_duration($id) {
	if (!is_array($id)) {
		$url      = sprintf( 'https://api.dailymotion.com/video/%s?fields=duration', $id );
		$response = wp_remote_get( $url,  array( 'timeout' => 15 ) );
		if( ! is_wp_error( $response ) && isset( $response['response']['code'] ) && 200 === $response['response']['code'] ) {
			$body		= wp_remote_retrieve_body( $response );
			$duration 	= json_decode( $body , TRUE );
			return $duration['duration'];
		}
	}	
}

/*
	Generate data info for videos
*/
function video_field_addinfo() { 
	
	global $post;
	$postid = $post->ID;
	// Get videos ids from content
	$old_shortcode 		= get_shortcode_vsw($postid);
	$new_shortcode 		= get_new_shortcode($postid);
	$get_youtube 		= get_youtube_id($postid);
	$get_vimeo 			= get_vimeo_id($postid); 
	$get_dailymotion 	= get_dailymotion_id($postid);
	
	// Get from old theme list of custom field
	$custom_field_yt = mwp_option('youtube_costum_field_list');
	$custom_field_vm = mwp_option('vimeo_costum_field_list');
	$custom_field_dm = mwp_option('dailymotion_costum_field_list');

	// Create array for old custom field
	$ytid = explode( ',', $custom_field_yt);
	$vmid = explode( ',', $custom_field_vm);
	$dmid = explode( ',', $custom_field_dm);
	
	// check custom field if exists
	$key_exists_yt = metadata_exists( 'post', $postid, 'mwp_yt_id' );
	$key_exists_yd = metadata_exists( 'post', $postid, 'mwp_yt_duration' );
	$key_exists_vi = metadata_exists( 'post', $postid, 'mwp_vi_id' );
	$key_exists_vd = metadata_exists( 'post', $postid, 'mwp_vi_duration' );
	$key_exists_dm = metadata_exists( 'post', $postid, 'mwp_dm_id' );
	$key_exists_dd = metadata_exists( 'post', $postid, 'mwp_dm_duration' );
	$key_exists_fv = metadata_exists( 'post', $postid, 'mwp_fb_id' );
	
	// Youtube old theme custom field
	if (isset($ytid[0])) {
		$key_exists_y1 = metadata_exists( 'post', $postid, $ytid[0]);
	} else { 
		$key_exists_y1 = false;
	}
	if (isset($ytid[1])) {
		$key_exists_y2 = metadata_exists( 'post', $postid, $ytid[1]);
	} else { 
		$key_exists_y2 = false;
	}
	if (isset($ytid[2])) {
		$key_exists_y3 = metadata_exists( 'post', $postid, $ytid[2]);
	} else { 
		$key_exists_y3 = false;
	}
	if (isset($ytid[3])) {
		$key_exists_y4 = metadata_exists( 'post', $postid, $ytid[3]);
	} else { 
		$key_exists_y4 = false;
	}
	if (isset($ytid[4])) {
		$key_exists_y5 = metadata_exists( 'post', $postid, $ytid[4]);
	} else { 
		$key_exists_y5 = false;
	}
	
	// Vimeo old theme custom field
	if (isset($vmid[0])) {
		$key_exists_v1 = metadata_exists( 'post', $postid, $vmid[0]);
	} else { 
		$key_exists_v1 = false;
	}
	if (isset($vmid[1])) {
		$key_exists_v2 = metadata_exists( 'post', $postid, $vmid[1]);
	} else { 
		$key_exists_v2 = false;
	}
	if (isset($vmid[2])) {
		$key_exists_v3 = metadata_exists( 'post', $postid, $vmid[2]);
	} else { 
		$key_exists_v3 = false;
	}
	if (isset($vmid[3])) {
		$key_exists_v4 = metadata_exists( 'post', $postid, $vmid[3]);
	} else { 
		$key_exists_v4 = false;
	}
	if (isset($vmid[4])) {
		$key_exists_v5 = metadata_exists( 'post', $postid, $vmid[4]);
	} else { 
		$key_exists_v5 = false;
	}
	
	// Dailymotion old theme custom field
	if (isset($dmid[0])) {
		$key_exists_d1 = metadata_exists( 'post', $postid, $dmid[0]);
	} else { 
		$key_exists_d1 = false;
	}
	if (isset($dmid[1])) {
		$key_exists_d2 = metadata_exists( 'post', $postid, $dmid[1]);
	} else { 
		$key_exists_d2 = false;
	}
	if (isset($dmid[2])) {
		$key_exists_d3 = metadata_exists( 'post', $postid, $dmid[2]);
	} else { 
		$key_exists_d3 = false;
	}
	if (isset($dmid[3])) {
		$key_exists_d4 = metadata_exists( 'post', $postid, $dmid[3]);
	} else { 
		$key_exists_d4 = false;
	}
	if (isset($dmid[4])) {
		$key_exists_d5 = metadata_exists( 'post', $postid, $dmid[4]);
	} else { 
		$key_exists_d5 = false;
	}
	// get custom field value (Video ID)
	$meta_yt = get_post_meta($postid, 'mwp_yt_id' , true);
	$meta_vi = get_post_meta($postid, 'mwp_vi_id' , true);
	$meta_dm = get_post_meta($postid, 'mwp_dm_id' , true);
	$meta_fb = get_post_meta($postid, 'mwp_fb_id' , true);
	
	// get custom field value (Video Duration)
	$meta_yd = get_post_meta($postid, 'mwp_yt_duration' , true);
	$meta_vd = get_post_meta($postid, 'mwp_vi_duration' , true);
	$meta_dd = get_post_meta($postid, 'mwp_dm_duration' , true);
	
	// Youtube old custom field
	
	if (isset($ytid[0])) :
	$check_y1 = get_post_meta($postid, $ytid[0] , true);
	endif;
	if (isset($ytid[1])) :
	$check_y2 = get_post_meta($postid, $ytid[1] , true);
	endif;
	if (isset($ytid[2])) :
	$check_y3 = get_post_meta($postid, $ytid[2] , true);
	endif;
	if (isset($ytid[3])) :
	$check_y4 = get_post_meta($postid, $ytid[3] , true);
	endif;
	if (isset($ytid[4])) :
	$check_y5 = get_post_meta($postid, $ytid[4] , true);
	endif;
	
	// Vimeo old custom field
	if (isset($vmid[0])) :
	$check_v1 = get_post_meta($postid, $vmid[0] , true);
	endif;
	if (isset($vmid[1])) :
	$check_v2 = get_post_meta($postid, $vmid[1] , true);
	endif;
	if (isset($vmid[2])) :
	$check_v3 = get_post_meta($postid, $vmid[2] , true);
	endif;
	if (isset($vmid[3])) :
	$check_v4 = get_post_meta($postid, $vmid[3] , true);
	endif;
	if (isset($vmid[4])) :
	$check_v5 = get_post_meta($postid, $vmid[4] , true);
	endif;
	
	// Dailymotion old custom field
	if (isset($dmid[0])) :
	$check_d1 = get_post_meta($postid, $dmid[0] , true);
	endif;
	if (isset($dmid[1])) :
	$check_d2 = get_post_meta($postid, $dmid[1] , true);
	endif;
	if (isset($dmid[2])) :
	$check_d3 = get_post_meta($postid, $dmid[2] , true);
	endif;
	if (isset($dmid[3])) :
	$check_d4 = get_post_meta($postid, $dmid[3] , true);
	endif;
	if (isset($dmid[4])) :
	$check_d5 = get_post_meta($postid, $dmid[4] , true);
	endif;
	
	if (!empty($old_shortcode['id'])) {
		
		$type = $old_shortcode['source'];
		
		switch( $type ) {
		
			case 'youtube':
				$yt_duration = secondsToTime(youtube_duration($old_shortcode['id']));
				if($key_exists_yt == true) {
					if ($meta_yt != $old_shortcode['id']) {
						update_post_meta($postid, 'mwp_yt_id', $old_shortcode['id']);
					}
				} else {
					add_post_meta($postid, 'mwp_yt_id', $old_shortcode['id'], true );
				}
				if($key_exists_yd == true) {
					if ($meta_yd != $yt_duration) {
						update_post_meta($postid, 'mwp_yt_duration', $yt_duration);
					}
				} else {
					add_post_meta($postid, 'mwp_yt_duration', $yt_duration, true );
				}
			break;
			case 'vimeo':
				$vi_duration = secondsToTime(vimeo_duration($old_shortcode['id']));
				if($key_exists_vi == true) {
					if ($meta_vi != $old_shortcode['id']) {
						update_post_meta($postid, 'mwp_vi_id', $old_shortcode['id']);
					}
				} else {
					add_post_meta($postid, 'mwp_vi_id', $old_shortcode['id'], true );
				}
				if($key_exists_vd == true) {
					if ($meta_vd != $vi_duration) {
						update_post_meta($postid, 'mwp_vi_duration', $vi_duration);
					}
				} else {
					add_post_meta($postid, 'mwp_vi_duration', $vi_duration, true );
				}
			break;
			case 'dailymotion':
				$dd_duration = secondsToTime(dailymotion_duration($old_shortcode['id']));
				if($key_exists_dm == true) {
					if ($meta_dm != $old_shortcode['id']) {
						update_post_meta($postid, 'mwp_dm_id', $old_shortcode['id']);
					}
				} else {
					add_post_meta($postid, 'mwp_dm_id', $old_shortcode['id'], true );
				}
				if($key_exists_dd == true) {
					if ($meta_dd != $dd_duration) {
						update_post_meta($postid, 'mwp_dm_duration', $dd_duration);
					}
				} else {
					add_post_meta($postid, 'mwp_dm_duration', $dd_duration, true );
				}
			break;
		}
		
	} elseif (!empty($new_shortcode['id'])) {

		$type = $new_shortcode['source'];
		
		switch( $type ) {
			case 'youtube':
				$yt_duration = secondsToTime(youtube_duration($new_shortcode['id']));
				if($key_exists_yt == true) {
					if ($meta_yt != $new_shortcode['id']) {
						update_post_meta($postid, 'mwp_yt_id', $new_shortcode['id']);
					}
				} else {
					add_post_meta($postid, 'mwp_yt_id', $new_shortcode['id'], true );
				}
				if($key_exists_yd == true) {
					if ($meta_yd != $yt_duration) {
						update_post_meta($postid, 'mwp_yt_duration', $yt_duration);
					}
				} else {
					add_post_meta($postid, 'mwp_yt_duration', $yt_duration, true );
				}
			break;
			case 'vimeo':
				$vi_duration = secondsToTime(vimeo_duration($new_shortcode['id']));
				if($key_exists_vi == true) {
					if ($meta_vi != $new_shortcode['id']) {
						update_post_meta($postid, 'mwp_vi_id', $new_shortcode['id']);
					}
				} else {
					add_post_meta($postid, 'mwp_vi_id', $new_shortcode['id'], true );
				}
				if($key_exists_vd == true) {
					if ($meta_vd != $vi_duration) {
						update_post_meta($postid, 'mwp_vi_duration', $vi_duration);
					}
				} else {
					add_post_meta($postid, 'mwp_vi_duration', $vi_duration, true );
				}
			break;
			case 'dailymotion':
				$dd_duration = secondsToTime(dailymotion_duration($new_shortcode['id']));
				if($key_exists_dm == true) {
					if ($meta_dm != $new_shortcode['id']) {
						update_post_meta($postid, 'mwp_dm_id', $new_shortcode['id']);
					}
				} else {
					add_post_meta($postid, 'mwp_dm_id', $new_shortcode['id'], true );
				}
				if($key_exists_dd == true) {
					if ($meta_dd != $dd_duration) {
						update_post_meta($postid, 'mwp_dm_duration', $dd_duration);
					}
				} else {
					add_post_meta($postid, 'mwp_dm_duration', $dd_duration, true );
				}
			break;
			case 'facebook':
				if($key_exists_fv == true) {
					if ($meta_fb != $new_shortcode['id']) {
						update_post_meta($postid, 'mwp_fb_id', $new_shortcode['id']);
					}
				} else {
					add_post_meta($postid, 'mwp_fb_id', $new_shortcode['id'], true );
				}
			break;
		}
		
	} elseif (!empty($get_youtube)) {
		$yt_duration = secondsToTime(youtube_duration($get_youtube));
		if($key_exists_vi == true) {
			if ($meta_vi != $get_youtube) {
				update_post_meta($postid, 'mwp_yt_id', $get_youtube);
			}
		} else {
			add_post_meta($postid, 'mwp_yt_id', $get_youtube, true );
		}
		if($key_exists_yd == true) {
			if ($meta_yd != $yt_duration) {
				update_post_meta($postid, 'mwp_yt_duration', $yt_duration);
			}
		} else {
			add_post_meta($postid, 'mwp_yt_duration', $yt_duration, true );
		}
	} elseif (!empty($get_vimeo)) {
		$vi_duration = secondsToTime(vimeo_duration($get_vimeo));
		if($key_exists_vi == true) {
			if ($meta_vi != $get_vimeo) {
				update_post_meta($postid, 'mwp_vi_id', $get_vimeo);
			}
		} else {
			add_post_meta($postid, 'mwp_vi_id', $get_vimeo, true );
		}
		if($key_exists_vd == true) {
			if ($meta_vd != $vi_duration) {
				update_post_meta($postid, 'mwp_vi_duration', $vi_duration);
			}
		} else {
			add_post_meta($postid, 'mwp_vi_duration', $vi_duration, true );
		}
	} elseif (!empty($get_dailymotion)) {
		$dd_duration = secondsToTime(dailymotion_duration($get_dailymotion));
		if($key_exists_vi == true) {
			if ($meta_vi != $get_dailymotion) {
				update_post_meta($postid, 'mwp_dm_id', $get_dailymotion);
			}
		} else {
			add_post_meta($postid, 'mwp_dm_id', $get_dailymotion, true );
		}
		if($key_exists_dd == true) {
			if ($meta_dd != $dd_duration) {
				update_post_meta($postid, 'mwp_dm_duration', $dd_duration);
			}
		} else {
			add_post_meta($postid, 'mwp_dm_duration', $dd_duration, true );
		}	
	} elseif ($key_exists_y1 == true && !empty($check_y1)) {

		$get_y1_id = mwp_ytcheck_url($check_y1);
		if (!empty($get_y1_id)) {
			$yt_duration = secondsToTime(youtube_duration($get_y1_id));
			add_post_meta($postid, 'mwp_yt_id', $get_y1_id, true);
			add_post_meta($postid, 'mwp_yt_duration' ,$yt_duration, true);
		} else {
			$yt_duration = secondsToTime(youtube_duration($check_y1));
			add_post_meta($postid, 'mwp_yt_id', $check_y1, true);
			add_post_meta($postid, 'mwp_yt_duration' ,$yt_duration, true);
		}	
	} elseif ($key_exists_y2 == true && !empty($check_y2)) {

		$get_y2_id = mwp_ytcheck_url($check_y2);
		if (!empty($get_y2_id)) {
			$yt_duration = secondsToTime(youtube_duration($get_y2_id));
			add_post_meta($postid, 'mwp_yt_id', $get_y2_id, true);
			add_post_meta($postid, 'mwp_yt_duration' ,$yt_duration, true);
		} else {
			$yt_duration = secondsToTime(youtube_duration($check_y2));
			add_post_meta($postid, 'mwp_yt_id', $check_y2, true);
			add_post_meta($postid, 'mwp_yt_duration' ,$yt_duration, true);
		}	
	} elseif ($key_exists_y3 == true && !empty($check_y3)) {

		$get_y3_id = mwp_ytcheck_url($check_y3);
		if (!empty($get_y3_id)) {
			$yt_duration = secondsToTime(youtube_duration($get_y3_id));
			add_post_meta($postid, 'mwp_yt_id', $get_y3_id, true);
			add_post_meta($postid, 'mwp_yt_duration' ,$yt_duration, true);
		} else {
			$yt_duration = secondsToTime(youtube_duration($check_y3));
			add_post_meta($postid, 'mwp_yt_id', $check_y3, true);
			add_post_meta($postid, 'mwp_yt_duration' ,$yt_duration, true);
		}	
	} elseif ($key_exists_y4 == true && !empty($check_y4)) {

		$get_y4_id = mwp_ytcheck_url($check_y4);
		if (!empty($get_y4_id)) {
			$yt_duration = secondsToTime(youtube_duration($get_y4_id));
			add_post_meta($postid, 'mwp_yt_id', $get_y4_id, true);
			add_post_meta($postid, 'mwp_yt_duration' ,$yt_duration, true);
		} else {
			$yt_duration = secondsToTime(youtube_duration($check_y4));
			add_post_meta($postid, 'mwp_yt_id', $check_y4, true);
			add_post_meta($postid, 'mwp_yt_duration' ,$yt_duration, true);
		}	
	} elseif ($key_exists_y5 == true && !empty($check_y5)) {

		$get_y5_id = mwp_ytcheck_url($check_y5);
		if (!empty($get_y5_id)) {
			$yt_duration = secondsToTime(youtube_duration($get_y5_id));
			add_post_meta($postid, 'mwp_yt_id', $get_y5_id, true);
			add_post_meta($postid, 'mwp_yt_duration' ,$yt_duration, true);
		} else {
			$yt_duration = secondsToTime(youtube_duration($check_y5));
			add_post_meta($postid, 'mwp_yt_id', $check_y5, true);
			add_post_meta($postid, 'mwp_yt_duration' ,$yt_duration, true);
		}	
	} elseif ($key_exists_v1 == true && !empty($check_v1)) {

		$check = mwp_vicheck_url($check_v1);
		if (!empty($check)) {
			$vi_duration = secondsToTime(vimeo_duration($check));
			add_post_meta($postid, 'mwp_vi_id', $check, true );
			add_post_meta($postid, 'mwp_vi_duration', $vi_duration, true );
		} else {
			$vi_duration = secondsToTime(vimeo_duration($check_v1));
			add_post_meta($postid, 'mwp_vi_id', $check_v1, true );
			add_post_meta($postid, 'mwp_vi_duration', $vi_duration, true );
		}
		
	} elseif ($key_exists_v2 == true && !empty($check_v2)) {

		$check = mwp_vicheck_url($check_v2);
		if (!empty($check)) {
			$vi_duration = secondsToTime(vimeo_duration($check));
			add_post_meta($postid, 'mwp_vi_id', $check, true );
			add_post_meta($postid, 'mwp_vi_duration', $vi_duration, true );
		} else {
			$vi_duration = secondsToTime(vimeo_duration($check_v2));
			$vi_thumbnail = mwp_vi_get_thumb($check_v2);
			add_post_meta($postid, 'mwp_vi_id', $check_v2, true );
			add_post_meta($postid, 'mwp_vi_duration', $vi_duration, true );
		}
		
	} elseif ($key_exists_v3 == true && !empty($check_v3)) {

		$check = mwp_vicheck_url($check_v3);
		if (!empty($check)) {
			$vi_duration = secondsToTime(vimeo_duration($check));
			add_post_meta($postid, 'mwp_vi_id', $check, true );
			add_post_meta($postid, 'mwp_vi_duration', $vi_duration, true );
		} else {
			$vi_duration = secondsToTime(vimeo_duration($check_v3));
			add_post_meta($postid, 'mwp_vi_id', $check_v3, true );
			add_post_meta($postid, 'mwp_vi_duration', $vi_duration, true );
		}
		
	} elseif ($key_exists_v4 == true && !empty($check_v4)) {

		$check = mwp_vicheck_url($check_v4);
		if (!empty($check)) {
			$vi_duration = secondsToTime(vimeo_duration($check));
			add_post_meta($postid, 'mwp_vi_id', $check, true );
			add_post_meta($postid, 'mwp_vi_duration', $vi_duration, true );
		} else {
			$vi_duration = secondsToTime(vimeo_duration($check_v4));
			add_post_meta($postid, 'mwp_vi_id', $check_v4, true );
			add_post_meta($postid, 'mwp_vi_duration', $vi_duration, true );
		}
		
	} elseif ($key_exists_v5 == true && !empty($check_v5)) {

		$check = mwp_vicheck_url($check_v5);
		if (!empty($check)) {
			$vi_duration = secondsToTime(vimeo_duration($check));
			add_post_meta($postid, 'mwp_vi_id', $check, true );
			add_post_meta($postid, 'mwp_vi_duration', $vi_duration, true );
		} else {
			$vi_duration = secondsToTime(vimeo_duration($check_v5));
			add_post_meta($postid, 'mwp_vi_id', $check_v5, true );
			add_post_meta($postid, 'mwp_vi_duration', $vi_duration, true );
		}
		
	} elseif ($key_exists_d1 == true && !empty($check_d1)) {

		$check = mwp_dmcheck_url($check_d1);
		if (!empty($check)) {
			$dd_duration = secondsToTime(dailymotion_duration($check));
			add_post_meta($postid, 'mwp_dm_id', $check, true );
			add_post_meta($postid, 'mwp_dm_duration', $dd_duration, true );
		} else {
			$dd_duration = secondsToTime(dailymotion_duration($check_d1));
			add_post_meta($postid, 'mwp_dm_id', $check_d1, true );
			add_post_meta($postid, 'mwp_dm_duration', $dd_duration, true );
		}
		
	} elseif ($key_exists_d2 == true && !empty($check_d2)) {

		$check = mwp_dmcheck_url($check_d2);
		if (!empty($check)) {
			$dd_duration = secondsToTime(dailymotion_duration($check));
			add_post_meta($postid, 'mwp_dm_id', $check, true );
			add_post_meta($postid, 'mwp_dm_duration', $dd_duration, true );
		} else {
			$dd_duration = secondsToTime(dailymotion_duration($check_d2));
			$dd_thumbnail = mwp_dm_get_thumb($check_d2);
			add_post_meta($postid, 'mwp_dm_id', $check_d2, true );
			add_post_meta($postid, 'mwp_dm_duration', $dd_duration, true );
		}
		
	} elseif ($key_exists_d3 == true && !empty($check_d3)) {

		$check = mwp_dmcheck_url($check_d3);
		if (!empty($check)) {
			$dd_duration = secondsToTime(dailymotion_duration($check));
			add_post_meta($postid, 'mwp_dm_id', $check, true );
			add_post_meta($postid, 'mwp_dm_duration', $dd_duration, true );
		} else {
			$dd_duration = secondsToTime(dailymotion_duration($check_d3));
			add_post_meta($postid, 'mwp_dm_id', $check_d3, true );
			add_post_meta($postid, 'mwp_dm_duration', $dd_duration, true );
		}
		
	} elseif ($key_exists_d4 == true && !empty($check_d4)) {

		$check = mwp_dmcheck_url($check_d4);
		if (!empty($check)) {
			$dd_duration = secondsToTime(dailymotion_duration($check));
			add_post_meta($postid, 'mwp_dm_id', $check, true );
			add_post_meta($postid, 'mwp_dm_duration', $dd_duration, true );
		} else {
			$dd_duration = secondsToTime(dailymotion_duration($check_d4));
			$dd_thumbnail = mwp_dm_get_thumb($check_d4);
			add_post_meta($postid, 'mwp_dm_id', $check_d4, true );
			add_post_meta($postid, 'mwp_dm_duration', $dd_duration, true );
		}
		
	} elseif ($key_exists_d5 == true && !empty($check_d5)) {

		$check = mwp_dmcheck_url($check_d5);
		if (!empty($check)) {
			$dd_duration = secondsToTime(dailymotion_duration($check));
			add_post_meta($postid, 'mwp_dm_id', $check, true );
			add_post_meta($postid, 'mwp_dm_duration', $dd_duration, true );
		} else {
			$dd_duration = secondsToTime(dailymotion_duration($check_d5));
			$dd_thumbnail = mwp_dm_get_thumb($check_d5);
			add_post_meta($postid, 'mwp_dm_id', $check_d5, true );
			add_post_meta($postid, 'mwp_dm_duration', $dd_duration, true );
		}
		
	}
}

function check_video_field_addinfo() {
	global $pagenow;
	global $post;
	
	if (is_edit_page('edit') && get_post_type($post->ID) == 'post' ){
	
	$postid = $post->ID;
	$data_content = get_post($postid);
	$data = $data_content->post_content;
		
		if ( has_shortcode( $data, 'vsw' ) || has_shortcode( $data, 'vid' ) || get_dailymotion_id($postid) || get_vimeo_id($postid) || get_youtube_id($postid)) :
			return video_field_addinfo();
		endif;
	}
	
}
add_action('publish_post', 'check_video_field_addinfo');
add_action('save_post', 'check_video_field_addinfo');

function mwp_add_thumbnail_field() {
	global $pagenow;
	global $post;
	
	
	if (is_edit_page('edit') && get_post_type($post->ID) == 'post' ){
		
		if ( has_post_thumbnail($post->ID) ) {
			$image_key_exists 	= metadata_exists( 'post', $post->ID, 'mwp_thumbnail_url' );
			$image_check 		= get_post_meta( $post->ID, 'mwp_thumbnail_url', true);
			$image				= wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full' );
			$url 				= $image['0'];

			if($image_key_exists == true && !empty($image_key_exists) ) {
				if ($image_check != $url) {
					delete_post_meta($post->ID, 'mwp_thumbnail_url', '' );
					add_post_meta($post->ID, 'mwp_thumbnail_url', $url, true );
				} else {
					update_post_meta($post->ID, 'mwp_thumbnail_url', $url, true );
				}	
			} else {
				add_post_meta($post->ID, 'mwp_thumbnail_url', $url, true );
			}
		}
		
	}
	
}
add_action('publish_post', 'mwp_add_thumbnail_field');
add_action('save_post', 'mwp_add_thumbnail_field');

require_once( get_template_directory() . '/panel/core/video-image-dl.php' );

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists