Ejemplo n.º 1
0
/**
 * Returns a mapping between field number and field value. Doesn't take translation into account. Doesn't take anything permissive into account.
 *
 * @param  MEMBER	The member.
 * @return array	The mapping.
 */
function ocf_get_custom_fields_member($member_id)
{
    $row = ocf_get_custom_field_mappings($member_id);
    $result = array();
    foreach ($row as $column => $val) {
        if (substr($column, 0, 6) == 'field_') {
            $result[intval(substr($column, 6))] = $val;
        }
    }
    return $result;
}
Ejemplo n.º 2
0
/**
 * Set a custom profile field for a member.
 *
 * @param  MEMBER		The member.
 * @param  AUTO_LINK The field being set.
 * @param  mixed 		The value of the field. For a trans-type field, this can be either a lang-ID to be copied (from forum DB), or an actual string.
 * @param  ?ID_TEXT 	The field type (NULL: look it up).
 * @param  boolean 	Whether to defer the change, by returning a result change rather than doing it right away.
 * @return ?array		Mapping change (NULL: none / can't defer).
 */
function ocf_set_custom_field($member_id, $field, $value, $type = NULL, $defer = false)
{
    if (is_null($type)) {
        $type = $GLOBALS['FORUM_DB']->query_value('f_custom_fields', 'cf_type', array('id' => $field));
    }
    ocf_get_custom_field_mappings($member_id);
    // This will do an auto-repair if CPF storage row is missing
    global $ANY_FIELD_ENCRYPTED;
    if ($ANY_FIELD_ENCRYPTED === NULL) {
        $ANY_FIELD_ENCRYPTED = !is_null($GLOBALS['FORUM_DB']->query_value_null_ok('f_custom_fields', 'cf_encrypted', array('cf_encrypted' => 1)));
    }
    if ($ANY_FIELD_ENCRYPTED) {
        $encrypted = $GLOBALS['FORUM_DB']->query_value('f_custom_fields', 'cf_encrypted', array('id' => $field));
        if ($encrypted) {
            require_code('encryption');
            $current = $GLOBALS['FORUM_DB']->query_value('f_member_custom_fields', 'field_' . strval(intval($field)), array('mf_member_id' => $member_id));
            if (remove_magic_encryption_marker($value) == remove_magic_encryption_marker($current) && is_data_encrypted($current)) {
                return NULL;
            }
            $value = encrypt_data($value);
        }
    } else {
        $encrypted = false;
    }
    require_code('fields');
    $ob = get_fields_hook($type);
    list(, , $storage_type) = $ob->get_field_value_row_bits(array('id' => $field, 'cf_default' => '', 'cf_type' => $type));
    if (strpos($storage_type, '_trans') !== false) {
        if (is_integer($value)) {
            $value = get_translated_text($value, $GLOBALS['FORUM_DB']);
        }
        $current = $GLOBALS['FORUM_DB']->query_value('f_member_custom_fields', 'field_' . strval(intval($field)), array('mf_member_id' => $member_id));
        if (is_null($current)) {
            if ($type == 'posting_field') {
                require_code('attachments2');
                $current = insert_lang_comcode_attachments(3, $value, 'null', strval($member_id), $GLOBALS['FORUM_DB']);
            } else {
                $current = insert_lang_comcode($value, 3, $GLOBALS['FORUM_DB']);
            }
            $GLOBALS['FORUM_DB']->query_update('f_member_custom_fields', array('field_' . strval(intval($field)) => $current), array('mf_member_id' => $member_id), '', 1);
        } else {
            if ($type == 'posting_field') {
                require_code('attachments2');
                require_code('attachments3');
                update_lang_comcode_attachments($current, $value, 'null', strval($member_id), $GLOBALS['FORUM_DB'], false, $member_id);
            } else {
                lang_remap_comcode($current, $value, $GLOBALS['FORUM_DB']);
            }
        }
    } else {
        $change = array('field_' . strval(intval($field)) => $value);
        if (!$defer) {
            $GLOBALS['FORUM_DB']->query_update('f_member_custom_fields', $change, array('mf_member_id' => $member_id), '', 1);
        }
        return $change;
    }
    return NULL;
}