public static function get_share_address($network, $share = array(), $salt = '')
 {
     global $essb_networks, $essb_options;
     // TODO: add handle of user_image_url
     if (ESSBOptionValuesHelper::options_bool_value($essb_options, 'advanced_custom_share')) {
         $as_url = ESSBOptionValuesHelper::options_value($essb_options, 'as_' . $network . '_url');
         $as_text = ESSBOptionValuesHelper::options_value($essb_options, 'as_' . $network . '_text');
         $as_image = ESSBOptionValuesHelper::options_value($essb_options, 'as_' . $network . '_image');
         $as_desc = ESSBOptionValuesHelper::options_value($essb_options, 'as_' . $network . '_desc');
         if (!empty($as_url)) {
             $share['url'] = $as_url;
         }
         if (!empty($as_text)) {
             $as_text = preg_replace(array('#%title%#', '#%siteurl%#', '#%permalink%#', '#%image%#', '#%shorturl%#'), array($share['title'], get_site_url(), $share['url'], $share['image'], $share['short_url']), $as_text);
             $share['title'] = $as_text;
         }
         if (!empty($as_image)) {
             $share['image'] = $as_image;
         }
         if (!empty($as_desc)) {
             $as_desc = preg_replace(array('#%title%#', '#%siteurl%#', '#%permalink%#', '#%image%#', '#%shorturl%#'), array($share['title'], get_site_url(), $share['url'], $share['image'], $share['short_url']), $as_desc);
             $share['description'] = $as_desc;
         }
     }
     // @since version 3.0.3 - fixes the GA Campaign tracking fields
     $ga_tracking_code = ESSBGlobalSettings::$activate_ga_campaign_tracking;
     //ESSBOptionValuesHelper::options_value($essb_options, 'activate_ga_campaign_tracking');
     if ($ga_tracking_code != '') {
         $share['url'] = str_replace('{network}', $network, $share['url']);
         $share['full_url'] = str_replace('{network}', $network, $share['full_url']);
         $share['url'] = str_replace('{title}', $share['title'], $share['url']);
         $share['full_url'] = str_replace('{title}', $share['title'], $share['full_url']);
         // rebuild shorturls if GA tracking is active
         // code refactor @since 3.4.2
         if (ESSBOptionValuesHelper::options_bool_value($essb_options, 'shorturl_activate')) {
             $global_provider = ESSBOptionValuesHelper::options_value($essb_options, 'shorturl_type');
             if (ESSBOptionValuesHelper::options_bool_value($essb_options, 'twitter_shareshort')) {
                 $global_shorturl = ESSBUrlHelper::short_url($share['full_url'], $global_provider, get_the_ID(), ESSBOptionValuesHelper::options_value($essb_options, 'shorturl_bitlyuser'), ESSBOptionValuesHelper::options_value($essb_options, 'shorturl_bitlyapi'));
                 $share['short_url_twitter'] = $global_shorturl;
                 $share['short_url_whatsapp'] = $global_shorturl;
             } else {
                 $share['short_url'] = ESSBUrlHelper::short_url($share['full_url'], $global_provider, get_the_ID(), ESSBOptionValuesHelper::options_value($essb_options, 'shorturl_bitlyuser'), ESSBOptionValuesHelper::options_value($essb_options, 'shorturl_bitlyapi'));
                 $share['short_url_twitter'] = $share['short_url'];
                 $share['short_url_whatsapp'] = $share['short_url'];
             }
             if ($share['short_url_twitter'] == '') {
                 $share['short_url_twitter'] = $share['url'];
             }
             if ($share['short_url_whatsapp'] == '') {
                 $share['short_url_whatsapp'] = $share['url'];
             }
             if ($share['short_url'] == '') {
                 $share['short_url'] = $share['url'];
             }
         } else {
             $share['twitter_tweet'] .= '%20' . $share['url'];
             $share['short_url_twitter'] = esc_attr($share['url']);
             $share['short_url_whatsapp'] = esc_attr($share['url']);
         }
         /*if (ESSBOptionValuesHelper::options_bool_value ( $essb_options, 'twitter_shareshort' ) || 
         				ESSBOptionValuesHelper::options_bool_value ( $essb_options, 'shorturl_activate' ) || 
         				ESSBOptionValuesHelper::options_bool_value ( $essb_options, 'whatsapp_shareshort' )) {
         			$global_provider = ESSBOptionValuesHelper::options_value ( $essb_options, 'shorturl_type' );
         			if (ESSBOptionValuesHelper::options_bool_value ( $essb_options, 'shorturl_activate' )) {
         				$share ['short_url'] = ESSBUrlHelper::short_url ( $share ['full_url'], $global_provider, get_the_ID (), ESSBOptionValuesHelper::options_value ( $essb_options, 'shorturl_bitlyuser' ), ESSBOptionValuesHelper::options_value ( $essb_options, 'shorturl_bitlyapi' ) );
         				
         				$share ['short_url_twitter'] = $share ['short_url'];
         				$share ['short_url_whatsapp'] = $share ['short_url'];
         			} else {
         				if (ESSBOptionValuesHelper::options_bool_value ( $essb_options, 'twitter_shareshort' )) {
         					$provider = ESSBOptionValuesHelper::options_value ( $essb_options, 'twitter_shareshort_service' );
         					$share ['short_url_twitter'] = ESSBUrlHelper::short_url ( $share ['full_url'], $global_provider, get_the_ID (), ESSBOptionValuesHelper::options_value ( $essb_options, 'shorturl_bitlyuser' ), ESSBOptionValuesHelper::options_value ( $essb_options, 'shorturl_bitlyapi' ) );
         				}
         				
         				if (ESSBOptionValuesHelper::options_bool_value ( $essb_options, 'whatsapp_shareshort' )) {
         					$provider = ESSBOptionValuesHelper::options_value ( $essb_options, 'whatsapp_shareshort_service' );
         					
         					if ($provider == ESSBOptionValuesHelper::options_value ( $essb_options, 'twitter_shareshort_service' ) && ESSBOptionValuesHelper::options_bool_value ( $essb_options, 'twitter_shareshort' )) {
         						$share ['short_url_whatsapp'] = $share ['short_url_twitter'];
         					} else {
         						$share ['short_url_whatsapp'] = ESSBUrlHelper::short_url ( $share ['full_url'], $global_provider, get_the_ID (), ESSBOptionValuesHelper::options_value ( $essb_options, 'shorturl_bitlyuser' ), ESSBOptionValuesHelper::options_value ( $essb_options, 'shorturl_bitlyapi' ) );
         					}
         				}
         				
         				if ($share ['short_url_twitter'] == '') {
         					$share ['short_url_twitter'] = $share ['url'];
         				}
         				if ($share ['short_url_whatsapp'] == '') {
         					$share ['short_url_whatsapp'] = $share ['url'];
         				}
         			}
         		} else {
         			$share ['twitter_tweet'] .= '%20' . $share ['url'];
         			$share ['short_url_twitter'] = esc_attr ( $share ['url'] );
         			$share ['short_url_whatsapp'] = esc_attr ( $share ['url'] );
         		}*/
     }
     if (!isset($share['query'])) {
         if (isset($share['essb_encode_url'])) {
             if ($share['essb_encode_url']) {
                 $share['short_url_twitter'] = urlencode($share['short_url_twitter']);
                 $share['full_url'] = urlencode($share['full_url']);
                 $share['url'] = urlencode($share['url']);
                 $share['full_url'] = str_replace('&', '&', $share['full_url']);
                 $share['url'] = str_replace('&', '&', $share['url']);
             }
         }
         if (isset($share['essb_encode_text'])) {
             if ($share['essb_encode_text']) {
                 $share['twitter_tweet'] = str_replace("+", " ", $share['twitter_tweet']);
                 $share['title'] = urlencode($share['title']);
                 $share['twitter_tweet'] = urlencode($share['twitter_tweet']);
                 $share['description'] = urlencode($share['description']);
                 $share['twitter_tweet'] = str_replace(" ", "%20", $share['twitter_tweet']);
                 $share['twitter_tweet'] = str_replace("+", "%20", $share['twitter_tweet']);
                 $share['twitter_tweet'] = str_replace('&', '&', $share['twitter_tweet']);
                 $share['title'] = str_replace('&', '&', $share['title']);
                 $share['description'] = str_replace('&', '&', $share['description']);
             }
         }
         if (isset($share['essb_encode_text_plus'])) {
             if ($share['essb_encode_text_plus']) {
                 $share['twitter_tweet'] = str_replace(" ", "%20", $share['twitter_tweet']);
                 $share['twitter_tweet'] = str_replace("+", "%20", $share['twitter_tweet']);
             }
         }
     }
     $share['url'] = esc_attr($share['url']);
     $share['short_url'] = esc_attr($share['short_url']);
     $share['full_url'] = esc_attr($share['full_url']);
     $share['title'] = esc_attr($share['title']);
     $share['image'] = esc_attr($share['image']);
     $share['description'] = esc_attr($share['description']);
     if (isset($share['mail_subject'])) {
         $share['mail_subject'] = esc_attr(stripslashes($share['mail_subject']));
     }
     if (isset($share['mail_body'])) {
         $share['mail_body'] = esc_attr(stripslashes($share['mail_body']));
     }
     $pinterest_description = $share['description'];
     if (empty($pinterest_description)) {
         $pinterest_description = $share['title'];
     }
     // @since version 3.0.4 - fix for shorturl
     $shorturl_activate = ESSBOptionValuesHelper::options_bool_value($essb_options, 'shorturl_activate');
     if ($shorturl_activate && !empty($share['short_url'])) {
         $share['url'] = $share['short_url'];
     }
     $url = "";
     $api_command = "";
     $network_type = "buildin";
     if (isset($essb_networks[$network])) {
         $network_type = isset($essb_networks[$network]['type']) ? $essb_networks[$network]['type'] : "buildin";
     }
     if (isset($share['query'])) {
         if ($share['query']) {
             $share['short_url_twitter'] = urlencode($share['short_url_twitter']);
             $share['full_url'] = urlencode($share['full_url']);
             $share['url'] = urlencode($share['url']);
         }
     }
     switch ($network) {
         case "facebook":
             $url = sprintf('http://www.facebook.com/sharer/sharer.php?u=%1$s&t=%2$s', $share['url'], $share['title']);
             break;
         case "facebook_advanced":
             $fbappid = ESSBOptionValuesHelper::options_value($essb_options, 'facebookadvancedappid');
             $url = 'https://www.facebook.com/dialog/feed?app_id=' . $fbappid . '&display=popup&name=' . $share['title'] . '&link=' . $share['url'] . '&redirect_uri=https://www.facebook.com';
             if ($share['image'] != '') {
                 $url .= '&picture=' . $share['image'];
             }
             if ($share['description'] != '') {
                 $url .= '&description=' . $share['description'];
             }
             break;
         case "twitter":
             if ($share['short_url_twitter'] == '') {
                 $share['short_url_twitter'] = $share['url'];
             }
             $use_tweet = $share['twitter_tweet'];
             $use_tweet = str_replace('#', '%23', $use_tweet);
             $use_tweet = str_replace('|', '%7C', $use_tweet);
             // @since 3.1 Twitter message optimization
             $twitter_message_optimize = ESSBGlobalSettings::$twitter_message_optimize;
             //ESSBOptionValuesHelper::options_bool_value($essb_options, 'twitter_message_optimize');
             if ($twitter_message_optimize) {
                 $twitter_message_optimize_method = ESSBOptionValuesHelper::options_value($essb_options, 'twitter_message_optimize_method');
                 $optmized_tweet = ESSBButtonHelper::twitter_message_optimization($use_tweet, $share['short_url_twitter'], $share['twitter_user'], $share['twitter_hashtags'], $twitter_message_optimize_method);
                 $use_tweet = $optmized_tweet['tweet'];
                 $share['twitter_user'] = $optmized_tweet['user'];
                 $share['twitter_hashtags'] = $optmized_tweet['hashtags'];
             }
             $twitter_pass_user = $share['twitter_user'] != '' ? sprintf('&related=%1$s&via=%1$s', $share['twitter_user']) : "";
             $twitter_pass_hastags = $share['twitter_hashtags'] != '' ? sprintf('&hashtags=%1$s', $share['twitter_hashtags']) : '';
             $url = sprintf('https://twitter.com/intent/tweet?text=%1$s&url=%2$s&counturl=%3$s%4$s%5$s', $use_tweet, $share['short_url_twitter'], $share['full_url'], $twitter_pass_user, $twitter_pass_hastags);
             break;
         case "google":
             $url = sprintf('https://plus.google.com/share?url=%1$s', $share['url']);
             break;
         case "pinterest":
             $pin_image = $share['image'];
             $custom_pin_image = isset($share['pinterest_image']) ? $share['pinterest_image'] : '';
             if (!empty($custom_pin_image)) {
                 $pin_image = $custom_pin_image;
             }
             $url = sprintf('http://pinterest.com/pin/create/bookmarklet/?media=%1$s&url=%2$s&title=%3$s&description=%4$s', $pin_image, $share['url'], $share['title'], $pinterest_description);
             break;
         case "pinterest_picker":
             $url = "#";
             $api_command = "essb_pinterest_picker('" . $salt . "'); return false;";
             break;
         case "linkedin":
             $url = sprintf('http://www.linkedin.com/shareArticle?mini=true&ro=true&trk=EasySocialShareButtons&title=%1$s&url=%2$s', $share['title'], $share['url']);
             break;
         case "digg":
             $url = sprintf('http://digg.com/submit?phase=2%20&url=%1$s&title=%2$s', $share['url'], $share['title']);
             break;
         case "reddit":
             $url = sprintf('http://reddit.com/submit?url=%1$s&title=%2$s', $share['url'], $share['title']);
             break;
         case "del":
             $url = sprintf('https://delicious.com/save?v=5&noui&jump=close&url=%1$s&title=%2$s', $share['url'], $share['title']);
             break;
         case "buffer":
             $url = sprintf('https://bufferapp.com/add?url=%1$s&text=%2$s&via=%3$s&picture=&count=horizontal&source=button', $share['url'], $share['title'], $share['twitter_user']);
             break;
         case "love":
             $url = "#";
             $api_command = "essb_lovethis('" . $salt . "'); return false;";
             break;
         case "stumbleupon":
             $url = sprintf('http://www.stumbleupon.com/badge/?url=%1$s', $share['full_url']);
             break;
         case "tumblr":
             $url = sprintf('http://tumblr.com/share?s=&v=3&t=%1$s&u=%2$s', $share['title'], urlencode($share['url']));
             break;
         case "vk":
             $url = sprintf('http://vkontakte.ru/share.php?url=%1$s', $share['url']);
             break;
         case "ok":
             $url = sprintf('http://www.odnoklassniki.ru/dk?st.cmd=addShare&st.s=1&st._surl=%1$s', $share['url']);
             break;
         case "weibo":
             $url = sprintf('http://service.weibo.com/share/share.php?url=%1$s&title=%2$s&pic=%3$s', $share['url'], $share['title'], $share['image']);
             break;
         case "xing":
             $url = sprintf('https://www.xing.com/social_plugins/share?h=1;url=%1$s', $share['url']);
             break;
         case "pocket":
             $url = sprintf('https://getpocket.com/save?title=%1$s&url=%2$s', $share['title'], urlencode($share['url']));
             break;
         case "mwp":
             $url = sprintf('http://managewp.org/share/form?url=%1$s', urlencode($share['url']));
             break;
         case "whatsapp":
             if ($share['short_url_whatsapp'] == '') {
                 $share['short_url_whatsapp'] = $share['url'];
             }
             $url = sprintf('whatsapp://send?text=%1$s%3$s%2$s', ESSBCoreHelper::urlencode($share['title_plain']), rawurlencode($share['short_url_whatsapp']), '%20');
             $api_command = "essb_tracking_only('', 'whatsapp', '" . $salt . "', true);";
             break;
         case "meneame":
             $url = sprintf('http://www.meneame.net/submit.php?url=%1$s', $share['url']);
             break;
         case "print_friendly":
             $url = sprintf('http://www.printfriendly.com/print/?url=%1$s', $share['url']);
             break;
         case "print":
             $url = "#";
             $api_command = "essb_print('" . $salt . "'); return false;";
             break;
         case "mail":
             if (!$share['mail_subject']) {
                 $share['mail_subject'] = '';
             }
             if (!$share['mail_body']) {
                 $share['mail_body'] = '';
             }
             $url = sprintf('mailto:?subject=%1$s&body=%2$s', $share['mail_subject'], $share['mail_body']);
             $api_command = "essb_tracking_only('', 'mail', '" . $salt . "', true);";
             break;
         case "mail_form":
             $url = "#";
             $api_command = "essb_mailform_" . $salt . "('" . $salt . "'); return false;";
             break;
         case "more":
             $url = "#";
             $api_command = "essb_toggle_more('" . $salt . "'); return false;";
             break;
         case "less":
             $url = "#";
             $api_command = "essb_toggle_less('" . $salt . "'); return false;";
             break;
         case "more_popup":
             $url = "#";
             $api_command = "essb_toggle_more_popup('" . $salt . "'); return false;";
             break;
         case "flattr":
             if (!class_exists('ESSBNetworks_Flattr')) {
                 include_once ESSB3_PLUGIN_ROOT . 'lib/networks/essb-flattr.php';
             }
             $url = ESSBNetworks_Flattr::getStaticFlattrUrl($share);
             break;
             // @since 3.0
         // @since 3.0
         case "blogger":
             $url = sprintf('https://www.blogger.com/blog_this.pyra?t&u=%1$s&n=%2$s', $share['url'], $share['title']);
             break;
         case 'amazon':
             $url = sprintf('http://www.amazon.com/gp/wishlist/static-add?u=%1$s&t=%2$s', $share['url'], $share['title']);
             break;
         case 'yahoomail':
             $url = sprintf('http://compose.mail.yahoo.com/?body=%1$s', $share['url']);
             break;
         case 'gmail':
             $url = sprintf('https://mail.google.com/mail/u/0/?view=cm&fs=1&su=%2$s&body=%1$s&ui=2&tf=1', $share['url'], $share['title']);
             break;
         case 'aol':
             $url = sprintf('http://webmail.aol.com/Mail/ComposeMessage.aspx?subject=%2$s&body=%1$s', $share['url'], $share['title']);
             break;
         case 'newsvine':
             $url = sprintf('http://www.newsvine.com/_tools/seed&save?u=%1$s&h=%2$s', $share['url'], $share['title']);
             break;
         case 'hackernews':
             $url = sprintf('https://news.ycombinator.com/submitlink?u=%1$s&t=%2$s', $share['url'], $share['title']);
             break;
         case 'evernote':
             $url = sprintf('http://www.evernote.com/clip.action?url=%1$s&title=%2$s', $share['url'], $share['title']);
             break;
         case 'myspace':
             $url = sprintf('https://myspace.com/post?u=%1$s', esc_attr($share['url']));
             break;
         case "mailru":
             $url = sprintf('http://connect.mail.ru/share?url=%1$s&title=%2$s&description=%3$s', $share['url'], $share['title'], $share['description']);
             break;
         case "viadeo":
             $url = sprintf('https://www.viadeo.com/?url=%1$s&title=%2$s', $share['url'], $share['title']);
             break;
         case "line":
             //$url = sprintf('http://line.me/R/msg/text/%1$s%20%2$s', ESSBCoreHelper::urlencode ( $share ['title'] ), rawurlencode ( $share ['short_url_whatsapp'] ));
             $url = sprintf('line://msg/text/%1$s%3$s%2$s', ESSBCoreHelper::urlencode($share['title_plain']), rawurlencode($share['short_url_whatsapp']), '%20');
             $api_command = "essb_tracking_only('', 'line', '" . $salt . "', true);";
             break;
         case "embedly":
             $url = "";
             $api_command = "embedly.modal();";
             break;
         case "flipboard":
             $url = sprintf('https://share.flipboard.com/bookmarklet/popout?url=%1$s&title=%2$s', $share['url'], $share['title']);
             break;
         case "yummly":
             $url = sprintf('http://www.yummly.com/urb/verify?url=%2$s&title=%3$s&image=%1$s&yumtype=button', $share['image'], $share['url'], $share['title'], $share['description']);
             break;
         case "sms":
             if ($share['short_url_whatsapp'] == '') {
                 $share['short_url_whatsapp'] = $share['url'];
             }
             $url = sprintf('sms:&body=%1$s%3$s%2$s', ESSBCoreHelper::urlencode($share['title_plain']), rawurlencode($share['short_url_whatsapp']), '%20');
             break;
         case "viber":
             if ($share['short_url_whatsapp'] == '') {
                 $share['short_url_whatsapp'] = $share['url'];
             }
             $url = sprintf('viber://forward?text=%1$s%3$s%2$s', ESSBCoreHelper::urlencode($share['title_plain']), rawurlencode($share['short_url_whatsapp']), '%20');
             $api_command = "essb_tracking_only('', 'viber', '" . $salt . "', true);";
             break;
         case "telegram":
             if ($share['short_url_whatsapp'] == '') {
                 $share['short_url_whatsapp'] = $share['url'];
             }
             // @since 3.4.2 - we include telegram alternative share method
             if (ESSBGlobalSettings::$telegram_alternative) {
                 $url = sprintf('https://telegram.me/share/url?url=%2$s&text=%1$s', ESSBCoreHelper::urlencode($share['title_plain']), rawurlencode($share['short_url_whatsapp']));
             } else {
                 $url = sprintf('tg://msg?text=%1$s%3$s%2$s', ESSBCoreHelper::urlencode($share['title_plain']), rawurlencode($share['short_url_whatsapp']), '%20');
             }
             $api_command = "essb_tracking_only('', 'telegram', '" . $salt . "', true);";
             break;
         default:
             // @since 3.0 - module parsing social buttons or custom social buttons
             if ($network_type != 'buildin') {
                 /*$url = '';
                 		$api_command = '';
                 		
                 		$button_object_name = "ESSBNetwork_".$network;
                 		if (method_exists($button_object_name, 'get_share_address')) {
                 			$url = $button_object_name::get_share_address($share);
                 		}
                 		if (method_exists($button_object_name, 'get_api_command')) {
                 			$api_command = $button_object_name::get_api_command($share);
                 		}*/
             }
             break;
     }
     if ($api_command == '') {
         $api_command = sprintf('essb_window('%1$s','%2$s','%3$s'); return false;', $url, $network, $salt);
         if ($network == "twitter") {
             $url = "#";
         }
     }
     if ($share['essb_encode_url']) {
         $url = str_replace('&', '&', $url);
         //print $url;
     }
     return array("url" => $url, 'api_command' => $api_command);
 }
