File/includes/functions.php

Description
  • version: $Id: functions.php 8787 2008-08-24 11:35:17Z acydburn $
  • copyright: (c) 2005 phpBB Group
  • license: GNU Public License
Functions
add_form_key (line 2244)

Add a secret token to the form (requires the S_FORM_TOKEN template variable)

void add_form_key (string $form_name)
  • string $form_name: The name of the form; has to match the name used in check_form_key, otherwise no restrictions apply
add_log (line 2831)

Add log event

void add_log ()
append_sid (line 1809)

Append session id to url.

This function supports hooks.

void append_sid (string $url, [mixed $params = false], [bool $is_amp = true], [string $session_id = false])
  • string $url: The url the session id needs to be appended to (can have params)
  • mixed $params: String or array of additional url parameters
  • bool $is_amp: Is url using & (true) or & (false)
  • string $session_id:

    Possibility to use a custom session id instead of the global one

    Examples:

    1.  append_sid("{$phpbb_root_path}viewtopic.$phpEx?t=1&f=2");
    2.  append_sid("{$phpbb_root_path}viewtopic.$phpEx"'t=1&f=2');
    3.  append_sid("{$phpbb_root_path}viewtopic.$phpEx"'t=1&f=2'false);
    4.  append_sid("{$phpbb_root_path}viewtopic.$phpEx"array('t' => 1'f' => 2));

array_combine (line 611)

A wrapper for the PHP5 function array_combine()

  • return: an array by using the values from the keys array as keys and the values from the values array as the corresponding values. Returns false if the number of elements for each array isn't equal or if the arrays are empty.
Returns array_combine (array $keys, array $values)
  • array $keys: contains keys for the resulting array
  • array $values: contains values for the resulting array
build_hidden_fields (line 2765)

Build simple hidden fields from array

  • return: the hidden fields
string build_hidden_fields (array $field_ary, [bool $specialchar = false], [bool $stripslashes = false])
  • array $field_ary: an array of values to build the hidden field from
  • bool $specialchar: if true, keys and values get specialchared
  • bool $stripslashes: if true, keys and values get stripslashed
build_url (line 2133)

Returns url from the session/current page with an re-appended SID with optionally stripping vars from the url

void build_url ([ $strip_vars = false])
  • $strip_vars
check_form_key (line 2267)

Check the form key. Required for all altering actions not secured by confirm_box

void check_form_key (string $form_name, [int $timespan = false], [string $return_page = ''], [bool $trigger = false])
  • string $form_name: The name of the form; has to match the name used in add_form_key, otherwise no restrictions apply
  • int $timespan: The maximum acceptable age for a submitted form in seconds. Defaults to the config setting.
  • string $return_page: The address for the return link
  • bool $trigger: If true, the function will triger an error when encountering an invalid form
check_link_hash (line 2235)

checks a link hash - for GET requests

  • return: true if all is fine
boolean check_link_hash (string $token, string $link_name)
  • string $token: the submitted token
  • string $link_name: The name of the link
confirm_box (line 2315)

Build Confirm box

void confirm_box (boolean $check, [string $title = ''], [string $hidden = ''], [string $html_body = 'confirm_body.html'], [string $u_action = ''])
  • boolean $check: True for checking if confirmed (without any additional parameters) and false for displaying the confirm box
  • string $title: Title/Message used for confirm box. message text is _CONFIRM appended to title. If title cannot be found in user->lang a default one is displayed If title_CONFIRM cannot be found in user->lang the text given is used.
  • string $hidden: Hidden variables
  • string $html_body: Template used for confirm box
  • string $u_action: Custom form action
exit_handler (line 3844)

Handler for exit calls in phpBB.

This function supports hooks.

Note: This function is called after the template has been outputted.

void exit_handler ()
garbage_collection (line 3821)

Closing the cache object and the database

Cool function name, eh? We might want to add operations to it later

void garbage_collection ()
generate_board_url (line 1894)

