PHP Bulletin Board Home
News About Home
Features of phpBB Test drive phpBB Downloads Support for phpBB The phpBB Community Styles for customising phpBB 3rd party modifications to phpBB

Support Home | Knowledge Base Home | Submit Article | Search Articles | Browse Articles
 Functions.php Doc's 
Description: Doc's on the main phpbb functions
Author: DanielT
Date: Wed Mar 05, 2003 4:58 pm
Type: Info
Keywords: function, functions, mod, mods, coding
Category: MODifications
Doc's For The Following Functions;

message_die
obtain_word_list
make_jumpbox
create_date
decode_ip
encode_ip
setup_style
init_userprefs
get_userdata
get_db_stat

____________________________________

message_die

Usage;

message_die($msg_code, $msg_text, $msg_title, $err_line, $err_file, $sql)

Explain;

This is general replacement for die(), allows templated output in users (or default) language, etc.

$msg_code can be one of these constants:

GENERAL_MESSAGE : Use for any simple text message, eg. results of an operation, authorisation failures, etc.

GENERAL_ERROR : Use for any error which occurs _AFTER_ the common.php include and session code, ie. most errors in

pages/functions

CRITICAL_MESSAGE : Used when basic config data is available but a session may not exist, eg. banned users

CRITICAL_ERROR : Used when config data cannot be obtained, eg no database connection. Should _not_ be used in 99.5% of cases

Examples;

Code:

<?php
define('IN_PHPBB', true);
$phpbb_root_path = './';
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.'.$phpEx);
$message = '<br />General Message<br />';
message_die(GENERAL_MESSAGE, $message);
?>


Example of 'general_message' only the msg_code and msg_text need to be set


Code:
<?php
define('IN_PHPBB', true);
$phpbb_root_path = './';
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.'.$phpEx);
message_die(GENERAL_ERROR, 'Could not query error list', '', __LINE__, __FILE__, $sql);
?>


Example of 'general_message' only the $sql will be the last $sql used, this is usally used for sql errors, it also displays

the line and file where the error is happening (if debug mode is enabled)


Code:
<?php
define('IN_PHPBB', true);
$phpbb_root_path = './';
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.'.$phpEx);
message_die(CRITICAL_MESSAGE, 'Session table full ect. ect.');
?>


Example of 'critical_message' only the msg_code and msg_text need to be set


Code:
<?php
define('IN_PHPBB', true);
$phpbb_root_path = './';
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.'.$phpEx);
message_die(CRITICAL_ERROR, 'The trolls have eaten your board!');
?>


will output

Quote:
phpBB : Critical Error

The trolls have eaten your board!


with no fancy templates.

____________________________________


obtain_word_list

Usage;

obtain_word_list(&$orig_word, &$replacement_word)

Explain;

'Obtain list of naughty words and build preg style replacement arrays for use by the calling script, note that the

vars are passed as references this just makes it easier to return both sets of arrays' (taken from functions.php)

Example;

Code:
<?php
define('IN_PHPBB', true);
$phpbb_root_path = './';
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.'.$phpEx);
$orig_word = array();
$replacement_word = array();
$text = "FACK";
obtain_word_list($orig_word, $replacement_word);
if ( count($orig_word) )
{
$text = preg_replace($orig_word, $replacement_word, $text);
}
echo $text;
?>


The $text is set to 'FACK' which i one my forum have set to be replaced with 'FAQ', so when it is echoed out it becomes 'FAQ', because of the word filter.

____________________________________


make_jumpbox

Usage;

make_jumpbox($action, $forum_id)

Explain;

Used to make the forum jump boxes which are displayed on 'viewforum'

$action;
This sets what page the jump box will 'jump to'
(sets the action tag in the form of the jumpbox)

$forum_id;
The forum id of the forum you which to be selected

Examples;

Code:
<?php
define('IN_PHPBB', true);
$phpbb_root_path = './';
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.'.$phpEx);
$userdata = session_pagestart($user_ip, PAGE_INDEX);
init_userprefs($userdata);
$forum_id = "1";
make_jumpbox('viewforum.'.$phpEx, $forum_id);
echo $template->_tpldata['.'][0]['JUMPBOX'];
?>


Will give you a jump box with forum 1 as the default value

Thanks;
Thanks to sj26 for the example code.


____________________________________


create_date

Usage;

