<?php
$theme_name = "Holiday";
$theme_version = "1.0.3";
global $theme_name;
global $theme_version;


define( 'ACF_LITE' , true);
include_once('includes/advanced-custom-fields/acf.php' );

include 'includes/custom-fields.php';
include 'includes/post-types.php';
include 'includes/social-share.php';
include 'includes/branding.php';
include 'includes/comment.php';
include 'includes/ajax-filters.php';
include 'includes/ajax-booking.php';
include 'includes/ajax_lightbox.php';
include 'includes/backend-booking.php';
include 'includes/shortcodes/shortcodes.php';
require "includes/woocommerce-twitterbootstrap/woocommerce-twitterbootstrap.php";

/* include widgets*/

include 'includes/widgets/instagram-widget.php';
include 'includes/widgets/twitter-widget.php';
include 'includes/widgets/contact-widget.php';
include 'includes/widgets/location-widget.php';
include 'includes/widgets/services-widget.php';
include 'includes/widgets/room_lightbox-widget.php';
include 'includes/widgets/room-widget.php';

/*ACF*/
// Fields
    add_action('acf/register_fields', 'my_register_fields');

    function my_register_fields()
    {
        include_once('includes/add-ons/acf-repeater/repeater.php');
        include_once('includes/add-ons/acf-gallery/gallery.php');
        include_once('includes/add-ons/acf-flexible-content/flexible-content.php');
        include_once('includes/add-ons/advanced-custom-fields-limiter-field/limiter-v4.php');
		
		
	   	
        include_once('includes/registered-fields/presets/acf-presets.php');
        include_once('includes/registered-fields/google-font/acf-googlefonts.php');
        include_once('includes/registered-fields/googlemap/acf-googlemap.php');
		
    }
	
//font awesome picker
	include_once('includes/add-ons/advanced-custom-fields-font-awesome/acf-font-awesome.php');
	

	
// Options Page
    include_once( 'includes/add-ons/acf-options-page/acf-options-page.php' );


add_filter('acf/options_page/settings','register_options_page');

    function register_options_page($options)
    {
       $options['title'] = __('Theme Options','um_lang');
       $options['pages'] = array(
            __('Main','um_lang'),
			__('Header','um_lang'),
			__('Footer','um_lang'),
			__('Branding','um_lang')
        );
       return $options;
    }
   

    add_action( 'acf/input/admin_enqueue_scripts', 'acf_collapse_fields' );
    function acf_collapse_fields(){
        wp_enqueue_script('collapse-fields_js', get_template_directory_uri().'/includes/collapse-fields/acf_collapse.js', array(),'',TRUE);
        wp_enqueue_style('collapse-fields_css',  get_template_directory_uri().'/includes/collapse-fields/acf_collapse.css' , false, "1.0");
    }

/*ACF*/


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


/*Image Sizes*/

	add_image_size('a_box', 405, 315, true);
	add_image_size('a_landscape', 855, 315, true);
	add_image_size('a_landscapeB', 1305, 315, true);
	add_image_size('a_landscapeb1', 1600, 315, true);
	add_image_size('a_portrait', 405, 765, true);
	add_image_size('blogMasonry', 720, 410, true);
	add_image_size('service_icon', 208, 208, true);
	add_image_size('shop_products', 450, 450, true);
	add_image_size('a_box1', 721, 265, true);
	add_image_size('a_landscape1', 348, 265, true);
	add_image_size('a_landscapeB1', 348, 613, true);
	
/*Image Sizes*/


/*Support Language Translation*/
    add_action('after_setup_theme', 'um_theme_setup');
    function um_theme_setup(){
        load_theme_textdomain('um_lang', get_template_directory().'/lang');
    }
/*Support Language Translation*/



/*Add Menu Support*/

    add_action( 'after_setup_theme', 'register_theme_menus' );
    function register_theme_menus() {
    register_nav_menus(
        array(
            	'main_menu' => __( 'Main Menu',"um_lang" ),
        		'wpml_menu' => __('Wpml Menu', "um_lang")
			)
			
    	);
register_nav_menu( 'contact', 'Contact Menu' );
register_nav_menu( 'room', 'Room Menu' );
register_nav_menu( 'footernav', 'Footernav Menu' );
register_nav_menu( 'sitemap', 'Sitemap Menu' );
	}
