/bp-forums/bp-forums-template.php

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