create_date($format, $gmepoch, $tz)

Explain;

Uses the board_config array variables 'board_timezone' & 'default_format' to make 'time' from a unix-timestamp
this allows users to set there time format and timezone in their profile and view time in the way which they want

Examples;

Code:
<?php
define('IN_PHPBB', true);
$phpbb_root_path = './';
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.'.$phpEx);
$userdata = session_pagestart($user_ip, PAGE_INDEX);
init_userprefs($userdata);
echo create_date($board_config['default_dateformat'], time(), $board_config['board_timezone']);
?>


Uses the default settings for 'default_dateformat' & 'board_timezone' to tunr the current unix-timestamp in to 'normal' time


____________________________________


decode_ip

Usage;

decode_ip($int_ip)

Explain;

Used to decode a users ip address when taking it out of the database.

Examples;

Code:
<?php
define('IN_PHPBB', true);
$phpbb_root_path = './';
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.'.$phpEx);
$int_ip = "7f000001";
echo decode_ip($int_ip);
?>


Will convert the encoded ip address/number of 7f000001 into 127.0.0.1


____________________________________


encode_ip

Usage;

encode_ip($dotquad_ip)

Explain;

Used to encode a users ip address before it is placed into the database.

Examples;

Code:
<?php
define('IN_PHPBB', true);
$phpbb_root_path = './';
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.'.$phpEx);
$dotquad_ip = "127.0.0.1";
echo encode_ip($dotquad_ip);
?>


Will convert the ip address/number of 127.0.0.1 into 7f000001


____________________________________


setup_style

Usage;
setup_style($style)

(nb. where $style is the style id of the style you which to use)

Explain;
Uses $board_config['default_style'] to set the current style and will get the style data from the database, and

return the result in a array.

Examples;

Code:
<?php
define('IN_PHPBB', true);
$phpbb_root_path = './';
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.'.$phpEx);
$userdata = session_pagestart($user_ip, PAGE_INDEX);
init_userprefs($userdata);
$style = setup_style($board_config['default_style']);
echo $style['template_name'];
?>


Will return the name of the forums current style.

Code:
<?php
define('IN_PHPBB', true);
$phpbb_root_path = './';
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.'.$phpEx);
$userdata = session_pagestart($user_ip, PAGE_INDEX);
init_userprefs($userdata);
$style = setup_style($board_config['default_style']);
echo $style['tr_color2'];
?>


Will return the 'tr_color2' colour value of the forums current style.

(nb. 'current style' is not always the boards default style, users may have selected a different style in their

profile)

the following settings maybe taken for the array;

Quote:
themes_id
template_name
style_name
head_stylesheet
body_background
body_bgcolor
body_text
body_link
body_vlink
body_alink
body_hlink
tr_color1
tr_color2
tr_color3
tr_class1
tr_class2
tr_class3
th_color1
th_color2
th_color3
th_class1
th_class2
th_class3
td_color1
td_color2
td_color3
td_class1
td_class2
td_class3
fontface1
fontface2
fontface3
fontsize1
fontsize2
fontsize3
fontcolor1
fontcolor2
fontcolor3
span_class1
span_class2
span_class3
img_size_poll
img_size_privmsg


____________________________________


init_userprefs

Usage;
init_userprefs($userdata)

(nb. $userdata is taken from the following piece of coding;
$userdata = session_pagestart($user_ip, PAGE_INDEX);

where PAGE_INDEX can be replaced with any of the following;
Quote:
PAGE_LOGIN
PAGE_SEARCH
PAGE_REGISTER
PAGE_PROFILE
PAGE_VIEWONLINE
PAGE_VIEWMEMBERS
PAGE_FAQ
PAGE_POSTING
PAGE_PRIVMSGS
PAGE_GROUPCP
PAGE_TOPIC_OFFSET


More can be set in the constants.php
you can also use $forum_id, if set.)


Explain;

Is used to setup the board language, time settings, cookie settings (as well as other things)
the function will return a $board_config arry with the config data in it.


Examples;

Code:
<?php
define('IN_PHPBB', true);
$phpbb_root_path = './';
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.'.$phpEx);
$userdata = session_pagestart($user_ip, PAGE_INDEX);
init_userprefs($userdata);
echo $board_config['sitename'];
?>


Will return the 'sitename' which has been set in the admin config panel


