<?php
/**
 * pagebuilderly functions and definitions.
 *
 * @link https://developer.wordpress.org/themes/basics/theme-functions/
 *
 * @package pagebuilderly
 */

if ( ! function_exists( 'pagebuilderly_setup' ) ) :
/**
 * Sets up theme defaults and registers support for various WordPress features.
 *
 * Note that this function is hooked into the after_setup_theme hook, which
 * runs before the init hook. The init hook is too late for some features, such
 * as indicating support for post thumbnails.
 */
function pagebuilderly_setup() {
	/*
	 * Make theme available for translation.
	 * Translations can be filed in the /languages/ directory.
	 * If you're building a theme based on pagebuilderly, use a find and replace
	 * to change 'pagebuilderly' to the name of your theme in all the template files.
	 */
	load_theme_textdomain( 'pagebuilderly', get_template_directory() . '/languages' );

	// Add default posts and comments RSS feed links to head.
	add_theme_support( 'automatic-feed-links' );

	/*
	 * Let WordPress manage the document title.
	 * By adding theme support, we declare that this theme does not use a
	 * hard-coded <title> tag in the document head, and expect WordPress to
	 * provide it for us.
	 */
	add_theme_support( 'title-tag' );

	/*
	 * Enable support for Post Thumbnails on posts and pages.
	 *
	 * @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/
	 */
	add_theme_support( 'post-thumbnails' );
	add_image_size( 'pagebuilderly-full-thumb', 768, 0, true );

	// This theme uses wp_nav_menu() in one location.
	register_nav_menus( array(
		'primary' => esc_html__( 'Primary', 'pagebuilderly' ),
	) );



        /*
         * Add support for starter content
        */
        // Starter Content Begin
        $nav_items = array(
            'home'                 => array(
                'title'      => 'Home',
                'url'    => '#',
            ),
            'custom_blog'           => array(
                'title'      => 'Blog',
                'url'    => '#',
            ),
            'custom_news'      => array(
                'title'      => 'News',
                'url'    => '#',
            ),
            'custom_categories' => array(
                'title'      => 'Categories',
                'url'    => '#',
            ),
            'custom_about'            => array(
                'title'      => 'About',
                'url'    => '#',
            ),
            'custom_contact'            => array(
                'title'      => 'Contact',
                'url'    => '#',
            ),
        );

        $header_widgets = array('custom' => array(
            'custom_html',
            array(
                'title' => '',
                'content' => '<p><img src="'.get_template_directory_uri().'/inc/starter_content/img/1.png" width="80" height="80"/></p> <h3>Lorem Ipsumm</h3> <p style="text-align: center;">Accusantium et doloremque veritatis architecto, eaque ipsa quae ab illo inventore veritatis perspiciatis. Sed ut iste natus voluptatem fringilla tempor dignissim at.</p>'
            )
        ));

        $header_widgets_two = array('custom' => array(
            'custom_html',
            array(
                'title' => '',
                'content' => '<p><img src="'.get_template_directory_uri().'/inc/starter_content/img/2.png" width="80" height="80"/></p> <h3>Lorem Ipsumm</h3> <p style="text-align: center;">Accusantium et doloremque veritatis architecto, eaque ipsa quae ab illo inventore veritatis perspiciatis. Sed ut iste natus voluptatem fringilla tempor dignissim at.</p>'
            )
        ));

        $header_widgets_three = array('custom' => array(
            'custom_html',
            array(
                'title' => '',
                'content' => '<p><img src="'.get_template_directory_uri().'/inc/starter_content/img/3.png" width="80" height="80"/></p> <h3>Lorem Ipsumm</h3> <p style="text-align: center;">Accusantium et doloremque veritatis architecto, eaque ipsa quae ab illo inventore veritatis perspiciatis. Sed ut iste natus voluptatem fringilla tempor dignissim at.</p>'
            )
        ));
        
        $footer_widgets = array('custom' => array(
            'custom_html',
            array(
                'title' => 'LOREM IPSUM',
                'content' => '<p>Sed ut perspiciatis unde omnis iste natus voluptatem fringilla tempor dignissim at, pretium et arcu. Sed ut perspiciatis unde omnis iste tempor dignissim at, pretium et arcu natus voluptatem fringilla.</p>'
            )
        ));

        $starter_content = array(
            'attachments' => array(
                'featured-image-nothing-breaks-new-york' => array(
                    'post_title'   => 'Featured Image 1',
                    'post_content' => 'Attachment Description',
                    'post_excerpt' => 'Attachment Caption',
                    'file'         => 'inc/starter_content/img/nothing-breaks-new-york.png',
                ),
                'featured-image-getting-what-you-want' => array(
                    'post_title'   => 'Featured Image 2',
                    'post_content' => 'Attachment Description',
                    'post_excerpt' => 'Attachment Caption',
                    'file'         => 'inc/starter_content/img/getting-what-you-want.png',
                ),
                'featured-image-are-you-sabotaging-your-creativity' => array(
                    'post_title'   => 'Featured Image 3',
                    'post_content' => 'Attachment Description',
                    'post_excerpt' => 'Attachment Caption',
                    'file'         => 'inc/starter_content/img/are-you-sabotaging-your-creativity.png',
                ),
                'featured-image-what-ive-learned-from-road-trips' => array(
                    'post_title'   => 'Featured Image 4',
                    'post_content' => 'Attachment Description',
                    'post_excerpt' => 'Attachment Caption',
                    'file'         => 'inc/starter_content/img/what-ive-learned-from-road-trips.png',
                ),
                'featured-image-how-to-write-10000-words-a-week' => array(
                    'post_title'   => 'Featured Image 5',
                    'post_content' => 'Attachment Description',
                    'post_excerpt' => 'Attachment Caption',
                    'file'         => 'inc/starter_content/img/how-to-write-10000-words-a-week.png',
                ),
            ),
            'posts' => array(
                'custom_post_1' => require dirname(__FILE__) . "/inc/starter_content/posts/nothing_beats_new_york.php",
                'custom_post_2' => require dirname(__FILE__) . "/inc/starter_content/posts/getting_what_you_want.php",
                'custom_post_3' => require dirname(__FILE__). "/inc/starter_content/posts/are_you_sabotaging_your_creativity.php",
                'custom_post_4' => require dirname(__FILE__). "/inc/starter_content/posts/how-to-write-10000-words-a-week.php",
                'custom_post_5' => require dirname(__FILE__). "/inc/starter_content/posts/what_ive_learned_from_road_trips.php",
            ),
            'nav_menus' => array(
                'primary' => array(
                    'name' => 'Primary',
                    'items' => $nav_items,
                ),
            ),
            'widgets' => array(
                'top_widget_left' => $header_widgets,
                'top_widget_middle' => $header_widgets_two,
                'top_widget_right' => $header_widgets_three,
                'footer_widget_left' => $footer_widgets,
                'footer_widget_middle' => $footer_widgets,
                'footer_widget_right' => $footer_widgets,
                'header_widget_right' => array(
                    'custom_portrait' => array(
                        'custom_html',
                        array(
                            'content' => '<img src="'.get_template_directory_uri().'/inc/starter_content/img/profile.jpg"/>'
                        )
                    ),
                ),
                'sidebar-1' => array(
                    'custom_portrait' => array(
                        'custom_html',
                        array(
                            'content' => '<div style="text-align:center;">
                            <img src="'.get_template_directory_uri().'/inc/starter_content/img/portrait.png">
                            <p style="text-align:center;margin-bottom:0;">
                            Aliquam et elit eu nunc rhoncus viverra quis at felis et netus et malesuada fames ac turpis egestas. Aenean commodo ligula eget dolor.
                            </p>'
                        )
                    ),
                    'custom_banner' => array(
                        'custom_html',
                        array(
                            'content' => '<img src="'.get_template_directory_uri().'/inc/starter_content/img/banner.png"/>'
                        )
                    ),
                ),
            ),
            'theme_mods' => array(
                'pagebuilderly_facebook' => "#",
                'pagebuilderly_twitter' => "#",
                'pagebuilderly_instagram' => "#",
                'pagebuilderly_youtube' => "#",
            )
        );

add_theme_support('starter-content', $starter_content);
        // Starter Content End


	/*
	 * Switch 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',
	) );

	// Set up the WordPress core custom background feature.
	add_theme_support( 'custom-background', apply_filters( 'pagebuilderly_custom_background_args', array(
		'default-color' => 'ffffff',
		'default-image' => '',
	) ) );

}
endif;
add_action( 'after_setup_theme', 'pagebuilderly_setup' );

/**
 * Set the content width in pixels, based on the theme's design and stylesheet.
 *
 * Priority 0 to make it available to lower priority callbacks.
 *
 * @global int $content_width
 */
function pagebuilderly_content_width() {
	$GLOBALS['content_width'] = apply_filters( 'pagebuilderly_content_width', 640 );
}
add_action( 'after_setup_theme', 'pagebuilderly_content_width', 0 );

/**
 *
 * Add Custom editor styles
 *
 */
function pagebuilderly_add_editor_styles() {
    add_editor_style( 'css/custom-editor-style.css' );
}
add_action( 'admin_init', 'pagebuilderly_add_editor_styles' );



/**
 *
 * Load Google Fonts
 *
 */
function pagebuilderly_google_fonts_url(){

    $fonts_url  = '';
    $Lato = _x( 'on', 'Lato font: on or off', 'pagebuilderly' );
    $Montserrat      = _x( 'on', 'Montserrat font: on or off', 'pagebuilderly' );

    if ( 'off' !== $Lato || 'off' !== $Montserrat ){

        $font_families = array();

        if ( 'off' !== $Lato ) {

            $font_families[] = 'Lato:300,400,400i,700';

        }

        if ( 'off' !== $Montserrat ) {

            $font_families[] = 'Montserrat:400,400i,500,600,700';

        }
        

        $query_args = array(

            'family' => urlencode( implode( '|', $font_families ) ),
            'subset' => urlencode( 'latin,latin-ext' ),
        );

        $fonts_url = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );

    }

    return esc_url_raw( $fonts_url );
}

