<?php
/*
Plugin Name: Maple Custom Post Types
Plugin URI: https://treethemes.com
Description: Testimonials, Projects, Widgets, Newsletter and TreeThemes Templates for WP Bakery page Builder.
Version: 4.0.2
Author: TreeThemes
Author URI: https://treethemes.com
*/


// don't load directly
if ( ! defined( 'ABSPATH' )) {
	die( '-1' );
}

/* defines */
if (!defined('MAPLE_PORTFOLIO_POST_TYPE')){
	if (!defined('MAPLE_SHORTNAME')) define('MAPLE_SHORTNAME', 'maple');
	$portfolio_permalink = get_option(MAPLE_SHORTNAME."_portfolio_permalink");
	if (!get_option(MAPLE_SHORTNAME."_portfolio_permalink")) define("MAPLE_PORTFOLIO_POST_TYPE", "portfolio");
	else define("MAPLE_PORTFOLIO_POST_TYPE", get_option(MAPLE_SHORTNAME."_portfolio_permalink"));
}
if (!defined('MAPLE_TESTIMONIALS_POST_TYPE')){
	define("MAPLE_TESTIMONIALS_POST_TYPE", 'testimonials');
}

if (!defined('MAPLE_PLG_URL')){
	define('MAPLE_PLG_URL', plugin_dir_url(__FILE__) );
}
if (!defined('MAPLE_PLG_PATH')){
	define('MAPLE_PLG_PATH', plugin_dir_path(__FILE__) );
}

if (!defined('MAPLE_PLG_ACTIVE')){
	define('MAPLE_PLG_ACTIVE', true );
}

function maple_cpt_scripts() {
	wp_register_style( 'maple-cpt', plugins_url( '/lib/css/treethemes-cpt-frontend.css', __FILE__ ) );
}
add_action( 'wp_enqueue_scripts', 'maple_cpt_scripts' );

/* widgets */
add_action( 'maple_plugin_widgets_init', 'maple_plugin_widgets_init' );
function maple_plugin_widgets_init(){
	global $vc_addons_url;
	$active_widgets = ["contactInfo/maple_widget_contactInfo.php","flickr/maple_widget_flickr.php", "recentPostsSidebar2/maple_widget_recentPostsSidebar2.php","vcelement/maple_widget_vc_element.php","video/maple_widget_video.php","socials/maple_socials_widget.php"];
	if (isset($vc_addons_url) && $vc_addons_url != ""){
		$active_widgets_with_addons = ["recentPostsSidebar/maple_widget_recentPostsSidebar.php","testimonials/maple_widget_testimonials.php"];
		$active_widgets = array_merge($active_widgets, $active_widgets_with_addons); 
	}
	if (!class_exists('CubePortfolioMain')) unset($active_widgets[ array_search("recentProjects/maple_widget_recentProjects.php", $active_widgets) ]);
	foreach ($active_widgets as $widget) require_once( "lib/widgets/" . $widget );
}

/* gutenberg */ 
add_action( 'init', 'maple_check_for_gutenberg', 1 );
if (!function_exists('maple_check_for_gutenberg')){
	function maple_check_for_gutenberg(){
		global $wp_version, $pagenow;
		
		$_wpb_vc_js_status = isset($_GET['post']) ? get_post_meta( $_GET['post'], '_wpb_vc_js_status', true ) : false;
		if (!$_wpb_vc_js_status){
			if (in_array( $pagenow, array( 'post-new.php' ) ) && function_exists('vc_remove_element') && get_option( 'wpb_js_gutenberg_disable', 1 ) )
				$_wpb_vc_js_status = true;
		}
		if ( ( defined('GUTENBERG_VERSION') || intval($wp_version) > 4 ) && !isset($_GET['classic-editor']) && !$_wpb_vc_js_status && function_exists('vc_remove_element') ){
			add_action('admin_enqueue_scripts', 'treethemes_admin_block_style');
			require_once( "lib/gutenberg/treethemes-block.php" );
		}
	}
}

if (!function_exists('treethemes_admin_block_style')){
	function treethemes_admin_block_style(){
		wp_enqueue_style( 'treethemes-block', MAPLE_PLG_URL . "lib/gutenberg/treethemes-block.css", 1 );
	}
}

/*******+++++**/
/*	projects
/********+++++*/
/**
 * ADD THE ACTIONS
 */
add_action('init', 'maple_register_portfolio_category');  //functions/portfolio.php
add_action('init', 'maple_register_portfolio_post_type');  //functions/portfolio.php
add_action('manage_posts_custom_column',  'portfolio_show_columns'); //functions/portfolio.php
add_filter('manage_edit-portfolio_columns', 'portfolio_columns');

/**
 * Registers the portfolio category taxonomy.
 */
if (!function_exists('maple_register_portfolio_category')){
    function maple_register_portfolio_category(){

        register_taxonomy("portfolio_category",
            array(MAPLE_PORTFOLIO_POST_TYPE),
            array(	"hierarchical" => true,
                "label" => "Categories",
                "singular_label" => "Categories",
                "rewrite" => true,
                "query_var" => true
            ));

        register_taxonomy("portfolio_type",
            array(MAPLE_PORTFOLIO_POST_TYPE),
            array(	"hierarchical" => true,
                "label" => "Portfolios",
                "singular_label" => "Portfolios",
                "rewrite" => true,
                "query_var" => true
            ));
    }
}


/**
 * Registers the portfolio custom type.
 */
if (!function_exists('maple_register_portfolio_post_type')){
    function maple_register_portfolio_post_type() {
        $portfolio_permalink = get_option(MAPLE_SHORTNAME."_portfolio_permalink");
        //the labels that will be used for the portfolio items
        $labels = array(
            'name' => _x('Projects', 'portfolio name','maple'),
            'singular_name' => _x('Project Item', 'portfolio type singular name','maple'),
            'add_new' => __('Add New','maple'),
            'add_new_item' => __('Add New Item','maple'),
            'edit_item' => __('Edit Item','maple'),
            'new_item' => __('New Project Item','maple'),
            'view_item' => __('View Item','maple'),
            'search_items' => __('Search Project Items','maple'),
            'not_found' =>  __('No project items found','maple'),
            'not_found_in_trash' => __('No project items found in Trash','maple'),
            'parent_item_colon' => ''
        );

        //register the custom post type
        register_post_type( MAPLE_PORTFOLIO_POST_TYPE,
            array( 'labels' => $labels,
                'public' => true,
                'show_ui' => true,
                'capability_type' => 'post',
                'menu_icon' => get_template_directory_uri() . '/images/maple_icons/projectsicon.png',
                'hierarchical' => false,
                'rewrite' => array( 'with_front' => 'false', 'slug' => $portfolio_permalink ),
                'taxonomies' => array('portfolio_category'),
                'supports' => array('title', 'editor', 'thumbnail', 'comments', 'page-attributes', 'excerpt') ) );


    }
}



/* ------------------------------------------------------------------------*
 * SET THE DEFAULT IMAGE SIZES FOR THE PORTFOLIO ITEMS REGARDING THE
 * NUMBER OF COLUMNS
 * ------------------------------------------------------------------------*/

if (!function_exists('portfolio_columns')){
    function portfolio_columns($columns) {
        $columns['category'] = 'Category';
        $columns['type'] = 'Portfolio';
        return $columns;
    }
}

/**
 * Add category column to the portfolio items page
 * @param $name
 */
if (!function_exists('portfolio_show_columns')){
    function portfolio_show_columns($name) {
        global $post;
        switch ($name) {
            case 'category':
                $cats = get_the_term_list( $post->ID, 'portfolio_category', '', ', ', '' );
                echo $cats;
                break;
            case 'type':
                $cats = get_the_term_list( $post->ID, 'portfolio_type', '', ', ', '' );
                echo $cats;
                break;
        }
    }
}


/* new order by features helper */
if (!function_exists('treethemes_orderby_tax_clauses')){
	function treethemes_orderby_tax_clauses( $clauses, $wp_query ) {
		$orderby_arg = $wp_query->get('orderby');
		if ( ! empty( $orderby_arg ) && substr_count( $orderby_arg, 'taxonomy.' ) ) {
			global $wpdb;
			$bytax = "GROUP_CONCAT({$wpdb->terms}.name ORDER BY name ASC)";
			$array = explode( ' ', $orderby_arg ); 
			if ( ! isset( $array[1] ) ) {
				$array = array( $bytax, "{$wpdb->posts}.post_date" );
				$taxonomy = str_replace( 'taxonomy.', '', $orderby_arg );
			} else {
				foreach ( $array as $i => $t ) {
					if ( substr_count( $t, 'taxonomy.' ) )  {
						$taxonomy = str_replace( 'taxonomy.', '', $t );
						$array[$i] = $bytax;
					} elseif ( $t === 'meta_value' || $t === 'meta_value_num' ) {
						$cast = ( $t === 'meta_value_num' ) ? 'SIGNED' : 'CHAR';
						$array[$i] = "CAST( {$wpdb->postmeta}.meta_value AS {$cast} )";
					} else {
					$array[$i] = "{$wpdb->posts}.{$t}";
					}
				}
			}
			$order = strtoupper( $wp_query->get('order') ) === 'ASC' ? ' ASC' : ' DESC';
			$ot = strtoupper( $wp_query->get('ordertax') );
			$ordertax = $ot === 'DESC' || $ot === 'ASC' ? " $ot" : " $order";
			$clauses['orderby'] = implode(', ',
			array_map( function($a) use ( $ordertax, $order ) {
				return ( strpos($a, 'GROUP_CONCAT') === 0 ) ? $a . $ordertax : $a . $order;
			}, $array ));
			$clauses['join'] .= " LEFT OUTER JOIN {$wpdb->term_relationships} ";
			$clauses['join'] .= "ON {$wpdb->posts}.ID = {$wpdb->term_relationships}.object_id";
			$clauses['join'] .= " LEFT OUTER JOIN {$wpdb->term_taxonomy} ";
			$clauses['join'] .= "USING (term_taxonomy_id)";
			$clauses['join'] .= " LEFT OUTER JOIN {$wpdb->terms} USING (term_id)";
			$clauses['groupby'] = "object_id";
			$clauses['where'] .= " AND (taxonomy = '{$taxonomy}' OR taxonomy IS NULL)";
		}
		return $clauses;
	}	
}

/**
 * Gets a list of custom taxomomies by type
 * @param $type the type of the taxonomy
 */
if (!function_exists('maple_get_taxonomies')){
    function maple_get_taxonomies($type){
        $args = array(
            'type' => 'post',
            'orderby' => 'id',
            'order' => 'ASC',
            'taxonomy' => $type,
            'hide_empty' => 1,
            'pad_counts' => false );

        $categories = get_categories( $args );

        return $categories;
    }
}


/**
 * Gets a list of custom taxomomies by slug
 * @param $term_id the slug
 */
if (!function_exists('maple_get_taxonomy_slug')){
    function maple_get_taxonomy_slug($term_id){
        global $wpdb;

        $res = $wpdb->get_results($wpdb->prepare("SELECT slug FROM $wpdb->terms WHERE term_id=%s LIMIT 1;", $term_id));
        $res=$res[0];
        return $res->slug;
    }
}

/**
 * Gets a list of custom taxomomy's children
 * @param $type the type of the taxonomy
 * @param $parent_id the slug of the parent taxonomy
 */
if (!function_exists('maple_get_taxonomy_children')){
    function maple_get_taxonomy_children($type, $parent_id){
        global $wpdb;

        if($parent_id!='-1'){
            $res = $wpdb->get_results($wpdb->prepare("SELECT t.term_id, t.name, t.slug FROM $wpdb->terms as t LEFT JOIN $wpdb->term_taxonomy tt ON t.term_id=tt.term_id WHERE tt.taxonomy=%s AND tt.parent=%s;", $type, $parent_id));
        }else{
            $res = $wpdb->get_results($wpdb->prepare("SELECT t.term_id, t.name, t.slug FROM $wpdb->terms as t LEFT JOIN $wpdb->term_taxonomy tt ON t.term_id=tt.term_id WHERE tt.taxonomy=%s;", $type));
        }
        return $res;
    }
}

