/bp-activity/bp-activity-template.php

  1. <?php 
  2. /** 
  3. * BuddyPress Activity Template Functions. 
  4. * 
  5. * @package BuddyPress 
  6. * @subpackage ActivityTemplate 
  7. * @since 1.5.0 
  8. */ 
  9.  
  10. // Exit if accessed directly. 
  11. defined( 'ABSPATH' ) || exit; 
  12.  
  13. /** 
  14. * Output the activity component slug. 
  15. * 
  16. * @since 1.5.0 
  17. * 
  18. */ 
  19. function bp_activity_slug() { 
  20. echo bp_get_activity_slug(); 
  21. /** 
  22. * Return the activity component slug. 
  23. * 
  24. * @since 1.5.0 
  25. * 
  26. * 
  27. * @return string The activity component slug. 
  28. */ 
  29. function bp_get_activity_slug() { 
  30.  
  31. /** 
  32. * Filters the activity component slug. 
  33. * 
  34. * @since 1.5.0 
  35. * 
  36. * @param string $slug Activity component slug. 
  37. */ 
  38. return apply_filters( 'bp_get_activity_slug', buddypress()->activity->slug ); 
  39.  
  40. /** 
  41. * Output the activity component root slug. 
  42. * 
  43. * @since 1.5.0 
  44. * 
  45. */ 
  46. function bp_activity_root_slug() { 
  47. echo bp_get_activity_root_slug(); 
  48. /** 
  49. * Return the activity component root slug. 
  50. * 
  51. * @since 1.5.0 
  52. * 
  53. * 
  54. * @return string The activity component root slug. 
  55. */ 
  56. function bp_get_activity_root_slug() { 
  57.  
  58. /** 
  59. * Filters the activity component root slug. 
  60. * 
  61. * @since 1.5.0 
  62. * 
  63. * @param string $root_slug Activity component root slug. 
  64. */ 
  65. return apply_filters( 'bp_get_activity_root_slug', buddypress()->activity->root_slug ); 
  66.  
  67. /** 
  68. * Output activity directory permalink. 
  69. * 
  70. * @since 1.5.0 
  71. * 
  72. */ 
  73. function bp_activity_directory_permalink() { 
  74. echo esc_url( bp_get_activity_directory_permalink() ); 
  75. /** 
  76. * Return activity directory permalink. 
  77. * 
  78. * @since 1.5.0 
  79. * 
  80. * 
  81. * @return string Activity directory permalink. 
  82. */ 
  83. function bp_get_activity_directory_permalink() { 
  84.  
  85. /** 
  86. * Filters the activity directory permalink. 
  87. * 
  88. * @since 1.5.0 
  89. * 
  90. * @param string $url Permalink url for the activity directory. 
  91. */ 
  92. return apply_filters( 'bp_get_activity_directory_permalink', trailingslashit( bp_get_root_domain() . '/' . bp_get_activity_root_slug() ) ); 
  93.  
  94. /** 
  95. * Initialize the activity loop. 
  96. * 
  97. * Based on the $args passed, bp_has_activities() populates the 
  98. * $activities_template global, enabling the use of BuddyPress templates and 
  99. * template functions to display a list of activity items. 
  100. * 
  101. * @since 1.0.0 
  102. * @since 2.4.0 Introduced the `$fields` parameter. 
  103. * 
  104. * @global object $activities_template {@link BP_Activity_Template} 
  105. * 
  106. * @param array|string $args { 
  107. * Arguments for limiting the contents of the activity loop. Most arguments 
  108. * are in the same format as {@link BP_Activity_Activity::get()}. However,  
  109. * because the format of the arguments accepted here differs in a number of 
  110. * ways, and because bp_has_activities() determines some default arguments in 
  111. * a dynamic fashion, we list all accepted arguments here as well. 
  112. * 
  113. * Arguments can be passed as an associative array, or as a URL querystring 
  114. * (eg, 'user_id=4&display_comments=threaded'). 
  115. * 
  116. * @type int $page Which page of results to fetch. Using page=1 without per_page will result 
  117. * in no pagination. Default: 1. 
  118. * @type int|bool $per_page Number of results per page. Default: 20. 
  119. * @type string $page_arg String used as a query parameter in pagination links. Default: 'acpage'. 
  120. * @type int|bool $max Maximum number of results to return. Default: false (unlimited). 
  121. * @type string $fields Activity fields to retrieve. 'all' to fetch entire activity objects,  
  122. * 'ids' to get only the activity IDs. Default 'all'. 
  123. * @type string|bool $count_total If true, an additional DB query is run to count the total activity items 
  124. * for the query. Default: false. 
  125. * @type string $sort 'ASC' or 'DESC'. Default: 'DESC'. 
  126. * @type array|bool $exclude Array of activity IDs to exclude. Default: false. 
  127. * @type array|bool $in Array of IDs to limit query by (IN). 'in' is intended to be used in 
  128. * conjunction with other filter parameters. Default: false. 
  129. * @type array|bool $include Array of exact activity IDs to query. Providing an 'include' array will 
  130. * override all other filters passed in the argument array. When viewing the 
  131. * permalink page for a single activity item, this value defaults to the ID of 
  132. * that item. Otherwise the default is false. 
  133. * @type array $meta_query Limit by activitymeta by passing an array of meta_query conditions. See 
  134. * {@link WP_Meta_Query::queries} for a description of the syntax. 
  135. * @type array $date_query Limit by date by passing an array of date_query conditions. See first 
  136. * parameter of {@link WP_Date_Query::__construct()} for syntax. 
  137. * @type array $filter_query Advanced activity filtering. See {@link BP_Activity_Query::__construct()}. 
  138. * @type string $search_terms Limit results by a search term. Default: false. 
  139. * @type string $scope Use a BuddyPress pre-built filter. 
  140. * - 'just-me' retrieves items belonging only to a user; this is equivalent 
  141. * to passing a 'user_id' argument. 
  142. * - 'friends' retrieves items belonging to the friends of a user. 
  143. * - 'groups' retrieves items belonging to groups to which a user belongs to. 
  144. * - 'favorites' retrieves a user's favorited activity items. 
  145. * - 'mentions' retrieves items where a user has received an @-mention. 
  146. * The default value of 'scope' is set to one of the above if that value 
  147. * appears in the appropriate place in the URL; eg, 'scope' will be 'groups' 
  148. * when visiting http://example.com/members/joe/activity/groups/. Otherwise 
  149. * defaults to false. 
  150. * @type int|array|bool $user_id The ID(s) of user(s) whose activity should be fetched. Pass a single ID or 
  151. * an array of IDs. When viewing a user profile page (but not that user's 
  152. * activity subpages, ie My Friends, My Groups, etc), 'user_id' defaults to 
  153. * the ID of the displayed user. Otherwise the default is false. 
  154. * @type string|array|bool $object Filters by the `component` column in the database, which is generally the 
  155. * component ID in the case of BuddyPress components, or the plugin slug in 
  156. * the case of plugins. For example, 'groups' will limit results to those that 
  157. * are associated with the BP Groups component. Accepts a single component 
  158. * string, or an array of multiple components. Defaults to 'groups' when 
  159. * viewing the page of a single group, the My Groups activity filter, or the 
  160. * Activity > Groups filter of a user profile. Otherwise defaults to false. 
  161. * @type string|array|bool $action Filters by the `type` column in the database, which is a string 
  162. * categorizing the activity item (eg, 'new_blog_post', 'created_group'). 
  163. * Accepts a comma-delimited string or an array of types. Default: false. 
  164. * @type int|array|bool $primary_id Filters by the `item_id` column in the database. The meaning of 
  165. * 'primary_id' differs between components/types; for example, in the case of 
  166. * 'created_group', 'primary_id' is the ID of the group. Accepts a single ID,  
  167. * or an array of multiple IDs. When viewing a single group, defaults to the 
  168. * current group ID. When viewing a user's Groups stream page, defaults to the 
  169. * IDs of the user's groups. Otherwise defaults to false. 
  170. * @type int|array|bool $secondary_id Filters by the `secondary_item_id` column in the database. The meaning of 
  171. * 'secondary_id' differs between components/types. Accepts a single ID, or an 
  172. * array of multiple IDs. Defaults to false. 
  173. * @type int $offset Return only activity items with an ID greater than or equal to this one. 
  174. * Note that providing an offset will disable pagination. Default: false. 
  175. * @type string|bool $display_comments How to handle activity comments. Possible values: 
  176. * - 'threaded' - comments appear in a threaded tree, under their parent 
  177. * items. 
  178. * - 'stream' - the activity stream is presented in a flat manner, with 
  179. * comments sorted in chronological order alongside other activity items. 
  180. * - false - don't fetch activity comments at all. 
  181. * Default: 'threaded'. 
  182. * @type bool $show_hidden Whether to show items marked hide_sitewide. Defaults to false, except in 
  183. * the following cases: 
  184. * - User is viewing his own activity stream. 
  185. * - User is viewing the activity stream of a non-public group of which he 
  186. * is a member. 
  187. * @type string|bool $spam Spam status. 'ham_only', 'spam_only', or false to show all activity 
  188. * regardless of spam status. Default: 'ham_only'. 
  189. * @type bool $populate_extras Whether to pre-fetch the activity metadata for the queried items. 
  190. * Default: true. 
  191. * } 
  192. * @return bool Returns true when activities are found, otherwise false. 
  193. */ 
  194. function bp_has_activities( $args = '' ) { 
  195. global $activities_template; 
  196.  
  197. // Get BuddyPress. 
  198. $bp = buddypress(); 
  199.  
  200. /** 
  201. * Smart Defaults. 
  202. */ 
  203.  
  204. // User filtering. 
  205. $user_id = bp_displayed_user_id() 
  206. ? bp_displayed_user_id() 
  207. : false; 
  208.  
  209. // Group filtering. 
  210. if ( bp_is_group() ) { 
  211. $object = $bp->groups->id; 
  212. $primary_id = bp_get_current_group_id(); 
  213. $show_hidden = (bool) ( groups_is_user_member( bp_loggedin_user_id(), $primary_id ) || bp_current_user_can( 'bp_moderate' ) ); 
  214. } else { 
  215. $object = false; 
  216. $primary_id = false; 
  217. $show_hidden = false; 
  218.  
  219. // The default scope should recognize custom slugs. 
  220. $scope = array_key_exists( bp_current_action(), (array) $bp->loaded_components ) 
  221. ? $bp->loaded_components[ bp_current_action() ] 
  222. : bp_current_action(); 
  223.  
  224. // Support for permalinks on single item pages: /groups/my-group/activity/124/. 
  225. $include = bp_is_current_action( bp_get_activity_slug() ) 
  226. ? bp_action_variable( 0 ) 
  227. : false; 
  228.  
  229. $search_terms_default = false; 
  230. $search_query_arg = bp_core_get_component_search_query_arg( 'activity' ); 
  231. if ( ! empty( $_REQUEST[ $search_query_arg ] ) ) { 
  232. $search_terms_default = stripslashes( $_REQUEST[ $search_query_arg ] ); 
  233.  
  234. /** 
  235. * Parse Args. 
  236. */ 
  237.  
  238. // Note: any params used for filtering can be a single value, or multiple 
  239. // values comma separated. 
  240. $r = bp_parse_args( $args, array( 
  241. 'display_comments' => 'threaded', // False for none, stream/threaded - show comments in the stream or threaded under items. 
  242. 'include' => $include, // Pass an activity_id or string of IDs comma-separated. 
  243. 'exclude' => false, // Pass an activity_id or string of IDs comma-separated. 
  244. 'in' => false, // Comma-separated list or array of activity IDs among which to search. 
  245. 'sort' => 'DESC', // Sort DESC or ASC. 
  246. 'page' => 1, // Which page to load. 
  247. 'per_page' => 20, // Number of items per page. 
  248. 'page_arg' => 'acpage', // See https://buddypress.trac.wordpress.org/ticket/3679. 
  249. 'max' => false, // Max number to return. 
  250. 'fields' => 'all',  
  251. 'count_total' => false,  
  252. 'show_hidden' => $show_hidden, // Show activity items that are hidden site-wide? 
  253. 'spam' => 'ham_only', // Hide spammed items. 
  254.  
  255. // Scope - pre-built activity filters for a user (friends/groups/favorites/mentions). 
  256. 'scope' => $scope,  
  257.  
  258. // Filtering 
  259. 'user_id' => $user_id, // user_id to filter on. 
  260. 'object' => $object, // Object to filter on e.g. groups, profile, status, friends. 
  261. 'action' => false, // Action to filter on e.g. activity_update, new_forum_post, profile_updated. 
  262. 'primary_id' => $primary_id, // Object ID to filter on e.g. a group_id or forum_id or blog_id etc. 
  263. 'secondary_id' => false, // Secondary object ID to filter on e.g. a post_id. 
  264. 'offset' => false, // Return only items >= this ID. 
  265. 'since' => false, // Return only items recorded since this Y-m-d H:i:s date. 
  266.  
  267. 'meta_query' => false, // Filter on activity meta. See WP_Meta_Query for format. 
  268. 'date_query' => false, // Filter by date. See first parameter of WP_Date_Query for format. 
  269. 'filter_query' => false, // Advanced filtering. See BP_Activity_Query for format. 
  270.  
  271. // Searching. 
  272. 'search_terms' => $search_terms_default,  
  273. 'update_meta_cache' => true,  
  274. ), 'has_activities' ); 
  275.  
  276. /** 
  277. * Smart Overrides. 
  278. */ 
  279.  
  280. // Translate various values for 'display_comments' 
  281. // This allows disabling comments via ?display_comments=0 
  282. // or =none or =false. Final true is a strict type check. See #5029. 
  283. if ( in_array( $r['display_comments'], array( 0, '0', 'none', 'false' ), true ) ) { 
  284. $r['display_comments'] = false; 
  285.  
  286. // Ignore pagination if an offset is passed. 
  287. if ( ! empty( $r['offset'] ) ) { 
  288. $r['page'] = 0; 
  289.  
  290. // Search terms. 
  291. if ( ! empty( $_REQUEST['s'] ) && empty( $r['search_terms'] ) ) { 
  292. $r['search_terms'] = $_REQUEST['s']; 
  293.  
  294. // Do not exceed the maximum per page. 
  295. if ( ! empty( $r['max'] ) && ( (int) $r['per_page'] > (int) $r['max'] ) ) { 
  296. $r['per_page'] = $r['max']; 
  297.  
  298. /** 
  299. * Filters whether BuddyPress should enable afilter support. 
  300. * 
  301. * Support for basic filters in earlier BP versions is disabled by default. 
  302. * To enable, put add_filter( 'bp_activity_enable_afilter_support', '__return_true' ); 
  303. * into bp-custom.php or your theme's functions.php. 
  304. * 
  305. * @since 1.6.0 
  306. * 
  307. * @param bool $value True if BuddyPress should enable afilter support. 
  308. */ 
  309. if ( isset( $_GET['afilter'] ) && apply_filters( 'bp_activity_enable_afilter_support', false ) ) { 
  310. $r['filter'] = array( 
  311. 'object' => $_GET['afilter'] 
  312. ); 
  313. } elseif ( ! empty( $r['user_id'] ) || ! empty( $r['object'] ) || ! empty( $r['action'] ) || ! empty( $r['primary_id'] ) || ! empty( $r['secondary_id'] ) || ! empty( $r['offset'] ) || ! empty( $r['since'] ) ) { 
  314. $r['filter'] = array( 
  315. 'user_id' => $r['user_id'],  
  316. 'object' => $r['object'],  
  317. 'action' => $r['action'],  
  318. 'primary_id' => $r['primary_id'],  
  319. 'secondary_id' => $r['secondary_id'],  
  320. 'offset' => $r['offset'],  
  321. 'since' => $r['since'] 
  322. ); 
  323. } else { 
  324. $r['filter'] = false; 
  325.  
  326. // If specific activity items have been requested, override the $hide_spam 
  327. // argument. This prevents backpat errors with AJAX. 
  328. if ( ! empty( $r['include'] ) && ( 'ham_only' === $r['spam'] ) ) { 
  329. $r['spam'] = 'all'; 
  330.  
  331. /** 
  332. * Query 
  333. */ 
  334.  
  335. $activities_template = new BP_Activity_Template( $r ); 
  336.  
  337. /** 
  338. * Filters whether or not there are activity items to display. 
  339. * 
  340. * @since 1.1.0 
  341. * 
  342. * @param bool $value Whether or not there are activity items to display. 
  343. * @param string $activities_template Current activities template being used. 
  344. * @param array $r Array of arguments passed into the BP_Activity_Template class. 
  345. */ 
  346. return apply_filters( 'bp_has_activities', $activities_template->has_activities(), $activities_template, $r ); 
  347.  
  348. /** 
  349. * Determine if there are still activities left in the loop. 
  350. * 
  351. * @since 1.0.0 
  352. * 
  353. * @global object $activities_template {@link BP_Activity_Template} 
  354. * 
  355. * @return bool Returns true when activities are found. 
  356. */ 
  357. function bp_activities() { 
  358. global $activities_template; 
  359. return $activities_template->user_activities(); 
  360.  
  361. /** 
  362. * Get the current activity object in the loop. 
  363. * 
  364. * @since 1.0.0 
  365. * 
  366. * @global object $activities_template {@link BP_Activity_Template} 
  367. * 
  368. * @return object The current activity within the loop. 
  369. */ 
  370. function bp_the_activity() { 
  371. global $activities_template; 
  372. return $activities_template->the_activity(); 
  373.  
  374. /** 
  375. * Output the URL for the Load More link. 
  376. * 
  377. * @since 2.1.0 
  378. */ 
  379. function bp_activity_load_more_link() { 
  380. echo esc_url( bp_get_activity_load_more_link() ); 
  381. /** 
  382. * Get the URL for the Load More link. 
  383. * 
  384. * @since 2.1.0 
  385. * 
  386. * @return string $link 
  387. */ 
  388. function bp_get_activity_load_more_link() { 
  389. global $activities_template; 
  390.  
  391. $url = bp_get_requested_url(); 
  392. $link = add_query_arg( $activities_template->pag_arg, $activities_template->pag_page + 1, $url ); 
  393.  
  394. /** 
  395. * Filters the Load More link URL. 
  396. * 
  397. * @since 2.1.0 
  398. * 
  399. * @param string $link The "Load More" link URL with appropriate query args. 
  400. * @param string $url The original URL. 
  401. * @param object $activities_template The activity template loop global. 
  402. */ 
  403. return apply_filters( 'bp_get_activity_load_more_link', $link, $url, $activities_template ); 
  404.  
  405. /** 
  406. * Output the activity pagination count. 
  407. * 
  408. * @since 1.0.0 
  409. * 
  410. * @global object $activities_template {@link BP_Activity_Template} 
  411. */ 
  412. function bp_activity_pagination_count() { 
  413. echo bp_get_activity_pagination_count(); 
  414.  
  415. /** 
  416. * Return the activity pagination count. 
  417. * 
  418. * @since 1.2.0 
  419. * 
  420. * @global object $activities_template {@link BP_Activity_Template} 
  421. * 
  422. * @return string The pagination text. 
  423. */ 
  424. function bp_get_activity_pagination_count() { 
  425. global $activities_template; 
  426.  
  427. $start_num = intval( ( $activities_template->pag_page - 1 ) * $activities_template->pag_num ) + 1; 
  428. $from_num = bp_core_number_format( $start_num ); 
  429. $to_num = bp_core_number_format( ( $start_num + ( $activities_template->pag_num - 1 ) > $activities_template->total_activity_count ) ? $activities_template->total_activity_count : $start_num + ( $activities_template->pag_num - 1 ) ); 
  430. $total = bp_core_number_format( $activities_template->total_activity_count ); 
  431.  
  432. if ( 1 == $activities_template->total_activity_count ) { 
  433. $message = __( 'Viewing 1 item', 'buddypress' ); 
  434. } else { 
  435. $message = sprintf( _n( 'Viewing %1$s - %2$s of %3$s item', 'Viewing %1$s - %2$s of %3$s items', $activities_template->total_activity_count, 'buddypress' ), $from_num, $to_num, $total ); 
  436.  
  437. return $message; 
  438.  
  439. /** 
  440. * Output the activity pagination links. 
  441. * 
  442. * @since 1.0.0 
  443. * 
  444. */ 
  445. function bp_activity_pagination_links() { 
  446. echo bp_get_activity_pagination_links(); 
  447.  
  448. /** 
  449. * Return the activity pagination links. 
  450. * 
  451. * @since 1.0.0 
  452. * 
  453. * @global object $activities_template {@link BP_Activity_Template} 
  454. * 
  455. * @return string The pagination links. 
  456. */ 
  457. function bp_get_activity_pagination_links() { 
  458. global $activities_template; 
  459.  
  460. /** 
  461. * Filters the activity pagination link output. 
  462. * 
  463. * @since 1.0.0 
  464. * 
  465. * @param string $pag_links Output for the activity pagination links. 
  466. */ 
  467. return apply_filters( 'bp_get_activity_pagination_links', $activities_template->pag_links ); 
  468.  
  469. /** 
  470. * Return true when there are more activity items to be shown than currently appear. 
  471. * 
  472. * @since 1.5.0 
  473. * 
  474. * @global object $activities_template {@link BP_Activity_Template} 
  475. * 
  476. * @return bool $has_more_items True if more items, false if not. 
  477. */ 
  478. function bp_activity_has_more_items() { 
  479. global $activities_template; 
  480.  
  481. if ( ! empty( $activities_template->has_more_items ) ) { 
  482. $has_more_items = true; 
  483. } else { 
  484. $remaining_pages = 0; 
  485.  
  486. if ( ! empty( $activities_template->pag_page ) ) { 
  487. $remaining_pages = floor( ( $activities_template->total_activity_count - 1 ) / ( $activities_template->pag_num * $activities_template->pag_page ) ); 
  488.  
  489. $has_more_items = (int) $remaining_pages > 0; 
  490.  
  491. /** 
  492. * Filters whether there are more activity items to display. 
  493. * 
  494. * @since 1.5.0 
  495. * 
  496. * @param bool $has_more_items Whether or not there are more activity items to display. 
  497. */ 
  498. return apply_filters( 'bp_activity_has_more_items', $has_more_items ); 
  499.  
  500. /** 
  501. * Output the activity count. 
  502. * 
  503. * @since 1.2.0 
  504. * 
  505. */ 
  506. function bp_activity_count() { 
  507. echo bp_get_activity_count(); 
  508.  
  509. /** 
  510. * Return the activity count. 
  511. * 
  512. * @since 1.2.0 
  513. * 
  514. * @global object $activities_template {@link BP_Activity_Template} 
  515. * 
  516. * @return int The activity count. 
  517. */ 
  518. function bp_get_activity_count() { 
  519. global $activities_template; 
  520.  
  521. /** 
  522. * Filters the activity count for the activity template. 
  523. * 
  524. * @since 1.2.0 
  525. * 
  526. * @param int $activity_count The count for total activity. 
  527. */ 
  528. return apply_filters( 'bp_get_activity_count', (int) $activities_template->activity_count ); 
  529.  
  530. /** 
  531. * Output the number of activities per page. 
  532. * 
  533. * @since 1.2.0 
  534. * 
  535. */ 
  536. function bp_activity_per_page() { 
  537. echo bp_get_activity_per_page(); 
  538.  
  539. /** 
  540. * Return the number of activities per page. 
  541. * 
  542. * @since 1.2.0 
  543. * 
  544. * @global object $activities_template {@link BP_Activity_Template} 
  545. * 
  546. * @return int The activities per page. 
  547. */ 
  548. function bp_get_activity_per_page() { 
  549. global $activities_template; 
  550.  
  551. /** 
  552. * Filters the activity posts per page value. 
  553. * 
  554. * @since 1.2.0 
  555. * 
  556. * @param int $pag_num How many post should be displayed for pagination. 
  557. */ 
  558. return apply_filters( 'bp_get_activity_per_page', (int) $activities_template->pag_num ); 
  559.  
  560. /** 
  561. * Output the activities title. 
  562. * 
  563. * @since 1.0.0 
  564. * 
  565. * @todo Deprecate. 
  566. */ 
  567. function bp_activities_title() { 
  568. echo bp_get_activities_title(); 
  569.  
  570. /** 
  571. * Return the activities title. 
  572. * 
  573. * @since 1.0.0 
  574. * 
  575. * @global string $bp_activity_title 
  576. * @todo Deprecate. 
  577. * 
  578. * @return string The activities title. 
  579. */ 
  580. function bp_get_activities_title() { 
  581. global $bp_activity_title; 
  582.  
  583. /** 
  584. * Filters the activities title for the activity template. 
  585. * 
  586. * @since 1.0.0 
  587. * 
  588. * @param string $bp_activity_title The title to be displayed. 
  589. */ 
  590. return apply_filters( 'bp_get_activities_title', $bp_activity_title ); 
  591.  
  592. /** 
  593. * {@internal Missing Description} 
  594. * 
  595. * @since 1.0.0 
  596. * 
  597. * @todo Deprecate. 
  598. */ 
  599. function bp_activities_no_activity() { 
  600. echo bp_get_activities_no_activity(); 
  601.  
  602. /** 
  603. * {@internal Missing Description} 
  604. * 
  605. * @since 1.0.0 
  606. * 
  607. * @global string $bp_activity_no_activity 
  608. * @todo Deprecate. 
  609. * 
  610. * @return string 
  611. */ 
  612. function bp_get_activities_no_activity() { 
  613. global $bp_activity_no_activity; 
  614.  
  615. /** 
  616. * Filters the text used when there is no activity to display. 
  617. * 
  618. * @since 1.0.0 
  619. * 
  620. * @param string $bp_activity_no_activity Text to display for no activity. 
  621. */ 
  622. return apply_filters( 'bp_get_activities_no_activity', $bp_activity_no_activity ); 
  623.  
  624. /** 
  625. * Output the activity ID. 
  626. * 
  627. * @since 1.2.0 
  628. * 
  629. */ 
  630. function bp_activity_id() { 
  631. echo bp_get_activity_id(); 
  632.  
  633. /** 
  634. * Return the activity ID. 
  635. * 
  636. * @since 1.2.0 
  637. * 
  638. * @global object $activities_template {@link BP_Activity_Template} 
  639. * 
  640. * @return int The activity ID. 
  641. */ 
  642. function bp_get_activity_id() { 
  643. global $activities_template; 
  644.  
  645. /** 
  646. * Filters the activity ID being displayed. 
  647. * 
  648. * @since 1.2.0 
  649. * 
  650. * @param int $id The activity ID. 
  651. */ 
  652. return apply_filters( 'bp_get_activity_id', $activities_template->activity->id ); 
  653.  
  654. /** 
  655. * Output the activity item ID. 
  656. * 
  657. * @since 1.2.0 
  658. * 
  659. */ 
  660. function bp_activity_item_id() { 
  661. echo bp_get_activity_item_id(); 
  662.  
  663. /** 
  664. * Return the activity item ID. 
  665. * 
  666. * @since 1.2.0 
  667. * 
  668. * @global object $activities_template {@link BP_Activity_Template} 
  669. * 
  670. * @return int The activity item ID. 
  671. */ 
  672. function bp_get_activity_item_id() { 
  673. global $activities_template; 
  674.  
  675. /** 
  676. * Filters the activity item ID being displayed. 
  677. * 
  678. * @since 1.2.0 
  679. * 
  680. * @param int $item_id The activity item ID. 
  681. */ 
  682. return apply_filters( 'bp_get_activity_item_id', $activities_template->activity->item_id ); 
  683.  
  684. /** 
  685. * Output the activity secondary item ID. 
  686. * 
  687. * @since 1.2.0 
  688. * 
  689. */ 
  690. function bp_activity_secondary_item_id() { 
  691. echo bp_get_activity_secondary_item_id(); 
  692.  
  693. /** 
  694. * Return the activity secondary item ID. 
  695. * 
  696. * @since 1.2.0 
  697. * 
  698. * @global object $activities_template {@link BP_Activity_Template} 
  699. * 
  700. * @return int The activity secondary item ID. 
  701. */ 
  702. function bp_get_activity_secondary_item_id() { 
  703. global $activities_template; 
  704.  
  705. /** 
  706. * Filters the activity secondary item ID being displayed. 
  707. * 
  708. * @since 1.2.0 
  709. * 
  710. * @param int $secondary_item_id The activity secondary item ID. 
  711. */ 
  712. return apply_filters( 'bp_get_activity_secondary_item_id', $activities_template->activity->secondary_item_id ); 
  713.  
  714. /** 
  715. * Output the date the activity was recorded. 
  716. * 
  717. * @since 1.2.0 
  718. * 
  719. */ 
  720. function bp_activity_date_recorded() { 
  721. echo bp_get_activity_date_recorded(); 
  722.  
  723. /** 
  724. * Return the date the activity was recorded. 
  725. * 
  726. * @since 1.2.0 
  727. * 
  728. * @global object $activities_template {@link BP_Activity_Template} 
  729. * 
  730. * @return string The date the activity was recorded. 
  731. */ 
  732. function bp_get_activity_date_recorded() { 
  733. global $activities_template; 
  734.  
  735. /** 
  736. * Filters the date the activity was recorded. 
  737. * 
  738. * @since 1.2.0 
  739. * 
  740. * @param int $date_recorded The activity's date. 
  741. */ 
  742. return apply_filters( 'bp_get_activity_date_recorded', $activities_template->activity->date_recorded ); 
  743.  
  744. /** 
  745. * Output the display name of the member who posted the activity. 
  746. * 
  747. * @since 2.1.0 
  748. * 
  749. */ 
  750. function bp_activity_member_display_name() { 
  751. echo bp_get_activity_member_display_name(); 
  752.  
  753. /** 
  754. * Return the display name of the member who posted the activity. 
  755. * 
  756. * @since 2.1.0 
  757. * 
  758. * @global object $activities_template {@link BP_Activity_Template} 
  759. * 
  760. * @return string The date the activity was recorded. 
  761. */ 
  762. function bp_get_activity_member_display_name() { 
  763. global $activities_template; 
  764.  
  765. $retval = isset( $activities_template->activity->display_name ) 
  766. ? $activities_template->activity->display_name 
  767. : ''; 
  768.  
  769. /** 
  770. * Filters the display name of the member who posted the activity. 
  771. * 
  772. * @since 2.1.0 
  773. * 
  774. * @param int $retval Display name for the member who posted. 
  775. */ 
  776. return apply_filters( 'bp_get_activity_member_display_name', $retval ); 
  777.  
  778. /** 
  779. * Output the activity object name. 
  780. * 
  781. * @since 1.2.0 
  782. * 
  783. */ 
  784. function bp_activity_object_name() { 
  785. echo bp_get_activity_object_name(); 
  786.  
  787. /** 
  788. * Return the activity object name. 
  789. * 
  790. * @since 1.2.0 
  791. * 
  792. * @global object $activities_template {@link BP_Activity_Template} 
  793. * 
  794. * @return string The activity object name. 
  795. */ 
  796. function bp_get_activity_object_name() { 
  797. global $activities_template; 
  798.  
  799. /** 
  800. * Filters the activity object name. 
  801. * 
  802. * @since 1.2.0 
  803. * 
  804. * @param string $activity_component The activity object name. 
  805. */ 
  806. return apply_filters( 'bp_get_activity_object_name', $activities_template->activity->component ); 
  807.  
  808. /** 
  809. * Output the activity type. 
  810. * 
  811. * @since 1.2.0 
  812. * 
  813. */ 
  814. function bp_activity_type() { 
  815. echo bp_get_activity_type(); 
  816.  
  817. /** 
  818. * Return the activity type. 
  819. * 
  820. * @since 1.2.0 
  821. * 
  822. * @global object $activities_template {@link BP_Activity_Template} 
  823. * 
  824. * @return string The activity type. 
  825. */ 
  826. function bp_get_activity_type() { 
  827. global $activities_template; 
  828.  
  829. /** 
  830. * Filters the activity type. 
  831. * 
  832. * @since 1.2.0 
  833. * 
  834. * @param string $activity_type The activity type. 
  835. */ 
  836. return apply_filters( 'bp_get_activity_type', $activities_template->activity->type ); 
  837.  
  838. /** 
  839. * Output the activity action name. 
  840. * 
  841. * Just a wrapper for bp_activity_type(). 
  842. * 
  843. * @since 1.2.0 
  844. * @deprecated 1.5.0 
  845. * 
  846. * @todo Properly deprecate in favor of bp_activity_type() and 
  847. * remove redundant echo 
  848. * 
  849. */ 
  850. function bp_activity_action_name() { echo bp_activity_type(); } 
  851.  
  852. /** 
  853. * Return the activity type. 
  854. * 
  855. * Just a wrapper for bp_get_activity_type(). 
  856. * 
  857. * @since 1.2.0 
  858. * @deprecated 1.5.0 
  859. * 
  860. * @todo Properly deprecate in favor of bp_get_activity_type(). 
  861. * 
  862. * 
  863. * @return string The activity type. 
  864. */ 
  865. function bp_get_activity_action_name() { return bp_get_activity_type(); } 
  866.  
  867. /** 
  868. * Output the activity user ID. 
  869. * 
  870. * @since 1.1.0 
  871. * 
  872. */ 
  873. function bp_activity_user_id() { 
  874. echo bp_get_activity_user_id(); 
  875.  
  876. /** 
  877. * Return the activity user ID. 
  878. * 
  879. * @since 1.1.0 
  880. * 
  881. * @global object $activities_template {@link BP_Activity_Template} 
  882. * 
  883. * @return int The activity user ID. 
  884. */ 
  885. function bp_get_activity_user_id() { 
  886. global $activities_template; 
  887.  
  888. /** 
  889. * Filters the activity user ID. 
  890. * 
  891. * @since 1.1.0 
  892. * 
  893. * @param int $user_id The activity user ID. 
  894. */ 
  895. return apply_filters( 'bp_get_activity_user_id', $activities_template->activity->user_id ); 
  896.  
  897. /** 
  898. * Output the activity user link. 
  899. * 
  900. * @since 1.2.0 
  901. * 
  902. */ 
  903. function bp_activity_user_link() { 
  904. echo bp_get_activity_user_link(); 
  905.  
  906. /** 
  907. * Return the activity user link. 
  908. * 
  909. * @since 1.2.0 
  910. * 
  911. * @global object $activities_template {@link BP_Activity_Template} 
  912. * 
  913. * @return string $link The activity user link. 
  914. */ 
  915. function bp_get_activity_user_link() { 
  916. global $activities_template; 
  917.  
  918. if ( empty( $activities_template->activity->user_id ) || empty( $activities_template->activity->user_nicename ) || empty( $activities_template->activity->user_login ) ) { 
  919. $link = $activities_template->activity->primary_link; 
  920. } else { 
  921. $link = bp_core_get_user_domain( $activities_template->activity->user_id, $activities_template->activity->user_nicename, $activities_template->activity->user_login ); 
  922.  
  923. /** 
  924. * Filters the activity user link. 
  925. * 
  926. * @since 1.2.0 
  927. * 
  928. * @param string $link The activity user link. 
  929. */ 
  930. return apply_filters( 'bp_get_activity_user_link', $link ); 
  931.  
  932. /** 
  933. * Output the avatar of the user that performed the action. 
  934. * 
  935. * @since 1.1.0 
  936. * 
  937. * @see bp_get_activity_avatar() for description of arguments. 
  938. * 
  939. * @param array|string $args See {@link bp_get_activity_avatar()} for description. 
  940. */ 
  941. function bp_activity_avatar( $args = '' ) { 
  942. echo bp_get_activity_avatar( $args ); 
  943. /** 
  944. * Return the avatar of the user that performed the action. 
  945. * 
  946. * @since 1.1.0 
  947. * 
  948. * @see bp_core_fetch_avatar() For a description of the arguments. 
  949. * @global object $activities_template {@link BP_Activity_Template} 
  950. * 
  951. * @param array|string $args { 
  952. * Arguments are listed here with an explanation of their defaults. 
  953. * For more information about the arguments, see 
  954. * {@link bp_core_fetch_avatar()}. 
  955. * @type string $alt Default: 'Profile picture of [user name]' if 
  956. * activity user name is available, otherwise 'Profile picture'. 
  957. * @type string $class Default: 'avatar'. 
  958. * @type string|bool $email Default: Email of the activity's 
  959. * associated user, if available. Otherwise false. 
  960. * @type string $type Default: 'full' when viewing a single activity 
  961. * permalink page, otherwise 'thumb'. 
  962. * @type int|bool $user_id Default: ID of the activity's user. 
  963. * } 
  964. * @return string User avatar string. 
  965. */ 
  966. function bp_get_activity_avatar( $args = '' ) { 
  967. global $activities_template; 
  968.  
  969. $bp = buddypress(); 
  970.  
  971. // On activity permalink pages, default to the full-size avatar. 
  972. $type_default = bp_is_single_activity() ? 'full' : 'thumb'; 
  973.  
  974. // Within the activity comment loop, the current activity should be set 
  975. // to current_comment. Otherwise, just use activity. 
  976. $current_activity_item = isset( $activities_template->activity->current_comment ) ? $activities_template->activity->current_comment : $activities_template->activity; 
  977.  
  978. // Activity user display name. 
  979. $dn_default = isset( $current_activity_item->display_name ) ? $current_activity_item->display_name : ''; 
  980.  
  981. // Prepend some descriptive text to alt. 
  982. $alt_default = !empty( $dn_default ) ? sprintf( __( 'Profile picture of %s', 'buddypress' ), $dn_default ) : __( 'Profile picture', 'buddypress' ); 
  983.  
  984. $defaults = array( 
  985. 'alt' => $alt_default,  
  986. 'class' => 'avatar',  
  987. 'email' => false,  
  988. 'type' => $type_default,  
  989. 'user_id' => false 
  990. ); 
  991.  
  992. $r = wp_parse_args( $args, $defaults ); 
  993. extract( $r, EXTR_SKIP ); 
  994.  
  995. if ( !isset( $height ) && !isset( $width ) ) { 
  996.  
  997. // Backpat. 
  998. if ( isset( $bp->avatar->full->height ) || isset( $bp->avatar->thumb->height ) ) { 
  999. $height = ( 'full' == $type ) ? $bp->avatar->full->height : $bp->avatar->thumb->height; 
  1000. } else { 
  1001. $height = 20; 
  1002.  
  1003. // Backpat. 
  1004. if ( isset( $bp->avatar->full->width ) || isset( $bp->avatar->thumb->width ) ) { 
  1005. $width = ( 'full' == $type ) ? $bp->avatar->full->width : $bp->avatar->thumb->width; 
  1006. } else { 
  1007. $width = 20; 
  1008.  
  1009. /** 
  1010. * Filters the activity avatar object based on current activity item component. 
  1011. * 
  1012. * This is a variable filter dependent on the component used. 
  1013. * Possible hooks are bp_get_activity_avatar_object_blog,  
  1014. * bp_get_activity_avatar_object_group, and bp_get_activity_avatar_object_user. 
  1015. * 
  1016. * @since 1.1.0 
  1017. * 
  1018. * @param string $component Component being displayed. 
  1019. */ 
  1020. $object = apply_filters( 'bp_get_activity_avatar_object_' . $current_activity_item->component, 'user' ); 
  1021. $item_id = !empty( $user_id ) ? $user_id : $current_activity_item->user_id; 
  1022.  
  1023. /** 
  1024. * Filters the activity avatar item ID. 
  1025. * 
  1026. * @since 1.2.10 
  1027. * 
  1028. * @param int $item_id Item ID for the activity avatar. 
  1029. */ 
  1030. $item_id = apply_filters( 'bp_get_activity_avatar_item_id', $item_id ); 
  1031.  
  1032. // If this is a user object pass the users' email address for Gravatar so we don't have to prefetch it. 
  1033. if ( 'user' == $object && empty( $user_id ) && empty( $email ) && isset( $current_activity_item->user_email ) ) { 
  1034. $email = $current_activity_item->user_email; 
  1035.  
  1036. /** 
  1037. * Filters the value returned by bp_core_fetch_avatar. 
  1038. * 
  1039. * @since 1.1.3 
  1040. * 
  1041. * @param array $value HTML image element containing the activity avatar. 
  1042. */ 
  1043. return apply_filters( 'bp_get_activity_avatar', bp_core_fetch_avatar( array( 
  1044. 'item_id' => $item_id,  
  1045. 'object' => $object,  
  1046. 'type' => $type,  
  1047. 'alt' => $alt,  
  1048. 'class' => $class,  
  1049. 'width' => $width,  
  1050. 'height' => $height,  
  1051. 'email' => $email 
  1052. ) ) ); 
  1053.  
  1054. /** 
  1055. * Output the avatar of the object that action was performed on. 
  1056. * 
  1057. * @since 1.2.0 
  1058. * 
  1059. * @see bp_get_activity_secondary_avatar() for description of arguments. 
  1060. * 
  1061. * @param array|string $args See {@link bp_get_activity_secondary_avatar} for description. 
  1062. */ 
  1063. function bp_activity_secondary_avatar( $args = '' ) { 
  1064. echo bp_get_activity_secondary_avatar( $args ); 
  1065.  
  1066. /** 
  1067. * Return the avatar of the object that action was performed on. 
  1068. * 
  1069. * @since 1.2.0 
  1070. * 
  1071. * @see bp_core_fetch_avatar() for description of arguments. 
  1072. * @global object $activities_template {@link BP_Activity_Template} 
  1073. * 
  1074. * @param array|string $args { 
  1075. * For a complete description of arguments, see {@link bp_core_fetch_avatar()}. 
  1076. * @type string $alt Default value varies based on current activity 
  1077. * item component. 
  1078. * @type string $type Default: 'full' when viewing a single activity 
  1079. * permalink page, otherwise 'thumb'. 
  1080. * @type string $class Default: 'avatar'. 
  1081. * @type string|bool $email Default: email of the activity's user. 
  1082. * @type int|bool $user_id Default: ID of the activity's user. 
  1083. * } 
  1084. * @return string The secondary avatar. 
  1085. */ 
  1086. function bp_get_activity_secondary_avatar( $args = '' ) { 
  1087. global $activities_template; 
  1088.  
  1089. $r = wp_parse_args( $args, array( 
  1090. 'alt' => '',  
  1091. 'type' => 'thumb',  
  1092. 'width' => 20,  
  1093. 'height' => 20,  
  1094. 'class' => 'avatar',  
  1095. 'link_class' => '',  
  1096. 'linked' => true,  
  1097. 'email' => false 
  1098. ) ); 
  1099. extract( $r, EXTR_SKIP ); 
  1100.  
  1101. // Set item_id and object (default to user). 
  1102. switch ( $activities_template->activity->component ) { 
  1103. case 'groups' : 
  1104. if ( bp_disable_group_avatar_uploads() ) { 
  1105. return false; 
  1106.  
  1107. $object = 'group'; 
  1108. $item_id = $activities_template->activity->item_id; 
  1109. $link = ''; 
  1110. $name = ''; 
  1111.  
  1112. // Only if groups is active. 
  1113. if ( bp_is_active( 'groups' ) ) { 
  1114. $group = groups_get_group( $item_id ); 
  1115. $link = bp_get_group_permalink( $group ); 
  1116. $name = $group->name; 
  1117.  
  1118. if ( empty( $alt ) ) { 
  1119. $alt = __( 'Group logo', 'buddypress' ); 
  1120.  
  1121. if ( ! empty( $name ) ) { 
  1122. $alt = sprintf( __( 'Group logo of %s', 'buddypress' ), $name ); 
  1123.  
  1124. break; 
  1125. case 'blogs' : 
  1126. $object = 'blog'; 
  1127. $item_id = $activities_template->activity->item_id; 
  1128. $link = home_url(); 
  1129.  
  1130. if ( empty( $alt ) ) { 
  1131. $alt = sprintf( __( 'Profile picture of the author of the site %s', 'buddypress' ), get_blog_option( $item_id, 'blogname' ) ); 
  1132.  
  1133. break; 
  1134. case 'friends' : 
  1135. $object = 'user'; 
  1136. $item_id = $activities_template->activity->secondary_item_id; 
  1137. $link = bp_core_get_userlink( $item_id, false, true ); 
  1138.  
  1139. if ( empty( $alt ) ) { 
  1140. $alt = sprintf( __( 'Profile picture of %s', 'buddypress' ), bp_core_get_user_displayname( $activities_template->activity->secondary_item_id ) ); 
  1141.  
  1142. break; 
  1143. default : 
  1144. $object = 'user'; 
  1145. $item_id = $activities_template->activity->user_id; 
  1146. $email = $activities_template->activity->user_email; 
  1147. $link = bp_core_get_userlink( $item_id, false, true ); 
  1148.  
  1149. if ( empty( $alt ) ) { 
  1150. $alt = sprintf( __( 'Profile picture of %s', 'buddypress' ), $activities_template->activity->display_name ); 
  1151.  
  1152. break; 
  1153.  
  1154. /** 
  1155. * Filters the activity secondary avatar object based on current activity item component. 
  1156. * 
  1157. * This is a variable filter dependent on the component used. Possible hooks are 
  1158. * bp_get_activity_secondary_avatar_object_blog, bp_get_activity_secondary_avatar_object_group,  
  1159. * and bp_get_activity_secondary_avatar_object_user. 
  1160. * 
  1161. * @since 1.2.10 
  1162. * 
  1163. * @param string $object Component being displayed. 
  1164. */ 
  1165. $object = apply_filters( 'bp_get_activity_secondary_avatar_object_' . $activities_template->activity->component, $object ); 
  1166.  
  1167. /** 
  1168. * Filters the activity secondary avatar item ID. 
  1169. * 
  1170. * @since 1.2.10 
  1171. * 
  1172. * @param int $item_id ID for the secondary avatar item. 
  1173. */ 
  1174. $item_id = apply_filters( 'bp_get_activity_secondary_avatar_item_id', $item_id ); 
  1175.  
  1176. // If we have no item_id or object, there is no avatar to display. 
  1177. if ( empty( $item_id ) || empty( $object ) ) { 
  1178. return false; 
  1179.  
  1180. // Get the avatar. 
  1181. $avatar = bp_core_fetch_avatar( array( 
  1182. 'item_id' => $item_id,  
  1183. 'object' => $object,  
  1184. 'type' => $type,  
  1185. 'alt' => $alt,  
  1186. 'class' => $class,  
  1187. 'width' => $width,  
  1188. 'height' => $height,  
  1189. 'email' => $email 
  1190. ) ); 
  1191.  
  1192. if ( !empty( $linked ) ) { 
  1193.  
  1194. /** 
  1195. * Filters the secondary avatar link for current activity. 
  1196. * 
  1197. * @since 1.7.0 
  1198. * 
  1199. * @param string $link Link to wrap the avatar image in. 
  1200. * @param string $component Activity component being acted on. 
  1201. */ 
  1202. $link = apply_filters( 'bp_get_activity_secondary_avatar_link', $link, $activities_template->activity->component ); 
  1203.  
  1204. /** 
  1205. * Filters the determined avatar for the secondary activity item. 
  1206. * 
  1207. * @since 1.2.10 
  1208. * 
  1209. * @param string $avatar Formatted HTML <img> element, or raw avatar URL. 
  1210. */ 
  1211. $avatar = apply_filters( 'bp_get_activity_secondary_avatar', $avatar ); 
  1212.  
  1213. return sprintf( '<a href="%s" class="%s">%s</a>',  
  1214. $link,  
  1215. $link_class,  
  1216. $avatar 
  1217. ); 
  1218.  
  1219. /** This filter is documented in bp-activity/bp-activity-template.php */ 
  1220. return apply_filters( 'bp_get_activity_secondary_avatar', $avatar ); 
  1221.  
  1222. /** 
  1223. * Output the activity action. 
  1224. * 
  1225. * @since 1.2.0 
  1226. * 
  1227. * @param array $args See bp_get_activity_action(). 
  1228. */ 
  1229. function bp_activity_action( $args = array() ) { 
  1230. echo bp_get_activity_action( $args ); 
  1231.  
  1232. /** 
  1233. * Return the activity action. 
  1234. * 
  1235. * @since 1.2.0 
  1236. * 
  1237. * @global object $activities_template {@link BP_Activity_Template} 
  1238. * 
  1239. * @param array $args { 
  1240. * @type bool $no_timestamp Whether to exclude the timestamp. 
  1241. * } 
  1242. * 
  1243. * @return string The activity action. 
  1244. */ 
  1245. function bp_get_activity_action( $args = array() ) { 
  1246. global $activities_template; 
  1247.  
  1248. $r = wp_parse_args( $args, array( 
  1249. 'no_timestamp' => false,  
  1250. ) ); 
  1251.  
  1252. /** 
  1253. * Filters the activity action before the action is inserted as meta. 
  1254. * 
  1255. * @since 1.2.10 
  1256. * 
  1257. * @param array $value Array containing the current action, the current activity, and the $args array passed into the function. 
  1258. */ 
  1259. $action = apply_filters_ref_array( 'bp_get_activity_action_pre_meta', array( 
  1260. $activities_template->activity->action,  
  1261. &$activities_template->activity,  
  1262. $r 
  1263. ) ); 
  1264.  
  1265. // Prepend the activity action meta (link, time since, etc...). 
  1266. if ( ! empty( $action ) && empty( $r['no_timestamp'] ) ) { 
  1267. $action = bp_insert_activity_meta( $action ); 
  1268.  
  1269. /** 
  1270. * Filters the activity action after the action has been inserted as meta. 
  1271. * 
  1272. * @since 1.2.0 
  1273. * 
  1274. * @param array $value Array containing the current action, the current activity, and the $args array passed into the function. 
  1275. */ 
  1276. return apply_filters_ref_array( 'bp_get_activity_action', array( 
  1277. $action,  
  1278. &$activities_template->activity,  
  1279. $r 
  1280. ) ); 
  1281.  
  1282. /** 
  1283. * Output the activity content body. 
  1284. * 
  1285. * @since 1.2.0 
  1286. * 
  1287. */ 
  1288. function bp_activity_content_body() { 
  1289. echo bp_get_activity_content_body(); 
  1290.  
  1291. /** 
  1292. * Return the activity content body. 
  1293. * 
  1294. * @since 1.2.0 
  1295. * 
  1296. * @global object $activities_template {@link BP_Activity_Template} 
  1297. * 
  1298. * @return string The activity content body. 
  1299. */ 
  1300. function bp_get_activity_content_body() { 
  1301. global $activities_template; 
  1302.  
  1303. // Backwards compatibility if action is not being used. 
  1304. if ( empty( $activities_template->activity->action ) && ! empty( $activities_template->activity->content ) ) { 
  1305. $activities_template->activity->content = bp_insert_activity_meta( $activities_template->activity->content ); 
  1306.  
  1307. /** 
  1308. * Filters the activity content body. 
  1309. * 
  1310. * @since 1.2.0 
  1311. * 
  1312. * @param string $content Content body. 
  1313. * @param object $activity Activity object. Passed by reference. 
  1314. */ 
  1315. return apply_filters_ref_array( 'bp_get_activity_content_body', array( $activities_template->activity->content, &$activities_template->activity ) ); 
  1316.  
  1317. /** 
  1318. * Does the activity have content? 
  1319. * 
  1320. * @since 1.2.0 
  1321. * 
  1322. * @global object $activities_template {@link BP_Activity_Template} 
  1323. * 
  1324. * @return bool True if activity has content, false otherwise. 
  1325. */ 
  1326. function bp_activity_has_content() { 
  1327. global $activities_template; 
  1328.  
  1329. if ( ! empty( $activities_template->activity->content ) ) { 
  1330. return true; 
  1331.  
  1332. return false; 
  1333.  
  1334. /** 
  1335. * Output the activity content. 
  1336. * 
  1337. * @since 1.0.0 
  1338. * @deprecated 1.5.0 
  1339. * 
  1340. * @todo properly deprecate this function. 
  1341. * 
  1342. */ 
  1343. function bp_activity_content() { 
  1344. echo bp_get_activity_content(); 
  1345.  
  1346. /** 
  1347. * Return the activity content. 
  1348. * 
  1349. * @since 1.0.0 
  1350. * @deprecated 1.5.0 
  1351. * 
  1352. * @todo properly deprecate this function. 
  1353. * 
  1354. * 
  1355. * @return string The activity content. 
  1356. */ 
  1357. function bp_get_activity_content() { 
  1358.  
  1359. /** 
  1360. * If you want to filter activity update content, please use 
  1361. * the filter 'bp_get_activity_content_body'. 
  1362. * 
  1363. * This function is mainly for backwards compatibility. 
  1364. */ 
  1365. $content = bp_get_activity_action() . ' ' . bp_get_activity_content_body(); 
  1366. return apply_filters( 'bp_get_activity_content', $content ); 
  1367.  
  1368. /** 
  1369. * Attach metadata about an activity item to the activity content. 
  1370. * 
  1371. * This metadata includes the time since the item was posted (which will appear 
  1372. * as a link to the item's permalink). 
  1373. * 
  1374. * @since 1.2.0 
  1375. * 
  1376. * @global object $activities_template {@link BP_Activity_Template} 
  1377. * 
  1378. * @param string $content The activity content. 
  1379. * @return string The activity content with the metadata string attached. 
  1380. */ 
  1381. function bp_insert_activity_meta( $content = '' ) { 
  1382. global $activities_template; 
  1383.  
  1384. // Strip any legacy time since placeholders from BP 1.0-1.1. 
  1385. $new_content = str_replace( '<span class="time-since">%s</span>', '', $content ); 
  1386.  
  1387. // Get the time since this activity was recorded. 
  1388. $date_recorded = bp_core_time_since( $activities_template->activity->date_recorded ); 
  1389.  
  1390. // Set up 'time-since' <span>. 
  1391. $time_since = sprintf( 
  1392. '<span class="time-since" data-livestamp="%1$s">%2$s</span>',  
  1393. bp_core_get_iso8601_date( $activities_template->activity->date_recorded ),  
  1394. $date_recorded 
  1395. ); 
  1396.  
  1397. /** 
  1398. * Filters the activity item time since markup. 
  1399. * 
  1400. * @since 1.2.0 
  1401. * 
  1402. * @param array $value Array containing the time since markup and the current activity component. 
  1403. */ 
  1404. $time_since = apply_filters_ref_array( 'bp_activity_time_since', array( 
  1405. $time_since,  
  1406. &$activities_template->activity 
  1407. ) ); 
  1408.  
  1409. // Insert the permalink. 
  1410. if ( ! bp_is_single_activity() ) { 
  1411.  
  1412. // Setup variables for activity meta. 
  1413. $activity_permalink = bp_activity_get_permalink( $activities_template->activity->id, $activities_template->activity ); 
  1414. $activity_meta = sprintf( '%1$s <a href="%2$s" class="view activity-time-since" title="%3$s">%4$s</a>',  
  1415. $new_content,  
  1416. $activity_permalink,  
  1417. esc_attr__( 'View Discussion', 'buddypress' ),  
  1418. $time_since 
  1419. ); 
  1420.  
  1421. /** 
  1422. * Filters the activity permalink to be added to the activity content. 
  1423. * 
  1424. * @since 1.2.0 
  1425. * 
  1426. * @param array $value Array containing the html markup for the activity permalink, after being parsed by 
  1427. * sprintf and current activity component. 
  1428. */ 
  1429. $new_content = apply_filters_ref_array( 'bp_activity_permalink', array( 
  1430. $activity_meta,  
  1431. &$activities_template->activity 
  1432. ) ); 
  1433. } else { 
  1434. $new_content .= str_pad( $time_since, strlen( $time_since ) + 2, ' ', STR_PAD_BOTH ); 
  1435.  
  1436. /** 
  1437. * Filters the activity content after activity metadata has been attached. 
  1438. * 
  1439. * @since 1.2.0 
  1440. * 
  1441. * @param string $content Activity content with the activity metadata added. 
  1442. */ 
  1443. return apply_filters( 'bp_insert_activity_meta', $new_content, $content ); 
  1444.  
  1445. /** 
  1446. * Determine if the current user can delete an activity item. 
  1447. * 
  1448. * @since 1.2.0 
  1449. * 
  1450. * @global object $activities_template {@link BP_Activity_Template} 
  1451. * 
  1452. * @param BP_Activity_Activity $activity Optional. Falls back on the current item in the loop. 
  1453. * @return bool True if can delete, false otherwise. 
  1454. */ 
  1455. function bp_activity_user_can_delete( $activity = false ) { 
  1456. global $activities_template; 
  1457.  
  1458. // Try to use current activity if none was passed. 
  1459. if ( empty( $activity ) && ! empty( $activities_template->activity ) ) { 
  1460. $activity = $activities_template->activity; 
  1461.  
  1462. // If current_comment is set, we'll use that in place of the main activity. 
  1463. if ( isset( $activity->current_comment ) ) { 
  1464. $activity = $activity->current_comment; 
  1465.  
  1466. // Assume the user cannot delete the activity item. 
  1467. $can_delete = false; 
  1468.  
  1469. // Only logged in users can delete activity. 
  1470. if ( is_user_logged_in() ) { 
  1471.  
  1472. // Community moderators can always delete activity (at least for now). 
  1473. if ( bp_current_user_can( 'bp_moderate' ) ) { 
  1474. $can_delete = true; 
  1475.  
  1476. // Users are allowed to delete their own activity. This is actually 
  1477. // quite powerful, because doing so also deletes all comments to that 
  1478. // activity item. We should revisit this eventually. 
  1479. if ( isset( $activity->user_id ) && ( $activity->user_id === bp_loggedin_user_id() ) ) { 
  1480. $can_delete = true; 
  1481.  
  1482. // Viewing a single item, and this user is an admin of that item. 
  1483. if ( bp_is_single_item() && bp_is_item_admin() ) { 
  1484. $can_delete = true; 
  1485.  
  1486. /** 
  1487. * Filters whether the current user can delete an activity item. 
  1488. * 
  1489. * @since 1.5.0 
  1490. * 
  1491. * @param bool $can_delete Whether the user can delete the item. 
  1492. * @param object $activity Current activity item object. 
  1493. */ 
  1494. return (bool) apply_filters( 'bp_activity_user_can_delete', $can_delete, $activity ); 
  1495.  
  1496. /** 
  1497. * Output the activity parent content. 
  1498. * 
  1499. * @since 1.2.0 
  1500. * 
  1501. * @see bp_get_activity_parent_content() for a description of arguments. 
  1502. * 
  1503. * @param array|string $args See {@link bp_get_activity_parent_content} for description. 
  1504. */ 
  1505. function bp_activity_parent_content( $args = '' ) { 
  1506. echo bp_get_activity_parent_content($args); 
  1507.  
  1508. /** 
  1509. * Return the activity content. 
  1510. * 
  1511. * @since 1.2.0 
  1512. * 
  1513. * @global object $activities_template {@link BP_Activity_Template} 
  1514. * 
  1515. * @param string $args Unused. Left over from an earlier implementation. 
  1516. * @return mixed False on failure, otherwise the activity parent content. 
  1517. */ 
  1518. function bp_get_activity_parent_content( $args = '' ) { 
  1519. global $activities_template; 
  1520.  
  1521. // Bail if no activity on no item ID. 
  1522. if ( empty( $activities_template->activity ) || empty( $activities_template->activity->item_id ) ) { 
  1523. return false; 
  1524.  
  1525. // Get the ID of the parent activity content. 
  1526. $parent_id = $activities_template->activity->item_id; 
  1527.  
  1528. // Bail if no parent content. 
  1529. if ( empty( $activities_template->activity_parents[ $parent_id ] ) ) { 
  1530. return false; 
  1531.  
  1532. // Bail if no action. 
  1533. if ( empty( $activities_template->activity_parents[ $parent_id ]->action ) ) { 
  1534. return false; 
  1535.  
  1536. // Content always includes action. 
  1537. $content = $activities_template->activity_parents[ $parent_id ]->action; 
  1538.  
  1539. // Maybe append activity content, if it exists. 
  1540. if ( ! empty( $activities_template->activity_parents[ $parent_id ]->content ) ) { 
  1541. $content .= ' ' . $activities_template->activity_parents[ $parent_id ]->content; 
  1542.  
  1543. // Remove the time since content for backwards compatibility. 
  1544. $content = str_replace( '<span class="time-since">%s</span>', '', $content ); 
  1545.  
  1546. // Remove images. 
  1547. $content = preg_replace( '/<img[^>]*>/Ui', '', $content ); 
  1548.  
  1549. /** 
  1550. * Filters the activity parent content. 
  1551. * 
  1552. * @since 1.2.0 
  1553. * 
  1554. * @param string $content Content set to be displayed as parent content. 
  1555. */ 
  1556. return apply_filters( 'bp_get_activity_parent_content', $content ); 
  1557.  
  1558. /** 
  1559. * Output the parent activity's user ID. 
  1560. * 
  1561. * @since 1.7.0 
  1562. */ 
  1563. function bp_activity_parent_user_id() { 
  1564. echo bp_get_activity_parent_user_id(); 
  1565.  
  1566. /** 
  1567. * Return the parent activity's user ID. 
  1568. * 
  1569. * @since 1.7.0 
  1570. * 
  1571. * @global BP_Activity_Template $activities_template 
  1572. * 
  1573. * @return bool|int False if parent activity can't be found, otherwise 
  1574. * the parent activity's user ID. 
  1575. */ 
  1576. function bp_get_activity_parent_user_id() { 
  1577. global $activities_template; 
  1578.  
  1579. // Bail if no activity on no item ID. 
  1580. if ( empty( $activities_template->activity ) || empty( $activities_template->activity->item_id ) ) { 
  1581. return false; 
  1582.  
  1583. // Get the ID of the parent activity content. 
  1584. $parent_id = $activities_template->activity->item_id; 
  1585.  
  1586. // Bail if no parent item. 
  1587. if ( empty( $activities_template->activity_parents[ $parent_id ] ) ) { 
  1588. return false; 
  1589.  
  1590. // Bail if no parent user ID. 
  1591. if ( empty( $activities_template->activity_parents[ $parent_id ]->user_id ) ) { 
  1592. return false; 
  1593.  
  1594. $retval = $activities_template->activity_parents[ $parent_id ]->user_id; 
  1595.  
  1596. /** 
  1597. * Filters the activity parent item's user ID. 
  1598. * 
  1599. * @since 1.7.0 
  1600. * 
  1601. * @param int $retval ID for the activity parent's user. 
  1602. */ 
  1603. return (int) apply_filters( 'bp_get_activity_parent_user_id', $retval ); 
  1604.  
  1605. /** 
  1606. * Output whether or not the current activity is in a current user's favorites. 
  1607. * 
  1608. * @since 1.2.0 
  1609. * 
  1610. */ 
  1611. function bp_activity_is_favorite() { 
  1612. echo bp_get_activity_is_favorite(); 
  1613.  
  1614. /** 
  1615. * Return whether the current activity is in a current user's favorites. 
  1616. * 
  1617. * @since 1.2.0 
  1618. * 
  1619. * @global object $activities_template {@link BP_Activity_Template} 
  1620. * 
  1621. * @return bool True if user favorite, false otherwise. 
  1622. */ 
  1623. function bp_get_activity_is_favorite() { 
  1624. global $activities_template; 
  1625.  
  1626. /** 
  1627. * Filters whether the current activity item is in the current user's favorites. 
  1628. * 
  1629. * @since 1.2.0 
  1630. * 
  1631. * @param bool $value Whether or not the current activity item is in the current user's favorites. 
  1632. */ 
  1633. return (bool) apply_filters( 'bp_get_activity_is_favorite', in_array( $activities_template->activity->id, (array) $activities_template->my_favs ) ); 
  1634.  
  1635. /** 
  1636. * Output the comment markup for an activity item. 
  1637. * 
  1638. * @since 1.2.0 
  1639. * 
  1640. * @todo deprecate $args param 
  1641. * 
  1642. * @param array|string $args See {@link bp_activity_get_comments} for description. 
  1643. */ 
  1644. function bp_activity_comments( $args = '' ) { 
  1645. echo bp_activity_get_comments( $args ); 
  1646.  
  1647. /** 
  1648. * Get the comment markup for an activity item. 
  1649. * 
  1650. * @since 1.2.0 
  1651. * 
  1652. * @todo deprecate $args param 
  1653. * @todo Given that checks for children already happen in bp_activity_recurse_comments(),  
  1654. * this function can probably be streamlined or removed. 
  1655. * 
  1656. * @global object $activities_template {@link BP_Activity_Template} 
  1657. * 
  1658. * @param string $args Unused. Left over from an earlier implementation. 
  1659. * @return bool 
  1660. */ 
  1661. function bp_activity_get_comments( $args = '' ) { 
  1662. global $activities_template; 
  1663.  
  1664. if ( empty( $activities_template->activity->children ) ) { 
  1665. return false; 
  1666.  
  1667. bp_activity_recurse_comments( $activities_template->activity ); 
  1668.  
  1669. /** 
  1670. * Loops through a level of activity comments and loads the template for each. 
  1671. * 
  1672. * Note: The recursion itself used to happen entirely in this function. Now it is 
  1673. * split between here and the comment.php template. 
  1674. * 
  1675. * @since 1.2.0 
  1676. * 
  1677. * @global object $activities_template {@link BP_Activity_Template} 
  1678. * 
  1679. * @param object $comment The activity object currently being recursed. 
  1680. * @return bool|string 
  1681. */ 
  1682. function bp_activity_recurse_comments( $comment ) { 
  1683. global $activities_template; 
  1684.  
  1685. if ( empty( $comment ) ) { 
  1686. return false; 
  1687.  
  1688. if ( empty( $comment->children ) ) { 
  1689. return false; 
  1690.  
  1691. /** 
  1692. * Filters the opening tag for the template that lists activity comments. 
  1693. * 
  1694. * @since 1.6.0 
  1695. * 
  1696. * @param string $value Opening tag for the HTML markup to use. 
  1697. */ 
  1698. echo apply_filters( 'bp_activity_recurse_comments_start_ul', '<ul>' ); 
  1699. foreach ( (array) $comment->children as $comment_child ) { 
  1700.  
  1701. // Put the comment into the global so it's available to filters. 
  1702. $activities_template->activity->current_comment = $comment_child; 
  1703.  
  1704. $template = bp_locate_template( 'activity/comment.php', false, false ); 
  1705.  
  1706. // Backward compatibility. In older versions of BP, the markup was 
  1707. // generated in the PHP instead of a template. This ensures that 
  1708. // older themes (which are not children of bp-default and won't 
  1709. // have the new template) will still work. 
  1710. if ( !$template ) { 
  1711. $template = buddypress()->plugin_dir . '/bp-themes/bp-default/activity/comment.php'; 
  1712.  
  1713. load_template( $template, false ); 
  1714.  
  1715. unset( $activities_template->activity->current_comment ); 
  1716.  
  1717. /** 
  1718. * Filters the closing tag for the template that list activity comments. 
  1719. * 
  1720. * @since 1.6.0 
  1721. * 
  1722. * @param string $value Closing tag for the HTML markup to use. 
  1723. */ 
  1724. echo apply_filters( 'bp_activity_recurse_comments_end_ul', '</ul>' ); 
  1725.  
  1726. /** 
  1727. * Utility function that returns the comment currently being recursed. 
  1728. * 
  1729. * @since 1.5.0 
  1730. * 
  1731. * @global object $activities_template {@link BP_Activity_Template} 
  1732. * 
  1733. * @return object|bool $current_comment The activity comment currently being 
  1734. * displayed. False on failure. 
  1735. */ 
  1736. function bp_activity_current_comment() { 
  1737. global $activities_template; 
  1738.  
  1739. $current_comment = !empty( $activities_template->activity->current_comment ) 
  1740. ? $activities_template->activity->current_comment 
  1741. : false; 
  1742.  
  1743. /** 
  1744. * Filters the current comment being recursed. 
  1745. * 
  1746. * @since 1.5.0 
  1747. * 
  1748. * @param object|bool $current_comment The activity comment currently being displayed. False on failure. 
  1749. */ 
  1750. return apply_filters( 'bp_activity_current_comment', $current_comment ); 
  1751.  
  1752.  
  1753. /** 
  1754. * Output the ID of the activity comment currently being displayed. 
  1755. * 
  1756. * @since 1.5.0 
  1757. * 
  1758. */ 
  1759. function bp_activity_comment_id() { 
  1760. echo bp_get_activity_comment_id(); 
  1761.  
  1762. /** 
  1763. * Return the ID of the activity comment currently being displayed. 
  1764. * 
  1765. * @since 1.5.0 
  1766. * 
  1767. * @global object $activities_template {@link BP_Activity_Template} 
  1768. * 
  1769. * @return int|bool $comment_id The ID of the activity comment currently 
  1770. * being displayed, false if none is found. 
  1771. */ 
  1772. function bp_get_activity_comment_id() { 
  1773. global $activities_template; 
  1774.  
  1775. $comment_id = isset( $activities_template->activity->current_comment->id ) ? $activities_template->activity->current_comment->id : false; 
  1776.  
  1777. /** 
  1778. * Filters the ID of the activity comment currently being displayed. 
  1779. * 
  1780. * @since 1.5.0 
  1781. * 
  1782. * @param int|bool $comment_id ID for the comment currently being displayed. 
  1783. */ 
  1784. return apply_filters( 'bp_activity_comment_id', $comment_id ); 
  1785.  
  1786. /** 
  1787. * Output the ID of the author of the activity comment currently being displayed. 
  1788. * 
  1789. * @since 1.5.0 
  1790. * 
  1791. */ 
  1792. function bp_activity_comment_user_id() { 
  1793. echo bp_get_activity_comment_user_id(); 
  1794.  
  1795. /** 
  1796. * Return the ID of the author of the activity comment currently being displayed. 
  1797. * 
  1798. * @since 1.5.0 
  1799. * 
  1800. * @global object $activities_template {@link BP_Activity_Template} 
  1801. * 
  1802. * @return int|bool $user_id The user_id of the author of the displayed 
  1803. * activity comment. False on failure. 
  1804. */ 
  1805. function bp_get_activity_comment_user_id() { 
  1806. global $activities_template; 
  1807.  
  1808. $user_id = isset( $activities_template->activity->current_comment->user_id ) ? $activities_template->activity->current_comment->user_id : false; 
  1809.  
  1810. /** 
  1811. * Filters the ID of the author of the activity comment currently being displayed. 
  1812. * 
  1813. * @since 1.5.0 
  1814. * 
  1815. * @param int|bool $user_id ID for the author of the comment currently being displayed. 
  1816. */ 
  1817. return apply_filters( 'bp_activity_comment_user_id', $user_id ); 
  1818.  
  1819. /** 
  1820. * Output the author link for the activity comment currently being displayed. 
  1821. * 
  1822. * @since 1.5.0 
  1823. * 
  1824. */ 
  1825. function bp_activity_comment_user_link() { 
  1826. echo bp_get_activity_comment_user_link(); 
  1827.  
  1828. /** 
  1829. * Return the author link for the activity comment currently being displayed. 
  1830. * 
  1831. * @since 1.5.0 
  1832. * 
  1833. * 
  1834. * @return string $user_link The URL of the activity comment author's profile. 
  1835. */ 
  1836. function bp_get_activity_comment_user_link() { 
  1837. $user_link = bp_core_get_user_domain( bp_get_activity_comment_user_id() ); 
  1838.  
  1839. /** 
  1840. * Filters the author link for the activity comment currently being displayed. 
  1841. * 
  1842. * @since 1.5.0 
  1843. * 
  1844. * @param string $user_link Link for the author of the activity comment currently being displayed. 
  1845. */ 
  1846. return apply_filters( 'bp_activity_comment_user_link', $user_link ); 
  1847.  
  1848. /** 
  1849. * Output the author name for the activity comment currently being displayed. 
  1850. * 
  1851. * @since 1.5.0 
  1852. * 
  1853. */ 
  1854. function bp_activity_comment_name() { 
  1855. echo bp_get_activity_comment_name(); 
  1856.  
  1857. /** 
  1858. * Return the author name for the activity comment currently being displayed. 
  1859. * 
  1860. * The use of the 'bp_acomment_name' filter is deprecated. Please use 
  1861. * 'bp_activity_comment_name'. 
  1862. * 
  1863. * @since 1.5.0 
  1864. * 
  1865. * @global object $activities_template {@link BP_Activity_Template} 
  1866. * 
  1867. * @return string $name The full name of the activity comment author. 
  1868. */ 
  1869. function bp_get_activity_comment_name() { 
  1870. global $activities_template; 
  1871.  
  1872. if ( isset( $activities_template->activity->current_comment->user_fullname ) ) { 
  1873.  
  1874. $name = apply_filters( 'bp_acomment_name', $activities_template->activity->current_comment->user_fullname, $activities_template->activity->current_comment ); // Backward compatibility. 
  1875. } else { 
  1876. $name = $activities_template->activity->current_comment->display_name; 
  1877.  
  1878. /** 
  1879. * Filters the name of the author for the activity comment. 
  1880. * 
  1881. * @since 1.5.0 
  1882. * 
  1883. * @param string $name Name to be displayed with the activity comment. 
  1884. */ 
  1885. return apply_filters( 'bp_activity_comment_name', $name ); 
  1886.  
  1887. /** 
  1888. * Output the formatted date_recorded of the activity comment currently being displayed. 
  1889. * 
  1890. * @since 1.5.0 
  1891. * 
  1892. */ 
  1893. function bp_activity_comment_date_recorded() { 
  1894. echo bp_get_activity_comment_date_recorded(); 
  1895.  
  1896. /** 
  1897. * Return the formatted date_recorded for the activity comment currently being displayed. 
  1898. * 
  1899. * @since 1.5.0 
  1900. * 
  1901. * 
  1902. * @return string|bool $date_recorded Time since the activity was recorded,  
  1903. * in the form "%s ago". False on failure. 
  1904. */ 
  1905. function bp_get_activity_comment_date_recorded() { 
  1906.  
  1907. /** 
  1908. * Filters the recorded date of the activity comment currently being displayed. 
  1909. * 
  1910. * @since 1.5.0 
  1911. * 
  1912. * @param string|bool Date for the activity comment currently being displayed. 
  1913. */ 
  1914. return apply_filters( 'bp_activity_comment_date_recorded', bp_core_time_since( bp_get_activity_comment_date_recorded_raw() ) ); 
  1915.  
  1916. /** 
  1917. * Output the date_recorded of the activity comment currently being displayed. 
  1918. * 
  1919. * @since 2.3.0 
  1920. * 
  1921. */ 
  1922. function bp_activity_comment_date_recorded_raw() { 
  1923. echo bp_get_activity_comment_date_recorded_raw(); 
  1924.  
  1925. /** 
  1926. * Return the date_recorded for the activity comment currently being displayed. 
  1927. * 
  1928. * @since 2.3.0 
  1929. * 
  1930. * @global object $activities_template {@link BP_Activity_Template} 
  1931. * 
  1932. * @return string|bool $date_recorded Time since the activity was recorded,  
  1933. * in the form "%s ago". False on failure. 
  1934. */ 
  1935. function bp_get_activity_comment_date_recorded_raw() { 
  1936. global $activities_template; 
  1937.  
  1938. /** 
  1939. * Filters the raw recorded date of the activity comment currently being displayed. 
  1940. * 
  1941. * @since 2.3.0 
  1942. * 
  1943. * @param string|bool Raw date for the activity comment currently being displayed. 
  1944. */ 
  1945. return apply_filters( 'bp_activity_comment_date_recorded', $activities_template->activity->current_comment->date_recorded ); 
  1946.  
  1947. /** 
  1948. * Output the 'delete' URL for the activity comment currently being displayed. 
  1949. * 
  1950. * @since 1.5.0 
  1951. * 
  1952. */ 
  1953. function bp_activity_comment_delete_link() { 
  1954. echo bp_get_activity_comment_delete_link(); 
  1955.  
  1956. /** 
  1957. * Gets the 'delete' URL for the activity comment currently being displayed. 
  1958. * 
  1959. * @since 1.5.0 
  1960. * 
  1961. * 
  1962. * @return string $link The nonced URL for deleting the current 
  1963. * activity comment. 
  1964. */ 
  1965. function bp_get_activity_comment_delete_link() { 
  1966. $link = wp_nonce_url( bp_get_activity_directory_permalink() . 'delete/' . bp_get_activity_comment_id() . '?cid=' . bp_get_activity_comment_id(), 'bp_activity_delete_link' ); 
  1967.  
  1968. /** 
  1969. * Filters the link used for deleting the activity comment currently being displayed. 
  1970. * 
  1971. * @since 1.5.0 
  1972. * 
  1973. * @param string $link Link to use for deleting the currently displayed activity comment. 
  1974. */ 
  1975. return apply_filters( 'bp_activity_comment_delete_link', $link ); 
  1976.  
  1977. /** 
  1978. * Output the content of the activity comment currently being displayed. 
  1979. * 
  1980. * @since 1.5.0 
  1981. * 
  1982. */ 
  1983. function bp_activity_comment_content() { 
  1984. echo bp_get_activity_comment_content(); 
  1985.  
  1986. /** 
  1987. * Return the content of the activity comment currently being displayed. 
  1988. * 
  1989. * The content is run through two filters. 'bp_get_activity_content' 
  1990. * will apply all filters applied to activity items in general. Use 
  1991. * 'bp_activity_comment_content' to modify the content of activity 
  1992. * comments only. 
  1993. * 
  1994. * @since 1.5.0 
  1995. * 
  1996. * @global object $activities_template {@link BP_Activity_Template} 
  1997. * 
  1998. * @return string $content The content of the current activity comment. 
  1999. */ 
  2000. function bp_get_activity_comment_content() { 
  2001. global $activities_template; 
  2002.  
  2003. /** This filter is documented in bp-activity/bp-activity-template.php */ 
  2004. $content = apply_filters( 'bp_get_activity_content', $activities_template->activity->current_comment->content ); 
  2005.  
  2006. /** 
  2007. * Filters the content of the current activity comment. 
  2008. * 
  2009. * @since 1.2.0 
  2010. * 
  2011. * @param string $content The content of the current activity comment. 
  2012. */ 
  2013. return apply_filters( 'bp_activity_comment_content', $content ); 
  2014.  
  2015. /** 
  2016. * Output the activity comment count. 
  2017. * 
  2018. * @since 1.2.0 
  2019. * 
  2020. */ 
  2021. function bp_activity_comment_count() { 
  2022. echo bp_activity_get_comment_count(); 
  2023.  
  2024. /** 
  2025. * Return the comment count of an activity item. 
  2026. * 
  2027. * @since 1.2.0 
  2028. * 
  2029. * @global object $activities_template {@link BP_Activity_Template} 
  2030. * 
  2031. * @param array|null $deprecated Deprecated. 
  2032. * @return int $count The activity comment count. 
  2033. */ 
  2034. function bp_activity_get_comment_count( $deprecated = null ) { 
  2035. global $activities_template; 
  2036.  
  2037. // Deprecated notice about $args. 
  2038. if ( ! empty( $deprecated ) ) { 
  2039. _deprecated_argument( __FUNCTION__, '1.2', sprintf( __( '%1$s no longer accepts arguments. See the inline documentation at %2$s for more details.', 'buddypress' ), __FUNCTION__, __FILE__ ) ); 
  2040.  
  2041. // Get the count using the purpose-built recursive function. 
  2042. $count = ! empty( $activities_template->activity->children ) 
  2043. ? bp_activity_recurse_comment_count( $activities_template->activity ) 
  2044. : 0; 
  2045.  
  2046. /** 
  2047. * Filters the activity comment count. 
  2048. * 
  2049. * @since 1.2.0 
  2050. * 
  2051. * @param int $count The activity comment count. 
  2052. */ 
  2053. return apply_filters( 'bp_activity_get_comment_count', (int) $count ); 
  2054.  
  2055. /** 
  2056. * Return the total number of comments to the current comment. 
  2057. * 
  2058. * This function recursively adds the total number of comments each 
  2059. * activity child has, and returns them. 
  2060. * 
  2061. * @since 1.2.0 
  2062. * 
  2063. * 
  2064. * @param object $comment Activity comment object. 
  2065. * @param int $count The current iteration count. 
  2066. * @return int $count The activity comment count. 
  2067. */ 
  2068. function bp_activity_recurse_comment_count( $comment, $count = 0 ) { 
  2069.  
  2070. // Copy the count. 
  2071. $new_count = $count; 
  2072.  
  2073. // Loop through children and recursively count comments. 
  2074. if ( ! empty( $comment->children ) ) { 
  2075. foreach ( (array) $comment->children as $comment ) { 
  2076. $new_count++; 
  2077. $new_count = bp_activity_recurse_comment_count( $comment, $new_count ); 
  2078.  
  2079. /** 
  2080. * Filters the total number of comments for the current comment. 
  2081. * 
  2082. * @since 2.1.0 
  2083. * 
  2084. * @param int $new_count New total count for the current comment. 
  2085. * @param object $comment Activity comment object. 
  2086. * @param int $count Current iteration count for the current comment. 
  2087. */ 
  2088. return apply_filters( 'bp_activity_recurse_comment_count', $new_count, $comment, $count ); 
  2089.  
  2090. /** 
  2091. * Output the depth of the current activity comment. 
  2092. * 
  2093. * @since 2.0.0 
  2094. * @since 2.8.0 Added $comment as a parameter. 
  2095. * 
  2096. * @param object|int $comment Object of the activity comment or activity comment ID. Usually unnecessary 
  2097. * when used in activity comment loop. 
  2098. */ 
  2099. function bp_activity_comment_depth( $comment = 0 ) { 
  2100. echo bp_activity_get_comment_depth( $comment ); 
  2101.  
  2102. /** 
  2103. * Return the current activity comment depth. 
  2104. * 
  2105. * @since 2.0.0 
  2106. * @since 2.8.0 Added $comment as a parameter. 
  2107. * 
  2108. * @param object|int $comment Object of the activity comment or activity comment ID. Usually unnecessary 
  2109. * when used in activity comment loop. 
  2110. * @return int 
  2111. */ 
  2112. function bp_activity_get_comment_depth( $comment = 0 ) { 
  2113. $depth = 0; 
  2114.  
  2115. // Activity comment loop takes precedence. 
  2116. if ( isset( $GLOBALS['activities_template']->activity->current_comment->depth ) ) { 
  2117. $depth = $GLOBALS['activities_template']->activity->current_comment->depth; 
  2118.  
  2119. // Get depth for activity comment manually. 
  2120. } elseif ( ! empty( $comment ) ) { 
  2121. // We passed an activity ID, so fetch the activity object. 
  2122. if ( is_int( $comment ) ) { 
  2123. $comment = new BP_Activity_Activity( $comment ); 
  2124.  
  2125. // Recurse through activity tree to find the depth. 
  2126. if ( is_object( $comment ) && isset( $comment->type ) && 'activity_comment' === $comment->type ) { 
  2127. // Fetch the entire root comment tree... ugh. 
  2128. $comments = BP_Activity_Activity::get_activity_comments( $comment->item_id, 1, constant( 'PHP_INT_MAX' ) ); 
  2129.  
  2130. // Recursively find our comment object from the comment tree. 
  2131. $iterator = new RecursiveArrayIterator( $comments ); 
  2132. $recursive = new RecursiveIteratorIterator( $iterator, RecursiveIteratorIterator::SELF_FIRST ); 
  2133. foreach ( $recursive as $cid => $cobj ) { 
  2134. // Skip items that are not a comment object. 
  2135. if ( ! is_numeric( $cid ) || ! is_object( $cobj ) ) { 
  2136. continue; 
  2137.  
  2138. // We found the activity comment! Set the depth. 
  2139. if ( $cid === $comment->id && isset( $cobj->depth ) ) { 
  2140. $depth = $cobj->depth; 
  2141. break; 
  2142.  
  2143. /** 
  2144. * Filters the comment depth of the current activity comment. 
  2145. * 
  2146. * @since 2.0.0 
  2147. * 
  2148. * @param int $depth Depth for the current activity comment. 
  2149. */ 
  2150. return apply_filters( 'bp_activity_get_comment_depth', $depth ); 
  2151.  
  2152. /** 
  2153. * Output the activity comment link. 
  2154. * 
  2155. * @since 1.2.0 
  2156. * 
  2157. */ 
  2158. function bp_activity_comment_link() { 
  2159. echo bp_get_activity_comment_link(); 
  2160.  
  2161. /** 
  2162. * Return the activity comment link. 
  2163. * 
  2164. * @since 1.2.0 
  2165. * 
  2166. * @global object $activities_template {@link BP_Activity_Template} 
  2167. * 
  2168. * @return string The activity comment link. 
  2169. */ 
  2170. function bp_get_activity_comment_link() { 
  2171. global $activities_template; 
  2172.  
  2173. /** 
  2174. * Filters the comment link for the current activity comment. 
  2175. * 
  2176. * @since 1.2.0 
  2177. * 
  2178. * @param string $value Constructed URL parameters with activity IDs. 
  2179. */ 
  2180. return apply_filters( 'bp_get_activity_comment_link', '?ac=' . $activities_template->activity->id . '/#ac-form-' . $activities_template->activity->id ); 
  2181.  
  2182. /** 
  2183. * Output the activity comment form no JavaScript display CSS. 
  2184. * 
  2185. * @since 1.2.0 
  2186. * 
  2187. */ 
  2188. function bp_activity_comment_form_nojs_display() { 
  2189. echo bp_get_activity_comment_form_nojs_display(); 
  2190.  
  2191. /** 
  2192. * Return the activity comment form no JavaScript display CSS. 
  2193. * 
  2194. * @since 1.2.0 
  2195. * 
  2196. * @global object $activities_template {@link BP_Activity_Template} 
  2197. * 
  2198. * @return string|bool The activity comment form no JavaScript 
  2199. * display CSS. False on failure. 
  2200. */ 
  2201. function bp_get_activity_comment_form_nojs_display() { 
  2202. global $activities_template; 
  2203.  
  2204. if ( isset( $_GET['ac'] ) && ( $_GET['ac'] === ( $activities_template->activity->id . '/' ) ) ) { 
  2205. return 'style="display: block"'; 
  2206.  
  2207. return false; 
  2208.  
  2209. /** 
  2210. * Output the activity comment form action. 
  2211. * 
  2212. * @since 1.2.0 
  2213. * 
  2214. */ 
  2215. function bp_activity_comment_form_action() { 
  2216. echo bp_get_activity_comment_form_action(); 
  2217.  
  2218. /** 
  2219. * Return the activity comment form action. 
  2220. * 
  2221. * @since 1.2.0 
  2222. * 
  2223. * 
  2224. * @return string The activity comment form action. 
  2225. */ 
  2226. function bp_get_activity_comment_form_action() { 
  2227.  
  2228. /** 
  2229. * Filters the activity comment form action URL. 
  2230. * 
  2231. * @since 1.2.0 
  2232. * 
  2233. * @param string $value URL to use in the comment form's action attribute. 
  2234. */ 
  2235. return apply_filters( 'bp_get_activity_comment_form_action', home_url( bp_get_activity_root_slug() . '/reply/' ) ); 
  2236.  
  2237. /** 
  2238. * Output the activity permalink ID. 
  2239. * 
  2240. * @since 1.2.0 
  2241. * 
  2242. */ 
  2243. function bp_activity_permalink_id() { 
  2244. echo bp_get_activity_permalink_id(); 
  2245.  
  2246. /** 
  2247. * Return the activity permalink ID. 
  2248. * 
  2249. * @since 1.2.0 
  2250. * 
  2251. * 
  2252. * @return string The activity permalink ID. 
  2253. */ 
  2254. function bp_get_activity_permalink_id() { 
  2255.  
  2256. /** 
  2257. * Filters the activity action permalink ID. 
  2258. * 
  2259. * @since 1.2.0 
  2260. * 
  2261. * @param string $value Current action for the activity item. 
  2262. */ 
  2263. return apply_filters( 'bp_get_activity_permalink_id', bp_current_action() ); 
  2264.  
  2265. /** 
  2266. * Output the activity thread permalink. 
  2267. * 
  2268. * @since 1.2.0 
  2269. * 
  2270. */ 
  2271. function bp_activity_thread_permalink() { 
  2272. echo esc_url( bp_get_activity_thread_permalink() ); 
  2273.  
  2274. /** 
  2275. * Return the activity thread permalink. 
  2276. * 
  2277. * @since 1.2.0 
  2278. * 
  2279. * 
  2280. * @return string $link The activity thread permalink. 
  2281. */ 
  2282. function bp_get_activity_thread_permalink() { 
  2283. global $activities_template; 
  2284.  
  2285. $link = bp_activity_get_permalink( $activities_template->activity->id, $activities_template->activity ); 
  2286.  
  2287. /** 
  2288. * Filters the activity thread permalink. 
  2289. * 
  2290. * @since 1.2.0 
  2291. * 
  2292. * @param string $link The activity thread permalink. 
  2293. */ 
  2294. return apply_filters( 'bp_get_activity_thread_permalink', $link ); 
  2295.  
  2296. /** 
  2297. * Output the activity comment permalink. 
  2298. * 
  2299. * @since 1.8.0 
  2300. * 
  2301. */ 
  2302. function bp_activity_comment_permalink() { 
  2303. echo esc_url( bp_get_activity_comment_permalink() ); 
  2304. /** 
  2305. * Return the activity comment permalink. 
  2306. * 
  2307. * @since 1.8.0 
  2308. * 
  2309. * @return string $link The activity comment permalink. 
  2310. */ 
  2311. function bp_get_activity_comment_permalink() { 
  2312. global $activities_template; 
  2313.  
  2314. $link = bp_activity_get_permalink( $activities_template->activity->id, $activities_template->activity ); 
  2315.  
  2316. // Used for filter below. 
  2317. $comment_id = isset( $activities_template->activity->current_comment->id ) 
  2318. ? $activities_template->activity->current_comment->id 
  2319. : 0; 
  2320.  
  2321. /** 
  2322. * Filters the activity comment permalink. 
  2323. * 
  2324. * @since 1.8.0 
  2325. * 
  2326. * @param string $link Activity comment permalink. 
  2327. * @param int $comment_id ID for the current activity comment. 
  2328. */ 
  2329. return apply_filters( 'bp_get_activity_comment_permalink', $link, $comment_id ); 
  2330.  
  2331. /** 
  2332. * Output the activity favorite link. 
  2333. * 
  2334. * @since 1.2.0 
  2335. * 
  2336. */ 
  2337. function bp_activity_favorite_link() { 
  2338. echo bp_get_activity_favorite_link(); 
  2339.  
  2340. /** 
  2341. * Return the activity favorite link. 
  2342. * 
  2343. * @since 1.2.0 
  2344. * 
  2345. * @global object $activities_template {@link BP_Activity_Template} 
  2346. * 
  2347. * @return string The activity favorite link. 
  2348. */ 
  2349. function bp_get_activity_favorite_link() { 
  2350. global $activities_template; 
  2351.  
  2352. /** 
  2353. * Filters the activity favorite link. 
  2354. * 
  2355. * @since 1.2.0 
  2356. * 
  2357. * @param string $value Constructed link for favoriting the activity comment. 
  2358. */ 
  2359. return apply_filters( 'bp_get_activity_favorite_link', wp_nonce_url( home_url( bp_get_activity_root_slug() . '/favorite/' . $activities_template->activity->id . '/' ), 'mark_favorite' ) ); 
  2360.  
  2361. /** 
  2362. * Output the activity unfavorite link. 
  2363. * 
  2364. * @since 1.2.0 
  2365. * 
  2366. */ 
  2367. function bp_activity_unfavorite_link() { 
  2368. echo bp_get_activity_unfavorite_link(); 
  2369.  
  2370. /** 
  2371. * Return the activity unfavorite link. 
  2372. * 
  2373. * @since 1.2.0 
  2374. * 
  2375. * @global object $activities_template {@link BP_Activity_Template} 
  2376. * 
  2377. * @return string The activity unfavorite link. 
  2378. */ 
  2379. function bp_get_activity_unfavorite_link() { 
  2380. global $activities_template; 
  2381.  
  2382. /** 
  2383. * Filters the activity unfavorite link. 
  2384. * 
  2385. * @since 1.2.0 
  2386. * 
  2387. * @param string $value Constructed link for unfavoriting the activity comment. 
  2388. */ 
  2389. return apply_filters( 'bp_get_activity_unfavorite_link', wp_nonce_url( home_url( bp_get_activity_root_slug() . '/unfavorite/' . $activities_template->activity->id . '/' ), 'unmark_favorite' ) ); 
  2390.  
  2391. /** 
  2392. * Output the activity CSS class. 
  2393. * 
  2394. * @since 1.0.0 
  2395. * 
  2396. */ 
  2397. function bp_activity_css_class() { 
  2398. echo bp_get_activity_css_class(); 
  2399.  
  2400. /** 
  2401. * Return the current activity item's CSS class. 
  2402. * 
  2403. * @since 1.0.0 
  2404. * 
  2405. * @global object $activities_template {@link BP_Activity_Template} 
  2406. * 
  2407. * @return string The activity item's CSS class. 
  2408. */ 
  2409. function bp_get_activity_css_class() { 
  2410. global $activities_template; 
  2411.  
  2412. /** 
  2413. * Filters the available mini activity actions available as CSS classes. 
  2414. * 
  2415. * @since 1.2.0 
  2416. * 
  2417. * @param array $value Array of classes used to determine classes applied to HTML element. 
  2418. */ 
  2419. $mini_activity_actions = apply_filters( 'bp_activity_mini_activity_types', array( 
  2420. 'friendship_accepted',  
  2421. 'friendship_created',  
  2422. 'new_blog',  
  2423. 'joined_group',  
  2424. 'created_group',  
  2425. 'new_member' 
  2426. ) ); 
  2427.  
  2428. $class = ' activity-item'; 
  2429.  
  2430. if ( in_array( $activities_template->activity->type, (array) $mini_activity_actions ) || empty( $activities_template->activity->content ) ) { 
  2431. $class .= ' mini'; 
  2432.  
  2433. if ( bp_activity_get_comment_count() && bp_activity_can_comment() ) { 
  2434. $class .= ' has-comments'; 
  2435.  
  2436. /** 
  2437. * Filters the determined classes to add to the HTML element. 
  2438. * 
  2439. * @since 1.0.0 
  2440. * 
  2441. * @param string $value Classes to be added to the HTML element. 
  2442. */ 
  2443. return apply_filters( 'bp_get_activity_css_class', $activities_template->activity->component . ' ' . $activities_template->activity->type . $class ); 
  2444.  
  2445. /** 
  2446. * Output the activity delete link. 
  2447. * 
  2448. * @since 1.1.0 
  2449. * 
  2450. */ 
  2451. function bp_activity_delete_link() { 
  2452. echo bp_get_activity_delete_link(); 
  2453.  
  2454. /** 
  2455. * Return the activity delete link. 
  2456. * 
  2457. * @since 1.1.0 
  2458. * 
  2459. * @global object $activities_template {@link BP_Activity_Template} 
  2460. * 
  2461. * @return string $link Activity delete link. Contains $redirect_to arg 
  2462. * if on single activity page. 
  2463. */ 
  2464. function bp_get_activity_delete_link() { 
  2465.  
  2466. $url = bp_get_activity_delete_url(); 
  2467. $class = 'delete-activity'; 
  2468.  
  2469. // Determine if we're on a single activity page, and customize accordingly. 
  2470. if ( bp_is_activity_component() && is_numeric( bp_current_action() ) ) { 
  2471. $class = 'delete-activity-single'; 
  2472.  
  2473. $link = '<a href="' . esc_url( $url ) . '" class="button item-button bp-secondary-action ' . $class . ' confirm" rel="nofollow">' . __( 'Delete', 'buddypress' ) . '</a>'; 
  2474.  
  2475. /** 
  2476. * Filters the activity delete link. 
  2477. * 
  2478. * @since 1.1.0 
  2479. * 
  2480. * @param string $link Activity delete HTML link. 
  2481. */ 
  2482. return apply_filters( 'bp_get_activity_delete_link', $link ); 
  2483.  
  2484. /** 
  2485. * Output the URL to delete a single activity stream item. 
  2486. * 
  2487. * @since 2.1.0 
  2488. * 
  2489. */ 
  2490. function bp_activity_delete_url() { 
  2491. echo esc_url( bp_get_activity_delete_url() ); 
  2492. /** 
  2493. * Return the URL to delete a single activity item. 
  2494. * 
  2495. * @since 2.1.0 
  2496. * 
  2497. * @global object $activities_template {@link BP_Activity_Template} 
  2498. * 
  2499. * @return string $link Activity delete link. Contains $redirect_to arg 
  2500. * if on single activity page. 
  2501. */ 
  2502. function bp_get_activity_delete_url() { 
  2503. global $activities_template; 
  2504.  
  2505. $url = trailingslashit( bp_get_root_domain() . '/' . bp_get_activity_root_slug() . '/delete/' . $activities_template->activity->id ); 
  2506.  
  2507. // Determine if we're on a single activity page, and customize accordingly. 
  2508. if ( bp_is_activity_component() && is_numeric( bp_current_action() ) ) { 
  2509. $url = add_query_arg( array( 'redirect_to' => wp_get_referer() ), $url ); 
  2510.  
  2511. $url = wp_nonce_url( $url, 'bp_activity_delete_link' ); 
  2512.  
  2513. /** 
  2514. * Filters the activity delete URL. 
  2515. * 
  2516. * @since 2.1.0 
  2517. * 
  2518. * @param string $url Activity delete URL. 
  2519. */ 
  2520. return apply_filters( 'bp_get_activity_delete_url', $url ); 
  2521.  
  2522. /** 
  2523. * Output the activity latest update link. 
  2524. * 
  2525. * @since 1.2.0 
  2526. * 
  2527. * @see bp_get_activity_latest_update() for description of parameters. 
  2528. * 
  2529. * @param int $user_id See {@link bp_get_activity_latest_update()} for description. 
  2530. */ 
  2531. function bp_activity_latest_update( $user_id = 0 ) { 
  2532. echo bp_get_activity_latest_update( $user_id ); 
  2533.  
  2534. /** 
  2535. * Return the activity latest update link. 
  2536. * 
  2537. * @since 1.2.0 
  2538. * 
  2539. * 
  2540. * @param int $user_id If empty, will fall back on displayed user. 
  2541. * @return string|bool $latest_update The activity latest update link. 
  2542. * False on failure. 
  2543. */ 
  2544. function bp_get_activity_latest_update( $user_id = 0 ) { 
  2545.  
  2546. if ( empty( $user_id ) ) { 
  2547. $user_id = bp_displayed_user_id(); 
  2548.  
  2549. if ( bp_is_user_inactive( $user_id ) ) { 
  2550. return false; 
  2551.  
  2552. if ( !$update = bp_get_user_meta( $user_id, 'bp_latest_update', true ) ) { 
  2553. return false; 
  2554.  
  2555. /** 
  2556. * Filters the latest update excerpt. 
  2557. * 
  2558. * @since 1.2.10 
  2559. * @since 2.6.0 Added the `$user_id` parameter. 
  2560. * 
  2561. * @param string $value The excerpt for the latest update. 
  2562. * @param int $user_id ID of the queried user. 
  2563. */ 
  2564. $latest_update = apply_filters( 'bp_get_activity_latest_update_excerpt', trim( strip_tags( bp_create_excerpt( $update['content'], bp_activity_get_excerpt_length() ) ) ), $user_id ); 
  2565.  
  2566. $latest_update = sprintf( 
  2567. '%s <a href="%s">%s</a>',  
  2568. $latest_update,  
  2569. esc_url_raw( bp_activity_get_permalink( $update['id'] ) ),  
  2570. esc_attr__( 'View', 'buddypress' ) 
  2571. ); 
  2572.  
  2573. /** 
  2574. * Filters the latest update excerpt with view link appended to the end. 
  2575. * 
  2576. * @since 1.2.0 
  2577. * @since 2.6.0 Added the `$user_id` parameter. 
  2578. * 
  2579. * @param string $latest_update The latest update with "view" link appended to it. 
  2580. * @param int $user_id ID of the queried user. 
  2581. */ 
  2582. return apply_filters( 'bp_get_activity_latest_update', $latest_update, $user_id ); 
  2583.  
  2584. /** 
  2585. * Output the activity filter links. 
  2586. * 
  2587. * @since 1.1.0 
  2588. * 
  2589. * @see bp_get_activity_filter_links() for description of parameters. 
  2590. * 
  2591. * @param array|bool $args See {@link bp_get_activity_filter_links()} for description. 
  2592. */ 
  2593. function bp_activity_filter_links( $args = false ) { 
  2594. echo bp_get_activity_filter_links( $args ); 
  2595.  
  2596. /** 
  2597. * Return the activity filter links. 
  2598. * 
  2599. * @since 1.1.0 
  2600. * 
  2601. * 
  2602. * @param array|bool $args { 
  2603. * @type string $style The type of markup to use for the links. 
  2604. * 'list', 'paragraph', or 'span'. Default: 'list'. 
  2605. * } 
  2606. * @return string|bool $component_links The activity filter links. 
  2607. * False on failure. 
  2608. */ 
  2609. function bp_get_activity_filter_links( $args = false ) { 
  2610.  
  2611. $r = wp_parse_args( $args, array( 
  2612. 'style' => 'list' 
  2613. ) ); 
  2614.  
  2615. // Define local variable. 
  2616. $component_links = array(); 
  2617.  
  2618. // Fetch the names of components that have activity recorded in the DB. 
  2619. $components = BP_Activity_Activity::get_recorded_components(); 
  2620.  
  2621. if ( empty( $components ) ) { 
  2622. return false; 
  2623.  
  2624. foreach ( (array) $components as $component ) { 
  2625.  
  2626. // Skip the activity comment filter. 
  2627. if ( 'activity' == $component ) { 
  2628. continue; 
  2629.  
  2630. if ( isset( $_GET['afilter'] ) && $component == $_GET['afilter'] ) { 
  2631. $selected = ' class="selected"'; 
  2632. } else { 
  2633. $selected = ''; 
  2634.  
  2635. $component = esc_attr( $component ); 
  2636.  
  2637. switch ( $r['style'] ) { 
  2638. case 'list': 
  2639. $tag = 'li'; 
  2640. $before = '<li id="afilter-' . $component . '"' . $selected . '>'; 
  2641. $after = '</li>'; 
  2642. break; 
  2643. case 'paragraph': 
  2644. $tag = 'p'; 
  2645. $before = '<p id="afilter-' . $component . '"' . $selected . '>'; 
  2646. $after = '</p>'; 
  2647. break; 
  2648. case 'span': 
  2649. $tag = 'span'; 
  2650. $before = '<span id="afilter-' . $component . '"' . $selected . '>'; 
  2651. $after = '</span>'; 
  2652. break; 
  2653.  
  2654. $link = add_query_arg( 'afilter', $component ); 
  2655. $link = remove_query_arg( 'acpage' , $link ); 
  2656.  
  2657. /** 
  2658. * Filters the activity filter link URL for the current activity component. 
  2659. * 
  2660. * @since 1.1.0 
  2661. * 
  2662. * @param string $link The URL for the current component. 
  2663. * @param string $component The current component getting links constructed for. 
  2664. */ 
  2665. $link = apply_filters( 'bp_get_activity_filter_link_href', $link, $component ); 
  2666.  
  2667. $component_links[] = $before . '<a href="' . esc_url( $link ) . '">' . ucwords( $component ) . '</a>' . $after; 
  2668.  
  2669. $link = remove_query_arg( 'afilter' , $link ); 
  2670.  
  2671. if ( isset( $_GET['afilter'] ) ) { 
  2672. $component_links[] = '<' . $tag . ' id="afilter-clear"><a href="' . esc_url( $link ) . '">' . __( 'Clear Filter', 'buddypress' ) . '</a></' . $tag . '>'; 
  2673.  
  2674. /** 
  2675. * Filters all of the constructed filter links. 
  2676. * 
  2677. * @since 1.1.0 
  2678. * @since 2.6.0 Added the `$r` parameter. 
  2679. * 
  2680. * @param string $value All of the links to be displayed to the user. 
  2681. * @param array $r Array of parsed arguments. 
  2682. */ 
  2683. return apply_filters( 'bp_get_activity_filter_links', implode( "\n", $component_links ), $r ); 
  2684.  
  2685. /** 
  2686. * Determine if a comment can be made on an activity item. 
  2687. * 
  2688. * @since 1.2.0 
  2689. * 
  2690. * @global object $activities_template {@link BP_Activity_Template} 
  2691. * 
  2692. * @return bool $can_comment True if item can receive comments. 
  2693. */ 
  2694. function bp_activity_can_comment() { 
  2695. global $activities_template; 
  2696. $bp = buddypress(); 
  2697.  
  2698. // Determine ability to comment based on activity type name. 
  2699. $activity_type = bp_get_activity_type(); 
  2700.  
  2701. // Get the 'comment-reply' support for the current activity type. 
  2702. $can_comment = bp_activity_type_supports( $activity_type, 'comment-reply' ); 
  2703.  
  2704. // Neutralize activity_comment. 
  2705. if ( 'activity_comment' === $activity_type ) { 
  2706. $can_comment = false; 
  2707.  
  2708. /** 
  2709. * Filters whether a comment can be made on an activity item. 
  2710. * 
  2711. * @since 1.5.0 
  2712. * @since 2.5.0 Use $activity_type instead of $activity_name for the second parameter. 
  2713. * 
  2714. * @param bool $can_comment Status on if activity can be commented on. 
  2715. * @param string $activity_type Current activity type being checked on. 
  2716. */ 
  2717. return apply_filters( 'bp_activity_can_comment', $can_comment, $activity_type ); 
  2718.  
  2719. /** 
  2720. * Determine whether a comment can be made on an activity reply item. 
  2721. * 
  2722. * @since 1.5.0 
  2723. * 
  2724. * @param bool|object $comment Activity comment. 
  2725. * @return bool $can_comment True if comment can receive comments,  
  2726. * otherwise false. 
  2727. */ 
  2728. function bp_activity_can_comment_reply( $comment = false ) { 
  2729.  
  2730. // Assume activity can be commented on. 
  2731. $can_comment = true; 
  2732.  
  2733. // Check that comment exists. 
  2734. if ( empty( $comment ) ) { 
  2735. $comment = bp_activity_current_comment(); 
  2736.  
  2737. if ( ! empty( $comment ) ) { 
  2738.  
  2739. // Fall back on current comment in activity loop. 
  2740. $comment_depth = isset( $comment->depth ) 
  2741. ? intval( $comment->depth ) 
  2742. : bp_activity_get_comment_depth( $comment ); 
  2743.  
  2744. // Threading is turned on, so check the depth. 
  2745. if ( get_option( 'thread_comments' ) ) { 
  2746. $can_comment = (bool) ( $comment_depth < get_option( 'thread_comments_depth' ) ); 
  2747.  
  2748. // No threading for comment replies if no threading for comments. 
  2749. } else { 
  2750. $can_comment = false; 
  2751.  
  2752. /** 
  2753. * Filters whether a comment can be made on an activity reply item. 
  2754. * 
  2755. * @since 1.5.0 
  2756. * 
  2757. * @param bool $can_comment Status on if activity reply can be commented on. 
  2758. * @param string $comment Current comment being checked on. 
  2759. */ 
  2760. return (bool) apply_filters( 'bp_activity_can_comment_reply', $can_comment, $comment ); 
  2761.  
  2762. /** 
  2763. * Determine whether favorites are allowed. 
  2764. * 
  2765. * Defaults to true, but can be modified by plugins. 
  2766. * 
  2767. * @since 1.5.0 
  2768. * 
  2769. * @return bool True if comment can receive comments. 
  2770. */ 
  2771. function bp_activity_can_favorite() { 
  2772.  
  2773. /** 
  2774. * Filters whether or not users can favorite activity items. 
  2775. * 
  2776. * @since 1.5.0 
  2777. * 
  2778. * @param bool $value Whether or not favoriting is enabled. 
  2779. */ 
  2780. return apply_filters( 'bp_activity_can_favorite', true ); 
  2781.  
  2782. /** 
  2783. * Output the total favorite count for a specified user. 
  2784. * 
  2785. * @since 1.2.0 
  2786. * 
  2787. * @see bp_get_total_favorite_count_for_user() for description of parameters. 
  2788. * 
  2789. * @param int $user_id See {@link bp_get_total_favorite_count_for_user()}. 
  2790. */ 
  2791. function bp_total_favorite_count_for_user( $user_id = 0 ) { 
  2792. echo bp_get_total_favorite_count_for_user( $user_id ); 
  2793.  
  2794. /** 
  2795. * Return the total favorite count for a specified user. 
  2796. * 
  2797. * @since 1.2.0 
  2798. * 
  2799. * 
  2800. * @param int $user_id ID of user being queried. Default: displayed user ID. 
  2801. * @return int The total favorite count for the specified user. 
  2802. */ 
  2803. function bp_get_total_favorite_count_for_user( $user_id = 0 ) { 
  2804. $retval = false; 
  2805.  
  2806. if ( bp_activity_can_favorite() ) { 
  2807. // Default to displayed user if none is passed. 
  2808. $user_id = empty( $user_id ) 
  2809. ? bp_displayed_user_id() 
  2810. : $user_id; 
  2811.  
  2812. // Get user meta if user ID exists. 
  2813. if ( ! empty( $user_id ) ) { 
  2814. $retval = bp_activity_total_favorites_for_user( $user_id ); 
  2815.  
  2816. /** 
  2817. * Filters the total favorite count for a user. 
  2818. * 
  2819. * @since 1.2.0 
  2820. * @since 2.6.0 Added the `$user_id` parameter. 
  2821. * 
  2822. * @param int|bool $retval Total favorite count for a user. False on no favorites. 
  2823. * @param int $user_id ID of the queried user. 
  2824. */ 
  2825. return apply_filters( 'bp_get_total_favorite_count_for_user', $retval, $user_id ); 
  2826.  
  2827.  
  2828. /** 
  2829. * Output the total mention count for a specified user. 
  2830. * 
  2831. * @since 1.2.0 
  2832. * 
  2833. * @see bp_get_total_mention_count_for_user() for description of parameters. 
  2834. * 
  2835. * @param int $user_id See {@link bp_get_total_mention_count_for_user()}. 
  2836. */ 
  2837. function bp_total_mention_count_for_user( $user_id = 0 ) { 
  2838. echo bp_get_total_mention_count_for_user( $user_id ); 
  2839.  
  2840. /** 
  2841. * Return the total mention count for a specified user. 
  2842. * 
  2843. * @since 1.2.0 
  2844. * 
  2845. * 
  2846. * @param int $user_id ID of user being queried. Default: displayed user ID. 
  2847. * @return int The total mention count for the specified user. 
  2848. */ 
  2849. function bp_get_total_mention_count_for_user( $user_id = 0 ) { 
  2850.  
  2851. // Default to displayed user if none is passed. 
  2852. $user_id = empty( $user_id ) 
  2853. ? bp_displayed_user_id() 
  2854. : $user_id; 
  2855.  
  2856. // Get user meta if user ID exists. 
  2857. $retval = ! empty( $user_id ) 
  2858. ? bp_get_user_meta( $user_id, 'bp_new_mention_count', true ) 
  2859. : false; 
  2860.  
  2861. /** 
  2862. * Filters the total mention count for a user. 
  2863. * 
  2864. * @since 1.2.0 
  2865. * @since 2.6.0 Added the `$user_id` parameter. 
  2866. * 
  2867. * @param int|bool $retval Total mention count for a user. False on no mentions. 
  2868. * @param int $user_id ID of the queried user. 
  2869. */ 
  2870. return apply_filters( 'bp_get_total_mention_count_for_user', $retval, $user_id ); 
  2871.  
  2872. /** 
  2873. * Output the public message link for displayed user. 
  2874. * 
  2875. * @since 1.2.0 
  2876. * 
  2877. */ 
  2878. function bp_send_public_message_link() { 
  2879. echo esc_url( bp_get_send_public_message_link() ); 
  2880.  
  2881. /** 
  2882. * Return the public message link for the displayed user. 
  2883. * 
  2884. * @since 1.2.0 
  2885. * 
  2886. * 
  2887. * @return string The public message link for the displayed user. 
  2888. */ 
  2889. function bp_get_send_public_message_link() { 
  2890.  
  2891. // No link if not logged in, not looking at someone else's profile. 
  2892. if ( ! is_user_logged_in() || ! bp_is_user() || bp_is_my_profile() ) { 
  2893. $retval = ''; 
  2894. } else { 
  2895. $args = array( 'r' => bp_get_displayed_user_mentionname() ); 
  2896. $url = add_query_arg( $args, bp_get_activity_directory_permalink() ); 
  2897. $retval = wp_nonce_url( $url ); 
  2898.  
  2899. /** 
  2900. * Filters the public message link for the displayed user. 
  2901. * 
  2902. * @since 1.2.0 
  2903. * 
  2904. * @param string $retval The URL for the public message link. 
  2905. */ 
  2906. return apply_filters( 'bp_get_send_public_message_link', $retval ); 
  2907.  
  2908. /** 
  2909. * Recurse through all activity comments and return the activity comment IDs. 
  2910. * 
  2911. * @since 2.0.0 
  2912. * 
  2913. * @param array $activity Array of activities generated from {@link bp_activity_get()}. 
  2914. * @param array $activity_ids Used for recursion purposes in this function. 
  2915. * @return array 
  2916. */ 
  2917. function bp_activity_recurse_comments_activity_ids( $activity = array(), $activity_ids = array() ) { 
  2918. if ( is_array( $activity ) && ! empty( $activity['activities'] ) ) { 
  2919. $activity = $activity['activities'][0]; 
  2920.  
  2921. if ( ! empty( $activity->children ) ) { 
  2922. foreach ($activity->children as $child ) { 
  2923. $activity_ids[] = $child->id; 
  2924.  
  2925. if( ! empty( $child->children ) ) { 
  2926. $activity_ids = bp_activity_recurse_comments_activity_ids( $child, $activity_ids ); 
  2927.  
  2928. return $activity_ids; 
  2929.  
  2930. /** 
  2931. * Output the mentioned user display name. 
  2932. * 
  2933. * @since 1.2.0 
  2934. * 
  2935. * @see bp_get_mentioned_user_display_name() for description of parameters. 
  2936. * 
  2937. * @param int|string|bool $user_id_or_username See {@link bp_get_mentioned_user_display_name()}. 
  2938. */ 
  2939. function bp_mentioned_user_display_name( $user_id_or_username = false ) { 
  2940. echo bp_get_mentioned_user_display_name( $user_id_or_username ); 
  2941.  
  2942. /** 
  2943. * Returns the mentioned user display name. 
  2944. * 
  2945. * @since 1.2.0 
  2946. * 
  2947. * 
  2948. * @param int|string|bool $user_id_or_username User ID or username. 
  2949. * @return string The mentioned user's display name. 
  2950. */ 
  2951. function bp_get_mentioned_user_display_name( $user_id_or_username = false ) { 
  2952.  
  2953. // Get user display name. 
  2954. $name = bp_core_get_user_displayname( $user_id_or_username ); 
  2955.  
  2956. // If user somehow has no name, return this really lame string. 
  2957. if ( empty( $name ) ) { 
  2958. $name = __( 'a user', 'buddypress' ); 
  2959.  
  2960. /** 
  2961. * Filters the mentioned user display name. 
  2962. * 
  2963. * @since 1.2.0 
  2964. * 
  2965. * @param string $name Display name for the mentioned user. 
  2966. * @param int|string $user_id_or_username User ID or username use for query. 
  2967. */ 
  2968. return apply_filters( 'bp_get_mentioned_user_display_name', $name, $user_id_or_username ); 
  2969.  
  2970. /** 
  2971. * Output button for sending a public message (an @-mention). 
  2972. * 
  2973. * @since 1.2.0 
  2974. * 
  2975. * @see bp_get_send_public_message_button() for description of parameters. 
  2976. * 
  2977. * @param array|string $args See {@link bp_get_send_public_message_button()}. 
  2978. */ 
  2979. function bp_send_public_message_button( $args = '' ) { 
  2980. echo bp_get_send_public_message_button( $args ); 
  2981.  
  2982. /** 
  2983. * Return button for sending a public message (an @-mention). 
  2984. * 
  2985. * @since 1.2.0 
  2986. * 
  2987. * 
  2988. * @param array|string $args { 
  2989. * All arguments are optional. See {@link BP_Button} for complete 
  2990. * descriptions. 
  2991. * @type string $id Default: 'public_message'. 
  2992. * @type string $component Default: 'activity'. 
  2993. * @type bool $must_be_logged_in Default: true. 
  2994. * @type bool $block_self Default: true. 
  2995. * @type string $wrapper_id Default: 'post-mention'. 
  2996. * @type string $link_href Default: the public message link for 
  2997. * the current member in the loop. 
  2998. * @type string $link_text Default: 'Public Message'. 
  2999. * @type string $link_class Default: 'activity-button mention'. 
  3000. * } 
  3001. * @return string The button for sending a public message. 
  3002. */ 
  3003. function bp_get_send_public_message_button( $args = '' ) { 
  3004.  
  3005. $r = bp_parse_args( $args, array( 
  3006. 'id' => 'public_message',  
  3007. 'component' => 'activity',  
  3008. 'must_be_logged_in' => true,  
  3009. 'block_self' => true,  
  3010. 'wrapper_id' => 'post-mention',  
  3011. 'link_href' => bp_get_send_public_message_link(),  
  3012. 'link_text' => __( 'Public Message', 'buddypress' ),  
  3013. 'link_class' => 'activity-button mention' 
  3014. ) ); 
  3015.  
  3016. /** 
  3017. * Filters the public message button HTML. 
  3018. * 
  3019. * @since 1.2.10 
  3020. * 
  3021. * @param array $r Array of arguments for the public message button HTML. 
  3022. */ 
  3023. return bp_get_button( apply_filters( 'bp_get_send_public_message_button', $r ) ); 
  3024.  
  3025. /** 
  3026. * Output the activity post form action. 
  3027. * 
  3028. * @since 1.2.0 
  3029. * 
  3030. */ 
  3031. function bp_activity_post_form_action() { 
  3032. echo bp_get_activity_post_form_action(); 
  3033.  
  3034. /** 
  3035. * Return the activity post form action. 
  3036. * 
  3037. * @since 1.2.0 
  3038. * 
  3039. * 
  3040. * @return string The activity post form action. 
  3041. */ 
  3042. function bp_get_activity_post_form_action() { 
  3043.  
  3044. /** 
  3045. * Filters the action url used for the activity post form. 
  3046. * 
  3047. * @since 1.2.0 
  3048. * 
  3049. * @param string $value URL to be used for the activity post form. 
  3050. */ 
  3051. return apply_filters( 'bp_get_activity_post_form_action', home_url( bp_get_activity_root_slug() . '/post/' ) ); 
  3052.  
  3053. /** 
  3054. * Echo a list of linked avatars of users who have commented on the current activity item. 
  3055. * 
  3056. * Use this function to easily output activity comment authors' avatars. 
  3057. * 
  3058. * Avatars are wrapped in <li> elements, but you've got to provide your own 
  3059. * <ul> or <ol> wrapper markup. 
  3060. * 
  3061. * @since 1.7.0 
  3062. * 
  3063. * @see bp_core_fetch_avatar() for a description of arguments. 
  3064. * 
  3065. * @param array $args See {@link bp_core_fetch_avatar()}. 
  3066. */ 
  3067. function bp_activity_comments_user_avatars( $args = array() ) { 
  3068.  
  3069. $r = bp_parse_args( $args, array( 
  3070. 'height' => false,  
  3071. 'html' => true,  
  3072. 'type' => 'thumb',  
  3073. 'width' => false,  
  3074. ) ); 
  3075.  
  3076. // Get the user IDs of everyone who has left a comment to the current activity item. 
  3077. $user_ids = bp_activity_get_comments_user_ids(); 
  3078. $output = array(); 
  3079. $retval = ''; 
  3080.  
  3081. if ( ! empty( $user_ids ) ) { 
  3082. foreach ( (array) $user_ids as $user_id ) { 
  3083.  
  3084. // Skip an empty user ID. 
  3085. if ( empty( $user_id ) ) { 
  3086. continue; 
  3087.  
  3088. // Get profile link for this user. 
  3089. $profile_link = bp_core_get_user_domain( $user_id ); 
  3090.  
  3091. // Get avatar for this user. 
  3092. $image_html = bp_core_fetch_avatar( array( 
  3093. 'item_id' => $user_id,  
  3094. 'height' => $r['height'],  
  3095. 'html' => $r['html'],  
  3096. 'type' => $r['type'],  
  3097. 'width' => $r['width'] 
  3098. ) ); 
  3099.  
  3100. // If user has link & avatar, add them to the output array. 
  3101. if ( ! empty( $profile_link ) && ! empty( $image_html ) ) { 
  3102. $output[] = sprintf( '<a href="%1$s">%2$s</a>', esc_url( $profile_link ), $image_html ); 
  3103.  
  3104. // If output array is not empty, wrap everything in some list items. 
  3105. if ( ! empty( $output ) ) { 
  3106. $retval = '<li>' . implode( '</li><li>', $output ) . '</li>'; 
  3107.  
  3108. /** 
  3109. * Filters the list of linked avatars for users who have commented on the current activity item. 
  3110. * 
  3111. * @since 1.7.0 
  3112. * 
  3113. * @param string $retval HTML markup for the list of avatars. 
  3114. * @param array $r Array of arguments used for each avatar. 
  3115. * @param array $output Array of each avatar found, before imploded into single string. 
  3116. */ 
  3117. echo apply_filters( 'bp_activity_comments_user_avatars', $retval, $r, $output ); 
  3118.  
  3119. /** 
  3120. * Return the IDs of every user who's left a comment on the current activity item. 
  3121. * 
  3122. * @since 1.7.0 
  3123. * 
  3124. * @return bool|array An array of IDs, or false if none are found. 
  3125. */ 
  3126. function bp_activity_get_comments_user_ids() { 
  3127. global $activities_template; 
  3128.  
  3129. $user_ids = ! empty( $activities_template->activity->children ) 
  3130. ? (array) bp_activity_recurse_comments_user_ids( $activities_template->activity->children ) 
  3131. : array(); 
  3132.  
  3133. /** 
  3134. * Filters the list of user IDs for the current activity item. 
  3135. * 
  3136. * @since 1.7.0 
  3137. * 
  3138. * @param array $value Array of unique user IDs for the current activity item. 
  3139. */ 
  3140. return apply_filters( 'bp_activity_get_comments_user_ids', array_unique( $user_ids ) ); 
  3141.  
  3142. /** 
  3143. * Recurse through all activity comments and collect the IDs of the users who wrote them. 
  3144. * 
  3145. * @since 1.7.0 
  3146. * 
  3147. * @param array $comments Array of {@link BP_Activity_Activity} items. 
  3148. * @return array Array of user IDs. 
  3149. */ 
  3150. function bp_activity_recurse_comments_user_ids( array $comments = array() ) { 
  3151.  
  3152. // Default user ID's array. 
  3153. $user_ids = array(); 
  3154.  
  3155. // Loop through comments and try to get user ID's. 
  3156. if ( ! empty( $comments ) ) { 
  3157. foreach ( $comments as $comment ) { 
  3158.  
  3159. // If a user is a spammer, their activity items will have been 
  3160. // automatically marked as spam. Skip these. 
  3161. if ( ! empty( $comment->is_spam ) ) { 
  3162. continue; 
  3163.  
  3164. // Add user ID to array. 
  3165. $user_ids[] = $comment->user_id; 
  3166.  
  3167. // Check for commentception. 
  3168. if ( ! empty( $comment->children ) ) { 
  3169. $user_ids = array_merge( $user_ids, bp_activity_recurse_comments_user_ids( $comment->children ) ); 
  3170.  
  3171. /** 
  3172. * Filters the list of user IDs for the current activity comment item. 
  3173. * 
  3174. * @since 2.1.0 
  3175. * 
  3176. * @param array $user_ids Array of user IDs for the current activity comment item. 
  3177. * @param array $comments Array of comments being checked for user IDs. 
  3178. */ 
  3179. return apply_filters( 'bp_activity_recurse_comments_user_ids', $user_ids, $comments ); 
  3180.  
  3181. /** 
  3182. * Output the mentionname for the displayed user. 
  3183. * 
  3184. * @since 1.9.0 
  3185. */ 
  3186. function bp_displayed_user_mentionname() { 
  3187. echo bp_get_displayed_user_mentionname(); 
  3188. /** 
  3189. * Get the mentionname for the displayed user. 
  3190. * 
  3191. * @since 1.9.0 
  3192. * 
  3193. * @return string Mentionname for the displayed user, if available. 
  3194. */ 
  3195. function bp_get_displayed_user_mentionname() { 
  3196.  
  3197. /** 
  3198. * Filters the mentionname for the displayed user. 
  3199. * 
  3200. * @since 1.9.0 
  3201. * 
  3202. * @param string $value The mentionanme for the displayed user. 
  3203. */ 
  3204. return apply_filters( 'bp_get_displayed_user_mentionname', bp_activity_get_user_mentionname( bp_displayed_user_id() ) ); 
  3205.  
  3206. /** 
  3207. * Echo a list of all registered activity types for use in dropdowns or checkbox lists. 
  3208. * 
  3209. * @since 1.7.0 
  3210. * 
  3211. * @param string $output Optional. Either 'select' or 'checkbox'. Default: 'select'. 
  3212. * @param array|string $args { 
  3213. * Optional extra arguments. 
  3214. * @type string $checkbox_name When returning checkboxes, sets the 'name' 
  3215. * attribute. 
  3216. * @type array|string $selected A list of types that should be checked/ 
  3217. * selected. 
  3218. * } 
  3219. */ 
  3220. function bp_activity_types_list( $output = 'select', $args = '' ) { 
  3221.  
  3222. $args = bp_parse_args( $args, array( 
  3223. 'checkbox_name' => 'bp_activity_types',  
  3224. 'selected' => array(),  
  3225. ) ); 
  3226.  
  3227. $activities = bp_activity_get_types(); 
  3228. natsort( $activities ); 
  3229.  
  3230. // Loop through the activity types and output markup. 
  3231. foreach ( $activities as $type => $description ) { 
  3232.  
  3233. // See if we need to preselect the current type. 
  3234. $checked = checked( true, in_array( $type, (array) $args['selected'] ), false ); 
  3235. $selected = selected( true, in_array( $type, (array) $args['selected'] ), false ); 
  3236.  
  3237. // Switch output based on the element. 
  3238. switch ( $output ) { 
  3239. case 'select' : 
  3240. printf( '<option value="%1$s" %2$s>%3$s</option>', esc_attr( $type ), $selected, esc_html( $description ) ); 
  3241. break; 
  3242. case 'checkbox' : 
  3243. printf( '<label style="" for="%1$s[]">%2$s<input type="checkbox" id="%1$s[]" name="%1$s[]" value="%3$s" %4$s/></label>', esc_attr( $args['checkbox_name'] ), esc_html( $description ), esc_attr( $args['checkbox_name'] ), esc_attr( $args['checkbox_name'] ), esc_attr( $type ), $checked ); 
  3244. break; 
  3245.  
  3246. /** 
  3247. * Fires at the end of the listing of activity types. 
  3248. * 
  3249. * This is a variable action hook. The actual hook to use will depend on the output type specified. 
  3250. * Two default hooks are bp_activity_types_list_select and bp_activity_types_list_checkbox. 
  3251. * 
  3252. * @since 1.7.0 
  3253. * 
  3254. * @param array $args Array of arguments passed into function. 
  3255. * @param string $type Activity type being rendered in the output. 
  3256. * @param string $description Description of the activity type being rendered. 
  3257. */ 
  3258. do_action( 'bp_activity_types_list_' . $output, $args, $type, $description ); 
  3259.  
  3260. // Backpat with BP-Default for dropdown boxes only. 
  3261. if ( 'select' === $output ) { 
  3262. do_action( 'bp_activity_filter_options' ); 
  3263.  
  3264.  
  3265. /** RSS Feed Template Tags ****************************************************/ 
  3266.  
  3267. /** 
  3268. * Output the sitewide activity feed link. 
  3269. * 
  3270. * @since 1.0.0 
  3271. * 
  3272. */ 
  3273. function bp_sitewide_activity_feed_link() { 
  3274. echo bp_get_sitewide_activity_feed_link(); 
  3275.  
  3276. /** 
  3277. * Returns the sitewide activity feed link. 
  3278. * 
  3279. * @since 1.0.0 
  3280. * 
  3281. * 
  3282. * @return string The sitewide activity feed link. 
  3283. */ 
  3284. function bp_get_sitewide_activity_feed_link() { 
  3285.  
  3286. /** 
  3287. * Filters the sidewide activity feed link. 
  3288. * 
  3289. * @since 1.0.0 
  3290. * 
  3291. * @param string $value The feed link for sitewide activity. 
  3292. */ 
  3293. return apply_filters( 'bp_get_sitewide_activity_feed_link', bp_get_root_domain() . '/' . bp_get_activity_root_slug() . '/feed/' ); 
  3294.  
  3295. /** 
  3296. * Output the member activity feed link. 
  3297. * 
  3298. * @since 1.2.0 
  3299. * 
  3300. */ 
  3301. function bp_member_activity_feed_link() { 
  3302. echo bp_get_member_activity_feed_link(); 
  3303.  
  3304. /** 
  3305. * Output the member activity feed link. 
  3306. * 
  3307. * @since 1.0.0 
  3308. * @deprecated 1.2.0 
  3309. * 
  3310. * @todo properly deprecate in favor of bp_member_activity_feed_link(). 
  3311. * 
  3312. */ 
  3313. function bp_activities_member_rss_link() { echo bp_get_member_activity_feed_link(); } 
  3314.  
  3315. /** 
  3316. * Return the member activity feed link. 
  3317. * 
  3318. * @since 1.2.0 
  3319. * 
  3320. * 
  3321. * @return string $link The member activity feed link. 
  3322. */ 
  3323. function bp_get_member_activity_feed_link() { 
  3324.  
  3325. // Single member activity feed link. 
  3326. if ( bp_is_profile_component() || bp_is_current_action( 'just-me' ) ) { 
  3327. $link = bp_displayed_user_domain() . bp_get_activity_slug() . '/feed/'; 
  3328.  
  3329. // Friend feed link. 
  3330. } elseif ( bp_is_active( 'friends' ) && bp_is_current_action( bp_get_friends_slug() ) ) { 
  3331. $link = bp_displayed_user_domain() . bp_get_activity_slug() . '/' . bp_get_friends_slug() . '/feed/'; 
  3332.  
  3333. // Group feed link. 
  3334. } elseif ( bp_is_active( 'groups' ) && bp_is_current_action( bp_get_groups_slug() ) ) { 
  3335. $link = bp_displayed_user_domain() . bp_get_activity_slug() . '/' . bp_get_groups_slug() . '/feed/'; 
  3336.  
  3337. // Favorites activity feed link. 
  3338. } elseif ( 'favorites' === bp_current_action() ) { 
  3339. $link = bp_displayed_user_domain() . bp_get_activity_slug() . '/favorites/feed/'; 
  3340.  
  3341. // Mentions activity feed link. 
  3342. } elseif ( ( 'mentions' === bp_current_action() ) && bp_activity_do_mentions() ) { 
  3343. $link = bp_displayed_user_domain() . bp_get_activity_slug() . '/mentions/feed/'; 
  3344.  
  3345. // No feed link. 
  3346. } else { 
  3347. $link = ''; 
  3348.  
  3349. /** 
  3350. * Filters the member activity feed link. 
  3351. * 
  3352. * @since 1.0.0 
  3353. * 
  3354. * @param string $link URL for the member activity feed. 
  3355. */ 
  3356. return apply_filters( 'bp_get_activities_member_rss_link', $link ); 
  3357.  
  3358. /** 
  3359. * Return the member activity feed link. 
  3360. * 
  3361. * @since 1.0.0 
  3362. * @deprecated 1.2.0 
  3363. * 
  3364. * @todo properly deprecate in favor of bp_get_member_activity_feed_link(). 
  3365. * 
  3366. * 
  3367. * @return string The member activity feed link. 
  3368. */ 
  3369. function bp_get_activities_member_rss_link() { return bp_get_member_activity_feed_link(); } 
  3370.  
  3371.  
  3372. /** Template tags for RSS feed output ****************************************/ 
  3373.  
  3374. /** 
  3375. * Outputs the activity feed item guid. 
  3376. * 
  3377. * @since 1.0.0 
  3378. * 
  3379. */ 
  3380. function bp_activity_feed_item_guid() { 
  3381. echo bp_get_activity_feed_item_guid(); 
  3382.  
  3383. /** 
  3384. * Returns the activity feed item guid. 
  3385. * 
  3386. * @since 1.2.0 
  3387. * 
  3388. * @global object $activities_template {@link BP_Activity_Template} 
  3389. * 
  3390. * @return string The activity feed item guid. 
  3391. */ 
  3392. function bp_get_activity_feed_item_guid() { 
  3393. global $activities_template; 
  3394.  
  3395. /** 
  3396. * Filters the activity feed item guid. 
  3397. * 
  3398. * @since 1.1.3 
  3399. * 
  3400. * @param string $value Calculated md5 value for the activity feed item. 
  3401. */ 
  3402. return apply_filters( 'bp_get_activity_feed_item_guid', md5( $activities_template->activity->date_recorded . '-' . $activities_template->activity->content ) ); 
  3403.  
  3404. /** 
  3405. * Output the activity feed item title. 
  3406. * 
  3407. * @since 1.0.0 
  3408. * 
  3409. */ 
  3410. function bp_activity_feed_item_title() { 
  3411. echo bp_get_activity_feed_item_title(); 
  3412.  
  3413. /** 
  3414. * Return the activity feed item title. 
  3415. * 
  3416. * @since 1.0.0 
  3417. * 
  3418. * @global object $activities_template {@link BP_Activity_Template} 
  3419. * 
  3420. * @return string $title The activity feed item title. 
  3421. */ 
  3422. function bp_get_activity_feed_item_title() { 
  3423. global $activities_template; 
  3424.  
  3425. if ( !empty( $activities_template->activity->action ) ) { 
  3426. $content = $activities_template->activity->action; 
  3427. } else { 
  3428. $content = $activities_template->activity->content; 
  3429.  
  3430. $content = explode( '<span', $content ); 
  3431. $title = strip_tags( ent2ncr( trim( convert_chars( $content[0] ) ) ) ); 
  3432.  
  3433. if ( ':' === substr( $title, -1 ) ) { 
  3434. $title = substr( $title, 0, -1 ); 
  3435.  
  3436. if ( 'activity_update' === $activities_template->activity->type ) { 
  3437. $title .= ': ' . strip_tags( ent2ncr( trim( convert_chars( bp_create_excerpt( $activities_template->activity->content, 70, array( 'ending' => " […]" ) ) ) ) ) ); 
  3438.  
  3439. /** 
  3440. * Filters the activity feed item title. 
  3441. * 
  3442. * @since 1.0.0 
  3443. * 
  3444. * @param string $title The title for the activity feed item. 
  3445. */ 
  3446. return apply_filters( 'bp_get_activity_feed_item_title', $title ); 
  3447.  
  3448. /** 
  3449. * Output the activity feed item link. 
  3450. * 
  3451. * @since 1.0.0 
  3452. * 
  3453. */ 
  3454. function bp_activity_feed_item_link() { 
  3455. echo bp_get_activity_feed_item_link(); 
  3456.  
  3457. /** 
  3458. * Return the activity feed item link. 
  3459. * 
  3460. * @since 1.0.0 
  3461. * 
  3462. * @global object $activities_template {@link BP_Activity_Template} 
  3463. * 
  3464. * @return string The activity feed item link. 
  3465. */ 
  3466. function bp_get_activity_feed_item_link() { 
  3467. global $activities_template; 
  3468.  
  3469. $retval = ! empty( $activities_template->activity->primary_link ) 
  3470. ? $activities_template->activity->primary_link 
  3471. : ''; 
  3472.  
  3473. /** 
  3474. * Filters the activity feed item link. 
  3475. * 
  3476. * @since 1.0.0 
  3477. * 
  3478. * @param string $retval The URL for the activity feed item. 
  3479. */ 
  3480. return apply_filters( 'bp_get_activity_feed_item_link', $retval ); 
  3481.  
  3482. /** 
  3483. * Output the activity feed item date. 
  3484. * 
  3485. * @since 1.0.0 
  3486. * 
  3487. */ 
  3488. function bp_activity_feed_item_date() { 
  3489. echo bp_get_activity_feed_item_date(); 
  3490.  
  3491. /** 
  3492. * Return the activity feed item date. 
  3493. * 
  3494. * @since 1.0.0 
  3495. * 
  3496. * @global object $activities_template {@link BP_Activity_Template} 
  3497. * 
  3498. * @return string The activity feed item date. 
  3499. */ 
  3500. function bp_get_activity_feed_item_date() { 
  3501. global $activities_template; 
  3502.  
  3503. $retval = ! empty( $activities_template->activity->date_recorded ) 
  3504. ? $activities_template->activity->date_recorded 
  3505. : ''; 
  3506.  
  3507. /** 
  3508. * Filters the activity feed item date. 
  3509. * 
  3510. * @since 1.0.0 
  3511. * 
  3512. * @param string $retval The date for the activity feed item. 
  3513. */ 
  3514. return apply_filters( 'bp_get_activity_feed_item_date', $retval ); 
  3515.  
  3516. /** 
  3517. * Output the activity feed item description. 
  3518. * 
  3519. * @since 1.0.0 
  3520. * 
  3521. */ 
  3522. function bp_activity_feed_item_description() { 
  3523. echo bp_get_activity_feed_item_description(); 
  3524.  
  3525. /** 
  3526. * Return the activity feed item description. 
  3527. * 
  3528. * @since 1.0.0 
  3529. * 
  3530. * @global object $activities_template {@link BP_Activity_Template} 
  3531. * 
  3532. * @return string The activity feed item description. 
  3533. */ 
  3534. function bp_get_activity_feed_item_description() { 
  3535. global $activities_template; 
  3536.  
  3537. // Get the content, if exists. 
  3538. $content = ! empty( $activities_template->activity->content ) 
  3539. ? $activities_template->activity->content 
  3540. : ''; 
  3541.  
  3542. // Perform a few string conversions on the content, if it's not empty. 
  3543. if ( ! empty( $content ) ) { 
  3544. $content = ent2ncr( convert_chars( str_replace( '%s', '', $content ) ) ); 
  3545.  
  3546. /** 
  3547. * Filters the activity feed item description. 
  3548. * 
  3549. * @since 1.0.0 
  3550. * 
  3551. * @param string $content The description for the activity feed item. 
  3552. */ 
  3553. return apply_filters( 'bp_get_activity_feed_item_description', $content ); 
  3554.  
  3555. /** 
  3556. * Template tag so we can hook activity feed to <head>. 
  3557. * 
  3558. * @since 1.5.0 
  3559. * 
  3560. */ 
  3561. function bp_activity_sitewide_feed() { 
  3562. ?> 
  3563.  
  3564. <link rel="alternate" type="application/rss+xml" title="<?php bloginfo( 'name' ) ?> | <?php _e( 'Site Wide Activity RSS Feed', 'buddypress' ) ?>" href="<?php bp_sitewide_activity_feed_link() ?>" /> 
  3565.  
  3566. <?php 
  3567. add_action( 'bp_head', 'bp_activity_sitewide_feed' ); 
  3568.  
  3569. /** 
  3570. * Display available filters depending on the scope. 
  3571. * 
  3572. * @since 2.1.0 
  3573. * 
  3574. * @param string $context The current context. 'activity', 'member',  
  3575. * 'member_groups', 'group'. 
  3576. */ 
  3577. function bp_activity_show_filters( $context = '' ) { 
  3578. echo bp_get_activity_show_filters( $context ); 
  3579. /** 
  3580. * Get available filters depending on the scope. 
  3581. * 
  3582. * @since 2.1.0 
  3583. * 
  3584. * @param string $context The current context. 'activity', 'member',  
  3585. * 'member_groups', 'group'. 
  3586. * 
  3587. * @return string HTML for <option> values. 
  3588. */ 
  3589. function bp_get_activity_show_filters( $context = '' ) { 
  3590. $filters = array(); 
  3591. $actions = bp_activity_get_actions_for_context( $context ); 
  3592. foreach ( $actions as $action ) { 
  3593. // Friends activity collapses two filters into one. 
  3594. if ( in_array( $action['key'], array( 'friendship_accepted', 'friendship_created' ) ) ) { 
  3595. $action['key'] = 'friendship_accepted, friendship_created'; 
  3596.  
  3597. $filters[ $action['key'] ] = $action['label']; 
  3598.  
  3599. /** 
  3600. * Filters the options available in the activity filter dropdown. 
  3601. * 
  3602. * @since 2.2.0 
  3603. * 
  3604. * @param array $filters Array of filter options for the given context, in the following format: $option_value => $option_name. 
  3605. * @param string $context Context for the filter. 'activity', 'member', 'member_groups', 'group'. 
  3606. */ 
  3607. $filters = apply_filters( 'bp_get_activity_show_filters_options', $filters, $context ); 
  3608.  
  3609. // Build the options output. 
  3610. $output = ''; 
  3611.  
  3612. if ( ! empty( $filters ) ) { 
  3613. foreach ( $filters as $value => $filter ) { 
  3614. $output .= '<option value="' . esc_attr( $value ) . '">' . esc_html( $filter ) . '</option>' . "\n"; 
  3615.  
  3616. /** 
  3617. * Filters the HTML markup result for the activity filter dropdown. 
  3618. * 
  3619. * @since 2.1.0 
  3620. * 
  3621. * @param string $output HTML output for the activity filter dropdown. 
  3622. * @param array $filters Array of filter options for the given context, in the following format: $option_value => $option_name. 
  3623. * @param string $context Context for the filter. 'activity', 'member', 'member_groups', 'group'. 
  3624. */ 
  3625. return apply_filters( 'bp_get_activity_show_filters', $output, $filters, $context ); 
.