Generate board url (example: http://www.example.com/phpBB)

void generate_board_url ([bool $without_script_path = false])
  • bool $without_script_path: if set to true the script path gets not appended (example: http://www.example.com)
generate_link_hash (line 2218)

Add a secret hash for use in links/GET requests

  • return: the hash
string generate_link_hash (string $link_name)
  • string $link_name: The name of the link; has to match the name used in check_link_hash, otherwise no restrictions apply
generate_pagination (line 1690)

Pagination routine, generates page number sequence

tpl_prefix is for using different pagination blocks at one page

void generate_pagination ( $base_url,  $num_items,  $per_page,  $start_item, [ $add_prevnext_text = false], [ $tpl_prefix = ''])
  • $base_url
  • $num_items
  • $per_page
  • $start_item
  • $add_prevnext_text
  • $tpl_prefix
gen_rand_string (line 170)

Generates an alphanumeric random string of given length

void gen_rand_string ([ $num_chars = 8])
  • $num_chars
get_backtrace (line 2889)

Return a nicely formatted backtrace (parts from the php manual by diz at ysagoon dot com)

void get_backtrace ()
get_complete_topic_tracking (line 1330)

Get topic tracking info from db (for cookie based tracking only this function is used)

void get_complete_topic_tracking ( $forum_id,  $topic_ids, [ $global_announce_list = false])
  • $forum_id
  • $topic_ids
  • $global_announce_list
get_formatted_filesize (line 204)

Return formatted string for filesizes

void get_formatted_filesize ( $bytes, [ $add_size_lang = true])
  • $bytes
  • $add_size_lang
get_preg_expression (line 2952)

This function returns a regular expression pattern for commonly used expressions

Use with / as delimiter for email mode and # for url modes mode can be: email|bbcode_htm|url|url_inline|www_url|www_url_inline|relative_url|relative_url_inline|ipv4|ipv6

void get_preg_expression ( $mode)
  • $mode
get_topic_tracking (line 1250)

Get topic tracking info by using already fetched info

void get_topic_tracking ( $forum_id,  $topic_ids,  &$rowset,  $forum_mark_time, [ $global_announce_list = false])
  • $forum_id
  • $topic_ids
  • &$rowset
  • $forum_mark_time
  • $global_announce_list
is_absolute (line 693)

Checks if a path ($path) is absolute or relative

boolean is_absolute (string $path)
  • string $path: Path to check absoluteness of
language_select (line 909)

Pick a language, any language ...

void language_select ([ $default = ''])
  • $default
login_box (line 2418)

Generate login box or verify password

void login_box ([ $redirect = ''], [ $l_explain = ''], [ $l_success = ''], [ $admin = false], [ $s_display = true])
  • $redirect
  • $l_explain
  • $l_success
  • $admin
  • $s_display
login_forum_box (line 2652)

Generate forum login box

void login_forum_box ( $forum_data)
  • $forum_data
markread (line 991)

Marks a topic/forum as read Marks a topic as posted to

void markread ( $mode, [ $forum_id = false], [ $topic_id = false], [ $post_time = 0], [int $user_id = 0])
  • int $user_id: can only be used with $mode == 'post'
  • $mode
  • $forum_id
  • $topic_id
  • $post_time
meta_refresh (line 2194)

Meta refresh assignment

void meta_refresh ( $time,  $url)
  • $time
  • $url
msg_handler (line 3096)

Error and message handler, call with trigger_error if reqd

void msg_handler ( $errno,  $msg_text,  $errfile,  $errline)
  • $errno
  • $msg_text
  • $errfile
  • $errline
obtain_guest_count (line 3296)

Queries the session table to get information about online guests

  • return: The number of active distinct guest sessions
int obtain_guest_count ([int $forum_id = 0])
  • int $forum_id: Limits the search to the forum with this id
obtain_users_online (line 3343)

Queries the session table to get information about online users

  • return: An array containing the ids of online, hidden and visible users, as well as statistical info
array obtain_users_online ([int $forum_id = 0])
  • int $forum_id: Limits the search to the forum with this id
obtain_users_online_string (line 3406)

Uses the result of obtain_users_online to generate a localized, readable representation.

  • return: An array containing the string for output to the template
array obtain_users_online_string (mixed $online_users, [int $forum_id = 0])
  • mixed $online_users: result of obtain_users_online - array with user_id lists for total, hidden and visible users, and statistics
  • int $forum_id: Indicate that the data is limited to one forum and not global.
on_page (line 1773)

Return current page (pagination)

void on_page ( $num_items,  $per_page,  $start)
  • $num_items
  • $per_page
  • $start
page_footer (line 3729)

Generate page footer

void page_footer ([ $run_cron = true])
  • $run_cron
page_header (line 3514)

Generate page header

void page_header ([ $page_title = ''], [ $display_online_list = true])
  • $page_title
  • $display_online_list
parse_cfg_file (line 2783)

Parse cfg file

void parse_cfg_file ( $filename, [ $lines = false])
  • $filename
  • $lines
phpbb_checkdnsrr (line 3046)

Wrapper for php's checkdnsrr function.

The windows failover is from the php manual Please make sure to check the return value for === true and === false, since NULL could be returned too.

  • return: if entry found, false if not, NULL if this function is not supported by this environment
true phpbb_checkdnsrr ( $host, [ $type = ''])
  • $host
  • $type
phpbb_check_hash (line 329)

Check for correct password

  • return: Returns true if the password is correct, false if not.
bool phpbb_check_hash (string $password, string $hash)
  • string $password: The password in plain text
  • string $hash: The stored password hash
phpbb_chmod (line 484)

Global function for chmodding directories and files for internal use This function determines owner and group whom the file belongs to and user and group of PHP and then set safest possible file permissions.

The function determines owner and group from common.php file and sets the same to the provided file. The function uses bit fields to build the permissions. The function sets the appropiate execute bit on directories.

Supported constants representing bit fields are:

CHMOD_ALL - all permissions (7) CHMOD_READ - read permission (4) CHMOD_WRITE - write permission (2) CHMOD_EXECUTE - execute permission (1)

NOTE: The function uses POSIX extension and fileowner()/filegroup() functions. If any of them is disabled, this function tries to build proper permissions, by calling is_readable() and is_writable() functions.

  • return: on success, otherwise false
  • author: faw, phpBB Group
true phpbb_chmod ($filename $filename, [$perms $perms = CHMOD_READ])
  • $filename $filename: The file/directory to be chmodded
  • $perms $perms: Permissions to set
phpbb_hash (line 285)
  • version:

    Version 0.1 / slightly modified for phpBB 3.0.x (using $H$ as hash type identifier)

    Portable PHP password hashing framework.

    Written by Solar Designer <solar at openwall.com> in 2004-2006 and placed in the public domain.

    There's absolutely no warranty.

    The homepage URL for this framework is:

    http://www.openwall.com/phpass/

    Please be sure to update the Version line if you edit this file in any way. It is suggested that you leave the main version number intact, but indicate your project name (after the slash) and add your own revision information.

    Please do not change the "private" password hashing method implemented in here, thereby making your hashes incompatible. However, if you must, please change the hash type identifier (the "$P$") to something different.

    Obviously, since this code is in the public domain, the above are not requirements (there can be none), but merely suggestions.

    Hash the password

void phpbb_hash ( $password)
  • $password
phpbb_own_realpath (line 704)
mixed phpbb_own_realpath (string $path)
  • string $path: The path which we should attempt to resolve.
phpbb_realpath (line 871)

A wrapper for realpath

void phpbb_realpath ( $path)
  • $path
phpbb_user_session_handler (line 3866)

Handler for init calls in phpBB. This function is called in user::setup(); This function supports hooks.

void phpbb_user_session_handler ()
reapply_sid (line 2100)

Re-Apply session id after page reloads

void reapply_sid ( $url)
  • $url
redirect (line 1952)

Redirects the user to another page then exits the script nicely This function is intended for urls within the board. It's not meant to redirect to cross-domains.

void redirect (string $url, [bool $return = false], [bool $disable_cd_check = false])
  • string $url: The url to redirect to
  • bool $return: If true, do not redirect but return the sanitized URL. Default is no return.
  • bool $disable_cd_check: If true, redirect() will redirect to an external domain. If false, the redirect point to the boards url if it does not match the current domain. Default is false.
request_var (line 63)

request_var

Used to get passed variable

void request_var ( $var_name,  $default, [ $multibyte = false], [ $cookie = false])
  • $var_name
  • $default
  • $multibyte
  • $cookie
set_config (line 141)

Set config value. Creates missing config entry.

void set_config ( $config_name,  $config_value, [ $is_dynamic = false])
  • $config_name
  • $config_value
  • $is_dynamic
set_var (line 28)

set_var

Set variable, used by the request_var function

  • access: private
void set_var ( &$result,  $var,  $type, [ $multibyte = false])
  • &$result
  • $var
  • $type
  • $multibyte
short_ipv6 (line 3012)

Returns the first block of the specified IPv6 address and as many additional ones as specified in the length paramater.

If length is zero, then an empty string is returned. If length is greater than 3 the complete IP will be returned

void short_ipv6 ( $ip,  $length)
  • $ip
  • $length
still_on_time (line 227)

Determine whether we are approaching the maximum execution time. Should be called once at the beginning of the script in which it's used.

  • return: Either true if the maximum execution time is nearly reached, or false if some time is still left.
bool still_on_time ([ $extra_time = 15])
  • $extra_time
stripos (line 676)

A wrapper for the PHP5 function stripos Find position of first occurrence of a case-insensitive string

  • return: Returns the numeric position of the first occurrence of needle in the haystack string. Unlike strpos(), stripos() is case-insensitive. Note that the needle may be a string of one or more characters. If needle is not found, stripos() will return boolean FALSE.
mixed stripos (string $haystack, string $needle)
  • string $haystack: is the string to search in
  • string $needle: is the string to search for
str_split (line 645)

A wrapper for the PHP5 function str_split()

  • return: a string to an array. If the optional split_length parameter is specified, the returned array will be broken down into chunks with each being split_length in length, otherwise each chunk will be one character in length. FALSE is returned if split_length is less than 1. If the split_length length exceeds the length of string, the entire string is returned as the first (and only) array element.
Converts str_split (array $string, [array $split_length = 1])
  • array $string: contains the string to be converted
  • array $split_length: contains the length of each chunk
style_select (line 932)

Pick a template/theme combo,

void style_select ([ $default = ''], [ $all = false])
  • $default
  • $all
tracking_serialize (line 1566)

Transform an array into a serialized format

void tracking_serialize ( $input)
  • $input
tracking_unserialize (line 1586)

Transform a serialized array into an actual array

void tracking_unserialize ( $string, [ $max_depth = 3])
  • $string
  • $max_depth
tz_select (line 957)

Pick a timezone

void tz_select ([ $default = ''], [ $truncate = false])
  • $default
  • $truncate
unique_id (line 182)

Return unique id

void unique_id ([string $extra = 'c'])
  • string $extra: additional entropy
update_forum_tracking_info (line 1466)

Check for read forums and update topic tracking info accordingly

  • return: if complete forum got marked read, else false.
true update_forum_tracking_info (int $forum_id, int $forum_last_post_time, [int $f_mark_time = false], [int $mark_time_forum = false])
  • int $forum_id: the forum id to check
  • int $forum_last_post_time: the forums last post time
  • int $f_mark_time: the forums last mark time if user is registered and load_db_lastread enabled
  • int $mark_time_forum: false if the mark time needs to be obtained, else the last users forum mark time
_build_hidden_fields (line 2731)

Little helper for the build_hidden_fields function

void _build_hidden_fields ( $key,  $value,  $specialchar,  $stripslashes)
  • $key
  • $value
  • $specialchar
  • $stripslashes
_hash_crypt_private (line 404)

The crypt function/replacement

void _hash_crypt_private ( $password,  $setting,  &$itoa64)
  • $password
  • $setting
  • &$itoa64
_hash_encode64 (line 360)

Encode hash

void _hash_encode64 ( $input,  $count,  &$itoa64)
  • $input
  • $count
  • &$itoa64
_hash_gensalt_private (line 343)

Generate salt for hash generation

void _hash_gensalt_private ( $input,  &$itoa64, [ $iteration_count_log2 = 6])
  • $input
  • &$itoa64
  • $iteration_count_log2

Documentation generated on Tue, 26 Aug 2008 08:34:03 +0200 by phpDocumentor 1.4.2