<?php 
/*
*	Disable Automatic Formatting In Wordpress Posts
* 	@http://www.wpbeginner.com/wp-tutorials/how-to-disable-automatic-formatting-in-wordpress-posts/
*/
function disable_formatter($content) {

	$new_content = '';
	$pattern_full = '{(\[raw\].*?\[/raw\])}is';
	$pattern_contents = '{\[raw\](.*?)\[/raw\]}is';
	$pieces = preg_split($pattern_full, $content, -1, PREG_SPLIT_DELIM_CAPTURE);
	foreach ($pieces as $piece) {
		if (preg_match($pattern_contents, $piece, $matches)) {
			$new_content .= $matches[1];
		} else {
			$new_content .= wptexturize(wpautop($piece));
		}
	}
	
	return $new_content;
}
remove_filter	('the_content',	'wpautop');
remove_filter	('the_content',	'wptexturize');
add_filter		('the_content', 'disable_formatter', 99);
add_filter		('widget_text', 'disable_formatter', 99);


/*
*	Shortcode: Default [????]
*/
function init_shortcode_default($atts, $content =  NULL, $case = NULL){
	return do_shortcode("<$case>$content</$case>");
}
add_shortcode('li', 'init_shortcode_default');
add_shortcode('h1', 'init_shortcode_default');
add_shortcode('h2', 'init_shortcode_default');
add_shortcode('h3', 'init_shortcode_default');
add_shortcode('h4', 'init_shortcode_default');
add_shortcode('h5', 'init_shortcode_default');
add_shortcode('h6', 'init_shortcode_default');
/*
*	Shortcode: 	 Grids
*	Attributes:	 id, style, class, top, bottom
*/
function init_grids($atts, $content =  NULL, $case = NULL){
	
	extract(shortcode_atts(array(
		'style'				=> NULL,
		'class'				=> NULL,
		'top'				=> NULL,
		'bottom'			=> NULL,
		'text_align'		=> NULL,
		'padding'			=> NULL
	), $atts));
	
switch($case):
	case 'full':case '1':$main_class = 'cl_1';$fix = true;	 		break;
	
	case '1of2':		$main_class = 'cl_2';					 	break;
	case '1of2_last': 	$main_class = 'cl_2 last';$fix = true; 		break;

	case '1of3':		$main_class = 'cl_3';					 	break;
	case '1of3_last':	$main_class = 'cl_3 last';$fix = true; 		break;
	case '2of3':		$main_class = 'cl_3_2';					 	break;
	case '2of3_last': 	$main_class = 'cl_3_2 last';$fix = true; 	break;
	
	case '1of4':		$main_class = 'cl_4';					 	break;
	case '1of4_last': 	$main_class = 'cl_4 last';$fix = true;		break;
	case '2of4':		$main_class = 'cl_2';					 	break;
	case '2of4_last': 	$main_class = 'cl_2 last';$fix = true; 		break;
	case '3of4':		$main_class = 'cl_4_3';				 		break;
	case '3of4_last': 	$main_class = 'cl_4_3 last';$fix = true;	break;

	case '1of5':		$main_class = 'cl_5';					 	break;
	case '1of5_last': 	$main_class = 'cl_5 last';$fix = true;		break;
	case '2of5':		$main_class = 'cl_5_2';					 	break;
	case '2of5_last': 	$main_class = 'cl_5_2 last';$fix = true; 	break;
	case '3of5':		$main_class = 'cl_5_3';				 		break;
	case '3of5_last': 	$main_class = 'cl_5_3 last';$fix = true;	break;
	case '4of5':		$main_class = 'cl_5_4';				 		break;
	case '4of5_last': 	$main_class = 'cl_5_4 last';$fix = true;	break;
	
	case '1of6':		$main_class = 'cl_6';					 	break;
	case '1of6_last': 	$main_class = 'cl_6 last';$fix = true;		break;
	case '2of6':		$main_class = 'cl_3';					 	break;
	case '2of6_last': 	$main_class = 'cl_3 last';$fix = true; 		break;
	case '3of6':		$main_class = 'cl_2';					 	break;
	case '3of6_last': 	$main_class = 'cl_2 last';$fix = true;		break;
	case '4of6':		$main_class = 'cl_6_4';					 	break;
	case '4of6_last': 	$main_class = 'cl_6_4 last';$fix = true;	break;
	case '5of6':		$main_class = 'cl_6_5';					 	break;
	case '5of6_last': 	$main_class = 'cl_6_5 last';$fix = true;	break;
endswitch;
	
	if ($id) {
		$id = "id=\"$id" ;
		}
	
	if ($style) {
		$style = "style=\"$style";
		}
	
	if ($class) {
		$main_class .= " $class";
		}
	
	if (isset($top)) {
		if ($style) $style .= " padding-top: $top"."px;"; else $style = "style=\"padding-top: $top"."px;";
		}
		
	if (isset($bottom)) {
		if ($style) $style .= " margin-bottom: $bottom"."px;"; else $style = "style=\"margin-bottom: $bottom"."px;";
		}
		
	if ($style) {
		$style .= "\" ";
		}
		
	if ($padding) {
		$content = "<div style=\"padding: $padding;\">$content</div>";
		}
		
	
	$out = "\n <div $id $style class=\"cl $main_class\">$content</div> \n";
	if ($fix) $out .= "\n <div class=\"cf\"></div> \n";

	return do_shortcode($out);

}
add_shortcode('1', 'init_grids');
add_shortcode('full', 'init_grids');
add_shortcode('1of2', 'init_grids');
add_shortcode('1of2_last', 'init_grids');
add_shortcode('1of3', 'init_grids');
add_shortcode('1of3_last', 'init_grids');
add_shortcode('2of3', 'init_grids');
add_shortcode('2of3_last', 'init_grids');
add_shortcode('1of4', 'init_grids');
add_shortcode('1of4_last', 'init_grids');
add_shortcode('2of4', 'init_grids');
add_shortcode('2of4_last', 'init_grids');
add_shortcode('3of4', 'init_grids');
add_shortcode('3of4_last', 'init_grids');
add_shortcode('1of5', 'init_grids');
add_shortcode('1of5_last', 'init_grids');
add_shortcode('2of5', 'init_grids');
add_shortcode('2of5_last', 'init_grids');
add_shortcode('3of5', 'init_grids');
add_shortcode('3of5_last', 'init_grids');
add_shortcode('4of5', 'init_grids');
add_shortcode('4of5_last', 'init_grids');
add_shortcode('1of6', 'init_grids');
add_shortcode('1of6_last', 'init_grids');
add_shortcode('2of6', 'init_grids');
add_shortcode('2of6_last', 'init_grids');
add_shortcode('3of6', 'init_grids');
add_shortcode('3of6_last', 'init_grids');
add_shortcode('4of6', 'init_grids');
add_shortcode('4of6_last', 'init_grids');
add_shortcode('5of6', 'init_grids');
add_shortcode('5of6_last', 'init_grids');

