Table of Contents
glProfile
Planning and ideas for the implementation of a custom user profile plugin, perhaps to be rolled into the main codebase at some point.
The sample functions shown here are abstract ideas. The actual implementation would use object-oriented programming, with a “UserProfile” class.
Goals
- Allow the site administrator to customize the user profile fields, and the registration screen, with a minimum of coding and file editing.
- Plugins should be able to provide and consume data to and from the user profile.
Field Definition Table
The Field Definition table will be used by administrators to create, delete and modify custom profile fields.
Fields will normally be created and maintained by the site administrator using a form similar to that used by the glFusion configuration system. glFusion's system lacks some of the desired elements, such as checkboxes and radio buttons, as well as the ability to draw data from plugins.
| Field | Description |
|---|---|
| id | Record ID, auto_increment |
| orderby | Order to appear on forms |
| name | Field name |
| type | Field type (integer, string, etc.). May be combined with “value” like gl_conf_values |
| value | Field value. Use “val:prompt;val:prompt” for selections |
| defvalue | Default value automatically chosen |
| enabled | Boolean, 1 indicates whether a field is in use |
| required | Boolean, 1 indicates whether the field is required |
| user_reg | Boolean, 1 indicates that the field appears on the registration form. Implied by “required” |
| readonly | Boolean, 1 indicates that the field data is not user-modifiable |
| prompt | Text string to appear with the field on forms |
| size | Field size. Applies to text fields only |
| maxlength | Field Max length. Applies to text fields only |
| options | Field-specific options, such as date/time formats |
| format | Format string, specific to date fields |
User Profile Table
This table holds the actual user profile information. Any functions which access this data should be prepared for an empty result set.
| Field | Description |
|---|---|
| uid | User ID, matches gl_users |
| name | Field name, matches definition.name |
| value | Field value |
Plugin Interaction
Since glFusion 1.1.5 has expanded the API's for plugin profiles, this sections has been removed. The Custom Profile plugin will only provide generic profile data. Plugins will be responsible for managing their own profiles in their own tables.
Profile Field Creation
The profile fields can be created similarly to the way the administrative lists are created.
function PROFILE_createFields($uid = 0)
{
global $_PLUGINS, $LANG_PROFILE;
// Get the current values from the user's profile record and load into a 'name'=>'value' array.
$userResult = DB_query("SELECT * from {$_TABLES['userprofile']} WHERE uid=$uid");
while ($row = DB_fetchArray($userResult)) {
$userdata[] = array($row['name'] => $row['value']);
}
// Now get all the field definitions
$result = DB_query("SELECT * FROM {$_TABLES['profiledef']} WHERE enabled=1");
while ($row = DB_fetchArray($result)) {
$field_name = $LANG_PROFILE[$row['name']];
$field_content = $userdata['value'];
// Ensure that the content matches the field type, and create the form elements
switch ($row['type']) {
case 'integer':
$field_content = (int)$field_content;
$html = '<input type="text" name="{$field_name}" value="{$field_content}">';
break;
case 'float':
$field_content = (float)$field_content;
$html = '<input type="text" name="{$field_name}" value="{$field_content}">';
break;
case 'boolean':
$field_content = $field_content == 1 ? 1 : 0;
$html = '<input type="checkbox" name="{$field_name}" ' .
$field_content == 1 ? 'checked' : '' . '>';
break;
}
... add field prompt and content to the form HTML ...
}
... set the template variable or return the form data ...
}