<?php
/* Visual Composer support functions
------------------------------------------------------------------------------- */

// Theme init
if (!function_exists('seohub_vc_theme_setup')) {
	add_action( 'seohub_action_before_init_theme', 'seohub_vc_theme_setup', 1 );
	function seohub_vc_theme_setup() {
		if (seohub_exists_visual_composer()) {
			if (is_admin()) {
				add_filter( 'seohub_filter_importer_options',				'seohub_vc_importer_set_options' );
			}
		}
		if (is_admin()) {
			add_filter( 'seohub_filter_importer_required_plugins',		'seohub_vc_importer_required_plugins' );
			add_filter( 'seohub_filter_required_plugins',					'seohub_vc_required_plugins' );
		}
	}
}

// Check if Visual Composer installed and activated
if ( !function_exists( 'seohub_exists_visual_composer' ) ) {
	function seohub_exists_visual_composer() {
		return class_exists('Vc_Manager');
	}
}

// Check if Visual Composer in frontend editor mode
if ( !function_exists( 'seohub_vc_is_frontend' ) ) {
	function seohub_vc_is_frontend() {
		return (isset($_GET['vc_editable']) && $_GET['vc_editable']=='true')
			|| (isset($_GET['vc_action']) && $_GET['vc_action']=='vc_inline');
		//return function_exists('vc_is_frontend_editor') && vc_is_frontend_editor();
	}
}

// Filter to add in the required plugins list
if ( !function_exists( 'seohub_vc_required_plugins' ) ) {
	//add_filter('seohub_filter_required_plugins',	'seohub_vc_required_plugins');
	function seohub_vc_required_plugins($list=array()) {
	    global $SEOHUB_GLOBALS;
		if (in_array('visual_composer', $SEOHUB_GLOBALS['required_plugins']))
			$list[] = array(
					'name' 		=> 'Visual Composer',
					'slug' 		=> 'js_composer',
					'source'	=> seohub_get_file_dir('plugins/install/js_composer.zip'),
					'required' 	=> false
				);
		return $list;
	}
}



// One-click import support
//------------------------------------------------------------------------

// Check VC in the required plugins
if ( !function_exists( 'seohub_vc_importer_required_plugins' ) ) {
	//add_filter( 'seohub_filter_importer_required_plugins',	'seohub_vc_importer_required_plugins' );
	function seohub_vc_importer_required_plugins($not_installed='') {
	    global $SEOHUB_GLOBALS;
		if (in_array('visual_composer', $SEOHUB_GLOBALS['required_plugins']) && !seohub_exists_visual_composer() && $_POST['data_type']=='vc' )
			$not_installed .= '<br>Visual Composer';
		return $not_installed;
	}
}

// Set options for one-click importer
if ( !function_exists( 'seohub_vc_importer_set_options' ) ) {
	//add_filter( 'seohub_filter_importer_options',	'seohub_vc_importer_set_options' );
	function seohub_vc_importer_set_options($options=array()) {
		if (is_array($options)) {
			$options['additional_options'][] = 'wpb_js_templates';		// Add slugs to export options for this plugin

		}
		return $options;
	}
}
?>