<?php
if(class_exists( 'Menu_Item_Custom_Fields' )){
	require_once get_template_directory() . '/framework/menu-item-custom-fields.php';
}
require_once get_template_directory() . '/framework/theme-configs.php';
require_once get_template_directory() . '/framework/widgets/popular.php';
require_once get_template_directory() . '/framework/wp_bootstrap_navwalker.php';
if(function_exists('vc_add_param')){
require_once get_template_directory() . '/vc_functions.php';
}

if ( ! isset( $content_width ) )
	$content_width = 604;

function photofolio_setup() {
	/*
	 * Makes photofolio available for translation.
	 *
	 * Translations can be added to the /languages/ directory.
	 * If you're building a theme based on photofolio, use a find and
	 * replace to change 'photofolio' to the name of your theme in all
	 * template files.
	 */
	load_theme_textdomain( 'photofolio', get_template_directory() . '/languages' );

	
	// Adds RSS feed links to <head> for posts and comments.
	add_theme_support( 'automatic-feed-links' );
	add_theme_support( 'title-tag' );
	 add_theme_support( 'custom-header');
	 add_theme_support( 'custom-background');
	/*
	 * Switches default core markup for search form, comment form,
	 * and comments to output valid HTML5.
	 */
	add_theme_support( 'html5', array(
		'search-form', 'comment-form', 'comment-list', 'gallery', 'caption'
	) );

	/*
	 * This theme supports all available post formats by default.
	 * See http://codex.wordpress.org/Post_Formats
	 */
	 add_theme_support( 'post-formats', array(
		 'video','gallery','quote'
	) );
	 
	add_theme_support( 'woocommerce' );

	// This theme uses wp_nav_menu() in one location.
	register_nav_menu( 'primary', esc_html__( 'Main Navigation Menu', 'photofolio' ) );
	register_nav_menu( 'onepage', esc_html__( 'Navigation Menu for One Page Template', 'photofolio' ) );

	/*
	 * This theme uses a custom image size for featured images, displayed on
	 * "standard" posts and pages.
	 */
	add_theme_support( 'post-thumbnails' );
	
	
}
add_action( 'after_setup_theme', 'photofolio_setup' );

function photofolio_thumbnail_url($size, $id){
    global $post;
    if($id==''){
        $id = $post->ID;
    }
    if($size==''){
        $url = wp_get_attachment_url( get_post_thumbnail_id($id) );
         return $url;
    }else{
        $url = wp_get_attachment_image_src( get_post_thumbnail_id($id), $size);
         return $url[0];
    }
   
}

function photofolio_scripts_styles() {
	global $photofolio_options;
	/*
	 * Adds JavaScript to pages with the comment form to support
	 * sites with threaded comments (when in use).
	 */
	if ( is_singular() && comments_open() && get_option( 'thread_comments' ) )
		wp_enqueue_script( 'comment-reply' );

	
	// Loads JavaScript file with functionality specific to photofolio.
	wp_enqueue_script("bootstrap", get_template_directory_uri()."/js/bootstrap.js",array('jquery'),false,true);
	wp_enqueue_script("photofolio-flexslider", get_template_directory_uri()."/js/jquery.flexslider.js",array('jquery'),false,true);
	wp_enqueue_script("imagesloaded", get_template_directory_uri()."/js/jquery.imagesloaded.min.js",array('jquery'),false,true);
	wp_enqueue_script("owl.carousel", get_template_directory_uri()."/js/owl.carousel.min.js",array('jquery'),false,true);
	wp_enqueue_script("isotope", get_template_directory_uri()."/js/jquery.isotope.min.js",array('jquery'),false,true);
	wp_enqueue_script("waypoint", get_template_directory_uri()."/js/waypoint.min.js",array('jquery'),false,true);
	
	if(is_page_template('template-one.php')){
		wp_enqueue_script("smooth-scroll", get_template_directory_uri()."/js/smooth-scroll.js",array('jquery'),false,true);
	}
	if(is_page_template('template-comming.php')){
		wp_enqueue_script("countdown", get_template_directory_uri()."/js/countdown.js",array('jquery'),false,true);
	}
	

	
	wp_enqueue_script("photofolio-script", get_template_directory_uri()."/js/script.js",array('jquery'),false,true);

	// Add Source Sans Pro and Bitter fonts, used in the main stylesheet.
	wp_enqueue_style( 'font-awesome', get_template_directory_uri().'/css/font-awesome.css');
	wp_enqueue_style( 'bootstrap', get_template_directory_uri().'/css/bootstrap.css');
	wp_enqueue_style( 'photofolio-flexslider', get_template_directory_uri().'/css/flexslider.css');
	wp_enqueue_style( 'owl.carousel', get_template_directory_uri().'/css/owl.carousel.css');
    wp_enqueue_style( 'owl.theme', get_template_directory_uri().'/css/owl.theme.css');

	wp_enqueue_style( 'photofolio-default', get_template_directory_uri().'/css/photofolio_style.css');
	// Loads our main stylesheet.
	wp_enqueue_style( 'photofolio-style', get_stylesheet_uri(), array(), '2016-04-10' );
	
	

}
add_action( 'wp_enqueue_scripts', 'photofolio_scripts_styles' );

