<?php
function theme_shortcode_contactform($atts,$content = null) {
	extract(shortcode_atts(array(
		'email' => get_bloginfo('admin_email'),
		'btncolor' => '#ffffff',
		'textcolor' => '#717171',
	), $atts));
	wp_print_scripts('jquery-tools-validator');

	$content = trim($content);
	if(!empty($content)){
		$success = do_shortcode($content);
	}
	if(!empty($btncolor)){
		$btncolor = 'background-color:'.$btncolor;
	}
	if(!empty($textcolor)){
		$textcolor = 'color:'.$textcolor;
	}
	if(empty($success)){
		$success = __('Your message was successfully sent. <strong>Thank You!</strong>',THEME_FRONT_DOMAIN);
	}
	$name_str = __('Name *',THEME_FRONT_DOMAIN);
	$email_str = __('Email *',THEME_FRONT_DOMAIN);
	$submit_str = __('Submit',THEME_FRONT_DOMAIN);
	$email = str_replace('@','*',$email);
	$include_path = THEME_INCLUDES;
	$id = rand(100,3000);
	//$action = $include_path.'/sendmail.php';
	$action = add_query_arg(array());
	return <<<HTML
<div class="contact_form_wrap">
	<div class="success" style="display:none;"><div class="message_box_content">{$success}</div></div> 
	<form class="contact_form" action="{$action}" method="post" novalidate="novalidate" style="{$textcolor}">
		<p>
		<label for="contact_{$id}_name">{$name_str}</label>
		<input type="text" required="required" id="contact_{$id}_name" name="contact_{$id}_name" class="text_input" value="" tabindex="5" />
		</p>
		<p>
		<label for="contact_{$id}_email">{$email_str}</label>
		<input type="email" required="required" id="contact_{$id}_email" name="contact_{$id}_email" class="text_input" value="" tabindex="6"  />
		</p>
		<p><textarea required="required" name="contact_{$id}_content" class="textarea" cols="30" rows="5" tabindex="7"></textarea></p>
		<p><button type="submit" class="button" style="font-family:'Lucida Sans Unicode','Lucida Grande',Garuda,sans-serif;{$btncolor}"><span style="{$textcolor}">{$submit_str}</span></button></p>
		<input type="hidden" value="1" name="theme_contact_form_submit"/>	
		<input type="hidden" value="{$id}" name="contact_widget_id"/>
		<input type="hidden" value="{$email}" name="contact_{$id}_to"/>
	</form>
</div>
HTML;
}
add_shortcode('contactform', 'theme_shortcode_contactform');

function theme_shortcode_search($atts,$content = null) {
	extract(shortcode_atts(array(
		'bgcolor' => '',
		'textcolor' => '',
	), $atts));
	
	$bgcolor = $bgcolor?' style="background-color:'.$bgcolor.'"':'';
	$textcolor = $textcolor?' style="color:'.$textcolor.'"':'';
	
	$search_str = __('Search..', THEME_FRONT_DOMAIN);
	$url = get_bloginfo('url');
	return <<<HTML
<form method="get" id="searchform" action="{$url}">
	<input type="text" class="text_input" value="{$search_str}" name="s" id="s" onfocus="if(this.value == '{$search_str}') {this.value = '';}" onblur="if (this.value == '') {this.value = '{$search_str}';}" />
	<button type="submit" class="button gray"{$bgcolor}><span{$textcolor}>{$search_str}</span></button></form>
HTML;
}
add_shortcode('search', 'theme_shortcode_search');

