Skip to:
Content

BuddyPress.org

Ticket #428: bp-blogs-widgets.php

File bp-blogs-widgets.php, 3.2 KB (added by j.conti, 17 years ago)

File Ready to use

Line 
1<?php
2
3/* Register widgets for blogs component */
4function bp_blogs_register_widgets() {
5 global $current_blog;
6
7 /* Latest Posts Widget */
8 register_sidebar_widget( __('Recent Blog Posts', 'buddypress'), 'bp_blogs_widget_recent_posts');
9 register_widget_control( __('Recent Blog Posts', 'buddypress'), 'bp_blogs_widget_recent_posts_control' );
10}
11add_action( 'plugins_loaded', 'bp_blogs_register_widgets' );
12
13
14function bp_blogs_widget_recent_posts($args) {
15 global $current_blog;
16
17 extract($args);
18 $options = get_blog_option( $current_blog->blog_id, 'bp_blogs_widget_recent_posts' );
19?>
20 <?php echo $before_widget; ?>
21 <?php echo $before_title
22 . $widget_name
23 . $after_title; ?>
24
25 <?php $posts = bp_blogs_get_latest_posts( null, $options['max_posts'] ) ?>
26 <?php $counter = 0; ?>
27
28 <?php if ( $posts ) : ?>
29 <div class="item-options" id="recent-posts-options">
30 <?php _e("Site Wide", 'buddypress') ?>
31 </div>
32 <ul id="recent-posts" class="item-list">
33 <?php foreach ( $posts as $post ) : ?>
34 <li>
35 <div class="item-avatar">
36 <a href="<?php echo bp_post_get_permalink( $post, $post->blog_id ) ?>" title="<?php echo apply_filters( 'the_title', $post->post_title ) ?>"><?php echo bp_core_get_avatar( $post->post_author, 1 ) ?></a>
37 </div>
38
39 <div class="item">
40 <h4 class="item-title"><a href="<?php echo bp_post_get_permalink( $post, $post->blog_id ) ?>" title="<?php echo apply_filters( 'the_title', $post->post_title ) ?>"><?php echo apply_filters( 'the_title', $post->post_title ) ?></a></h4>
41 <?php if ( !$counter ) : ?>
42 <div class="item-content"><?php echo bp_create_excerpt($post->post_content) ?></div>
43 <?php endif; ?>
44 <div class="item-meta"><em><?php _e('by ','buddypress'); ?> <?php echo bp_core_get_userlink($post->post_author) ?><?php _e(' from the blog ', 'buddypress'; ?>"<a href="<?php echo get_blog_option($post->blog_id, 'siteurl') ?>"><?php echo get_blog_option($post->blog_id, 'blogname') ?></a>"</em></div>
45 </div>
46 </li>
47 <?php $counter++; ?>
48 <?php endforeach; ?>
49 </ul>
50 <?php else: ?>
51 <div class="widget-error">
52 <?php _e('There are no recent blog posts, why not write one?', 'buddypress') ?>
53 </div>
54 <?php endif; ?>
55
56 <?php echo $after_widget; ?>
57<?php
58}
59
60function bp_blogs_widget_recent_posts_control() {
61 global $current_blog;
62
63 $options = $newoptions = get_blog_option( $current_blog->blog_id, 'bp_blogs_widget_recent_posts');
64
65 if ( $_POST['bp-blogs-widget-recent-posts-submit'] ) {
66 $newoptions['max_posts'] = strip_tags( stripslashes( $_POST['bp-blogs-widget-recent-posts-max'] ) );
67 }
68
69 if ( $options != $newoptions ) {
70 $options = $newoptions;
71 update_blog_option( $current_blog->blog_id, 'bp_blogs_widget_recent_posts', $options );
72 }
73
74 $max_posts = attribute_escape( $options['max_posts'] );
75?>
76 <p><label for="bp-blogs-widget-recent-posts-max"><?php _e('Max Number of Posts:', 'buddypress'); ?> <input class="widefat" id="bp-blogs-widget-recent-posts-max" name="bp-blogs-widget-recent-posts-max" type="text" value="<?php echo $max_posts; ?>" style="width: 30%" /></label></p>
77 <input type="hidden" id="bp-blogs-widget-recent-posts-submit" name="bp-blogs-widget-recent-posts-submit" value="1" />
78<?php
79}
80
81?>