/*
Register Fonts
*/
function photofolio_fonts_url() {
	global $photofolio_options;
    $font_url = '';
    
    /*
    Translators: If there are characters in your language that are not supported
    by chosen font(s), translate this to 'off'. Do not translate into your own language.
     */
    if ( 'off' !== _x( 'on', 'Google font: on or off', 'photofolio' ) ) {
        $font_url = add_query_arg( 'family', urlencode( 'Montserrat:400,700|Yesteryear:400|Dancing+Script:400,700|'.$photofolio_options['body-font2']['font-family'].':400,500,700,500italic,400italic,300italic,300,100,100italic,700italic,900,900italic&subset=latin,latin-ext' ), "//fonts.googleapis.com/css" );
    }
    return $font_url;
}
/*
Enqueue scripts and styles.
*/
function photofolio_scripts() {
	global $photofolio_options;
	if($photofolio_options!=null && $photofolio_options['body-font2']['font-family'] != ''){
		wp_enqueue_style( 'photofolio-fonts', photofolio_fonts_url(), array(), '1.0.0' );
	}
}
add_action( 'wp_enqueue_scripts', 'photofolio_scripts' );



//Colors


function photofolio_hex2rgb($hex) {
   $hex = str_replace("#", "", $hex);

   if(strlen($hex) == 3) {
      $r = hexdec(substr($hex,0,1).substr($hex,0,1));
      $g = hexdec(substr($hex,1,1).substr($hex,1,1));
      $b = hexdec(substr($hex,2,1).substr($hex,2,1));
   } else {
      $r = hexdec(substr($hex,0,2));
      $g = hexdec(substr($hex,2,2));
      $b = hexdec(substr($hex,4,2));
   }
   $rgb = array($r, $g, $b);
  
   return $rgb; // returns an array with the rgb values
}


function photofolio_color() {
	wp_enqueue_style(
        'custom-style',
        get_template_directory_uri() . '/css/custom_script.css'
    );
	global $photofolio_options, $wp_query;
	
	
	$custom_css = '';
	
		$custom_css = "
			
		
		".$photofolio_options['custom-css'];
		
		$custom_css .= "
			
		";
		if($photofolio_options['404_bg']['url']!=''){
			$custom_css .= " .error-section{
				background-image: url(".$photofolio_options['404_bg']['url'].");
			} ";
		}
		
		
	

	wp_add_inline_style( 'custom-style', $custom_css );

}
add_action( 'wp_enqueue_scripts', 'photofolio_color' );



add_filter('wp_list_categories', 'photofolio__span_cat_count');
function photofolio__span_cat_count($links) {
$links = str_replace('</a> (', '</a> <span>(', $links);
$links = str_replace(')', ')</span>', $links);
return $links;
}


add_action( 'photofolio_post_meta', 'photofolio_post_meta' );
if (!function_exists('photofolio_post_meta')) {
function photofolio_post_meta(){ ?>
	 <span><?php the_time(get_option( 'date_format' )); ?>, <?php comments_popup_link('0 Comments','1 Comment','% Comments','comm'); ?></span>
<?php } }

add_action( 'photofolio_post_share', 'photofolio_post_share' );
if (!function_exists('photofolio_post_share')) {
function photofolio_post_share($id){ ?>
	 <div class="social-box">
		<?php if( function_exists('get_simple_likes_button') ) echo get_simple_likes_button($id);?>
		<ul class="social-icons">
			<li><a class="facebook" onclick="window.open('http://www.facebook.com/sharer.php?u=<?php the_permalink(); ?>','Facebook','width=600,height=300,left='+(screen.availWidth/2-300)+',top='+(screen.availHeight/2-150)+''); return false;" href="http://www.facebook.com/sharer.php?u=<?php the_permalink(); ?>"><i class="fa fa-facebook"></i></a></li>
			<li><a class="twitter" onclick="window.open('http://twitter.com/share?url=<?php the_permalink(); ?>&amp;text=<?php echo str_replace(" ","%20",get_the_title()); ?>','Twitter share','width=600,height=300,left='+(screen.availWidth/2-300)+',top='+(screen.availHeight/2-150)+''); return false;" href="http://twitter.com/share?url=<?php the_permalink(); ?>&amp;text=<?php echo str_replace(" ","%20",get_the_title()); ?>"><i class="fa fa-twitter"></i></a></li>
			<li><a class="google" href="http://plus.google.com/share?url=<?php the_permalink(); ?>" onclick="window.open(this.href, 'mywin','left=50,top=50,width=600,height=350,toolbar=0'); return false;"><i class="fa fa-google-plus"></i></a></li>
			<li><a class="linkedin" onclick="window.open('http://www.linkedin.com/shareArticle?mini=true&amp;url=<?php the_permalink(); ?>','Linkedin','width=863,height=500,left='+(screen.availWidth/2-431)+',top='+(screen.availHeight/2-250)+''); return false;" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=<?php the_permalink(); ?>"><i class="fa fa-linkedin"></i></a></li>
			<li><a href="#"><i class="fa fa-share-alt"></i></a></li>
		</ul>
	</div>
<?php } }

function photofolio_custom(){
	global $photofolio_options;

	$theme_options = $photofolio_options;

	return $theme_options;
}


function photofolio_widgets_init() {
	register_sidebar( array(
		'name'          => esc_html__( 'Main Widget Area', 'photofolio' ),
		'id'            => 'sidebar-1',
		'description'   => esc_html__( 'Appears in main sidebar of the site.', 'photofolio' ),
		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
		'after_widget'  => '</aside>',
		'before_title'  => '<h2 class="widget-title">',
		'after_title'   => '</h2>',
	) );register_sidebar( array(
		'name'          => esc_html__( 'Right Sidebar', 'photofolio' ),
		'id'            => 'sidebar-2',
		'description'   => esc_html__( 'Appears in right flying sidebar of the site.', 'photofolio' ),
		'before_widget' => '<aside id="%1$s" class="sidebar-widget %2$s">',
		'after_widget'  => '</aside>',
		'before_title'  => '<h2 class="widget-title">',
		'after_title'   => '</h2>',
	) );
	register_sidebar( array(
		'name'          => esc_html__( 'Shop Sidebar', 'photofolio' ),
		'id'            => 'sidebar-3',
		'description'   => esc_html__( 'Appears in Shop page of the site.', 'photofolio' ),
		'before_widget' => '<aside id="%1$s" class="shop-widget %2$s">',
		'after_widget'  => '</aside>',
		'before_title'  => '<h2 class="widget-title">',
		'after_title'   => '</h2>',
	) );
	register_sidebar( array(
        'name'          => esc_html__( 'Footer Bottom Section', 'photofolio' ),
        'id'            => 'footer-b',
        'description'   => esc_html__( 'Appears in the footer section at bottom of the site.', 'photofolio' ),
        'before_widget' => '<aside id="%1$s" class="footer-widget %2$s">',
        'after_widget'  => '</aside>',
        'before_title'  => '<h6 class="widget-title">',
        'after_title'   => '</h6>',
    ) );
	
    
}
add_action( 'widgets_init', 'photofolio_widgets_init' );