function theme_shortcode_twitter($atts) {
	extract(shortcode_atts(array(
		'username' => '',
		'count' => 3,
		'query' => 'null',
		'avatarsize' => 'null',
	), $atts));
	
	$user_array = explode(',',$username);
	foreach($user_array as $key => $user){
		$user_array[$key] = '"'.$user.'"';
	}	
	
	wp_print_scripts('jquery-tweet');
	$id = rand(1,1000);
	$just_now_text = __('just now',THEME_FRONT_DOMAIN);
	$seconds_ago_text = __('about %d seconds ago',THEME_FRONT_DOMAIN);
	$a_minutes_ago_text = __('about a minute ago',THEME_FRONT_DOMAIN);
	$minutes_ago_text = __('about %d minutes ago',THEME_FRONT_DOMAIN);
	$a_hours_ago_text = __('about an hour ago',THEME_FRONT_DOMAIN);
	$hours_ago_text = __('about %d hours ago',THEME_FRONT_DOMAIN);
	$a_day_ago_text = __('about a day ago',THEME_FRONT_DOMAIN);
	$days_ago_text = __('about %d days ago',THEME_FRONT_DOMAIN);
	$view_text = __('view tweet on twitter',THEME_FRONT_DOMAIN);
	
	if ( !empty( $user_array )|| $query!="null" ) {
		$username = implode(',',$user_array);
		if($query != "null"){
			$query = '"'.html_entity_decode($query).'"';
		}
		$with_avatar = ($avatarsize != 'null')?' with_avatar':'';
		return <<<HTML
<div class="twitter_wrap{$with_avatar}">
<script type="text/javascript">
jQuery(document).ready(function($) {
	jQuery("#twitter_wrap_{$id}").tweet({
		username: [{$username}],
		count: {$count},
		query: {$query},
		avatar_size: {$avatarsize},
		just_now_text: "{$just_now_text}",
		seconds_ago_text: "{$seconds_ago_text}",
		a_minutes_ago_text: "{$a_minutes_ago_text}",
		minutes_ago_text: "{$minutes_ago_text}",
		a_hours_ago_text: "{$a_hours_ago_text}",
		hours_ago_text: "{$hours_ago_text}",
		a_day_ago_text: "{$a_day_ago_text}",
		days_ago_text: "{$days_ago_text}",
		view_text: "{$view_text}"
	});
});
</script>
	<div id="twitter_wrap_{$id}"></div>
	<div class="clear"></div>
</div>
HTML;
	}
}
add_shortcode('twitter', 'theme_shortcode_twitter');

function theme_shortcode_flickr($atts) {
	extract(shortcode_atts(array(
		'id' => '',
		'type' => 'user',
		'count' => 4,
		'display' => 'latest'//lastest or random
	), $atts));
	
	return <<<HTML
<div class="flickr_wrap">
	<script type="text/javascript" src="http://www.flickr.com/badge_code_v2.gne?count={$count}&amp;display={$display}&amp;size=s&amp;layout=x&amp;source={$type}&amp;{$type}={$id}"></script>
</div>
<div class="clear"></div>
HTML;
}
add_shortcode('flickr', 'theme_shortcode_flickr');


function theme_shortcode_links($atts) {
	extract(shortcode_atts(array(
		'desc' => 'false',
		'name' => 'false',
		'rating' => 'false',
		'images' => 'false',
		'cat' => '',
		'cat_title' => 'true',
	), $atts));
	if ($desc == 'false') {
		$desc = 0;
	}else{
		$desc = 1;
	}
	if ($name == 'false') {
		$name = 0;
	}else{
		$rating = 1;
	}
	if ($rating == 'false') {
		$rating = 0;
	}else{
		$images = 1;
	}
	if ($images == 'false') {
		$images = 0;
	}else{
		$images = 1;
	}
	if($cat_title == 'true'){
		$categorize = 1;
	}else{
		$categorize = 0;
	}
	
	$output = wp_list_bookmarks(array(
		'show_images' => $images,
		'show_description' => $desc,
		'show_name' => $name, 
		'show_rating' => $rating,
		'category' => $cat,
		'class' => 'linkcat',
		'category_before' =>null,
		'category_after' => null,
		'title_before' => '<h3>',
		'title_after' => '</h3>',
		'categorize' => $categorize,
		'title_li' => 0,
		'echo' => 0
	));
	if($cat_title == 'true'){
		$output = '<div class="links_wrap">'.$output.'</div>';
	}else{
		$output = '<div class="links_wrap"><ul class="xoxo blogroll">'.$output.'</ul></div>';;
	}
	return $output;
}
add_shortcode('links', 'theme_shortcode_links');

