<?php
/**
 * @copyright	Copyright (c) 2016 AmyTheme (http://www.amytheme.com). All rights reserved.
 * @license		http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
 */

defined( 'ABSPATH' ) or die;

/**
 * Get sidebar name.
 */
if ( ! function_exists( 'amy_movie_get_sidebar_name' ) ) {
	function amy_movie_get_sidebar_name( $name ) {
		if ( empty( $GLOBALS['wp_registered_sidebars'] ) ) {
			return $name;
		}

		$sidebars	= get_option( 'stag_custom_sidebars' );
		$taken		= array();

		foreach ( $GLOBALS['wp_registered_sidebars'] as $sidebar ) {
			$taken[]	= $sidebar['name'];
		}

		if ( empty( $sidebars ) ) {
			$sidebars	= array();
		}

		$taken	= array_merge( $taken, $sidebars );

		if ( in_array( $name, $taken ) ) {
			$counter 	= substr( $name, -1 );

			if ( ! is_numeric( $counter ) ) {
				$new_name	= $name . ' 1';
			} else {
				$new_name	= substr( $name, 0, -1 ) . ((int) $counter + 1);
			}

			$name = amy_movie_get_sidebar_name( $new_name );
		}

		return $name;
	}
}

/**
 * Get registered sidebars
 */
if ( ! function_exists( 'amy_movie_wp_registered_sidebars' ) ) {
	function amy_movie_wp_registered_sidebars() {
		global $wp_registered_sidebars;

		$widgets	= array();

		if ( ! empty( $wp_registered_sidebars ) ) {
			foreach ( $wp_registered_sidebars as $key => $value ) {
				$widgets[ $key ]	= $value['name'];
			}
		}

		return array_reverse( $widgets );
	}
}

/**
 * Check Google Fonts
 */
if ( ! function_exists( 'amy_movie_is_google_font' ) ) {
	function amy_movie_is_google_font( $font_family ) {
		static $google_fonts;

		if ( empty( $google_fonts ) ) {
			$google_json	= amy_get_google_fonts();

			if ( is_object( $google_json ) ) {
				$google_fonts	= array();

				foreach ( $google_json->items as $key => $font ) {
					$google_fonts[ $font->family ]	= $font->variants;
				}
			}
		}

		return is_array( $google_fonts ) && array_key_exists( $font_family, $google_fonts );
	}
}

/**
 * Enqueue Google Fonts.
 */
if ( ! function_exists( 'amy_movie_enqueue_google_fonts' ) ) {
	function amy_movie_enqueue_google_fonts() {
		$embed_fonts	= array();
		$query_args		= array();
		$subsets		= amy_get_option( 'subsets' );
		$subsets		= ! empty( $subsets ) ? '&subset=' . implode( ',', $subsets ) : '';
		$typography		= amy_get_option( 'typography' );
		$google_json	= amy_get_google_fonts();

		if ( empty( $typography ) ) {
			return;
		}

		foreach ( $typography as $font ) {
			if ( ! empty( $font['selector'] ) ) {
				if ( amy_movie_is_google_font( $font['font']['family'] ) ) {
					$family		= $font['font']['family'];
					$variant	= $font['font']['variant'] != 'regular' ? $font['font']['variant'] : 400;
					$embed_fonts[ $family ]['variant'][ $variant ]	= $variant;
				}
			}
		}

		if ( ! empty( $embed_fonts ) ) {
			foreach ( $embed_fonts as $name => $font ) {
				$variants		= $font['variant'];
				$embed_variants	= ! empty( $font['variant'] ) ? ':' . implode( ',', $font['variant'] ) : '';
				$query_args[]	= $name . $embed_variants;
			}

			wp_enqueue_style( 'amy-movie-google-fonts', esc_url( add_query_arg( 'family', urlencode( implode( '|', $query_args ) ) . $subsets, '//fonts.googleapis.com/css' ) ) );
		}
	}
}

/*
 * Get all custom sizes of image
 */