/* add admin-ajax */
function photofolio_custom_head(){
	echo '<script type="text/javascript">var ajaxurl = \'' . admin_url('admin-ajax.php') . '\';</script>';
}
add_action('wp_head', 'photofolio_custom_head');


function photofolio_load_portfolio_grid(){
	global $photofolio_options;
	$response = '';
	$cat = $_POST['cat'];
	$order = $_POST['order'];
	$offset = $_POST['offset'];

	if(isset($cat) and $cat!='all'){
		$args = array('post_type' => 'portfolio','post_status' => 'publish','offset' =>$offset, 'posts_per_page' => $order, 'tax_query' => array(
		array(
			'taxonomy' => 'portfolio_category',
			'field'    => 'slug',
			'terms'    => $cat,
		),
	));
	}else{
		$args = array('post_type' => 'portfolio', 'post_status' => 'publish','offset' =>$offset, 'posts_per_page' => $order);
	}

	
	$portfolio = new WP_Query($args);
?>	

<?php 
      if($portfolio->have_posts()) :
             $i=1; while($portfolio->have_posts()) : $portfolio->the_post(); 
    ?>
	
    <?php
			$item_classes = '';
			$item_skill = '';
			$item_cats = get_the_terms(get_the_ID(), 'portfolio_tag');
			$i=1; foreach((array)$item_cats as $item_cat){
				if(count($item_cat)>0){
					$item_classes .= $item_cat->slug . ' ';
					
				}

				if($i=1){
					$item_skill .= $item_cat->name;
				}else{
					$item_skill .= ', '. $item_cat->name;
				}

			$i++; }
		?>
	<div class="project-post <?php echo esc_attr($item_classes); ?>">
		<?php the_post_thumbnail($thumbsize); ?>
		<div class="hover-box">
			<div class="inner-hover">
				<?php if( function_exists('get_simple_likes_button') ) echo get_simple_likes_button(get_the_ID());?>
				<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
				
				<?php echo get_the_term_list( get_the_ID(), 'portfolio_tag', '<ul class="project-tags"><li>', ',</li><li>', '</li></ul>' );?>
			</div>
		</div>
	</div>
	

	<?php $i++; endwhile; ?>
	<?php endif; ?>
	<?php wp_reset_postdata(); ?>

<?php	
	echo $response;
	die();
}
add_action('wp_ajax_photofolio_load_portfolio_grid', 'photofolio_load_portfolio_grid');
add_action('wp_ajax_nopriv_photofolio_load_portfolio_grid', 'photofolio_load_portfolio_grid');


function photofolio_load_portfolio_grid2(){
	global $photofolio_options;
	$response = '';
	$cat = $_POST['cat'];
	$order = $_POST['order'];
	$offset = $_POST['offset'];

	if(isset($cat) and $cat!='all'){
		$args = array('post_type' => 'portfolio','post_status' => 'publish','offset' =>$offset, 'posts_per_page' => $order, 'tax_query' => array(
		array(
			'taxonomy' => 'portfolio_category',
			'field'    => 'slug',
			'terms'    => $cat,
		),
	));
	}else{
		$args = array('post_type' => 'portfolio', 'post_status' => 'publish','offset' =>$offset, 'posts_per_page' => $order);
	}

	
	$portfolio = new WP_Query($args);
?>	

<?php 
      if($portfolio->have_posts()) :
             $i=1; while($portfolio->have_posts()) : $portfolio->the_post(); 
    ?>
	
    <?php
			$item_classes = '';
			$item_skill = '';
			$item_cats = get_the_terms(get_the_ID(), 'portfolio_tag');
			$i=1; foreach((array)$item_cats as $item_cat){
				if(count($item_cat)>0){
					$item_classes .= $item_cat->slug . ' ';
					
				}

				if($i=1){
					$item_skill .= $item_cat->name;
				}else{
					$item_skill .= ', '. $item_cat->name;
				}

			$i++; }
		?>
	<div class="project-post <?php echo esc_attr($item_classes); ?>">
		<div class="post-gallery">
				<?php the_post_thumbnail($thumbsize); ?>
				<?php if( function_exists('get_simple_likes_button') ) echo get_simple_likes_button(get_the_ID());?>
			</div>
			<div class="title-post">
				<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
				<?php echo get_the_term_list( get_the_ID(), 'portfolio_tag', '<ul class="project-tags"><li>', ',</li><li>', '</li></ul>' );?>
			</div>
	</div>
	

	<?php $i++; endwhile; ?>
	<?php endif; ?>
	<?php wp_reset_postdata(); ?>

<?php	
	echo $response;
	die();
}
add_action('wp_ajax_photofolio_load_portfolio_grid2', 'photofolio_load_portfolio_grid2');
add_action('wp_ajax_nopriv_photofolio_load_portfolio_grid2', 'photofolio_load_portfolio_grid2');




