<?php
/**
 * Custom functions and definitions
 */


//	Add specific CSS class by filter
add_filter( 'body_class', 'restorator_body_class' );
function restorator_body_class( $classes ) {
	
	global $post, $restorator_options;
	
	$restorator_postId = ( isset( $post->ID ) ? get_the_ID() : NULL );
	
	//	If Site Boxed
	if ( isset( $restorator_postId ) && get_post_meta( $restorator_postId, 'restorator_page_layout', true ) ) {
		$restorator_options_theme_layout = isset( $restorator_options['theme_layout'] ) ? $restorator_options['theme_layout'] : 'full-width';
		$restorator_theme_layout = ( get_post_meta( $restorator_postId, 'restorator_page_layout', true ) ? get_post_meta( $restorator_postId, 'restorator_page_layout', true ) : $restorator_options_theme_layout );
	} else {
		$restorator_theme_layout = isset( $restorator_options['theme_layout'] ) ? $restorator_options['theme_layout'] : 'full-width';
	}
	if ($restorator_theme_layout == 'boxed') {
		$classes[] = 'boxed';
	} else {
		$classes[] = 'full-width';
	}
	
	//	Header Layout
	$restorator_header_style = 'header-top';
	$classes[] = $restorator_header_style;
	
	//	Header has BG
	$restorator_header_bg_style = isset( $restorator_options['header_bg_style'] ) ? $restorator_options['header_bg_style'] : 'bgcolor';
	$restorator_header_page_bg_style = get_post_meta( $restorator_postId, 'restorator_header_page_bg_style', true );
	$restorator_header_bg_style = !empty( $restorator_header_page_bg_style ) ? $restorator_header_page_bg_style : $restorator_header_bg_style;
	$classes[] = 'header_' . $restorator_header_bg_style;
	
	//	Header has BG with Opacity
	$restorator_header_bgcolor_opacity = isset( $restorator_options['header_bgcolor_opacity'] ) ? $restorator_options['header_bgcolor_opacity'] : '90';
	if ( isset( $restorator_header_bg_style ) && $restorator_header_bgcolor_opacity != '99' ) {
		$classes[] = 'header_opacity';
	}
	
	//	Page Title show/hide
	$restorator_options_pagetitle = isset( $restorator_options['pagetitle'] ) ? $restorator_options['pagetitle'] : 'show';
	$restorator_pagetitle = ( get_post_meta( $restorator_postId, 'restorator_pagetitle', true ) ? get_post_meta( $restorator_postId, 'restorator_pagetitle', true ) : $restorator_options_pagetitle );
	if ( is_home() || is_singular('post') || is_category() || is_tag() || is_search() || is_day() || is_month() || is_year() ) {
		$restorator_pagetitle = isset( $restorator_options['blog_pagetitle'] ) ? $restorator_options['blog_pagetitle'] : 'hide';
	} elseif ( is_search() ) {
		$restorator_pagetitle = isset( $restorator_options['blog_pagetitle'] ) ? $restorator_options['blog_pagetitle'] : 'hide';
	} else if ( is_singular('portfolio') ) {
		$restorator_pagetitle = isset( $restorator_options['portfolio_single_pagetitle'] ) ? $restorator_options['portfolio_single_pagetitle'] : 'show';
	} else if( class_exists('WooCommerce') && ( is_shop() || is_product_category() || is_product_tag() || is_cart() || is_checkout() || is_account_page() ) ) {
		$restorator_shop_pagetitle = isset( $restorator_options['shop_pagetitle'] ) ? $restorator_options['shop_pagetitle'] : 'show';
		$restorator_pagetitle = $restorator_shop_pagetitle;
	} else if( class_exists('WooCommerce') && is_singular('product') ) {
		$restorator_pagetitle = 'hide';
	}
	
	$classes[] = 'pagetitle_' . $restorator_pagetitle;
	
	//	Page Title show/hide
	$restorator_options_breadcrumbs = isset( $restorator_options['breadcrumbs'] ) ? $restorator_options['breadcrumbs'] : 'show';
	$restorator_breadcrumbs = ( get_post_meta( $restorator_postId, 'restorator_breadcrumbs', true ) ? get_post_meta( $restorator_postId, 'restorator_breadcrumbs', true ) : $restorator_options_breadcrumbs );
	$classes[] = 'breadcrumbs_' . $restorator_breadcrumbs;
	
	//	Footer Fixed
	if( isset( $restorator_options['footer_fixed'] ) && $restorator_options['footer_fixed'] != '0' ) {
		$classes[] = 'footer_fixed';
	}
	
	if ( class_exists( 'woocommerce' ) ) {
		if( isset( $restorator_options['products_no_padding'] ) && $restorator_options['products_no_padding'] != 0 ) {
			$classes[] = 'woo_no_paddings';
		}
	}
	
	return $classes;
}


