[ Index ] |
PHP Cross Reference of BuddyPress |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Common functions 4 * 5 * @since 3.0.0 6 * @version 3.1.0 7 */ 8 9 // Exit if accessed directly. 10 defined( 'ABSPATH' ) || exit; 11 12 /** 13 * This function looks scarier than it actually is. :) 14 * Each object loop (activity/members/groups/blogs/forums) contains default 15 * parameters to show specific information based on the page we are currently 16 * looking at. 17 * 18 * The following function will take into account any cookies set in the JS and 19 * allow us to override the parameters sent. That way we can change the results 20 * returned without reloading the page. 21 * 22 * By using cookies we can also make sure that user settings are retained 23 * across page loads. 24 * 25 * @since 3.0.0 26 * 27 * @param string $query_string Query string for the current request. 28 * @param string $object Object for cookie. 29 * 30 * @return string Query string for the component loops 31 */ 32 function bp_nouveau_ajax_querystring( $query_string, $object ) { 33 if ( empty( $object ) ) { 34 return ''; 35 } 36 37 // Default query 38 $post_query = array( 39 'filter' => '', 40 'scope' => 'all', 41 'page' => 1, 42 'search_terms' => '', 43 'extras' => '', 44 ); 45 46 if ( ! empty( $_POST ) ) { 47 $post_query = bp_parse_args( 48 $_POST, 49 $post_query, 50 'nouveau_ajax_querystring' 51 ); 52 53 // Make sure to transport the scope, filter etc.. in HeartBeat Requests 54 if ( ! empty( $post_query['data']['bp_heartbeat'] ) ) { 55 $bp_heartbeat = $post_query['data']['bp_heartbeat']; 56 57 // Remove heartbeat specific vars 58 $post_query = array_diff_key( 59 bp_parse_args( 60 $bp_heartbeat, 61 $post_query, 62 'nouveau_ajax_querystring_heartbeat' 63 ), 64 array( 65 'data' => false, 66 'interval' => false, 67 '_nonce' => false, 68 'action' => false, 69 'screen_id' => false, 70 'has_focus' => false, 71 ) 72 ); 73 } 74 } 75 76 // Init the query string 77 $qs = array(); 78 79 // Activity stream filtering on action. 80 if ( ! empty( $post_query['filter'] ) && '-1' !== $post_query['filter'] ) { 81 if ( 'notifications' === $object ) { 82 $qs[] = 'component_action=' . $post_query['filter']; 83 } else { 84 $qs[] = 'type=' . $post_query['filter']; 85 $qs[] = 'action=' . $post_query['filter']; 86 } 87 } 88 89 // Sort the notifications if needed 90 if ( ! empty( $post_query['extras'] ) && 'notifications' === $object ) { 91 $qs[] = 'sort_order=' . $post_query['extras']; 92 } 93 94 if ( 'personal' === $post_query['scope'] ) { 95 $user_id = ( bp_displayed_user_id() ) ? bp_displayed_user_id() : bp_loggedin_user_id(); 96 $qs[] = 'user_id=' . $user_id; 97 } 98 99 // Activity stream scope only on activity directory. 100 if ( 'all' !== $post_query['scope'] && ! bp_displayed_user_id() && ! bp_is_single_item() ) { 101 $qs[] = 'scope=' . $post_query['scope']; 102 } 103 104 // If page have been passed via the AJAX post request, use those. 105 if ( '-1' != $post_query['page'] ) { 106 $qs[] = 'page=' . absint( $post_query['page'] ); 107 } 108 109 // Excludes activity just posted and avoids duplicate ids. 110 if ( ! empty( $post_query['exclude_just_posted'] ) ) { 111 $just_posted = wp_parse_id_list( $post_query['exclude_just_posted'] ); 112 $qs[] = 'exclude=' . implode( ',', $just_posted ); 113 } 114 115 // To get newest activities. 116 if ( ! empty( $post_query['offset'] ) ) { 117 $qs[] = 'offset=' . intval( $post_query['offset'] ); 118 } 119 120 $object_search_text = bp_get_search_default_text( $object ); 121 if ( ! empty( $post_query['search_terms'] ) && $object_search_text != $post_query['search_terms'] && 'false' != $post_query['search_terms'] && 'undefined' != $post_query['search_terms'] ) { 122 $qs[] = 'search_terms=' . urlencode( $_POST['search_terms'] ); 123 } 124 125 // Specific to messages 126 if ( 'messages' === $object ) { 127 if ( ! empty( $post_query['box'] ) ) { 128 $qs[] = 'box=' . $post_query['box']; 129 } 130 } 131 132 // Single activity. 133 if ( bp_is_single_activity() ) { 134 $qs = array( 135 'display_comments=threaded', 136 'show_hidden=true', 137 'include=' . bp_current_action(), 138 ); 139 } 140 141 // Now pass the querystring to override default values. 142 $query_string = empty( $qs ) ? '' : join( '&', (array) $qs ); 143 144 // List the variables for the filter 145 list( $filter, $scope, $page, $search_terms, $extras ) = array_values( $post_query ); 146 147 /** 148 * Filters the AJAX query string for the component loops. 149 * 150 * @since 3.0.0 151 * 152 * @param string $query_string The query string we are working with. 153 * @param string $object The type of page we are on. 154 * @param string $filter The current object filter. 155 * @param string $scope The current object scope. 156 * @param string $page The current object page. 157 * @param string $search_terms The current object search terms. 158 * @param string $extras The current object extras. 159 */ 160 return apply_filters( 'bp_nouveau_ajax_querystring', $query_string, $object, $filter, $scope, $page, $search_terms, $extras ); 161 } 162 163 /** 164 * @since 3.0.0 165 * 166 * @return string 167 */ 168 function bp_nouveau_ajax_button( $output = '', $button = null, $before = '', $after = '', $r = array() ) { 169 if ( empty( $button->component ) ) { 170 return $output; 171 } 172 173 // Custom data attribute. 174 $r['button_attr']['data-bp-btn-action'] = $button->id; 175 176 $reset_ids = array( 177 'member_friendship' => true, 178 'group_membership' => true, 179 ); 180 181 if ( ! empty( $reset_ids[ $button->id ] ) ) { 182 $parse_class = array_map( 'sanitize_html_class', explode( ' ', $r['button_attr']['class'] ) ); 183 if ( false === $parse_class ) { 184 return $output; 185 } 186 187 $find_id = array_intersect( $parse_class, array( 188 'pending_friend', 189 'is_friend', 190 'not_friends', 191 'leave-group', 192 'join-group', 193 'accept-invite', 194 'membership-requested', 195 'request-membership', 196 ) ); 197 198 if ( 1 !== count( $find_id ) ) { 199 return $output; 200 } 201 202 $data_attribute = reset( $find_id ); 203 if ( 'pending_friend' === $data_attribute ) { 204 $data_attribute = str_replace( '_friend', '', $data_attribute ); 205 } elseif ( 'group_membership' === $button->id ) { 206 $data_attribute = str_replace( '-', '_', $data_attribute ); 207 } 208 209 $r['button_attr']['data-bp-btn-action'] = $data_attribute; 210 } 211 212 // Re-render the button with our custom data attribute. 213 $output = new BP_Core_HTML_Element( array( 214 'element' => $r['button_element'], 215 'attr' => $r['button_attr'], 216 'inner_html' => ! empty( $r['link_text'] ) ? $r['link_text'] : '' 217 ) ); 218 $output = $output->contents(); 219 220 // Add span bp-screen-reader-text class 221 return $before . $output . $after; 222 } 223 224 /** 225 * Output HTML content into a wrapper. 226 * 227 * @since 3.0.0 228 * 229 * @param array $args { 230 * Optional arguments. 231 * 232 * @type string $container String HTML container type that should wrap 233 * the items as a group: 'div', 'ul', or 'p'. Required. 234 * @type string $container_id The group wrapping container element ID 235 * @type string $container_classes The group wrapping container elements class 236 * @type string $output The HTML to output. Required. 237 * } 238 */ 239 function bp_nouveau_wrapper( $args = array() ) { 240 /** 241 * Classes need to be determined & set by component to a certain degree 242 * 243 * Check the component to find a default container_class to add 244 */ 245 $current_component_class = bp_current_component() . '-meta'; 246 247 if ( bp_is_group_activity() ) { 248 $generic_class = ' activity-meta '; 249 } else { 250 $generic_class = ''; 251 } 252 253 $r = bp_parse_args( 254 $args, 255 array( 256 'container' => 'div', 257 'container_id' => '', 258 'container_classes' => array( $generic_class, $current_component_class ), 259 'output' => '', 260 ), 261 'nouveau_wrapper' 262 ); 263 264 $valid_containers = array( 265 'div' => true, 266 'ul' => true, 267 'ol' => true, 268 'span' => true, 269 'p' => true, 270 ); 271 272 // Actually merge some classes defaults and $args 273 // @todo This is temp, we need certain classes but maybe improve this approach. 274 $default_classes = array( 'action' ); 275 $r['container_classes'] = array_merge( $r['container_classes'], $default_classes ); 276 277 if ( empty( $r['container'] ) || ! isset( $valid_containers[ $r['container'] ] ) || empty( $r['output'] ) ) { 278 return; 279 } 280 281 $container = $r['container']; 282 $container_id = ''; 283 $container_classes = ''; 284 $output = $r['output']; 285 286 if ( ! empty( $r['container_id'] ) ) { 287 $container_id = ' id="' . esc_attr( $r['container_id'] ) . '"'; 288 } 289 290 if ( ! empty( $r['container_classes'] ) && is_array( $r['container_classes'] ) ) { 291 $container_classes = ' class="' . join( ' ', array_map( 'sanitize_html_class', $r['container_classes'] ) ) . '"'; 292 } 293 294 // Print the wrapper and its content. 295 printf( '<%1$s%2$s%3$s>%4$s</%1$s>', $container, $container_id, $container_classes, $output ); 296 } 297 298 /** 299 * Register the 2 sidebars for the Group & User default front page 300 * 301 * @since 3.0.0 302 */ 303 function bp_nouveau_register_sidebars() { 304 $default_fronts = bp_nouveau_get_appearance_settings(); 305 $default_user_front = 0; 306 $default_group_front = 0; 307 $is_active_groups = bp_is_active( 'groups' ); 308 309 if ( isset( $default_fronts['user_front_page'] ) ) { 310 $default_user_front = $default_fronts['user_front_page']; 311 } 312 313 if ( $is_active_groups ) { 314 if ( isset( $default_fronts['group_front_page'] ) ) { 315 $default_group_front = $default_fronts['group_front_page']; 316 } 317 } 318 319 // Setting the front template happens too early, so we need this! 320 if ( is_customize_preview() ) { 321 $default_user_front = bp_nouveau_get_temporary_setting( 'user_front_page', $default_user_front ); 322 323 if ( $is_active_groups ) { 324 $default_group_front = bp_nouveau_get_temporary_setting( 'group_front_page', $default_group_front ); 325 } 326 } 327 328 $sidebars = array(); 329 if ( $default_user_front ) { 330 $sidebars[] = array( 331 'name' => __( 'BuddyPress Member\'s Home', 'buddypress' ), 332 'id' => 'sidebar-buddypress-members', 333 'description' => __( 'Add widgets here to appear in the front page of each member of your community.', 'buddypress' ), 334 'before_widget' => '<div id="%1$s" class="widget %2$s">', 335 'after_widget' => '</div>', 336 'before_title' => '<h2 class="widget-title">', 337 'after_title' => '</h2>', 338 ); 339 } 340 341 if ( $default_group_front ) { 342 $sidebars[] = array( 343 'name' => __( 'BuddyPress Group\'s Home', 'buddypress' ), 344 'id' => 'sidebar-buddypress-groups', 345 'description' => __( 'Add widgets here to appear in the front page of each group of your community.', 'buddypress' ), 346 'before_widget' => '<div id="%1$s" class="widget %2$s">', 347 'after_widget' => '</div>', 348 'before_title' => '<h2 class="widget-title">', 349 'after_title' => '</h2>', 350 ); 351 } 352 353 if ( empty( $sidebars ) ) { 354 return; 355 } 356 357 // Register the sidebars if needed. 358 foreach ( $sidebars as $sidebar ) { 359 register_sidebar( $sidebar ); 360 } 361 } 362 363 /** 364 * @since 3.0.0 365 * 366 * @return bool 367 */ 368 function bp_nouveau_is_object_nav_in_sidebar() { 369 return is_active_widget( false, false, 'bp_nouveau_sidebar_object_nav_widget', true ); 370 } 371 372 /** 373 * @since 3.0.0 374 * 375 * @return bool 376 */ 377 function bp_nouveau_current_user_can( $capability = '' ) { 378 /** 379 * Filters whether or not the current user can perform an action for BuddyPress Nouveau. 380 * 381 * @since 3.0.0 382 * 383 * @param bool $value Whether or not the user is logged in. 384 * @param string $capability Current capability being checked. 385 * @param int $value Current logged in user ID. 386 */ 387 return apply_filters( 'bp_nouveau_current_user_can', is_user_logged_in(), $capability, bp_loggedin_user_id() ); 388 } 389 390 /** 391 * Parse an html output to a list of component's directory nav item. 392 * 393 * @since 3.0.0 394 * 395 * @param string $hook The hook to fire. 396 * @param string $component The component nav belongs to. 397 * @param int $position The position of the nav item. 398 * 399 * @return array A list of component's dir nav items 400 */ 401 function bp_nouveau_parse_hooked_dir_nav( $hook = '', $component = '', $position = 99 ) { 402 $extra_nav_items = array(); 403 404 if ( empty( $hook ) || empty( $component ) || ! has_action( $hook ) ) { 405 return $extra_nav_items; 406 } 407 408 // Get the hook output. 409 ob_start(); 410 411 /** 412 * Fires at the start of the output for `bp_nouveau_parse_hooked_dir_nav()`. 413 * 414 * This hook is variable and depends on the hook parameter passed in. 415 * 416 * @since 3.0.0 417 */ 418 do_action( $hook ); 419 $output = ob_get_clean(); 420 421 if ( empty( $output ) ) { 422 return $extra_nav_items; 423 } 424 425 preg_match_all( "/<li\sid=\"{$component}\-(.*)\"[^>]*>/siU", $output, $lis ); 426 if ( empty( $lis[1] ) ) { 427 return $extra_nav_items; 428 } 429 430 $extra_nav_items = array_fill_keys( $lis[1], array( 'component' => $component, 'position' => $position ) ); 431 preg_match_all( '/<a\s[^>]*>(.*)<\/a>/siU', $output, $as ); 432 433 if ( ! empty( $as[0] ) ) { 434 foreach ( $as[0] as $ka => $a ) { 435 $extra_nav_items[ $lis[1][ $ka ] ]['slug'] = $lis[1][ $ka ]; 436 $extra_nav_items[ $lis[1][ $ka ] ]['text'] = $as[1][ $ka ]; 437 preg_match_all( '/([\w\-]+)=([^"\'> ]+|([\'"]?)(?:[^\3]|\3+)+?\3)/', $a, $attrs ); 438 439 if ( ! empty( $attrs[1] ) ) { 440 foreach ( $attrs[1] as $katt => $att ) { 441 if ( 'href' === $att ) { 442 $extra_nav_items[ $lis[1][ $ka ] ]['link'] = trim( $attrs[2][ $katt ], '"' ); 443 } else { 444 $extra_nav_items[ $lis[1][ $ka ] ][ $att ] = trim( $attrs[2][ $katt ], '"' ); 445 } 446 } 447 } 448 } 449 } 450 451 if ( ! empty( $as[1] ) ) { 452 foreach ( $as[1] as $ks => $s ) { 453 preg_match_all( '/<span>(.*)<\/span>/siU', $s, $spans ); 454 455 if ( empty( $spans[0] ) ) { 456 $extra_nav_items[ $lis[1][ $ks ] ]['count'] = false; 457 } elseif ( ! empty( $spans[1][0] ) ) { 458 $extra_nav_items[ $lis[1][ $ks ] ]['count'] = (int) $spans[1][0]; 459 } else { 460 $extra_nav_items[ $lis[1][ $ks ] ]['count'] = ''; 461 } 462 } 463 } 464 465 return $extra_nav_items; 466 } 467 468 /** 469 * Run specific "select filter" hooks to catch the options and build an array out of them 470 * 471 * @since 3.0.0 472 * 473 * @param string $hook 474 * @param array $filters 475 * 476 * @return array 477 */ 478 function bp_nouveau_parse_hooked_options( $hook = '', $filters = array() ) { 479 if ( empty( $hook ) ) { 480 return $filters; 481 } 482 483 ob_start(); 484 485 /** 486 * Fires at the start of the output for `bp_nouveau_parse_hooked_options()`. 487 * 488 * This hook is variable and depends on the hook parameter passed in. 489 * 490 * @since 3.0.0 491 */ 492 do_action( $hook ); 493 494 $output = ob_get_clean(); 495 496 preg_match_all( '/<option value="(.*?)"\s*>(.*?)<\/option>/', $output, $matches ); 497 498 if ( ! empty( $matches[1] ) && ! empty( $matches[2] ) ) { 499 foreach ( $matches[1] as $ik => $key_action ) { 500 if ( ! empty( $matches[2][ $ik ] ) && ! isset( $filters[ $key_action ] ) ) { 501 $filters[ $key_action ] = $matches[2][ $ik ]; 502 } 503 } 504 } 505 506 return $filters; 507 } 508 509 /** 510 * Get Dropdawn filters for the current component of the one passed in params 511 * 512 * @since 3.0.0 513 * 514 * @param string $context 'directory', 'user' or 'group' 515 * @param string $component The BuddyPress component ID 516 * 517 * @return array the dropdown filters 518 */ 519 function bp_nouveau_get_component_filters( $context = '', $component = '' ) { 520 $filters = array(); 521 522 if ( empty( $context ) ) { 523 if ( bp_is_user() ) { 524 $context = 'user'; 525 } elseif ( bp_is_group() ) { 526 $context = 'group'; 527 528 // Defaults to directory 529 } else { 530 $context = 'directory'; 531 } 532 } 533 534 if ( empty( $component ) ) { 535 if ( 'directory' === $context || 'user' === $context ) { 536 $component = bp_current_component(); 537 538 if ( 'friends' === $component ) { 539 $context = 'friends'; 540 $component = 'members'; 541 } 542 } elseif ( 'group' === $context && bp_is_group_activity() ) { 543 $component = 'activity'; 544 } elseif ( 'group' === $context && bp_is_group_members() ) { 545 $component = 'members'; 546 } 547 } 548 549 if ( ! bp_is_active( $component ) ) { 550 return $filters; 551 } 552 553 if ( 'members' === $component ) { 554 $filters = bp_nouveau_get_members_filters( $context ); 555 } elseif ( 'activity' === $component ) { 556 $filters = bp_nouveau_get_activity_filters(); 557 558 // Specific case for the activity dropdown 559 $filters = array_merge( array( '-1' => __( '— Everything —', 'buddypress' ) ), $filters ); 560 } elseif ( 'groups' === $component ) { 561 $filters = bp_nouveau_get_groups_filters( $context ); 562 } elseif ( 'blogs' === $component ) { 563 $filters = bp_nouveau_get_blogs_filters( $context ); 564 } 565 566 return $filters; 567 } 568 569 /** 570 * When previewing make sure to get the temporary setting of the customizer. 571 * This is necessary when we need to get these very early. 572 * 573 * @since 3.0.0 574 * 575 * @param string $option the index of the setting to get. 576 * @param mixed $retval the value to use as default. 577 * 578 * @return mixed The value for the requested option. 579 */ 580 function bp_nouveau_get_temporary_setting( $option = '', $retval = false ) { 581 if ( empty( $option ) || ! isset( $_POST['customized'] ) ) { 582 return $retval; 583 } 584 585 $temporary_setting = wp_unslash( $_POST['customized'] ); 586 if ( ! is_array( $temporary_setting ) ) { 587 $temporary_setting = json_decode( $temporary_setting, true ); 588 } 589 590 // This is used to transport the customizer settings into Ajax requests. 591 if ( 'any' === $option ) { 592 $retval = array(); 593 594 foreach ( $temporary_setting as $key => $setting ) { 595 if ( 0 !== strpos( $key, 'bp_nouveau_appearance' ) ) { 596 continue; 597 } 598 599 $k = str_replace( array( '[', ']' ), array( '_', '' ), $key ); 600 $retval[ $k ] = $setting; 601 } 602 603 // Used when it's an early regular request 604 } elseif ( isset( $temporary_setting[ 'bp_nouveau_appearance[' . $option . ']' ] ) ) { 605 $retval = $temporary_setting[ 'bp_nouveau_appearance[' . $option . ']' ]; 606 607 // Used when it's an ajax request 608 } elseif ( isset( $_POST['customized'][ 'bp_nouveau_appearance_' . $option ] ) ) { 609 $retval = $_POST['customized'][ 'bp_nouveau_appearance_' . $option ]; 610 } 611 612 return $retval; 613 } 614 615 /** 616 * Get the BP Nouveau Appearance settings. 617 * 618 * @since 3.0.0 619 * 620 * @param string $option Leave empty to get all settings, specify a value for a specific one. 621 * @param mixed An array of settings, the value of the requested setting. 622 * 623 * @return array|false|mixed 624 */ 625 function bp_nouveau_get_appearance_settings( $option = '' ) { 626 $default_args = array( 627 'avatar_style' => 0, 628 'global_alignment' => 'alignwide', 629 'user_front_page' => 1, 630 'user_front_bio' => 0, 631 'user_nav_display' => 0, // O is default (horizontally). 1 is vertically. 632 'user_nav_tabs' => 0, 633 'user_subnav_tabs' => 0, 634 'user_nav_order' => array(), 635 'members_layout' => 1, 636 'members_dir_tabs' => 0, 637 'members_dir_layout' => 0, 638 ); 639 640 if ( bp_is_active( 'friends' ) ) { 641 $default_args['members_friends_layout'] = 1; 642 } 643 644 if ( bp_is_active( 'activity' ) ) { 645 $default_args['activity_dir_layout'] = 0; 646 $default_args['activity_dir_tabs'] = 0; // default = no tabs 647 } 648 649 if ( bp_is_active( 'groups' ) ) { 650 $default_args = array_merge( $default_args, array( 651 'group_front_page' => 1, 652 'group_front_boxes' => 1, 653 'group_front_description' => 0, 654 'group_nav_display' => 0, // O is default (horizontally). 1 is vertically. 655 'group_nav_order' => array(), 656 'group_nav_tabs' => 0, 657 'group_subnav_tabs' => 0, 658 'groups_create_tabs' => 1, 659 'groups_layout' => 1, 660 'members_group_layout' => 1, 661 'groups_dir_layout' => 0, 662 'groups_dir_tabs' => 0, 663 ) ); 664 } 665 666 if ( is_multisite() && bp_is_active( 'blogs' ) ) { 667 $default_args = array_merge( $default_args, array( 668 'sites_dir_layout' => 0, 669 'sites_dir_tabs' => 0, 670 ) ); 671 } 672 673 $settings = bp_parse_args( 674 bp_get_option( 'bp_nouveau_appearance', array() ), 675 $default_args, 676 'nouveau_appearance_settings' 677 ); 678 679 if ( ! empty( $option ) ) { 680 if ( isset( $settings[ $option ] ) ) { 681 return $settings[ $option ]; 682 } else { 683 return false; 684 } 685 } 686 687 return $settings; 688 } 689 690 /** 691 * Returns the choices for the Layout option of the customizer 692 * or the list of corresponding css classes. 693 * 694 * @since 3.0.0 695 * 696 * @param string $type 'option' to get the labels, 'classes' to get the classes 697 * 698 * @return array The list of labels or classes preserving keys. 699 */ 700 function bp_nouveau_customizer_grid_choices( $type = 'option' ) { 701 $columns = array( 702 array( 'key' => '1', 'label' => __( 'One column', 'buddypress' ), 'class' => '' ), 703 array( 'key' => '2', 'label' => __( 'Two columns', 'buddypress' ), 'class' => 'two' ), 704 array( 'key' => '3', 'label' => __( 'Three columns', 'buddypress' ), 'class' => 'three' ), 705 array( 'key' => '4', 'label' => __( 'Four columns', 'buddypress' ), 'class' => 'four' ), 706 ); 707 708 if ( 'option' === $type ) { 709 return wp_list_pluck( $columns, 'label', 'key' ); 710 } 711 712 return wp_list_pluck( $columns, 'class', 'key' ); 713 } 714 715 /** 716 * Sanitize a list of slugs to save it as an array 717 * 718 * @since 3.0.0 719 * 720 * @param string $option A comma separated list of nav items slugs. 721 * 722 * @return array An array of nav items slugs. 723 */ 724 function bp_nouveau_sanitize_nav_order( $option = '' ) { 725 $option = explode( ',', $option ); 726 return array_map( 'sanitize_key', $option ); 727 } 728 729 /** 730 * BP Nouveau's callback for the cover image feature. 731 * 732 * @since 3.0.0 733 * 734 * @param array $params Optional. The current component's feature parameters. 735 * 736 * @return string 737 */ 738 function bp_nouveau_theme_cover_image( $params = array() ) { 739 if ( empty( $params ) ) { 740 return ''; 741 } 742 743 // Avatar height - padding - 1/2 avatar height. 744 $avatar_offset = $params['height'] - 5 - round( (int) bp_core_avatar_full_height() / 2 ); 745 746 // Header content offset + spacing. 747 $top_offset = bp_core_avatar_full_height() - 10; 748 $left_offset = bp_core_avatar_full_width() + 20; 749 750 $cover_image = isset( $params['cover_image'] ) ? 'background-image: url( ' . $params['cover_image'] . ' );' : ''; 751 $hide_avatar_style = ''; 752 753 // Adjust the cover image header, in case avatars are completely disabled. 754 if ( ! buddypress()->avatar->show_avatars ) { 755 $hide_avatar_style = ' 756 #buddypress #item-header-cover-image #item-header-avatar { 757 display: none; 758 } 759 '; 760 761 if ( bp_is_user() ) { 762 $hide_avatar_style = ' 763 #buddypress #item-header-cover-image #item-header-avatar a { 764 display: block; 765 height: ' . $top_offset . 'px; 766 margin: 0 15px 19px 0; 767 } 768 769 #buddypress div#item-header #item-header-cover-image #item-header-content { 770 margin-left:auto; 771 } 772 '; 773 } 774 } 775 776 return ' 777 /* Cover image */ 778 #buddypress #item-header-cover-image { 779 min-height: ' . $params['height'] . 'px; 780 margin-bottom: 1em; 781 } 782 783 #buddypress #item-header-cover-image:after { 784 clear: both; 785 content: ""; 786 display: table; 787 } 788 789 #buddypress #header-cover-image { 790 height: ' . $params['height'] . 'px; 791 ' . $cover_image . ' 792 } 793 794 #buddypress #create-group-form #header-cover-image { 795 position: relative; 796 margin: 1em 0; 797 } 798 799 .bp-user #buddypress #item-header { 800 padding-top: 0; 801 } 802 803 #buddypress #item-header-cover-image #item-header-avatar { 804 margin-top: ' . $avatar_offset . 'px; 805 float: left; 806 overflow: visible; 807 width:auto; 808 } 809 810 #buddypress div#item-header #item-header-cover-image #item-header-content { 811 clear: both; 812 float: left; 813 margin-left: ' . $left_offset . 'px; 814 margin-top: -' . $top_offset . 'px; 815 width:auto; 816 } 817 818 body.single-item.groups #buddypress div#item-header #item-header-cover-image #item-header-content, 819 body.single-item.groups #buddypress div#item-header #item-header-cover-image #item-actions { 820 margin-top: ' . $params['height'] . 'px; 821 margin-left: 0; 822 clear: none; 823 max-width: 50%; 824 } 825 826 body.single-item.groups #buddypress div#item-header #item-header-cover-image #item-actions { 827 padding-top: 20px; 828 max-width: 20%; 829 } 830 831 ' . $hide_avatar_style . ' 832 833 #buddypress div#item-header-cover-image h2 a, 834 #buddypress div#item-header-cover-image h2 { 835 color: #FFF; 836 text-rendering: optimizelegibility; 837 text-shadow: 0px 0px 3px rgba( 0, 0, 0, 0.8 ); 838 margin: 0 0 .6em; 839 font-size:200%; 840 } 841 842 #buddypress #item-header-cover-image #item-header-avatar img.avatar { 843 border: solid 2px #FFF; 844 background: rgba( 255, 255, 255, 0.8 ); 845 } 846 847 #buddypress #item-header-cover-image #item-header-avatar a { 848 border: none; 849 text-decoration: none; 850 } 851 852 #buddypress #item-header-cover-image #item-buttons { 853 margin: 0 0 10px; 854 padding: 0 0 5px; 855 } 856 857 #buddypress #item-header-cover-image #item-buttons:after { 858 clear: both; 859 content: ""; 860 display: table; 861 } 862 863 @media screen and (max-width: 782px) { 864 #buddypress #item-header-cover-image #item-header-avatar, 865 .bp-user #buddypress #item-header #item-header-cover-image #item-header-avatar, 866 #buddypress div#item-header #item-header-cover-image #item-header-content { 867 width:100%; 868 text-align:center; 869 } 870 871 #buddypress #item-header-cover-image #item-header-avatar a { 872 display:inline-block; 873 } 874 875 #buddypress #item-header-cover-image #item-header-avatar img { 876 margin:0; 877 } 878 879 #buddypress div#item-header #item-header-cover-image #item-header-content, 880 body.single-item.groups #buddypress div#item-header #item-header-cover-image #item-header-content, 881 body.single-item.groups #buddypress div#item-header #item-header-cover-image #item-actions { 882 margin:0; 883 } 884 885 body.single-item.groups #buddypress div#item-header #item-header-cover-image #item-header-content, 886 body.single-item.groups #buddypress div#item-header #item-header-cover-image #item-actions { 887 max-width: 100%; 888 } 889 890 #buddypress div#item-header-cover-image h2 a, 891 #buddypress div#item-header-cover-image h2 { 892 color: inherit; 893 text-shadow: none; 894 margin:25px 0 0; 895 font-size:200%; 896 } 897 898 #buddypress #item-header-cover-image #item-buttons div { 899 float:none; 900 display:inline-block; 901 } 902 903 #buddypress #item-header-cover-image #item-buttons:before { 904 content:""; 905 } 906 907 #buddypress #item-header-cover-image #item-buttons { 908 margin: 5px 0; 909 } 910 } 911 '; 912 } 913 914 /** 915 * All user feedback messages are available here 916 * 917 * @since 3.0.0 918 * 919 * @param string $feedback_id The ID of the message. 920 * 921 * @return string|false The list of parameters for the message 922 */ 923 function bp_nouveau_get_user_feedback( $feedback_id = '' ) { 924 /** 925 * Filters the BuddyPress Nouveau feedback messages. 926 * 927 * Use this filter to add your custom feedback messages. 928 * 929 * @since 3.0.0 930 * 931 * @param array $value The list of feedback messages. 932 */ 933 $feedback_messages = apply_filters( 'bp_nouveau_feedback_messages', array( 934 'registration-disabled' => array( 935 'type' => 'info', 936 'message' => __( 'Member registration is currently not allowed.', 'buddypress' ), 937 'before' => 'bp_before_registration_disabled', 938 'after' => 'bp_after_registration_disabled' 939 ), 940 'request-details' => array( 941 'type' => 'info', 942 'message' => __( 'Registering for this site is easy. Just fill in the fields below, and we\'ll get a new account set up for you in no time.', 'buddypress' ), 943 'before' => false, 944 'after' => false, 945 ), 946 'completed-confirmation' => array( 947 'type' => 'info', 948 'message' => __( 'You have successfully created your account! Please log in using the username and password you have just created.', 'buddypress' ), 949 'before' => 'bp_before_registration_confirmed', 950 'after' => 'bp_after_registration_confirmed', 951 ), 952 'directory-activity-loading' => array( 953 'type' => 'loading', 954 'message' => __( 'Loading the community updates. Please wait.', 'buddypress' ), 955 ), 956 'single-activity-loading' => array( 957 'type' => 'loading', 958 'message' => __( 'Loading the update. Please wait.', 'buddypress' ), 959 ), 960 'activity-loop-none' => array( 961 'type' => 'info', 962 'message' => __( 'Sorry, there was no activity found. Please try a different filter.', 'buddypress' ), 963 ), 964 'blogs-loop-none' => array( 965 'type' => 'info', 966 'message' => __( 'Sorry, there were no sites found.', 'buddypress' ), 967 ), 968 'blogs-no-signup' => array( 969 'type' => 'info', 970 'message' => __( 'Site registration is currently disabled.', 'buddypress' ), 971 ), 972 'directory-blogs-loading' => array( 973 'type' => 'loading', 974 'message' => __( 'Loading the sites of the network. Please wait.', 'buddypress' ), 975 ), 976 'directory-groups-loading' => array( 977 'type' => 'loading', 978 'message' => __( 'Loading the groups of the community. Please wait.', 'buddypress' ), 979 ), 980 'groups-loop-none' => array( 981 'type' => 'info', 982 'message' => __( 'Sorry, there were no groups found.', 'buddypress' ), 983 ), 984 'group-activity-loading' => array( 985 'type' => 'loading', 986 'message' => __( 'Loading the group updates. Please wait.', 'buddypress' ), 987 ), 988 'group-members-loading' => array( 989 'type' => 'loading', 990 'message' => __( 'Requesting the group members. Please wait.', 'buddypress' ), 991 ), 992 'group-members-none' => array( 993 'type' => 'info', 994 'message' => __( 'Sorry, there were no group members found.', 'buddypress' ), 995 ), 996 'group-members-search-none' => array( 997 'type' => 'info', 998 'message' => __( 'Sorry, there was no member of that name found in this group.', 'buddypress' ), 999 ), 1000 'group-manage-members-none' => array( 1001 'type' => 'info', 1002 'message' => __( 'This group has no members.', 'buddypress' ), 1003 ), 1004 'group-requests-none' => array( 1005 'type' => 'info', 1006 'message' => __( 'There are no pending membership requests.', 'buddypress' ), 1007 ), 1008 'group-requests-loading' => array( 1009 'type' => 'loading', 1010 'message' => __( 'Loading the members who requested to join the group. Please wait.', 'buddypress' ), 1011 ), 1012 'group-delete-warning' => array( 1013 'type' => 'warning', 1014 'message' => __( 'WARNING: Deleting this group will completely remove ALL content associated with it. There is no way back. Please be careful with this option.', 'buddypress' ), 1015 ), 1016 'group-avatar-delete-info' => array( 1017 'type' => 'info', 1018 'message' => __( 'If you\'d like to remove the existing group profile photo but not upload a new one, please use the delete group profile photo button.', 'buddypress' ), 1019 ), 1020 'directory-members-loading' => array( 1021 'type' => 'loading', 1022 'message' => __( 'Loading the members of your community. Please wait.', 'buddypress' ), 1023 ), 1024 'members-loop-none' => array( 1025 'type' => 'info', 1026 'message' => __( 'Sorry, no members were found.', 'buddypress' ), 1027 ), 1028 'member-requests-none' => array( 1029 'type' => 'info', 1030 'message' => __( 'You have no pending friendship requests.', 'buddypress' ), 1031 ), 1032 'member-invites-none' => array( 1033 'type' => 'info', 1034 'message' => __( 'You have no outstanding group invites.', 'buddypress' ), 1035 ), 1036 'member-notifications-none' => array( 1037 'type' => 'info', 1038 'message' => __( 'This member has no notifications.', 'buddypress' ), 1039 ), 1040 'member-wp-profile-none' => array( 1041 'type' => 'info', 1042 /* translators: %s: member name */ 1043 'message' => __( '%s did not save any profile information yet.', 'buddypress' ), 1044 ), 1045 'member-delete-account' => array( 1046 'type' => 'warning', 1047 'message' => __( 'Deleting this account will delete all of the content it has created. It will be completely unrecoverable.', 'buddypress' ), 1048 ), 1049 'member-activity-loading' => array( 1050 'type' => 'loading', 1051 'message' => __( 'Loading the member\'s updates. Please wait.', 'buddypress' ), 1052 ), 1053 'member-blogs-loading' => array( 1054 'type' => 'loading', 1055 'message' => __( 'Loading the member\'s blogs. Please wait.', 'buddypress' ), 1056 ), 1057 'member-friends-loading' => array( 1058 'type' => 'loading', 1059 'message' => __( 'Loading the member\'s friends. Please wait.', 'buddypress' ), 1060 ), 1061 'member-groups-loading' => array( 1062 'type' => 'loading', 1063 'message' => __( 'Loading the member\'s groups. Please wait.', 'buddypress' ), 1064 ), 1065 'member-notifications-loading' => array( 1066 'type' => 'loading', 1067 'message' => __( 'Loading notifications. Please wait.', 'buddypress' ), 1068 ), 1069 'member-group-invites-all' => array( 1070 'type' => 'info', 1071 'message' => __( 'Currently every member of the community can invite you to join their groups. If you are not comfortable with it, you can always restrict group invites to your friends only.', 'buddypress' ), 1072 ), 1073 'member-group-invites-friends-only' => array( 1074 'type' => 'info', 1075 'message' => __( 'Currently only your friends can invite you to groups. Uncheck the box to allow any member to send invites.', 'buddypress' ), 1076 ), 1077 ) ); 1078 1079 if ( ! isset( $feedback_messages[ $feedback_id ] ) ) { 1080 return false; 1081 } 1082 1083 /* 1084 * Adjust some messages to the context. 1085 */ 1086 if ( 'completed-confirmation' === $feedback_id && bp_registration_needs_activation() ) { 1087 $feedback_messages['completed-confirmation']['message'] = __( 'You have successfully created your account! To begin using this site you will need to activate your account via the email we have just sent to your address.', 'buddypress' ); 1088 } elseif ( 'member-notifications-none' === $feedback_id ) { 1089 $is_myprofile = bp_is_my_profile(); 1090 1091 if ( bp_is_current_action( 'unread' ) ) { 1092 $feedback_messages['member-notifications-none']['message'] = __( 'This member has no unread notifications.', 'buddypress' ); 1093 1094 if ( $is_myprofile ) { 1095 $feedback_messages['member-notifications-none']['message'] = __( 'You have no unread notifications.', 'buddypress' ); 1096 } 1097 } elseif ( $is_myprofile ) { 1098 $feedback_messages['member-notifications-none']['message'] = __( 'You have no notifications.', 'buddypress' ); 1099 } 1100 } elseif ( 'member-wp-profile-none' === $feedback_id && bp_is_user_profile() ) { 1101 $feedback_messages['member-wp-profile-none']['message'] = sprintf( $feedback_messages['member-wp-profile-none']['message'], bp_get_displayed_user_fullname() ); 1102 } elseif ( 'member-delete-account' === $feedback_id && bp_is_my_profile() ) { 1103 $feedback_messages['member-delete-account']['message'] = __( 'Deleting your account will delete all of the content you have created. It will be completely irrecoverable.', 'buddypress' ); 1104 } elseif ( 'member-activity-loading' === $feedback_id && bp_is_my_profile() ) { 1105 $feedback_messages['member-activity-loading']['message'] = __( 'Loading your updates. Please wait.', 'buddypress' ); 1106 } elseif ( 'member-blogs-loading' === $feedback_id && bp_is_my_profile() ) { 1107 $feedback_messages['member-blogs-loading']['message'] = __( 'Loading your blogs. Please wait.', 'buddypress' ); 1108 } elseif ( 'member-friends-loading' === $feedback_id && bp_is_my_profile() ) { 1109 $feedback_messages['member-friends-loading']['message'] = __( 'Loading your friends. Please wait.', 'buddypress' ); 1110 } elseif ( 'member-groups-loading' === $feedback_id && bp_is_my_profile() ) { 1111 $feedback_messages['member-groups-loading']['message'] = __( 'Loading your groups. Please wait.', 'buddypress' ); 1112 } 1113 1114 /** 1115 * Filter here if you wish to edit the message just before being displayed 1116 * 1117 * @since 3.0.0 1118 * 1119 * @param array $feedback_messages 1120 */ 1121 return apply_filters( 'bp_nouveau_get_user_feedback', $feedback_messages[ $feedback_id ] ); 1122 } 1123 1124 /** 1125 * Get the signup fields for the requested section 1126 * 1127 * @since 3.0.0 1128 * 1129 * @param string $section Optional. The section of fields to get 'account_details' or 'blog_details'. 1130 * 1131 * @return array|false The list of signup fields for the requested section. False if not found. 1132 */ 1133 function bp_nouveau_get_signup_fields( $section = '' ) { 1134 if ( empty( $section ) ) { 1135 return false; 1136 } 1137 1138 /** 1139 * Filter to add your specific 'text' or 'password' inputs 1140 * 1141 * If you need to use other types of field, please use the 1142 * do_action( 'bp_account_details_fields' ) or do_action( 'blog_details' ) hooks instead. 1143 * 1144 * @since 3.0.0 1145 * 1146 * @param array $value The list of fields organized into sections. 1147 */ 1148 $fields = apply_filters( 'bp_nouveau_get_signup_fields', array( 1149 'account_details' => array( 1150 'signup_username' => array( 1151 'label' => __( 'Username', 'buddypress' ), 1152 'required' => true, 1153 'value' => 'bp_get_signup_username_value', 1154 'attribute_type' => 'username', 1155 'type' => 'text', 1156 'class' => '', 1157 ), 1158 'signup_email' => array( 1159 'label' => __( 'Email Address', 'buddypress' ), 1160 'required' => true, 1161 'value' => 'bp_get_signup_email_value', 1162 'attribute_type' => 'email', 1163 'type' => 'email', 1164 'class' => '', 1165 ), 1166 'signup_password' => array(), 1167 'signup_password_confirm' => array(), 1168 ), 1169 'blog_details' => array( 1170 'signup_blog_url' => array( 1171 'label' => __( 'Site URL', 'buddypress' ), 1172 'required' => true, 1173 'value' => 'bp_get_signup_blog_url_value', 1174 'attribute_type' => 'slug', 1175 'type' => 'text', 1176 'class' => '', 1177 ), 1178 'signup_blog_title' => array( 1179 'label' => __( 'Site Title', 'buddypress' ), 1180 'required' => true, 1181 'value' => 'bp_get_signup_blog_title_value', 1182 'attribute_type' => 'title', 1183 'type' => 'text', 1184 'class' => '', 1185 ), 1186 'signup_blog_privacy_public' => array( 1187 'label' => __( 'Yes', 'buddypress' ), 1188 'required' => false, 1189 'value' => 'public', 1190 'attribute_type' => '', 1191 'type' => 'radio', 1192 'class' => '', 1193 ), 1194 'signup_blog_privacy_private' => array( 1195 'label' => __( 'No', 'buddypress' ), 1196 'required' => false, 1197 'value' => 'private', 1198 'attribute_type' => '', 1199 'type' => 'radio', 1200 'class' => '', 1201 ), 1202 ), 1203 ) ); 1204 1205 if ( ! bp_get_blog_signup_allowed() ) { 1206 unset( $fields['blog_details'] ); 1207 } 1208 1209 if ( isset( $fields[ $section ] ) ) { 1210 return $fields[ $section ]; 1211 } 1212 1213 return false; 1214 } 1215 1216 /** 1217 * Get Some submit buttons data. 1218 * 1219 * @since 3.0.0 1220 * 1221 * @param string $action The action requested. 1222 * 1223 * @return array|false The list of the submit button parameters for the requested action 1224 * False if no actions were found. 1225 */ 1226 function bp_nouveau_get_submit_button( $action = '' ) { 1227 if ( empty( $action ) ) { 1228 return false; 1229 } 1230 1231 /** 1232 * Filter the Submit buttons to add your own. 1233 * 1234 * @since 3.0.0 1235 * 1236 * @param array $value The list of submit buttons. 1237 * 1238 * @return array|false 1239 */ 1240 $actions = apply_filters( 'bp_nouveau_get_submit_button', array( 1241 'register' => array( 1242 'before' => 'bp_before_registration_submit_buttons', 1243 'after' => 'bp_after_registration_submit_buttons', 1244 'nonce' => 'bp_new_signup', 1245 'attributes' => array( 1246 'name' => 'signup_submit', 1247 'id' => 'submit', 1248 'value' => __( 'Complete Sign Up', 'buddypress' ), 1249 ), 1250 ), 1251 'member-profile-edit' => array( 1252 'before' => '', 1253 'after' => '', 1254 'nonce' => 'bp_xprofile_edit', 1255 'attributes' => array( 1256 'name' => 'profile-group-edit-submit', 1257 'id' => 'profile-group-edit-submit', 1258 'value' => __( 'Save Changes', 'buddypress' ), 1259 ), 1260 ), 1261 'member-capabilities' => array( 1262 'before' => 'bp_members_capabilities_account_before_submit', 1263 'after' => 'bp_members_capabilities_account_after_submit', 1264 'nonce' => 'capabilities', 1265 'attributes' => array( 1266 'name' => 'capabilities-submit', 1267 'id' => 'capabilities-submit', 1268 'value' => __( 'Save', 'buddypress' ), 1269 ), 1270 ), 1271 'member-delete-account' => array( 1272 'before' => 'bp_members_delete_account_before_submit', 1273 'after' => 'bp_members_delete_account_after_submit', 1274 'nonce' => 'delete-account', 1275 'attributes' => array( 1276 'disabled' => 'disabled', 1277 'name' => 'delete-account-button', 1278 'id' => 'delete-account-button', 1279 'value' => __( 'Delete Account', 'buddypress' ), 1280 ), 1281 ), 1282 'members-general-settings' => array( 1283 'before' => 'bp_core_general_settings_before_submit', 1284 'after' => 'bp_core_general_settings_after_submit', 1285 'nonce' => 'bp_settings_general', 1286 'attributes' => array( 1287 'name' => 'submit', 1288 'id' => 'submit', 1289 'value' => __( 'Save Changes', 'buddypress' ), 1290 'class' => 'auto', 1291 ), 1292 ), 1293 'member-notifications-settings' => array( 1294 'before' => 'bp_members_notification_settings_before_submit', 1295 'after' => 'bp_members_notification_settings_after_submit', 1296 'nonce' => 'bp_settings_notifications', 1297 'attributes' => array( 1298 'name' => 'submit', 1299 'id' => 'submit', 1300 'value' => __( 'Save Changes', 'buddypress' ), 1301 'class' => 'auto', 1302 ), 1303 ), 1304 'members-profile-settings' => array( 1305 'before' => 'bp_core_xprofile_settings_before_submit', 1306 'after' => 'bp_core_xprofile_settings_after_submit', 1307 'nonce' => 'bp_xprofile_settings', 1308 'attributes' => array( 1309 'name' => 'xprofile-settings-submit', 1310 'id' => 'submit', 1311 'value' => __( 'Save Changes', 'buddypress' ), 1312 'class' => 'auto', 1313 ), 1314 ), 1315 'member-group-invites' => array( 1316 'nonce' => 'bp_nouveau_group_invites_settings', 1317 'attributes' => array( 1318 'name' => 'member-group-invites-submit', 1319 'id' => 'submit', 1320 'value' => __( 'Save', 'buddypress' ), 1321 'class' => 'auto', 1322 ), 1323 ), 1324 'activity-new-comment' => array( 1325 'after' => 'bp_activity_entry_comments', 1326 'nonce' => 'new_activity_comment', 1327 'nonce_key' => '_wpnonce_new_activity_comment', 1328 'wrapper' => false, 1329 'attributes' => array( 1330 'name' => 'ac_form_submit', 1331 'value' => _x( 'Post', 'button', 'buddypress' ), 1332 ), 1333 ), 1334 ) ); 1335 1336 if ( isset( $actions[ $action ] ) ) { 1337 return $actions[ $action ]; 1338 } 1339 1340 return false; 1341 } 1342 1343 /** 1344 * Reorder a BuddyPress item nav according to a given list of nav item slugs 1345 * 1346 * @since 3.0.0 1347 * 1348 * @param object $nav The BuddyPress Item Nav object to reorder 1349 * @param array $order A list of slugs ordered (eg: array( 'profile', 'activity', etc..) ) 1350 * @param string $parent_slug A parent slug if it's a secondary nav we are reordering (case of the Groups single item) 1351 * 1352 * @return bool True on success. False otherwise. 1353 */ 1354 function bp_nouveau_set_nav_item_order( $nav = null, $order = array(), $parent_slug = '' ) { 1355 if ( ! is_object( $nav ) || empty( $order ) || ! is_array( $order ) ) { 1356 return false; 1357 } 1358 1359 $position = 0; 1360 1361 foreach ( $order as $slug ) { 1362 $position += 10; 1363 1364 $key = $slug; 1365 if ( ! empty( $parent_slug ) ) { 1366 $key = $parent_slug . '/' . $key; 1367 } 1368 1369 $item_nav = $nav->get( $key ); 1370 1371 if ( ! $item_nav ) { 1372 continue; 1373 } 1374 1375 if ( (int) $item_nav->position !== (int) $position ) { 1376 $nav->edit_nav( array( 'position' => $position ), $slug, $parent_slug ); 1377 } 1378 } 1379 1380 return true; 1381 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Mar 7 01:01:37 2021 | Cross-referenced by PHPXref 0.7.1 |