function pagebuilderly_enqueue_googlefonts() {

    wp_enqueue_style( 'pagebuilderly-googlefonts', pagebuilderly_google_fonts_url(), array(), null );
}

add_action( 'wp_enqueue_scripts', 'pagebuilderly_enqueue_googlefonts' );



/**
 * Fix editor font after WP 7.0.
 */
function pagebuilderly_editor_font_fix() {
    wp_add_inline_style(
        'pagebuilderly-googlefonts',
        '
        body,
        .editor-styles-wrapper {
            font-family: "Lato", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
        }

        .editor-styles-wrapper h1,
        .editor-styles-wrapper h2,
        .editor-styles-wrapper h3,
        .editor-styles-wrapper h4,
        .editor-styles-wrapper h5,
        .editor-styles-wrapper h6 {
            font-family: "Montserrat", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
        }
        '
    );
}
add_action( 'enqueue_block_assets', 'pagebuilderly_enqueue_googlefonts' );
add_action( 'enqueue_block_assets', 'pagebuilderly_editor_font_fix', 20 );


/**
 * Register widget area.
 *
 * @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
 */
function pagebuilderly_widgets_init() {

	register_sidebar( array(
		'name' => esc_html__('Header Widget (Right)', 'pagebuilderly'),
		'id' => 'header_widget_right',
		'before_widget' => '<div class="header-widgets">',
		'description'   => esc_html__( 'Widgets here will appear inside the header image, to the right', 'pagebuilderly' ),
		'after_widget' => '</div>',
		'before_title' => '<h3>',
		'after_title' => '</h3>',
  ) );

	register_sidebar( array(
		'name' => esc_html__('Top Widgets: Full Width', 'pagebuilderly'),
		'id' => 'top_widget_fullwidth',
		'before_widget' => '<div class="top-widgets">',
		'description'   => esc_html__( 'Widgets here will appear under the header image', 'pagebuilderly' ),
		'after_widget' => '</div>',
		'before_title' => '<h3>',
		'after_title' => '</h3>',
  ) );


	register_sidebar( array(
		'name' => esc_html__('Top Widgets: left', 'pagebuilderly'),
		'id' => 'top_widget_left',
		'before_widget' => '<div class="top-widgets">',
		'description'   => esc_html__( 'Widgets here will appear under the header image', 'pagebuilderly' ),
		'after_widget' => '</div>',
		'before_title' => '<h3>',
		'after_title' => '</h3>',
  ) );

  register_sidebar( array(
      'name' => esc_html__('Top Widgets: middle', 'pagebuilderly'),
      'id' => 'top_widget_middle',
      'description'   => esc_html__( 'Widgets here will appear under the header image', 'pagebuilderly' ),
      'before_widget' => '<div class="top-widgets">',
      'after_widget' => '</div>',
      'before_title' => '<h3>',
      'after_title' => '</h3>',
  ) );

  register_sidebar( array(
      'name' => esc_html__('Top Widgets: right', 'pagebuilderly'),
      'id' => 'top_widget_right',
      'before_widget' => '<div class="top-widgets">',
      'after_widget' => '</div>',
      'description'   => esc_html__( 'Widgets here will appear under the header image', 'pagebuilderly' ),
      'before_title' => '<h3>',
      'after_title' => '</h3>',
  ) );


  register_sidebar( array(
      'name' => esc_html__('Footer Widget One', 'pagebuilderly'),
      'id' => 'footer_widget_left',
      'before_widget' => '<div class="footer-widgets">',
      'description'   => esc_html__( 'Widgets here will appear in the footer', 'pagebuilderly' ),
      'after_widget' => '</div>',
      'before_title' => '<h3>',
      'after_title' => '</h3>',
  ) );

  register_sidebar( array(
      'name' => esc_html__('Footer Widget Two', 'pagebuilderly'),
      'id' => 'footer_widget_middle',
      'description'   => esc_html__( 'Widgets here will appear in the footer', 'pagebuilderly' ),
      'before_widget' => '<div class="footer-widgets">',
      'after_widget' => '</div>',
      'before_title' => '<h3>',
      'after_title' => '</h3>',
  ) );

  register_sidebar( array(
      'name' => esc_html__('Footer Widget Three', 'pagebuilderly'),
      'id' => 'footer_widget_right',
      'before_widget' => '<div class="footer-widgets">',
      'after_widget' => '</div>',
      'description'   => esc_html__( 'Widgets here will appear in the footer', 'pagebuilderly' ),
      'before_title' => '<h3>',
      'after_title' => '</h3>',
  ) );


}
add_action( 'widgets_init', 'pagebuilderly_widgets_init' );

