ocPortal Developer's Guide: Users and forums
» Return to Contents
sources/users.php
Global_functions_users.php
void init__users()
Standard code module initialisation function.
Parameters…
(No return value)
function init__users()
{
global $MEMBERS_BLOCKED,$MEMBERS_BLOCKING_US;
$MEMBERS_BLOCKED=NULL;
$MEMBERS_BLOCKING_US=NULL;
global $SESSION_CACHE,$MEMBER_CACHED,$ADMIN_GROUP_CACHE,$MODERATOR_GROUP_CACHE,$USERGROUP_LIST_CACHE;
global $USER_NAME_CACHE,$MEMBER_EMAIL_CACHE,$USERS_GROUPS_CACHE;
global $SESSION_CONFIRMED,$GETTING_MEMBER,$EMOTICON_CACHE,$CACHED_THEME,$EMOTICON_LEVELS,$EMOTICON_SET_DIR;
$EMOTICON_LEVELS=NULL;
$USER_NAME_CACHE=array();
$MEMBER_EMAIL_CACHE=array();
$USERGROUP_LIST_CACHE=NULL;
$USERS_GROUPS_CACHE=array();
$ADMIN_GROUP_CACHE=NULL;
$MODERATOR_GROUP_CACHE=NULL;
$MEMBER_CACHED=NULL;
$SESSION_CONFIRMED=0;
$GETTING_MEMBER=false;
$EMOTICON_CACHE=NULL;
$CACHED_THEME=NULL;
$EMOTICON_SET_DIR=NULL;
global $IS_ACTUALLY_ADMIN;
$IS_ACTUALLY_ADMIN=false;
global $IS_A_COOKIE_LOGIN;
$IS_A_COOKIE_LOGIN=false;
// Load all sessions into memory, if possible
if (get_value('session_prudence')!=='1')
{
$SESSION_CACHE=persistant_cache_get('SESSION_CACHE');
} else
{
$SESSION_CACHE=NULL;
}
global $IN_MINIKERNEL_VERSION;
if ((!is_array($SESSION_CACHE)) && ($IN_MINIKERNEL_VERSION==0))
{
if (get_value('session_prudence')!=='1')
{
$where='';
} else
{
$where=' WHERE the_session='.strval(get_session_id()).' OR '.db_string_equal_to('ip',get_ip_address());
}
$SESSION_CACHE=array();
if ((get_forum_type()=='ocf') && (get_db_site()==get_db_forums()) && (get_db_site_host()==get_db_forums_host()))
{
$GLOBALS['NO_DB_SCOPE_CHECK']=true;
$_s=$GLOBALS['SITE_DB']->query('SELECT s.*,m.m_primary_group FROM '.get_table_prefix().'sessions s LEFT JOIN '.$GLOBALS['SITE_DB']->get_table_prefix().'f_members m ON m.id=s.the_user'.$where);
$SESSION_CACHE=list_to_map('the_session',$_s);
$GLOBALS['NO_DB_SCOPE_CHECK']=false;
} else
{
$SESSION_CACHE=list_to_map('the_session',$GLOBALS['SITE_DB']->query('SELECT * FROM '.get_table_prefix().'sessions'.$where));
}
if (get_value('session_prudence')!=='1')
{
persistant_cache_set('SESSION_CACHE',$SESSION_CACHE);
}
}
// Canonicalise various disparities in how HTTP auth environment variables are set
if (array_key_exists('REDIRECT_REMOTE_USER',$_SERVER))
$_SERVER['PHP_AUTH_USER']=preg_replace('#@.*$#','',$_SERVER['REDIRECT_REMOTE_USER']);
if (array_key_exists('PHP_AUTH_USER',$_SERVER))
$_SERVER['PHP_AUTH_USER']=preg_replace('#@.*$#','',$_SERVER['PHP_AUTH_USER']);
if (array_key_exists('REMOTE_USER',$_SERVER))
$_SERVER['PHP_AUTH_USER']=preg_replace('#@.*$#','',$_SERVER['REMOTE_USER']);
}
void handle_logins()
Handles an attempted login or logout, and take care of all the sessions and cookies etc.
Parameters…
(No return value)
function handle_logins()
{
if (get_param_integer('httpauth',0)==1)
{
require_code('users_inactive_occasionals');
force_httpauth();
}
$username=trim(post_param('login_username',''));
if (($username!='') && ($username!=do_lang('GUEST')))
{
require_code('users_active_actions');
handle_active_login($username);
}
// If it was a log out
$page=get_page_name();
$type=get_param('type','',true);
if (($page=='login') && ($type=='logout'))
{
require_code('users_active_actions');
handle_active_logout();
}
}
boolean is_guest(?MEMBER member_id, boolean quick_only)
Find whether the current member is a guest.
Parameters…
| Name |
member_id |
| Description |
Member ID to check (NULL: current user) |
| Default value |
|
| Type |
?MEMBER |
| Name |
quick_only |
| Description |
Whether to just do a quick check, don't establish new sessions |
| Default value |
boolean-false |
| Type |
boolean |
Returns…
| Description |
Whether the current member is a guest |
| Type |
boolean |
function is_guest($member_id=NULL,$quick_only=false)
{
if (!isset($GLOBALS['FORUM_DRIVER'])) return true;
if ($member_id===NULL) $member_id=get_member($quick_only);
return ($GLOBALS['FORUM_DRIVER']->get_guest_id()==$member_id);
}
MEMBER get_member(boolean quick_only)
Get the ID of the currently active member.It see's if the session exists / cookie is valid – and gets the member id accordingly
Parameters…
| Name |
quick_only |
| Description |
Whether to just do a quick check, don't establish new sessions |
| Default value |
boolean-false |
| Type |
boolean |
Returns…
| Description |
The member requesting this web page (possibly the guest member - which strictly speaking, is not a member) |
| Type |
MEMBER |
function get_member($quick_only=false)
{
global $SESSION_CACHE,$MEMBER_CACHED,$GETTING_MEMBER,$SITE_INFO;
if ($MEMBER_CACHED!==NULL)
{
$GETTING_MEMBER=false;
return $MEMBER_CACHED;
}
// If lots of aging sessions, clean out
reset($SESSION_CACHE);
if ((count($SESSION_CACHE)>50) && ($SESSION_CACHE[key($SESSION_CACHE)]['last_activity']<time()-60*60*max(1,intval(get_option('session_expiry_time')))))
delete_expired_sessions_or_recover();
// Try via backdoor that someone with full server access can place
$backdoor_ip_address=mixed(); // Enable to a real IP address to force login from FTP access (if lost admin password)
if (array_key_exists('backdoor_ip',$SITE_INFO)) $backdoor_ip_address=$SITE_INFO['backdoor_ip'];
if ((is_string($backdoor_ip_address)) && (get_ip_address()==$backdoor_ip_address))
{
require_code('users_active_actions');
$MEMBER_CACHED=restricted_manually_enabled_backdoor();
// Will have created a session in here already
return $MEMBER_CACHED;
}
if ($GETTING_MEMBER)
{
if (!isset($GLOBALS['FORUM_DRIVER'])) return db_get_first_id(); // :S
return $GLOBALS['FORUM_DRIVER']->get_guest_id();
}
$GETTING_MEMBER=true;
global $FORCE_INVISIBLE_GUEST;
if ($FORCE_INVISIBLE_GUEST)
{
$GETTING_MEMBER=false;
if (!isset($GLOBALS['FORUM_DRIVER']))
{
fatal_exit(do_lang_tempcode('INTERNAL_ERROR'));
}
$MEMBER_CACHED=$GLOBALS['FORUM_DRIVER']->get_guest_id();
return $MEMBER_CACHED;
}
$member=NULL;
$cookie_bits=explode(':',str_replace('|',':',get_member_cookie()));
$base=$cookie_bits[0];
// Try by session
$session=get_session_id();
if (($session!=-1) && (get_param_integer('keep_force_htaccess',0)==0))
{
$ip=get_ip_address(3); // I hope AOL can cope with this
$allow_unbound_guest=true; // Note: Guest sessions are not IP bound
$member_row=NULL;
if (($SESSION_CACHE!==NULL) && (array_key_exists($session,$SESSION_CACHE)) && ($SESSION_CACHE[$session]!==NULL) && (array_key_exists('the_user',$SESSION_CACHE[$session])) && ((get_option('ip_strict_for_sessions')=='0') || ($SESSION_CACHE[$session]['ip']==$ip) || ((is_guest($SESSION_CACHE[$session]['the_user'])) && ($allow_unbound_guest)) || (($SESSION_CACHE[$session]['session_confirmed']==0) && (!is_guest($SESSION_CACHE[$session]['the_user'])))) && ($SESSION_CACHE[$session]['last_activity']>time()-60*60*max(1,intval(get_option('session_expiry_time')))))
$member_row=$SESSION_CACHE[$session];
if (($member_row!==NULL) && ((!array_key_exists($base,$_COOKIE)) || (!is_guest($member_row['the_user']))))
{
$member=$member_row['the_user'];
if (($member!==NULL) && ((time()-$member_row['last_activity'])>10)) // Performance optimisation. Pointless re-storing the last_activity if less than 3 seconds have passed!
{
//$GLOBALS['SITE_DB']->query_update('sessions',array('last_activity'=>time(),'the_zone'=>get_zone_name(),'the_page'=>get_page_name()),array('the_session'=>$session),'',1); Done in get_page_title now
$SESSION_CACHE[$session]['last_activity']=time();
if (get_value('session_prudence')!=='1')
{
persistant_cache_set('SESSION_CACHE',$SESSION_CACHE);
}
}
global $SESSION_CONFIRMED;
$SESSION_CONFIRMED=$member_row['session_confirmed'];
if (get_forum_type()=='ocf') $GLOBALS['FORUM_DRIVER']->ocf_flood_control($member);
if ((!is_guest($member)) && ($GLOBALS['FORUM_DRIVER']->is_banned($member))) // All hands to the guns
{
warn_exit(do_lang_tempcode('USER_BANNED'));
}
// Test this member still exists
if ($GLOBALS['FORUM_DRIVER']->get_username($member)===NULL) $member=$GLOBALS['FORUM_DRIVER']->get_guest_id();
if (array_key_exists($base,$_COOKIE))
{
global $IS_A_COOKIE_LOGIN;
$IS_A_COOKIE_LOGIN=true;
}
} else
{
require_code('users_inactive_occasionals');
set_session_id(-1);
}
}
if (($member===NULL) && (get_session_id()==-1) && (get_param_integer('keep_force_htaccess',0)==0))
{
// Try by cookie (will defer to forum driver to authorise against detected cookie)
require_code('users_inactive_occasionals');
$member=try_cookie_login();
// Can forum driver help more directly?
if (method_exists($GLOBALS['FORUM_DRIVER'],'get_member')) $member=$GLOBALS['FORUM_DRIVER']->get_member();
}
// Try via additional login providers. They can choose whether to respect existing $member of get_session_id() settings. Some may do an account linkage, so we need to let them decide what to do.
$hooks=find_all_hooks('systems','login_providers');
foreach (array_keys($hooks) as $hook)
{
require_code('hooks/systems/login_providers/'.$hook);
$ob=object_factory('Hook_login_provider_'.$hook);
$member=$ob->try_login($member);
}
// Guest or banned
if ($member===NULL)
{
$member=$GLOBALS['FORUM_DRIVER']->get_guest_id();
$is_guest=true;
} else
{
$is_guest=is_guest($member);
}
// If we are doing a very quick init, bomb out now - no need to establish session etc
global $SITE_INFO;
if ($quick_only)
{
$GETTING_MEMBER=false;
return $member;
}
// If one of the try_* functions hasn't actually created the session, call it here
$session=get_session_id();
if ($session==-1)
{
require_code('users_inactive_occasionals');
create_session($member);
}
// If we are logged in, maybe do some further processing
if (!$is_guest)
{
// Is there a su operation?
$ks=get_param('keep_su','');
if ($ks!='')
{
require_code('users_inactive_occasionals');
$member=try_su_login($member);
}
// Run hooks, if any exist
$hooks=find_all_hooks('systems','upon_login');
foreach (array_keys($hooks) as $hook)
{
require_code('hooks/systems/upon_login/'.filter_naughty($hook));
$ob=object_factory('upon_login'.filter_naughty($hook),true);
if ($ob===NULL) continue;
$ob->run(false,NULL,$member); // false means "not a new login attempt"
}
}
// Ok we have our answer
$MEMBER_CACHED=$member;
$GETTING_MEMBER=false;
// We call this to ensure any HTTP-auth specific code has a chance to run
is_httpauth_login();
return $member;
}
string apply_forum_driver_md5_variant(string data, string key)
Apply hashing to some input. To this date, all forum drivers use md5, but some use it differently.This function will pass through the parameters to an equivalent forum_md5 function if it is defined.
Parameters…
| Name |
data |
| Description |
The data to hash (the password in actuality) |
| Type |
string |
| Name |
key |
| Description |
The string converted member-ID in actuality, although this function is more general |
| Type |
string |
Returns…
| Description |
The hashed data |
| Type |
string |
function apply_forum_driver_md5_variant($data,$key)
{
if (method_exists($GLOBALS['FORUM_DRIVER'],'forum_md5')) return $GLOBALS['FORUM_DRIVER']->forum_md5($data,$key);
return md5($data);
}
integer get_session_id()
Get the current session ID.
Parameters…
Returns…
| Description |
The current session ID |
| Type |
integer |
function get_session_id()
{
if ((!isset($_COOKIE['ocp_session'])) || (/*To work around OcCLE's development mode trick*/$GLOBALS['DEBUG_MODE'] && running_script('occle')))
{
if (array_key_exists('keep_session',$_GET)) return get_param_integer('keep_session');
return (-1);
}
return intval($_COOKIE['ocp_session']); // No need to stripslashes as it's numeric
}
boolean is_httpauth_login()
Find whether the current member is logged in via httpauth.
Parameters…
Returns…
| Description |
Whether the current member is logged in via httpauth |
| Type |
boolean |
function is_httpauth_login()
{
if (get_forum_type()!='ocf') return false;
if (is_guest()) return false;
require_code('ocf_members');
return ((array_key_exists('PHP_AUTH_USER',$_SERVER)) && (!is_null(ocf_authusername_is_bound_via_httpauth($_SERVER['PHP_AUTH_USER']))));
}
URLPATH enforce_sessioned_url(URLPATH url)
Make sure that the given URL contains a session if cookies are disabled.NB: This is used for login redirection. It had to add the session id into the redirect url.
Parameters…
| Name |
url |
| Description |
The URL to enforce results in session persistence for the user |
| Type |
URLPATH |
Returns…
| Description |
The fixed URL (potentially nothing was done, depending on cookies) |
| Type |
URLPATH |
function enforce_sessioned_url($url)
{
if ((!has_cookies()) && (is_null(get_bot_type())))
{
require_code('users_inactive_occasionals');
return _enforce_sessioned_url($url);
}
return $url;
}
?AUTO_LINK delete_expired_sessions_or_recover(?MEMBER member)
Find what sessions are expired and delete them, and recover an existing one for $member if there is one.
Parameters…
| Name |
member |
| Description |
User to get a current session for (NULL: do not try, which guarantees a return result of NULL also) |
| Default value |
|
| Type |
?MEMBER |
Returns…
| Description |
The session id we rebound to (NULL: did not rebind) |
| Type |
?AUTO_LINK |
function delete_expired_sessions_or_recover($member=NULL)
{
$new_session=NULL;
$ip=get_ip_address(3);
// Delete expired sessions
$GLOBALS['SITE_DB']->query('DELETE FROM '.get_table_prefix().'sessions WHERE last_activity<'.strval(time()-60*60*max(1,intval(get_option('session_expiry_time')))));
$new_session=NULL;
$dirty_session_cache=false;
global $SESSION_CACHE;
foreach ($SESSION_CACHE as $_session=>$row)
{
if (!array_key_exists('the_user',$row)) continue; // Workaround to HipHop PHP weird bug
// Delete expiry from cache
if ($row['last_activity']<time()-60*60*max(1,intval(get_option('session_expiry_time'))))
{
$dirty_session_cache=true;
unset($SESSION_CACHE[$_session]);
continue;
}
// Get back to prior session if there was one
if ($member!==NULL)
{
if (($row['the_user']==$member) && ((get_option('ip_strict_for_sessions')=='0') || ($row['ip']==$ip)) && ($row['last_activity']>time()-60*60*max(1,intval(get_option('session_expiry_time')))))
{
$new_session=$_session;
}
}
}
if ($dirty_session_cache)
{
if (get_value('session_prudence')!=='1')
{
persistant_cache_set('SESSION_CACHE',$SESSION_CACHE);
}
}
return $new_session;
}
string get_member_cookie()
Get the member cookie's name.
Parameters…
Returns…
| Description |
The member username/id (depending on forum driver) cookie's name |
| Type |
string |
function get_member_cookie()
{
global $SITE_INFO;
if (!array_key_exists('user_cookie',$SITE_INFO)) $SITE_INFO['user_cookie']='ocp_member_id';
return $SITE_INFO['user_cookie'];
}
string get_pass_cookie()
Get the member password cookie's name.
Parameters…
Returns…
| Description |
The member password cookie's name |
| Type |
string |
function get_pass_cookie()
{
global $SITE_INFO;
if (!array_key_exists('pass_cookie',$SITE_INFO)) $SITE_INFO['pass_cookie']='ocp_member_hash';
return $SITE_INFO['pass_cookie'];
}
?string ocp_admirecookie(string name, ?string default)
Get a cookie value.
Parameters…
| Name |
name |
| Description |
The name of the cookie |
| Type |
string |
| Name |
default |
| Description |
The default value (NULL: just use the value NULL) |
| Default value |
|
| Type |
?string |
Returns…
| Description |
The value stored in the cookie (NULL: the default default) |
| Type |
?string |
function ocp_admirecookie($name,$default=NULL)
{
if (!isset($_COOKIE[$name])) return $default;
$the_cookie=$_COOKIE[$name];
if (get_magic_quotes_gpc()) $the_cookie=stripslashes($the_cookie);
return $the_cookie;
}
boolean ocp_eatcookie(string name)
Deletes a cookie (if it exists), from within ocPortal's cookie environment.
Parameters…
| Name |
name |
| Description |
The name of the cookie |
| Type |
string |
Returns…
| Description |
The result of the PHP setcookie command |
| Type |
boolean |
function ocp_eatcookie($name)
{
$expire=time()-100000; // Note the negative number must be greater than 13*60*60 to account for maximum timezone difference
// Try and remove other potentials
@setcookie($name,'',$expire,'',preg_replace('#^www\.#','',ocp_srv('HTTP_HOST')));
@setcookie($name,'',$expire,'/',preg_replace('#^www\.#','',ocp_srv('HTTP_HOST')));
@setcookie($name,'',$expire,'','www.'.preg_replace('#^www\.#','',ocp_srv('HTTP_HOST')));
@setcookie($name,'',$expire,'/','www.'.preg_replace('#^www\.#','',ocp_srv('HTTP_HOST')));
@setcookie($name,'',$expire,'','');
@setcookie($name,'',$expire,'/','');
// Delete standard potential
return @setcookie($name,'',$expire,get_cookie_path(),get_cookie_domain());
}
string get_ocp_cpf(ID_TEXT cpf, ?MEMBER member)
Get the value of a special 'ocp_' custom profile field. For OCF it can also do it for a pure field title, e.g. "Example Field".
Parameters…
| Name |
cpf |
| Description |
The CPF name stem |
| Type |
ID_TEXT |
| Name |
member |
| Description |
Member to lookup for (NULL: current member) |
| Default value |
|
| Type |
?MEMBER |
Returns…
| Description |
The value (blank: has a blank value, or does not exist) |
| Type |
string |
function get_ocp_cpf($cpf,$member=NULL)
{
if (is_null($member)) $member=get_member();
if (($cpf=='fullname') && (get_option('signup_fullname')=='1'))
{
return preg_replace('# \(\d+\)$#','',$GLOBALS['FORUM_DRIVER']->get_username($member));
}
$values=$GLOBALS['FORUM_DRIVER']->get_custom_fields($member);
if (is_null($values)) return '';
if (array_key_exists($cpf,$values)) return $values[$cpf];
if (get_forum_type()=='ocf')
{
$values=ocf_get_all_custom_fields_match_member($member);
if (array_key_exists($cpf,$values)) return $values[$cpf]['RAW'];
}
return '';
}
?array get_online_members(boolean longer_time, ?MEMBER filter, integer count)
Get database rows of all the online members.
Parameters…
| Name |
longer_time |
| Description |
Whether to use a longer online-time -- the session expiry-time |
| Type |
boolean |
| Name |
filter |
| Description |
We really only need to make sure we get the status for this user, although at this functions discretion more may be returned and the row won't be there if the user is not online (NULL: no filter). May not be the guest ID |
| Type |
?MEMBER |
| Name |
count |
| Description |
The total online members, returned by reference |
| Type |
integer |
Returns…
| Description |
Database rows (NULL: too many) |
| Type |
?array |
function get_online_members($longer_time,$filter,&$count)
{
$users_online_time_seconds=$longer_time?(60*60*intval(get_option('session_expiry_time'))):(60*intval(get_option('users_online_time')));
if (get_value('session_prudence')==='1')
{
// If we have multiple servers this many not be accurate as we probably turned replication off for the sessions table. The site design should be updated to not show this kind of info
$count=$GLOBALS['SITE_DB']->query_value_null_ok_full('SELECT COUNT(*) FROM '.get_table_prefix().'sessions WHERE last_activity>'.strval($users_online_time_seconds));
if (!is_null($filter))
return $GLOBALS['SITE_DB']->query('SELECT * FROM '.get_table_prefix().'sessions WHERE last_activity>'.strval($users_online_time_seconds).' AND the_user='.strval($filter),1);
return NULL;
}
$members=array();
$cutoff=time()-$users_online_time_seconds;
$guest_id=$GLOBALS['FORUM_DRIVER']->get_guest_id();
global $SESSION_CACHE;
$members_online=0;
foreach ($SESSION_CACHE as $row)
{
if (!isset($row['the_user'])) continue; // Workaround to HipHop PHP weird bug
if (($row['last_activity']>$cutoff) && ($row['session_invisible']==0))
{
if ($row['the_user']==$guest_id)
{
$count++;
$members[]=$row;
$members_online++;
if ($members_online==200) // This is silly, don't display any
{
if (!is_null($filter)) // Unless we are filtering
return $GLOBALS['SITE_DB']->query('SELECT * FROM '.get_table_prefix().'sessions WHERE last_activity>'.strval($users_online_time_seconds).' AND the_user='.strval($filter),1);
return NULL;
}
} elseif (!member_blocked(get_member(),$row['the_user']))
{
$count++;
$members[-$row['the_user']]=$row; // - (minus) is just a hackerish thing to allow it to do a unique, without messing with the above
}
}
}
return $members;
}
boolean member_is_online(MEMBER member_id)
Find if a member is online.
Parameters…
| Name |
member_id |
| Description |
The member to check |
| Type |
MEMBER |
Returns…
| Description |
Whether they are online |
| Type |
boolean |
function member_is_online($member_id)
{
$count=0;
$online=get_online_members(false,$member_id,$count);
foreach ($online as $m)
{
if ($m['the_user']==$member_id) return true;
}
return false;
}
boolean member_blocked(MEMBER member_id, ?MEMBER member_blocker)
Find if a member is blocked by a member.
Parameters…
| Name |
member_id |
| Description |
The member being checked |
| Type |
MEMBER |
| Name |
member_blocker |
| Description |
The member who may be blocking (NULL: current member) |
| Default value |
|
| Type |
?MEMBER |
Returns…
| Description |
Whether the member is blocked |
| Type |
boolean |
function member_blocked($member_id,$member_blocker=NULL)
{
if (!addon_installed('chat')) return false;
if (is_null($member_blocker)) $member_blocker=get_member();
if ($member_blocker==$member_id) return false;
if (is_guest($member_id)) return false;
if (is_guest($member_blocker)) return false;
if ($member_id==get_member())
{
global $MEMBERS_BLOCKING_US;
if (is_null($MEMBERS_BLOCKING_US))
{
$rows=$GLOBALS['SITE_DB']->query_select('chat_blocking',array('member_blocker'),array('member_blocked'=>get_member()),'',NULL,NULL,true);
if (is_null($rows))
{
$MEMBERS_BLOCKING_US=array();
return false;
}
$MEMBERS_BLOCKING_US=collapse_1d_complexity('member_blocker',$rows);
}
return (in_array($member_blocker,$MEMBERS_BLOCKING_US));
}
global $MEMBERS_BLOCKED;
if (is_null($MEMBERS_BLOCKED))
{
$rows=$GLOBALS['SITE_DB']->query_select('chat_blocking',array('member_blocked'),array('member_blocker'=>get_member()),'',NULL,NULL,true);
if (is_null($rows))
{
$MEMBERS_BLOCKED=array();
return false;
}
$MEMBERS_BLOCKED=collapse_1d_complexity('member_blocked',$rows);
}
return (in_array($member_id,$MEMBERS_BLOCKED));
}
Fully internal driver functions
sources/forum_stub.php
Global_functions_forum_stub.php
void init__forum_stub()
Standard code module initialisation function.
Parameters…
(No return value)
function init__forum_stub()
{
global $IS_SUPER_ADMIN_CACHE,$IS_STAFF_CACHE;
$IS_SUPER_ADMIN_CACHE=array();
$IS_STAFF_CACHE=array();
}
forum_driver_base
Function summary
|
GROUP
|
get_guest_group ()
|
|
mixed
|
member_profile_url (MEMBER id, boolean definitely_profile, boolean tempcode_okay)
|
|
tempcode
|
member_profile_hyperlink (MEMBER id, boolean definitely_profile, string _username)
|
|
mixed
|
join_url ()
|
|
mixed
|
online_members_url ()
|
|
mixed
|
member_pm_url (MEMBER id)
|
|
mixed
|
forum_url (integer id, boolean tempcode_okay)
|
|
?SHORT_TEXT
|
get_username (MEMBER id)
|
|
SHORT_TEXT
|
get_member_email_address (MEMBER id)
|
|
boolean
|
is_staff (MEMBER id, boolean skip_staff_filter)
|
|
boolean
|
disable_staff_filter ()
|
|
boolean
|
is_super_admin (MEMBER id)
|
|
array
|
get_super_admin_groups ()
|
|
array
|
get_moderator_groups ()
|
|
array
|
get_usergroup_list (boolean hide_hidden, boolean only_permissive, boolean force_show_all, ?array force_find, ?MEMBER for_member, boolean skip_hidden)
|
|
array
|
get_members_groups (MEMBER id, boolean skip_secret, boolean handle_probation)
|
|
ID_TEXT
|
get_theme (?ID_TEXT zone_for)
|
|
integer
|
get_num_new_forum_posts ()
|
|
boolean
|
topic_is_threaded (integer topic_id)
|
|
array
|
get_post_remaining_details (AUTO_LINK topic_id, array post_ids)
|
GROUP get_guest_group()
Find the usergroup id of the forum guest member.
Parameters…
Returns…
| Description |
The usergroup id of the forum guest member |
| Type |
GROUP |
function get_guest_group()
{
return db_get_first_id();
}
mixed member_profile_url(MEMBER id, boolean definitely_profile, boolean tempcode_okay)
Get a URL to a forum member's member profile.
Parameters…
| Name |
id |
| Description |
The forum member |
| Type |
MEMBER |
| Name |
definitely_profile |
| Description |
Whether to be insistent that we go to the profile, rather than possibly starting an IM which can link to the profile |
| Default value |
boolean-false |
| Type |
boolean |
| Name |
tempcode_okay |
| Description |
Whether it is okay to return the result using Tempcode (more efficient, and allows keep_* parameters to propagate which you almost certainly want!) |
| Default value |
boolean-false |
| Type |
boolean |
Returns…
| Description |
The URL |
| Type |
mixed |
function member_profile_url($id,$definitely_profile=false,$tempcode_okay=false)
{
$url=mixed();
if ((!$definitely_profile) && ($id!=$this->get_guest_id()) && (addon_installed('chat')))
{
$username_click_im=get_option('username_click_im',true);
if ($username_click_im=='1')
{
$url=build_url(array('page'=>'chat','type'=>'misc','enter_im'=>$id),get_module_zone('chat'));
return $url;
}
}
$url=$this->_member_profile_url($id,$tempcode_okay);
if (($tempcode_okay) && (!is_object($url)))
$url=make_string_tempcode($url);
if ((get_forum_type()!='none') && (get_forum_type()!='ocf') && (get_option('forum_in_portal',true)=='1'))
{
$url=build_url(array('page'=>'forums','url'=>$url),get_module_zone('forums'));
}
return $url;
}
tempcode member_profile_hyperlink(MEMBER id, boolean definitely_profile, string _username)
Get a hyperlink (i.e. HTML link, not just a URL) to a forum member's member profile.
Parameters…
| Name |
id |
| Description |
The forum member |
| Type |
MEMBER |
| Name |
definitely_profile |
| Description |
Whether to be insistent that we go to the profile, rather than possibly starting an IM which can link to the profile |
| Default value |
boolean-false |
| Type |
boolean |
| Name |
_username |
| Description |
The username (blank: look it up) |
| Default value |
|
| Type |
string |
Returns…
| Description |
The hyperlink |
| Type |
tempcode |
function member_profile_hyperlink($id,$definitely_profile=false,$_username='')
{
if (is_guest($id))
return ($_username=='')?do_lang_tempcode('GUEST'):make_string_tempcode(escape_html($_username));
if ($_username=='') $_username=$this->get_username($id);
if (is_null($_username))
return do_lang_tempcode('UNKNOWN');
$url=$this->member_profile_url($id,$definitely_profile,true);
return hyperlink($url,$_username,false,true);
}
mixed join_url()
Get a URL to a forum join page.
Parameters…
Returns…
| Description |
The URL |
| Type |
mixed |
function join_url()
{
$url=$this->_join_url();
if ((get_forum_type()!='none') && (get_forum_type()!='ocf') && (get_option('forum_in_portal',true)=='1')) $url=build_url(array('page'=>'forums','url'=>$url),get_module_zone('forums'));
return $url;
}
mixed online_members_url()
Get a URL to a forum 'user online' list.
Parameters…
Returns…
| Description |
The URL |
| Type |
mixed |
function online_members_url()
{
$url=$this->_online_members_url();
if ((get_forum_type()!='none') && (get_forum_type()!='ocf') && (get_option('forum_in_portal',true)=='1')) $url=build_url(array('page'=>'forums','url'=>$url),get_module_zone('forums'));
return $url;
}
mixed member_pm_url(MEMBER id)
Get a URL to send a forum member a PM.
Parameters…
| Name |
id |
| Description |
The forum member |
| Type |
MEMBER |
Returns…
| Description |
The URL |
| Type |
mixed |
function member_pm_url($id)
{
$url=$this->_member_pm_url($id);
if ((get_forum_type()!='none') && (get_forum_type()!='ocf') && (get_option('forum_in_portal',true)=='1')) $url=build_url(array('page'=>'forums','url'=>$url),get_module_zone('forums'));
return $url;
}
mixed forum_url(integer id, boolean tempcode_okay)
Get a URL to a forum.
Parameters…
| Name |
id |
| Description |
The ID of the forum |
| Type |
integer |
| Name |
tempcode_okay |
| Description |
Whether it is okay to return the result using Tempcode (more efficient) |
| Default value |
boolean-false |
| Type |
boolean |
Returns…
| Description |
The URL |
| Type |
mixed |
function forum_url($id,$tempcode_okay=false)
{
$url=$this->_forum_url($id,$tempcode_okay);
if ((get_forum_type()!='none') && (get_forum_type()!='ocf') && (get_option('forum_in_portal',true)=='1'))
$url=build_url(array('page'=>'forums','url'=>$url),get_module_zone('forums'));
return $url;
}
?SHORT_TEXT get_username(MEMBER id)
Get a member's username.
Parameters…
| Name |
id |
| Description |
The member |
| Type |
MEMBER |
Returns…
| Description |
The username (NULL: deleted member) |
| Type |
?SHORT_TEXT |
function get_username($id)
{
if ($id==$this->get_guest_id())
{
require_code('lang');
if (!function_exists('do_lang')) return 'Guest';
$ret=do_lang('GUEST',NULL,NULL,NULL,NULL,false);
if ($ret===NULL) $ret='Guest';
return $ret;
}
global $USER_NAME_CACHE;
if (isset($USER_NAME_CACHE[$id])) return $USER_NAME_CACHE[$id];
$ret=$this->_get_username($id);
if ($ret=='') $ret=NULL; // Odd, but sometimes
$USER_NAME_CACHE[$id]=$ret;
return $ret;
}
SHORT_TEXT get_member_email_address(MEMBER id)
Get a member's e-mail address.
Parameters…
| Name |
id |
| Description |
The member |
| Type |
MEMBER |
Returns…
| Description |
The e-mail address (blank: not known) |
| Type |
SHORT_TEXT |
function get_member_email_address($id)
{
global $MEMBER_EMAIL_CACHE;
if (array_key_exists($id,$MEMBER_EMAIL_CACHE)) return $MEMBER_EMAIL_CACHE[$id];
$ret=$this->_get_member_email_address($id);
$MEMBER_EMAIL_CACHE[$id]=$ret;
return $ret;
}
boolean is_staff(MEMBER id, boolean skip_staff_filter)
Find whether a member is staff.
Parameters…
| Name |
id |
| Description |
The member |
| Type |
MEMBER |
| Name |
skip_staff_filter |
| Description |
Whether to avoid checking the staff filter (i.e. ignore M.S.N.'s) |
| Default value |
boolean-false |
| Type |
boolean |
Returns…
| Description |
The answer |
| Type |
boolean |
function is_staff($id,$skip_staff_filter=false)
{
if (is_guest($id)) return false;
if (!$skip_staff_filter)
{
global $IS_STAFF_CACHE;
if (array_key_exists($id,$IS_STAFF_CACHE)) return $IS_STAFF_CACHE[$id];
if ((isset($this->connection)) && ($this->connection->connection_write!=$GLOBALS['SITE_DB']->connection_write) && (get_option('is_on_staff_filter',true)==='1') && (get_forum_type()!='none') && (!$GLOBALS['FORUM_DRIVER']->disable_staff_filter()))
{
if (strpos(strtolower(get_ocp_cpf('sites',$id)),strtolower(substr(get_site_name(),0,200)))===false)
{
$IS_STAFF_CACHE[$id]=false;
return false;
}
}
}
$ret=$this->_is_staff($id);
if (!$skip_staff_filter)
{
$IS_STAFF_CACHE[$id]=$ret;
}
return $ret;
}
boolean disable_staff_filter()
If we can't get a list of admins via a usergroup query, we have to disable the staff filter - else the staff filtering can cause disaster at the point of being turned on (because it can't automatically sync).
Parameters…
Returns…
| Description |
Whether the staff filter is disabled |
| Type |
boolean |
function disable_staff_filter()
{
if (method_exists($this,'_disable_staff_filter')) return $this->_disable_staff_filter();
return false;
}
boolean is_super_admin(MEMBER id)
Find whether a member is a super administrator.
Parameters…
| Name |
id |
| Description |
The member |
| Type |
MEMBER |
Returns…
| Description |
The answer |
| Type |
boolean |
function is_super_admin($id)
{
if (is_guest($id)) return false;
global $IS_SUPER_ADMIN_CACHE;
if (isset($IS_SUPER_ADMIN_CACHE[$id])) return $IS_SUPER_ADMIN_CACHE[$id];
$ret=$this->_is_super_admin($id);
$IS_SUPER_ADMIN_CACHE[$id]=$ret;
return $ret;
}
array get_super_admin_groups()
Get a list of the super admin usergroups.
Parameters…
Returns…
| Description |
The list of usergroups |
| Type |
array |
function get_super_admin_groups()
{
global $ADMIN_GROUP_CACHE;
if ($ADMIN_GROUP_CACHE!==NULL) return $ADMIN_GROUP_CACHE;
$ret=$this->_get_super_admin_groups();
$ADMIN_GROUP_CACHE=$ret;
return $ret;
}
array get_moderator_groups()
Get a list of the moderator usergroups.
Parameters…
Returns…
| Description |
The list of usergroups |
| Type |
array |
function get_moderator_groups()
{
global $MODERATOR_GROUP_CACHE,$IN_MINIKERNEL_VERSION;
if ((!is_null($MODERATOR_GROUP_CACHE)) && (($IN_MINIKERNEL_VERSION==0) || ($MODERATOR_GROUP_CACHE!=array()))) return $MODERATOR_GROUP_CACHE;
$ret=$this->_get_moderator_groups();
$MODERATOR_GROUP_CACHE=$ret;
return $ret;
}
array get_usergroup_list(boolean hide_hidden, boolean only_permissive, boolean force_show_all, ?array force_find, ?MEMBER for_member, boolean skip_hidden)
Get a map of forum usergroups (id=>name).
Parameters…
| Name |
hide_hidden |
| Description |
Whether to obscure the name of hidden usergroups |
| Default value |
boolean-false |
| Type |
boolean |
| Name |
only_permissive |
| Description |
Whether to only grab permissive usergroups |
| Default value |
boolean-false |
| Type |
boolean |
| Name |
force_show_all |
| Description |
Do not limit things even if there are huge numbers of usergroups |
| Default value |
boolean-false |
| Type |
boolean |
| Name |
force_find |
| Description |
Usergroups that must be included in the results (NULL: no extras must be) |
| Default value |
|
| Type |
?array |
| Name |
for_member |
| Description |
Always return usergroups of this member (NULL: current member) |
| Default value |
|
| Type |
?MEMBER |
| Name |
skip_hidden |
| Description |
Whether to completely skip hidden usergroups |
| Default value |
boolean-false |
| Type |
boolean |
Returns…
| Description |
The map |
| Type |
array |
function get_usergroup_list($hide_hidden=false,$only_permissive=false,$force_show_all=false,$force_find=NULL,$for_member=NULL,$skip_hidden=false)
{
global $USERGROUP_LIST_CACHE;
if ((!is_null($USERGROUP_LIST_CACHE)) && (isset($USERGROUP_LIST_CACHE[$hide_hidden][$only_permissive][$force_show_all][serialize($force_find)][$for_member][$skip_hidden])))
{
return $USERGROUP_LIST_CACHE[$hide_hidden][$only_permissive][$force_show_all][serialize($force_find)][$for_member][$skip_hidden];
}
$ret=$this->_get_usergroup_list($hide_hidden,$only_permissive,$force_show_all,$force_find,$for_member,$skip_hidden);
if (count($ret)!=0) // Conditional is for when installing... can't cache at point of there being no usergroups
{
if (is_null($USERGROUP_LIST_CACHE)) $USERGROUP_LIST_CACHE=array();
$USERGROUP_LIST_CACHE[$hide_hidden][$only_permissive][$force_show_all][serialize($force_find)][$for_member][$skip_hidden]=$ret;
}
return $ret;
}
array get_members_groups(MEMBER id, boolean skip_secret, boolean handle_probation)
Get a list of usergroups a member is in.
Parameters…
| Name |
id |
| Description |
The member |
| Type |
MEMBER |
| Name |
skip_secret |
| Description |
Whether to skip looking at secret usergroups. |
| Default value |
boolean-false |
| Type |
boolean |
| Name |
handle_probation |
| Description |
Whether to take probation into account |
| Default value |
boolean-true |
| Type |
boolean |
Returns…
| Description |
The list of usergroups |
| Type |
array |
function get_members_groups($id,$skip_secret=false,$handle_probation=true)
{
if ((is_guest($id)) && (get_forum_type()=='ocf'))
{
static $ret=NULL;
if ($ret===NULL) $ret=array(db_get_first_id());
return $ret;
}
global $USERS_GROUPS_CACHE;
if (isset($USERS_GROUPS_CACHE[$id][$skip_secret][$handle_probation])) return $USERS_GROUPS_CACHE[$id][$skip_secret][$handle_probation];
$ret=$this->_get_members_groups($id,$skip_secret,$handle_probation);
$USERS_GROUPS_CACHE[$id][$skip_secret][$handle_probation]=$ret;
return $ret;
}
ID_TEXT get_theme(?ID_TEXT zone_for)
Get the current member's theme identifier.
Parameters…
| Name |
zone_for |
| Description |
The zone we are getting the theme for (NULL: current zone) |
| Default value |
|
| Type |
?ID_TEXT |
Returns…
| Description |
The theme identifier |
| Type |
ID_TEXT |
function get_theme($zone_for=NULL)
{
global $SITE_INFO;
if ($zone_for!==NULL)
{
$zone_theme=$GLOBALS['SITE_DB']->query_value('zones','zone_theme',array('zone_name'=>$zone_for));
if ($zone_theme!='-1')
{
if ((!isset($SITE_INFO['no_disk_sanity_checks'])) || ($SITE_INFO['no_disk_sanity_checks']=='0'))
{
if (!is_dir(get_custom_file_base().'/themes/'.$zone_theme)) return $this->get_theme();
}
return $zone_theme;
}
return $this->get_theme();
}
global $CACHED_THEME;
if ($CACHED_THEME!==NULL) return $CACHED_THEME;
global $IN_MINIKERNEL_VERSION;
if (($IN_MINIKERNEL_VERSION==1) || (in_safe_mode())) return 'default';
// Try hardcoded in URL
$CACHED_THEME=filter_naughty(get_param('keep_theme',get_param('utheme','-1')));
if ($CACHED_THEME!='-1')
{
if ((!is_dir(get_file_base().'/themes/'.$CACHED_THEME)) && (!is_dir(get_custom_file_base().'/themes/'.$CACHED_THEME)))
{
$theme=$CACHED_THEME;
$CACHED_THEME='default';
require_code('site');
attach_message(do_lang_tempcode('NO_SUCH_THEME',escape_html($theme)),'warn');
$CACHED_THEME=NULL;
} else
{
if (($CACHED_THEME=='default') || (has_category_access(get_member(),'theme',$CACHED_THEME)))
{
return $CACHED_THEME;
} else
{
$theme=$CACHED_THEME;
$CACHED_THEME='default';
attach_message(do_lang_tempcode('NO_THEME_PERMISSION',escape_html($theme)),'warn');
$CACHED_THEME=NULL;
}
}
} else $CACHED_THEME=NULL;
// Try hardcoded in ocPortal
global $ZONE;
$zone_theme=($ZONE===NULL)?$GLOBALS['SITE_DB']->query_value_null_ok('zones','zone_theme',array('zone_name'=>get_zone_name())):$ZONE['zone_theme'];
$default_theme=((get_page_name()=='login') && (get_option('root_zone_login_theme')=='1'))?$GLOBALS['SITE_DB']->query_value('zones','zone_theme',array('zone_name'=>'')):$zone_theme;
if (($default_theme!==NULL) && ($default_theme!='-1'))
{
if ((!isset($SITE_INFO['no_disk_sanity_checks'])) || ($SITE_INFO['no_disk_sanity_checks']=='0'))
{
if (!is_dir(get_custom_file_base().'/themes/'.$default_theme)) $default_theme='-1';
}
}
if ($default_theme!='-1')
{
$CACHED_THEME=$default_theme;
if ($CACHED_THEME=='') $CACHED_THEME='default';
return $CACHED_THEME;
}
if ($default_theme=='-1') $default_theme='default';
// Get from forums
$CACHED_THEME=filter_naughty($this->_get_theme());
if (($CACHED_THEME=='') || (($CACHED_THEME!='default') && (!is_dir(get_custom_file_base().'/themes/'.$CACHED_THEME)))) $CACHED_THEME='default';
if ($CACHED_THEME=='-1') $CACHED_THEME='default';
require_code('permissions');
if (($CACHED_THEME!='default') && (!has_category_access(get_member(),'theme',$CACHED_THEME)))
{
$CACHED_THEME='default';
}
if ($CACHED_THEME=='') $CACHED_THEME='default';
return $CACHED_THEME;
}
integer get_num_new_forum_posts()
Get the number of new forum posts on the system in the last 24 hours.
Parameters…
Returns…
| Description |
Number of forum posts |
| Type |
integer |
function get_num_new_forum_posts()
{
$value=NULL;//get_value_newer_than('num_new_forum_posts',time()-60*60*6);
if (is_null($value))
{
$value=strval($this->_get_num_new_forum_posts());
//set_value('num_new_forum_posts',$value);
}
return intval($value);
}
boolean topic_is_threaded(integer topic_id)
Find whether a forum is threaded.
Parameters…
| Name |
topic_id |
| Description |
The topic ID |
| Type |
integer |
Returns…
| Description |
Whether it is |
| Type |
boolean |
function topic_is_threaded($topic_id)
{
return false;
}
array get_post_remaining_details(AUTO_LINK topic_id, array post_ids)
Load extra details for a list of posts. Does not need to return anything if forum driver doesn't support partial post loading (which is only useful for threaded topic partial-display).
Parameters…
| Name |
topic_id |
| Description |
Topic the posts come from |
| Type |
AUTO_LINK |
| Name |
post_ids |
| Description |
List of post IDs |
| Type |
array |
Returns…
| Description |
Extra details |
| Type |
array |
function get_post_remaining_details($topic_id,$post_ids)
{
return array();
}
Drivers may define extra methods, that are called directly, if they exist.
Code (php)
$output = forum_create_cookie($id,$name,$password);
This function will create an auth cookie based on the input parameters. It is defined for forums that don't store plain-hashed cookies.
0 reviews: Unrated (average)
There have been no comments yet