bb_since

The BuddyPress bb since function.

Description

bb_since( $original, (string) $args = '' ); 

Parameters (2)

0. $original
The original.
1. $args — Optional. (string) => ''
The args.

Usage

  1. if ( !function_exists( 'bb_since' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-forums/bbpress/bb-includes/functions.bb-core.php'; 
  3.  
  4. // The original. 
  5. $original = null; 
  6.  
  7. // The args. 
  8. $args = ''; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = bb_since($original, $args); 
  12.  

Defined (1)

The function is defined in the following location(s).

/bp-forums/bbpress/bb-includes/functions.bb-core.php  
  1. function bb_since( $original, $args = '' ) 
  2. $defaults = array( 
  3. 'levels' => 1,  
  4. 'separator' => ', ' 
  5. ); 
  6.  
  7. // $args used to be $do_more 
  8. // $do_more = 0 is equivalent to $args['levels'] = 1 
  9. // $do_more = 1 is equivalent to $args['levels'] = 2 
  10. if ( !is_array( $args ) ) { 
  11. $args = array( 
  12. 'levels' => abs( (integer) $args ) + 1 
  13. ); 
  14.  
  15. $args = wp_parse_args( $args, $defaults ); 
  16. extract( $args, EXTR_SKIP ); 
  17.  
  18. $today = (integer) time(); 
  19.  
  20. if ( !is_numeric( $original ) ) { 
  21. if ( $today < $_original = bb_gmtstrtotime( str_replace( ', ', ' ', $original ) ) ) { // Looks like bb_since was called twice 
  22. return $original; 
  23. } else { 
  24. $original = $_original; 
  25.  
  26. $seconds = $today - ( (integer) $original ); 
  27. if ( 0 === $seconds ) { 
  28. return sprintf( _n( '%d second', '%d seconds', 0 ), 0 ); 
  29.  
  30. $levels = abs( (integer) $levels ); 
  31. if ( 0 === $levels ) { 
  32. return ''; 
  33.  
  34. // array of time period chunks 
  35. $chunks = array( 
  36. ( 60 * 60 * 24 * 365 ), // years 
  37. ( 60 * 60 * 24 * 30 ), // months 
  38. ( 60 * 60 * 24 * 7 ), // weeks 
  39. ( 60 * 60 * 24 ), // days 
  40. ( 60 * 60 ), // hours 
  41. ( 60 ), // minutes 
  42. ( 1 ) // seconds 
  43. ); 
  44.  
  45. $caught = 0; 
  46. $parts = array(); 
  47. for ( $i = 0; $i < count( $chunks ); $i++ ) { 
  48. if ( ( $count = floor( $seconds / $chunks[$i] ) ) || $caught ) { 
  49. if ( $count ) { 
  50. $trans = array( 
  51. _n( '%d year', '%d years', $count ),  
  52. _n( '%d month', '%d months', $count ),  
  53. _n( '%d week', '%d weeks', $count ),  
  54. _n( '%d day', '%d days', $count ),  
  55. _n( '%d hour', '%d hours', $count ),  
  56. _n( '%d minute', '%d minutes', $count ),  
  57. _n( '%d second', '%d seconds', $count ) 
  58. ); 
  59. $parts[] = sprintf( $trans[$i], $count ); 
  60. $caught++; 
  61. $seconds = $seconds - ( $count * $chunks[$i] ); 
  62. if ( $caught === $levels ) { 
  63. break; 
  64.  
  65. if ( empty( $parts ) ) { 
  66. return sprintf( _n( '%d second', '%d seconds', 0 ), 0 ); 
  67.  
  68. return join( $separator, $parts );