<?php
global $startos_option;
if ( ! class_exists( 'ReduxFramewrk' ) ) {
    require_once( get_template_directory() . '/framework/sample-config.php' );
	function removeDemoModeLink() { // Be sure to rename this function to something more unique
		if ( class_exists('ReduxFrameworkPlugin') ) {
			remove_filter( 'plugin_row_meta', array( ReduxFrameworkPlugin::get_instance(), 'plugin_metalinks'), null, 2 );
		}
		if ( class_exists('ReduxFrameworkPlugin') ) {
			remove_action('admin_notices', array( ReduxFrameworkPlugin::get_instance(), 'admin_notices' ) );    
		}
	}
	add_action('init', 'removeDemoModeLink');
}

//Custom fields:
require_once get_template_directory() . '/framework/bfi_thumb-master/BFI_Thumb.php';
require_once get_template_directory() . '/framework/meta-boxes.php';
require_once get_template_directory() . '/framework/widget/recentpost.php';
require_once get_template_directory() . '/shortcodes.php';
require_once get_template_directory() . '/framework/wp_bootstrap_navwalker.php';

//Theme Set up:
function startos_theme_setup() {

    if ( ! isset( $content_width ) ) {
      $content_width = 900;
    }

    /*
     * This theme uses a custom image size for featured images, displayed on
     * "standard" posts and pages.
     */
  	load_theme_textdomain( 'startos', get_template_directory() . '/languages' );
  	
  	add_theme_support( 'custom-header' ); 

  	add_theme_support( 'custom-background' );

    add_theme_support( 'post-thumbnails' );
    // Adds RSS feed links to <head> for posts and comments.
    add_theme_support( 'automatic-feed-links' );
    // 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' ) );
    //Post formats
    add_theme_support( 'post-formats', array(
        'audio',  'gallery', 'image', 'video',
    ) );
	
	  //Tags
	  add_theme_support( 'title-tag' );

    // This theme uses wp_nav_menu() in one location.

  	register_nav_menus( array(    
      'primary'   => __('Main Menu', 'startos'),    
  	) );

}

add_action( 'after_setup_theme', 'startos_theme_setup' );


function startos_load_custom_wp_admin_style() {
        wp_register_style( 'custom_wp_admin_css', get_template_directory_uri() . '/framework/startos-admin.css', false, '1.0.0' );
        wp_enqueue_style( 'custom_wp_admin_css' );
}
add_action( 'admin_enqueue_scripts', 'startos_load_custom_wp_admin_style' );

