<?php 
/*********=============== Get Fixed Content ============*****************/
if(!function_exists('get_excerpt')){
	function get_excerpt($count){
	  global $post;
	  $permalink = get_permalink($post->ID);
	  $excerpt = get_the_content();
	  $excerpt = strip_tags($excerpt);
	  $excerpt = substr($excerpt, 0, $count);
	  $excerpt = substr($excerpt, 0, strripos($excerpt, " "));
	  $excerpt = $excerpt.'... ';
	  return $excerpt;
	}
}

/*********=============== Edit Search Form ============*****************/
if(!function_exists('rockon_search_form')){
	function rockon_search_form( $form ) {
		$form = '<form class="form-inline" role="search" method="get" action="' .esc_url(home_url( '/' )) . '" >
            <div class="form-group has-feedback">
				<label class="screen-reader-text" for="s">' . __( 'Search for:' ,'rockon' ) . '</label>
              <input type="text" class="form-control" placeholder="Search Keyword" id="s" value="'.get_search_query().'"  name="s">
              <span class="glyphicon glyphicon-search form-control-feedback"></span> </div>
          </form>';

		return $form;
	}
}
add_filter( 'get_search_form', 'rockon_search_form' );

/*********=============== Footer ============*****************/
if(!function_exists('rockon_youtubevideo_single')){
	function rockon_youtubevideo_single(  ) {
		if(is_single()){	
			$video = '';
			global $post;
			$audiosrc = get_post_meta( $post->ID, 'rockon_audio_src', true );
			if(!empty($audiosrc)){
				$filetype = wp_check_filetype($audiosrc);
				$type = $filetype['type'];
				$audiosrc = 'http:'.$audiosrc;
				if($type != 'audio/mpeg'){
					$video = '<script>var youtube = {"@type": "VideoObject","playerType": "iframe","embedURL":"'.esc_js($audiosrc).'"};mediaFactory.insert(youtube, {strategy: "mediaElement", width: 1140, height: 540}, "rockon_youtube_player");</script>';
				}
			}
			echo $video;
		}
	}
}
add_action( 'wp_footer', 'rockon_youtubevideo_single' );

/*********=============== Header ============*****************/
add_action('wp_head','customcss_rockonoption');
if(!function_exists('customcss_rockonoption')){
	function customcss_rockonoption(){
		global $rockon_data;
		$css = $rockon_data['rockon_customcss'];
		$css_output = "<!-- Custom CSS -->\n<style type=\"text/css\">\n" . $css . "\n</style>";
		if(!empty($css)) {
			echo $css_output;
		}
	}
}

/**
 * Add custom HTML between the `</h3>` and the `<form>` tags in the comment_form() output.
 */
function rockon_wpse_156112_rs( $comment_registration )
{
     // Adjust this to your needs:
     echo '<div class="rock_heading_div">
        <div class="rock_heading">
          <h1>'.__('Leave a Comment','rockon').'</h1>
          <p>X</p>
        </div>
      </div>'; 

    remove_filter( current_filter(), __FUNCTION__ );
    return $comment_registration;
}
add_action( 'comment_form_before', 'rockon_fun_comment_form' );
function rockon_fun_comment_form(){
    add_filter( 'pre_option_comment_registration', 'rockon_wpse_156112_rs' );
}

/*********==== Sidebar Position ====*****************/
function sidebar_position_post(){
	global $rockon_data; 
	$position = $rockon_data['rockon_sidebarposition'];
	switch($position){
		case 1:
			$position = 'full';
		break;
		case 2:
			$position = 'left';
		break;
		case 3:
			$position = 'right';
		break;
		default :
			$position = 'right';
		break;
	}
	return $position;
}

function rockon_plupload_admin_head() {  
// place js config array for plupload
    $plupload_init = array(
        'runtimes' => 'html5,silverlight,flash,html4',
        'browse_button' => 'plupload-browse-button', // will be adjusted per uploader
        'container' => 'plupload-upload-ui', // will be adjusted per uploader
        'drop_element' => 'drag-drop-area', // will be adjusted per uploader
        'file_data_name' => 'async-upload', // will be adjusted per uploader
        'multiple_queues' => true,
        'max_file_size' => wp_max_upload_size() . 'b',
        'url' => admin_url('admin-ajax.php'),
        'flash_swf_url' => includes_url('js/plupload/plupload.flash.swf'),
        'silverlight_xap_url' => includes_url('js/plupload/plupload.silverlight.xap'),
        'filters' => array(array('title' => __('Allowed Files','rockon'), 'extensions' => '*')),
        'multipart' => true,
        'urlstream_upload' => true,
        'multi_selection' => false, // will be added per uploader
         // additional post data to send to our ajax hook
        'multipart_params' => array(
            '_ajax_nonce' => "", // will be added per uploader
            'action' => 'plupload_action', // the ajax action name
            'imgid' => 0 // will be added per uploader
        )
    );
	echo '<script type="text/javascript"> var base_plupload_config='.json_encode($plupload_init).'</script>';
}
add_action("admin_head", "rockon_plupload_admin_head"); 
function rockon_g_plupload_action() {
 
    // check ajax noonce
    $imgid = $_POST["imgid"];
    check_ajax_referer($imgid . 'pluploadan');
 
    // handle file upload
    $status = wp_handle_upload($_FILES[$imgid . 'async-upload'], array('test_form' => true, 'action' => 'plupload_action'));
 
    // send the uploaded file url in response
    echo $status['url'];
    exit;
}
add_action('wp_ajax_plupload_action', "rockon_g_plupload_action"); 
?>