Changeset 8251
- Timestamp:
- 04/08/2014 06:55:30 AM (11 years ago)
- Location:
- trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-activity/bp-activity-classes.php
r8249 r8251 1190 1190 * 1191 1191 * @param array $filter_array { 1192 * Fields and values to filter by. Each can be either a single 1193 * string, a comma-separated list, or an array of values. 1192 * Fields and values to filter by. 1194 1193 * @type array|string|id $user_id User ID(s). 1195 1194 * @type array|string $object Corresponds to the 'component' … … 1201 1200 * @type array|string|int $secondary_id Corresponds to the 1202 1201 * 'secondary_item_id' column in the database. 1202 * @type int $offset Return only those items with an ID greater 1203 * than the offset value. 1204 * @type string $since Return only those items that have a 1205 * date_recorded value greater than a given MySQL-formatted 1206 * date. 1203 1207 * } 1204 1208 * @return string The filter clause, for use in a SQL query. … … 1241 1245 $sid_sql = absint( $filter_array['offset'] ); 1242 1246 $filter_sql[] = "a.id >= {$sid_sql}"; 1247 } 1248 1249 if ( ! empty( $filter_array['since'] ) ) { 1250 // Validate that this is a proper Y-m-d H:i:s date 1251 // Trick: parse to UNIX date then translate back 1252 $translated_date = date( 'Y-m-d H:i:s', strtotime( $filter_array['since'] ) ); 1253 if ( $translated_date === $filter_array['since'] ) { 1254 $filter_sql[] = "a.date_recorded > '{$translated_date}'"; 1255 } 1243 1256 } 1244 1257 -
trunk/bp-activity/bp-activity-filters.php
r8219 r8251 430 430 $bp = buddypress(); 431 431 432 if ( ! empty( $bp->activity-> new_update_id ) && $bp->activity->new_update_id == bp_get_activity_id() ) {432 if ( ! empty( $bp->activity->last_recorded ) && $bp->activity->last_recorded == bp_get_activity_date_recorded() ) { 433 433 $classes .= ' new-update'; 434 434 } … … 439 439 440 440 /** 441 * Check if Activity Heartbeat feature i on to add a timestamp class. 442 * 443 * @since BuddyPress (2.0.0) 444 * 445 * @param string $classes 446 * @return string $classes 447 */ 448 function bp_activity_timestamp_class( $classes = '' ) { 449 450 if ( ! bp_activity_do_heartbeat() ) { 451 return $classes; 452 } 453 454 $activity_date = bp_get_activity_date_recorded(); 455 456 if ( empty( $activity_date ) ) { 457 return $classes; 458 } 459 460 $classes .= ' date-recorded-' . strtotime( $activity_date ); 461 462 return $classes; 463 } 464 add_filter( 'bp_get_activity_css_class', 'bp_activity_timestamp_class', 9, 1 ); 465 466 /** 441 467 * Use WordPress Heartbeat API to check for latest activity update. 442 468 * … … 444 470 * 445 471 * @uses bp_activity_get_last_updated() to get the recorded date of the last activity 446 472 * 447 473 * @param array $response 448 474 * @param array $data … … 452 478 $bp = buddypress(); 453 479 454 if ( empty( $data['bp_activity_last_ id'] ) ) {480 if ( empty( $data['bp_activity_last_recorded'] ) ) { 455 481 return $response; 456 482 } … … 460 486 $activity_latest_args = bp_parse_args( 461 487 bp_ajax_querystring( 'activity' ), 462 array( ' offset' => absint( $data['bp_activity_last_id'] ) + 1),488 array( 'since' => date( 'Y-m-d H:i:s', $data['bp_activity_last_recorded'] ) ), 463 489 'activity_latest_args' 464 490 ); 465 491 466 492 $newest_activities = array(); 467 $last_activity_ id= 0;493 $last_activity_recorded = 0; 468 494 469 495 // Temporarly add a just-posted class for new activity items … … 475 501 bp_the_activity(); 476 502 477 if ( $last_activity_id < bp_get_activity_id() ) { 478 $last_activity_id = bp_get_activity_id(); 503 $atime = strtotime( bp_get_activity_date_recorded() ); 504 if ( $last_activity_recorded < $atime ) { 505 $last_activity_recorded = $atime; 479 506 } 480 507 … … 483 510 } 484 511 485 $newest_activities['activities'] = ob_get_contents();486 $newest_activities['last_ id'] = $last_activity_id;512 $newest_activities['activities'] = ob_get_contents(); 513 $newest_activities['last_recorded'] = $last_activity_recorded; 487 514 ob_end_clean(); 488 515 … … 490 517 remove_filter( 'bp_get_activity_css_class', 'bp_activity_newest_class', 10, 1 ); 491 518 492 if ( ! empty( $newest_activities['last_ id'] ) ) {519 if ( ! empty( $newest_activities['last_recorded'] ) ) { 493 520 $response['bp_activity_newest_activities'] = $newest_activities; 494 521 } -
trunk/bp-activity/bp-activity-template.php
r8201 r8251 548 548 'secondary_id' => false, // secondary object ID to filter on e.g. a post_id 549 549 'offset' => false, // return only items >= this ID 550 'since' => false, // return only items recorded since this Y-m-d H:i:s date 550 551 551 552 'meta_query' => false, // filter on activity meta. See WP_Meta_Query for format … … 642 643 if ( isset( $_GET['afilter'] ) && apply_filters( 'bp_activity_enable_afilter_support', false ) ) 643 644 $filter = array( 'object' => $_GET['afilter'] ); 644 else if ( ! empty( $user_id ) || ! empty( $object ) || ! empty( $action ) || ! empty( $primary_id ) || ! empty( $secondary_id ) || ! empty( $offset ) )645 $filter = array( 'user_id' => $user_id, 'object' => $object, 'action' => $action, 'primary_id' => $primary_id, 'secondary_id' => $secondary_id, 'offset' => $offset );645 else if ( ! empty( $user_id ) || ! empty( $object ) || ! empty( $action ) || ! empty( $primary_id ) || ! empty( $secondary_id ) || ! empty( $offset ) || ! empty( $since ) ) 646 $filter = array( 'user_id' => $user_id, 'object' => $object, 'action' => $action, 'primary_id' => $primary_id, 'secondary_id' => $secondary_id, 'offset' => $offset, 'since' => $since ); 646 647 else 647 648 $filter = false; … … 2806 2807 function bp_activity_recurse_comments_activity_ids( $activity = array(), $activity_ids = array() ) { 2807 2808 if ( is_array( $activity ) && ! empty( $activity['activities'] ) ) { 2808 $activity = $activity['activities'][0]; 2809 $activity = $activity['activities'][0]; 2809 2810 } 2810 2811 -
trunk/bp-templates/bp-legacy/buddypress-functions.php
r8201 r8251 707 707 exit( '-1<div id="message" class="error"><p>' . __( 'There was a problem posting your update, please try again.', 'buddypress' ) . '</p></div>' ); 708 708 709 $last_ id = isset( $_POST['offset'] ) ? absint( $_POST['offset'] ) + 1: 0;710 if ( $last_ id ) {711 $activity_args = array( ' offset' => $last_id );712 $bp->activity-> new_update_id = $activity_id;709 $last_recorded = isset( $_POST['since'] ) ? date( 'Y-m-d H:i:s', intval( $_POST['since'] ) ) : 0; 710 if ( $last_recorded ) { 711 $activity_args = array( 'since' => $last_recorded ); 712 $bp->activity->last_recorded = $last_recorded; 713 713 add_filter( 'bp_get_activity_css_class', 'bp_activity_newest_class', 10, 1 ); 714 714 } else { … … 723 723 } 724 724 725 if ( ! empty( $last_ id ) ) {725 if ( ! empty( $last_recorded ) ) { 726 726 remove_filter( 'bp_get_activity_css_class', 'bp_activity_newest_class', 10, 1 ); 727 727 } -
trunk/bp-templates/bp-legacy/js/buddypress.js
r8151 r8251 7 7 // Global variables to temporarly store newest activities 8 8 var newest_activities = ''; 9 var activity_last_ id = 0;9 var activity_last_recorded = 0; 10 10 11 11 jq(document).ready( function() { … … 92 92 /* New posts */ 93 93 jq("#aw-whats-new-submit").on( 'click', function() { 94 var last_d isplayed_id = 0;94 var last_date_recorded = 0; 95 95 var button = jq(this); 96 96 var form = button.closest("form#whats-new-form"); … … 112 112 var content = jq("#whats-new").val(); 113 113 var firstrow = jq( '#buddypress ul.activity-list li' ).first(); 114 115 if ( firstrow.hasClass( 'load-newest' ) ) { 116 last_displayed_id = firstrow.next().prop( 'id' ) ? firstrow.next().prop( 'id' ).replace( 'activity-','' ) : 0; 117 } else { 118 last_displayed_id = firstrow.prop( 'id' ) ? firstrow.prop( 'id' ).replace( 'activity-','' ) : 0; 114 var activity_row = firstrow; 115 116 if ( activity_row.hasClass( 'load-newest' ) ) { 117 activity_row = firstrow.next(); 118 } 119 120 timestamp = activity_row.prop( 'class' ).match( /date-recorded-([0-9]+)/ ); 121 122 if ( timestamp ) { 123 last_date_recorded = timestamp[1]; 119 124 } 120 125 … … 131 136 'object': object, 132 137 'item_id': item_id, 133 ' offset': last_displayed_id,138 'since': last_date_recorded, 134 139 '_bp_as_nonce': jq('#_bp_as_nonce').val() || '' 135 140 }, … … 158 163 jq("#activity-stream").prepend(response); 159 164 160 if ( ! last_d isplayed_id )165 if ( ! last_date_recorded ) 161 166 jq("#activity-stream li:first").addClass('new-update just-posted'); 162 167 … … 185 190 // reset vars to get newest activities 186 191 newest_activities = ''; 187 activity_last_ id = 0;192 activity_last_recorded = 0; 188 193 } 189 194 … … 306 311 var link_href = target.attr('href'); 307 312 var nonce = link_href.split('_wpnonce='); 313 var timestamp = li.prop( 'class' ).match( /date-recorded-([0-9]+)/ ); 308 314 309 315 nonce = nonce[1]; … … 326 332 327 333 // reset vars to get newest activities 328 if ( activity_last_id == id) {334 if ( timestamp && activity_last_recorded == timestamp[1] ) { 329 335 newest_activities = ''; 330 activity_last_ id = 0;336 activity_last_recorded = 0; 331 337 } 332 338 } … … 338 344 // Spam activity stream items 339 345 if ( target.hasClass( 'spam-activity' ) ) { 340 var li = target.parents( 'div.activity ul li' ); 346 var li = target.parents( 'div.activity ul li' ); 347 var timestamp = li.prop( 'class' ).match( /date-recorded-([0-9]+)/ ); 341 348 target.addClass( 'loading' ); 342 349 … … 355 362 li.slideUp( 300 ); 356 363 // reset vars to get newest activities 357 if ( activity_last_id == id) {364 if ( timestamp && activity_last_recorded == timestamp[1] ) { 358 365 newest_activities = ''; 359 activity_last_ id = 0;366 activity_last_recorded = 0; 360 367 } 361 368 } … … 408 415 409 416 target.parent().hide(); 417 418 /** 419 * If a plugin is updating the recorded_date of an activity 420 * it will be loaded as a new one. We need to look in the 421 * stream and eventually remove similar ids to avoid "double". 422 */ 423 activity_html = jq.parseHTML( newest_activities ); 424 425 jq.each( activity_html, function( i, el ){ 426 if( 'LI' == el.nodeName && jq(el).hasClass( 'just-posted' ) ) { 427 if( jq( '#' + jq(el).attr( 'id' ) ).length ) 428 jq( '#' + jq(el).attr( 'id' ) ).remove(); 429 } 430 } ); 431 432 // Now the stream is cleaned, prepend newest 410 433 jq( '#buddypress ul.activity-list' ).prepend( newest_activities ); 411 434 … … 1493 1516 // Set the last id to request after 1494 1517 jq( document ).on( 'heartbeat-send.buddypress', function( e, data ) { 1518 1519 firstrow = 0; 1495 1520 1496 1521 // First row is default latest activity id 1497 1522 if ( jq( '#buddypress ul.activity-list li' ).first().prop( 'id' ) ) { 1498 firstrow = jq( '#buddypress ul.activity-list li' ).first().prop( 'id' ).replace( 'activity-','' ); 1499 } else { 1500 firstrow = 0; 1501 } 1502 1503 if ( 0 == activity_last_id || Number( firstrow ) > activity_last_id ) 1504 activity_last_id = Number( firstrow ); 1505 1506 data['bp_activity_last_id'] = activity_last_id; 1507 }); 1508 1509 // Increment newest_activities and activity_last_id if data has been returned 1523 // getting the timestamp 1524 timestamp = jq( '#buddypress ul.activity-list li' ).first().prop( 'class' ).match( /date-recorded-([0-9]+)/ ); 1525 1526 if ( timestamp ) { 1527 firstrow = timestamp[1]; 1528 } 1529 } 1530 1531 if ( 0 == activity_last_recorded || Number( firstrow ) > activity_last_recorded ) 1532 activity_last_recorded = Number( firstrow ); 1533 1534 data['bp_activity_last_recorded'] = activity_last_recorded; 1535 }); 1536 1537 // Increment newest_activities and activity_last_recorded if data has been returned 1510 1538 jq( document ).on( 'heartbeat-tick', function( e, data ) { 1511 1539 … … 1516 1544 1517 1545 newest_activities = data['bp_activity_newest_activities']['activities'] + newest_activities; 1518 activity_last_ id = Number( data['bp_activity_newest_activities']['last_id'] );1546 activity_last_recorded = Number( data['bp_activity_newest_activities']['last_recorded'] ); 1519 1547 1520 1548 if ( jq( '#buddypress ul.activity-list li' ).first().hasClass( 'load-newest' ) ) -
trunk/tests/testcases/activity/class.BP_Activity_Activity.php
r8249 r8251 283 283 $this->assertEquals( array( $a3, $a2 ), $ids ); 284 284 } 285 286 /** 287 * @group get 288 */ 289 public function test_get_with_since() { 290 $now = time(); 291 $a1 = $this->factory->activity->create( array( 292 'content' => 'Life Rules', 293 'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ), 294 ) ); 295 $a2 = $this->factory->activity->create( array( 296 'content' => 'Life Drools', 297 'recorded_time' => date( 'Y-m-d H:i:s', $now - 50 ), 298 ) ); 299 $a3 = $this->factory->activity->create( array( 300 'content' => 'Life Drools', 301 'recorded_time' => date( 'Y-m-d H:i:s', $now - 10 ), 302 ) ); 303 304 $activity = BP_Activity_Activity::get( array( 305 'filter' => array( 306 'since' => date( 'Y-m-d H:i:s', $now - 70 ), 307 ), 308 ) ); 309 $ids = wp_list_pluck( $activity['activities'], 'id' ); 310 $this->assertEquals( array( $a3, $a2 ), $ids ); 311 } 312 285 313 /** 286 314 * @group get_id
Note: See TracChangeset
for help on using the changeset viewer.