function photofolio_load_post(){
	global $photofolio_options;
	$response = '';
	$cat = $_POST['cat'];
	$order = $_POST['order'];
	$offset = $_POST['offset'];

	$args = array(
		'post_type' => 'post',
		'posts_per_page' =>$order,
		'offset' =>$offset
	);
	if($cat!='all'){
	  if ( is_rtl() ) {
	  	$args['cat'] = $cat;
	  }else{
	  	$args['category_name'] = $cat;
	  }
	}
	
	$portfolio = new WP_Query($args);
?>	

<?php 
      if($portfolio->have_posts()) :
             $i=1; while($portfolio->have_posts()) : $portfolio->the_post(); 
    ?>
	
   
	<?php get_template_part( 'content', ( post_type_supports( get_post_type(), 'post-formats' ) ? get_post_format() : get_post_type() ) ); ?>
	

	<?php $i++; endwhile; ?>
	<?php endif; ?>
	<?php wp_reset_postdata(); ?>

<?php	
	echo $response;
	die();
}
add_action('wp_ajax_photofolio_load_post', 'photofolio_load_post');
add_action('wp_ajax_nopriv_photofolio_load_post', 'photofolio_load_post');


function photofolio_excerpt($limit = 30) {
 
  $excerpt = explode(' ', get_the_excerpt(), $limit);
  if (count($excerpt)>=$limit) {
    array_pop($excerpt);
    $excerpt = implode(" ",$excerpt).'...';
  } else {
    $excerpt = implode(" ",$excerpt);
  }
  $excerpt = preg_replace('`[[^]]*]`','',$excerpt);
  return $excerpt;
}


function photofolio_excerpt_more( $more ) {
	return '...';
}
add_filter( 'excerpt_more', 'photofolio_excerpt_more' );

