Example #1
0
function checkPerm($permission, $contentOwnerID)
{
    $currUserID = wp_get_current_user();
    $currUserID = $currUserID->ID;
    $privacySettings = get_usermeta($contentOwnerID, 'privacy_settings');
    if ($privacySettings) {
        foreach ($privacySettings as $key => $perm) {
            if ($key == $permission) {
                $permission = $perm;
            }
        }
    }
    $friendList = new userFriends();
    $friends = $friendList->get_friends($contentOwnerID);
    if ($permission['status'] == 'friends' && is_friend($contentOwnerID)) {
        return true;
    }
    if ($permission['status'] == 'all_members' && is_user_logged_in()) {
        return true;
    }
    if ($permission['status'] == 'public') {
        return true;
    }
    if ($currUserID == $contentOwnerID) {
        return true;
    }
    return false;
    // If someone hasn't set their privacy then we default to private
}
Example #2
0
/**
 * Alerts your friends when you leave a group
 *
 * @author: Tom Willmot
 * @version 1.0
 **/
function nm_alert_friend_left_group($group)
{
    $userInfo = wp_get_current_user();
    $userInfo = get_userdata($userInfo->ID);
    global $group;
    $group = $group;
    $post = get_post($group);
    $friendList = new userFriends();
    $friends = $friendList->get_friends($userInfo->ID);
    if ($friends) {
        $friends = array_flip($friends);
        $alert = array();
        $alert['content'] = '<a href="' . getProfileLink($userInfo->ID) . '" title="View ' . nm_user_public_name($userInfo) . 's profile">' . nm_user_public_name($userInfo) . '</a> has left the <a href="' . nm_group_permalink() . '" title="View the ' . $post->post_title . '">' . $post->post_title . '</a> Group.';
        $alert['type'] = 'group';
        nm_add_alert($friends, $alert);
    }
}
Example #3
0
function nm_members_you_should_meet($uid = 'current', $limit = '999', $matches = true, $fields = 'hometown,interests')
{
    global $wpdb;
    if ($uid == 'current') {
        $uid = wp_get_current_user();
        $uid = $uid->ID;
    }
    $fields = explode(',', $fields);
    //Get all the user except the current one and users friends
    $friendList = new userFriends();
    $friends = nm_array_invert($friendList->get_friends($uid));
    $friends_sql = '';
    if (!empty($friends)) {
        foreach ($friends as $friend) {
            $sep = ' AND ';
            $friends_sql .= $sep . "ID != '" . $friend . "'";
        }
    }
    $query = "SELECT ID FROM {$wpdb->users} WHERE ID != '{$uid}'" . $friends_sql;
    $users = $wpdb->get_col($query);
    $results = array();
    //Loop through the users' profile info
    foreach ($fields as $field) {
        $field = trim($field);
        $userField = nm_profile_info($field, $uid);
        //Only check if the user has filled in thair profile info
        if ($userField != '' || !empty($userField)) {
            foreach ($users as $user) {
                $otherField = nm_profile_info($field, $user);
                if ($userField == $otherField && !is_array($userField)) {
                    $results[] = $user;
                } elseif (is_array($userField) && is_array($otherField)) {
                    foreach ($userField as $singleField) {
                        foreach ($otherField as $otherSingle) {
                            if ($otherSingle == $singleField) {
                                $results[] = $user;
                            }
                        }
                    }
                }
            }
        }
    }
    //Sort the array by most matches
    $numResults = array_count_values($results);
    $finalResults = array();
    //Compile the final array of IDs
    foreach ($numResults as $key => $result) {
        $finalResults[] = $key;
    }
    $finalResults = array_slice($finalResults, 0, $limit);
    //Add random users until there are 4 matches
    $needed = $limit - count($finalResults);
    while ($needed > 0) {
        $randomUser = $users[array_rand($users)];
        if (!in_array($randomUser, $finalResults) && $randomUser != 0) {
            $finalResults[] = $randomUser;
            $needed--;
        }
    }
    //Return the array of IDs
    return $finalResults;
}