/**
 * Theme Options
 */
function restorator_option($index1, $index2 = false) {
    global $smof_data;
    if ($index2) {
        $output = isset($smof_data[$index1][$index2]) ? $smof_data[$index1][$index2] : false;
        return $output;
    }
    $output = isset($smof_data[$index1]) ? $smof_data[$index1] : false;
    return $output;
}


//	if WooCommerce Plugin Active
function restorator_woo_enabled() {
    if ( class_exists( 'woocommerce' ) )
        return true;
    return false;
}


/**
 * Insert social metadata into the header
 */
if ( ! function_exists( 'restorator_social_meta' ) ) {
	function restorator_social_meta() {

		global $post, $restorator_options;

		if ( is_singular() ) {

	        echo '<meta property="og:title" content="' . get_the_title() . '"/>';
	        echo '<meta property="og:type" content="article"/>';
	        echo '<meta property="og:url" content="' . get_permalink() . '"/>';
	        echo '<meta property="og:site_name" content="' . get_bloginfo( 'name' ) . '"/>';

			if ( has_post_thumbnail( $post->ID ) ) {
				$restorator_thumb = get_post_thumbnail_id();
				$restorator_img_url = wp_get_attachment_image_src( $restorator_thumb, 'large' );
				$restorator_img_url = $restorator_img_url[0];
			} else {
				$restorator_img_url = isset( $restorator_options['header-logo']['url'] ) ? $restorator_options['header-logo']['url'] : get_template_directory_uri() . '/assets/images/logo.png';
			}

			echo '<meta itemprop="image" content="' . $restorator_img_url . '"> ';
			echo '<meta name="twitter:image:src" content="' . $restorator_img_url . '">';
			echo '<meta property="og:image" content="' . $restorator_img_url . '" />';

		}
	}
}


//	Theme Logo
if ( ! function_exists( 'restorator_logo' ) ) { 
	function restorator_logo() {
		
		global $restorator_options;
		
		if ( ! class_exists( 'ReduxFrameworkPlugin' ) ) {
			$restorator_logo_src 			= get_template_directory_uri() . '/assets/images/logo.png';
			$restorator_logo_retina_src 	= '';
		} else {
			$restorator_logo_src 			= isset( $restorator_options['header-logo']['url'] ) ? $restorator_options['header-logo']['url'] : '';
			$restorator_logo_retina_src 	= isset( $restorator_options['header-logo-retina']['url'] ) ? $restorator_options['header-logo-retina']['url'] : '';
			$restorator_logo_width 			= isset( $restorator_options['header-logo-width'] ) ? $restorator_options['header-logo-width'] : '';
		}
		
		echo '<div class="cstheme-logo">';
			if ( $restorator_logo_src != '' || $restorator_logo_retina_src != '' ) {
				echo '<a class="logo" href="' . esc_url( home_url( '/' ) ) . '">';
					if( $restorator_logo_retina_src != '' ) {
						echo '<img class="logo-img retina" src="' . esc_url( $restorator_logo_retina_src ) . '" style="width:' . esc_attr( $restorator_logo_width ) . 'px" alt="' . get_bloginfo( 'name' ) . '" />';
					} else {
						echo '<img class="logo-img" src="' . esc_url( $restorator_logo_src ) . '" alt="' . get_bloginfo( 'name' ) . '" />';
					}
				echo '</a>';
			} else {
				echo '<h1 class="site-name">';
					echo '<a class="logo" href="'. esc_url( home_url( '/' ) ) .'">';
						bloginfo('name');
					echo '</a>';
				echo '</h1>';
			}
		echo '</div>';
	}
}


