Changeset 3704 for trunk/wp-includes/functions.php
- Timestamp:
- 04/13/2006 04:40:48 AM (20 years ago)
- File:
-
- 1 edited
-
trunk/wp-includes/functions.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/functions.php
r3701 r3704 713 713 return $_page; 714 714 } 715 }716 717 function walk_tree($tree_type, $elements, $to_depth, $start_element_callback, $end_element_callback = '', $start_level_callback = '', $end_level_callback = '') {718 $args = array_slice(func_get_args(), 7);719 $parents = array();720 $depth = 1;721 $previous_element = '';722 $output = '';723 724 $last_element->post_parent = 0;725 $last_element->post_id = 0;726 $elements[] = $last_element;727 728 if ( 'page' == $tree_type ) {729 $parent_field = 'post_parent';730 $id_field = 'ID';731 } else {732 $parent_field = 'category_parent';733 $id_field = 'cat_ID';734 }735 736 $flat = false;737 if ( $to_depth == -1 )738 $flat = true;739 740 foreach ( $elements as $element ) {741 // If flat, start and end the element and skip the level checks.742 if ( $flat) {743 // Start the element.744 if ( !empty($start_element_callback) && ($element->$id_field != 0) ) {745 $cb_args = array_merge( array($output, $element, $depth), $args);746 $output = call_user_func_array($start_element_callback, $cb_args);747 }748 749 // End the element.750 if ( !empty($end_element_callback) && ($element->$id_field != 0) ) {751 $cb_args = array_merge( array($output, $element, $depth), $args);752 $output = call_user_func_array($end_element_callback, $cb_args);753 }754 755 continue;756 }757 758 // Walk the tree.759 if ( !empty($previous_element) && ($element->$parent_field == $previous_element->$id_field) ) {760 // Previous element is my parent. Descend a level.761 $depth++; //always do this so when we start the element further down, we know where we are762 array_unshift($parents, $previous_element);763 if ( !$to_depth || ($depth < $to_depth) ) { //only descend if we're below $to_depth764 if ( !empty($start_level_callback) ) {765 $cb_args = array_merge( array($output, $depth), $args);766 $output = call_user_func_array($start_level_callback, $cb_args);767 }768 }769 } else if ( $element->$parent_field == $previous_element->$parent_field ) {770 // On the same level as previous element, so close the previous771 if ( !$to_depth || ($depth <= $to_depth) ) {772 if ( !empty($end_element_callback) ) {773 $cb_args = array_merge( array($output, $previous_element, $depth), $args);774 $output = call_user_func_array($end_element_callback, $cb_args);775 }776 }777 } else if ( $depth > 1 ) {778 // Ascend one or more levels.779 if ( !$to_depth || ($depth <= $to_depth) ) {780 if ( !empty($end_element_callback) ) {781 $cb_args = array_merge( array($output, $previous_element, $depth), $args);782 $output = call_user_func_array($end_element_callback, $cb_args);783 }784 }785 786 while ( $parent = array_shift($parents) ) {787 $depth--;788 if ( !$to_depth || ($depth < $to_depth) ) {789 if ( !empty($end_level_callback) ) {790 $cb_args = array_merge( array($output, $depth), $args);791 $output = call_user_func_array($end_level_callback, $cb_args);792 }793 if ( !empty($end_element_callback) ) {794 $cb_args = array_merge( array($output, $parent, $depth), $args);795 $output = call_user_func_array($end_element_callback, $cb_args);796 }797 }798 if ( $element->$parent_field == $parents[0]->$id_field ) {799 break;800 }801 }802 } else if ( !empty($previous_element) ) {803 // Close off previous element.804 if ( !$to_depth || ($depth <= $to_depth) ) {805 if ( !empty($end_element_callback) ) {806 $cb_args = array_merge( array($output, $previous_element, $depth), $args);807 $output = call_user_func_array($end_element_callback, $cb_args);808 }809 }810 }811 812 // Start the element.813 if ( !$to_depth || ($depth <= $to_depth) ) {814 if ( !empty($start_element_callback) && ($element->$id_field != 0) ) {815 $cb_args = array_merge( array($output, $element, $depth), $args);816 $output = call_user_func_array($start_element_callback, $cb_args);817 }818 }819 820 $previous_element = $element;821 }822 823 return $output;824 }825 826 function walk_page_tree($pages, $to_depth, $start_element_callback, $end_element_callback = '', $start_level_callback = '', $end_level_callback = '') {827 $args = array('page', $pages, $to_depth, $start_element_callback, $end_element_callback, $start_level_callback, $end_level_callback);828 $extra_args = array_slice(func_get_args(), 6);829 830 return call_user_func_array('walk_tree', array_merge($args, $extra_args));831 }832 833 function walk_category_tree($pages, $to_depth, $start_element_callback, $end_element_callback = '', $start_level_callback = '', $end_level_callback = '') {834 $args = array('category', $pages, $to_depth, $start_element_callback, $end_element_callback, $start_level_callback, $end_level_callback);835 $extra_args = array_slice(func_get_args(), 6);836 return call_user_func_array('walk_tree', array_merge($args, $extra_args));837 715 } 838 716
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)