public function import_post_settings()
 {
     global $wpdb;
     $post_types = array("post", "page");
     $querydata = new WP_Query(array('posts_per_page' => -1, 'post_status' => 'publish', 'post_type' => $post_types));
     $translation_settings_map = array();
     $translation_settings_map['essb_position'] = 'complex';
     $translation_settings_map['essb_theme'] = 'essb_post_template';
     $translation_settings_map['essb_names'] = 'complex';
     $translation_settings_map['essb_counter'] = 'essb_post_counters';
     $translation_settings_map['essb_counter_pos'] = 'essb_post_counter_pos';
     $translation_settings_map['essb_total_counter_pos'] = 'essb_post_total_counter_pos';
     $translation_settings_map['essb_hidefb'] = 'complex';
     $translation_settings_map['essb_hideplusone'] = 'complex';
     $translation_settings_map['essb_hidevk'] = 'complex';
     $translation_settings_map['essb_hidetwitter'] = 'complex';
     $translation_settings_map['essb_hideyoutube'] = 'complex';
     $translation_settings_map['essb_hidepinfollow'] = 'complex';
     $translation_settings_map['essb_another_display_sidebar'] = 'essb_post_button_position_sidebar';
     $translation_settings_map['essb_another_display_popup'] = 'essb_post_button_position_popup';
     $translation_settings_map['essb_another_display_postfloat'] = 'essb_post_button_position_postfloat';
     $translation_settings_map['essb_another_display_flyin'] = 'essb_post_button_position_flyin';
     $translation_settings_map['essb_activate_customizer'] = 'essb_post_animations';
     $translation_settings_map['essb_opt_by_bp'] = 'essb_post_optionsbp';
     $translation_settings_map['essb_animation'] = 'essb_post_animations';
     $translation_settings_map['essb_activate_nativeskinned'] = 'essb_post_native_skin';
     if ($querydata->have_posts()) {
         while ($querydata->have_posts()) {
             $querydata->the_post();
             global $post;
             $post_id = $post->ID;
             foreach ($translation_settings_map as $old_key => $new_key) {
                 $value = get_post_meta($post_id, $old_key, true);
                 if (empty($value)) {
                     continue;
                 }
                 if ($old_key == "essb_theme") {
                     $value = ESSBCoreHelper::template_folder($value);
                 }
                 if ($new_key != 'complex') {
                     if ($value == '0') {
                         $value = 'no';
                     }
                     if ($value == '1') {
                         $value = 'yes';
                     }
                     $this->save_metabox_value_simple($post_id, $new_key, $value);
                 } else {
                     switch ($old_key) {
                         case "essb_position":
                             break;
                         case "essb_names":
                             $new_value = "";
                             if ($value == "0") {
                                 $new_value = "button";
                             } else {
                                 $new_value = "icon_hover";
                             }
                             $this->save_metabox_value_simple($post_id, 'essb_post_button_style', $new_value);
                             break;
                         case "essb_hidefb":
                         case "essb_hideplusone":
                         case "essb_hidevk":
                         case "essb_hidetwitter":
                         case "essb_hideyoutube":
                         case "essb_hidepinfollow":
                             if ($value == "1") {
                                 $this->save_metabox_value_simple($post_id, 'essb_post_native', 'no');
                             }
                             break;
                         case "essb_position":
                             if ($value == "top" || $value == "bottom" || $value == "both" || $value == "float") {
                                 $this->save_metabox_value_simple($post_id, 'essb_post_content_position', 'content_' . $value);
                             } else {
                                 if ($value == 'likeshare') {
                                     $this->save_metabox_value_simple($post_id, 'essb_post_content_position', 'content_nativeshare');
                                 } else {
                                     if ($value == 'sharelike') {
                                         $this->save_metabox_value_simple($post_id, 'essb_post_content_position', 'content_sharenative');
                                     } else {
                                         $this->save_metabox_value_simple($post_id, 'essb_post_content_position', 'no');
                                         if ($value == 'sidebar') {
                                             $this->save_metabox_value_simple($post_id, 'essb_post_button_position_sidebar', 'yes');
                                         }
                                         if ($value == 'popup') {
                                             $this->save_metabox_value_simple($post_id, 'essb_post_button_position_popup', 'yes');
                                         }
                                         if ($value == 'flyin') {
                                             $this->save_metabox_value_simple($post_id, 'essb_post_button_position_flyin', 'yes');
                                         }
                                         if ($value == 'postfloat') {
                                             $this->save_metabox_value_simple($post_id, 'essb_post_button_position_postfloat', 'yes');
                                         }
                                     }
                                 }
                             }
                             break;
                     }
                 }
             }
         }
     }
 }
    public static function draw_buttons_start($style = array(), $position = '', $salt = '', $like_or_share = 'share', $share = array(), $cached_counters = array())
    {
        global $essb_options;
        $network_hidden_name_class = "";
        if ($style['button_style'] == "icon_hover") {
            $network_hidden_name_class = " essb_hide_name";
        }
        if ($style['button_style'] == "icon") {
            $network_hidden_name_class = " essb_force_hide_name essb_force_hide";
        }
        if ($style['button_style'] == "button_name") {
            $network_hidden_name_class = " essb_hide_icon";
        }
        $template = ESSBCoreHelper::template_folder($style['template']);
        $instance_template = $template;
        if ($template != '') {
            $template = " essb_template_" . $template;
        }
        $use_legacy_lass = ESSBGlobalSettings::$legacy_class;
        //ESSBOptionValuesHelper::options_bool_value($essb_options, 'legacy_class');
        // TODO: implement all other width styles
        $css_class_width = "";
        if ($style['button_width'] == "fixed") {
            $fixedwidth_key = $style['button_width_fixed_value'] . "_" . $style['button_width_fixed_align'];
            $css_class_width = " essb_fixedwidth_" . $fixedwidth_key;
        }
        if ($style['button_width'] == "full") {
            $container_width = $style['button_width_full_container'];
            $single_button_width = intval($container_width) / intval($style['included_button_count']);
            $single_button_width = floor($single_button_width);
            //print_r($style);
            $css_class_width = " essb_fullwidth_" . $single_button_width . '_' . $style['button_width_full_button'] . '_' . $style['button_width_full_container'];
            if ($style['fullwidth_align'] == "center") {
                $css_class_width .= " essb_network_align_center";
            }
            if ($style['fullwidth_align'] == "right") {
                $css_class_width .= " essb_network_align_right";
                $style['button_align'] = "left";
            }
            if ($style['fullwidth_align'] == "left") {
                $style['button_align'] = "left";
            }
        }
        if ($style['button_width'] == "column") {
            $css_class_width = " essb_width_columns_" . $style['button_width_columns'];
            if ($style['fullwidth_share_buttons_columns_align'] == "center") {
                $css_class_width .= " essb_network_align_center";
            }
            if ($style['fullwidth_share_buttons_columns_align'] == "right") {
                $css_class_width .= " essb_network_align_right";
            }
        }
        $css_class_align = "";
        if ($style['button_align'] == "right") {
            $css_class_align = " essb_links_right";
        }
        if ($style['button_align'] == "center") {
            $css_class_align = " essb_links_center";
        }
        // modern counter style
        $essb_css_modern_counter_class = "";
        if ($style['counter_pos'] == 'leftm') {
            $style['counter_pos'] = 'left';
            $essb_css_modern_counter_class = ' essb_counter_modern_left';
        }
        if ($style['counter_pos'] == 'rightm') {
            $style['counter_pos'] = 'right';
            $essb_css_modern_counter_class = ' essb_counter_modern_right';
        }
        if ($style['counter_pos'] == 'top') {
            $style['counter_pos'] = 'left';
            $essb_css_modern_counter_class = ' essb_counter_modern_top';
        }
        if ($style['counter_pos'] == 'topm') {
            $style['counter_pos'] = 'left';
            $essb_css_modern_counter_class = ' essb_counter_modern_top_mini';
        }
        if ($style['counter_pos'] == "bottom") {
            $essb_css_modern_counter_class = ' essb_counter_modern_bottom';
        }
        if ($style['counter_pos'] == "topn") {
            $essb_css_modern_counter_class = ' essb_counter_modern_topn';
        }
        if (isset($style['button_animation'])) {
            if ($style['button_animation'] != '' && $style['button_animation'] != 'no') {
                $css_class_align .= ' ' . $style['button_animation'];
            }
        }
        $counter_class = $style['show_counter'] ? " essb_counters" : "";
        $total_text = ESSBGlobalSettings::$counter_total_text;
        //ESSBOptionValuesHelper::options_value($essb_options, 'counter_total_text');
        if (empty($total_text)) {
            $total_text = __('Total: ', ESSB3_TEXT_DOMAIN);
        }
        $css_hide_total_counter = "";
        if ($style['total_counter_hidden_till'] != '') {
            $css_hide_total_counter = ' style="display: none !important;" data-essb-hide-till="' . $style['total_counter_hidden_till'] . '"';
        }
        $cached_total_counter = '';
        if (defined('ESSB3_CACHED_COUNTERS')) {
            $cached_total_counter = isset($cached_counters['total']) ? $cached_counters['total'] : '0';
            if ($style['total_counter_hidden_till'] != '') {
                if (intval($cached_total_counter) > intval($style['total_counter_hidden_till'])) {
                    $css_hide_total_counter = "";
                }
            }
            $cached_total_counter = ESSBButtonHelper::kilomega($cached_total_counter);
        }
        $css_class_nospace = $style['nospace'] ? " essb_nospace" : "";
        $css_class_nostats = "";
        if (isset($style['nostats'])) {
            $css_class_nostats = $style['nostats'] ? " essb_nostats" : "";
        }
        $like_share_position = $like_or_share == "share" ? " essb_share" : " essb_native";
        $links_start = "";
        $key_position = $position;
        if ($position == "sidebar") {
            $current_sidebar_pos = ESSBOptionValuesHelper::options_value($essb_options, 'sidebar_pos');
            if (!empty($style['sidebar_pos'])) {
                $current_sidebar_pos = $style['sidebar_pos'];
            }
            if ($current_sidebar_pos != '' && $current_sidebar_pos != 'left') {
                $key_position .= "_" . $current_sidebar_pos;
            }
        }
        if ($use_legacy_lass) {
            if ($position == "bottombar") {
                $key_position .= ' essb_displayed_sidebar_bottom';
            }
            if ($position == "topbar") {
                $key_position .= ' essb_displayed_sidebar_top';
            }
        }
        $counter_url = $share['url'];
        $counter_full_url = $share['full_url'];
        if (!defined('ESSB3_LIGHTMODE')) {
            $ga_tracking_code = ESSBGlobalSettings::$activate_ga_campaign_tracking;
            //ESSBOptionValuesHelper::options_value($essb_options, 'activate_ga_campaign_tracking');
            if ($ga_tracking_code != '' || strpos($counter_url, '{network}') !== false) {
                $post_ga_campaign_tracking = get_post_meta(get_the_ID(), 'essb_activate_ga_campaign_tracking', true);
                if ($post_ga_campaign_tracking != '') {
                    $ga_tracking_code = $post_ga_campaign_tracking;
                }
                $ga_tracking_code = str_replace('&', '%26', $ga_tracking_code);
                $counter_url = str_replace($ga_tracking_code, '', $counter_url);
                $counter_full_url = str_replace('{network}', 'twitter', $counter_full_url);
                $counter_full_url = str_replace('{title}', '', $counter_full_url);
            }
        }
        $links_start = sprintf('<div class="essb_links%1$s%2$s essb_displayed_%3$s%4$s%5$s essb_%6$s%13$s%14$s%15$s%16$s print-no" 
				id="essb_displayed_%3$s_%6$s" data-essb-postid="%7$s" data-essb-position="%3$s" data-essb-button-style="%8$s" 
				data-essb-template="%9$s" data-essb-counter-pos="%10$s" data-essb-url="%11$s" data-essb-twitter-url="%12$s" data-essb-instance="%6$s">', $counter_class, $essb_css_modern_counter_class, $key_position, $like_share_position, $template, $salt, $share['post_id'], $style['button_style'], $instance_template, $style['counter_pos'], $counter_url, $counter_full_url, $css_class_width, $css_class_align, $css_class_nospace, $css_class_nostats);
        $deactivate_message_for_location = ESSBOptionValuesHelper::options_bool_value($essb_options, $position . '_text_deactivate');
        //@since 3.4.2 - deactivate message before share buttons on mobile display methods
        if ($position == "sharebottom" || $position == "sharebar" || $position == "sharepoint") {
            $deactivate_message_for_location = true;
        }
        if ($deactivate_message_for_location) {
            $style['message_share_before_buttons'] = '';
            $style['message_share_buttons'] = '';
        }
        if ($like_or_share == "share" && $style['message_share_buttons'] != '') {
            $style['message_share_buttons'] = preg_replace(array('#%title%#', '#%siteurl%#', '#%permalink%#', '#%image%#', '#%shorturl%#'), array($share['title'], get_site_url(), $share['url'], $share['image'], $share['short_url']), $style['message_share_buttons']);
            $style['message_share_buttons'] = do_shortcode(stripslashes($style['message_share_buttons']));
            $links_start .= sprintf('<div class="essb_message_above_share">%1$s</div>', stripslashes($style['message_share_buttons']));
            //print "links_start state = ".$links_start;
        }
        $links_start .= sprintf('<ul class="essb_links_list%1$s">', $network_hidden_name_class);
        // generating share buttons template start
        if ($like_or_share == "share" && $style['message_share_before_buttons'] != '') {
            $style['message_share_before_buttons'] = preg_replace(array('#%title%#', '#%siteurl%#', '#%permalink%#', '#%image%#', '#%shorturl%#'), array($share['title'], get_site_url(), $share['url'], $share['image'], $share['short_url']), $style['message_share_before_buttons']);
            $style['message_share_before_buttons'] = do_shortcode(stripslashes($style['message_share_before_buttons']));
            $links_start .= sprintf('<li class="essb_message_before">%1$s</li>', stripslashes($style['message_share_before_buttons']));
        }
        if ($like_or_share == "share" && $style['show_counter']) {
            if ($style['total_counter_pos'] == "left" || $style['total_counter_pos'] == "leftbig" || $style['total_counter_pos'] == "before" || $style['total_counter_pos'] == "hidden") {
                // left
                if ($style['total_counter_pos'] == "left" || $style['total_counter_pos'] == "hidden") {
                    $links_start .= '<li class="essb_item essb_totalcount_item" ' . ($style['total_counter_pos'] == "hidden" ? 'style="display: none !important;"' : '') . $css_hide_total_counter . ' data-counter-pos="' . $style['counter_pos'] . '"><span class="essb_totalcount essb_t_l"  title="' . $total_text . '"><span class="essb_t_nb">' . $cached_total_counter . '</span></span></li>';
                }
                if ($style['total_counter_pos'] == "leftbig") {
                    $links_start .= '<li class="essb_item essb_totalcount_item" ' . ($style['total_counter_pos'] == "hidden" ? 'style="display: none !important;"' : '') . $css_hide_total_counter . ' data-counter-pos="' . $style['counter_pos'] . '"><span class="essb_totalcount essb_t_l_big" title=""><span class="essb_t_nb">' . $cached_total_counter . '</span></span></li>';
                }
                if ($style['total_counter_pos'] == "before") {
                    $userbased_text = $style['total_counter_afterbefore_text'];
                    if ($userbased_text == '') {
                        $userbased_text = '{TOTAL} shares';
                    }
                    $userbased_text = str_replace('{TOTAL}', '<span class="essb_t_nb">' . $cached_total_counter . '</span>', $userbased_text);
                    $links_start .= '<li class="essb_item essb_totalcount_item essb_totalcount_item_before" ' . ($style['total_counter_pos'] == "hidden" ? 'style="display: none !important;"' : '') . $css_hide_total_counter . ' data-counter-pos="' . $style['counter_pos'] . '"><span class="essb_totalcount essb_t_before" title="">' . $userbased_text . '</span></li>';
                }
            }
        }
        // ESSB Post Views add-on bridge
        // @since 3.5
        if (defined('ESSB3_POSTVIEWS_ACTIVE')) {
            $postviews_position = essb_postview_position($position, $style['total_counter_pos']);
            if (!empty($style['postviews'])) {
                $postviews_position = essb_postviews_position_from_shortcode($style['postviews'], $style['total_counter_pos']);
            }
            if ($postviews_position == 'left') {
                $links_start .= essb_generate_views_code($share['post_id'], $postviews_position);
            }
        }
        return $links_start;
    }
    function generate_share_buttons($position, $likeshare = 'share', $share_options = array(), $is_shortcode = false, $shortcode_options = array(), $media_url = '')
    {
        global $post;
        //timer_start();
        // @since 3.5 - runtime cache
        $cache_key_runtime = "";
        if (ESSBGlobalSettings::$cache_runtime) {
            if (isset($post) && !$is_shortcode) {
                $cache_key_runtime = sprintf('essb_cache_share_%1$s_%2$s', $post->ID, $position);
                $cached_data = wp_cache_get($cache_key_runtime);
                if (false !== $cached_data) {
                    return $cached_data;
                }
            }
        }
        $only_share = ESSBOptionValuesHelper::options_bool_value($share_options, 'only_share');
        $post_type = ESSBOptionValuesHelper::options_value($share_options, 'post_type');
        if ($this->general_options['reset_postdata']) {
            wp_reset_postdata();
        }
        $cache_key = "";
        if (isset($post) && defined('ESSB3_CACHE_ACTIVE') && !$is_shortcode) {
            $cache_key = sprintf('essb_cache_share_%1$s_%2$s', $post->ID, $position);
            $cached_data = ESSBDynamicCache::get($cache_key);
            if (!empty($cached_data)) {
                return $cached_data;
            }
        }
        if (empty($post_type) && isset($post)) {
            $post_type = $post->post_type;
        }
        // -- getting main share details based on current post
        $post_share_details = $this->get_post_share_details($position);
        // generate native button main settings
        $post_native_details = $this->get_native_button_settings($position, $only_share);
        $post_native_details['order'] = $post_native_details['active'] ? ESSBNativeButtonsHelper::active_native_buttons() : array();
        // apply shortcode options
        if ($is_shortcode) {
            if ($shortcode_options['forceurl']) {
                $post_share_details['url'] = ESSBUrlHelper::get_current_page_url();
            }
            if ($shortcode_options['url'] != '') {
                $post_share_details['url'] = $shortcode_options['url'];
            }
            if ($shortcode_options['title'] != '') {
                $post_share_details['title'] = $shortcode_options['title'];
                $post_share_details['title_plain'] = $shortcode_options['title'];
            }
            if ($shortcode_options['image'] != '') {
                $post_share_details['image'] = $shortcode_options['image'];
            }
            if ($shortcode_options['description'] != '') {
                $post_share_details['description'] = $shortcode_options['description'];
            }
            // customize tweet message
            if ($shortcode_options['twitter_user'] != '') {
                $post_share_details['twitter_user'] = $shortcode_options['twitter_user'];
            }
            if ($shortcode_options['twitter_hashtags'] != '') {
                $post_share_details['twitter_hashtags'] = $shortcode_options['twitter_hashtags'];
            }
            if ($shortcode_options['twitter_tweet'] != '') {
                $post_share_details['twitter_tweet'] = $shortcode_options['twitter_tweet'];
            } else {
                if ($shortcode_options['title'] != '') {
                    $post_share_details['twitter_tweet'] = $shortcode_options['title'];
                }
            }
            $affwp_active_shortcode = ESSBOptionValuesHelper::options_bool_value($this->options, 'affwp_active_shortcode');
            if ($affwp_active_shortcode) {
                $post_share_details['url'] = ESSBUrlHelper::generate_affiliatewp_referral_link($post_share_details['url']);
            }
            $affs_active_shortcode = ESSBOptionValuesHelper::options_bool_value($this->options, 'affs_active_shortcode');
            if ($affs_active_shortcode) {
                $post_share_details['url'] = do_shortcode('[affiliates_url]' . $post_share_details['url'] . '[/affiliates_url]');
            }
            if (isset($shortcode_options['query'])) {
                $post_share_details['query'] = $shortcode_options['query'];
            }
        } else {
            // activate short url and custom campaign tracking codes
            // apply custom share options
            if (!empty($share_options['url'])) {
                $post_share_details['url'] = $share_options['url'];
            }
            if (!empty($share_options['title'])) {
                $post_share_details['title'] = $share_options['title'];
                $post_share_details['title_plain'] = $share_options['title_plain'];
            }
            if (!empty($share_options['image'])) {
                $post_share_details['image'] = $share_options['image'];
            }
            if (!empty($share_options['description'])) {
                $post_share_details['description'] = $share_options['description'];
            }
            // customize tweet message
            if (!empty($share_options['twitter_user'])) {
                $post_share_details['twitter_user'] = $share_options['twitter_user'];
            }
            if (!empty($share_options['twitter_hashtags'])) {
                $post_share_details['twitter_hashtags'] = $share_options['twitter_hashtags'];
            }
            if (!empty($share_options['twitter_tweet'])) {
                $post_share_details['twitter_tweet'] = $share_options['twitter_tweet'];
            }
            if ($media_url != '') {
                $post_share_details['image'] = $media_url;
                $post_share_details['user_image_url'] = $media_url;
            }
            if (!defined('ESSB3_LIGHTMODE')) {
                // Google Campaign Tracking code
                $ga_campaign_tracking = $this->general_options['activate_ga_campaign_tracking'];
                $post_ga_campaign_tracking = get_post_meta(get_the_ID(), 'essb_activate_ga_campaign_tracking', true);
                if ($post_ga_campaign_tracking != '') {
                    $ga_campaign_tracking = $post_ga_campaign_tracking;
                }
                if ($ga_campaign_tracking != '') {
                    $post_share_details['url'] = ESSBUrlHelper::attach_tracking_code($post_share_details['url'], $ga_campaign_tracking);
                }
            }
        }
        // @since 3.1.2 exist filter to control the share address
        if (has_filter('essb3_share_url')) {
            $post_share_details['url'] = apply_filters('essb3_share_url', $post_share_details['url']);
        }
        // -- short url code block
        // code refactor @since 3.4.2
        $post_share_details['full_url'] = $post_share_details['url'];
        if ($this->general_options['shorturl_activate']) {
            $global_provider = $this->general_options['shorturl_type'];
            // generating short urls only for selected networks
            if ($this->network_options['twitter_shareshort']) {
                $generated_shorturl = ESSBUrlHelper::short_url($post_share_details['url'], $global_provider, get_the_ID(), $this->general_options['shorturl_bitlyuser'], $this->general_options['shorturl_bitlyapi']);
                $post_share_details['short_url_twitter'] = $generated_shorturl;
                $post_share_details['short_url_whatsapp'] = $generated_shorturl;
            } else {
                // generate short url for all networks
                $post_share_details['short_url'] = ESSBUrlHelper::short_url($post_share_details['url'], $global_provider, get_the_ID(), $this->general_options['shorturl_bitlyuser'], $this->general_options['shorturl_bitlyapi']);
                $post_share_details['short_url_twitter'] = $post_share_details['short_url'];
                $post_share_details['short_url_whatsapp'] = $post_share_details['short_url'];
            }
            if (empty($post_share_details['short_url'])) {
                $post_share_details['short_url'] = $post_share_details['url'];
            }
            if (empty($post_share_details['short_url_twitter'])) {
                $post_share_details['short_url_twitter'] = $post_share_details['url'];
            }
            if (empty($post_share_details['short_url_whatsapp'])) {
                $post_share_details['short_url_whatsapp'] = $post_share_details['url'];
            }
        } else {
            $post_share_details['short_url'] = $post_share_details['url'];
            $post_share_details['short_url_twitter'] = $post_share_details['url'];
            $post_share_details['short_url_whatsapp'] = $post_share_details['url'];
        }
        //-- end: short url code block
        // -- main button design
        $button_style = $this->get_buttons_visual_options($position);
        $social_networks = $this->network_options['networks'];
        $social_networks_order = $this->network_options['networks_order'];
        $social_networks_names = $this->network_options['default_names'];
        // apply settings based on position when active
        $check_position_settings_key = $position;
        if (essb_is_mobile() && ESSBOptionValuesHelper::is_active_position_settings('mobile')) {
            $check_position_settings_key = 'mobile';
        }
        if (essb_is_mobile()) {
            if (ESSBGlobalSettings::$mobile_networks_active) {
                $social_networks = ESSBGlobalSettings::$mobile_networks;
            }
            if (ESSBGlobalSettings::$mobile_networks_order_active) {
                $social_networks_order = ESSBGlobalSettings::$mobile_networks_order;
            }
        }
        // double check to avoid missconfiguration based on mobile specific settings
        if ($check_position_settings_key != 'sharebar' && $check_position_settings_key != 'sharepoint' && $check_position_settings_key != 'sharebottom') {
            // first check for post type settins - if there are such that will be the settings key. If nothing is active switch to button position
            // settings
            if (!defined('ESSB3_LIGHTMODE')) {
                if (!empty($post_type)) {
                    if (ESSBOptionValuesHelper::is_active_position_settings(sprintf('post-type-%1$s', $post_type))) {
                        $check_position_settings_key = sprintf('post-type-%1$s', $post_type);
                    }
                }
            }
            // postbar settings that are over the setup
            if ($position == 'postbar') {
                $button_style = ESSBOptionValuesHelper::apply_postbar_position_style_settings('postbar', $button_style);
                $instance_template = $button_style['template'];
                $instance_template_slug = ESSBCoreHelper::template_folder($instance_template);
                // @since 3.4.2 - add check to avoid load of blank templates
                if ($instance_template_slug != $this->design_options['template_slug'] && !empty($instance_template_slug)) {
                    $use_minifed_css = $this->general_options['use_minified_css'] ? ".min" : "";
                    $template_url = ESSB3_PLUGIN_URL . '/assets/css/' . $instance_template_slug . '/easy-social-share-buttons' . $use_minifed_css . '.css';
                    essb_resource_builder()->add_static_footer_css($template_url, 'easy-social-share-buttons-' . $instance_template_slug);
                }
            }
            if (ESSBOptionValuesHelper::is_active_position_settings($check_position_settings_key)) {
                $button_style = ESSBOptionValuesHelper::apply_position_style_settings($check_position_settings_key, $button_style);
                $instance_template = $button_style['template'];
                $instance_template_slug = ESSBCoreHelper::template_folder($instance_template);
                // @since 3.4.2 - add check to avoid load of blank templates
                if ($instance_template_slug != $this->design_options['template_slug'] && !empty($instance_template_slug)) {
                    $use_minifed_css = $this->general_options['use_minified_css'] ? ".min" : "";
                    $template_url = ESSB3_PLUGIN_URL . '/assets/css/' . $instance_template_slug . '/easy-social-share-buttons' . $use_minifed_css . '.css';
                    essb_resource_builder()->add_static_footer_css($template_url, 'easy-social-share-buttons-' . $instance_template_slug);
                }
                if ($check_position_settings_key != 'mobile') {
                    $personalized_networks = ESSBOptionValuesHelper::get_active_social_networks_by_position($check_position_settings_key);
                    $personalized_network_order = ESSBOptionValuesHelper::get_order_of_social_networks_by_position($check_position_settings_key);
                    if (is_array($personalized_networks) && count($personalized_networks) > 0) {
                        $social_networks = $personalized_networks;
                    }
                    if (is_array($personalized_network_order) && count($personalized_network_order) > 0) {
                        $social_networks_order = $personalized_network_order;
                    }
                }
                $social_networks_names = ESSBOptionValuesHelper::apply_position_network_names($check_position_settings_key, $social_networks_names);
            } else {
                if (defined('ESSB3_LIGHTMODE')) {
                    if (ESSBLightModeHelper::position_with_predefined_options($position)) {
                        $button_style = ESSBLightModeHelper::apply_position_predefined_settings($position, $button_style);
                    }
                }
            }
        }
        // apply safe default of mobile styles to avoid miss configured display
        $share_bottom_networks = array();
        if ($position == 'sharebar' || $position == 'sharepoint' || $position == 'sharebottom') {
            $post_native_details['active'] = false;
            // apply mobile personalizations by display methods
            if (ESSBOptionValuesHelper::is_active_position_settings($position)) {
                $button_style = ESSBOptionValuesHelper::apply_mobile_position_style_settings($position, $button_style);
                $instance_template = $button_style['template'];
                $instance_template_slug = ESSBCoreHelper::template_folder($instance_template);
                if ($instance_template_slug != $this->design_options['template_slug']) {
                    $use_minifed_css = $this->general_options['use_minified_css'] ? ".min" : "";
                    $template_url = ESSB3_PLUGIN_URL . '/assets/css/' . $instance_template_slug . '/easy-social-share-buttons' . $use_minifed_css . '.css';
                    essb_resource_builder()->add_static_footer_css($template_url, 'easy-social-share-buttons-' . $instance_template_slug);
                }
                $personalized_networks = ESSBOptionValuesHelper::get_active_social_networks_by_position($position);
                $personalized_network_order = ESSBOptionValuesHelper::get_order_of_social_networks_by_position($position);
                if (is_array($personalized_networks) && count($personalized_networks) > 0) {
                    $social_networks = $personalized_networks;
                }
                if (is_array($personalized_network_order) && count($personalized_network_order) > 0) {
                    $social_networks_order = $personalized_network_order;
                }
                $social_networks_names = ESSBOptionValuesHelper::apply_position_network_names($position, $social_networks_names);
            }
            // apply sharebar and sharepoint default styles
            if ($position == 'sharebar' || $position == 'sharepoint') {
                // for those display methods the more buttons is not needed
                if (in_array('more', $social_networks)) {
                    if (($key = array_search('more', $social_networks)) !== false) {
                        unset($social_networks[$key]);
                    }
                }
                $button_style['button_style'] = "button";
                if ($button_style['show_counter']) {
                    if (strpos($button_style['counter_pos'], 'inside') === false && strpos($button_style['counter_pos'], 'hidden') === false) {
                        $button_style['counter_pos'] = "insidename";
                    }
                    if ($button_style['total_counter_pos'] != 'hidden' && $button_style['total_counter_pos'] != 'after') {
                        $button_style['total_counter_pos'] = "before";
                    }
                }
                $button_style['button_width'] = "column";
                $button_style['button_width_columns'] = "1";
            }
            if ($position == 'sharebottom') {
                if (in_array('more', $social_networks)) {
                    if (($key = array_search('more', $social_networks)) !== false) {
                        unset($social_networks[$key]);
                    }
                }
                $button_style['button_style'] = "icon";
                $button_style['show_counter'] = false;
                $button_style['nospace'] = true;
                $button_style['button_width'] = "column";
                $available_networks_count = ESSBOptionValuesHelper::options_value($this->options, 'mobile_sharebuttonsbar_count');
                $mobile_sharebuttonsbar_names = ESSBOptionValuesHelper::options_bool_value($this->options, 'mobile_sharebuttonsbar_names');
                if ($mobile_sharebuttonsbar_names) {
                    $button_style['button_style'] = 'button';
                }
                if (intval($available_networks_count) == 0) {
                    $available_networks_count = 4;
                }
                if (count($social_networks) > intval($available_networks_count)) {
                    $share_bottom_networks = $social_networks;
                    array_splice($social_networks, intval($available_networks_count) - 1);
                    $social_networks[] = "more";
                    //$button_style['more_button_icon'] = "dots";
                }
                $button_style['button_width_columns'] = intval($available_networks_count);
            }
        }
        if (!is_array($social_networks)) {
            $social_networks = array();
        }
        if (!is_array($social_networks_order) || count($social_networks_order) == 0) {
            $social_networks_order = ESSBCoreHelper::generate_network_list();
        }
        // apply shortcode customizations
        if ($is_shortcode) {
            // apply personalization of social networks if set from shortcode
            if (count($shortcode_options['networks']) > 0) {
                $social_networks = $shortcode_options['networks'];
                $social_networks_order = $shortcode_options['networks'];
            }
            if ($shortcode_options['customize_texts']) {
                $social_networks_names = $shortcode_options['network_texts'];
            }
            // apply shortcode counter options
            if ($shortcode_options['counters'] == 1) {
                $button_style['show_counter'] = true;
            } else {
                $button_style['show_counter'] = false;
            }
            if (!empty($shortcode_options['style'])) {
                $button_style['button_style'] = $shortcode_options['style'];
            }
            if (!empty($shortcode_options['counters_pos'])) {
                $button_style['counter_pos'] = $shortcode_options['counters_pos'];
            }
            if (!empty($shortcode_options['total_counter_pos'])) {
                $button_style['total_counter_pos'] = $shortcode_options['total_counter_pos'];
            }
            if ($shortcode_options['hide_total']) {
                $button_style['total_counter_pos'] = "hidden";
            }
            if ($shortcode_options['fullwidth']) {
                $button_style['button_width'] = "full";
                if (!empty($shortcode_options['fullwidth_fix'])) {
                    $button_style['button_width_full_button'] = $shortcode_options['fullwidth_fix'];
                }
                if (!empty($shortcode_options['fullwidth_align'])) {
                    $button_style['fullwidth_align'] = $shortcode_options['fullwidth_align'];
                }
                if (!empty($shortcode_options['fullwidth_first'])) {
                    $button_style['button_width_full_first'] = $shortcode_options['fullwidth_first'];
                }
                if (!empty($shortcode_options['fullwidth_second'])) {
                    $button_style['button_width_full_second'] = $shortcode_options['fullwidth_second'];
                }
            }
            if ($shortcode_options['fixedwidth']) {
                $button_style['button_width'] = "fixed";
                if (!empty($shortcode_options['fixedwidth_px'])) {
                    $button_style['button_width_fixed_value'] = $shortcode_options['fixedwidth_px'];
                }
                if (!empty($shortcode_options['fixedwidth_align'])) {
                    $button_style['button_width_fixed_align'] = $shortcode_options['fixedwidth_align'];
                }
            }
            if (!empty($shortcode_options['morebutton'])) {
                $button_style['more_button_func'] = $shortcode_options['morebutton'];
            }
            if (!empty($shortcode_options['morebutton_icon'])) {
                $button_style['more_button_icon'] = $shortcode_options['morebutton_icon'];
            }
            if ($shortcode_options['column']) {
                $button_style['button_width'] = "column";
                if (!empty($shortcode_options['columns'])) {
                    $button_style['button_width_columns'] = $shortcode_options['columns'];
                }
            }
            if (!empty($shortcode_options['template'])) {
                $instance_template_slug = $shortcode_options['template'];
                if ($instance_template_slug != $this->design_options['template_slug']) {
                    $use_minifed_css = $this->general_options['use_minified_css'] ? ".min" : "";
                    $template_url = ESSB3_PLUGIN_URL . '/assets/css/' . $instance_template_slug . '/easy-social-share-buttons' . $use_minifed_css . '.css';
                    essb_resource_builder()->add_static_footer_css($template_url, 'easy-social-share-buttons-' . $instance_template_slug);
                }
                $button_style['template'] = $shortcode_options['template'];
            }
            if (!empty($shortcode_options['sidebar_pos'])) {
                $button_style['sidebar_pos'] = $shortcode_options['sidebar_pos'];
            }
            $button_style['nospace'] = $shortcode_options['nospace'];
            $button_style['nostats'] = $shortcode_options['nostats'];
            if (!empty($shortcode_options['animation'])) {
                $button_style['button_animation'] = $shortcode_options['animation'];
            }
            if (!empty($shortcode_options['fblike'])) {
                $post_native_details['facebook_url'] = $shortcode_options['fblike'];
            }
            if (!empty($shortcode_options['plusone'])) {
                $post_native_details['google_url'] = $shortcode_options['plusone'];
            }
            if (!$shortcode_options['message']) {
                $button_style['message_share_buttons'] = "";
                $button_style['message_before_share_buttons'] = "";
            }
            //apply again mobile settings for the mobile buttons bar
            if ($position == 'sharebottom') {
                if (in_array('more', $social_networks)) {
                    if (($key = array_search('more', $social_networks)) !== false) {
                        unset($social_networks[$key]);
                    }
                }
                $button_style['button_style'] = "icon";
                $button_style['show_counter'] = false;
                $button_style['nospace'] = true;
                $button_style['button_width'] = "column";
                $available_networks_count = ESSBOptionValuesHelper::options_value($this->options, 'mobile_sharebuttonsbar_count');
                $mobile_sharebuttonsbar_names = ESSBOptionValuesHelper::options_bool_value($this->options, 'mobile_sharebuttonsbar_names');
                if ($mobile_sharebuttonsbar_names) {
                    $button_style['button_style'] = 'button';
                }
                if (intval($available_networks_count) == 0) {
                    $available_networks_count = 4;
                }
                if (count($social_networks) > intval($available_networks_count)) {
                    $share_bottom_networks = $social_networks;
                    array_splice($social_networks, intval($available_networks_count) - 1);
                    $social_networks[] = "more";
                    $social_networks_order[] = "more";
                    //$button_style['more_button_icon'] = "dots";
                }
                $button_style['button_width_columns'] = intval($available_networks_count);
            }
            // @since 3.5 Integration with post views add-on via shortcode option
            if (!empty($shortcode_options['postviews'])) {
                $button_style['postviews'] = $shortcode_options['postviews'];
            }
        }
        // generate unique instance key
        $salt = mt_rand();
        // attache compliled mail message data
        if (in_array("mail", $social_networks)) {
            //if ($this->network_options['mail_function'] == "form") {
            $base_subject = $this->network_options['mail_subject'];
            $base_body = $this->network_options['mail_body'];
            $base_subject = preg_replace(array('#%%title%%#', '#%%siteurl%%#', '#%%permalink%%#', '#%%image%%#', '#%%shorturl%%#'), array($post_share_details['title_plain'], get_site_url(), $post_share_details['url'], $post_share_details['image'], $post_share_details['short_url']), $base_subject);
            $base_body = preg_replace(array('#%%title%%#', '#%%siteurl%%#', '#%%permalink%%#', '#%%image%%#', '#%%shorturl%%#'), array($post_share_details['title_plain'], get_site_url(), $post_share_details['url'], $post_share_details['image'], $post_share_details['short_url']), $base_body);
            $post_share_details['mail_subject'] = $base_subject;
            $post_share_details['mail_body'] = $base_body;
            $ga_tracking = ESSBOptionValuesHelper::options_value($this->options, 'activate_ga_campaign_tracking');
            if ($ga_tracking != '') {
                $post_share_details['mail_subject'] = str_replace('{network}', 'mail', $post_share_details['mail_subject']);
                $post_share_details['mail_body'] = str_replace('{title}', $post_share_details['title_plain'], $post_share_details['mail_body']);
                $post_share_details['mail_body'] = str_replace('{network}', 'mail', $post_share_details['mail_body']);
            }
            //}
            //else {
            //	$post_share_details['mail_subject'] = '';
            //	$post_share_details['mail_body'] = '';
            //}
            essb_resource_builder()->add_js(ESSBResourceBuilderSnippets::js_build_generate_popup_mailform(), true, 'essb-mailform');
            essb_resource_builder()->add_js(ESSBButtonHelper::print_mailer_code($post_share_details['mail_subject'], $post_share_details['mail_body'], $salt, $post_share_details["post_id"], $position), true, 'essb-mailform-' . $salt);
        }
        $button_style['included_button_count'] = count($social_networks);
        if ($button_style['show_counter']) {
            if (isset($button_style['total_counter_pos'])) {
                if ($button_style['total_counter_pos'] != 'hidden') {
                    $button_style['included_button_count']++;
                }
            }
        }
        $intance_morebutton_func = $this->network_options['more_button_func'];
        if ($position == "sidebar" || $position == "postfloat") {
            //$intance_morebutton_func = "2";
            if ($button_style['more_button_func'] == '1') {
                $button_style['more_button_func'] = "2";
            }
        }
        if ($position == "sharebottom") {
            //$intance_morebutton_func = "3";
            $button_style['more_button_func'] = "3";
        }
        //$button_style['more_button_func'] = $intance_morebutton_func;
        // sidebar close button option if activated into settings
        if ($this->design_options['sidebar_leftright_close'] && $position == "sidebar") {
            $social_networks[] = "sidebar-close";
            $social_networks_order[] = "sidebar-close";
        }
        // apply additional native button options
        if ($post_native_details['active']) {
            $post_native_details['url'] = $post_share_details['url'];
            $post_native_details['text'] = $post_share_details['title'];
        }
        // @since 3.0 beta 4 - check if on post settings we have set counters that are not active generally
        if ($button_style['show_counter']) {
            if (!isset($this->activated_resources['counters'])) {
                if (!defined('ESSB3_COUNTER_LOADED') && !defined('ESSB3_CACHED_COUNTERS')) {
                    $script_url = ESSB3_PLUGIN_URL . '/assets/js/easy-social-share-buttons' . $this->use_minified_js . '.js';
                    essb_resource_builder()->add_static_resource_footer($script_url, 'easy-social-share-buttons', 'js');
                    $this->activated_resources['counters'] = true;
                    define('ESSB3_COUNTER_LOADED', true);
                }
            }
        }
        // @since 3.0.3 fix for the mail function
        $button_style['mail_function'] = $this->network_options['mail_function'];
        // @since 3.2 - passing mobile state to button style to allow deactivate advaned share on mobile (does not work);
        $button_style['is_mobile'] = essb_is_mobile();
        $ssbuttons = ESSBButtonHelper::draw_share_buttons($post_share_details, $button_style, $social_networks, $social_networks_order, $social_networks_names, $position, $salt, $likeshare, $post_native_details);
        //print_r($post_native_details);
        if (!defined('ESSB3_LIGHTMODE')) {
            if ($post_native_details['active']) {
                if (!$post_native_details['sameline']) {
                    $post_native_details['withshare'] = true;
                    //@fixed display of native for float in 3.0beta5
                    $native_buttons_code = ESSBNativeButtonsHelper::draw_native_buttons($post_native_details, $post_native_details['order'], $post_native_details['counters'], $post_native_details['sameline'], $post_native_details['skinned']);
                    $ssbuttons = str_replace('<!--native--></div>', $native_buttons_code . '</div>', $ssbuttons);
                }
            }
        }
        if ($button_style['button_width'] == "fixed") {
            //print "fixed button code adding";
            $fixedwidth_key = $button_style['button_width_fixed_value'] . "-" . $button_style['button_width_fixed_align'];
            essb_resource_builder()->add_css(ESSBResourceBuilderSnippets::css_build_fixedwidth_button($salt, $button_style['button_width_fixed_value'], $button_style['button_width_fixed_align']), 'essb-fixed-width-' . $fixedwidth_key, 'footer');
        }
        if ($button_style['button_width'] == "full") {
            //print_r($button_style);
            //print "fixed button code adding";
            $count_of_social_networks = count($social_networks);
            if ($button_style['show_counter']) {
                if (isset($button_style['total_counter_pos'])) {
                    if ($button_style['total_counter_pos'] != 'hidden') {
                        $count_of_social_networks++;
                    }
                }
            }
            $container_width = $button_style['button_width_full_container'];
            $single_button_width = intval($container_width) / $count_of_social_networks;
            $single_button_width = floor($single_button_width);
            //essb_resource_builder()->add_css(ESSBResourceBuilderSnippets::css_build_fullwidth_button($single_button_width, $button_style['button_width_full_button'], $button_style['button_width_full_container']), 'essb-full-width-'.$single_button_width.'-'.$button_style['button_width_full_button'].'-'.$button_style['button_width_full_container'], 'footer');
            essb_resource_builder()->add_css(ESSBResourceBuilderSnippets::css_build_fullwidth_buttons($count_of_social_networks, $button_style['button_width_full_container'], $button_style['button_width_full_button'], $button_style['button_width_full_first'], $button_style['button_width_full_second']), 'essb-full-width-' . $single_button_width . '-' . $button_style['button_width_full_button'] . '-' . $button_style['button_width_full_container'], 'footer');
        }
        // more buttons code append
        if (in_array("more", $social_networks)) {
            //print "position = ".$position. ", more button = ".$intance_morebutton_func;
            $user_set_morebutton_func = $button_style['more_button_func'];
            // @since 3.3 - option to change more button style on each display position
            if (isset($button_style['location_more_button_func'])) {
                if (!empty($button_style['location_more_button_func'])) {
                    $user_set_morebutton_func = $button_style['location_more_button_func'];
                }
            }
            if ($user_set_morebutton_func == '1') {
                essb_resource_builder()->add_js(ESSBResourceBuilderSnippets::js_build_generate_more_button_inline(), true, 'essb-inlinemore-code');
            }
            if ($user_set_morebutton_func == '2' || $user_set_morebutton_func == '3') {
                essb_resource_builder()->add_js(ESSBResourceBuilderSnippets::js_build_generate_more_button_popup(), true, 'essb-popupmore-code');
                $listAllNetworks = $user_set_morebutton_func == '2' ? true : false;
                $more_social_networks = ESSBCoreHelper::generate_list_networks($listAllNetworks);
                $more_social_networks_order = ESSBCoreHelper::generate_network_list();
                if ($position == "sharebottom") {
                    $more_social_networks = $share_bottom_networks;
                    $more_social_networks_order = $social_networks_order;
                    //$button_style['more_button_icon'] = "dots";
                }
                $button_style['button_style'] = "button";
                $button_style['show_counter'] = false;
                $button_style['button_width'] = "column";
                $button_style['button_width_columns'] = essb_is_mobile() ? "1" : "3";
                $button_style['counter_pos'] = "left";
                if ($position == "sharebottom") {
                    $button_style['button_width_columns'] = "1";
                }
                $more_salt = mt_rand();
                $ssbuttons .= sprintf('<div class="essb_morepopup essb_morepopup_%1$s" style="display:none;">
						<a href="#" class="essb_morepopup_close" onclick="essb_toggle_less_popup(\'%1$s\'); return false;"></a>
						<div class="essb_morepopup_content essb_morepopup_content_%1$s">%2$s</div></div>
						<div class="essb_morepopup_shadow essb_morepopup_shadow_%1$s" onclick="essb_toggle_less_popup(\'%1$s\'); return false;"></div>', $salt, ESSBButtonHelper::draw_share_buttons($post_share_details, $button_style, $more_social_networks, $more_social_networks_order, $social_networks_names, "more_popup", $more_salt, 'share'));
                //print $more_salt."|";
                // fix for not workin mail in more button
                if (!isset($post_share_details['mail_subject'])) {
                    $base_subject = $this->network_options['mail_subject'];
                    $base_body = $this->network_options['mail_body'];
                    $base_subject = preg_replace(array('#%%title%%#', '#%%siteurl%%#', '#%%permalink%%#', '#%%image%%#', '#%%shorturl%%#'), array($post_share_details['title_plain'], get_site_url(), $post_share_details['url'], $post_share_details['image'], $post_share_details['short_url']), $base_subject);
                    $base_body = preg_replace(array('#%%title%%#', '#%%siteurl%%#', '#%%permalink%%#', '#%%image%%#', '#%%shorturl%%#'), array($post_share_details['title_plain'], get_site_url(), $post_share_details['url'], $post_share_details['image'], $post_share_details['short_url']), $base_body);
                    $post_share_details['mail_subject'] = $base_subject;
                    $post_share_details['mail_body'] = $base_body;
                    $ga_tracking = ESSBOptionValuesHelper::options_value($this->options, 'activate_ga_campaign_tracking');
                    if ($ga_tracking != '') {
                        $post_share_details['mail_subject'] = str_replace('{network}', 'mail', $post_share_details['mail_subject']);
                        $post_share_details['mail_body'] = str_replace('{title}', $post_share_details['title_plain'], $post_share_details['mail_body']);
                        $post_share_details['mail_body'] = str_replace('{network}', 'mail', $post_share_details['mail_body']);
                    }
                }
                essb_resource_builder()->add_js(ESSBButtonHelper::print_mailer_code($post_share_details['mail_subject'], $post_share_details['mail_body'], $more_salt, $post_share_details["post_id"], $position), true, 'essb-mailform-' . $more_salt);
                essb_resource_builder()->add_css(ESSBResourceBuilderSnippets::css_build_morepopup_css(), 'essb-morepopup-css', 'footer');
            }
        }
        // apply clean of new lines
        if (!empty($ssbuttons)) {
            $ssbuttons = trim(preg_replace('/\\s+/', ' ', $ssbuttons));
        }
        if (!empty($cache_key)) {
            ESSBDynamicCache::put($cache_key, $ssbuttons);
        }
        if (!empty($cache_key_runtime) && ESSBGlobalSettings::$cache_runtime) {
            wp_cache_set($cache_key_runtime, $ssbuttons);
        }
        //print "generated in ".timer_stop(0, 5);
        return $ssbuttons;
    }