<?php
/** 
 * Plugin recomendations
 **/

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

add_action( 'tgmpa_register', 'inspiredise_register_required_plugins' );

function inspiredise_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'                  => '_NSPIREDISE Custom Post Types', // The plugin name
            'slug'                  => 'inspiredise-post-types', // The plugin slug (typically the folder name)
            'source'                => get_stylesheet_directory() . '/inc/plugins/inspiredise-post-types.zip', // The plugin source
            'required'              => true, // If false, the plugin is only 'recommended' instead of required
            'version'               => '1.0', // E.g. 1.0.0. If set, the active plugin must be this version or higher, otherwise a notice is presented
            'force_activation'      => false, // If true, plugin is activated upon theme activation and cannot be deactivated until theme switch
            'force_deactivation'    => false, // If true, plugin is deactivated upon theme switch, useful for theme-specific plugins
            'external_url'          => '', // If set, overrides default API URL and points to an external URL
        ),

        array(
            'name'                  => '_NSPIREDISE Multi Image Uploader', // The plugin name
            'slug'                  => 'multi-image-metabox', // The plugin slug (typically the folder name)
            'source'                => get_stylesheet_directory() . '/inc/plugins/multi-image-metabox.zip', // The plugin source
            'required'              => true, // If false, the plugin is only 'recommended' instead of required
            'version'               => '1.3.4', // E.g. 1.0.0. If set, the active plugin must be this version or higher, otherwise a notice is presented
            'force_activation'      => false, // If true, plugin is activated upon theme activation and cannot be deactivated until theme switch
            'force_deactivation'    => false, // If true, plugin is deactivated upon theme switch, useful for theme-specific plugins
            'external_url'          => '', // If set, overrides default API URL and points to an external URL
        ),

        array(
            'name'                  => '_NSPIREDISE Visual Page Builder', // The plugin name
            'slug'                  => 'js_composer', // The plugin slug (typically the folder name)
            'source'                => get_stylesheet_directory() . '/inc/plugins/js_composer.zip', // The plugin source
            'required'              => false, // If false, the plugin is only 'recommended' instead of required
            'version'               => '4.11.2.1', // E.g. 1.0.0. If set, the active plugin must be this version or higher, otherwise a notice is presented
            'force_activation'      => false, // If true, plugin is activated upon theme activation and cannot be deactivated until theme switch
            'force_deactivation'    => false, // If true, plugin is deactivated upon theme switch, useful for theme-specific plugins
            'external_url'          => '', // If set, overrides default API URL and points to an external URL
        ),
        
        array(
            'name'                  => 'Contact Form 7', // The plugin name
            'slug'                  => 'contact-form-7', // The plugin slug (typically the folder name)
            'source'                => get_stylesheet_directory() . '/inc/plugins/contact-form-7.3.7.zip', // The plugin source
            'required'              => false, // If false, the plugin is only 'recommended' instead of required
            'version'               => '3.7', // E.g. 1.0.0. If set, the active plugin must be this version or higher, otherwise a notice is presented
            'force_activation'      => false, // If true, plugin is activated upon theme activation and cannot be deactivated until theme switch
            'force_deactivation'    => false, // If true, plugin is deactivated upon theme switch, useful for theme-specific plugins
            'external_url'          => '', // If set, overrides default API URL and points to an external URL
        ),
        
        array(
            'name'                  => 'Regenerate Thumbnails', // The plugin name
            'slug'                  => 'regenerate-thumbnails', // The plugin slug (typically the folder name)
            'source'                => get_stylesheet_directory() . '/inc/plugins/regenerate-thumbnails.zip', // The plugin source
            'required'              => false, // If false, the plugin is only 'recommended' instead of required
            'version'               => '2.2.4', // E.g. 1.0.0. If set, the active plugin must be this version or higher, otherwise a notice is presented
            'force_activation'      => false, // If true, plugin is activated upon theme activation and cannot be deactivated until theme switch
            'force_deactivation'    => false, // If true, plugin is deactivated upon theme switch, useful for theme-specific plugins
            'external_url'          => '', // If set, overrides default API URL and points to an external URL
        ),
        
        array(
            'name'                  => 'Simple WP Retina', // The plugin name
            'slug'                  => 'simple-wp-retina', // The plugin slug (typically the folder name)
            'source'                => get_stylesheet_directory() . '/inc/plugins/simple-wp-retina.1.1.1.zip', // The plugin source
            'required'              => false, // If false, the plugin is only 'recommended' instead of required
            'version'               => '1.1.1', // E.g. 1.0.0. If set, the active plugin must be this version or higher, otherwise a notice is presented
            'force_activation'      => false, // If true, plugin is activated upon theme activation and cannot be deactivated until theme switch
            'force_deactivation'    => false, // If true, plugin is deactivated upon theme switch, useful for theme-specific plugins
            'external_url'          => '', // If set, overrides default API URL and points to an external URL
        )

    );

    /**
     * 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(
        'domain'            => 'inspiredise',           // Text domain - likely want to be the same as your theme.
        'default_path'      => '',                          // Default absolute path to pre-packaged plugins
        'parent_menu_slug'  => 'themes.php',                // Default parent menu slug
        'parent_url_slug'   => 'themes.php',                // Default parent URL slug
        'menu'              => 'install-required-plugins',  // Menu slug
        'has_notices'       => true,                        // Show admin notices or not
        'is_automatic'      => false,                       // Automatically activate plugins after installation or not
        'message'           => '',                          // Message to output right before the plugins table
        'strings'           => array(
            'page_title'                                => __( 'Install Required Plugins', 'inspiredise' ),
            'menu_title'                                => __( 'Install Plugins', 'inspiredise' ),
            'installing'                                => __( 'Installing Plugin: %s', 'inspiredise' ), // %1$s = plugin name
            'oops'                                      => __( 'Something went wrong with the plugin API.', 'inspiredise' ),
            'notice_can_install_required'               => _n_noop( 'This theme requires the following plugin: %1$s.', 'This theme requires the following plugins: %1$s.' ), // %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.' ), // %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.' ), // %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.' ), // %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.' ), // %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.' ), // %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.' ), // %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.' ), // %1$s = plugin name(s)
            'install_link'                              => _n_noop( 'Begin installing plugin', 'Begin installing plugins' ),
            'activate_link'                             => _n_noop( 'Activate installed plugin', 'Activate installed plugins' ),
            'return'                                    => __( 'Return to Required Plugins Installer', 'inspiredise' ),
            'plugin_activated'                          => __( 'Plugin activated successfully.', 'inspiredise' ),
            'complete'                                  => __( 'All plugins installed and activated successfully. %s', 'inspiredise' ), // %1$s = dashboard link
            'nag_type'                                  => 'updated' // Determines admin notice type - can only be 'updated' or 'error'
        )
    );

    tgmpa( $plugins, $config );

}

register_sidebar(array(
  'name' => __( 'Footer sidebar', 'inspiredise' ),
  'id' => 'footer-sidebar',
  'description' => __( 'Widgets in this area will be shown in the footer.', 'inspiredise' )
));

// Customisation Menu Link
class description_walker extends Walker_Nav_Menu{
      function start_el(&$output, $item, $depth = 0, $args = Array(), $current_object_id = 0 ){
           global $wp_query;
           $indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
           $class_names = $value = '';
           $classes = empty( $item->classes ) ? array() : (array) $item->classes;
           $class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item ) );
          
           $add_class = '';
           
           $post = get_post($item->object_id);
           $page_openinnewwindow = get_post_meta( $post->ID, '_page_openinnewwindow_value', true );
           if($page_openinnewwindow) {
                $add_class = 'blank-link';
           }
          
           $class_names = ' class="'.$add_class.' '. esc_attr( $class_names ) . '"';
           $output .= $indent . '<li id="menu-item-'. $item->ID . '"' . $value . $class_names .'>';
           $attributes  = ! empty( $item->attr_title ) ? ' title="'  . esc_attr( $item->attr_title ) .'"' : '';
           $attributes .= ! empty( $item->target )     ? ' target="' . esc_attr( $item->target     ) .'"' : '';
           $attributes .= ! empty( $item->xfn )        ? ' rel="'    . esc_attr( $item->xfn        ) .'"' : '';

           if($item->object == 'page' && $item->classes[0] !== 'page')
           {
                $varpost = get_post($item->object_id);

                if($page_openinnewwindow) {
                    $attributes .= ! empty( $item->url )        ? ' href="'   . esc_attr( $item->url        ) .'"' : '';
                } else {
                    if(is_front_page()){
                      $attributes .= ' href="#' . $varpost->post_name . '"';
                    }else{
                        if (preg_replace('/^[^:]+:\/\/[^\/]+\/?|^\/|\/$/', '', get_home_url()) == preg_replace('/^\/|\/$/', '', $_SERVER['REQUEST_URI'])) {
                            $attributes .= ' href="#' . $varpost->post_name . '"';
                        } else {
                            $attributes .= ' href="'.home_url().'/#' . $varpost->post_name . '"';
                        }
                    }
                }

                
           }
           else
                $attributes .= ! empty( $item->url )        ? ' href="'   . esc_attr( $item->url        ) .'"' : '';
            if (is_object($args)) {
                $item_output = $args->before;
                $item_output .= '<a'. $attributes .'>';
                $item_output .= $args->link_before . apply_filters( 'the_title', $item->title, $item->ID );
                $item_output .= $args->link_after;
                $item_output .= '</a>';
                $item_output .= $args->after;
                $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
            }
     }
}

/** 
* Favicon, Google Fonts and custom styles
**/
function inspiredise_js_settings() {
    global $theme_options;

    if(isset($theme_options['header_show_slider_navigation']) && $theme_options['header_show_slider_navigation']) {
      $header_show_slider_navigation = 'true';
    } else {
      $header_show_slider_navigation = 'false';
    }

    if(isset($theme_options['header_slider_autoplay']) && $theme_options['header_slider_autoplay']) {
      $header_slider_autoplay = 'true';
    } else {
      $header_slider_autoplay = 'false';
    }

    
    ?>
    <script>
    (function($){
    $(document).ready(function() {
        <?php if(isset($theme_options['disable_slider']) && !$theme_options['disable_slider']): ?>
        /** 
        * FlexSlider
        */
        $('#main-slider').flexslider({
            directionNav: <?php echo $header_show_slider_navigation; ?>,
            controlNav: false,
            slideshow: <?php echo $header_slider_autoplay; ?>,
            slideshowSpeed: <?php echo $theme_options['header_slider_speed']; ?>,
            animation: "<?php echo $theme_options['header_slider_animation']; ?>",
            prevText: "",
            nextText: "", 
        });

        <?php endif; ?>

        <?php if(isset($theme_options['enable_theme_preloader']) && $theme_options['enable_theme_preloader']): ?>
        //Page Preloader
        $(window).load(function() { 
            $("#preloader").delay(500).fadeOut(); 
            $(".mask").delay(1000).fadeOut("slow");
        });
        <?php endif; ?>

        <?php if(isset($theme_options['enable_theme_animations']) && $theme_options['enable_theme_animations']): ?>

        var left_items = $(".left"),
        right_items = $(".right"),
        bottom_items = $(".bottom"),
        left_top_items = 0,
        right_top_items = 0,
        bottom_top_items = 0;

        $(window).load(function () {
            left_top_items = left_items.map(function() { return $(this).position().top; });
            right_top_items = right_items.map(function() { return $(this).position().top; });
            bottom_top_items = bottom_items.map(function() { return $(this).position().top; });
            
            if($(window).scrollTop() < $(window).height())
            {
                var scrollonscreen = $(window).scrollTop() + $(window).height();
                
                $(left_top_items).each(function (i) {
                    if (scrollonscreen > this)
                        $(left_items[i]).css({left: 0});
                });
            
                $(right_top_items).each(function (i) {
                    if (scrollonscreen > this)
                        $(right_items[i]).css({right: 0});
                });
            
                $(bottom_top_items).each(function (i) {
                    if (scrollonscreen > this - 1100)
                        $(bottom_items[i]).css({bottom: 0});
                });
                
            }
        });
            
        $(window).scroll(function () {
                        
            var scrollonscreen = $(window).scrollTop() + $(window).height();
            
            $(left_top_items).each(function (i) {
                if (scrollonscreen > this)
                    $(left_items[i]).css({left: 0});
            });
        
            $(right_top_items).each(function (i) {
                if (scrollonscreen > this)
                    $(right_items[i]).css({right: 0});
            });
        
            $(bottom_top_items).each(function (i) {
                if (scrollonscreen > this - 1100)
                    $(bottom_items[i]).css({bottom: 0});
            });
        
        });
        <?php endif; ?>
        $(window).scroll(function () {
            <?php if(isset($theme_options['enable_parallax']) && $theme_options['enable_parallax']): ?>
            // Parralax
        
            var scaleBg = -$(window).scrollTop() / 4;
            
            var iOS = false,
                device = navigator.platform;
        
            if (device === 'iPad' || device === 'iPhone' || device === 'iPod') {
                iOS = true;
            }
            
            if (iOS === false) {
                $('#main-slider .slides > li').css('background-position-y', scaleBg);
                //$('.content-block').css('background-position-y', scaleBg + $('.content-block').offset().top);
            }
            else
            {
                $('.content-block, #main-slider.flexslider > li').css('background-attachment', 'inherit');
            }
            <?php endif; ?>
            <?php if(isset($theme_options['enable_fixed_menu']) && $theme_options['enable_fixed_menu']): ?>
            // Scrolling menu
            if ($(window).scrollTop() >= $("header").height()) {
                $(".navbar").css({position: "fixed", top: "0px"});
                
            } else {
                $(".navbar").css({position: "relative", top: "-70px"});
                
            }
            <?php endif; ?>

        });

    });
    })(jQuery);
    </script>
    <?php if(isset($theme_options['enable_theme_preloader']) && !$theme_options['enable_theme_preloader']): ?>
        <style>
        .mask {
            display: none;
        }
        </style>
    <?php endif; ?>
    <?php if(isset($theme_options['enable_parallax']) && !$theme_options['enable_parallax']): ?>
        <style>
        .content-block, #main-slider.flexslider li {
            background-attachment: inherit!important;
        }
        </style>
    <?php endif; ?>
    <?php if(isset($theme_options['enable_theme_animations']) && $theme_options['enable_theme_animations']): ?>
        <style>
        .left {
            position: relative;
            left: -3000px;
            -webkit-transition: all .6s;
            transition: all .6s;
        }
        .right {
            position: relative;
            right: -3000px;
            -webkit-transition: all .6s;
            transition: all .6s;
        }
        .bottom {
            position: relative;
            bottom: -1000px;
            -webkit-transition: all 1s;
            transition: all 1s;
        }
        </style>
    <?php endif; ?>
    <?php
   
}
add_action( 'wp_head' , 'inspiredise_js_settings' );

