/** * Displays the sitewide comments widget. * * @uses ClassBlogs_Plugins_Aggregation_SitewideComments to get all sitewide comments */ public function widget($args, $instance) { $instance = $this->maybe_apply_instance_defaults($instance); $plugin = ClassBlogs::get_plugin('sitewide_comments'); $sitewide_comments = $plugin->get_comments_for_widget($instance['max_comments'], $instance['max_comments_per_blog'], $instance['meta_format']); if (empty($sitewide_comments)) { return; } $this->start_widget($args, $instance); echo '<ul>'; foreach ($sitewide_comments as $comment) { ?> <li class="cb-sitewide-comment"> <?php printf(_x('%1$s on %2$s', 'comment author, then post', 'classblogs'), '<span class="cb-sitewide-comment-author">' . esc_html($comment->author_name) . '</span>', '<a class="cb-sitewide-comment-post" href="' . esc_url($comment->permalink) . '">' . esc_html($comment->post_title) . '</a>'); ?> <?php if ($comment->meta) { ?> <p class="cb-sitewide-comment-meta"><?php echo $comment->meta; ?> </p> <?php } ?> <?php if ($instance['show_excerpt']) { ?> <p class="cb-sitewide-comment-excerpt"><?php echo esc_html(ClassBlogs_Utils::make_post_excerpt($comment->content, self::_EXCERPT_LENGTH_WORDS)); ?> </p> <?php } ?> </li> <?php } echo '</ul>'; $this->end_widget($args); }
/** * Returns an array of sitewide posts. * * These posts returned are limited only by the options of the sitewide * aggregator, which can restrict which blogs populate the sitewide tables. * The returned posts are in descending order by their published date. * * Since the posts will be from multiple different blogs, certain values * are precomputed and added to each post. The values are as follows: * * cb_sw_excerpt - the post's excerpt * cb_sw_from_blog - the ID of the blog on which the post was made * * @return array a list of sitewide posts * * @since 0.1 */ public function get_sitewide_posts() { // Return the cached version if we've already built the sitewide post list $cached = $this->get_site_cache('all_posts'); if ($cached !== null) { return $cached; } global $nxtdb; $posts = array(); $use_root_excerpt = $this->get_option('root_use_excerpt'); $excerpt_words = $this->get_option('root_excerpt_words'); foreach ($nxtdb->get_results("SELECT * FROM {$this->sw_tables->posts} ORDER BY post_date DESC") as $post) { // Precompute each post's excerpt if ($use_root_excerpt) { $post->cb_sw_excerpt = ClassBlogs_Utils::make_post_excerpt($post->post_content, $excerpt_words); } $posts[] = $post; } $this->set_site_cache('all_posts', $posts); return $posts; }