//	Theme Favicon
function restorator_favicon() {
	
	global $restorator_options;
	
	if ( ! function_exists( 'has_site_icon' ) || ! has_site_icon() ) {
		if(isset($restorator_options['favicon']['url']) && $restorator_options['favicon']['url']) {
			echo '<link rel="shortcut icon" href="' . esc_url( $restorator_options['favicon']['url'] ) . '"/>';
		} else {
			echo '<link rel="shortcut icon" href="'. get_template_directory_uri() . '/assets/images/favicon.png" />';
		}
		
		if( isset( $restorator_options['favicon-retina']['url'] ) && $restorator_options['favicon-retina']['url'] ) {
			echo '<link rel="apple-touch-icon" href="' . esc_url( $restorator_options['favicon-retina']['url'] ) . '">';
		}
		if( isset( $restorator_options['apple_icons_57x57']['url'] ) && $restorator_options['apple_icons_57x57']['url'] ) {
			echo '<link rel="apple-touch-icon" sizes="57x57" href="' . esc_url( $restorator_options['apple_icons_57x57']['url'] ) . '">';
		}
		if( isset( $restorator_options['apple_icons_72x72']['url'] ) && $restorator_options['apple_icons_72x72']['url'] ) {
			echo '<link rel="apple-touch-icon" sizes="72x72" href="' . esc_url( $restorator_options['apple_icons_72x72']['url'] ) . '">';
		}
		if( isset( $restorator_options['apple_icons_114x114']['url'] ) && $restorator_options['apple_icons_114x114']['url'] ) {
			echo '<link rel="apple-touch-icon" sizes="114x114" href="' . esc_url( $restorator_options['apple_icons_114x114']['url'] ) . '">';
		}
		
	}
	
}


//	Theme Preloader
function restorator_preloader() {
	
	global $restorator_options;
	
	$restorator_preloader = isset( $restorator_options['preloader'] ) ? $restorator_options['preloader'] : 1;
	
	if( $restorator_preloader != 0 ) {
		echo '<div id="loader"><div class="loader_wrap"><span>' . esc_attr__( 'Loading', 'restorator' ) . '</span><div class="bar_wrap"><div class="bar"></div></div></div></div>';
	}
}


//	Social Links
if ( ! function_exists( 'restorator_social_links' ) ) { 

	function restorator_social_links() {	
	
		global $restorator_options;
		
		$output = '';
		$restorator_social_links = array();
		
		if( isset( $restorator_options['facebook_link'] ) && $restorator_options['facebook_link'] ) {
			$restorator_social_links['facebook'] = $restorator_options['facebook_link'];
		}
		
		if( isset( $restorator_options['twitter_link'] ) && $restorator_options['twitter_link'] ) {
			$restorator_social_links['twitter'] = $restorator_options['twitter_link'];
		}
		
		if( isset( $restorator_options['linkedin_link'] ) && $restorator_options['linkedin_link'] ) {
			$restorator_social_links['linkedin'] = $restorator_options['linkedin_link'];
		}
		
		if( isset( $restorator_options['pinterest_link'] ) && $restorator_options['pinterest_link'] ) {
			$restorator_social_links['pinterest'] = $restorator_options['pinterest_link'];
		}
		
		if( isset( $restorator_options['googleplus_link'] ) && $restorator_options['googleplus_link'] ) {
			$restorator_social_links['google-plus'] = $restorator_options['googleplus_link'];
		}
		
		if( isset( $restorator_options['youtube_link'] ) && $restorator_options['youtube_link'] ) {
			$restorator_social_links['youtube'] = $restorator_options['youtube_link'];
		}
		
		if( isset( $restorator_options['rss_link'] ) && $restorator_options['rss_link'] ) {
			$restorator_social_links['rss'] = $restorator_options['rss_link'];
		}
		
		if( isset( $restorator_options['tumblr_link'] ) && $restorator_options['tumblr_link'] ) {
			$restorator_social_links['tumblr'] = $restorator_options['tumblr_link'];
		}
		
		if( isset( $restorator_options['reddit_link'] ) && $restorator_options['reddit_link'] ) {
			$restorator_social_links['reddit'] = $restorator_options['reddit_link'];
		}
		
		if( isset( $restorator_options['dribbble_link'] ) && $restorator_options['dribbble_link'] ) {
			$restorator_social_links['dribbble'] = $restorator_options['dribbble_link'];
		}
		
		if( isset( $restorator_options['digg_link'] ) && $restorator_options['digg_link'] ) {
			$restorator_social_links['digg'] = $restorator_options['digg_link'];
		}
		
		if( isset( $restorator_options['flickr_link'] ) && $restorator_options['flickr_link'] ) {
			$restorator_social_links['flickr'] = $restorator_options['flickr_link'];
		}
		
		if( isset( $restorator_options['instagram_link'] ) && $restorator_options['instagram_link'] ) {
			$restorator_social_links['instagram'] = $restorator_options['instagram_link'];
		}
		
		if( isset( $restorator_options['vimeo_link'] ) && $restorator_options['vimeo_link'] ) {
			$restorator_social_links['vimeo'] = $restorator_options['vimeo_link'];
		}
		
		if( isset( $restorator_options['skype_link'] ) && $restorator_options['skype_link'] ) {
			$restorator_social_links['skype'] = $restorator_options['skype_link'];
		}
		
		if( isset( $restorator_options['yahoo_link'] ) && $restorator_options['yahoo_link'] ) {
			$restorator_social_links['yahoo'] = $restorator_options['yahoo_link'];
		}
		
		if( isset( $restorator_options['tripadvisor_link'] ) && $restorator_options['tripadvisor_link'] ) {
			$restorator_social_links['tripadvisor'] = $restorator_options['tripadvisor_link'];
		}
		
		$restorator_icon_class = '';
		$restorator_social_link = '';
		
		if( isset( $restorator_social_links ) && is_array( $restorator_social_links ) ) {
			foreach( $restorator_social_links as $restorator_icon => $restorator_link ) {
				$restorator_icon_class = $restorator_icon;
				
				$restorator_icon = 'fa fa-' . $restorator_icon;
				
				$restorator_social_link .= '<a class="social_link" href="' . esc_url( $restorator_link ) . '" target="_blank"><i class="' . esc_attr( $restorator_icon ) . '"></i><i class="' . esc_attr( $restorator_icon ) . '"></i></a>';
			}
		}
		
		if( isset( $restorator_social_link ) && $restorator_social_link != '' ) {
			$output .= $restorator_social_link;
		}

		return $output;
	}
}


