[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/src/bp-forums/ -> bp-forums-template.php (source)

   1  <?php
   2  /**
   3   * BuddyPress Forums Template Tags.
   4   *
   5   * @package BuddyPress
   6   * @subpackage ForumsTemplate
   7   * @since 1.5.0
   8   */
   9  
  10  // Exit if accessed directly.
  11  defined( 'ABSPATH' ) || exit;
  12  
  13  /**
  14   * Output the forums component slug.
  15   *
  16   * @since 1.5.0
  17   *
  18   */
  19  function bp_forums_slug() {
  20      echo bp_get_forums_slug();
  21  }
  22      /**
  23       * Return the forums component slug.
  24       *
  25       * @since 1.5.0
  26       *
  27       * @return string Slug for the forums component.
  28       */
  29  	function bp_get_forums_slug() {
  30          /**
  31           * Filters the forums component slug.
  32           *
  33           * @since 1.5.0
  34           *
  35           * @param string $slug Forums component slug.
  36           */
  37          return apply_filters( 'bp_get_forums_slug', buddypress()->forums->slug );
  38      }
  39  
  40  /**
  41   * Output the forums component root slug.
  42   *
  43   * @since 1.5.0
  44   *
  45   */
  46  function bp_forums_root_slug() {
  47      echo bp_get_forums_root_slug();
  48  }
  49      /**
  50       * Return the forums component root slug.
  51       *
  52       * @since 1.5.0
  53       *
  54       * @return string Root slug for the forums component.
  55       */
  56  	function bp_get_forums_root_slug() {
  57          /**
  58           * Filters the forums component root slug.
  59           *
  60           * @since 1.5.0
  61           *
  62           * @param string $root_slug Forums component root slug.
  63           */
  64          return apply_filters( 'bp_get_forums_root_slug', buddypress()->forums->root_slug );
  65      }
  66  
  67  /**
  68   * Output permalink for the forum directory.
  69   *
  70   * @since 1.5.0
  71   *
  72   */
  73  function bp_forums_directory_permalink() {
  74      echo esc_url( bp_get_forums_directory_permalink() );
  75  }
  76      /**
  77       * Return permalink for the forum directory.
  78       *
  79       * @since 1.5.0
  80       *
  81       *
  82       * @return string The permalink for the forums component directory.
  83       */
  84  	function bp_get_forums_directory_permalink() {
  85  
  86          /**
  87           * Filters the permalink for the forum directory.
  88           *
  89           * @since 1.5.0
  90           *
  91           * @param string $value Permalink for the forum directory.
  92           */
  93          return apply_filters( 'bp_get_forums_directory_permalink', trailingslashit( bp_get_root_domain() . '/' . bp_get_forums_root_slug() ) );
  94      }
  95  
  96  /**
  97   * The main forums template loop class.
  98   *
  99   * Responsible for loading a group of forum topics into a loop for display.
 100   *
 101   * @since 1.0.0
 102   */
 103  class BP_Forums_Template_Forum {
 104      /**
 105       * The loop iterator.
 106       *
 107       * @since 1.0.0
 108       * @var int
 109       */
 110      public $current_topic = -1;
 111  
 112      /**
 113       * The number of topics returned by the paged query.
 114       *
 115       * @since 1.0.0
 116       * @var int
 117       */
 118      public $topic_count;
 119  
 120      /**
 121       * Array of topics located by the query.
 122       *
 123       * @since 1.0.0
 124       * @var array
 125       */
 126      public $topics;
 127  
 128      /**
 129       * The topic object currently being iterated on.
 130       *
 131       * @since 1.0.0
 132       * @var object
 133       */
 134      public $topic;
 135  
 136      /**
 137       * The ID of the forum whose topics are being queried.
 138       *
 139       * @since 1.5.0
 140       * @var int
 141       */
 142      public $forum_id;
 143  
 144      /**
 145       * A flag for whether the loop is currently being iterated.
 146       *
 147       * @since 1.0.0
 148       * @var bool
 149       */
 150      public $in_the_loop;
 151  
 152      /**
 153       * The page number being requested.
 154       *
 155       * @since 1.0.0
 156       * @var int
 157       */
 158      public $pag_page;
 159  
 160      /**
 161       * The number of items being requested per page.
 162       *
 163       * @since 1.0.0
 164       * @var int
 165       */
 166      public $pag_num;
 167  
 168      /**
 169       * An HTML string containing pagination links.
 170       *
 171       * @since 1.0.0
 172       * @var string
 173       */
 174      public $pag_links;
 175  
 176      /**
 177       * The total number of topics matching the query parameters.
 178       *
 179       * @since 1.0.0
 180       * @var int
 181       */
 182      public $total_topic_count;
 183  
 184      /**
 185       * Whether requesting a single topic. Not currently used.
 186       *
 187       * @since 1.0.0
 188       * @var bool
 189       */
 190      public $single_topic = false;
 191  
 192      /**
 193       * Term to sort by. Not currently used.
 194       *
 195       * @since 1.0.0
 196       * @var string
 197       */
 198      public $sort_by;
 199  
 200      /**
 201       * Sort order. Not currently used.
 202       *
 203       * @since 1.0.0
 204       * @var string
 205       */
 206      public $order;
 207  
 208      /**
 209       * Constructor method.
 210       *
 211       * @since 1.5.0
 212       *
 213       * @param string   $type         The 'type' is the sort order/kind. 'newest',
 214       *                               'popular', 'unreplied', 'tags'.
 215       * @param int      $forum_id     The ID of the forum for which topics are being
 216       *                               queried.
 217       * @param int      $user_id      The ID of the user to whom topics should be
 218       *                               limited. Pass false to remove this filter.
 219       * @param int      $page         The number of the page being requested.
 220       * @param int      $per_page     The number of items being requested per page.
 221       * @param int      $max          Max amount to retrieve.
 222       * @param string   $no_stickies  Requested sticky format.
 223       * @param string   $search_terms Filter results by a string.
 224       * @param int|bool $offset       Optional. Offset results by a given numeric value.
 225       * @param int|bool $number       Optional. Total number of items to retrieve.
 226       */
 227  	function __construct( $type, $forum_id, $user_id, $page, $per_page, $max, $no_stickies, $search_terms, $offset = false, $number = false ) {
 228          $bp = buddypress();
 229  
 230          $this->pag_page     = $page;
 231          $this->pag_num      = $per_page;
 232          $this->type         = $type;
 233          $this->search_terms = $search_terms;
 234          $this->forum_id     = $forum_id;
 235          $this->offset        = $offset;
 236          $this->number        = $number;
 237  
 238          switch ( $type ) {
 239              case 'newest': default:
 240                  $this->topics = bp_forums_get_forum_topics( array( 'user_id' => $user_id, 'forum_id' => $forum_id, 'filter' => $search_terms, 'page' => $this->pag_page, 'per_page' => $this->pag_num, 'show_stickies' => $no_stickies, 'offset' => $offset, 'number' => $number ) );
 241                  break;
 242  
 243              case 'popular':
 244                  $this->topics = bp_forums_get_forum_topics( array( 'user_id' => $user_id, 'type' => 'popular', 'filter' => $search_terms, 'forum_id' => $forum_id, 'page' => $this->pag_page, 'per_page' => $this->pag_num, 'show_stickies' => $no_stickies, 'offset' => $offset, 'number' => $number ) );
 245                  break;
 246  
 247              case 'unreplied':
 248                  $this->topics = bp_forums_get_forum_topics( array( 'user_id' => $user_id, 'type' => 'unreplied', 'filter' => $search_terms, 'forum_id' => $forum_id, 'page' => $this->pag_page, 'per_page' => $this->pag_num, 'show_stickies' => $no_stickies, 'offset' => $offset, 'number' => $number ) );
 249                  break;
 250  
 251              case 'tags':
 252                  $this->topics = bp_forums_get_forum_topics( array( 'user_id' => $user_id, 'type' => 'tags', 'filter' => $search_terms, 'forum_id' => $forum_id, 'page' => $this->pag_page, 'per_page' => $this->pag_num, 'show_stickies' => $no_stickies, 'offset' => $offset, 'number' => $number ) );
 253                  break;
 254          }
 255  
 256          /**
 257           * Filters the forums template topics.
 258           *
 259           * @since 1.1.0
 260           *
 261           * @param array  $topics      Array of topics being set for display.
 262           * @param string $type        The sort order/kind. 'newest',
 263           *                            'popular', 'unreplied', 'tags'.
 264           * @param int    $forum_id    ID for the current forum.
 265           * @param int    $per_page    The number of the page being requested.
 266           * @param int    $max         The max number of posts to show.
 267           * @param string $no_stickies Requested sticky format.
 268           */
 269          $this->topics = apply_filters( 'bp_forums_template_topics', $this->topics, $type, $forum_id, $per_page, $max, $no_stickies );
 270  
 271          if ( !(int) $this->topics ) {
 272              $this->topic_count       = 0;
 273              $this->total_topic_count = 0;
 274          } else {
 275              // Get a total topic count, for use in pagination. This value will differ
 276              // depending on scope.
 277              if ( !empty( $forum_id ) ) {
 278                  // Group forums.
 279                  $topic_count = bp_forums_get_forum( $forum_id );
 280                  $topic_count = (int) $topic_count->topics;
 281              } else if ( !empty( $bp->groups->current_group ) ) {
 282                  $topic_count = (int)groups_total_public_forum_topic_count( $type );
 283              } else if ( bp_is_user_forums_started() || ( bp_is_directory() && $user_id ) ) {
 284                  // This covers the case of Profile > Forums > Topics Started, as
 285                  // well as Forum Directory > My Topics.
 286                  $topic_count = bp_forums_total_topic_count_for_user( bp_displayed_user_id(), $type );
 287              } else if ( bp_is_user_forums_replied_to() ) {
 288                  // Profile > Forums > Replied To.
 289                  $topic_count = bp_forums_total_replied_count_for_user( bp_displayed_user_id(), $type );
 290              } else if ( 'tags' == $type ) {
 291                  $tag         = bb_get_tag( $search_terms );
 292                  $topic_count = $tag->count;
 293              } else {
 294                  // For forum directories (All Topics), get a true count
 295                  $status = bp_current_user_can( 'bp_moderate' ) ? 'all' : 'public'; // @todo: member-of.
 296                  $topic_count = (int)groups_total_forum_topic_count( $status, $search_terms );
 297              }
 298  
 299              if ( !$max || $max >= $topic_count ) {
 300                  $this->total_topic_count = $topic_count;
 301              } else {
 302                  $this->total_topic_count = (int) $max;
 303              }
 304  
 305              if ( $max ) {
 306                  if ( $max >= count($this->topics) ) {
 307                      $this->topic_count = count( $this->topics );
 308                  } else {
 309                      $this->topic_count = (int) $max;
 310                  }
 311              } else {
 312                  $this->topic_count = count( $this->topics );
 313              }
 314          }
 315  
 316          /**
 317           * Filters the topic count for the forum being displayed.
 318           *
 319           * @since 1.1.0
 320           *
 321           * @param int    $topic_count Topic count to be displayed.
 322           * @param array  $topics      Array of topics to be displayed.
 323           * @param string $type        The sort order/kind. 'newest',
 324           *                            'popular', 'unreplied', 'tags'.
 325           * @param int    $forum_id    ID for the current forum.
 326           * @param int    $per_page    The number of the page being requested.
 327           * @param int    $max         The max number of posts to show.
 328           * @param string $no_stickies Requested sticky format.
 329           */
 330          $this->topic_count = apply_filters_ref_array( 'bp_forums_template_topic_count', array( $this->topic_count, &$this->topics, $type, $forum_id, $per_page, $max, $no_stickies ) );
 331  
 332          /**
 333           * Filters the total topic count for the forum being displayed.
 334           *
 335           * @since 1.1.0
 336           *
 337           * @param int    $total_topic_count Total topic count found.
 338           * @param int    $topic_count       Topic count to be displayed.
 339           * @param array  $topics            Array of topics to be displayed.
 340           * @param string $type              The sort order/kind. 'newest',
 341           *                                  'popular', 'unreplied', 'tags'.
 342           * @param int    $forum_id          ID for the current forum.
 343           * @param int    $per_page          The number of the page being requested.
 344           * @param int    $max               The max number of posts to show.
 345           * @param string $no_stickies       Requested sticky format.
 346           */
 347          $this->total_topic_count = apply_filters_ref_array( 'bp_forums_template_total_topic_count', array( $this->total_topic_count, $this->topic_count, &$this->topics, $type, $forum_id, $per_page, $max, $no_stickies ) );
 348  
 349          // Fetch extra information for topics, so we don't have to query inside the loop.
 350          $this->topics = bp_forums_get_topic_extras( $this->topics );
 351  
 352          if ( (int) $this->total_topic_count && (int) $this->pag_num ) {
 353              $this->pag_links = paginate_links( array(
 354                  'base'      => add_query_arg( array( 'p' => '%#%', 'n' => $this->pag_num ) ),
 355                  'format'    => '',
 356                  'total'     => ceil( (int) $this->total_topic_count / (int) $this->pag_num),
 357                  'current'   => $this->pag_page,
 358                  'prev_text' => _x( '&larr;', 'Forum topic pagination previous text', 'buddypress' ),
 359                  'next_text' => _x( '&rarr;', 'Forum topic pagination next text', 'buddypress' ),
 360                  'mid_size'  => 1,
 361                  'add_args'  => array(),
 362              ) );
 363          }
 364      }
 365  
 366      /**
 367       * Whether there are topics available in the loop.
 368       *
 369       * @since 1.0.0
 370       *
 371       * @see bp_has_forum_topics()
 372       *
 373       * @return bool True if there are items in the loop, otherwise false.
 374       */
 375  	function has_topics() {
 376          if ( $this->topic_count ) {
 377              return true;
 378          }
 379  
 380          return false;
 381      }
 382  
 383      /**
 384       * Set up the next topic and iterate index.
 385       *
 386       * @since 1.0.0
 387       *
 388       * @return object The next topic to iterate over.
 389       */
 390  	function next_topic() {
 391          $this->current_topic++;
 392          $this->topic = $this->topics[$this->current_topic];
 393  
 394          return $this->topic;
 395      }
 396  
 397      /**
 398       * Rewind the topics and reset topic index.
 399       *
 400       * @since 1.0.0
 401       */
 402  	function rewind_topics() {
 403          $this->current_topic = -1;
 404          if ( $this->topic_count > 0 ) {
 405              $this->topic = $this->topics[0];
 406          }
 407      }
 408  
 409      /**
 410       * Whether there are blogs left in the loop to iterate over.
 411       *
 412       * This method is used by {@link bp_forum_topics()} as part of the while loop
 413       * that controls iteration inside the blogs loop, eg:
 414       *     while ( bp_forum_topics() ) { ...
 415       *
 416       * @see bp_forum_topics()
 417       *
 418       * @since 1.0.0
 419       *
 420       * @return bool True if there are more topics to show, otherwise false.
 421       */
 422  	function user_topics() {
 423          if ( $this->current_topic + 1 < $this->topic_count ) {
 424              return true;
 425          } elseif ( $this->current_topic + 1 == $this->topic_count ) {
 426  
 427              /**
 428               * Fires right before the rewinding of user topics.
 429               *
 430               * @since 1.5.0
 431               */
 432              do_action('forum_loop_end');
 433              // Do some cleaning up after the loop.
 434              $this->rewind_topics();
 435          }
 436  
 437          $this->in_the_loop = false;
 438          return false;
 439      }
 440  
 441      /**
 442       * Set up the current topic in the loop.
 443       *
 444       * @since 1.0.0
 445       *
 446       * @see bp_the_forum_topic()
 447       */
 448  	function the_topic() {
 449          global $topic;
 450  
 451          $this->in_the_loop = true;
 452          $this->topic = $this->next_topic();
 453          $this->topic = (object)$this->topic;
 454  
 455          if ( $this->current_topic == 0 ) {
 456  
 457              /**
 458               * Fires if the current topic item is the first in the topic loop.
 459               *
 460               * @since 1.5.0
 461               */
 462              do_action( 'forum_loop_start' );
 463          }
 464      }
 465  }
 466  
 467  /**
 468   * Initiate the forum topics loop.
 469   *
 470   * Like other BuddyPress custom loops, the default arguments for this function
 471   * are determined dynamically, depending on your current page. All of these
 472   * $defaults can be overridden in the $args parameter.
 473   *
 474   * @since 1.1.0
 475   *
 476   *       $forums_template global before it's rendered, or to modify the value
 477   *       of has_topics().
 478   *
 479   * @param array|string $args {
 480   *     Arguments for limiting the contents of the forum topics loop.
 481   *
 482   *     @type string      $type         The 'type' is the sort order/kind. 'newest',
 483   *                                     'popular', 'unreplied', 'tags'. Default: 'newest'.
 484   *     @type int         $forum_id     The ID of the forum for which topics are being
 485   *                                     queried. Default: the ID of the forum belonging to the current
 486   *                                     group, if available.
 487   *     @type int         $user_id      The ID of a user to whom to limit results. If viewing
 488   *                                     a member's profile, defaults to that member's ID; otherwise
 489   *                                     defaults to 0.
 490   *     @type int         $page         The number of the page being requested. Default: 1, or
 491   *                                     the value of $_GET['p'].
 492   *     @type int         $per_pag      The number items to return per page. Default: 20, or
 493   *                                     the value of $_GET['n'].
 494   *     @type int         $max          Optional. Max records to return. Default: false (no max).
 495   *     @type int         $number       Optional. Number of records to return. Default: false.
 496   *     @type int         $offset       Optional. Offset results by a given value.
 497   *                                     Default: false.
 498   *     @type string      $search_terms Optional. A string to which results should be
 499   *                                     limited. Default: false, or the value of $_GET['fs'].
 500   *     @type string|bool $do_stickies  Whether to move stickies to the top of
 501   *                                     the sort order. Default: true if looking at a group forum,
 502   *                                     otherwise false.
 503   * }
 504   * @return bool True when forum topics are found corresponding to the args,
 505   *         false otherwise.
 506   */
 507  function bp_has_forum_topics( $args = '' ) {
 508      global $forum_template;
 509  
 510      $bp = buddypress();
 511  
 512      /*
 513       * Set the defaults based on the current page. Any of these will be overridden
 514       * if arguments are directly passed into the loop. Custom plugins should always
 515       * pass their parameters directly to the loop.
 516       */
 517      $type         = 'newest';
 518      $user_id      = 0;
 519      $forum_id     = false;
 520      $search_terms = false;
 521      $do_stickies  = false;
 522  
 523      // User filtering.
 524      if ( bp_displayed_user_id() )
 525          $user_id = bp_displayed_user_id();
 526  
 527      // "Replied" query must be manually modified
 528      if ( 'replies' == bp_current_action() ) {
 529          $user_id = 0; // User id must be handled manually by the filter, not by BB_Query.
 530  
 531          add_filter( 'get_topics_distinct',   'bp_forums_add_replied_distinct_sql', 20 );
 532          add_filter( 'get_topics_join',          'bp_forums_add_replied_join_sql', 20 );
 533          add_filter( 'get_topics_where',      'bp_forums_add_replied_where_sql', 20  );
 534      }
 535  
 536      // If we're in a single group, set this group's forum_id.
 537      if ( !$forum_id && !empty( $bp->groups->current_group ) ) {
 538          $bp->groups->current_group->forum_id = groups_get_groupmeta( $bp->groups->current_group->id, 'forum_id' );
 539  
 540          // If it turns out there is no forum for this group, return false so
 541          // we don't fetch all global topics.
 542          if ( empty( $bp->groups->current_group->forum_id ) )
 543              return false;
 544  
 545          $forum_id = $bp->groups->current_group->forum_id;
 546      }
 547  
 548      // If $_GET['fs'] is set, let's auto populate the search_terms var.
 549      if ( bp_is_directory() && !empty( $_GET['fs'] ) )
 550          $search_terms = $_GET['fs'];
 551  
 552      // Get the pagination arguments from $_REQUEST.
 553      $page     = isset( $_REQUEST['p'] ) ? intval( $_REQUEST['p'] ) : 1;
 554      $per_page = isset( $_REQUEST['n'] ) ? intval( $_REQUEST['n'] ) : 20;
 555  
 556      // By default, stickies are only pushed to the top of the order on individual group forums.
 557      if ( bp_is_group_forum() )
 558          $do_stickies = true;
 559  
 560      $defaults = array(
 561          'type'         => $type,
 562          'forum_id'     => $forum_id,
 563          'user_id'      => $user_id,
 564          'page'         => $page,
 565          'per_page'     => $per_page,
 566          'max'          => false,
 567          'number'       => false,
 568          'offset'       => false,
 569          'search_terms' => $search_terms,
 570          'do_stickies'  => $do_stickies
 571      );
 572  
 573      $r = bp_parse_args( $args, $defaults, 'has_forum_topics' );
 574      extract( $r );
 575  
 576      // If we're viewing a tag URL in the directory, let's override the type and
 577      // set it to tags and the filter to the tag name.
 578      if ( bp_is_current_action( 'tag' ) && $search_terms = bp_action_variable( 0 ) ) {
 579          $type = 'tags';
 580      }
 581  
 582      /** Sticky logic ******************************************************************/
 583  
 584      if ( $do_stickies ) {
 585          // Fetch the stickies.
 586          $stickies_template = new BP_Forums_Template_Forum( $type, $forum_id, $user_id, 0, 0, $max, 'sticky', $search_terms );
 587  
 588          // If stickies are found, try merging them.
 589          if ( $stickies_template->has_topics() ) {
 590  
 591              // If stickies are for current $page.
 592              $page_start_num = ( ( $page - 1 ) * $per_page ) + 1;
 593              $page_end_num     = $page * $per_page <= $stickies_template->total_topic_count ? $page * $per_page : $stickies_template->total_topic_count;
 594  
 595              // Calculate the number of sticky topics that will be shown on this page.
 596              if ( $stickies_template->topic_count < $page_start_num ) {
 597                  $this_page_stickies = 0;
 598              } else {
 599                  $this_page_stickies = $stickies_template->topic_count - $per_page * floor( $stickies_template->topic_count / $per_page ) * ( $page - 1 ); // Total stickies minus sticky count through this page.
 600  
 601                  // $this_page_stickies cannot be more than $per_page or less than 0
 602                  if ( $this_page_stickies > $per_page )
 603                      $this_page_stickies = $per_page;
 604                  else if ( $this_page_stickies < 0 )
 605                      $this_page_stickies = 0;
 606              }
 607  
 608              // Calculate the total number of topics that will be shown on this page.
 609              $this_page_topics = $stickies_template->total_topic_count >= ( $page * $per_page ) ? $per_page : $page_end_num - ( $page_start_num - 1 );
 610  
 611              // If the number of stickies to be shown is less than $per_page, fetch some
 612              // non-stickies to fill in the rest.
 613              if ( $this_page_stickies < $this_page_topics ) {
 614                  // How many non-stickies do we need?
 615                  $non_sticky_number = $this_page_topics - $this_page_stickies;
 616  
 617                  // Calculate the non-sticky offset
 618                  // How many non-stickies on all pages up to this point?
 619                  $non_sticky_total = $page_end_num - $stickies_template->topic_count;
 620  
 621                  // The offset is the number of total non-stickies, less the number
 622                  // to be shown on this page.
 623                  $non_sticky_offset = $non_sticky_total - $non_sticky_number;
 624  
 625                  // Fetch the non-stickies.
 626                  $forum_template = new BP_Forums_Template_Forum( $type, $forum_id, $user_id, 1, $per_page, $max, 'no', $search_terms, $non_sticky_offset, $non_sticky_number );
 627  
 628                  // If there are stickies to merge on this page, do it now.
 629                  if ( $this_page_stickies ) {
 630                      // Correct the topic_count.
 631                      $forum_template->topic_count += (int) $this_page_stickies;
 632  
 633                      // Figure out which stickies need to be included.
 634                      $this_page_sticky_topics = array_slice( $stickies_template->topics, 0 - $this_page_stickies );
 635  
 636                      // Merge these topics into the forum template.
 637                      $forum_template->topics = array_merge( $this_page_sticky_topics, (array) $forum_template->topics );
 638                  }
 639              } else {
 640                  // This page has no non-stickies.
 641                  $forum_template = $stickies_template;
 642  
 643                  // Adjust the topic count and trim the topics.
 644                  $forum_template->topic_count = $this_page_stickies;
 645                  $forum_template->topics      = array_slice( $forum_template->topics, $page - 1 );
 646              }
 647  
 648              // Because we're using a manual offset and number for the topic query, we
 649              // must set the page number manually, and recalculate the pagination links.
 650              $forum_template->pag_num     = $per_page;
 651              $forum_template->pag_page    = $page;
 652  
 653              $forum_template->pag_links = paginate_links( array(
 654                  'base'      => add_query_arg( array( 'p' => '%#%', 'n' => $forum_template->pag_num ) ),
 655                  'format'    => '',
 656                  'total'     => ceil( (int) $forum_template->total_topic_count / (int) $forum_template->pag_num ),
 657                  'current'   => $forum_template->pag_page,
 658                  'prev_text' => _x( '&larr;', 'Forum topic pagination previous text', 'buddypress' ),
 659                  'next_text' => _x( '&rarr;', 'Forum topic pagination next text', 'buddypress' ),
 660                  'mid_size'  => 1,
 661                  'add_args'  => array(),
 662              ) );
 663  
 664          } else {
 665              // Fetch the non-sticky topics if no stickies were found.
 666              $forum_template = new BP_Forums_Template_Forum( $type, $forum_id, $user_id, $page, $per_page, $max, 'all', $search_terms );
 667          }
 668      } else {
 669          // When skipping the sticky logic, just pull up the forum topics like usual.
 670          $forum_template = new BP_Forums_Template_Forum( $type, $forum_id, $user_id, $page, $per_page, $max, 'all', $search_terms );
 671      }
 672  
 673      /**
 674       * Filters whether or not there are topics to display.
 675       *
 676       * @since 1.1.0
 677       *
 678       * @param bool   $value          Whether or not there are topics to display.
 679       * @param object $forum_template Global $forum_template object.
 680       */
 681      return apply_filters( 'bp_has_topics', $forum_template->has_topics(), $forum_template );
 682  }
 683  
 684  /**
 685   * Determine whether there are still topics left in the loop.
 686   *
 687   * @since 1.1.0
 688   *
 689   * @global BP_Forums_Template_Forum $forum_template Template global.
 690   *
 691   * @return bool Returns true when topics are found.
 692   */
 693  function bp_forum_topics() {
 694      global $forum_template;
 695      return $forum_template->user_topics();
 696  }
 697  
 698  /**
 699   * Get the current topic object in the loop.
 700   *
 701   * @since 1.1.0
 702   *
 703   * @global BP_Forums_Template_Forum $forum_template Template global.
 704   *
 705   * @return object The current topic object.
 706   */
 707  function bp_the_forum_topic() {
 708      global $forum_template;
 709      return $forum_template->the_topic();
 710  }
 711  
 712  /**
 713   * Output the ID of the current topic in the loop.
 714   *
 715   * @since 1.0.0
 716   */
 717  function bp_the_topic_id() {
 718      echo bp_get_the_topic_id();
 719  }
 720      /**
 721       * Return the ID of the current topic in the loop.
 722       *
 723       * @since 1.0.0
 724       *
 725       * @return int ID of the current topic in the loop.
 726       */
 727  	function bp_get_the_topic_id() {
 728          global $forum_template;
 729  
 730          /**
 731           * Filters the ID of the current topic in the loop.
 732           *
 733           * @since 1.0.0
 734           *
 735           * @param int $topic_id ID for the current topic.
 736           */
 737          return apply_filters( 'bp_get_the_topic_id', $forum_template->topic->topic_id );
 738      }
 739  
 740  /**
 741   * Output the title of the current topic in the loop.
 742   *
 743   * @since 1.0.0
 744   */
 745  function bp_the_topic_title() {
 746      echo bp_get_the_topic_title();
 747  }
 748      /**
 749       * Return the title of the current topic in the loop.
 750       *
 751       * @since 1.0.0
 752       *
 753       * @return string Title of the current topic in the loop.
 754       */
 755  	function bp_get_the_topic_title() {
 756          global $forum_template;
 757  
 758          /**
 759           * Filters the title of the current topic in the loop.
 760           *
 761           * @since 1.0.0
 762           *
 763           * @param string $topic_title Title for the current topic.
 764           */
 765          return apply_filters( 'bp_get_the_topic_title', stripslashes( $forum_template->topic->topic_title ) );
 766      }
 767  
 768  /**
 769   * Output the slug of the current topic in the loop.
 770   *
 771   * @since 1.0.0
 772   */
 773  function bp_the_topic_slug() {
 774      echo bp_get_the_topic_slug();
 775  }
 776      /**
 777       * Return the slug of the current topic in the loop.
 778       *
 779       * @since 1.0.0
 780       *
 781       * @return string Slug of the current topic in the loop.
 782       */
 783  	function bp_get_the_topic_slug() {
 784          global $forum_template;
 785  
 786          /**
 787           * Filters the slug of the current topic in the loop.
 788           *
 789           * @since 1.0.0
 790           *
 791           * @param string $topic_slug Slug for the current topic.
 792           */
 793          return apply_filters( 'bp_get_the_topic_slug', $forum_template->topic->topic_slug );
 794      }
 795  
 796  /**
 797   * Output the text of the first post in the current topic in the loop.
 798   *
 799   * @since 1.1.0
 800   */
 801  function bp_the_topic_text() {
 802      echo bp_get_the_topic_text();
 803  }
 804      /**
 805       * Return the text of the first post in the current topic in the loop.
 806       *
 807       * @since 1.1.0
 808       *
 809       * @return string Text of the first post in the current topic.
 810       */
 811  	function bp_get_the_topic_text() {
 812          global $forum_template;
 813  
 814          $post = bb_get_first_post( (int) $forum_template->topic->topic_id, false );
 815  
 816          /**
 817           * Filters the text of the first post in the current topic in the loop.
 818           *
 819           * @since 1.1.0
 820           *
 821           * @param string $post_text Text for the first post in the current topic.
 822           */
 823          return apply_filters( 'bp_get_the_topic_text', esc_attr( $post->post_text ) );
 824      }
 825  
 826  /**
 827   * Output the ID of the user who posted the current topic in the loop.
 828   *
 829   * @since 1.0.0
 830   */
 831  function bp_the_topic_poster_id() {
 832      echo bp_get_the_topic_poster_id();
 833  }
 834      /**
 835       * Return the ID of the user who posted the current topic in the loop.
 836       *
 837       * @since 1.0.0
 838       *
 839       * @return int ID of the user who posted the current topic.
 840       */
 841  	function bp_get_the_topic_poster_id() {
 842          global $forum_template;
 843  
 844          /**
 845           * Filters the ID of the user who posted the current topic in the loop.
 846           *
 847           * @since 1.0.0
 848           *
 849           * @param int $topic_poster ID for the user.
 850           */
 851          return apply_filters( 'bp_get_the_topic_poster_id', $forum_template->topic->topic_poster );
 852      }
 853  
 854  /**
 855   * Output the avatar of the user who posted the current topic in the loop.
 856   *
 857   * @since 1.0.0
 858   *
 859   * @see bp_get_the_topic_poster_avatar() for a description of arguments.
 860   *
 861   * @param array|string $args See {@link bp_get_the_topic_poster_avatar()}.
 862   */
 863  function bp_the_topic_poster_avatar( $args = '' ) {
 864      echo bp_get_the_topic_poster_avatar( $args );
 865  }
 866      /**
 867       * Return the avatar of the user who posted the current topic in the loop.
 868       *
 869       * @since 1.0.0
 870       *
 871       * @param array|string $args {
 872       *     Arguments for building the avatar.
 873       *     @type string $type   Avatar type. 'thumb' or 'full'. Default:
 874       *                          'thumb'.
 875       *     @type int    $width  Width of the avatar, in pixels. Default: the
 876       *                          width corresponding to $type.
 877       *                          See {@link bp_core_fetch_avatar()}.
 878       *     @type int    $height Height of the avatar, in pixels. Default: the
 879       *                          height corresponding to $type.
 880       *                          See {@link bp_core_fetch_avatar()}.
 881       *     @type string $alt    The text of the image's 'alt' attribute.
 882       *                          Default: 'Profile picture of [user name]'.
 883       * }
 884       * @return string HTML of user avatar.
 885       */
 886  	function bp_get_the_topic_poster_avatar( $args = '' ) {
 887          global $forum_template;
 888  
 889          $defaults = array(
 890              'type'   => 'thumb',
 891              'width'  => false,
 892              'height' => false,
 893              'alt'    => sprintf( __( 'Profile picture of %s', 'buddypress' ), bp_core_get_user_displayname( $forum_template->topic->topic_poster ) )
 894          );
 895  
 896          $r = wp_parse_args( $args, $defaults );
 897          extract( $r, EXTR_SKIP );
 898  
 899          /**
 900           * Filters the avatar for the user who posted the current topic in the loop.
 901           *
 902           * @since 1.0.0
 903           *
 904           * @param string $value HTML for the display of the user's avatar.
 905           */
 906          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, 'alt' => $alt ) ) );
 907      }
 908  
 909  /**
 910   * Output the name of the user who posted the current topic in the loop.
 911   *
 912   * @since 1.0.0
 913   */
 914  function bp_the_topic_poster_name() {
 915      echo bp_get_the_topic_poster_name();
 916  }
 917      /**
 918       * Return the name of the user who posted the current topic in the loop.
 919       *
 920       * @since 1.0.0
 921       *
 922       * @return string Name of the user who posted the current topic.
 923       */
 924  	function bp_get_the_topic_poster_name() {
 925          global $forum_template;
 926  
 927          $poster_id = ( empty( $forum_template->topic->poster_id ) ) ? $forum_template->topic->topic_poster : $forum_template->topic->poster_id;
 928  
 929          if ( !$name = bp_core_get_userlink( $poster_id ) )
 930              return __( 'Deleted User', 'buddypress' );
 931  
 932          /**
 933           * Filters the name of the user who posted the current topic in the loop.
 934           *
 935           * @since 1.0.0
 936           *
 937           * @param string $name Name for the user who posted the current topic.
 938           */
 939          return apply_filters( 'bp_get_the_topic_poster_name', $name );
 940      }
 941  
 942  /**
 943   * Output the ID of the object associated with the current topic in the loop.
 944   *
 945   * @since 1.1.0
 946   */
 947  function bp_the_topic_object_id() {
 948      echo bp_get_the_topic_object_id();
 949  }
 950      /**
 951       * Return the ID of the object associated with the current topic in the loop.
 952       *
 953       * Objects are things like associated groups.
 954       *
 955       * @since 1.1.0
 956       *
 957       * @return int ID of the associated object.
 958       */
 959  	function bp_get_the_topic_object_id() {
 960          global $forum_template;
 961  
 962          /**
 963           * Filters the ID of the object associated with the current topic in the loop.
 964           *
 965           * Objects are things like associated groups.
 966           *
 967           * @since 1.1.0
 968           *
 969           * @param int $object_id ID for the object associated with the current topic.
 970           */
 971          return apply_filters( 'bp_get_the_topic_object_id', $forum_template->topic->object_id );
 972      }
 973  
 974  /**
 975   * Output the name of the object associated with the current topic in the loop.
 976   *
 977   * @since 1.1.0
 978   */
 979  function bp_the_topic_object_name() {
 980      echo bp_get_the_topic_object_name();
 981  }
 982      /**
 983       * Return the name of the object associated with the current topic in the loop.
 984       *
 985       * Objects are things like groups. So this function would return the
 986       * name of the group associated with the forum topic, if it exists.
 987       *
 988       * @since 1.1.0
 989       *
 990       * @return string Object name.
 991       */
 992  	function bp_get_the_topic_object_name() {
 993          global $forum_template;
 994  
 995          if ( isset( $forum_template->topic->object_name ) )
 996              $retval = $forum_template->topic->object_name;
 997          else
 998              $retval = '';
 999  
1000          /**
1001           * Filters the name of the object associated with the current topic in the loop.
1002           *
1003           * Objects are things like groups. So this filter would return the
1004           * name of the group associated with the forum topic, if it exists.
1005           *
1006           * @since 1.1.0
1007           *
1008           * @param string $retval Name for the object associated with the current topic.
1009           */
1010          return apply_filters( 'bp_get_the_topic_object_name', $retval );
1011      }
1012  
1013  /**
1014   * Output the slug of the object associated with the current topic in the loop.
1015   *
1016   * @since 1.1.0
1017   */
1018  function bp_the_topic_object_slug() {
1019      echo bp_get_the_topic_object_slug();
1020  }
1021      /**
1022       * Return the slug of the object associated with the current topic in the loop.
1023       *
1024       * Objects are things like groups. So this function would return the
1025       * slug of the group associated with the forum topic, if it exists.
1026       *
1027       * @since 1.1.0
1028       *
1029       * @return string Object slug.
1030       */
1031  	function bp_get_the_topic_object_slug() {
1032          global $forum_template;
1033  
1034          /**
1035           * Filters the slug of the object associated with the current topic in the loop.
1036           *
1037           * Objects are things like groups. So this filter would return the
1038           * slug of the group associated with the forum topic, if it exists.
1039           *
1040           * @since 1.1.0
1041           *
1042           * @param string $object_slug Slug for the object associated with the current topic.
1043           */
1044          return apply_filters( 'bp_get_the_topic_object_slug', $forum_template->topic->object_slug );
1045      }
1046  
1047  /**
1048   * Output the permalink of the object associated with the current topic in the loop.
1049   *
1050   * @since 1.1.0
1051   */
1052  function bp_the_topic_object_permalink() {
1053      echo bp_get_the_topic_object_permalink();
1054  }
1055      /**
1056       * Return the permalink of the object associated with the current topic in the loop.
1057       *
1058       * Objects are things like groups. So this function would return the
1059       * permalink of the group associated with the forum topic, if it exists.
1060       *
1061       * @since 1.1.0
1062       *
1063       * @return string Object permalink.
1064       */
1065  	function bp_get_the_topic_object_permalink() {
1066  
1067          // Currently this will only work with group forums, extended support in the future.
1068          if ( bp_is_active( 'groups' ) ) {
1069              $permalink = trailingslashit( bp_get_groups_directory_permalink() . bp_get_the_topic_object_slug() . '/forum' );
1070          } else {
1071              $permalink = '';
1072          }
1073  
1074          /**
1075           * Filters the permalink of the object associated with the current topic in the loop.
1076           *
1077           * Objects are things like groups. So this filter would return the
1078           * slug of the group associated with the forum topic, if it exists.
1079           *
1080           * @since 1.1.0
1081           *
1082           * @param string $permalink Permalink for the object associated with the current topic.
1083           */
1084          return apply_filters( 'bp_get_the_topic_object_permalink', $permalink );
1085      }
1086  
1087  /**
1088   * Output the linked name of the user who last posted to the current topic in the loop.
1089   *
1090   * @since 1.0.0
1091   */
1092  function bp_the_topic_last_poster_name() {
1093      echo bp_get_the_topic_last_poster_name();
1094  }
1095      /**
1096       * Return the linked name of the user who last posted to the current topic in the loop.
1097       *
1098       * @since 1.0.0
1099       *
1100       * @return string HTML link to the profile of the user who last posted
1101       *                to the current topic.
1102       */
1103  	function bp_get_the_topic_last_poster_name() {
1104          global $forum_template;
1105  
1106          $domain = bp_core_get_user_domain( $forum_template->topic->topic_last_poster, $forum_template->topic->topic_last_poster_nicename, $forum_template->topic->topic_last_poster_login );
1107  
1108          // In the case where no user is found, bp_core_get_user_domain() may return the URL
1109          // of the Members directory.
1110          if ( empty( $domain ) || ( bp_get_members_directory_permalink() === $domain ) ) {
1111              return __( 'Deleted User', 'buddypress' );
1112          }
1113  
1114          /**
1115           * Filters the linked name of the user who last posted to the current topic in the loop.
1116           *
1117           * @since 1.0.0
1118           *
1119           * @param string $value HTML link to the profile of the user who last posted.
1120           */
1121          return apply_filters( 'bp_get_the_topic_last_poster_name', '<a href="' . $domain . '">' . $forum_template->topic->topic_last_poster_displayname . '</a>' );
1122      }
1123  
1124  /**
1125   * Output the permalink of the object associated with the current topic in the loop.
1126   *
1127   * @since 1.1.0
1128   *
1129   * @see bp_get_the_topic_object_avatar() for description of arguments.
1130   *
1131   * @param array|string $args See {@bp_get_the_topic_object_avatar()}.
1132   */
1133  function bp_the_topic_object_avatar( $args = '' ) {
1134      echo bp_get_the_topic_object_avatar( $args );
1135  }
1136      /**
1137       * Return the avatar of the object associated with the current topic in the loop.
1138       *
1139       * Objects are things like groups. So this function would return the
1140       * avatar of the group associated with the forum topic, if it exists.
1141       *
1142       * @since 1.1.0
1143       *
1144       * @param array|string $args {
1145       *     Arguments for building the avatar.
1146       *     @type string $type   Avatar type. 'thumb' or 'full'. Default:
1147       *                         'thumb'.
1148       *     @type int    $width  Width of the avatar, in pixels. Default: the
1149       *                          width corresponding to $type.
1150       *                          See {@link bp_core_fetch_avatar()}.
1151       *     @type int    $height Height of the avatar, in pixels. Default:
1152       *                          the height corresponding to $type.
1153       *                          See {@link bp_core_fetch_avatar()}.
1154       *     @type string $alt    The text of the image's 'alt' attribute.
1155       *                          Default: 'Group logo for [group name]'.
1156       * }
1157       * @return string Object avatar.
1158       */
1159  	function bp_get_the_topic_object_avatar( $args = '' ) {
1160          global $forum_template;
1161  
1162          if ( !isset( $forum_template->topic->object_id ) )
1163              return false;
1164  
1165          $defaults = array(
1166              'type'   => 'thumb',
1167              'width'  => false,
1168              'height' => false,
1169              'alt'    => __( 'Group logo for %s', 'buddypress' )
1170          );
1171  
1172          $r = wp_parse_args( $args, $defaults );
1173          extract( $r, EXTR_SKIP );
1174  
1175          /**
1176           * Filters the avatar of the object associated with the current topic in the loop.
1177           *
1178           * @since 1.1.0
1179           *
1180           * @param string $value HTML output for the object associated with the current topic.
1181           */
1182          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, 'alt' => $alt ) ) );
1183      }
1184  
1185  /**
1186   * Output the avatar for the user who last posted to the current topic in the loop.
1187   *
1188   * @since 1.0.0
1189   *
1190   * @see bp_get_the_topic_last_poster_avatar() for description of arguments.
1191   *
1192   * @param array|string $args See {@bp_get_the_topic_last_poster_avatar()}.
1193   */
1194  function bp_the_topic_last_poster_avatar( $args = '' ) {
1195      echo bp_get_the_topic_last_poster_avatar( $args );
1196  }
1197      /**
1198       * Return the avatar for the user who last posted to the current topic in the loop.
1199       *
1200       * @since 1.0.0
1201       *
1202       * @param array|string $args {
1203       *     Arguments for building the avatar.
1204       *     @type string $type   Avatar type. 'thumb' or 'full'. Default:
1205       *                          'thumb'.
1206       *     @type int    $width  Width of the avatar, in pixels. Default: the
1207       *                          width corresponding to $type.
1208       *                          See {@link bp_core_fetch_avatar()}.
1209       *     @type int    $height Height of the avatar, in pixels. Default:
1210       *                          the height corresponding to $type.
1211       *                          See {@link bp_core_fetch_avatar()}.
1212       *     @type string $alt    The text of the image's 'alt' attribute.
1213       *                          Default: 'Profile picture of [group name]'.
1214       * }
1215       * @return string User avatar.
1216       */
1217  	function bp_get_the_topic_last_poster_avatar( $args = '' ) {
1218          global $forum_template;
1219  
1220          $defaults = array(
1221              'type'   => 'thumb',
1222              'width'  => false,
1223              'height' => false,
1224              'alt'    => __( 'Profile picture of %s', 'buddypress' )
1225          );
1226  
1227          $r = wp_parse_args( $args, $defaults );
1228          extract( $r, EXTR_SKIP );
1229  
1230          /**
1231           * Filters the avatar for the user who last posted to the current topic in the loop.
1232           *
1233           * @since 1.0.0
1234           *
1235           * @param string $value HTML output for the avatar for the user who last posted.
1236           */
1237          return apply_filters( 'bp_get_the_topic_last_poster_avatar', bp_core_fetch_avatar( array( 'email' => $forum_template->topic->topic_last_poster_email, 'item_id' => $forum_template->topic->topic_last_poster, 'type' => $type, 'width' => $width, 'height' => $height, 'alt' => $alt ) ) );
1238      }
1239  
1240  /**
1241   * Output the start time of the current topic in the loop.
1242   *
1243   * @since 1.0.0
1244   */
1245  function bp_the_topic_start_time() {
1246      echo bp_get_the_topic_start_time();
1247  }
1248      /**
1249       * Return the start time of the current topic in the loop.
1250       *
1251       * @since 1.0.0
1252       *
1253       * @return string Start time of the current topic.
1254       */
1255  	function bp_get_the_topic_start_time() {
1256          global $forum_template;
1257  
1258          /**
1259           * Filters the start time of the current topic in the loop.
1260           *
1261           * @since 1.0.0
1262           *
1263           * @param string $topic_start_time Start time for the current topic.
1264           */
1265          return apply_filters( 'bp_get_the_topic_start_time', $forum_template->topic->topic_start_time );
1266      }
1267  
1268  /**
1269   * Output the topic time of the current topic in the loop.
1270   *
1271   * @since 1.0.0
1272   */
1273  function bp_the_topic_time() {
1274      echo bp_get_the_topic_time();
1275  }
1276      /**
1277       * Return the topic time of the current topic in the loop.
1278       *
1279       * @since 1.0.0
1280       *
1281       * @return string Topic time of the current topic.
1282       */
1283  	function bp_get_the_topic_time() {
1284          global $forum_template;
1285  
1286          /**
1287           * Filters the topic time of the current topic in the loop.
1288           *
1289           * @since 1.0.0
1290           *
1291           * @param string $topic_time Topic time for the current topic.
1292           */
1293          return apply_filters( 'bp_get_the_topic_time', $forum_template->topic->topic_time );
1294      }
1295  
1296  /**
1297   * Output the ID of the forum associated with the current topic in the loop.
1298   *
1299   * @since 1.0.0
1300   */
1301  function bp_the_topic_forum_id() {
1302      echo bp_get_the_topic_forum_id();
1303  }
1304      /**
1305       * Return the ID of the forum associated with the current topic in the loop.
1306       *
1307       * @since 1.0.0
1308       *
1309       * @return int ID of the forum associated with the current topic.
1310       */
1311  	function bp_get_the_topic_forum_id() {
1312          global $forum_template;
1313  
1314          /**
1315           * Filters the ID of the forum associated with the current topic in the loop.
1316           *
1317           * @since 1.0.0
1318           *
1319           * @param int $forum_id ID of the forum associated with the current topic.
1320           */
1321          return apply_filters( 'bp_get_the_topic_forum_id', $forum_template->topic->forum_id );
1322      }
1323  
1324  /**
1325   * Output the status of the current topic in the loop.
1326   *
1327   * @since 1.0.0
1328   */
1329  function bp_the_topic_status() {
1330      echo bp_get_the_topic_status();
1331  }
1332      /**
1333       * Return the status of the current topic in the loop.
1334       *
1335       * @since 1.0.0
1336       *
1337       * @return string Status of the current topic.
1338       */
1339  	function bp_get_the_topic_status() {
1340          global $forum_template;
1341  
1342          /**
1343           * Filters the status of the current topic in the loop.
1344           *
1345           * @since 1.0.0
1346           *
1347           * @param string $topic_status Status of the current topic.
1348           */
1349          return apply_filters( 'bp_get_the_topic_status', $forum_template->topic->topic_status );
1350      }
1351  
1352  /**
1353   * Output whether the current topic in the loop is open.
1354   *
1355   * @since 1.0.0
1356   */
1357  function bp_the_topic_is_topic_open() {
1358      echo bp_get_the_topic_is_topic_open();
1359  }
1360      /**
1361       * Return whether the current topic in the loop is open.
1362       *
1363       * @since 1.0.0
1364       *
1365       * @return string
1366       */
1367  	function bp_get_the_topic_is_topic_open() {
1368          global $forum_template;
1369  
1370          /**
1371           * Filters whether or not the current topic in the loop is open.
1372           *
1373           * @since 1.0.0
1374           *
1375           * @param string $topic_open Whether or not the current topic is open.
1376           */
1377          return apply_filters( 'bp_get_the_topic_is_topic_open', $forum_template->topic->topic_open );
1378      }
1379  
1380  /**
1381   * Output the ID of the last post in the current topic in the loop.
1382   *
1383   * @since 1.0.0
1384   */
1385  function bp_the_topic_last_post_id() {
1386      echo bp_get_the_topic_last_post_id();
1387  }
1388      /**
1389       * Return the ID of the last post in the current topic in the loop.
1390       *
1391       * @since 1.0.0
1392       *
1393       * @return int ID of the last post in the current topic.
1394       */
1395  	function bp_get_the_topic_last_post_id() {
1396          global $forum_template;
1397  
1398          /**
1399           * Filters the ID of the last post in the current topic in the loop.
1400           *
1401           * @since 1.0.0
1402           *
1403           * @param int $topic_last_post_id ID for the last post in the current topic.
1404           */
1405          return apply_filters( 'bp_get_the_topic_last_post_id', $forum_template->topic->topic_last_post_id );
1406      }
1407  
1408  /**
1409   * Output whether the current topic in the loop is sticky.
1410   *
1411   * @since 1.0.0
1412   */
1413  function bp_the_topic_is_sticky() {
1414      echo bp_get_the_topic_is_sticky();
1415  }
1416      /**
1417       * Return whether the current topic in the loop is sticky.
1418       *
1419       * @since 1.0.0
1420       *
1421       * @return bool
1422       */
1423  	function bp_get_the_topic_is_sticky() {
1424          global $forum_template;
1425  
1426          /**
1427           * Filters whether or not the current topic in the loop is sticky.
1428           *
1429           * @since 1.0.0
1430           *
1431           * @param bool $topic_sticky Whether or not the current topic is sticky.
1432           */
1433          return apply_filters( 'bp_get_the_topic_is_sticky', $forum_template->topic->topic_sticky );
1434      }
1435  
1436  /**
1437   * Output a 'x posts' string with the number of posts in the current topic.
1438   *
1439   * @since 1.0.0
1440   */
1441  function bp_the_topic_total_post_count() {
1442      echo bp_get_the_topic_total_post_count();
1443  }
1444      /**
1445       * Return a 'x posts' string with the number of posts in the current topic.
1446       *
1447       * @since 1.0.0
1448       *
1449       * @return string String of the form 'x posts'.
1450       */
1451  	function bp_get_the_topic_total_post_count() {
1452          global $forum_template;
1453  
1454          $output = _n( '%d post', '%d posts', (int) $forum_template->topic->topic_posts, 'buddypress' );
1455  
1456          /**
1457           * Filters a 'x posts' string with the number of posts in the current topic.
1458           *
1459           * @since 1.0.0
1460           *
1461           * @param string $value 'X posts' string value for the current topic.
1462           */
1463          return apply_filters( 'bp_get_the_topic_total_post_count', sprintf( $output, $forum_template->topic->topic_posts ) );
1464      }
1465  
1466  /**
1467   * Output the total number of posts in the current topic in the loop.
1468   *
1469   * @since 1.1.0
1470   */
1471  function bp_the_topic_total_posts() {
1472      echo bp_get_the_topic_total_posts();
1473  }
1474      /**
1475       * Return the total number of posts in the current topic in the loop.
1476       *
1477       * @since 1.1.0
1478       *
1479       * @return int Total number of posts in the current topic.
1480       */
1481  	function bp_get_the_topic_total_posts() {
1482          global $forum_template;
1483  
1484          /**
1485           * Filters the total number of posts in the current topic in the loop.
1486           *
1487           * @since 1.2.4
1488           *
1489           * @param int $topic_posts Total number of posts in the current topic.
1490           */
1491          return apply_filters( 'bp_get_the_topic_total_posts', $forum_template->topic->topic_posts );
1492      }
1493  
1494  /**
1495   * Output the tag count for the current topic in the loop.
1496   *
1497   * @since 1.0.0
1498   */
1499  function bp_the_topic_tag_count() {
1500      echo bp_get_the_topic_tag_count();
1501  }
1502      /**
1503       * Return the tag count for the current topic in the loop.
1504       *
1505       * @since 1.0.0
1506       *
1507       * @return int Tag count for the current topic.
1508       */
1509  	function bp_get_the_topic_tag_count() {
1510          global $forum_template;
1511  
1512          /**
1513           * Filters the tag count for the current topic in the loop.
1514           *
1515           * @since 1.0.0
1516           *
1517           * @param int $tag_count Tag count for the current topic.
1518           */
1519          return apply_filters( 'bp_get_the_topic_tag_count', $forum_template->topic->tag_count );
1520      }
1521  
1522  /**
1523   * Output the permalink of the current topic in the loop.
1524   *
1525   * @since 1.0.0
1526   */
1527  function bp_the_topic_permalink() {
1528      echo bp_get_the_topic_permalink();
1529  }
1530      /**
1531       * Return the permalink for the current topic in the loop.
1532       *
1533       * @since 1.0.0
1534       *
1535       * @return string Permalink for the current topic.
1536       */
1537  	function bp_get_the_topic_permalink() {
1538          global $forum_template;
1539  
1540          // The topic is in a loop where its parent object is loaded.
1541          if ( bp_get_the_topic_object_slug() ) {
1542              $permalink = trailingslashit( bp_get_groups_directory_permalink() . bp_get_the_topic_object_slug() . '/forum' );
1543  
1544          // We are viewing a single group topic, so use the current item.
1545          } elseif ( bp_is_group_forum_topic() ) {
1546              $permalink = trailingslashit( bp_get_groups_directory_permalink() . bp_current_item() . '/forum' );
1547  
1548          // We are unsure what the context is, so fallback to forum root slug.
1549          } elseif ( bp_is_single_item() ) {
1550              $permalink = trailingslashit( bp_get_root_domain() . '/' . bp_get_forums_root_slug() . '/' . bp_current_item() );
1551  
1552          // This is some kind of error situation, so use forum root.
1553          } else {
1554              $permalink = trailingslashit( bp_get_root_domain() . '/' . bp_get_forums_root_slug() );
1555          }
1556  
1557          /**
1558           * Filters the permalink for the current topic in the loop.
1559           *
1560           * @since 1.0.0
1561           *
1562           * @param string $value Permalink for the current topic in the loop.
1563           */
1564          return apply_filters( 'bp_get_the_topic_permalink', trailingslashit( $permalink . 'topic/' . $forum_template->topic->topic_slug ) );
1565      }
1566  
1567  /**
1568   * Output a 'since' string describing when the current topic was created.
1569   *
1570   * @since 1.0.0
1571   */
1572  function bp_the_topic_time_since_created() {
1573      echo bp_get_the_topic_time_since_created();
1574  }
1575      /**
1576       * Return a 'since' string describing when the current topic was created.
1577       *
1578       * @since 1.0.0
1579       *
1580       * @see bp_core_time_since() for a description of return value.
1581       *
1582       * @return string
1583       */
1584  	function bp_get_the_topic_time_since_created() {
1585          global $forum_template;
1586  
1587          /**
1588           * Filters a 'time since' string describing when the current topic was created.
1589           *
1590           * @since 1.0.0
1591           *
1592           * @param string $value 'Time since' value for the current topic.
1593           */
1594          return apply_filters( 'bp_get_the_topic_time_since_created', bp_core_time_since( strtotime( $forum_template->topic->topic_start_time ) ) );
1595      }
1596  
1597  /**
1598   * Output an excerpt from the latest post of the current topic in the loop.
1599   *
1600   * @since 1.0.0
1601   *
1602   * @param array|string $args See {@bp_get_the_topic_latest_post_excerpt()}.
1603   */
1604  function bp_the_topic_latest_post_excerpt( $args = '' ) {
1605      echo bp_get_the_topic_latest_post_excerpt( $args );
1606  }
1607      /**
1608       * Return an excerpt from the latest post of the current topic in the loop.
1609       *
1610       * @since 1.0.0
1611       *
1612       * @param array|string $args {
1613       *     @type int $length The length of the excerpted text. Default: 225.
1614       * }
1615       * @return string Post excerpt.
1616       */
1617  	function bp_get_the_topic_latest_post_excerpt( $args = '' ) {
1618          global $forum_template;
1619  
1620          $defaults = array(
1621              'length' => 225
1622          );
1623  
1624          $r = wp_parse_args( $args, $defaults );
1625          extract( $r, EXTR_SKIP );
1626  
1627          $post = bp_forums_get_post( $forum_template->topic->topic_last_post_id );
1628          $post = bp_create_excerpt( $post->post_text, $length );
1629  
1630          /**
1631           * Filters an excerpt from the latest post of the current topic in the loop.
1632           *
1633           * @since 1.0.0
1634           *
1635           * @param string $post   Post exceprt for the current topic.
1636           * @param string $length String length to trim excerpt down to.
1637           */
1638          return apply_filters( 'bp_get_the_topic_latest_post_excerpt', $post, $length );
1639      }
1640  
1641  /**
1642   * Output a 'since' string describing when the last post in the current topic was created.
1643   *
1644   * @since 1.0.0
1645   */
1646  function bp_the_topic_time_since_last_post() {
1647      echo bp_get_the_topic_time_since_last_post();
1648  }
1649      /**
1650       * Return a 'since' string describing when the last post in the current topic was created.
1651       *
1652       * @since 1.0.0
1653       *
1654       * @see bp_core_time_since() for a description of return value.
1655       *
1656       * @return string
1657       */
1658  	function bp_get_the_topic_time_since_last_post() {
1659          global $forum_template;
1660  
1661          /**
1662           * Filters a 'time since' string describing when the last post in the current topic was created.
1663           *
1664           * @since 1.0.0
1665           *
1666           * @param string $value The 'time since' string for the last post in the current topic.
1667           */
1668          return apply_filters( 'bp_get_the_topic_time_since_last_post', bp_core_time_since( strtotime( $forum_template->topic->topic_time ) ) );
1669      }
1670  
1671  /**
1672   * Output whether the current topic in the loop belongs to the logged-in user.
1673   *
1674   * @since 1.1.0
1675   */
1676  function bp_the_topic_is_mine() {
1677      echo bp_get_the_topic_is_mine();
1678  }
1679      /**
1680       * Does the current topic belong to the logged-in user?
1681       *
1682       * @since 1.1.0
1683       *
1684       * @return bool True if the current topic in the loop was created by
1685       *              the logged-in user, otherwise false.
1686       */
1687  	function bp_get_the_topic_is_mine() {
1688          global $forum_template;
1689  
1690          return bp_loggedin_user_id() == $forum_template->topic->topic_poster;
1691      }
1692  
1693  /**
1694   * Output the admin links for the current topic in the loop.
1695   *
1696   * @since 1.1.0
1697   *
1698   * @see bp_get_the_topic_admin_links() for a description of arguments.
1699   *
1700   * @param array|string $args See {@link bp_get_the_topic_admin_links()}.
1701   */
1702  function bp_the_topic_admin_links( $args = '' ) {
1703      echo bp_get_the_topic_admin_links( $args );
1704  }
1705      /**
1706       * Return the admin links for the current topic in the loop.
1707       *
1708       * @since 1.1.0
1709       *
1710       * @param array|string $args {
1711       *     @type string $separator The character to use when separating links. Default: '|'.
1712       * }
1713       * @return string HTML string containing the admin links for the current topic.
1714       */
1715  	function bp_get_the_topic_admin_links( $args = '' ) {
1716          global $forum_template;
1717  
1718          $defaults = array(
1719              'separator' => '|'
1720          );
1721  
1722          $r = wp_parse_args( $args, $defaults );
1723          extract( $r, EXTR_SKIP );
1724  
1725          $links[] = '<a href="' . wp_nonce_url( bp_get_the_topic_permalink() . 'edit', 'bp_forums_edit_topic' ) . '">' . __( 'Edit Topic', 'buddypress' ) . '</a>';
1726  
1727          if ( bp_is_item_admin() || bp_is_item_mod() || bp_current_user_can( 'bp_moderate' ) ) {
1728              if ( 0 == (int) $forum_template->topic->topic_sticky )
1729                  $links[] = '<a href="' . wp_nonce_url( bp_get_the_topic_permalink() . 'stick', 'bp_forums_stick_topic' ) . '">' . __( 'Sticky Topic', 'buddypress' ) . '</a>';
1730              else
1731                  $links[] = '<a href="' . wp_nonce_url( bp_get_the_topic_permalink() . 'unstick', 'bp_forums_unstick_topic' ) . '">' . __( 'Un-stick Topic', 'buddypress' ) . '</a>';
1732  
1733              if ( 0 == (int) $forum_template->topic->topic_open )
1734                  $links[] = '<a href="' . wp_nonce_url( bp_get_the_topic_permalink() . 'open', 'bp_forums_open_topic' ) . '">' . __( 'Open Topic', 'buddypress' ) . '</a>';
1735              else
1736                  $links[] = '<a href="' . wp_nonce_url( bp_get_the_topic_permalink() . 'close', 'bp_forums_close_topic' ) . '">' . __( 'Close Topic', 'buddypress' ) . '</a>';
1737  
1738              $links[] = '<a class="confirm" id="topic-delete-link" href="' . wp_nonce_url( bp_get_the_topic_permalink() . 'delete', 'bp_forums_delete_topic' ) . '">' . __( 'Delete Topic', 'buddypress' ) . '</a>';
1739          }
1740  
1741          return implode( ' ' . $separator . ' ', (array) $links );
1742      }
1743  
1744  /**
1745   * Output the CSS class for the current topic in the loop.
1746   *
1747   * @since 1.1.0
1748   */
1749  function bp_the_topic_css_class() {
1750      echo bp_get_the_topic_css_class();
1751  }
1752      /**
1753       * Return the CSS class for the current topic in the loop.
1754       *
1755       * This class may contain keywords like 'alt', 'sticky', or 'closed',
1756       * based on context.
1757       *
1758       * @since 1.1.0
1759       *
1760       * @return string Contents of the 'class' attribute.
1761       */
1762  	function bp_get_the_topic_css_class() {
1763          global $forum_template;
1764  
1765          $class = false;
1766  
1767          if ( $forum_template->current_topic % 2 == 1 )
1768              $class .= 'alt';
1769  
1770          if ( isset( $forum_template->topic->topic_sticky ) && 1 == (int) $forum_template->topic->topic_sticky )
1771              $class .= ' sticky';
1772  
1773          if ( !isset( $forum_template->topic->topic_open ) || 0 == (int) $forum_template->topic->topic_open )
1774              $class .= ' closed';
1775  
1776          /**
1777           * Filters the CSS class for the current topic in the loop.
1778           *
1779           * This class may contain keywords like 'alt', 'sticky', or 'closed',
1780           * based on context.
1781           *
1782           * @since 1.2.4
1783           *
1784           * @param string $value Concatenated classes for the current topic in the loop.
1785           */
1786          return apply_filters( 'bp_get_the_topic_css_class', trim( $class ) );
1787      }
1788  
1789  /**
1790   * Output the permalink to the 'personal' topics tab.
1791   *
1792   * @since 1.1.0
1793   */
1794  function bp_my_forum_topics_link() {
1795      echo bp_get_my_forum_topics_link();
1796  }
1797      /**
1798       * Return the permalink to the 'personal' topics tab.
1799       *
1800       * @since 1.1.0
1801       *
1802       * @return string Link to the 'personal' topics tab.
1803       */
1804  	function bp_get_my_forum_topics_link() {
1805          /**
1806           * Filters the permalink to the 'personal' topics tab.
1807           *
1808           * @since 1.1.0
1809           *
1810           * @param string $value Permalink to the 'personal' topics tab.
1811           */
1812          return apply_filters( 'bp_get_my_forum_topics_link', bp_get_root_domain() . '/' . bp_get_forums_root_slug() . '/personal/' );
1813      }
1814  
1815  /**
1816   * Output the permalink to the 'unreplied' topics tab.
1817   *
1818   * @since 1.1.0
1819   */
1820  function bp_unreplied_forum_topics_link() {
1821      echo bp_get_unreplied_forum_topics_link();
1822  }
1823      /**
1824       * Return the permalink to the 'unreplied' topics tab.
1825       *
1826       * @since 1.1.0
1827       *
1828       * @return string Link to the 'unreplied' topics tab.
1829       */
1830  	function bp_get_unreplied_forum_topics_link() {
1831          /**
1832           * Filters the permalink to the 'unreplied' topics tab.
1833           *
1834           * @since 1.1.0
1835           *
1836           * @param string $value Permalink to the 'unreplied' topics tab.
1837           */
1838          return apply_filters( 'bp_get_unreplied_forum_topics_link', bp_get_root_domain() . '/' . bp_get_forums_root_slug() . '/unreplied/' );
1839      }
1840  
1841  /**
1842   * Output the permalink to the 'popular' topics tab.
1843   *
1844   * @since 1.1.0
1845   */
1846  function bp_popular_forum_topics_link() {
1847      echo bp_get_popular_forum_topics_link();
1848  }
1849      /**
1850       * Return the permalink to the 'popular' topics tab.
1851       *
1852       * @since 1.1.0
1853       *
1854       * @return string Link to the 'popular' topics tab.
1855       */
1856  	function bp_get_popular_forum_topics_link() {
1857          /**
1858           * Filters the permalink to the 'popular' topics tab.
1859           *
1860           * @since 1.1.0
1861           *
1862           * @param string $value Permalink to the 'popular' topics tab.
1863           */
1864          return apply_filters( 'bp_get_popular_forum_topics_link', bp_get_root_domain() . '/' . bp_get_forums_root_slug() . '/popular/' );
1865      }
1866  
1867  /**
1868   * Output the link to the forums directory.
1869   *
1870   * @since 1.1.0
1871   */
1872  function bp_newest_forum_topics_link() {
1873      echo bp_get_newest_forum_topics_link();
1874  }
1875      /**
1876       * Return the link to the forums directory.
1877       *
1878       * @since 1.1.0
1879       *
1880       * @return string Link to the forums directory.
1881       */
1882  	function bp_get_newest_forum_topics_link() {
1883          /**
1884           * Filters the link to the forums directory.
1885           *
1886           * @since 1.1.0
1887           *
1888           * @param string $value Link to the forums directory.
1889           */
1890          return apply_filters( 'bp_get_newest_forum_topics_link', bp_get_root_domain() . '/' . bp_get_forums_root_slug() . '/' );
1891      }
1892  
1893  /**
1894   * Output the currently viewed topic list type.
1895   *
1896   * @since 1.1.0
1897   */
1898  function bp_forum_topic_type() {
1899      echo bp_get_forum_topic_type();
1900  }
1901      /**
1902       * Return the currently viewed topic list type.
1903       *
1904       * Eg, 'newest', 'popular', etc.
1905       *
1906       * @since 1.1.0
1907       *
1908       * @return string Type of the currently viewed topic list.
1909       */
1910  	function bp_get_forum_topic_type() {
1911  
1912          if ( !bp_is_directory() || !bp_current_action() )
1913              return 'newest';
1914  
1915          /**
1916           * Filters the currently viewed topic list type.
1917           *
1918           * Eg, 'newest', 'popular', etc.
1919           *
1920           * @since 1.1.0
1921           *
1922           * @param string $value Currently viewed topic list type.
1923           */
1924          return apply_filters( 'bp_get_forum_topic_type', bp_current_action() );
1925      }
1926  
1927  /**
1928   * Output the value of bp_get_forum_topic_new_reply_link().
1929   *
1930   * @since 1.5.0
1931   */
1932  function bp_forum_topic_new_reply_link() {
1933      echo esc_url( bp_get_forum_topic_new_reply_link() );
1934  }
1935      /**
1936       * Return the permalink for the New Reply button at the top of forum topics.
1937       *
1938       * @since 1.5.0
1939       *
1940       *       modify.
1941       *
1942       * @return string The URL for the New Reply link.
1943       */
1944  	function bp_get_forum_topic_new_reply_link() {
1945          global $topic_template;
1946  
1947          if ( $topic_template->pag->total_pages == $topic_template->pag_page ) {
1948              // If we are on the last page, no need for a URL base.
1949              $link = '';
1950          } else {
1951              // Create a link to the last page for the topic.
1952              $link = add_query_arg( array(
1953                  'topic_page' =>    $topic_template->pag->total_pages,
1954                  'num'        => $topic_template->pag_num
1955              ), bp_get_the_topic_permalink() );
1956          }
1957  
1958          /**
1959           * Filters the permalink for the New Reply button at the top of forum topics.
1960           *
1961           * @since 1.5.0
1962           *
1963           * @param string $value Permalink for the New Reply button.
1964           */
1965          return apply_filters( 'bp_get_forum_topic_new_reply_link', $link . '#post-topic-reply', $link );
1966      }
1967  
1968  /**
1969   * Output the currently viewed tag name.
1970   *
1971   * @since 1.1.0
1972   *
1973   * @todo Deprecate?
1974   */
1975  function bp_forums_tag_name() {
1976      echo bp_get_forums_tag_name();
1977  }
1978      /**
1979       * Return the currently viewed tag name.
1980       *
1981       * @since 1.1.0
1982       *
1983       * @todo Deprecate? Seems unused
1984       *
1985       * @return bool|string
1986       */
1987  	function bp_get_forums_tag_name() {
1988          $tag_name = bp_is_directory() && bp_is_forums_component() ? bp_action_variable( 0 ) : false;
1989  
1990          return apply_filters( 'bp_get_forums_tag_name', $tag_name );
1991      }
1992  
1993  /**
1994   * Output the pagination links for the current topic list.
1995   *
1996   * @since 1.0.0
1997   */
1998  function bp_forum_pagination() {
1999      echo bp_get_forum_pagination();
2000  }
2001      /**
2002       * Return the pagination links for the current topic list.
2003       *
2004       * @since 1.0.0
2005       *
2006       * @return string HTML pagination links.
2007       */
2008  	function bp_get_forum_pagination() {
2009          global $forum_template;
2010  
2011          /**
2012           * Filters the pagination links for the current topic list.
2013           *
2014           * @since 1.0.0
2015           *
2016           * @param string $pag_links HTML pagination links.
2017           */
2018          return apply_filters( 'bp_get_forum_pagination', $forum_template->pag_links );
2019      }
2020  
2021  /**
2022   * Output the pagination count for the current topic list.
2023   *
2024   * @since 1.0.0
2025   */
2026  function bp_forum_pagination_count() {
2027      echo bp_get_forum_pagination_count();
2028  }
2029      /**
2030       * Return the pagination count for the current topic list.
2031       *
2032       * The "count" is a string of the form "Viewing x of y topics".
2033       *
2034       * @since 1.5.0
2035       *
2036       * @return string
2037       */
2038  	function bp_get_forum_pagination_count() {
2039          global $forum_template;
2040  
2041          $start_num  = intval( ( $forum_template->pag_page - 1 ) * $forum_template->pag_num ) + 1;
2042          $from_num   = bp_core_number_format( $start_num );
2043          $to_num     = bp_core_number_format( ( $start_num + ( $forum_template->pag_num - 1  ) > $forum_template->total_topic_count ) ? $forum_template->total_topic_count : $start_num + ( $forum_template->pag_num - 1 ) );
2044          $total      = bp_core_number_format( $forum_template->total_topic_count );
2045          $pag_filter = false;
2046  
2047          if ( 'tags' == $forum_template->type && !empty( $forum_template->search_terms ) )
2048              $pag_filter = sprintf( __( ' matching tag "%s"', 'buddypress' ), $forum_template->search_terms );
2049  
2050          if ( 1 == $forum_template->total_topic_count ) {
2051              $message = __( 'Viewing 1 topic', 'buddypress' );
2052          } else {
2053              $message = sprintf( _n( 'Viewing %1$s - %2$s of %3$s topic', 'Viewing %1$s - %2$s of %3$s topics', (int) $forum_template->total_topic_count, 'buddypress' ), $from_num, $to_num, $total, $pag_filter );
2054          }
2055  
2056          /**
2057           * Filters the pagination count for the current topic list.
2058           *
2059           * @since 1.5.0
2060           *
2061           * @param string $message  Pagination count for the current topic list.
2062           * @param string $from_num Low end count in the view.
2063           * @param string $to_num   High end count in the view.
2064           * @param string $total    Total count of topics found.
2065           */
2066          return apply_filters( 'bp_get_forum_pagination_count', $message, $from_num, $to_num, $total );
2067      }
2068  
2069  /**
2070   * Are we currently on an Edit Topic screen?
2071   *
2072   * @since 1.1.0
2073   *
2074   * @return bool True if currently editing a topic, otherwise false.
2075   */
2076  function bp_is_edit_topic() {
2077  
2078      if ( bp_is_action_variable( 'post' ) && bp_is_action_variable( 'edit' ) )
2079          return false;
2080  
2081      return true;
2082  }
2083  
2084  /**
2085   * The single forum topic template loop class.
2086   *
2087   * Responsible for loading a topic's posts into a loop for display.
2088   *
2089   * @since 1.0.0
2090   */
2091  class BP_Forums_Template_Topic {
2092      /**
2093       * The loop iterator.
2094       *
2095       * @since 1.0.0
2096       * @var int
2097       */
2098      public $current_post = -1;
2099  
2100      /**
2101       * The number of posts returned by the paged query.
2102       *
2103       * @since 1.0.0
2104       * @var int
2105       */
2106      public $post_count;
2107  
2108      /**
2109       * Array of posts located by the query.
2110       *
2111       * @since 1.0.0
2112       * @var array
2113       */
2114      public $posts;
2115  
2116      /**
2117       * The post object currently being iterated on.
2118       *
2119       * @since 1.0.0
2120       * @var object
2121       */
2122      public $post;
2123  
2124      /**
2125       * The ID of the forum whose topic is being queried.
2126       *
2127       * @since 1.5.0
2128       * @var int
2129       */
2130      public $forum_id;
2131  
2132      /**
2133       * The ID of the topic whose posts are being queried.
2134       *
2135       * @since 1.0.0
2136       * @var int
2137       */
2138      public $topic_id;
2139  
2140      /**
2141       * The topic object to which the posts belong.
2142       *
2143       * @since 1.0.0
2144       * @var object
2145       */
2146      public $topic;
2147  
2148      /**
2149       * A flag for whether the loop is currently being iterated.
2150       *
2151       * @since 1.0.0
2152       * @var bool
2153       */
2154      public $in_the_loop;
2155  
2156      /**
2157       * Contains a 'total_pages' property holding total number of pages in
2158       * this loop.
2159       *
2160       * @since 1.2.0
2161       * @var stdClass
2162       */
2163      public $pag;
2164  
2165      /**
2166       * The page number being requested.
2167       *
2168       * @since 1.0.0
2169       * @var int
2170       */
2171      public $pag_page;
2172  
2173      /**
2174       * The number of items being requested per page.
2175       *
2176       * @since 1.0.0
2177       * @var int
2178       */
2179      public $pag_num;
2180  
2181      /**
2182       * An HTML string containing pagination links.
2183       *
2184       * @since 1.0.0
2185       * @var string
2186       */
2187      public $pag_links;
2188  
2189      /**
2190       * The total number of posts matching the query parameters.
2191       *
2192       * @since 1.0.0
2193       * @var int
2194       */
2195      public $total_post_count;
2196  
2197      /**
2198       * Whether requesting a single topic. Not currently used.
2199       *
2200       * @since 1.0.0
2201       * @var bool
2202       */
2203      public $single_post = false;
2204  
2205      /**
2206       * Term to sort by.
2207       *
2208       * @since 1.0.0
2209       * @var string
2210       */
2211      public $sort_by;
2212  
2213      /**
2214       * Sort order.
2215       *
2216       * @since 1.0.0
2217       * @var string
2218       */
2219      public $order;
2220  
2221      /**
2222       * Constructor method.
2223       *
2224       * @since 1.5.0
2225       *
2226       * @param int    $topic_id ID of the topic whose posts are being requested.
2227       * @param int    $per_page Number of items to return per page.
2228       * @param int    $max Max records to return.
2229       * @param string $order Direction to order results.
2230       */
2231  	function __construct( $topic_id, $per_page, $max, $order ) {
2232          global $forum_template;
2233  
2234          if ( !isset( $forum_template ) ) {
2235              $forum_template = new stdClass;
2236          }
2237  
2238          $this->pag_page        = isset( $_REQUEST['topic_page'] ) ? intval( $_REQUEST['topic_page'] ) : 1;
2239          $this->pag_num         = isset( $_REQUEST['num'] ) ? intval( $_REQUEST['num'] ) : $per_page;
2240  
2241          $this->order           = $order;
2242          $this->topic_id        = $topic_id;
2243          $forum_template->topic = (object) bp_forums_get_topic_details( $this->topic_id );
2244          $this->forum_id        = $forum_template->topic->forum_id;
2245  
2246          $this->posts           = bp_forums_get_topic_posts( array( 'topic_id' => $this->topic_id, 'page' => $this->pag_page, 'per_page' => $this->pag_num, 'order' => $this->order ) );
2247  
2248          if ( !$this->posts ) {
2249              $this->post_count       = 0;
2250              $this->total_post_count = 0;
2251          } else {
2252              if ( !$max || $max >= (int) $forum_template->topic->topic_posts ) {
2253                  $this->total_post_count = (int) $forum_template->topic->topic_posts;
2254              } else {
2255                  $this->total_post_count = (int) $max;
2256              }
2257  
2258              if ( $max ) {
2259                  if ( $max >= count( $this->posts ) ) {
2260                      $this->post_count = count( $this->posts );
2261                  } else {
2262                      $this->post_count = (int) $max;
2263                  }
2264              } else {
2265                  $this->post_count = count( $this->posts );
2266              }
2267          }
2268  
2269          // Load topic tags.
2270          $this->topic_tags = bb_get_topic_tags( $this->topic_id );
2271  
2272          $this->pag = new stdClass;
2273  
2274          if ( (int) $this->total_post_count && (int) $this->pag_num ) {
2275              $this->pag_links = paginate_links( array(
2276                  'base'      => add_query_arg( array( 'topic_page' => '%#%', 'num' => (int) $this->pag_num ) ),
2277                  'format'    => '',
2278                  'total'     => ceil( (int) $this->total_post_count / (int) $this->pag_num ),
2279                  'current'   => $this->pag_page,
2280                  'prev_text' => _x( '&larr;', 'Forum thread pagination previous text', 'buddypress' ),
2281                  'next_text' => _x( '&rarr;', 'Forum thread pagination next text', 'buddypress' ),
2282                  'mid_size'  => 1,
2283                  'add_args'  => array(),
2284              ) );
2285  
2286              $this->pag->total_pages = ceil( (int) $this->total_post_count / (int) $this->pag_num );
2287          } else {
2288              $this->pag->total_pages = 1;
2289          }
2290      }
2291  
2292      /**
2293       * Whether there are posts available in the loop.
2294       *
2295       * @since 1.0.0
2296       *
2297       * @see bp_has_forum_topic_posts()
2298       *
2299       * @return bool True if there are items in the loop, otherwise false.
2300       */
2301  	function has_posts() {
2302          if ( $this->post_count )
2303              return true;
2304  
2305          return false;
2306      }
2307  
2308      /**
2309       * Set up the next post and iterate index.
2310       *
2311       * @since 1.0.0
2312       *
2313       * @return object The next post to iterate over.
2314       */
2315  	function next_post() {
2316          $this->current_post++;
2317          $this->post = $this->posts[$this->current_post];
2318  
2319          return $this->post;
2320      }
2321  
2322      /**
2323       * Rewind the posts and reset post index.
2324       *
2325       * @since 1.0.0
2326       */
2327  	function rewind_posts() {
2328          $this->current_post = -1;
2329          if ( $this->post_count > 0 ) {
2330              $this->post = $this->posts[0];
2331          }
2332      }
2333  
2334      /**
2335       * Whether there are posts left in the loop to iterate over.
2336       *
2337       * This method is used by {@link bp_forum_topic_posts()} as part of
2338       * the while loop that controls iteration inside the blogs loop, eg:
2339       *     while ( bp_forum_topic_posts() ) { ...
2340       *
2341       * @since 1.0.0
2342       *
2343       * @see bp_forum_topic_posts()
2344       *
2345       * @return bool True if there are more posts to show, otherwise false.
2346       */
2347  	function user_posts() {
2348          if ( $this->current_post + 1 < $this->post_count ) {
2349              return true;
2350          } elseif ( $this->current_post + 1 == $this->post_count ) {
2351  
2352              /**
2353               * Fires right before the rewinding of user posts.
2354               *
2355               * @since 1.5.0
2356               */
2357              do_action('topic_loop_end');
2358              // Do some cleaning up after the loop.
2359              $this->rewind_posts();
2360          }
2361  
2362          $this->in_the_loop = false;
2363          return false;
2364      }
2365  
2366      /**
2367       * Set up the current topic in the loop.
2368       *
2369       * @since 1.0.0
2370       *
2371       * @see bp_the_forum_topic_post()
2372       */
2373  	function the_post() {
2374  
2375          $this->in_the_loop = true;
2376          $this->post = $this->next_post();
2377          $this->post = (object)$this->post;
2378  
2379          if ( $this->current_post == 0 ) {
2380  
2381              /**
2382               * Fires if the current post item is the first in the topic loop.
2383               *
2384               * @since 1.5.0
2385               */
2386              do_action( 'topic_loop_start' );
2387          }
2388      }
2389  }
2390  
2391  /**
2392   * Initiate the loop for a single topic's posts.
2393   *
2394   * @since 1.1.0
2395   *
2396   * @param array|string $args {
2397   *     Arguments for limiting the contents of the topic posts loop.
2398   *     @type int    $topic_id ID of the topic to which the posts belong.
2399   *     @type int    $per_page Number of items to return per page. Default: 15.
2400   *     @type int    $max      Max items to return. Default: false.
2401   *     @type string $order   'ASC' or 'DESC'.
2402   * }
2403   * @return bool True when posts are found corresponding to the args,
2404   *              otherwise false.
2405   */
2406  function bp_has_forum_topic_posts( $args = '' ) {
2407      global $topic_template;
2408  
2409      $defaults = array(
2410          'topic_id' => false,
2411          'per_page' => 15,
2412          'max'      => false,
2413          'order'    => 'ASC'
2414      );
2415  
2416      $r = bp_parse_args( $args, $defaults, 'has_forum_topic_posts' );
2417      extract( $r, EXTR_SKIP );
2418  
2419      if ( empty( $topic_id ) && bp_is_groups_component() && bp_is_current_action( 'forum' ) && bp_is_action_variable( 'topic', 0 ) && bp_action_variable( 1 ) )
2420          $topic_id = bp_forums_get_topic_id_from_slug( bp_action_variable( 1 ) );
2421      elseif ( empty( $topic_id ) && bp_is_forums_component() && bp_is_current_action( 'topic' ) && bp_action_variable( 0 ) )
2422          $topic_id = bp_forums_get_topic_id_from_slug( bp_action_variable( 0 ) );
2423  
2424      if ( empty( $topic_id ) ) {
2425          return false;
2426  
2427      } else {
2428          $topic_template = new BP_Forums_Template_Topic( (int) $topic_id, $per_page, $max, $order );
2429  
2430          // Current topic forum_id needs to match current_group forum_id.
2431          if ( bp_is_groups_component() && $topic_template->forum_id != groups_get_groupmeta( bp_get_current_group_id(), 'forum_id' ) )
2432              return false;
2433      }
2434  
2435      /**
2436       * Filters whether or not there are topics to display.
2437       *
2438       * @since 1.1.0
2439       *
2440       * @param bool                     $value          Whether or not there are topics.
2441       * @param BP_Forums_Template_Topic $topic_template Topic template global to use when rendering.
2442       */
2443      return apply_filters( 'bp_has_topic_posts', $topic_template->has_posts(), $topic_template );
2444  }
2445  
2446  /**
2447   * Determine whether there are posts left in the loop.
2448   *
2449   * @since 1.1.0
2450   *
2451   * @return bool True when posts are found.
2452   */
2453  function bp_forum_topic_posts() {
2454      global $topic_template;
2455      return $topic_template->user_posts();
2456  }
2457  
2458  /**
2459   * Set up the current post in the loop.
2460   *
2461   * @since 1.1.0
2462   *
2463   * @return object
2464   */
2465  function bp_the_forum_topic_post() {
2466      global $topic_template;
2467      return $topic_template->the_post();
2468  }
2469  
2470  /**
2471   * Output the ID of the current post in the loop.
2472   *
2473   * @since 1.0.0
2474   */
2475  function bp_the_topic_post_id() {
2476      echo bp_get_the_topic_post_id();
2477  }
2478      /**
2479       * Return the ID of the current post in the loop.
2480       *
2481       * @since 1.0.0
2482       *
2483       * @return int ID of the current post in the loop.
2484       */
2485  	function bp_get_the_topic_post_id() {
2486          global $topic_template;
2487  
2488          /**
2489           * Filters the ID of the current post in the loop.
2490           *
2491           * @since 1.0.0
2492           *
2493           * @param int $post_id ID of the current post.
2494           */
2495          return apply_filters( 'bp_get_the_topic_post_id', $topic_template->post->post_id );
2496      }
2497  
2498  /**
2499   * Output the content of the current post in the loop.
2500   *
2501   * @since 1.0.0
2502   */
2503  function bp_the_topic_post_content() {
2504      echo bp_get_the_topic_post_content();
2505  }
2506      /**
2507       * Return the content of the current post in the loop.
2508       *
2509       * @since 1.0.0
2510       *
2511       * @return string Content of the current post.
2512       */
2513  	function bp_get_the_topic_post_content() {
2514          global $topic_template;
2515  
2516          /**
2517           * Filters the content of the current post in the loop.
2518           *
2519           * @since 1.0.0
2520           *
2521           * @param string $post_text The content of the current post.
2522           */
2523          return apply_filters( 'bp_get_the_topic_post_content', stripslashes( $topic_template->post->post_text ) );
2524      }
2525  
2526  /**
2527   * Output the CSS class of the current post in the loop.
2528   *
2529   * @since 1.2.4
2530   */
2531  function bp_the_topic_post_css_class() {
2532      echo bp_get_the_topic_post_css_class();
2533  }
2534      /**
2535       * Return the CSS class of the current post in the loop.
2536       *
2537       * May contain strings 'alt', 'deleted', or 'open', depending on
2538       * context.
2539       *
2540       * @since 1.2.4
2541       *
2542       * @return string String to put in the 'class' attribute of the current
2543       *                post.
2544       */
2545  	function bp_get_the_topic_post_css_class() {
2546          global $topic_template;
2547  
2548          $class = false;
2549  
2550          if ( $topic_template->current_post % 2 == 1 )
2551              $class .= 'alt';
2552  
2553          if ( 1 == (int) $topic_template->post->post_status )
2554              $class .= ' deleted';
2555  
2556          if ( 0 == (int) $topic_template->post->post_status )
2557              $class .= ' open';
2558  
2559          /**
2560           * Filters the CSS class for the current post in the loop.
2561           *
2562           * This class may contain keywords like 'alt', 'deleted', or 'open',
2563           * based on context.
2564           *
2565           * @since 1.2.4
2566           *
2567           * @param string $value Concatenated classes for the current post in the loop.
2568           */
2569          return apply_filters( 'bp_get_the_topic_post_css_class', trim( $class ) );
2570      }
2571  
2572  /**
2573   * Output the avatar of the user who posted the current post in the loop.
2574   *
2575   * @since 1.0.0
2576   *
2577   * @see bp_get_the_topic_post_poster_avatar() for a description of arguments.
2578   *
2579   * @param array|string $args See {@link bp_get_the_topic_post_poster_avatar()}.
2580   */
2581  function bp_the_topic_post_poster_avatar( $args = '' ) {
2582      echo bp_get_the_topic_post_poster_avatar( $args );
2583  }
2584      /**
2585       * Return the avatar of the user who posted the current post in the loop.
2586       *
2587       * @since 1.0.0
2588       *
2589       * @param array|string $args {
2590       *     Arguments for building the avatar.
2591       *     @type string $type   Avatar type. 'thumb' or 'full'. Default:
2592       *                          'thumb'.
2593       *     @type int    $width  Width of the avatar, in pixels. Default: the
2594       *                          width corresponding to $type.
2595       *                          See {@link bp_core_fetch_avatar()}.
2596       *     @type int    $height Height of the avatar, in pixels. Default: the
2597       *                          height corresponding to $type.
2598       *                          See {@link bp_core_fetch_avatar()}.
2599       *     @type string $alt    The text of the image's 'alt' attribute.
2600       *                          Default: 'Profile picture of [user name]'.
2601       * }
2602       * @return string HTML of user avatar.
2603       */
2604  	function bp_get_the_topic_post_poster_avatar( $args = '' ) {
2605          global $topic_template;
2606  
2607          $defaults = array(
2608              'type' => 'thumb',
2609              'width' => 20,
2610              'height' => 20,
2611              'alt' => __( 'Profile picture of %s', 'buddypress' )
2612          );
2613  
2614          $r = wp_parse_args( $args, $defaults );
2615          extract( $r, EXTR_SKIP );
2616  
2617          /**
2618           * Filters the avatar of the user who posted the current post in the loop.
2619           *
2620           * @since 1.0.0
2621           *
2622           * @param string $value Avatar of the user who posted the current post.
2623           */
2624          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, 'alt' => $alt ) ) );
2625      }
2626  
2627  /**
2628   * Output the name of the user who posted the current post in the loop.
2629   *
2630   * @since 1.0.0
2631   */
2632  function bp_the_topic_post_poster_name() {
2633      echo bp_get_the_topic_post_poster_name();
2634  }
2635      /**
2636       * Return the name of the user who posted the current post in the loop.
2637       *
2638       * @since 1.0.0
2639       *
2640       * @return string Name of the user who posted the current post.
2641       */
2642  	function bp_get_the_topic_post_poster_name() {
2643          global $topic_template;
2644  
2645          if ( empty( $topic_template->post->poster_name ) || ( !$link = bp_core_get_user_domain( $topic_template->post->poster_id ) ) )
2646              return __( 'Deleted User', 'buddypress' );
2647  
2648          /**
2649           * Filters the name of the user who posted the current post in the loop.
2650           *
2651           * @since 1.0.0
2652           *
2653           * @param string $value HTML link for the poster's name.
2654           */
2655          return apply_filters( 'bp_get_the_topic_post_poster_name', '<a href="' . esc_url( $link ) . '">' . esc_html( $topic_template->post->poster_name ) . '</a>' );
2656      }
2657  
2658  /**
2659   * Output a link to the profile of the user who posted the current post.
2660   *
2661   * @since 1.2.0
2662   */
2663  function bp_the_topic_post_poster_link() {
2664      echo bp_get_the_topic_post_poster_link();
2665  }
2666      /**
2667       * Return a link to the profile of the user who posted the current post.
2668       *
2669       * @since 1.2.0
2670       *
2671       * @return string Link to the profile of the user who posted the
2672       *                current post.
2673       */
2674  	function bp_get_the_topic_post_poster_link() {
2675          global $topic_template;
2676  
2677          /**
2678           * Filters a link to the profile of the user who posted the current post.
2679           *
2680           * @since 1.2.1
2681           *
2682           * @param string $value Link for the current poster's profile.
2683           */
2684          return apply_filters( 'bp_the_topic_post_poster_link', bp_core_get_user_domain( $topic_template->post->poster_id ) );
2685      }
2686  
2687  /**
2688   * Output a 'since' string describing when the current post in the loop was posted.
2689   *
2690   * @since 1.0.0
2691   */
2692  function bp_the_topic_post_time_since() {
2693      echo bp_get_the_topic_post_time_since();
2694  }
2695      /**
2696       * Return a 'since' string describing when the current post in the loop was posted.
2697       *
2698       * @since 1.0.0
2699       *
2700       * @see bp_core_time_since() for a description of return value.
2701       *
2702       * @return string
2703       */
2704  	function bp_get_the_topic_post_time_since() {
2705          global $topic_template;
2706  
2707          /**
2708           * Filters the 'since' string describing when the current post in the loop was posted.
2709           *
2710           * @since 1.0.0
2711           *
2712           * @param string $value The 'since' string.
2713           */
2714          return apply_filters( 'bp_get_the_topic_post_time_since', bp_core_time_since( strtotime( $topic_template->post->post_time ) ) );
2715      }
2716  
2717  /**
2718   * Output whether the current post in the loop belongs to the logged-in user.
2719   *
2720   * @since 1.1.0
2721   */
2722  function bp_the_topic_post_is_mine() {
2723      echo bp_get_the_topic_post_is_mine();
2724  }
2725      /**
2726       * Does the current post belong to the logged-in user?
2727       *
2728       * @since 1.1.0
2729       *
2730       * @return bool True if the current post in the loop was created by
2731       *              the logged-in user, otherwise false.
2732       */
2733  	function bp_get_the_topic_post_is_mine() {
2734          global $topic_template;
2735  
2736          return bp_loggedin_user_id() == $topic_template->post->poster_id;
2737      }
2738  
2739  /**
2740   * Output the admin links for the current post in the loop.
2741   *
2742   * @since 1.1.0
2743   *
2744   * @see bp_get_the_post_admin_links() for a description of arguments.
2745   *
2746   * @param array|string $args See {@link bp_get_the_post_admin_links()}.
2747   */
2748  function bp_the_topic_post_admin_links( $args = '' ) {
2749      echo bp_get_the_topic_post_admin_links( $args );
2750  }
2751      /**
2752       * Return the admin links for the current post in the loop.
2753       *
2754       * @since 1.1.0
2755       *
2756       * @param array|string $args {
2757       *     @type string $separator The character to use when separating
2758       *                             links. Default: '|'.
2759       * }
2760       * @return string HTML string containing the admin links for the current post.
2761       */
2762  	function bp_get_the_topic_post_admin_links( $args = '' ) {
2763          global $topic_template;
2764  
2765          // Never show for the first post in a topic.
2766          if ( 0 == $topic_template->current_post && 1 == $topic_template->pag_page )
2767              return;
2768  
2769          $defaults = array(
2770              'separator' => ' | '
2771          );
2772  
2773          $r = wp_parse_args( $args, $defaults );
2774          extract( $r, EXTR_SKIP );
2775  
2776          $query_vars = '';
2777          if ( $_SERVER['QUERY_STRING'] )
2778              $query_vars = '?' . $_SERVER['QUERY_STRING'];
2779  
2780          $links    = array();
2781          $links[]  = '<a href="' . wp_nonce_url( bp_get_the_topic_permalink() . 'edit/post/' . $topic_template->post->post_id . '/' . $query_vars, 'bp_forums_edit_post' ) . '">' . __( 'Edit', 'buddypress' ) . '</a>';
2782          $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>';
2783  
2784          /**
2785           * Filters the admin links for the current post in the loop.
2786           *
2787           * @since 1.2.7
2788           *
2789           * @param string $value HTML string containing the admin links for the current post.
2790           */
2791          return apply_filters( 'bp_get_the_topic_post_admin_links', implode( $separator, $links ), $links, $r );
2792      }
2793  
2794  /**
2795   * Output the text to edit when editing a post.
2796   *
2797   * @since 1.1.0
2798   */
2799  function bp_the_topic_post_edit_text() {
2800      echo bp_get_the_topic_post_edit_text();
2801  }
2802      /**
2803       * Return the text to edit when editing a post.
2804       *
2805       * @since 1.1.0
2806       *
2807       * @return string Editable text.
2808       */
2809  	function bp_get_the_topic_post_edit_text() {
2810          $post = bp_forums_get_post( bp_action_variable( 4 ) );
2811  
2812          /**
2813           * Filters the text to edit when editing a post.
2814           *
2815           * @since 1.2.4
2816           *
2817           * @param string $value The text to edit when editing a post.
2818           */
2819          return apply_filters( 'bp_get_the_topic_post_edit_text', esc_attr( $post->post_text ) );
2820      }
2821  
2822  /**
2823   * Output the pagination links for the current topic.
2824   *
2825   * @since 1.0.0
2826   */
2827  function bp_the_topic_pagination() {
2828      echo bp_get_the_topic_pagination();
2829  }
2830      /**
2831       * Return the pagination links for the current topic page.
2832       *
2833       * @since 1.0.0
2834       *
2835       * @return string HTML pagination links.
2836       */
2837  	function bp_get_the_topic_pagination() {
2838          global $topic_template;
2839  
2840  
2841          /**
2842           * Filters the pagination links for the current topic page.
2843           *
2844           * @since 1.0.0
2845           *
2846           * @param string $pag_links HTML pagination links.
2847           */
2848          return apply_filters( 'bp_get_the_topic_pagination', $topic_template->pag_links );
2849      }
2850  
2851  /**
2852   * Return the pagination count for the current topic page.
2853   *
2854   * The "count" is a string of the form "Viewing x of y posts".
2855   *
2856   * @since 1.0.0
2857   */
2858  function bp_the_topic_pagination_count() {
2859      global $topic_template;
2860  
2861      $start_num = intval( ( $topic_template->pag_page - 1 ) * $topic_template->pag_num ) + 1;
2862      $from_num = bp_core_number_format( $start_num );
2863      $to_num = bp_core_number_format( ( $start_num + ( $topic_template->pag_num - 1  ) > $topic_template->total_post_count ) ? $topic_template->total_post_count : $start_num + ( $topic_template->pag_num - 1 ) );
2864      $total = bp_core_number_format( $topic_template->total_post_count );
2865  
2866      if ( 1 == $topic_template->total_post_count ) {
2867          $message = __( 'Viewing 1 post', 'buddypress' );
2868      } else {
2869          $message = sprintf( _n( 'Viewing %1$s - %2$s of %3$s post', 'Viewing %1$s - %2$s of %3$s posts', (int) $topic_template->total_post_count, 'buddypress' ), $from_num, $to_num, $total );
2870      }
2871  
2872      /**
2873       * Filters the pagination count for the current topic page.
2874       *
2875       * @since 1.0.0
2876       *
2877       * @param string $message  Pagination count for the current topic page.
2878       * @param string $from_num Low end count in the view.
2879       * @param string $to_num   High end count in the view.
2880       * @param string $total    Total count of topics found.
2881       */
2882      echo apply_filters( 'bp_the_topic_pagination_count', $message, $from_num, $to_num, $total );
2883  }
2884  
2885  /**
2886   * Output whether this is the last page in the current topic.
2887   *
2888   * @since 1.2.0
2889   */
2890  function bp_the_topic_is_last_page() {
2891      echo bp_get_the_topic_is_last_page();
2892  }
2893      /**
2894       * Is this the last page in the current topic?
2895       *
2896       * @since 1.2.0
2897       *
2898       * @return bool True if this is the last page of posts for the current
2899       *              topic, otherwise false.
2900       */
2901  	function bp_get_the_topic_is_last_page() {
2902          global $topic_template;
2903  
2904          /**
2905           * Filters whether or not a user is on the last page in the current topic.
2906           *
2907           * @since 1.2.0
2908           *
2909           * @param bool $value Whether or not user is on last page.
2910           */
2911          return apply_filters( 'bp_get_the_topic_is_last_page', $topic_template->pag_page == $topic_template->pag->total_pages );
2912      }
2913  
2914  /**
2915   * Output the forums directory search form.
2916   *
2917   * @since 1.1.0
2918   */
2919  function bp_directory_forums_search_form() {
2920      $default_search_value = bp_get_search_default_text( 'forums' );
2921      $search_value = !empty( $_REQUEST['fs'] ) ? stripslashes( $_REQUEST['fs'] ) : $default_search_value;
2922  
2923      $search_form_html = '<form action="" method="get" id="search-forums-form">
2924          <label for="forums_search"><input type="text" name="s" id="forums_search" placeholder="'. esc_attr( $search_value ) .'" /></label>
2925          <input type="submit" id="forums_search_submit" name="forums_search_submit" value="' . __( 'Search', 'buddypress' ) . '" />
2926      </form>';
2927  
2928      /**
2929       * Filters the forums directory search form.
2930       *
2931       * @since 1.9.0
2932       *
2933       * @param string $search_form_html HTML search form for the forums directory.
2934       */
2935      echo apply_filters( 'bp_directory_forums_search_form', $search_form_html );
2936  }
2937  
2938  /**
2939   * Output the link to a given forum.
2940   *
2941   * @since 1.0.0
2942   *
2943   * @see bp_get_forum_permalink() for a description of arguments.
2944   *
2945   * @param int $forum_id See {@link bp_get_forum_permalink()}.
2946   */
2947  function bp_forum_permalink( $forum_id = 0 ) {
2948      echo bp_get_forum_permalink( $forum_id );
2949  }
2950      /**
2951       * Return the permalink to a given forum.
2952       *
2953       * @since 1.0.0
2954       *
2955       * @param int $forum_id Optional. Defaults to the current forum, if
2956       *                      there is one.
2957       * @return string|bool False on failure, a URL on success.
2958       */
2959  	function bp_get_forum_permalink( $forum_id = 0 ) {
2960  
2961          if ( bp_is_groups_component() ) {
2962              $permalink = trailingslashit( bp_get_groups_directory_permalink() . bp_current_item() . '/forum' );
2963          } else {
2964              if ( empty( $forum_id ) ) {
2965                  global $topic_template;
2966                  if ( isset( $topic_template->forum_id ) )
2967                      $forum_id = $topic_template->forum_id;
2968              }
2969  
2970              if ( $forum = bp_forums_get_forum( $forum_id ) )
2971                  $permalink = trailingslashit( bp_get_root_domain() . '/' . bp_get_forums_root_slug() . '/forum/' . $forum->forum_slug );
2972              else
2973                  return false;
2974          }
2975  
2976          /**
2977           * Filters the permalink to a given forum.
2978           *
2979           * @since 1.0.0
2980           *
2981           * @param string $value Peramlink to the given forum.
2982           */
2983          return apply_filters( 'bp_get_forum_permalink', trailingslashit( $permalink ) );
2984      }
2985  
2986  /**
2987   * Output the name of a given forum.
2988   *
2989   * @since 1.5.0
2990   *
2991   * @see bp_get_forum_name() for a description of parameters.
2992   *
2993   * @param int $forum_id See {@link bp_get_forum_name()}.
2994   */
2995  function bp_forum_name( $forum_id = 0 ) {
2996      echo bp_get_forum_name( $forum_id );
2997  }
2998      /**
2999       * Return the name of a given forum.
3000       *
3001       * @since 1.5.0
3002       *
3003       * @param int $forum_id Optional. Defaults to the current forum, if
3004       *                      there is one.
3005       * @return string|bool False on failure, a name on success.
3006       */
3007  	function bp_get_forum_name( $forum_id = 0 ) {
3008  
3009          if ( empty( $forum_id ) ) {
3010              global $topic_template;
3011              if ( isset( $topic_template->forum_id ) )
3012                  $forum_id = $topic_template->forum_id;
3013          }
3014  
3015          if ( $forum = bp_forums_get_forum( $forum_id ) ) {
3016  
3017              /**
3018               * Filters the name of a given forum.
3019               *
3020               * @since 1.5.0
3021               *
3022               * @param string $forum_name Name of the given forum.
3023               * @param string $forum_id   ID of the given forum.
3024               */
3025              return apply_filters( 'bp_get_forum_name', $forum->forum_name, $forum->forum_id );
3026          } else {
3027              return false;
3028          }
3029      }
3030  
3031  /**
3032   * Get a heatmap of forum tags for the installation.
3033   *
3034   * A wrapper for {@link bb_tag_heat_map}, which provides it with BP-friendly
3035   * defaults.
3036   *
3037   * @since 1.1.0
3038   *
3039   * @param array|string $args {
3040   *     An array of optional arguments.
3041   *     @type int    $smallest Size of the smallest link. Default: 10.
3042   *     @type int    $largest  Size of the largest link. Default: 42.
3043   *     @type string $sizing   Unit for $largest and $smallest. Default: 'px'.
3044   *     @type int    $limit    Max number of tags to display. Default: 50.
3045   * }
3046   */
3047  function bp_forums_tag_heat_map( $args = '' ) {
3048      $defaults = array(
3049          'smallest' => '10',
3050          'largest'  => '42',
3051          'sizing'   => 'px',
3052          'limit'    => '50'
3053      );
3054  
3055      $r = wp_parse_args( $args, $defaults );
3056      extract( $r, EXTR_SKIP );
3057  
3058      bb_tag_heat_map( $smallest, $largest, $sizing, $limit );
3059  }
3060  
3061  /**
3062   * Output the current topic's tag list, comma-separated.
3063   *
3064   * @since 1.5.0
3065   */
3066  function bp_forum_topic_tag_list() {
3067      echo bp_get_forum_topic_tag_list();
3068  }
3069      /**
3070       * Get the current topic's tag list.
3071       *
3072       * @since 1.5.0
3073       *
3074       * @param string $format 'string' returns comma-separated string;
3075       *                       otherwise returns array.
3076       * @return mixed $tags
3077       */
3078  	function bp_get_forum_topic_tag_list( $format = 'string' ) {
3079          global $topic_template;
3080  
3081          $tags_data = !empty( $topic_template->topic_tags ) ? $topic_template->topic_tags : false;
3082  
3083          $tags = array();
3084  
3085          if ( $tags_data ) {
3086              foreach( $tags_data as $tag_data ) {
3087                  $tags[] = $tag_data->name;
3088              }
3089          }
3090  
3091          if ( 'string' == $format )
3092              $tags = implode( ', ', $tags );
3093  
3094          /**
3095           * Filters the current topic's tag list.
3096           *
3097           * @since 1.5.0
3098           *
3099           * @param string|array $tags   List or array of tags for the current topic.
3100           * @param string       $format Requested format for the tags.
3101           */
3102          return apply_filters( 'bp_forum_topic_tag_list', $tags, $format );
3103      }
3104  
3105  /**
3106   * Does the current topic have any tags?
3107   *
3108   * @since 1.5.0
3109   *
3110   * @return bool True if the current topic has tags, otherwise false.
3111   */
3112  function bp_forum_topic_has_tags() {
3113      global $topic_template;
3114  
3115      $has_tags = false;
3116  
3117      if ( !empty( $topic_template->topic_tags ) )
3118          $has_tags = true;
3119  
3120      /**
3121       * Filters whether or not a forum topic has any tags.
3122       *
3123       * @since 1.5.0
3124       *
3125       * @param bool $has_tags Whether or not there are any tags.
3126       */
3127      return apply_filters( 'bp_forum_topic_has_tags', $has_tags );
3128  }
3129  
3130  /**
3131   * Output a URL to use in as a forum form 'action'.
3132   *
3133   * @since 1.0.0
3134   */
3135  function bp_forum_action() {
3136      echo bp_get_forum_action();
3137  }
3138      /**
3139       * Get a URL to use in as a forum form 'action'.
3140       *
3141       * @since 1.0.0
3142       *
3143       * @return string URL of the current page, minus query args.
3144       */
3145  	function bp_get_forum_action() {
3146          global $topic_template;
3147  
3148          /**
3149           * Filters the url to use in a forum form 'action'.
3150           *
3151           * @since 1.0.0
3152           *
3153           * @param string $value URL to use in the forum form 'action'.
3154           */
3155          return apply_filters( 'bp_get_forum_action', bp_get_root_domain() . esc_attr( $_SERVER['REQUEST_URI'] ) );
3156      }
3157  
3158  /**
3159   * Output a URL to use in as a forum topic form 'action'.
3160   *
3161   * @since 1.0.0
3162   */
3163  function bp_forum_topic_action() {
3164      echo bp_get_forum_topic_action();
3165  }
3166      /**
3167       * Get a URL to use in as a forum topic form 'action'.
3168       *
3169       * @since 1.0.0
3170       *
3171       * @return string URL of the current page, minus query args.
3172       */
3173  	function bp_get_forum_topic_action() {
3174  
3175          /**
3176           * Filters the url to use in a forum topic form 'action'.
3177           *
3178           * @since 1.0.0
3179           *
3180           * @param string $value URL to use in the forum topic form 'action'.
3181           */
3182          return apply_filters( 'bp_get_forum_topic_action', $_SERVER['REQUEST_URI'] );
3183      }
3184  
3185  /**
3186   * Output the total topic count for a given user.
3187   *
3188   * @since 1.2.0
3189   *
3190   * @see bp_get_forum_topic_count_for_user() for description of parameters.
3191   *
3192   * @param int $user_id See {@link bp_get_forum_topic_count_for_user()}.
3193   */
3194  function bp_forum_topic_count_for_user( $user_id = 0 ) {
3195      echo bp_get_forum_topic_count_for_user( $user_id );
3196  }
3197      /**
3198       * Return the total topic count for a given user.
3199       *
3200       * @since 1.2.0
3201       *
3202       * @param int $user_id See {@link bp_forums_total_topic_count_for_user}.
3203       *
3204       * @return int
3205       */
3206  	function bp_get_forum_topic_count_for_user( $user_id = 0 ) {
3207  
3208          /**
3209           * Filters the total topic count for a given user.
3210           *
3211           * @since 1.2.0
3212           *
3213           * @param int $value Total topic count for the given user.
3214           */
3215          return apply_filters( 'bp_get_forum_topic_count_for_user', bp_forums_total_topic_count_for_user( $user_id ) );
3216      }
3217  
3218  /**
3219   * Output the total topic count for a given user.
3220   *
3221   * @since 1.2.0
3222   *
3223   * @see bp_get_forum_topic_count() for description of parameters.
3224   *
3225   * @param int $user_id See {@link bp_get_forum_topic_count()}.
3226   */
3227  function bp_forum_topic_count( $user_id = 0 ) {
3228      echo bp_get_forum_topic_count( $user_id );
3229  }
3230      /**
3231       * Return the total topic count for a given user.
3232       *
3233       * @since 1.2.0
3234       *
3235       * @param int $user_id See {@link bp_forums_total_topic_count()}.
3236       *
3237       * @return int
3238       */
3239  	function bp_get_forum_topic_count( $user_id = 0 ) {
3240  
3241          /**
3242           * Filters the total topic count for a given user.
3243           *
3244           * @since 1.2.0
3245           *
3246           * @param int $value Total topic count for the given user.
3247           */
3248          return apply_filters( 'bp_get_forum_topic_count', bp_forums_total_topic_count( $user_id ) );
3249      }


Generated: Thu Dec 7 01:01:35 2017 Cross-referenced by PHPXref 0.7.1