if ( ! function_exists( 'amy_movie_get_image_sizes' ) ) {
	function amy_movie_get_image_sizes( $force = false, $flip = true ) {
		$current_image_sizes	= get_intermediate_image_sizes();

		foreach ( $current_image_sizes as $image_size ) {
			$dimenssion					= (in_array( $image_size, array( 'thumbnail', 'medium', 'large' ) )) ? ' - (' . get_option( $image_size . '_size_w' ) . 'x' . get_option( $image_size . '_size_h' ) . ')' : '';
			$image_sizes[ $image_size ]	= $image_size . $dimenssion;
		}

		if ( $force ) {
			$get_custom_image_sizes	= amy_get_option( 'custom_image_sizes' );

			if ( ! empty( $get_custom_image_sizes ) ) {
				foreach ( $get_custom_image_sizes as $custom_size ) {
					$name						= sanitize_title( $custom_size['img_size_name'] );
					$custom_image_sizes[ $name ]	= $name . ' - (' . $custom_size['img_size_width'] . 'x' . $custom_size['img_size_height'] . ')';
				}

				$image_sizes	= array_filter( array_merge( $image_sizes, $custom_image_sizes ) );
			}
		}

		$image_sizes['full']	= 'full (orginal size)';
		$image_sizes			= ($flip) ? array_flip( $image_sizes ) : $image_sizes;

		return apply_filters( 'amy_movie_custom_image_sizes', $image_sizes );
	}
}

/**
 * encapsulates post-classes to use them on different tags
 */
if ( ! function_exists( 'amy_movie_get_post_classes' ) ) {
	function amy_movie_get_post_classes( $classes = array() ) {
		// Adds a class for microformats v2
		$classes[] = 'h-entry';

		// add hentry to the same tag as h-entry
		$classes[] = 'hentry';

		// adds microformats 2 activity-stream support
		// for pages and articles
		if ( get_post_type() === 'page' ) {
			$classes[] = 'h-as-page';
		}
		if ( ! get_post_format() && 'post' === get_post_type() ) {
			$classes[] = 'h-as-article';
		}

		// adds some more microformats 2 classes based on the
		// posts "format"
		switch ( get_post_format() ) {
			case 'aside':
			case 'status':
				$classes[] = 'h-as-note';
				break;
			case 'audio':
				$classes[] = 'h-as-audio';
				break;
			case 'video':
				$classes[] = 'h-as-video';
				break;
			case 'gallery':
			case 'image':
				$classes[] = 'h-as-image';
				break;
			case 'link':
				$classes[] = 'h-as-bookmark';
				break;
		}

		return array_unique( $classes );
	}
}

/**
 * add semantics
 *
 * @param string $id the class identifier
 * @return array
 */
if ( ! function_exists( 'amy_movie_get_semantics' ) ) {
	function amy_movie_get_semantics( $id = null ) {
		$classes = array();

		// add default values
		switch ( $id ) {
			case 'body':
				if ( ! is_singular() ) {
					$classes['itemscope'] 	= array( '' );
					$classes['itemtype'] 	= array( 'http://schema.org/Blog' );
				} elseif ( is_single() ) {
					$classes['itemscope'] 	= array( '' );
					$classes['itemtype'] 	= array( 'http://schema.org/BlogPosting' );
				} elseif ( is_page() ) {
					$classes['itemscope'] 	= array( '' );
					$classes['itemtype'] 	= array( 'http://schema.org/WebPage' );
				}

				break;
			case 'site-title':
				if ( ! is_singular() ) {
					$classes['itemprop'] 	= array( 'name' );
					$classes['class'] 		= array( 'p-name' );
				}

				break;
			case 'site-description':
				if ( ! is_singular() ) {
					$classes['itemprop'] 	= array( 'description' );
					$classes['class'] 		= array( 'p-summary', 'e-content' );
				}

				break;
			case 'site-url':
				if ( ! is_singular() ) {
					$classes['itemprop'] 	= array( 'url' );
					$classes['class'] 		= array( 'u-url', 'url' );
				}

				break;
			case 'post':
				if ( ! is_singular() ) {
					$classes['itemprop'] 	= array( 'blogPost' );
					$classes['itemscope'] 	= array( '' );
					$classes['itemtype'] 	= array( 'http://schema.org/BlogPosting' );
				}

				break;
		}

		$classes = apply_filters( 'amy_movie_semantics', $classes, $id );
		$classes = apply_filters( "amy_movie_semantics_{$id}", $classes, $id );

		return $classes;
	}
}

/**
 * echos the semantic classes added via
 *
 * @param string $id the class identifier
 */
if ( ! function_exists( 'amy_movie_semantics' ) ) {
	function amy_movie_semantics( $id ) {
		$classes = amy_movie_get_semantics( $id );

		if ( ! $classes ) {
			return;
		}

		foreach ( $classes as $key => $value ) {
			echo ' ' . esc_attr( $key ) . '="' . esc_attr( join( ' ', $value ) ) . '"';
		}
	}
}