Code:
<?php
define('IN_PHPBB', true);
$phpbb_root_path = './';
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.'.$phpEx);
$userdata = session_pagestart($user_ip, PAGE_INDEX);
init_userprefs($userdata);
echo $board_config['site_desc'];
?>


Will return the 'site_desc' which has been set in the admin config panel

here is a full list of all config options that can be taken form the array;

Quote:
config_id
board_disable
sitename
site_desc
cookie_name
cookie_path
cookie_domain
cookie_secure
session_length
allow_html
allow_html_tags
allow_bbcode
allow_smilies
allow_sig
allow_namechange
allow_theme_create
allow_avatar_local
allow_avatar_remote
allow_avatar_upload
override_user_style
posts_per_page
topics_per_page
hot_threshold
max_poll_options
max_sig_chars
max_inbox_privmsgs
max_sentbox_privmsgs
max_savebox_privmsgs
board_email_sig
board_email
smtp_delivery
smtp_host
smtp_username
smtp_password
require_activation
flood_interval
board_email_form
avatar_filesize
avatar_max_width
avatar_max_height
avatar_path
avatar_gallery_path
smilies_path
default_style
default_dateformat
board_timezone
prune_enable
privmsg_disable
gzip_compress
coppa_fax
coppa_mail
record_online_users
record_online_date
server_name
server_port
script_path
version
board_startdate
default_lang
vote_graphic_length
privmsg_graphic_length



____________________________________


get_userdata

Usage;
get_userdata('user_id')
get_userdata('username')

(nb; where user_id & username are the user_id or username of the user you want to query)

Explain;
Used to get user information for the database for the users profile and 'viewtopic' information,

Examples;

Code:
<?php
define('IN_PHPBB', true);
$phpbb_root_path = './';
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.'.$phpEx);
$user_id = 2;
$array = get_userdata($user_id);
echo $array['username'];
?>


Will Get the username of the user who has the user_id of 2;

Code:
<?php
define('IN_PHPBB', true);
$phpbb_root_path = './';
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.'.$phpEx);
$username = "usera";
$array = get_userdata($username);
echo $array['user_id'];
?>


Will Get the user_id of the user who has the username of 'usera';

a full list of what variables you can get from the function;

Quote:
user_id
user_active
username
user_password
user_session_time
user_session_page
user_lastvisit
user_regdate
user_level
user_posts
user_timezone
user_style
user_lang
user_dateformat
user_new_privmsg
user_unread_privmsg
user_last_privmsg
user_emailtime
user_viewemail
user_attachsig
user_allowhtml
user_allowbbcode
user_allowsmile
user_allowavatar
user_allow_pm
user_allow_viewonline
user_notify
user_notify_pm
user_popup_pm
user_rank
user_avatar
user_avatar_type
user_email
user_icq
user_website
user_from
user_sig
user_sig_bbcode_uid
user_aim
user_yim
user_msnm
user_occ
user_interests
user_actkey
user_newpasswd




____________________________________



get_db_stat

Usage;

get_db_stat('usercount')
get_db_stat('newestuser')
get_db_stat('postcount')
get_db_stat('topiccount')

Explain;
Used to get board/forum info on admin panel and 'who's online' box,

Examples;

Code:
<?php
define('IN_PHPBB', true);
$phpbb_root_path = './';
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.'.$phpEx);
echo get_db_stat('usercount');
?>


would output the total number of users the board/forum has

Code:
<?php
define('IN_PHPBB', true);
$phpbb_root_path = './';
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.'.$phpEx);
$array = get_db_stat('newestuser');
echo $array[0];
echo "<br />";
echo $array[1];
?>


would output the newest users id (user_id, $array[0]) and the username ($array[1])
for example;

Quote:
2
DanielT



Code:
<?php
define('IN_PHPBB', true);
$phpbb_root_path = './';
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.'.$phpEx);
$array = get_db_stat('postcount');
echo $array;
?>


would output the total postcount for your board/forum

Code:
<?php
define('IN_PHPBB', true);
$phpbb_root_path = './';
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.'.$phpEx);
$array = get_db_stat('topiccount');
echo $array;
?>


would output the total number of topics that your board/forum has.

Username: Password:
News | Features | Demo | Downloads | Support | Community | Styles | Mods | Links | Merchandise | About | Home
 © Copyright 2002 The phpBB Group.