Changeset 2077 for trunk/bp-forums/bp-forums-templatetags.php
- Timestamp:
- 11/02/2009 07:54:21 PM (16 years ago)
- File:
-
- 1 edited
-
trunk/bp-forums/bp-forums-templatetags.php (modified) (61 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-forums/bp-forums-templatetags.php
r2012 r2077 6 6 var $topics; 7 7 var $topic; 8 8 9 9 var $in_the_loop; 10 10 11 11 var $pag_page; 12 12 var $pag_num; 13 13 var $pag_links; 14 14 var $total_topic_count; 15 15 16 16 var $single_topic = false; 17 17 18 18 var $sort_by; 19 19 var $order; 20 20 21 21 function BP_Forums_Template_Forum( $type, $forum_id, $per_page, $max, $no_stickies, $filter ) { 22 22 global $bp; … … 24 24 $this->pag_page = isset( $_REQUEST['p'] ) ? intval( $_REQUEST['p'] ) : 1; 25 25 $this->pag_num = isset( $_REQUEST['n'] ) ? intval( $_REQUEST['n'] ) : $per_page; 26 26 27 27 /* Only show stickies if we are viewing a single group forum, otherwise we could end up with hundreds globally */ 28 28 if ( $no_stickies ) … … 33 33 $this->topics = bp_forums_get_forum_topics( array( 'forum_id' => $forum_id, 'filter' => $filter, 'page' => $this->pag_page, 'per_page' => $this->pag_num, 'show_stickies' => $show_stickies ) ); 34 34 break; 35 35 36 36 case 'popular': 37 37 $this->topics = bp_forums_get_forum_topics( array( 'type' => 'popular', 'filter' => $filter, 'forum_id' => $forum_id, 'page' => $this->pag_page, 'per_page' => $this->pag_num, 'show_stickies' => $show_stickies ) ); 38 38 break; 39 39 40 40 case 'unreplied': 41 41 $this->topics = bp_forums_get_forum_topics( array( 'type' => 'unreplied', 'filter' => $filter, 'forum_id' => $forum_id, 'page' => $this->pag_page, 'per_page' => $this->pag_num, 'show_stickies' => $show_stickies ) ); 42 42 break; 43 43 44 44 case 'personal': 45 45 $this->topics = bp_forums_get_forum_topics( array( 'type' => 'personal', 'filter' => $filter, 'forum_id' => $forum_id, 'page' => $this->pag_page, 'per_page' => $this->pag_num, 'show_stickies' => $show_stickies ) ); 46 46 break; 47 47 48 48 case 'tag': 49 49 $this->topics = bp_forums_get_forum_topics( array( 'type' => 'tag', 'filter' => $filter, 'forum_id' => $forum_id, 'page' => $this->pag_page, 'per_page' => $this->pag_num, 'show_stickies' => $show_stickies ) ); 50 break; 50 break; 51 51 } 52 52 53 53 $this->topics = apply_filters( 'bp_forums_template_topics', $this->topics, $type, $forum_id, $per_page, $max, $no_stickies ); 54 54 55 55 if ( !(int)$this->topics ) { 56 56 $this->topic_count = 0; … … 63 63 $topic_count = (int)groups_total_public_forum_topic_count( $type ); 64 64 } else { 65 $topic_count = count( $this->topics ); 65 $topic_count = count( $this->topics ); 66 66 } 67 67 68 68 if ( !$max || $max >= $topic_count ) 69 69 $this->total_topic_count = $topic_count; … … 78 78 } else { 79 79 $this->topic_count = count( $this->topics ); 80 } 80 } 81 81 } 82 82 … … 90 90 $stickies[] = $topic; 91 91 else 92 $standard[] = $topic; 92 $standard[] = $topic; 93 93 } 94 94 $this->topics = array_merge( (array)$stickies, (array)$standard ); … … 105 105 )); 106 106 } 107 107 108 108 function has_topics() { 109 109 if ( $this->topic_count ) 110 110 return true; 111 111 112 112 return false; 113 113 } 114 114 115 115 function next_topic() { 116 116 $this->current_topic++; 117 117 $this->topic = $this->topics[$this->current_topic]; 118 118 119 119 return $this->topic; 120 120 } 121 121 122 122 function rewind_topics() { 123 123 $this->current_topic = -1; … … 126 126 } 127 127 } 128 129 function user_topics() { 128 129 function user_topics() { 130 130 if ( $this->current_topic + 1 < $this->topic_count ) { 131 131 return true; … … 139 139 return false; 140 140 } 141 141 142 142 function the_topic() { 143 143 global $topic; … … 146 146 $this->topic = $this->next_topic(); 147 147 $this->topic = (object)$this->topic; 148 148 149 149 if ( $this->current_topic == 0 ) // loop has just started 150 150 do_action('loop_start'); … … 154 154 function bp_has_forum_topics( $args = '' ) { 155 155 global $forum_template, $bp; 156 156 157 157 $defaults = array( 158 158 'type' => 'newest', … … 175 175 return false; 176 176 } 177 177 178 178 /* If we're viewing a tag in the directory, let's auto set the filter to the tag name */ 179 179 if ( $bp->is_directory && 'tag' == $type && !empty( $bp->action_variables[0] ) ) … … 183 183 if ( $bp->is_directory && !empty( $_GET['fs'] ) ) 184 184 $filter = $_GET['fs']; 185 185 186 186 $forum_template = new BP_Forums_Template_Forum( $type, $forum_id, $per_page, $max, $no_stickies, $filter ); 187 187 188 return apply_filters( 'bp_has_topics', $forum_template->has_topics(), &$forum_template ); 188 return apply_filters( 'bp_has_topics', $forum_template->has_topics(), &$forum_template ); 189 189 } 190 190 /* DEPRECATED use bp_has_forum_topics() */ … … 213 213 return apply_filters( 'bp_get_the_topic_id', $forum_template->topic->topic_id ); 214 214 } 215 215 216 216 function bp_the_topic_title() { 217 217 echo bp_get_the_topic_title(); … … 256 256 function bp_get_the_topic_poster_avatar( $args = '' ) { 257 257 global $forum_template; 258 258 259 259 $defaults = array( 260 260 'type' => 'thumb', … … 266 266 extract( $r, EXTR_SKIP ); 267 267 268 return apply_filters( 'bp_get_the_topic_poster_avatar', bp_core_fetch_avatar( array( 'item_id' => $forum_template->topic->topic_poster, 'type' => $type, 'width' => $width, 'height' => $height ) ) ); 268 return apply_filters( 'bp_get_the_topic_poster_avatar', bp_core_fetch_avatar( array( 'item_id' => $forum_template->topic->topic_poster, 'type' => $type, 'width' => $width, 'height' => $height ) ) ); 269 269 } 270 270 … … 277 277 return apply_filters( 'bp_get_the_topic_poster_name', bp_core_get_userlink( $forum_template->topic->topic_poster ) ); 278 278 } 279 279 280 280 function bp_the_topic_object_id() { 281 281 echo bp_get_the_topic_object_id(); … … 286 286 return apply_filters( 'bp_get_the_topic_object_id', $forum_template->topic->object_id ); 287 287 } 288 288 289 289 function bp_the_topic_object_name() { 290 290 echo bp_get_the_topic_object_name(); … … 295 295 return apply_filters( 'bp_get_the_topic_object_name', $forum_template->topic->object_name ); 296 296 } 297 297 298 298 function bp_the_topic_object_slug() { 299 299 echo bp_get_the_topic_object_slug(); … … 304 304 return apply_filters( 'bp_get_the_topic_object_slug', $forum_template->topic->object_slug ); 305 305 } 306 306 307 307 function bp_the_topic_object_permalink() { 308 308 echo bp_get_the_topic_object_permalink(); … … 310 310 function bp_get_the_topic_object_permalink() { 311 311 global $bp, $forum_template; 312 312 313 313 /* Currently this will only work with group forums, extended support in the future */ 314 314 return apply_filters( 'bp_get_the_topic_object_permalink', $bp->root_domain . '/' . BP_GROUPS_SLUG . '/' . $forum_template->topic->object_slug . '/forum/' ); 315 315 } 316 316 317 317 function bp_the_topic_last_poster_name() { 318 318 echo bp_get_the_topic_last_poster_name(); … … 323 323 return apply_filters( 'bp_get_the_topic_last_poster_name', bp_core_get_userlink( $forum_template->topic->topic_last_poster ) ); 324 324 } 325 325 326 326 function bp_the_topic_object_avatar( $args = '' ) { 327 327 echo bp_get_the_topic_object_avatar( $args ); … … 339 339 extract( $r, EXTR_SKIP ); 340 340 341 return apply_filters( 'bp_get_the_topic_object_avatar', bp_core_fetch_avatar( array( 'item_id' => $forum_template->topic->object_id, 'type' => $type, 'object' => 'group', 'width' => $width, 'height' => $height ) ) ); 342 } 343 341 return apply_filters( 'bp_get_the_topic_object_avatar', bp_core_fetch_avatar( array( 'item_id' => $forum_template->topic->object_id, 'type' => $type, 'object' => 'group', 'width' => $width, 'height' => $height ) ) ); 342 } 343 344 344 function bp_the_topic_last_poster_avatar( $args = '' ) { 345 345 echo bp_get_the_topic_last_poster_avatar( $args ); … … 357 357 extract( $r, EXTR_SKIP ); 358 358 359 return apply_filters( 'bp_get_the_topic_last_poster_avatar', bp_core_fetch_avatar( array( 'item_id' => $forum_template->topic->topic_last_poster, 'type' => $type, 'width' => $width, 'height' => $height ) ) ); 359 return apply_filters( 'bp_get_the_topic_last_poster_avatar', bp_core_fetch_avatar( array( 'item_id' => $forum_template->topic->topic_last_poster, 'type' => $type, 'width' => $width, 'height' => $height ) ) ); 360 360 } 361 361 … … 368 368 return apply_filters( 'bp_get_the_topic_start_time', $forum_template->topic->topic_start_time ); 369 369 } 370 370 371 371 function bp_the_topic_time() { 372 372 echo bp_get_the_topic_time(); … … 432 432 return apply_filters( 'bp_get_the_topic_total_post_count', sprintf( __( '%d post', 'buddypress' ), $forum_template->topic->topic_posts ) ); 433 433 else 434 return apply_filters( 'bp_get_the_topic_total_post_count', sprintf( __( '%d posts', 'buddypress' ), $forum_template->topic->topic_posts ) ); 435 } 436 434 return apply_filters( 'bp_get_the_topic_total_post_count', sprintf( __( '%d posts', 'buddypress' ), $forum_template->topic->topic_posts ) ); 435 } 436 437 437 function bp_the_topic_total_posts() { 438 438 echo bp_get_the_topic_total_posts(); … … 440 440 function bp_get_the_topic_total_posts() { 441 441 global $forum_template; 442 442 443 443 return $forum_template->topic->topic_posts; 444 444 } 445 445 446 446 function bp_the_topic_tag_count() { 447 447 echo bp_get_the_topic_tag_count(); … … 458 458 function bp_get_the_topic_permalink() { 459 459 global $forum_template, $bp; 460 460 461 461 if ( $forum_template->topic->object_slug ) 462 462 $permalink = $bp->root_domain . '/' . BP_GROUPS_SLUG . '/' . $forum_template->topic->object_slug . '/'; … … 465 465 else 466 466 $permalink = $bp->root_domain . '/' . $bp->current_component . '/' . $bp->current_action . '/'; 467 467 468 468 return apply_filters( 'bp_get_the_topic_permalink', $permalink . 'forum/topic/' . $forum_template->topic->topic_slug . '/' ); 469 469 } … … 477 477 return apply_filters( 'bp_get_the_topic_time_since_created', bp_core_time_since( strtotime( $forum_template->topic->topic_start_time ) ) ); 478 478 } 479 479 480 480 function bp_the_topic_latest_post_excerpt( $args = '' ) { 481 481 echo bp_get_the_topic_latest_post_excerpt( $args ); … … 498 498 function bp_the_topic_time_since_last_post( $deprecated = true ) { 499 499 global $forum_template; 500 500 501 501 if ( !$deprecated ) 502 502 return bp_get_the_topic_time_since_last_post(); … … 515 515 function bp_get_the_topic_is_mine() { 516 516 global $bp, $forum_template; 517 517 518 518 return $bp->loggedin_user->id == $forum_template->topic->topic_poster; 519 519 } … … 523 523 } 524 524 function bp_get_the_topic_admin_links( $args = '' ) { 525 global $bp, $forum_template; 526 525 global $bp, $forum_template; 526 527 527 $defaults = array( 528 528 'seperator' => '|' … … 533 533 534 534 $links[] = '<a href="' . wp_nonce_url( bp_get_the_topic_permalink() . 'edit', 'bp_forums_edit_topic' ) . '">' . __( 'Edit', 'buddypress' ) . '</a>'; 535 535 536 536 if ( $bp->is_item_admin || $bp->is_item_mod || is_site_admin() ) { 537 537 if ( 0 == (int)$forum_template->topic->topic_sticky ) … … 547 547 $links[] = '<a class="confirm" id="topic-delete-link" href="' . wp_nonce_url( bp_get_the_topic_permalink() . 'delete', 'bp_forums_delete_topic' ) . '">' . __( 'Delete', 'buddypress' ) . '</a>'; 548 548 } 549 549 550 550 return implode( ' ' . $seperator . ' ', (array) $links ); 551 551 } … … 557 557 function bp_get_the_topic_css_class() { 558 558 global $forum_template; 559 559 560 560 $class = false; 561 561 562 562 if ( $forum_template->current_topic % 2 == 1 ) 563 563 $class .= 'alt'; 564 564 565 565 if ( 1 == (int)$forum_template->topic->topic_sticky ) 566 566 $class .= ' sticky'; 567 567 568 568 if ( 0 == (int)$forum_template->topic->topic_open ) 569 569 $class .= ' closed'; 570 570 571 571 return trim( $class ); 572 572 } … … 577 577 function bp_get_my_forum_topics_link() { 578 578 global $bp; 579 579 580 580 return apply_filters( 'bp_get_my_forum_topics_link', $bp->root_domain . '/' . $bp->forums->slug . '/personal/' ); 581 581 } … … 586 586 function bp_get_unreplied_forum_topics_link() { 587 587 global $bp; 588 588 589 589 return apply_filters( 'bp_get_unreplied_forum_topics_link', $bp->root_domain . '/' . $bp->forums->slug . '/unreplied/' ); 590 590 } … … 596 596 function bp_get_popular_forum_topics_link() { 597 597 global $bp; 598 598 599 599 return apply_filters( 'bp_get_popular_forum_topics_link', $bp->root_domain . '/' . $bp->forums->slug . '/popular/' ); 600 600 } … … 605 605 function bp_get_newest_forum_topics_link() { 606 606 global $bp; 607 607 608 608 return apply_filters( 'bp_get_newest_forum_topics_link', $bp->root_domain . '/' . $bp->forums->slug . '/' ); 609 609 } … … 614 614 function bp_get_forum_topic_type() { 615 615 global $bp; 616 616 617 617 if ( !$bp->is_directory || !$bp->current_action ) 618 618 return 'newest'; 619 619 620 620 621 621 return apply_filters( 'bp_get_forum_topic_type', $bp->current_action ); 622 622 } 623 623 624 624 function bp_forums_tag_name() { 625 625 echo bp_get_forums_tag_name(); … … 627 627 function bp_get_forums_tag_name() { 628 628 global $bp; 629 629 630 630 if ( $bp->is_directory && $bp->forums->slug == $bp->current_component ) 631 return apply_filters( 'bp_get_forums_tag_name', $bp->action_variables[0] ); 631 return apply_filters( 'bp_get_forums_tag_name', $bp->action_variables[0] ); 632 632 } 633 633 … … 643 643 function bp_forum_pagination_count() { 644 644 global $bp, $forum_template; 645 645 646 646 $from_num = intval( ( $forum_template->pag_page - 1 ) * $forum_template->pag_num ) + 1; 647 $to_num = ( $from_num + ( $forum_template->pag_num - 1 ) > $forum_template->total_topic_count ) ? $forum_template->total_topic_count : $from_num + ( $forum_template->pag_num - 1 ); 648 647 $to_num = ( $from_num + ( $forum_template->pag_num - 1 ) > $forum_template->total_topic_count ) ? $forum_template->total_topic_count : $from_num + ( $forum_template->pag_num - 1 ); 648 649 649 echo apply_filters( 'bp_forum_pagination_count', sprintf( __( 'Viewing topic %d to %d (%d total topics)', 'buddypress' ), $from_num, $to_num, $forum_template->total_topic_count ) ); 650 650 ?> … … 655 655 function bp_is_edit_topic() { 656 656 global $bp; 657 657 658 658 if ( in_array( 'post', (array)$bp->action_variables ) && in_array( 'edit', (array)$bp->action_variables ) ) 659 659 return false; 660 660 661 661 return true; 662 662 } … … 668 668 var $posts; 669 669 var $post; 670 670 671 671 var $topic_id; 672 672 var $topic; 673 673 674 674 var $in_the_loop; 675 675 676 676 var $pag_page; 677 677 var $pag_num; 678 678 var $pag_links; 679 679 var $total_post_count; 680 680 681 681 var $single_post = false; 682 682 683 683 var $sort_by; 684 684 var $order; 685 685 686 686 function BP_Forums_Template_Topic( $topic_id, $per_page, $max ) { 687 687 global $bp, $current_user, $forum_template; 688 688 689 689 $this->pag_page = isset( $_REQUEST['topic_page'] ) ? intval( $_REQUEST['topic_page'] ) : 1; 690 690 $this->pag_num = isset( $_REQUEST['num'] ) ? intval( $_REQUEST['num'] ) : $per_page; 691 691 692 692 $this->topic_id = $topic_id; 693 693 $forum_template->topic = (object) bp_forums_get_topic_details( $this->topic_id ); 694 694 695 695 $this->posts = bp_forums_get_topic_posts( array( 'topic_id' => $this->topic_id, 'page' => $this->pag_page, 'per_page' => $this->pag_num ) ); 696 696 697 697 if ( !$this->posts ) { 698 698 $this->post_count = 0; … … 724 724 )); 725 725 } 726 726 727 727 function has_posts() { 728 728 if ( $this->post_count ) 729 729 return true; 730 730 731 731 return false; 732 732 } 733 733 734 734 function next_post() { 735 735 $this->current_post++; 736 736 $this->post = $this->posts[$this->current_post]; 737 737 738 738 return $this->post; 739 739 } 740 740 741 741 function rewind_posts() { 742 742 $this->current_post = -1; … … 745 745 } 746 746 } 747 748 function user_posts() { 747 748 function user_posts() { 749 749 if ( $this->current_post + 1 < $this->post_count ) { 750 750 return true; … … 758 758 return false; 759 759 } 760 760 761 761 function the_post() { 762 762 global $post; … … 765 765 $this->post = $this->next_post(); 766 766 $this->post = (object)$this->post; 767 767 768 768 if ( $this->current_post == 0 ) // loop has just started 769 769 do_action('loop_start'); … … 773 773 function bp_has_forum_topic_posts( $args = '' ) { 774 774 global $topic_template, $bp; 775 775 776 776 $defaults = array( 777 777 'topic_id' => false, … … 815 815 function bp_get_the_topic_post_id() { 816 816 global $topic_template; 817 817 818 818 return apply_filters( 'bp_get_the_topic_post_id', $topic_template->post->post_id ); 819 819 } … … 843 843 extract( $r, EXTR_SKIP ); 844 844 845 return apply_filters( 'bp_get_the_topic_post_poster_avatar', bp_core_fetch_avatar( array( 'item_id' => $topic_template->post->poster_id, 'type' => $type, 'width' => $width, 'height' => $height ) ) ); 845 return apply_filters( 'bp_get_the_topic_post_poster_avatar', bp_core_fetch_avatar( array( 'item_id' => $topic_template->post->poster_id, 'type' => $type, 'width' => $width, 'height' => $height ) ) ); 846 846 } 847 847 … … 855 855 global $topic_template; 856 856 857 return apply_filters( 'bp_get_the_topic_post_poster_name', bp_core_get_userlink( $topic_template->post->poster_id ) ); 857 return apply_filters( 'bp_get_the_topic_post_poster_name', bp_core_get_userlink( $topic_template->post->poster_id ) ); 858 858 } 859 859 … … 875 875 function bp_get_the_topic_post_is_mine() { 876 876 global $bp, $topic_template; 877 877 878 878 return $bp->loggedin_user->id == $topic_template->post->poster_id; 879 879 } … … 883 883 } 884 884 function bp_get_the_topic_post_admin_links( $args = '' ) { 885 global $topic_template; 886 885 global $topic_template; 886 887 887 /* Never show for the first post in a topic. */ 888 888 if ( 0 == $topic_template->current_post ) 889 889 return; 890 890 891 891 $defaults = array( 892 892 'seperator' => '|' … … 907 907 function bp_get_the_topic_post_edit_text() { 908 908 global $bp; 909 909 910 910 $post = bp_forums_get_post( $bp->action_variables[4] ); 911 911 return attribute_escape( $post->post_text ); … … 923 923 function bp_the_topic_pagination_count() { 924 924 global $bp, $topic_template; 925 925 926 926 $from_num = intval( ( $topic_template->pag_page - 1 ) * $topic_template->pag_num ) + 1; 927 $to_num = ( $from_num + ( $topic_template->pag_num - 1 ) > $topic_template->total_post_count ) ? $topic_template->total_post_count : $from_num + ( $topic_template->pag_num - 1 ); 928 927 $to_num = ( $from_num + ( $topic_template->pag_num - 1 ) > $topic_template->total_post_count ) ? $topic_template->total_post_count : $from_num + ( $topic_template->pag_num - 1 ); 928 929 929 echo apply_filters( 'bp_the_topic_pagination_count', sprintf( __( 'Viewing post %d to %d (%d total posts)', 'buddypress' ), $from_num, $to_num, $topic_template->total_post_count ) ); 930 930 ?> … … 947 947 function bp_get_forum_permalink() { 948 948 global $bp; 949 949 950 950 if ( $bp->is_single_item ) 951 951 $permalink = $bp->root_domain . '/' . $bp->current_component . '/' . $bp->current_item . '/'; … … 961 961 function bp_get_forum_directory_permalink() { 962 962 global $bp; 963 963 964 964 return apply_filters( 'bp_get_forum_directory_permalink', $bp->root_domain . '/' . $bp->forums->slug ); 965 965 } 966 966 967 function bp_forums_tag_heat_map( $args = '' ) { 967 function bp_forums_tag_heat_map( $args = '' ) { 968 968 $defaults = array( 969 969 'smallest' => '10', … … 985 985 global $topic_template; 986 986 987 return apply_filters( 'bp_get_forum_action', $bp->root_domain . attribute_escape( $_SERVER['REQUEST_URI'] ) ); 987 return apply_filters( 'bp_get_forum_action', $bp->root_domain . attribute_escape( $_SERVER['REQUEST_URI'] ) ); 988 988 } 989 989 … … 993 993 function bp_get_forum_topic_action() { 994 994 global $bp; 995 996 return apply_filters( 'bp_get_forum_topic_action', $bp->root_domain . attribute_escape( $_SERVER['REQUEST_URI'] ) ); 995 996 return apply_filters( 'bp_get_forum_topic_action', $bp->root_domain . attribute_escape( $_SERVER['REQUEST_URI'] ) ); 997 997 } 998 998
Note: See TracChangeset
for help on using the changeset viewer.