theme; if ( ! empty( $atts['theme'] ) ) { $theme = $atts['theme']; } $theme = $this->is_theme_available( $theme ); $posts = $this->get_posts_to_display(); if ( empty( $posts ) ) { return ''; } if ( 'curated' === $this->sort && apply_filters( 'monsterinsights_popular_posts_inline_curated_shuffle', true ) ) { // Randomize the order. shuffle( $posts ); } $theme_styles = $this->get_theme_props( $theme )->get_theme(); $limit = ! empty( $theme_styles['posts'] ) ? $theme_styles['posts'] : 1; $label_text = ''; if ( isset( $theme_styles['styles']['label'] ) ) { $label_text = isset( $atts['labelText'] ) ? $atts['labelText'] : $theme_styles['styles']['label']['text']; } // Wrap in a P tag to keep the same spacing. $html = '
get_element_style( $theme, 'background', $atts ) . '>'; if ( ! empty( $theme_styles['image'] ) && ! empty( $posts[0]['image'] ) ) { $html .= ''; } $html .= '';// Text div. $html .= '

';// Main div. return $html; } /** * Specific inline styles based on theme settings. * * @return string */ 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 .= '.monsterinsights-inline-popular-posts.monsterinsights-popular-posts-styled.monsterinsights-inline-popular-posts-' . $theme_key . ' {'; 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 .= '.monsterinsights-inline-popular-posts.monsterinsights-popular-posts-styled.monsterinsights-inline-popular-posts-' . $theme_key . ' .monsterinsights-inline-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 .= '.monsterinsights-inline-popular-posts.monsterinsights-popular-posts-styled.monsterinsights-inline-popular-posts-' . $theme_key . ' .monsterinsights-inline-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 .= '.monsterinsights-inline-popular-posts.monsterinsights-popular-posts-styled.monsterinsights-inline-popular-posts-' . $theme_key . ' .monsterinsights-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 ) && 'automatic' === $this->placement ) { 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; } $words_count = str_word_count( $content ); $after_count = intval( $this->after_count ); // Insert only if there are more words then the insert after value. if ( $words_count > $after_count ) { $words = explode( ' ', $content ); $count = 0; foreach ( $words as $index => $word ) { $count ++; if ( $count > $after_count ) { $p_index = strpos( $word, '

' ); // Make sure the paragraph tag is not wrapped in another element like a blockquote. if ( false !== $p_index && false === strpos( $word, '

shortcode_output( array() ), $p_index + 4, 0 ); $this->posts = array(); break; } } } $content = implode( ' ', $words ); } 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 MonsterInsights_Popular_Posts_Inline Instance of the current class. */ function MonsterInsights_Popular_Posts_Inline() { return MonsterInsights_Popular_Posts_Inline::get_instance(); } MonsterInsights_Popular_Posts_Inline();