/**
 * Post excerpt
 */
if (!function_exists('restorator_smarty_modifier_truncate')) {
    function restorator_smarty_modifier_truncate($string, $length = 80, $etc = '... ',
		$break_words = false)
    {
        if ($length == 0)
            return '';

        if (mb_strlen($string, 'utf8') > $length) {
            $length -= mb_strlen($etc, 'utf8');
            if (!$break_words) {
                $string = preg_replace('/\s+\S+\s*$/su', '', mb_substr($string, 0, $length + 1, 'utf8'));
            }
            return mb_substr($string, 0, $length, 'utf8') . $etc;
        } else {
            return $string;
        }
    }
}

//	Comments Count
if (!function_exists('restorator_comment_count')) {
	function restorator_comment_count() {
		$restorator_comment_count = get_comments_number('0', '1', '%');
		if ($restorator_comment_count == 0) {
			$restorator_comment_trans = esc_attr__('No comment', 'restorator');
		} elseif ($restorator_comment_count == 1) {
			$restorator_comment_trans = esc_attr__('1 Comment', 'restorator');
		} else {
			$restorator_comment_trans = $restorator_comment_count . ' ' . esc_attr__('Comments', 'restorator');
		}
		return '<a class="cstheme_comment_count" href="' . get_comments_link() . '" title="' . $restorator_comment_trans . '"><i class="icon Evatheme-Icon-Fonts-thin-0274_chat_message_comment_bubble"></i>' . $restorator_comment_trans . '</a>';
	}
}

/**
 * Single Post Comments List
 */

if (!function_exists('restorator_comment')) {
    function restorator_comment( $comment, $args, $depth ) {
		$GLOBALS['comment'] = $comment; ?>
	
		<li <?php comment_class(); ?> id="li-comment-<?php comment_ID() ?>">
			<div id="comment-<?php comment_ID(); ?>" class="comment-body clearfix">
				<div class="comment-avatar">
					<?php echo get_avatar($comment, $size = '70'); ?>
				</div>
				<div class="comment-content">
					<div class="comment-meta clearfix">
						<span><?php echo esc_html__('author','restorator'); ?></span>
						<span class="comment_author"><?php comment_author(); ?></span>
						<span><?php echo esc_html__('posted','restorator'); ?></span>
						<span class="comment-date"><?php comment_date('F jS Y. g:i a'); ?></span>
						<?php comment_reply_link(array_merge( $args, array( 'depth' => $depth, 'max_depth' => $args['max_depth'], 'reply_text' => '<i class="fa fa-reply"></i>' . esc_attr__('Reply', 'restorator') ))); ?>
						<?php edit_comment_link( esc_html__( 'Edit', 'restorator'),' ','' ); ?>
					</div>
					<div class="comment-text clearfix">
						<?php comment_text(); ?>
						<?php if ( $comment->comment_approved == '0' ) : ?>
							<em><?php esc_html_e( 'Your comment is awaiting moderation.', 'restorator'); ?></em>
							<br>
						<?php endif; ?>
					</div>
				</div>
			</div>
	<?php
	}
}