/*
 * Custom Movie Query
 */
if ( ! function_exists( 'amy_movie_query' ) ) {
	function amy_movie_query( $params ) {
		$post_date		= isset( $params['movie_date'] ) 		? $params['movie_date'] 	: '';
		$post_orderby	= isset( $params['movie_orderby'] ) 	? $params['movie_orderby'] 	: '';
		$post_order		= isset( $params['movie_order'] ) 	? $params['movie_order'] 	: '';
		$genre			= isset( $params['movie_genre'] ) 	? $params['movie_genre'] 	: '';
		$mrelease		= isset( $params['movie_release'] ) 	? $params['movie_release'] 	: '';
		$mcinema 		= isset( $params['movie_cinema'] ) 	? $params['movie_cinema'] 	: '';
		$mper_page		= isset( $params['movie_per_page'] )	? $params['movie_per_page']	: '';
		$paged			= isset( $params['paged'] )			? $params['paged']			: '';
		$sortby			= isset( $params['sortby'] )			? $params['sortby']			: '';

		if ( $mrelease != '' ) {
			$release	= array(
				'key'		=> '_amy_movie_release',
				'value'		=> strtotime( $mrelease ),
				'compare' 	=> '=',
			);
		} else {
			$release		= '';
		}

		if ( $mcinema != '' ) {
			$cinema	= array(
				'key'		=> '_amy_movie_cinema',
				'value'		=> 'amy' . $mcinema . 'c',
				'compare' 	=> 'LIKE',
			);
		} else {
			$cinema		= '';
		}

		if ( $genre != '' ) {
			$tax_query_genre = array(
				'taxonomy'	=> 'amy_genre',
				'field'		=> 'term_id',
				'terms'		=> explode( ',', $genre ),
			);
		} else {
			$tax_query_genre = '';
		}

		$query_date = array();

		if ( $post_date == 'day' ) {
			$query_date = array(
				array(
					'after'	=> '24 hours ago',
				),
			);
		} else if ( $post_date == 'week' ) {
			$query_date = array(
				array(
					'after'	=> '1 week ago',
				),
			);
		} else if ( $post_date == 'month' ) {
			$query_date = array(
				array(
					'after'	=> '1 month ago',
				),
			);
		} else if ( $post_date == 'cm' ) {
			$query_date = '';

			$current_day = strtotime( current_time( 'Y/m/d' ) );

			$release	= array(
				'key'		=> '_amy_movie_release',
				'value'		=> $current_day,
				'compare' 	=> '>',
			);
		}

		if ( $sortby != 'default' && $sortby != 'release_date' && $sortby != '' ) {
			$orderby = $sortby;
		} else if ( $sortby == 'title' ) {
			$orderby 	= $post_orderby;
			$post_order	= 'DESC';
		} else {
			$orderby	= $post_orderby;
		}

		if ( $sortby == 'undefined' ) {
			$orderby	= $post_orderby;
		}

		if ( $sortby == 'release_date' ) {
			$arpg	= array(
				'post_type'	=> 'amy_movie',
				'tax_query'	=> array(
					$tax_query_genre,
				),
				'meta_query'	=> array(
					$release,
					$cinema,
				),
				'date_query'		=> $query_date,
				'posts_per_page'	=> $mper_page,
				'meta_key'			=> '_amy_movie_release',
				'orderby'			=> 'meta_value',
				'order'				=> $post_order,
				'paged'				=> $paged,
			);
		} else {
			if ( $post_orderby == '_amy_movie_rate' || $post_orderby == '_amy_movie_release' || $post_orderby == '_amy_post_views_count' ) {
				$arpg	= array(
					'post_type'	=> 'amy_movie',
					'tax_query'	=> array(
						$tax_query_genre,
					),
					'meta_query'	=> array(
						$release,
						$cinema,
					),
					'date_query'		=> $query_date,
					'posts_per_page'	=> $mper_page,
					'meta_key'			=> $orderby,
					'orderby'			=> 'meta_value_num',
					'order'				=> $post_order,
					'paged'				=> $paged,
				);
			} else {
				$arpg	= array(
					'post_type'	=> 'amy_movie',
					'tax_query'	=> array(
						$tax_query_genre,
					),
					'meta_query'	=> array(
						$release,
						$cinema,
					),
					'date_query'		=> $query_date,
					'posts_per_page'	=> $mper_page,
					'orderby'			=> $orderby,
					'order'				=> $post_order,
					'paged'				=> $paged,
				);
			}
		}

		return $arpg;
	}
}