function inspiredise_custom_favicon() {
    global $theme_options;

    if(isset($theme_options['favicon_image']) && $theme_options['favicon_image']['url'] <> '') {
      echo '<link rel="icon" type="image/png" href="'.$theme_options['favicon_image']['url'].'" />';
    }
}
add_action( 'wp_head' , 'inspiredise_custom_favicon' );

function inspiredise_google_fonts() {
    global $theme_options;
    ?>
    <link href='//fonts.googleapis.com/css?family=<?php if(isset($theme_options['header_font'])) { echo $theme_options['header_font']['font-family']; } ?>' rel='stylesheet' type='text/css'>
    <?php if($theme_options['header_font']['font-family'] <> $theme_options['body_font']['font-family']): ?>
    <link href='//fonts.googleapis.com/css?family=<?php echo $theme_options['body_font']['font-family']; ?>' rel='stylesheet' type='text/css'>
    <?php endif; ?>
    <?php
}
add_action( 'wp_head' , 'inspiredise_google_fonts' );


function inspiredise_custom_styles() {
    global $theme_options;
    ?>
    
    <style type="text/css">
    /**
    * Custom CSS
    **/
    <?php if(isset($theme_options['custom_css_code'])) { echo $theme_options['custom_css_code']; } ?>

    /** 
    * Theme Google Font
    **/
    
    h1, h2, h3, h4, h5, h6 {
        font-family: '<?php echo str_replace("+"," ", $theme_options['header_font']['font-family']); ?>';
    }
    h1 {
        font-size: <?php echo $theme_options['header_font']['font-size']; ?>px;
    }
    body {
        font-family: '<?php echo str_replace("+"," ", $theme_options['body_font']['font-family']); ?>';
        font-size: <?php echo $theme_options['body_font']['font-size']; ?>px;
    }
    a,
    .content-block:nth-child(2n) a:hover {
        color: <?php echo $theme_options['theme_main_color']; ?>;
    }
    a.btn,
    .btn,
    .btn:focus, 
    input[type="submit"],
    .navbar .btn-navbar .icon-bar,
    .portfolio-item-block .share i,
    .nav-collapse.collapse {
        background-color: <?php echo $theme_options['theme_main_color']; ?>;
    }
    .portfolio-item-block:hover,
    .portfolio-item-block.open,
    #sidebar .widgettitle,
    .page-header-title,
    .flexslider li .slide-content .slide-button,
    .portfolio-item-block:hover,
    .portfolio-item-block.open,
    .comment-author,
    .sub-menu li a,
    .children li a {
        border-color: <?php echo $theme_options['theme_second_color']; ?>;
    }
    .footer-social a,
    .btn-primary,
    .btn-primary:focus,
    .flexslider li .slide-content .slide-button:hover,
    .navbar .nav > .active > a, 
    .navbar .nav > li > a:hover, 
    .navbar .nav > .active > a:hover, 
    .navbar .nav > .active > a:focus {
        background-color: <?php echo $theme_options['theme_second_color']; ?>;
    }
    .page-header-title a:hover {
        color: <?php echo $theme_options['theme_second_color']; ?>;
    }
    <?php if(isset($theme_options['slider_downarrow_image']) && $theme_options['slider_downarrow_image']['url'] <> ''): ?>
    header .skip-intro, header .skip-intro:hover {
        background-image: url(<?php echo $theme_options['slider_downarrow_image']['url']; ?>);
    }
    <?php endif; ?>
    </style>
    <script>
    <?php if(isset($theme_options['custom_js_code'])) { echo $theme_options['custom_js_code']; } ?>
    </script>
    <?php
}
add_action( 'wp_head' , 'inspiredise_custom_styles' );