/*Add Menu Support*/


/*Add Menu Support*/

  
 
	
/*Add Menu Support*/


/*Excerpt more*/


	function custom_excerpt_length( $length ) {
		return 30;
	}
	add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );
	
	function new_excerpt_more($more )
    {
        return '...';
    }
    add_filter('excerpt_more', 'new_excerpt_more');
	
	//Custom Excerpt for blog
	function excerpt($limit){	
     
		 $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 strip_tags($excerpt);
    }
	
/*Excerpt more*/



add_action( 'after_setup_theme', 'um_registerSidebar' );
function um_registerSidebar(){
	
	
	register_sidebar( array(
        'name' => __( 'Home Sidebar', 'um_lang' ),
        'id' => 'sidebar-home',
		'description' => __('Add widgets to the Home sidebar','um_lang'),
        'before_widget' => '<div class="um_masonryItem homeWidgets col-md-4 col-xs-12"><div id="%1$s" class="widget mainBgColor">',
        'after_widget' => "</div></div>",
        'before_title' => '<h4>',
        'after_title' => '</h4>'
	));
	
	
	register_sidebar( array(
        'name' => __( 'Main Sidebar', 'um_lang' ),
        'id' => 'sidebar-main',
		'description' => __('Add widgets to the Footer sidebar','um_lang'),
        'before_widget' => '<div id="%1$s" class="widget mainBgColor">',
        'after_widget' => "</div>",
        'before_title' => '<h4>',
        'after_title' => '</h4>'
	));
	
	register_sidebar( array(
        'name' => __( 'Footer Sidebar', 'um_lang' ),
        'id' => 'sidebar-footer',
		'description' => __('Add widgets to the Main sidebar','um_lang'),
        'before_widget' => '<div class="um_masonryItem col-md-4 col-xs-12"><div id="%1$s" class="widget mainBgColor">',
        'after_widget' => "</div></div>",
        'before_title' => '<h4>',
        'after_title' => '</h4>'
	));
	
	register_post_type( 'homecontent', 
		array(
			'labels' => array(
				'name' => 'HomeContent' ,
				'singular_name' => 'Content',
				'add_new' => 'Add New',
				'add_new_item' => 'Add New Content',
				'edit' => 'Edit Content',
				'edit_item' => 'Edit Content',
			),
			'public' => true,
			'supports' => array( 'excerpt', 'title', 'editor', 'thumbnail', 'comments'),
			'menu_icon' => get_stylesheet_directory_uri() . '/images/media-button.png'
		)
	);
	register_sidebar( array(
        'name' => __('Shop Sidebar' , "um_lang"),
        'id' => 'sidebar-shop',
        'description' => __( 'Add widgets to the Shop sidebar' ,"um_lang" ),
        'before_widget' => '<div id="%1$s" class="widget mainBgColor %2$s">',
         'after_widget' => "</div>",
        'before_title' => '<h4>',
        'after_title' => '</h4>'
    ) );
	
}

	add_theme_support( 'woocommerce' );
	add_theme_support( 'automatic-feed-links' );
  	add_theme_support( 'post-thumbnails' );
  	add_theme_support( 'post-formats', array('image','video','audio'));
	add_post_type_support('post','page-attributes');