//	Display navigation to next/previous set of posts when applicable.
if ( ! function_exists( 'restorator_pagination' ) ) { 

	function restorator_pagination( $pages = '' ) {
		
		global $wp_query, $wp_rewrite;
		
		$compile = '';
		
		$pages = ($pages) ? $pages : $wp_query->max_num_pages;

		// Don't print empty markup if there's only one page.
		if ( $pages < 2 ) {
			return;
		}

		$paged        = get_query_var( 'paged' ) ? intval( get_query_var( 'paged' ) ) : 1;
		$pagenum_link = html_entity_decode( get_pagenum_link() );
		$query_args   = array();
		$url_parts    = explode( '?', $pagenum_link );
	
		if ( isset( $url_parts[1] ) ) {
			wp_parse_str( $url_parts[1], $query_args );
		}
	
		$pagenum_link = esc_url ( remove_query_arg( array_keys( $query_args ), $pagenum_link ) );
		$pagenum_link = trailingslashit( $pagenum_link ) . '%_%';
	
		$format  = $wp_rewrite->using_index_permalinks() && ! strpos( $pagenum_link, 'index.php' ) ? 'index.php/' : '';
		$format .= $wp_rewrite->using_permalinks() ? user_trailingslashit( $wp_rewrite->pagination_base . '/%#%', 'paged' ) : '?paged=%#%';
		
		$prev_arrow = 'fa fa-angle-left';
		$next_arrow = 'fa fa-angle-right';
		
		// Set up paginated links.
		$links = paginate_links( array(
			'base'     				=> $pagenum_link,
			'format'   				=> $format,
			'total'    				=> $pages,
			'current'  				=> $paged,
			'show_all' 				=> false,
			'mid_size' 				=> 2,
			'type' 					=> 'array',
			'add_args' 				=> array_map( 'urlencode', $query_args ),
			'prev_text' 			=> '<i class="'. $prev_arrow .'"></i>',
			'next_text' 			=> '<i class="'. $next_arrow .'"></i>',
		) );

		if ( !empty($links) ) {
			$compile .= '<div class="eva-pagination">';
			foreach( $links as $link ) {
				$compile .= $link;
			}
			$compile .= '</div>';
		}

		return $compile;
	}
}


/**
 *	Load More button
 */

if (!function_exists('restorator_infinite_scroll')) {
	function restorator_infinite_scroll( $pages = "" ) {
		
		global $paged, $restorator_wp_query_in_shortcodes;
		
		$compile = '';

        if (empty($paged)) {
            $paged = (get_query_var('page')) ? get_query_var('page') : 1;
        }
		$pages = intval($restorator_wp_query_in_shortcodes->max_num_pages);
		if (empty($pages)) {
			$pages = 1;
		}
		if (1 != $pages) {
			$compile .= '<div class="text-center">';
				$compile .= '<div class="eva-infinite-scroll" data-has-next="' . ( $paged === $pages ? 'false' : 'true' ) . '">';
					$compile .= '<a class="btn btn-infinite-scroll no-more hide" href="#">' . esc_html__('No more posts', 'restorator') . '</a>';
					$compile .= '<a class="btn btn-infinite-scroll loading" href="#"><i class="fa fa-refresh"></i></a>';
					$compile .= '<a class="btn btn-infinite-scroll next" href="' . get_pagenum_link( $paged + 1 ) . '">' . esc_html__('Load more posts', 'restorator') . '</a>';
				$compile .= '</div>';
			$compile .= '</div>';
		}
		
		return $compile; 
	}
}



