Changeset 6726 for trunk/wp-includes/classes.php
- Timestamp:
- 02/05/2008 06:47:27 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/classes.php
r6711 r6726 387 387 } 388 388 389 /* 390 * A class for displaying various tree-like structures. 389 /* 390 * A class for displaying various tree-like structures. 391 391 * Extend the Walker class to use it, see examples at the bottom 392 392 */ … … 406 406 */ 407 407 function display_element( $element, &$children_elements, $max_depth, $depth=0, $args, $output ) { 408 408 409 409 if ( !$element) 410 return $output; 411 410 return $output; 411 412 412 if ( $max_depth != 0 ) { 413 413 if ($depth >= $max_depth) 414 return $output; 415 } 416 414 return $output; 415 } 416 417 417 $id_field = $this->db_fields['id']; 418 418 $parent_field = $this->db_fields['parent']; 419 419 420 420 if ($depth > 0) { 421 421 //start the child delimiter 422 422 $cb_args = array_merge( array($output, $depth), $args); 423 423 $output = call_user_func_array(array(&$this, 'start_lvl'), $cb_args); 424 } 425 424 } 425 426 426 //display this element 427 427 $cb_args = array_merge( array($output, $element, $depth), $args); … … 429 429 430 430 for ( $i = 0; $i < sizeof( $children_elements ); $i++ ) { 431 431 432 432 $child = $children_elements[$i]; 433 433 if ( $child->$parent_field == $element->$id_field ) { 434 434 435 435 array_splice( $children_elements, $i, 1 ); 436 436 $output = $this->display_element( $child, $children_elements, $max_depth, $depth + 1, $args, $output ); 437 $i = -1; 437 $i = -1; 438 438 } 439 439 } 440 440 441 441 //end this element 442 442 $cb_args = array_merge( array($output, $element, $depth), $args); 443 443 $output = call_user_func_array(array(&$this, 'end_el'), $cb_args); 444 444 445 445 if ($depth > 0) { 446 446 //end the child delimiter … … 448 448 $output = call_user_func_array(array(&$this, 'end_lvl'), $cb_args); 449 449 } 450 451 return $output; 450 451 return $output; 452 452 } 453 453 … … 455 455 * displays array of elements hierarchically 456 456 * it is a generic function which does not assume any existing order of elements 457 * max_depth = -1 means flatly display every element 458 * max_depth = 0 means display all levels 459 * max_depth > 0 specifies the number of display levels. 457 * max_depth = -1 means flatly display every element 458 * max_depth = 0 means display all levels 459 * max_depth > 0 specifies the number of display levels. 460 460 */ 461 461 function walk( $elements, $max_depth) { 462 462 463 463 $args = array_slice(func_get_args(), 2); 464 464 $output = ''; 465 465 466 466 if ($max_depth < -1) //invalid parameter 467 return $output; 468 467 return $output; 468 469 469 if (empty($elements)) //nothing to walk 470 return $output; 471 470 return $output; 471 472 472 $id_field = $this->db_fields['id']; 473 473 $parent_field = $this->db_fields['parent']; 474 474 475 475 // flat display 476 476 if ( -1 == $max_depth ) { 477 $empty_array = array(); 478 foreach ( $elements as $e ) 477 $empty_array = array(); 478 foreach ( $elements as $e ) 479 479 $output = $this->display_element( $e, $empty_array, 1, 0, $args, $output ); 480 return $output; 481 } 482 483 /* 484 * need to display in hierarchical order 480 return $output; 481 } 482 483 /* 484 * need to display in hierarchical order 485 485 * splice elements into two buckets: those without parent and those with parent 486 486 */ … … 489 489 foreach ( $elements as $e) { 490 490 if ( 0 == $e->$parent_field ) 491 $top_level_elements[] = $e; 491 $top_level_elements[] = $e; 492 492 else 493 $children_elements[] = $e; 494 } 495 496 /* 493 $children_elements[] = $e; 494 } 495 496 /* 497 497 * none of the elements is top level 498 498 * the first one must be root of the sub elements 499 499 */ 500 500 if ( !$top_level_elements ) { 501 501 502 502 $root = $children_elements[0]; 503 503 for ( $i = 0; $i < sizeof( $children_elements ); $i++ ) { 504 504 505 505 $child = $children_elements[$i]; 506 506 if ($root->$parent_field == $child->$parent_field ) 507 $top_level_elements[] = $child; 507 $top_level_elements[] = $child; 508 508 array_splice( $children_elements, $i, 1 ); 509 $i--; 509 $i--; 510 510 } 511 511 } 512 512 513 513 foreach ( $top_level_elements as $e ) 514 514 $output = $this->display_element( $e, $children_elements, $max_depth, 0, $args, $output ); 515 516 /* 517 * if we are displaying all levels, and remaining children_elements is not empty, 515 516 /* 517 * if we are displaying all levels, and remaining children_elements is not empty, 518 518 * then we got orphans, which should be displayed regardless 519 519 */ 520 520 if ( ( $max_depth == 0 ) && sizeof( $children_elements ) > 0 ) { 521 $empty_array = array(); 521 $empty_array = array(); 522 522 foreach ( $children_elements as $orphan_e ) 523 523 $output = $this->display_element( $orphan_e, $empty_array, 1, 0, $args, $output ); … … 548 548 else 549 549 $indent = ''; 550 550 551 551 extract($args, EXTR_SKIP); 552 552 $css_class = 'page_item page-item-'.$page->ID; … … 750 750 $response = ''; 751 751 if ( is_wp_error($data) ) { 752 foreach ( $data->get_error_codes() as $code ) { 752 foreach ( $data->get_error_codes() as $code ) { 753 753 $response .= "<wp_error code='$code'><![CDATA[" . $data->get_error_message($code) . "]]></wp_error>"; 754 754 if ( !$error_data = $data->get_error_data($code) )
Note: See TracChangeset
for help on using the changeset viewer.