Skip to:
Content

BuddyPress.org

Changeset 2397


Ignore:
Timestamp:
01/21/2010 03:47:02 PM (17 years ago)
Author:
apeatling
Message:

Fixes #1598 - broken sitewide notices

Location:
trunk
Files:
1 added
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-activity.php

    r2389 r2397  
    598598}
    599599
     600/**
     601 * bp_activity_get_activity_id()
     602 *
     603 * Fetch the activity_id for an existing activity entry in the DB.
     604 *
     605 * @package BuddyPress Activity
     606 */
     607function bp_activity_get_activity_id( $args = '' ) {
     608        $defaults = array(
     609                'user_id' => false,
     610                'component' => false,
     611                'type' => false,
     612                'item_id' => false,
     613                'secondary_item_id' => false
     614        );
     615
     616        $r = wp_parse_args( $args, $defaults );
     617        extract( $r, EXTR_SKIP );
     618
     619        return apply_filters( 'bp_activity_get_activity_id', BP_Activity_Activity::get_id( $user_id, $component, $type, $item_id, $secondary_item_id ) );
     620}
     621
    600622/***
    601623 * Deleting Activity
     
    712734}
    713735
     736/**
     737 * bp_activity_thumnail_content_images()
     738 *
     739 * Take content, remove all images and replace them with one thumbnail image.
     740 *
     741 * @package BuddyPress Activity
     742 * @param $content str - The content to work with
     743 * @return $content str - The content with images stripped and replaced with a single thumb.
     744 */
    714745function bp_activity_thumnail_content_images( $content ) {
    715746        preg_match_all( '/<img[^>]*>/Ui', $content, $matches );
     
    742773        }
    743774
    744         return $content;
     775        return apply_filters( 'bp_activity_thumnail_content_images', $content, $matches );
    745776}
    746777
  • trunk/bp-activity/bp-activity-classes.php

    r2381 r2397  
    295295        }
    296296
     297        function get_id( $user_id, $component, $type, $item_id, $secondary_item_id ) {
     298                global $bp, $wpdb;
     299
     300                $where_args = false;
     301
     302                if ( !empty( $user_id ) )
     303                        $where_args[] = $wpdb->prepare( "user_id = %d", $user_id );
     304
     305                if ( !empty( $component ) )
     306                        $where_args[] = $wpdb->prepare( "component = %s", $component );
     307
     308                if ( !empty( $type ) )
     309                        $where_args[] = $wpdb->prepare( "type = %s", $type );
     310
     311                if ( !empty( $item_id ) )
     312                        $where_args[] = $wpdb->prepare( "item_id = %s", $item_id );
     313
     314                if ( !empty( $secondary_item_id ) )
     315                        $where_args[] = $wpdb->prepare( "secondary_item_id = %s", $secondary_item_id );
     316
     317                if ( !empty( $where_args ) )
     318                        $where_sql = 'WHERE ' . join( ' AND ', $where_args );
     319                else
     320                        return false;
     321
     322                return $wpdb->get_var( "SELECT id FROM {$bp->activity->table_name} {$where_sql}" );
     323        }
     324
    297325        function append_comments( $activities ) {
    298326                global $bp, $wpdb;
  • trunk/bp-blogs.php

    r2394 r2397  
    270270                $content = apply_filters( 'bp_blogs_record_activity_content', "<blockquote>" . bp_create_excerpt( $content ) . "</blockquote>" );
    271271
    272         return bp_activity_add( array( 'user_id' => $user_id, 'action' => $action, 'content' => $content, 'primary_link' => $primary_link, 'component' => $component, 'type' => $type, 'item_id' => $item_id, 'secondary_item_id' => $secondary_item_id, 'recorded_time' => $recorded_time, 'hide_sitewide' => $hide_sitewide ) );
     272        /* Check for an existing entry and update if one exists. */
     273        $id = bp_activity_get_activity_id( array(
     274                'user_id' => $user_id,
     275                'component' => $component,
     276                'type' => $type,
     277                'item_id' => $item_id,
     278                'secondary_item_id' => $secondary_item_id
     279        ) );
     280
     281        return bp_activity_add( array( 'id' => $id, 'user_id' => $user_id, 'action' => $action, 'content' => $content, 'primary_link' => $primary_link, 'component' => $component, 'type' => $type, 'item_id' => $item_id, 'secondary_item_id' => $secondary_item_id, 'recorded_time' => $recorded_time, 'hide_sitewide' => $hide_sitewide ) );
    273282}
    274283
     
    418427                $existing_post = new BP_Blogs_Post( null, $blog_id, $post_id );
    419428
    420                 /* Delete and the activity stream item as we are probably going to re-add it later with new info. */
    421                 bp_blogs_delete_activity( array( 'item_id' => $existing_post->id, 'component' => $bp->blogs->slug, 'type' => 'new_blog_post' ) );
    422 
    423429                /* Delete the recorded post if the status is not published or it is password protected */
    424430                if ( 'publish' != $post->post_status || '' != $post->post_password ) {
     
    441447                        $activity_content = $post->post_content;
    442448
    443                         /* Record this in activity streams */
    444449                        bp_blogs_record_activity( array(
    445450                                'user_id' => (int)$post->post_author,
     
    449454                                'type' => 'new_blog_post',
    450455                                'item_id' => $blog_id,
    451                                 'secondary_item_id' => $existing_post->id,
     456                                'secondary_item_id' => $post_id,
    452457                                'recorded_time' => strtotime( $post->post_date_gmt )
    453458                        ) );
  • trunk/bp-groups.php

    r2389 r2397  
    13331333        extract( $r, EXTR_SKIP );
    13341334
    1335         return bp_activity_add( array( 'user_id' => $user_id, 'action' => $action, 'content' => $content, 'primary_link' => $primary_link, 'component' => $component, 'type' => $type, 'item_id' => $item_id, 'secondary_item_id' => $secondary_item_id, 'recorded_time' => $recorded_time, 'hide_sitewide' => $hide_sitewide ) );
     1335        /* Check for an existing entry and update if one exists. */
     1336        $id = bp_activity_get_activity_id( array(
     1337                'user_id' => $user_id,
     1338                'component' => $component,
     1339                'type' => $type,
     1340                'item_id' => $item_id,
     1341                'secondary_item_id' => $secondary_item_id
     1342        ) );
     1343
     1344        return bp_activity_add( array( 'id' => $id, 'user_id' => $user_id, 'action' => $action, 'content' => $content, 'primary_link' => $primary_link, 'component' => $component, 'type' => $type, 'item_id' => $item_id, 'secondary_item_id' => $secondary_item_id, 'recorded_time' => $recorded_time, 'hide_sitewide' => $hide_sitewide ) );
    13361345}
    13371346
  • trunk/bp-messages.php

    r2389 r2397  
    174174                } else {
    175175                        /* If this is a notice, send it */
    176                         if ( isset($_POST['send-notice']) ) {
    177                                 messages_send_notice( $_POST['subject'], $_POST['content'] );
     176                        if ( isset( $_POST['send-notice'] ) ) {
     177                                if ( messages_send_notice( $_POST['subject'], $_POST['content'] ) ) {
     178                                        bp_core_add_message( __( 'Notice sent successfully!', 'buddypress' ) );
     179                                        bp_core_redirect( $bp->loggedin_user->domain . $bp->messages->slug . '/inbox/' );
     180                                } else {
     181                                        bp_core_add_message( __( 'There was an error sending that notice, please try again', 'buddypress' ), 'error' );
     182                                }
    178183                        } else {
    179184                                /* Filter recipients into the format we need - array( 'username/userid', 'username/userid' ) */
     
    420425        /* If we have a thread ID, use the existing recipients, otherwise use the recipients passed */
    421426        if ( $thread_id ) {
    422                 $thread = new BP_Messages_Thread($thread_id);
     427                $thread = new BP_Messages_Thread( $thread_id );
    423428                $message->recipients = $thread->get_recipients();
    424429        } else {
  • trunk/bp-messages/bp-messages-templatetags.php

    r2389 r2397  
    162162                global $messages_template;
    163163
    164                 return apply_filters( 'bp_get_message_thread_id', $messages_template->thread->thread_id );
     164                /* Notice support */
     165                if ( empty( $messages_template->thread->thread_id ) )
     166                        $id = $messages_template->thread->id;
     167                else
     168                        $id = $messages_template->thread->thread_id;
     169
     170                return apply_filters( 'bp_get_message_thread_id', $id );
    165171        }
    166172
     
    170176        function bp_get_message_thread_subject() {
    171177                global $messages_template;
    172                 return apply_filters( 'bp_get_message_thread_subject', stripslashes_deep( $messages_template->thread->last_message_subject ) );
     178
     179                /* Notice support */
     180                if ( empty( $messages_template->thread->last_message_subject ) )
     181                        $subject = $messages_template->thread->subject;
     182                else
     183                        $subject = $messages_template->thread->last_message_subject;
     184
     185                return apply_filters( 'bp_get_message_thread_subject', stripslashes_deep( $subject ) );
    173186        }
    174187
     
    178191        function bp_get_message_thread_excerpt() {
    179192                global $messages_template;
    180                 return apply_filters( 'bp_get_message_thread_excerpt', strip_tags( bp_create_excerpt($messages_template->thread->last_message_message, 10 ) ) );
     193
     194                /* Notice support */
     195                if ( empty( $messages_template->thread->last_message_message ) )
     196                        $message = $messages_template->thread->message;
     197                else
     198                        $message = $messages_template->thread->last_message_message;
     199
     200                return apply_filters( 'bp_get_message_thread_excerpt', strip_tags( bp_create_excerpt( $message, 10 ) ) );
    181201        }
    182202
     
    185205}
    186206        function bp_get_message_thread_from() {
    187                 global $messages_template;
    188                 return apply_filters( 'bp_get_message_thread_from', bp_core_get_userlink($messages_template->thread->last_sender_id) );
     207                global $messages_template, $bp;
     208
     209                /* Notice support */
     210                if ( empty( $messages_template->thread->last_sender_id ) )
     211                        $sender = $bp->loggedin_user->id;
     212                else
     213                        $sender = $messages_template->thread->last_sender_id;
     214
     215                return apply_filters( 'bp_get_message_thread_from', bp_core_get_userlink($sender) );
    189216        }
    190217
     
    239266        function bp_get_message_thread_last_post_date() {
    240267                global $messages_template;
    241                 echo apply_filters( 'bp_get_message_thread_last_post_date', bp_format_time( strtotime($messages_template->thread->last_post_date) ) );
     268
     269                /* Notice support */
     270                if ( empty( $messages_template->thread->last_post_date ) )
     271                        $date = $messages_template->thread->date_sent;
     272                else
     273                        $date = $messages_template->thread->last_post_date;
     274
     275                echo apply_filters( 'bp_get_message_thread_last_post_date', bp_format_time( strtotime($date) ) );
    242276        }
    243277
     
    246280}
    247281        function bp_get_message_thread_avatar() {
    248                 global $messages_template;
    249                 echo apply_filters( 'bp_get_message_thread_avatar', bp_core_fetch_avatar( array( 'item_id' => $messages_template->thread->last_sender_id, 'type' => 'thumb' ) ) );
     282                global $messages_template, $bp;
     283
     284                /* Notice support */
     285                if ( empty( $messages_template->thread->last_sender_id ) )
     286                        $sender = $bp->loggedin_user->id;
     287                else
     288                        $sender = $messages_template->thread->last_sender_id;
     289
     290                echo apply_filters( 'bp_get_message_thread_avatar', bp_core_fetch_avatar( array( 'item_id' => $sender, 'type' => 'thumb' ) ) );
    250291        }
    251292
     
    318359function bp_messages_options() {
    319360        global $bp;
    320 
    321         if ( $bp->current_action != 'sentbox' ) {
    322361?>
    323                 <?php _e( 'Select:', 'buddypress' ) ?>
    324                 <select name="message-type-select" id="message-type-select">
    325                         <option value=""></option>
    326                         <option value="read"><?php _e('Read', 'buddypress') ?></option>
    327                         <option value="unread"><?php _e('Unread', 'buddypress') ?></option>
    328                         <option value="all"><?php _e('All', 'buddypress') ?></option>
    329                 </select> &nbsp;
     362        <?php _e( 'Select:', 'buddypress' ) ?>
     363        <select name="message-type-select" id="message-type-select">
     364                <option value=""></option>
     365                <option value="read"><?php _e('Read', 'buddypress') ?></option>
     366                <option value="unread"><?php _e('Unread', 'buddypress') ?></option>
     367                <option value="all"><?php _e('All', 'buddypress') ?></option>
     368        </select> &nbsp;
     369        <?php if ( $bp->current_action != 'sentbox' && $bp->current_action != 'notices' ) : ?>
    330370                <a href="#" id="mark_as_read"><?php _e('Mark as Read', 'buddypress') ?></a> &nbsp;
    331371                <a href="#" id="mark_as_unread"><?php _e('Mark as Unread', 'buddypress') ?></a> &nbsp;
    332         <?php } ?>
     372        <?php endif; ?>
    333373        <a href="#" id="delete_<?php echo $bp->current_action ?>_messages"><?php _e('Delete Selected', 'buddypress') ?></a> &nbsp;
    334374<?php
     
    418458
    419459        $notice = BP_Messages_Notice::get_active();
    420         $closed_notices = get_usermeta( $userdata->ID, 'closed_notices');
     460
     461        if ( empty( $notice ) )
     462                return false;
     463
     464        $closed_notices = get_usermeta( $userdata->ID, 'closed_notices' );
    421465
    422466        if ( !$closed_notices )
     
    426470                if ( !in_array( $notice->id, $closed_notices ) && $notice->id ) {
    427471                        ?>
    428                         <div class="notice" id="<?php echo $notice->id ?>">
    429                                 <h5><?php echo stripslashes($notice->subject) ?></h5>
    430                                 <?php echo stripslashes($notice->message) ?>
    431                                 <a href="#" id="close-notice"><?php _e( 'Close', 'buddypress' ) ?></a>
     472                        <div id="message" class="info notice" rel="n-<?php echo $notice->id ?>">
     473                                <p>
     474                                        <strong><?php echo stripslashes( wp_filter_kses( $notice->subject ) ) ?></strong><br />
     475                                        <?php echo stripslashes( wp_filter_kses( $notice->message) ) ?>
     476                                        <a href="#" id="close-notice"><?php _e( 'Close', 'buddypress' ) ?></a>
     477                                </p>
    432478                        </div>
    433479                        <?php
  • trunk/bp-themes/bp-default/_inc/ajax.php

    r2372 r2397  
    425425add_action( 'wp_ajax_joinleave_group', 'bp_dtheme_ajax_joinleave_group' );
    426426
     427function bp_dtheme_ajax_close_notice() {
     428        global $userdata;
     429
     430        if ( !isset( $_POST['notice_id'] ) ) {
     431                echo "-1<div id='message' class='error'><p>" . __('There was a problem closing the notice.', 'buddypress') . '</p></div>';
     432        } else {
     433                $notice_ids = get_usermeta( $userdata->ID, 'closed_notices' );
     434
     435                $notice_ids[] = (int) $_POST['notice_id'];
     436
     437                update_usermeta( $userdata->ID, 'closed_notices', $notice_ids );
     438        }
     439}
     440add_action( 'wp_ajax_messages_close_notice', 'bp_dtheme_ajax_close_notice' );
     441
    427442function bp_dtheme_ajax_messages_send_reply() {
    428443        global $bp;
     
    460475add_action( 'wp_ajax_messages_send_reply', 'bp_dtheme_ajax_messages_send_reply' );
    461476
    462 function bp_dtheme_ajax_markunread() {
     477function bp_dtheme_ajax_message_markunread() {
    463478        global $bp;
    464479
     
    473488        }
    474489}
    475 add_action( 'wp_ajax_messages_markunread', 'bp_dtheme_ajax_markunread' );
     490add_action( 'wp_ajax_messages_markunread', 'bp_dtheme_ajax_message_markunread' );
    476491
    477492function bp_dtheme_ajax_message_markread() {
     
    488503        }
    489504}
    490 add_action( 'wp_ajax_messages_markread', 'bp_dtheme_ajax_messages_markread' );
     505add_action( 'wp_ajax_messages_markread', 'bp_dtheme_ajax_message_markread' );
    491506
    492507function bp_dtheme_ajax_messages_delete() {
  • trunk/bp-themes/bp-default/_inc/css/default.css

    r2383 r2397  
    14331433                text-align: right;
    14341434        }
    1435                 a#delete_inbox_messages, .sentbox div.messages-options-nav {
     1435                a#delete_inbox_messages {
    14361436                        display: none;
    14371437                }
  • trunk/bp-themes/bp-default/_inc/global.js

    r2381 r2397  
    493493        });
    494494
     495        /* Hide long lists of activity comments, only show the latest five root comments. */
    495496        function bp_dtheme_hide_comments() {
    496497                var comments_divs = j('div.activity-comments');
     
    526527        /**** Directory Search ****************************************************/
    527528
     529        /* The search form on all directory pages */
    528530        j('div.dir-search').click( function(event) {
    529531                var target = j(event.target);
     
    541543        /**** Tabs and Filters ****************************************************/
    542544
     545        /* When a navigation tab is clicked - e.g. | All Groups | My Groups | */
    543546        j('div.item-list-tabs').click( function(event) {
    544547                if ( j(this).hasClass('no-ajax') )
     
    570573        });
    571574
     575        /* When the filter select box is changed re-query */
    572576        j('li.filter select').change( function() {
    573577                if ( j('div.item-list-tabs li.selected').length )
     
    587591        });
    588592
     593        /* Filter the current content list (groups/members/blogs/topics) */
    589594        function bp_filter_request( type, filter, id, target, page, search_terms, extras ) {
    590595                if ( 'activity' == id )
     
    646651        }
    647652
    648         /* Pagination Links */
     653        /* All pagination links run through this function */
    649654        j('div#content').click( function(event) {
    650655                var target = j(event.target);
     
    684689        /**** New Forum Directory Post **************************************/
    685690
     691        /* Hit the "New Topic" button on the forums directory page */
    686692        j('a#new-topic-button').click( function() {
    687693                if ( !j('div#new-topic-post').length )
     
    696702        });
    697703
     704        /* Cancel the posting of a new forum topic */
    698705        j('input#submit_topic_cancel').click( function() {
    699706                if ( !j('div#new-topic-post').length )
     
    706713        /** Invite Friends Interface ****************************************/
    707714
     715        /* Select a user from the list of friends and add them to the invite list */
    708716        j("div#invite-list input").click( function() {
    709717                j('.ajax-loader').toggle();
     
    743751        });
    744752
     753        /* Remove a user from the list of users to invite to a group */
    745754        j("#friend-list li a.remove").live('click', function() {
    746755                j('.ajax-loader').toggle();
     
    770779        /** Friendship Requests **************************************/
    771780
     781        /* Accept and Reject friendship request buttons */
    772782        j("ul#friend-list a.accept, ul#friend-list a.reject").click( function() {
    773783                var button = j(this);
     
    816826        });
    817827
     828        /* Add / Remove friendship buttons */
    818829        j("div.friendship-button a").live('click', function() {
    819830                j(this).parent().addClass('loading');
     
    924935        /** Private Messaging ******************************************/
    925936
     937        /* AJAX send reply functionality */
    926938        j("input#send_reply_button").click(
    927939                function() {
     
    964976        );
    965977
     978        /* Marking private messages as read and unread */
    966979        j("a#mark_as_read, a#mark_as_unread").click(
    967980                function() {
     
    10191032        );
    10201033
     1034        /* Selecting unread and read messages in inbox */
    10211035        j("select#message-type-select").change(
    10221036                function() {
     
    10471061        );
    10481062
     1063        /* Close site wide notices in the sidebar */
     1064        j("a#close-notice").click( function() {
     1065                j(this).addClass('loading');
     1066                j('div#sidebar div.error').remove();
     1067
     1068                j.post( ajaxurl, {
     1069                        action: 'messages_close_notice',
     1070                        'notice_id': j('.notice').attr('rel').substr( 2, j('.notice').attr('rel').length )
     1071                },
     1072                function(response) {
     1073                        j("a#close-notice").removeClass('loading');
     1074
     1075                        if ( response[0] + response[1] == '-1' ) {
     1076                                j('.notice').prepend( response.substr( 2, response.length ) );
     1077                                j( 'div#sidebar div.error').hide().fadeIn( 200 );
     1078                        } else {
     1079                                j('.notice').slideUp( 100 );
     1080                        }
     1081                });
     1082                return false;
     1083        });
     1084
    10491085        /* Admin Bar Javascript */
    10501086        j("#wp-admin-bar ul.main-nav li").mouseover( function() {
  • trunk/bp-themes/bp-default/members/single/messages.php

    r2287 r2397  
    1616
    1717        <div class="messages">
    18                 <?php locate_template( array( 'members/single/messages/messages-loop.php' ), true ) ?>
     18                <?php if ( 'notices' == bp_current_action() ) : ?>
     19                        <?php locate_template( array( 'members/single/messages/notices-loop.php' ), true ) ?>
     20
     21                <?php else : ?>
     22                        <?php locate_template( array( 'members/single/messages/messages-loop.php' ), true ) ?>
     23
     24                <?php endif; ?>
    1925        </div>
    2026
  • trunk/bp-themes/bp-default/members/single/messages/messages-loop.php

    r2284 r2397  
    1616
    1717        <?php do_action( 'bp_after_member_messages_pagination' ) ?>
    18 
    19         <div class="messages-options-nav">
    20                 <?php bp_messages_options() ?>
    21         </div><!-- .messages-options-nav -->
    22 
    2318        <?php do_action( 'bp_before_member_messages_threads' ) ?>
    2419
     
    3227                                <td width="1%" class="thread-avatar"><?php bp_message_thread_avatar() ?></td>
    3328                                <td width="30%" class="thread-from">
    34                                         <?php _e("From:", "buddypress"); ?> <?php bp_message_thread_from() ?><br />
     29                                        <?php _e( 'From:', 'buddypress' ); ?> <?php bp_message_thread_from() ?><br />
    3530                                        <span class="activity"><?php bp_message_thread_last_post_date() ?></span>
    3631                                </td>
     
    5146        </table><!-- #message-threads -->
    5247
    53         <?php do_action( 'bp_after_member_messages_threads' ) ?>
    54 
    5548        <div class="messages-options-nav">
    5649                <?php bp_messages_options() ?>
    57         </div>
     50        </div><!-- .messages-options-nav -->
     51
     52        <?php do_action( 'bp_after_member_messages_threads' ) ?>
    5853
    5954        <?php do_action( 'bp_after_member_messages_options' ) ?>
  • trunk/bp-themes/bp-default/sidebar.php

    r2302 r2397  
    1212                        <h3><?php bp_loggedinuser_link() ?></h3>
    1313                        <a class="button" href="<?php echo wp_logout_url(wp_get_referer()) ?>"><?php _e( 'Log Out', 'buddypress' ) ?></a>
     14
    1415                </div>
     16
     17                <?php if ( function_exists( 'bp_message_get_notices' ) ) : ?>
     18                        <?php bp_message_get_notices(); /* Site wide notices to all users */ ?>
     19                <?php endif; ?>
    1520
    1621        <?php else : ?>
  • trunk/bp-xprofile.php

    r2389 r2397  
    498498        extract( $r, EXTR_SKIP );
    499499
    500         return bp_activity_add( array( 'user_id' => $user_id, 'action' => $action, 'content' => $content, 'primary_link' => $primary_link, 'component' => $component, 'type' => $type, 'item_id' => $item_id, 'secondary_item_id' => $secondary_item_id, 'recorded_time' => $recorded_time, 'hide_sitewide' => $hide_sitewide ) );
     500        /* Check for an existing entry and update if one exists. */
     501        $id = bp_activity_get_activity_id( array(
     502                'user_id' => $user_id,
     503                'component' => $component,
     504                'type' => $type,
     505                'item_id' => $item_id,
     506                'secondary_item_id' => $secondary_item_id
     507        ) );
     508
     509        return bp_activity_add( array( 'id' => $id, 'user_id' => $user_id, 'action' => $action, 'content' => $content, 'primary_link' => $primary_link, 'component' => $component, 'type' => $type, 'item_id' => $item_id, 'secondary_item_id' => $secondary_item_id, 'recorded_time' => $recorded_time, 'hide_sitewide' => $hide_sitewide ) );
    501510}
    502511
Note: See TracChangeset for help on using the changeset viewer.