/*
 * Get Poster Movie
 */
if ( ! function_exists( 'amy_movie_get_poster' ) ) {
	function amy_movie_get_poster( $mid, $img_size ) {
		$arr 	= get_post_meta( $mid, '_movie_poster', true );
		$image	= '';

		if ( isset( $arr['movie_poster'] ) ) {
			$image	= wp_get_attachment_image( $arr['movie_poster'], $img_size );
		}

		return $image;

	}
}

/*
 * Get Banner Movie
 */
if ( ! function_exists( 'amy_movie_get_banner' ) ) {
	function amy_movie_get_banner( $mid, $img_size ) {
		$arr 	= get_post_meta( $mid, '_movie_banner', true );
		$image	= '';

		if ( isset( $arr['movie_banner'] ) ) {
			$image	= wp_get_attachment_image( $arr['movie_banner'], $img_size );
		}

		return $image;

	}
}

/*
 * Get Details Movie
 */
if ( ! function_exists( 'amy_movie_get_details' ) ) {
	function amy_movie_get_details( $mid ) {
		$details = get_post_meta( $mid, '_movie_block_details', true );

		return $details;
	}
}

/*
 * Get Movie Rating
 */
if ( ! function_exists( 'amy_movie_get_rating' ) ) {
	function amy_movie_get_rating( $mid ) {
		$rating = get_post_meta( $mid, '_movie_block_rating', true );

		return $rating;
	}
}

/*
 * Get Movie Genre
 */
if ( ! function_exists( 'amy_movie_get_genre' ) ) {
	function amy_movie_get_genre() {
		$args = array(
			'taxonomy' => 'amy_genre',
		);

		$genres = get_terms( $args );

		return $genres;
	}
}

/*
 * Get Cinema
 */
if ( ! function_exists( 'amy_movie_get_cinema' ) ) {
	function amy_movie_get_cinema() {
		$cinema_list = get_posts(array(
			'posts_per_page'	=> -1,
			'post_type'		=> 'amy_cinema',
			'post_status'   => 'publish',
		));

		return $cinema_list;
	}
}

/*
 * Get List Movie
 */
if ( ! function_exists( 'amy_movie_get_movie' ) ) {
	function amy_movie_get_movie() {
		$movie_list = get_posts(array(
			'posts_per_page'	=> -1,
			'post_type'		=> 'amy_movie',
			'post_status'   => 'publish',
		));

		return $movie_list;
	}
}

/*
 * Social List
 */
if ( ! function_exists( 'amy_movie_social_list' ) ) {
	function amy_movie_social_list() {
		$fb_link 	= amy_get_option( 'facebook_url' );
		$gg_link 	= amy_get_option( 'twitter_url' );
		$tw_link 	= amy_get_option( 'google_url' );
		$printerest = amy_get_option( 'pinterest_url' );

		$html = '<ul class="amy-social-list">';

		if ( $fb_link ) {
			$html .= '<li><a href="' . esc_url( $fb_link ) . '" class="fa fa-facebook"></a></li>';
		}

		if ( $tw_link ) {
			$html .= '<li><a href="' . esc_url( $tw_link ) . '" class="fa fa-twitter"></a></li>';
		}

		if ( $gg_link ) {
			$html .= '<li><a href="' . esc_url( $gg_link ) . '" class="fa fa-google-plus"></a></li>';
		}

		if ( $printerest ) {
			$html .= '<li><a href="' . esc_url( $printerest ) . '" class="fa fa-pinterest"></a></li>';
		}

		$html .= '</ul>';

		return $html;
	}
}

/*
 * Login / Register
 */