/*
*	Shortcode: 	 [blog]
*	Attributes:	 column, id, limit, style, title, cat
*/
function cloudfw_sc_blog($atts, $content =  NULL){
	
	extract(shortcode_atts(array(
		'id'				=> NULL,
		'columns'			=> 3,
		'limit'				=> 3,
		'cat'				=> NULL,
		'style'				=> 1,
		'title'				=> NULL,
		'height'			=> 100,
		'excerpt'			=> 0
	), $atts));
	
	$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
	

	if (!is_numeric($columns) || (int)$columns > 3 || (int)$columns < 1 ) $columns = 3;
	
	if (!is_numeric($limit)) $limit = $columns;
	if (!is_numeric($height)) $height = 100;
	
	if (!empty($id)) {
		$id = explode(",",$id);
		}
		
	if (!empty($cat)) {
		$cat = explode(",",$cat);
		}
		
	$post = new WP_Query();
	$arg = array(
		'post__in' 			=> $id,
		'category__in'		=> $cat,
		'posts_per_page'	=> $limit,
		'paged'				=> $paged,
	);
	
	
	$post->query($arg);
		
	$i = 0;
	if (!empty($title)) {$out .= '<h3>'.$title.'</h3>';}
		
	if($post->have_posts()) : while($post->have_posts()) : $post->the_post();
		$i ++;
		

		
		 
			$class = 'cl cl_'.$columns.'';
			if ($i%$columns == 0) $class .= ' last';
			if ($i !== 1)	$class .= ''; 
			if ($columns == 1)	$class = 'cl cl_1 last'; 
			
			
			$commentscount = get_comments_number();
			if ($commentscount > 0) $comment = ' | '. sprintf("%s comment", $commentscount);
			
			$blog_title = __translate( get_the_title() );
			
			
	if ($style == 1):
			$out .= '
			
				<div class="shortcode_minimal_blog_container '.$class.'">';
				if (has_post_thumbnail()) $out .= '<div class="blog-thumbnail" style="float:left; margin:0 15px 10px 0;">
					<a href="'.__url(get_permalink()).'" title="'.sprintf( esc_attr__( 'Permalink to %s', 'cloudfw' ), the_title_attribute( 'echo=0' ) ).'" rel="bookmark">'.get_the_post_thumbnail(get_the_ID(),array(75,75)).'</a>
				</div>';
				$out .= '
				<div class="blog-title">
					<a href="'.__url(get_permalink()).'" title="'.sprintf( esc_attr__( 'Permalink to %s', 'cloudfw' ), the_title_attribute( 'echo=0' ) ).'" rel="bookmark">'.__translate( get_the_title() ).'</a>
				</div>
				<div class="blog-metas">
					'.	sprintf( '<span class="blog-post-date" title="%1$s, %2$s">%1$s</span>',
                        get_the_date( $date_format ),
                        esc_attr( get_the_time( $time_format ) )).
						$comment
					.'
				</div>
				
				<div class="cf"></div>
				</div>
				';
		else:
		
		if (strlen($blog_title)>50) $blog_title = mb_substr($blog_title,0,50).'..';
		
		if (has_post_thumbnail()) {
			$thumbnail =  wp_get_attachment_image_src( get_post_thumbnail_id(), 'large', TRUE );
			$thumbnail_src = cloudfw_thumbnail(array('src'=> $thumbnail[0],'w'=> cloudfw_get_image_width($columns),'h'=> $height,'r'=> cloudfw_get_image_width($columns).':'.$height));
		}
		
			$out .= '
				<div class="shortcode_minimal_blog_container_style_2 '.$class.'">';
				if ($thumbnail_src) $out .= '<div class="blog-thumbnail">
					<a href="'.__url(get_permalink()).'" title="'.sprintf( esc_attr__( 'Permalink to %s', 'cloudfw' ), the_title_attribute( 'echo=0' ) ).'" rel="bookmark"><img src="'.$thumbnail_src.'" alt="'.the_title_attribute( 'echo=0' ).'"/><span class="blog-title">'.$blog_title.'</span></a>
				</div>';
				if ($excerpt == 1) $out .= '
				<div class="blog-excerpt">
					'. wp_the_excerpt_reloaded("excerpt_length=25&more_tag=span") .'
				</div>';
				$out .= '
				<div class="cf"></div>
				</div>
				';
		
		
		
		endif;
		
		
		endwhile;
		
		$out .= '<div class="cf"></div>';
		
		endif;
		
	wp_reset_query();	
		
	return "[raw]{$out}[/raw]";
	
	
	}
add_shortcode('blog', 'cloudfw_sc_blog');
	

/*
*	Shortcode: 	 [call_a_page]
*	Attributes:	 id
*/
function init_call_a_page($atts, $content =  NULL){
	
	extract(shortcode_atts(array(
		"id" 		=> NULL
	), $atts));
	
	if (empty($id) || !is_numeric($id) ) return false;
	
	global $post;
	
	$callpage_query = "showposts=1&page_id=$id";
	query_posts($callpage_query);

	if (have_posts()) : 
	the_post();
	$more = 0; 
	
		$out .= do_shortcode(get_the_content(__('Read More','cloudfw'), FALSE));

	endif;
	
	
	return $out;

}
add_shortcode('call_a_page', 'init_call_a_page');



