public static function get_counters($post_id, $share = array(), $networks)
 {
     global $essb_options;
     $cached_counters = array();
     $cached_counters['total'] = 0;
     if (!ESSBCachedCounters::is_fresh_cache($post_id)) {
         $cached_counters = ESSBCachedCounters::update_counters($post_id, $share['url'], $share['full_url'], $networks);
         if (defined('ESSB3_SHARED_COUNTER_RECOVERY')) {
             $recovery_till_date = ESSBOptionValuesHelper::options_value($essb_options, 'counter_recover_date');
             $is_applying_for_recovery = true;
             // @since 3.4 - apply recovery till provided date only
             if (!empty($recovery_till_date)) {
                 $is_applying_for_recovery = ESSBCachedCounters::is_matching_recovery_date($post_id, $recovery_till_date);
             }
             if ($is_applying_for_recovery) {
                 $current_url = $share['full_url'];
                 // get post meta recovery value
                 // essb_activate_sharerecovery - post meta recovery address
                 $post_essb_activate_sharerecovery = get_post_meta($post_id, 'essb_activate_sharerecovery', true);
                 if (!empty($post_essb_activate_sharerecovery)) {
                     $current_url = $post_essb_activate_sharerecovery;
                 } else {
                     $current_url = ESSBCachedCounters::get_alternate_permalink($current_url, $post_id);
                 }
                 $recovery_counters = ESSBCachedCounters::update_counters($post_id, $current_url, $current_url, $networks, true);
                 $cached_counters = ESSBCachedCounters::consolidate_results($cached_counters, $recovery_counters, $networks);
             }
         }
         foreach ($networks as $k) {
             $single = isset($cached_counters[$k]) ? $cached_counters[$k] : '0';
             update_post_meta($post_id, 'essb_c_' . $k, $single);
         }
     } else {
         foreach ($networks as $k) {
             $cached_counters[$k] = get_post_meta($post_id, 'essb_c_' . $k, true);
             $cached_counters['total'] += intval($cached_counters[$k]);
         }
     }
     //print_r($cached_counters);
     return $cached_counters;
 }
    public static function draw_share_buttons($share = array(), $style = array(), $networks = array(), $networks_order = array(), $network_names = array(), $position = '', $salt = '', $like_or_share = 'share', $native_buttons = '')
    {
        global $essb_networks, $essb_options;
        $content = "";
        $leading_width_mode_fullwidth = false;
        $button_width_full_first = ESSBOptionValuesHelper::options_value($style, 'button_width_full_first');
        $button_width_full_second = ESSBOptionValuesHelper::options_value($style, 'button_width_full_second');
        if (!empty($button_width_full_first) || !empty($button_width_full_second)) {
            $leading_width_mode_fullwidth = true;
        }
        $sigle_counter_hidden_till = ESSBGlobalSettings::$button_counter_hidden_till;
        //ESSBOptionValuesHelper::options_value($essb_options, 'button_counter_hidden_till');
        $mycred_group = ESSBGlobalSettings::$mycred_group;
        //ESSBOptionValuesHelper::options_value($essb_options, 'mycred_group', 'mycred_default');
        $mycred_points = ESSBGlobalSettings::$mycred_points;
        //ESSBOptionValuesHelper::options_value($essb_options, 'mycred_points', '1');
        $more_button_icon = ESSBGlobalSettings::$more_button_icon;
        //ESSBOptionValuesHelper::options_value($essb_options, 'more_button_icon');
        $comments_address = ESSBGlobalSettings::$comments_address;
        //ESSBOptionValuesHelper::options_value($essb_options, 'comments_address');
        if ($comments_address == '') {
            $comments_address = '#comments';
        }
        $button_follow_state = "nofollow";
        //if (ESSBOptionValuesHelper::options_bool_value($essb_options, 'use_rel_me')) {
        if (ESSBGlobalSettings::$use_rel_me) {
            $button_follow_state = "me";
        }
        if (isset($style['more_button_icon'])) {
            $more_button_icon = $style['more_button_icon'];
        }
        // since @3.2.4
        // encoding of url parts
        $share['essb_encode_text'] = ESSBGlobalSettings::$essb_encode_text;
        //ESSBOptionValuesHelper::options_bool_value($essb_options, 'essb_encode_text');
        $share['essb_encode_url'] = ESSBGlobalSettings::$essb_encode_url;
        //ESSBOptionValuesHelper::options_bool_value($essb_options, 'essb_encode_url');
        $share['essb_encode_text_plus'] = ESSBGlobalSettings::$essb_encode_text_plus;
        //ESSBOptionValuesHelper::options_bool_value($essb_options, 'essb_encode_text_plus');
        $cached_counters = array();
        $cached_counters_active = false;
        if (defined('ESSB3_CACHED_COUNTERS') && $style['show_counter']) {
            $cached_counter_networks = ESSBCachedCounters::prepare_list_of_networks_with_counter($networks_order, $networks);
            $cached_counters = ESSBCachedCounters::get_counters($share['post_id'], $share, $cached_counter_networks);
            $cached_counters_active = true;
        }
        // beginning of share buttons snippet
        $content .= ESSBButtonHelper::draw_buttons_start($style, $position, $salt, $like_or_share, $share, $cached_counters);
        $is_active_more_button = false;
        $is_active_fullwidth = false;
        if ($style['button_width'] == 'full') {
            $is_active_fullwidth = true;
        }
        $count_displayed = 0;
        foreach ($networks_order as $single) {
            // generate single network button
            if (in_array($single, $networks)) {
                if ($single == "no") {
                    continue;
                }
                $count_displayed++;
                $url = '';
                $api_command = '';
                $link_target = "_blank";
                $single_share_address = $single;
                $icon = $single;
                $cached_code_left = "";
                $cached_code_right = "";
                $cached_code_insidebefore = "";
                $cached_code_insideafter = "";
                $cached_code_before = "";
                if ($cached_counters_active) {
                    if (isset($cached_counters[$single])) {
                        $single_counter = isset($cached_counters[$single]) ? $cached_counters[$single] : '0';
                        if ($style['counter_pos'] == "left" || $style['counter_pos'] == "" || $style['counter_pos'] == "leftm" || $style['counter_pos'] == "topm" || $style['counter_pos'] == "top") {
                            $cached_code_left = ESSBButtonHelper::draw_share_counter_code('', $single_counter, $sigle_counter_hidden_till);
                        }
                        if ($style['counter_pos'] == "right" || $style['counter_pos'] == "rightm") {
                            $cached_code_right = ESSBButtonHelper::draw_share_counter_code('_right', $single_counter, $sigle_counter_hidden_till);
                        }
                        if ($style['counter_pos'] == "insidename" || $style['counter_pos'] == "inside" || $style['counter_pos'] == "bottom") {
                            $cached_code_insideafter = ESSBButtonHelper::draw_share_counter_code('_' . $style['counter_pos'], $single_counter, $sigle_counter_hidden_till);
                        }
                        if ($style['counter_pos'] == "insidebeforename") {
                            $cached_code_insidebefore = ESSBButtonHelper::draw_share_counter_code('_' . $style['counter_pos'], $single_counter, $sigle_counter_hidden_till);
                        }
                        if ($style['counter_pos'] == "hidden") {
                            $cached_code_right = ESSBButtonHelper::draw_share_counter_code('_' . $style['counter_pos'], $single_counter, $sigle_counter_hidden_till);
                        }
                        if ($style['counter_pos'] == "topn") {
                            $cached_code_before = ESSBButtonHelper::draw_share_counter_code('_' . $style['counter_pos'], $single_counter, $sigle_counter_hidden_till);
                        }
                    }
                }
                // specail network code
                //if ($single == "print" && ESSBOptionValuesHelper::options_bool_value($essb_options, 'print_use_printfriendly')) {
                if ($single == "print" && ESSBGlobalSettings::$print_use_printfriendly) {
                    $single_share_address = "print_friendly";
                }
                if ($single == "mail" && $style['mail_function'] == "form") {
                    $single_share_address = "mail_form";
                }
                //if ($single == "pinterest" && !ESSBOptionValuesHelper::options_bool_value($essb_options, 'pinterest_sniff_disable')) {
                if ($single == "pinterest" && !ESSBGlobalSettings::$pinterest_sniff_disable) {
                    $single_share_address = "pinterest_picker";
                }
                if (!$style['is_mobile']) {
                    //if ($single == "facebook" && ESSBOptionValuesHelper::options_bool_value($essb_options, 'facebookadvanced')) {
                    if ($single == "facebook" && ESSBGlobalSettings::$facebookadvanced) {
                        $fbappid = ESSBGlobalSettings::$facebookadvancedappid;
                        //ESSBOptionValuesHelper::options_value($essb_options, 'facebookadvancedappid');
                        if ($fbappid != '') {
                            $single_share_address = "facebook_advanced";
                        }
                    }
                }
                if ($single == "more" && $style['more_button_func'] != "1") {
                    $single_share_address = "more_popup";
                }
                if ($single == "more" && $more_button_icon == "dots") {
                    $icon = "more_dots";
                }
                if ($is_active_fullwidth && $count_displayed == 1 && $leading_width_mode_fullwidth) {
                    $icon .= ' essb_item_fw_first';
                }
                if ($is_active_fullwidth && $count_displayed == 2 && $leading_width_mode_fullwidth) {
                    $icon .= ' essb_item_fw_second';
                }
                // get single social network commands
                $share_details = ESSBButtonHelper::get_share_address($single_share_address, $share, $salt);
                $url = $share_details['url'];
                $api_command = $share_details['api_command'];
                if ($single == "sidebar-close") {
                    $api_command = "";
                }
                if ($single == "comments") {
                    $api_command = "";
                    $url = $comments_address;
                    $link_target = "_self";
                }
                if ($single_share_address == "mail" || $single_share_address == "line" || $single_share_address == "whatsapp") {
                    $link_target = "_self";
                }
                $hover_text = ESSBOptionValuesHelper::options_value($essb_options, 'hovertext_' . $single);
                $name = isset($network_names[$single]) ? $network_names[$single] : '';
                $noname_class = "";
                if ($style['button_style'] == "icon" || $name == "-" || $single == "more") {
                    $noname_class = " essb_noname";
                }
                if ($style['counter_pos'] == "insidehover" && $style['counters']) {
                    $noname_class .= " essb_hideonhover";
                }
                // clean network names when depends on button style or seleceted network
                if ($style['button_style'] == "icon" || ($style['counter_pos'] == "inside" || $style['counter_pos'] == "bottom") && $style['show_counter'] || $name == "-" || $single == "more") {
                    $name = "";
                }
                $mycred_token = "";
                if (defined('ESSB3_MYCRED_ACTIVE')) {
                    $mycred_token = ESSBMyCredIntegration::generate_mycred_datatoken($mycred_group, $mycred_points);
                }
                $more_after_class = $is_active_more_button ? " essb_after_more" : "";
                if ($single == "sidebar-close") {
                    $more_after_class = "";
                }
                $content .= sprintf('<li class="essb_item essb_link_%8$s nolightbox%2$s">
						%12$s<a href="%3$s" title="%4$s" onclick="%5$s" target="%10$s" rel="%11$s" %7$s>%13$s<span class="essb_icon"></span><span class="essb_network_name%9$s">%14$s%6$s%15$s</span></a>%16$s</li>', $single, $more_after_class, $url, $hover_text, $api_command, $name, $mycred_token, $icon, $noname_class, $link_target, $button_follow_state, $cached_code_left, $cached_code_before, $cached_code_insidebefore, $cached_code_insideafter, $cached_code_right);
                // at the end toggle more button state
                if ($single == "more") {
                    $is_active_more_button = true;
                }
            }
        }
        // adding less button when + function of more button is active
        if ($is_active_more_button && $style['more_button_func'] == "1") {
            $share_details = ESSBButtonHelper::get_share_address("less", $share, $salt);
            $url = $share_details['url'];
            $api_command = $share_details['api_command'];
            $content .= sprintf('<li class="essb_item essb_link_%1$s nolightbox%2$s">
					<a href="%3$s" title="%4$s" onclick="%5$s" target="_blank" rel="nofollow"><span class="essb_icon"></span><span class="essb_network_name">%6$s</span></a></li>', "less", $more_after_class, $url, "", $api_command, "");
        }
        if (is_array($native_buttons)) {
            if ($native_buttons['active']) {
                if ($native_buttons['sameline']) {
                    $content .= ESSBNativeButtonsHelper::draw_native_buttons($native_buttons, $native_buttons['order'], $native_buttons['counters'], $native_buttons['sameline'], $native_buttons['skinned']);
                }
            }
        }
        // end of share buttons snippet
        $content .= ESSBButtonHelper::draw_buttons_end($style, $position, $salt, $like_or_share, $native_buttons, $cached_counters, $share);
        return $content;
    }
示例#3
0
 function essb_shortcode_total_shares($atts)
 {
     global $post;
     $atts = shortcode_atts(array('message' => '', 'align' => '', 'url' => '', 'share_text' => '', 'fullnumber' => 'no', 'networks' => '', 'inline' => 'no'), $atts);
     $align = isset($atts['align']) ? $atts['align'] : '';
     $message = isset($atts['message']) ? $atts['message'] : '';
     $url = isset($atts['url']) ? $atts['url'] : '';
     $share_text = isset($atts['share_text']) ? $atts['share_text'] : '';
     $fullnumber = isset($atts['fullnumber']) ? $atts['fullnumber'] : 'no';
     $networks = isset($atts['networks']) ? $atts['networks'] : 'no';
     $inline = isset($atts['inline']) ? $atts['inline'] : 'no';
     $data_full_number = "false";
     if ($fullnumber == 'yes') {
         $data_full_number = "true";
     }
     // init global options
     $options = $this->options;
     if ($networks != '') {
         $buttons = $networks;
     } else {
         $buttons = implode(',', $this->network_options['networks']);
     }
     $css_class_align = "";
     $data_url = $post ? get_permalink() : ESSBUrlHelper::get_current_url('raw');
     if (ESSBOptionValuesHelper::options_bool_value($this->options, 'avoid_nextpage')) {
         $data_url = $post ? get_permalink(get_the_ID()) : ESSBUrlHelper::get_current_url('raw');
     }
     if (ESSBOptionValuesHelper::options_bool_value($this->options, 'force_wp_fullurl')) {
         $data_url = ESSBUrlHelper::get_current_page_url();
     }
     if (ESSBOptionValuesHelper::options_bool_value($this->options, 'always_use_http')) {
         $data_url = str_replace("https://", "http://", $data_url);
     }
     if ($url != '') {
         $data_url = $url;
     }
     $data_post_id = "";
     if (isset($post)) {
         $data_post_id = $post->ID;
     }
     if ($align == "right" || $align == "center") {
         $css_class_align = $align;
     }
     $total_counter_hidden = $this->general_options['total_counter_hidden_till'];
     // @since 3.3 support for cached counters
     $cached_counters = array();
     $cached_counters_active = false;
     $cached_total_counter = '';
     if (defined('ESSB3_CACHED_COUNTERS')) {
         $share_options = array('url' => $data_url, 'full_url' => $data_url);
         $cached_counter_networks = ESSBCachedCounters::prepare_list_of_networks_with_counter(explode(',', $buttons), explode(',', $buttons));
         $cached_counters = ESSBCachedCounters::get_counters($data_post_id, $share_options, $cached_counter_networks);
         $cached_counters_active = true;
     } else {
         $use_minifed_js = $this->general_options['use_minified_js'] ? ".min" : "";
         $script_url = ESSB3_PLUGIN_URL . '/assets/js/easy-social-share-buttons-total' . $use_minifed_js . '.js';
         essb_resource_builder()->add_static_resource_footer($script_url, 'easy-social-share-buttons-total', 'js');
     }
     $css_hide_total_counter = "";
     if ($total_counter_hidden != '') {
         $css_hide_total_counter = ' style="display: none !important;" data-essb-hide-till="' . $total_counter_hidden . '"';
     }
     if ($cached_counters_active) {
         $cached_total_counter = isset($cached_counters['total']) ? $cached_counters['total'] : '0';
         if ($total_counter_hidden != '') {
             if (intval($cached_total_counter) > intval($total_counter_hidden)) {
                 $css_hide_total_counter = "";
             }
         }
         $cached_total_counter = ESSBButtonHelper::kilomega($cached_total_counter);
     }
     $output = "";
     $tag = $inline == 'yes' ? 'span' : 'div';
     $output .= '<' . $tag . ' class="essb-total ' . $css_class_align . '" data-network-list="' . $buttons . '" data-url="' . $data_url . '" data-full-number="' . $data_full_number . '" data-post="' . $data_post_id . '" ' . $css_hide_total_counter . '>';
     if ($message != '') {
         $output .= '<' . $tag . ' class="essb-message essb-block">' . $message . '</' . $tag . '>';
     }
     $output .= '<' . $tag . ' class="essb-total-value essb-block">' . $cached_total_counter . '</' . $tag . '>';
     if ($share_text != '') {
         $output .= '<' . $tag . ' class="essb-total-text essb-block">' . $share_text . '</' . $tag . '>';
     }
     $output .= '</' . $tag . '>';
     return $output;
 }