| 900 | |
| 901 | /** |
| 902 | * Finds and exports friendship data associated with an email address. |
| 903 | * |
| 904 | * @since 4.0.0 |
| 905 | * |
| 906 | * @param string $email_address The user's email address. |
| 907 | * @param int $page Batch number. |
| 908 | * @return array An array of personal data. |
| 909 | */ |
| 910 | function bp_friends_personal_data_exporter( $email_address, $page ) { |
| 911 | $number = 50; |
| 912 | |
| 913 | $email_address = trim( $email_address ); |
| 914 | |
| 915 | $data_to_export = array(); |
| 916 | |
| 917 | $user = get_user_by( 'email', $email_address ); |
| 918 | |
| 919 | if ( ! $user ) { |
| 920 | return array( |
| 921 | 'data' => array(), |
| 922 | 'done' => true, |
| 923 | ); |
| 924 | } |
| 925 | |
| 926 | $friendships = BP_Friends_Friendship::get_friendships( $user->ID, array( |
| 927 | 'is_confirmed' => true, |
| 928 | 'page' => $page, |
| 929 | 'per_page' => $number, |
| 930 | ) ); |
| 931 | |
| 932 | $user_data_to_export = array(); |
| 933 | |
| 934 | foreach ( $friendships as $friendship ) { |
| 935 | if ( (int) $user->ID === (int) $friendship->initiator_user_id ) { |
| 936 | $friend_id = $friendship->friend_user_id; |
| 937 | $user_is_initiator = true; |
| 938 | } else { |
| 939 | $friend_id = $friendship->initiator_user_id; |
| 940 | $user_is_initiator = false; |
| 941 | } |
| 942 | |
| 943 | $item_data = array( |
| 944 | array( |
| 945 | 'name' => __( 'Friend', 'buddypress' ), |
| 946 | 'value' => bp_core_get_userlink( $friend_id ), |
| 947 | ), |
| 948 | array( |
| 949 | 'name' => __( 'Initiated By Me', 'buddypress' ), |
| 950 | 'value' => $user_is_initiator ? __( 'Yes', 'buddypress' ) : __( 'No', 'buddypress' ), |
| 951 | ), |
| 952 | array( |
| 953 | 'name' => __( 'Friendship Date', 'buddypress' ), |
| 954 | 'value' => $friendship->date_created, |
| 955 | ), |
| 956 | ); |
| 957 | |
| 958 | $data_to_export[] = array( |
| 959 | 'group_id' => 'bp_friends', |
| 960 | 'group_label' => __( 'Friends', 'buddypress' ), |
| 961 | 'item_id' => "bp-friends-{$friend_id}", |
| 962 | 'data' => $item_data, |
| 963 | ); |
| 964 | } |
| 965 | |
| 966 | // Tell core if we have more items to process. |
| 967 | $done = count( $friendships ) < $number; |
| 968 | |
| 969 | return array( |
| 970 | 'data' => $data_to_export, |
| 971 | 'done' => $done, |
| 972 | ); |
| 973 | } |
| 974 | |
| 975 | /** |
| 976 | * Finds and exports pending sent friendship request data associated with an email address. |
| 977 | * |
| 978 | * @since 4.0.0 |
| 979 | * |
| 980 | * @param string $email_address The user's email address. |
| 981 | * @param int $page Batch number. |
| 982 | * @return array An array of personal data. |
| 983 | */ |
| 984 | function bp_friends_pending_sent_requests_personal_data_exporter( $email_address, $page ) { |
| 985 | $number = 50; |
| 986 | |
| 987 | $email_address = trim( $email_address ); |
| 988 | |
| 989 | $data_to_export = array(); |
| 990 | |
| 991 | $user = get_user_by( 'email', $email_address ); |
| 992 | |
| 993 | if ( ! $user ) { |
| 994 | return array( |
| 995 | 'data' => array(), |
| 996 | 'done' => true, |
| 997 | ); |
| 998 | } |
| 999 | |
| 1000 | $friendships = BP_Friends_Friendship::get_friendships( $user->ID, array( |
| 1001 | 'is_confirmed' => false, |
| 1002 | 'initiator_user_id' => $user->ID, |
| 1003 | 'page' => $page, |
| 1004 | 'per_page' => $number, |
| 1005 | ) ); |
| 1006 | |
| 1007 | $user_data_to_export = array(); |
| 1008 | |
| 1009 | foreach ( $friendships as $friendship ) { |
| 1010 | $item_data = array( |
| 1011 | array( |
| 1012 | 'name' => __( 'Recipient', 'buddypress' ), |
| 1013 | 'value' => bp_core_get_userlink( $friendship->friend_user_id ), |
| 1014 | ), |
| 1015 | array( |
| 1016 | 'name' => __( 'Date Sent', 'buddypress' ), |
| 1017 | 'value' => $friendship->date_created, |
| 1018 | ), |
| 1019 | ); |
| 1020 | |
| 1021 | $data_to_export[] = array( |
| 1022 | 'group_id' => 'bp_friends_pending_sent_requests', |
| 1023 | 'group_label' => __( 'Pending Friend Requests (Sent)', 'buddypress' ), |
| 1024 | 'item_id' => "bp-friends-pending-sent-request-{$friendship->friend_user_id}", |
| 1025 | 'data' => $item_data, |
| 1026 | ); |
| 1027 | } |
| 1028 | |
| 1029 | // Tell core if we have more items to process. |
| 1030 | $done = count( $friendships ) < $number; |
| 1031 | |
| 1032 | return array( |
| 1033 | 'data' => $data_to_export, |
| 1034 | 'done' => $done, |
| 1035 | ); |
| 1036 | } |
| 1037 | |
| 1038 | /** |
| 1039 | * Finds and exports pending received friendship request data associated with an email address. |
| 1040 | * |
| 1041 | * @since 4.0.0 |
| 1042 | * |
| 1043 | * @param string $email_address The user's email address. |
| 1044 | * @param int $page Batch number. |
| 1045 | * @return array An array of personal data. |
| 1046 | */ |
| 1047 | function bp_friends_pending_received_requests_personal_data_exporter( $email_address, $page ) { |
| 1048 | $number = 50; |
| 1049 | |
| 1050 | $email_address = trim( $email_address ); |
| 1051 | |
| 1052 | $data_to_export = array(); |
| 1053 | |
| 1054 | $user = get_user_by( 'email', $email_address ); |
| 1055 | |
| 1056 | if ( ! $user ) { |
| 1057 | return array( |
| 1058 | 'data' => array(), |
| 1059 | 'done' => true, |
| 1060 | ); |
| 1061 | } |
| 1062 | |
| 1063 | $friendships = BP_Friends_Friendship::get_friendships( $user->ID, array( |
| 1064 | 'is_confirmed' => false, |
| 1065 | 'friend_user_id' => $user->ID, |
| 1066 | 'page' => $page, |
| 1067 | 'per_page' => $number, |
| 1068 | ) ); |
| 1069 | |
| 1070 | $user_data_to_export = array(); |
| 1071 | |
| 1072 | foreach ( $friendships as $friendship ) { |
| 1073 | $item_data = array( |
| 1074 | array( |
| 1075 | 'name' => __( 'Requester', 'buddypress' ), |
| 1076 | 'value' => bp_core_get_userlink( $friendship->initiator_user_id ), |
| 1077 | ), |
| 1078 | array( |
| 1079 | 'name' => __( 'Date Sent', 'buddypress' ), |
| 1080 | 'value' => $friendship->date_created, |
| 1081 | ), |
| 1082 | ); |
| 1083 | |
| 1084 | $data_to_export[] = array( |
| 1085 | 'group_id' => 'bp_friends_pending_received_requests', |
| 1086 | 'group_label' => __( 'Pending Friend Requests (Received)', 'buddypress' ), |
| 1087 | 'item_id' => "bp-friends-pending-received-request-{$friendship->initiator_user_id}", |
| 1088 | 'data' => $item_data, |
| 1089 | ); |
| 1090 | } |
| 1091 | |
| 1092 | // Tell core if we have more items to process. |
| 1093 | $done = count( $friendships ) < $number; |
| 1094 | |
| 1095 | return array( |
| 1096 | 'data' => $data_to_export, |
| 1097 | 'done' => $done, |
| 1098 | ); |
| 1099 | } |