function bp_em_group_events_build_sql_conditions($conditions, $args) { if (!empty($args['group']) && is_numeric($args['group'])) { $conditions['group'] = "( `group_id`={$args['group']} )"; } elseif (!empty($args['group']) && $args['group'] == 'my') { $groups = groups_get_user_groups(get_current_user_id()); if (count($groups) > 0) { $conditions['group'] = "( `group_id` IN (" . implode(',', $groups['groups']) . ") )"; } } //deal with private groups and events if (is_user_logged_in()) { global $wpdb; //find out what private groups they belong to, and don't show private group events not in their memberships $group_ids = BP_Groups_Member::get_group_ids(get_current_user_id()); if ($group_ids['total'] > 0) { $conditions['group_privacy'] = "(`event_private`=0 OR (`event_private`=1 AND (`group_id` IS NULL OR `group_id` = 0)) OR (`event_private`=1 AND `group_id` IN (" . implode(',', $group_ids['groups']) . ")))"; } else { //find out what private groups they belong to, and don't show private group events not in their memberships $conditions['group_privacy'] = "(`event_private`=0 OR (`event_private`=1 AND (`group_id` IS NULL OR `group_id` = 0)))"; } } return $conditions; }
/** * @group invite_anyone_group_invite_access_test * * Using this as a proxy for testing every possible combination */ public function test_group_access_test_friends() { $settings = bp_get_option('invite_anyone'); bp_update_option('invite_anyone', array('group_invites_can_admin' => 'friends', 'group_invites_can_group_admin' => 'friends', 'group_invites_can_group_mod' => 'friends', 'group_invites_can_group_member' => 'friends')); unset($GLOBALS['iaoptions']); $g = $this->factory->group->create(); $u1 = $this->factory->user->create(array('role' => 'administrator')); $this->add_user_to_group($u1, $g); $u2 = $this->factory->user->create(); $this->add_user_to_group($u2, $g); $u3 = $this->factory->user->create(); $this->add_user_to_group($u3, $g); $m3 = new BP_Groups_Member($u3, $g); $m3->promote('mod'); $u4 = $this->factory->user->create(); $this->add_user_to_group($u4, $g); $m4 = new BP_Groups_Member($u4, $g); $m4->promote('admin'); $user = new WP_User($u1); $this->assertSame('friends', invite_anyone_group_invite_access_test($g, $u1)); $this->assertSame('friends', invite_anyone_group_invite_access_test($g, $u2)); $this->assertSame('friends', invite_anyone_group_invite_access_test($g, $u3)); $this->assertSame('friends', invite_anyone_group_invite_access_test($g, $u4)); bp_update_option('invite_anyone', $settings); }
function groups_notification_group_updated($group_id) { global $bp; $group = new BP_Groups_Group($group_id); $sitename = wp_specialchars_decode(get_blog_option(bp_get_root_blog_id(), 'blogname'), ENT_QUOTES); $subject = '[' . $sitename . '] ' . __('Group Details Updated', 'buddypress'); $user_ids = BP_Groups_Member::get_group_member_ids($group->id); foreach ((array) $user_ids as $user_id) { if ('no' == bp_get_user_meta($user_id, 'notification_groups_group_updated', true)) { continue; } $ud = bp_core_get_core_userdata($user_id); // Set up and send the message $to = $ud->user_email; $group_link = site_url(bp_get_groups_root_slug() . '/' . $group->slug); $settings_slug = function_exists('bp_get_settings_slug') ? bp_get_settings_slug() : 'settings'; $settings_link = bp_core_get_user_domain($user_id) . $settings_slug . '/notifications/'; $message = sprintf(__('Group details for the group "%1$s" were updated: To view the group: %2$s --------------------- ', 'buddypress'), $group->name, $group_link); $message .= sprintf(__('To disable these notifications please log in and go to: %s', 'buddypress'), $settings_link); /* Send the message */ $to = apply_filters('groups_notification_group_updated_to', $to); $subject = apply_filters_ref_array('groups_notification_group_updated_subject', array($subject, &$group)); $message = apply_filters_ref_array('groups_notification_group_updated_message', array($message, &$group, $group_link, $settings_link)); wp_mail($to, $subject, $message); unset($message, $to); } do_action('bp_groups_sent_updated_email', $user_ids, $subject, '', $group_id); }
function groups_notification_group_updated($group_id) { $group = groups_get_group(array('group_id' => $group_id)); $subject = bp_get_email_subject(array('text' => __('Group Details Updated', 'buddypress'))); $user_ids = BP_Groups_Member::get_group_member_ids($group->id); foreach ((array) $user_ids as $user_id) { if ('no' == bp_get_user_meta($user_id, 'notification_groups_group_updated', true)) { continue; } $ud = bp_core_get_core_userdata($user_id); // Set up and send the message $to = $ud->user_email; $group_link = bp_get_group_permalink($group); $settings_slug = function_exists('bp_get_settings_slug') ? bp_get_settings_slug() : 'settings'; $settings_link = bp_core_get_user_domain($user_id) . $settings_slug . '/notifications/'; $message = sprintf(__('Group details for the group "%1$s" were updated: To view the group: %2$s --------------------- ', 'buddypress'), $group->name, $group_link); $message .= sprintf(__('To disable these notifications please log in and go to: %s', 'buddypress'), $settings_link); /* Send the message */ $to = apply_filters('groups_notification_group_updated_to', $to); $subject = apply_filters_ref_array('groups_notification_group_updated_subject', array($subject, &$group)); $message = apply_filters_ref_array('groups_notification_group_updated_message', array($message, &$group, $group_link, $settings_link)); wp_mail($to, $subject, $message); unset($message, $to); } do_action('bp_groups_sent_updated_email', $user_ids, $subject, '', $group_id); }
/** * Get a list of a user's groups, as well as those groups of which * the user is an admin or mod * * @since 1.2 */ protected function set_up_user_groups() { $groups = BP_Groups_Member::get_group_ids($this->user_id); $this->user_groups['groups'] = $groups['groups']; $admin_groups = BP_Groups_Member::get_is_admin_of($this->user_id); $mod_groups = BP_Groups_Member::get_is_mod_of($this->user_id); $this->user_groups['admin_mod_of'] = array_merge(wp_list_pluck($admin_groups['groups'], 'id'), wp_list_pluck($mod_groups['groups'], 'id')); }
public function user_member_ids() { if (is_null($this->_user_members)) { if (self::owner_type_group == $this->owner_type) { $this->_user_members = (array) BP_Groups_Member::get_group_member_ids($this->owner_id); } else { $this->_user_members = array($this->owner_id); } } return $this->_user_members; }
/** * Notify all group members when a group is updated. * * @since BuddyPress (1.0.0) * * @param int $group_id ID of the group. * @param BP_Groups_Group $old_group Group before new details were saved. */ function groups_notification_group_updated($group_id = 0, $old_group = null) { $group = groups_get_group(array('group_id' => $group_id)); if ($old_group instanceof BP_Groups_Group) { $changed = array(); if ($group->name !== $old_group->name) { $changed[] = sprintf(_x('* Name changed from "%s" to "%s"', 'Group update email text', 'buddypress'), esc_html($old_group->name), esc_html($group->name)); } if ($group->description !== $old_group->description) { $changed[] = sprintf(_x('* Description changed from "%s" to "%s"', 'Group update email text', 'buddypress'), esc_html($old_group->description), esc_html($group->description)); } } /** * Filters the bullet points listing updated items in the email notification after a group is updated. * * @since BuddyPress (2.2.0) * * @param array $changed Array of bullet points. */ $changed = apply_filters('groups_notification_group_update_updated_items', $changed); $changed_text = ''; if (!empty($changed)) { $changed_text = "\n\n" . implode("\n", $changed); } $subject = bp_get_email_subject(array('text' => __('Group Details Updated', 'buddypress'))); $user_ids = BP_Groups_Member::get_group_member_ids($group->id); foreach ((array) $user_ids as $user_id) { // Continue if member opted out of receiving this email if ('no' === bp_get_user_meta($user_id, 'notification_groups_group_updated', true)) { continue; } $ud = bp_core_get_core_userdata($user_id); // Set up and send the message $to = $ud->user_email; $group_link = bp_get_group_permalink($group); $settings_slug = function_exists('bp_get_settings_slug') ? bp_get_settings_slug() : 'settings'; $settings_link = bp_core_get_user_domain($user_id) . $settings_slug . '/notifications/'; $message = sprintf(__('Group details for the group "%1$s" were updated: %2$s To view the group: %3$s --------------------- ', 'buddypress'), $group->name, $changed_text, $group_link); $message .= sprintf(__('To disable these notifications please log in and go to: %s', 'buddypress'), $settings_link); /* Send the message */ $to = apply_filters('groups_notification_group_updated_to', $to); $subject = apply_filters_ref_array('groups_notification_group_updated_subject', array($subject, &$group)); $message = apply_filters_ref_array('groups_notification_group_updated_message', array($message, &$group, $group_link, $settings_link)); wp_mail($to, $subject, $message); unset($message, $to); } do_action('bp_groups_sent_updated_email', $user_ids, $subject, '', $group_id); }
/** * Notify all group members when a group is updated. * * @since 1.0.0 * * @param int $group_id ID of the group. * @param BP_Groups_Group|null $old_group Group before new details were saved. */ function groups_notification_group_updated($group_id = 0, $old_group = null) { $group = groups_get_group($group_id); if ($old_group instanceof BP_Groups_Group) { $changed = array(); if ($group->name !== $old_group->name) { $changed[] = sprintf(_x('* Name changed from "%s" to "%s".', 'Group update email text', 'buddypress'), esc_html($old_group->name), esc_html($group->name)); } if ($group->description !== $old_group->description) { $changed[] = sprintf(_x('* Description changed from "%s" to "%s".', 'Group update email text', 'buddypress'), esc_html($old_group->description), esc_html($group->description)); } } /** * Filters the bullet points listing updated items in the email notification after a group is updated. * * @since 2.2.0 * * @param array $changed Array of bullet points. */ $changed = apply_filters('groups_notification_group_update_updated_items', $changed); $changed_text = ''; if (!empty($changed)) { $changed_text = implode("\n", $changed); } $user_ids = BP_Groups_Member::get_group_member_ids($group->id); foreach ((array) $user_ids as $user_id) { // Continue if member opted out of receiving this email. if ('no' === bp_get_user_meta($user_id, 'notification_groups_group_updated', true)) { continue; } $unsubscribe_args = array('user_id' => $user_id, 'notification_type' => 'groups-details-updated'); $args = array('tokens' => array('changed_text' => $changed_text, 'group' => $group, 'group.id' => $group_id, 'group.url' => esc_url(bp_get_group_permalink($group)), 'group.name' => $group->name, 'unsubscribe' => esc_url(bp_email_get_unsubscribe_link($unsubscribe_args)))); bp_send_email('groups-details-updated', (int) $user_id, $args); } /** * Fires after the notification is sent that a group has been updated. * * See https://buddypress.trac.wordpress.org/ticket/3644 for blank message parameter. * * @since 1.5.0 * @since 2.5.0 $subject has been unset and is deprecated. * * @param array $user_ids Array of user IDs to notify about the update. * @param string $subject Deprecated in 2.5; now an empty string. * @param string $value Empty string preventing PHP error. * @param int $group_id ID of the group that was updated. */ do_action('bp_groups_sent_updated_email', $user_ids, '', '', $group_id); }
/** * Checks upload permissions. * Adapted from Group Documents plugin. */ function bpfb_documents_allowed($group = false) { if (!$group) { return false; } $user = wp_get_current_user(); $moderator_of = BP_Groups_Member::get_is_admin_of($user->ID) + BP_Groups_Member::get_is_mod_of($user->ID); $moderator_of = is_array($moderator_of) && isset($moderator_of['groups']) ? $moderator_of['groups'] : false; $is_mod = false; foreach ($moderator_of as $gm) { if ($gm->id == $group->id) { $is_mod = true; break; } } switch (get_option('bp_group_documents_upload_permission')) { case 'mods_decide': switch (groups_get_groupmeta($group->id, 'group_documents_upload_permission')) { case 'mods_only': if ($is_mod) { return true; } break; case 'members': default: if (bp_group_is_member($group)) { return true; } break; } break; case 'mods_only': if ($is_mod) { return true; } break; case 'members': default: if (bp_group_is_member($group)) { return true; } break; } return false; }
function groups_notification_group_updated( $group_id ) { global $bp; $group = new BP_Groups_Group( $group_id ); $sitename = wp_specialchars_decode( get_blog_option( BP_ROOT_BLOG, 'blogname' ), ENT_QUOTES ); $subject = '[' . $sitename . '] ' . __( 'Group Details Updated', 'buddypress' ); $user_ids = BP_Groups_Member::get_group_member_ids( $group->id ); foreach ( (array)$user_ids as $user_id ) { if ( 'no' == get_user_meta( $user_id, 'notification_groups_group_updated', true ) ) continue; $ud = bp_core_get_core_userdata( $user_id ); // Set up and send the message $to = $ud->user_email; $group_link = site_url( $bp->groups->slug . '/' . $group->slug ); $settings_link = bp_core_get_user_domain( $user_id ) . BP_SETTINGS_SLUG . '/notifications/'; $message = sprintf( __( 'Group details for the group "%s" were updated: To view the group: %s --------------------- ', 'buddypress' ), $group->name, $group_link ); $message .= sprintf( __( 'To disable these notifications please log in and go to: %s', 'buddypress' ), $settings_link ); /* Send the message */ $to = apply_filters( 'groups_notification_group_updated_to', $to ); $subject = apply_filters( 'groups_notification_group_updated_subject', $subject, &$group ); $message = apply_filters( 'groups_notification_group_updated_message', $message, &$group, $group_link ); wp_mail( $to, $subject, $message ); unset( $message, $to ); } }
public function test_groups_is_user_pending_should_return_true_for_pending_member() { $m = new BP_Groups_Member(); $m->group_id = self::$groups[1]; $m->user_id = self::$user; $m->inviter_id = 0; $m->is_admin = 0; $m->user_title = ''; $m->date_modified = bp_core_current_time(); $m->is_confirmed = 0; $m->comments = 'request'; $m->save(); $this->assertNotEmpty(groups_is_user_pending(self::$user, self::$groups[1])); }
function __construct($group_id, $per_page, $max, $exclude_admins_mods, $exclude_banned, $exclude) { global $bp; $this->pag_page = isset($_REQUEST['mlpage']) ? intval($_REQUEST['mlpage']) : 1; $this->pag_num = isset($_REQUEST['num']) ? intval($_REQUEST['num']) : $per_page; $this->members = BP_Groups_Member::get_all_for_group($group_id, $this->pag_num, $this->pag_page, $exclude_admins_mods, $exclude_banned, $exclude); if (!$max || $max >= (int) $this->members['count']) { $this->total_member_count = (int) $this->members['count']; } else { $this->total_member_count = (int) $max; } $this->members = $this->members['members']; if ($max) { if ($max >= count($this->members)) { $this->member_count = count($this->members); } else { $this->member_count = (int) $max; } } else { $this->member_count = count($this->members); } $this->pag_links = paginate_links(array('base' => add_query_arg('mlpage', '%#%'), 'format' => '', 'total' => ceil($this->total_member_count / $this->pag_num), 'current' => $this->pag_page, 'prev_text' => '←', 'next_text' => '→', 'mid_size' => 1)); }
/** * Invites a friend to join a group via a POST request. * * @since BuddyPress (1.2) * @todo Audit return types */ function bp_legacy_theme_ajax_invite_user() { // Bail if not a POST action if ('POST' !== strtoupper($_SERVER['REQUEST_METHOD'])) { return; } check_ajax_referer('groups_invite_uninvite_user'); if (!$_POST['friend_id'] || !$_POST['friend_action'] || !$_POST['group_id']) { return; } if (!bp_groups_user_can_send_invites($_POST['group_id'])) { return; } if (!friends_check_friendship(bp_loggedin_user_id(), $_POST['friend_id'])) { return; } $group_id = (int) $_POST['group_id']; $friend_id = (int) $_POST['friend_id']; if ('invite' == $_POST['friend_action']) { $group = groups_get_group($group_id); // Users who have previously requested membership do not need // another invitation created for them if (BP_Groups_Member::check_for_membership_request($friend_id, $group_id)) { $user_status = 'is_pending'; // Create the user invitation } elseif (groups_invite_user(array('user_id' => $friend_id, 'group_id' => $group_id))) { $user_status = 'is_invited'; // Miscellaneous failure } else { return; } $user = new BP_Core_User($friend_id); $uninvite_url = bp_is_current_action('create') ? bp_get_groups_directory_permalink() . 'create/step/group-invites/?user_id=' . $friend_id : bp_get_group_permalink($group) . 'send-invites/remove/' . $friend_id; echo '<li id="uid-' . esc_attr($user->id) . '">'; echo $user->avatar_thumb; echo '<h4>' . $user->user_link . '</h4>'; echo '<span class="activity">' . esc_attr($user->last_active) . '</span>'; echo '<div class="action"> <a class="button remove" href="' . wp_nonce_url($uninvite_url, 'groups_invite_uninvite_user') . '" id="uid-' . esc_attr($user->id) . '">' . __('Remove Invite', 'buddypress') . '</a> </div>'; if ('is_pending' == $user_status) { echo '<p class="description">' . sprintf(__('%s has previously requested to join this group. Sending an invitation will automatically add the member to the group.', 'buddypress'), $user->user_link) . '</p>'; } echo '</li>'; exit; } elseif ('uninvite' == $_POST['friend_action']) { // Users who have previously requested membership should not // have their requests deleted on the "uninvite" action if (BP_Groups_Member::check_for_membership_request($friend_id, $group_id)) { return; } // Remove the unsent invitation if (!groups_uninvite_user($friend_id, $group_id)) { return; } exit; } else { return; } }
/** * @group map_meta_cap * @group dissociate_from_group */ public function test_user_can_dissociate_from_group_within_group_mod() { $g = $this->factory->group->create(); $old_current_user = get_current_user_id(); $u1 = $this->factory->user->create(); $gm1 = new BP_Groups_Member($u1, $g); $gm1->promote('admin'); $this->set_current_user($u1); $this->go_to(bp_get_group_permalink(groups_get_group(array('group_id' => $g)))); // $this->go_to( bp_docs_get_doc_link( $post_id ) ); $this->assertTrue(current_user_can('bp_docs_dissociate_from_group')); }
/** * Delete all group membership information for the specified user. * * @since 1.0.0 * * @param int $user_id ID of the user. */ function groups_remove_data_for_user($user_id) { BP_Groups_Member::delete_all_for_user($user_id); /** * Fires after the deletion of all data for a user. * * @since 1.1.0 * * @param int $user_id ID of the user whose data is being deleted. */ do_action('groups_remove_data_for_user', $user_id); }
/** * @group get_group_extras */ public function test_get_group_extras_banned() { $u = $this->factory->user->create(); $g = $this->factory->group->create(); $member = new BP_Groups_Member(); $member->group_id = $g; $member->user_id = $u; $member->date_modified = bp_core_current_time(); $member->is_banned = true; $member->save(); $paged_groups = array(); $paged_groups[] = new stdClass(); $paged_groups[0]->id = $g; $group_ids = array($g); $expected = array(); foreach ($paged_groups as $key => $value) { $expected[$key] = new stdClass(); $expected[$key]->id = $value->id; $expected[$key]->is_member = '0'; $expected[$key]->is_invited = '0'; $expected[$key]->is_pending = '0'; $expected[$key]->is_banned = true; } $old_user = get_current_user_id(); $this->set_current_user($u); $this->assertEquals($expected, BP_Groups_Group::get_group_extras($paged_groups, $group_ids)); $this->set_current_user($old_user); }
/** * Recalculate group counts for each user. * * @since BuddyPress (2.0.0) * * @return array */ function bp_admin_repair_group_count() { global $wpdb; if (!bp_is_active('groups')) { return; } $statement = __('Counting the number of groups for each user… %s', 'buddypress'); $result = __('Failed!', 'buddypress'); $sql_delete = "DELETE FROM {$wpdb->usermeta} WHERE meta_key IN ( 'total_group_count' );"; if (is_wp_error($wpdb->query($sql_delete))) { return array(1, sprintf($statement, $result)); } $bp = buddypress(); // Walk through all users on the site $total_users = $wpdb->get_row("SELECT count(ID) as c FROM {$wpdb->users}")->c; if ($total_users > 0) { $per_query = 500; $offset = 0; while ($offset < $total_users) { // But only bother to update counts for users that have groups $users = $wpdb->get_col($wpdb->prepare("SELECT user_id FROM {$bp->groups->table_name_members} WHERE is_confirmed = 1 AND is_banned = 0 AND user_id > %d AND user_id <= %d", $offset, $offset + $per_query)); foreach ($users as $user) { BP_Groups_Member::refresh_total_group_count_for_user($user); } $offset += $per_query; } } else { return array(2, sprintf($statement, $result)); } return array(0, sprintf($statement, __('Complete!', 'buddypress'))); }
/** * bp_group_documents_email_notificiation() * * This function will send email notifications to users on successful document upload. * For each group memeber, it will check to see the users notification settings first, * if the user has the notifications turned on, they will be sent a formatted email notification. */ function bp_group_documents_email_notification($document) { global $bp; $user_name = bp_core_get_userlink($bp->loggedin_user->id, true); $user_profile_link = bp_core_get_userlink($bp->loggedin_user->id, false, true); $group_name = $bp->groups->current_group->name; $group_link = bp_get_group_permalink($bp->groups->current_group); $document_name = $document->name; $document_link = $document->get_url(); $subject = '[' . get_blog_option(1, 'blogname') . '] ' . sprintf(__('A document was uploaded to %s', 'bp-group-documents'), $bp->groups->current_group->name); //these will be all the emails getting the update //'user_id' => 'user_email $emails = array(); //first get the admin & moderator emails if (count($bp->groups->current_group->admins)) { foreach ($bp->groups->current_group->admins as $user) { if ('no' == get_user_meta($user->user_id, 'notification_group_documents_upload_mod')) { continue; } $emails[$user->user_id] = $user->user_email; } } if (count($bp->groups->current_group->mods)) { foreach ($bp->groups->current_group->mods as $user) { if ('no' == get_user_meta($user->user_id, 'notification_group_documents_upload_mod')) { continue; } if (!in_array($user->user_email, $emails)) { $emails[$user->user_id] = $user->user_email; } } } //now get all member emails, checking to make sure not to send any emails twice $user_ids = BP_Groups_Member::get_group_member_ids($bp->groups->current_group->id); foreach ((array) $user_ids as $user_id) { if ('no' == get_user_meta($user_id, 'notification_group_documents_upload_member')) { continue; } $ud = bp_core_get_core_userdata($user_id); if (!in_array($ud->user_email, $emails)) { $emails[$user_id] = $ud->user_email; } } foreach ($emails as $current_id => $current_email) { $message = sprintf(__('%s uploaded a new file: %s to the group: %s. To see %s\'s profile: %s To see the group %s\'s homepage: %s To download the new document directly: %s ------------------------ ', 'bp-group-documents'), $user_name, $document_name, $group_name, $user_name, $user_profile_link, $group_name, $group_link, $document_link); $settings_link = bp_core_get_user_domain($current_id) . $bp->settings->slug . '/notifications/'; $message .= sprintf(__('To disable these notifications please log in and go to: %s', 'bp-group-documents'), $settings_link); // Set up and send the message $to = $current_email; wp_mail($to, $subject, $message); unset($to, $message); } //end foreach }
/** * gradebook_screen( $vars ) * * Hooks into screen_handler * Adds a UI to assignments for gradebook management. * * @param Array $vars a set of variables received for this screen template * @return Array $vars a set of variable passed to this screen template */ function gradebook_screen($vars) { global $bp; $nonce_name = 'gradebook_nonce'; $nonce_import_name = 'gradebook_import_nonce'; $nonce_clear_name = 'gradebook_clear_nonce'; if (!$this->has_gradebook_caps($bp->loggedin_user->id) && !is_super_admin()) { $vars['die'] = __('BuddyPress Courseware Error while forbidden user tried to manage gradebook.', 'bpsp'); return $vars; } $students = BP_Groups_Member::get_all_for_group($bp->groups->current_group->id); if (isset($_POST['_nxtnonce'])) { $is_nonce = nxt_verify_nonce($_POST['_nxtnonce'], $nonce_name); } if (isset($_POST['_nxtnonce']) && true != $is_nonce) { $vars['die'] = __('BuddyPress Courseware Nonce Error while updating gradebook.', 'bpsp'); return $vars; } $gradebook_id = $this->has_gradebook($this->current_assignment); if (!$gradebook_id) { $vars['die'] = __('BuddyPress Courseware Error while creating gradebook.', 'bpsp'); return $vars; } if (!empty($_POST['grade'])) { foreach ($_POST['grade'] as $grade) { if (!empty($grade) && !empty($grade['uid']) && !empty($grade['value'])) { # If grade was added or updated! $status = $this->save_grade($gradebook_id, $grade); if ($status !== null) { $data = array('grade' => $grade, 'teacher' => $bp->loggedin_user->userdata, 'assignment' => $this->current_assignment); if ($status == true) { do_action('courseware_grade_added', $data); } else { do_action('courseware_grade_updated', $data); } } } } $vars['message'] = __('Gradebook saved.', 'bpsp'); } $vars['name'] = 'gradebook'; $vars['students'] = $students['members']; if (empty($vars['grades'])) { $vars['grades'] = $this->load_grades($gradebook_id, true); } $vars['bpsp_gradebook_format'] = get_option('bpsp_gradebook_format'); $vars['assignment'] = BPSP_Assignments::is_assignment($this->current_assignment); $vars['gradebook_permalink'] = $vars['assignment_permalink'] . '/gradebook'; $vars['clear_gradebook_permalink'] = add_query_arg('_nxtnonce', nxt_create_nonce($nonce_clear_name), $vars['gradebook_permalink'] . '/clear'); $vars['import_gradebook_nonce'] = nxt_nonce_field($nonce_import_name, '_nxtnonce', true, false); $vars['nonce'] = nxt_nonce_field($nonce_name, '_nxtnonce', true, false); return $vars; }
/** * Populates extra fields such as group and friendship counts. */ public function populate_extras() { if (bp_is_active('friends')) { $this->total_friends = BP_Friends_Friendship::total_friend_count($this->id); } if (bp_is_active('groups')) { $this->total_groups = BP_Groups_Member::total_group_count($this->id); $this->total_groups = sprintf(_n('%d group', '%d groups', $this->total_groups, 'buddypress'), $this->total_groups); } }
/** * Get a list of a user's groups, filtered by a search string. * * @param string $filter Search term. Matches against 'name' and * 'description' fields. * @param int $user_id ID of the user whose groups are being searched. * Default: the displayed user. * @param mixed $order Not used. * @param int|null $limit Optional. The max number of results to return. * Default: null (no limit). * @param int|null $page Optional. The page offset of results to return. * Default: null (no limit). * @return false|array { * @type array $groups Array of matched and paginated group objects. * @type int $total Total count of groups matching the query. * } */ public static function filter_user_groups($filter, $user_id = 0, $order = false, $limit = null, $page = null) { global $wpdb; if (empty($user_id)) { $user_id = bp_displayed_user_id(); } $search_terms_like = bp_esc_like($filter) . '%'; $pag_sql = $order_sql = $hidden_sql = ''; if (!empty($limit) && !empty($page)) { $pag_sql = $wpdb->prepare(" LIMIT %d, %d", intval(($page - 1) * $limit), intval($limit)); } // Get all the group ids for the current user's groups. $gids = BP_Groups_Member::get_group_ids($user_id); if (empty($gids['groups'])) { return false; } $bp = buddypress(); $gids = esc_sql(implode(',', wp_parse_id_list($gids['groups']))); $paged_groups = $wpdb->get_results($wpdb->prepare("SELECT id as group_id FROM {$bp->groups->table_name} WHERE ( name LIKE %s OR description LIKE %s ) AND id IN ({$gids}) {$pag_sql}", $search_terms_like, $search_terms_like)); $total_groups = $wpdb->get_var($wpdb->prepare("SELECT COUNT(id) FROM {$bp->groups->table_name} WHERE ( name LIKE %s OR description LIKE %s ) AND id IN ({$gids})", $search_terms_like, $search_terms_like)); return array('groups' => $paged_groups, 'total' => $total_groups); }
function groups_remove_data_for_user($user_id) { global $bp; BP_Groups_Member::delete_all_for_user($user_id); bp_core_delete_notifications_from_user($user_id, $bp->groups->id, 'new_membership_request'); do_action('groups_remove_data_for_user', $user_id); }
function filter_user_groups($filter, $user_id = false, $order = false, $limit = null, $page = null) { global $wpdb, $bp; if (!$user_id) { $user_id = $bp->displayed_user->id; } like_escape($filter); if ($limit && $page) { $pag_sql = $wpdb->prepare(" LIMIT %d, %d", intval(($page - 1) * $limit), intval($limit)); } // Get all the group ids for the current user's groups. $gids = BP_Groups_Member::get_group_ids($user_id, false, false, false, true); if (!$gids['groups']) { return false; } $gids = implode(',', $gids['groups']); $paged_groups = $wpdb->get_results($wpdb->prepare("SELECT id as group_id FROM {$bp->groups->table_name} WHERE ( name LIKE '{$filter}%%' OR description LIKE '{$filter}%%' ) AND id IN ({$gids}) {$pag_sql}")); $total_groups = $wpdb->get_var($wpdb->prepare("SELECT count(id) FROM {$bp->groups->table_name} WHERE ( name LIKE '{$filter}%%' OR description LIKE '{$filter}%%' ) AND id IN ({$gids})")); return array('groups' => $paged_groups, 'total' => $total_groups); }
function gtags_activity_for_item($args) { global $wpdb, $bp; ob_start(); $defaults = array('group_ids' => '', 'scope' => '', 'show' => 4, 'show_more' => 8, 'truncate' => 190); $args = wp_parse_args($args, $defaults); extract($args, EXTR_SKIP); if ($scope == 'my' && is_user_logged_in()) { $my_groups = BP_Groups_Member::get_group_ids($bp->loggedin_user->id); $group_ids = array_intersect($group_ids, $my_groups['groups']); $show_hidden = true; } if (empty($group_ids)) { echo '<div class="recent recent-none-found">' . __('Sorry no groups were found.', 'gtags') . '</div>'; return; } ?> <div class="recent"><?php // generate source group links foreach ($group_ids as $group_id) { $group = groups_get_group(array('group_id' => $group_id)); $avatar = bp_core_fetch_avatar('object=group&type=thumb&width=50&height=50&item_id=' . $group->id); $group_output .= $sep . '<a href="' . bp_get_group_permalink($group) . '" class="recent-group-avatar">' . $avatar . ' ' . $group->name . '</a>'; $sep = ', '; //compile group data to be used in loop below $the_groups[$group->id] = array('permalink' => bp_get_group_permalink($group), 'name' => bp_get_group_name($group), 'avatar' => $avatar); } ?> <div class="gtags-recent-groups"> <?php _e('Recent Activity From', 'gtags'); ?> <a href="#" class="gtags-more-groups"><?php _e('these groups +', 'gtags'); ?> </a> <div class="gtags-recent-groups-list"><?php echo $group_output; ?> </div> </div> <?php // fetch a whole bunch of activity so we can sort them by date below, otherwise they are sorted by group $filter = array('user_id' => false, 'object' => 'groups', 'action' => false, 'primary_id' => implode(',', (array) $group_ids)); $activity = bp_activity_get(array('max' => 1000, 'per_page' => 1000, 'filter' => $filter, 'show_hidden' => $show_hidden)); //$type_skip = apply_filters( 'gtags_type_skip', array( 'joined_group' ) ); // array of activity types to skip // generate a cleaned array of content foreach ($activity['activities'] as $item) { if (in_array($item->type, (array) $type_skip)) { continue; } $action = preg_replace('/:$/', '', $item->action); // remove trailing colon in activity $action = apply_filters('gtags_action', $action); $content = strip_tags(stripslashes($item->content)); if ($truncate && strlen($content) > $truncate) { $content = substr($content, 0, $truncate) . '... '; } if ($content) { $content .= ' <a href="' . $item->primary_link . '">view</a>'; } $activity_list[$item->date_recorded] = array('action' => $action, 'group_id' => $item->item_id, 'content' => $content, 'primary_link' => $item->primary_link, 'user_id' => $item->user_id); } if (empty($activity_list)) { echo __("Sorry, there was no activity found.", 'gtags'); echo "</div>"; //close the div return; } // sort them by date (regardless of group) ksort($activity_list); $activity_list = array_reverse($activity_list); // output pretty html for recent activity for groups foreach ((array) $activity_list as $date => $item) { $i++; $group_id = $item['group_id']; $action = $item['action']; // show only a certain amount, after that make a 'show more' link and show the rest in a hidden div if ($i == $show + 1 && $show_more) { ?> <a href="#" class="gtags-more-activity"><?php _e('show more +', 'gtags'); ?> </a> <div class="gtags-more-content"><?php $more_link = true; } if ($i > $show + $show_more + 1) { break; } // for repeating group content, remove group link and shrink group avatar if ($prev_group_id == $group_id) { $action = preg_replace('/ in the group(.*)$/i', '', $action); $dup_class = ' duplicate-group'; } else { $dup_class = ''; } $prev_group_id = $group_id; // group avatar echo '<a href="' . $the_groups[$group_id]['permalink'] . '" title="' . $the_groups[$group_id]['name'] . '" class="gtags-item-group-avatar' . $dup_class . '">' . $the_groups[$group_id]['avatar'] . '</a>'; // the actual content ?> <div class="gtags-item-recent group"> <div class="gtags-item-avatar"> <a href="<?php echo bp_core_get_user_domain($item['user_id']); ?> "> <?php echo bp_core_fetch_avatar('object=user&type=full&width=50&height=50&item_id=' . $item['user_id']); ?> </a> </div> <div class="gtags-item-action"> <?php echo $action; ?> <span class="gtags-time-ago"><?php echo bp_core_time_since($date); ?> <?php _e('ago', 'gtags'); ?> </span> </div> <div class="gtags-item-content"> <?php echo convert_smilies($item['content']); ?> </div> </div><?php } if ($more_link) { echo '<div class="gtags-recent-groups"> ' . __('Continue reading in:', 'gtags') . ' ' . $group_output . '</div>'; echo '</div>'; // close the more div } ?> </div><?php // end recent return ob_get_clean(); }
/** * Get the group count for the displayed user. * * @since 1.1.0 * * @return string */ function bp_get_group_total_for_member() { /** * FIlters the group count for a displayed user. * * @since 1.1.0 * * @param int $value Total group count for a displayed user. */ return apply_filters('bp_get_group_total_for_member', BP_Groups_Member::total_group_count()); }
function get_invitable_friend_count($user_id, $group_id) { // Setup some data we'll use below $is_group_admin = BP_Groups_Member::check_is_admin($user_id, $group_id); $friend_ids = BP_Friends_Friendship::get_friend_user_ids($user_id); $invitable_count = 0; for ($i = 0, $count = count($friend_ids); $i < $count; ++$i) { // If already a member, they cannot be invited again if (BP_Groups_Member::check_is_member((int) $friend_ids[$i], $group_id)) { continue; } // If user already has invite, they cannot be added if (BP_Groups_Member::check_has_invite((int) $friend_ids[$i], $group_id)) { continue; } // If user is not group admin and friend is banned, they cannot be invited if (false === $is_group_admin && BP_Groups_Member::check_is_banned((int) $friend_ids[$i], $group_id)) { continue; } $invitable_count++; } return $invitable_count; }
function the_invite() { global $group_id; $this->in_the_loop = true; $user_id = $this->next_invite(); $this->invite = new stdClass(); $this->invite->user = $this->invite_data[$user_id]; // This method previously populated the user object with // BP_Core_User. We manually configure BP_Core_User data for // backward compatibility. if (bp_is_active('xprofile')) { $this->invite->user->profile_data = BP_XProfile_ProfileData::get_all_for_user($user_id); } $this->invite->user->avatar = bp_core_fetch_avatar(array('item_id' => $user_id, 'type' => 'full', 'alt' => sprintf(__('Avatar of %s', 'buddypress'), $this->invite->user->fullname))); $this->invite->user->avatar_thumb = bp_core_fetch_avatar(array('item_id' => $user_id, 'type' => 'thumb', 'alt' => sprintf(__('Avatar of %s', 'buddypress'), $this->invite->user->fullname))); $this->invite->user->avatar_mini = bp_core_fetch_avatar(array('item_id' => $user_id, 'type' => 'thumb', 'alt' => sprintf(__('Avatar of %s', 'buddypress'), $this->invite->user->fullname), 'width' => 30, 'height' => 30)); $this->invite->user->email = $this->invite->user->user_email; $this->invite->user->user_url = bp_core_get_user_domain($user_id, $this->invite->user->user_nicename, $this->invite->user->user_login); $this->invite->user->user_link = "<a href='{$this->invite->user->user_url}' title='{$this->invite->user->fullname}'>{$this->invite->user->fullname}</a>"; $this->invite->user->last_active = bp_core_get_last_activity($this->invite->user->last_activity, __('active %s', 'buddypress')); if (bp_is_active('groups')) { $total_groups = BP_Groups_Member::total_group_count($user_id); $this->invite->user->total_groups = sprintf(_n('%d group', '%d groups', $total_groups, 'buddypress'), $total_groups); } if (bp_is_active('friends')) { $this->invite->user->total_friends = BP_Friends_Friendship::total_friend_count($user_id); } if (bp_is_active('friends')) { $this->invite->user->total_friends = BP_Friends_Friendship::total_friend_count($user_id); } $this->invite->user->total_blogs = null; $this->invite->group_id = $group_id; // Globaled in bp_group_has_invites() if (0 == $this->current_invite) { // loop has just started do_action('loop_start'); } }
/** * Notify all group members when a group is updated. * * @since 1.0.0 * * @param int $group_id ID of the group. * @param BP_Groups_Group|null $old_group Group before new details were saved. */ function groups_notification_group_updated($group_id = 0, $old_group = null) { $group = groups_get_group(array('group_id' => $group_id)); if ($old_group instanceof BP_Groups_Group) { $changed = array(); if ($group->name !== $old_group->name) { $changed[] = sprintf(_x('* Name changed from "%s" to "%s"', 'Group update email text', 'buddypress'), esc_html($old_group->name), esc_html($group->name)); } if ($group->description !== $old_group->description) { $changed[] = sprintf(_x('* Description changed from "%s" to "%s"', 'Group update email text', 'buddypress'), esc_html($old_group->description), esc_html($group->description)); } } /** * Filters the bullet points listing updated items in the email notification after a group is updated. * * @since 2.2.0 * * @param array $changed Array of bullet points. */ $changed = apply_filters('groups_notification_group_update_updated_items', $changed); $changed_text = ''; if (!empty($changed)) { $changed_text = "\n\n" . implode("\n", $changed); } $subject = bp_get_email_subject(array('text' => __('Group Details Updated', 'buddypress'))); $user_ids = BP_Groups_Member::get_group_member_ids($group->id); foreach ((array) $user_ids as $user_id) { // Continue if member opted out of receiving this email. if ('no' === bp_get_user_meta($user_id, 'notification_groups_group_updated', true)) { continue; } $ud = bp_core_get_core_userdata($user_id); // Set up and send the message. $to = $ud->user_email; $group_link = bp_get_group_permalink($group); $settings_slug = function_exists('bp_get_settings_slug') ? bp_get_settings_slug() : 'settings'; $settings_link = bp_core_get_user_domain($user_id) . $settings_slug . '/notifications/'; $message = sprintf(__('Group details for the group "%1$s" were updated: %2$s To view the group: %3$s --------------------- ', 'buddypress'), $group->name, $changed_text, $group_link); $message .= sprintf(__('To disable these notifications please log in and go to: %s', 'buddypress'), $settings_link); /** * Filters the user email that the group update notification will be sent to. * * @since 1.2.0 * * @param string $to User email the notification is being sent to. */ $to = apply_filters('groups_notification_group_updated_to', $to); /** * Filters the group update notification subject that will be sent to user. * * @since 1.2.0 * * @param string $subject Email notification subject text. * @param BP_Groups_Group $group Object holding the current group instance. Passed by reference. */ $subject = apply_filters_ref_array('groups_notification_group_updated_subject', array($subject, &$group)); /** * Filters the group update notification message that will be sent to user. * * @since 1.2.0 * * @param string $message Email notification message text. * @param BP_Groups_Group $group Object holding the current group instance. Passed by reference. * @param string $group_link URL permalink to the group that was updated. * @param string $settings_link URL permalink for the user's notification settings area. */ $message = apply_filters_ref_array('groups_notification_group_updated_message', array($message, &$group, $group_link, $settings_link)); wp_mail($to, $subject, $message); unset($message, $to); } /** * Fires after the notification is sent that a group has been updated. * * See https://buddypress.trac.wordpress.org/ticket/3644 for blank message parameter. * * @since 1.5.0 * * @param array $user_ids Array of user IDs to notify about the update. * @param string $subject Email notification subject text. * @param string $value Empty string preventing PHP error. * @param int $group_id ID of the group that was updated. */ do_action('bp_groups_sent_updated_email', $user_ids, $subject, '', $group_id); }
/** * Delete all group membership information for the specified user * * @global object $bp BuddyPress global settings * @global wpdb $wpdb WordPress database object * @param int $user_id * @since 1.0 * @uses BP_Groups_Member */ function delete_all_for_user($user_id) { global $bp, $wpdb; // Get all the group ids for the current user's groups and update counts $group_ids = BP_Groups_Member::get_group_ids($user_id); foreach ($group_ids['groups'] as $group_id) { groups_update_groupmeta($group_id, 'total_member_count', groups_get_total_member_count($group_id) - 1); // If current user is the creator of a group and is the sole admin, delete that group to avoid counts going out-of-sync if (groups_is_user_admin($user_id, $group_id) && count(groups_get_group_admins($group_id)) < 2 && groups_is_user_creator($user_id, $group_id)) { groups_delete_group($group_id); } } return $wpdb->query($wpdb->prepare("DELETE FROM {$bp->groups->table_name_members} WHERE user_id = %d", $user_id)); }
/** * Process group invitation removal requests. * * Note that this function is only used when JS is disabled. Normally, clicking * Remove Invite removes the invitation via AJAX. * * @since 2.0.0 */ function groups_remove_group_invite() { if (!bp_is_group_invites()) { return; } if (!bp_is_action_variable('remove', 0) || !is_numeric(bp_action_variable(1))) { return; } if (!check_admin_referer('groups_invite_uninvite_user')) { return false; } $friend_id = intval(bp_action_variable(1)); $group_id = bp_get_current_group_id(); $message = __('Invite successfully removed', 'buddypress'); $redirect = wp_get_referer(); $error = false; if (!bp_groups_user_can_send_invites($group_id)) { $message = __('You are not allowed to send or remove invites', 'buddypress'); $error = 'error'; } elseif (BP_Groups_Member::check_for_membership_request($friend_id, $group_id)) { $message = __('The member requested to join the group', 'buddypress'); $error = 'error'; } elseif (!groups_uninvite_user($friend_id, $group_id)) { $message = __('There was an error removing the invite', 'buddypress'); $error = 'error'; } bp_core_add_message($message, $error); bp_core_redirect($redirect); }