<?php
/*
/*---------------------------------------------------------*/
/* KENTOOZ SHORTCODE FRAMEWORK - PREMIUM ONLY
/* We have more than 100 Shortcode Not all includes in theme
/* Website: kentooz.com
/* The Author: Gian Mokhammad Ramadhan 
/* Social network :twitter.com/g14nnakal facebook.com/gianmr
/* Version :1.0
/*---------------------------------------------------------*/

// Do not load directly...
if ( ! defined( 'ABSPATH' ) ) { die( 'Direct access forbidden.' ); }

function ktz_shortcodes_js() {
	global $pagenow;
  	if ( $pagenow == 'post.php' || $pagenow == 'post-new.php' || $pagenow == 'page-new.php' || $pagenow == 'page.php' ) {
		wp_enqueue_script("shortcode_js", ktz_url."includes/shortcodes/js/scripts.js", false, "1.0");
	}
}
add_action( 'admin_enqueue_scripts', 'ktz_shortcodes_js' );

/*******************************************
# Functions add button to tinymce editor
*******************************************/
add_action('init', 'add_buttons');
function add_buttons() {
    if ( current_user_can('edit_posts') &&  current_user_can('edit_pages') )
    {
	  add_filter('mce_external_plugins', 'add_plugins');
      add_filter('mce_buttons', 'register_buttons');	  
    }
 }

function register_buttons( $buttons ) {
	array_push( $buttons, '|', 'ktz_shortcodes' );
	return $buttons;

}

function add_plugins( $plugin_array ) {
	$plugin_array['ktz_shortcodes'] = ktz_url . 'includes/shortcodes/tinymce.js';
	return $plugin_array;

}

/*******************************************
# Functions register shortcode to init
*******************************************/
function kentooz_add_shortcodes() {
	add_shortcode('googlemap', 'googlemap'); /* format [googlemap height="" weight="" src=""][/googlemap] */
	add_shortcode('vimeo', 'vimeo'); /* format [vimeo height="" weight="" url=""][/vimeo] */
	add_shortcode('youtube', 'youtube'); /* format [youtube height="" weight="" url=""][/youtube] */
	add_shortcode('soundcloud', 'soundcloud'); /* format [soundcloud height="" weight="" url=""][/soundcloud] */
}
add_action( 'init', 'kentooz_add_shortcodes' );

/*******************************************
# Better cache function shortcode button
*******************************************/
function my_refresh_mce($ver) {
	$ver += 3;
	return $ver;
}

add_filter( 'tiny_mce_version', 'my_refresh_mce');

/*******************************************
# Function shorcode - youtube
# iframe is get warning in theme check
*******************************************/
function youtube($atts) {
	extract(shortcode_atts(array(
				"width" => '100%',
				"height" => '300',
				"src" => ''
		 ), $atts));
	$widths = empty($width) ? '' : $width;
	$heights = empty($height) ? '' : $height;
	$srcs = empty($src) ? '' : $src;
	return '<div class="video-container" style="margin-top:20px;"><iframe width="'. esc_attr ( $widths ) .'" height="'. esc_attr ( $heights ) .'" src="http://www.youtube.com/embed/' . esc_attr ( $srcs ) . '" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowfullscreen></iframe></div>';
}

/*******************************************
# Function shorcode - vimeo
# iframe is get warning in theme check
*******************************************/
function vimeo($atts) {
	extract(shortcode_atts(array(
				"width" => '100%',
				"height" => '300',
				"src" => ''
		 ), $atts));
	$widths = empty($width) ? '' : $width;
	$heights = empty($height) ? '' : $height;
	$srcs = empty($src) ? '' : $src;
	return '<div class="video-container" style="margin-top:20px;"><iframe width="'. esc_attr ( $widths ) .'" height="'. esc_attr ( $heights ) .'" src="http://player.vimeo.com/video/' . esc_attr ( $srcs ) . '" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe></div>';
}

/*******************************************
# Function shorcode - souncloud
# With iframe now with better speed
*******************************************/
function soundcloud($atts) {
	extract(shortcode_atts(array(
				"url" => ''
		 ), $atts));
	$urls = empty($url) ? '' : $url;
	return '<iframe width="100%" height="166" scrolling="no" frameborder="no" src="http://w.soundcloud.com/player/?url=' . esc_url ( $urls ) . '&amp;auto_play=false&amp;show_artwork=true&amp;color=ff7700"></iframe>';
}

/*******************************************
# Function shorcode - googlemap
# iframe is get warning in theme check
*******************************************/
function googlemap($atts) {
	extract(shortcode_atts(array(
				"width" => '100%',
				"height" => '',
				"src" => ''
		 ), $atts));
	$widths = empty($width) ? '' : $width;
	$heights = empty($height) ? '' : $height;
	$srcs = empty($src) ? '' : $src;
	return '<iframe width="'. esc_attr ( $widths ).'" height="'. esc_attr ( $heights ) .'" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="'. esc_attr ( $srcs ) .'&amp;output=embed" ></iframe>';
}