if ( ! function_exists( 'amy_movie_user' ) ) {
	function amy_movie_user() {
		$html  = '<div class="box-user">';

		if ( is_user_logged_in() ) {
			$current_user = wp_get_current_user();
			$html .= '<span>' . esc_html__( 'Hello ', 'amy-movie' ) . $current_user->display_name . ',</span>';
			$html .= '<a href="' . wp_logout_url() . '">' . esc_html__( 'Log Out', 'amy-movie' ) . '</a>';
		} else {
			if ( function_exists( 'amy_user_popup' ) ) {
				$html .= amy_user_popup();
			} else {
				$html .= '<a href="' . esc_url( home_url( '/wp-login.php' ) ) . '"><i aria-hidden="true" class="fa fa-user"></i>' . esc_html__( 'Login', 'amy-movie' ) . '</a>';

				if ( get_option( 'users_can_register' ) ) {
					$html	.= '<a href="' . esc_url( home_url( '/wp-login.php?action=register' ) ) . '">' . esc_html__( 'Register', 'amy-movie' ) . '</a>';
				}
			}
		}

		$html .= '</div>';

		return $html;
	}
}

/*
 * Show Menu by ID
 */
if ( ! function_exists( 'amy_movie_menu_item' ) ) {
	function amy_movie_menu_item( $slug ) {
		$menu = wp_get_nav_menu_items( $slug );

		$html  = '<div class="amy-menu">';
		$html .= '<ul class="menu">';

		if ( ! empty( $menu ) ) {
			foreach ( $menu as $item ) {
				$html .= '<li class="menu-item">';
				$html .= '<a href="' . esc_url( $item->url ) . '">' . esc_attr( $item->title ) . '</a>';
				$html .= '</li>';
			}
		}

		$html .= '</ul></div>';

		return $html;
	}
}

/*
 * Convert minutes to hour
 */
if ( ! function_exists( 'amy_movie_converttime' ) ) {
	function amy_movie_converttime( $time ) {
		$format = '%02d ' . esc_html__( 'hours', 'amy-movie' ) . ' %02d ' . esc_html__( 'minutes', 'amy-movie' );

		if ( $time < 1 ) {
			return;
		}

		$hours 		= floor( $time / 60 );
		$minutes 	= ($time % 60);

		return sprintf( $format, $hours, $minutes );
	}
}

/*
 * Show star movie
 */
if ( ! function_exists( 'amy_movie_show_star' ) ) {
	function amy_movie_show_star( $m_id ) {
		$star = '<ul class="movie-rating-stars">';
		$star .= '<li><a class="movie-rating-star movie-rating-star-1" data-value="1" data-post="' . $m_id . '"></a></li>';
		$star .= '<li><a class="movie-rating-star movie-rating-star-2" data-value="2" data-post="' . $m_id . '"></a></li>';
		$star .= '<li><a class="movie-rating-star movie-rating-star-3" data-value="3" data-post="' . $m_id . '"></a></li>';
		$star .= '<li><a class="movie-rating-star movie-rating-star-4" data-value="4" data-post="' . $m_id . '"></a></li>';
		$star .= '<li><a class="movie-rating-star movie-rating-star-5" data-value="5" data-post="' . $m_id . '"></a></li>';
		$star .= '</ul>';

		return $star;
	}
}

/*
 * Get movie actor
 */
if ( ! function_exists( 'amy_movie_get_movie_taxomony' ) ) {
	function amy_movie_get_movie_taxomony( $movie_id, $type ) {
		$taxomonys	= wp_get_post_terms( $movie_id, $type );

		$html 		= '';
		$numItems 	= count( $taxomonys );
		$i 			= 0;

		if ( ! empty( $taxomonys ) ) {
			foreach ( $taxomonys as $taxomony ) {
				if ( ++$i === $numItems ) {
					$space = '';
				} else {
					$space = ', ';
				}

				$html .= '<a href="' . get_term_link( $taxomony->slug, $type ) . '">';
				$html .= $taxomony->name;
				$html .= '</a>';
				$html .= $space;
			}
		}

		return $html;
	}
}

/*
 * Get movie showtime
 */
if ( ! function_exists( 'amy_movie_get_showtime' ) ) {
	function amy_movie_get_showtime( $m_id, $c_id, $date, $layout ) {
		$items 		= get_post_meta( $m_id, '_movie_block_cinema', true );
		$content 	= '';

		if ( isset( $items['amy_movie_cinema'] ) ) {
			$items = $items['amy_movie_cinema'];

			if ( ! empty( $items ) ) {
				foreach ( $items as $i => $item ) {
					if ( isset( $c_id ) && $c_id != '' ) {
						if ( $item['select_cinema'] == $c_id ) {
							for ( $j = 1; $j < 6; $j++ ) {
								$content .= amy_movie_check_number( $item, $j, $date );
							}
						}
					} else {
						if ( $layout == 'tsl' ) {
							$content .= '<div class="showtime-item"><h3>' . get_the_title( $item['select_cinema'] ) . '</h3><div class="st-item">';
						}

						for ( $j = 1; $j < 6; $j++ ) {
							$content .= amy_movie_check_number( $item, $j, $date );
						}

						if ( $layout == 'tsl' ) {
							$content .= '</div></div>';
						}
					}
				}
			}
		}

		return $content;
	}
}