if (!function_exists('maple_get_projects')){
    function maple_get_projects(){
        $proj = array();
        $args= array(
            'posts_per_page' =>-1,
            'post_type' => MAPLE_PORTFOLIO_POST_TYPE
        );
        query_posts($args);

        if(have_posts()) {
            while (have_posts()) {
                the_post();
                $proj[] = array("p_title"=>get_the_title(), "p_id"=>get_the_ID());
                //$ret .= get_the_title() . "|*|";
            }
        }

        return $proj;
    }
}



/*******+++++**/
/*	testimonials
/********+++++*/
/**
 * ADD THE ACTIONS
 */
add_action('init', 'maple_register_testimonials_post_type');  //functions/testimonials.php


/**
 * Registers the portfolio custom type.
 */
if (!function_exists('maple_register_testimonials_post_type')){
    function maple_register_testimonials_post_type() {

        register_taxonomy("testimonials_category",
            array(MAPLE_TESTIMONIALS_POST_TYPE),
            array(	"hierarchical" => true,
                "label" => "Categories",
                "singular_label" => "Categories",
                "rewrite" => true,
                "query_var" => true,
                "show_admin_column" => true,
            ));

        //the labels that will be used for the portfolio items
        $labels = array(
            'name' => _x('Testimonials', 'testimonials name','maple'),
            'singular_name' => _x('Testimonials Item', 'testimonials type singular name','maple'),
            'add_new' => __('Add New','maple'),
            'add_new_item' => __('Add New Item','maple'),
            'edit_item' => __('Edit Item','maple'),
            'new_item' => __('New Testimonials Item','maple'),
            'view_item' => __('View Item','maple'),
            'search_items' => __('Search Testimonials Items','maple'),
            'not_found' =>  __('No testimonials items found','maple'),
            'not_found_in_trash' => __('No testimonials items found in Trash','maple'),
            'parent_item_colon' => ''
        );

        //register the custom post type
        register_post_type( MAPLE_TESTIMONIALS_POST_TYPE,
            array( 'labels' => $labels,
                'public' => true,
                'show_ui' => true,
                'exclude_from_search' => true,
                'show_in_nav_menus' => false,
                'menu_icon' => get_template_directory_uri() . '/images/maple_icons/testicon.png',
                'capability_type' => 'post',
                'hierarchical' => false,
                'rewrite' => array('slug'=>'testimonials'),
                'taxonomies' => array('testimonials_category'),
                'supports' => array('title', 'editor', 'thumbnail', 'comments', 'page-attributes') ) );


    }
}

if (!function_exists('maple_init_cpt_plugin')){
    function maple_init_cpt_plugin(){
        maple_register_testimonials_post_type();
    }
}


/*  EXTEND VC SHORTCODES  */

/* 2020 */
if (!function_exists('maple_posts_cats_settings_field')){
	function maple_posts_cats_settings_field($settings, $value){
		$taxonomy = 'category';
		$tax_terms = get_terms($taxonomy);
		$output = "";
		if (!count($tax_terms)){
			$output .= "No categories defined.";
			$output .= '<input name="'.esc_attr($settings['param_name']).'" class="hidden wpb_vc_param_value wpb-textinput '.esc_attr($settings['param_name']).' '.esc_attr($settings['type']).'_field" type="text" value="-1" />';
		} else {
			if (count($tax_terms) > 1) $output .= "<label class='post_categories'><input class='selectall' type='checkbox' name='categories[]' value='-1' onchange=\"if(jQuery(this).is(':checked')){ jQuery(this).parent().siblings().children('input').attr('checked',true);jQuery(this).parent().siblings('input.".esc_js($settings['param_name'])."').val('-1');} else { jQuery(this).parent().siblings().children('input').attr('checked',false);jQuery(this).parent().siblings('input.".esc_js($settings['param_name'])."').val('-1');}\" />".esc_html__('All','maple')."</label>";
			$value_array = explode(",",$value);
			foreach ($tax_terms as $tax_term) {
				$output .= "<label class='post_categories'><input ";
				if (in_array($tax_term->slug, $value_array) || $value == '-1') $output .= " checked='checked' ";
				$output .= "class='categories_checks' type='checkbox' name='categories[]' value='".esc_attr($tax_term->slug)."' onchange=\"var output = '';jQuery('.edit_form_line input:checked').not('.selectall').each(function(e){ if(e!=0){output += ',';} output += jQuery(this).val(); }); jQuery(this).parent().siblings('.posts_cats_field').val(output); if (jQuery('.edit_form_line input').not('.selectall').not(':checked').length) jQuery('.edit_form_line input.selectall').attr('checked',false); if (jQuery('.edit_form_line input.categories_checks:checked').not('.selectall').length == jQuery('.edit_form_line input.categories_checks').not('.selectall').length) jQuery('.edit_form_line input.selectall').attr('checked',true); \" />".esc_html($tax_term->name)."</label>";
			}
			$output .= '<input name="'.esc_attr($settings['param_name']).'" class="hidden wpb_vc_param_value wpb-textinput '.esc_attr($settings['param_name']).' '.esc_attr($settings['type']).'_field" type="text" value="'.esc_attr($value).'" />';
		}
		return $output;
	}
}



if (!function_exists('maple_testimonials_categories_settings_field')){
	function maple_testimonials_categories_settings_field($settings, $value){
		//$dependency = vc_generate_dependencies_attributes($settings);
		$taxonomy = 'testimonials_category';
		$tax_terms = get_terms($taxonomy);
		$output = "";
		if (!count($tax_terms)){
			$output .= "No categories defined.";
			$output .= '<input name="'.esc_attr($settings['param_name']).'" class="hidden wpb_vc_param_value wpb-textinput '.esc_attr($settings['param_name']).' '.esc_attr($settings['type']).'_field" type="text" value="0" />';
		} else {
			if (count($tax_terms) > 1) $output .= "<label class='testimonial_categories'><input class='selectall' type='checkbox' name='categories[]' value='0' onchange=\"if(jQuery(this).is(':checked')){ jQuery(this).parent().siblings().children('input').attr('checked',true);jQuery(this).parent().siblings('input.".esc_js($settings['param_name'])."').val('-1');} else { jQuery(this).parent().siblings().children('input').attr('checked',false);jQuery(this).parent().siblings('input.".esc_js($settings['param_name'])."').val('0');}\" />".esc_html__('All','maple')."</label>";
			$value = explode(",",$value);
			foreach ($tax_terms as $tax_term) {
				$output .= "<label class='testimonial_categories'><input ";
				if (in_array($tax_term->slug, $value)) $output .= " checked='checked' ";
				$output .= "class='categories_checks' type='checkbox' name='categories[]' value='".esc_attr($tax_term->slug)."' onchange=\"var output = '';jQuery('.edit_form_line input:checked').not('.selectall').each(function(e){ if(e!=0){output += ',';} output += jQuery(this).val(); }); jQuery(this).parent().siblings('.testimonials_cats_field').val(output); if (jQuery('.edit_form_line input').not('.selectall').not(':checked').length) jQuery('.edit_form_line input.selectall').attr('checked',false); if (jQuery('.edit_form_line input.categories_checks:checked').not('.selectall').length == jQuery('.edit_form_line input.categories_checks').not('.selectall').length) jQuery('.edit_form_line input.selectall').attr('checked',true); \" />".esc_html($tax_term->name)."</label>";
			}
			$output .= '<input name="'.esc_attr($settings['param_name']).'" class="hidden wpb_vc_param_value wpb-textinput '.esc_attr($settings['param_name']).' '.esc_attr($settings['type']).'_field" type="text" value="'.esc_attr(implode(",",$value)).'" />';
		}
		return $output;
	}
}


