Skip to:
Content

BuddyPress.org

Ticket #4982: bp-blogs-widgets.php

File bp-blogs-widgets.php, 4.5 KB (added by lenasterg, 13 years ago)

Patched file

Line 
1<?php
2/**
3 * BuddyPress Blogs Widgets
4 *
5 * @package BuddyPress
6 * @subpackage BlogsWidgets
7 */
8// Exit if accessed directly
9if (!defined('ABSPATH'))
10 exit;
11
12// @todo not use create_function()
13function bp_blogs_register_widgets() {
14 global $wpdb;
15
16 if (bp_is_active('activity') && (int) $wpdb->blogid == bp_get_root_blog_id())
17 add_action('widgets_init', create_function('', 'return register_widget("BP_Blogs_Recent_Posts_Widget");'));
18}
19
20add_action('bp_register_widgets', 'bp_blogs_register_widgets');
21
22class BP_Blogs_Recent_Posts_Widget extends WP_Widget {
23
24 function __construct() {
25 $widget_ops = array(
26 'description' => __('A list of recently added posts from the network blogs', 'buddypress'),
27 'classname' => 'widget_bp_blogs_widget buddypress',
28 );
29
30 parent::__construct(false, $name = _x('(BuddyPress) Recent Networkwide Posts', 'widget name', 'buddypress'), $widget_ops);
31 }
32
33 function widget($args, $instance) {
34 extract($args);
35 if (empty($instance['title']))
36 $instance['title'] = __('Recent Networkwide Posts', 'buddypress');
37
38 echo $before_widget;
39
40 $title = !empty($instance['link_title']) ? '<a href="' . trailingslashit(bp_get_root_domain() . '/' . bp_get_blogs_root_slug()) . '">' . $instance['title'] . '</a>' : $instance['title'];
41
42 echo $before_title . $title . $after_title;
43
44 if (empty($instance['max_posts']) || !$instance['max_posts'])
45 $instance['max_posts'] = 10;
46 ?>
47
48 <?php // Override some of the contextually set parameters for bp_has_activities() ?>
49 <?php if (bp_has_activities(array('action' => 'new_blog_post', 'max' => $instance['max_posts'], 'per_page' => $instance['max_posts'], 'user_id' => 0, 'scope' => false, 'object' => false, 'primary_id' => false))) : ?>
50
51 <ul id="blog-post-list" class="activity-list item-list">
52
53 <?php while (bp_activities()) : bp_the_activity(); ?>
54
55 <li>
56 <div class="activity-content" style="margin: 0">
57
58 <div class="activity-header">
59 <?php bp_activity_action() ?>
60 </div>
61
62 <?php if (bp_get_activity_content_body()) : ?>
63 <div class="activity-inner">
64 <?php bp_activity_content_body() ?>
65 </div>
66 <?php endif; ?>
67
68 </div>
69 </li>
70 <?php endwhile; ?>
71 </ul>
72 <?php else : ?>
73 <div id="message" class="info">
74 <p><?php _e('Sorry, there were no posts found. Why not write one?', 'buddypress') ?></p>
75 </div>
76 <?php endif; ?>
77
78 <?php echo $after_widget; ?>
79 <?php
80 }
81
82 function update($new_instance, $old_instance) {
83 $instance = $old_instance;
84 $instance['title'] = strip_tags($new_instance['title']);
85 $instance['max_posts'] = strip_tags($new_instance['max_posts']);
86 $instance['link_title'] = (bool) $new_instance['link_title'];
87
88 return $instance;
89 }
90
91 function form($instance) {
92 $defaults = array(
93 'title' => __('Recent Networkwite Posts', 'buddypress'),
94 'max_posts' => 10,
95 );
96 $instance = wp_parse_args((array) $instance, $defaults);
97
98 $title = strip_tags($instance['title']);
99 $link_title = (bool) $instance['link_title'];
100 $max_posts = strip_tags($instance['max_posts']);
101 ?>
102 <p><label for="bp-blogs-widget-title"><?php _e('Title:', 'buddypress'); ?> <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" style="width: 100%" /></label></p>
103 <p><label for="<?php echo $this->get_field_name('link_title') ?>"><input type="checkbox" name="<?php echo $this->get_field_name('link_title') ?>" value="1" <?php checked($link_title) ?> /> <?php _e('Link widget title to Blogs directory', 'buddypress') ?></label></p>
104
105 <p><label for="bp-blogs-widget-posts-max"><?php _e('Max posts to show:', 'buddypress'); ?> <input class="widefat" id="<?php echo $this->get_field_id('max_posts'); ?>" name="<?php echo $this->get_field_name('max_posts'); ?>" type="text" value="<?php echo esc_attr($max_posts); ?>" style="width: 30%" /></label></p>
106 <?php
107 }
108
109}