function theme_shortcode_contact_info($atts) {
	extract(shortcode_atts(array(
		'color' => '',
		'phone' => '',
		'cellphone' => '',
		'email' => '',
		'link' => '',
		'address' => '',
		'city' => '',
		'state' => '',
		'zip' => '',
		'name' => '',
		'fax'=>'',
	), $atts));
	
	if(!empty($city) && !empty($state)){
		$city = $city.',&nbsp;'.$state;
	}elseif(!empty($state)){
		$city = $state;
	}
	if(!empty($color)){
		$color = ' '.$color;
	}
	
	$output = '<div class="contact_info_wrap">';
	if(!empty($phone)){
		$output .= '<p><span class="icon_text icon_phone'.$color.'">'.$phone.'</span></p>';
	}
	if(!empty($fax)){
		$output .= '<p><span class="icon_text icon_fax'.$color.'">'.$fax.'</span></p>';
	}
	
	if(!empty($cellphone)){
		$output .= '<p><span class="icon_text icon_cellphone'.$color.'">'.$cellphone.'</span></p>';
	}
	if(!empty($email)){
		$email = str_replace('@','*',$email);
		$output .= '<p><a href="mailto:'.$email.'" class="icon_text icon_email'.$color.'">'.$email.'</a></p>';
	}
	if(!empty($link)){
		$output .= '<p><a href="'.$link.'" target="_blank" class="icon_text icon_link'.$color.'">'.$link.'</a></p>';
	}
	if(!empty($address)){
		$output .= '<p><span class="icon_text icon_home'.$color.'">'.$address.'</span></p>';
	}
	if(!empty($city)||!empty($zip)){
		$output .= '<p class="contact_address">';
		if(!empty($city)){
			$output .= '<span>'.$city.'</span>';
		}
		if(!empty($zip)){
			$output .= '<span class="contact_zip">'.$zip.'</span>';
		}
	}
	if(!empty($name)){
		$output .= '<p><span class="icon_text icon_id'.$color.'">'.$name.'</span></p>';
	}
	$output .= '</div>';
	return $output;
}
add_shortcode('contact_info', 'theme_shortcode_contact_info');
function theme_archives($atts){
	extract(shortcode_atts(array(
		'dropdown' => 'false',
		'count' => 'false',
	), $atts));
	if($count === 'true'){
		$count = 1;
	}else{
		$count = 0;
	}
	if($dropdown === 'true'){
		return '<select name="archive-dropdown" onchange=\'document.location.href=this.options[this.selectedIndex].value;\'> <option value="">'.esc_attr(__('Select Month')).'</option> '.wp_get_archives(apply_filters('widget_archives_dropdown_args', array('type' => 'monthly', 'format' => 'option', 'show_post_count' => $count,'echo'=> 0))).' </select>';
	}else{
		return '<ul>'.wp_get_archives(apply_filters('widget_archives_args', array('type' => 'monthly', 'show_post_count' => $count))).'</ul>';
	}	
}
add_shortcode('archives', 'theme_archives');

function theme_categories($atts){
	extract(shortcode_atts(array(
		'dropdown' => 'false',
		'count' => 'false',
		'hierarchical' => 'false',
	), $atts));
	if($count === 'true'){
		$count = 1;
	}else{
		$count = 0;
	}
	if($hierarchical === 'true'){
		$hierarchical = 1;
	}else{
		$hierarchical = 0;
	}
	$cat_args = array('orderby' => 'name', 'show_count' => $count, 'hierarchical' => $hierarchical, 'echo'=>0);

	if($dropdown === 'true'){
		$cat_args['show_option_none'] = __('Select Category');
		$output = wp_dropdown_categories(apply_filters('widget_categories_dropdown_args', $cat_args));
		$home_url = home_url();
		$output .= <<<HTML
<script type='text/javascript'>
/* <![CDATA[ */
	var dropdown = document.getElementById("cat");
	function onCatChange() {
		if ( dropdown.options[dropdown.selectedIndex].value > 0 ) {
			location.href = "{$home_url}/?cat="+dropdown.options[dropdown.selectedIndex].value;
		}
	}
	dropdown.onchange = onCatChange;
/* ]]> */
</script>
HTML;
		return $output;
	}else{
		$cat_args['title_li'] = '';
		return '<ul>'.wp_list_categories(apply_filters('widget_categories_args', $cat_args)).'</ul>';
	}	
}
add_shortcode('categories', 'theme_categories');


