/** * Public funciton: we need to use it to generate the widget's content outside the class. * This funciton is also used to generate the content for shortcode since it has similar layout. * It generates the content for widget by default. */ public static function display_widget($type = 'widget', $shortcode_atts = '') { $monarch_options = ET_Monarch::get_options_array(); //check whether social networks selected, if yes - process all the settings and generate the icons, otherwise generate empty container if (isset($monarch_options['follow_networks_networks_sorting']) && !empty($monarch_options['follow_networks_networks_sorting'])) { // If we're generating content for shortcode, then shortcode attributes should be used $col_number = 'shortcode' == $type ? $shortcode_atts['col_number'] : $monarch_options['follow_widget_col_number']; $icon_style = 'shortcode' == $type ? $shortcode_atts['icon_style'] : $monarch_options['follow_widget_icon_style']; $icon_shape = 'shortcode' == $type ? $shortcode_atts['icon_shape'] : $monarch_options['follow_widget_icon_shape']; $icons_location = 'shortcode' == $type ? $shortcode_atts['icons_location'] : $monarch_options['follow_widget_icons_location']; $counts = 'shortcode' == $type ? $shortcode_atts['counts'] : $monarch_options['follow_widget_counts']; $counts_num = 'shortcode' == $type ? intval($shortcode_atts['counts_num']) : intval($monarch_options['follow_widget_counts_num']); $spacing = 'shortcode' == $type ? $shortcode_atts['spacing'] : $monarch_options['follow_widget_spacing']; $total = 'shortcode' == $type ? $shortcode_atts['total'] : $monarch_options['follow_widget_total']; $outer_color = 'shortcode' == $type ? $shortcode_atts['outer_color'] : $monarch_options['follow_widget_outer_color']; $hide_mobile = 'shortcode' == $type ? $shortcode_atts['mobile'] : $monarch_options['follow_widget_mobile']; $network_names = 'shortcode' == $type ? $shortcode_atts['network_names'] : $monarch_options['follow_widget_network_names']; $custom_colors = false; if ('shortcode' == $type && false !== $shortcode_atts['custom_colors']) { $custom_colors = true; $bg_color = $shortcode_atts['bg_color']; $bg_color_hover = $shortcode_atts['bg_color_hover']; $icon_color = $shortcode_atts['icon_color']; $icon_color_hover = $shortcode_atts['icon_color_hover']; $shortcodes_count = ET_Monarch::$shortcodes_count++; // shortcodes global counter to apply color styles properly. } if (isset($monarch_options['general_main_reset_postdata']) && true == $monarch_options['general_main_reset_postdata']) { wp_reset_postdata(); } $sharing_icons = '<ul class="et_social_icons_container">'; $i = 0; $post_id = is_singular() ? get_the_ID() : 0; foreach ($monarch_options['follow_networks_networks_sorting']['class'] as $icon) { $icon_name = $monarch_options['follow_networks_networks_sorting']['label'][$i]; $is_follows_cached = ET_Monarch::check_cached_counts(get_the_ID(), $icon, 'follow', $monarch_options['follow_networks_use_api']); $follow_counts = true == $counts && true == $is_follows_cached ? ET_Monarch::get_follow_counts($counts_num, $icon, $i, true, false) : ''; $network_name = true == $network_names ? sprintf('<div class="et_social_networkname">%1$s</div>', esc_html($icon_name)) : ''; $icon_label = true == $counts || '' != $network_name ? sprintf('<div class="et_social_network_label%2$s"%3$s%4$s%5$s>%1$s%6$s</div>', '' != $network_name ? $network_name : '', true == $counts && false == $is_follows_cached ? ' et_social_display_follow_counts' : '', true == $counts && false == $is_follows_cached ? sprintf(' data-min_count="%1$s"', esc_attr($counts_num)) : '', true == $counts && false == $is_follows_cached ? sprintf(' data-network="%1$s"', esc_attr($icon)) : '', true == $counts && false == $is_follows_cached ? sprintf(' data-index="%1$s"', esc_attr($i)) : '', $follow_counts) : ''; $sharing_icons .= sprintf('<li class="et_social_%1$s"> <a href="%5$s" class="et_social_follow" data-social_name="%1$s" data-social_type="%3$s" data-post_id="%4$s"%6$s> <i class="et_social_icon et_social_icon_%1$s"></i> %2$s <span class="et_social_overlay"></span> </a> </li>', esc_attr($icon), $icon_label, 'like' == $icon ? 'like' : 'follow', esc_attr($post_id), ET_Monarch::get_follow_link($icon, isset($monarch_options['follow_networks_networks_sorting']['username'][$i]) ? $monarch_options['follow_networks_networks_sorting']['username'][$i] : ''), true == $monarch_options['follow_networks_new_window'] ? ' target="_blank"' : ''); $i++; } $sharing_icons .= '</ul>'; $widget_output = sprintf('<div class="et_social_networks et_social_%2$s et_social_%3$s et_social_%4$s et_social_%5$s%6$s%7$s%9$s%11$s%12$s%13$s%14$s%15$s"> %10$s %8$s %1$s </div>', $sharing_icons, 'auto' == $col_number ? 'autowidth' : esc_html($col_number . 'col'), esc_attr($icon_style), esc_attr($icon_shape), esc_attr($icons_location), true == $counts ? ' et_social_withcounts' : '', true == $spacing ? ' et_social_nospace' : '', true == $total ? sprintf('<div class="et_social_totalcount"> <span class="et_social_totalcount_count et_social_follow_total"></span> <span class="et_social_totalcount_label">%1$s</span> </div>', esc_html__('Follows', 'Monarch')) : '', 'shortcode' == $type && true == $custom_colors ? esc_attr(' et_social_shortcode_' . $shortcodes_count) : '', 'shortcode' == $type && true == $custom_colors ? sprintf('<style type="text/css">%1$s%2$s%3$s%4$s</style>', '' !== $bg_color ? sprintf('.et_monarch .et_social_shortcode_%1$s li,.et_monarch .et_social_shortcode_%1$s.et_social_circle ul li i.et_social_icon { background: %2$s; }', esc_html($shortcodes_count), esc_html($bg_color)) : '', '' !== $bg_color_hover ? sprintf(' .et_monarch .et_social_shortcode_%1$s.et_social_rounded .et_social_icons_container li:hover, .et_monarch .et_social_shortcode_%1$s.et_social_rectangle .et_social_icons_container li:hover, .et_monarch .et_social_shortcode_%1$s.et_social_circle .et_social_icons_container li:hover i.et_social_icon { background: %2$s !important; }', esc_html($shortcodes_count), esc_html($bg_color_hover)) : '', '' !== $icon_color ? sprintf(' .et_monarch .et_social_shortcode_%1$s .et_social_icon, .et_monarch .et_social_shortcode_%1$s .et_social_networks .et_social_network_label, .et_monarch .et_social_shortcode_%1$s .et_social_networkname, .et_monarch .et_social_shortcode_%1$s .et_social_count { color: %2$s !important; }', esc_html($shortcodes_count), esc_html($icon_color)) : '', '' !== $icon_color_hover ? sprintf(' .et_monarch .et_social_shortcode_%1$s .et_social_icons_container li:hover .et_social_icon, .et_monarch .et_social_shortcode_%1$s .et_social_networks .et_social_icons_container li:hover .et_social_network_label, .et_monarch .et_social_shortcode_%1$s .et_social_icons_container li:hover .et_social_networkname, .et_monarch .et_social_rounded.et_social_shortcode_%1$s .et_social_icons_container li:hover .et_social_count, .et_monarch .et_social_rectangle.et_social_shortcode_%1$s .et_social_icons_container li:hover .et_social_count { color: %2$s !important; }', esc_html($shortcodes_count), esc_html($icon_color_hover)) : '') : '', true == $total ? ' et_social_withtotalcount' : '', true == $hide_mobile ? ' et_social_mobile_off' : ' et_social_mobile_on', true == $network_names ? ' et_social_withnetworknames' : '', esc_attr(sprintf(' et_social_outer_%1$s', $outer_color)), 'widget' == $type ? ' widget_monarchwidget' : ''); } else { $widget_output = sprintf('<div class="et_social_networks no_networks_selected"></div>'); } return $widget_output; }