/**
 * Filter the except length to 20 words.
 *
 * @param int $length Excerpt length.
 * @return int (Maybe) modified excerpt length.
 */
function pagebuilderly_custom_excerpt_length( $length ) {
    return 35;
}
add_filter( 'excerpt_length', 'pagebuilderly_custom_excerpt_length', 999 );


/**
 * Enqueue scripts and styles.
 */
function pagebuilderly_scripts() {
	wp_enqueue_style( 'pagebuilderly-style', get_stylesheet_uri() );
	wp_enqueue_style( 'pagebuilderly-font-awesome-css', get_template_directory_uri() . '/css/font-awesome.min.css');
	wp_enqueue_script( 'pagebuilderly-navigation', get_template_directory_uri() . '/js/navigation.js', array(), '20151215', true );
	wp_enqueue_script( 'pagebuilderly-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), '20151215', true );
	wp_enqueue_script( 'pagebuilderly-script', get_template_directory_uri() . '/js/pagebuilderly.js', array('jquery'), false, true);

	if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
		wp_enqueue_script( 'comment-reply' );
	}
}
add_action( 'wp_enqueue_scripts', 'pagebuilderly_scripts' );

/**
 * Custom template tags for this theme.
 */
require get_template_directory() . '/inc/template-tags.php';