if (!function_exists('maple_fa_settings_field')){
	function maple_fa_settings_field($settings, $value) {
	   //$dependency = vc_generate_dependencies_attributes($settings);
		$icons = array('fa-adjust','fa-adn','fa-align-center','fa-align-justify','fa-align-left','fa-align-right','fa-ambulance','fa-anchor','fa-android','fa-angle-double-down','fa-angle-double-left','fa-angle-double-right','fa-angle-double-up','fa-angle-down','fa-angle-left','fa-angle-right','fa-angle-up','fa-apple','fa-archive','fa-arrow-circle-down','fa-arrow-circle-left','fa-arrow-circle-o-down','fa-arrow-circle-o-left','fa-arrow-circle-o-right','fa-arrow-circle-o-up','fa-arrow-circle-right','fa-arrow-circle-up','fa-arrow-down','fa-arrow-left','fa-arrow-right','fa-arrow-up','fa-arrows','fa-arrows-alt','fa-arrows-h','fa-arrows-v','fa-asterisk','fa-automobile','fa-backward','fa-ban','fa-bank','fa-bar-chart-o','fa-barcode','fa-bars','fa-beer','fa-behance','fa-behance-square','fa-bell','fa-bell-o','fa-bitbucket','fa-bitbucket-square','fa-bitcoin','fa-bold','fa-bolt','fa-bomb','fa-book','fa-bookmark','fa-bookmark-o','fa-briefcase','fa-btc','fa-bug','fa-building','fa-building-o','fa-bullhorn','fa-bullseye','fa-cab','fa-calendar','fa-calendar-o','fa-camera','fa-camera-retro','fa-car','fa-caret-down','fa-caret-left','fa-caret-right','fa-caret-square-o-down','fa-caret-square-o-left','fa-caret-square-o-right','fa-caret-square-o-up','fa-caret-up','fa-certificate','fa-chain','fa-chain-broken','fa-check','fa-check-circle','fa-check-circle-o','fa-check-square','fa-check-square-o','fa-chevron-circle-down','fa-chevron-circle-left','fa-chevron-circle-right','fa-chevron-circle-up','fa-chevron-down','fa-chevron-left','fa-chevron-right','fa-chevron-up','fa-child','fa-circle','fa-circle-o','fa-circle-o-notch','fa-circle-thin','fa-clipboard','fa-clock-o','fa-cloud','fa-cloud-download','fa-cloud-upload','fa-cny','fa-code','fa-code-fork','fa-codepen','fa-coffee','fa-cog','fa-cogs','fa-columns','fa-comment','fa-comment-o','fa-comments','fa-comments-o','fa-compass','fa-compress','fa-copy','fa-credit-card','fa-crop','fa-crosshairs','fa-css3','fa-cube','fa-cubes','fa-cut','fa-cutlery','fa-dashboard','fa-database','fa-dedent','fa-delicious','fa-desktop','fa-deviantart','fa-digg','fa-dollar','fa-dot-circle-o','fa-download','fa-dribbble','fa-dropbox','fa-drupal','fa-edit','fa-eject','fa-ellipsis-h','fa-ellipsis-v','fa-empire','fa-envelope','fa-envelope-o','fa-envelope-square','fa-eraser','fa-eur','fa-euro','fa-exchange','fa-exclamation','fa-exclamation-circle','fa-exclamation-triangle','fa-expand','fa-external-link','fa-external-link-square','fa-eye','fa-eye-slash','fa-facebook','fa-facebook-square','fa-fast-backward','fa-fast-forward','fa-fax','fa-female','fa-fighter-jet','fa-file','fa-file-archive-o','fa-file-audio-o','fa-file-code-o','fa-file-excel-o','fa-file-image-o','fa-file-movie-o','fa-file-o','fa-file-pdf-o','fa-file-photo-o','fa-file-picture-o','fa-file-powerpoint-o','fa-file-sound-o','fa-file-text','fa-file-text-o','fa-file-video-o','fa-file-word-o','fa-file-zip-o','fa-files-o','fa-film','fa-filter','fa-fire','fa-fire-extinguisher','fa-flag','fa-flag-checkered','fa-flag-o','fa-flash','fa-flask','fa-flickr','fa-floppy-o','fa-folder','fa-folder-o','fa-folder-open','fa-folder-open-o','fa-font','fa-forward','fa-foursquare','fa-frown-o','fa-gamepad','fa-gavel','fa-gbp','fa-ge','fa-gear','fa-gears','fa-gift','fa-git','fa-git-square','fa-github','fa-github-alt','fa-github-square','fa-gittip','fa-glass','fa-globe','fa-google','fa-google-plus','fa-google-plus-square','fa-graduation-cap','fa-group','fa-h-square','fa-hacker-news','fa-hand-o-down','fa-hand-o-left','fa-hand-o-right','fa-hand-o-up','fa-hdd-o','fa-header','fa-headphones','fa-heart','fa-heart-o','fa-history','fa-home','fa-hospital-o','fa-html5','fa-image','fa-inbox','fa-indent','fa-info','fa-info-circle','fa-inr','fa-instagram','fa-institution','fa-italic','fa-joomla','fa-jpy','fa-jsfiddle','fa-key','fa-keyboard-o','fa-krw','fa-language','fa-laptop','fa-leaf','fa-legal','fa-lemon-o','fa-level-down','fa-level-up','fa-life-bouy','fa-life-ring','fa-life-saver','fa-lightbulb-o','fa-link','fa-linkedin','fa-linkedin-square','fa-linux','fa-list','fa-list-alt','fa-list-ol','fa-list-ul','fa-location-arrow','fa-lock','fa-long-arrow-down','fa-long-arrow-left','fa-long-arrow-right','fa-long-arrow-up','fa-magic','fa-magnet','fa-mail-forward','fa-mail-reply','fa-mail-reply-all','fa-male','fa-map-marker','fa-maxcdn','fa-medkit','fa-meh-o','fa-microphone','fa-microphone-slash','fa-minus','fa-minus-circle','fa-minus-square','fa-minus-square-o','fa-mobile','fa-mobile-phone','fa-money','fa-moon-o','fa-mortar-board','fa-music','fa-navicon','fa-openid','fa-outdent','fa-pagelines','fa-paper-plane','fa-paper-plane-o','fa-paperclip','fa-paragraph','fa-paste','fa-pause','fa-paw','fa-pencil','fa-pencil-square','fa-pencil-square-o','fa-phone','fa-phone-square','fa-photo','fa-picture-o','fa-pied-piper','fa-pied-piper-alt','fa-pinterest','fa-pinterest-square','fa-plane','fa-play','fa-play-circle','fa-play-circle-o','fa-plus','fa-plus-circle','fa-plus-square','fa-plus-square-o','fa-power-off','fa-print','fa-puzzle-piece','fa-qq','fa-qrcode','fa-question','fa-question-circle','fa-quote-left','fa-quote-right','fa-ra','fa-random','fa-rebel','fa-recycle','fa-reddit','fa-reddit-square','fa-refresh','fa-renren','fa-reorder','fa-repeat','fa-reply','fa-reply-all','fa-retweet','fa-rmb','fa-road','fa-rocket','fa-rotate-left','fa-rotate-right','fa-rouble','fa-rss','fa-rss-square','fa-rub','fa-ruble','fa-rupee','fa-save','fa-scissors','fa-search','fa-search-minus','fa-search-plus','fa-send','fa-send-o','fa-share','fa-share-alt','fa-share-alt-square','fa-share-square','fa-share-square-o','fa-shield','fa-shopping-cart','fa-sign-in','fa-sign-out','fa-signal','fa-sitemap','fa-skype','fa-slack','fa-sliders','fa-smile-o','fa-sort','fa-sort-alpha-asc','fa-sort-alpha-desc','fa-sort-amount-asc','fa-sort-amount-desc','fa-sort-asc','fa-sort-desc','fa-sort-down','fa-sort-numeric-asc','fa-sort-numeric-desc','fa-sort-up','fa-soundcloud','fa-space-shuttle','fa-spinner','fa-spoon','fa-spotify','fa-square','fa-square-o','fa-stack-exchange','fa-stack-overflow','fa-star','fa-star-half','fa-star-half-empty','fa-star-half-full','fa-star-half-o','fa-star-o','fa-steam','fa-steam-square','fa-step-backward','fa-step-forward','fa-stethoscope','fa-stop','fa-strikethrough','fa-stumbleupon','fa-stumbleupon-circle','fa-subscript','fa-suitcase','fa-sun-o','fa-superscript','fa-support','fa-table','fa-tablet','fa-tachometer','fa-tag','fa-tags','fa-tasks','fa-taxi','fa-tencent-weibo','fa-terminal','fa-text-height','fa-text-width','fa-th','fa-th-large','fa-th-list','fa-thumb-tack','fa-thumbs-down','fa-thumbs-o-down','fa-thumbs-o-up','fa-thumbs-up','fa-ticket','fa-times','fa-times-circle','fa-times-circle-o','fa-tint','fa-toggle-down','fa-toggle-left','fa-toggle-right','fa-toggle-up','fa-trash-o','fa-tree','fa-trello','fa-trophy','fa-truck','fa-try','fa-tumblr','fa-tumblr-square','fa-turkish-lira','fa-twitter','fa-twitter-square','fa-umbrella','fa-underline','fa-undo','fa-university','fa-unlink','fa-unlock','fa-unlock-alt','fa-unsorted','fa-upload','fa-usd','fa-user','fa-user-md','fa-users','fa-video-camera','fa-vimeo-square','fa-vine','fa-vk','fa-volume-down','fa-volume-off','fa-volume-up','fa-warning','fa-wechat','fa-weibo','fa-weixin','fa-wheelchair','fa-windows','fa-won','fa-wordpress','fa-wrench','fa-xing','fa-xing-square','fa-yahoo','fa-yen','fa-youtube','fa-youtube-play','fa-youtube-square');
		$output = '<div class="maple_fa_block">'
		             .'<input name="'.esc_attr($settings['param_name'])
		             .'" class="wpb_vc_param_value wpb-textinput '
		             .esc_attr($settings['param_name']).' '.esc_attr($settings['type']).'_field" type="text" value="'
		             .esc_attr($value).'" />'
		         .'</div><div class="icons-container">';
		foreach($icons as $i){
			$output .= '<i class="fa '.esc_attr($i);
			if ($i == $value) $output .= ' selected';
			$output .= '" onclick="jQuery(this).closest(\'.edit_form_line\').find(\'input.maple_fa_field\').val(\''.esc_js($i).'\');jQuery(this).addClass(\'selected\').siblings().removeClass(\'selected\');"/>';
		}
		$output .= '</div>';
	   return $output;
	}
}