function theme_shortcode_popular_posts($atts) {
	extract(shortcode_atts(array(
		'count' => '4',
		'thumbnail' => 'true',
		'extra' => 'desc', //desc, time, both
		'cat' => '',
		'author' => '',
		'posts' => '',
		'title_length' => '',
		'desc_length' => '80',
		'lightbox'=>'true',
		'offset' => 0,
	), $atts));
	
	global $wp_filter;
	$the_content_filter_backup = $wp_filter['the_content'];
	
	$query = array('showposts' => $count, 'nopaging' => 0, 'orderby'=> 'comment_count', 'post_status' => 'publish', 'ignore_sticky_posts' => 1);
	if($cat){
		$query['cat'] = $cat;
	}
	if($posts){
		$query['post__in'] = explode(',',$posts);
	}
	if($author){
		$query['author'] = $author;
	}
	if($extra == 'both'){
		$extra = array('time','desc');
	}else{
		$extra = array($extra);
	}
	if((int)$offset != 0){
		$query['offset'] = (int)$offset;
	}
	$exclude_cats = theme_get_option('blog','exclude_categorys');
	if(!empty($exclude_cats)){
		$query['category__not_in'] = $exclude_cats;
	}
	$r = new WP_Query($query);

	if ($r->have_posts()){
		$output = '<div class="popular_posts_wrap">';
		$output .= '<ul class="posts_list">';
		while ($r->have_posts()){
			$r->the_post();
			$output .= '<li>';
			if($thumbnail!='false'){
				if($lightbox =='true'){
					if (has_post_thumbnail() ){
						$image = wp_get_attachment_image_src(get_post_thumbnail_id(),'full',true);
						$output .= '<a class="thumbnail" rel="prettyPhoto" href="'.$image[0].'" title="'.get_the_title().'">';
					}elseif(theme_get_option('blog','display_default_thumbnail')){
						$default_thumbnail_custom = theme_get_option('blog','default_thumbnail_custom');
						$image = theme_parse_image($default_thumbnail_custom,'widget_posts_thumbnail.png',false);
						$resize = theme_resize($image['media'],65,65,$image['method']);
						$output .= '<a class="thumbnail" rel="prettyPhoto" href="'.$resize['url'].'" title="'.get_the_title().'">';
					}
				}else{
					$output .= '<a class="thumbnail" href="'.get_permalink().'" title="'.get_the_title().'">';
				}
				if (has_post_thumbnail() ){
					$output .= get_the_post_thumbnail(get_the_ID(),array(65,65),array('title'=>get_the_title(),'alt'=>get_the_title()));
				}elseif(theme_get_option('blog','display_default_thumbnail')){
					$default_thumbnail_custom = theme_get_option('blog','default_thumbnail_custom');
					$image = theme_parse_image($default_thumbnail_custom,'widget_posts_thumbnail.png',false);
					$resize = theme_resize($image['media'],65,65,$image['method']);
					$output .= '<img src="'.$resize['url'].'" width="65" height="65" title="'.get_the_title().'" alt="'. get_the_title().'"/>';
				}
				$output .= '</a>';
			}
			$output .= '<div class="post_extra_info">';
			$title = get_the_title();
			if((int)$title_length && mb_strlen($title)>$title_length){
				$title =  mb_substr($title,0,$title_length).'...';
			}
			$output .= '<a class="post_title" href="'.get_permalink().'" title="'.get_the_title().'" rel="bookmark">'.$title.'</a>';
			if(in_array('time', $extra)){
				$output .= '<time datetime="'.get_the_time('Y-m-d').'">'.get_the_date().'</time>';
			}
			if(in_array('desc', $extra)){
				global $post;
				$excerpt = $post->post_excerpt;
				$excerpt = apply_filters('get_the_excerpt', $excerpt);
				$output .= '<p>'.wp_html_excerpt($excerpt,$desc_length).'...</p>';
			}
			$output .= '</div>';
			$output .= '<div class="clear"></div>';
			$output .= '</li>';
		}
		$output .= '</ul>';
		$output .= '</div>';
	} 
	wp_reset_query();
	
	$wp_filter['the_content'] = $the_content_filter_backup;
	return $output;
}
add_shortcode('popular_posts', 'theme_shortcode_popular_posts');

