<?php
/* CHECK LIST SHORTCODE */
add_shortcode('checklist', 'shortcode_checklist');
	function shortcode_checklist( $atts, $content = null ) {
	$content = str_replace('<ul>', '<ul class="checklist">', do_shortcode($content));
	$content = str_replace('<li>', '<li>', do_shortcode($content));
	return $content;
}

/* YOTUBE SHORTCODE */
add_shortcode('youtube', 'shortcode_youtube');
  function shortcode_youtube($atts) {
  $atts = shortcode_atts(
  array(
 'id' => '',
 'width' => 633,
 'height' => 356
), $atts);

return '<div class="video-shortcode"><iframe title="YouTube video player" width="' . $atts['width'] . '" height="' . $atts['height'] . '" src="http://www.youtube.com/embed/' . $atts['id'] . '?wmode=transparent" frameborder="0" allowfullscreen></iframe></div>';
	}
	
/* VIMEO SHORTCODE */
add_shortcode('vimeo', 'shortcode_vimeo');
  function shortcode_vimeo($atts) {
  $atts = shortcode_atts(
  array(
  'id' => '',
  'width' => 633,
  'height' => 340
), $atts);
		
return '<div class="video-shortcode"><iframe src="http://player.vimeo.com/video/' . $atts['id'] . '" width="' . $atts['width'] . '" height="' . $atts['height'] . '" frameborder="0"></iframe></div>';
	}
	
/* SOUNDCLOUD SHORTCODE */
add_shortcode('soundcloud', 'shortcode_soundcloud');
  function shortcode_soundcloud($atts) {
  $atts = shortcode_atts(
  array(
  'url' => '',
  'width' => '100%',
  'height' => 81,
  'comments' => 'true',
  'auto_play' => 'true',
  'color' => 'fb2900',
), $atts);
		
return '<div class="soundcloud-shortcode"><object height="' . $atts['height'] . '" width="' . $atts['width'] . '"><param name="movie" value="http://player.soundcloud.com/player.swf?url=' . urlencode($atts['url']) . '&amp;show_comments=' . $atts['comments'] . '&amp;auto_play=' . $atts['auto_play'] . '&amp;color=' . $atts['color'] . '"></param><param name="allowscriptaccess" value="always"></param><embed allowscriptaccess="always" height="' . $atts['height'] . '" src="http://player.soundcloud.com/player.swf?url=' . urlencode($atts['url']) . '&amp;show_comments=' . $atts['comments'] . '&amp;auto_play=' . $atts['auto_play'] . '&amp;color=' . $atts['color'] . '" type="application/x-shockwave-flash" width="' . $atts['width'] . '"></embed></object></div>';
	}

/* BAD LIST SHORTCODE */
add_shortcode('badlist', 'shortcode_badlist');
	function shortcode_badlist( $atts, $content = null ) {
	$content = str_replace('<ul>', '<ul class="badlist">', do_shortcode($content));
	$content = str_replace('<li>', '<li>', do_shortcode($content));
	return $content;
}

/* TABS SHORTCODE */
add_shortcode('tabs', 'shortcode_tabs');
	function shortcode_tabs( $atts, $content = null ) {
	extract(shortcode_atts(array(
    ), $atts));
	$out .= '<div class="tabs-wrapper">';
	$out .= '<ul class="tabs">';
	foreach ($atts as $key => $tab) {
		$out .= '<li><a href="#' . $key . '">' . $tab . '</a></li>';
	}
	$out .= '</ul>';
	$out .= '<div class="tabs_container">';
	$out .= do_shortcode($content) .'</div></div>';
	return $out;
}

add_shortcode('tab', 'shortcode_tab');
	function shortcode_tab( $atts, $content = null ) {
	extract(shortcode_atts(array(
    ), $atts));
	$out .= '<div id="tab' . $atts['id'] . '" class="tab_content">' . do_shortcode($content) .'</div>';
	return $out;
}

/* TOGGLE SHORTCODE */

 function shortcode_toggle( $atts, $content = null ) {
 extract( shortcode_atts(
 array(
 'title' => '',
 'color' => ''
 ),
 $atts ) );
 return '<h5 class="toggle"><a href="#">' .$title. '</a></h5><div class="toggle-content"><div class="block">' . do_shortcode($content) . '</div></div>';
 }
 add_shortcode('toggle', 'shortcode_toggle');



/* DROPCAP SHORTCODE */
add_shortcode('dropcap', 'shortcode_dropcap');
	function shortcode_dropcap( $atts, $content = null ) {
	return '<span class="dropcap">' .do_shortcode($content). '</span>';
}

/* BUTTON SHORTCODE */
add_shortcode('button', 'shortcode_button');
	function shortcode_button($atts, $content = null) {
	$atts = shortcode_atts(
	array(
	'color' => 'black',
	'link' => '#',
	'target' => '',
	), $atts);
	return '<span class="button ' . $atts['color'] . '"><a href="' . $atts['link'] . '">' .do_shortcode($content). '</a></span>';
	}

/* INFO BOX SHORTCODE */
add_shortcode('infobox', 'shortcode_infobox');
	function shortcode_infobox($atts, $content = null) {
	$atts = shortcode_atts(
	array(
	'color' => 'light', 'yellow', 'red', 'green', 'blue',
	), $atts);
	return '<div class="infobox ' . $atts['color'] . '">' .do_shortcode($content). '</div>';
	}