/**
 * Custom functions that act independently of the theme templates.
 */
require get_template_directory() . '/inc/extras.php';

/**
 * Customizer additions.
 */
require get_template_directory() . '/inc/customizer.php';

/**
 * Load Jetpack compatibility file.
 */
require get_template_directory() . '/inc/jetpack.php';


/**
 * Implement the Custom Header feature.
 */
require get_template_directory() . '/inc/custom-header.php';


/*TGA activation*/

require_once get_template_directory() . '/lib/class-tgm-plugin-activation.php';

/**
 * 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 Free Seo Optimized Responsive Theme for publication on WordPress.org
 * @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
 */

/**
 * Include the TGM_Plugin_Activation class.
 *
 * Depending on your implementation, you may want to change the include call:
 *
 * Parent Theme:
 * require_once get_template_directory() . '/path/to/class-tgm-plugin-activation.php';
 *
 * Child Theme:
 * require_once get_stylesheet_directory() . '/path/to/class-tgm-plugin-activation.php';
 *
 * Plugin:
 * require_once dirname( __FILE__ ) . '/path/to/class-tgm-plugin-activation.php';
 */
require_once get_template_directory() . '/inc/tgm/class-tgm-plugin-activation.php';

add_action( 'tgmpa_register', 'pagebuilderly_register_required_plugins' );

