diff --git a/phpBB/docs/coding-guidelines.html b/phpBB/docs/coding-guidelines.html index 6cd2627f43..cedf03ba9b 100644 --- a/phpBB/docs/coding-guidelines.html +++ b/phpBB/docs/coding-guidelines.html @@ -79,6 +79,8 @@
@@ -106,8 +108,8 @@Tabs in front of lines are no problem, but having them within the text can be a problem if you do not set it to the amount of spaces every one of us uses. Here is a short example of how it should look like:
-{TAB}$mode{TAB}{TAB}= request_var('mode', ''); -{TAB}$search_id{TAB}= request_var('search_id', ''); +{TAB}$mode{TAB}{TAB}= $request->variable('mode', ''); +{TAB}$search_id{TAB}= $request->variable('search_id', '');
If entered with tabs (replace the {TAB}) both equal signs need to be on the same column.
@@ -190,19 +192,12 @@ class .../includes/cache
/phpbb/cache
/adm
, /includes/acp
, /includes/functions_admin.php
/includes/db
dbal
+ /phpbb/db
, /includes/db
/includes/db/dbal.php
/includes/db/firebird.php
/includes/db/msssql.php
/includes/db/mssql_odbc.php
/includes/db/mysql.php
/includes/db/mysqli.php
/includes/db/oracle.php
/includes/db/postgres.php
/includes/db/sqlite.php
/phpbb/db/driver/
/phpbb/db/migration/
/includes/diff
/images
/install
/language
/includes/auth
/phpbb/auth
/includes/captcha
mcp.php
, /includes/mcp
, report.php
ucp.php
, /includes/ucp
/includes/utf
/includes/search
, search.php
/styles
, style.php
/phpbb/search
, search.php
/styles
If the PHPBB_USE_BOARD_URL_PATH
constant is set to true, phpBB uses generate_board_url() (this will return the boards url with the script path included) on all instances where web-accessible images are loaded. The exact locations are:
Functions should also be named descriptively. We're not programming in C here, we don't want to write functions called things like "stristr()". Again, all lower-case names with words separated by a single underscore character in PHP, and camel caps in JavaScript. Function names should preferably have a verb in them somewhere. Good function names are print_login_status()
, get_user_data()
, etc. Constructor functions in JavaScript should begin with a capital letter.
Functions should also be named descriptively. We're not programming in C here, we don't want to write functions called things like "stristr()". Again, all lower-case names with words separated by a single underscore character in PHP, and camel caps in JavaScript. Function names should be prefixed with "phpbb_" and preferably have a verb in them somewhere. Good function names are phpbb_print_login_status()
, phpbb_get_user_data()
, etc. Constructor functions in JavaScript should begin with a capital letter.
Arguments are subject to the same guidelines as variable names. We don't want a bunch of functions like: do_stuff($a, $b, $c)
. In most cases, we'd like to be able to tell how to use a function by just looking at its declaration.
Apart from following the rules for function names, all classes should meet the following conditions:
includes/
.phpbb_
to avoid name clashes, the filename should not contain the prefix.phpbb/
.\phpbb\
to avoid name clashes.dir
in the example below, not dirs
.So given the following example directory structure you would result in the below listed lookups
-includes/ +phpbb/ class_name.php dir/ class_name.php - dir.php subdir/ class_name.php
-phpbb_class_name - includes/class_name.php -phpbb_dir_class_name - includes/dir/class_name.php -phpbb_dir - includes/dir/dir.php -phpbb_dir_subdir_class_name - includes/dir/subdir/class_name.php +\phpbb\class_name - phpbb/class_name.php +\phpbb\dir\class_name - phpbb/dir/class_name.php +\phpbb\dir\subdir\class_name - phpbb/dir/subdir/class_name.php
The basic philosophy here is to not hurt code clarity for the sake of laziness. This has to be balanced by a little bit of common sense, though; print_login_status_for_a_given_user()
goes too far, for example -- that function would be better named print_user_login_status()
, or just print_login_status()
.
The basic philosophy here is to not hurt code clarity for the sake of laziness. This has to be balanced by a little bit of common sense, though; phpbb_print_login_status_for_a_given_user()
goes too far, for example -- that function would be better named phpbb_print_user_login_status()
, or just phpbb_print_login_status()
.
For all emoticons use the term smiley
in singular and smilies
in plural. For emails we use the term email
(without dash between “e” and “m”).
No attempt should be made to remove any copyright information (either contained within the source or displayed interactively when the source is run/compiled), neither should the copyright information be altered in any way (it may be added to).
Make use of the request_var()
function for anything except for submit or single checking params.
The request_var function determines the type to set from the second parameter (which determines the default value too). If you need to get a scalar variable type, you need to tell this the request_var function explicitly. Examples:
+Make use of the \phpbb\request\request
class for everything.
The $request->variable() method determines the type to set from the second parameter (which determines the default value too). If you need to get a scalar variable type, you need to tell this the variable() method explicitly. Examples:
// Old method, do not use it
@@ -1038,23 +1029,23 @@ $submit = (isset($HTTP_POST_VARS['submit'])) ? true : false;// Use request var and define a default variable (use the correct type)
--$start = request_var('start', 0); -$submit = (isset($_POST['submit'])) ? true : false; +$start = $request->variable('start', 0); +$submit = $request->is_set_post('submit');// $start is an int, the following use of request_var therefore is not allowed
+// $start is an int, the following use of $request->variable() therefore is not allowed
-$start = request_var('start', '0'); +$start = $request->variable('start', '0');// Getting an array, keys are integers, value defaults to 0
-$mark_array = request_var('mark', array(0)); +$mark_array = $request->variable('mark', array(0));// Getting an array, keys are strings, value defaults to 0
-$action_ary = request_var('action', array('' => 0)); +$action_ary = $request->variable('action', array('' => 0));Login checks/redirection:
@@ -1162,6 +1153,14 @@ append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=group&The e modifier in preg_replace can be replaced by preg_replace_callback and objects to encapsulate state that is needed in the callback code.
+Other functions, operators, statements and keywords:
+ +The following PHP statements should also not be used in phpBB:
+ +
# General Information about this style name = prosilver_duplicate -copyright = © phpBB Group, 2007 -version = 3.1.0 +copyright = © phpBB Group, 2007 +style_version = 3.1.0 +phpbb_version = 3.1.0 # Defining a different template bitfield # template_bitfield = lNg= @@ -1670,8 +1670,9 @@ div# General Information about this style name = Custom Style -copyright = © phpBB Group, 2007 -version = 3.1.0 +copyright = © phpBB Group, 2007 +style_version = 3.1.0-b1 +phpbb_version = 3.1.0-b1 # Defining a different template bitfield # template_bitfield = lNg= @@ -1689,13 +1690,15 @@ parent = prosilver
- An event name must be all lowercase, with each word separated by an underscore.
- An event name must briefly describe the location and purpose of the event.
-- An event name must end with one of the following suffixes:
--
+- -
_prepend
- This event adds an item to the beginning of a block of related items, or adds to the beginning of individual items in a block.- -
_append
- This event adds an item to the end of a block of related items, or adds to the end of individual items in a block.- -
_before
- This event adds content directly before the specified block- -
_after
- This event adds content directly after the specified block- + An event name must end with one of the following suffixes: +
+
+- +
_prepend
- This event adds an item to the beginning of a block of related items, or adds to the beginning of individual items in a block.- +
_append
- This event adds an item to the end of a block of related items, or adds to the end of individual items in a block.- +
_before
- This event adds content directly before the specified block- +
_after
- This event adds content directly after the specified blockTemplate event documentation
@@ -1707,6 +1710,7 @@ parent = prosilver * Location: styles/<style_name>/template/filename.html * Purpose: A brief description of what this event should be used for. This may span multiple lines. +* Since: Version since when the event was added
event_name @@ -1715,6 +1719,7 @@ This may span multiple lines. + first/file/path.html + second/file/path.html * Purpose: Same as above. +* Since: 3.1.0-b1
event_name @@ -1723,6 +1728,7 @@ This may span multiple lines. + first/file/path.html (2) + second/file/path.html * Purpose: Same as above. +* Since: 3.1.0-b1
forumlist_body_last_post_title_prepend @@ -1730,7 +1736,9 @@ This may span multiple lines. * Locations: + styles/prosilver/template/forumlist_body.html + styles/subsilver2/template/forumlist_body.html -* Purpose: Add content before the post title of the latest post in a forum on the forum list.
phpBB only uses the ASCII and the UTF-8 character encodings. Still all Strings are UTF-8 encoded because ASCII is a subset of UTF-8. The only exceptions to this rule are code sections which deal with external systems which use other encodings and character sets. Such external data should be converted to UTF-8 using the utf8_recode()
function supplied with phpBB. It supports a variety of other character sets and encodings, a full list can be found below.
With request_var()
you can either allow all UCS characters in user input or restrict user input to ASCII characters. This feature is controlled by the function's third parameter called $multibyte
. You should allow multibyte characters in posts, PMs, topic titles, forum names, etc. but it's not necessary for internal uses like a $mode
variable which should only hold a predefined list of ASCII strings anyway.
With $request->variable()
you can either allow all UCS characters in user input or restrict user input to ASCII characters. This feature is controlled by the method's third parameter called $multibyte
. You should allow multibyte characters in posts, PMs, topic titles, forum names, etc. but it's not necessary for internal uses like a $mode
variable which should only hold a predefined list of ASCII strings anyway.
// an input string containing a multibyte character $_REQUEST['multibyte_string'] = 'Käse'; // print request variable as a UTF-8 string allowing multibyte characters -echo request_var('multibyte_string', '', true); +echo $request->variable('multibyte_string', '', true); // print request variable as ASCII string -echo request_var('multibyte_string', ''); +echo $request->variable('multibyte_string', '');
This code snippet will generate the following output:
@@ -1779,19 +1787,6 @@ Käse K??se -If you retrieve user input with multibyte characters you should additionally normalize the string using utf8_normalize_nfc()
before you work with it. This is necessary to make sure that equal characters can only occur in one particular binary representation. For example the character Å can be represented either as U+00C5
(LATIN CAPITAL LETTER A WITH RING ABOVE) or as U+212B
(ANGSTROM SIGN). phpBB uses Normalization Form Canonical Composition (NFC) for all text. So the correct version of the above example would look like this:
-$_REQUEST['multibyte_string'] = 'Käse'; - -// normalize multibyte strings -echo utf8_normalize_nfc(request_var('multibyte_string', '', true)); -// ASCII strings do not need to be normalized -echo request_var('multibyte_string', ''); -
Case insensitive comparison of strings is no longer possible with strtolower
or strtoupper
as some characters have multiple lower case or multiple upper case forms depending on their position in a word. The utf8_strtolower
and the utf8_strtoupper
functions suffer from the same problem so they can only be used to display upper/lower case versions of a string but they cannot be used for case insensitive comparisons either. So instead you should use case folding which gives you a case insensitive version of the string which can be used for case insensitive comparisons. An NFC normalized string can be case folded using utf8_case_fold_nfc()
.
Within some cases, there may be mixed scripts of a left-to-right and right-to-left direction, so using LRE
& RLE
with PDF
may be more appropriate. Lastly, in very rare instances where directionality must be forced, then use LRO
& RLO
with PDF
.
For further information on authoring techniques of bi-directional text, please see the W3C tutorial on authoring techniques for XHTML pages with bi-directional text.
-As phpBB is translated into languages with different ordering rules to that of English, it is possible to show specific values in any order deemed appropriate. Take for example the extremely simple "Page X of Y", whilst in English this could just be coded as:
@@ -2380,7 +2375,59 @@ if (utf8_case_fold_nfc($string1) == utf8_case_fold_nfc($string2)) ... -
+ The english language is very simple when it comes to plurals.
+ You have 0 elephants
, 1 elephant
, or 2+ elephants
. So basically you have 2 different forms: one singular and one plural.
+ But for some other languages this is quite more difficult. Let's take the Bosnian language as another example:
+ You have [1/21/31] slon
, [2/3/4] slona
, [0/5/6] slonova
and [7/8/9/11] ...
and some more difficult rules.
+
The plural system takes care of this and can be used as follows:
+ +The PHP code will basically look like this:
+ ++ ... + $user->lang('NUMBER_OF_ELEPHANTS', $number_of_elephants); + ... +
And the English translation would be:
+ ++ ... + 'NUMBER_OF_ELEPHANTS' => array( + 0 => 'You have no elephants', // Optional special case for 0 + 1 => 'You have 1 elephant', // Singular + 2 => 'You have %d elephants', // Plural + ), + ... +
While the Bosnian translation can have more cases:
+ ++ ... + 'NUMBER_OF_ELEPHANTS' => array( + 0 => 'You have no slonova', // Optional special case for 0 + 1 => 'You have %d slon', // Used for 1, 21, 31, .. + 2 => 'You have %d slona', // Used for 5, 6, + 3 => ... + ), + ... +
NOTE: It is okay to use plurals for an unknown number compared to a single item, when the number is not known and displayed:
++ ... + 'MODERATOR' => 'Moderator', // Your board has 1 moderator + 'MODERATORS' => 'Moderators', // Your board has multiple moderators + ... +