if (!class_exists('VCExtendAddonClass')){
	class VCExtendAddonClass {
	
	    function __construct() {
	        // We safely integrate with VC with this hook
	        add_action( 'vc_before_init', array( $this, 'maple_integrateWithVC' ) );
 
	        // Use this when creating a shortcode addon
	        // the code has been moved for gutenberg compatibility. its down there
	        
	        
	        add_action( 'admin_enqueue_scripts', array( $this, 'treethemes_cpt_admin_scripts' ) );
	        
	        //ererere
	        global $maple_testimonials_index, $maple_single_testimonial_index, $maple_vertical_tabs, $maple_vt_index, $maple_social_networks_index, $maple_recent_posts_index;
	        	$maple_testimonials_index = $maple_single_testimonial_index = $maple_vertical_tabs = $maple_vt_index = $maple_social_networks_index = $maple_recent_posts_index = 1;
	    }
		
		function treethemes_cpt_admin_scripts(){
			wp_enqueue_style("treethemes-cpt-admin",plugins_url("lib/css/treethemes-cpt-admin.css",__FILE__));
		}
		
	    public function maple_integrateWithVC() {
		    
		    // this code here for gutenberg compat
		    if (function_exists('add_shortcode')){
				add_shortcode( 'verticaltabs', array( $this, 'maple_renderVerticalTabs' ) );
				add_shortcode( 'verticaltab', array( $this, 'maple_renderVerticalTab' ) );
				add_shortcode( 'testimonials', array( $this, 'maple_renderTestimonials' ) );
				/* 2020 */
				add_shortcode( 'social_networks', array( $this, 'maple_renderSocialNetworks' ) );
				add_shortcode( 'recent_posts', array( $this, 'maple_renderRecentPosts' ) );
	        }
		    
	        $vs_posttypes = get_option('wpb_js_content_types');
	        if (!isset($vs_posttypes)) update_option('wpb_js_content_types', array('post','page','portfolio'), true );
	        else {
		        if (!isset($vs_posttypes) || !$vs_posttypes) {
			        $vs_posttypes = array('post','page','portfolio');
		        }
				if (is_array($vs_posttypes) && !in_array('page',$vs_posttypes)){ 
					array_push($vs_posttypes, 'page');
				}
				if (is_array($vs_posttypes) && !in_array('portfolio',$vs_posttypes)){ 
					array_push($vs_posttypes, 'portfolio');
				} 
				update_option('wpb_js_content_types', $vs_posttypes, true);
	        }
        
	        
	        $tab_id_1 = time() . '-1-' . rand( 0, 100 );
	        vc_map( array(
	            "name" => esc_html__("Vertical Tabs", 'maple'),
	            "base" => "verticaltabs",
	            "icon" => "vc_extend_vertical_tabs_icon", // or css class name which you can reffer in your css file later. Example: "vc_extend_my_class"
	            "category" => 'TreeThemes Shortcodes',
				'show_settings_on_create' => false,
				"as_parent" => array('only' => 'verticaltab'),
	            'admin_enqueue_js' => MAPLE_PLG_URL . 'lib/vc_shortcodes/vertical_tabs.js', // This will load js file in the VC backend editor
	            'front_enqueue_js' => MAPLE_PLG_URL . 'lib/vc_shortcodes/vertical_tabs.js', // This will load js file in the VC backend editor
	            'admin_enqueue_css' => MAPLE_PLG_URL . 'lib/vc_shortcodes/vertical_tabs.css', // This will load css file in the VC 
	            'params' => array(
					array(
						'type' => 'textfield',
						'heading' => esc_html__( 'Widget title', 'maple' ),
						'param_name' => 'tab_title',
						'description' => esc_html__( 'Enter text which will be used as widget title. Leave blank if no title is needed.', 'maple' )
					),
					array(
						'type' => 'dropdown',
						'heading' => esc_html__( 'Style', 'maple' ),
						'param_name' => 'style_vt',
						'value' => array( 'Icon' => 'icon', 'Text' => 'text', 'Icon + Text' => 'icontext' ),
						'std' => 'icon',
						'description' => esc_html__( 'Choose between just display an icon or icon and text.', 'maple' )
					),
					array(
						'type' => 'dropdown',
						'heading' => esc_html__( 'Orientation', 'maple' ),
						'param_name' => 'orientation',
						'value' => array( 'Vertical' => 'vertical', 'Horizontal' => 'horizontal' ),
						'std' => 'vertical',
						'description' => esc_html__( 'Choose between Vertical and Horizontal orientation (it also affects the effect).', 'maple' )
					),
					array(
						'type' => 'textfield',
						'heading' => esc_html__( 'Extra class name', 'maple' ),
						'param_name' => 'el_class',
						'description' => esc_html__( 'If you wish to style particular content element differently, then use this field to add a class name and then refer to it in your css file.', 'maple' )
					)
				),
				'custom_markup' => '<div class="wpb_tabs_holder wpb_holder vc_container_for_children"><ul class="tabs_controls"></ul>%content%</div>',
				'default_content' => '[verticaltab title="' . esc_html__( 'Tab 1', 'maple' ) . '" tab_id="' . $tab_id_1 . '" icon="fa-adjust"][/verticaltab]',
				'js_view' => 'VcVerticalTabsView',
				'category' => array('TreeThemes Shortcodes',esc_html__('Content','maple')),
		        )
			);
			
			$treethemes_icons_set_type = class_exists('Ultimate_VC_Addons') ? "icon_manager" : "maple_fa";
		
			vc_map( array(
				'name' => esc_html__( 'Vertical Tab', 'maple' ),
				"category" => 'TreeThemes Shortcodes',
				'base' => 'verticaltab',
				"as_child" => array('only' => 'verticaltabs'),
				"as_parent" => array('only' => 'vc_row'),
				"allowed_container_element" => true,
				"is_container" => true,
				'params' => array(
					array(
						'type' => 'textfield',
						'heading' => esc_html__( 'Title', 'maple' ),
						'param_name' => 'title',
						'description' => esc_html__( 'Tab title.', 'maple' )
					),
					array(
						"type" => $treethemes_icons_set_type,
						"class" => "",
						"heading" => __("Select Icon ","maple"),
						"param_name" => "icon",
						"value" => "",
						'description' => esc_html__( 'Choose an Icon', 'maple' )
					),
					array(
						'type' => 'tab_id',
						'heading' => esc_html__( 'Tab ID', 'maple' ),
						'param_name' => "tab_id"
					)
				),
				'default_content' => '[vc_row_inner][vc_column_inner][/vc_column_inner][/vc_row_inner]',
				'js_view' => 'VcVerticalTabView',
			) );
		
			vc_map( array(
				'name' => esc_html__( 'Testimonials', 'maple' ),
				"category" => 'TreeThemes Shortcodes',
				'base' => 'testimonials',
				'is_container' => false,
				"icon" => "vc_extend_testimonials_icon", // or css class name which you can reffer in your css file later. Example: "vc_extend_my_class"
				'admin_enqueue_js' => MAPLE_PLG_URL . 'lib/vc_shortcodes/testimonials.js',
				'params' => array(
					array(
						'type' => 'dropdown',
						'heading' => esc_html__('Style', 'maple'),
						'param_name' => 'style_testimonials',
						'description' => esc_html__('3 Different Styles to choose from.','maple'),
						'value' => array(
							esc_html__( 'Style 1', 'maple' ) => 'style1',
							esc_html__( 'Style 2 (with scroller)', 'maple' ) => 'style2',
							esc_html__( 'Style 3 (single wide)', 'maple' ) => 'style3'
						),
					),
					
					array(
						'type' => 'dropdown',
						'heading' => esc_html__('Show Image ?', 'maple'),
						'param_name' => 'testimonials_show_image',
						'value' => array( esc_html__( 'Yes, please', 'maple' ) => 'yes', esc_html__( 'No, thanks', 'maple' ) => 'no' ),
						'dependency' => array(
							'element' => 'style_testimonials',
							'value' => array('style2','style3'),
						),
					),
					
					array(
						'type' => 'dropdown',
						'heading' => esc_html__('Elements Alignment', 'maple'),
						'param_name' => 'testimonials_align',
						'value' => array( esc_html__( 'Center', 'maple' ) => 'center', esc_html__( 'Left', 'maple' ) => 'left' , esc_html__( 'Right', 'maple' ) => 'right' ),
					),
				
					/*flexoptions*/
					array(
						'type' => 'dropdown',
						'heading' => esc_html__('Animation Type','maple'),
						'param_name' => 'des_testimonials_flex_animation',
						'description' => esc_html__('Choose between Slide and Fade effects.','maple'),
						'value' => array(
							esc_html__( 'Slide', 'maple' ) => 'slide',
							esc_html__( 'Fade', 'maple' ) => 'fade'
						),
					),
					array(
						'type' => 'dropdown',
						'heading' => esc_html__( 'Slideshow?', 'maple' ),
						'param_name' => 'des_testimonials_flex_slideshow',
						'description' => esc_html__( 'Animate slider automatically.', 'maple' ),
						'value' => array( esc_html__( 'Yes, please', 'maple' ) => 'yes', esc_html__( 'No, thanks', 'maple' ) => 'no' )
					),
					array(
						'type' => 'textfield',
						'heading' => esc_html__( 'Slideshow Speed', 'maple' ),
						'param_name' => 'des_testimonials_flex_slideshow_speed',
						'description' => esc_html__( 'Set the speed of the slideshow cycling, in milliseconds.', 'maple' ),
						'value' => '3500'
					),
					array(
						'type' => 'textfield',
						'heading' => esc_html__( 'Animation Duration', 'maple' ),
						'param_name' => 'des_testimonials_flex_animation_duration',
						'description' => esc_html__( 'Set the speed of animations, in milliseconds.', 'maple' ),
						'value' => '1000'
					),
					
					/* new maple options */
					array(
						'type' => 'dropdown',
						'heading' => esc_html__( 'Number of Items in Desktop', 'maple' ),
						'param_name' => 'des_testimonials_flex_items_desktop',
						'description' => esc_html__( 'The number of visible items per slide in a desktop.', 'maple' ),
						'value' => array('1'=>1,'2'=>2,'3'=>3),
					),
					array(
						'type' => 'dropdown',
						'heading' => esc_html__( 'Number of Items in a Small Desktop', 'maple' ),
						'param_name' => 'des_testimonials_flex_items_small_desktop',
						'description' => esc_html__( 'The number of visible items per slide in a small desktop.', 'maple' ),
						'value' => array('1'=>1,'2'=>2,'3'=>3),
					),
					array(
						'type' => 'dropdown',
						'heading' => esc_html__( 'Number of Items in a Tablet', 'maple' ),
						'param_name' => 'des_testimonials_flex_items_tablet',
						'description' => esc_html__( 'The number of visible items per slide in a tablet.', 'maple' ),
						'value' => array('1'=>1,'2'=>2,'3'=>3),
					),
					array(
						'type' => 'dropdown',
						'heading' => esc_html__( 'Number of Items in Mobile', 'maple' ),
						'param_name' => 'des_testimonials_flex_items_mobile',
						'description' => esc_html__( 'The number of visible items per slide in a mobile.', 'maple' ),
						'value' => array('1'=>1,'2'=>2,'3'=>3),
					),
					/* endof new maple options */
					
					
					array(
						'type' => 'dropdown',
						'heading' => esc_html__( 'Direction Navigation', 'maple' ),
						'param_name' => 'des_testimonials_flex_direction_nav',
						'description' => esc_html__( 'Create navigation for previous/next navigation.', 'maple' ),
						'value' => array( esc_html__( 'Yes, please', 'maple' ) => 'yes', esc_html__( 'No, thanks', 'maple' ) => 'no' )
					),
					array(
						'type' => 'dropdown',
						'heading' => esc_html__( 'Navigation Style', 'maple' ),
						'param_name' => 'des_testimonials_flex_nav_style',
						'description' => esc_html__( 'Choose between Dark and Light style.', 'maple' ),
						'value' => array( esc_html__( 'Dark', 'maple' ) => 'dark', esc_html__( 'Light', 'maple' ) => 'light' )
					),
					array(
						'type' => 'dropdown',
						'heading' => esc_html__( 'Control Navigation', 'maple' ),
						'param_name' => 'des_testimonials_flex_control_nav',
						'description' => esc_html__( 'Create navigation for paging control of each slide.', 'maple' ),
						'value' => array( esc_html__( 'Yes, please', 'maple' ) => 'yes', esc_html__( 'No, thanks', 'maple' ) => 'no' )
					),
					array(
						'type' => 'dropdown',
						'heading' => esc_html__( 'Pause on Hover', 'maple' ),
						'param_name' => 'des_testimonials_flex_pause_on_hover',
						'description' => esc_html__( 'Pause the slideshow when hovering over slider, then resume when no longer hovering.', 'maple' ),
						'value' => array( esc_html__( 'Yes, please', 'maple' ) => 'yes', esc_html__( 'No, thanks', 'maple' ) => 'no' )
					),
					
					array(
						'type' => 'textfield',
						'heading' => esc_html__( 'Testimonials Scroller Height', 'maple' ),
						'param_name' => 'des_testimonials_flex_height',
						'description' => esc_html__( 'The height of the testimonials scroller in pixels.', 'maple' ),
						'std' => '650'
					),
					/*endofflexoptions*/
				
					array(
						'type' => 'testimonials_cats',
						'heading' => esc_html__( 'Categories', 'maple' ),
						'param_name' => 'testimonials_cats',
						'description' => esc_html__( 'Choose one or more Categories', 'maple' )
					),
					array(
						'type' => 'textfield',
						'heading' => esc_html__( 'Number of Testimonials', 'maple' ),
						'param_name' => 'number',
						'description' => esc_html__( 'The number of testimonials. If set to 0 it will display all.', 'maple' )
					),
					/* new order options */
					array(
						'type' => 'dropdown',
						'heading' => esc_html__( 'Order By', 'maple' ),
						'param_name' => 'maple_testimonials_orderby',
						'value' => array( esc_html__( 'Date', 'maple' ) => 'date', esc_html__( 'Author', 'maple' ) => 'author', esc_html__( 'Company', 'maple' ) => 'company' )
					),
					array(
						'type' => 'dropdown',
						'heading' => esc_html__( 'Order', 'maple' ),
						'param_name' => 'maple_testimonials_order',
						'value' => array( esc_html__( 'DESC', 'maple' ) => 'DESC', esc_html__( 'ASC', 'maple' ) => 'ASC' )
					),
					/* endof new order options */
					array(
						'type' => 'checkbox',
						'heading' => esc_html__( 'Hide author?', 'maple' ),
						'param_name' => 'hide_author',
						'description' => esc_html__( 'If selected, the author will not be displayed.', 'maple' ),
						'value' => array( esc_html__( 'Yes, please', 'maple' ) => 'yes' )
					),
					array(
						'type' => 'checkbox',
						'heading' => esc_html__( 'Hide company?', 'maple' ),
						'param_name' => 'hide_company',
						'description' => esc_html__( 'If selected, the company will not be displayed.', 'maple' ),
						'value' => array( esc_html__( 'Yes, please', 'maple' ) => 'yes' )
					)
				),
				'js_view' => 'VcTestimonialsView',
				'front_enqueue_js' => array(MAPLE_PLG_URL . "lib/vc_shortcodes/testimonials.js")
			) );
		
			
			
			/* 2020 social networks */
			$socials = ["facebook", "twitter", "tumblr", "stumbleupon", "flickr", "linkedin", "delicious", "skype", "digg", "vimeo-square", "deviantart", "behance", "instagram", "blogger", "wordpress", "youtube", "reddit", "rss", "soundcloud", "pinterest", "dribbble","vk","twitch","foursquare","slack","whatsapp","line","weixin","imdb","tiktok","amazon","apple","google-play","snapchat","tripadvisor"];
			$socials_labels = ["Facebook", "Twitter", "Tumblr", "StumbleUpon", "Flickr", "LinkedIn", "Delicious", "Skype", "Digg", "Vimeo", "DeviantArt", "Behance", "Instagram", "Blogger", "WordPress", "Youtube", "Reddit", "RSS", "SoundCloud", "Pinterest", "Dribbble","VK","Twitch","Foursquare","Slack","whatsapp","Line","weixin","imdb","tiktok","amazon","apple","google-play","snapchat","tripadvisor"];
			$social_networks_params = array(
				array(
					'type' => 'number',
					'heading' => esc_html__( 'Icon Size', 'maple' ),
					'param_name' => 'maple_social_network_iconsize',
					'description' => esc_html__( 'The size of the icons, in pixels.', 'maple' ),
					'value' => '16'
				),
				array(
					'type' => 'dropdown',
					'heading' => esc_html__('Alignment','maple'),
					'param_name' => 'maple_social_network_align',
					'description' => esc_html__('How to align the icons','maple'),
					'value' => array(
						esc_html__( 'Left', 'maple' ) => 'left',
						esc_html__( 'Center', 'maple' ) => 'center',
						esc_html__( 'Right', 'maple' ) => 'right'
					),
				),
				array(
					'type' => 'colorpicker',
					'heading' => esc_html__( 'Icon Color', 'maple' ),
					'param_name' => 'maple_social_network_color',
					'description' => esc_html__( 'The color of the icons', 'maple' ),
					'value' => '#000000'
				),
				array(
					'type' => 'colorpicker',
					'heading' => esc_html__( 'Icon Color Hover', 'maple' ),
					'param_name' => 'maple_social_network_colorhover',
					'description' => esc_html__( 'The color of the icons, on hover.', 'maple' ),
					'value' => "#".get_option('maple_style_color', 'a1a1a1')
				),
				array(
					'type' => 'dropdown',
					'heading' => esc_html__('Use Panel Options?','maple'),
					'param_name' => 'maple_social_network_usepaneloptions',
					'description' => wp_kses_post(__('Either to use the Social Networks defined on the <strong>Maple Options > Social Networks</strong> or custom ones.','maple')),
					'value' => array(
						esc_html__( 'Yes, please.', 'maple' ) => 'yes',
						esc_html__( 'No, thanks.', 'maple' ) => 'no'
					),
				),
			);
			foreach ($socials as $key => $social){
				array_push($social_networks_params, array(
					'type' => 'textfield',
					'heading' => esc_html__('Link to '.$socials_labels[$key], 'maple'),
					'param_name' => 'maple_social_network_'.$social,
					'dependency' => array(
						'element' => 'maple_social_network_usepaneloptions',
						'value' => 'no'
					)
				));
			}
			vc_map( array(
				'name' => esc_html__('Social Networks', 'maple'),
				"category" => 'TreeThemes Shortcodes',
				'base' => 'social_networks',
				'is_container' => false,
				'icon' => 'vc_extend_social_networks_icon',
				'params' => $social_networks_params,
			) );
			
			/* 2020 recent posts */
			$recent_posts_params = array(
				array(
					'type' => 'number',
					'heading' => esc_html__( 'Number of Posts', 'maple' ),
					'param_name' => 'maple_recent_posts_nposts',
					'description' => esc_html__('Number of posts. If set to 0 all posts will be shown.', 'maple'),
					'value' => '-1',
					'min'=> '-1',
					'step' => '1',
				),
				array(
					'type' => 'posts_cats',
					'heading' => esc_html__( 'Categories', 'maple' ),
					'param_name' => 'maple_recent_posts_posts_cats',
					'description' => esc_html__( 'Choose one or more Categories', 'maple' )
				),
				array(
					'type' => 'dropdown',
					'heading' => esc_html__('Order By','maple'),
					'param_name' => 'maple_recent_posts_orderby',
					'value' => array(
						esc_html__( 'ID', 'maple' ) => 'id',
						esc_html__( 'Title', 'maple' ) => 'title',
						esc_html__( 'Date', 'maple' ) => 'date',
						esc_html__( 'Author', 'maple' ) => 'author',
						esc_html__( 'Comment Count', 'maple' ) => 'comment_count'
					),
				),
				array(
					'type' => 'dropdown',
					'heading' => esc_html__('Order','maple'),
					'param_name' => 'maple_recent_posts_order',
					'value' => array(
						esc_html__( 'Ascendent', 'maple' ) => 'ASC',
						esc_html__( 'Descendent', 'maple' ) => 'DESC'
					),
				),
				array(
					'type' => 'dropdown',
					'heading' => esc_html__('Add Scroller ?','maple'),
					'param_name' => 'maple_recent_posts_scroller',
					'description' => esc_html__('Displays the Posts within a Scroller.','maple'),
					'value' => array(
						esc_html__( 'Yes, please.', 'maple' ) => 'yes',
						esc_html__( 'No, thanks.', 'maple' ) => 'no'
					),
				),
				array(
					'type' => 'dropdown',
					'heading' => esc_html__('Scroll Items Automatically ? ','maple'),
					'param_name' => 'maple_recent_posts_scroller_autoplay',
					'description' => esc_html__('Automatically scrolls items.','maple'),
					'value' => array(
						esc_html__( 'No, thanks.', 'maple' ) => 'no',
						esc_html__( 'Yes, please.', 'maple' ) => 'yes'
					),
					'dependency' => array(
						'element' => 'maple_recent_posts_scroller',
						'value' => 'yes'
					)
				),
				array(
					'type' => 'number',
					'heading' => esc_html__( 'Interval to Automatically Scroll Items (in miliseconds)', 'maple' ),
					'param_name' => 'maple_recent_posts_scroller_autoplay_speed',
					'value' => '5000',
					'min'=> '1000',
					'step' => '100',
					'dependency' => array(
						'element' => 'maple_recent_posts_scroller_autoplay',
						'value' => 'yes'
					)
				),
				array(
					'type' => 'dropdown',
					'heading' => esc_html__('Pause Automatic Scroll on Hover ? ','maple'),
					'param_name' => 'maple_recent_posts_scroller_pause_on_hover',
					'value' => array(
						esc_html__( 'Yes, please.', 'maple' ) => 'yes',
						esc_html__( 'No, thanks.', 'maple' ) => 'no'
					),
					'dependency' => array(
						'element' => 'maple_recent_posts_scroller_autoplay',
						'value' => 'yes'
					)
				),
				array(
					'type' => 'dropdown',
					'heading' => esc_html__('Hide Scroller Navigation Arrows ? ','maple'),
					'param_name' => 'maple_recent_posts_scroller_hidearrows',
					'value' => array(
						esc_html__( 'No, thanks.', 'maple' ) => 'no',
						esc_html__( 'Yes, please.', 'maple' ) => 'yes'
					),
					'dependency' => array(
						'element' => 'maple_recent_posts_scroller',
						'value' => 'yes'
					)
				),
				array(
					'type' => 'dropdown',
					'heading' => esc_html__('Hide Scroller Navigation ? ','maple'),
					'param_name' => 'maple_recent_posts_scroller_hidenav',
					'value' => array(
						esc_html__( 'No, thanks.', 'maple' ) => 'no',
						esc_html__( 'Yes, please.', 'maple' ) => 'yes'
					),
					'dependency' => array(
						'element' => 'maple_recent_posts_scroller',
						'value' => 'yes'
					)
				),
				array(
					'type' => 'number',
					'heading' => esc_html__( 'Posts Per Line Desktops', 'maple' ),
					'param_name' => 'maple_recent_posts_ppl_desktop',
					'value' => '3',
					'min'=> '1',
					'step' => '1'
				),
				array(
					'type' => 'number',
					'heading' => esc_html__( 'Posts Per Line Tablets', 'maple' ),
					'param_name' => 'maple_recent_posts_ppl_tablet',
					'value' => '2',
					'min'=> '1',
					'step' => '1'
				),
				array(
					'type' => 'number',
					'heading' => esc_html__( 'Posts Per Line Mobiles', 'maple' ),
					'param_name' => 'maple_recent_posts_ppl_mobile',
					'value' => '1',
					'min'=> '1',
					'step' => '1'
				),
			);
			vc_map( array(
				'name' => esc_html__('Recent Posts', 'maple'),
				"category" => 'TreeThemes Shortcodes',
				'base' => 'recent_posts',
				'is_container' => false,
				'icon' => 'vc_extend_recent_posts_icon',
				'params' => $recent_posts_params,
			) );
		}

		/*
		Shortcode logic how it should be rendered
		*/
		
		/* 2020 recent posts */
		public function maple_renderRecentPosts( $atts, $content = null ){
			
			wp_enqueue_script('ultimate-vc-addons-slick');
			
			$prefix = 'maple_recent_posts_';
			$pairs = array(
				$prefix.'nposts'					=> '-1',
				$prefix.'posts_cats'				=> '-1',
				$prefix.'orderby'					=> 'id',
				$prefix.'order'						=> 'ASC',
				$prefix.'scroller'					=> 'yes',
				$prefix.'scroller_autoplay'			=> 'no',
				$prefix.'scroller_pause_on_hover'	=> 'yes',
				$prefix.'scroller_autoplay_speed'	=> '5000',
				$prefix.'scroller_hidearrows'		=> 'no',
				$prefix.'scroller_hidenav'			=> 'no',
				$prefix.'ppl_desktop'				=> '3',
				$prefix.'ppl_tablet'				=> '2',
				$prefix.'ppl_mobile'				=> '1'
			);
			extract( shortcode_atts( $pairs, $atts ) );
			
			global $maple_recent_posts_index;
				$maple_recent_posts_index = vc_is_inline() ? uniqid() : $maple_recent_posts_index;
			
			$query_args = array(
				'post_type'				=> 'post',
				'showposts' 			=> ${$prefix.'nposts'},
				'orderby'				=> ${$prefix.'orderby'},
				'order'					=> ${$prefix.'order'},
				'post_status'			=> 'publish',
				'suppress_filters'		=> false
			);
			if (${$prefix.'posts_cats'} != -1){
				$categories = explode(",", ${$prefix.'posts_cats'});
				$catsids = array();
				foreach ($categories as $cats){
					$aux = get_term_by('slug', $cats, 'category', OBJECT);
					if (isset($aux) && isset($aux->term_id)) $catsids[] = $aux->term_id;
				}
				$query_args['category__in'] = $catsids;
			}
			
			if (!intval(${$prefix.'nposts'},10)) $query_args['showposts'] = -1;
			
			$recent_posts = get_posts( $query_args );
			
			$flex_options = array(
				'maple_widgets_flex_navigation' => get_option('maple_widgets_flex_navigation', 'on'),
				'maple_widgets_flex_controls' => get_option('maple_widgets_flex_controls', 'on'),
				'maple_widgets_flex_transition' => get_option('maple_widgets_flex_transition', 'fade'),
				'maple_widgets_flex_transition_duration' => get_option('maple_widgets_flex_transition_duration', 1000),
				'maple_widgets_flex_slide_duration' => get_option('maple_widgets_flex_slide_duration', 3500),
				'maple_widgets_flex_autoplay' => get_option('maple_widgets_flex_autoplay', 'on'),
				'maple_widgets_flex_pause_hover' => get_option('maple_widgets_flex_pause_hover', 'on')
			);
			
			$class_helper = ${$prefix.'scroller'} == 'no' ? 'without-scroller' : ''; // helps fixing the width for the gap
			
			$maple_inline_script = '';
			$output = '<div id="treethemes-recent-posts-shortcode-'.$maple_recent_posts_index.'" class="widget des_recent_posts_widget maple_recent_posts maple-recent-posts '.esc_attr($class_helper).'">';
				
				if ( ${$prefix.'scroller'} == 'yes' ){
					$uid = uniqid(rand());
					$uniqid = uniqid(rand());
					$output .= '<div id="ult-carousel-'.$uniqid.'" class="ult-carousel-wrapper ult_horizontal" data-gutter="10"><div class="ult-carousel-'.$uid.'">';
					if (function_exists('ultimate_override_shortcodes')) ultimate_override_shortcodes(10, 'no-animation');
				} else {
					wp_enqueue_style( 'maple-cpt' );
					$aux_desktop = intval(${$prefix.'ppl_desktop'},10) > 0 ? intval(${$prefix.'ppl_desktop'},10) : 3;
					$aux_tablet = intval(${$prefix.'ppl_tablet'},10) > 0 ? intval(${$prefix.'ppl_tablet'},10) : 2;
					$aux_mobile = intval(${$prefix.'ppl_mobile'},10) > 0 ? intval(${$prefix.'ppl_mobile'},10) : 1;
					$aux_margin = 1.9; /* em */ 
					$widget_style = ' #treethemes-recent-posts-shortcode-'.$maple_recent_posts_index.' .recent-posts-post{ margin: 0 '.$aux_margin.'em 3.5em !important; } #treethemes-recent-posts-shortcode-'.$maple_recent_posts_index.' .recent-posts-post{ width: calc('. 100/$aux_desktop .'% - '. $aux_margin*2 .'em); } @media (max-width: 1024px) { #treethemes-recent-posts-shortcode-'.$maple_recent_posts_index.' .recent-posts-post{ width: calc('. 100/$aux_tablet .'% - '. $aux_margin*2 .'em); } } @media (max-width: 768px) { #treethemes-recent-posts-shortcode-'.$maple_recent_posts_index.' .recent-posts-post{ width: calc('. 100/$aux_mobile .'% - '. $aux_margin*2 .'em); } }';
					wp_add_inline_style( 'maple-cpt', $widget_style );
				}
				
				foreach ($recent_posts as $post){
					$posttype = (get_post_meta($post->ID, 'posttype_value', true) == "") ? "text" : get_post_meta($post->ID, 'posttype_value', true);
					$output .= '<div class="recent-posts-post '.$posttype.' '. ( ${$prefix.'scroller'} == 'yes' ? 'ult-item-wrap' : '' ) .'" data-animation="animated no-animation">';
					
					ob_start();
					
					switch ($posttype){
						case "image": case "gallery":
							if (wp_get_attachment_url( get_post_thumbnail_id($post->ID))){
								?>
								<div class="featured-image">
									<a href="<?php echo get_permalink($post->ID); ?>" title="<?php echo wp_kses_post($post->post_title); ?>">
										<img alt="<?php echo esc_attr($post->post_title); ?>" src="<?php echo esc_url(wp_get_attachment_url( get_post_thumbnail_id($post->ID))); ?>" title="<?php echo esc_attr(get_the_title($post->ID)); ?>"/>
										<span class="post_overlay">
											<i class="fa fa-plus" aria-hidden="true"></i>
										</span>
									</a>
								</div>
								<?php
							}
						break;
						case "slider":
							$randClass = rand(0,1000);
							?>
								<div class="flexslider <?php echo esc_attr($posttype); ?>" id="treethemes-flex-<?php echo esc_attr($randClass); ?>">
									<ul class="slides">
									<?php
										$sliderData = get_post_meta($post->ID, "sliderImages_value", true);
										$slide = explode("|*|",$sliderData);
										foreach ($slide as $s){
											if ($s != ""){
												$params = explode("|!|",$s);
												if ($params[1]) echo "<li><img src='".esc_url($params[1])."' alt='' title='".esc_attr($post->post_title)."'></li>";
											}
										}
									?>
									</ul>
								</div>
							<?php
							$maple_inline_script .= '
								jQuery(document).ready(function(){
									jQuery("#treethemes-flex-'.esc_js($randClass).'.flexslider").flexslider({
										animation: "'.esc_js( $flex_options['maple_widgets_flex_transition'] ).'",
										slideshow: '. esc_js($flex_options['maple_widgets_flex_autoplay'] == 'on' ? 'true' : 'false') .',
										slideshowSpeed: '. esc_js(intval( $flex_options['maple_widgets_flex_slide_duration'], 10)) .',
										animationSpeed: '. esc_js(intval( $flex_options['maple_widgets_flex_transition_duration'], 10)) .',
										directionNav: '. esc_js($flex_options['maple_widgets_flex_navigation'] == 'on' ? 'true' : 'false') .',
										controlNav: '. esc_js($flex_options['maple_widgets_flex_controls'] == 'on' ? 'true' : 'false') .',
										pauseOnHover: '. esc_js($flex_options['maple_widgets_flex_pause_hover'] == 'on' ? 'true' : 'false') .'
									});
								});
							';
						break;
						
						case "video":
							?>
							<div class="post-video">
								<div class="video-thumb">
									<div class="video-wrapper vendor">
									<?php
										$videosType = get_post_meta($post->ID, "videoSource_value", true);
										if ($videosType != "embed"){
											$videos = get_post_meta($post->ID, "videoCode_value", true);
											$videos = preg_replace( '/\s+/', '', $videos );
											$vid = explode(",",$videos);
										}
										switch (get_post_meta($post->ID, "videoSource_value", true)){
											case "media":
												$video = explode("|!|",get_post_meta($post->ID, 'videoMediaLibrary_value', true));
												if (isset($video[1])) {
													$ext = explode(".",$video[1]);
													if (isset($ext)) $ext = $ext[count($ext)-1];
													?>
													<video controls="controls" style="width: 100%;"><source type="video/<?php echo esc_attr($ext); ?>" src="<?php echo esc_url($video[1]); ?>"></video>
													<?php
												}
											break;
											case "youtube":
												if (isset($vid[0])) echo "<iframe src='//www.youtube.com/embed/".$vid[0]."' frameborder='0' allowfullscreen></iframe>";
												break;
											case "vimeo":
												if (isset($vid[0])) echo '<iframe src="//player.vimeo.com/video/'.$vid[0].'" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>';
												break;
										}
									?>
									</div>
								</div>
							</div>
							<?php
						break;
					}
					?>
					<div class="recentpostsvc">
					<div class="title"><a href="<?php echo get_permalink($post->ID); ?>"><h4><?php echo wp_kses_post($post->post_title); ?></h4></a></div>
					
					<?php
						if ($posttype != "quote" && $posttype != "link"){
							?>
							<div class="excerpt"><p><?php
								$content = $post->post_content;
								$pos=strpos($content, '<!--more-->');
								$more_tag = '';
								if ($pos){
									$text = explode('<!--more-->', $content);
									$text = $text[0];
									$text = strip_shortcodes( $text );
									$text = apply_filters('the_content', $text);
									$text = str_replace(']]>', ']]&gt;', $text);
									echo wp_kses_post(strip_tags($text." ".$more_tag));
								} else {
									$text = strip_shortcodes( $post->post_content );
									$text = apply_filters('the_content', $text);
									$text = str_replace(']]>', ']]&gt;', $text);
									$excerpt_length = apply_filters('excerpt_length', 55);
									$excerpt_more = apply_filters('excerpt_more', ' ' . $more_tag);
									$text = wp_trim_words( $text, $excerpt_length, $excerpt_more );
									echo apply_filters('wp_trim_excerpt', strip_tags($text));
								}
								
							?>
							</p></div>
							
							<?php
							printf( '<a class="blog-read-more" href="%1$s">%2$s</a>',
								get_permalink( $post->ID ),
								sprintf(esc_html__("%s", "maple"), get_option("maple_read_more"))
							);
						
						}
					?>
					
					<?php
					
					
					$output .= ob_get_clean();
					
					$output .= '</div></div>'; // end of each post
				} // end of foreach
				
				if ( ${$prefix.'scroller'} == 'yes' ){
					$output .= '</div></div>';
					if (function_exists('ultimate_restore_shortcodes')) ultimate_restore_shortcodes();
					$maple_inline_script .= '
						jQuery(document).ready(function(){
							"use strict";
							jQuery(".ult-carousel-'.esc_js($uid).'").slick({';
								if ( ${$prefix.'scroller_hidenav'} == 'no' ) $maple_inline_script .= 'dots:true,';
								if ( ${$prefix.'scroller_autoplay'} == 'yes' ) $maple_inline_script .= 'autoplay:true,autoplaySpeed:'.intval(${$prefix.'scroller_autoplay_speed'},10).',';
								$maple_inline_script .= 'speed:1500,infinite:true,';
								if ( ${$prefix.'scroller_hidearrows'} == 'no' ) $maple_inline_script .= 'arrows:true,';
								$maple_inline_script .= 'adaptiveHeight:true,';
								if ( ${$prefix.'scroller_hidearrows'} == 'no' ){
									$maple_inline_script .= 'prevArrow:"<button type=\'button\' style=\'color: rgb(51, 51, 51); font-size: 24px; display: block;\' class=\'slick-prev default\'><i class=\'ultsl-arrow-left6\'></i></button>",nextArrow:"<button type=\'button\' style=\'color: rgb(51, 51, 51); font-size: 24px; display: block;\' class=\'slick-next default\'><i class=\'ultsl-arrow-right6\'></i></button>",';
								}
								$maple_inline_script .= 'slidesToScroll:'.esc_js(${$prefix.'ppl_desktop'}).',slidesToShow:'.esc_js(${$prefix.'ppl_desktop'}).',swipe:true,draggable:true,touchMove:true,responsive:[{breakpoint:1024,settings:{slidesToShow:'.esc_js(${$prefix.'ppl_desktop'}).',slidesToScroll:'.esc_js(${$prefix.'ppl_desktop'}).'}},{breakpoint:767,settings:{slidesToShow:'.esc_js(${$prefix.'ppl_tablet'}).',slidesToScroll:'.esc_js(${$prefix.'ppl_tablet'}).'}},{breakpoint:480,settings:{slidesToShow:'.esc_js(${$prefix.'ppl_mobile'}).',slidesToScroll:'.esc_js(${$prefix.'ppl_mobile'}).'}},{breakpoint:0,settings:{slidesToShow:'.esc_js(${$prefix.'ppl_mobile'}).',slidesToScroll:'.esc_js(${$prefix.'ppl_mobile'}).'}}],pauseOnHover:'. (${$prefix.'scroller_pause_on_hover'} == 'yes' ? 'true' : 'false' ) .',pauseOnDotsHover:'. (${$prefix.'scroller_pause_on_hover'} == 'yes' ? 'true' : 'false' ) .',mobileFirst:true,customPaging:function(slider,i){return "<i type=\'button\' style=\'color:#333333;\' class=\'ultsl-record\' data-role=\'none\'></i>";}}).on("init afterChange", function(){
										var slick = jQuery(".ult-carousel-'.esc_js($uid).'").slick("getSlick");
										var slickActives = jQuery(slick.$slides).filter(".slick-active");
										if (slickActives.length > 1){
											var currentHeight = jQuery(slick.$list).outerHeight(true),
												auxHeight = 0;
											slickActives.each(function(){
												if (jQuery(this).outerHeight(true) > auxHeight) auxHeight = jQuery(this).outerHeight(true);
											});
											if (auxHeight != currentHeight) jQuery(slick.$list, slick.$slideTrack).height( auxHeight );
										}
									}).trigger("init");
						});
					';
				} 
				
			$output .= '</div>'; // end of the shortcode
			
			wp_reset_query();
				
			$maple_recent_posts_index++;
			
			wp_add_inline_script('maple-global', $maple_inline_script, 'after');
			
			return $output;
		}
		
		/* 2020 social networks */
		public function maple_renderSocialNetworks( $atts, $content = null ){
			$prefix = 'maple_social_network_';
			
			$socials = ["facebook", "twitter", "tumblr", "stumbleupon", "flickr", "linkedin", "delicious", "skype", "digg", "vimeo-square", "deviantart", "behance", "instagram", "blogger", "wordpress", "youtube", "reddit", "rss", "soundcloud", "pinterest", "dribbble","vk","twitch","foursquare","slack","whatsapp","line","weixin","imdb","tiktok","amazon","apple","google-play","snapchat","tripadvisor"];
			$socials_labels = ["Facebook", "Twitter", "Tumblr", "StumbleUpon", "Flickr", "LinkedIn", "Delicious", "Skype", "Digg", "Vimeo", "DeviantArt", "Behance", "Instagram", "Blogger", "WordPress", "Youtube", "Reddit", "RSS", "SoundCloud", "Pinterest", "Dribbble","VK","Twitch","Foursquare","Slack","whatsapp","Line","weixin","imdb","tiktok","amazon","apple","google-play","snapchat","tripadvisor"];
			
			$pairs = array(
				$prefix.'iconsize'			=> '16',
				$prefix.'align'				=> 'left',
				$prefix.'color'				=> '#000000',
				$prefix.'colorhover'		=> '#'.get_option('maple_style_color', 'a1a1a1'),
				$prefix.'usepaneloptions'	=> 'yes'
			);
			foreach ($socials as $social) $pairs[$prefix.$social] = '';
			extract( shortcode_atts( $pairs, $atts ) );

			global $maple_social_networks_index;
				$maple_social_networks_index = vc_is_inline() ? uniqid() : $maple_social_networks_index;
			
			$output = '<div id="treethemes-social-networks-shortcode-'.$maple_social_networks_index.'" class="widget maple_socials_widget">';
				$output .= '<div class="social-icons-fa align-'.esc_attr( ${$prefix.'align'} ). '"><ul>';
				if (${$prefix.'usepaneloptions'} == "yes"){
					foreach ($socials as $key => $social){
						if (is_string(get_option("maple_icon-".$social)) && get_option("maple_icon-".$social) != "") $output .= '<li><a href="'.esc_attr(esc_url(get_option("maple_icon-".$social))).'" target="_blank" class="social-network '.$social.'" title="'.esc_attr($socials_labels[$key]).'"><i class="fab fa-'.esc_attr($social).'"></i></a></li>';
					}
				} else {
					foreach ($socials as $key => $social){
						if (isset($atts[$prefix.$social]) && $atts[$prefix.$social] != "") $output .= '<li><a href="'.esc_attr(esc_url( $atts[$prefix.$social] )).'" target="_blank" class="social-network '.$social.'" title="'.esc_attr($socials_labels[$key]).'"><i class="fab fa-'.esc_attr($social).'"></i></a></li>';
					}
				}
				$output .= '</ul></div>';
			$output .= '</div>';
			
			wp_enqueue_style( 'maple-cpt' );
			$widget_style = ' #treethemes-social-networks-shortcode-'.$maple_social_networks_index.' i:before{ font-size: '. intval(${$prefix.'iconsize'}, 10) .'px; color: '. esc_html(${$prefix.'color'}) .'; } #treethemes-social-networks-shortcode-'.$maple_social_networks_index.' i:hover:before{ color: '. esc_html(${$prefix.'colorhover'}) .'; }';
			wp_add_inline_style( 'maple-cpt', $widget_style );
			
			$maple_social_networks_index++;
			
			return $output;
		}

		
		
		public function maple_renderTestimonials( $atts, $content = null ) {
			
			wp_enqueue_script('ultimate-vc-addons-slick');
	    
		  extract( shortcode_atts( array(
			 'style_testimonials' => 'style1',
			 'testimonials_cats' => -1,
		  	 'number' => -1,
			 'hide_author' => 'no',
			 'hide_company' => 'no',
			 'des_testimonials_flex_animation' => 'slide',
			 'des_testimonials_flex_direction' => 'horizontal',
			 'des_testimonials_flex_items_desktop' => 1,
			 'des_testimonials_flex_items_small_desktop' => 1,
			 'des_testimonials_flex_items_tablet' => 1,
			 'des_testimonials_flex_items_mobile' => 1,
			 'des_testimonials_flex_slideshow' => 'yes',
			 'des_testimonials_flex_slideshow_speed' => '3500',
			 'des_testimonials_flex_animation_duration' => '1000',
			 'des_testimonials_flex_direction_nav' => 'yes',
			 'des_testimonials_flex_control_nav' => 'yes',
			 'des_testimonials_flex_pause_on_hover' => 'yes',
			 'des_testimonials_flex_nav_style' => 'dark',
			 'des_testimonials_flex_height' => '650',
			 /* 2020 */
			 'testimonials_show_image' => 'yes',
			 'testimonials_align' => 'center'
		  ), $atts ) );
	      $content = wpb_js_remove_wpautop($content, true); // fix unclosed/unwanted paragraph tags in $content

		  global $maple_testimonials_index, $maple_single_testimonial_index;
			  $maple_testimonials_index = vc_is_inline() ? uniqid() : $maple_testimonials_index;
			  $maple_single_testimonial_index = vc_is_inline() ? uniqid() : $maple_single_testimonial_index;
		  $output = "";
	  
		  if ($testimonials_cats == "0" || $testimonials_cats == -1 || $testimonials_cats == "") {
			  $args = array(
				'posts_per_page' => $number,
			  	'post_type' => 'testimonials'
			  );
			  $testimonials = get_posts($args);
		  } else {
			  $testimonials_cats = explode(",",$testimonials_cats);
			  $aux_cats = array();
  			  foreach($testimonials_cats as $t){
  			  	  $term = get_term_by( 'slug', $t, 'testimonials_category', ARRAY_A );
  			  	  if (!empty($term)){
	  			  	  $aux_cats[] = $term['term_taxonomy_id'];
  			  	  }
  			  }
  			  $testimonials_cats = $aux_cats;
			  $args = array(
				'posts_per_page' => $number,
			  	'post_type' => 'testimonials',
			  	'tax_query' => array(
			        array(
			            'taxonomy' => 'testimonials_category',
			            'field'    => 'term_id',
			            'terms'    => $testimonials_cats
			        ),
			    )
		   	  );
		   	  $testimonials = get_posts($args);
		  }
	  
		  if ($style_testimonials === "style1"){
			  $output .= '<div id="testimonials-container-'.esc_attr($maple_testimonials_index).'" class="container testimonials '.esc_attr($style_testimonials).' testimonials-align-'.esc_attr($testimonials_align).'"><div class="testimonial-box">'; 
			  
			  $first = true;
			  $maple_single_testimonial_index = 1;
			  $output .= '<ul class="testimonial-nav">';
			  foreach ($testimonials as $t){
				$output .= '<li><a href="#testimonial-'.esc_attr($maple_single_testimonial_index).'" ';
				if ($first){
					$first = false;
					$output .= ' class="active" ';
				}
				 
				/* Case testimonial without featured image*/
				$image = wp_get_attachment_image_src( get_post_thumbnail_id( $t->ID ), 'maple_mini' );
				if( !$image ){
					$output .= '';
					$output .= '';
					$output .= '" /><div class="cover-test-img"></div></a></li>';
				} else{
					$output .= '><img alt="'.esc_attr(get_the_title( $t->ID )).'" src="';
					$output .= esc_url($image[0]);
					$output .= '" /><div class="cover-test-img"></div></a></li>';
				}
				
				
				$maple_single_testimonial_index++;
			  }

			  $output .= '</ul>';
			  
			  
			  
			  
			  $maple_single_testimonial_index = 1;

			  $output .= '<div class="testimonials-content">';
			  foreach ($testimonials as $t){
				  	$active = ($maple_single_testimonial_index == 1) ? " active" : "";
					$output .= '<div class="testimonial'.esc_attr($active).'" id="testimonial-'.esc_attr($maple_single_testimonial_index).'">'.wp_kses_post($t->post_content);
					if ($hide_author === "no" && $hide_company === "no" || get_post_meta($t->ID,'author_value', true) != '' && get_post_meta($t->ID,'company_value', true) != '') { $output .= '<span class="t-author-style1">'; }
						if (get_post_meta($t->ID,'author_value', true) != ''){
							if (get_post_meta($t->ID,'author_link_value', true) != ''){ $output .= '<a href="'.esc_url(get_post_meta($t->ID,'author_link_value', true)).'">'; }
							$output .= esc_html(get_post_meta($t->ID,'author_value', true));
							if (get_post_meta($t->ID,'author_link_value', true) != ''){ $output .= '</a>'; }
						}
						if (get_post_meta($t->ID,'author_value', true) != '' && get_post_meta($t->ID,'company_value', true) != '') $output .= ' <br/> ';
						if (get_post_meta($t->ID,'company_value', true) != ''){
							if (get_post_meta($t->ID,'company_link_value', true) != ''){ $output .= '<a href="'.esc_url(get_post_meta($t->ID,'company_link_value', true)).'">'; }
							$output .= esc_html(get_post_meta($t->ID,'company_value', true));
							if (get_post_meta($t->ID,'company_link_value', true) != ''){ $output .= '</a>'; }
						}
					if ($hide_author === "no" && $hide_company === "no" || get_post_meta($t->ID,'author_value', true) != '' && get_post_meta($t->ID,'company_value', true) != '') { $output .= '</span>'; }
					$output .= '</div>';
				    $maple_single_testimonial_index++;
			  }
			  $output .= '</div>'; // end of testimonials-content

			  $output .= '</div></div>'; //end of #testimonials
		  
			  $output .= "
			  <script type=\"text/javascript\">
			  jQuery(document).ready(function(){
					var who = jQuery('#testimonials-container-".esc_js($maple_testimonials_index)."');
					who.find('.testimonials-content').height( who.find('.testimonials-content .testimonial.active > p').height() + who.find('.testimonials-content .testimonial.active > span').height() +40 );
					who.find('.testimonial-nav a').on('click', function(e){
						e.preventDefault();
					});
					who.find('.testimonial-nav a').on('mouseenter', function(){
						who.find('.testimonial-nav a').removeClass('active');
						jQuery(this).addClass('active');
						who.find('.testimonial.active').removeClass('active');
						who.find(jQuery(this).attr('href')).addClass('active');
						who.find('.testimonials-content').height( who.find('.testimonials-content .testimonial.active > p').height() + who.find('.testimonials-content .testimonial.active > span').height() +40 );
					});
			  });
			  </script>";		  
		  } else {
		  	wp_enqueue_script( 'ultimate-vc-addons-slick' );
		  	wp_enqueue_script( 'ultimate-vc-addons-appear' );
		  	wp_enqueue_script( 'ultimate-vc-addons-slick-custom' );
			
			
			$show_image_class = "";
			if ($testimonials_show_image == 'no') $show_image_class = " testimonials-hide-image ";
			
			if ($style_testimonials == "style2"){
				$output .= '<div id="testimonials-slider-'.esc_attr($maple_testimonials_index).'" class="testimonials-style2 style-'.esc_attr($des_testimonials_flex_nav_style).' testimonials-align-'.esc_attr($testimonials_align).' '.esc_attr( $show_image_class ).'"><ul class="slides styled-list"'; 
			} else {
				$output .= '<div id="testimonials-slider-'.esc_attr($maple_testimonials_index).'" class="single-wide-testimonials testimonials-style2 style-'.esc_attr($des_testimonials_flex_nav_style).' testimonials-align-'.esc_attr($testimonials_align).' '.esc_attr( $show_image_class ).'"><ul class="slides styled-list"'; 
			}
			
			$output .= ' style="max-height:'.intval($des_testimonials_flex_height,10).'px;" ';
			$output .= '>';
					
			foreach ($testimonials as $t){
				$output .= '<li class="testimonials-slide"><div class="testimonials-slide-content container"><div class="testimonilas1bg">';
			
				$image = wp_get_attachment_image_src( get_post_thumbnail_id( $t->ID ), 'maple_mini' );
				
				/* Case testimonial without featured image */
				if( !$image ){
					$output .= '<div class="img-container">';
					$output .= '</div>';
				} else{
					$output .= '<div class="img-container"><img title="'.esc_attr(get_post_meta($t->ID,'author_value', true)).'" src="'.esc_url($image[0]).'" alt="'.esc_attr(get_post_meta($t->ID,'author_value', true)).'">';
					$output .= '</div>';
				}

				
				$output .= '<div class="text-container">';
				
				$output .= '<span class="testimonials_text_content">';
				$output .= wp_kses_post($t->post_content);
				$output .= '</span>';
				$output .= '</div>';
				
				
				if ($hide_author === "no" && $hide_company === "no" || get_post_meta($t->ID,'author_value', true) != '' && get_post_meta($t->ID,'company_value', true) != '') { $output .= '<span class="t-author">'; }
				if (get_post_meta($t->ID,'author_value', true) != ''){
					if (get_post_meta($t->ID,'author_link_value', true) != ''){ $output .= '<a href="'.esc_url(get_post_meta($t->ID,'author_link_value', true)).'">'; }
					$output .= esc_html(get_post_meta($t->ID,'author_value', true));
					if (get_post_meta($t->ID,'author_link_value', true) != ''){ $output .= '</a>'; }
				}
				if (get_post_meta($t->ID,'author_value', true) != '' && get_post_meta($t->ID,'company_value', true) != '') $output .= '';
				if (get_post_meta($t->ID,'company_value', true) != ''){
					if (get_post_meta($t->ID,'company_link_value', true) != ''){ $output .= '<a href="'.esc_url(get_post_meta($t->ID,'company_link_value', true)).'">'; }
					$output .= esc_html(get_post_meta($t->ID,'company_value', true));
					if (get_post_meta($t->ID,'company_link_value', true) != ''){ $output .= '</a>'; }
				}
				if ($hide_author === "no" && $hide_company === "no" || get_post_meta($t->ID,'author_value', true) != '' && get_post_meta($t->ID,'company_value', true) != '') { $output .= '</span>'; }
				
				$output .= '</div></div></li>';
			}
			$output .= '</ul></div>';
			
			
			if ($style_testimonials == "style3"){
				$des_testimonials_flex_items_desktop = $des_testimonials_flex_items_small_desktop = $des_testimonials_flex_items_tablet = $des_testimonials_flex_items_mobile = 1;
			}
			
					
			$output .= "
			<script type=\"text/javascript\">
				jQuery(document).ready(function(){
					
					if (window.self===window.top){
						if (jQuery('body').is('.wp-admin.compose-mode')){
							return;
						}
					}
					
					var who = jQuery('#testimonials-slider-".esc_js($maple_testimonials_index)." ul.slides');
				
					var opts = ['".esc_js($des_testimonials_flex_animation)."','".esc_js($des_testimonials_flex_direction)."','".esc_js($des_testimonials_flex_slideshow)."','".esc_js($des_testimonials_flex_slideshow_speed)."','".esc_js($des_testimonials_flex_animation_duration)."','".esc_js($des_testimonials_flex_direction_nav)."','".esc_js($des_testimonials_flex_control_nav)."','".esc_js($des_testimonials_flex_pause_on_hover)."','".esc_js($des_testimonials_flex_nav_style)."','".esc_js($des_testimonials_flex_items_desktop)."','".esc_js($des_testimonials_flex_items_small_desktop)."','".esc_js($des_testimonials_flex_items_tablet)."','".esc_js($des_testimonials_flex_items_mobile)."'];
					if (opts[2] == 'yes') opts[2] = true; else opts[2] = false;
					if (opts[5] == 'yes') {
						opts[5] = true;
					} else opts[5] = false;
					if (opts[6] == 'yes') {
						opts[6] = true;
					} else opts[6] = false;
					if (opts[7] == 'yes') opts[7] = true; else opts[7] = false;
					if (opts[0] == 'fade') opts[0] = true; else opts[0] = false;
				
					who.slick({
						fade: opts[0],
						dots: opts[6], 
						autoplay: opts[2], 
						autoplaySpeed:opts[3], speed:opts[4], infinite: true,
						arrows: opts[5],
						adaptiveHeight:true,
						nextArrow:'<button type=\"button\" class=\"slick-next default\"><i class=\"ultsl-arrow-right6\"></i></button>',
						prevArrow:'<button type=\"button\" class=\"slick-prev default\"><i class=\"ultsl-arrow-left6\"></i></button>',
						swipe:true,
						draggable:true,
						touchMove:true,
						slidesToScroll: parseInt(opts[9],10),
						slidesToShow: parseInt(opts[9],10),
						responsive:[{
							breakpoint: 1024,
							settings:{
								slidesToShow: parseInt(opts[10],10),
								slidesToScroll: parseInt(opts[10],10)
							}
						},{
							breakpoint: 768,
							settings:{
								slidesToShow: parseInt(opts[11],10),
								slidesToScroll: parseInt(opts[11],10)
							}
						},{
							breakpoint: 480,
							settings:{
								slidesToShow: parseInt(opts[12],10),
								slidesToScroll: parseInt(opts[12],10)
							}
						}],
						pauseOnHover:opts[7],
						pauseOnDotsHover:opts[7],
						customPaging:function(slider,i){
							return'<i type=\"button\" class=\"ultsl-record\" data-role=\"none\"></i>';
						}
					});
				});
			</script>";
		  }
	
	      wp_reset_postdata();

		  $maple_testimonials_index++;
	      return $output;
		}

	    public function maple_renderVerticalTabs( $atts, $content = null ) {
	      extract( shortcode_atts( array(
	        'title' => '',
	        'style_vt' => 'icon',
	        'orientation' => 'vertical'
	      ), $atts ) );
		  
		  global $maple_vertical_tabs;
			  $maple_vertical_tabs = vc_is_inline() ? uniqid() : $maple_vertical_tabs;
	     
	      $content = wpb_js_remove_wpautop($content, true); // fix unclosed/unwanted paragraph tags in $content
 
		  if ($orientation === 'horizontal'){
				$tabslayout = 'col-xs-12 col-sm-12';
		  } else {
				$tabslayout = ($style_vt === 'icon') ? 'col-xs-12 col-sm-1' : 'col-xs-12 col-sm-3';  
		  }
	  
		  if ($orientation === 'horizontal'){
				$contentlayout = 'col-xs-12 col-sm-12';
		  } else {
				$contentlayout = ($style_vt === 'icon') ? 'col-xs-12 col-sm-11' : 'col-xs-12 col-sm-9';
		  }
		
	      $output = "<section class='special_tabs {$style_vt} {$orientation}'>";
		  if ($title) $output .= "<h2>".esc_html($title)."</h2>";
		  $output .= "<div class='tab-selector {$tabslayout}'></div><div class='tab-container {$contentlayout}' style='margin-left:0px;'></div>";
		  $output .= "{$content}</section>";
  
		  $maple_vertical_tabs++;
	      return $output;
	    }

		public function maple_renderVerticalTab( $atts, $content = '[vc_row_inner][vc_column_inner][/vc_column_inner][/vc_row_inner]' ) {
	      extract( shortcode_atts( array(
	        'title' => 'Tab',
			'icon' => 'fa-adjust',
	        'tab_id' => ''
	      ), $atts ) );
	      $content = wpb_js_remove_wpautop($content, true); // fix unclosed/unwanted paragraph tags in $content
		  
		  global $maple_vt_index;
			  $maple_vt_index = vc_is_inline() ? uniqid() : $maple_vt_index;
	        
		  $output = "<div class='label {$maple_vt_index}'><div class='maple_icon_special_tabs'><i class='fa {$icon}'></i></div><div class='title'><a class='special_tabs_linkage'>{$title}</a></div><div class='divider-vertical-tabs'></div></div><div class='content {$maple_vt_index}'>{$content}</div>";

		  $maple_vt_index++;
	      return $output;
	    }
	} 
}

