Skip to:
Content

Changeset 3142


Ignore:
Timestamp:
07/21/2010 07:33:39 PM (9 years ago)
Author:
johnjamesjacoby
Message:

Fixes #2203 and #2497. Introduces bp_core_current_time function as central handler for all time related functions. Removes unused bp_core_format_time in lieu of currently used bp_format_time.

Location:
branches/1.2
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • branches/1.2/bp-activity.php

    r3111 r3142  
    627627
    628628    $defaults = array(
    629         'id' => false, // Pass an existing activity ID to update an existing entry.
    630 
    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!"
    633 
    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)
    637 
    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
     629        'id'                => false, // Pass an existing activity ID to update an existing entry.
     630
     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!"
     633
     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)
     637
     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
  • branches/1.2/bp-blogs.php

    r3132 r3142  
    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    );
     
    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 */
     
    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 );
     
    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
  • branches/1.2/bp-core.php

    r3133 r3142  
    12901290
    12911291/**
    1292  * bp_core_format_time()
    1293  */
    1294 function bp_core_format_time( $time, $just_date = false ) {
    1295     if ( !$time )
    1296         return false;
    1297 
    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;
     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
     1298 */
     1299function bp_core_current_time() {
     1300    // Get current time in MYSQL format
     1301    $current_time = current_time( 'mysql', true );
     1302
     1303    return apply_filters( 'bp_core_current_time', $current_time );
    13051304}
    13061305
     
    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
     
    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 */
     
    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
     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' );
  • branches/1.2/bp-core/bp-core-classes.php

    r2924 r3142  
    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
  • branches/1.2/bp-core/bp-core-notifications.php

    r2576 r3142  
    55
    66    if ( !$date_notified )
    7         $date_notified = time();
     7        $date_notified = bp_core_current_time();
    88
    99    $notification = new BP_Core_Notification;
  • branches/1.2/bp-core/bp-core-signup.php

    r3038 r3142  
    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 */
     
    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 */
  • branches/1.2/bp-core/bp-core-templatetags.php

    r3111 r3142  
    841841
    842842function bp_format_time( $time, $just_date = false ) {
    843     $date = date( get_option('date_format'), $time );
    844 
    845     if ( !$just_date ) {
    846         $date .= ' ' . __( 'at', 'buddypress' ) . date( ' ' . get_option('time_format'), $time );
    847     }
     843    if ( !$time )
     844        return false;
     845
     846    // Get GMT offset from root blog
     847    $root_blog_offset = get_blog_option( BP_ROOT_BLOG, 'gmt_offset' );
     848
     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 );
    848861
    849862    return apply_filters( 'bp_format_time', $date );
  • branches/1.2/bp-friends.php

    r3111 r3142  
    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    );
     
    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 )
  • branches/1.2/bp-friends/bp-friends-classes.php

    r3044 r3142  
    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        }
     
    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
  • branches/1.2/bp-groups.php

    r3129 r3142  
    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    );
  • branches/1.2/bp-groups/bp-groups-classes.php

    r3113 r3142  
    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
  • branches/1.2/bp-messages.php

    r3140 r3142  
    403403        'subject' => false,
    404404        'content' => false,
    405         'date_sent' => time()
     405        'date_sent' => bp_core_current_time()
    406406    );
    407407
     
    493493        $notice->subject = $subject;
    494494        $notice->message = $message;
    495         $notice->date_sent = time();
     495        $notice->date_sent = bp_core_current_time();
    496496        $notice->is_active = 1;
    497497        $notice->save(); // send it.
  • branches/1.2/bp-messages/bp-messages-classes.php

    r2576 r3142  
    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
     
    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
     
    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 );
  • branches/1.2/bp-themes/bp-default/_inc/ajax.php

    r2733 r3142  
    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>
     
    466466                <?php echo bp_loggedin_user_avatar( 'type=thumb&width=30&height=30' ); ?>
    467467
    468                 <strong><a href="<?php echo $bp->loggedin_user->domain ?>"><?php echo $bp->loggedin_user->fullname ?></a> <span class="activity"><?php printf( __( 'Sent %s ago', 'buddypress' ), bp_core_time_since( time() ) ) ?></span></strong>
     468                <strong><a href="<?php echo $bp->loggedin_user->domain ?>"><?php echo $bp->loggedin_user->fullname ?></a> <span class="activity"><?php printf( __( 'Sent %s ago', 'buddypress' ), bp_core_time_since( bp_core_current_time() ) ) ?></span></strong>
    469469
    470470                <?php do_action( 'bp_after_message_meta' ) ?>
  • branches/1.2/bp-xprofile.php

    r3058 r3142  
    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    );
Note: See TracChangeset for help on using the changeset viewer.