/*
*	Shortcode: 	 [portfolio]
*	Attributes:	 id, from, columns, forcing, height, carousel, title
*/
function init_call_portfolio($atts, $content =  NULL, $case = NULL){
	global $wp_query;
	
	if (
		is_page_template( 'page-sidebar.php' )	||
		is_page_template( 'page-sidebar-left.php' ) ||
		is_page_template( 'page-blog.php' )
	) return cloudfw_fatalError(__('You cannot use <strong>[portfolio]</strong> shortcode with this page template','cloudfw'));

	if ( !isset( $atts['id'] ) || !is_numeric( $atts['id'] ) )
		return '<br/><br/>'.cloudfw_fatalError('<a href="'.get_edit_post_link($wp_query->queried_object_id).'">'.__('Please insert an ID key for the Portfolio Shortcode [portfolio] by editing this post','cloudfw').'</a>') . '<br/><br/>';
	
		$output = cloudfw_portfolio($atts);
	
	return $output;

}
add_shortcode('portfolio', 'init_call_portfolio');

/*
*	Shortcode: 	 [slider]
*	Attributes:	 id
*/
function init_call_slider($atts = array(), $content =  NULL){
	
	$output = cloudfw_get_the_slider($atts);
	
	return "[raw]{$output}[/raw]";

}
add_shortcode('slider', 'init_call_slider');

/*
*	Shortcode: 	 [icon_box]
*	Attributes:	 icon, title, color, content
*/
function init_call_icon_box($atts = array(), $content =  NULL){
	extract(shortcode_atts(array(
		"icon" 		=> NULL,
		"src" 		=> NULL,
		"title" 	=> NULL,
		"color"		=> '',
		"tag"		=> 'h3',
		"style_img" => '',
		"style_title"=> ''
	), $atts));
	
	$content = do_shortcode($content);

	if (!empty($src))
		$icon = $src;
	else
		$icon = cloudfw_make_icon_url($icon);
		
	
	if (!empty($icon)) {
		$_e_icon = "<span class=\"iconbox-icon\"><img"._isso($style_img, " style=\"".$style_img."\"")." src=\"".$icon."\"  alt=\"\"/></span>";
	}
		$_e_content = "<div class=\"iconbox-content\">"._isso($title, "<".$tag.""._isso($color, " style=\"".cloudfw_skin_engine_make_attribute(NULL,"color",$color)."\"").">{$title}</".$tag.">" )."{$content}</div>";
	
	$output = "<div class=\"iconbox\">{$_e_icon}{$_e_content}</div>";
	return "[raw]{$output}[/raw]";
}
add_shortcode('icon_box', 'init_call_icon_box');

/*
*	Shortcode: 	 [icon]
*	Attributes:	 src
*/
function init_call_icon($atts = array(), $content =  NULL){
	extract(shortcode_atts(array(
		"src" 		=> NULL,
		"external"	=> NULL
	), $atts));

	if (!empty($external))
		$src = $external;
	else
		$src = cloudfw_make_icon_url($src);

	
	if (!empty($src)) {
		$output = "<span class=\"icon\"><img src=\"".$src."\"  alt=\"\"/></span>";
		return $output;
	}
	return false;
}
add_shortcode('icon', 'init_call_icon');



/*
*	Shortcode: 	 [pricing_table]
*	Attributes:	 
*/
function init_call_pricing_table($atts = array(), $content =  NULL, $case = NULL){
	
switch($case):
	case 'pricing_table':
		return "<div class=\"pricing_table\">".do_shortcode($content)."</div>";
	break;
	case 'pricing_table_header':
		return "<div class=\"pricing_table_header\">".do_shortcode($content)."</div>";
	break;
	
endswitch;
}
add_shortcode('pricing_table', 'init_call_pricing_table');
add_shortcode('pricing_table_header', 'init_call_pricing_table');



/*
*	Shortcode: 	 [gallery]
*	@ Re-edit	 order, orderby, id, itemtag, icontag, captiontag, columns, size, include, exclude, link
*/

add_filter( 'post_gallery', 'my_post_gallery', 10, 2 );
function my_post_gallery( $output, $attr) {
    global $post, $wp_locale;

    static $instance = 0;
    $instance++;

    // We're trusting author input, so let's at least make sure it looks like a valid orderby statement
    if ( isset( $attr['orderby'] ) ) {
        $attr['orderby'] = sanitize_sql_orderby( $attr['orderby'] );
        if ( !$attr['orderby'] )
            unset( $attr['orderby'] );
    }

    extract(shortcode_atts(array(
        'order'      => 'ASC',
        'orderby'    => 'menu_order ID',
        'id'         => $post->ID,
        'itemtag'    => 'dl',
        'icontag'    => 'dt',
        'captiontag' => 'dd',
        'columns'    => 3,
        'size'       => 'thumbnail',
        'include'    => '',
        'exclude'    => '',
		'link'		 => 'file'
    ), $attr));

    $id = intval($id);
    if ( 'RAND' == $order )
        $orderby = 'none';

    if ( !empty($include) ) {
        $include = preg_replace( '/[^0-9,]+/', '', $include );
        $_attachments = get_posts( array('include' => $include, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) );

        $attachments = array();
        foreach ( $_attachments as $key => $val ) {
            $attachments[$val->ID] = $_attachments[$key];
        }
    } elseif ( !empty($exclude) ) {
        $exclude = preg_replace( '/[^0-9,]+/', '', $exclude );
        $attachments = get_children( array('post_parent' => $id, 'exclude' => $exclude, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) );
    } else {
        $attachments = get_children( array('post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) );
    }

    if ( empty($attachments) )
        return '';

    if ( is_feed() ) {
        $output = "\n";
        foreach ( $attachments as $att_id => $attachment )
            $output .= wp_get_attachment_link($att_id, $size, true) . "\n";
        return $output;
    }

    $itemtag = tag_escape($itemtag);
    $captiontag = tag_escape($captiontag);
    $columns = intval($columns);
    $itemwidth = $columns > 0 ? floor(100/$columns) : 100;
    $float = is_rtl() ? 'right' : 'left';

    $selector = "gallery_{$instance}";

    $output = apply_filters('gallery_style', "
        <style type='text/css'>
            #{$selector} {
                margin: auto;
                width: 100%;
            }
            #{$selector} .gallery-item {
                float: {$float};
               /* margin:0 20px 20px 0;*/
                text-align: center;
				width: {$itemwidth}%;
				display: block;
                }
            #{$selector} img {
				max-width: 95% !important;
				height: auto !important;
				margin: 0 auto;
            }
            #{$selector} .gallery-caption {
                margin-left: 0;
            }
        </style>

        <div id='$selector' class='gallery galleryid-{$id}'>");

    $i = 0; //
    foreach ( $attachments as $id => $attachment ) {
        $link = isset($attr['link']) && 'file' == $attr['link'] ? wp_get_attachment_link($id, $size, false, false) : wp_get_attachment_link($id, $size, true, false);

        $output .= "<{$itemtag} class='gallery-item'>";
        $output .= "
            <{$icontag} class='gallery-icon' data-group='$selector'>
                $link
            </{$icontag}>";
        if ( $captiontag && trim($attachment->post_excerpt) ) {
            $output .= "
                <{$captiontag} class='gallery-caption'>
                " . wptexturize($attachment->post_excerpt) . "
                </{$captiontag}>";
        }
        $output .= "</{$itemtag}>";
        if ( $columns > 0 && ++$i % $columns == 0 )
            $output .= '<br style="clear: both" />';
    }

    $output .= "
            <br style='clear: both;' />
        </div>\n";

    return $output;
}