if (!function_exists('maple_vc_before_init')){
	function maple_vc_before_init(){

		if (function_exists('vc_add_shortcode_param')){
			vc_add_shortcode_param('testimonials_cats', 'maple_testimonials_categories_settings_field');
			vc_add_shortcode_param('maple_fa', 'maple_fa_settings_field');
			/* 2020 */
			vc_add_shortcode_param('posts_cats', 'maple_posts_cats_settings_field');
		}
		if (function_exists('vc_remove_element')){
			vc_remove_element('vc_carousel');
			vc_remove_element('vc_posts_slider');
			vc_remove_element('vc_gallery');
			vc_remove_element('vc_images_carousel');
			vc_remove_element('vc_button');
			vc_remove_element('vc_cta_button');
		}

	
		if ( class_exists( 'WPBakeryShortCodesContainer' ) && !class_exists('WPBakeryShortCode_Verticaltabs')) {
			class WPBakeryShortCode_des_info_list extends WPBakeryShortCodesContainer {}
		    class WPBakeryShortCode_Verticaltabs extends WPBakeryShortCodesContainer {
				static $filter_added = false;
				public function __construct( $settings ) {
					parent::__construct( $settings );
					if ( ! self::$filter_added ) {
						$this->addFilter( 'vc_inline_template_content', 'setCustomTabId' );
						self::$filter_added = true;
					}
				}
				public function contentAdmin( $atts, $content = null ) {
					if (!isset($output)) $output = "";
					$width = $custom_markup = '';
					$shortcode_attributes = array( 'width' => '1/1' );
					foreach ( $this->settings['params'] as $param ) {
						if ( $param['param_name'] != 'content' ) {
							if ( isset( $param['value'] ) && is_string( $param['value'] ) ) {
								$shortcode_attributes[$param['param_name']] = esc_html__( $param['value'], "maple" );
							} elseif ( isset( $param['value'] ) ) {
								$shortcode_attributes[$param['param_name']] = $param['value'];
							}
						} else if ( $param['param_name'] == 'content' && $content == NULL ) {
							$content = esc_html__( $param['value'], "maple" );
						}
					}
					extract( shortcode_atts(
						$shortcode_attributes
						, $atts ) );
					preg_match_all( '/verticaltab title="([^\"]+)"(\stab_id\=\"([^\"]+)\"){0,1}/i', $content, $matches, PREG_OFFSET_CAPTURE );			
					$tab_titles = array();
					if ( isset( $matches[0] ) ) {
						$tab_titles = $matches[0];
					}
					$tmp = '';
					if ( count( $tab_titles ) ) {
						$tmp .= '<ul class="clearfix tabs_controls">';
						foreach ( $tab_titles as $tab ) {
							preg_match( '/title="([^\"]+)"(\stab_id\=\"([^\"]+)\"){0,1}/i', $tab[0], $tab_matches, PREG_OFFSET_CAPTURE );
							if ( isset( $tab_matches[1][0] ) ) {
								$tmp .= '<li><a href="#tab-' . ( isset( $tab_matches[3][0] ) ? $tab_matches[3][0] : sanitize_title( $tab_matches[1][0] ) ) . '">' . $tab_matches[1][0] . '</a></li>';
	
							}
						}
						$tmp .= '</ul>' . "\n";
					} else {
						$output .= do_shortcode( $content );
					}
					$elem = $this->getElementHolder( $width );
					$iner = '';
					foreach ( $this->settings['params'] as $param ) {
						$custom_markup = '';
						$param_value = isset($param) && isset( $param['param_name'] ) ? $param['param_name'] : '';
						if ( is_array( $param_value ) ) {
							reset( $param_value );
							$first_key = key( $param_value );
							$param_value = $param_value[$first_key];
						}
						$iner .= $this->singleParamHtmlHolder( $param, $param_value );
					}
					if ( isset( $this->settings["custom_markup"] ) && $this->settings["custom_markup"] != '' ) {
						if ( $content != '' ) {
							$custom_markup = str_ireplace( "%content%", $tmp . $content, $this->settings["custom_markup"] );
						} else if ( $content == '' && isset( $this->settings["default_content_in_template"] ) && $this->settings["default_content_in_template"] != '' ) {
							$custom_markup = str_ireplace( "%content%", $this->settings["default_content_in_template"], $this->settings["custom_markup"] );
						} else {
							$custom_markup = str_ireplace( "%content%", '', $this->settings["custom_markup"] );
						}
						$iner .= do_shortcode( $custom_markup );
					}
					$elem = str_ireplace( '%wpb_element_content%', $iner, $elem );
					$output = $elem;
					return $output;
				}
				public function getTabTemplate() {
					return '<div class="wpb_template">' . do_shortcode( '[verticaltab title="" tab_id="" icon=""][/verticaltab]' ) . '</div>';
				}
				public function setCustomTabId( $content ) {
					return preg_replace( '/tab\_id\=\"([^\"]+)\"/', 'tab_id="$1-' . time() . '"', $content );
				}
	
		    }
		}
	
	
		if ( class_exists('WPBakeryShortCodesContainer') && !class_exists('WPBakeryShortCode_Verticaltab')){
			class WPBakeryShortCode_Verticaltab extends WPBakeryShortCodesContainer {
				protected $predefined_atts = array(
					'tab_id' => '',
					'icon' => 'fa-adjust',
					'title' => ''
				);
	
				public function __construct( $settings ) {
					parent::__construct( $settings );
				}
	
				public function customAdminBlockParams() {
					return ' id="tab-' . esc_attr($this->atts['tab_id']) . '"';
				}
	
				public function mainHtmlBlockParams( $width, $i ) {
					return 'data-element_type="' . esc_attr($this->settings["base"]) . '" class="wpb_' . esc_attr($this->settings['base']) . ' wpb_sortable wpb_content_holder"' . $this->customAdminBlockParams();
				}
	
				public function containerHtmlBlockParams( $width, $i ) {
					return 'class="wpb_column_container vc_container_for_children"';
				}
			}
		}
		
		if (class_exists('WPBakeryVisualComposerAbstract')){
			if (!function_exists('treethemes_vc_library_cat_list')){
				function treethemes_vc_library_cat_list() {
					return array( __('All','maple') => 'all', 
						__('About & Team','maple') => 'about', 
						__('Contact & Maps','maple') => 'contactforms', 						
						__('General','maple') => 'general',  
						__('Portfolio','maple') => 'portfolio',
						__('Pricing','maple') => 'pricing',
						__('Services','maple') => 'services',
						__('Testimonials','maple') => 'testimonials');
				}
			}
		
			if(!function_exists('add_treethemes_studio_to_vc')) {
				function add_treethemes_vc_modules_to_vc() {
					if (is_admin()) { 
						require_once ('lib/treethemes-vc-modules/treethemes-vc-modules-templates.php');
						wp_enqueue_style( 'treethemes-vc-modules', plugins_url('lib/treethemes-vc-modules/treethemes-vc-modules.css', __FILE__), 'all' );
					}
				}
			}
		
			add_treethemes_vc_modules_to_vc();
		}
		
		
	}
}


add_action('vc_before_init', 'maple_vc_before_init');

if (!function_exists('maple_add_increase_time')){
	function maple_add_increase_time(){
		@ini_set( 'max_execution_time', '300' );
	}
}

add_filter('widget_text', 'do_shortcode');

?>