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;
}
Example #2
0
 /**
  * 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'));
 }
 /**
  * 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));
 }
/**
 * Get the IDs of the groups of which a specified user is a member.
 *
 * @param int $user_id  ID of the user.
 * @param int $pag_num  Optional. Max number of results to return.
 *                      Default: false (no limit).
 * @param int $pag_page Optional. Page offset of results to return.
 *                      Default: false (no limit).
 * @return array {
 *     @type array $groups Array of groups returned by paginated query.
 *     @type int   $total Count of groups matching query.
 * }
 */
function groups_get_user_groups($user_id = 0, $pag_num = 0, $pag_page = 0)
{
    if (empty($user_id)) {
        $user_id = bp_displayed_user_id();
    }
    return BP_Groups_Member::get_group_ids($user_id, $pag_num, $pag_page);
}
 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 . '&nbsp;' . $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 .= ' &nbsp;<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 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_get_user_groups($user_id = 0, $pag_num = 0, $pag_page = 0)
{
    global $bp;
    if (!$user_id) {
        $user_id = $bp->displayed_user->id;
    }
    return BP_Groups_Member::get_group_ids($user_id, $pag_num, $pag_page);
}
 /**
  * GET WALL ACTIVITES
  */
 function get_wall_activities($page = 0, $per_page = 20)
 {
     global $bp, $wpdb;
     $min = $page > 0 ? ($page - 1) * $per_page : 0;
     $max = ($page + 1) * $per_page;
     $per_page = bp_get_activity_per_page();
     buddy_boss_log(" per page {$per_page}");
     if (isset($bp->loggedin_user) && isset($bp->loggedin_user->id) && $bp->displayed_user->id == $bp->loggedin_user->id) {
         $myprofile = true;
     } else {
         $myprofile = false;
     }
     $wpdb->show_errors = BUDDY_BOSS_DEBUG;
     $user_id = $bp->displayed_user->id;
     buddy_boss_log("Looking at {$user_id}");
     $filter = addslashes($bp->displayed_user->fullname);
     $friend_ids = friends_get_friend_user_ids($user_id);
     $admin_ids = array();
     //buddyboss_users_by_role( 'administrator' );
     $friend_ids = array_merge($friend_ids, $admin_ids);
     // var_dump($friend_ids);
     buddy_boss_log($friend_ids);
     if (!empty($friend_ids)) {
         $friend_id_list = implode(",", $friend_ids);
     }
     buddy_boss_log($friend_id_list);
     $table = $wpdb->prefix . bp_activity;
     $table2 = $wpdb->prefix . bp_activity_meta;
     // Group Display code
     if (array_search("groups", $bp->active_components)) {
         $groups = BP_Groups_Member::get_group_ids($user_id);
     }
     //var_dump($groups);
     $valid_groups = array();
     if (!empty($groups)) {
         foreach ($groups['groups'] as $id) {
             $group = new BP_Groups_Group($id);
             //var_dump($group);
             if ("public" == $group->status) {
                 //echo $group->slug;
                 $valid_groups[] = $id;
             }
             $user_group[] = $group->slug;
         }
     }
     $group_modifier = "OR ( {$table}.user_id = {$user_id} AND {$table}.component = 'groups' ) ";
     $group_mentions = "OR ( {$table}.component = 'groups' AND ({$table}.content LIKE '%@{$filter}%'))";
     $friendships = "OR ( {$table}.user_id = {$user_id} AND {$table}.component = 'friends' )";
     $mentions_modifier = "OR ( {$table}.component = 'activity' AND {$table}.action LIKE '%@{$filter}%' ) ";
     //$mem_slugs = $bp->members->slug;
     $friends_modifier = "OR ( {$table2}.meta_value LIKE '%{$filter}%' AND {$table}.type!='activity_comment') ";
     $qry = "SELECT {$table}.id FROM {$table} LEFT JOIN {$table2} ON {$table}.id={$table2}.activity_id\r\n\t\t\tWHERE ( {$table}.user_id = {$user_id} AND {$table}.type!='activity_comment' AND {$table}.type!='friends' )\r\n\t\t\t{$friends_modifier}\r\n\t\t\t{$group_modifier}\r\n\t\t\t{$group_mentions}\r\n\t\t\t{$friendships}\r\n\t\t\t{$mentions_modifier}\r\n\t\t\tORDER BY date_recorded DESC LIMIT {$min}, 30";
     //echo $qry;
     $activities = $wpdb->get_results($qry, ARRAY_A);
     //var_dump($wpdb->print_error());
     buddy_boss_log($qry);
     buddy_boss_log($activities);
     if (empty($activities)) {
         return null;
     }
     $tmp = array();
     foreach ($activities as $a) {
         $tmp[] = $a["id"];
     }
     $activity_list = implode(",", $tmp);
     return $activity_list;
 }
