BB_Loop

The BuddyPress BB Loop class.

Defined (1)

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

/bp-forums/bbpress/bb-includes/class.bb-walker.php  
  1. class BB_Loop { 
  2. var $elements; 
  3. var $walker; 
  4. var $_preserve = array(); 
  5. var $_looping = false; 
  6.  
  7. function &start( $elements, $walker = 'BB_Walker_Blank' ) { 
  8. $null = null; 
  9. $a = new BB_Loop( $elements ); 
  10. if ( !$a->elements ) 
  11. return $null; 
  12. $a->walker = new $walker; 
  13. return $a; 
  14.  
  15. function __construct( &$elements ) { 
  16. $this->elements = $elements; 
  17. if ( !is_array($this->elements) || empty($this->elements) ) 
  18. return $this->elements = false; 
  19.  
  20. function BB_Loop( &$elements ) { 
  21. $this->__construct( $elements ); 
  22.  
  23. function step() { 
  24. if ( !is_array($this->elements) || !current($this->elements) || !is_object($this->walker) ) 
  25. return false; 
  26.  
  27. if ( !$this->_looping ) { 
  28. $r = reset($this->elements); 
  29. $this->_looping = true; 
  30. } else { 
  31. $r = next($this->elements); 
  32.  
  33. if ( !$args = func_get_args() ) 
  34. $args = array( 0 ); 
  35. echo call_user_func_array( array(&$this->walker, 'step'), array_merge(array(current($this->elements)), $args) ); 
  36. return $r; 
  37.  
  38. function pad( $pad, $offset = 0 ) { 
  39. if ( !is_array($this->elements) || !is_object($this->walker) ) 
  40. return false; 
  41.  
  42. if ( is_numeric($pad) ) 
  43. return $pad * ($this->walker->depth - 1) + (int) $offset; 
  44.  
  45. return str_repeat( $pad, $this->walker->depth - 1 ); 
  46.  
  47. function preserve( $array ) { 
  48. if ( !is_array( $array ) ) 
  49. return false; 
  50.  
  51. foreach ( $array as $key ) 
  52. $this->_preserve[$key] = isset( $GLOBALS[$key] ) ? $GLOBALS[$key] : null; 
  53.  
  54. function reinstate() { 
  55. foreach ( $this->_preserve as $key => $value ) 
  56. $GLOBALS[$key] = $value; 
  57.  
  58. function classes( $output = 'string' ) { 
  59. if ( !is_array($this->elements) || !is_object($this->walker) ) 
  60. return false; 
  61. $classes = array(); 
  62.  
  63. $current = current($this->elements); 
  64.  
  65. if ( $prev = prev($this->elements) ) 
  66. next($this->elements); 
  67. else  
  68. reset($this->elements); 
  69.  
  70. if ( $next = next($this->elements) ) 
  71. prev($this->elements); 
  72. else 
  73. end($this->elements); 
  74.  
  75. if ( !empty($next) && $next->{$this->walker->db_fields['parent']} == $current->{$this->walker->db_fields['id']} ) 
  76. $classes[] = 'bb-parent'; 
  77. elseif ( !empty($next) && $next->{$this->walker->db_fields['parent']} == $current->{$this->walker->db_fields['parent']} ) 
  78. $classes[] = 'bb-precedes-sibling'; 
  79. else 
  80. $classes[] = 'bb-last-child'; 
  81.  
  82. if ( !empty($prev) && $current->{$this->walker->db_fields['parent']} == $prev->{$this->walker->db_fields['id']} ) 
  83. $classes[] = 'bb-first-child'; 
  84. elseif ( !empty($prev) && $current->{$this->walker->db_fields['parent']} == $prev->{$this->walker->db_fields['parent']} ) 
  85. $classes[] = 'bb-follows-sibling'; 
  86. elseif ( $prev ) 
  87. $classes[] = 'bb-follows-niece'; 
  88.  
  89. if ( $this->walker->depth > 1 ) 
  90. $classes[] = 'bb-child'; 
  91. else 
  92. $classes[] = 'bb-root'; 
  93.  
  94. if ( $output === 'string' ) 
  95. $classes = join(' ', $classes); 
  96.  
  97. return $classes; 
  98.