//pagination
if (!function_exists('photofolio_pagination')) {
function photofolio_pagination($pages='') {
    global $wp_query, $wp_rewrite;
    $wp_query->query_vars['paged'] > 1 ? $current = $wp_query->query_vars['paged'] : $current = 1;
    if($pages==''){
        global $wp_query;
         $pages = $wp_query->max_num_pages;
         if(!$pages)
         {
             $pages = 1;
         }
    }if(is_front_page() and !is_home()) {
		$curent = (get_query_var('page')) ? get_query_var('page') : 1;
	} else {
		$curent = (get_query_var('paged')) ? get_query_var('paged') : 1;
	}
    ?>

    <ul class="pagination-list">
    	
		<li class="prev"><?php previous_posts_link('<i class="fa fa-angle-left"></i>'); ?></li>
		
		<li><a href="#"><?php echo esc_html($current); ?></a></li>
		<li><a href="#"><?php echo esc_html($pages); ?></a></li>
		
		<li class="next"><?php next_posts_link('<i class="fa fa-angle-right"></i>', $pages); ?></li>
		
	</ul>

<?php	
}
}
//Custom comment List:
function photofolio_theme_comment($comment, $args, $depth) {
	
     $GLOBALS['comment'] = $comment; ?>
     <!--=======  COMMENTS =========-->
     <li <?php comment_class(''); ?> id="comment-<?php comment_ID() ?>" >
		
	 	
	 	<div class="comment-box">
			<?php if($comment->user_id!='0' and get_user_meta($comment->user_id, '_photofolio_avatar' ,true)!=''){ ?>
				<?php $image = get_user_meta($comment->user_id, '_photofolio_avatar' ,true); ?>
				<img src="<?php echo esc_attr($image); ?>" />
			<?php }else{ ?>
				<?php echo get_avatar($comment); ?>
			<?php } ?>
			<div class="comment-content">
				<h4><?php printf(esc_html__('%s','photofolio'), get_comment_author_link()) ?></h4>
				<span><?php printf(esc_html__('%1$s at %2$s','photofolio'), get_comment_date(), get_comment_time()) ?></span>
				<?php comment_text() ?>
				 <?php if ($comment->comment_approved == '0') : ?>
				 <em><?php esc_html_e('Your comment is awaiting moderation.','photofolio') ?></em>
				 <br />
			 <?php endif; ?>
				<?php comment_reply_link(array_merge( $args, array('depth' => $depth, 'max_depth' => $args['max_depth']))) ?>
			</div>
		</div>
	 
<?php

}
if (!function_exists('photofolio_breadcrumb')) {
function photofolio_breadcrumb() {
       /* === OPTIONS === */
    $text['home']     = esc_html__('Home','photofolio'); // text for the 'Home' link
    $text['category'] = esc_html__('Archive by Category','photofolio').' "%s"'; // text for a category page
    $text['tax']       = esc_html__('Archive for','photofolio').' "%s"'; // text for a taxonomy page
    $text['search']   = esc_html__('Search Results for','photofolio').' "%s"'.esc_html(' Query','photofolio'); // text for a search results page
    $text['tag']      = esc_html__('Posts Tagged','photofolio').' "%s"'; // text for a tag page
    $text['author']   = esc_html__('Articles Posted','photofolio').' by %s'; // text for an author page
    $text['404']      = esc_html__('Error 404','photofolio'); // text for the 404 page
    $showCurrent = 1; // 1 - show current post/page title in breadcrumbs, 0 - don't show
    $showOnHome  = 0; // 1 - show breadcrumbs on the homepage, 0 - don't show
    $delimiter   = ''; // delimiter between crumbs
    $before      = '<li class="active">'; // tag before the current crumb
    $after       = '</li>'; // tag after the current crumb

    /* === END OF OPTIONS === */

    global $post;
    $homeLink = home_url('/');
    $linkBefore = '<li>';
    $linkAfter = '</li>';
    $linkAttr = ' rel="v:url" property="v:title"';
    $link = $linkBefore . '<a' . $linkAttr . ' href="%1$s">%2$s</a>' . $linkAfter;
    if (is_home() || is_front_page()) {
        if ($showOnHome == 1) echo '<div id="crumbs"><a href="' . esc_url($homeLink) . '">' . $text['home'] . '</a></div>';
    } else {
        echo '<ul id="breadcrumbs" class="page-pag">' . sprintf($link, $homeLink, $text['home']) . $delimiter;
        if ( is_category() ) {
            $thisCat = get_category(get_query_var('cat'), false);
            if ($thisCat->parent != 0) {
                $cats = get_category_parents($thisCat->parent, TRUE, $delimiter);
                $cats = str_replace('<a', $linkBefore . '<a' . $linkAttr, $cats);
                $cats = str_replace('</a>', '</a>' . $linkAfter, $cats);
                echo $cats;
            }
            echo $before . sprintf($text['category'], single_cat_title('', false)) . $after;
        } elseif( is_tax() ){
            $thisCat = get_category(get_query_var('cat'), false);
            if (isset($thisCat->parent)) {
                $cats = get_category_parents($thisCat->parent, TRUE, $delimiter);
                $cats = str_replace('<a', $linkBefore . '<a' . $linkAttr, $cats);
                $cats = str_replace('</a>', '</a>' . $linkAfter, $cats);
                echo $cats;
            }

            echo $before . sprintf($text['tax'], single_cat_title('', false)) . $after;
        }elseif ( is_search() ) {
            echo $before . sprintf($text['search'], get_search_query()) . $after;
        } elseif ( is_day() ) {
            echo sprintf($link, get_year_link(get_the_time('Y')), get_the_time('Y')) . $delimiter;
            echo sprintf($link, get_month_link(get_the_time('Y'),get_the_time('m')), get_the_time('F')) . $delimiter;
            echo $before . get_the_time('d') . $after;
        } elseif ( is_month() ) {
            echo sprintf($link, get_year_link(get_the_time('Y')), get_the_time('Y')) . $delimiter;
            echo $before . get_the_time('F') . $after;
        } elseif ( is_year() ) {
            echo $before . get_the_time('Y') . $after;
        } elseif ( is_single() && !is_attachment() ) {
            if ( get_post_type() != 'post' ) {
                $post_type = get_post_type_object(get_post_type());
                $slug = $post_type->rewrite;
                printf($link, $homeLink . '/' . $slug['slug'] . '/', $post_type->labels->singular_name);
                if ($showCurrent == 1) echo $delimiter . $before . get_the_title() . $after;
            } else {
                $cat = get_the_category(); $cat = $cat[0];
                $cats = get_category_parents($cat, TRUE, $delimiter);
                if ($showCurrent == 0) $cats = preg_replace("#^(.+)$delimiter$#", "$1", $cats);
                $cats = str_replace('<a', $linkBefore . '<a' . $linkAttr, $cats);
                $cats = str_replace('</a>', '</a>' . $linkAfter, $cats);
                echo $cats;
                if ($showCurrent == 1) echo $before . get_the_title() . $after;
            }
        } elseif ( !is_single() && !is_page() && get_post_type() != 'post' && !is_404() ) {
            $post_type = get_post_type_object(get_post_type());
            echo $before . $post_type->labels->singular_name . $after;
        } elseif ( is_attachment() ) {
            $parent = get_post($post->post_parent);
            $cat = get_the_category($parent->ID); $cat = $cat[0];
            $cats = get_category_parents($cat, TRUE, $delimiter);
            $cats = str_replace('<a', $linkBefore . '<a' . $linkAttr, $cats);
            $cats = str_replace('</a>', '</a>' . $linkAfter, $cats);
            echo $cats;
            printf($link, get_permalink($parent), $parent->post_title);
            if ($showCurrent == 1) echo $delimiter . $before . get_the_title() . $after;
        } elseif ( is_page() && !$post->post_parent ) {
            if ($showCurrent == 1) echo $before . get_the_title() . $after;
        } elseif ( is_page() && $post->post_parent ) {
            $parent_id  = $post->post_parent;
            $breadcrumbs = array();
            while ($parent_id) {
                $page = get_page($parent_id);
                $breadcrumbs[] = sprintf($link, get_permalink($page->ID), get_the_title($page->ID));
                $parent_id  = $page->post_parent;
            }
            $breadcrumbs = array_reverse($breadcrumbs);
            for ($i = 0; $i < count($breadcrumbs); $i++) {
                echo $breadcrumbs[$i];
                if ($i != count($breadcrumbs)-1) echo $delimiter;
            }
            if ($showCurrent == 1) echo $delimiter . $before . get_the_title() . $after;
        } elseif ( is_tag() ) {
            echo $before . sprintf($text['tag'], single_tag_title('', false)) . $after;
        } elseif ( is_author() ) {
             global $author;
            $userdata = get_userdata($author);
            echo $before . sprintf($text['author'], $userdata->display_name) . $after;
        } elseif ( is_404() ) {
            echo $before . $text['404'] . $after;
        }
        if ( get_query_var('paged') ) {
            if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) echo ' (';
            echo esc_html__('Page','photofolio') . ' ' . get_query_var('paged');
            if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) echo ')';
        }
        echo '</ul>';
    }
}

}

add_action( 'cmb2_admin_init', 'photofolio_metaboxes' );
/**
 * Define the metabox and field configurations.
 */
