Changeset 1858 for trunk/bp-forums/bp-forums-templatetags.php
- Timestamp:
- 09/11/2009 11:59:16 PM (17 years ago)
- File:
-
- 1 edited
-
trunk/bp-forums/bp-forums-templatetags.php (modified) (18 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-forums/bp-forums-templatetags.php
r1844 r1858 19 19 var $order; 20 20 21 function BP_Forums_Template_Forum( $forum_id, $per_page, $max, $no_stickies ) { 22 global $bp; 23 24 $this->pag_page = isset( $_REQUEST['forum_page'] ) ? intval( $_REQUEST['forum_page'] ) : 1; 25 $this->pag_num = isset( $_REQUEST['num'] ) ? intval( $_REQUEST['num'] ) : $per_page; 26 27 $this->topics = bp_forums_get_forum_topics( array( 'forum_id' => $forum_id, 'page' => $this->pag_page, 'per_page' => $this->pag_num ) ); 28 21 function BP_Forums_Template_Forum( $type, $forum_id, $per_page, $max, $no_stickies, $filter ) { 22 global $bp; 23 24 $this->pag_page = isset( $_REQUEST['p'] ) ? intval( $_REQUEST['p'] ) : 1; 25 $this->pag_num = isset( $_REQUEST['n'] ) ? intval( $_REQUEST['n'] ) : $per_page; 26 27 /* Only show stickies if we are viewing a single group forum, otherwise we could end up with hundreds globally */ 28 if ( !$forum_id ) 29 $show_stickies = 'no'; // bbPress needs str 'no' 30 31 switch ( $type ) { 32 case 'newest': default: 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 break; 35 36 case 'popular': 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 break; 39 40 case 'unreplied': 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 break; 43 44 case 'personal': 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 break; 47 48 case 'tag': 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; 51 } 52 53 $this->topics = apply_filters( 'bp_forums_template_topics', $this->topics, $type, $forum_id, $per_page, $max, $no_stickies ); 54 29 55 if ( !(int)$this->topics ) { 30 56 $this->topic_count = 0; 31 57 $this->total_topic_count = 0; 32 58 } else { 33 $topic_count = bp_forums_get_forum( $forum_id ); 34 $topic_count = (int)$topic_count->topics; 59 if ( $forum_id ) { 60 $topic_count = bp_forums_get_forum( $forum_id ); 61 $topic_count = (int)$topic_count->topics; 62 } else if ( function_exists( 'groups_total_public_forum_topic_count' ) ) { 63 $topic_count = (int)groups_total_public_forum_topic_count( $type ); 64 } else { 65 $topic_count = count( $this->topics ); 66 } 35 67 36 68 if ( !$max || $max >= $topic_count ) … … 48 80 } 49 81 } 50 82 83 $this->topic_count = apply_filters( 'bp_forums_template_topic_count', $this->topic_count, &$topics, $type, $forum_id, $per_page, $max, $no_stickies ); 84 $this->total_topic_count = apply_filters( 'bp_forums_template_total_topic_count', $this->total_topic_count, $this->topic_count, &$topics, $type, $forum_id, $per_page, $max, $no_stickies ); 85 51 86 if ( !$no_stickies) { 52 87 /* Place stickies at the top - not sure why bbPress doesn't do this? */ … … 61 96 62 97 $this->pag_links = paginate_links( array( 63 'base' => add_query_arg( array( ' forum_page' => '%#%', 'num' => $this->pag_num ) ),98 'base' => add_query_arg( array( 'p' => '%#%', 'n' => $this->pag_num ) ), 64 99 'format' => '', 65 100 'total' => ceil($this->total_topic_count / $this->pag_num), … … 117 152 } 118 153 119 function bp_has_ topics( $args = '' ) {154 function bp_has_forum_topics( $args = '' ) { 120 155 global $forum_template, $bp; 121 156 122 157 $defaults = array( 158 'type' => 'newest', 123 159 'forum_id' => false, 124 160 'per_page' => 15, 125 161 'max' => false, 126 'no_stickies' => false 162 'no_stickies' => false, 163 'filter' => false 127 164 ); 128 165 … … 130 167 extract( $r, EXTR_SKIP ); 131 168 132 if ( !$forum_id && $bp->current_component == $bp->groups->slug ) 169 /* If we're in a single group, set this group's forum_id */ 170 if ( !$forum_id && $bp->groups->current_group ) { 133 171 $forum_id = groups_get_groupmeta( $bp->groups->current_group->id, 'forum_id' ); 134 135 if ( is_numeric( $forum_id ) ) 136 $forum_template = new BP_Forums_Template_Forum( (int)$forum_id, $per_page, $max, $no_stickies ); 137 else 138 return false; 139 140 return apply_filters( 'bp_has_topics', $forum_template->has_topics(), &$forum_template ); 141 } 142 143 function bp_topics() { 172 173 /* If it turns out there is no forum for this group, return false so we don't fetch all global topics */ 174 if ( !$forum_id ) 175 return false; 176 } 177 178 /* If we're viewing a tag in the directory, let's auto set the filter to the tag name */ 179 if ( $bp->is_directory && 'tag' == $type && !empty( $bp->action_variables[0] ) ) 180 $filter = $bp->action_variables[0]; 181 182 /* If $_GET['s'] is set, let's auto populate the filter var */ 183 if ( $bp->is_directory && !empty( $_GET['s'] ) ) 184 $filter = $_GET['s']; 185 186 $forum_template = new BP_Forums_Template_Forum( $type, $forum_id, $per_page, $max, $no_stickies, $filter ); 187 188 return apply_filters( 'bp_has_topics', $forum_template->has_topics(), &$forum_template ); 189 } 190 /* DEPRECATED use bp_has_forum_topics() */ 191 function bp_has_topics( $args = '' ) { return bp_has_forum_topics( $args ); } 192 193 function bp_forum_topics() { 144 194 global $forum_template; 145 195 return $forum_template->user_topics(); 146 196 } 147 148 function bp_the_topic() { 197 /* DEPRECATED use bp_has_forum_topics() */ 198 function bp_topics() { return bp_forum_topics(); } 199 200 function bp_the_forum_topic() { 149 201 global $forum_template; 150 202 return $forum_template->the_topic(); 151 203 } 204 /* DEPRECATED use bp_the_forum_topic() */ 205 function bp_the_topic() { return bp_the_forum_topic(); } 152 206 153 207 function bp_the_topic_id() { … … 224 278 } 225 279 280 function bp_the_topic_object_id() { 281 echo bp_get_the_topic_object_id(); 282 } 283 function bp_get_the_topic_object_id() { 284 global $forum_template; 285 286 return apply_filters( 'bp_get_the_topic_object_id', $forum_template->topic->object_id ); 287 } 288 289 function bp_the_topic_object_name() { 290 echo bp_get_the_topic_object_name(); 291 } 292 function bp_get_the_topic_object_name() { 293 global $forum_template; 294 295 return apply_filters( 'bp_get_the_topic_object_name', $forum_template->topic->object_name ); 296 } 297 298 function bp_the_topic_object_slug() { 299 echo bp_get_the_topic_object_slug(); 300 } 301 function bp_get_the_topic_object_slug() { 302 global $forum_template; 303 304 return apply_filters( 'bp_get_the_topic_object_slug', $forum_template->topic->object_slug ); 305 } 306 307 function bp_the_topic_object_permalink() { 308 echo bp_get_the_topic_object_permalink(); 309 } 310 function bp_get_the_topic_object_permalink() { 311 global $forum_template; 312 313 /* Currently this will only work with group forums, extended support in the future */ 314 return apply_filters( 'bp_get_the_topic_object_permalink', $bp->root_domain . '/' . BP_GROUPS_SLUG . '/' . $forum_template->topic->object_slug . '/' ); 315 } 316 226 317 function bp_the_topic_last_poster_name() { 227 318 echo bp_get_the_topic_last_poster_name(); … … 233 324 } 234 325 235 function bp_the_topic_ last_poster_avatar( $args = '' ) {236 echo bp_get_the_topic_ last_poster_avatar( $args );237 } 238 function bp_get_the_topic_ last_poster_avatar( $args = '' ) {326 function bp_the_topic_object_avatar( $args = '' ) { 327 echo bp_get_the_topic_object_avatar( $args ); 328 } 329 function bp_get_the_topic_object_avatar( $args = '' ) { 239 330 global $forum_template; 240 331 … … 248 339 extract( $r, EXTR_SKIP ); 249 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 344 function bp_the_topic_last_poster_avatar( $args = '' ) { 345 echo bp_get_the_topic_last_poster_avatar( $args ); 346 } 347 function bp_get_the_topic_last_poster_avatar( $args = '' ) { 348 global $forum_template; 349 350 $defaults = array( 351 'type' => 'thumb', 352 'width' => false, 353 'height' => false, 354 ); 355 356 $r = wp_parse_args( $args, $defaults ); 357 extract( $r, EXTR_SKIP ); 358 250 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 ) ) ); 251 360 } … … 325 434 return apply_filters( 'bp_get_the_topic_total_post_count', sprintf( __( '%d posts', 'buddypress' ), $forum_template->topic->topic_posts ) ); 326 435 } 327 436 437 function bp_the_topic_total_posts() { 438 echo bp_get_the_topic_total_posts(); 439 } 440 function bp_get_the_topic_total_posts() { 441 global $forum_template; 442 443 return $forum_template->topic->topic_posts; 444 } 445 328 446 function bp_the_topic_tag_count() { 329 447 echo bp_get_the_topic_tag_count(); … … 341 459 global $forum_template, $bp; 342 460 343 if ( $bp->is_single_item ) 461 if ( $forum_template->topic->object_slug ) 462 $permalink = $bp->root_domain . '/' . BP_GROUPS_SLUG . '/' . $forum_template->topic->object_slug . '/'; 463 else if ( $bp->is_single_item ) 344 464 $permalink = $bp->root_domain . '/' . $bp->current_component . '/' . $bp->current_item . '/'; 345 465 else 346 $permalink = $bp->root_domain . $bp->current_component . '/' . $bp->current_action . '/';466 $permalink = $bp->root_domain . '/' . $bp->current_component . '/' . $bp->current_action . '/'; 347 467 348 return apply_filters( 'bp_get_the_topic_permalink', $permalink . 'forum/topic/' . $forum_template->topic->topic_slug );468 return apply_filters( 'bp_get_the_topic_permalink', $permalink . 'forum/topic/' . $forum_template->topic->topic_slug . '/' ); 349 469 } 350 470 … … 403 523 extract( $r, EXTR_SKIP ); 404 524 405 $links = '<a href="' . wp_nonce_url( bp_get_the_topic_permalink() . ' /edit', 'bp_forums_edit_topic' ) . '">' . __( 'Edit', 'buddypress' ) . '</a> ' . $seperator . ' ';525 $links = '<a href="' . wp_nonce_url( bp_get_the_topic_permalink() . 'edit', 'bp_forums_edit_topic' ) . '">' . __( 'Edit', 'buddypress' ) . '</a> ' . $seperator . ' '; 406 526 407 527 if ( 0 == (int)$forum_template->topic->topic_sticky ) 408 $links .= '<a href="' . wp_nonce_url( bp_get_the_topic_permalink() . ' /stick', 'bp_forums_stick_topic' ) . '">' . __( 'Sticky', 'buddypress' ) . '</a> ' . $seperator . ' ';528 $links .= '<a href="' . wp_nonce_url( bp_get_the_topic_permalink() . 'stick', 'bp_forums_stick_topic' ) . '">' . __( 'Sticky', 'buddypress' ) . '</a> ' . $seperator . ' '; 409 529 else 410 $links .= '<a href="' . wp_nonce_url( bp_get_the_topic_permalink() . ' /unstick', 'bp_forums_unstick_topic' ) . '">' . __( 'Un-stick', 'buddypress' ) . '</a> ' . $seperator . ' ';530 $links .= '<a href="' . wp_nonce_url( bp_get_the_topic_permalink() . 'unstick', 'bp_forums_unstick_topic' ) . '">' . __( 'Un-stick', 'buddypress' ) . '</a> ' . $seperator . ' '; 411 531 412 532 if ( 0 == (int)$forum_template->topic->topic_open ) 413 $links .= '<a href="' . wp_nonce_url( bp_get_the_topic_permalink() . ' /open', 'bp_forums_open_topic' ) . '">' . __( 'Open', 'buddypress' ) . '</a> ' . $seperator . ' ';533 $links .= '<a href="' . wp_nonce_url( bp_get_the_topic_permalink() . 'open', 'bp_forums_open_topic' ) . '">' . __( 'Open', 'buddypress' ) . '</a> ' . $seperator . ' '; 414 534 else 415 $links .= '<a href="' . wp_nonce_url( bp_get_the_topic_permalink() . ' /close', 'bp_forums_close_topic' ) . '">' . __( 'Close', 'buddypress' ) . '</a> ' . $seperator . ' ';416 417 $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>';535 $links .= '<a href="' . wp_nonce_url( bp_get_the_topic_permalink() . 'close', 'bp_forums_close_topic' ) . '">' . __( 'Close', 'buddypress' ) . '</a> ' . $seperator . ' '; 536 537 $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>'; 418 538 419 539 return $links; … … 429 549 $class = false; 430 550 431 if ( 1 == (int)$forum_template->topic->topic_sticky ) { 432 $class .= 'sticky'; 433 } 434 435 if ( 0 == (int)$forum_template->topic->topic_open ) { 551 if ( $forum_template->current_topic % 2 == 1 ) 552 $class .= 'alt'; 553 554 if ( 1 == (int)$forum_template->topic->topic_sticky ) 555 $class .= ' sticky'; 556 557 if ( 0 == (int)$forum_template->topic->topic_open ) 436 558 $class .= ' closed'; 437 }438 559 439 560 return trim( $class ); 440 561 } 441 562 563 function bp_my_forum_topics_link() { 564 echo bp_get_my_forum_topics_link(); 565 } 566 function bp_get_my_forum_topics_link() { 567 global $bp; 568 569 return apply_filters( 'bp_get_my_forum_topics_link', $bp->root_domain . '/' . $bp->forums->slug . '/personal/' ); 570 } 571 572 function bp_unreplied_forum_topics_link() { 573 echo bp_get_unreplied_forum_topics_link(); 574 } 575 function bp_get_unreplied_forum_topics_link() { 576 global $bp; 577 578 return apply_filters( 'bp_get_unreplied_forum_topics_link', $bp->root_domain . '/' . $bp->forums->slug . '/unreplied/' ); 579 } 580 581 582 function bp_popular_forum_topics_link() { 583 echo bp_get_popular_forum_topics_link(); 584 } 585 function bp_get_popular_forum_topics_link() { 586 global $bp; 587 588 return apply_filters( 'bp_get_popular_forum_topics_link', $bp->root_domain . '/' . $bp->forums->slug . '/popular/' ); 589 } 590 591 function bp_newest_forum_topics_link() { 592 echo bp_get_newest_forum_topics_link(); 593 } 594 function bp_get_newest_forum_topics_link() { 595 global $bp; 596 597 return apply_filters( 'bp_get_newest_forum_topics_link', $bp->root_domain . '/' . $bp->forums->slug . '/' ); 598 } 599 600 function bp_forum_topic_type() { 601 echo bp_get_forum_topic_type(); 602 } 603 function bp_get_forum_topic_type() { 604 global $bp; 605 606 if ( !$bp->is_directory || !$bp->current_action ) 607 return 'newest'; 608 609 610 return apply_filters( 'bp_get_forum_topic_type', $bp->current_action ); 611 } 612 613 function bp_forums_tag_name() { 614 echo bp_get_forums_tag_name(); 615 } 616 function bp_get_forums_tag_name() { 617 global $bp; 618 619 if ( $bp->is_directory && $bp->forums->slug == $bp->current_component ) 620 return apply_filters( 'bp_get_forums_tag_name', $bp->action_variables[0] ); 621 } 442 622 443 623 function bp_forum_pagination() { … … 580 760 } 581 761 582 function bp_has_ topic_posts( $args = '' ) {762 function bp_has_forum_topic_posts( $args = '' ) { 583 763 global $topic_template, $bp; 584 764 … … 602 782 return apply_filters( 'bp_has_topic_posts', $topic_template->has_posts(), &$topic_template ); 603 783 } 604 605 function bp_topic_posts() { 784 /* DEPRECATED use bp_has_forum_topic_posts() */ 785 function bp_has_topic_posts() { return bp_has_forum_topic_posts( $args ); } 786 787 function bp_forum_topic_posts() { 606 788 global $topic_template; 607 789 return $topic_template->user_posts(); 608 790 } 609 610 function bp_the_topic_post() { 791 /* DEPRECATED use bp_forum_topic_posts() */ 792 function bp_topic_posts() { return bp_forum_topic_posts(); } 793 794 function bp_the_forum_topic_post() { 611 795 global $topic_template; 612 796 return $topic_template->the_post(); 613 797 } 798 /* DEPRECATED use bp_the_forum_topic_post() */ 799 function bp_the_topic_post() { return bp_the_forum_topic_post(); } 614 800 615 801 function bp_the_topic_post_id() { … … 695 881 extract( $r, EXTR_SKIP ); 696 882 697 $links = '<a href="' . wp_nonce_url( bp_get_the_topic_permalink() . $topic_template->post->id . ' /post/' . $topic_template->post->post_id . '/edit/', 'bp_forums_edit_post' ) . '">' . __( 'Edit', 'buddypress' ) . '</a> ' . $seperator . ' ';698 $links .= '<a class="confirm" id="post-delete-link" href="' . wp_nonce_url( bp_get_the_topic_permalink() . ' /post/' . $topic_template->post->post_id . '/delete/', 'bp_forums_delete_post' ) . '">' . __( 'Delete', 'buddypress' ) . '</a>';883 $links = '<a href="' . wp_nonce_url( bp_get_the_topic_permalink() . $topic_template->post->id . 'edit/post/' . $topic_template->post->post_id, 'bp_forums_edit_post' ) . '">' . __( 'Edit', 'buddypress' ) . '</a> ' . $seperator . ' '; 884 $links .= '<a class="confirm" id="post-delete-link" href="' . wp_nonce_url( bp_get_the_topic_permalink() . 'delete/post/' . $topic_template->post->post_id, 'bp_forums_delete_post' ) . '">' . __( 'Delete', 'buddypress' ) . '</a>'; 699 885 700 886 return $links; … … 707 893 global $bp; 708 894 709 $post = bp_forums_get_post( $bp->action_variables[ 3] );895 $post = bp_forums_get_post( $bp->action_variables[4] ); 710 896 return attribute_escape( $post->post_text ); 711 897 } … … 732 918 } 733 919 920 function bp_directory_forums_search_form() { 921 global $bp; ?> 922 <form action="<?php echo $bp->root_domain . '/' . $bp->forums->slug . '/'; ?>" method="get" id="search-forums-form"> 923 <label><input type="text" name="s" id="forums_search" value="<?php if ( isset( $_GET['s'] ) ) { echo attribute_escape( $_GET['s'] ); } else { _e( 'Search anything...', 'buddypress' ); } ?>" onfocus="if (this.value == '<?php _e( 'Search anything...', 'buddypress' ) ?>') {this.value = '';}" onblur="if (this.value == '') {this.value = '<?php _e( 'Search anything...', 'buddypress' ) ?>';}" /></label> 924 <input type="submit" id="forums_search_submit" name="submit" value="<?php _e( 'Search', 'buddypress' ) ?>" /> 925 </form> 926 <?php 927 } 928 734 929 function bp_forum_permalink() { 735 930 echo bp_get_forum_permalink(); … … 746 941 } 747 942 943 function bp_forum_directory_permalink() { 944 echo bp_get_forum_directory_permalink(); 945 } 946 function bp_get_forum_directory_permalink() { 947 global $bp; 948 949 return apply_filters( 'bp_get_forum_directory_permalink', $bp->root_domain . '/' . $bp->forums->slug ); 950 } 951 952 function bp_forums_tag_heat_map( $args = '' ) { 953 $defaults = array( 954 'smallest' => '10', 955 'largest' => '42', 956 'sizing' => 'px', 957 'limit' => '50' 958 ); 959 960 $r = wp_parse_args( $args, $defaults ); 961 extract( $r, EXTR_SKIP ); 962 963 bb_tag_heat_map( $smallest, $largest, $sizing, $limit ); 964 } 965 748 966 function bp_forum_action() { 749 967 echo bp_get_forum_action();
Note: See TracChangeset
for help on using the changeset viewer.