//	Post Likes
function restorator_enqueue_script() {
	wp_enqueue_script('restorator_ajaxurl', get_template_directory_uri() . '/assets/js/jquery.cookie.js', array('jquery'), false, true);
	wp_add_inline_script( 'restorator_ajaxurl', 'var restorator_ajaxurl = "' . admin_url("admin-ajax.php") . '";' );
}
add_action( 'wp_enqueue_scripts', 'restorator_enqueue_script' );

function restorator_likes() {
	
	wp_enqueue_script('restorator_cookie', get_template_directory_uri() . '/assets/js/jquery.cookie.js', array('jquery'), false, true);
    $restorator_all_likes = get_post_meta(get_the_ID(), 'restorator_likes', true);
    if (!isset($restorator_all_likes) || absint($restorator_all_likes) < 1) {
        $restorator_all_likes = 0;
    }
    echo '
    <span class="cstheme_likes ' . (isset($_COOKIE['like' . get_the_ID()]) ? "already_liked" : "restorator_add_like") . '" data-postid="' . get_the_ID() . '">
        <i class="fa fa-heart-o"></i>
        <span class="likes_count">' . esc_html( $restorator_all_likes ) . '</span>
    </span>
    ';
}

add_action('wp_ajax_add_like_post', 'restorator_add_like_post');
add_action('wp_ajax_nopriv_add_like_post', 'restorator_add_like_post');
function restorator_add_like_post()
{
    $restorator_post_id = absint($_POST['post_id']);
    $restorator_all_likes = get_post_meta($restorator_post_id, 'restorator_likes', true);
    $restorator_all_likes = (isset($restorator_all_likes) ? $restorator_all_likes : 0) + 1;
    update_post_meta($restorator_post_id, 'restorator_likes', $restorator_all_likes);
    echo $restorator_all_likes;
    die();
}



//	Posts per author posts page
add_filter( 'pre_option_posts_per_page', 'restorator_author_posts_per_page' );
function restorator_author_posts_per_page( $posts_per_page ) {
	global $wp_query;
	if ( is_author() ) {
		return 9;
	}
	
	if ( is_search() ) {
		return 500;
	} 

	return $posts_per_page;
}


//	Array of social profiles for team members
function restorator_staff_social_array() {
	return apply_filters( 'restorator_staff_social_array', array(
		'twitter'        => array (
			'key'        => 'twitter',
			'meta'       => 'restorator_staff_twitter',
			'icon_class' => 'fa fa-twitter',
			'label'      => esc_attr__('Twitter', 'restorator'),
		),
		'facebook'        => array (
			'key'        => 'facebook',
			'meta'       => 'restorator_staff_facebook',
			'icon_class' => 'fa fa-facebook',
			'label'      => esc_attr__('Facebook', 'restorator'),
		),
		'instagram'      => array (
			'key'        => 'instagram',
			'meta'       => 'restorator_staff_instagram',
			'icon_class' => 'fa fa-instagram',
			'label'      => esc_attr__('Instagram', 'restorator'),
		),
		'google-plus'    => array (
			'key'        => 'google-plus',
			'meta'       => 'restorator_staff_google-plus',
			'icon_class' => 'fa fa-google-plus',
			'label'      => esc_attr__('Google Plus', 'restorator'),
		),
		'linkedin'       => array (
			'key'        => 'linkedin',
			'meta'       => 'restorator_staff_linkedin',
			'icon_class' => 'fa fa-linkedin',
			'label'      => esc_attr__('Linkedin', 'restorator'),
		),
		'dribbble'       => array (
			'key'        => 'dribbble',
			'meta'       => 'restorator_staff_dribbble',
			'icon_class' => 'fa fa-dribbble',
			'label'      => esc_attr__('Dribbble', 'restorator'),
		),
		'vk'             => array (
			'key'        => 'vk',
			'meta'       => 'restorator_staff_vk',
			'icon_class' => 'fa fa-vk',
			'label'      => esc_attr__('VK', 'restorator'),
		),
		'skype'          => array (
			'key'        => 'skype',
			'meta'       => 'restorator_staff_skype',
			'icon_class' => 'fa fa-skype',
			'label'      => esc_attr__('Skype', 'restorator'),
		),
		'phone_number'   => array (
			'key'        => 'phone_number',
			'meta'       => 'restorator_staff_phone_number',
			'icon_class' => 'fa fa-phone',
			'label'      => esc_attr__( 'Phone Number', 'restorator' ),
		),
		'email'          => array (
			'key'        => 'email',
			'meta'       => 'restorator_staff_email',
			'icon_class' => 'fa fa-envelope',
			'label'      => esc_attr__( 'Email', 'restorator' ),
		),
		'website'        => array (
			'key'        => 'website',
			'meta'       => 'restorator_staff_website',
			'icon_class' => 'fa fa-external-link-square',
			'label'      => esc_attr__( 'Website', 'restorator' ),
		),
	) );
}