function photofolio_metaboxes() {
	global $photofolio_options; 
    // Start with an underscore to hide fields from custom fields list
    $prefix = '_photofolio_';

    /**
     * Initiate the metabox
     */
    $cmb = new_cmb2_box( array(
        'id'            => 'page_options',
        'title'         => esc_html__( 'Page Setting', 'photofolio' ),
        'object_types'  => array( 'page' ), // Post type
        'context'       => 'normal',
        'priority'      => 'high',
        'show_names'    => true, // Show field names on the left
        
    ) );
    $cmb->add_field( array(
		'name'             => esc_html__( 'Header Style', 'photofolio' ),
		'desc'             => esc_html__( 'Select your header style', 'photofolio' ),
		'id'               => $prefix . 'header_style',
		'type'             => 'select',
		
		'options'          => array(
			'standard' => esc_html__( 'Default', 'photofolio' ),
			'vertical' => esc_html__( 'Vertical', 'photofolio' ),
			'transparent' => esc_html__( 'Transparent', 'photofolio' ),
			
		),
	) );

	 $cmb->add_field( array(
		'name'             => esc_html__( 'Trurn On/Off Footer Widget Area', 'photofolio' ),
		'desc'             => '',
		'id'               => $prefix . 'footer_widget',
		'type'             => 'select',
		
		'options'          => array(
			'on' => esc_html__( 'On', 'photofolio' ),
			'off' => esc_html__( 'Off', 'photofolio' ),
			
		),
	) );
	 $cmb->add_field( array(
		'name'             => esc_html__( 'Trurn On/Off Page title section', 'photofolio' ),
		'desc'             => '',
		'id'               => $prefix . 'page_title',
		'type'             => 'select',
		
		'options'          => array(
			'on' => esc_html__( 'On', 'photofolio' ),
			'off' => esc_html__( 'Off', 'photofolio' ),
			
		),
	) );
	 $cmb->add_field(  array(
        'name' => esc_html__('Slider Shortcode For "One Page" Template','photofolio'),
        'desc' => '',
        'id'   => $prefix . 'slider',
        'type'    => 'text',
        
    ));
	 $cmb = new_cmb2_box( array(
        'id'            => 'product_options',
        'title'         => esc_html__( 'Product Setting', 'photofolio' ),
        'object_types'  => array( 'product' ), // Post type
        'context'       => 'normal',
        'priority'      => 'high',
        'show_names'    => true, // Show field names on the left
        
    ) );
    $cmb->add_field( array(
		'name'             => esc_html__( 'Header Style', 'photofolio' ),
		'desc'             => esc_html__( 'Select your header style', 'photofolio' ),
		'id'               => $prefix . 'header_style',
		'type'             => 'select',
		
		'options'          => array(
			'standard' => esc_html__( 'Default', 'photofolio' ),
			'vertical' => esc_html__( 'Vertical', 'photofolio' ),
			'transparent' => esc_html__( 'Transparent', 'photofolio' ),
			
		),
	) );
    /**
     * Initiate the metabox
     */
    $cmb = new_cmb2_box( array(
        'id'            => 'post_options',
        'title'         => esc_html__( 'Post Options', 'photofolio' ),
        'object_types'  => array( 'post', ), // Post type
        'context'       => 'normal',
        'priority'      => 'high',
        'show_names'    => true, // Show field names on the left
        
    ) );

    // Regular text field
    $cmb->add_field( array(
        'name'       => esc_html__( 'Post Gallery', 'photofolio' ),
        'desc'       => esc_html__( 'Upload post images for intro slider', 'photofolio' ),
        'id'         => $prefix . 'gallery',
        'type'       => 'file_list',
       
    ) );

   $cmb->add_field(  array(
        'name' => esc_html__('oembed URL for post format video','photofolio'),
        'desc' => esc_html__('Set Intro video, audio','photofolio'),
        'id'   => $prefix . 'intro_video',
        'type'    => 'oembed',
        
    ));

   	 $cmb->add_field( array(
		'name'             => esc_html__( 'Header Style', 'photofolio' ),
		'desc'             => esc_html__( 'Select your header style', 'photofolio' ),
		'id'               => $prefix . 'header_style',
		'type'             => 'select',
		
		'options'          => array(
			'standard' => esc_html__( 'Default', 'photofolio' ),
			'vertical' => esc_html__( 'Vertical', 'photofolio' ),
			'transparent' => esc_html__( 'Transparent', 'photofolio' ),
		),
	) );

   	  $cmb->add_field( array(
		'name'             => esc_html__( 'Single Post Layout', 'photofolio' ),
		'desc'             => esc_html__( 'Select your single layout', 'photofolio' ),
		'id'               => $prefix . 'single_layout',
		'type'             => 'select',
		
		'options'          => array(
			'standard' => esc_html__( 'Default', 'photofolio' ),
			'no-sidebar' => esc_html__( 'No Sidebar', 'photofolio' ),
			
		),
	) );

   	  $cmb = new_cmb2_box( array(
        'id'            => 'portfolio_options',
        'title'         => esc_html__( 'Portfolio Options', 'photofolio' ),
        'object_types'  => array( 'portfolio', ), // Post type
        'context'       => 'normal',
        'priority'      => 'high',
        'show_names'    => true, // Show field names on the left
        
    ) );
   	  $cmb->add_field(  array(
        'name' => esc_html__('Portfolio Subtile','photofolio'),
        'desc' => '',
        'id'   => $prefix . 'subtitle',
        'type'    => 'textarea',
        
    ));
   	   $cmb->add_field(  array(
        'name' => esc_html__('Portfolio Date','photofolio'),
        'desc' => '',
        'id'   => $prefix . 'date',
        'type'    => 'text',
        
    ));
   	  $cmb->add_field( array(
        'name'       => esc_html__( 'Portfolio Gallery', 'photofolio' ),
        'desc'       => esc_html__( 'Upload portfolio images ', 'photofolio' ),
        'id'         => $prefix . 'pgallery',
        'type'       => 'file_list',
       
    ) );

   	 $cmb->add_field( array(
		'name'             => esc_html__( 'Portfolio Single Style', 'photofolio' ),
		'desc'             => esc_html__( 'Select your single style', 'photofolio' ),
		'id'               => $prefix . 'portfolio_style',
		'type'             => 'select',
		
		'options'          => array(
			'standard' => esc_html__( 'Default', 'photofolio' ),
			'right-desc' => esc_html__( 'Right Description', 'photofolio' ),
			'grid-set' => esc_html__( 'Grid Set', 'photofolio' ),
			
		),
	) );
   	 $cmb->add_field( array(
		'name'             => esc_html__( 'Header Style', 'photofolio' ),
		'desc'             => esc_html__( 'Select your header style', 'photofolio' ),
		'id'               => $prefix . 'header_style',
		'type'             => 'select',
		
		'options'          => array(
			'standard' => esc_html__( 'Default', 'photofolio' ),
			'vertical' => esc_html__( 'Vertical', 'photofolio' ),
			'transparent' => esc_html__( 'Transparent', 'photofolio' ),
			
		),
	) );
   	 $cmb->add_field( array(
		'name'             => esc_html__( 'Custom Class', 'photofolio' ),
		'desc'             => esc_html__( 'Select your width in portfolio Carousel element', 'photofolio' ),
		'id'               => $prefix . 'width',
		'type'             => 'select',
		
		'options'          => array(
			'default' => esc_html__( 'Default', 'photofolio' ),
			'snd-width' => esc_html__( 'Second Width', 'photofolio' ),
			
		),
	) );
    $cmb = new_cmb2_box( array(
        'id'            => 'user_edit',
        'title'         => esc_html__( 'User Meta Profile', 'photofolio' ),
        'object_types'  => array( 'user', ), // Post type
        'context'       => 'normal',
        'priority'      => 'high',
        'show_names'    => true, // Show field names on the left
        
    ) );
    $cmb->add_field(
    	array(
				'name'    => esc_html__( 'Avatar', 'photofolio' ),
				'desc'    => esc_html__( 'field description (optional)', 'photofolio' ),
				'id'      => $prefix . 'avatar',
				'type'    => 'file',
				'save_id' => true,
			)
    );
    
 	
}