function theme_shortcode_recent_posts($atts) {
	extract(shortcode_atts(array(
		'count' => '4',
		'thumbnail' => 'true',
		'extra' => 'desc',
		'cat' => '',
		'posts' => '',
		'author' => '',
		'title_length' => '',
		'desc_length' => '80',
		'offset' => 0,
		'lightbox'=>'true',
	), $atts));
	
	global $wp_filter;
	$the_content_filter_backup = $wp_filter['the_content'];
	
	$query = array('showposts' => $count, 'nopaging' => 0, 'post_status' => 'publish', 'ignore_sticky_posts' => 1);
	if($cat){
		$query['cat'] = $cat;
	}
	if($posts){
		$query['post__in'] = explode(',',$posts);
	}
	if($author){
		$query['author'] = $author;
	}
	if($extra == 'both'){
		$extra = array('time','desc');
	}else{
		$extra = array($extra);
	}
	if((int)$offset != 0){
		$query['offset'] = (int)$offset;
	}
	$exclude_cats = theme_get_option('blog','exclude_categorys');
	if(!empty($exclude_cats)){
		$query['category__not_in'] = $exclude_cats;
	}
	$r = new WP_Query($query);
	
	if ($r->have_posts()){
		$output = '<div class="recent_posts_wrap">';
		$output .= '<ul class="posts_list">';
		while ($r->have_posts()){
			$r->the_post();
			$output .= '<li>';
			if($thumbnail!='false'){
				if($lightbox =='true'){
					if (has_post_thumbnail() ){
						$image = wp_get_attachment_image_src(get_post_thumbnail_id(),'full',true);
						$output .= '<a class="thumbnail" rel="prettyPhoto" href="'.$image[0].'" title="'.get_the_title().'">';
					}elseif(theme_get_option('blog','display_default_thumbnail')){
						$default_thumbnail_custom = theme_get_option('blog','default_thumbnail_custom');
						$image = theme_parse_image($default_thumbnail_custom,'widget_posts_thumbnail.png',false);
						$resize = theme_resize($image['media'],65,65,$image['method']);
						$output .= '<a class="thumbnail" rel="prettyPhoto" href="'.$resize['url'].'" title="'.get_the_title().'">';
					}
				}else{
					$output .= '<a class="thumbnail" href="'.get_permalink().'" title="'.get_the_title().'">';
				}
				if (has_post_thumbnail() ){
					$output .= get_the_post_thumbnail(get_the_ID(),array(65,65),array('title'=>get_the_title(),'alt'=>get_the_title()));
				}elseif(theme_get_option('blog','display_default_thumbnail')){
					$default_thumbnail_custom = theme_get_option('blog','default_thumbnail_custom');
					$image = theme_parse_image($default_thumbnail_custom,'widget_posts_thumbnail.png',false);
					$resize = theme_resize($image['media'],65,65,$image['method']);
					$output .= '<img src="'.$resize['url'].'" width="65" height="65" title="'.get_the_title().'" alt="'. get_the_title().'"/>';
				}
				$output .= '</a>';
			}
			$output .= '<div class="post_extra_info">';
			$title = get_the_title();
			if((int)$title_length && mb_strlen($title)>$title_length){
				$title =  mb_substr($title,0,$title_length).'...';
			}
			$output .= '<a class="post_title" href="'.get_permalink().'" title="'.get_the_title().'" rel="bookmark">'.$title.'</a>';if(in_array('time', $extra)){
				$output .= '<time datetime="'.get_the_time('Y-m-d').'">'.get_the_date().'</time>';
			}
			if(in_array('desc', $extra)){
				global $post;
				$excerpt = $post->post_excerpt;
				$excerpt = apply_filters('get_the_excerpt', $excerpt);
				$output .= '<p>'.wp_html_excerpt($excerpt,$desc_length).'...</p>';
			}
			$output .= '</div>';
			$output .= '<div class="clear"></div>';
			$output .= '</li>';
		}
		$output .= '</ul>';
		$output .= '</div>';
	} 
	wp_reset_query();
	
	$wp_filter['the_content'] = $the_content_filter_backup;
	return $output;
}
add_shortcode('recent_posts', 'theme_shortcode_recent_posts');


