Skip to:
Content

BuddyPress.org

Ticket #2203: fix-wonky-time.patch

File fix-wonky-time.patch, 19.0 KB (added by johnjamesjacoby, 16 years ago)

Wonky Time

  • bp-activity.php

     
    626626        global $bp, $wpdb;
    627627
    628628        $defaults = array(
    629                 'id' => false, // Pass an existing activity ID to update an existing entry.
     629                'id'                => false, // Pass an existing activity ID to update an existing entry.
    630630
    631                 'action' => '', // The activity action - e.g. "Jon Doe posted an update"
    632                 'content' => '', // Optional: The content of the activity item e.g. "BuddyPress is awesome guys!"
     631                'action'            => '', // The activity action - e.g. "Jon Doe posted an update"
     632                'content'           => '', // Optional: The content of the activity item e.g. "BuddyPress is awesome guys!"
    633633
    634                 'component' => false, // The name/ID of the component e.g. groups, profile, mycomponent
    635                 'type' => false, // The activity type e.g. activity_update, profile_updated
    636                 'primary_link' => '', // Optional: The primary URL for this item in RSS feeds (defaults to activity permalink)
     634                'component'         => false, // The name/ID of the component e.g. groups, profile, mycomponent
     635                'type'              => false, // The activity type e.g. activity_update, profile_updated
     636                'primary_link'      => '', // Optional: The primary URL for this item in RSS feeds (defaults to activity permalink)
    637637
    638                 'user_id' => $bp->loggedin_user->id, // Optional: The user to record the activity for, can be false if this activity is not for a user.
    639                 'item_id' => false, // Optional: The ID of the specific item being recorded, e.g. a blog_id
     638                'user_id'           => $bp->loggedin_user->id, // Optional: The user to record the activity for, can be false if this activity is not for a user.
     639                'item_id'           => false, // Optional: The ID of the specific item being recorded, e.g. a blog_id
    640640                'secondary_item_id' => false, // Optional: A second ID used to further filter e.g. a comment_id
    641                 'recorded_time' => gmdate( "Y-m-d H:i:s" ), // The GMT time that this activity was recorded
    642                 'hide_sitewide' => false // Should this be hidden on the sitewide activity stream?
     641                'recorded_time'     => bp_core_current_time(), // The GMT time that this activity was recorded
     642                'hide_sitewide'     => false // Should this be hidden on the sitewide activity stream?
    643643        );
    644644
    645645        $params = wp_parse_args( $args, $defaults );
  • bp-blogs.php

     
    213213                'type' => false,
    214214                'item_id' => false,
    215215                'secondary_item_id' => false,
    216                 'recorded_time' => gmdate( "Y-m-d H:i:s" ),
     216                'recorded_time' => bp_core_current_time(),
    217217                'hide_sitewide' => false
    218218        );
    219219
     
    338338
    339339        bp_blogs_update_blogmeta( $recorded_blog->blog_id, 'name', $name );
    340340        bp_blogs_update_blogmeta( $recorded_blog->blog_id, 'description', $description );
    341         bp_blogs_update_blogmeta( $recorded_blog->blog_id, 'last_activity', gmdate( "Y-m-d H:i:s" ) );
     341        bp_blogs_update_blogmeta( $recorded_blog->blog_id, 'last_activity', bp_core_current_time() );
    342342
    343343        /* Only record this activity if the blog is public */
    344344        if ( (int)$_POST['blog_public'] && !$no_activity ) {
     
    425425        } else
    426426                bp_blogs_remove_post( $post_id, $blog_id );
    427427
    428         bp_blogs_update_blogmeta( $blog_id, 'last_activity', gmdate( "Y-m-d H:i:s" ) );
     428        bp_blogs_update_blogmeta( $blog_id, 'last_activity', bp_core_current_time() );
    429429
    430430        do_action( 'bp_blogs_new_blog_post', $post_id, $post, $user_id );
    431431}
     
    493493                ) );
    494494
    495495                // Update the blogs last active date
    496                 bp_blogs_update_blogmeta( $blog_id, 'last_activity', gmdate( "Y-m-d H:i:s" ) );
     496                bp_blogs_update_blogmeta( $blog_id, 'last_activity', bp_core_current_time() );
    497497        }
    498498
    499499        return $recorded_comment;
  • bp-core.php

     
    12891289}
    12901290
    12911291/**
    1292  * bp_core_format_time()
     1292 * bp_core_current_time()
     1293 *
     1294 * Get the current GMT time to save into the DB
     1295 *
     1296 * @package BuddyPress Core
     1297 * @since 1.2.6
    12931298 */
    1294 function bp_core_format_time( $time, $just_date = false ) {
    1295         if ( !$time )
    1296                 return false;
     1299function bp_core_current_time() {
     1300        // Get current time in MYSQL format
     1301        $current_time = current_time( 'mysql', true );
    12971302
    1298         $date = date( "F j, Y ", $time );
    1299 
    1300         if ( !$just_date ) {
    1301                 $date .= __('at', 'buddypress') . date( ' g:iA', $time );
    1302         }
    1303 
    1304         return $date;
     1303        return apply_filters( 'bp_core_current_time', $current_time );
    13051304}
    13061305
    13071306/**
     
    13991398 * @return str The time since.
    14001399 */
    14011400function bp_core_time_since( $older_date, $newer_date = false ) {
     1401
    14021402        // array of time period chunks
    1403 
    14041403        $chunks = array(
    1405         array( 60 * 60 * 24 * 365 , __( 'year', 'buddypress' ), __( 'years', 'buddypress' ) ),
    1406         array( 60 * 60 * 24 * 30 , __( 'month', 'buddypress' ), __( 'months', 'buddypress' ) ),
    1407         array( 60 * 60 * 24 * 7, __( 'week', 'buddypress' ), __( 'weeks', 'buddypress' ) ),
    1408         array( 60 * 60 * 24 , __( 'day', 'buddypress' ), __( 'days', 'buddypress' ) ),
    1409         array( 60 * 60 , __( 'hour', 'buddypress' ), __( 'hours', 'buddypress' ) ),
    1410         array( 60 , __( 'minute', 'buddypress' ), __( 'minutes', 'buddypress' ) ),
    1411         array( 1, __( 'second', 'buddypress' ), __( 'seconds', 'buddypress' ) )
     1404                array( 60 * 60 * 24 * 365 , __( 'year', 'buddypress' ), __( 'years', 'buddypress' ) ),
     1405                array( 60 * 60 * 24 * 30 , __( 'month', 'buddypress' ), __( 'months', 'buddypress' ) ),
     1406                array( 60 * 60 * 24 * 7, __( 'week', 'buddypress' ), __( 'weeks', 'buddypress' ) ),
     1407                array( 60 * 60 * 24 , __( 'day', 'buddypress' ), __( 'days', 'buddypress' ) ),
     1408                array( 60 * 60 , __( 'hour', 'buddypress' ), __( 'hours', 'buddypress' ) ),
     1409                array( 60 , __( 'minute', 'buddypress' ), __( 'minutes', 'buddypress' ) ),
     1410                array( 1, __( 'second', 'buddypress' ), __( 'seconds', 'buddypress' ) )
    14121411        );
    14131412
    14141413        if ( !is_numeric( $older_date ) ) {
     
    14201419
    14211420        /* $newer_date will equal false if we want to know the time elapsed between a date and the current time */
    14221421        /* $newer_date will have a value if we want to work out time elapsed between two known dates */
    1423         $newer_date = ( !$newer_date ) ? gmmktime( gmdate( 'H' ), gmdate( 'i' ), gmdate( 's' ), gmdate( 'n' ), gmdate( 'j' ), gmdate( 'Y' ) ) : $newer_date;
     1422        $newer_date = ( !$newer_date ) ? strtotime( bp_core_current_time() ) : $newer_date;
    14241423
    14251424        /* Difference in seconds */
    14261425        $since = $newer_date - $older_date;
     
    14881487        if ( !is_numeric( $activity ) )
    14891488                $activity = strtotime( $activity );
    14901489
    1491         if ( '' == $activity || strtotime( gmdate( "Y-m-d H:i:s" ) ) >= strtotime( '+5 minutes', $activity ) )
    1492                 update_usermeta( $bp->loggedin_user->id, 'last_activity', gmdate( "Y-m-d H:i:s" ) );
     1490        // Get current time with gmt offset
     1491        $current_time = bp_core_current_time();
     1492
     1493        if ( '' == $activity || strtotime( $current_time ) >= strtotime( '+5 minutes', $activity ) )
     1494                update_usermeta( $bp->loggedin_user->id, 'last_activity', $current_time );
    14931495}
    14941496add_action( 'wp_head', 'bp_core_record_activity' );
    14951497
  • bp-core/bp-core-classes.php

     
    424424
    425425                if ( $this->id ) {
    426426                        // Update
    427                         $sql = $wpdb->prepare( "UPDATE {$bp->core->table_name_notifications} SET item_id = %d, secondary_item_id = %d, user_id = %d, component_name = %s, component_action = %d, date_notified = FROM_UNIXTIME(%d), is_new = %d ) WHERE id = %d", $this->item_id, $this->secondary_item_id, $this->user_id, $this->component_name, $this->component_action, $this->date_notified, $this->is_new, $this->id );
     427                        $sql = $wpdb->prepare( "UPDATE {$bp->core->table_name_notifications} SET item_id = %d, secondary_item_id = %d, user_id = %d, component_name = %s, component_action = %d, date_notified = %s, is_new = %d ) WHERE id = %d", $this->item_id, $this->secondary_item_id, $this->user_id, $this->component_name, $this->component_action, $this->date_notified, $this->is_new, $this->id );
    428428                } else {
    429429                        // Save
    430                         $sql = $wpdb->prepare( "INSERT INTO {$bp->core->table_name_notifications} ( item_id, secondary_item_id, user_id, component_name, component_action, date_notified, is_new ) VALUES ( %d, %d, %d, %s, %s, FROM_UNIXTIME(%d), %d )", $this->item_id, $this->secondary_item_id, $this->user_id, $this->component_name, $this->component_action, $this->date_notified, $this->is_new );
     430                        $sql = $wpdb->prepare( "INSERT INTO {$bp->core->table_name_notifications} ( item_id, secondary_item_id, user_id, component_name, component_action, date_notified, is_new ) VALUES ( %d, %d, %d, %s, %s, %s, %d )", $this->item_id, $this->secondary_item_id, $this->user_id, $this->component_name, $this->component_action, $this->date_notified, $this->is_new );
    431431                }
    432432
    433433                if ( !$result = $wpdb->query( $sql ) )
  • bp-core/bp-core-notifications.php

     
    44        global $bp;
    55
    66        if ( !$date_notified )
    7                 $date_notified = time();
     7                $date_notified = bp_core_current_time();
    88
    99        $notification = new BP_Core_Notification;
    1010        $notification->item_id = $item_id;
  • bp-core/bp-core-signup.php

     
    494494        wp_update_user( array( 'ID' => $user_id, 'user_url' => bp_core_get_user_domain( $user_id, sanitize_title( $user_login ), $user_login ), 'display_name' => bp_core_get_user_displayname( $user_id ) ) );
    495495
    496496        /* Add a last active entry */
    497         update_usermeta( $user_id, 'last_activity', gmdate( "Y-m-d H:i:s" ) );
     497        update_usermeta( $user_id, 'last_activity', bp_core_current_time() );
    498498
    499499        /* Set the password on multisite installs */
    500500        if ( bp_core_is_multisite() && !empty( $user['meta']['password'] ) )
     
    537537                return false;
    538538
    539539        /* Add a last active entry */
    540         update_usermeta( $user_id, 'last_activity', gmdate( "Y-m-d H:i:s" ) );
     540        update_usermeta( $user_id, 'last_activity', bp_core_current_time() );
    541541
    542542        /* Add the user's fullname to Xprofile */
    543543        if ( function_exists( 'xprofile_set_field_data' ) ) {
  • bp-core/bp-core-templatetags.php

     
    840840}
    841841
    842842function bp_format_time( $time, $just_date = false ) {
    843         $date = date( get_option('date_format'), $time );
     843        if ( !$time )
     844                return false;
    844845
    845         if ( !$just_date ) {
    846                 $date .= ' ' . __( 'at', 'buddypress' ) . date( ' ' . get_option('time_format'), $time );
    847         }
     846        // Get GMT offset from root blog
     847        $root_blog_offset = get_blog_option( BP_ROOT_BLOG, 'gmt_offset' );
    848848
     849        // Calculate offset time
     850        $time_offest = $time + ( $root_blog_offset * 3600 );
     851
     852        // Current date (January 1, 2010)
     853        $date = date( 'F j, Y ', $time_offest );
     854
     855        // Current time (9:50pm)
     856        $time = date( ' g:iA', $time_offest );
     857
     858        // Should we show the time also?
     859        if ( !$just_date )
     860                $date .= __( 'at', 'buddypress' ) . date( ' g:iA', $time_offest );
     861
    849862        return apply_filters( 'bp_format_time', $date );
    850863}
    851864
  • bp-friends.php

     
    280280                'type' => false,
    281281                'item_id' => false,
    282282                'secondary_item_id' => false,
    283                 'recorded_time' => gmdate( "Y-m-d H:i:s" ),
     283                'recorded_time' => bp_core_current_time(),
    284284                'hide_sitewide' => false
    285285        );
    286286
     
    361361        $friendship->friend_user_id = $friend_userid;
    362362        $friendship->is_confirmed = 0;
    363363        $friendship->is_limited = 0;
    364         $friendship->date_created = time();
     364        $friendship->date_created = bp_core_current_time();
    365365
    366366        if ( $force_accept )
    367367                $friendship->is_confirmed = 1;
  • bp-friends/bp-friends-classes.php

     
    6060
    6161                if ( $this->id ) {
    6262                        // Update
    63                         $result = $wpdb->query( $wpdb->prepare( "UPDATE {$bp->friends->table_name} SET initiator_user_id = %d, friend_user_id = %d, is_confirmed = %d, is_limited = %d, date_created = FROM_UNIXTIME(%d) ) WHERE id = %d", $this->initiator_user_id, $this->friend_user_id, $this->is_confirmed, $this->is_limited, $this->date_created, $this->id ) );
     63                        $result = $wpdb->query( $wpdb->prepare( "UPDATE {$bp->friends->table_name} SET initiator_user_id = %d, friend_user_id = %d, is_confirmed = %d, is_limited = %d, date_created = %s ) WHERE id = %d", $this->initiator_user_id, $this->friend_user_id, $this->is_confirmed, $this->is_limited, $this->date_created, $this->id ) );
    6464                } else {
    6565                        // Save
    66                         $result = $wpdb->query( $wpdb->prepare( "INSERT INTO {$bp->friends->table_name} ( initiator_user_id, friend_user_id, is_confirmed, is_limited, date_created ) VALUES ( %d, %d, %d, %d, FROM_UNIXTIME(%d) )", $this->initiator_user_id, $this->friend_user_id, $this->is_confirmed, $this->is_limited, $this->date_created ) );
     66                        $result = $wpdb->query( $wpdb->prepare( "INSERT INTO {$bp->friends->table_name} ( initiator_user_id, friend_user_id, is_confirmed, is_limited, date_created ) VALUES ( %d, %d, %d, %d, %s )", $this->initiator_user_id, $this->friend_user_id, $this->is_confirmed, $this->is_limited, $this->date_created ) );
    6767                        $this->id = $wpdb->insert_id;
    6868                }
    6969
     
    202202        function accept($friendship_id) {
    203203                global $wpdb, $bp;
    204204
    205                 return $wpdb->query( $wpdb->prepare( "UPDATE {$bp->friends->table_name} SET is_confirmed = 1, date_created = FROM_UNIXTIME(%d) WHERE id = %d AND friend_user_id = %d", time(), $friendship_id, $bp->loggedin_user->id ) );
     205                return $wpdb->query( $wpdb->prepare( "UPDATE {$bp->friends->table_name} SET is_confirmed = 1, date_created = %s WHERE id = %d AND friend_user_id = %d", bp_core_current_time(), $friendship_id, $bp->loggedin_user->id ) );
    206206        }
    207207
    208208        function reject($friendship_id) {
  • bp-groups.php

     
    13421342                'type' => false,
    13431343                'item_id' => false,
    13441344                'secondary_item_id' => false,
    1345                 'recorded_time' => gmdate( "Y-m-d H:i:s" ),
     1345                'recorded_time' => bp_core_current_time(),
    13461346                'hide_sitewide' => $hide_sitewide
    13471347        );
    13481348
  • bp-groups/bp-groups-classes.php

     
    770770        function accept_invite() {
    771771                $this->inviter_id = 0;
    772772                $this->is_confirmed = 1;
    773                 $this->date_modified = gmdate( "Y-m-d H:i:s" );
     773                $this->date_modified = bp_core_current_time();
    774774        }
    775775
    776776        function accept_request() {
    777777                $this->is_confirmed = 1;
    778                 $this->date_modified = gmdate( "Y-m-d H:i:s" );
     778                $this->date_modified = bp_core_current_time();
    779779        }
    780780
    781781        /* Static Functions */
  • bp-messages.php

     
    402402                'recipients' => false, // Can be an array of usernames, user_ids or mixed.
    403403                'subject' => false,
    404404                'content' => false,
    405                 'date_sent' => time()
     405                'date_sent' => bp_core_current_time()
    406406        );
    407407
    408408        $r = wp_parse_args( $args, $defaults );
     
    487487                $notice = new BP_Messages_Notice;
    488488                $notice->subject = $subject;
    489489                $notice->message = $message;
    490                 $notice->date_sent = time();
     490                $notice->date_sent = bp_core_current_time();
    491491                $notice->is_active = 1;
    492492                $notice->save(); // send it.
    493493
  • bp-messages/bp-messages-classes.php

     
    243243        function bp_messages_message( $id = null ) {
    244244                global $bp;
    245245
    246                 $this->date_sent = time();
     246                $this->date_sent = bp_core_current_time();
    247247                $this->sender_id = $bp->loggedin_user->id;
    248248
    249249                if ( $id ) {
     
    288288                }
    289289
    290290                // First insert the message into the messages table
    291                 if ( !$wpdb->query( $wpdb->prepare( "INSERT INTO {$bp->messages->table_name_messages} ( thread_id, sender_id, subject, message, date_sent ) VALUES ( %d, %d, %s, %s, FROM_UNIXTIME(%d) )", $this->thread_id, $this->sender_id, $this->subject, $this->message, $this->date_sent ) ) )
     291                if ( !$wpdb->query( $wpdb->prepare( "INSERT INTO {$bp->messages->table_name_messages} ( thread_id, sender_id, subject, message, date_sent ) VALUES ( %d, %d, %s, %s, %s )", $this->thread_id, $this->sender_id, $this->subject, $this->message, $this->date_sent ) ) )
    292292                        return false;
    293293
    294294                if ( $new_thread ) {
     
    387387                do_action( 'messages_notice_before_save', $this );
    388388
    389389                if ( !$this->id ) {
    390                         $sql = $wpdb->prepare( "INSERT INTO {$bp->messages->table_name_notices} (subject, message, date_sent, is_active) VALUES (%s, %s, FROM_UNIXTIME(%d), %d)", $this->subject, $this->message, $this->date_sent, $this->is_active );
     390                        $sql = $wpdb->prepare( "INSERT INTO {$bp->messages->table_name_notices} (subject, message, date_sent, is_active) VALUES (%s, %s, %s, %d)", $this->subject, $this->message, $this->date_sent, $this->is_active );
    391391                } else {
    392392                        $sql = $wpdb->prepare( "UPDATE {$bp->messages->table_name_notices} SET subject = %s, message = %s, is_active = %d WHERE id = %d", $this->subject, $this->message, $this->is_active, $this->id );
    393393                }
  • bp-themes/bp-default/_inc/ajax.php

     
    187187                                </div>
    188188
    189189                                <div class="acomment-meta">
    190                                         <?php echo bp_core_get_userlink( bp_get_activity_user_id() ) ?> &middot; <?php printf( __( '%s ago', 'buddypress' ), bp_core_time_since( gmdate( "Y-m-d H:i:s" ) ) ) ?> &middot;
     190                                        <?php echo bp_core_get_userlink( bp_get_activity_user_id() ) ?> &middot; <?php printf( __( '%s ago', 'buddypress' ), bp_core_time_since( bp_core_current_time() ) ) ?> &middot;
    191191                                        <a class="acomment-reply" href="#acomment-<?php bp_activity_id() ?>" id="acomment-reply-<?php echo attribute_escape( $_POST['form_id'] ) ?>"><?php _e( 'Reply', 'buddypress' ) ?></a>
    192192                                         &middot; <a href="<?php echo wp_nonce_url( $bp->root_domain . '/' . $bp->activity->slug . '/delete/' . bp_get_activity_id() . '?cid=' . $comment_id, 'bp_activity_delete_link' ) ?>" class="delete acomment-delete confirm"><?php _e( 'Delete', 'buddypress' ) ?></a>
    193193                                </div>
  • bp-xprofile.php

     
    484484                'type' => false,
    485485                'item_id' => false,
    486486                'secondary_item_id' => false,
    487                 'recorded_time' => gmdate( "Y-m-d H:i:s" ),
     487                'recorded_time' => bp_core_current_time(),
    488488                'hide_sitewide' => false
    489489        );
    490490