/**
 * This file represents an example of the code that themes would use to register
 * the required plugins.
 *
 * It is expected that theme authors would copy and paste this code into their
 * functions.php file, and amend to suit.
 *
 * @see http://tgmpluginactivation.com/configuration/ for detailed documentation.
 *
 * @package    TGM-Plugin-Activation
 * @subpackage Example
 * @version    2.6.1 for parent theme photofolio for publication on ThemeForest
 * @author     Thomas Griffin, Gary Jones, Juliette Reinders Folmer
 * @copyright  Copyright (c) 2011, Thomas Griffin
 * @license    http://opensource.org/licenses/gpl-2.0.php GPL v2 or later
 * @link       https://github.com/TGMPA/TGM-Plugin-Activation
 */

require_once get_template_directory() . '/framework/class-tgm-plugin-activation.php';
add_action( 'tgmpa_register', 'photofolio_register_required_plugins' );
/**
 * Register the required plugins for this theme.
 *
 * In this example, we register two plugins - one included with the TGMPA library
 * and one from the .org repo.
 *
 * The variable passed to tgmpa_register_plugins() should be an array of plugin
 * arrays.
 *
 * This function is hooked into tgmpa_init, which is fired within the
 * TGM_Plugin_Activation class constructor.
 */
function photofolio_register_required_plugins() {
    /**
     * Array of plugin arrays. Required keys are name and slug.
     * If the source is NOT from the .org repo, then source is also required.
     */
    $plugins = array(
             // This is an example of how to include a plugin from a private repo in your theme.

		array(            
            'name'               => esc_html__('WPBakery Visual Composer','photofolio'), // The plugin name.
            'slug'               => 'js_composer', // The plugin slug (typically the folder name).
            'source'             => 'http://qkthemes.net/plugins/js_composer.zip', // The plugin source.
            'required'           => true, // If false, the plugin is only 'recommended' instead of required.
        ),
        array(            
            'name'               => esc_html__('Revolution Slider','photofolio'), // The plugin name.
            'slug'               => 'revslider', // The plugin slug (typically the folder name).
            'source'             => 'http://qkthemes.net/plugins/revslider.zip', // The plugin source.
            'required'           => true, // If false, the plugin is only 'recommended' instead of required.
        ),
        array(            
            'name'               => esc_html__( 'QK Import', 'photofolio' ), 
            'slug'               => 'qk-import', 
            'source'             => get_template_directory() . '/framework/plugins/qk-import.zip', 
            'required'           => true, 
        ),array(            
            'name'               => esc_html__( 'QK Register Post Type', 'photofolio' ), 
            'slug'               => 'qk-post_type', 
            'source'             => get_template_directory() . '/framework/plugins/qk-post_type.zip', 
            'required'           => true, 
        ),array(            
            'name'               => esc_html__('WordPress Post Like System','photofolio'), // The plugin name.
            'slug'               => 'WordPress-Post-Like-System', // The plugin slug (typically the folder name).
            'source'             => get_template_directory() . '/framework/plugins/WordPress-Post-Like-System.zip', // The plugin source.
            'required'           => true, // If false, the plugin is only 'recommended' instead of required.
        ),array(            
	            'name'               => 'Menu Item Custom Fields', // The plugin name.
	            'slug'               => 'wp-menu-item-custom-fields', // The plugin slug (typically the folder name).
	            'source'             => get_template_directory() . '/framework/plugins/wp-menu-item-custom-fields.zip', // The plugin source.
	            'required'           => true, // If false, the plugin is only 'recommended' instead of required.
	        ),
        
        // This is an example of how to include a plugin from the WordPress Plugin Repository.
		
        array(
            'name'      => esc_html__( 'Redux Framework', 'photofolio' ),
            'slug'      => 'redux-framework',
            'required'  => true,
        ),array(
            'name'      => esc_html__( 'Redux Developer Mode Disabler', 'photofolio' ),
            'slug'      => 'redux-developer-mode-disabler',
            'required'  => false,
        ),array(
            'name'      => esc_html__( 'CMB2', 'photofolio' ),
            'slug'      => 'cmb2',
            'required'  => true,
        ),array(
            'name'      => esc_html__( 'Contact Form 7', 'photofolio' ),
            'slug'      => 'contact-form-7',
            'required'  => true,
        ),array(
            'name'      => esc_html__( 'Instagram Slider Widget', 'photofolio' ),
            'slug'      => 'instagram-slider-widget',
            'required'  => false,
        ),
		array(
            'name'      => esc_html__('WooCommerce','photofolio'),
            'slug'      => 'woocommerce',
            'required'  => false,
        ),
    );

    /**
     * Array of configuration settings. Amend each line as needed.
     * If you want the default strings to be available under your own theme domain,
     * leave the strings uncommented.
     * Some of the strings are added into a sprintf, so see the comments at the
     * end of each line for what each argument will be.
     */
    $config = array(
        'default_path' => '',                      // Default absolute path to pre-packaged plugins.
        'menu'         => 'tgmpa-install-plugins', // Menu slug.
        'has_notices'  => true,                    // Show admin notices or not.
        'dismissable'  => true,                    // If false, a user cannot dismiss the nag message.
        'dismiss_msg'  => '',                      // If 'dismissable' is false, this message will be output at top of nag.
        'is_automatic' => false,                   // Automatically activate plugins after installation or not.
        'message'      => '',                      // Message to output right before the plugins table.
        'strings'      => array(
            'page_title'                      => esc_html__( 'Install Required Plugins', 'photofolio' ),
            'menu_title'                      => esc_html__( 'Install Plugins', 'photofolio' ),
            'installing'                      => esc_html__( 'Installing Plugin: %s', 'photofolio' ), // %s = plugin name.
            'oops'                            => esc_html__( 'Something went wrong with the plugin API.', 'photofolio' ),
            'notice_can_install_required'     => _n_noop( 'This theme requires the following plugin: %1$s.', 'This theme requires the following plugins: %1$s.', 'photofolio' ), // %1$s = plugin name(s).
            'notice_can_install_recommended'  => _n_noop( 'This theme recommends the following plugin: %1$s.', 'This theme recommends the following plugins: %1$s.', 'photofolio' ), // %1$s = plugin name(s).
            'notice_cannot_install'           => _n_noop( 'Sorry, but you do not have the correct permissions to install the %s plugin. Contact the administrator of this site for help on getting the plugin installed.', 'Sorry, but you do not have the correct permissions to install the %s plugins. Contact the administrator of this site for help on getting the plugins installed.', 'photofolio' ), // %1$s = plugin name(s).
            'notice_can_activate_required'    => _n_noop( 'The following required plugin is currently inactive: %1$s.', 'The following required plugins are currently inactive: %1$s.', 'photofolio' ), // %1$s = plugin name(s).
            'notice_can_activate_recommended' => _n_noop( 'The following recommended plugin is currently inactive: %1$s.', 'The following recommended plugins are currently inactive: %1$s.', 'photofolio' ), // %1$s = plugin name(s).
            'notice_cannot_activate'          => _n_noop( 'Sorry, but you do not have the correct permissions to activate the %s plugin. Contact the administrator of this site for help on getting the plugin activated.', 'Sorry, but you do not have the correct permissions to activate the %s plugins. Contact the administrator of this site for help on getting the plugins activated.', 'photofolio' ), // %1$s = plugin name(s).
            'notice_ask_to_update'            => _n_noop( 'The following plugin needs to be updated to its latest version to ensure maximum compatibility with this theme: %1$s.', 'The following plugins need to be updated to their latest version to ensure maximum compatibility with this theme: %1$s.', 'photofolio' ), // %1$s = plugin name(s).
            'notice_cannot_update'            => _n_noop( 'Sorry, but you do not have the correct permissions to update the %s plugin. Contact the administrator of this site for help on getting the plugin updated.', 'Sorry, but you do not have the correct permissions to update the %s plugins. Contact the administrator of this site for help on getting the plugins updated.', 'photofolio' ), // %1$s = plugin name(s).
            'install_link'                    => _n_noop( 'Begin installing plugin', 'Begin installing plugins', 'photofolio' ),
            'activate_link'                   => _n_noop( 'Begin activating plugin', 'Begin activating plugins', 'photofolio' ),
            'return'                          => esc_html__( 'Return to Required Plugins Installer', 'photofolio' ),
            'plugin_activated'                => esc_html__( 'Plugin activated successfully.', 'photofolio' ),
            'complete'                        => esc_html__( 'All plugins installed and activated successfully. %s', 'photofolio' ), // %s = dashboard link.
            'nag_type'                        => 'updated' // Determines admin notice type - can only be 'updated', 'update-nag' or 'error'.
        )
    );
    tgmpa( $plugins, $config );
}
remove_action( 'woocommerce_before_main_content','woocommerce_breadcrumb', 20, 0);
add_filter('loop_shop_columns', 'loop_columns');
if (!function_exists('loop_columns')) {
	function loop_columns() {
		return 3; // 3 products per row
	}
}
remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_rating', 5 );
?>