/*Add theme css and js*/
    add_action( 'wp_enqueue_scripts', 'add_external_stylesheets' );
    add_action( 'wp_enqueue_scripts', 'add_external_js' );

    function add_external_stylesheets()
    {
    	//style.css
        	wp_enqueue_style("main", get_stylesheet_uri() , false, "1.0");
		//bootstrap
            wp_enqueue_style("bootstrap", get_template_directory_uri().'/assets/bootstrap/css/bootstrap.min.css', false, "1.0");
        //owl-carousel
            wp_enqueue_style("owl-carousel-style", get_template_directory_uri().'/assets/owl-carousel/assets/owl.carousel.css', false, "1.0");
        //royal-slider    
            wp_enqueue_style("royal-slider", get_template_directory_uri().'/assets/royalSlider/royalslider/royalslider.css', false, "1.0");
        //royal-slider-skin
            wp_enqueue_style("royal-slider-skin", get_template_directory_uri().'/assets/royalSlider/royalslider/skins/default/rs-default.css', false, "1.0");
        //raleway-font
            wp_enqueue_style("raleway-font", get_template_directory_uri().'/assets/fonts/Raleway/stylesheet.css', false, "1.0");
        //FontAwesome
            wp_enqueue_style("FontAwesome", get_template_directory_uri().'/assets/fonts/FontAwesome/css/font-awesome.min.css', false, "1.0");
		//umCustomIcons
            wp_enqueue_style("umCustomIcons", get_template_directory_uri().'/assets/fonts/umCustomIcons/style.css', false, "1.0");
		//BootstrapSelect
            wp_enqueue_style("BootstrapSelect", get_template_directory_uri().'/assets/css/bootstrap-select.css', false, "1.0");
		//comments	
            wp_enqueue_style("comments", get_template_directory_uri().'/assets/css/comments.css', false, "1.0");
		//date time picker
			wp_enqueue_style("date-time-picker", get_template_directory_uri().'/assets/css/jquery.datetimepicker.css', false, "1.0");
		//shortcodes	
            wp_enqueue_style("shortcodes", get_template_directory_uri().'/assets/css/shortcodes.css', false, "1.0");
		//animate    
            wp_enqueue_style("animate", get_template_directory_uri().'/assets/css/animate.css', false, "1.0");
		//mCustomScroll    
            wp_enqueue_style("mCustomScrollbar", get_template_directory_uri().'/assets/css/jquery.mCustomScrollbar.css', false, "1.0");
		//widgets    
            wp_enqueue_style("widgets", get_template_directory_uri().'/assets/css/um_widgets.css', false, "1.0");
		
		//global-stylesheet	
            wp_enqueue_style("global-stylesheet", get_template_directory_uri().'/assets/css/global.css', false, "1.0");
		//Main Stylesheet
			wp_enqueue_style("main-stylesheet", get_template_directory_uri().'/assets/css/main_stylesheet.css', false, "1.0");
		 // wooCommerceStyle	
		 	if(is_woocommerce_active()){
				wp_enqueue_style("um_wooStyle", get_template_directory_uri().'/assets/css/woocommerce-twitterboostrap.css', false, "1.0");	
			}
		//logo custom font
        $logo_font = get_field('logo_font','option');
        if($logo_font){
            wp_enqueue_style("logo_font","http://fonts.googleapis.com/css?family=".$logo_font['family']."&subset=latin,cyrillic", false, "1.0");
        }
		//siteFont
		$webFont = get_field('website_font','option');
        if($webFont){
            wp_enqueue_style("website_font","http://fonts.googleapis.com/css?family=".$webFont['family']."&subset=latin,cyrillic", false, "1.0");
        }
        else{
        	wp_enqueue_style("default_font",get_template_directory_uri().'/assets/css/defaultFontStyle.css', false, "1.0");
        }
			
    }

    function add_external_js()
    {
        //jQyery
            wp_enqueue_script('jquery');
        //easing
			wp_enqueue_script("easing", get_template_directory_uri()."/assets/royalSlider/royalslider/jquery.easing-1.3.js" , array(),'',TRUE);   
		// Royal Slider
			wp_enqueue_script("royalSlider", get_template_directory_uri()."/assets/royalSlider/royalslider/jquery.royalslider.min.js" , array(),'',TRUE);   
		// Owl Carousel
			wp_enqueue_script("owlCarousel", get_template_directory_uri()."/assets/owl-carousel/owl.carousel.js" , array(),'',TRUE);   
		//Scrolly (parallax)
			wp_enqueue_script("scrolly", get_template_directory_uri()."/assets/js/jquery.scrolly.js" , array(),'',TRUE);   
		// Smooth Scroll
			wp_enqueue_script("smoothscroll", get_template_directory_uri()."/assets/js/jquery.smoothscroll.js" , array(),'',TRUE);   
		//Bootstrap
			wp_enqueue_script("bootstrap", get_template_directory_uri()."/assets/bootstrap/js/bootstrap.min.js" , array(),'',TRUE);
	 	//BootstrapSelect
			wp_enqueue_script("BootstrapSelectJS", get_template_directory_uri()."/assets/js/bootstrap-select.js" , array(),'',TRUE);   
	 	//isotope
			 wp_enqueue_script("isotopeJS", get_template_directory_uri()."/assets/js/isotope.js" , array(),'',TRUE);   	
			 wp_enqueue_script("imgLoaded", get_template_directory_uri()."/assets/js/imagesloaded.pkgd.min.js" , array(),'',TRUE);  
		//date time picker
			wp_enqueue_script("dateTimePicker", get_template_directory_uri()."/assets/js/jquery.datetimepicker.js" , array(),'',TRUE);   	  	
	 	//mCustomScroll
			wp_enqueue_script("mCustomScroll", get_template_directory_uri()."/assets/js/jquery.mCustomScrollbar.min.js" , array(),'',TRUE);   	  	
	 	//twitter
			wp_enqueue_script("widgetTwitter", get_template_directory_uri()."/assets/js/jquery.twitterfeed.js" , array(),'',TRUE);
	 	//GoogleMap
			wp_enqueue_script("google_map","https://maps.googleapis.com/maps/api/js?sensor=true",'','',TRUE);	
	 	
	 	//themeScripts
			wp_enqueue_script("tabAccTog", get_template_directory_uri()."/assets/js/tabAccTog.js" , array(),'',TRUE); 
			wp_enqueue_script("mainScript", get_template_directory_uri()."/assets/js/main_script.js" , array(),'',TRUE);  
			wp_enqueue_script("roomsScript", get_template_directory_uri()."/assets/js/rooms_script.js" , array(),'',TRUE);   
			wp_enqueue_script("um_booking", get_template_directory_uri()."/assets/js/um_booking.js" , array(),'',TRUE);   
			wp_enqueue_script("um_lightbox", get_template_directory_uri()."/assets/js/um_lightbox.js" , array(),'',TRUE);   
		//Comment Replay
           if ( is_singular() ){
                wp_enqueue_script( 'comment-reply','',array(),'',TRUE );
            }
    }

 
 
 	function um_html5_shiv() {
        ?>
        <!-- IE Fix for HTML5 Tags -->
        <!--[if lt IE 9]>
    	 	<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
      		<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
        <![endif]-->
        <?php
	}
	//add scripts for IE 9
    add_action('wp_head','um_html5_shiv');
	
 //*Add theme css and js*/


