nguyenvanduocit
10/30/2015 - 4:05 PM

Plugin to support oember with zing

Plugin to support oember with zing

<?php

/*
Plugin Name: Zing Oembed
Plugin URI: http://URI_Of_Page_Describing_Plugin_and_Updates
Description: A brief description of the Plugin.
Version: 1.0
Author: nguyenvanduocit
Author URI: http://URI_Of_The_Plugin_Author
License: A "Slug" license name e.g. GPL2
*/

wp_embed_register_handler('zing-oembed', '#http?://(www\.)?mp3\.zing\.vn/(bai-hat|video-clip|album|playlist)/([a-zA-Z,\-]+)/([a-zA-Z,\d]*)\.html#i', 'my_zing_oembed_callback');

function my_zing_oembed_callback($matches, $attr, $url, $raw_attr){
	$embedCode = false;
	$pattern = null;
	switch($matches[2]){
		case 'bai-hat':
			$pattern = '<iframe class="zingmp3embed song-embed" width="600" height="168" src="http://mp3.zing.vn/embed/song/%1$s" frameborder="0" allowfullscreen="true"></iframe>';
			break;
		case 'video-clip':
			$pattern = '<iframe class="zingmp3embed video-embed" width="450" height="291" src="http://mp3.zing.vn/embed/video/%1$s?autostart=false" frameborder="0" allowfullscreen="true"></iframe>';
			break;
		case 'album':
		case 'playlist':
			$pattern = '<iframe class="zingmp3embed album_playlist-embed" width="410" height="300" src="http://mp3.zing.vn/embed/album/%1$s?autostart=false" frameborder="0" allowfullscreen="true"></iframe>';
			break;
	}
	if ($pattern) {
		$embedCode = sprintf(
			$pattern,
			esc_attr($matches[4])
		);
	}
	return $embedCode;
}