/*
*	Shortcode: 	 [showcase]
*	Attributes:	 id, width, height, thumbnail(small, medium, large), order, ordeby, featured_image
*/
function init_showcase($atts, $content =  NULL){
	
	extract(shortcode_atts(array(
		'id'				=> get_the_ID(),
		'width' 			=> '440',
		'height'			=> '360',
		'order' 			=> 'ASC',
		"orderby"			=> 'menu_order',
		"thumbnails"		=> 'small',
		"featured_image"	=> 1
	), $atts));
	
	if (empty($id) || !is_numeric($id) ) return false;
	
	
	if (!is_numeric($width)) $width = 440;
	if (!is_numeric($height)) $height = 360;
	
	$width = $width.'px';
	$height = ($height+40).'px';
	
	
	$gallery = $attachments = get_children( array('post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) );
	$post_thumb_id = get_post_thumbnail_id($id);
	
	if (is_array($attachments)):
	
	$out = '<div class="galleria '.$thumbnails.'" style="width:'.$width.'; height:'.$height.';">';
	foreach ($gallery as $gal_id => $gal) {
		
		if ($post_thumb_id == $gal_id && !$featured_image) continue;
		
		 $title	= 	$gal -> post_title;
		 $desc	= 	$gal -> post_content;
		
		 $thumbnail = wp_get_attachment_image_src($gal_id, 'thumbnail', TRUE );
		 $thumbnail_src = cloudfw_thumbnail(array('src'=> $thumbnail[0],'w'=> 100,'h'=> 100,'r'=> '1:1'));
		 
		 $large = wp_get_attachment_image_src($gal_id, 'large', TRUE );
		 $large_src = $large[0];		
		 
		 $full = wp_get_attachment_image_src($gal_id, 'full', TRUE );
		 $full_src = $full[0];
		 
		 $out .= "				  
		   <a href=\"$large_src\"> <img title=\"$title\" alt=\"$desc\" src=\"$thumbnail_src\"></a>
		 ";
		 
		}
	$out .= '</div>';
	
	endif;
	
	return $out;

}
add_shortcode('showcase', 'init_showcase');


/*
*	Shortcode: 	 [button]
*	Attributes:	 link, color, size, target, rel
*/
function init_buttons($atts, $content =  NULL, $case = NULL){
	
	extract(shortcode_atts(array(
		'link'				=> NULL,
		'color'				=> "sky",
		'size'				=> "normal",
		'target'			=> NULL,
		'style'				=> NULL,
		'rel'				=> NULL
	), $atts));
	
	$cloudfw_button_colors = cloudfw_button_array();

		
		if ($size == "small") :
			$class = "small ";
		elseif ($size == "normal") :
		elseif ($size == "big") :
			$class = "large ";
		endif;
			
	$class .= $cloudfw_button_colors[$color]["class"];
	$attributes = '';

	if (!$link) $link = "#";
	if ($rel) $attributes .= " rel=\"$rel\"";
	if ($style) $attributes .= " style=\"$style\"";
	if ($target) $attributes .= " target=\"$target\"";
	
	return do_shortcode("<a class=\"button $class\" href=\"$link\"{$attributes}><span>$content</span></a>");
}
add_shortcode('button', 'init_buttons');

/*
*	Shortcode: 	[action]
*	Attributes:	link, button, title, content
*/
function init_action_c($atts, $content =  NULL, $case = NULL){
	
	extract(shortcode_atts(array(
		'link'				=> NULL,
		'color'				=> 'sky',
		'button_title'		=> NULL
	), $atts));
	
	if (!empty($button_title)) $button = do_shortcode('[button link="'.$link.'" color="'.$color.'" size="big"]'.$button_title.'[/button]');
	
	$out = 	'<div class="action-container">
				<div class="action-left">'.$content.'</div>';
	if (isset($button))
	$out .=	'	<div class="action-right">'.$button.'</div>	';
				
	$out .=	'<div class=\"clear\"></div></div>';
	

	return $out;
}
add_shortcode('action', 'init_action_c');


/*
*	Shortcode: 	 [dropcap]
*/
function init_dcap($atts, $content =  NULL, $case = NULL){
	$class = "dropcap";
	$content = trim($content);
	$length = strlen($content);
	if ($length > 1) {$c_content = substr($content,1,$length-1); $content = $content{0};}
	return "<h2 class=\"$class\">$content</h2>$c_content";}
add_shortcode('dropcap', 'init_dcap');

/*
*	Shortcode: 	 [highlight#]
*/
function init_highlight($atts, $content =  NULL, $case = NULL){
	switch ($case) {
	case 'highlight1':default:	$class = "highlight_1";	break;
	case 'highlight2':			$class = "highlight_2";	break;
	case 'highlight3':			$class = "highlight_3";	break;
	}
	
	return "<span class=\"$class\">$content</span>";}
add_shortcode('highlight1', 'init_highlight');
add_shortcode('highlight2', 'init_highlight');
add_shortcode('highlight3', 'init_highlight');

/*
*	Shortcode: 	 [list]
*	Attributes:	 type
*/
function init_list($atts, $content =  NULL, $case = NULL){
	extract(shortcode_atts(array(
		'type'				=> 'arrow',
	), $atts));
	
	switch ($type) {
	case 'arrow':default:			$class = "list-arrow";		break;
	case 'check':					$class = "list-check";		break;
	case 'cancel':					$class = "list-cancel";		break;
	case 'download':				$class = "list-download";	break;
	case 'comment':					$class = "list-comment";	break;
	case 'rss':						$class = "list-rss";		break;
	case 'doc':						$class = "list-doc";		break;
	case 'star':					$class = "list-star";		break;
	case 'info':					$class = "list-info";		break;
	case 'plus':					$class = "list-plus";		break;
	case 'negative':				$class = "list-negative";	break;
	case 'caution':					$class = "list-caution";	break;
	case 'bull':					$class = "list-bull";		break;
	case 'ordered':					$class = "list-decimal";	break;
	case 'roman':					$class = "list-roman";		break;
	case 'square':					$class = "list-square";		break;
	case 'circle':					$class = "list-circle";		break;
	}
	
	return do_shortcode("<ul class=\"list $class\">$content</ul>");
}
add_shortcode('list', 'init_list');


/*
*	Group:		Quotes
*	Shortcode: 	[blockquote] [pullquote_left] [pullquote_right]
*/
function init_pullquote($atts, $content =  NULL, $case = NULL){
	
	switch ($case) {
	case 'pullquote_left':			$class = "pullquote";		break;
	case 'pullquote_right':			$class = "pullquote-right";	break;
	case 'blockquote':				$class = "blockquote";		break;
	}
	
	return do_shortcode("<span class=\"$class\">$content</span>");
}
add_shortcode('pullquote_left', 'init_pullquote');
add_shortcode('pullquote_right', 'init_pullquote');
add_shortcode('blockquote', 'init_pullquote');

/*
*	Shortcode: 	 [pre]
*/
function init_code($atts, $content =  NULL, $case = NULL){
	//$content = htmlentities($content);
	return "<pre><span>$content</span></pre><div class=\"clear\"></div>";
}
add_shortcode('pre', 'init_code');

/*
*	Shortcode: 	 [no_shortcode]
*/
function init_no_shortcode($atts, $content =  NULL, $case = NULL){
	//$content = htmlentities($content);
	return "$content";
}
add_shortcode('no_shortcode', 'init_no_shortcode');



/*
*	Group:		Titles
*	Shortcode: 	[title#]
*	Attributes:	size
*/
function init_titles($atts, $content =  NULL, $case = NULL){
	extract(shortcode_atts(array(
		'size'				=> 'h3',
	), $atts));
	
	switch ($case) {
	case 'stitle':default:			
		$out = '
	<p class="ts">'.$content.'</p>
	';
	break;	
}
	
	return $out;
}
add_shortcode('stitle', 'init_titles');

/*
*	Group:		Dividers
*	Shortcode: 	[slice] [divider] [divider_top] [clear] [nomargin]
*/
function init_dividers($atts, $content =  NULL, $case = NULL){
	extract(shortcode_atts(array(
		'size'				=> 'h3',
	), $atts));
	
	switch ($case) {
	case 'slice':			
		$out = '
		<div class="sector"></div>
		';	
	break;
	case 'divider':			
		$out = '
		<div class="d1">
		<div class="d1-bg">
			<div class="d1-bg-left"></div>
			<div class="d1-bg-right"></div>
		</div>
		</div>
		';
	
	break;
	case 'divider_line':			
		$out = '
		<span class="d2"></span>
		';	
	break;
	case 'divider_top':	
		$out = '
	<div class="section">
		<div class="inside-section-divid-top"><a href="#">top</a></div>
	</div>
	<div class="clear"></div>
	';
	
	break;
	case 'clear':			
		$out = '<div class="clear"></div>';
	
	break;
	case 'nomargin':			
		$out = do_shortcode("<div class=\"full-width\">{$content}</div>");
	
	break;
	case 'up':			
		$out = '<div class="up"></div>';
	
	break;
	case 'down':			
	case 'space':			
		$out = '<div class="down"></div>';
	
	break;
	case 'half_space':			
		$out = '<div class="down_half"></div>';
	
	break;
	case 'downx2':			
		$out = '<div class="down downx2"></div>';
	
	break;
	}
	
	return $out;
}
add_shortcode('slice', 'init_dividers');
add_shortcode('divider', 'init_dividers');
add_shortcode('divider_line', 'init_dividers');
add_shortcode('divider_top', 'init_dividers');
add_shortcode('clear', 'init_dividers');
add_shortcode('space', 'init_dividers');
add_shortcode('half_space', 'init_dividers');
add_shortcode('nomargin', 'init_dividers');
add_shortcode('up', 'init_dividers');
add_shortcode('down', 'init_dividers');
add_shortcode('downx2', 'init_dividers');


/*
*	Group:		Boxes
*	Shortcodes: [info] [caution] [warning] [bulb] [note] [success] [error]
*	Attributes:	title
*/
function init_boxes($atts, $content =  NULL, $case = NULL){
	extract(shortcode_atts(array(
		'title' 		=> NULL
	), $atts));
	
	if (!empty($title)) $tit = "<div class=\"box-title\">$title</div>";
	
	switch ($case) {	
	case 'box': default:$class="box box-default";	break;	
	case 'info':		$class="box box-info";		break;	
	case 'caution':		$class="box box-caution";	break;	
	case 'warning':		$class="box box-warning";	break;	
	case 'bulb':		$class="box box-bulb";		break;	
	case 'note':		$class="box box-note";		break;	
	case 'success':		$class="box box-success";	break;	
	case 'error':		$class="box box-error";		break;	
	}
	
	$out = "<div class=\"$class\"><div class=\"box-inline\">$tit "._isso(!empty($content), "<p>$content</p>")."</div></div>";
	
	return do_shortcode($out);
}
add_shortcode('box', 'init_boxes');
add_shortcode('caution', 'init_boxes');
add_shortcode('info', 'init_boxes');
add_shortcode('warning', 'init_boxes');
add_shortcode('bulb', 'init_boxes');
add_shortcode('note', 'init_boxes');
add_shortcode('success', 'init_boxes');
add_shortcode('error', 'init_boxes');


/*
*	Shortcodes: [lightbox]
*	Attributes: href, desc, group
*/
function init_lightbox($atts, $content =  NULL, $case = NULL){
	extract(shortcode_atts(array(
		'href'		=> '#',
		'desc'		=> NULL,
		'group'		=> NULL
	), $atts));
	
	if (empty($group)) $rel = "prettyPhoto"; else $rel = "prettyPhoto[$group]";
	if (!empty($desc)) $description = "title=\"$desc\""; else $description = " title=\"\"";
	
	return do_shortcode("<a href=\"$href\" rel=\"$rel\" $description>$content</a>");
}
add_shortcode('lightbox', 'init_lightbox');

/*
*	Group:		Image Frames
*	Shortcodes: [frame_left] [frame_right]
*/
function init_imageframes($atts, $content =  NULL, $case = NULL){
	extract(shortcode_atts(array(
		'caption'		=> NULL
	), $atts));
	
	if (!empty($caption)) {
		$caption = '<span class="block-caption">'.$caption.'</span>';
		}

	switch($case){
	case 'frame_left':	
		$out = "<span class=\"image-frame image-left\">$content $caption</span>";
	break;
	case 'frame_right':	
		$out = "<span class=\"image-frame image-right\">$content $caption</span>";
	break;
	
	}
	
	return do_shortcode($out);
	
}
add_shortcode('frame_left', 'init_imageframes');
add_shortcode('frame_right', 'init_imageframes');

/*
*	Group:		Blocks
*	Shortcodes: [left] [right]
*/
function init_blocks($atts, $content =  NULL, $case = NULL){
	extract(shortcode_atts(array(
		'left'		=> NULL,
		'right'		=> NULL,
		'top'		=> NULL,
		'bottom'	=> NULL,
		'style'		=> NULL
	), $atts));
	
	if (!empty($left)) 		$style_ .= "margin-left:$left\px;";
	if (!empty($right)) 	$style_ .= "margin-right:$right\px;";
	if (!empty($top)) 		$style_ .= "margin-top:$top\px;";
	if (!empty($bottom))	$style_ .= "margin-bottom:$bottom\px;";
	if (!empty($style)) 	$style_ .= "$style";

	switch($case){
	case 'left':	
		$out = "<div class=\"block-left\" style=\"$style_\">$content</div>";
	break;
	case 'right':	
		$out = "<div class=\"block-right\" style=\"$style_\">$content</div>";
	break;
	
	}
	return do_shortcode($out);
	
}
add_shortcode('left', 'init_blocks');
add_shortcode('right', 'init_blocks');

/*
*	Group:		Tabs
*	Shortcodes: [tabs] [tabs_simple] [tab]
*/
function init_tabs($atts, $content =  NULL, $case = NULL){
	extract(shortcode_atts(array(
		'tabs'		=> NULL,
		'nomargin'	=> 1
	), $atts));
	
	switch ($case){
		case 'tabs': default:
			$class = 'framed_tabs';
		break;
		case 'tabs_simple':
			$class = 'simple_tabs';
		break;
		}
	
	if ($case == 'tabs' || $case == 'tabs_simple'){
		
		$out = "
		<div class=\"{$class} tabs\">
		<ul class=\"tab_titles{$class_2}\">";
		$i = 1;
		
		$tabs = explode("|",$tabs);
		
		foreach ($tabs as $tb):
			
			$out .= "<li class=\"tab_{$i}";
			if ($i == 1) $out .= " first current";
			$out .= "\"><a href=\"#tab_$i\">$tb</a></li>";
			
		$i++;
		endforeach;

		$out .= "
		</ul>
		<ul class=\"tab_contents{$class_2}\">";
			$content = do_shortcode($content);
			$out .= $content;
		$out .= "
		</ul>
		</div>";
		

	}else if ($case == 'tab'){
		$content = do_shortcode($content);
		$out .= "<li class=\"hidden\">$content</li>";
	}


	return $out;
	
}
add_shortcode('tab', 'init_tabs');
add_shortcode('tabs', 'init_tabs');
add_shortcode('tabs_simple', 'init_tabs');


/*
*	Group:		Custom Gallery
*	Shortcodes: [slideshow] [slide]
*	Attributes:	width, height, thumbnails
*/
function init_slideshow($atts, $content =  NULL, $case = NULL){
	extract(shortcode_atts(array(
		'width'			=> 360,
		'height'		=> 260,
		'thumbnails'	=> NULL
	), $atts));

	if (!is_numeric($width)) $width = 360;
	if (!is_numeric($height)) $height = 260;
	
	$width = $width.'px';
	$height = ($height+40).'px';
	
	switch($case){
	case 'slideshow':default:
		
		$out = '<div class="galleria '.$thumbnails.'" style="width:'.$width.'; height:'.$height.'; margin: auto;">';
			
			 $out .= do_shortcode($content);			  
			  
		$out .= '</div>';
		
	break;
	case 'slide':
			$out .= "<img title=\"$title\" alt=\"$desc\" src=\"$content\">";
	break;
	}
	
	return $out;
	
}
add_shortcode('slideshow', 'init_slideshow');
add_shortcode('slide', 'init_slideshow');


/*
*	Shortcodes: [toggle]
*	Attributes:	title, closed
*/
function init_toggle($atts, $content =  NULL, $case = NULL){
	extract(shortcode_atts(array(
		'title'		=> 'Toggle',
		'closed'	=> 0,
		'style'		=> 0,
		'group'		=> NULL,
	), $atts));

	if ($closed==0) $class = 'toggle-opened'; else $class = 'toggle-closed';
	if ($style==1)	$class .= ' toggle-box';
	if (!empty($group)) $rel = " data-group=\"toggle_$group\"";
	
	$out = do_shortcode("<div class=\"toggle $class\"$rel><div class=\"toggle-head\"><a class=\"toggle-link\" href=\"#toggle\">$title</a></div><div class=\"toggle-content\">$content</div></div>");
	
	return $out;
	
}
add_shortcode('toggle', 'init_toggle');

/*
*	Shortcodes: [tooltip]
*	Attributes:	text
*/
function init_tooltip($atts, $content =  NULL, $case = NULL){
	extract(shortcode_atts(array(
		'text'		=> '',
	), $atts));
	
	$text = esc_attr($text);
	
	$out = do_shortcode("<span class=\"tooltip\" title=\"$text\">$content</span>");
	
	return $out;
	
}
add_shortcode('tooltip', 'init_tooltip');

/*
*	Group: 		Twitter
*	Shortcode: 	[twitter] [twitter_search]
*	Attributes:	username, count, key, columns
*/
function init_twitter($atts, $content =  NULL, $case = NULL){
	extract(shortcode_atts(array(
		'username'		=> NULL,
		'key'			=> NULL,
		'count'			=> 3,
		'columns'		=> 3
	), $atts));
	
	if (!is_numeric($columns) || $columns >4 || $columns <1 ) $columns = 3;
	$id = 'twitter_'.cloudfw_randomizer(5);

	switch($case){
		case 'twitter': default:	
		
		if (empty($username)) 
			return __('Plase Enter Your Twitter Username To Show Twitter Post Here','cloudfw');
		
		$kind = 'username: "'.$username.'",';
		
		break;
		
		case 'twitter_search':	
		
		$kind = 'query: "'.$key.'",';
		
		break;
	
	}
	
	$out = '<p id="'.$id.'" class="twitter-loading">
	<script type="text/javascript">
    $(document).ready(function(){
        $("#'.$id.'").tweet({
            '.$kind.'
            join_text: false,
            avatar_size: 32,
			columns: '.$columns.',
            count: '.$count.',
			loading_text: " "
			});
    });
	</script>';
	
	
	return $out;
	
}
add_shortcode('twitter', 'init_twitter');
add_shortcode('twitter_search', 'init_twitter');


/*
*	Group: 		Flickr
*	Shortcode: 	[flickr] 
*	Attributes:	id, type, count, display
*/
function init_flickr($atts) {
	extract(shortcode_atts(array(
		'id' => '',
		'type' => 'user',
		'count' => 4,
		'display' => 'latest'//lastest or random
	), $atts));
	
	$uID = 'flickr-'.cloudfw_randomizer(4);
	$flickr_source = "http://www.flickr.com/badge_code_v2.gne?count={$count}&amp;display={$display}&amp;size=s&amp;layout=h&amp;source={$type}&amp;{$type}={$id}";

	return <<<HTML
	[raw]
	<div id="{$uID}" class="flickr_container">
		<script type="text/javascript" src="{$flickr_source}"></script>
	</div>
	<div class="cf"></div>
	[/raw]
HTML;
}
add_shortcode('flickr', 'init_flickr');


/*
*	Group:		Yes/No
*	Shortcodes: [yes] [no]
*/
function init_yesno($atts, $content =  NULL, $case = NULL){

	switch($case){
	case 'yes':	
		$out = "<div class=\"sign_yes\">&nbsp;</div>";
	break;
	case 'no':	
		$out = "<div class=\"sign_no\">&nbsp;</div>";
	break;
	
	}
	return $out;
}
add_shortcode('yes', 'init_yesno');
add_shortcode('no', 'init_yesno');


/*
*	Shortcode: 	[contact]
*/
function init_contact($atts, $content =  NULL, $case = NULL){

	include_once(TMP_INCLUDES . '/functions/mail_functions.php');
	return '[raw]'.cloudfw_contact_form($atts).'[/raw]';
}
add_shortcode('contact', 'init_contact');



/*
*	Group:		Social Buttons
*	Shortcodes: [facebook_like], [tweet_button]
*	Attributes:	url
*/
function init_social($atts, $content =  NULL, $case = NULL){
	extract(shortcode_atts(array(
		'url'		=> NULL
	), $atts));
	
	switch($case){
	case 'facebook_like':	
		$out = "[raw]".facebook_like_button($url)."[/raw]";
	break;
	case 'tweet_button':	
		$out = '[raw]<a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>[/raw]';
	break;
	
	}
	return $out;
}
add_shortcode('facebook_like', 'init_social');
add_shortcode('tweet_button', 'init_social');


/*
*	Shortcode: 	[template_url]
*/
function init_bloginfos($atts, $content =  NULL, $case = NULL){

	switch($case){
	case 'template_url':	
		$out = TMP_URL;
	break;
		
	}
	return $out;
}
add_shortcode('template_url', 'init_bloginfos');

/*
*	Shortcode: 	[frame]
*/
function init_frames($atts, $content =  NULL, $case = NULL){

	switch($case){
	case 'frame':	
		$out = "<span class=\"frame\">$content</span>";
	break;
		
	}
	return $out;
}
add_shortcode('frame', 'init_frames');


/*
*	Shortcode: 	[login]
*/
function init_user_functions($atts, $content =  NULL, $case = NULL){
		
	switch($case){
	case 'login':
		require_once(TEMPLATEPATH . '/includes/functions/user_functions.php' );
	
		ob_start();
			cloudfw_login_form();
		ob_end_flush;
		$out = "[raw]".ob_get_contents()."[/raw]";
		ob_end_clean();
		
	break;
	}
	
	return $out;
}

add_shortcode('login', 'init_user_functions');



/*
*	Testimonial: 	[testimonial]
*/
function init_testimonial($atts, $content =  NULL, $case = NULL){
	extract(shortcode_atts(array(
		'image'		=> NULL,
		'height'	=> NULL,
		'icon'		=> NULL,
		'name'		=> NULL,
		'caption'	=> NULL
	), $atts));
	
	return '[raw]
	<div class="testimonial-wrap">
	
	<div class="testimonial"'._isso( !empty($height), ' style="height:'.$height.'px;"' ).'>
		<div class="testimonial-bg">
			<div class="testimonial-bg-left"></div>
			<div class="testimonial-bg-right"></div>
		</div>	
		
		<div class="testimonial-content">
			'._isso(!empty($image),'
			<div class="testimonial-image">
				<div class="testimonial-image-position"><img src="'.$image.'" alt="" /></div>
			</div>').'		
			
			<div class="testimonial-content-init">
			
			'.do_shortcode($content).'
			'._isso(!empty($name),'
				<div class="testimonial-brand">
					—  '.$name._isso(!empty($icon), ' <img src="'.$icon.'" alt="" width="16" height="16" />').'
					'._isso(!empty($caption), '<span>'.$caption.'</span>').'
				</div>').'
			</div>


		
		</div>
				
		<div class="cf"></div>

	
	</div>	
	
	</div>
	[/raw]';
}
add_shortcode('testimonial', 'init_testimonial');


//thank to http://blue-anvil.com/archives/8-fun-useful-shortcode-functions-for-wordpress/
function init_charts( $atts ) {
	extract(shortcode_atts(array(
	    'data' => '',
	    'colors' => '',
		'size' => '400x200',
	    'bg' => 'bg,s,ffffff',
	    'title' => '',
	    'labels' => '',
	    'advanced' => '',
	    'type' => 'pie'
	), $atts));
 
	switch ($type) {
		case 'line' :
			$charttype = 'lc'; break;
		case 'xyline' :
			$charttype = 'lxy'; break;
		case 'sparkline' :
			$charttype = 'ls'; break;
		case 'meter' :
			$charttype = 'gom'; break;
		case 'scatter' :
			$charttype = 's'; break;
		case 'venn' :
			$charttype = 'v'; break;
		case 'pie' :
			$charttype = 'p3'; break;
		case 'pie2d' :
			$charttype = 'p'; break;
		default :
			$charttype = $type;
		break;
	}
 
	if ($title) $string .= '&chtt='.$title.'';
	if ($labels) $string .= '&chl='.$labels.'';
	if ($colors) $string .= '&chco='.$colors.'';
	$string .= '&chs='.$size.'';
	$string .= '&chd=t:'.$data.'';
	$string .= '&chf='.$bg.'';
 
	return '<img title="'.$title.'" src="http://chart.apis.google.com/chart?cht='.$charttype.''.$string.$advanced.'" alt="'.$title.'" />';
}
add_shortcode('chart', 'init_charts');



function init_gmap($atts, $content = null, $case) {
	extract(shortcode_atts(array(
		"width" => false,
		"height" => '400',
		"address" => '',
		"latitude" => 0,
		"longitude" => 0,
		"zoom" => 1,
		"html" => '',
		"popup" => 'false',
		"controls" => '[]',
		"scrollwheel" => 'true',
		"maptype" => 'G_NORMAL_MAP',
		"marker" => 'true',
	), $atts));
	
	$gmap_api_key = get_cOption('apis', 'gmap_api_key');
	
	if (! $gmap_api_key )
		return cloudfw_fatalError( sprintf(__('Please insert your Google Map API key to use [gmap] shortcode. %s','cloudfw'), '<a target="_blank" href="'.cloudfw_admin_url('general', 3).'">'.__('click to manage APIs','cloudfw').'</a>' ) );

	$width = $width && is_numeric($width) ? 'width:'.$width.'px;' : '';
	$height = $height && is_numeric($height) ? 'height:'.$height.'px;' : '';
	$id = 'gmap-'.cloudfw_randomizer(4);
	
	
	$out = "
	[raw]<div id=\"{$id}\" class=\"gmap{$align}\" style=\"{$width}{$height}\"></div>
	<script type=\"text/javascript\">
		
		var gmap;
		gmap = '';
		
		jQuery.getScript(\"".TMP_URL."/lib/js/gmap.js\", function(){
			
			var tabs = jQuery(\"#{$id}\").parents('.tabs');	
			jQuery(\"#{$id}\").unbind('gMapReady');
			jQuery(\"#{$id}\").bind('gMapReady',function(){
			
				gmap = jQuery(this).gMap({
					zoom: {$zoom},
					latitude: {$latitude},
					longitude: {$longitude},
					"._isso(
						!empty($marker),
						"
						markers:[{
							address: \"{$address}\",
							latitude: {$latitude},
							longitude: {$longitude},
							html: \"{$html}\",
							popup: {$popup}
						}],
						
						",
						"
						address: \"{$address}\",
						latitude: {$latitude},
						longitude: {$longitude},
						"
					
					)."
					controls: {$controls},
					maptype: {$maptype},
					scrollwheel:{$scrollwheel}
				});
				jQuery(this).data(\"gMapReady\",true);
				
			}).data(\"gMapReady\",false);
			
			
			if(tabs.length > 0){
				tabs.find('.tab_titles a').click(function() {
					tabs.find('.currentTab .gmap').each(function(){
						if(jQuery(this).data(\"gMapReady\")==false){
							jQuery(this).trigger('gMapReady');
						}
					});
				});
				
				tabs.find('.tab_contents > .currentTab').find('.gmap').each(function(){
					jQuery(this).trigger('gMapReady');
				});
				
			}else{
				jQuery(\"#{$id}\").trigger('gMapReady');
			}


		});
	
	</script>
	[/raw]";
	
	return $out;
}

add_shortcode('gmap','init_gmap');

?>