//	Creates an array for adding the team social options to the metaboxes
function restorator_staff_social_meta_array() {
	$profiles = restorator_staff_social_array();
	$array = array();
	foreach ( $profiles as $profile ) {
		$array[] = array(
				'title' => '<span class="'. $profile['icon_class'] .'"></span>' . $profile['label'],
				'id'    => $profile['meta'],
				'type'  => 'text',
				'std'   => '',
		);
	}
	return $array;
}


//	Get FontAwesome Icons Array
if ( ! function_exists( 'restorator_get_fontawesome_icon_array' ) ) {
	function restorator_get_fontawesome_icon_array() {
		global $wp_filesystem;

		$pattern = '/\.(fa-(?:\w+(?:-)?)+):before\s+{\s*content:\s*"(.+)";\s+}/';
		
		if (empty($wp_filesystem)) {
			require_once(ABSPATH . '/wp-admin/includes/file.php');
			WP_Filesystem();
		}
		$fontawesome_path = get_template_directory() . '/assets/css/font-awesome.css';
		if( file_exists( $fontawesome_path ) ) {
			$subject = $wp_filesystem->get_contents($fontawesome_path);
		}
		
		preg_match_all($pattern, $subject, $matches, PREG_SET_ORDER);
		
		$icons = array();
		
		foreach($matches as $match){
			$icons[$match[1]] = $match[2];
		}
		
		return $icons;
		
	}
}


//	Portfolio Filter
if (!function_exists('restorator_portfolio_filter')) {
    function restorator_portfolio_filter($post_type_terms = "")
    {
        if (!isset($term_list)) {
            $term_list = '';
        }
        $permalink = get_permalink();
        $args = array('taxonomy' => 'Category', 'include' => $post_type_terms);
        $terms = get_terms('portfolio_category', $args);
        $count = count($terms);
        $i = 0;
        $iterm = 1;
		
		$compile = '';
		
        if ($count > 0) {
            $cape_list = '';
            if ($count > 1) {
                $term_list .= '<li class="' . (!isset($_GET['slug']) ? 'selected' : '') . '">';

                $args_for_count_all_terms = array(
                    'post_type' => 'portfolio',
                    'post_status' => 'publish'
                );
                $query_for_count_all_terms = new WP_Query($args_for_count_all_terms);

                $term_list .= '<a href="#filter" data-option-value="*" data-catname="all" data-title="' . $query_for_count_all_terms->post_count . '">' . esc_html__('All', 'restorator') . '</a>
				</li>';
            }
            $termcount = count($terms);
            if (is_array($terms)) {
                foreach ($terms as $term) {

                    $args_for_count_all_terms = array(
                        'post_type' => 'portfolio',
                        'post_status' => 'publish',
                        'tax_query' => array(
                            array(
                                'taxonomy' => 'portfolio_category',
                                'field' => 'id',
                                'terms' => $term->term_id
                            )
                        )
                    );
                    $query_for_count_all_terms = new WP_Query($args_for_count_all_terms);

                    $i++;
                    $permalink = esc_url(add_query_arg("slug", $term->term_id, $permalink));
                    $term_list .= '<li ';
                    if (isset($_GET['slug'])) {
                        $getslug = $_GET['slug'];
                    } else {
                        $getslug = '';
                    }

                    if (strnatcasecmp($getslug, $term->term_id) == 0) $term_list .= 'class="selected"';

                    $tempname = strtr($term->name, array(
                        ' ' => '-',
                    ));
                    $tempname = strtolower($tempname);
                    $term_list .= '><a data-option-value=".' . $tempname . '" data-catname="' . $tempname . '" href="#filter"  data-title="' . $query_for_count_all_terms->post_count . '">' . $term->name . '</a>
                </li>';
                    if ($count != $i) $term_list .= ' '; else $term_list .= '';

                    $iterm++;
                }
            }
            
			$compile .= '<div class="filter_block"><ul data-option-key="filter" class="optionset">' . $term_list . '</ul></div>';
			
			return $compile;
			
        }
    }
}