<?php
	//remove_theme_mods();

	/**
	 *  We strongly recommend you do not edit this file or any other files
	 *  because at the next update you will lose all your customizations.
	 *
	 *  If you want to customize theme you can use a child theme or a plugin
	 *  extension. For more details about please read the file instructions.txt
	 *
	 *
	 *  @creaded    october 11, 2017
	 *  @updated    october 11, 2017
	 *
	 *  @package 	Gourmand
	 *  @since      Gourmand 0.0.2
	 *  @version    0.0.1
	 */


	//deb::e( date_i18n( 'U' ) );
	//deb::e( get_post( 1447 ) );

	$args = array(
		'post_type'     => 'mc4wp-form',
		'post_name'     => null,
		'post_title'    => 'Gourmand Newsletter Test 2',
		'post_status'   => 'publish',
		'post_author'   => 1,
		'post_content'	=>

			'<div>' . "\n\t" .
			'<input type="email" name="EMAIL" placeholder="Your Email Address" required="">'  . "\n\t" .
			'<input type="submit" value="Sign up Now">' . "\n" .
			'</div>'
	);

	if( empty( $args[ 'post_title' ] ) )
		return 0;

	if( empty( $args[ 'post_name' ] ) )
		$args[ 'post_name' ] = sanitize_title_with_dashes( $args[ 'post_title' ] );


	// Insert the post into the database
	//$form_id = wp_insert_post( $args );

	//$default_form_id = (int) get_option( 'mc4wp_default_form_id', 0 );

	//if( empty( $default_form_id ) ) {
		//update_option( 'mc4wp_default_form_id', $form_id );
	//}

	//$obj = new MC4WP_Forms_Admin();

	// set default form ID
	//$obj -> set_default_form_id( $form_id );

	//date_default_timezone_set( get_option( 'timezone_string' ) );

	include_once get_template_directory() . '/includes/main.php';
	include_once get_template_directory() . '/configs/main.php';
	include_once get_template_directory() . '/settings/main.php';

	/**
	 *	Setup Theme
	 */

	function gourmand_setup_theme()
	{
		global $content_width;

		$gourmand_content_width = apply_filters( 'gourmand_content_width', 1057 );

		if( empty( $content_width ) )
			$content_width = $gourmand_content_width;

		add_theme_support( 'content-width', absint( $content_width ) ) ;
		add_theme_support( 'automatic-feed-links' );
		add_theme_support( 'post-thumbnails' );
		add_theme_support( 'title-tag' );


		/**
         *  Custom Background Image
         */

        $args = apply_filters( 'gourmand_custom_background', (array)gourmand_config::get( 'custom-background' ) );

		if( !empty( $args ) )
        	add_theme_support( 'custom-background', $args );


        /**
         *  Custom Header Image
         */

		$args = apply_filters( 'gourmand_custom_header', (array)gourmand_config::get( 'custom-header' ) );

		if( !empty( $args ) )
        	add_theme_support( 'custom-header', $args );


        /**
         *	Custom Logo
         */

		$args = apply_filters( 'gourmand_custom_logo', (array)gourmand_config::get( 'custom-logo' ) );

		if( !empty( $args ) )
        	add_theme_support( 'custom-logo', $args );


		/**
		 *	Additional Theme Support
		 */

		$cfgs = apply_filters( 'gourmand_additional_support', (array)gourmand_config::get( 'additional-support' ) );

		foreach( $cfgs as $key => $args ){
			if( !empty( $args ) ){
				add_theme_support( $key, $args );
			}

			else{
				add_theme_support( $key );
			}
		}


        /**
         *  Custom Images Sizes
         */

        $cfgs = apply_filters( 'gourmand_images_sizes', (array)gourmand_config::get( 'images-sizes' ) );

        foreach( $cfgs as $id => $size ){

            if( !(isset( $size[ 'width' ] ) && absint( $size[ 'width' ] ) > 0) )
                continue;

            if( !(isset( $size[ 'height' ] ) && absint( $size[ 'height' ] ) > 0) )
                continue;

            $width  = $size[ 'width' ];
            $height = $size[ 'height' ];
            $crop   = isset( $size[ 'crop' ] ) && (bool)$size[ 'crop' ];

            // add custom image size
            add_image_size( esc_attr( $id ), absint( $width ), absint( $height ), (bool)$crop );
        }

        set_post_thumbnail_size( 1057, 595 );


		/**
		 *  Internationalizations and Localization
		 */

		load_theme_textdomain( 'gourmand' , get_template_directory() . '/languages' );
	}

	add_action( 'after_setup_theme', 'gourmand_setup_theme' );


	/**
     *  Register Menus
     */

    function gourmand_register_menus()
    {
        $cfgs = apply_filters( 'gourmand_register_menus', (array)gourmand_config::get( 'menus' ) );

        if( !empty( $cfgs ) )
            register_nav_menus( $cfgs );
    }

    add_action( 'init', 'gourmand_register_menus' );


    /**
     *  Register Sidebars
     */

    function gourmand_register_sidebars()
    {
        $cfgs = apply_filters( 'gourmand_register_sidebars', (array)gourmand_config::get( 'sidebars' ) );

        if( !empty( $cfgs ) ){
            foreach( $cfgs as $sides => $sidebars ){
                foreach( $sidebars as $id => $sidebar ){
                    register_sidebar( $sidebar );
                }
            }
        }
    }

    add_action( 'widgets_init', 'gourmand_register_sidebars' );

	function gourmand_custom_styles()
	{
		gourmand_template::partial( 'templates/head/ie' );
		gourmand_template::partial( 'templates/head/style' );
		gourmand_template::partial( 'templates/head/hyphens' );
	}

	add_action( 'wp_head', 'gourmand_custom_styles' );

	/**
	 *	Enqueue Scripts and Styles
	 */

	add_action( 'admin_enqueue_scripts', array( 'gourmand_scripts', 'backend' ) );
	add_action( 'wp_enqueue_scripts', array( 'gourmand_scripts', 'frontend' ), 0 );
	add_action( 'in_admin_footer', array( 'gourmand_scripts', 'admin_footer' ) );
	add_action( 'wp_footer', array( 'gourmand_scripts', 'footer' ), 0 );
?>