function startos_fonts_url() {
    $fonts_url = '';
 
    /* Translators: If there are characters in your language that are not
    * supported by Open Sans, translate this to 'off'. Do not translate
    * into your own language.
    */
    $open_sans = _x( 'on', 'Open Sans font: on or off', 'startos' );
 
    if ( 'off' !== $open_sans ) {
        $font_families = array();
 
        if ( 'off' !== $open_sans ) {
            $font_families[] = 'Open Sans:400,600,700,800,300';
        }
 
        $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 startos_theme_scripts_styles() {

	global $startos_option;

	$protocol = is_ssl() ? 'https' : 'http';	

	// Add custom fonts, used in the main stylesheet.
	wp_enqueue_style( 'startos-fonts', startos_fonts_url(), array(), null );
	wp_enqueue_style( 'startos-awesome', get_template_directory_uri().'/font-awesome/css/font-awesome.min.css');
	wp_enqueue_style( 'startos-owl-car', get_template_directory_uri().'/css/owl.carousel.css');
	wp_enqueue_style( 'startos-animate', get_template_directory_uri().'/css/animate.css');
	wp_enqueue_style( 'startos-owl-theme', get_template_directory_uri().'/css/owl.theme.css');
	wp_enqueue_style( 'startos-style', get_stylesheet_uri(), array(), '15-09-2015' );
	wp_enqueue_style( 'startos-nivo-lightbox', get_template_directory_uri().'/css/nivo-lightbox.css');
	wp_enqueue_style( 'startos-demo-css', get_template_directory_uri().'/css/demo.css');

	//theme option for color
	wp_enqueue_style( 'startos-color', get_template_directory_uri() .'/framework/color.php');

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

	wp_enqueue_script("startos-maps-js", "$protocol://maps.googleapis.com/maps/api/js?key=AIzaSyDm7mKzTHlw2f0FuWW-YFG1DrvnsJDivLM",array(),false,false);
	wp_enqueue_script("startos-modernizer", get_template_directory_uri()."/js/modernizer.js",array(),false,true);
	wp_enqueue_script("startos-fitvids-js", get_template_directory_uri()."/js/jquery.fitvids.js",array(),false,true);
	
	wp_enqueue_script("startos-wow-js", get_template_directory_uri()."/js/wow.min.js",array(),false,true);
	
	wp_enqueue_script("startos-retina-js", get_template_directory_uri()."/js/retina-1.1.0.min.js",array(),false,true);
	wp_enqueue_script("startos-imagesloaded-pkgd", get_template_directory_uri()."/js/imagesloaded.pkgd.min.js",array(),false,true);
	wp_enqueue_script("startos-smoothscroll", get_template_directory_uri()."/js/smoothscroll.js",array(),false,true);
	wp_enqueue_script("startos-easing-js", get_template_directory_uri()."/js/jquery.easing.min.js",array(),false,true);
	wp_enqueue_script("startos-mobile-events", get_template_directory_uri()."/js/jquery.mobile-events.min.js",array(),false,true);
	wp_enqueue_script("startos-owl-carousel", get_template_directory_uri()."/js/owl.carousel.min.js",array(),false,false);
	wp_enqueue_script("startos-slider-js", get_template_directory_uri()."/js/jquery.slider.js",array(),false,true);
	wp_enqueue_script("startos-inview-js", get_template_directory_uri()."/js/jquery.inview.min.js",array(),false,true);
	wp_enqueue_script("startos-malihu-js", get_template_directory_uri()."/js/jquery.malihu.PageScroll2id.js",array(),false,true);
	wp_enqueue_script("startos-nivo-lightbox", get_template_directory_uri()."/js/nivo-lightbox.min.js",array(),false,true);
	wp_enqueue_script("startos-controller", get_template_directory_uri()."/js/controller.js",array(),false,true);		

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



if(!function_exists('startos_custom_frontend_style')){
	function startos_custom_frontend_style(){
		global $startos_option;
		echo '<style type="text/css">'.$startos_option['custom-css'].'</style>';
	}
}

add_action('wp_head', 'startos_custom_frontend_style');


// Widget Sidebar
function startos_widgets_init() {
	register_sidebar( array(

        'name'          => __( 'Primary Sidebar', 'startos' ),

        'id'            => 'sidebar-1',        

		'description'   => __( 'Appears in the sidebar section of the site.', 'startos' ),        

		'before_widget' => '<div id="%1$s" class="widget %2$s">',        

		'after_widget'  => '</div>',        

		'before_title'  => '<h2>',        

		'after_title'   => '</h2>'

    ) );

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


function startos_excerpt() {
  global $startos_option;
  if(isset($startos_option['blog_excerpt'])){
    $limit = $startos_option['blog_excerpt'];
  }else{
    $limit = 15;
  }
  $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;
}

//pagination
function startos_pagination($prev = '<i class="fa fa-angle-double-left"></i>', $next = '<i class="fa fa-angle-double-right"></i>', $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;
        }
    }

    $pagination = array(
		'base' 			=> str_replace( 999999999, '%#%', get_pagenum_link( 999999999 ) ),
		'format' 		=> '',
		'current' 		=> max( 1, get_query_var('paged') ),
		'total' 		=> $pages,
		'prev_text' => $prev,
		'next_text' => $next,		
		'type'			=> 'list',
		'end_size'		=> 3,
		'mid_size'		=> 3
);
    $return =  paginate_links( $pagination );
	echo str_replace( "<ul class='page-numbers'>", '', $return );
}



function startos_search_form( $form ) {
    $form = '<form role="search" method="get" id="searchform" class="search-form" action="' . home_url( '/' ) . '" >  
    	<input type="text" value="' . get_search_query() . '" name="s" id="s" placeholder="' . __('type to search and hit enter','startos') . '" />
    </form>';
    return $form;
}
add_filter( 'get_search_form', 'startos_search_form' );

// Comment Form
function startos_theme_comment($comment, $args, $depth) {
   $GLOBALS['comment'] = $comment; ?>
   <li>

   		<div class="avatar">

		<?php echo get_avatar($comment,$size='70',$default='http://0.gravatar.com/avatar/ad516503a11cd5ca435acc9bb6523536?s=70' ); ?>

		</div>

		<div class="comment-info">

			<span class="c_name"><?php printf(__('%s','startos'), get_comment_author()) ?></span>
          <div class="date-reply">
            <span class="c_date"><?php the_time('dS M Y'); ?></span>

            <span class="c_reply"><?php comment_reply_link(array_merge( $args, array('depth' => $depth, 'max_depth' => $args['max_depth']))) ?></span>
          </div> 
      <div class="comment">

      <?php if ($comment->comment_approved == '0'){ ?>

         <p><em><?php _e('Your comment is awaiting moderation.','startos') ?></em></p>

      <?php }else{ ?>

      

          <?php comment_text() ?>

      <?php } ?>

      </div>     
		</div>

	 <div class="clearfix"></div>	

	</li> 

<?php

}



//Code Visual Compurso.
require_once get_template_directory() . '/vc_shortcode.php';
//if(class_exists('WPBakeryVisualComposerSetup')){
function startos_custom_css_classes_for_vc_row_and_vc_column($class_string, $tag) {
    if($tag=='vc_row' || $tag=='vc_row_inner') {
        $class_string = str_replace('vc_row-fluid', '', $class_string);
    }
    if($tag=='vc_column' || $tag=='vc_column_inner') {

        $class_string = preg_replace('/vc_col-xs-(\d{1,2})/', 'col$1', $class_string);

        $class_string = preg_replace('/vc_col-sm-(\d{1,2})/', 'col$1', $class_string);

        $class_string = preg_replace('/vc_col-md-(\d{1,2})/', 'col$1', $class_string);

        $class_string = preg_replace('/vc_col-lg-(\d{1,2})/', 'col$1', $class_string);

    }

    return $class_string;

}

// Filter to Replace default css class for vc_row shortcode and vc_column

add_filter('vc_shortcodes_css_class', 'startos_custom_css_classes_for_vc_row_and_vc_column', 10, 2); 

// Add new Param in Row
if(function_exists('vc_add_param')){
vc_add_param('vc_row',array(

                              "type" => "dropdown",

                              "heading" => __('Fullwidth', 'wpb'),

                              "param_name" => "fullwidth",

                              "value" => array(   

                                                __('No', 'wpb') => 'no',  

                                                __('Yes', 'wpb') => 'yes',                                                                                

                                              ),

                              "description" => __("Select Fullwidth or not, Default: No fullwidth", "wpb"),      

                            ) 

    );

	

// Add new Param in Column	
vc_add_param('vc_column',array(

                              "type" => "dropdown",

                              "heading" => __('Animate', 'wpb'),

                              "param_name" => "animate",

                              "value" => array(   

                                                __('None', 'wpb') => 'none', 

                                                __('Fade In Up', 'wpb') => 'fadeinup', 

                                                __('Fade In Down', 'wpb') => 'fadeindown', 

                                                __('Fade In', 'wpb') => 'fadein', 

                                                __('Fade In Left', 'wpb') => 'fadeinleft',  

                                                __('Fade In Right', 'wpb') => 'fadeinright',



                                              ),

                              "description" => __("Select Animate , Default: None", "wpb"),      

                            ) 

    );


	

vc_remove_param( "vc_row", "parallax" );
vc_remove_param( "vc_row", "parallax_image" );
vc_remove_param( "vc_row", "full_width" );
vc_remove_param( "vc_row", "full_height" );
vc_remove_param( "vc_row", "video_bg" );
vc_remove_param( "vc_row", "video_bg_parallax" );
vc_remove_param( "vc_row", "content_placement" );
vc_remove_param( "vc_row", "video_bg_url" );
}

//}

require_once get_template_directory() . '/framework/class-tgm-plugin-activation.php';
add_action( 'tgmpa_register', 'startos_theme_register_required_plugins' );
function startos_theme_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(        
        // Plugin Download the http://wordpress.org
        array(
            'name'               => 'Meta Box',
            'slug'               => 'meta-box',
            'required'           => true,
            'force_activation'   => false,
            'force_deactivation' => false,
        ),
		array(
            'name'      => 'Redux Framework',
            'slug'      => 'redux-framework',
            'required'           => true,
			'force_activation'   => false,
            'force_deactivation' => false,
        ),		

        // This is an example of how to include a plugin from a private repo in your theme.
        array(            
            'name'               => 'WPBakery Visual Composer', // The plugin name.
            'slug'               => 'js_composer', // The plugin slug (typically the folder name).
            'source'             => get_template_directory_uri() . '/framework/plugins/js_composer.zip', // The plugin source.
            'required'           => true, // If false, the plugin is only 'recommended' instead of required.
        ),
        array(
            'name'               => 'Revolution Slider', // The plugin name.
            'slug'               => 'revslider', // The plugin slug (typically the folder name).            
            'source'             => get_template_directory_uri() . '/framework/plugins/revslider.zip', // The plugin source.            
            'required'           => false, // 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'      => 'Contact Form 7',
            'slug'      => 'contact-form-7',
            'required'  => false,
        ),
		array(
            'name'      => 'Newsletter',
            'slug'      => 'newsletter',
            'required'  => false,
        ),		
        array(            
            'name'               => 'OT Testimonial', // The plugin name.
            'slug'               => 'ot_testimonial', // The plugin slug (typically the folder name).
            'source'             => get_template_directory_uri() . '/framework/plugins/ot_testimonial.zip', // The plugin source.
            'required'           => false, // If false, the plugin is only 'recommended' instead of required.
        ),
		array(            
            'name'               => 'OT One Click Import Demo Content', // The plugin name.
            'slug'               => 'ot-themes-one-click-import', // The plugin slug (typically the folder name).
            'source'             => get_template_directory_uri() . '/framework/plugins/ot-themes-one-click-import.zip', // The plugin source.
            'required'           => false, // If false, the plugin is only 'recommended' instead of required.
        ),		
    );



    $config = array(

        'id'           => 'tgmpa',                 // Unique ID for hashing notices for multiple instances of TGMPA.

        'default_path' => '',                      // Default absolute path to pre-packaged plugins.

        'menu'         => 'tgmpa-install-plugins', // Menu slug.

        'parent_slug'  => 'themes.php',            // Parent menu slug.

        'capability'   => 'edit_theme_options',    // Capability needed to view plugin install page, should be a capability associated with the parent menu used.

        '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'                      => __( 'Install Required Plugins', 'theme-slug' ),

            'menu_title'                      => __( 'Install Plugins', 'theme-slug' ),

            'installing'                      => __( 'Installing Plugin: %s', 'theme-slug' ), // %s = plugin name.

            'oops'                            => __( 'Something went wrong with the plugin API.', 'theme-slug' ),

            'notice_can_install_required'     => _n_noop(

                'This theme requires the following plugin: %1$s.',

                'This theme requires the following plugins: %1$s.',

                'theme-slug'

            ), // %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.',

                'theme-slug'

            ), // %1$s = plugin name(s).

            'notice_cannot_install'           => _n_noop(

                'Sorry, but you do not have the correct permissions to install the %1$s plugin.',

                'Sorry, but you do not have the correct permissions to install the %1$s plugins.',

                'theme-slug'

            ), // %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.',

                'theme-slug'

            ), // %1$s = plugin name(s).

            'notice_ask_to_update_maybe'      => _n_noop(

                'There is an update available for: %1$s.',

                'There are updates available for the following plugins: %1$s.',

                'theme-slug'

            ), // %1$s = plugin name(s).

            'notice_cannot_update'            => _n_noop(

                'Sorry, but you do not have the correct permissions to update the %1$s plugin.',

                'Sorry, but you do not have the correct permissions to update the %1$s plugins.',

                'theme-slug'

            ), // %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.',

                'theme-slug'

            ), // %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.',

                'theme-slug'

            ), // %1$s = plugin name(s).

            'notice_cannot_activate'          => _n_noop(

                'Sorry, but you do not have the correct permissions to activate the %1$s plugin.',

                'Sorry, but you do not have the correct permissions to activate the %1$s plugins.',

                'theme-slug'

            ), // %1$s = plugin name(s).

            'install_link'                    => _n_noop(

                'Begin installing plugin',

                'Begin installing plugins',

                'theme-slug'

            ),

            'update_link'                     => _n_noop(

                'Begin updating plugin',

                'Begin updating plugins',

                'theme-slug'

            ),

            'activate_link'                   => _n_noop(

                'Begin activating plugin',

                'Begin activating plugins',

                'theme-slug'

            ),

            'return'                          => __( 'Return to Required Plugins Installer', 'theme-slug' ),

            'plugin_activated'                => __( 'Plugin activated successfully.', 'theme-slug' ),

            'activated_successfully'          => __( 'The following plugin was activated successfully:', 'theme-slug' ),

            'plugin_already_active'           => __( 'No action taken. Plugin %1$s was already active.', 'theme-slug' ),  // %1$s = plugin name(s).

            'plugin_needs_higher_version'     => __( 'Plugin not activated. A higher version of %s is needed for this theme. Please update the plugin.', 'theme-slug' ),  // %1$s = plugin name(s).

            'complete'                        => __( 'All plugins installed and activated successfully. %1$s', 'theme-slug' ), // %s = dashboard link.

            'contact_admin'                   => __( 'Please contact the administrator of this site for help.', 'tgmpa' ),



            'nag_type'                        => 'updated', // Determines admin notice type - can only be 'updated', 'update-nag' or 'error'.

        )

    );



    tgmpa( $plugins, $config );



}

?>