function essb_ctt_shortcode($atts)
{
    global $essb_options;
    extract(shortcode_atts(array('tweet' => '', 'via' => 'yes', 'url' => 'yes', 'nofollow' => 'no', 'user' => '', 'hashtags' => '', 'usehashtags' => 'yes'), $atts));
    $handle = $user;
    if (function_exists('mb_internal_encoding')) {
        $handle_length = 6 + mb_strlen($handle);
    } else {
        $handle_length = 6 + strlen($handle);
    }
    if (!empty($handle) && $via != 'no') {
        $handle_code = "&via=" . $handle . "&related=" . $handle;
    } else {
        $handle_code = '';
    }
    if ($via != 'yes') {
        $handle = '';
        $handle_code = '';
        $handle_length = 0;
    }
    if ($usehashtags != 'no' && $hashtags != '') {
        $handle_code .= "&hashtags=" . $hashtags;
        if (function_exists('mb_internal_encoding')) {
            $handle_length = 6 + mb_strlen($hashtags);
        } else {
            $handle_length = 6 + strlen($hashtags);
        }
    }
    $text = $tweet;
    $post_url = get_permalink();
    $short_url = "";
    $twitter_shareshort = ESSBOptionValuesHelper::options_bool_value($essb_options, 'twitter_shareshort');
    if ($twitter_shareshort) {
        $provider = ESSBOptionValuesHelper::options_value($essb_options, 'twitter_shareshort_service');
        $shorturl_bitlyuser = ESSBOptionValuesHelper::options_value($essb_options, 'shorturl_bitlyuser');
        $shorturl_bitlyapi = ESSBOptionValuesHelper::options_value($essb_options, 'shorturl_bitlyapi');
        $short_url = ESSBUrlHelper::short_url($post_url, $provider, get_the_ID(), $shorturl_bitlyuser, $shorturl_bitlyapi);
    }
    if (filter_var($url, FILTER_VALIDATE_URL)) {
        $bcttURL = '&url=' . $url;
    } elseif ($url != 'no') {
        if ($short_url != '') {
            $bcttURL = '&url=' . $short_url . '&counturl=' . $post_url;
        } else {
            $bcttURL = '&url=' . $post_url;
        }
    } else {
        $bcttURL = '';
    }
    $bcttBttn = __('Click to Tweet', ESSB3_TEXT_DOMAIN);
    $user_text = ESSBOptionValuesHelper::options_value($essb_options, 'translate_clicktotweet');
    if ($user_text != '') {
        $bcttBttn = $user_text;
    }
    if ($url != 'no') {
        $short = essb_ctt_shorten($text, 117 - $handle_length);
    } else {
        $short = essb_ctt_shorten($text, 140 - $handle_length);
    }
    $link_short = $short;
    //$link_short = str_replace('#', '%23', $link_short);
    if ($nofollow != 'no') {
        $rel = "rel='nofollow'";
    } else {
        $rel = '';
    }
    if (!is_feed()) {
        return "<div class='essb-click-to-tweet' onclick=\"window.open('https://twitter.com/intent/tweet?text=" . urlencode($link_short) . $handle_code . $bcttURL . "', 'essb_share_window', 'height=300,width=500,resizable=1,scrollbars=yes');\">\n\t\t\t<span class='essb-click-to-tweet-quote'>\n\t\t\t" . $short . "\n\t\t\t</span>\n\t\t\t<span class='essb-click-to-tweet-button'>" . $bcttBttn . "<span class='essb-click-to-tweet-button-icon'></span>\n\t\t</div>";
    }
    //else {
    //	return "<hr /><p><em>" . $short . "</em><br /><a href='https://twitter.com/intent/tweet?text=" . urlencode ( $short ) . $handle_code . $bcttURL . "' target='_blank' class='essb-ctt-ctt-btn'" . $rel . ">" . $bcttBttn . "</a><br /><hr />";
    //}
}
    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;
    }