function theme_shortcode_portfolio_list($atts) {
	extract(shortcode_atts(array(
		'count' => '4',
		'thumbnail' => 'true',
		'extra' => 'desc',
		'cat' => '',
		'type'=>'',
		'author' => '',
		'title_length' => '',
		'desc_length' => '80',
		'offset' => 0,
		'lightbox'=>'true',
	), $atts));
	
	global $wp_filter;
	$the_content_filter_backup = $wp_filter['the_content'];
	
	$query = array(
		'showposts' => $count, 
		'nopaging' => 0, 
		'post_status' => 'publish', 
		'ignore_sticky_posts' => 1,
		'post_type' => 'portfolio',
		'suppress_filters'=>0,
	);
	if($cat != ''){
		global $wp_version;
		if(version_compare($wp_version, "3.1", '>=')){
			$query['tax_query'] = array(
				array(
					'taxonomy' => 'portfolio_category',
					'field' => 'slug',
					'terms' => explode(',', $cat)
				)
			);
		}else{
			$query['taxonomy'] = 'portfolio_category';
			$query['term'] = $cat;
		}
	}
	if($type != ''){
		$query['meta_key'] = '_type';
		$query['meta_value'] = $type;
		$query['meta_compare'] = 'IN';
	}
	if($author != '' ){
		$query['author'] = $author;
	}
	if($extra == 'both'){
		$extra = array('time','desc');
	}else{
		$extra = array($extra);
	}
	if((int)$offset != 0){
		$query['offset'] = (int)$offset;
	}
	$r = new WP_Query($query);
	
	if ($r->have_posts()){
		$output = '<div class="portfolio_list_wrap">';
		$output .= '<ul class="posts_list">';
		while ($r->have_posts()){
			$r->the_post();
			$output .= '<li>';
			if($thumbnail!='false'){

				if($lightbox){
					$image_title = get_the_title();
					if (has_post_thumbnail()) {
						$image = wp_get_attachment_image_src(get_post_thumbnail_id(get_the_id()), 'full', true);
						$type = get_post_meta(get_the_id(), '_type', true);
						if($type == 'image'){
							$href =  get_post_meta(get_the_id(), '_image', true);
							if(!empty($href)){
								$href = theme_parse_image($href,null,true);
								$href = $href['media'];
							}else
								$href = $image[0];					
							$rel = 'prettyPhoto';
						}elseif($type == 'video'){
							$href =  get_post_meta(get_the_id(), '_video', true);
							$video_width =  get_post_meta(get_the_id(), '_video_width', true);
							$video_height =  get_post_meta(get_the_id(), '_video_height', true);
							$video_size = '';
							if(!empty($video_width) && is_numeric($video_width)){
								$video_size .= 'width='.$video_width;
							}else{
								$video_size .= 'width='.theme_get_option('portfolio','video_width');
							}

							if(!empty($video_height) && is_numeric($video_height)){
								$video_size = '&amp;height='.$video_height;
							}else{
								$video_size .= '&amp;height='.theme_get_option('portfolio','video_height');
							}
							if(empty($href)){
								$href = $image[0];
							}
							$href=$href.'?'.$video_size;
							$rel = 'prettyPhoto';
						}elseif($type == 'doc'){
							global $theme_inline_id;
							$theme_inline_id = md5(uniqid(rand()));
							$href="#inline-".$theme_inline_id;
							$content =  get_post_meta(get_the_id(), '_lightbox_content', true);
							$lightbox_width = get_post_meta(get_the_id(), '_lightbox_doc_width', true);
							$lightbox_height = get_post_meta(get_the_id(), '_lightbox_doc_height', true);
							if(empty($lightbox_width) || !is_numeric($lightbox_width)){
								$lightbox_width =theme_get_option('portfolio','lightbox_width');
							}

							if(empty($lightbox_height) || !is_numeric($lightbox_height)){
								$lightbox_height =theme_get_option('portfolio','lightbox_height');
							}
							$content='<div id="inline-'.$theme_inline_id.'" class="hide" style="width:'.$lightbox_width.'px;height:'.$lightbox_height.'px">'.do_shortcode($content).'</div>';
							$rel = 'prettyPhoto';
						}elseif($type == 'iframe'){
							$href =  get_post_meta(get_the_id(), '_lightbox_href', true);
							$lightbox_width = get_post_meta(get_the_id(), '_lightbox_iframe_width', true);
							$lightbox_height = get_post_meta(get_the_id(), '_lightbox_iframe_height', true);
							$lightbox_size = '';
							if(!empty($lightbox_width) && is_numeric($lightbox_width)){
								$lightbox_size .= 'width='.$lightbox_width;
							}else{
								$lightbox_size .= 'width='.theme_get_option('portfolio','lightbox_width');
							}

							if(!empty($lightbox_height) && is_numeric($lightbox_height)){
								$lightbox_size = '&amp;height='.$lightbox_height;
							}else{
								$lightbox_size .= '&amp;height='.theme_get_option('portfolio','lightbox_height');
							}
							$href=$href.'?iframe=true&'.$lightbox_size;
							$rel = 'prettyPhoto';
						}elseif($type == 'link'){
							$link = get_post_meta(get_the_ID(), '_link', true);
							$href = theme_get_superlink($link);
							$link_target = get_post_meta(get_the_ID(), '_link_target', true);
							$link_target = $link_target?$link_target:'_self';
							$lightbox = '';
							$rel = '';
						}elseif($type == 'gallery'){
							$image_ids_str = get_post_meta(get_the_id(), '_image_ids', true);
							$image_ids = array();
							if(!empty($image_ids_str)){
								$image_ids = explode(',',str_replace('image-','',$image_ids_str));
								$image_src = wp_get_attachment_image_src(array_pop($image_ids),'full');
								$href = $image_src[0];
							}else{
								$href =  get_post_meta(get_the_id(), '_image', true);
								if(empty($href)){
									$href = $image[0];
								}
							}
							$rel = 'prettyPhoto';
							$image_title = get_the_title($image_ids[0]);
						}else{
							$href = get_permalink();
							$rel = 'prettyPhoto';
						}
					}else{
						$type = 'image';
						$image_source = theme_get_option('portfolio','default_portfolio_image');
						$image_source = theme_parse_image($image_source,'post-image-placer.png',true);
						$source_type = $image_source['method'];
						$image_source = $image_source['media'];
						$href = theme_parse_image($image_source,'post-image-placer.png',false);
						$href = $href['media'];
						$rel = 'prettyPhoto';
					}


					if($type == 'gallery' && !empty($image_ids)){
						$output .= '<div style="display:none">';
						foreach($image_ids as $image_id){
							$image_src = wp_get_attachment_image_src($image_id,'full');
							$image_title = get_the_title($image_id);
							$output .= '<a title="'.$image_title.'" href="'.$image_src[0].'" rel="prettyPhoto'.'['.strtolower(get_the_title()).']'.'">gallery-'.get_the_ID().'</a>';
						}
						$output .= '</div>';
					}
					$output .= '<a class="thumbnail" title="'.$image_title.'" href="'.$href.'" '.(isset($link_target)?' target="'.$link_target.'" ':'').' rel="'.$rel.(($type == 'gallery')?'['.strtolower(get_the_title()).']':'').'">';
					if($type =='doc'){
						$output .= $content;
					}

				}else{
					$output .= '<a class="thumbnail" href="'.get_permalink().'" title="'.get_the_title().'">';
				}
				if (has_post_thumbnail() ){
					$output .= get_the_post_thumbnail(get_the_ID(),array(65,65),array('title'=>get_the_title(),'alt'=>get_the_title()));
				}elseif(theme_get_option('portfolio','display_default_thumbnail')){
					$default_thumbnail_custom = theme_get_option('portfolio','default_thumbnail_custom');
					$image = theme_parse_image($default_thumbnail_custom,'widget_posts_thumbnail.png',false);
					$resize = theme_resize($image['media'],65,65,$image['method']);
					$output .= '<img src="'.$resize['url'].'" width="65" height="65" title="'.get_the_title().'" alt="'. get_the_title().'"/>';
				}
				$output .= '</a>';
			}
			$output .= '<div class="post_extra_info">';
			$title = get_the_title();
			if((int)$title_length && mb_strlen($title)>$title_length){
				$title =  mb_substr($title,0,$title_length).'...';
			}
			$output .= '<a class="post_title" href="'.get_permalink().'" title="'.get_the_title().'" rel="bookmark">'.$title.'</a>';
			if(in_array('time', $extra)){
				$output .= '<time datetime="'.get_the_time('Y-m-d').'">'.get_the_date().'</time>';
			}
			if(in_array('desc', $extra)){
				global $post;
				$excerpt = $post->post_excerpt;
				$excerpt = apply_filters('get_the_excerpt', $excerpt);
				$excerpt = wp_html_excerpt($excerpt,$desc_length);
				$excerpt = empty($excerpt) ? '' : $excerpt.'...';
				$output .= '<p>'.$excerpt.'</p>';
			}
			$output .= '</div>';
			$output .= '<div class="clear"></div>';
			$output .= '</li>';
		}
		$output .= '</ul>';
		$output .= '</div>';
	} 
	wp_reset_query();
	
	$wp_filter['the_content'] = $the_content_filter_backup;
	return $output;
}
add_shortcode('portfolio_list', 'theme_shortcode_portfolio_list');
