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