function bps_update_meta()
{
    $bps_options = array();
    list($x, $fields) = bps_get_fields();
    $bps_options['field_name'] = array();
    $bps_options['field_label'] = array();
    $bps_options['field_desc'] = array();
    $bps_options['field_range'] = array();
    $j = 0;
    $posted = isset($_POST['bps_options']) ? $_POST['bps_options'] : array();
    if (isset($posted['field_name'])) {
        foreach ($posted['field_name'] as $k => $id) {
            if (empty($fields[$id])) {
                continue;
            }
            $field = $fields[$id];
            $field_type = $field->type;
            $field_type = apply_filters('bps_field_validation_type', $field_type, $field);
            $field_type = apply_filters('bps_field_type_for_validation', $field_type, $field);
            $label = stripslashes($posted['field_label'][$k]);
            $desc = stripslashes($posted['field_desc'][$k]);
            $bps_options['field_name'][$j] = $id;
            $bps_options['field_label'][$j] = $l = $label;
            $bps_options['field_desc'][$j] = $d = $desc;
            $bps_options['field_range'][$j] = $r = isset($posted['field_range'][$k]);
            if (bps_custom_field($field_type)) {
                list($l, $d, $r) = apply_filters('bps_field_validation', array($l, $d, $r), $field);
                $bps_options['field_label'][$j] = $l;
                $bps_options['field_desc'][$j] = $d;
                $bps_options['field_range'][$j] = $r;
            } else {
                if ($field_type == 'datebox') {
                    $bps_options['field_range'][$j] = true;
                }
                if ($field_type == 'checkbox' || $field_type == 'multiselectbox') {
                    $bps_options['field_range'][$j] = false;
                }
            }
            if ($bps_options['field_range'][$j] == false) {
                $bps_options['field_range'][$j] = null;
            }
            $j = $j + 1;
        }
    }
    return $bps_options;
}
Beispiel #2
0
function bps_search($request)
{
    global $bp, $wpdb;
    $done = array();
    $results = array('users' => array(0), 'validated' => true);
    list($x, $fields) = bps_get_fields();
    foreach ($request as $key => $value) {
        if ($value === '') {
            continue;
        }
        $split = explode('_', $key);
        if ($split[0] != 'field') {
            continue;
        }
        $id = $split[1];
        $op = isset($split[2]) ? $split[2] : 'eq';
        if (isset($done[$id]) || empty($fields[$id])) {
            continue;
        }
        $field = $fields[$id];
        $field_type = $field->type;
        $field_type = apply_filters('bps_field_query_type', $field_type, $field);
        $field_type = apply_filters('bps_field_type_for_query', $field_type, $field);
        if (bps_custom_field($field_type)) {
            $found = apply_filters('bps_field_query', array(), $field, $key, $value);
        } else {
            $sql = $wpdb->prepare("SELECT user_id FROM {$bp->profile->table_name_data} WHERE field_id = %d ", $id);
            $sql = apply_filters('bps_field_sql', $sql, $field);
            if ($op == 'min' || $op == 'max') {
                if ($field_type == 'multiselectbox' || $field_type == 'checkbox') {
                    continue;
                }
                list($min, $max) = bps_minmax($request, $id, $field_type);
                if ($min === '' && $max === '') {
                    continue;
                }
                switch ($field_type) {
                    case 'textbox':
                    case 'number':
                    case 'textarea':
                    case 'selectbox':
                    case 'radio':
                        if ($min !== '') {
                            $sql .= $wpdb->prepare("AND value >= %f", $min);
                        }
                        if ($max !== '') {
                            $sql .= $wpdb->prepare("AND value <= %f", $max);
                        }
                        break;
                    case 'datebox':
                        $time = time();
                        $day = date("j", $time);
                        $month = date("n", $time);
                        $year = date("Y", $time);
                        $ymin = $year - $max - 1;
                        $ymax = $year - $min;
                        if ($max !== '') {
                            $sql .= $wpdb->prepare("AND DATE(value) > %s", "{$ymin}-{$month}-{$day}");
                        }
                        if ($min !== '') {
                            $sql .= $wpdb->prepare("AND DATE(value) <= %s", "{$ymax}-{$month}-{$day}");
                        }
                        break;
                }
            } else {
                if ($op == 'eq') {
                    if ($field_type == 'datebox') {
                        continue;
                    }
                    switch ($field_type) {
                        case 'textbox':
                        case 'textarea':
                        case 'url':
                            $value = str_replace('&', '&amp;', $value);
                            $escaped = '%' . bps_esc_like($value) . '%';
                            $meta = bps_meta($request['bp_profile_search']);
                            if ($meta['searchmode'] != 'EQUAL') {
                                $sql .= $wpdb->prepare("AND value LIKE %s", $escaped);
                            } else {
                                $sql .= $wpdb->prepare("AND value LIKE %s", $value);
                            }
                            break;
                        case 'number':
                            $sql .= $wpdb->prepare("AND value = %d", $value);
                            break;
                        case 'selectbox':
                        case 'radio':
                            $values = (array) $value;
                            $parts = array();
                            foreach ($values as $value) {
                                $value = str_replace('&', '&amp;', $value);
                                $parts[] = $wpdb->prepare("value = %s", $value);
                            }
                            $sql .= 'AND (' . implode(' OR ', $parts) . ')';
                            break;
                        case 'multiselectbox':
                        case 'checkbox':
                            $values = (array) $value;
                            $parts = array();
                            foreach ($values as $value) {
                                $value = str_replace('&', '&amp;', $value);
                                $escaped = '%:"' . bps_esc_like($value) . '";%';
                                $parts[] = $wpdb->prepare("value LIKE %s", $escaped);
                            }
                            $match = apply_filters('bps_field_checkbox_match_all', false, $id) ? ' AND ' : ' OR ';
                            $sql .= 'AND (' . implode($match, $parts) . ')';
                            break;
                    }
                } else {
                    continue;
                }
            }
            $found = $wpdb->get_col($sql);
        }
        $users = isset($users) ? array_intersect($users, $found) : $found;
        if (count($users) == 0) {
            return $results;
        }
        $done[$id] = true;
    }
    if (count($done) == 0) {
        $results['validated'] = false;
        return $results;
    }
    $results['users'] = $users;
    return $results;
}