theme;
if ( ! empty( $atts['theme'] ) ) {
$theme = $atts['theme'];
}
$theme = $this->is_theme_available( $theme );
if ( ! empty( $atts['post_count'] ) ) {
$limit = intval( $atts['post_count'] );
} else {
$limit = $this->count;
}
$posts = $this->get_posts_to_display();
if ( empty( $posts ) ) {
return '';
}
if ( 'curated' === $this->sort && apply_filters( 'exactmetrics_popular_posts_widget_curated_shuffle', true ) ) {
// Randomize the order.
shuffle( $posts );
}
$theme_styles = $this->get_theme_props( $theme )->get_theme();
$label_text = '';
if ( isset( $theme_styles['styles']['label'] ) ) {
$label_text = isset( $atts['label_text'] ) ? $atts['label_text'] : $theme_styles['styles']['label']['text'];
}
if ( isset( $atts['widget_title'] ) ) {
$show_title = (bool) $atts['widget_title'];
$title_text = empty( $atts['widget_title_text'] ) ? '' : $atts['widget_title_text'];
} else {
$show_title = $this->title;
$title_text = $this->title_text;
}
$html = '
';
if ( $show_title ) {
$html .= '
' . wp_kses_post( $title_text ) . '
';
}
$html .= '
';// Main div.
return $html;
}
/**
* Add widget-specific styles based on theme settings.
*/
public function build_inline_styles() {
$themes = $this->get_themes_styles_for_output();
$styles = '';
foreach ( $themes as $theme_key => $theme_styles ) {
if ( ! empty( $theme_styles['background'] ) ) {
$styles .= '.exactmetrics-popular-posts-styled.exactmetrics-widget-popular-posts.exactmetrics-widget-popular-posts-' . $theme_key . ' .exactmetrics-widget-popular-posts-list li {';
if ( ! empty( $theme_styles['background']['color'] ) ) {
$styles .= 'background-color:' . $theme_styles['background']['color'] . ';';
}
if ( ! empty( $theme_styles['background']['border'] ) ) {
$styles .= 'border-color:' . $theme_styles['background']['border'] . ';';
}
$styles .= '}';
}
if ( ! empty( $theme_styles['label'] ) ) {
$styles .= '.exactmetrics-popular-posts-styled.exactmetrics-widget-popular-posts.exactmetrics-widget-popular-posts-' . $theme_key . ' .exactmetrics-widget-popular-posts-label {';
if ( ! empty( $theme_styles['label']['color'] ) ) {
$styles .= 'color:' . $theme_styles['label']['color'] . ';';
}
if ( ! empty( $theme_styles['label']['background'] ) ) {
$styles .= 'background-color:' . $theme_styles['label']['background'] . ';';
}
$styles .= '}';
}
if ( ! empty( $theme_styles['title'] ) ) {
$styles .= '.exactmetrics-popular-posts-styled.exactmetrics-widget-popular-posts.exactmetrics-widget-popular-posts-' . $theme_key . ' .exactmetrics-widget-popular-posts-list li .exactmetrics-widget-popular-posts-title {';
if ( ! empty( $theme_styles['title']['color'] ) ) {
$styles .= 'color:' . $theme_styles['title']['color'] . ';';
}
if ( ! empty( $theme_styles['title']['size'] ) ) {
$styles .= 'font-size:' . $theme_styles['title']['size'] . 'px;';
}
$styles .= '}';
}
if ( ! empty( $theme_styles['border'] ) ) {
$styles .= '.exactmetrics-popular-posts-styled.exactmetrics-widget-popular-posts-' . $theme_key . ' .exactmetrics-inline-popular-posts-border {';
if ( ! empty( $theme_styles['border']['color'] ) ) {
$styles .= 'border-color:' . $theme_styles['border']['color'] . ';';
}
$styles .= '}';
}
}
return $styles;
}
/**
* Check if we should attempt to automatically insert the inline widget.
*/
public function maybe_auto_insert() {
$post_types = $this->post_types;
if ( ! empty( $post_types ) && is_singular( $post_types ) && $this->automatic ) {
add_filter( 'the_content', array( $this, 'add_inline_posts_to_content' ) );
}
}
/**
* Insert the widget in the content.
*
* @param string $content The post content.
*
* @return string
*/
public function add_inline_posts_to_content( $content ) {
if ( $this->is_post_excluded() ) {
return $content;
}
$content .= $this->shortcode_output( array() );
return $content;
}
/**
* Check if the selected theme is available with the current license to avoid showing a theme not available.
* Returns the default 'alpha' theme if not available.
*
* @param string $theme Theme slug for which we are checking.
*
* @return string
*/
public function is_theme_available( $theme ) {
$theme_props = $this->get_theme_props( $theme )->get_theme();
if ( ! empty( $theme_props['level'] ) && 'lite' === $theme_props['level'] ) {
return $theme;
}
return 'alpha';
}
}
/**
* Get the current class in a function.
*
* @return ExactMetrics_Popular_Posts_Widget Instance of the current class.
*/
function ExactMetrics_Popular_Posts_Widget() {
return ExactMetrics_Popular_Posts_Widget::get_instance();
}
ExactMetrics_Popular_Posts_Widget();