/*Add admin css and js*/
    add_action('admin_enqueue_scripts', 'load_custom_admin_js');
    add_action( 'admin_enqueue_scripts', 'load_custom_admin_css' );

    function load_custom_admin_js()
    {
         wp_enqueue_script("um_adminJS", get_template_directory_uri()."/assets/js/admin_js.js" , array(),'',TRUE);
    }
    function load_custom_admin_css()
    {
	//iCONS
         wp_enqueue_style("font-awesome", get_template_directory_uri().'/assets/fonts/FontAwesome/css/font-awesome.min.css' , false, "1.0");
    //admin Styles
        wp_enqueue_style("um_adminStyle", get_template_directory_uri()."/assets/css/admin_style.css" , false, "1.0");
    }
 //*Add admin css and js*/



	/*WooCommerce*/
		remove_action( 'woocommerce_before_main_content', 'woocommerce_output_content_wrapper', 10);
		remove_action( 'woocommerce_after_main_content', 'woocommerce_output_content_wrapper_end', 10);
		remove_action( 'woocommerce_sidebar', 'woocommerce_get_sidebar', 10);
		add_action('woocommerce_before_main_content', 'um_wrapper_start', 10);
		add_action('woocommerce_after_main_content', 'um_wrapper_end', 10);
		add_filter('woocommerce_show_page_title', "um_shop_no_title");
		
	
		
		/*Return Cart Total Items*/
		function um_cart_total(){
			global $woocommerce;
			echo $woocommerce->cart->cart_contents_count;
			die;
		}
		
		add_action('wp_ajax_um_cart_total', 'um_cart_total');
		add_action('wp_ajax_nopriv_um_cart_total', 'um_cart_total');
		/*Return Cart Total Items*/
		
		function um_shop_no_title(){
			return false;
		}
		
		function um_wrapper_start() {
		   	 if(is_product()){
		   	 	global $post;
		   	 	$page_id = $post->ID;
		   	 }	
			else{
			  	 $page_id = woocommerce_get_page_id('shop');
			}
		 
			 $featuredImageType = get_field('background_image_type',$page_id);
			 setBgImg(); 
			 
		   ?> 
		   <main class="content shopPage <?php echo $featuredImageType;  ?>">
	
				<section class="pageImage">
					<?php if($featuredImageType == "bgImg"): ?>	
						<div class="fullBg"></div>
					<?php elseif($featuredImageType == "headerImg"): ?>
						<div class="um_parallax" data-velocity="-.1"></div>
					<?php endif; ?>
				</section>
			
			
			
		        <div class="container">
		            <?php if(!is_product()): ?>
		            	 <section class="pageTitle text-center">
		                    <div class="um_helper">
		                    	<div class="um_middle">
		                    		<h3 class="title pageTitle titleUp"><?php echo get_the_title($page_id); ?></h3>
		                    	</div>
		                    </div>
		                </section>
		   			<?php else:  ?>
		   				    <div class="row">
		            	 <section class="pageTitle text-center">
		                    <div class="um_helper">
		                    	<div class="um_middle">
		                    		<h3 class="title pageTitle titleUp"></h3>
		                    	</div>
		                    </div>
		                </section>
	   				<?php endif; ?>
	   				<?php 
	   					$sidebar_position = get_field('sidebar_position','options'); 
	   					$contanerClass = 'col-md-12';
						$col_md_push = "";  
					
	   				 ?>
		  	
	  			<?php 	
	  			if ( is_active_sidebar( 'sidebar-shop' ) ){
	  				$contanerClass = 'col-md-9';	
					if($sidebar_position == 'left'){
						
							$col_md_push = "col-md-push-3";
						} 
		  		
			  	}	 
			  	?>
		  	
			<div class ="<?php echo $contanerClass.' '.$col_md_push; ?> col-sm-12 col-xs-12">
 				<div class ="shopContent">
		  	 <?php
		}



		function um_wrapper_end() {?>
			
				<?php
					 $col_md_pull = "";
					 $sidebar_position = get_field('sidebar_position','options');  
				?>
	  		
		     			</div>
		     		</div>
		     		 <?php if ( is_active_sidebar( 'sidebar-shop' ) ):?>
		     		 	<?php 
		     		 			if($sidebar_position == 'left'){
									$col_md_pull = "col-md-pull-9";
								}
		     		 	 ?>
						<div class="col-md-3 col-sm-12 col-xs-12 <?php echo $col_md_pull; ?>">
							<aside class="sidebar shopSidebar">
								<?php dynamic_sidebar( 'sidebar-shop' );?>
							</aside>
						</div>
					<?php endif; ?>
				</div>
		    </main>
			<?php
		}
		
/*is WooCommerce active*/
		if(!function_exists('is_woocommerce_active')){
			function is_woocommerce_active(){
				global $woocommerce;
				return $woocommerce instanceof WooCommerce;
			}
		}
/*is WooCommerce active*/
		
	/*WooCommerce*/
 
 
 function pagination($query, $wp_rewrite){
    ?>
	
    <div class="isCentered col-md-12">
        <div class="pagination mainBgColor type2">
            <?php
            $format = $wp_rewrite->using_permalinks() ? "/page/%#%" : '?paged=%#%';
            $big = 999999999; // need an unlikely integer
            echo paginate_links( array(
                'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
                'format' => $format,
                'current' => max( 1, get_query_var('paged') ),
                'total' => $query->max_num_pages,
                'prev_next'    => true,
                'show_all'     => False,
            ) );
            ?>
        </div>
    </div>
<?php
}
/*pagination*/

?>