Changeset 10253 for trunk/src/bp-activity/bp-activity-functions.php
- Timestamp:
- 10/12/2015 05:45:14 AM (11 years ago)
- File:
-
- 1 edited
-
trunk/src/bp-activity/bp-activity-functions.php (modified) (93 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-activity/bp-activity-functions.php
r10217 r10253 9 9 */ 10 10 11 // Exit if accessed directly 11 // Exit if accessed directly. 12 12 defined( 'ABSPATH' ) || exit; 13 13 … … 86 86 * @param string $content The content of the activity, usually found in 87 87 * $activity->content. 88 *89 88 * @return array|bool Associative array with user ID as key and username as 90 89 * value. Boolean false if no mentions found. … … 95 94 preg_match_all( $pattern, $content, $usernames ); 96 95 97 // Make sure there's only one instance of each username 96 // Make sure there's only one instance of each username. 98 97 $usernames = array_unique( $usernames[1] ); 99 98 100 // Bail if no usernames 99 // Bail if no usernames. 101 100 if ( empty( $usernames ) ) { 102 101 return false; … … 105 104 $mentioned_users = array(); 106 105 107 // We've found some mentions! Check to see if users exist 106 // We've found some mentions! Check to see if users exist. 108 107 foreach( (array) array_values( $usernames ) as $username ) { 109 108 $user_id = bp_activity_get_userid_from_mentionname( $username ); 110 109 111 // user ID exists, so let's add it to our array110 // The user ID exists, so let's add it to our array. 112 111 if ( ! empty( $user_id ) ) { 113 112 $mentioned_users[ $user_id ] = $username; … … 151 150 * @param int $activity_id The unique id for the activity item. 152 151 * @param string $action Can be 'delete' or 'add'. Defaults to 'add'. 153 *154 152 * @return bool 155 153 */ 156 154 function bp_activity_adjust_mention_count( $activity_id = 0, $action = 'add' ) { 157 155 158 // Bail if no activity ID passed 156 // Bail if no activity ID passed. 159 157 if ( empty( $activity_id ) ) { 160 158 return false; 161 159 } 162 160 163 // Get activity object 161 // Get activity object. 164 162 $activity = new BP_Activity_Activity( (int) $activity_id ); 165 163 166 // Try to find mentions 164 // Try to find mentions. 167 165 $usernames = bp_activity_find_mentions( strip_tags( $activity->content ) ); 168 166 169 // Still empty? Stop now 167 // Still empty? Stop now. 170 168 if ( empty( $usernames ) ) { 171 169 return false; 172 170 } 173 171 174 // Increment mention count foreach mentioned user 172 // Increment mention count foreach mentioned user. 175 173 foreach( (array) array_keys( $usernames ) as $user_id ) { 176 174 bp_activity_update_mention_count_for_user( $user_id, $activity_id, $action ); … … 192 190 * @param int $activity_id The unique ID for the activity item. 193 191 * @param string $action 'delete' or 'add'. Default: 'add'. 194 *195 192 * @return bool 196 193 */ … … 201 198 } 202 199 203 // Adjust the mention list and count for the member 200 // Adjust the mention list and count for the member. 204 201 $new_mention_count = (int) bp_get_user_meta( $user_id, 'bp_new_mention_count', true ); 205 202 $new_mentions = bp_get_user_meta( $user_id, 'bp_new_mentions', true ); 206 203 207 // Make sure new mentions is an array 204 // Make sure new mentions is an array. 208 205 if ( empty( $new_mentions ) ) { 209 206 $new_mentions = array(); … … 229 226 } 230 227 231 // Get an updated mention count 228 // Get an updated mention count. 232 229 $new_mention_count = count( $new_mentions ); 233 230 234 // Resave the user_meta 231 // Resave the user_meta. 235 232 bp_update_user_meta( $user_id, 'bp_new_mention_count', $new_mention_count ); 236 233 bp_update_user_meta( $user_id, 'bp_new_mentions', $new_mentions ); … … 245 242 * 246 243 * @param int|string $user_id ID of the user to get @-mention name for. 247 * 248 * @return string User name appropriate for @-mentions. 244 * @return string $mentionname User name appropriate for @-mentions. 249 245 */ 250 246 function bp_activity_get_user_mentionname( $user_id ) { … … 270 266 * 271 267 * @param string $mentionname Username of user in @-mentions. 272 *273 268 * @return int|bool ID of the user, if one is found. Otherwise false. 274 269 */ … … 276 271 $user_id = false; 277 272 278 // In username compatibility mode, hyphens are ambiguous between 279 // actual hyphens and converted spaces. 280 // 281 // @todo There is the potential for username clashes between 'foo bar' 282 // and 'foo-bar' in compatibility mode. Come up with a system for 283 // unique mentionnames. 273 /* 274 * In username compatibility mode, hyphens are ambiguous between 275 * actual hyphens and converted spaces. 276 * 277 * @todo There is the potential for username clashes between 'foo bar' 278 * and 'foo-bar' in compatibility mode. Come up with a system for 279 * unique mentionnames. 280 */ 284 281 if ( bp_is_username_compatibility_mode() ) { 285 // First, try the raw username 282 // First, try the raw username. 286 283 $userdata = get_user_by( 'login', $mentionname ); 287 284 … … 297 294 298 295 // When username compatibility mode is disabled, the mentionname is 299 // the same as the nicename 296 // the same as the nicename. 300 297 } else { 301 298 $user_id = bp_core_get_userid_from_nicename( $mentionname ); … … 332 329 * Values: 'activity', 'member', 'member_groups', 'group'. 333 330 * @param int $position Optional. The position of the action when listed in dropdowns. 334 *335 331 * @return bool False if any param is empty, otherwise true. 336 332 */ … … 338 334 $bp = buddypress(); 339 335 340 // Return false if any of the above values are not set 336 // Return false if any of the above values are not set. 341 337 if ( empty( $component_id ) || empty( $type ) || empty( $description ) ) { 342 338 return false; 343 339 } 344 340 345 // Set activity action 341 // Set activity action. 346 342 if ( ! isset( $bp->activity->actions ) || ! is_object( $bp->activity->actions ) ) { 347 343 $bp->activity->actions = new stdClass; 348 344 } 349 345 350 // Verify callback 346 // Verify callback. 351 347 if ( ! is_callable( $format_callback ) ) { 352 348 $format_callback = ''; … … 393 389 * @param array $args { 394 390 * An associative array of tracking parameters. All items are optional. 395 *396 391 * @type string $bp_activity_admin_filter String to use in the Dashboard > Activity dropdown. 397 392 * @type string $bp_activity_front_filter String to use in frontend dropdown. … … 415 410 * the post type does not natively support comments, otherwise false. 416 411 * } 417 *418 412 * @return bool 419 413 */ … … 445 439 * 446 440 * @param string $post_type Name of the post type. 447 *448 441 * @return object The tracking arguments of the post type. 449 442 */ … … 515 508 */ 516 509 function bp_activity_get_post_types_tracking_args() { 517 // Fetch all public post types 510 // Fetch all public post types. 518 511 $post_types = get_post_types( array( 'public' => true ), 'names' ); 519 512 … … 595 588 * @param string $component_id The unique string ID of the component. 596 589 * @param string $key The action key. 597 *598 590 * @return string|bool Action value if found, otherwise false. 599 591 */ 600 592 function bp_activity_get_action( $component_id, $key ) { 601 593 602 // Return false if any of the above values are not set 594 // Return false if any of the above values are not set. 603 595 if ( empty( $component_id ) || empty( $key ) ) { 604 596 return false; … … 643 635 } 644 636 645 // This was a mis-named activity type from before BP 1.6 637 // This was a mis-named activity type from before BP 1.6. 646 638 unset( $actions['friends_register_activity_action'] ); 647 639 … … 667 659 * 668 660 * @param int $user_id ID of the user whose favorites are being queried. 669 *670 661 * @return array IDs of the user's favorite activity items. 671 662 */ 672 663 function bp_activity_get_user_favorites( $user_id = 0 ) { 673 664 674 // Fallback to logged in user if no user_id is passed 665 // Fallback to logged in user if no user_id is passed. 675 666 if ( empty( $user_id ) ) { 676 667 $user_id = bp_displayed_user_id(); 677 668 } 678 669 679 // Get favorites for user 670 // Get favorites for user. 680 671 $favs = bp_get_user_meta( $user_id, 'bp_favorite_activities', true ); 681 672 … … 705 696 * @param int $activity_id ID of the activity item being favorited. 706 697 * @param int $user_id ID of the user favoriting the activity item. 707 *708 698 * @return bool True on success, false on failure. 709 699 */ 710 700 function bp_activity_add_user_favorite( $activity_id, $user_id = 0 ) { 711 701 712 // Favorite activity stream items are for logged in users only 702 // Favorite activity stream items are for logged in users only. 713 703 if ( ! is_user_logged_in() ) { 714 704 return false; 715 705 } 716 706 717 // Fallback to logged in user if no user_id is passed 707 // Fallback to logged in user if no user_id is passed. 718 708 if ( empty( $user_id ) ) { 719 709 $user_id = bp_loggedin_user_id(); … … 725 715 } 726 716 727 // Bail if the user has already favorited this activity item 717 // Bail if the user has already favorited this activity item. 728 718 if ( in_array( $activity_id, $my_favs ) ) { 729 719 return false; 730 720 } 731 721 732 // Add to user's favorites 722 // Add to user's favorites. 733 723 $my_favs[] = $activity_id; 734 724 735 // Update the total number of users who have favorited this activity 725 // Update the total number of users who have favorited this activity. 736 726 $fav_count = bp_activity_get_meta( $activity_id, 'favorite_count' ); 737 727 $fav_count = !empty( $fav_count ) ? (int) $fav_count + 1 : 1; 738 728 739 // Update user meta 729 // Update user meta. 740 730 bp_update_user_meta( $user_id, 'bp_favorite_activities', $my_favs ); 741 731 742 // Update activity meta counts 732 // Update activity meta counts. 743 733 if ( bp_activity_update_meta( $activity_id, 'favorite_count', $fav_count ) ) { 744 734 … … 753 743 do_action( 'bp_activity_add_user_favorite', $activity_id, $user_id ); 754 744 755 // Success 745 // Success. 756 746 return true; 757 747 758 // Saving meta was unsuccessful for an unknown reason 748 // Saving meta was unsuccessful for an unknown reason. 759 749 } else { 760 750 … … 787 777 * @param int $activity_id ID of the activity item being unfavorited. 788 778 * @param int $user_id ID of the user unfavoriting the activity item. 789 *790 779 * @return bool True on success, false on failure. 791 780 */ 792 781 function bp_activity_remove_user_favorite( $activity_id, $user_id = 0 ) { 793 782 794 // Favorite activity stream items are for logged in users only 783 // Favorite activity stream items are for logged in users only. 795 784 if ( ! is_user_logged_in() ) { 796 785 return false; 797 786 } 798 787 799 // Fallback to logged in user if no user_id is passed 788 // Fallback to logged in user if no user_id is passed. 800 789 if ( empty( $user_id ) ) { 801 790 $user_id = bp_loggedin_user_id(); … … 805 794 $my_favs = array_flip( (array) $my_favs ); 806 795 807 // Bail if the user has not previously favorited the item 796 // Bail if the user has not previously favorited the item. 808 797 if ( ! isset( $my_favs[ $activity_id ] ) ) { 809 798 return false; 810 799 } 811 800 812 // Remove the fav from the user's favs 801 // Remove the fav from the user's favs. 813 802 unset( $my_favs[$activity_id] ); 814 803 $my_favs = array_unique( array_flip( $my_favs ) ); 815 804 816 // Update the total number of users who have favorited this activity 805 // Update the total number of users who have favorited this activity. 817 806 $fav_count = bp_activity_get_meta( $activity_id, 'favorite_count' ); 818 807 if ( ! empty( $fav_count ) ) { 819 808 820 // Deduct from total favorites 809 // Deduct from total favorites. 821 810 if ( bp_activity_update_meta( $activity_id, 'favorite_count', (int) $fav_count - 1 ) ) { 822 811 823 // Update users favorites 812 // Update users favorites. 824 813 if ( bp_update_user_meta( $user_id, 'bp_favorite_activities', $my_favs ) ) { 825 814 … … 834 823 do_action( 'bp_activity_remove_user_favorite', $activity_id, $user_id ); 835 824 836 // Success 825 // Success. 837 826 return true; 838 827 839 // Error updating 828 // Error updating. 840 829 } else { 841 830 return false; 842 831 } 843 832 844 // Error updating favorite count 833 // Error updating favorite count. 845 834 } else { 846 835 return false; 847 836 } 848 837 849 // Error getting favorite count 838 // Error getting favorite count. 850 839 } else { 851 840 return false; … … 862 851 * 863 852 * @param string $content The content to filter by. 864 *865 853 * @return int|null The ID of the located activity item. Null if none is found. 866 854 */ … … 907 895 * 908 896 * @param int $user_id ID of the user whose favorite count is being requested. 909 *910 897 * @return int Total favorite count for the user. 911 898 */ 912 899 function bp_activity_total_favorites_for_user( $user_id = 0 ) { 913 900 914 // Fallback on displayed user, and then logged in user 901 // Fallback on displayed user, and then logged in user. 915 902 if ( empty( $user_id ) ) { 916 903 $user_id = ( bp_displayed_user_id() ) ? bp_displayed_user_id() : bp_loggedin_user_id(); … … 937 924 * @param bool $delete_all Optional. If true, delete matching metadata entries 938 925 * for all objects, ignoring the specified object_id. Otherwise, 939 * only delete matching metadata entries for the specified 940 * activity item. Default: false. 941 * 926 * only delete matching metadata entries for the specified 927 * activity item. Default: false. 942 928 * @return bool True on success, false on failure. 943 929 */ 944 930 function bp_activity_delete_meta( $activity_id, $meta_key = '', $meta_value = '', $delete_all = false ) { 945 931 946 // Legacy - if no meta_key is passed, delete all for the item 932 // Legacy - if no meta_key is passed, delete all for the item. 947 933 if ( empty( $meta_key ) ) { 948 934 $all_meta = bp_activity_get_meta( $activity_id ); 949 935 $keys = ! empty( $all_meta ) ? array_keys( $all_meta ) : array(); 950 936 951 // With no meta_key, ignore $delete_all 937 // With no meta_key, ignore $delete_all. 952 938 $delete_all = false; 953 939 } else { … … 978 964 * activity item will be fetched. 979 965 * @param bool $single Optional. If true, return only the first value of the 980 * specified meta_key. This parameter has no effect if meta_key is not 981 * specified. Default: true. 982 * 966 * specified meta_key. This parameter has no effect if meta_key is not 967 * specified. Default: true. 983 968 * @return mixed The meta value(s) being requested. 984 969 */ … … 1011 996 * @param mixed $prev_value Optional. If specified, only update existing metadata entries 1012 997 * with the specified value. Otherwise, update all entries. 1013 *1014 998 * @return bool|int Returns false on failure. On successful update of existing 1015 999 * metadata, returns true. On successful creation of new metadata, … … 1035 1019 * given key. If true, and the object already has a value for 1036 1020 * the key, no change will be made. Default: false. 1037 *1038 1021 * @return int|bool The meta ID on successful update, false on failure. 1039 1022 */ … … 1060 1043 * 1061 1044 * @param int $user_id ID of the user whose activity is being deleted. 1062 *1063 1045 * @return bool 1064 1046 */ 1065 1047 function bp_activity_remove_all_user_data( $user_id = 0 ) { 1066 1048 1067 // Do not delete user data unless a logged in user says so 1049 // Do not delete user data unless a logged in user says so. 1068 1050 if ( empty( $user_id ) || ! is_user_logged_in() ) { 1069 1051 return false; 1070 1052 } 1071 1053 1072 // Clear the user's activity from the sitewide stream and clear their activity tables 1054 // Clear the user's activity from the sitewide stream and clear their activity tables. 1073 1055 bp_activity_delete( array( 'user_id' => $user_id ) ); 1074 1056 1075 // Remove any usermeta 1057 // Remove any usermeta. 1076 1058 bp_delete_user_meta( $user_id, 'bp_latest_update' ); 1077 1059 bp_delete_user_meta( $user_id, 'bp_favorite_activities' ); … … 1100 1082 * 1101 1083 * @param int $user_id ID of the user whose activity is being spammed. 1102 *1103 1084 * @return bool 1104 1085 */ … … 1106 1087 global $wpdb; 1107 1088 1108 // Do not delete user data unless a logged in user says so 1089 // Do not delete user data unless a logged in user says so. 1109 1090 if ( empty( $user_id ) || ! is_user_logged_in() ) { 1110 1091 return false; … … 1120 1101 $bp = buddypress(); 1121 1102 1122 // Mark each as spam 1103 // Mark each as spam. 1123 1104 foreach ( (array) $activities['activities'] as $activity ) { 1124 1105 1125 // Create an activity object 1106 // Create an activity object. 1126 1107 $activity_obj = new BP_Activity_Activity; 1127 1108 foreach ( $activity as $k => $v ) { … … 1129 1110 } 1130 1111 1131 // Mark as spam 1112 // Mark as spam. 1132 1113 bp_activity_mark_as_spam( $activity_obj ); 1133 1114 … … 1143 1124 } 1144 1125 1145 // Tidy up 1126 // Tidy up. 1146 1127 unset( $activity_obj ); 1147 1128 } 1148 1129 1149 // Mark all of this user's activities as spam 1130 // Mark all of this user's activities as spam. 1150 1131 $wpdb->query( $wpdb->prepare( "UPDATE {$bp->activity->table_name} SET is_spam = 1 WHERE user_id = %d", $user_id ) ); 1151 1132 … … 1170 1151 * 1171 1152 * @param int $user_id ID of the user whose activity is being hammed. 1172 *1173 1153 * @return bool 1174 1154 */ … … 1176 1156 global $wpdb; 1177 1157 1178 // Do not delete user data unless a logged in user says so 1158 // Do not delete user data unless a logged in user says so. 1179 1159 if ( empty( $user_id ) || ! is_user_logged_in() ) { 1180 1160 return false; … … 1191 1171 $bp = buddypress(); 1192 1172 1193 // Mark each as not spam 1173 // Mark each as not spam. 1194 1174 foreach ( (array) $activities['activities'] as $activity ) { 1195 1175 1196 // Create an activity object 1176 // Create an activity object. 1197 1177 $activity_obj = new BP_Activity_Activity; 1198 1178 foreach ( $activity as $k => $v ) { … … 1200 1180 } 1201 1181 1202 // Mark as not spam 1182 // Mark as not spam. 1203 1183 bp_activity_mark_as_ham( $activity_obj ); 1204 1184 … … 1214 1194 } 1215 1195 1216 // Tidy up 1196 // Tidy up. 1217 1197 unset( $activity_obj ); 1218 1198 } 1219 1199 1220 // Mark all of this user's activities as not spam 1200 // Mark all of this user's activities as not spam. 1221 1201 $wpdb->query( $wpdb->prepare( "UPDATE {$bp->activity->table_name} SET is_spam = 0 WHERE user_id = %d", $user_id ) ); 1222 1202 … … 1276 1256 * 1277 1257 * @param object $activity Activity data object. 1278 *1279 1258 * @return string|bool Returns false if no callback is found, otherwise returns 1280 1259 * the formatted action string. … … 1282 1261 function bp_activity_generate_action_string( $activity ) { 1283 1262 1284 // Check for valid input 1263 // Check for valid input. 1285 1264 if ( empty( $activity->component ) || empty( $activity->type ) ) { 1286 1265 return false; 1287 1266 } 1288 1267 1289 // Check for registered format callback 1268 // Check for registered format callback. 1290 1269 $actions = bp_activity_get_actions(); 1291 1270 if ( empty( $actions->{$activity->component}->{$activity->type}['format_callback'] ) ) { … … 1293 1272 } 1294 1273 1295 // We apply the format_callback as a filter 1274 // We apply the format_callback as a filter. 1296 1275 add_filter( 'bp_activity_generate_action_string', $actions->{$activity->component}->{$activity->type}['format_callback'], 10, 2 ); 1297 1276 … … 1306 1285 $action = apply_filters( 'bp_activity_generate_action_string', $activity->action, $activity ); 1307 1286 1308 // Remove the filter for future activity items 1287 // Remove the filter for future activity items. 1309 1288 remove_filter( 'bp_activity_generate_action_string', $actions->{$activity->component}->{$activity->type}['format_callback'], 10, 2 ); 1310 1289 … … 1319 1298 * @param string $action Static activity action. 1320 1299 * @param object $activity Activity data object. 1321 * 1322 * @return string 1300 * @return string $action 1323 1301 */ 1324 1302 function bp_activity_format_activity_action_activity_update( $action, $activity ) { … … 1343 1321 * @param string $action Static activity action. 1344 1322 * @param object $activity Activity data object. 1345 * 1346 * @return string 1323 * @return string $action 1347 1324 */ 1348 1325 function bp_activity_format_activity_action_activity_comment( $action, $activity ) { … … 1367 1344 * @param string $action Static activity action. 1368 1345 * @param object $activity Activity data object. 1369 * 1370 * @return string 1346 * @return string $action 1371 1347 */ 1372 1348 function bp_activity_format_activity_action_custom_post_type_post( $action, $activity ) { … … 1418 1394 } 1419 1395 1420 /* *****************************************************************************1396 /* 1421 1397 * Business functions are where all the magic happens in BuddyPress. They will 1422 1398 * handle the actual saving or manipulation of information. Usually they will … … 1428 1404 * Retrieve an activity or activities. 1429 1405 * 1430 * bp_activity_get() shares all arguments with BP_Activity_Activity::get(). The1431 * following is a list of bp_activity_get() parameters that have different1406 * The bp_activity_get() function shares all arguments with BP_Activity_Activity::get(). 1407 * The following is a list of bp_activity_get() parameters that have different 1432 1408 * default values from BP_Activity_Activity::get() (value in parentheses is 1433 1409 * the default for the bp_activity_get()). … … 1446 1422 * 1447 1423 * @param array|string $args See BP_Activity_Activity::get() for description. 1448 *1449 1424 * @return array $activity See BP_Activity_Activity::get() for description. 1450 1425 */ … … 1464 1439 'filter_query' => false, 1465 1440 'show_hidden' => false, // Show activity items that are hidden site-wide? 1466 'exclude' => false, // Comma-separated list of activity IDs to exclude 1467 'in' => false, // Comma-separated list or array of activity IDs to which you want to limit the query 1441 'exclude' => false, // Comma-separated list of activity IDs to exclude. 1442 'in' => false, // Comma-separated list or array of activity IDs to which you 1443 // want to limit the query. 1468 1444 'spam' => 'ham_only', // 'ham_only' (default), 'spam_only' or 'all'. 1469 1445 'update_meta_cache' => true, … … 1474 1450 * Pass filters as an array -- all filter items can be multiple values comma separated: 1475 1451 * array( 1476 * 'user_id' => false, // user_id to filter on1477 * 'object' => false, // object to filter on e.g. groups, profile, status, friends1478 * 'action' => false, // action to filter on e.g. activity_update, profile_updated1479 * 'primary_id' => false, // object ID to filter on e.g. a group_id or forum_id or blog_id etc.1480 * 'secondary_id' => false, // secondary object ID to filter on e.g. a post_id1452 * 'user_id' => false, // User ID to filter on. 1453 * 'object' => false, // Object to filter on e.g. groups, profile, status, friends. 1454 * 'action' => false, // Action to filter on e.g. activity_update, profile_updated. 1455 * 'primary_id' => false, // Object ID to filter on e.g. a group_id or forum_id or blog_id etc. 1456 * 'secondary_id' => false, // Secondary object ID to filter on e.g. a post_id. 1481 1457 * ); 1482 1458 */ … … 1558 1534 * except for the following: 1559 1535 * @type string|int|array Single activity ID, comma-separated list of IDs, 1560 * or array of IDs.1536 * or array of IDs. 1561 1537 * } 1562 1538 * @return array $activity See BP_Activity_Activity::get() for description. … … 1566 1542 $r = bp_parse_args( $args, array( 1567 1543 'activity_ids' => false, // A single activity_id or array of IDs. 1568 'display_comments' => false, // true or false to display threaded comments for these specific activity items1569 'max' => false, // Maximum number of results to return 1570 'page' => 1, // page 1 without a per_page will result in no pagination.1571 'per_page' => false, // results per page1572 'show_hidden' => true, // When fetching specific items, show all 1573 'sort' => 'DESC', // sort ASC or DESC1574 'spam' => 'ham_only', // Retrieve items marked as spam 1544 'display_comments' => false, // True or false to display threaded comments for these specific activity items. 1545 'max' => false, // Maximum number of results to return. 1546 'page' => 1, // Page 1 without a per_page will result in no pagination. 1547 'per_page' => false, // Results per page. 1548 'show_hidden' => true, // When fetching specific items, show all. 1549 'sort' => 'DESC', // Sort ASC or DESC 1550 'spam' => 'ham_only', // Retrieve items marked as spam. 1575 1551 'update_meta_cache' => true, 1576 1552 ) ); … … 1650 1626 'action' => '', // The activity action - e.g. "Jon Doe posted an update" 1651 1627 'content' => '', // Optional: The content of the activity item e.g. "BuddyPress is awesome guys!" 1652 'component' => false, // The name/ID of the component e.g. groups, profile, mycomponent 1653 'type' => false, // The activity type e.g. activity_update, profile_updated 1654 'primary_link' => '', // Optional: The primary URL for this item in RSS feeds (defaults to activity permalink) 1628 'component' => false, // The name/ID of the component e.g. groups, profile, mycomponent. 1629 'type' => false, // The activity type e.g. activity_update, profile_updated. 1630 'primary_link' => '', // Optional: The primary URL for this item in RSS feeds (defaults to activity permalink). 1655 1631 'user_id' => bp_loggedin_user_id(), // Optional: The user to record the activity for, can be false if this activity is not for a user. 1656 'item_id' => false, // Optional: The ID of the specific item being recorded, e.g. a blog_id 1657 'secondary_item_id' => false, // Optional: A second ID used to further filter e.g. a comment_id 1658 'recorded_time' => bp_core_current_time(), // The GMT time that this activity was recorded 1632 'item_id' => false, // Optional: The ID of the specific item being recorded, e.g. a blog_id. 1633 'secondary_item_id' => false, // Optional: A second ID used to further filter e.g. a comment_id. 1634 'recorded_time' => bp_core_current_time(), // The GMT time that this activity was recorded. 1659 1635 'hide_sitewide' => false, // Should this be hidden on the sitewide activity stream? 1660 1636 'is_spam' => false, // Is this activity item to be marked as spam? 1661 1637 ), 'activity_add' ); 1662 1638 1663 // Make sure we are backwards compatible 1639 // Make sure we are backwards compatible. 1664 1640 if ( empty( $r['component'] ) && !empty( $r['component_name'] ) ) { 1665 1641 $r['component'] = $r['component_name']; … … 1670 1646 } 1671 1647 1672 // Setup activity to be added 1648 // Setup activity to be added. 1673 1649 $activity = new BP_Activity_Activity( $r['id'] ); 1674 1650 $activity->user_id = $r['user_id']; … … 1690 1666 } 1691 1667 1692 // If this is an activity comment, rebuild the tree 1668 // If this is an activity comment, rebuild the tree. 1693 1669 if ( 'activity_comment' === $activity->type ) { 1694 // Also clear the comment cache for the parent activity ID 1670 // Also clear the comment cache for the parent activity ID. 1695 1671 wp_cache_delete( $activity->item_id, 'bp_activity_comments' ); 1696 1672 … … 1749 1725 } 1750 1726 1751 // Record this on the user's profile 1727 // Record this on the user's profile. 1752 1728 $activity_content = $r['content']; 1753 1729 $primary_link = bp_core_get_userlink( $r['user_id'], false, true ); … … 1771 1747 $add_primary_link = apply_filters( 'bp_activity_new_update_primary_link', $primary_link ); 1772 1748 1773 // Now write the values 1749 // Now write the values. 1774 1750 $activity_id = bp_activity_add( array( 1775 1751 'user_id' => $r['user_id'], … … 1815 1791 * @since 2.2.0 1816 1792 * 1817 * @param int $post_id ID of the new post. 1818 * @param WP_Post $post Post object. 1819 * @param int $user_id ID of the post author. 1820 * 1793 * @param int $post_id ID of the new post. 1794 * @param WP_Post $post Post object. 1795 * @param int $user_id ID of the post author. 1821 1796 * @return int|bool The ID of the activity on success. False on error. 1822 1797 */ … … 1953 1928 * @since 2.2.0 1954 1929 * 1955 * @param WP_Post $post Post item. 1956 * 1957 * @return bool True on success, false on failure. 1930 * @param WP_Post $post Post item. 1931 * @return bool True on success, false on failure. 1958 1932 */ 1959 1933 function bp_activity_post_type_update( $post = null ) { … … 2024 1998 * @param int $post_id ID of the post being unpublished. 2025 1999 * @param WP_Post $post Post object. 2026 * 2027 * @return bool True on success, false on failure. 2000 * @return bool True on success, false on failure. 2028 2001 */ 2029 2002 function bp_activity_post_type_unpublish( $post_id = 0, $post = null ) { … … 2033 2006 } 2034 2007 2035 // Get the post type tracking args 2008 // Get the post type tracking args. 2036 2009 $activity_post_object = bp_activity_get_post_type_tracking_args( $post->post_type ); 2037 2010 … … 2106 2079 'content' => false, 2107 2080 'user_id' => bp_loggedin_user_id(), 2108 'activity_id' => false, // ID of the root activity item 2109 'parent_id' => false // ID of a parent comment (optional) 2081 'activity_id' => false, // ID of the root activity item. 2082 'parent_id' => false // ID of a parent comment (optional). 2110 2083 ) ); 2111 2084 2112 // Bail if missing necessary data 2085 // Bail if missing necessary data. 2113 2086 if ( empty( $r['content'] ) || empty( $r['user_id'] ) || empty( $r['activity_id'] ) ) { 2114 2087 $errors->add( 'missing_data', $feedback ); … … 2118 2091 } 2119 2092 2120 // Maybe set current activity ID as the parent 2093 // Maybe set current activity ID as the parent. 2121 2094 if ( empty( $r['parent_id'] ) ) { 2122 2095 $r['parent_id'] = $r['activity_id']; … … 2125 2098 $activity_id = $r['activity_id']; 2126 2099 2127 // Get the parent activity 2100 // Get the parent activity. 2128 2101 $activity = new BP_Activity_Activity( $activity_id ); 2129 2102 2130 // Bail if the parent activity does not exist 2103 // Bail if the parent activity does not exist. 2131 2104 if ( empty( $activity->date_recorded ) ) { 2132 2105 $errors->add( 'missing_activity', __( 'Sorry, the item you are replying to no longer exists.', 'buddypress' ) ); … … 2148 2121 $comment_content = apply_filters( 'bp_activity_comment_content', $r['content'] ); 2149 2122 2150 // Insert the activity comment 2123 // Insert the activity comment. 2151 2124 $comment_id = bp_activity_add( array( 2152 2125 'id' => $r['id'], … … 2160 2133 ) ); 2161 2134 2162 // Comment caches are stored only with the top-level item 2135 // Comment caches are stored only with the top-level item. 2163 2136 wp_cache_delete( $activity_id, 'bp_activity_comments' ); 2164 2137 2165 // Walk the tree to clear caches for all parent items 2138 // Walk the tree to clear caches for all parent items. 2166 2139 $clear_id = $r['parent_id']; 2167 2140 while ( $clear_id != $activity_id ) { … … 2202 2175 * 2203 2176 * @param array|string $args See BP_Activity_Activity::get() for description. 2204 *2205 2177 * @return int $activity_id The ID of the activity item found. 2206 2178 */ … … 2268 2240 * the same as BP_Activity_Activity::get(). 2269 2241 * See that method for a description. 2270 *2271 2242 * @return bool True on success, false on failure. 2272 2243 */ 2273 2244 function bp_activity_delete( $args = '' ) { 2274 2245 2275 // Pass one or more the of following variables to delete by those variables 2246 // Pass one or more the of following variables to delete by those variables. 2276 2247 $args = bp_parse_args( $args, array( 2277 2248 'id' => false, … … 2297 2268 do_action( 'bp_before_activity_delete', $args ); 2298 2269 2299 // Adjust the new mention count of any mentioned member 2270 // Adjust the new mention count of any mentioned member. 2300 2271 bp_activity_adjust_mention_count( $args['id'], 'delete' ); 2301 2272 … … 2305 2276 } 2306 2277 2307 // Check if the user's latest update has been deleted 2278 // Check if the user's latest update has been deleted. 2308 2279 $user_id = empty( $args['user_id'] ) 2309 2280 ? bp_loggedin_user_id() … … 2353 2324 * @param array|string $args See BP_Activity_Activity::get for a 2354 2325 * description of accepted arguments. 2355 *2356 2326 * @return bool True on success, false on failure. 2357 2327 */ … … 2377 2347 * 2378 2348 * @param int $activity_id ID of the activity item to be deleted. 2379 *2380 2349 * @return bool True on success, false on failure. 2381 2350 */ … … 2398 2367 * @param string $component The activity component. 2399 2368 * @param string $type The activity type. 2400 *2401 2369 * @return bool True on success, false on failure. 2402 2370 */ … … 2422 2390 * @param int $user_id The user id. 2423 2391 * @param string $component The activity component. 2424 *2425 2392 * @return bool True on success, false on failure. 2426 2393 */ … … 2450 2417 * oldest ancestor. 2451 2418 * @param int $comment_id The ID of the comment to be deleted. 2452 *2453 2419 * @return bool True on success, false on failure. 2454 2420 */ … … 2474 2440 bp_activity_delete_children( $activity_id, $comment_id ); 2475 2441 2476 // Delete the actual comment 2442 // Delete the actual comment. 2477 2443 if ( ! bp_activity_delete( array( 'id' => $comment_id, 'type' => 'activity_comment' ) ) ) { 2478 2444 return false; 2479 2445 } 2480 2446 2481 // Purge comment cache for the root activity update 2447 // Purge comment cache for the root activity update. 2482 2448 wp_cache_delete( $activity_id, 'bp_activity_comments' ); 2483 2449 2484 // Recalculate the comment tree 2450 // Recalculate the comment tree. 2485 2451 BP_Activity_Activity::rebuild_activity_comment_tree( $activity_id ); 2486 2452 … … 2513 2479 function bp_activity_delete_children( $activity_id, $comment_id ) { 2514 2480 2515 // Get activity children to delete 2481 // Get activity children to delete. 2516 2482 $children = BP_Activity_Activity::get_child_comments( $comment_id ); 2517 2483 … … 2523 2489 } 2524 2490 2525 // Delete the comment itself 2491 // Delete the comment itself. 2526 2492 bp_activity_delete( array( 2527 2493 'secondary_item_id' => $comment_id, … … 2547 2513 * @param int $activity_id The unique id of the activity object. 2548 2514 * @param object|bool $activity_obj Optional. The activity object. 2549 *2550 2515 * @return string $link Permalink for the activity item. 2551 2516 */ … … 2600 2565 * 2601 2566 * @param int $user_id The ID of the user whose activity is being hidden. 2602 *2603 2567 * @return bool True on success, false on failure. 2604 2568 */ … … 2629 2593 * @param array|bool $args Optional. The args passed to the activity 2630 2594 * creation function (eg bp_blogs_record_activity()). 2631 *2632 2595 * @return string $content The content with images stripped and replaced with a 2633 2596 * single thumb. … … 2637 2600 preg_match_all( '/<img[^>]*>/Ui', $content, $matches ); 2638 2601 2639 // Remove <img> tags. Also remove caption shortcodes and caption text if present 2602 // Remove <img> tags. Also remove caption shortcodes and caption text if present. 2640 2603 $content = preg_replace('|(\[caption(.*?)\])?<img[^>]*>([^\[\[]*\[\/caption\])?|', '', $content ); 2641 2604 2642 2605 if ( !empty( $matches ) && !empty( $matches[0] ) ) { 2643 2606 2644 // Get the SRC value 2607 // Get the SRC value. 2645 2608 preg_match( '/<img.*?(src\=[\'|"]{0,1}.*?[\'|"]{0,1})[\s|>]{1}/i', $matches[0][0], $src ); 2646 2609 2647 // Get the width and height 2610 // Get the width and height. 2648 2611 preg_match( '/<img.*?(height\=[\'|"]{0,1}.*?[\'|"]{0,1})[\s|>]{1}/i', $matches[0][0], $height ); 2649 2612 preg_match( '/<img.*?(width\=[\'|"]{0,1}.*?[\'|"]{0,1})[\s|>]{1}/i', $matches[0][0], $width ); … … 2702 2665 * @param array $activity The data passed to bp_activity_add() or the values 2703 2666 * from an Activity obj. 2704 * 2705 * @return string 2667 * @return string $summary 2706 2668 */ 2707 2669 function bp_activity_create_summary( $content, $activity ) { … … 2886 2848 $activity->is_spam = 1; 2887 2849 2888 // Clear the activity stream first page cache 2850 // Clear the activity stream first page cache. 2889 2851 wp_cache_delete( 'bp_activity_sitewide_front', 'bp' ); 2890 2852 2891 // Clear the activity comment cache for this activity item 2853 // Clear the activity comment cache for this activity item. 2892 2854 wp_cache_delete( $activity->id, 'bp_activity_comments' ); 2893 2855 2894 // If Akismet is active, and this was a manual spam/ham request, stop Akismet checking the activity 2856 // If Akismet is active, and this was a manual spam/ham request, stop Akismet checking the activity. 2895 2857 if ( 'by_a_person' == $source && !empty( $bp->activity->akismet ) ) { 2896 2858 remove_action( 'bp_activity_before_save', array( $bp->activity->akismet, 'check_activity' ), 4, 1 ); 2897 2859 2898 // Build data package for Akismet 2860 // Build data package for Akismet. 2899 2861 $activity_data = BP_Akismet::build_akismet_data_package( $activity ); 2900 2862 2901 // Tell Akismet this is spam 2863 // Tell Akismet this is spam. 2902 2864 $activity_data = $bp->activity->akismet->send_akismet_request( $activity_data, 'submit', 'spam' ); 2903 2865 2904 // Update meta 2866 // Update meta. 2905 2867 add_action( 'bp_activity_after_save', array( $bp->activity->akismet, 'update_activity_spam_meta' ), 1, 1 ); 2906 2868 } … … 2933 2895 $activity->is_spam = 0; 2934 2896 2935 // Clear the activity stream first page cache 2897 // Clear the activity stream first page cache. 2936 2898 wp_cache_delete( 'bp_activity_sitewide_front', 'bp' ); 2937 2899 2938 // Clear the activity comment cache for this activity item 2900 // Clear the activity comment cache for this activity item. 2939 2901 wp_cache_delete( $activity->id, 'bp_activity_comments' ); 2940 2902 2941 // If Akismet is active, and this was a manual spam/ham request, stop Akismet checking the activity 2903 // If Akismet is active, and this was a manual spam/ham request, stop Akismet checking the activity. 2942 2904 if ( 'by_a_person' == $source && !empty( $bp->activity->akismet ) ) { 2943 2905 remove_action( 'bp_activity_before_save', array( $bp->activity->akismet, 'check_activity' ), 4, 1 ); 2944 2906 2945 // Build data package for Akismet 2907 // Build data package for Akismet. 2946 2908 $activity_data = BP_Akismet::build_akismet_data_package( $activity ); 2947 2909 2948 // Tell Akismet this is spam 2910 // Tell Akismet this is spam. 2949 2911 $activity_data = $bp->activity->akismet->send_akismet_request( $activity_data, 'submit', 'ham' ); 2950 2912 2951 // Update meta 2913 // Update meta. 2952 2914 add_action( 'bp_activity_after_save', array( $bp->activity->akismet, 'update_activity_ham_meta' ), 1, 1 ); 2953 2915 } … … 3072 3034 * @param int $id The ID of the activity item. 3073 3035 * @param string $cachekey The cache key generated in BP_Embed::parse_oembed(). 3074 *3075 3036 * @return mixed The cached embeds for this activity item. 3076 3037 */ … … 3093 3054 * @param string $cachekey The cache key generated in BP_Embed::parse_oembed(). 3094 3055 * @param int $id The ID of the activity item. 3095 *3096 * @return bool True on success, false on failure.3097 3056 */ 3098 3057 function bp_embed_activity_save_cache( $cache, $cachekey, $id ) {
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)