PageRenderTime 50ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-content/plugins/buddypress/bp-core/bp-core-templatetags.php

https://bitbucket.org/openfarmtech/weblog-content
PHP | 2082 lines | 1407 code | 479 blank | 196 comment | 412 complexity | 6702377945b91f9333f3701cb2340e69 MD5 | raw file
Possible License(s): GPL-2.0, AGPL-1.0, LGPL-2.0, LGPL-3.0, BSD-3-Clause, GPL-3.0, LGPL-2.1, AGPL-3.0, CC-BY-SA-3.0

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /***
  3. * Members template loop that will allow you to loop all members or friends of a member
  4. * if you pass a user_id.
  5. */
  6. class BP_Core_Members_Template {
  7. var $current_member = -1;
  8. var $member_count;
  9. var $members;
  10. var $member;
  11. var $in_the_loop;
  12. var $pag_page;
  13. var $pag_num;
  14. var $pag_links;
  15. var $total_member_count;
  16. function bp_core_members_template( $type, $page_number, $per_page, $max, $user_id, $search_terms, $include, $populate_extras ) {
  17. global $bp;
  18. $this->pag_page = isset( $_REQUEST['upage'] ) ? intval( $_REQUEST['upage'] ) : $page_number;
  19. $this->pag_num = isset( $_REQUEST['num'] ) ? intval( $_REQUEST['num'] ) : $per_page;
  20. $this->type = $type;
  21. if ( isset( $_REQUEST['letter'] ) && '' != $_REQUEST['letter'] ) {
  22. $this->members = BP_Core_User::get_users_by_letter( $_REQUEST['letter'], $this->pag_num, $this->pag_page, $populate_extras );
  23. } else {
  24. $this->members = bp_core_get_users( array( 'type' => $this->type, 'per_page' => $this->pag_num, 'page' => $this->pag_page, 'user_id' => $user_id, 'include' => $include, 'search_terms' => $search_terms, 'populate_extras' => $populate_extras ) );
  25. }
  26. if ( !$max || $max >= (int)$this->members['total'] )
  27. $this->total_member_count = (int)$this->members['total'];
  28. else
  29. $this->total_member_count = (int)$max;
  30. $this->members = $this->members['users'];
  31. if ( $max ) {
  32. if ( $max >= count($this->members) )
  33. $this->member_count = count($this->members);
  34. else
  35. $this->member_count = (int)$max;
  36. } else {
  37. $this->member_count = count($this->members);
  38. }
  39. if ( (int) $this->total_member_count && (int) $this->pag_num ) {
  40. $this->pag_links = paginate_links( array(
  41. 'base' => add_query_arg( 'upage', '%#%' ),
  42. 'format' => '',
  43. 'total' => ceil( (int) $this->total_member_count / (int) $this->pag_num ),
  44. 'current' => (int) $this->pag_page,
  45. 'prev_text' => '&larr;',
  46. 'next_text' => '&rarr;',
  47. 'mid_size' => 1
  48. ));
  49. }
  50. }
  51. function has_members() {
  52. if ( $this->member_count )
  53. return true;
  54. return false;
  55. }
  56. function next_member() {
  57. $this->current_member++;
  58. $this->member = $this->members[$this->current_member];
  59. return $this->member;
  60. }
  61. function rewind_members() {
  62. $this->current_member = -1;
  63. if ( $this->member_count > 0 ) {
  64. $this->member = $this->members[0];
  65. }
  66. }
  67. function members() {
  68. if ( $this->current_member + 1 < $this->member_count ) {
  69. return true;
  70. } elseif ( $this->current_member + 1 == $this->member_count ) {
  71. do_action('loop_end');
  72. // Do some cleaning up after the loop
  73. $this->rewind_members();
  74. }
  75. $this->in_the_loop = false;
  76. return false;
  77. }
  78. function the_member() {
  79. global $member, $bp;
  80. $this->in_the_loop = true;
  81. $this->member = $this->next_member();
  82. if ( 0 == $this->current_member ) // loop has just started
  83. do_action('loop_start');
  84. }
  85. }
  86. function bp_rewind_members() {
  87. global $members_template;
  88. return $members_template->rewind_members();
  89. }
  90. function bp_has_members( $args = '' ) {
  91. global $bp, $members_template;
  92. /***
  93. * Set the defaults based on the current page. Any of these will be overridden
  94. * if arguments are directly passed into the loop. Custom plugins should always
  95. * pass their parameters directly to the loop.
  96. */
  97. $type = 'active';
  98. $user_id = false;
  99. $page = 1;
  100. $search_terms = false;
  101. // User filtering
  102. if ( !empty( $bp->displayed_user->id ) )
  103. $user_id = $bp->displayed_user->id;
  104. // Pass a filter if ?s= is set.
  105. if ( isset( $_REQUEST['s'] ) && !empty( $_REQUEST['s'] ) )
  106. $search_terms = $_REQUEST['s'];
  107. // type: active ( default ) | random | newest | popular | online | alphabetical
  108. $defaults = array(
  109. 'type' => $type,
  110. 'page' => $page,
  111. 'per_page' => 20,
  112. 'max' => false,
  113. 'include' => false, // Pass a user_id or comma separated list of user_ids to only show these users
  114. 'user_id' => $user_id, // Pass a user_id to only show friends of this user
  115. 'search_terms' => $search_terms, // Pass search_terms to filter users by their profile data
  116. 'populate_extras' => true // Fetch usermeta? Friend count, last active etc.
  117. );
  118. $r = wp_parse_args( $args, $defaults );
  119. extract( $r );
  120. if ( $max ) {
  121. if ( $per_page > $max )
  122. $per_page = $max;
  123. }
  124. // Make sure we return no members if we looking at friendship requests and there are none.
  125. if ( empty( $include ) && $bp->friends->slug == $bp->current_component && 'requests' == $bp->current_action )
  126. return false;
  127. $members_template = new BP_Core_Members_Template( $type, $page, $per_page, $max, $user_id, $search_terms, $include, (bool)$populate_extras );
  128. return apply_filters( 'bp_has_members', $members_template->has_members(), &$members_template );
  129. }
  130. function bp_the_member() {
  131. global $members_template;
  132. return $members_template->the_member();
  133. }
  134. function bp_members() {
  135. global $members_template;
  136. return $members_template->members();
  137. }
  138. function bp_members_pagination_count() {
  139. global $bp, $members_template;
  140. $start_num = intval( ( $members_template->pag_page - 1 ) * $members_template->pag_num ) + 1;
  141. $from_num = bp_core_number_format( $start_num );
  142. $to_num = bp_core_number_format( ( $start_num + ( $members_template->pag_num - 1 ) > $members_template->total_member_count ) ? $members_template->total_member_count : $start_num + ( $members_template->pag_num - 1 ) );
  143. $total = bp_core_number_format( $members_template->total_member_count );
  144. if ( 'active' == $members_template->type )
  145. echo sprintf( __( 'Viewing member %1$s to %2$s (of %3$s active members)', 'buddypress' ), $from_num, $to_num, $total );
  146. else if ( 'popular' == $members_template->type )
  147. echo sprintf( __( 'Viewing member %1$s to %2$s (of %3$s members with friends)', 'buddypress' ), $from_num, $to_num, $total );
  148. else if ( 'online' == $members_template->type )
  149. echo sprintf( __( 'Viewing member %1$s to %2$s (of %3$s members online)', 'buddypress' ), $from_num, $to_num, $total );
  150. else
  151. echo sprintf( __( 'Viewing member %1$s to %2$s (of %3$s members)', 'buddypress' ), $from_num, $to_num, $total );
  152. ?><span class="ajax-loader"></span><?php
  153. }
  154. function bp_members_pagination_links() {
  155. echo bp_get_members_pagination_links();
  156. }
  157. function bp_get_members_pagination_links() {
  158. global $members_template;
  159. return apply_filters( 'bp_get_members_pagination_links', $members_template->pag_links );
  160. }
  161. /**
  162. * bp_member_user_id()
  163. *
  164. * Echo id from bp_get_member_user_id()
  165. *
  166. * @uses bp_get_member_user_id()
  167. */
  168. function bp_member_user_id() {
  169. echo bp_get_member_user_id();
  170. }
  171. /**
  172. * bp_get_member_user_id()
  173. *
  174. * Get the id of the user in a members loop
  175. *
  176. * @global object $members_template
  177. * @return string Members id
  178. */
  179. function bp_get_member_user_id() {
  180. global $members_template;
  181. return apply_filters( 'bp_get_member_user_id', $members_template->member->id );
  182. }
  183. /**
  184. * bp_member_user_nicename()
  185. *
  186. * Echo nicename from bp_get_member_user_nicename()
  187. *
  188. * @uses bp_get_member_user_nicename()
  189. */
  190. function bp_member_user_nicename() {
  191. echo bp_get_member_user_nicename();
  192. }
  193. /**
  194. * bp_get_member_user_nicename()
  195. *
  196. * Get the nicename of the user in a members loop
  197. *
  198. * @global object $members_template
  199. * @return string Members nicename
  200. */
  201. function bp_get_member_user_nicename() {
  202. global $members_template;
  203. return apply_filters( 'bp_get_member_user_nicename', $members_template->member->user_nicename );
  204. }
  205. /**
  206. * bp_member_user_login()
  207. *
  208. * Echo login from bp_get_member_user_login()
  209. *
  210. * @uses bp_get_member_user_login()
  211. */
  212. function bp_member_user_login() {
  213. echo bp_get_member_user_login();
  214. }
  215. /**
  216. * bp_get_member_user_login()
  217. *
  218. * Get the login of the user in a members loop
  219. *
  220. * @global object $members_template
  221. * @return string Members login
  222. */
  223. function bp_get_member_user_login() {
  224. global $members_template;
  225. return apply_filters( 'bp_get_member_user_login', $members_template->member->user_login );
  226. }
  227. /**
  228. * bp_member_user_email()
  229. *
  230. * Echo email address from bp_get_member_user_email()
  231. *
  232. * @uses bp_get_member_user_email()
  233. */
  234. function bp_member_user_email() {
  235. echo bp_get_member_user_email();
  236. }
  237. /**
  238. * bp_get_member_user_email()
  239. *
  240. * Get the email address of the user in a members loop
  241. *
  242. * @global object $members_template
  243. * @return string Members email address
  244. */
  245. function bp_get_member_user_email() {
  246. global $members_template;
  247. return apply_filters( 'bp_get_member_user_email', $members_template->member->user_email );
  248. }
  249. function bp_member_is_loggedin_user() {
  250. global $bp, $members_template;
  251. return apply_filters( 'bp_member_is_loggedin_user', $bp->loggedin_user->id == $members_template->member->id ? true : false );
  252. }
  253. function bp_member_avatar( $args = '' ) {
  254. echo apply_filters( 'bp_member_avatar', bp_get_member_avatar( $args ) );
  255. }
  256. function bp_get_member_avatar( $args = '' ) {
  257. global $bp, $members_template;
  258. $defaults = array(
  259. 'type' => 'thumb',
  260. 'width' => false,
  261. 'height' => false,
  262. 'class' => 'avatar',
  263. 'id' => false,
  264. 'alt' => __( 'Member avatar', 'buddypress' )
  265. );
  266. $r = wp_parse_args( $args, $defaults );
  267. extract( $r, EXTR_SKIP );
  268. return apply_filters( 'bp_get_member_avatar', bp_core_fetch_avatar( array( 'item_id' => $members_template->member->id, 'type' => $type, 'alt' => $alt, 'css_id' => $id, 'class' => $class, 'width' => $width, 'height' => $height, 'email' => $members_template->member->user_email ) ) );
  269. }
  270. function bp_member_permalink() {
  271. echo bp_get_member_permalink();
  272. }
  273. function bp_get_member_permalink() {
  274. global $members_template;
  275. return apply_filters( 'bp_get_member_permalink', bp_core_get_user_domain( $members_template->member->id, $members_template->member->user_nicename, $members_template->member->user_login ) );
  276. }
  277. function bp_member_link() { echo bp_get_member_permalink(); }
  278. function bp_get_member_link() { return bp_get_member_permalink(); }
  279. function bp_member_name() {
  280. echo apply_filters( 'bp_member_name', bp_get_member_name() );
  281. }
  282. function bp_get_member_name() {
  283. global $members_template;
  284. if ( empty($members_template->member->fullname) )
  285. $members_template->member->fullname = $members_template->member->display_name;
  286. return apply_filters( 'bp_get_member_name', $members_template->member->fullname );
  287. }
  288. add_filter( 'bp_get_member_name', 'wp_filter_kses' );
  289. add_filter( 'bp_get_member_name', 'stripslashes' );
  290. add_filter( 'bp_get_member_name', 'strip_tags' );
  291. function bp_member_last_active() {
  292. echo bp_get_member_last_active();
  293. }
  294. function bp_get_member_last_active() {
  295. global $members_template;
  296. $last_activity = bp_core_get_last_activity( $members_template->member->last_activity, __( 'active %s ago', 'buddypress' ) );
  297. return apply_filters( 'bp_member_last_active', $last_activity );
  298. }
  299. function bp_member_latest_update( $args = '' ) {
  300. echo bp_get_member_latest_update( $args );
  301. }
  302. function bp_get_member_latest_update( $args = '' ) {
  303. global $members_template, $bp;
  304. $defaults = array(
  305. 'length' => 15
  306. );
  307. $r = wp_parse_args( $args, $defaults );
  308. extract( $r, EXTR_SKIP );
  309. if ( !$update = maybe_unserialize( $members_template->member->latest_update ) )
  310. return false;
  311. $update_content = apply_filters( 'bp_get_activity_latest_update', strip_tags( bp_create_excerpt( $update['content'], $length ) ) );
  312. if ( !empty( $update['id'] ) )
  313. $update_content .= ' &middot; <a href="' . $bp->root_domain . '/' . BP_ACTIVITY_SLUG . '/p/' . $update['id'] . '">' . __( 'View', 'buddypress' ) . '</a>';
  314. return apply_filters( 'bp_get_member_latest_update', $update_content );
  315. }
  316. function bp_member_profile_data( $args = '' ) {
  317. echo bp_get_member_profile_data( $args );
  318. }
  319. function bp_get_member_profile_data( $args = '' ) {
  320. global $members_template;
  321. if ( !function_exists( 'xprofile_install' ) )
  322. return false;
  323. $defaults = array(
  324. 'field' => false, // Field name
  325. );
  326. $r = wp_parse_args( $args, $defaults );
  327. extract( $r, EXTR_SKIP );
  328. // Populate the user if it hasn't been already.
  329. if ( empty( $members_template->member->profile_data ) && method_exists( 'BP_XProfile_ProfileData', 'get_all_for_user' ) )
  330. $members_template->member->profile_data = BP_XProfile_ProfileData::get_all_for_user( $members_template->member->id );
  331. $data = xprofile_format_profile_field( $members_template->member->profile_data[$field]['field_type'], $members_template->member->profile_data[$field]['field_data'] );
  332. return apply_filters( 'bp_get_member_profile_data', $data );
  333. }
  334. function bp_member_registered() {
  335. echo bp_get_member_registered();
  336. }
  337. function bp_get_member_registered() {
  338. global $members_template;
  339. $registered = attribute_escape( bp_core_get_last_activity( $members_template->member->user_registered, __( 'registered %s ago', 'buddypress' ) ) );
  340. return apply_filters( 'bp_member_last_active', $registered );
  341. }
  342. function bp_member_add_friend_button() {
  343. global $members_template;
  344. if ( function_exists( 'bp_add_friend_button' ) ) {
  345. if ( null === $members_template->member->is_friend )
  346. $friend_status = 'not_friends';
  347. else
  348. $friend_status = ( 0 == $members_template->member->is_friend ) ? 'pending' : 'is_friend';
  349. echo bp_add_friend_button( $members_template->member->id, $friend_status );
  350. }
  351. }
  352. function bp_member_total_friend_count() {
  353. global $members_template;
  354. echo bp_get_member_total_friend_count();
  355. }
  356. function bp_get_member_total_friend_count() {
  357. global $members_template;
  358. if ( 1 == (int) $members_template->member->total_friend_count )
  359. return apply_filters( 'bp_get_member_total_friend_count', sprintf( __( '%d friend', 'buddypress' ), (int) $members_template->member->total_friend_count ) );
  360. else
  361. return apply_filters( 'bp_get_member_total_friend_count', sprintf( __( '%d friends', 'buddypress' ), (int) $members_template->member->total_friend_count ) );
  362. }
  363. function bp_member_random_profile_data() {
  364. global $members_template;
  365. if ( function_exists( 'xprofile_get_random_profile_data' ) ) { ?>
  366. <?php $random_data = xprofile_get_random_profile_data( $members_template->member->id, true ); ?>
  367. <strong><?php echo wp_filter_kses( $random_data[0]->name ) ?></strong>
  368. <?php echo wp_filter_kses( $random_data[0]->value ) ?>
  369. <?php }
  370. }
  371. function bp_member_hidden_fields() {
  372. if ( isset( $_REQUEST['s'] ) ) {
  373. echo '<input type="hidden" id="search_terms" value="' . attribute_escape( $_REQUEST['s'] ) . '" name="search_terms" />';
  374. }
  375. if ( isset( $_REQUEST['letter'] ) ) {
  376. echo '<input type="hidden" id="selected_letter" value="' . attribute_escape( $_REQUEST['letter'] ) . '" name="selected_letter" />';
  377. }
  378. if ( isset( $_REQUEST['members_search'] ) ) {
  379. echo '<input type="hidden" id="search_terms" value="' . attribute_escape( $_REQUEST['members_search'] ) . '" name="search_terms" />';
  380. }
  381. }
  382. function bp_directory_members_search_form() {
  383. global $bp;
  384. $search_value = __( 'Search anything...', 'buddypress' );
  385. if ( !empty( $_GET['s'] ) )
  386. $search_value = $_GET['s'];
  387. ?>
  388. <form action="" method="get" id="search-members-form">
  389. <label><input type="text" name="s" id="members_search" value="<?php echo attribute_escape( $search_value ) ?>" onfocus="if (this.value == '<?php _e( 'Search anything...', 'buddypress' ) ?>') {this.value = '';}" onblur="if (this.value == '') {this.value = '<?php _e( 'Search anything...', 'buddypress' ) ?>';}" /></label>
  390. <input type="submit" id="members_search_submit" name="members_search_submit" value="<?php _e( 'Search', 'buddypress' ) ?>" />
  391. </form>
  392. <?php
  393. }
  394. function bp_total_site_member_count() {
  395. echo bp_get_total_site_member_count();
  396. }
  397. function bp_get_total_site_member_count() {
  398. return apply_filters( 'bp_get_total_site_member_count', bp_core_number_format( bp_core_get_total_member_count() ) );
  399. }
  400. /** Navigation and other misc template tags **/
  401. /**
  402. * bp_get_nav()
  403. * TEMPLATE TAG
  404. *
  405. * Uses the $bp->bp_nav global to render out the navigation within a BuddyPress install.
  406. * Each component adds to this navigation array within its own [component_name]_setup_nav() function.
  407. *
  408. * This navigation array is the top level navigation, so it contains items such as:
  409. * [Blog, Profile, Messages, Groups, Friends] ...
  410. *
  411. * The function will also analyze the current component the user is in, to determine whether
  412. * or not to highlight a particular nav item.
  413. *
  414. * @package BuddyPress Core
  415. * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
  416. */
  417. function bp_get_loggedin_user_nav() {
  418. global $bp, $current_blog;
  419. /* Loop through each navigation item */
  420. foreach( (array) $bp->bp_nav as $nav_item ) {
  421. /* If the current component matches the nav item id, then add a highlight CSS class. */
  422. if ( !bp_is_directory && $bp->active_components[$bp->current_component] == $nav_item['css_id'] )
  423. $selected = ' class="current selected"';
  424. else
  425. $selected = '';
  426. /* If we are viewing another person (current_userid does not equal loggedin_user->id)
  427. then check to see if the two users are friends. if they are, add a highlight CSS class
  428. to the friends nav item if it exists. */
  429. if ( !bp_is_my_profile() && $bp->displayed_user->id ) {
  430. $selected = '';
  431. if ( function_exists('friends_install') ) {
  432. if ( $nav_item['css_id'] == $bp->friends->id ) {
  433. if ( friends_check_friendship( $bp->loggedin_user->id, $bp->displayed_user->id ) )
  434. $selected = ' class="current selected"';
  435. }
  436. }
  437. }
  438. /* echo out the final list item */
  439. echo apply_filters( 'bp_get_loggedin_user_nav_' . $nav_item['css_id'], '<li id="li-nav-' . $nav_item['css_id'] . '" ' . $selected . '><a id="my-' . $nav_item['css_id'] . '" href="' . $nav_item['link'] . '">' . $nav_item['name'] . '</a></li>', &$nav_item );
  440. }
  441. /* Always add a log out list item to the end of the navigation */
  442. if ( function_exists( 'wp_logout_url' ) ) {
  443. $logout_link = '<li><a id="wp-logout" href="' . wp_logout_url( $bp->root_domain ) . '">' . __( 'Log Out', 'buddypress' ) . '</a></li>';
  444. } else {
  445. $logout_link = '<li><a id="wp-logout" href="' . site_url() . '/wp-login.php?action=logout&amp;redirect_to=' . $bp->root_domain . '">' . __( 'Log Out', 'buddypress' ) . '</a></li>';
  446. }
  447. echo apply_filters( 'bp_logout_nav_link', $logout_link );
  448. }
  449. /**
  450. * bp_get_displayed_user_nav()
  451. * TEMPLATE TAG
  452. *
  453. * Uses the $bp->bp_users_nav global to render out the user navigation when viewing another user other than
  454. * yourself.
  455. *
  456. * @package BuddyPress Core
  457. * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
  458. */
  459. function bp_get_displayed_user_nav() {
  460. global $bp;
  461. foreach ( (array)$bp->bp_nav as $user_nav_item ) {
  462. if ( !$user_nav_item['show_for_displayed_user'] && !bp_is_my_profile() )
  463. continue;
  464. if ( $bp->current_component == $user_nav_item['slug'] )
  465. $selected = ' class="current selected"';
  466. else
  467. $selected = '';
  468. if ( $bp->loggedin_user->domain )
  469. $link = str_replace( $bp->loggedin_user->domain, $bp->displayed_user->domain, $user_nav_item['link'] );
  470. else
  471. $link = $bp->displayed_user->domain . $user_nav_item['link'];
  472. echo apply_filters( 'bp_get_displayed_user_nav_' . $user_nav_item['css_id'], '<li id="' . $user_nav_item['css_id'] . '-personal-li" ' . $selected . '><a id="user-' . $user_nav_item['css_id'] . '" href="' . $link . '">' . $user_nav_item['name'] . '</a></li>', &$user_nav_item );
  473. }
  474. }
  475. /**
  476. * bp_get_options_nav()
  477. * TEMPLATE TAG
  478. *
  479. * Uses the $bp->bp_options_nav global to render out the sub navigation for the current component.
  480. * Each component adds to its sub navigation array within its own [component_name]_setup_nav() function.
  481. *
  482. * This sub navigation array is the secondary level navigation, so for profile it contains:
  483. * [Public, Edit Profile, Change Avatar]
  484. *
  485. * The function will also analyze the current action for the current component to determine whether
  486. * or not to highlight a particular sub nav item.
  487. *
  488. * @package BuddyPress Core
  489. * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
  490. * @uses bp_get_user_nav() Renders the navigation for a profile of a currently viewed user.
  491. */
  492. function bp_get_options_nav() {
  493. global $bp;
  494. if ( count( $bp->bp_options_nav[$bp->current_component] ) < 1 )
  495. return false;
  496. /* Loop through each navigation item */
  497. foreach ( (array)$bp->bp_options_nav[$bp->current_component] as $subnav_item ) {
  498. if ( !$subnav_item['user_has_access'] )
  499. continue;
  500. /* If the current action or an action variable matches the nav item id, then add a highlight CSS class. */
  501. if ( $subnav_item['slug'] == $bp->current_action ) {
  502. $selected = ' class="current selected"';
  503. } else {
  504. $selected = '';
  505. }
  506. /* echo out the final list item */
  507. echo apply_filters( 'bp_get_options_nav_' . $subnav_item['css_id'], '<li id="' . $subnav_item['css_id'] . '-personal-li" ' . $selected . '><a id="' . $subnav_item['css_id'] . '" href="' . $subnav_item['link'] . '">' . $subnav_item['name'] . '</a></li>', $subnav_item );
  508. }
  509. }
  510. function bp_get_options_title() {
  511. global $bp;
  512. if ( empty( $bp->bp_options_title ) )
  513. $bp->bp_options_title = __( 'Options', 'buddypress' );
  514. echo apply_filters( 'bp_get_options_title', attribute_escape( $bp->bp_options_title ) );
  515. }
  516. /** AVATAR TEMPLATE TAGS *******************************************************/
  517. /**
  518. * bp_has_options_avatar()
  519. * TEMPLATE TAG
  520. *
  521. * Check to see if there is an options avatar. An options avatar is an avatar for something
  522. * like a group, or a friend. Basically an avatar that appears in the sub nav options bar.
  523. *
  524. * @package BuddyPress Core
  525. * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
  526. */
  527. function bp_has_options_avatar() {
  528. global $bp;
  529. if ( empty( $bp->bp_options_avatar ) )
  530. return false;
  531. return true;
  532. }
  533. function bp_get_options_avatar() {
  534. global $bp;
  535. echo apply_filters( 'bp_get_options_avatar', $bp->bp_options_avatar );
  536. }
  537. function bp_comment_author_avatar() {
  538. global $comment;
  539. if ( function_exists('bp_core_fetch_avatar') ) {
  540. echo apply_filters( 'bp_comment_author_avatar', bp_core_fetch_avatar( array( 'item_id' => $comment->user_id, 'type' => 'thumb' ) ) );
  541. } else if ( function_exists('get_avatar') ) {
  542. get_avatar();
  543. }
  544. }
  545. function bp_post_author_avatar() {
  546. global $post;
  547. if ( function_exists('bp_core_fetch_avatar') ) {
  548. echo apply_filters( 'bp_post_author_avatar', bp_core_fetch_avatar( array( 'item_id' => $post->post_author, 'type' => 'thumb' ) ) );
  549. } else if ( function_exists('get_avatar') ) {
  550. get_avatar();
  551. }
  552. }
  553. function bp_loggedin_user_avatar( $args = '' ) {
  554. echo bp_get_loggedin_user_avatar( $args );
  555. }
  556. function bp_get_loggedin_user_avatar( $args = '' ) {
  557. global $bp;
  558. $defaults = array(
  559. 'type' => 'thumb',
  560. 'width' => false,
  561. 'height' => false,
  562. 'html' => true
  563. );
  564. $r = wp_parse_args( $args, $defaults );
  565. extract( $r, EXTR_SKIP );
  566. return apply_filters( 'bp_get_loggedin_user_avatar', bp_core_fetch_avatar( array( 'item_id' => $bp->loggedin_user->id, 'type' => $type, 'width' => $width, 'height' => $height, 'html' => $html ) ) );
  567. }
  568. function bp_displayed_user_avatar( $args = '' ) {
  569. echo bp_get_displayed_user_avatar( $args );
  570. }
  571. function bp_get_displayed_user_avatar( $args = '' ) {
  572. global $bp;
  573. $defaults = array(
  574. 'type' => 'thumb',
  575. 'width' => false,
  576. 'height' => false,
  577. 'html' => true
  578. );
  579. $r = wp_parse_args( $args, $defaults );
  580. extract( $r, EXTR_SKIP );
  581. return apply_filters( 'bp_get_displayed_user_avatar', bp_core_fetch_avatar( array( 'item_id' => $bp->displayed_user->id, 'type' => $type, 'width' => $width, 'height' => $height, 'html' => $html ) ) );
  582. }
  583. function bp_avatar_admin_step() {
  584. echo bp_get_avatar_admin_step();
  585. }
  586. function bp_get_avatar_admin_step() {
  587. global $bp;
  588. return apply_filters( 'bp_get_avatar_admin_step', $bp->avatar_admin->step );
  589. }
  590. function bp_avatar_to_crop() {
  591. echo bp_get_avatar_to_crop();
  592. }
  593. function bp_get_avatar_to_crop() {
  594. global $bp;
  595. return apply_filters( 'bp_get_avatar_to_crop', $bp->avatar_admin->image->url );
  596. }
  597. function bp_avatar_to_crop_src() {
  598. echo bp_get_avatar_to_crop_src();
  599. }
  600. function bp_get_avatar_to_crop_src() {
  601. global $bp;
  602. return apply_filters( 'bp_get_avatar_to_crop_src', str_replace( WP_CONTENT_DIR, '', $bp->avatar_admin->image->dir ) );
  603. }
  604. function bp_avatar_cropper() {
  605. global $bp;
  606. echo '<img id="avatar-to-crop" class="avatar" src="' . $bp->avatar_admin->image . '" />';
  607. }
  608. /** OTHER TEMPLATE TAGS *******************************************************/
  609. function bp_site_name() {
  610. echo apply_filters( 'bp_site_name', get_blog_option( BP_ROOT_BLOG, 'blogname' ) );
  611. }
  612. function bp_core_get_wp_profile() {
  613. global $bp;
  614. $ud = get_userdata( $bp->displayed_user->id );
  615. ?>
  616. <div class="bp-widget wp-profile">
  617. <h4><?php _e( 'My Profile' ) ?></h4>
  618. <table class="wp-profile-fields zebra">
  619. <?php if ( $ud->display_name ) { ?>
  620. <tr id="wp_displayname">
  621. <td class="label">
  622. <?php _e( 'Name', 'buddypress' ) ?>
  623. </td>
  624. <td class="data">
  625. <?php echo $ud->display_name ?>
  626. </td>
  627. </tr>
  628. <?php } ?>
  629. <?php if ( $ud->user_description ) { ?>
  630. <tr id="wp_desc">
  631. <td class="label">
  632. <?php _e( 'About Me', 'buddypress' ) ?>
  633. </td>
  634. <td class="data">
  635. <?php echo $ud->user_description ?>
  636. </td>
  637. </tr>
  638. <?php } ?>
  639. <?php if ( $ud->user_url ) { ?>
  640. <tr id="wp_website">
  641. <td class="label">
  642. <?php _e( 'Website', 'buddypress' ) ?>
  643. </td>
  644. <td class="data">
  645. <?php echo make_clickable( $ud->user_url ) ?>
  646. </td>
  647. </tr>
  648. <?php } ?>
  649. <?php if ( $ud->jabber ) { ?>
  650. <tr id="wp_jabber">
  651. <td class="label">
  652. <?php _e( 'Jabber', 'buddypress' ) ?>
  653. </td>
  654. <td class="data">
  655. <?php echo $ud->jabber ?>
  656. </td>
  657. </tr>
  658. <?php } ?>
  659. <?php if ( $ud->aim ) { ?>
  660. <tr id="wp_aim">
  661. <td class="label">
  662. <?php _e( 'AOL Messenger', 'buddypress' ) ?>
  663. </td>
  664. <td class="data">
  665. <?php echo $ud->aim ?>
  666. </td>
  667. </tr>
  668. <?php } ?>
  669. <?php if ( $ud->yim ) { ?>
  670. <tr id="wp_yim">
  671. <td class="label">
  672. <?php _e( 'Yahoo Messenger', 'buddypress' ) ?>
  673. </td>
  674. <td class="data">
  675. <?php echo $ud->yim ?>
  676. </td>
  677. </tr>
  678. <?php } ?>
  679. </table>
  680. </div>
  681. <?php
  682. }
  683. function bp_get_profile_header() {
  684. locate_template( array( '/profile/profile-header.php' ), true );
  685. }
  686. function bp_exists( $component_name ) {
  687. if ( function_exists($component_name . '_install') )
  688. return true;
  689. return false;
  690. }
  691. function bp_format_time( $time, $just_date = false ) {
  692. $date = date( get_option('date_format'), $time );
  693. if ( !$just_date ) {
  694. $date .= ' ' . __( 'at', 'buddypress' ) . date( ' ' . get_option('time_format'), $time );
  695. }
  696. return apply_filters( 'bp_format_time', $date );
  697. }
  698. function bp_word_or_name( $youtext, $nametext, $capitalize = true, $echo = true ) {
  699. global $bp;
  700. if ( $capitalize )
  701. $youtext = bp_core_ucfirst($youtext);
  702. if ( $bp->displayed_user->id == $bp->loggedin_user->id ) {
  703. if ( $echo )
  704. echo apply_filters( 'bp_word_or_name', $youtext );
  705. else
  706. return apply_filters( 'bp_word_or_name', $youtext );
  707. } else {
  708. $fullname = (array)explode( ' ', $bp->displayed_user->fullname );
  709. $nametext = sprintf( $nametext, $fullname[0] );
  710. if ( $echo )
  711. echo apply_filters( 'bp_word_or_name', $nametext );
  712. else
  713. return apply_filters( 'bp_word_or_name', $nametext );
  714. }
  715. }
  716. function bp_your_or_their( $capitalize = true, $echo = true ) {
  717. global $bp;
  718. if ( $capitalize )
  719. $yourtext = bp_core_ucfirst($yourtext);
  720. if ( $bp->displayed_user->id == $bp->loggedin_user->id ) {
  721. if ( $echo )
  722. echo apply_filters( 'bp_your_or_their', $yourtext );
  723. else
  724. return apply_filters( 'bp_your_or_their', $yourtext );
  725. } else {
  726. if ( $echo )
  727. echo apply_filters( 'bp_your_or_their', $theirtext );
  728. else
  729. return apply_filters( 'bp_your_or_their', $theirtext );
  730. }
  731. }
  732. function bp_get_plugin_sidebar() {
  733. locate_template( array( 'plugin-sidebar.php' ), true );
  734. }
  735. function bp_page_title() {
  736. echo bp_get_page_title();
  737. }
  738. function bp_get_page_title() {
  739. global $bp, $post, $wp_query, $current_blog;
  740. if ( is_front_page() || !bp_current_component() || ( is_home() && bp_is_page( 'home' ) ) ) {
  741. $title = __( 'Home', 'buddypress' );
  742. } else if ( bp_is_blog_page() ) {
  743. if ( is_single() ) {
  744. $title = __( 'Blog &#124; ' . $post->post_title, 'buddypress' );
  745. } else if ( is_category() ) {
  746. $title = __( 'Blog &#124; Categories &#124; ' . ucwords( $wp_query->query_vars['category_name'] ), 'buddypress' );
  747. } else if ( is_tag() ) {
  748. $title = __( 'Blog &#124; Tags &#124; ' . ucwords( $wp_query->query_vars['tag'] ), 'buddypress' );
  749. } else if ( is_page() ){
  750. $title = $post->post_title;
  751. } else
  752. $title = __( 'Blog', 'buddypress' );
  753. } else if ( !empty( $bp->displayed_user->fullname ) ) {
  754. $title = strip_tags( $bp->displayed_user->fullname . ' &#124; ' . ucwords( $bp->current_component ) );
  755. } else if ( $bp->is_single_item ) {
  756. $title = ucwords( $bp->current_component ) . ' &#124; ' . $bp->bp_options_title . ' &#124; ' . $bp->bp_options_nav[$bp->current_component][$bp->current_action]['name'];
  757. } else if ( $bp->is_directory ) {
  758. if ( !$bp->current_component )
  759. $title = sprintf( __( '%s Directory', 'buddypress' ), ucwords( BP_MEMBERS_SLUG ) );
  760. else
  761. $title = sprintf( __( '%s Directory', 'buddypress' ), ucwords( $bp->current_component ) );
  762. } else if ( bp_is_register_page() ) {
  763. $title = __( 'Create an Account', 'buddypress' );
  764. } else if ( bp_is_activation_page() ) {
  765. $title = __( 'Activate your Account', 'buddypress' );
  766. } else if ( bp_is_group_create() ) {
  767. $title = __( 'Create a Group', 'buddypress' );
  768. } else if ( bp_is_create_blog() ) {
  769. $title = __( 'Create a Blog', 'buddypress' );
  770. }
  771. if ( defined( 'BP_ENABLE_MULTIBLOG' ) ) {
  772. $blog_title = get_blog_option( $current_blog->blog_id, 'blogname' );
  773. } else {
  774. $blog_title = get_blog_option( BP_ROOT_BLOG, 'blogname' );
  775. }
  776. return apply_filters( 'bp_page_title', $blog_title . ' &#124; ' . esc_attr( $title ), esc_attr( $title ) );
  777. }
  778. function bp_styles() {
  779. do_action( 'bp_styles' );
  780. wp_print_styles();
  781. }
  782. function bp_has_custom_signup_page() {
  783. if ( locate_template( array( 'register.php' ), false ) || locate_template( array( '/registration/register.php' ), false ) )
  784. return true;
  785. return false;
  786. }
  787. function bp_signup_page() {
  788. echo bp_get_signup_page();
  789. }
  790. function bp_get_signup_page() {
  791. global $bp;
  792. if ( bp_has_custom_signup_page() )
  793. $page = $bp->root_domain . '/' . BP_REGISTER_SLUG;
  794. else
  795. $page = $bp->root_domain . '/wp-signup.php';
  796. return apply_filters( 'bp_get_signup_page', $page );
  797. }
  798. function bp_has_custom_activation_page() {
  799. if ( locate_template( array( 'activate.php' ), false ) || locate_template( array( '/registration/activate.php' ), false ) )
  800. return true;
  801. return false;
  802. }
  803. function bp_activation_page() {
  804. echo bp_get_activation_page();
  805. }
  806. function bp_get_activation_page() {
  807. global $bp;
  808. if ( bp_has_custom_activation_page() )
  809. $page = $bp->root_domain . '/' . BP_ACTIVATION_SLUG;
  810. else
  811. $page = $bp->root_domain . '/wp-activate.php';
  812. return apply_filters( 'bp_get_activation_page', $page );
  813. }
  814. /**
  815. * bp_search_form_available()
  816. *
  817. * Only show the search form if there are available objects to search for.
  818. *
  819. * @global array $bp
  820. * @uses function_exists
  821. * @uses bp_core_is_multisite()
  822. * @return bool Filterable result
  823. */
  824. function bp_search_form_enabled() {
  825. global $bp;
  826. if ( function_exists( 'xprofile_install' )
  827. || function_exists( 'groups_install' )
  828. || ( function_exists( 'bp_blogs_install' ) && bp_core_is_multisite() )
  829. || ( function_exists( 'bp_forums_setup' ) && !(int)$bp->site_options['bp-disable-forum-directory'] )
  830. ) {
  831. $search_enabled = true;
  832. } else {
  833. $search_enabled = false;
  834. }
  835. return apply_filters( 'bp_search_form_enabled', $search_enabled );
  836. }
  837. function bp_search_form_action() {
  838. global $bp;
  839. return apply_filters( 'bp_search_form_action', $bp->root_domain . '/' . BP_SEARCH_SLUG );
  840. }
  841. function bp_search_form_type_select() {
  842. global $bp;
  843. // Eventually this won't be needed and a page will be built to integrate all search results.
  844. $selection_box = '<select name="search-which" id="search-which" style="width: auto">';
  845. if ( function_exists( 'xprofile_install' ) )
  846. $selection_box .= '<option value="members">' . __( 'Members', 'buddypress' ) . '</option>';
  847. if ( function_exists( 'groups_install' ) )
  848. $selection_box .= '<option value="groups">' . __( 'Groups', 'buddypress' ) . '</option>';
  849. if ( function_exists( 'bp_forums_setup' ) && !(int)$bp->site_options['bp-disable-forum-directory'] )
  850. $selection_box .= '<option value="forums">' . __( 'Forums', 'buddypress' ) . '</option>';
  851. if ( function_exists( 'bp_blogs_install' ) && bp_core_is_multisite() )
  852. $selection_box .= '<option value="blogs">' . __( 'Blogs', 'buddypress' ) . '</option>';
  853. $selection_box .= '</select>';
  854. return apply_filters( 'bp_search_form_type_select', $selection_box );
  855. }
  856. function bp_search_form() {
  857. $form = '
  858. <form action="' . bp_search_form_action() . '" method="post" id="search-form">
  859. <input type="text" id="search-terms" name="search-terms" value="" />
  860. ' . bp_search_form_type_select() . '
  861. <input type="submit" name="search-submit" id="search-submit" value="' . __( 'Search', 'buddypress' ) . '" />
  862. ' . wp_nonce_field( 'bp_search_form' ) . '
  863. </form>
  864. ';
  865. echo apply_filters( 'bp_search_form', $form );
  866. }
  867. function bp_log_out_link() {
  868. global $bp;
  869. if ( function_exists('wp_logout_url') )
  870. $logout_link = '<a href="' . wp_logout_url( $bp->root_domain ) . '">' . __( 'Log Out', 'buddypress' ) . '</a>';
  871. else
  872. $logout_link = '<a href="' . $bp->root_domain . '/wp-login.php?action=logout&amp;redirect_to=' . $bp->root_domain . '">' . __( 'Log Out', 'buddypress' ) . '</a>';
  873. echo apply_filters( 'bp_logout_link', $logout_link );
  874. }
  875. function bp_custom_profile_boxes() {
  876. do_action( 'bp_custom_profile_boxes' );
  877. }
  878. function bp_custom_profile_sidebar_boxes() {
  879. do_action( 'bp_custom_profile_sidebar_boxes' );
  880. }
  881. /**
  882. * bp_create_excerpt()
  883. *
  884. * Fakes an excerpt on any content. Will not truncate words.
  885. *
  886. * @package BuddyPress Core
  887. * @param $text str The text to create the excerpt from
  888. * @uses $excerpt_length The maximum length in characters of the excerpt.
  889. * @return str The excerpt text
  890. */
  891. function bp_create_excerpt( $text, $excerpt_length = 55, $filter_shortcodes = true ) { // Fakes an excerpt if needed
  892. $text = str_replace(']]>', ']]&gt;', $text);
  893. if ( $filter_shortcodes )
  894. $text = preg_replace( '|\[(.+?)\](.+?\[/\\1\])?|s', '', $text );
  895. $words = preg_split(
  896. "%\s*((?:<[^>]+>)+\S*)\s*|\s+%s",
  897. $text,
  898. $excerpt_length + 1,
  899. PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE
  900. );
  901. if (count($words) > $excerpt_length) {
  902. array_pop($words);
  903. array_push($words, '[...]');
  904. $text = implode(' ', $words);
  905. }
  906. return apply_filters( 'bp_create_excerpt', $text );
  907. }
  908. add_filter( 'bp_create_excerpt', 'wp_trim_excerpt' );
  909. add_filter( 'bp_create_excerpt', 'stripslashes_deep' );
  910. add_filter( 'bp_create_excerpt', 'force_balance_tags' );
  911. /**
  912. * bp_is_serialized()
  913. *
  914. * Checks to see if the data passed has been serialized.
  915. *
  916. * @package BuddyPress Core
  917. * @param $data str The data that will be checked
  918. * @return bool false if the data is not serialized
  919. * @return bool true if the data is serialized
  920. */
  921. function bp_is_serialized( $data ) {
  922. if ( '' == trim($data) )
  923. return false;
  924. if ( preg_match( "/^(i|s|a|o|d)(.*);/si", $data ) )
  925. return true;
  926. return false;
  927. }
  928. function bp_total_member_count() {
  929. echo bp_get_total_member_count();
  930. }
  931. function bp_get_total_member_count() {
  932. return apply_filters( 'bp_get_total_member_count', bp_core_get_total_member_count() );
  933. }
  934. add_filter( 'bp_get_total_member_count', 'bp_core_number_format' );
  935. /*** Signup form template tags **********************/
  936. function bp_signup_username_value() {
  937. echo bp_get_signup_username_value();
  938. }
  939. function bp_get_signup_username_value() {
  940. return apply_filters( 'bp_get_signup_username_value', $_POST['signup_username'] );
  941. }
  942. function bp_signup_email_value() {
  943. echo bp_get_signup_email_value();
  944. }
  945. function bp_get_signup_email_value() {
  946. return apply_filters( 'bp_get_signup_email_value', $_POST['signup_email'] );
  947. }
  948. function bp_signup_with_blog_value() {
  949. echo bp_get_signup_with_blog_value();
  950. }
  951. function bp_get_signup_with_blog_value() {
  952. return apply_filters( 'bp_get_signup_with_blog_value', $_POST['signup_with_blog'] );
  953. }
  954. function bp_signup_blog_url_value() {
  955. echo bp_get_signup_blog_url_value();
  956. }
  957. function bp_get_signup_blog_url_value() {
  958. return apply_filters( 'bp_get_signup_blog_url_value', $_POST['signup_blog_url'] );
  959. }
  960. function bp_signup_blog_title_value() {
  961. echo bp_get_signup_blog_title_value();
  962. }
  963. function bp_get_signup_blog_title_value() {
  964. return apply_filters( 'bp_get_signup_blog_title_value', $_POST['signup_blog_title'] );
  965. }
  966. function bp_signup_blog_privacy_value() {
  967. echo bp_get_signup_blog_privacy_value();
  968. }
  969. function bp_get_signup_blog_privacy_value() {
  970. return apply_filters( 'bp_get_signup_blog_privacy_value', $_POST['signup_blog_privacy'] );
  971. }
  972. function bp_signup_avatar_dir_value() {
  973. echo bp_get_signup_avatar_dir_value();
  974. }
  975. function bp_get_signup_avatar_dir_value() {
  976. global $bp;
  977. return apply_filters( 'bp_get_signup_avatar_dir_value', $bp->signup->avatar_dir );
  978. }
  979. function bp_current_signup_step() {
  980. echo bp_get_current_signup_step();
  981. }
  982. function bp_get_current_signup_step() {
  983. global $bp;
  984. return $bp->signup->step;
  985. }
  986. function bp_signup_avatar( $args = '' ) {
  987. echo bp_get_signup_avatar( $args );
  988. }
  989. function bp_get_signup_avatar( $args = '' ) {
  990. global $bp;
  991. $defaults = array(
  992. 'size' => BP_AVATAR_FULL_WIDTH,
  993. 'class' => 'avatar',
  994. 'alt' => __( 'Your Avatar', 'buddypress' )
  995. );
  996. $r = wp_parse_args( $args, $defaults );
  997. extract( $r, EXTR_SKIP );
  998. $signup_avatar_dir = ( !empty( $_POST['signup_avatar_dir'] ) ) ? $_POST['signup_avatar_dir'] : $bp->signup->avatar_dir;
  999. if ( empty( $signup_avatar_dir ) ) {
  1000. if ( empty( $bp->grav_default->user ) ) {
  1001. $default_grav = 'wavatar';
  1002. } else if ( 'mystery' == $bp->grav_default->user ) {
  1003. $default_grav = BP_PLUGIN_URL . '/bp-core/images/mystery-man.jpg';
  1004. } else {
  1005. $default_grav = $bp->grav_default->user;
  1006. }
  1007. $gravatar_url = apply_filters( 'bp_gravatar_url', 'http://www.gravatar.com/avatar/' );
  1008. $gravatar_img = '<img src="' . $gravatar_url . md5( strtolower( $_POST['signup_email'] ) ) . '?d=' . $default_grav . '&amp;s=' . $size . '" width="' . $size . '" height="' . $size . '" alt="' . $alt . '" class="' . $class . '" />';
  1009. } else {
  1010. $gravatar_img = bp_core_fetch_avatar( array( 'item_id' => $signup_avatar_dir, 'object' => 'signup', 'avatar_dir' => 'avatars/signups', 'type' => 'full', 'width' => $size, 'height' => $size, 'alt' => $alt, 'class' => $class ) );
  1011. }
  1012. return apply_filters( 'bp_get_signup_avatar', $gravatar_img );
  1013. }
  1014. function bp_signup_allowed() {
  1015. echo bp_get_signup_allowed();
  1016. }
  1017. function bp_get_signup_allowed() {
  1018. global $bp;
  1019. if ( bp_core_is_multisite() ) {
  1020. if ( in_array( $bp->site_options['registration'], array( 'all', 'user' ) ) )
  1021. return true;
  1022. } else {
  1023. if ( (int)get_option( 'users_can_register') )
  1024. return true;
  1025. }
  1026. return false;
  1027. }
  1028. function bp_blog_signup_allowed() {
  1029. echo bp_get_blog_signup_allowed();
  1030. }
  1031. function bp_get_blog_signup_allowed() {
  1032. global $bp;
  1033. if ( !bp_core_is_multisite() )
  1034. return false;
  1035. $status = $bp->site_options['registration'];
  1036. if ( 'none' != $status && 'user' != $status )
  1037. return true;
  1038. return false;
  1039. }
  1040. function bp_account_was_activated() {
  1041. global $bp;
  1042. return $bp->activation_complete;
  1043. }
  1044. function bp_registration_needs_activation() {
  1045. return apply_filters( 'bp_registration_needs_activation', true );
  1046. }
  1047. function bp_mentioned_user_display_name( $user_id_or_username ) {
  1048. echo bp_get_mentioned_user_display_name( $user_id_or_username );
  1049. }
  1050. function bp_get_mentioned_user_display_name( $user_id_or_username ) {
  1051. if ( !$name = bp_core_get_user_displayname( $user_id_or_username ) )
  1052. $name = __( 'a user' );
  1053. return apply_filters( 'bp_get_mentioned_user_display_name', $name, $user_id_or_username );
  1054. }
  1055. function bp_get_option( $option_name ) {
  1056. global $bp;
  1057. return apply_filters( 'bp_get_option', $bp->site_options[$option_name] );
  1058. }
  1059. /**
  1060. * Allow templates to pass parameters directly into the template loops via AJAX
  1061. *
  1062. * For the most part this will be filtered in a theme's functions.php for example
  1063. * in the default theme it is filtered via bp_dtheme_ajax_querystring()
  1064. *
  1065. * By using this template tag in the templates it will stop them from showing errors
  1066. * if someone copies the templates from the default theme into another WordPress theme
  1067. * without coping the functions from functions.php.
  1068. */
  1069. function bp_ajax_querystring( $object = false ) {
  1070. global $bp;
  1071. $bp->ajax_querystring = apply_filters( 'bp_ajax_querystring', $query_string, $object );
  1072. return $bp->ajax_querystring;
  1073. }
  1074. /*** CUSTOM LOOP TEMPLATE CLASSES *******************/
  1075. /* Template functions for fetching globals, without querying the DB again
  1076. also means we dont have to use the $bp variable in the template (looks messy) */
  1077. function bp_last_activity( $user_id = false, $echo = true ) {
  1078. global $bp;
  1079. if ( !$user_id )
  1080. $user_id = $bp->displayed_user->id;
  1081. $last_activity = bp_core_get_last_activity( get_usermeta( $user_id, 'last_activity' ), __('active %s ago', 'buddypress') );
  1082. if ( $echo )
  1083. echo apply_filters( 'bp_last_activity', $last_activity );
  1084. else
  1085. return apply_filters( 'bp_last_activity', $last_activity );
  1086. }
  1087. function bp_user_has_access() {
  1088. global $bp;
  1089. if ( is_site_admin() || is_user_logged_in() && $bp->loggedin_user->id == $bp->displayed_user->id )
  1090. $has_access = true;
  1091. else
  1092. $has_access = false;
  1093. return apply_filters( 'bp_user_has_access', $has_access );
  1094. }
  1095. function bp_user_firstname() {
  1096. echo bp_get_user_firstname();
  1097. }
  1098. function bp_get_user_firstname( $name = false ) {
  1099. global $bp;
  1100. // Try to get displayed user
  1101. if ( empty( $name ) )
  1102. $name = $bp->displayed_user->fullname;
  1103. // Fall back on logged in user
  1104. if ( empty( $name ) )
  1105. $name = $bp->loggedin_user->fullname;
  1106. $fullname = (array)explode( ' ', $name );
  1107. return apply_filters( 'bp_get_user_firstname', $fullname[0], $fullname );
  1108. }
  1109. function bp_loggedin_user_link() {
  1110. echo bp_get_loggedin_user_link();
  1111. }
  1112. function bp_get_loggedin_user_link() {
  1113. global $bp;
  1114. return apply_filters( 'bp_get_loggedin_user_link', $bp->loggedin_user->domain );
  1115. }
  1116. /* @todo Deprecate incorrectly named function? */
  1117. function bp_loggedinuser_link() {
  1118. global $bp;
  1119. if ( $link = bp_core_get_userlink( $bp->loggedin_user->id ) )
  1120. echo apply_filters( 'bp_loggedin_user_link', $link );
  1121. }
  1122. function bp_displayed_user_link() {
  1123. echo bp_get_displayed_user_link();
  1124. }
  1125. function bp_get_displayed_user_link() {
  1126. global $bp;
  1127. return apply_filters( 'bp_get_displayed_user_link', $bp->displayed_user->domain );
  1128. }
  1129. function bp_user_link() { bp_displayed_user_link(); } // Deprecated.
  1130. function bp_displayed_user_id() {
  1131. global $bp;
  1132. return apply_filters( 'bp_displayed_user_id', $bp->displayed_user->id );
  1133. }
  1134. function bp_current_user_id() { return bp_displayed_user_id(); }
  1135. function bp_loggedin_user_id() {
  1136. global $bp;
  1137. return apply_filters( 'bp_loggedin_user_id', $bp->loggedin_user->id );
  1138. }
  1139. function bp_displayed_user_domain() {
  1140. global $bp;
  1141. return apply_filters( 'bp_displayed_user_domain', $bp->displayed_user->domain );
  1142. }
  1143. function bp_loggedin_user_domain() {
  1144. global $bp;
  1145. return apply_filters( 'bp_loggedin_user_domain', $bp->loggedin_user->domain );
  1146. }
  1147. function bp_displayed_user_fullname() {
  1148. echo bp_get_displayed_user_fullname();
  1149. }
  1150. function bp_get_displayed_user_fullname() {
  1151. global $bp;
  1152. return apply_filters( 'bp_displayed_user_fullname', $bp->displayed_user->fullname );
  1153. }
  1154. function bp_user_fullname() { echo bp_get_displayed_user_fullname(); }
  1155. function bp_loggedin_user_fullname() {
  1156. echo bp_get_loggedin_user_fullname();
  1157. }
  1158. function bp_get_loggedin_user_fullname() {
  1159. global $bp;
  1160. return apply_filters( 'bp_get_loggedin_user_fullname', $bp->loggedin_user->fullname );
  1161. }
  1162. function bp_displayed_user_username() {
  1163. echo bp_get_displayed_user_username();
  1164. }
  1165. function bp_get_displayed_user_username() {
  1166. global $bp;
  1167. return apply_filters( 'bp_get_displayed_user_username', bp_core_get_username( $bp->displayed_user->id, $bp->displayed_user->userdata->user_nicename, $bp->displayed_user->userdata->user_login ) );
  1168. }
  1169. function bp_loggedin_user_username() {
  1170. echo bp_get_loggedin_user_username();
  1171. }
  1172. function bp_get_loggedin_user_username() {
  1173. global $bp;
  1174. return apply_filters( 'bp_get_loggedin_user_username', bp_core_get_username( $bp->loggedin_user->id, $bp->loggedin_user->userdata->user_nicename, $bp->loggedin_user->userdata->user_login ) );
  1175. }
  1176. function bp_current_component() {
  1177. global $bp;
  1178. return apply_filters( 'bp_current_component', $bp->current_component );
  1179. }
  1180. function bp_current_action() {
  1181. global $bp;
  1182. return apply_filters( 'bp_current_action', $bp->current_action );
  1183. }
  1184. function bp_current_item() {
  1185. global $bp;
  1186. return apply_filters( 'bp_current_item', $bp->current_item );
  1187. }
  1188. function bp_action_variables() {
  1189. global $bp;
  1190. return apply_filters( 'bp_action_variables', $bp->action_variables );
  1191. }
  1192. function bp_root_domain() {
  1193. echo bp_get_root_domain();
  1194. }
  1195. function bp_get_root_domain() {
  1196. global $bp;
  1197. return apply_filters( 'bp_get_root_domain', $bp->root_domain );
  1198. }
  1199. /* Template is_() functions to determine the current page */
  1200. function bp_is_blog_page() {
  1201. global $bp, $is_member_page, $wp_query;
  1202. if ( $wp_query->is_home && !$bp->is_directory )
  1203. return true;
  1204. if ( !$bp->displayed_user->id && !$bp->is_single_item && !$bp->is_directory && !bp_core_is_root_component( $bp->current_component ) )
  1205. return true;
  1206. return false;
  1207. }
  1208. function bp_is_my_profile() {
  1209. global $bp;
  1210. if ( is_user_logged_in() && $bp->loggedin_user->id == $bp->displayed_user->id )
  1211. $my_profile = true;
  1212. else
  1213. $my_profile = false;
  1214. return apply_filters( 'bp_is_my_profile', $my_profile );
  1215. }
  1216. function bp_is_home() { return bp_is_my_profile(); }
  1217. function bp_is_front_page() {
  1218. if ( 'posts' == get_option('show_on_front') && is_home() )
  1219. return true;
  1220. else if ( bp_is_activity_front_page() )
  1221. return true;
  1222. else
  1223. return is_front_page();
  1224. }
  1225. function bp_is_activity_front_page() {
  1226. return ( 'page' == get_option('show_on_front') && 'activity' == get_option('page_on_front') && $_SERVER['REQUEST_URI'] == bp_core_get_site_path() );
  1227. }
  1228. function bp_is_directory() {
  1229. global $bp;
  1230. return $bp->is_directory;
  1231. }
  1232. function bp_is_page($page) {
  1233. global $bp;
  1234. if ( !$bp->displayed_user->id && $bp->current_component == $page )
  1235. return true;
  1236. if ( 'home' == $page )
  1237. return bp_is_front_page();
  1238. return false;
  1239. }
  1240. function bp_is_active( $component ) {
  1241. global $bp_deactivated;
  1242. if ( !isset( $bp_deactivated[ 'bp-' . $component . '.php' ] ) )
  1243. return true;
  1244. return false;
  1245. }
  1246. function bp_is_profile_component() {
  1247. global $bp;
  1248. if ( BP_XPROFILE_SLUG == $bp->current_component )
  1249. return true;
  1250. return false;
  1251. }
  1252. function bp_is_activity_component() {
  1253. global $bp;
  1254. if ( BP_ACTIVITY_SLUG == $bp->current_component )
  1255. return true;
  1256. return false;
  1257. }
  1258. function bp_is_blogs_component() {
  1259. global $bp;
  1260. if ( BP_BLOGS_SLUG == $bp->current_component )
  1261. return true;
  1262. return false;
  1263. }
  1264. function bp_is_messages_component() {
  1265. global $bp;
  1266. if ( BP_MESSAGES_SLUG == $bp->current_component )
  1267. return true;
  1268. return false;
  1269. }
  1270. function bp_is_friends_component() {
  1271. global $bp;
  1272. if ( BP_FRIENDS_SLUG == $bp->current_component )
  1273. return true;
  1274. return false;
  1275. }
  1276. function bp_is_groups_component() {
  1277. global $bp;
  1278. if ( BP_GROUPS_SLUG == $bp->current_component )
  1279. return true;
  1280. return false;
  1281. }
  1282. function bp_is_settings_component() {
  1283. global $bp;
  1284. if ( BP_SETTINGS_SLUG == $bp->current_component )
  1285. return true;
  1286. return false;
  1287. }
  1288. function bp_is_member() {
  1289. global $bp;
  1290. if ( $bp->displayed_user->id )
  1291. return true;
  1292. return false;
  1293. }
  1294. function bp_is_user_activity() {
  1295. global $bp;
  1296. if ( BP_ACTIVITY_SLUG == $bp->current_component )
  1297. return true;
  1298. return false;
  1299. }
  1300. function bp_is_user_friends_activity() {
  1301. global $bp;
  1302. if ( BP_ACTIVITY_SLUG == $bp->current_component && 'my-friends' == $bp->current_action )
  1303. return true;
  1304. return false;
  1305. }
  1306. function bp_is_activity_permalink() {
  1307. global $bp;
  1308. if ( BP_ACTIVITY_SLUG == $bp->current_component && is_numeric( $bp->current_action ) )
  1309. return true;
  1310. return false;
  1311. }

Large files files are truncated, but you can click here to view the full file