Example #10
0
function groups_get_user_groups($pag_num, $pag_page)
{
    global $bp;
    $groups = BP_Groups_Member::get_group_ids($bp->displayed_user->id, $pag_num, $pag_page);
    return array('groups' => $groups['ids'], 'total' => $groups['total']);
}
function wangguard_spam_all_data($user_id)
{
    global $wpdb, $bp;
    $wpdb->query($wpdb->prepare("DELETE FROM {$bp->blogs->table_name} WHERE user_id = %d", $user_id));
    friends_remove_data($user_id);
    $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));
    BP_Groups_Member::delete_all_for_user($user_id);
}
 /**
  * Evaluates current visitor and determines what a vistor is relative to various biz rules. these "flags" are used for managing editability and visibility.  
  */
 public function ez_bp_profile_current_visitor_is($int_compare_to_user_id = '')
 {
     global $bp;
     // start with nothing
     $arr_visitor_is = array();
     // EVERY visitor gets to see public - if there is any public
     $arr_visitor_is['public'] = true;
     /**
      * If the visitor is not loggedin then all other checks are irrelevant; so save time and return if not logged in.
      */
     if (is_user_logged_in()) {
         $arr_visitor_is['loggedin'] = true;
     } else {
         return $arr_visitor_is;
     }
     // now that we're sure we have a logged in visitor use the $bp global to work some magic
     $int_loggedin_user_id = $bp->loggedin_user->id;
     $int_displayed_user_id = $bp->displayed_user->id;
     /**
      * fyi - did you notice, we're going to allow a user id to be passed in and used for the current loggedin user. 
      * we don't really need this now per se, but it made sense to bake it in for later, just in case.
      */
     if (is_int($int_compare_to_user_id)) {
         $int_displayed_user_id = $int_compare_to_user_id;
     }
     /**
      * what if you want more layers in your organization? then you only have to customize this one method.
      */
     $arr_visitor_is_custom = $this->ez_bp_profile_current_visitor_is_custom($int_compare_to_user_id = '');
     // if we get an array back then merge it in
     if (is_array($arr_visitor_is_custom)) {
         $arr_visitor_is = array_merge($arr_visitor_is, $arr_visitor_is_custom);
     }
     // if the loggedin user is the display / compare to user then set the user flag and return 'cause checking friends and groups doesn't make sense.
     if ($int_loggedin_user_id == $int_displayed_user_id) {
         $arr_visitor_is['user'] = true;
         return $arr_visitor_is;
     }
     if (bp_is_active('friends')) {
         if (friends_check_friendship($int_displayed_user_id, $int_loggedin_user_id)) {
             $arr_visitor_is['friends'] = true;
         }
     }
     if (bp_is_active('groups')) {
         // does the current (loggedin) visitor share any groups with the profile'd person?
         if ($int_loggedin_user_id != $int_displayed_user_id) {
             $arr_displayed_user_id_groups = BP_Groups_Member::get_group_ids($int_displayed_user_id);
             $arr_loggedin_user_id_groups = BP_Groups_Member::get_group_ids($int_loggedin_user_id);
             $arr_intersect_groups = array_intersect($arr_displayed_user_id_groups['groups'], $arr_loggedin_user_id_groups['groups']);
             // intersect means the users have a group(s) in common
             if (!empty($arr_intersect_groups)) {
                 $arr_visitor_is['groups'] = true;
             }
         }
     }
     return $arr_visitor_is;
 }