Changeset 10180
- Timestamp:
- 10/04/2015 06:17:20 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-templates/bp-legacy/buddypress-functions.php
r10155 r10180 1 1 <?php 2 2 /** 3 * Functions of BuddyPress's Legacy theme 3 * Functions of BuddyPress's Legacy theme. 4 4 * 5 5 * @since 1.7.0 … … 17 17 18 18 /** 19 * Loads BuddyPress Legacy Theme functionality 19 * Loads BuddyPress Legacy Theme functionality. 20 20 * 21 21 * This is not a real theme by WordPress standards, and is instead used as the … … 38 38 39 39 /** 40 * The main BuddyPress (Legacy) Loader 40 * The main BuddyPress (Legacy) Loader. 41 41 * 42 42 * @since 1.7.0 … … 50 50 51 51 /** 52 * Component global variables 52 * Component global variables. 53 53 * 54 54 * You'll want to customize the values in here, so they match whatever your … … 68 68 69 69 /** 70 * Setup the theme hooks 70 * Setup the theme hooks. 71 71 * 72 72 * @since 1.7.0 … … 78 78 protected function setup_actions() { 79 79 80 // Template Output 80 // Template Output. 81 81 add_filter( 'bp_get_activity_action_pre_meta', array( $this, 'secondary_avatars' ), 10, 2 ); 82 82 83 // Filter BuddyPress template hierarchy and look for page templates 83 // Filter BuddyPress template hierarchy and look for page templates. 84 84 add_filter( 'bp_get_buddypress_template', array( $this, 'theme_compat_page_templates' ), 10, 1 ); 85 85 … … 89 89 add_action( 'bp_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); // Enqueue theme JS 90 90 add_filter( 'bp_enqueue_scripts', array( $this, 'localize_scripts' ) ); // Enqueue theme script localization 91 add_action( 'bp_head', array( $this, 'head_scripts' ) ); // Output some extra JS in the <head> 91 add_action( 'bp_head', array( $this, 'head_scripts' ) ); // Output some extra JS in the <head>. 92 92 93 93 /** Body no-js Class **************************************************/ … … 99 99 if ( ! is_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) { 100 100 // Register buttons for the relevant component templates 101 // Friends button 101 // Friends button. 102 102 if ( bp_is_active( 'friends' ) ) 103 103 add_action( 'bp_member_header_actions', 'bp_add_friend_button', 5 ); 104 104 105 // Activity button 105 // Activity button. 106 106 if ( bp_is_active( 'activity' ) && bp_activity_do_mentions() ) 107 107 add_action( 'bp_member_header_actions', 'bp_send_public_message_button', 20 ); 108 108 109 // Messages button 109 // Messages button. 110 110 if ( bp_is_active( 'messages' ) ) 111 111 add_action( 'bp_member_header_actions', 'bp_send_private_message_button', 20 ); 112 112 113 // Group buttons 113 // Group buttons. 114 114 if ( bp_is_active( 'groups' ) ) { 115 115 add_action( 'bp_group_header_actions', 'bp_group_join_button', 5 ); … … 119 119 } 120 120 121 // Blog button 121 // Blog button. 122 122 if ( bp_is_active( 'blogs' ) ) { 123 123 add_action( 'bp_directory_blogs_actions', 'bp_blogs_visit_blog_button' ); … … 138 138 $actions = array( 139 139 140 // Directory filters 140 // Directory filters. 141 141 'blogs_filter' => 'bp_legacy_theme_object_template_loader', 142 142 'forums_filter' => 'bp_legacy_theme_object_template_loader', … … 147 147 'requests_filter' => 'bp_legacy_theme_requests_template_loader', 148 148 149 // Friends 149 // Friends. 150 150 'accept_friendship' => 'bp_legacy_theme_ajax_accept_friendship', 151 151 'addremove_friend' => 'bp_legacy_theme_ajax_addremove_friend', 152 152 'reject_friendship' => 'bp_legacy_theme_ajax_reject_friendship', 153 153 154 // Activity 154 // Activity. 155 155 'activity_get_older_updates' => 'bp_legacy_theme_activity_template_loader', 156 156 'activity_mark_fav' => 'bp_legacy_theme_mark_activity_favorite', … … 165 165 'bp_spam_activity_comment' => 'bp_legacy_theme_spam_activity', 166 166 167 // Groups 167 // Groups. 168 168 'groups_invite_user' => 'bp_legacy_theme_ajax_invite_user', 169 169 'joinleave_group' => 'bp_legacy_theme_ajax_joinleave_group', 170 170 171 // Messages 171 // Messages. 172 172 'messages_autocomplete_results' => 'bp_legacy_theme_ajax_messages_autocomplete_results', 173 173 'messages_close_notice' => 'bp_legacy_theme_ajax_close_notice', … … 178 178 ); 179 179 180 // Conditional actions 180 // Conditional actions. 181 181 if ( bp_is_active( 'messages', 'star' ) ) { 182 182 $actions['messages_star'] = 'bp_legacy_theme_ajax_messages_star_handler'; … … 184 184 185 185 /** 186 * Register all of these AJAX handlers 186 * Register all of these AJAX handlers. 187 187 * 188 188 * The "wp_ajax_" action is used for logged in users, and "wp_ajax_nopriv_" … … 219 219 $min = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; 220 220 221 // Locate the BP stylesheet 221 // Locate the BP stylesheet. 222 222 $ltr = $this->locate_asset_in_stack( "buddypress{$min}.css", 'css' ); 223 223 224 // LTR 224 // LTR. 225 225 if ( ! is_rtl() && isset( $ltr['location'], $ltr['handle'] ) ) { 226 226 wp_enqueue_style( $ltr['handle'], $ltr['location'], array(), $this->version, 'screen' ); … … 231 231 } 232 232 233 // RTL 233 // RTL. 234 234 if ( is_rtl() ) { 235 235 $rtl = $this->locate_asset_in_stack( "buddypress-rtl{$min}.css", 'css' ); 236 236 237 237 if ( isset( $rtl['location'], $rtl['handle'] ) ) { 238 $rtl['handle'] = str_replace( '-css', '-css-rtl', $rtl['handle'] ); // Backwards compatibility 238 $rtl['handle'] = str_replace( '-css', '-css-rtl', $rtl['handle'] ); // Backwards compatibility. 239 239 wp_enqueue_style( $rtl['handle'], $rtl['location'], array(), $this->version, 'screen' ); 240 240 … … 248 248 $theme = $this->locate_asset_in_stack( get_template() . "{$min}.css", 'css' ); 249 249 if ( ! is_rtl() && isset( $theme['location'] ) ) { 250 // use a unique handle250 // Use a unique handle. 251 251 $theme['handle'] = 'bp-' . get_template(); 252 252 wp_enqueue_style( $theme['handle'], $theme['location'], array(), $this->version, 'screen' ); … … 257 257 } 258 258 259 // Compatibility stylesheet for specific themes, RTL-version 259 // Compatibility stylesheet for specific themes, RTL-version. 260 260 if ( is_rtl() ) { 261 261 $theme_rtl = $this->locate_asset_in_stack( get_template() . "-rtl{$min}.css", 'css' ); … … 280 280 $min = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; 281 281 282 // Locate the BP JS file 282 // Locate the BP JS file. 283 283 $asset = $this->locate_asset_in_stack( "buddypress{$min}.js", 'js' ); 284 284 285 285 // Enqueue the global JS, if found - AJAX will not work 286 // without it 286 // without it. 287 287 if ( isset( $asset['location'], $asset['handle'] ) ) { 288 288 wp_enqueue_script( $asset['handle'], $asset['location'], bp_core_get_js_dependencies(), $this->version ); … … 313 313 wp_localize_script( $asset['handle'], 'BP_DTheme', $params ); 314 314 315 // Maybe enqueue comment reply JS 315 // Maybe enqueue comment reply JS. 316 316 if ( is_singular() && bp_is_blog_page() && get_option( 'thread_comments' ) ) { 317 317 wp_enqueue_script( 'comment-reply' ); 318 318 } 319 319 320 // Maybe enqueue password verify JS (register page or user settings page) 320 // Maybe enqueue password verify JS (register page or user settings page). 321 321 if ( bp_is_register_page() || ( function_exists( 'bp_is_user_settings_general' ) && bp_is_user_settings_general() ) ) { 322 322 323 // Locate the Register Page JS file 323 // Locate the Register Page JS file. 324 324 $asset = $this->locate_asset_in_stack( "password-verify{$min}.js", 'js', 'bp-legacy-password-verify' ); 325 325 … … 328 328 ) ); 329 329 330 // Enqueue script 330 // Enqueue script. 331 331 wp_enqueue_script( $asset['handle'] . '-password-verify', $asset['location'], $dependencies, $this->version); 332 332 } 333 333 334 // Star private messages 334 // Star private messages. 335 335 if ( bp_is_active( 'messages', 'star' ) && bp_is_user_messages() ) { 336 336 wp_localize_script( $asset['handle'], 'BP_PM_Star', array( … … 374 374 * @since 1.8.0 375 375 * @access private 376 * @param string $file A filename like buddypress.css 376 * @param string $file A filename like buddypress.css. 377 377 * @param string $type Optional. Either "js" or "css" (the default). 378 378 * @param string $script_handle Optional. If set, used as the script name in `wp_enqueue_script`. … … 389 389 } 390 390 391 // No need to check child if template == stylesheet 391 // No need to check child if template == stylesheet. 392 392 if ( is_child_theme() ) { 393 393 $locations['bp-child'] = array( … … 410 410 ); 411 411 412 // Subdirectories within the top-level $locations directories 412 // Subdirectories within the top-level $locations directories. 413 413 $subdirs = array( 414 414 'buddypress/' . $type, … … 434 434 435 435 /** 436 * Put some scripts in the header, like AJAX url for wp-lists 436 * Put some scripts in the header, like AJAX url for wp-lists. 437 437 * 438 438 * @since 1.7.0 … … 460 460 * 461 461 * @since 1.7.0 462 * 463 * @param array $classes Array of classes to append to body tag. 464 * @return array $classes 462 465 */ 463 466 public function add_nojs_body_class( $classes ) { … … 469 472 470 473 /** 471 * Load localizations for topic script 474 * Load localizations for topic script. 472 475 * 473 476 * These localizations require information that may not be loaded even by init. … … 486 489 */ 487 490 public function sitewide_notices() { 488 // Do not show notices if user is not logged in 491 // Do not show notices if user is not logged in. 489 492 if ( ! is_user_logged_in() ) 490 493 return; 491 494 492 // add a class to determine if the admin bar is on or not495 // Add a class to determine if the admin bar is on or not. 493 496 $class = did_action( 'admin_bar_menu' ) ? 'admin-bar-on' : 'admin-bar-off'; 494 497 … … 503 506 * @since 1.7.0 504 507 * 505 * @param string $action The text of this activity 506 * @param BP_Activity_Activity $activity Activity object 507 * @package BuddyPress Theme 508 * @param string $action The text of this activity. 509 * @param BP_Activity_Activity $activity Activity object. 508 510 * @return string 509 511 */ … … 512 514 case 'groups' : 513 515 case 'friends' : 514 // Only insert avatar if one exists 516 // Only insert avatar if one exists. 515 517 if ( $secondary_avatar = bp_get_activity_secondary_avatar() ) { 516 518 $reverse_content = strrev( $action ); … … 532 534 * @since 2.2.0 533 535 * 534 * @param array $templates 536 * @param array $templates Array of templates. 535 537 * @uses apply_filters() call 'bp_legacy_theme_compat_page_templates_directory_only' and return false 536 538 * to use the defined page template for component's directory and its single items … … 550 552 } 551 553 552 // No page ID yet 554 // No page ID yet. 553 555 $page_id = 0; 554 556 … … 573 575 } 574 576 575 // Bail if no directory page set 577 // Bail if no directory page set. 576 578 if ( 0 === $page_id ) { 577 579 return $templates; 578 580 } 579 581 580 // Check for page template 582 // Check for page template. 581 583 $page_template = get_page_template_slug( $page_id ); 582 584 … … 605 607 * Add the Create a Group button to the Groups directory title. 606 608 * 607 * bp-legacy puts the Create a Group button into the page title, to mimic609 * The bp-legacy puts the Create a Group button into the page title, to mimic 608 610 * the behavior of bp-default. 609 611 * … … 621 623 * Add the Create a Group nav to the Groups directory navigation. 622 624 * 623 * bp-legacy puts the Create a Group nav at the last position of625 * The bp-legacy puts the Create a Group nav at the last position of 624 626 * the Groups directory navigation. 625 627 * 626 628 * @since 2.2.0 627 629 * 628 * @uses bp_group_create_nav_item() to output the create a Group nav item 629 * @return string 630 * @uses bp_group_create_nav_item() to output the create a Group nav item. 630 631 */ 631 632 function bp_legacy_theme_group_create_nav() { … … 636 637 * Add the Create a Site button to the Sites directory title. 637 638 * 638 * bp-legacy puts the Create a Site button into the page title, to mimic639 * The bp-legacy puts the Create a Site button into the page title, to mimic 639 640 * the behavior of bp-default. 640 641 * … … 652 653 * Add the Create a Site nav to the Sites directory navigation. 653 654 * 654 * bp-legacy puts the Create a Site nav at the last position of655 * The bp-legacy puts the Create a Site nav at the last position of 655 656 * the Sites directory navigation. 656 657 * … … 658 659 * 659 660 * @uses bp_blog_create_nav_item() to output the Create a Site nav item 660 * @return string661 661 */ 662 662 function bp_legacy_theme_blog_create_nav() { … … 677 677 * across page loads. 678 678 * 679 * @param string $query_string Query string for the current request. 680 * @param string $object Object for cookie. 679 681 * @return string Query string for the component loops 680 682 * @since 1.2.0 … … 684 686 return ''; 685 687 686 // Set up the cookies passed on this AJAX request. Store a local var to avoid conflicts 688 // Set up the cookies passed on this AJAX request. Store a local var to avoid conflicts. 687 689 if ( ! empty( $_POST['cookie'] ) ) { 688 690 $_BP_COOKIE = wp_parse_args( str_replace( '; ', '&', urldecode( $_POST['cookie'] ) ) ); … … 698 700 */ 699 701 700 // Activity stream filtering on action 702 // Activity stream filtering on action. 701 703 if ( ! empty( $_BP_COOKIE['bp-' . $object . '-filter'] ) && '-1' != $_BP_COOKIE['bp-' . $object . '-filter'] ) { 702 704 $qs[] = 'type=' . $_BP_COOKIE['bp-' . $object . '-filter']; … … 719 721 $qs[] = 'page=' . absint( $_POST['page'] ); 720 722 721 // excludes activity just posted and avoids duplicate ids723 // Excludes activity just posted and avoids duplicate ids. 722 724 if ( ! empty( $_POST['exclude_just_posted'] ) ) { 723 725 $just_posted = wp_parse_id_list( $_POST['exclude_just_posted'] ); … … 725 727 } 726 728 727 // to get newest activities729 // To get newest activities. 728 730 if ( ! empty( $_POST['offset'] ) ) { 729 731 $qs[] = 'offset=' . intval( $_POST['offset'] ); … … 780 782 */ 781 783 function bp_legacy_theme_object_template_loader() { 782 // Bail if not a POST action 784 // Bail if not a POST action. 783 785 if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) ) 784 786 return; 785 787 786 // Bail if no object passed 788 // Bail if no object passed. 787 789 if ( empty( $_POST['object'] ) ) 788 790 return; 789 791 790 // Sanitize the object 792 // Sanitize the object. 791 793 $object = sanitize_title( $_POST['object'] ); 792 794 793 // Bail if object is not an active component to prevent arbitrary file inclusion 795 // Bail if object is not an active component to prevent arbitrary file inclusion. 794 796 if ( ! bp_is_active( $object ) ) 795 797 return; … … 806 808 $template_part = $object . '/' . $object . '-loop'; 807 809 808 // The template part can be overridden by the calling JS function 810 // The template part can be overridden by the calling JS function. 809 811 if ( ! empty( $_POST['template'] ) ) { 810 812 $template_part = sanitize_option( 'upload_path', $_POST['template'] ); 811 813 } 812 814 813 // Locate the object template 815 // Locate the object template. 814 816 bp_get_template_part( $template_part ); 815 817 exit(); … … 819 821 * Load messages template loop when searched on the private message page 820 822 * 821 * @return string Prints template loop for the Messages component822 823 * @since 1.6.0 824 * 825 * @return string Prints template loop for the Messages component. 823 826 */ 824 827 function bp_legacy_theme_messages_template_loader() { … … 848 851 849 852 /** 850 * Load the activity loop template when activity is requested via AJAX ,853 * Load the activity loop template when activity is requested via AJAX. 851 854 * 852 855 * @return string JSON object containing 'contents' (output of the template loop … … 856 859 */ 857 860 function bp_legacy_theme_activity_template_loader() { 858 // Bail if not a POST action 861 // Bail if not a POST action. 859 862 if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) ) 860 863 return; … … 864 867 $scope = $_POST['scope']; 865 868 866 // We need to calculate and return the feed URL for each scope 869 // We need to calculate and return the feed URL for each scope. 867 870 switch ( $scope ) { 868 871 case 'friends': … … 912 915 $bp = buddypress(); 913 916 914 // Bail if not a POST action 917 // Bail if not a POST action. 915 918 if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) ) 916 919 return; 917 920 918 // Check the nonce 921 // Check the nonce. 919 922 check_admin_referer( 'post_update', '_wpnonce_post_update' ); 920 923 … … 968 971 * Posts new Activity comments received via a POST request. 969 972 * 973 * @since 1.2.0 974 * 970 975 * @global BP_Activity_Template $activities_template 976 * 971 977 * @return string HTML 972 * @since 1.2.0973 978 */ 974 979 function bp_legacy_theme_new_activity_comment() { … … 977 982 $bp = buddypress(); 978 983 979 // Bail if not a POST action 984 // Bail if not a POST action. 980 985 if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) ) { 981 986 return; 982 987 } 983 988 984 // Check the nonce 989 // Check the nonce. 985 990 check_admin_referer( 'new_activity_comment', '_wpnonce_new_activity_comment' ); 986 991 … … 1014 1019 } 1015 1020 1016 // Load the new activity item into the $activities_template global 1021 // Load the new activity item into the $activities_template global. 1017 1022 bp_has_activities( 'display_comments=stream&hide_spam=false&show_hidden=true&include=' . $comment_id ); 1018 1023 1019 // Swap the current comment with the activity item we just loaded 1024 // Swap the current comment with the activity item we just loaded. 1020 1025 if ( isset( $activities_template->activities[0] ) ) { 1021 1026 $activities_template->activity = new stdClass(); … … 1024 1029 1025 1030 // Because the whole tree has not been loaded, we manually 1026 // determine depth 1031 // determine depth. 1027 1032 $depth = 1; 1028 1033 $parent_id = (int) $activities_template->activities[0]->secondary_item_id; … … 1035 1040 } 1036 1041 1037 // get activity comment template part1042 // Get activity comment template part. 1038 1043 bp_get_template_part( 'activity/comment' ); 1039 1044 … … 1045 1050 * Deletes an Activity item received via a POST request. 1046 1051 * 1047 * @return mixed String on error, void on success1048 1052 * @since 1.2.0 1053 * 1054 * @return mixed String on error, void on success. 1049 1055 */ 1050 1056 function bp_legacy_theme_delete_activity() { 1051 // Bail if not a POST action 1057 // Bail if not a POST action. 1052 1058 if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) ) 1053 1059 return; 1054 1060 1055 // Check the nonce 1061 // Check the nonce. 1056 1062 check_admin_referer( 'bp_activity_delete_link' ); 1057 1063 … … 1064 1070 $activity = new BP_Activity_Activity( (int) $_POST['id'] ); 1065 1071 1066 // Check access 1072 // Check access. 1067 1073 if ( ! bp_activity_user_can_delete( $activity ) ) 1068 1074 exit( '-1' ); … … 1080 1086 1081 1087 /** 1082 * Deletes an Activity comment received via a POST request 1083 * 1084 * @return mixed String on error, void on success 1088 * Deletes an Activity comment received via a POST request. 1089 * 1085 1090 * @since 1.2.0 1091 * 1092 * @return mixed String on error, void on success. 1086 1093 */ 1087 1094 function bp_legacy_theme_delete_activity_comment() { 1088 // Bail if not a POST action 1095 // Bail if not a POST action. 1089 1096 if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) ) 1090 1097 return; 1091 1098 1092 // Check the nonce 1099 // Check the nonce. 1093 1100 check_admin_referer( 'bp_activity_delete_link' ); 1094 1101 … … 1098 1105 $comment = new BP_Activity_Activity( $_POST['id'] ); 1099 1106 1100 // Check access 1107 // Check access. 1101 1108 if ( ! bp_current_user_can( 'bp_moderate' ) && $comment->user_id != bp_loggedin_user_id() ) 1102 1109 exit( '-1' ); … … 1117 1124 1118 1125 /** 1119 * AJAX spam an activity item or comment 1120 * 1121 * @return mixed String on error, void on success 1126 * AJAX spam an activity item or comment. 1127 * 1122 1128 * @since 1.6.0 1129 * 1130 * @return mixed String on error, void on success. 1123 1131 */ 1124 1132 function bp_legacy_theme_spam_activity() { 1125 1133 $bp = buddypress(); 1126 1134 1127 // Bail if not a POST action 1135 // Bail if not a POST action. 1128 1136 if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) ) 1129 1137 return; … … 1133 1141 exit( '-1' ); 1134 1142 1135 // Check an item ID was passed 1143 // Check an item ID was passed. 1136 1144 if ( empty( $_POST['id'] ) || ! is_numeric( $_POST['id'] ) ) 1137 1145 exit( '-1' ); … … 1141 1149 exit( '-1' ); 1142 1150 1143 // Load up the activity item 1151 // Load up the activity item. 1144 1152 $activity = new BP_Activity_Activity( (int) $_POST['id'] ); 1145 1153 if ( empty( $activity->component ) ) 1146 1154 exit( '-1' ); 1147 1155 1148 // Check nonce 1156 // Check nonce. 1149 1157 check_admin_referer( 'bp_activity_akismet_spam_' . $activity->id ); 1150 1158 … … 1152 1160 do_action( 'bp_activity_before_action_spam_activity', $activity->id, $activity ); 1153 1161 1154 // Mark as spam 1162 // Mark as spam. 1155 1163 bp_activity_mark_as_spam( $activity ); 1156 1164 $activity->save(); … … 1164 1172 * Mark an activity as a favourite via a POST request. 1165 1173 * 1174 * @since 1.2.0 1175 * 1166 1176 * @return string HTML 1167 * @since 1.2.01168 1177 */ 1169 1178 function bp_legacy_theme_mark_activity_favorite() { 1170 // Bail if not a POST action 1179 // Bail if not a POST action. 1171 1180 if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) ) 1172 1181 return; … … 1183 1192 * Un-favourite an activity via a POST request. 1184 1193 * 1194 * @since 1.2.0 1195 * 1185 1196 * @return string HTML 1186 * @since 1.2.01187 1197 */ 1188 1198 function bp_legacy_theme_unmark_activity_favorite() { 1189 // Bail if not a POST action 1199 // Bail if not a POST action. 1190 1200 if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) ) 1191 1201 return; … … 1203 1213 * Used for the 'Read More' link on long activity items. 1204 1214 * 1215 * @since 1.5.0 1216 * 1205 1217 * @return string HTML 1206 * @since 1.5.01207 1218 */ 1208 1219 function bp_legacy_theme_get_single_activity_content() { 1209 // Bail if not a POST action 1220 // Bail if not a POST action. 1210 1221 if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) ) 1211 1222 return; … … 1230 1241 do_action_ref_array( 'bp_legacy_theme_get_single_activity_content', array( &$activity ) ); 1231 1242 1232 // Activity content retrieved through AJAX should run through normal filters, but not be truncated 1243 // Activity content retrieved through AJAX should run through normal filters, but not be truncated. 1233 1244 remove_filter( 'bp_get_activity_content_body', 'bp_activity_truncate_entry', 5 ); 1234 1245 … … 1243 1254 * 1244 1255 * @since 1.2.0 1256 * 1245 1257 * @todo Audit return types 1246 1258 */ 1247 1259 function bp_legacy_theme_ajax_invite_user() { 1248 // Bail if not a POST action 1260 // Bail if not a POST action. 1249 1261 if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) ) 1250 1262 return; … … 1268 1280 1269 1281 // Users who have previously requested membership do not need 1270 // another invitation created for them 1282 // another invitation created for them. 1271 1283 if ( BP_Groups_Member::check_for_membership_request( $friend_id, $group_id ) ) { 1272 1284 $user_status = 'is_pending'; 1273 1285 1274 // Create the user invitation 1286 // Create the user invitation. 1275 1287 } elseif ( groups_invite_user( array( 'user_id' => $friend_id, 'group_id' => $group_id ) ) ) { 1276 1288 $user_status = 'is_invited'; 1277 1289 1278 // Miscellaneous failure 1290 // Miscellaneous failure. 1279 1291 } else { 1280 1292 return; … … 1304 1316 } elseif ( 'uninvite' == $_POST['friend_action'] ) { 1305 1317 // Users who have previously requested membership should not 1306 // have their requests deleted on the "uninvite" action 1318 // have their requests deleted on the "uninvite" action. 1307 1319 if ( BP_Groups_Member::check_for_membership_request( $friend_id, $group_id ) ) { 1308 1320 return; 1309 1321 } 1310 1322 1311 // Remove the unsent invitation 1323 // Remove the unsent invitation. 1312 1324 if ( ! groups_uninvite_user( $friend_id, $group_id ) ) { 1313 1325 return; … … 1324 1336 * Friend/un-friend a user via a POST request. 1325 1337 * 1338 * @since 1.2.0 1339 * 1326 1340 * @return string HTML 1327 * @since 1.2.01328 1341 */ 1329 1342 function bp_legacy_theme_ajax_addremove_friend() { 1330 1343 1331 // Bail if not a POST action 1344 // Bail if not a POST action. 1332 1345 if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) ) 1333 1346 return; 1334 1347 1335 // Cast fid as an integer 1348 // Cast fid as an integer. 1336 1349 $friend_id = (int) $_POST['fid']; 1337 1350 1338 // Trying to cancel friendship 1351 // Trying to cancel friendship. 1339 1352 if ( 'is_friend' == BP_Friends_Friendship::check_is_friend( bp_loggedin_user_id(), $friend_id ) ) { 1340 1353 check_ajax_referer( 'friends_remove_friend' ); … … 1346 1359 } 1347 1360 1348 // Trying to request friendship 1361 // Trying to request friendship. 1349 1362 } elseif ( 'not_friends' == BP_Friends_Friendship::check_is_friend( bp_loggedin_user_id(), $friend_id ) ) { 1350 1363 check_ajax_referer( 'friends_add_friend' ); … … 1356 1369 } 1357 1370 1358 // Trying to cancel pending request 1371 // Trying to cancel pending request. 1359 1372 } elseif ( 'pending' == BP_Friends_Friendship::check_is_friend( bp_loggedin_user_id(), $friend_id ) ) { 1360 1373 check_ajax_referer( 'friends_withdraw_friendship' ); … … 1366 1379 } 1367 1380 1368 // Request already pending 1381 // Request already pending. 1369 1382 } else { 1370 1383 echo __( 'Request Pending', 'buddypress' ); … … 1377 1390 * Accept a user friendship request via a POST request. 1378 1391 * 1379 * @return mixed String on error, void on success1380 1392 * @since 1.2.0 1393 * 1394 * @return mixed String on error, void on success. 1381 1395 */ 1382 1396 function bp_legacy_theme_ajax_accept_friendship() { 1383 // Bail if not a POST action 1397 // Bail if not a POST action. 1384 1398 if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) ) 1385 1399 return; … … 1396 1410 * Reject a user friendship request via a POST request. 1397 1411 * 1398 * @return mixed String on error, void on success1399 1412 * @since 1.2.0 1413 * 1414 * @return mixed String on error, void on success. 1400 1415 */ 1401 1416 function bp_legacy_theme_ajax_reject_friendship() { 1402 // Bail if not a POST action 1417 // Bail if not a POST action. 1403 1418 if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) ) 1404 1419 return; … … 1415 1430 * Join or leave a group when clicking the "join/leave" button via a POST request. 1416 1431 * 1432 * @since 1.2.0 1433 * 1417 1434 * @return string HTML 1418 * @since 1.2.01419 1435 */ 1420 1436 function bp_legacy_theme_ajax_joinleave_group() { 1421 // Bail if not a POST action 1437 // Bail if not a POST action. 1422 1438 if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) ) 1423 1439 return; 1424 1440 1425 // Cast gid as integer 1441 // Cast gid as integer. 1426 1442 $group_id = (int) $_POST['gid']; 1427 1443 … … 1445 1461 1446 1462 // If the user has already been invited, then this is 1447 // an Accept Invitation button 1463 // an Accept Invitation button. 1448 1464 if ( groups_check_user_has_invite( bp_loggedin_user_id(), $group->id ) ) { 1449 1465 check_ajax_referer( 'groups_accept_invite' ); … … 1455 1471 } 1456 1472 1457 // Otherwise, it's a Request Membership button 1473 // Otherwise, it's a Request Membership button. 1458 1474 } else { 1459 1475 check_ajax_referer( 'groups_request_membership' ); … … 1485 1501 * Close and keep closed site wide notices from an admin in the sidebar, via a POST request. 1486 1502 * 1487 * @return mixed String on error, void on success1488 1503 * @since 1.2.0 1504 * 1505 * @return mixed String on error, void on success. 1489 1506 */ 1490 1507 function bp_legacy_theme_ajax_close_notice() { 1491 // Bail if not a POST action 1508 // Bail if not a POST action. 1492 1509 if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) ) 1493 1510 return; … … 1510 1527 * Send a private message reply to a thread via a POST request. 1511 1528 * 1529 * @since 1.2.0 1530 * 1512 1531 * @return string HTML 1513 * @since 1.2.01514 1532 */ 1515 1533 function bp_legacy_theme_ajax_messages_send_reply() { 1516 // Bail if not a POST action 1534 // Bail if not a POST action. 1517 1535 if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) ) 1518 1536 return; … … 1524 1542 if ( !empty( $result ) ) { 1525 1543 1526 // pretend we're in the message loop1544 // Pretend we're in the message loop. 1527 1545 global $thread_template; 1528 1546 1529 1547 bp_thread_has_messages( array( 'thread_id' => (int) $_REQUEST['thread_id'] ) ); 1530 1548 1531 // set the current message to the 2nd last1549 // Set the current message to the 2nd last. 1532 1550 $thread_template->message = end( $thread_template->thread->messages ); 1533 1551 $thread_template->message = prev( $thread_template->thread->messages ); 1534 1552 1535 // set current message to current key1553 // Set current message to current key. 1536 1554 $thread_template->current_message = key( $thread_template->thread->messages ); 1537 1555 1538 // now manually iterate message like we're in the loop1556 // Now manually iterate message like we're in the loop. 1539 1557 bp_thread_the_message(); 1540 1558 1541 // manually call oEmbed1542 // this is needed because we're not at the beginning of the loop 1559 // Manually call oEmbed 1560 // this is needed because we're not at the beginning of the loop. 1543 1561 bp_messages_embed(); 1544 1562 1545 // add new-message css class1563 // Add new-message css class. 1546 1564 add_filter( 'bp_get_the_thread_message_css_class', create_function( '$retval', ' 1547 1565 $retval[] = "new-message"; … … 1549 1567 ' ) ); 1550 1568 1551 // output single message template part1569 // Output single message template part. 1552 1570 bp_get_template_part( 'members/single/messages/message' ); 1553 1571 1554 // clean up the loop1572 // Clean up the loop. 1555 1573 bp_thread_messages(); 1556 1574 … … 1565 1583 * Mark a private message as unread in your inbox via a POST request. 1566 1584 * 1567 * @return mixed String on error, void on success1568 1585 * @since 1.2.0 1586 * 1587 * @return mixed String on error, void on success. 1569 1588 */ 1570 1589 function bp_legacy_theme_ajax_message_markunread() { 1571 // Bail if not a POST action 1590 // Bail if not a POST action. 1572 1591 if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) ) 1573 1592 return; … … 1590 1609 * Mark a private message as read in your inbox via a POST request. 1591 1610 * 1592 * @return mixed String on error, void on success1593 1611 * @since 1.2.0 1612 * 1613 * @return mixed String on error, void on success. 1594 1614 */ 1595 1615 function bp_legacy_theme_ajax_message_markread() { 1596 // Bail if not a POST action 1616 // Bail if not a POST action. 1597 1617 if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) ) 1598 1618 return; … … 1615 1635 * Delete a private message(s) in your inbox via a POST request. 1616 1636 * 1637 * @since 1.2.0 1638 * 1617 1639 * @return string HTML 1618 * @since 1.2.01619 1640 */ 1620 1641 function bp_legacy_theme_ajax_messages_delete() { 1621 // Bail if not a POST action 1642 // Bail if not a POST action. 1622 1643 if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) ) 1623 1644 return; … … 1642 1663 * 1643 1664 * @since 1.2.0 1644 *1645 * @return string HTML.1646 1665 */ 1647 1666 function bp_legacy_theme_ajax_messages_autocomplete_results() { … … 1675 1694 1676 1695 // Note that the final line break acts as a delimiter for the 1677 // autocomplete JavaScript and thus should not be removed 1696 // autocomplete JavaScript and thus should not be removed. 1678 1697 printf( '<span id="%s" href="#"></span><img src="%s" style="width: 15px"> %s (%s)' . "\n", 1679 1698 esc_attr( 'link-' . $user->ID ), … … 1698 1717 } 1699 1718 1700 // Check nonce 1719 // Check nonce. 1701 1720 check_ajax_referer( 'bp-messages-star-' . (int) $_POST['message_id'], 'nonce' ); 1702 1721 1703 // Check capability 1722 // Check capability. 1704 1723 if ( ! is_user_logged_in() || ! bp_core_can_edit_settings() ) { 1705 1724 return; … … 1720 1739 1721 1740 /** 1722 * BP Legacy's callback for the cover image feature 1741 * BP Legacy's callback for the cover image feature. 1723 1742 * 1724 1743 * @since 2.4.0 1725 1744 * 1726 * @param array $params the current component's feature parameters1745 * @param array $params the current component's feature parameters. 1727 1746 * @return array an array to inform about the css handle to attach the css rules to 1728 1747 */ … … 1732 1751 } 1733 1752 1734 // avatar height - padding - 1/2 avatar height1753 // Avatar height - padding - 1/2 avatar height. 1735 1754 $avatar_offset = $params['height'] - 5 - round( (int) bp_core_avatar_full_height() / 2 ); 1736 1755 1737 // header content offset + spacing1756 // Header content offset + spacing. 1738 1757 $top_offset = bp_core_avatar_full_height() - 10; 1739 1758 $left_offset = bp_core_avatar_full_width() + 20; … … 1743 1762 $hide_avatar_style = ''; 1744 1763 1745 // Adjust the cover image header, in case avatars are completely disabled 1764 // Adjust the cover image header, in case avatars are completely disabled. 1746 1765 if ( ! buddypress()->avatar->show_avatars ) { 1747 1766 $hide_avatar_style = '
Note: See TracChangeset
for help on using the changeset viewer.