if ( ! function_exists( 'amy_movie_check_number' ) ) {
	function amy_movie_check_number( $item, $number, $date ) {
		$content	= '';

		if ( $item[ 'cinema_date_' . $number ] != '' ) {
			$time_list 	= explode( ',', $item[ 'cinema_hour_' . $number ] );
			$day 		= strtotime( $item[ 'cinema_date_' . $number ] );
			$today 		= strtotime( date( 'Y-m-d' ) );

			if ( ($date == 'today' && $today == $day) || ($date == 'cm' && $day > $today) || ($date == 'all') ) {
				$content .= '<div><label>' . date_i18n( get_option( 'date_format' ), $day ) . '</label></div>';

				$content .= '<ul>';

				foreach ( $time_list as $t => $time ) {
					$content .= '<li>' . $time . '</li>';
				}

				$content .= '</ul>';
			}
		}

		return $content;
	}
}

/*
 * Get cinema in movie
 */
if ( ! function_exists( 'amy_movie_cinema_in_movie' ) ) {
	function amy_movie_cinema_in_movie( $movie_id ) {
		$items 		= get_post_meta( $movie_id, '_movie_block_cinema', true );
		$c_array	= array();

		if ( isset( $items['amy_movie_cinema'] ) ) {
			$items		= $items['amy_movie_cinema'];

			if ( ! empty( $items ) ) {
				foreach ( $items as $i => $item ) {
					$c_array[] = $item['select_cinema'];
				}
			}
		}

		return $c_array;
	}
}

/*
 * Default Image Size
 */
if ( ! function_exists( 'amy_movie_default_image_size' ) ) {
	function amy_movie_default_image_size() {
		$img_size = array();

		$img_size[0]['img_size_name'] 	= 'Movie Widget List';
		$img_size[0]['img_size_width'] 	= '118';
		$img_size[0]['img_size_height']	= '159';
		$img_size[0]['img_crop'] 		= '1';

		$img_size[1]['img_size_name'] 	= 'Blog Widget List';
		$img_size[1]['img_size_width'] 	= '120';
		$img_size[1]['img_size_height']	= '85';
		$img_size[1]['img_crop'] 		= '1';

		$img_size[2]['img_size_name'] 	= 'Blog Masonry Size 1';
		$img_size[2]['img_size_width'] 	= '360';
		$img_size[2]['img_size_height']	= '240';
		$img_size[2]['img_crop'] 		= '1';

		$img_size[3]['img_size_name'] 	= 'Blog Masonry Size 2';
		$img_size[3]['img_size_width'] 	= '360';
		$img_size[3]['img_size_height']	= '430';
		$img_size[3]['img_crop'] 		= '1';

		$img_size[4]['img_size_name'] 	= 'Blog Masonry Size 3';
		$img_size[4]['img_size_width'] 	= '750';
		$img_size[4]['img_size_height']	= '430';
		$img_size[4]['img_crop'] 		= '1';

		return $img_size;
	}
}

/*
 * Convert tralier
 */
if ( ! function_exists( 'amy_movie_convert_tralier_link' ) ) {
	function amy_movie_convert_tralier_link( $link ) {
		if ( strpos( $link, 'youtube' ) == true ) {
			parse_str( parse_url( $link, PHP_URL_QUERY ), $youtube );

			$newlink = 'https://www.youtube.com/embed/' . $youtube['v'] . '';
		} else if ( strpos( $link, 'vimeo.com' ) == true ) {
			$id		= (int) substr( parse_url( $link, PHP_URL_PATH ), 1 );

			$newlink = 'https://player.vimeo.com/video/' . $id . '';
		} else if ( strpos( $link, 'dailymotion.com' ) == true ) {
			$id = strtok( basename( $link ), '_' );

			$newlink = 'http://www.dailymotion.com/embed/video/' . $id . '';
		} else {
			$newlink = '';
		}

		return $newlink;
	}
}
