Skip to:
Content

BuddyPress.org

Changeset 2147


Ignore:
Timestamp:
11/27/2009 03:58:51 PM (17 years ago)
Author:
apeatling
Message:

Updated site wide activity widget. Added new AJAX functionality along with more powerful filtering

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-activity/bp-activity-classes.php

    r2138 r2147  
    460460                global $wpdb;
    461461
     462                if ( !empty( $filter_array['user_id'] ) ) {
     463                        $user_filter = explode( ',', $filter_array['user_id'] );
     464                        $user_sql = ' ( ';
     465
     466                        $counter = 1;
     467                        foreach( (array) $user_filter as $user ) {
     468                                $user_sql .= $wpdb->prepare( "user_id = %d", trim( $user ) );
     469
     470                                if ( $counter != count( $user_filter ) )
     471                                        $user_sql .= ' || ';
     472
     473                                $counter++;
     474                        }
     475
     476                        $user_sql .= ' )';
     477                        $filter_sql[] = $user_sql;
     478                }
     479
    462480                if ( !empty( $filter_array['object'] ) ) {
    463481                        $object_filter = explode( ',', $filter_array['object'] );
  • trunk/bp-activity/bp-activity-templatetags.php

    r2138 r2147  
    156156                $filter = array( 'object' => $_GET['afilter'] );
    157157        else
    158                 $filter = array( 'object' => $object, 'action' => $action, 'primary_id' => $primary_id, 'secondary_id' => $secondary_id );
     158                $filter = array( 'user_id' => $user_id, 'object' => $object, 'action' => $action, 'primary_id' => $primary_id, 'secondary_id' => $secondary_id );
    159159
    160160        $activities_template = new BP_Activity_Template( $type, $user_id, $per_page, $max, $include, $sort, $filter, $search_terms, $display_comments, $show_hidden );
  • trunk/bp-activity/bp-activity-widgets.php

    r2128 r2147  
    1010        function bp_activity_widget() {
    1111                parent::WP_Widget( false, $name = __( 'Site Wide Activity', 'buddypress' ) );
     12
     13                if ( is_active_widget( false, false, $this->id_base ) )
     14                        wp_enqueue_script( 'activity_widget_js', BP_PLUGIN_URL . '/bp-activity/js/widget-activity.js' );
    1215        }
    1316
    … …  
    2023                echo $before_title
    2124                   . $widget_name .
    22                          ' <a class="rss-image" href="' . bp_get_sitewide_activity_feed_link() . '" title="' . __( 'Site Wide Activity RSS Feed', 'buddypress' ) . '">' . __( '[RSS]', 'buddypress' ) . '</a>'
     25                         ' &nbsp;<span class="ajax-loader"></span>
     26                          <a class="rss-image" href="' . bp_get_sitewide_activity_feed_link() . '" title="' . __( 'Site Wide Activity RSS Feed', 'buddypress' ) . '">' . __( '[RSS]', 'buddypress' ) . '</a>'
    2327                   . $after_title; ?>
    2428
    25         <?php if ( bp_has_activities( 'type=sitewide&max=' . $instance['max_items'] . '&per_page=' . $instance['per_page'] . '&display_comments=threaded' ) ) : ?>
     29        <?php if ( is_user_logged_in() ) : ?>
     30        <div class="item-list-tabs">
     31                <ul>
     32                        <li class="selected" id="activity-all"><a href="<?php bp_root_domain() ?>"><?php _e( 'All Members', 'buddypress' ) ?></a></li>
     33                        <li id="activity-friends"><a href="<?php echo bp_loggedin_user_domain() . BP_ACTIVITY_SLUG . '/my-friends/' ?>"><?php _e( 'My Friends', 'buddypress') ?></a></li>
     34                        <li id="activity-groups"><a href="<?php echo bp_loggedin_user_domain() . BP_ACTIVITY_SLUG . '/my-groups/' ?>"><?php _e( 'My Groups', 'buddypress') ?></a></li>
    2635
    27                 <?php if ( !file_exists( WP_CONTENT_DIR . '/bp-themes' ) ) : ?>
    28                         <div class="pagination">
    29                                 <div class="pag-count" id="activity-count">
    30                                         <?php bp_activity_pagination_count() ?>
    31                                 </div>
     36                        <?php do_action( 'bp_activity_types' ) ?>
    3237
    33                                 <div class="pagination-links" id="activity-pag">
    34                                         &nbsp; <?php bp_activity_pagination_links() ?>
    35                                 </div>
    36                         </div>
     38                        <li id="activity-filter-select">
     39                                <select>
     40                                        <option value="-1"><?php _e( 'No Filter', 'buddypress' ) ?></option>
     41                                        <option value="new_wire_post"><?php _e( 'Updates Only', 'buddypress' ) ?></option>
     42                                        <option value="new_forum_post,new_forum_topic"><?php _e( 'Group Forum Activity Only', 'buddypress' ) ?></option>
     43                                        <option value="new_blog_post,new_blog_comment"><?php _e( 'Blog Activity Only', 'buddypress' ) ?></option>
    3744
    38                         <ul id="activity-filter-links">
    39                                 <?php bp_activity_filter_links() ?>
    40                         </ul>
    41                 <?php endif; ?>
     45                                        <?php do_action( 'bp_activity_filter_options' ) ?>
     46                                </select>
     47                        </li>
     48                </ul>
     49        </div>
     50        <?php endif; ?>
    4251
     52        <div class="astream">
     53                <?php // The loop will be loaded here via AJAX on page load to retain settings. ?>
     54        </div>
     55
     56        <?php echo $after_widget; ?>
     57        <?php
     58        }
     59
     60        function update( $new_instance, $old_instance ) {
     61                $instance = $old_instance;
     62                $instance['max_items'] = strip_tags( $new_instance['max_items'] );
     63                $instance['per_page'] = strip_tags( $new_instance['per_page'] );
     64
     65                return $instance;
     66        }
     67
     68        function form( $instance ) {
     69                $instance = wp_parse_args( (array) $instance, array( 'max_items' => 200, 'per_page' => 25 ) );
     70                $per_page = strip_tags( $instance['per_page'] );
     71                $max_items = strip_tags( $instance['max_items'] );
     72                ?>
     73
     74                <p><label for="bp-activity-widget-sitewide-per-page"><?php _e('Number of Items Per Page:', 'buddypress'); ?> <input class="widefat" id="<?php echo $this->get_field_id( 'per_page' ); ?>" name="<?php echo $this->get_field_name( 'per_page' ); ?>" type="text" value="<?php echo attribute_escape( $per_page ); ?>" style="width: 30%" /></label></p>
     75                <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>
     76        <?php
     77        }
     78}
     79
     80function bp_activity_widget_loop( $type = 'all', $filter = false, $per_page = 20 ) {
     81        global $bp;
     82
     83        /* Set a valid type */
     84        if ( !$type || ( 'all' != $type && 'friends' != $type && 'groups' != $type ) )
     85                $type = 'all';
     86
     87        if ( ( 'friends' == $type || 'groups' == $type ) && !is_user_logged_in() )
     88                $type = 'all';
     89
     90        switch( $type ) {
     91                case 'friends':
     92                        $friend_ids = implode( ',', friends_get_friend_user_ids( $bp->loggedin_user->id ) );
     93                        $query_string = 'user_id=' . $friend_ids;
     94                        break;
     95                case 'groups':
     96                        $groups = groups_get_user_groups( $bp->loggedin_user->id );
     97                        $group_ids = implode( ',', $groups['groups'] );
     98                        $query_string = 'object=groups&primary_id=' . $group_ids;
     99                        break;
     100        }
     101
     102        /* Build the filter */
     103        if ( $filter && $filter != '-1' )
     104                $query_string .= '&action=' . $filter;
     105
     106        /* Add the per_page param */
     107        $query_string .= '&per_page=' . $per_page;
     108
     109        if ( bp_has_activities( $query_string . '&display_comments=threaded' ) ) : ?>
    43110                <ul id="site-wide-stream" class="activity-list">
    44111                <?php while ( bp_activities() ) : bp_the_activity(); ?>
    … …  
    78145
    79146        <?php else: ?>
     147<?php echo "-1<div id='message' class='info'><p>" . __( 'No activity found', 'buddypress' ) . '</p></div>'; ?>
     148        <?php endif;
     149}
    80150
    81                 <div class="widget-error">
    82                         <?php _e('There has been no recent site activity.', 'buddypress') ?>
    83                 </div>
    84         <?php endif;?>
     151/* The ajax function to reload the activity widget. In here because this is a self contained widget. */
     152function bp_activity_ajax_widget_filter() {
     153        bp_activity_widget_loop( $_POST['type'], $_POST['filter'] );
     154}
     155add_action( 'wp_ajax_activity_widget_filter', 'bp_activity_ajax_widget_filter' );
    85156
    86         <?php echo $after_widget; ?>
    87         <?php
    88         }
    89157
    90         function update( $new_instance, $old_instance ) {
    91                 $instance = $old_instance;
    92                 $instance['max_items'] = strip_tags( $new_instance['max_items'] );
    93                 $instance['per_page'] = strip_tags( $new_instance['per_page'] );
    94158
    95                 return $instance;
    96         }
    97 
    98         function form( $instance ) {
    99                 $instance = wp_parse_args( (array) $instance, array( 'max_items' => 200, 'per_page' => 25 ) );
    100                 $per_page = strip_tags( $instance['per_page'] );
    101                 $max_items = strip_tags( $instance['max_items'] );
    102                 ?>
    103 
    104                 <p><label for="bp-activity-widget-sitewide-per-page"><?php _e('Number of Items Per Page:', 'buddypress'); ?> <input class="widefat" id="<?php echo $this->get_field_id( 'per_page' ); ?>" name="<?php echo $this->get_field_name( 'per_page' ); ?>" type="text" value="<?php echo attribute_escape( $per_page ); ?>" style="width: 30%" /></label></p>
    105                 <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>
    106         <?php
    107         }
    108 }
    109159?>
  • trunk/bp-groups.php

    r2128 r2147  
    19181918}
    19191919
     1920/* TODO: These user group functions could be merged with the above with an optional user ID param */
     1921
    19201922function groups_get_user_groups( $user_id = false, $pag_num = false, $pag_page = false ) {
    19211923        global $bp;
    … …  
    19261928        return BP_Groups_Member::get_group_ids( $user_id, $pag_num, $pag_page );
    19271929}
    1928 
    1929 /* TODO: These user group functions could be merged with the above with an optional user ID param */
    19301930
    19311931function groups_get_recently_joined_for_user( $user_id = false, $pag_num = false, $pag_page = false, $filter = false ) {
  • trunk/bp-themes/bp-default/_inc/css/screen.css

    r2145 r2147  
    12631263        border-bottom: 1px solid #eee;
    12641264}
    1265         ul#activity-filter-links li#afilter-blogs a {
    1266                 background: url(../images/blog_bullet.gif) 20px 4px no-repeat;
    1267         }
    1268 
    1269         ul#activity-filter-links li#afilter-profile a {
    1270                 background: url(../images/profile_bullet.gif) 0 4px no-repeat;
    1271         }
    1272 
    1273         ul#activity-filter-links li#afilter-friends a {
    1274                 background: url(../images/friends_bullet.gif) 0 4px no-repeat;
    1275         }
    1276 
    1277         ul#activity-filter-links li#afilter-groups a {
    1278                 background: url(../images/groups_bullet.gif) 0 4px no-repeat;
    1279         }
    1280 
    1281         ul#activity-filter-links li#afilter-wire a {
    1282                 background: url(../images/wire_bullet.gif) 0 4px no-repeat;
    1283         }
    1284 
    1285         ul#activity-filter-links li#afilter-status a {
    1286                 background: url(../images/status_bullet.gif) 0 4px no-repeat;
    1287         }
    1288 
    12891265        .activity-list li.mini {
    12901266                font-size: 0.9em;
    … …  
    13911367        }
    13921368
    1393 ul#activity-filter-links {
     1369div.item-list-tabs ul {
    13941370        margin: 0;
    13951371        padding: 0;
    … …  
    13971373        background: url(../images/item_list_back.gif) top left repeat-x;
    13981374        padding: 15px;
    1399         min-height: 22px;
    14001375        overflow: hidden;
    14011376}
    1402         .activity ul#activity-filter-links {
    1403                 margin-top: 35px;
    1404         }
    1405 
    1406 ul#activity-filter-links li {
     1377
     1378div.item-list-tabs ul li {
    14071379        float: left;
    1408         margin-bottom: 5px;
    1409 }
    1410         ul#activity-filter-links li a {
     1380}
     1381        div.item-list-tabs ul li a {
    14111382                display: block;
    1412                 padding: 2px 8px 2px 30px;
     1383                padding: 2px 8px;
    14131384                background-color: #fff !important;
    14141385                background-position: 8px 6px !important;
    … …  
    14201391                text-decoration: none;
    14211392        }
    1422                 ul#activity-filter-links li.selected a {
     1393                div.item-list-tabs ul li.selected a {
    14231394                        border: 1px solid #ccc;
     1395                        color: #555;
    14241396                        font-weight: bold;
    14251397                }
    14261398
    1427                 ul#activity-filter-links li#afilter-clear a {
     1399                div.item-list-tabs ul li.afilter-clear a {
    14281400                        background: url(../images/error_icon.gif) 0 4px no-repeat;
    14291401                        border-color: #ffa6ac;
    14301402                        color: #ff5560;
    14311403                }
     1404
     1405                div.item-list-tabs li#activity-filter-select {
     1406                        float: right;
     1407                }
     1408                        div.item-list-tabs li#activity-filter-select select {
     1409                                max-width: 120px;
     1410                        }
    14321411
    14331412a.rss-image {
Note: See TracChangeset for help on using the changeset viewer.