function pagebuilderly_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(
        array(
            'name'        => 'Superb Addons',
            'slug'        => 'superb-blocks',
        ),

    );

	$config = array(
		'id'           => 'pagebuilderly',                 // Unique ID for hashing notices for multiple instances of TGMPA.
		'default_path' => '',                      // Default absolute path to bundled 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' => true,                   // Automatically activate plugins after installation or not.
		'message'      => '',                      // Message to output right before the plugins table.


  );

	tgmpa( $plugins, $config );
}




/**
 * Copyright and License for Upsell button by Justin Tadlock - 2016 © Justin Tadlock. customizer button https://github.com/justintadlock/trt-customizer-pro
 */
require_once( trailingslashit( get_template_directory() ) . 'justinadlock-customizer-button/class-customize.php' );











// Initialize information content
require_once trailingslashit(get_template_directory()) . 'inc/vendor/autoload.php';

use SuperbThemesThemeInformationContent\ThemeEntryPoint;

ThemeEntryPoint::init([
    'type' => 'classic', // block / classic
    'theme_url' => 'https://superbthemes.com/pagebuilderly/',
    'demo_url' => 'https://superbthemes.com/demo/pagebuilderly/',
    'features' => array(
        array('title'=>'Customize All Fonts'),
        array('title'=>'Customize All Colors'),
        array('title'=>'Only Show Header On Front Page'),
        array('title'=>'Customize Header Buttons'),
        array('title'=>'Add Up To 14 Navigation Social Media Icons'),
        array('title'=>'Custom Header Text'),
        array('title'=>'Add Recent Posts Widget'),
        array('title'=>'Customize header Height'),
        array('title'=>'Custom Copyright Text'),
        array('title'=>'Remove "Tag" from tag page title'),
        array('title'=>'Remove "Author" from author page title'),
        array('title'=>'Remove "Category" from author page title'),
        array('title'=>'Only Show Top Widgets On Front Page')
    )
]);