/* HIGHLIGHT SHORTCODE */
add_shortcode('highlight', 'shortcode_highlight');
	function shortcode_highlight($atts, $content = null) {
	$atts = shortcode_atts(
	array(
	'color' => 'yellow', 'red', 'green', 'blue', 'black',
    ), $atts);
	return '<span class="highlight-' . $atts['color'] . '">' .do_shortcode($content). '</span>';
	}


/* COLUMN ONE HALF SHORTCODE */
add_shortcode('one_half', 'shortcode_one_half');
	function shortcode_one_half($atts, $content = null) {
	$atts = shortcode_atts(
	array(
	'last' => 'no',
	), $atts);
	if($atts['last'] == 'yes') {
	return '<div class="one_half last">' .do_shortcode($content). '</div><div class="clearboth"></div>';
	} else {
	return '<div class="one_half">' .do_shortcode($content). '</div>';
	}
}

/* COLUMN ONE THIRD SHORTCODE */
add_shortcode('one_third', 'shortcode_one_third');
	function shortcode_one_third($atts, $content = null) {
	$atts = shortcode_atts(
	array(
	'last' => 'no',
	), $atts);
	if($atts['last'] == 'yes') {
	return '<div class="one_third last">' .do_shortcode($content). '</div><div class="clearboth"></div>';
	} else {
	return '<div class="one_third">' .do_shortcode($content). '</div>';
	}
}

/* COLUMN TWO THIRD SHORTCODE */
add_shortcode('two_third', 'shortcode_two_third');
	function shortcode_two_third($atts, $content = null) {
	$atts = shortcode_atts(
	array(
	'last' => 'no',
	), $atts);
	if($atts['last'] == 'yes') {
	return '<div class="two_third last">' .do_shortcode($content). '</div><div class="clearboth"></div>';
	} else {
	return '<div class="two_third">' .do_shortcode($content). '</div>';
	}
}

/* COLUMN ONE FOURTH SHORTCODE */
add_shortcode('one_fourth', 'shortcode_one_fourth');
	function shortcode_one_fourth($atts, $content = null) {
	$atts = shortcode_atts(
	array(
	'last' => 'no',
	), $atts);
	if($atts['last'] == 'yes') {
	return '<div class="one_fourth last">' .do_shortcode($content). '</div><div class="clearboth"></div>';
	} else {
	return '<div class="one_fourth">' .do_shortcode($content). '</div>';
	}
}

/* COLUMN THREE FOURTH SHORTCODE */
add_shortcode('three_fourth', 'shortcode_three_fourth');
	function shortcode_three_fourth($atts, $content = null) {
	$atts = shortcode_atts(
	array(
	'last' => 'no',
	), $atts);
	if($atts['last'] == 'yes') {
	return '<div class="three_fourth last">' .do_shortcode($content). '</div><div class="clearboth"></div>';
	} else {
	return '<div class="three_fourth">' .do_shortcode($content). '</div>';
	}
}

/* ADD BUTTONS TO tinyMCE */
add_action('init', 'add_button');
function add_button() {
   if ( current_user_can('edit_posts') &&  current_user_can('edit_pages') )
   {
   add_filter('mce_external_plugins', 'add_plugin');
   add_filter('mce_buttons_3', 'register_button');
   }
}

function register_button($buttons) {
   array_push($buttons, "youtube", "vimeo", "soundcloud", "checklist", "badlist", "tabs", "toggle", "dropcap", "button", "infobox", "highlight", "one_half", "one_third", "two_third", "one_fourth", "three_fourth");
   return $buttons;
}

function add_plugin($plugin_array) {
   $plugin_array['youtube'] = get_template_directory_uri().'/tinymce/customcodes.js';
   $plugin_array['vimeo'] = get_template_directory_uri().'/tinymce/customcodes.js';
   $plugin_array['soundcloud'] = get_template_directory_uri().'/tinymce/customcodes.js';
   $plugin_array['checklist'] = get_template_directory_uri().'/tinymce/customcodes.js';
   $plugin_array['badlist'] = get_template_directory_uri().'/tinymce/customcodes.js';
   $plugin_array['tabs'] = get_template_directory_uri().'/tinymce/customcodes.js';
   $plugin_array['toggle'] = get_template_directory_uri().'/tinymce/customcodes.js';
   $plugin_array['dropcap'] = get_template_directory_uri().'/tinymce/customcodes.js';
   $plugin_array['button'] = get_template_directory_uri().'/tinymce/customcodes.js';
   $plugin_array['infobox'] = get_template_directory_uri().'/tinymce/customcodes.js';
   $plugin_array['highlight'] = get_template_directory_uri().'/tinymce/customcodes.js';
   $plugin_array['one_half'] = get_template_directory_uri().'/tinymce/customcodes.js';
   $plugin_array['one_third'] = get_template_directory_uri().'//tinymce/customcodes.js';
   $plugin_array['two_third'] = get_template_directory_uri().'/tinymce/customcodes.js';
   $plugin_array['one_fourth'] = get_template_directory_uri().'/tinymce/customcodes.js';
   $plugin_array['three_fourth'] = get_template_directory_uri().'/tinymce/customcodes.js';
   return $plugin_array;
}