Changeset 1621 for trunk/bp-forums/bp-forums-templatetags.php
- Timestamp:
- 07/21/2009 09:45:28 PM (15 years ago)
- Location:
- trunk/bp-forums
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-forums
- Property svn:externals set to
-
trunk/bp-forums/bp-forums-templatetags.php
r1538 r1621 19 19 var $order; 20 20 21 function BP_Forums_Template_Forum( $forum_id, $per_page, $max ) {22 global $bp , $current_user;21 function BP_Forums_Template_Forum( $forum_id, $per_page, $max, $no_stickies ) { 22 global $bp; 23 23 24 24 $this->pag_page = isset( $_REQUEST['forum_page'] ) ? intval( $_REQUEST['forum_page'] ) : 1; 25 25 $this->pag_num = isset( $_REQUEST['num'] ) ? intval( $_REQUEST['num'] ) : $per_page; 26 26 27 $this->topics = bp_forums_get_ topics( $forum_id, $this->pag_num, $this->pag_page);28 29 if ( ! $this->topics ) {27 $this->topics = bp_forums_get_forum_topics( array( 'forum_id' => $forum_id, 'page' => $this->pag_page, 'per_page' => $this->pag_num ) ); 28 29 if ( !(int)$this->topics ) { 30 30 $this->topic_count = 0; 31 31 $this->total_topic_count = 0; 32 32 } else { 33 $forum_count = count( bp_forums_get_topics( $forum_id ) ); 33 $topic_count = bp_forums_get_forum( $forum_id ); 34 $topic_count = (int)$topic_count->topics; 34 35 35 if ( !$max || $max >= $ forum_count )36 $this->total_topic_count = $ forum_count;36 if ( !$max || $max >= $topic_count ) 37 $this->total_topic_count = $topic_count; 37 38 else 38 39 $this->total_topic_count = (int)$max; … … 46 47 $this->topic_count = count( $this->topics ); 47 48 } 49 } 50 51 if ( !$no_stickies) { 52 /* Place stickies at the top - not sure why bbPress doesn't do this? */ 53 foreach( (array)$this->topics as $topic ) { 54 if ( 1 == (int)$topic->topic_sticky ) 55 $stickies[] = $topic; 56 else 57 $standard[] = $topic; 58 } 59 $this->topics = array_merge( (array)$stickies, (array)$standard ); 48 60 } 49 61 … … 107 119 function bp_has_topics( $args = '' ) { 108 120 global $forum_template, $bp; 109 global $group_obj;110 121 111 122 $defaults = array( 112 123 'forum_id' => false, 113 'per_page' => 10, 114 'max' => false 124 'per_page' => 15, 125 'max' => false, 126 'no_stickies' => false 115 127 ); 116 128 … … 118 130 extract( $r, EXTR_SKIP ); 119 131 120 if ( !$forum_id && $bp->current_component == $bp->groups->slug && 'forum' == $bp->current_action)121 $forum_id = groups_get_groupmeta( $ group_obj->id, 'forum_id' );132 if ( !$forum_id && $bp->current_component == $bp->groups->slug ) 133 $forum_id = groups_get_groupmeta( $bp->groups->current_group->id, 'forum_id' ); 122 134 123 135 if ( is_numeric( $forum_id ) ) 124 $forum_template = new BP_Forums_Template_Forum( $forum_id, $per_page, $max);136 $forum_template = new BP_Forums_Template_Forum( (int)$forum_id, $per_page, $max, $no_stickies ); 125 137 else 126 138 return false; … … 166 178 } 167 179 180 function bp_the_topic_text() { 181 echo bp_get_the_topic_text(); 182 } 183 function bp_get_the_topic_text() { 184 global $forum_template; 185 186 $post = bb_get_first_post( $forum_template->topic->topic_id ); 187 return apply_filters( 'bp_get_the_topic_text', $post->post_text ); 188 } 189 168 190 function bp_the_topic_poster_id() { 169 191 echo bp_get_the_topic_poster_id(); … … 175 197 } 176 198 177 function bp_the_topic_poster_avatar() { 178 echo bp_get_the_topic_poster_avatar(); 179 } 180 function bp_get_the_topic_poster_avatar() { 181 global $forum_template; 182 183 return apply_filters( 'bp_get_the_topic_poster_avatar', bp_core_get_avatar( $forum_template->topic->topic_poster, 1 ) ); 199 function bp_the_topic_poster_avatar( $args = '' ) { 200 echo bp_get_the_topic_poster_avatar( $args ); 201 } 202 function bp_get_the_topic_poster_avatar( $args = '' ) { 203 global $forum_template; 204 205 $defaults = array( 206 'type' => 'thumb', 207 'width' => false, 208 'height' => false, 209 ); 210 211 $r = wp_parse_args( $args, $defaults ); 212 extract( $r, EXTR_SKIP ); 213 214 if ( 'thumb' == $type ) 215 $size = 1; 216 else 217 $size = 2; 218 219 if ( $width && $height ) 220 $av = bp_core_get_avatar( $forum_template->topic->topic_poster, $size, $width, $height ); 221 else 222 $av = bp_core_get_avatar( $forum_template->topic->topic_poster, $size ); 223 224 return apply_filters( 'bp_get_the_topic_poster_avatar', $av ); 184 225 } 185 226 … … 202 243 } 203 244 204 function bp_the_topic_last_poster_avatar() { 205 echo bp_get_the_topic_last_poster_avatar(); 206 } 207 function bp_get_the_topic_last_poster_avatar() { 208 global $forum_template; 209 210 return apply_filters( 'bp_get_the_topic_last_poster_avatar', bp_core_get_avatar( $forum_template->topic->topic_last_poster, 1 ) ); 245 function bp_the_topic_last_poster_avatar( $args = '' ) { 246 echo bp_get_the_topic_last_poster_avatar( $args ); 247 } 248 function bp_get_the_topic_last_poster_avatar( $args = '' ) { 249 global $forum_template; 250 251 $defaults = array( 252 'type' => 'thumb', 253 'width' => false, 254 'height' => false, 255 ); 256 257 $r = wp_parse_args( $args, $defaults ); 258 extract( $r, EXTR_SKIP ); 259 260 if ( 'thumb' == $type ) 261 $size = 1; 262 else 263 $size = 2; 264 265 if ( $width && $height ) 266 $av = bp_core_get_avatar( $forum_template->topic->topic_last_poster, $size, $width, $height ); 267 else 268 $av = bp_core_get_avatar( $forum_template->topic->topic_last_poster, $size ); 269 270 return apply_filters( 'bp_get_the_topic_last_poster_avatar', $av ); 211 271 } 212 272 … … 299 359 } 300 360 function bp_get_the_topic_permalink() { 301 global $forum_template, $bbpress_live, $group_obj; 302 303 $target_uri = $bbpress_live->fetch->options['target_uri']; 304 305 return apply_filters( 'bp_get_the_topic_permalink', bp_get_group_permalink( $group_obj ) . '/forum/topic/' . $forum_template->topic->topic_id ); 361 global $forum_template, $bp; 362 363 if ( $bp->is_single_item ) 364 $permalink = $bp->root_domain . '/' . $bp->current_component . '/' . $bp->current_item . '/'; 365 else 366 $permalink = $bp->root_domain . $bp->current_component . '/' . $bp->current_action . '/'; 367 368 return apply_filters( 'bp_get_the_topic_permalink', $permalink . 'forum/topic/' . $forum_template->topic->topic_slug ); 306 369 } 307 370 … … 312 375 global $forum_template; 313 376 314 return apply_filters( 'bp_get_the_topic_time_since_created', $forum_template->topic->topic_start_time_since ); 315 } 316 317 function bp_the_topic_latest_post_excerpt() { 318 echo bp_get_the_topic_latest_post_excerpt(); 319 } 320 function bp_get_the_topic_latest_post_excerpt() { 321 global $forum_template; 377 return apply_filters( 'bp_get_the_topic_time_since_created', bp_core_time_since( bb_gmtstrtotime( $forum_template->topic->topic_start_time ) ) ); 378 } 379 380 function bp_the_topic_latest_post_excerpt( $args = '' ) { 381 echo bp_get_the_topic_latest_post_excerpt( $args ); 382 } 383 function bp_get_the_topic_latest_post_excerpt( $args = '' ) { 384 global $forum_template; 385 386 $defaults = array( 387 'length' => 10 388 ); 389 390 $r = wp_parse_args( $args, $defaults ); 391 extract( $r, EXTR_SKIP ); 322 392 323 393 $post = bp_forums_get_post( $forum_template->topic->topic_last_post_id ); 324 return apply_filters( 'bp_get_the_topic_latest_post_excerpt', $post['post_text'] ); 394 $post = bp_create_excerpt( $post->post_text, $length ); 395 return apply_filters( 'bp_get_the_topic_latest_post_excerpt', $post ); 325 396 } 326 397 … … 336 407 global $forum_template; 337 408 338 return apply_filters( 'bp_get_the_topic_time_since_last_post', $forum_template->topic->topic_time_since ); 339 } 409 return apply_filters( 'bp_get_the_topic_time_since_last_post', bp_core_time_since( bb_gmtstrtotime( $forum_template->topic->topic_time ) ) ); 410 } 411 412 function bp_the_topic_admin_links( $args = '' ) { 413 echo bp_get_the_topic_admin_links( $args ); 414 } 415 function bp_get_the_topic_admin_links( $args = '' ) { 416 global $forum_template; 417 418 $defaults = array( 419 'seperator' => '|' 420 ); 421 422 $r = wp_parse_args( $args, $defaults ); 423 extract( $r, EXTR_SKIP ); 424 425 $links = '<a href="' . wp_nonce_url( bp_get_the_topic_permalink() . '/edit', 'bp_forums_edit_topic' ) . '">' . __( 'Edit', 'buddypress' ) . '</a> ' . $seperator . ' '; 426 427 if ( 0 == (int)$forum_template->topic->topic_sticky ) 428 $links .= '<a href="' . wp_nonce_url( bp_get_the_topic_permalink() . '/stick', 'bp_forums_stick_topic' ) . '">' . __( 'Sticky', 'buddypress' ) . '</a> ' . $seperator . ' '; 429 else 430 $links .= '<a href="' . wp_nonce_url( bp_get_the_topic_permalink() . '/unstick', 'bp_forums_unstick_topic' ) . '">' . __( 'Un-stick', 'buddypress' ) . '</a> ' . $seperator . ' '; 431 432 if ( 0 == (int)$forum_template->topic->topic_open ) 433 $links .= '<a href="' . wp_nonce_url( bp_get_the_topic_permalink() . '/open', 'bp_forums_open_topic' ) . '">' . __( 'Open', 'buddypress' ) . '</a> ' . $seperator . ' '; 434 else 435 $links .= '<a href="' . wp_nonce_url( bp_get_the_topic_permalink() . '/close', 'bp_forums_close_topic' ) . '">' . __( 'Close', 'buddypress' ) . '</a> ' . $seperator . ' '; 436 437 $links .= '<a id="topic-delete-link" href="' . wp_nonce_url( bp_get_the_topic_permalink() . '/delete', 'bp_forums_delete_topic' ) . '">' . __( 'Delete', 'buddypress' ) . '</a>'; 438 439 return $links; 440 } 441 442 function bp_the_topic_css_class() { 443 echo bp_get_the_topic_css_class(); 444 } 445 446 function bp_get_the_topic_css_class() { 447 global $forum_template; 448 449 $class = false; 450 451 if ( 1 == (int)$forum_template->topic->topic_sticky ) { 452 $class .= 'sticky'; 453 } 454 455 if ( 0 == (int)$forum_template->topic->topic_open ) { 456 $class .= ' closed'; 457 } 458 459 return trim( $class ); 460 } 461 340 462 341 463 function bp_forum_pagination() { … … 358 480 <img id="ajax-loader-groups" src="<?php echo $bp->core->image_base ?>/ajax-loader.gif" height="7" alt="<?php _e( "Loading", "buddypress" ) ?>" style="display: none;" /> 359 481 <?php 482 } 483 484 function bp_is_edit_topic() { 485 global $bp; 486 487 if ( in_array( 'post', (array)$bp->action_variables ) && in_array( 'edit', (array)$bp->action_variables ) ) 488 return false; 489 490 return true; 360 491 } 361 492 … … 391 522 $forum_template->topic = (object) bp_forums_get_topic_details( $this->topic_id ); 392 523 393 $this->posts = bp_forums_get_ posts( $this->topic_id, $this->pag_num, $this->pag_page);524 $this->posts = bp_forums_get_topic_posts( array( 'topic_id' => $this->topic_id, 'page' => $this->pag_page, 'per_page' => $this->pag_num ) ); 394 525 395 526 if ( !$this->posts ) { … … 474 605 $defaults = array( 475 606 'topic_id' => false, 476 'per_page' => 1 0,607 'per_page' => 15, 477 608 'max' => false 478 609 ); … … 482 613 483 614 if ( !$topic_id && $bp->current_component == $bp->groups->slug && 'forum' == $bp->current_action && 'topic' == $bp->action_variables[0] ) 484 $topic_id = $bp->action_variables[1];615 $topic_id = bp_forums_get_topic_id_from_slug( $bp->action_variables[1] ); 485 616 486 617 if ( is_numeric( $topic_id ) ) … … 520 651 } 521 652 522 function bp_the_topic_post_poster_avatar( ) {523 echo bp_get_the_topic_post_poster_avatar( );524 } 525 function bp_get_the_topic_post_poster_avatar( ) {653 function bp_the_topic_post_poster_avatar( $args = '' ) { 654 echo bp_get_the_topic_post_poster_avatar( $args ); 655 } 656 function bp_get_the_topic_post_poster_avatar( $args = '' ) { 526 657 global $topic_template; 527 658 528 return apply_filters( 'bp_get_the_topic_post_poster_avatar', bp_core_get_avatar( $topic_template->post->poster_id, 1, 20, 20 ) ); 659 $defaults = array( 660 'type' => 'thumb', 661 'width' => 20, 662 'height' => 20, 663 ); 664 665 $r = wp_parse_args( $args, $defaults ); 666 extract( $r, EXTR_SKIP ); 667 668 if ( 'thumb' == $type ) 669 $size = 1; 670 else 671 $size = 2; 672 673 if ( $width && $height ) 674 $av = bp_core_get_avatar( $topic_template->post->poster_id, $size, $width, $height ); 675 else 676 $av = bp_core_get_avatar( $topic_template->post->poster_id, $size ); 677 678 return apply_filters( 'bp_get_the_topic_post_poster_avatar', $av ); 529 679 } 530 680 … … 550 700 global $topic_template; 551 701 552 return apply_filters( 'bp_get_the_topic_post_time_since', $topic_template->post->post_time_since ); 702 return apply_filters( 'bp_get_the_topic_post_time_since', bp_core_time_since( bb_gmtstrtotime( $topic_template->post->post_time ) ) ); 703 } 704 705 function bp_the_topic_post_is_mine() { 706 echo bp_the_topic_post_is_mine(); 707 } 708 function bp_get_the_topic_post_is_mine() { 709 global $bp, $topic_template; 710 711 return $bp->loggedin_user->id == $topic_template->post->poster_id; 712 } 713 714 function bp_the_topic_post_admin_links( $args = '' ) { 715 echo bp_get_the_topic_post_admin_links( $args ); 716 } 717 function bp_get_the_topic_post_admin_links( $args = '' ) { 718 global $topic_template; 719 720 $defaults = array( 721 'seperator' => '|' 722 ); 723 724 $r = wp_parse_args( $args, $defaults ); 725 extract( $r, EXTR_SKIP ); 726 727 $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 . ' '; 728 $links .= '<a 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>'; 729 730 return $links; 731 } 732 733 function bp_the_topic_post_edit_text() { 734 echo bp_get_the_topic_post_edit_text(); 735 } 736 function bp_get_the_topic_post_edit_text() { 737 global $bp; 738 739 $post = bp_forums_get_post( $bp->action_variables[3] ); 740 return attribute_escape( $post->post_text ); 553 741 } 554 742 … … 578 766 } 579 767 function bp_get_forum_permalink() { 580 global $group_obj; 581 582 return apply_filters( 'bp_get_forum_permalink', bp_get_group_permalink( $group_obj ) . '/forum' ); 768 global $bp; 769 770 if ( $bp->is_single_item ) 771 $permalink = $bp->root_domain . '/' . $bp->current_component . '/' . $bp->current_item . '/'; 772 else 773 $permalink = $bp->root_domain . $bp->current_component . '/' . $bp->current_action . '/'; 774 775 return apply_filters( 'bp_get_forum_permalink', $permalink . 'forum' ); 583 776 } 584 777 … … 589 782 global $topic_template; 590 783 591 return apply_filters( 'bp_get_forum_action', bp_get_group_permalink( $group_obj ) . '/forum');784 return apply_filters( 'bp_get_forum_action', $bp->root_domain . attribute_escape( $_SERVER['REQUEST_URI'] ) ); 592 785 } 593 786 … … 596 789 } 597 790 function bp_get_forum_topic_action() { 598 global $ topic_template;599 600 return apply_filters( 'bp_get_forum_topic_action', bp_get_group_permalink( $group_obj ) . '/forum/topic/' . $topic_template->topic_id);791 global $bp; 792 793 return apply_filters( 'bp_get_forum_topic_action', $bp->root_domain . attribute_escape( $_SERVER['REQUEST_URI'] ) ); 601 794 } 602 795
Note: See TracChangeset
for help on using the changeset viewer.