ocPortal Developer's Guide: OCF members
» Return to Contents
sources/ocf_members.php
Global_functions_ocf_members.php
Function summary
|
void
|
init__ocf_members ()
|
|
array
|
ocf_get_filter_cats (boolean only_exists_now)
|
|
?integer
|
ocf_authusername_is_bound_via_httpauth (string authusername)
|
|
boolean
|
ocf_is_ldap_member (MEMBER member_id)
|
|
boolean
|
ocf_is_httpauth_member (MEMBER member_id)
|
|
array
|
ocf_get_all_custom_fields_match (?array groups, ?BINARY public_view, ?BINARY owner_view, ?BINARY owner_set, ?BINARY required, ?BINARY show_in_posts, ?BINARY show_in_post_previews, BINARY special_start, ?boolean show_on_join_form)
|
|
array
|
ocf_get_all_custom_fields_match_member (MEMBER member_id, ?BINARY public_view, ?BINARY owner_view, ?BINARY owner_set, ?BINARY encrypted, ?BINARY required, ?BINARY show_in_posts, ?BINARY show_in_post_previews, BINARY special_start, ?boolean show_on_join_form)
|
|
?AUTO_LINK
|
find_cpf_field_id (SHORT_TEXT title)
|
|
array
|
ocf_get_custom_field_mappings (MEMBER member_id)
|
|
array
|
ocf_get_custom_fields_member (MEMBER member_id)
|
|
GROUP
|
ocf_get_member_primary_group (MEMBER member_id)
|
void init__ocf_members()
Standard code module initialisation function.
Parameters…
(No return value)
function init__ocf_members()
{
global $CUSTOM_FIELD_CACHE;
$CUSTOM_FIELD_CACHE=array();
global $MEMBER_CACHE_FIELD_MAPPINGS;
$MEMBER_CACHE_FIELD_MAPPINGS=array();
global $PRIMARY_GROUP_MEMBERS;
$PRIMARY_GROUP_MEMBERS=array();
global $MAY_WHISPER_CACHE;
$MAY_WHISPER_CACHE=array();
}
array ocf_get_filter_cats(boolean only_exists_now)
Find all the Private Topic filter categories employed by the current member.
Parameters…
| Name |
only_exists_now |
| Description |
Whether to only show ones that already have things in (i.e. not default ones) |
| Default value |
boolean-false |
| Type |
boolean |
Returns…
| Description |
List of filter categories |
| Type |
array |
function ocf_get_filter_cats($only_exists_now=false)
{
$filter_rows_a=$GLOBALS['FORUM_DB']->query('SELECT DISTINCT t_pt_from_category FROM '.$GLOBALS['FORUM_DB']->get_table_prefix().'f_topics WHERE t_pt_from='.strval((integer)get_member()));
$filter_rows_b=$GLOBALS['FORUM_DB']->query('SELECT DISTINCT t_pt_to_category FROM '.$GLOBALS['FORUM_DB']->get_table_prefix().'f_topics WHERE t_pt_to='.strval((integer)get_member()));
$filter_cats=array(''=>1);
if (!$only_exists_now)
$filter_cats[do_lang('TRASH')]=1;
if ($GLOBALS['FORUM_DB']->query_value('f_special_pt_access','COUNT(*)',array('s_member_id'=>get_member()))>0)
$filter_cats[do_lang('INVITED_TO_PTS')]=1;
foreach ($filter_rows_a as $filter_row)
$filter_cats[$filter_row['t_pt_from_category']]=1;
foreach ($filter_rows_b as $filter_row)
$filter_cats[$filter_row['t_pt_to_category']]=1;
return array_keys($filter_cats);
}
?integer ocf_authusername_is_bound_via_httpauth(string authusername)
Find whether a member of a certain username is bound to HTTP authentication (an exceptional situation, only for sites that use it).
Parameters…
| Name |
authusername |
| Description |
The username. |
| Type |
string |
Returns…
| Description |
The member ID, if it is (NULL: not bound). |
| Type |
?integer |
function ocf_authusername_is_bound_via_httpauth($authusername)
{
$ret=$GLOBALS['FORUM_DB']->query_value_null_ok('f_members','id',array('m_password_compat_scheme'=>'httpauth','m_pass_hash_salted'=>$authusername));
if (is_null($ret))
$ret=$GLOBALS['FORUM_DB']->query_value_null_ok_full('SELECT id FROM '.$GLOBALS['FORUM_DB']->get_table_prefix().'f_members WHERE '.db_string_not_equal_to('m_password_compat_scheme','').' AND '.db_string_equal_to('m_username',$authusername));
return $ret;
}
boolean ocf_is_ldap_member(MEMBER member_id)
Find whether a member is bound to HTTP LDAP (an exceptional situation, only for sites that use it).
Parameters…
| Name |
member_id |
| Description |
The member. |
| Type |
MEMBER |
Returns…
| Description |
The answer. |
| Type |
boolean |
function ocf_is_ldap_member($member_id)
{
global $LDAP_CONNECTION;
if (is_null($LDAP_CONNECTION)) return false;
$scheme=$GLOBALS['OCF_DRIVER']->get_member_row_field($member_id,'m_password_compat_scheme');
return $scheme=='ldap';
}
boolean ocf_is_httpauth_member(MEMBER member_id)
Find whether a member is bound to HTTP authentication (an exceptional situation, only for sites that use it).
Parameters…
| Name |
member_id |
| Description |
The member. |
| Type |
MEMBER |
Returns…
| Description |
The answer. |
| Type |
boolean |
function ocf_is_httpauth_member($member_id)
{
$scheme=$GLOBALS['OCF_DRIVER']->get_member_row_field($member_id,'m_password_compat_scheme');
return $scheme=='httpauth';
}
array ocf_get_all_custom_fields_match(?array groups, ?BINARY public_view, ?BINARY owner_view, ?BINARY owner_set, ?BINARY required, ?BINARY show_in_posts, ?BINARY show_in_post_previews, BINARY special_start, ?boolean show_on_join_form)
Gets all the system custom fields that match certain parameters.
Parameters…
| Name |
groups |
| Description |
That are applicable only to one of the usergroups in this list (empty: CPFs with no restriction) (NULL: disregard restriction). |
| Type |
?array |
| Name |
public_view |
| Description |
That are publicly viewable (NULL: don't care). |
| Default value |
|
| Type |
?BINARY |
| Name |
owner_view |
| Description |
That are owner viewable (NULL: don't care). |
| Default value |
|
| Type |
?BINARY |
| Name |
owner_set |
| Description |
That are owner settable (NULL: don't care). |
| Default value |
|
| Type |
?BINARY |
| Name |
required |
| Description |
That are required (NULL: don't care). |
| Default value |
|
| Type |
?BINARY |
| Name |
show_in_posts |
| Description |
That are to be shown in posts (NULL: don't care). |
| Default value |
|
| Type |
?BINARY |
| Name |
show_in_post_previews |
| Description |
That are to be shown in post previews (NULL: don't care). |
| Default value |
|
| Type |
?BINARY |
| Name |
special_start |
| Description |
That start 'ocp_' |
| Default value |
0 |
| Type |
BINARY |
| Name |
show_on_join_form |
| Description |
That are to go on the join form (NULL: don't care). |
| Default value |
|
| Type |
?boolean |
Returns…
| Description |
A list of rows of such fields. |
| Type |
array |
function ocf_get_all_custom_fields_match($groups,$public_view=NULL,$owner_view=NULL,$owner_set=NULL,$required=NULL,$show_in_posts=NULL,$show_in_post_previews=NULL,$special_start=0,$show_on_join_form=NULL)
{
global $CUSTOM_FIELD_CACHE;
$x=serialize(array($public_view,$owner_view,$owner_set,$required,$show_in_posts,$show_in_post_previews,$special_start));
if (array_key_exists($x,$CUSTOM_FIELD_CACHE)) // ocPortal offers a wide array of features. It's multi dimensional. ocPortal.. entering the 6th dimension. hyper-hyper-time.
{
$result=$CUSTOM_FIELD_CACHE[$x];
} else
{
// Load up filters
$hooks=find_all_hooks('systems','ocf_cpf_filter');
$to_keep=array();
foreach (array_keys($hooks) as $hook)
{
require_code('hooks/systems/ocf_cpf_filter/'.$hook);
$_hook=object_factory('Hook_ocf_cpf_filter_'.$hook,true);
if (is_null($_hook)) continue;
$to_keep+=$_hook->to_enable();
}
$where='WHERE 1=1 ';
if (!is_null($public_view)) $where.=' AND cf_public_view='.strval((integer)$public_view);
if (!is_null($owner_view)) $where.=' AND cf_owner_view='.strval((integer)$owner_view);
if (!is_null($owner_set)) $where.=' AND cf_owner_set='.strval((integer)$owner_set);
if (!is_null($required)) $where.=' AND cf_required='.strval((integer)$required);
if (!is_null($show_in_posts)) $where.=' AND cf_show_in_posts='.strval((integer)$show_in_posts);
if (!is_null($show_in_post_previews)) $where.=' AND cf_show_in_post_previews='.strval((integer)$show_in_post_previews);
if ($special_start==1) $where.=' AND tx.text_original LIKE \''.db_encode_like('ocp_%').'\'';
if (!is_null($show_on_join_form)) $where.=' AND cf_show_on_join_form='.strval((integer)$show_on_join_form);
global $TABLE_LANG_FIELDS;
$_result=$GLOBALS['FORUM_DB']->query('SELECT f.* FROM '.$GLOBALS['FORUM_DB']->get_table_prefix().'f_custom_fields f LEFT JOIN '.$GLOBALS['FORUM_DB']->get_table_prefix().'translate tx ON (tx.id=f.cf_name AND '.db_string_equal_to('tx.language',get_site_default_lang()).') '.$where.' ORDER BY cf_order',NULL,NULL,false,false,array_key_exists('f_custom_fields',$TABLE_LANG_FIELDS)?$TABLE_LANG_FIELDS['f_custom_fields']:array());
$result=array();
foreach ($_result as $row)
{
$row['trans_name']=get_translated_text($row['cf_name'],$GLOBALS['FORUM_DB']);
if ((substr($row['trans_name'],0,4)=='ocp_') && ($special_start==0))
{
// See if it gets filtered
if (!array_key_exists(substr($row['trans_name'],4),$to_keep)) continue;
$test=do_lang('SPECIAL_CPF__'.$row['trans_name'],NULL,NULL,NULL,NULL,false);
if (!is_null($test)) $row['trans_name']=$test;
}
$result[]=$row;
}
$CUSTOM_FIELD_CACHE[$x]=$result;
}
$result2=array();
foreach ($result as $row)
{
if (($row['cf_only_group']=='') || (is_null($groups)) || (count(array_intersect(explode(',',$row['cf_only_group']),$groups))!=0)) $result2[]=$row;
}
return $result2;
}
array ocf_get_all_custom_fields_match_member(MEMBER member_id, ?BINARY public_view, ?BINARY owner_view, ?BINARY owner_set, ?BINARY encrypted, ?BINARY required, ?BINARY show_in_posts, ?BINARY show_in_post_previews, BINARY special_start, ?boolean show_on_join_form)
Gets all a member's custom fields that match certain parameters.
Parameters…
| Name |
member_id |
| Description |
The member. |
| Type |
MEMBER |
| Name |
public_view |
| Description |
That are publically viewable (NULL: don't care). |
| Default value |
|
| Type |
?BINARY |
| Name |
owner_view |
| Description |
That are owner viewable (NULL: don't care). |
| Default value |
|
| Type |
?BINARY |
| Name |
owner_set |
| Description |
That are owner settable (NULL: don't care). |
| Default value |
|
| Type |
?BINARY |
| Name |
encrypted |
| Description |
That are encrypted (NULL: don't care). |
| Default value |
|
| Type |
?BINARY |
| Name |
required |
| Description |
That are required (NULL: don't care). |
| Default value |
|
| Type |
?BINARY |
| Name |
show_in_posts |
| Description |
That are to be shown in posts (NULL: don't care). |
| Default value |
|
| Type |
?BINARY |
| Name |
show_in_post_previews |
| Description |
That are to be shown in post previews (NULL: don't care). |
| Default value |
|
| Type |
?BINARY |
| Name |
special_start |
| Description |
That start 'ocp_' |
| Default value |
0 |
| Type |
BINARY |
| Name |
show_on_join_form |
| Description |
That are to go on the join form (NULL: don't care). |
| Default value |
|
| Type |
?boolean |
Returns…
| Description |
A mapping of field title to a map of details: 'RAW' as the raw field value, 'RENDERED' as the rendered field value. |
| Type |
array |
function ocf_get_all_custom_fields_match_member($member_id,$public_view=NULL,$owner_view=NULL,$owner_set=NULL,$encrypted=NULL,$required=NULL,$show_in_posts=NULL,$show_in_post_previews=NULL,$special_start=0,$show_on_join_form=NULL)
{
$fields_to_show=ocf_get_all_custom_fields_match($GLOBALS['FORUM_DRIVER']->get_members_groups($member_id),$public_view,$owner_view,$owner_set,$required,$show_in_posts,$show_in_post_previews,$special_start,$show_on_join_form);
$custom_fields=array();
$member_mappings=ocf_get_custom_field_mappings($member_id);
$member_value=mixed(); // Initialise type to mixed
$all_cpf_permissions=((get_member()==$member_id)||$GLOBALS['FORUM_DRIVER']->is_super_admin(get_member()))?/*no restricts if you are the member or a super-admin*/array():list_to_map('field_id',$GLOBALS['FORUM_DB']->query_select('f_member_cpf_perms',array('*'),array('member_id'=>$member_id)));
require_code('fields');
foreach ($fields_to_show as $i=>$field_to_show)
{
$member_value=$member_mappings['field_'.strval($field_to_show['id'])];
// Decrypt the value if appropriate
if ((array_key_exists('cf_encrypted',$field_to_show)) && ($field_to_show['cf_encrypted']==1))
{
require_code('encryption');
if ((is_encryption_enabled()) && (!is_null(post_param('decrypt',NULL))))
{
$member_value=decrypt_data($member_value,post_param('decrypt'));
}
}
$ob=get_fields_hook($field_to_show['cf_type']);
list(,,$storage_type)=$ob->get_field_value_row_bits($field_to_show);
if (strpos($storage_type,'_trans')!==false)
{
if ((is_null($member_value)) || ($member_value==0)) $member_value=''; else $member_value=get_translated_tempcode($member_value,$GLOBALS['FORUM_DB']); // This is meant to be '' for blank, not new ocp_tempcode()
if ((is_object($member_value)) && ($member_value->is_empty())) $member_value='';
}
// get custom permissions for the current CPF
$cpf_permissions=array_key_exists($field_to_show['id'],$all_cpf_permissions)?$all_cpf_permissions[$field_to_show['id']]:array();
$display_cpf=true;
// if there are custom permissions set and we are not showing to all
if ((array_key_exists(0,$cpf_permissions)) && (!is_null($public_view)))
{
$display_cpf=false;
// Negative ones
if ($cpf_permissions[0]['guest_view']==1) $display_cpf=true;
if (!is_guest())
{
if ($cpf_permissions[0]['member_view']==1) $display_cpf=true;
}
if (!$display_cpf) // Guard this, as the code will take some time to run
{
if ($cpf_permissions[0]['friend_view']==1)
{
if (!is_null($GLOBALS['SITE_DB']->query_value_null_ok('chat_buddies','member_liked',array('member_likes'=>$member_id,'member_liked'=>get_member()))))
$display_cpf=true;
}
if (strlen($cpf_permissions[0]['group_view'])>0)
{
require_code('ocfiltering');
$groups=$GLOBALS['FORUM_DRIVER']->get_usergroup_list(false,false,false,NULL,$member_id);
$groups_to_search=array();
foreach (array_keys($groups) as $group_id)
{
$groups_to_search[$group_id]=NULL;
}
$matched_groups=ocfilter_to_idlist_using_memory($cpf_permissions[0]['group_view'],$groups_to_search);
if (count($matched_groups)>0)
{
$display_cpf=true;
}
}
}
}
if ($display_cpf)
{
$rendered_value=$ob->render_field_value($field_to_show,$member_value,$i,NULL);
$custom_fields[$field_to_show['trans_name']]=array('RAW'=>$member_value,'RENDERED'=>$rendered_value);
}
}
return $custom_fields;
}
?AUTO_LINK find_cpf_field_id(SHORT_TEXT title)
Get the ID for a CPF if we only know the title. Warning: Only use this with custom code, never core code! It assumes a single language and that fields aren't renamed.
Parameters…
| Name |
title |
| Description |
The title. |
| Type |
SHORT_TEXT |
Returns…
| Description |
The ID (NULL: could not find). |
| Type |
?AUTO_LINK |
function find_cpf_field_id($title)
{
$fields_to_show=ocf_get_all_custom_fields_match(NULL);
foreach ($fields_to_show as $field_to_show)
{
if ($field_to_show['trans_name']==$title)
{
return $field_to_show['id'];
}
}
return NULL;
}
array ocf_get_custom_field_mappings(MEMBER member_id)
Returns a list of all field values for user. Doesn't take translation into account. Doesn't take anything permissive into account.
Parameters…
| Name |
member_id |
| Description |
The member. |
| Type |
MEMBER |
Returns…
| Description |
The list. |
| Type |
array |
function ocf_get_custom_field_mappings($member_id)
{
require_code('fields');
global $MEMBER_CACHE_FIELD_MAPPINGS;
if (!array_key_exists($member_id,$MEMBER_CACHE_FIELD_MAPPINGS))
{
$query=$GLOBALS['FORUM_DB']->query_select('f_member_custom_fields',array('*'),array('mf_member_id'=>$member_id),'',1);
if (!array_key_exists(0,$query)) // Repair
{
$all_fields_regardless=$GLOBALS['FORUM_DB']->query_select('f_custom_fields',array('id','cf_type'));
$row=array('mf_member_id'=>$member_id);
foreach ($all_fields_regardless as $field)
{
$ob=get_fields_hook($field['cf_type']);
list(,$default,$storage_type)=$ob->get_field_value_row_bits($field,false,'',$GLOBALS['FORUM_DB']);
if (strpos($storage_type,'_trans')!==false)
{
$row['field_'.strval($field['id'])]=intval($default);
} else
{
$row['field_'.strval($field['id'])]=$default;
}
}
$GLOBALS['FORUM_DB']->query_insert('f_member_custom_fields',$row);
$query=array($row);
}
$MEMBER_CACHE_FIELD_MAPPINGS[$member_id]=$query[0];
}
return $MEMBER_CACHE_FIELD_MAPPINGS[$member_id];
}
array ocf_get_custom_fields_member(MEMBER member_id)
Returns a mapping between field number and field value. Doesn't take translation into account. Doesn't take anything permissive into account.
Parameters…
| Name |
member_id |
| Description |
The member. |
| Type |
MEMBER |
Returns…
| Description |
The mapping. |
| Type |
array |
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;
}
GROUP ocf_get_member_primary_group(MEMBER member_id)
Get the primary of a member (supports consulting of LDAP).
Parameters…
| Name |
member_id |
| Description |
The member. |
| Type |
MEMBER |
Returns…
| Description |
The primary. |
| Type |
GROUP |
function ocf_get_member_primary_group($member_id)
{
global $PRIMARY_GROUP_MEMBERS;
if (array_key_exists($member_id,$PRIMARY_GROUP_MEMBERS)) return $PRIMARY_GROUP_MEMBERS[$member_id];
if (ocf_is_ldap_member($member_id))
{
ocf_ldap_get_member_primary_group($member_id);
} else
{
$PRIMARY_GROUP_MEMBERS[$member_id]=$GLOBALS['OCF_DRIVER']->get_member_row_field($member_id,'m_primary_group');
}
return $PRIMARY_GROUP_MEMBERS[$member_id];
}
sources/ocf_members_action.php
Global_functions_ocf_members_action.php
Function summary
|
AUTO_LINK
|
ocf_make_member (SHORT_TEXT username, SHORT_TEXT password, SHORT_TEXT email_address, ?array groups, ?integer dob_day, ?integer dob_month, ?integer dob_year, array custom_fields, ?ID_TEXT timezone, ?GROUP primary_group, BINARY validated, ?TIME join_time, ?TIME last_visit_time, ID_TEXT theme, ?URLPATH avatar_url, LONG_TEXT signature, BINARY is_perm_banned, BINARY preview_posts, BINARY reveal_age, SHORT_TEXT title, URLPATH photo_url, URLPATH photo_thumb_url, BINARY views_signatures, ?BINARY auto_monitor_contrib_content, ?LANGUAGE_NAME language, BINARY allow_emails, BINARY allow_emails_from_staff, LONG_TEXT personal_notes, ?IP ip_address, SHORT_TEXT validated_email_confirm_code, boolean check_correctness, ?ID_TEXT password_compatibility_scheme, SHORT_TEXT salt, BINARY zone_wide, ?TIME last_submit_time, ?AUTO_LINK id, BINARY highlighted_name, SHORT_TEXT pt_allow, LONG_TEXT pt_rules_text)
|
|
AUTO_LINK
|
ocf_make_boiler_custom_field (ID_TEXT type)
|
|
array
|
get_cpf_storage_for (ID_TEXT type)
|
|
AUTO_LINK
|
ocf_make_custom_field (SHORT_TEXT name, BINARY locked, SHORT_TEXT description, LONG_TEXT default, BINARY public_view, BINARY owner_view, BINARY owner_set, BINARY encrypted, ID_TEXT type, BINARY required, BINARY show_in_posts, BINARY show_in_post_previews, ?integer order, LONG_TEXT only_group, boolean no_name_dupe, BINARY show_on_join_form)
|
AUTO_LINK ocf_make_member(SHORT_TEXT username, SHORT_TEXT password, SHORT_TEXT email_address, ?array groups, ?integer dob_day, ?integer dob_month, ?integer dob_year, array custom_fields, ?ID_TEXT timezone, ?GROUP primary_group, BINARY validated, ?TIME join_time, ?TIME last_visit_time, ID_TEXT theme, ?URLPATH avatar_url, LONG_TEXT signature, BINARY is_perm_banned, BINARY preview_posts, BINARY reveal_age, SHORT_TEXT title, URLPATH photo_url, URLPATH photo_thumb_url, BINARY views_signatures, ?BINARY auto_monitor_contrib_content, ?LANGUAGE_NAME language, BINARY allow_emails, BINARY allow_emails_from_staff, LONG_TEXT personal_notes, ?IP ip_address, SHORT_TEXT validated_email_confirm_code, boolean check_correctness, ?ID_TEXT password_compatibility_scheme, SHORT_TEXT salt, BINARY zone_wide, ?TIME last_submit_time, ?AUTO_LINK id, BINARY highlighted_name, SHORT_TEXT pt_allow, LONG_TEXT pt_rules_text)
Add a member.
Parameters…
| Name |
username |
| Description |
The username. |
| Type |
SHORT_TEXT |
| Name |
password |
| Description |
The password. |
| Type |
SHORT_TEXT |
| Name |
email_address |
| Description |
The e-mail address. |
| Type |
SHORT_TEXT |
| Name |
groups |
| Description |
A list of usergroups (NULL: default/current usergroups). |
| Type |
?array |
| Name |
dob_day |
| Description |
Day of date of birth (NULL: unknown). |
| Type |
?integer |
| Name |
dob_month |
| Description |
Month of date of birth (NULL: unknown). |
| Type |
?integer |
| Name |
dob_year |
| Description |
Year of date of birth (NULL: unknown). |
| Type |
?integer |
| Name |
custom_fields |
| Description |
A map of custom field values (field-id=>value). |
| Type |
array |
| Name |
timezone |
| Description |
The member timezone (NULL: auto-detect). |
| Default value |
|
| Type |
?ID_TEXT |
| Name |
primary_group |
| Description |
The member's primary (NULL: default). |
| Default value |
|
| Type |
?GROUP |
| Name |
validated |
| Description |
Whether the profile has been validated. |
| Default value |
1 |
| Type |
BINARY |
| Name |
join_time |
| Description |
When the member joined (NULL: now). |
| Default value |
|
| Type |
?TIME |
| Name |
last_visit_time |
| Description |
When the member last visited (NULL: now). |
| Default value |
|
| Type |
?TIME |
| Name |
theme |
| Description |
The member's default theme. |
| Default value |
|
| Type |
ID_TEXT |
| Name |
avatar_url |
| Description |
The URL to the member's avatar (blank: none) (NULL: choose one automatically). |
| Default value |
|
| Type |
?URLPATH |
| Name |
signature |
| Description |
The member's signature (blank: none). |
| Default value |
|
| Type |
LONG_TEXT |
| Name |
is_perm_banned |
| Description |
Whether the member is permanently banned. |
| Default value |
0 |
| Type |
BINARY |
| Name |
preview_posts |
| Description |
Whether posts are previewed before they are made. |
| Default value |
0 |
| Type |
BINARY |
| Name |
reveal_age |
| Description |
Whether the member's age may be shown. |
| Default value |
1 |
| Type |
BINARY |
| Name |
title |
| Description |
The member's title (blank: get from primary). |
| Default value |
|
| Type |
SHORT_TEXT |
| Name |
photo_url |
| Description |
The URL to the member's photo (blank: none). |
| Default value |
|
| Type |
URLPATH |
| Name |
photo_thumb_url |
| Description |
The URL to the member's photo thumbnail (blank: none). |
| Default value |
|
| Type |
URLPATH |
| Name |
views_signatures |
| Description |
Whether the member sees signatures in posts. |
| Default value |
1 |
| Type |
BINARY |
| Name |
auto_monitor_contrib_content |
| Description |
Whether the member automatically is enabled for notifications for content they contribute to (NULL: get default from config). |
| Default value |
|
| Type |
?BINARY |
| Name |
language |
| Description |
The member's language (NULL: auto detect). |
| Default value |
|
| Type |
?LANGUAGE_NAME |
| Name |
allow_emails |
| Description |
Whether the member allows e-mails via the site. |
| Default value |
1 |
| Type |
BINARY |
| Name |
allow_emails_from_staff |
| Description |
Whether the member allows e-mails from staff via the site. |
| Default value |
1 |
| Type |
BINARY |
| Name |
personal_notes |
| Description |
Personal notes of the member. |
| Default value |
|
| Type |
LONG_TEXT |
| Name |
ip_address |
| Description |
The member's IP address (NULL: IP address of current user). |
| Default value |
|
| Type |
?IP |
| Name |
validated_email_confirm_code |
| Description |
The code required before the account becomes active (blank: already entered). |
| Default value |
|
| Type |
SHORT_TEXT |
| Name |
check_correctness |
| Description |
Whether to check details for correctness. |
| Default value |
boolean-true |
| Type |
boolean |
| Name |
password_compatibility_scheme |
| Description |
The compatibility scheme that the password operates in (blank: none) (NULL: none [meaning normal ocPortal salted style] or plain, depending on whether passwords are encrypted). |
| Default value |
|
| Type |
?ID_TEXT |
| Name |
salt |
| Description |
The password salt (blank: password compatibility scheme does not use a salt / auto-generate). |
| Default value |
|
| Type |
SHORT_TEXT |
| Name |
zone_wide |
| Description |
Whether the member likes to view zones without menus, when a choice is available. |
| Default value |
1 |
| Type |
BINARY |
| Name |
last_submit_time |
| Description |
The time the member last made a submission (NULL: set to now). |
| Default value |
|
| Type |
?TIME |
| Name |
id |
| Description |
Force an ID (NULL: don't force an ID) |
| Default value |
|
| Type |
?AUTO_LINK |
| Name |
highlighted_name |
| Description |
Whether the member username will be highlighted. |
| Default value |
0 |
| Type |
BINARY |
| Name |
pt_allow |
| Description |
Usergroups that may PT the member. |
| Default value |
* |
| Type |
SHORT_TEXT |
| Name |
pt_rules_text |
| Description |
Rules that other members must agree to before they may start a PT with the member. |
| Default value |
|
| Type |
LONG_TEXT |
Returns…
| Description |
The ID of the new member. |
| Type |
AUTO_LINK |
function ocf_make_member($username,$password,$email_address,$groups,$dob_day,$dob_month,$dob_year,$custom_fields,$timezone=NULL,$primary_group=NULL,$validated=1,$join_time=NULL,$last_visit_time=NULL,$theme='',$avatar_url=NULL,$signature='',$is_perm_banned=0,$preview_posts=0,$reveal_age=1,$title='',$photo_url='',$photo_thumb_url='',$views_signatures=1,$auto_monitor_contrib_content=NULL,$language=NULL,$allow_emails=1,$allow_emails_from_staff=1,$personal_notes='',$ip_address=NULL,$validated_email_confirm_code='',$check_correctness=true,$password_compatibility_scheme=NULL,$salt='',$zone_wide=1,$last_submit_time=NULL,$id=NULL,$highlighted_name=0,$pt_allow='*',$pt_rules_text='')
{
if (is_null($auto_monitor_contrib_content))
{
$auto_monitor_contrib_content=(get_value('no_auto_notifications')==='1')?0:1;
}
if (is_null($password_compatibility_scheme))
{
if (get_value('no_password_hashing')==='1')
{
$password_compatibility_scheme='plain';
} else
{
$password_compatibility_scheme='';
}
}
if (is_null($language)) $language='';
if (is_null($signature)) $signature='';
if (is_null($title)) $title='';
if (is_null($timezone)) $timezone=get_site_timezone();
if (is_null($allow_emails)) $allow_emails=1;
if (is_null($allow_emails_from_staff)) $allow_emails_from_staff=1;
if (is_null($personal_notes)) $personal_notes='';
if (is_null($avatar_url))
{
if (($GLOBALS['IN_MINIKERNEL_VERSION']==1) || (!addon_installed('ocf_member_avatars')))
{
$avatar_url='';
} else
{
if ((get_option('random_avatars')=='1') && (!running_script('stress_test_loader')))
{
require_code('themes2');
$codes=get_all_image_ids_type('ocf_default_avatars/default_set',false,$GLOBALS['FORUM_DB']);
shuffle($codes);
$results=array();
foreach ($codes as $code)
{
if (strpos($code,'ocp_fanatic')!==false) continue;
$count=$GLOBALS['FORUM_DB']->query_value_null_ok_full('SELECT SUM(m_cache_num_posts) FROM '.$GLOBALS['FORUM_DB']->get_table_prefix().'f_members WHERE '.db_string_equal_to('m_avatar_url',find_theme_image($code,false,true)));
if (is_null($count)) $count=0;
$results[$code]=$count;
}
@asort($results); // @'d as type checker fails for some odd reason
$found_avatars=array_keys($results);
$avatar_url=find_theme_image(array_shift($found_avatars),true,true);
}
if (is_null($avatar_url))
{
$GLOBALS['SITE_DB']->query_delete('theme_images',array('id'=>'ocf_default_avatars/default','path'=>'')); // In case failure cached, gets very confusing
$avatar_url=find_theme_image('ocf_default_avatars/default',true,true);
if (is_null($avatar_url))
$avatar_url='';
}
}
}
if ($check_correctness)
{
if (!in_array($password_compatibility_scheme,array('ldap','httpauth'))) ocf_check_name_valid($username,NULL,$password);
if ((!function_exists('has_actual_page_access')) || (!has_actual_page_access(get_member(),'admin_ocf_join')))
{
require_code('type_validation');
if ((!is_valid_email_address($email_address)) && ($email_address!=''))
warn_exit(do_lang_tempcode('_INVALID_EMAIL_ADDRESS',escape_html($email_address)));
}
}
require_code('ocf_members');
require_code('ocf_groups');
if (is_null($last_submit_time)) $last_submit_time=time();
if (is_null($join_time)) $join_time=time();
if (is_null($last_visit_time)) $last_visit_time=time();
if (is_null($primary_group))
{
$primary_group=get_first_default_group(); // This is members
$secondary_groups=ocf_get_all_default_groups();
} else $secondary_groups=ocf_get_all_default_groups();
if (is_null($ip_address)) $ip_address=get_ip_address();
if (($password_compatibility_scheme=='') && (get_value('no_password_hashing')==='1'))
{
$password_compatibility_scheme='plain';
$salt='';
}
if (($salt=='') && ($password_compatibility_scheme==''))
{
$salt=produce_salt();
$password_salted=md5($salt.md5($password));
} else
{
$password_salted=$password;
}
// Supplement custom field values given with defaults, and check constraints
if (is_null($groups)) $groups=ocf_get_all_default_groups(true);
$all_fields=ocf_get_all_custom_fields_match($groups);
require_code('fields');
foreach ($all_fields as $field)
{
$field_id=$field['id'];
if (array_key_exists($field_id,$custom_fields))
{
if (($check_correctness) && ($field[array_key_exists('cf_show_on_join_form',$field)?'cf_show_on_join_form':'cf_required']==0) && ($field['cf_owner_set']==0) && (!has_actual_page_access(get_member(),'admin_ocf_join')))
{
access_denied('I_ERROR');
}
} else
{
$custom_fields[$field_id]='';
}
}
if (!addon_installed('unvalidated')) $validated=1;
$map=array(
'm_username'=>$username,
'm_pass_hash_salted'=>$password_salted,
'm_pass_salt'=>$salt,
'm_theme'=>$theme,
'm_avatar_url'=>$avatar_url,
'm_validated'=>$validated,
'm_validated_email_confirm_code'=>$validated_email_confirm_code,
'm_cache_num_posts'=>0,
'm_cache_warnings'=>0,
'm_max_email_attach_size_mb'=>5,
'm_join_time'=>$join_time,
'm_timezone_offset'=>$timezone,
'm_primary_group'=>$primary_group,
'm_last_visit_time'=>$last_visit_time,
'm_last_submit_time'=>$last_submit_time,
'm_signature'=>insert_lang_comcode($signature,4,$GLOBALS['FORUM_DB']),
'm_is_perm_banned'=>$is_perm_banned,
'm_preview_posts'=>$preview_posts,
'm_notes'=>$personal_notes,
'm_dob_day'=>$dob_day,
'm_dob_month'=>$dob_month,
'm_dob_year'=>$dob_year,
'm_reveal_age'=>$reveal_age,
'm_email_address'=>$email_address,
'm_title'=>$title,
'm_photo_url'=>$photo_url,
'm_photo_thumb_url'=>$photo_thumb_url,
'm_views_signatures'=>$views_signatures,
'm_auto_monitor_contrib_content'=>$auto_monitor_contrib_content,
'm_highlighted_name'=>$highlighted_name,
'm_pt_allow'=>$pt_allow,
'm_pt_rules_text'=>insert_lang_comcode($pt_rules_text,4,$GLOBALS['FORUM_DB']),
'm_language'=>$language,
'm_ip_address'=>$ip_address,
'm_zone_wide'=>$zone_wide,
'm_allow_emails'=>$allow_emails,
'm_allow_emails_from_staff'=>$allow_emails_from_staff,
'm_password_change_code'=>'',
'm_password_compat_scheme'=>$password_compatibility_scheme,
'm_on_probation_until'=>NULL
);
if (!is_null($id)) $map['id']=$id;
$member_id=$GLOBALS['FORUM_DB']->query_insert('f_members',$map,true);
if ($check_correctness)
{
// If it was an invite/recommendation, award the referrer
if (addon_installed('recommend'))
{
$inviter=$GLOBALS['FORUM_DB']->query_value_null_ok('f_invites','i_inviter',array('i_email_address'=>$email_address),'ORDER BY i_time');
if (!is_null($inviter))
{
if (addon_installed('points'))
{
require_code('points2');
require_lang('recommend');
system_gift_transfer(do_lang('RECOMMEND_SITE_TO',$username,get_site_name()),intval(get_option('points_RECOMMEND_SITE')),$inviter);
}
if (addon_installed('chat'))
{
require_code('chat2');
buddy_add($inviter,$member_id);
buddy_add($member_id,$inviter);
}
}
}
}
$value=mixed();
// Store custom fields
$row=array('mf_member_id'=>$member_id);
$all_fields_types=collapse_2d_complexity('id','cf_type',$all_fields);
foreach ($custom_fields as $field_num=>$value)
{
if (!array_key_exists($field_num,$all_fields_types)) continue; // Trying to set a field we're not allowed to (doesn't apply to our group)
$ob=get_fields_hook($all_fields_types[$field_num]);
list(,,$storage_type)=$ob->get_field_value_row_bits($all_fields_types[$field_num]);
if (strpos($storage_type,'_trans')!==false)
{
$value=insert_lang($value,3,$GLOBALS['FORUM_DB']);
}
$row['field_'.strval($field_num)]=$value;
}
// Set custom field row
$all_fields_regardless=$GLOBALS['FORUM_DB']->query_select('f_custom_fields',array('id','cf_type'));
foreach ($all_fields_regardless as $field)
{
if (!array_key_exists('field_'.strval($field['id']),$row))
{
$ob=get_fields_hook($field['cf_type']);
list(,,$storage_type)=$ob->get_field_value_row_bits($field);
$value='';
if (strpos($storage_type,'_trans')!==false)
{
$value=insert_lang($value,3,$GLOBALS['FORUM_DB']);
}
$row['field_'.strval($field['id'])]=$value;
}
}
$GLOBALS['FORUM_DB']->query_insert('f_member_custom_fields',$row);
// Any secondary work
foreach ($secondary_groups as $g)
{
if ($g!=$primary_group)
{
$GLOBALS['FORUM_DB']->query_insert('f_group_members',array(
'gm_group_id'=>$g,
'gm_member_id'=>$member_id,
'gm_validated'=>1
));
}
}
if ($check_correctness)
{
if (function_exists('decache')) decache('side_stats');
}
return $member_id;
}
AUTO_LINK ocf_make_boiler_custom_field(ID_TEXT type)
Make a custom profile field from one of the predefined templates (this is often used by importers).
Parameters…
| Name |
type |
| Description |
The identifier of the boiler custom profile field. |
| Type |
ID_TEXT |
Returns…
| Description |
The ID of the new custom profile field. |
| Type |
AUTO_LINK |
function ocf_make_boiler_custom_field($type)
{
$_type='long_trans';
if (substr($type,0,3)=='im_') $_type='short_text';
elseif ($type=='location') $_type='short_text';
elseif ($type=='occupation') $_type='short_text';
elseif ($type=='website') $_type='short_trans';
$public_view=1;
$owner_view=1;
$owner_set=1;
if ($type=='staff_notes')
{
$public_view=0;
$owner_view=0;
$owner_set=0;
}
global $CUSTOM_FIELD_CACHE;
$CUSTOM_FIELD_CACHE=array();
return ocf_make_custom_field(do_lang('DEFAULT_CPF_'.$type.'_NAME'),0,do_lang('DEFAULT_CPF_'.$type.'_DESCRIPTION'),'',$public_view,$owner_view,$owner_set,0,$_type,0,0,0,NULL,'',true);
}
array get_cpf_storage_for(ID_TEXT type)
Find how to store a field in the database.
Parameters…
| Name |
type |
| Description |
The field type. |
| Type |
ID_TEXT |
Returns…
| Description |
A pair: the DB field type, whether to index. |
| Type |
array |
function get_cpf_storage_for($type)
{
require_code('fields');
$ob=get_fields_hook($type);
list(,,$storage_type)=$ob->get_field_value_row_bits(array('cf_type'=>$type,'cf_default'=>''));
$_type='SHORT_TEXT';
switch ($storage_type)
{
case 'short_trans':
$_type='SHORT_TRANS';
break;
case 'long_trans':
$_type='LONG_TRANS';
break;
case 'long':
$_type='LONG_TEXT';
break;
}
$index=true;
switch ($type)
{
case 'short_trans':
case 'short_trans_multi':
case 'long_trans':
case 'posting_field':
case 'tick':
case 'integer':
case 'float':
case 'color':
case 'content_link':
case 'date':
case 'just_date':
case 'just_time':
case 'picture':
case 'password':
case 'page_link':
case 'upload':
$index=false;
break;
}
return array($_type,$index);
}
AUTO_LINK ocf_make_custom_field(SHORT_TEXT name, BINARY locked, SHORT_TEXT description, LONG_TEXT default, BINARY public_view, BINARY owner_view, BINARY owner_set, BINARY encrypted, ID_TEXT type, BINARY required, BINARY show_in_posts, BINARY show_in_post_previews, ?integer order, LONG_TEXT only_group, boolean no_name_dupe, BINARY show_on_join_form)
Make a custom profile field.
Parameters…
| Name |
name |
| Description |
Name of the field. |
| Type |
SHORT_TEXT |
| Name |
locked |
| Description |
Whether the field is locked (i.e. cannot be deleted from the system). |
| Default value |
0 |
| Type |
BINARY |
| Name |
description |
| Description |
Description of the field. |
| Default value |
|
| Type |
SHORT_TEXT |
| Name |
default |
| Description |
The default value for the field. |
| Default value |
|
| Type |
LONG_TEXT |
| Name |
public_view |
| Description |
Whether the field is publically viewable. |
| Default value |
0 |
| Type |
BINARY |
| Name |
owner_view |
| Description |
Whether the field is viewable by the owner. |
| Default value |
0 |
| Type |
BINARY |
| Name |
owner_set |
| Description |
Whether the field may be set by the owner. |
| Default value |
0 |
| Type |
BINARY |
| Name |
encrypted |
| Description |
Whether the field is encrypted. |
| Default value |
0 |
| Type |
BINARY |
| Name |
type |
| Description |
The type of the field. |
| Default value |
long_text |
| Type |
ID_TEXT |
| Values restricted to |
short_text long_text short_trans long_trans integer upload picture url list tick float |
| Name |
required |
| Description |
Whether it is required that every member have this field filled in. |
| Default value |
0 |
| Type |
BINARY |
| Name |
show_in_posts |
| Description |
Whether this field is shown in posts and places where member details are highlighted (such as an image in a member gallery). |
| Default value |
0 |
| Type |
BINARY |
| Name |
show_in_post_previews |
| Description |
Whether this field is shown in preview places, such as in the teaser for a member gallery. |
| Default value |
0 |
| Type |
BINARY |
| Name |
order |
| Description |
The order of this field relative to other fields (NULL: next). |
| Default value |
|
| Type |
?integer |
| Name |
only_group |
| Description |
The usergroups that this field is confined to (comma-separated list). |
| Default value |
|
| Type |
LONG_TEXT |
| Name |
no_name_dupe |
| Description |
Whether to check that no field has this name already. |
| Default value |
boolean-false |
| Type |
boolean |
| Name |
show_on_join_form |
| Description |
Whether the field is to be shown on the join form |
| Default value |
0 |
| Type |
BINARY |
Returns…
| Description |
The ID of the new custom profile field. |
| Type |
AUTO_LINK |
function ocf_make_custom_field($name,$locked=0,$description='',$default='',$public_view=0,$owner_view=0,$owner_set=0,$encrypted=0,$type='long_text',$required=0,$show_in_posts=0,$show_in_post_previews=0,$order=NULL,$only_group='',$no_name_dupe=false,$show_on_join_form=0)
{
$dbs_back=$GLOBALS['NO_DB_SCOPE_CHECK'];
$GLOBALS['NO_DB_SCOPE_CHECK']=true;
if ($only_group=='-1') $only_group='';
// Can only encrypt things if encryption support is available
require_code('encryption');
//if (!is_encryption_enabled()) $encrypted=0;
// Can't have publically-viewable encrypted fields
if ($encrypted==1)
{
$public_view=0;
}
if ($no_name_dupe)
{
$test=$GLOBALS['FORUM_DB']->query_value_null_ok('f_custom_fields f LEFT JOIN '.$GLOBALS['FORUM_DB']->get_table_prefix().'translate t ON f.cf_name=t.id','f.id',array('text_original'=>$name));
if (!is_null($test))
{
$GLOBALS['NO_DB_SCOPE_CHECK']=$dbs_back;
return $test;
}
}
if (is_null($order))
{
$order=$GLOBALS['FORUM_DB']->query_value('f_custom_fields','MAX(cf_order)');
if (is_null($order)) $order=0; else $order++;
}
$map=array(
'cf_name'=>insert_lang($name,2,$GLOBALS['FORUM_DB']),
'cf_locked'=>$locked,
'cf_description'=>insert_lang($description,2,$GLOBALS['FORUM_DB']),
'cf_default'=>$default,
'cf_public_view'=>$public_view,
'cf_owner_view'=>$owner_view,
'cf_owner_set'=>$owner_set,
'cf_type'=>$type,
'cf_required'=>$required,
'cf_show_in_posts'=>$show_in_posts,
'cf_show_in_post_previews'=>$show_in_post_previews,
'cf_order'=>$order,
'cf_only_group'=>$only_group,
'cf_show_on_join_form'=>$show_on_join_form
);
$id=$GLOBALS['FORUM_DB']->query_insert('f_custom_fields',$map+array('cf_encrypted'=>$encrypted),true,true);
if (is_null($id)) $id=$GLOBALS['FORUM_DB']->query_insert('f_custom_fields',$map,true); // Still upgrading, cf_encrypted does not exist yet
list($_type,$index)=get_cpf_storage_for($type);
require_code('database_action');
// ($index?'#':'').
$GLOBALS['FORUM_DB']->add_table_field('f_member_custom_fields','field_'.strval($id),$_type); // Default will be made explicit when we insert rows
if ($index)
{
$indices_count=$GLOBALS['FORUM_DB']->query_value_null_ok_full('SELECT COUNT(*) FROM '.get_table_prefix().'f_custom_fields WHERE '.db_string_not_equal_to('cf_type','integer').' AND '.db_string_not_equal_to('cf_type','tick').' AND '.db_string_not_equal_to('cf_type','long_trans').' AND '.db_string_not_equal_to('cf_type','short_trans'));
if ($indices_count<60) // Could be 64 but trying to be careful here...
{
$GLOBALS['FORUM_DB']->create_index('f_member_custom_fields','#mcf'.strval($id),array('field_'.strval($id)),'mf_member_id');
}
}
log_it('ADD_CUSTOM_PROFILE_FIELD',strval($id),$name);
$GLOBALS['NO_DB_SCOPE_CHECK']=$dbs_back;
return $id;
}
0 reviews: Unrated (average)
There have been no comments yet