Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
07/15/2009 12:47:21 AM (17 years ago)
Author:
apeatling
Message:

Updating BuddyPress widgets to support new widget API.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/1.0/bp-activity/bp-activity-widgets.php

    r1520 r1602  
    33/* Register widgets for blogs component */
    44function bp_activity_register_widgets() {
    5         global $current_blog;
    6 
    7         /* Site Wide Activity Widget */
    8         wp_register_sidebar_widget( 'buddypress-activity', __('Site Wide Activity', 'buddypress'), 'bp_activity_widget_sitewide_activity');
    9         wp_register_widget_control( 'buddypress-activity', __('Site Wide Activity', 'buddypress'), 'bp_activity_widget_sitewide_activity_control' );
    10 
    11         if ( is_active_widget( 'bp_activity_widget_sitewide_activity' ) ) {
    12                 wp_enqueue_style( 'bp-activity-widget-activity-css', BP_PLUGIN_URL . '/bp-activity/css/widget-activity.css' );         
    13         }
     5        add_action('widgets_init', create_function('', 'return register_widget("BP_Activity_Widget");') );
    146}
    157add_action( 'plugins_loaded', 'bp_activity_register_widgets' );
    168
    17 
    18 function bp_activity_widget_sitewide_activity($args) {
    19         global $bp, $current_blog;
    20        
    21     extract($args);
    22         $options = get_blog_option( $current_blog->blog_id, 'bp_activity_widget_sitewide_activity' );
    23 ?>
    24         <?php echo $before_widget; ?>
    25         <?php echo $before_title
    26                 . $widget_name
    27                 . $after_title; ?>
    28                
    29         <?php
    30         if ( !$options['max_items'] || empty( $options['max_items'] ) )
    31                 $options['max_items'] = 20;
    32         ?>
    33        
    34         <?php
    35         if ( !$activity = wp_cache_get( 'sitewide_activity', 'bp' ) ) {
    36                 $activity = bp_activity_get_sitewide_activity( $options['max_items'] );
    37                 wp_cache_set( 'sitewide_activity', $activity, 'bp' );
    38         }
    39         ?>
    40 
    41         <?php if ( $activity['activities'] ) : ?>
    42                 <div class="item-options" id="activity-list-options">
    43                         <img src="<?php echo $bp->activity->image_base; ?>/rss.png" alt="<?php _e( 'RSS Feed', 'buddypress' ) ?>" /> <a href="<?php bp_sitewide_activity_feed_link() ?>" title="<?php _e( 'Site Wide Activity RSS Feed', 'buddypress' ) ?>"><?php _e( 'RSS Feed', 'buddypress' ) ?></a>
    44                 </div>
    45                 <ul id="site-wide-stream" class="activity-list">
    46                 <?php foreach( $activity['activities'] as $item ) : ?>
    47                         <li class="<?php echo $item['component_name'] ?>">
    48                                 <?php echo apply_filters( 'bp_get_activity_content', bp_activity_content_filter( $item['content'], $item['date_recorded'], '', true, false, true ) ); ?>
    49                         </li>
    50                 <?php endforeach; ?>
    51                 </ul>
    52         <?php else: ?>
    53                 <div class="widget-error">
    54                         <?php _e('There has been no recent site activity.', 'buddypress') ?>
    55                 </div>
    56         <?php endif; ?>
    57 
    58         <?php echo $after_widget; ?>
    59 <?php
    60 }
    61 
    62 function bp_activity_widget_sitewide_activity_control() {
    63         global $current_blog;
    64        
    65         $options = $newoptions = get_blog_option( $current_blog->blog_id, 'bp_activity_widget_sitewide_activity');
    66 
    67         if ( $_POST['bp-activity-widget-sitewide-submit'] ) {
    68                 $newoptions['max_items'] = strip_tags( stripslashes( $_POST['bp-activity-widget-sitewide-items-max'] ) );
    69         }
    70        
    71         if ( $options != $newoptions ) {
    72                 $options = $newoptions;
    73                 update_blog_option( $current_blog->blog_id, 'bp_activity_widget_sitewide_activity', $options );
     9class BP_Activity_Widget extends WP_Widget {
     10        function bp_activity_widget() {
     11                parent::WP_Widget( false, $name = 'Site Wide Activity' );
     12                wp_enqueue_style( 'bp-activity-widget-activity-css', BP_PLUGIN_URL . '/bp-activity/css/widget-activity.css' );         
    7413        }
    7514
     15        function widget($args, $instance) {
     16                global $bp;
     17               
     18            extract( $args );
     19               
     20                echo $before_widget;
     21                echo $before_title
     22                   . $widget_name
     23                   . $after_title; ?>
     24       
     25                <?php
     26                if ( empty( $instance['max_items'] ) || !$instance['max_items'] )
     27                        $instance['max_items'] = 30; ?>
     28               
     29                <?php
     30                if ( !$activity = wp_cache_get( 'sitewide_activity', 'bp' ) ) {
     31                        $activity = bp_activity_get_sitewide_activity( $instance['max_items'] );
     32                        wp_cache_set( 'sitewide_activity', $activity, 'bp' );
     33                }
     34                ?>
     35
     36                <?php if ( $activity['activities'] ) : ?>
     37                        <div class="item-options" id="activity-list-options">
     38                                <img src="<?php echo $bp->activity->image_base; ?>/rss.png" alt="<?php _e( 'RSS Feed', 'buddypress' ) ?>" /> <a href="<?php bp_sitewide_activity_feed_link() ?>" title="<?php _e( 'Site Wide Activity RSS Feed', 'buddypress' ) ?>"><?php _e( 'RSS Feed', 'buddypress' ) ?></a>
     39                        </div>
     40                        <ul id="site-wide-stream" class="activity-list">
     41                        <?php foreach( $activity['activities'] as $item ) : ?>
     42                                <li class="<?php echo $item['component_name'] ?>">
     43                                        <?php echo apply_filters( 'bp_get_activity_content', bp_activity_content_filter( $item['content'], $item['date_recorded'], '', true, false, true ) ); ?>
     44                                </li>
     45                        <?php endforeach; ?>
     46                        </ul>
     47                <?php else: ?>
     48                        <div class="widget-error">
     49                                <?php _e('There has been no recent site activity.', 'buddypress') ?>
     50                        </div>
     51                <?php endif; ?>
     52                       
     53                <?php echo $after_widget; ?>
     54        <?php
     55        }
     56
     57        function update( $new_instance, $old_instance ) {
     58                $instance = $old_instance;
     59                $instance['max_items'] = strip_tags( $new_instance['max_items'] );
     60
     61                return $instance;
     62        }
     63
     64        function form( $instance ) {
     65                $instance = wp_parse_args( (array) $instance, array( 'max_items' => 30 ) );
     66                $max_items = strip_tags( $instance['max_items'] );
     67                ?>
     68
     69                <p><label for="bp-core-widget-members-max"><?php _e('Max items to show:', 'buddypress'); ?> <input class="widefat" id="<?php echo $this->get_field_id( 'max_items' ); ?>" name="<?php echo $this->get_field_name( 'max_items' ); ?>" type="text" value="<?php echo attribute_escape( $max_items ); ?>" style="width: 30%" /></label></p>
     70        <?php
     71        }
     72}
    7673?>
    77                 <p><label for="bp-activity-widget-sitewide-items-max"><?php _e('Max Number of Items:', 'buddypress'); ?> <input class="widefat" id="bp-activity-widget-sitewide-items-max" name="bp-activity-widget-sitewide-items-max" type="text" value="<?php echo attribute_escape( $options['max_items'] ); ?>" style="width: 30%" /></label></p>
    78                 <input type="hidden" id="bp-activity-widget-sitewide-submit" name="bp-activity-widget-sitewide-submit" value="1" />
    79 <?php
    80 }
    81 
    82 ?>
Note: See TracChangeset for help on using the changeset viewer.