Changeset 3263 for trunk/bp-core/bp-core-classes.php
- Timestamp:
- 09/13/2010 03:04:20 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-core/bp-core-classes.php
r3232 r3263 497 497 } 498 498 499 /** 500 * BP_Button 501 * 502 * API to create BuddyPress buttons 503 * 504 * @package BuddyPress Core 505 * @since 1.2.6 506 */ 507 class BP_Button { 508 509 // Button properties 510 var $id; 511 var $component; 512 var $must_be_logged_in; 513 var $block_self; 514 515 // Wrapper div 516 var $wrapper_class; 517 var $wrapper_id; 518 519 // Button 520 var $link_href; 521 var $link_class; 522 var $link_id; 523 var $link_rel; 524 var $link_title; 525 var $link_text; 526 527 // HTML result 528 var $contents; 529 530 /** 531 * bp_button() 532 * 533 * Builds the button based on passed parameters: 534 * 535 * component: Which component this button is for 536 * must_be_logged_in: Button only appears for logged in users 537 * block_self: Button will not appear when viewing your own profile. 538 * wrapper_id: The DOM ID of the button wrapper 539 * wrapper_class: The DOM class of the button wrapper 540 * link_href: The destination link of the button 541 * link_title: Title of the button 542 * link_id: The DOM ID of the button 543 * link_class: The DOM class of the button 544 * link_rel: The DOM rel of the button 545 * link_text: The contents of the button 546 * 547 * @param array $args 548 * @return bool False if not allowed 549 */ 550 function bp_button( $args = '' ) { 551 552 $defaults = array( 553 'id' => '', 554 'component' => 'core', 555 'must_be_logged_in' => true, 556 'block_self' => true, 557 558 'wrapper_id' => '', 559 'wrapper_class' => '', 560 561 'link_href' => '', 562 'link_title' => '', 563 'link_id' => '', 564 'link_class' => '', 565 'link_rel' => '', 566 'link_text' => '', 567 ); 568 569 $r = wp_parse_args( $args, $defaults ); 570 extract( $r, EXTR_SKIP ); 571 572 // Required button properties 573 $this->id = $id; 574 $this->component = $component; 575 $this->must_be_logged_in = (bool)$must_be_logged_in; 576 $this->block_self = (bool)$block_self; 577 578 // $id and $component are required 579 if ( empty( $id ) || empty( $component ) ) 580 return false; 581 582 // No button if component is not active 583 if ( !bp_is_active( $this->component ) ) 584 return false; 585 586 // No button for guests if must be logged in 587 if ( true == $this->must_be_logged_in && !is_user_logged_in ) 588 return false; 589 590 // No button if viewing your own profile 591 if ( true == $this->block_self && bp_is_my_profile() ) 592 return false; 593 594 // Wrapper properties 595 if ( !empty( $wrapper_id ) ) 596 $this->wrapper_id = ' id="' . $wrapper_id . '"'; 597 598 if ( !empty( $wrapper_class ) ) 599 $this->wrapper_class = ' class="generic-button ' . $wrapper_class . '"'; 600 else 601 $this->wrapper_class = ' class="generic-button"'; 602 603 // Link properties 604 if ( !empty( $link_id ) ) 605 $this->link_id = ' id="' . $link_id . '"'; 606 607 if ( !empty( $link_href ) ) 608 $this->link_href = ' href="' . $link_href . '"'; 609 610 if ( !empty( $link_title ) ) 611 $this->link_title = ' title="' . $link_title . '"'; 612 613 if ( !empty( $link_rel ) ) 614 $this->link_rel = ' rel="' . $link_rel . '"'; 615 616 if ( !empty( $link_class ) ) 617 $this->link_class = ' class="' . $link_class . '"'; 618 619 if ( !empty( $link_text ) ) 620 $this->link_text = $link_text; 621 622 // Build the button 623 $this->contents = '<div' . $this->wrapper_class . $this->wrapper_id . '>'; 624 $this->contents .= '<a'. $this->link_href . $this->link_title . $this->link_id . $this->link_rel . $this->link_class . '>' . $this->link_text . '</a>'; 625 $this->contents .= '</div>'; 626 627 // Allow button to be manipulated externally 628 $this->contents = apply_filters( 'bp_button_' . $component . '_' . $id, $this->contents, $this ); 629 } 630 631 /** 632 * contents() 633 * 634 * Return contents of button 635 * 636 * @return string 637 */ 638 function contents() { 639 return $this->contents; 640 } 641 642 /** 643 * display() 644 * 645 * Output contents of button 646 */ 647 function display() { 648 if ( !empty( $this->contents ) ) 649 echo $this->contents; 650 } 651 } 499 652 500 653 ?>
Note: See TracChangeset
for help on using the changeset viewer.