Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
01/09/2010 11:13:31 AM (15 years ago)
Author:
apeatling
Message:

Moving the site wide activity widget into the bp-sn-parent theme since it is now specific to this theme and not used at all in the new default. The new default includes better editable templates instead.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-themes/bp-sn-parent/functions.php

    r2126 r2281  
    8282}
    8383
     84/* Activity Widget */
     85
     86class BP_Activity_Widget extends WP_Widget {
     87    function bp_activity_widget() {
     88        parent::WP_Widget( false, $name = __( 'Site Wide Activity', 'buddypress' ) );
     89
     90        if ( is_active_widget( false, false, $this->id_base ) )
     91            wp_enqueue_script( 'activity_widget_js', BP_PLUGIN_URL . '/bp-activity/js/widget-activity.js' );
     92    }
     93
     94    function widget($args, $instance) {
     95        global $bp;
     96
     97        extract( $args );
     98
     99        echo $before_widget;
     100        echo $before_title
     101           . $widget_name .
     102             ' &nbsp;<span class="ajax-loader"></span>
     103              <a class="rss-image" href="' . bp_get_sitewide_activity_feed_link() . '" title="' . __( 'Site Wide Activity RSS Feed', 'buddypress' ) . '">' . __( '[RSS]', 'buddypress' ) . '</a>'
     104           . $after_title; ?>
     105
     106        <?php if ( is_user_logged_in() ) : ?>
     107        <form action="" method="post" id="whats-new-form" name="whats-new-form">
     108            <div id="whats-new-avatar">
     109                <?php bp_loggedin_user_avatar('width=40&height=40') ?>
     110                <span class="loading"></span>
     111            </div>
     112
     113            <h5>
     114                <?php
     115                    $fullname = (array)explode( ' ', $bp->loggedin_user->fullname );
     116                    printf( __( "What's new %s?", 'buddypress' ), $fullname[0] )
     117                ?>
     118            </h5>
     119
     120            <div id="whats-new-content">
     121                <div id="whats-new-textarea">
     122                    <textarea name="whats-new" id="whats-new" value="" /></textarea>
     123                </div>
     124
     125                <div id="whats-new-options">
     126                    <div id="whats-new-submit">
     127                        <span class="ajax-loader"></span> &nbsp;
     128                        <input type="submit" name="aw-whats-new-submit" id="aw-whats-new-submit" value="<?php _e( 'Post Update', 'callisto' ) ?>" />
     129                    </div>
     130
     131                    <div id="whats-new-post-in-box">
     132                        <?php _e( 'Post in', 'callisto' ) ?>:
     133
     134                        <select id="whats-new-post-in" name="whats-new-post-in">
     135                            <option selected="selected" value="0"><?php _e( 'My Profile', 'buddypress' ) ?></option>
     136                            <?php if ( bp_has_groups( 'user_id=' . bp_loggedin_user_id() . '&type=alphabetical&max=100&per_page=100' ) ) : while ( bp_groups() ) : bp_the_group(); ?>
     137                                <option value="<?php bp_group_id() ?>"><?php bp_group_name() ?></option>
     138                            <?php endwhile; endif; ?>
     139                        </select>
     140                    </div>
     141                </div>
     142
     143                <div class="clear"></div>
     144
     145            </div>
     146
     147            <?php wp_nonce_field( 'post_update', '_wpnonce_post_update' ); ?>
     148        </form>
     149        <?php endif; ?>
     150
     151        <div class="item-list-tabs">
     152            <ul>
     153                <li class="selected" id="activity-all"><a href="<?php bp_root_domain() ?>"><?php _e( 'All Members', 'buddypress' ) ?></a></li>
     154
     155                <?php if ( is_user_logged_in() ) : ?>
     156                    <li id="activity-friends"><a href="<?php echo bp_loggedin_user_domain() . BP_ACTIVITY_SLUG . '/my-friends/' ?>"><?php _e( 'My Friends', 'buddypress') ?></a></li>
     157                    <li id="activity-groups"><a href="<?php echo bp_loggedin_user_domain() . BP_ACTIVITY_SLUG . '/my-groups/' ?>"><?php _e( 'My Groups', 'buddypress') ?></a></li>
     158                <?php endif; ?>
     159
     160                <?php do_action( 'bp_activity_types' ) ?>
     161
     162                <li id="activity-filter-select">
     163                    <select>
     164                        <option value="-1"><?php _e( 'No Filter', 'buddypress' ) ?></option>
     165                        <option value="new_wire_post"><?php _e( 'Updates Only', 'buddypress' ) ?></option>
     166                        <option value="new_forum_post,new_forum_topic"><?php _e( 'Group Forum Activity Only', 'buddypress' ) ?></option>
     167                        <option value="new_blog_post,new_blog_comment"><?php _e( 'Blog Activity Only', 'buddypress' ) ?></option>
     168
     169                        <?php do_action( 'bp_activity_filter_options' ) ?>
     170                    </select>
     171                </li>
     172            </ul>
     173        </div>
     174
     175        <div class="activity">
     176            <?php // The loop will be loaded here via AJAX on page load to retain settings. ?>
     177        </div>
     178
     179        <form action="" name="activity-widget-form" id="activity-widget-form" method="post">
     180            <?php wp_nonce_field( 'activity_filter', '_wpnonce_activity_filter' ) ?>
     181            <input type="hidden" id="aw-querystring" name="aw-querystring" value="" />
     182            <input type="hidden" id="aw-oldestpage" name="aw-oldestpage" value="1" />
     183        </div>
     184
     185    <?php echo $after_widget; ?>
     186    <?php
     187    }
     188
     189    function update( $new_instance, $old_instance ) {
     190        $instance = $old_instance;
     191        $instance['max_items'] = strip_tags( $new_instance['max_items'] );
     192        $instance['per_page'] = strip_tags( $new_instance['per_page'] );
     193
     194        return $instance;
     195    }
     196
     197    function form( $instance ) {
     198        $instance = wp_parse_args( (array) $instance, array( 'max_items' => 200, 'per_page' => 25 ) );
     199        $per_page = strip_tags( $instance['per_page'] );
     200        $max_items = strip_tags( $instance['max_items'] );
     201        ?>
     202
     203        <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>
     204        <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>
     205    <?php
     206    }
     207}
     208register_widget( "BP_Activity_Widget" );
     209
     210function bp_activity_widget_loop( $type = 'all', $filter = false, $query_string = false, $per_page = 20 ) {
     211    global $bp;
     212
     213    if ( !$query_string ) {
     214        /* Set a valid type */
     215        if ( !$type || ( 'all' != $type && 'friends' != $type && 'groups' != $type ) )
     216            $type = 'all';
     217
     218        if ( ( 'friends' == $type || 'groups' == $type ) && !is_user_logged_in() )
     219            $type = 'all';
     220
     221        switch( $type ) {
     222            case 'friends':
     223                $friend_ids = implode( ',', friends_get_friend_user_ids( $bp->loggedin_user->id ) );
     224                $query_string = 'user_id=' . $friend_ids;
     225                break;
     226            case 'groups':
     227                $groups = groups_get_user_groups( $bp->loggedin_user->id );
     228                $group_ids = implode( ',', $groups['groups'] );
     229                $query_string = 'object=groups&primary_id=' . $group_ids;
     230                break;
     231        }
     232
     233        /* Build the filter */
     234        if ( $filter && $filter != '-1' )
     235            $query_string .= '&action=' . $filter;
     236
     237        /* Add the per_page param */
     238        $query_string .= '&per_page=' . $per_page;
     239    }
     240
     241    if ( bp_has_activities( $query_string . '&display_comments=threaded' ) ) : ?>
     242        <?php echo $query_string . '&display_comments=threaded||'; // Pass the qs back to the JS. ?>
     243
     244        <?php if ( !$_POST['acpage'] || 1 == $_POST['acpage'] ) : ?>
     245            <ul id="site-wide-stream" class="activity-list item-list">
     246        <?php endif; ?>
     247
     248        <?php while ( bp_activities() ) : bp_the_activity(); ?>
     249            <li class="<?php bp_activity_css_class() ?>" id="activity-<?php bp_activity_id() ?>">
     250                <div class="activity-avatar">
     251                    <?php bp_activity_avatar('type=full&width=40&height=40') ?>
     252                </div>
     253
     254                <div class="activity-content">
     255                    <?php bp_activity_content() ?>
     256
     257                    <?php if ( is_user_logged_in() ) : ?>
     258                    <div class="activity-meta">
     259                        <a href="#acomment-<?php bp_activity_id() ?>" class="acomment-reply" id="acomment-comment-<?php bp_activity_id() ?>"><?php _e( 'Comment', 'buddypress' ) ?> (<?php bp_activity_comment_count() ?>)</a>
     260                    </div>
     261                    <?php endif; ?>
     262                </div>
     263
     264                <div class="activity-comments">
     265                    <?php bp_activity_comments() ?>
     266
     267                    <?php if ( is_user_logged_in() ) : ?>
     268                    <form action="" method="post" name="activity-comment-form" id="ac-form-<?php bp_activity_id() ?>" class="ac-form">
     269                        <div class="ac-reply-avatar"><?php bp_loggedin_user_avatar( 'width=25&height=25' ) ?></div>
     270                        <div class="ac-reply-content">
     271                            <div class="ac-textarea">
     272                                <textarea id="ac-input-<?php bp_activity_id() ?>" class="ac-input" name="ac-input-<?php bp_activity_id() ?>"></textarea>
     273                            </div>
     274                            <input type="submit" name="ac-form-submit" value="<?php _e( 'Post', 'buddypress' ) ?> &rarr;" />
     275                        </div>
     276                        <?php wp_nonce_field( 'new_activity_comment', '_wpnonce_new_activity_comment' ) ?>
     277                    </form>
     278                    <?php endif; ?>
     279                </div>
     280
     281            </li>
     282        <?php endwhile; ?>
     283            <li class="load-more">
     284                <a href="#more"><?php _e( 'Load More', 'buddypress' ) ?></a> &nbsp; <span class="ajax-loader"></span>
     285            </li>
     286
     287        <?php if ( !$_POST['acpage'] || 1 == $_POST['acpage']  ) : ?>
     288            </ul>
     289        <?php endif; ?>
     290
     291    <?php else: ?>
     292<?php echo "-1<div id='message' class='info'><p>" . __( 'No activity found', 'buddypress' ) . '</p></div>'; ?>
     293    <?php endif;
     294}
     295
     296/* The ajax function to reload the activity widget. In here because this is a self contained widget. */
     297function bp_activity_ajax_widget_filter() {
     298    bp_activity_widget_loop( $_POST['type'], $_POST['filter'] );
     299}
     300add_action( 'wp_ajax_activity_widget_filter', 'bp_activity_ajax_widget_filter' );
     301
     302/* The ajax function to load older updates at the end of the list */
     303function bp_activity_ajax_load_older_updates() {
     304    bp_activity_widget_loop( false, false, $_POST['query_string'] );
     305}
     306add_action( 'wp_ajax_aw_get_older_updates', 'bp_activity_ajax_load_older_updates' );
     307
    84308?>
Note: See TracChangeset for help on using the changeset viewer.