aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/docs/coding-guidelines.html
diff options
context:
space:
mode:
Diffstat (limited to 'phpBB/docs/coding-guidelines.html')
-rw-r--r--phpBB/docs/coding-guidelines.html820
1 files changed, 523 insertions, 297 deletions
diff --git a/phpBB/docs/coding-guidelines.html b/phpBB/docs/coding-guidelines.html
index f3d161589b..56b71006c7 100644
--- a/phpBB/docs/coding-guidelines.html
+++ b/phpBB/docs/coding-guidelines.html
@@ -1,19 +1,13 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en" xml:lang="en">
+<!DOCTYPE html>
+<html dir="ltr" lang="en">
<head>
-
-<meta http-equiv="content-type" content="text/html; charset=utf-8" />
-<meta http-equiv="content-style-type" content="text/css" />
-<meta http-equiv="content-language" content="en" />
-<meta http-equiv="imagetoolbar" content="no" />
-<meta name="resource-type" content="document" />
-<meta name="distribution" content="global" />
-<meta name="copyright" content="phpBB Group" />
+<meta charset="utf-8">
+<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="keywords" content="" />
-<meta name="description" content="Olympus coding guidelines document" />
+<meta name="description" content="Ascraeus coding guidelines document" />
<title>phpBB3 &bull; Coding Guidelines</title>
-<link href="stylesheet.css" rel="stylesheet" type="text/css" media="screen, projection" />
+<link href="assets/css/stylesheet.css" rel="stylesheet" type="text/css" media="screen" />
</head>
@@ -23,16 +17,16 @@
<a id="top" name="top" accesskey="t"></a>
<div id="page-header">
<div class="headerbar">
- <div class="inner"><span class="corners-top"><span></span></span>
+ <div class="inner">
<div id="doc-description">
- <a href="../index.php" id="logo"><img src="site_logo.gif" alt="" /></a>
+ <a href="../index.php" id="logo"><img src="assets/images/site_logo.gif" alt="" /></a>
<h1>Coding Guidelines</h1>
- <p>Olympus coding guidelines document</p>
+ <p>Ascraeus coding guidelines document</p>
<p style="display: none;"><a href="#start_here">Skip</a></p>
</div>
- <span class="corners-bottom"><span></span></span></div>
+ </div>
</div>
</div>
@@ -42,12 +36,14 @@
<!-- BEGIN DOCUMENT -->
-<p>These are the phpBB Coding Guidelines for Olympus, all attempts should be made to follow them as closely as possible.</p>
+<p class="paragraph main-description">
+ These are the phpBB Coding Guidelines for Ascraeus, all attempts should be made to follow them as closely as possible.
+</p>
<h1>Coding Guidelines</h1>
<div class="paragraph menu">
- <div class="inner"><span class="corners-top"><span></span></span>
+ <div class="inner">
<div class="content">
@@ -62,11 +58,12 @@
</li>
<li><a href="#code">Code Layout/Guidelines</a>
<ol style="list-style-type: lower-roman;">
- <li><a href="#namingvars">Variable/Function Naming</a></li>
+ <li><a href="#namingvars">Variable/Function/Class Naming</a></li>
<li><a href="#codelayout">Code Layout</a></li>
<li><a href="#sql">SQL/SQL Layout</a></li>
<li><a href="#optimizing">Optimizations</a></li>
<li><a href="#general">General Guidelines</a></li>
+ <li><a href="#phprestrictions">Restrictions on the Use of PHP</a></li>
</ol>
</li>
<li><a href="#styling">Styling</a>
@@ -77,13 +74,16 @@
<li><a href="#templating">Templating</a>
<ol style="list-style-type: lower-roman;">
<li><a href="#templates">General Templating</a></li>
- <li><a href="#inheritance">Template Inheritance</a></li>
+ <li><a href="#stylestree">Styles Tree</a></li>
+ <li><a href="#template-events">Template Events</a></li>
</ol></li>
<li><a href="#charsets">Character Sets and Encodings</a></li>
<li><a href="#translation">Translation (<abbr title="Internationalisation">i18n</abbr>/<abbr title="Localisation">L10n</abbr>) Guidelines</a>
<ol style="list-style-type: lower-roman;">
<li><a href="#standardisation">Standardisation</a></li>
<li><a href="#otherconsiderations">Other considerations</a></li>
+ <li><a href="#placeholders">Working with placeholders</a></li>
+ <li><a href="#usingplurals">Using plurals</a></li>
<li><a href="#writingstyle">Writing Style</a></li>
</ol>
</li>
@@ -92,7 +92,7 @@
</div>
- <span class="corners-bottom"><span></span></span></div>
+ </div>
</div>
<hr />
@@ -100,7 +100,7 @@
<a name="defaults"></a><h2>1. Defaults</h2>
<div class="paragraph">
- <div class="inner"><span class="corners-top"><span></span></span>
+ <div class="inner">
<div class="content">
@@ -111,16 +111,16 @@
<p>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:</p>
<div class="codebox"><pre>
-{TAB}$mode{TAB}{TAB}= request_var('mode', '');
-{TAB}$search_id{TAB}= request_var('search_id', '');
- </pre></div>
+{TAB}$mode{TAB}{TAB}= $request->variable('mode', '');
+{TAB}$search_id{TAB}= $request->variable('search_id', '');</pre>
+ </div>
<p>If entered with tabs (replace the {TAB}) both equal signs need to be on the same column.</p>
<h3>Linefeeds:</h3>
<p>Ensure that your editor is saving files in the UNIX (LF) line ending format. This means that lines are terminated with a newline, not with Windows Line endings (CR/LF combo) as they are on Win32 or Classic Mac (CR) Line endings. Any decent editor should be able to do this, but it might not always be the default setting. Know your editor. If you want advice for an editor for your Operating System, just ask one of the developers. Some of them do their editing on Win32.</p>
- <a name="fileheader"></a><h3>1.ii. File Header</h3>
+ <a name="fileheader"></a><h3>1.ii. File Layout</h3>
<h4>Standard header for new files:</h4>
<p>This template of the header must be included at the start of all phpBB files: </p>
@@ -128,15 +128,27 @@
<div class="codebox"><pre>
/**
*
-* @package {PACKAGENAME}
-* @copyright (c) 2007 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+* This file is part of the phpBB Forum Software package.
*
-*/
- </pre></div>
+* @copyright (c) phpBB Limited &lt;https://www.phpbb.com&gt;
+* @license GNU General Public License, version 2 (GPL-2.0)
+*
+* For full copyright and license information, please see
+* the docs/CREDITS.txt file.
+*
+*/</pre>
+ </div>
<p>Please see the <a href="#locations">File Locations section</a> for the correct package name.</p>
+ <h4>PHP closing tags</h4>
+
+ <p>A file containg only PHP code should not end with the optional PHP closing tag <strong>?&gt;</strong> to avoid issues with whitespace following it.</p>
+
+ <h4>Newline at end of file</h4>
+
+ <p>All files should end in a newline so the last line does not appear as modified in diffs, when a line is appended to the file.</p>
+
<h4>Files containing inline code:</h4>
<p>For those files you have to put an empty comment directly after the header to prevent the documentor assigning the header to the first code element found.</p>
@@ -148,8 +160,8 @@
/**
*/
-{CODE}
- </pre></div>
+{CODE}</pre>
+ </div>
<h4>Files containing only functions:</h4>
@@ -176,8 +188,8 @@ Small code snipped, mostly one or two defines or an if statement
/**
* {DOCUMENTATION}
*/
-class ...
- </pre></div>
+class ...</pre>
+ </div>
<a name="locations"></a><h3>1.iii. File Locations</h3>
@@ -187,19 +199,12 @@ class ...
<ul>
<li><strong>phpBB3</strong><br />Core files and all files not assigned to a separate package</li>
- <li><strong>acm</strong><br /><code>/includes/acm</code>, <code>/includes/cache.php</code><br />Cache System</li>
+ <li><strong>acm</strong><br /><code>/phpbb/cache</code><br />Cache System</li>
<li><strong>acp</strong><br /><code>/adm</code>, <code>/includes/acp</code>, <code>/includes/functions_admin.php</code><br />Administration Control Panel</li>
- <li><strong>dbal</strong><br /><code>/includes/db</code><br />Database Abstraction Layer.<br />Base class is <code>dbal</code>
+ <li><strong>dbal</strong><br /><code>/phpbb/db</code>, <code>/includes/db</code><br />Database Abstraction Layer.
<ul>
- <li><code>/includes/db/dbal.php</code><br />Base DBAL class, defining the overall framework</li>
- <li><code>/includes/db/firebird.php</code><br />Firebird/Interbase Database Abstraction Layer</li>
- <li><code>/includes/db/msssql.php</code><br />MSSQL Database Abstraction Layer</li>
- <li><code>/includes/db/mssql_odbc.php</code><br />MSSQL ODBC Database Abstraction Layer for MSSQL</li>
- <li><code>/includes/db/mysql.php</code><br />MySQL Database Abstraction Layer for MySQL 3.x/4.0.x/4.1.x/5.x</li>
- <li><code>/includes/db/mysqli.php</code><br />MySQLi Database Abstraction Layer</li>
- <li><code>/includes/db/oracle.php</code><br />Oracle Database Abstraction Layer</li>
- <li><code>/includes/db/postgres.php</code><br />PostgreSQL Database Abstraction Layer</li>
- <li><code>/includes/db/sqlite.php</code><br />Sqlite Database Abstraction Layer</li>
+ <li><code>/phpbb/db/driver/</code><br />Database Abstraction Layer classes</li>
+ <li><code>/phpbb/db/migration/</code><br />Migrations are used for updating the database from one release to another</li>
</ul>
</li>
<li><strong>diff</strong><br /><code>/includes/diff</code><br />Diff Engine</li>
@@ -207,13 +212,13 @@ class ...
<li><strong>images</strong><br /><code>/images</code><br />All global images not connected to styles</li>
<li><strong>install</strong><br /><code>/install</code><br />Installation System</li>
<li><strong>language</strong><br /><code>/language</code><br />All language files</li>
- <li><strong>login</strong><br /><code>/includes/auth</code><br />Login Authentication Plugins</li>
+ <li><strong>login</strong><br /><code>/phpbb/auth</code><br />Login Authentication Plugins</li>
<li><strong>VC</strong><br /><code>/includes/captcha</code><br />CAPTCHA</li>
<li><strong>mcp</strong><br /><code>mcp.php</code>, <code>/includes/mcp</code>, <code>report.php</code><br />Moderator Control Panel</li>
<li><strong>ucp</strong><br /><code>ucp.php</code>, <code>/includes/ucp</code><br />User Control Panel</li>
<li><strong>utf</strong><br /><code>/includes/utf</code><br />UTF8-related functions/classes</li>
- <li><strong>search</strong><br /><code>/includes/search</code>, <code>search.php</code><br />Search System</li>
- <li><strong>styles</strong><br /><code>/styles</code>, <code>style.php</code><br />phpBB Styles/Templates/Themes/Imagesets</li>
+ <li><strong>search</strong><br /><code>/phpbb/search</code>, <code>search.php</code><br />Search System</li>
+ <li><strong>styles</strong><br /><code>/styles</code><br />phpBB Styles/Templates/Themes</li>
</ul>
<a name="constants"></a><h3>1.iv. Special Constants</h3>
@@ -246,18 +251,17 @@ PHPBB_QA (Set board to QA-Mode, which means the updater also c
<p>If the <code>PHPBB_USE_BOARD_URL_PATH</code> 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:</p>
<ul>
- <li>/includes/session.php - user::img()</li>
+ <li>/phpbb/user.php - \phpbb\user::img()</li>
<li>/includes/functions_content.php - smiley_text()</li>
</ul>
<p>Path locations for the following template variables are affected by this too:</p>
<ul>
+ <li>{T_ASSETS_PATH} - assets (non-style specific, static resources)</li>
<li>{T_THEME_PATH} - styles/xxx/theme</li>
<li>{T_TEMPLATE_PATH} - styles/xxx/template</li>
<li>{T_SUPER_TEMPLATE_PATH} - styles/xxx/template</li>
- <li>{T_IMAGESET_PATH} - styles/xxx/imageset</li>
- <li>{T_IMAGESET_LANG_PATH} - styles/xxx/imageset/yy</li>
<li>{T_IMAGES_PATH} - images/</li>
<li>{T_SMILIES_PATH} - $config['smilies_path']/</li>
<li>{T_AVATAR_PATH} - $config['avatar_path']/</li>
@@ -265,7 +269,7 @@ PHPBB_QA (Set board to QA-Mode, which means the updater also c
<li>{T_ICONS_PATH} - $config['icons_path']/</li>
<li>{T_RANKS_PATH} - $config['ranks_path']/</li>
<li>{T_UPLOAD_PATH} - $config['upload_path']/</li>
- <li>{T_STYLESHEET_LINK} - styles/xxx/theme/stylesheet.css (or link to style.php if css is parsed dynamically)</li>
+ <li>{T_STYLESHEET_LINK} - styles/xxx/theme/stylesheet.css</li>
<li>New template variable {BOARD_URL} for the board url + script path.</li>
</ul>
@@ -273,7 +277,7 @@ PHPBB_QA (Set board to QA-Mode, which means the updater also c
<div class="back2top"><a href="#wrap" class="top">Back to Top</a></div>
- <span class="corners-bottom"><span></span></span></div>
+ </div>
</div>
<hr />
@@ -281,23 +285,29 @@ PHPBB_QA (Set board to QA-Mode, which means the updater also c
<a name="code"></a><h2>2. Code Layout/Guidelines</h2>
<div class="paragraph">
- <div class="inner"><span class="corners-top"><span></span></span>
+ <div class="inner">
<div class="content">
<p>Please note that these guidelines apply to all php, html, javascript and css files.</p>
- <a name="namingvars"></a><h3>2.i. Variable/Function Naming</h3>
+ <a name="namingvars"></a><h3>2.i. Variable/Function/Class Naming</h3>
<p>We will not be using any form of hungarian notation in our naming conventions. Many of us believe that hungarian naming is one of the primary code obfuscation techniques currently in use.</p>
<h4>Variable Names:</h4>
- <p>Variable names should be in all lowercase, with words separated by an underscore, example:</p>
+ <p>In PHP, variable names should be in all lowercase, with words separated by an underscore, example:</p>
<div class="indent">
<p><code>$current_user</code> is right, but <code>$currentuser</code> and <code> $currentUser</code> are not.</p>
</div>
+ <p>In JavaScript, variable names should use camel case:</p>
+
+ <div class="indent">
+ <p><code>currentUser</code> is right, but <code>currentuser</code> and <code>current_user</code> are not.</p>
+ </div>
+
<p>Names should be descriptive, but concise. We don't want huge sentences as our variable names, but typing an extra couple of characters is always better than wondering what exactly a certain variable is for. </p>
<h4>Loop Indices:</h4>
@@ -310,20 +320,48 @@ for ($i = 0; $i &lt; $outer_size; $i++)
{
foo($i, $j);
}
-}
- </pre></div>
+}</pre>
+ </div>
<h4>Function Names:</h4>
- <p>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. Function names should preferably have a verb in them somewhere. Good function names are <code>print_login_status()</code>, <code>get_user_data()</code>, etc. </p>
+ <p>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 <code>phpbb_print_login_status()</code>, <code>phpbb_get_user_data()</code>, etc. Constructor functions in JavaScript should begin with a capital letter.</p>
<h4>Function Arguments:</h4>
<p>Arguments are subject to the same guidelines as variable names. We don't want a bunch of functions like: <code>do_stuff($a, $b, $c)</code>. In most cases, we'd like to be able to tell how to use a function by just looking at its declaration. </p>
+ <h4>Class Names:</h4>
+
+ <p>Apart from following the rules for function names, all classes should meet the following conditions:</p>
+ <ul>
+ <li>Every class must be defined in a separate file.</li>
+ <li>The classes have to be located in a subdirectory of <code>phpbb/</code>.</li>
+ <li>Classnames must be namespaced with <code>\phpbb\</code> to avoid name clashes.</li>
+ <li>Class names/namespaces have to reflect the location of the file they are defined in. The namespace must be the directory in which the file is located. So the directory names must not contain any underscores, but the filename may.</li>
+ <li>Directories should typically be a singular noun (e.g. <code>dir</code> in the example below, not <code>dirs</code>.</li>
+ </ul>
+
+ <p>So given the following example directory structure you would result in the below listed lookups</p>
+ <div class="codebox"><pre>
+phpbb/
+ class_name.php
+ dir/
+ class_name.php
+ subdir/
+ class_name.php</pre>
+ </div>
+
+ <div class="codebox"><pre>
+\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</pre>
+ </div>
+
+
<h4>Summary:</h4>
- <p>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; <code>print_login_status_for_a_given_user()</code> goes too far, for example -- that function would be better named <code>print_user_login_status()</code>, or just <code>print_login_status()</code>.</p>
+ <p>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; <code>phpbb_print_login_status_for_a_given_user()</code> goes too far, for example -- that function would be better named <code>phpbb_print_user_login_status()</code>, or just <code>phpbb_print_login_status()</code>.</p>
<h4>Special Namings: </h4>
- <p>For all emoticons use the term <code>smiley</code> in singular and <code>smilies</code> in plural.</p>
+ <p>For all emoticons use the term <code>smiley</code> in singular and <code>smilies</code> in plural. For emails we use the term <code>email</code> (without dash between “e” and “m”).</p>
<a name="codelayout"></a><h3>2.ii. Code Layout</h3>
@@ -342,8 +380,8 @@ while (condition)
do_stuff();
for ($i = 0; $i &lt; size; $i++)
- do_stuff($i);
- </pre></div>
+ do_stuff($i);</pre>
+ </div>
<p class="good">// These are all right. </p>
<div class="codebox"><pre>
@@ -360,11 +398,11 @@ while (condition)
for ($i = 0; $i &lt; size; $i++)
{
do_stuff();
-}
- </pre></div>
+}</pre>
+ </div>
<h4>Where to put the braces:</h4>
- <p>This one is a bit of a holy war, but we're going to use a style that can be summed up in one sentence: Braces always go on their own line. The closing brace should also always be at the same column as the corresponding opening brace, examples:</p>
+ <p>In PHP code, braces always go on their own line. The closing brace should also always be at the same column as the corresponding opening brace, examples:</p>
<div class="codebox"><pre>
if (condition)
@@ -392,8 +430,32 @@ while (condition)
function do_stuff()
{
...
+}</pre>
+ </div>
+
+ <p>In JavaScript code, braces always go on the same line:</p>
+
+ <div class="codebox"><pre>
+if (condition) {
+ while (condition2) {
+ ...
+ }
+} else {
+ ...
}
- </pre></div>
+
+for (var i = 0; i &lt; size; i++) {
+ ...
+}
+
+while (condition) {
+ ...
+}
+
+function do_stuff() {
+ ...
+}</pre>
+ </div>
<h4>Use spaces between tokens:</h4>
<p>This is another simple, easy step that helps keep code readable without much effort. Whenever you write an assignment, expression, etc.. Always leave <em>one</em> space between the tokens. Basically, write code as if it was English. Put spaces between variable names and operators. Don't put spaces just after an opening bracket or before a closing bracket. Don't put spaces just before a comma or a semicolon. This is best shown with a few examples, examples:</p>
@@ -417,26 +479,26 @@ for($i=0; $i&lt;$size; $i++) ...
for ($i = 0; $i &lt; $size; $i++) ...
$i=($j &lt; $size)?0:1;
-$i = ($j &lt; $size) ? 0 : 1;
- </pre></div>
+$i = ($j &lt; $size) ? 0 : 1;</pre>
+ </div>
<h4>Operator precedence:</h4>
<p>Do you know the exact precedence of all the operators in PHP? Neither do I. Don't guess. Always make it obvious by using brackets to force the precedence of an equation so you know what it does. Remember to not over-use this, as it may harden the readability. Basically, do not enclose single expressions. Examples:</p>
<p class="bad">// what's the result? who knows. </p>
- <div class="codebox"><pre>
-$bool = ($i &lt; 7 &amp;&amp; $j &gt; 8 || $k == 4);
- </pre></div>
+ <div class="codebox">
+ <pre>$bool = ($i &lt; 7 &amp;&amp; $j &gt; 8 || $k == 4);</pre>
+ </div>
<p class="bad">// now you can be certain what I'm doing here.</p>
- <div class="codebox"><pre>
-$bool = (($i &lt; 7) &amp;&amp; (($j &lt; 8) || ($k == 4)));
- </pre></div>
+ <div class="codebox">
+ <pre>$bool = (($i &lt; 7) &amp;&amp; (($j &lt; 8) || ($k == 4)));</pre>
+ </div>
<p class="good">// But this one is even better, because it is easier on the eye but the intention is preserved</p>
- <div class="codebox"><pre>
-$bool = ($i &lt; 7 &amp;&amp; ($j &lt; 8 || $k == 4));
- </pre></div>
+ <div class="codebox">
+ <pre>$bool = ($i &lt; 7 &amp;&amp; ($j &lt; 8 || $k == 4));</pre>
+ </div>
<h4>Quoting strings:</h4>
<p>There are two different ways to quote strings in PHP - either with single quotes or with double quotes. The main difference is that the parser does variable interpolation in double-quoted strings, but not in single quoted strings. Because of this, you should <em>always</em> use single quotes <em>unless</em> you specifically need variable interpolation to be done on that string. This way, we can save the parser the trouble of parsing a bunch of strings where no interpolation needs to be done.</p>
@@ -446,50 +508,70 @@ $bool = ($i &lt; 7 &amp;&amp; ($j &lt; 8 || $k == 4));
<div class="codebox"><pre>
$str = "This is a really long string with no variables for the parser to find.";
-do_stuff("$str");
- </pre></div>
+do_stuff("$str");</pre>
+ </div>
<p class="good">// right</p>
<div class="codebox"><pre>
$str = 'This is a really long string with no variables for the parser to find.';
-do_stuff($str);
- </pre></div>
+do_stuff($str);</pre>
+ </div>
<p class="bad">// Sometimes single quotes are just not right</p>
<div class="codebox"><pre>
-$post_url = $phpbb_root_path . 'posting.' . $phpEx . '?mode=' . $mode . '&amp;amp;start=' . $start;
- </pre></div>
+$post_url = $phpbb_root_path . 'posting.' . $phpEx . '?mode=' . $mode . '&amp;amp;start=' . $start;</pre>
+ </div>
<p class="good">// Double quotes are sometimes needed to not overcrowd the line with concatenations.</p>
<div class="codebox"><pre>
-$post_url = "{$phpbb_root_path}posting.$phpEx?mode=$mode&amp;amp;start=$start";
- </pre></div>
+$post_url = "{$phpbb_root_path}posting.$phpEx?mode=$mode&amp;amp;start=$start";</pre>
+ </div>
<p>In SQL statements mixing single and double quotes is partly allowed (following the guidelines listed here about SQL formatting), else one should try to only use one method - mostly single quotes.</p>
- <h4>Associative array keys:</h4>
- <p>In PHP, it's legal to use a literal string as a key to an associative array without quoting that string. We don't want to do this -- the string should always be quoted to avoid confusion. Note that this is only when we're using a literal, not when we're using a variable, examples:</p>
+ <h4>Commas after every array element:</h4>
+ <p>If an array is defined with each element on its own line, you still have to modify the previous line to add a comma when appending a new element. PHP allows for trailing (useless) commas in array definitions. These should always be used so each element including the comma can be appended with a single line. In JavaScript, do not use the trailing comma, as it causes browsers to throw errors.</p>
<p class="bad">// wrong</p>
<div class="codebox"><pre>
-$foo = $assoc_array[blah];
- </pre></div>
+$foo = array(
+ 'bar' => 42,
+ 'boo' => 23
+);</pre>
+ </div>
<p class="good">// right </p>
<div class="codebox"><pre>
-$foo = $assoc_array['blah'];
- </pre></div>
+$foo = array(
+ 'bar' => 42,
+ 'boo' => 23,
+);</pre>
+ </div>
+
+
+ <h4>Associative array keys:</h4>
+ <p>In PHP, it's legal to use a literal string as a key to an associative array without quoting that string. We don't want to do this -- the string should always be quoted to avoid confusion. Note that this is only when we're using a literal, not when we're using a variable, examples:</p>
<p class="bad">// wrong</p>
- <div class="codebox"><pre>
-$foo = $assoc_array["$var"];
- </pre></div>
+ <div class="codebox">
+ <pre>$foo = $assoc_array[blah];</pre>
+ </div>
<p class="good">// right </p>
- <div class="codebox"><pre>
-$foo = $assoc_array[$var];
- </pre></div>
+ <div class="codebox">
+ <pre>$foo = $assoc_array['blah'];</pre>
+ </div>
+
+ <p class="bad">// wrong</p>
+ <div class="codebox">
+ <pre>$foo = $assoc_array["$var"];</pre>
+ </div>
+
+ <p class="good">// right </p>
+ <div class="codebox">
+ <pre>$foo = $assoc_array[$var];</pre>
+ </div>
<h4>Comments:</h4>
<p>Each complex function should be preceded by a comment that tells a programmer everything they need to know to use that function. The meaning of every parameter, the expected input, and the output are required as a minimal comment. The function's behaviour in error conditions (and what those error conditions are) should also be present - but mostly included within the comment about the output.<br /><br />Especially important to document are any assumptions the code makes, or preconditions for its proper operation. Any one of the developers should be able to look at any part of the application and figure out what's going on in a reasonable amount of time.<br /><br />Avoid using <code>/* */</code> comment blocks for one-line comments, <code>//</code> should be used for one/two-liners.</p>
@@ -503,8 +585,8 @@ $foo = $assoc_array[$var];
<p class="bad">// wrong </p>
<div class="codebox"><pre>
$array[++$i] = $j;
-$array[$i++] = $k;
- </pre></div>
+$array[$i++] = $k;</pre>
+ </div>
<p class="good">// right </p>
<div class="codebox"><pre>
@@ -512,39 +594,38 @@ $i++;
$array[$i] = $j;
$array[$i] = $k;
-$i++;
- </pre></div>
+$i++;</pre>
+ </div>
<h4>Inline conditionals:</h4>
<p>Inline conditionals should only be used to do very simple things. Preferably, they will only be used to do assignments, and not for function calls or anything complex at all. They can be harmful to readability if used incorrectly, so don't fall in love with saving typing by using them, examples:</p>
<p class="bad">// Bad place to use them</p>
<div class="codebox"><pre>
-($i &lt; $size &amp;&amp; $j &gt; $size) ? do_stuff($foo) : do_stuff($bar);
- </pre></div>
+($i &lt; $size &amp;&amp; $j &gt; $size) ? do_stuff($foo) : do_stuff($bar);</pre>
+ </div>
<p class="good">// OK place to use them </p>
<div class="codebox"><pre>
-$min = ($i &lt; $j) ? $i : $j;
- </pre></div>
+$min = ($i &lt; $j) ? $i : $j;</pre>
+ </div>
<h4>Don't use uninitialized variables.</h4>
<p>For phpBB3, we intend to use a higher level of run-time error reporting. This will mean that the use of an uninitialized variable will be reported as a warning. These warnings can be avoided by using the built-in isset() function to check whether a variable has been set - but preferably the variable is always existing. For checking if an array has a key set this can come in handy though, examples:</p>
<p class="bad">// Wrong </p>
- <div class="codebox"><pre>
-if ($forum) ...
- </pre></div>
+ <div class="codebox">
+ <pre>if ($forum) ...</pre>
+ </div>
<p class="good">// Right </p>
- <div class="codebox"><pre>
-if (isset($forum)) ...
- </pre></div>
+ <div class="codebox">
+ <pre>if (isset($forum)) ...</pre></div>
<p class="good">// Also possible</p>
- <div class="codebox"><pre>
-if (isset($forum) &amp;&amp; $forum == 5)
- </pre></div>
+ <div class="codebox">
+ <pre>if (isset($forum) &amp;&amp; $forum == 5)</pre>
+ </div>
<p>The <code>empty()</code> function is useful if you want to check if a variable is not set or being empty (an empty string, 0 as an integer or string, NULL, false, an empty array or a variable declared, but without a value in a class). Therefore empty should be used in favor of <code>isset($array) &amp;&amp; sizeof($array) &gt; 0</code> - this can be written in a shorter way as <code>!empty($array)</code>.</p>
@@ -561,8 +642,8 @@ switch ($mode)
case 'mode2':
// I am doing something completely different here
break;
-}
- </pre></div>
+}</pre>
+ </div>
<p class="good">// Good </p>
<div class="codebox"><pre>
@@ -579,8 +660,8 @@ switch ($mode)
default:
// Always assume that a case was not caught
break;
-}
- </pre></div>
+}</pre>
+ </div>
<p class="good">// Also good, if you have more code between the case and the break </p>
<div class="codebox"><pre>
@@ -603,8 +684,8 @@ switch ($mode)
// Always assume that a case was not caught
break;
-}
- </pre></div>
+}</pre>
+ </div>
<p>Even if the break for the default case is not needed, it is sometimes better to include it just for readability and completeness.</p>
@@ -631,13 +712,33 @@ switch ($mode)
// Always assume that a case was not caught
break;
-}
- </pre></div>
+}</pre>
+ </div>
+
+ <h4>Class Members</h4>
+ <p>Use the explicit visibility qualifiers <code>public</code>, <code>private</code> and <code>protected</code> for all properties instead of <code>var</code>.
+
+ <p>Place the <code>static</code> qualifier before the visibility qualifiers.</p>
+
+ <p class="bad">//Wrong </p>
+ <div class="codebox"><pre>
+var $x;
+private static function f()</pre>
+ </div>
+
+ <p class="good">// Right </p>
+ <div class="codebox"><pre>
+public $x;
+static private function f()</pre>
+ </div>
+
+ <h4>Constants</h4>
+ <p>Prefer class constants over global constants created with <code>define()</code>.</p>
<a name="sql"></a><h3>2.iii. SQL/SQL Layout</h3>
<h4>Common SQL Guidelines: </h4>
- <p>All SQL should be cross-DB compatible, if DB specific SQL is used alternatives must be provided which work on all supported DB's (MySQL3/4/5, MSSQL (7.0 and 2000), PostgreSQL (7.0+), Firebird, SQLite, Oracle8, ODBC (generalised if possible)).</p>
+ <p>All SQL should be cross-DB compatible, if DB specific SQL is used alternatives must be provided which work on all supported DB's (MySQL3/4/5, MSSQL (7.0 and 2000), PostgreSQL (8.3+), SQLite, Oracle8, ODBC (generalised if possible)).</p>
<p>All SQL commands should utilise the DataBase Abstraction Layer (DBAL)</p>
<h4>SQL code layout:</h4>
@@ -649,8 +750,8 @@ $sql = 'SELECT *
&lt;-one tab-&gt;WHERE a = 1
&lt;-two tabs-&gt;AND (b = 2
&lt;-three tabs-&gt;OR b = 3)
-&lt;-one tab-&gt;ORDER BY b';
- </pre></div>
+&lt;-one tab-&gt;ORDER BY b';</pre>
+ </div>
<p>Here the example with the tabs applied:</p>
@@ -660,8 +761,8 @@ $sql = 'SELECT *
WHERE a = 1
AND (b = 2
OR b = 3)
- ORDER BY b';
- </pre></div>
+ ORDER BY b';</pre>
+ </div>
<h4>SQL Quotes: </h4>
<p>Use double quotes where applicable. (The variables in these examples are typecasted to integers beforehand.) Examples: </p>
@@ -670,16 +771,16 @@ $sql = 'SELECT *
<div class="codebox"><pre>
"UPDATE " . SOME_TABLE . " SET something = something_else WHERE a = $b";
-'UPDATE ' . SOME_TABLE . ' SET something = ' . $user_id . ' WHERE a = ' . $something;
- </pre></div>
+'UPDATE ' . SOME_TABLE . ' SET something = ' . $user_id . ' WHERE a = ' . $something;</pre>
+ </div>
<p class="good">// These are right. </p>
<div class="codebox"><pre>
'UPDATE ' . SOME_TABLE . " SET something = something_else WHERE a = $b";
-'UPDATE ' . SOME_TABLE . " SET something = $user_id WHERE a = $something";
- </pre></div>
+'UPDATE ' . SOME_TABLE . " SET something = $user_id WHERE a = $something";</pre>
+ </div>
<p>In other words use single quotes where no variable substitution is required or where the variable involved shouldn't appear within double quotes. Otherwise use double quotes.</p>
@@ -690,15 +791,15 @@ $sql = 'SELECT *
<div class="codebox"><pre>
$sql = 'SELECT *
FROM ' . SOME_TABLE . '
- WHERE a != 2';
- </pre></div>
+ WHERE a != 2';</pre>
+ </div>
<p class="good">// This is right. </p>
<div class="codebox"><pre>
$sql = 'SELECT *
FROM ' . SOME_TABLE . '
- WHERE a &lt;&gt; 2';
- </pre></div>
+ WHERE a &lt;&gt; 2';</pre>
+ </div>
<h4>Common DBAL methods: </h4>
@@ -709,8 +810,8 @@ $sql = 'SELECT *
<div class="codebox"><pre>
$sql = 'SELECT *
FROM ' . SOME_TABLE . "
- WHERE username = '" . $db-&gt;sql_escape($username) . "'";
- </pre></div>
+ WHERE username = '" . $db-&gt;sql_escape($username) . "'";</pre>
+ </div>
<h4>sql_query_limit():</h4>
@@ -731,8 +832,8 @@ $sql_ary = array(
'moredata' =&gt; $another_int,
);
-$db-&gt;sql_query('INSERT INTO ' . SOME_TABLE . ' ' . $db-&gt;sql_build_array('INSERT', $sql_ary));
- </pre></div>
+$db-&gt;sql_query('INSERT INTO ' . SOME_TABLE . ' ' . $db-&gt;sql_build_array('INSERT', $sql_ary));</pre>
+ </div>
<p>To complete the example, this is how an update statement would look like:</p>
@@ -746,8 +847,8 @@ $sql_ary = array(
$sql = 'UPDATE ' . SOME_TABLE . '
SET ' . $db-&gt;sql_build_array('UPDATE', $sql_ary) . '
WHERE user_id = ' . (int) $user_id;
-$db-&gt;sql_query($sql);
- </pre></div>
+$db-&gt;sql_query($sql);</pre>
+ </div>
<p>The <code>$db-&gt;sql_build_array()</code> function supports the following modes: <code>INSERT</code> (example above), <code>INSERT_SELECT</code> (building query for <code>INSERT INTO table (...) SELECT value, column ...</code> statements), <code>UPDATE</code> (example above) and <code>SELECT</code> (for building WHERE statement [AND logic]).</p>
@@ -770,8 +871,8 @@ $sql_ary[] = array(
'moredata' =&gt; $another_int_2,
);
-$db->sql_multi_insert(SOME_TABLE, $sql_ary);
- </pre></div>
+$db->sql_multi_insert(SOME_TABLE, $sql_ary);</pre>
+ </div>
<h4>sql_in_set():</h4>
@@ -781,22 +882,22 @@ $db->sql_multi_insert(SOME_TABLE, $sql_ary);
$sql = 'SELECT *
FROM ' . FORUMS_TABLE . '
WHERE ' . $db-&gt;sql_in_set('forum_id', $forum_ids);
-$db-&gt;sql_query($sql);
- </pre></div>
+$db-&gt;sql_query($sql);</pre>
+ </div>
<p>Based on the number of values in $forum_ids, the query can look differently.</p>
<p class="good">// SQL Statement if $forum_ids = array(1, 2, 3);</p>
<div class="codebox"><pre>
-SELECT FROM phpbb_forums WHERE forum_id IN (1, 2, 3)
- </pre></div>
+SELECT FROM phpbb_forums WHERE forum_id IN (1, 2, 3)</pre>
+ </div>
<p class="good">// SQL Statement if $forum_ids = array(1) or $forum_ids = 1</p>
<div class="codebox"><pre>
-SELECT FROM phpbb_forums WHERE forum_id = 1
- </pre></div>
+SELECT FROM phpbb_forums WHERE forum_id = 1</pre>
+ </div>
<p>Of course the same is possible for doing a negative match against a number of values:</p>
@@ -804,22 +905,22 @@ SELECT FROM phpbb_forums WHERE forum_id = 1
$sql = 'SELECT *
FROM ' . FORUMS_TABLE . '
WHERE ' . $db-&gt;sql_in_set('forum_id', $forum_ids, <strong>true</strong>);
-$db-&gt;sql_query($sql);
- </pre></div>
+$db-&gt;sql_query($sql);</pre>
+ </div>
<p>Based on the number of values in $forum_ids, the query can look differently here too.</p>
<p class="good">// SQL Statement if $forum_ids = array(1, 2, 3);</p>
<div class="codebox"><pre>
-SELECT FROM phpbb_forums WHERE forum_id <strong>NOT</strong> IN (1, 2, 3)
- </pre></div>
+SELECT FROM phpbb_forums WHERE forum_id <strong>NOT</strong> IN (1, 2, 3)</pre>
+ </div>
<p class="good">// SQL Statement if $forum_ids = array(1) or $forum_ids = 1</p>
<div class="codebox"><pre>
-SELECT FROM phpbb_forums WHERE forum_id <strong>&lt;&gt;</strong> 1
- </pre></div>
+SELECT FROM phpbb_forums WHERE forum_id <strong>&lt;&gt;</strong> 1</pre>
+ </div>
<p>If the given array is empty, an error will be produced.</p>
@@ -849,8 +950,8 @@ $sql_array = array(
'ORDER_BY' =&gt; 'left_id',
);
-$sql = $db-&gt;sql_build_query('SELECT', $sql_array);
- </pre></div>
+$sql = $db-&gt;sql_build_query('SELECT', $sql_array);</pre>
+ </div>
<p>The possible first parameter for sql_build_query() is SELECT or SELECT_DISTINCT. As you can see, the logic is pretty self-explaining. For the LEFT_JOIN key, just add another array if you want to join on to tables for example. The added benefit of using this construct is that you are able to easily build the query statement based on conditions - for example the above LEFT_JOIN is only necessary if server side topic tracking is enabled; a slight adjustement would be:</p>
@@ -885,8 +986,8 @@ else
// Here we read the cookie data
}
-$sql = $db-&gt;sql_build_query('SELECT', $sql_array);
- </pre></div>
+$sql = $db-&gt;sql_build_query('SELECT', $sql_array);</pre>
+ </div>
<a name="optimizing"></a><h3>2.iv. Optimizations</h3>
@@ -898,16 +999,16 @@ $sql = $db-&gt;sql_build_query('SELECT', $sql_array);
for ($i = 0; $i &lt; sizeof($post_data); $i++)
{
do_something();
-}
- </pre></div>
+}</pre>
+ </div>
<p class="good">// You are able to assign the (not changing) result within the loop itself</p>
<div class="codebox"><pre>
for ($i = 0, $size = sizeof($post_data); $i &lt; $size; $i++)
{
do_something();
-}
- </pre></div>
+}</pre>
+ </div>
<h4>Use of in_array(): </h4>
<p>Try to avoid using in_array() on huge arrays, and try to not place them into loops if the array to check consist of more than 20 entries. in_array() can be very time consuming and uses a lot of cpu processing time. For little checks it is not noticeable, but if checked against a huge array within a loop those checks alone can take several seconds. If you need this functionality, try using isset() on the arrays keys instead, actually shifting the values into keys and vice versa. A call to <code>isset($array[$var])</code> is a lot faster than <code>in_array($var, array_keys($array))</code> for example.</p>
@@ -923,35 +1024,35 @@ for ($i = 0, $size = sizeof($post_data); $i &lt; $size; $i++)
<p>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).</p>
<h4>Variables: </h4>
- <p>Make use of the <code>request_var()</code> function for anything except for submit or single checking params.</p>
- <p>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:</p>
+ <p>Make use of the <code>\phpbb\request\request</code> class for everything.</p>
+ <p>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:</p>
<p class="bad">// Old method, do not use it</p>
<div class="codebox"><pre>
$start = (isset($HTTP_GET_VARS['start'])) ? intval($HTTP_GET_VARS['start']) : intval($HTTP_POST_VARS['start']);
-$submit = (isset($HTTP_POST_VARS['submit'])) ? true : false;
- </pre></div>
+$submit = (isset($HTTP_POST_VARS['submit'])) ? true : false;</pre>
+ </div>
<p class="good">// Use request var and define a default variable (use the correct type)</p>
<div class="codebox"><pre>
-$start = request_var('start', 0);
-$submit = (isset($_POST['submit'])) ? true : false;
- </pre></div>
+$start = $request->variable('start', 0);
+$submit = $request->is_set_post('submit');</pre>
+ </div>
- <p class="bad">// $start is an int, the following use of request_var therefore is not allowed</p>
+ <p class="bad">// $start is an int, the following use of $request->variable() therefore is not allowed</p>
<div class="codebox"><pre>
-$start = request_var('start', '0');
- </pre></div>
+$start = $request->variable('start', '0');</pre>
+ </div>
<p class="good">// Getting an array, keys are integers, value defaults to 0</p>
<div class="codebox"><pre>
-$mark_array = request_var('mark', array(0));
- </pre></div>
+$mark_array = $request->variable('mark', array(0));</pre>
+ </div>
<p class="good">// Getting an array, keys are strings, value defaults to 0</p>
<div class="codebox"><pre>
-$action_ary = request_var('action', array('' =&gt; 0));
- </pre></div>
+$action_ary = $request->variable('action', array('' =&gt; 0));</pre>
+ </div>
<h4>Login checks/redirection: </h4>
<p>To show a forum login box use <code>login_forum_box($forum_data)</code>, else use the <code>login_box()</code> function.</p>
@@ -974,8 +1075,8 @@ $action_ary = request_var('action', array('' =&gt; 0));
{
trigger_error('FORM_INVALID');
}
- }
- </pre></div>
+ }</pre>
+ </div>
<p>The string passed to <code>add_form_key()</code> needs to match the string passed to <code>check_form_key()</code>. Another requirement for this to work correctly is that all forms include the <code>{S_FORM_TOKEN}</code> template variable.</p>
@@ -986,8 +1087,8 @@ $action_ary = request_var('action', array('' =&gt; 0));
<div class="codebox"><pre>
$user-&gt;session_begin();
$auth-&gt;acl($user-&gt;data);
-$user-&gt;setup();
- </pre></div>
+$user-&gt;setup();</pre>
+ </div>
<p>The <code>$user-&gt;setup()</code> call can be used to pass on additional language definition and a custom style (used in viewforum).</p>
@@ -995,16 +1096,16 @@ $user-&gt;setup();
<p>All messages/errors should be outputted by calling <code>trigger_error()</code> using the appropriate message type and language string. Example:</p>
<div class="codebox"><pre>
-trigger_error('NO_FORUM');
- </pre></div>
+trigger_error('NO_FORUM');</pre>
+ </div>
<div class="codebox"><pre>
-trigger_error($user-&gt;lang['NO_FORUM']);
- </pre></div>
+trigger_error($user-&gt;lang['NO_FORUM']);</pre>
+ </div>
<div class="codebox"><pre>
-trigger_error('NO_MODE', E_USER_ERROR);
- </pre></div>
+trigger_error('NO_MODE', E_USER_ERROR);</pre>
+ </div>
<h4>Url formatting</h4>
@@ -1013,8 +1114,8 @@ trigger_error('NO_MODE', E_USER_ERROR);
<p>The <code>append_sid()</code> function from 2.0.x is available too, though it does not handle url alterations automatically. Please have a look at the code documentation if you want to get more details on how to use append_sid(). A sample call to append_sid() can look like this:</p>
<div class="codebox"><pre>
-append_sid(&quot;{$phpbb_root_path}memberlist.$phpEx&quot;, 'mode=group&amp;amp;g=' . $row['group_id'])
- </pre></div>
+append_sid(&quot;{$phpbb_root_path}memberlist.$phpEx&quot;, 'mode=group&amp;amp;g=' . $row['group_id'])</pre>
+ </div>
<h4>General function usage: </h4>
@@ -1022,9 +1123,6 @@ append_sid(&quot;{$phpbb_root_path}memberlist.$phpEx&quot;, 'mode=group&amp;amp;
<ul>
<li>
- <p>Use <code>sizeof</code> instead of <code>count</code></p>
- </li>
- <li>
<p>Use <code>strpos</code> instead of <code>strstr</code></p>
</li>
<li>
@@ -1042,31 +1140,60 @@ append_sid(&quot;{$phpbb_root_path}memberlist.$phpEx&quot;, 'mode=group&amp;amp;
<p>Your page should either call <code>page_footer()</code> in the end to trigger output through the template engine and terminate the script, or alternatively at least call the <code>exit_handler()</code>. That call is necessary because it provides a method for external applications embedding phpBB to be called at the end of the script.</p>
+ <a name="phprestrictions"></a><h3>2.vi. Restrictions on the Use of PHP</h3>
+
+ <h4>Dynamic code execution:</h4>
+
+ <p>Never execute dynamic PHP code (generated or in a constant string) using any of the following PHP functions:</p>
+
+ <ul>
+ <li><strong>eval</strong></li>
+ <li><strong>create_function</strong></li>
+ <li><strong>preg_replace</strong> with the <strong>e</strong> modifier in the pattern</li>
+ </ul>
+
+ <p>If absolutely necessary a file should be created, and a mechanism for creating this file prior to running phpBB should be provided as a setup process.</p>
+
+ <p>The <strong>e</strong> modifier in <strong>preg_replace</strong> can be replaced by <strong>preg_replace_callback</strong> and objects to encapsulate state that is needed in the callback code.</p>
+
+ <h4>Other functions, operators, statements and keywords:</h4>
+
+ <p>The following PHP statements should also not be used in phpBB:</p>
+
+ <ul>
+ <li><strong>goto</strong></li>
+ </ul>
+
</div>
<div class="back2top"><a href="#wrap" class="top">Back to Top</a></div>
- <span class="corners-bottom"><span></span></span></div>
+ </div>
</div>
<hr />
<a name="styling"></a><h2>3. Styling</h2>
<div class="paragraph">
- <div class="inner"><span class="corners-top"><span></span></span>
+ <div class="inner">
<div class="content">
<a name="cfgfiles"></a><h3>3.i. Style Config Files</h3>
- <p>Style cfg files are simple name-value lists with the information necessary for installing a style. Similar cfg files exist for templates, themes and imagesets. These follow the same principle and will not be introduced individually. Styles can use installed components by using the required_theme/required_template/required_imageset entries. The important part of the style configuration file is assigning an unique name.</p>
- <div class="codebox"><pre>
- # General Information about this style
- name = prosilver_duplicate
- copyright = &copy; phpBB Group, 2007
- version = 3.0.3
- required_template = prosilver
- required_theme = prosilver
- required_imageset = prosilver
- </pre></div>
+ <p>Style cfg files are simple name-value lists with the information necessary for installing a style. The important part of the style configuration file is assigning an unique name.</p>
+ <div class="codebox"><pre>
+# General Information about this style
+name = prosilver_duplicate
+copyright = © phpBB Limited, 2007
+style_version = 3.1.0
+phpbb_version = 3.1.0
+
+# Defining a different template bitfield
+# template_bitfield = lNg=
+
+# Parent style
+# Set value to empty or to this style's name if this style does not have a parent style
+parent = prosilver</pre>
+ </div>
<a name="genstyling"></a><h3>3.2. General Styling Rules</h3>
<p>Templates should be produced in a consistent manner. Where appropriate they should be based off an existing copy, e.g. index, viewforum or viewtopic (the combination of which implement a range of conditional and variable forms). Please also note that the indentation and coding guidelines also apply to templates where possible.</p>
@@ -1088,7 +1215,7 @@ append_sid(&quot;{$phpbb_root_path}memberlist.$phpEx&quot;, 'mode=group&amp;amp;
<p>Row colours/classes are now defined by the template, use an <code>IF S_ROW_COUNT</code> switch, see viewtopic or viewforum for an example.</p>
-<p>Remember block level ordering is important ... while not all pages validate as XHTML 1.0 Strict compliant it is something we're trying to work on.</p>
+<p>Remember block level ordering is important.</p>
<p>Use a standard cellpadding of 2 and cellspacing of 0 on outer tables. Inner tables can vary from 0 to 3 or even 4 depending on the need.</p>
@@ -1124,14 +1251,14 @@ append_sid(&quot;{$phpbb_root_path}memberlist.$phpEx&quot;, 'mode=group&amp;amp;
<div class="back2top"><a href="#wrap" class="top">Back to Top</a></div>
- <span class="corners-bottom"><span></span></span></div>
+ </div>
</div>
<hr />
<a name="templating"></a><h2>4. Templating</h2>
<div class="paragraph">
- <div class="inner"><span class="corners-top"><span></span></span>
+ <div class="inner">
<div class="content">
<a name="templates"></a><h3>4.i. General Templating</h3>
@@ -1156,13 +1283,13 @@ append_sid(&quot;{$phpbb_root_path}memberlist.$phpEx&quot;, 'mode=group&amp;amp;
<p>A bit later loops will be explained further. To not irritate you we will explain conditionals as well as other statements first.</p>
<h4>Including files</h4>
-<p>Something that existed in 2.0.x which no longer exists in 3.0.x is the ability to assign a template to a variable. This was used (for example) to output the jumpbox. Instead (perhaps better, perhaps not but certainly more flexible) we now have INCLUDE. This takes the simple form:</p>
+<p>Something that existed in 2.0.x which no longer exists in 3.x is the ability to assign a template to a variable. This was used (for example) to output the jumpbox. Instead (perhaps better, perhaps not but certainly more flexible) we now have INCLUDE. This takes the simple form:</p>
<div class="codebox"><pre>
<span class="comment">&lt;!-- INCLUDE filename --&gt;</span>
</pre></div>
-<p>You will note in the 3.0 templates the major sources start with <code>&lt;!-- INCLUDE overall_header.html --&gt;</code> or <code>&lt;!-- INCLUDE simple_header.html --&gt;</code>, etc. In 2.0.x control of &quot;which&quot; header to use was defined entirely within the code. In 3.0.x the template designer can output what they like. Note that you can introduce new templates (i.e. other than those in the default set) using this system and include them as you wish ... perhaps useful for a common &quot;menu&quot; bar or some such. No need to modify loads of files as with 2.0.x.</p>
+<p>You will note in the 3.x templates the major sources start with <code>&lt;!-- INCLUDE overall_header.html --&gt;</code> or <code>&lt;!-- INCLUDE simple_header.html --&gt;</code>, etc. In 2.0.x control of &quot;which&quot; header to use was defined entirely within the code. In 3.x the template designer can output what they like. Note that you can introduce new templates (i.e. other than those in the default set) using this system and include them as you wish ... perhaps useful for a common &quot;menu&quot; bar or some such. No need to modify loads of files as with 2.0.x.</p>
<p>Added in <strong>3.0.6</strong> is the ability to include a file using a template variable to specify the file, this functionality only works for root variables (i.e. not block variables).</p>
<div class="codebox"><pre>
@@ -1194,7 +1321,7 @@ append_sid(&quot;{$phpbb_root_path}memberlist.$phpEx&quot;, 'mode=group&amp;amp;
<p>it will be included and executed inline.<br /><br />A note, it is very much encouraged that template designers do not include PHP. The ability to include raw PHP was introduced primarily to allow end users to include banner code, etc. without modifying multiple files (as with 2.0.x). It was not intended for general use ... hence <!-- w --><a href="https://www.phpbb.com">www.phpbb.com</a><!-- w --> will <strong>not</strong> make available template sets which include PHP. And by default templates will have PHP disabled (the admin will need to specifically activate PHP for a template).</p>
<h4>Conditionals/Control structures</h4>
-<p>The most significant addition to 3.0.x are conditions or control structures, &quot;if something then do this else do that&quot;. The system deployed is very similar to Smarty. This may confuse some people at first but it offers great potential and great flexibility with a little imagination. In their most simple form these constructs take the form:</p>
+<p>The most significant addition to 3.x are conditions or control structures, &quot;if something then do this else do that&quot;. The system deployed is very similar to Smarty. This may confuse some people at first but it offers great potential and great flexibility with a little imagination. In their most simple form these constructs take the form:</p>
<div class="codebox"><pre>
<span class="comment">&lt;!-- IF expr --&gt;</span>
@@ -1265,7 +1392,7 @@ div
<span class="comment">&lt;!-- ENDIF --&gt;</span>
</pre></div>
-<p>Each statement will be tested in turn and the relevant output generated when a match (if a match) is found. It is not necessary to always use ELSEIF, ELSE can be used alone to match &quot;everything else&quot;.<br /><br />So what can you do with all this? Well take for example the colouration of rows in viewforum. In 2.0.x row colours were predefined within the source as either row color1, row color2 or row class1, row class2. In 3.0.x this is moved to the template, it may look a little daunting at first but remember control flows from top to bottom and it's not too difficult:</p>
+<p>Each statement will be tested in turn and the relevant output generated when a match (if a match) is found. It is not necessary to always use ELSEIF, ELSE can be used alone to match &quot;everything else&quot;.<br /><br />So what can you do with all this? Well take for example the colouration of rows in viewforum. In 2.0.x row colours were predefined within the source as either row color1, row color2 or row class1, row class2. In 3.x this is moved to the template, it may look a little daunting at first but remember control flows from top to bottom and it's not too difficult:</p>
<div class="codebox"><pre>
&lt;table&gt;
@@ -1536,31 +1663,91 @@ div
&lt;/form&gt;
</pre></div><br />
- <a name="inheritance"></a><h3>4.ii. Template Inheritance</h3>
- <p>When basing a new style on an existing one, it is not necessary to provide all the template files. By declaring the base style name in the <strong>inherit_from</strong> field in the template configuration file, the style can be set to inherit template files from the base style. The limitation on this is that the base style has to be installed and complete, meaning that it is not itself inheriting.</p>
+ <a name="stylestree"></a><h3>4.ii. Styles Tree</h3>
+ <p>When basing a new style on an existing one, it is not necessary to provide all the template files. By declaring the base style name in the <strong>parent</strong> field in the style configuration file, the style can be set to reuse template files from the parent style.</p>
- <p>The effect of doing so is that the template engine will use the template files in the new style where they exist, but fall back to files in the base style otherwise. Declaring a style to inherit from another also causes it to use some of the configuration settings of the base style, notably database storage.</p>
+ <p>The effect of doing so is that the template engine will use the template files in the new style where they exist, but fall back to files in the parent style otherwise.</p>
- <p>We strongly encourage the use of inheritance for styles based on the bundled styles, as it will ease the update procedure.</p>
+ <p>We strongly encourage the use of parent styles for styles based on the bundled styles, as it will ease the update procedure.</p>
<div class="codebox"><pre>
- # General Information about this template
- name = inherits
- copyright = &copy; phpBB Group, 2007
- version = 3.0.3
-
- # Defining a different template bitfield
- template_bitfield = lNg=
-
- # Are we inheriting?
- inherit_from = prosilver
+# General Information about this style
+name = Custom Style
+copyright = © phpBB Limited, 2007
+style_version = 3.1.0-b1
+phpbb_version = 3.1.0-b1
+
+# Defining a different template bitfield
+# template_bitfield = lNg=
+
+# Parent style
+# Set value to empty or to this style's name if this style does not have a parent style
+parent = prosilver
</pre></div>
+ <a name="template-events"></a><h3>4.iii. Template Events</h3>
+ <p>Template events must follow this format: <code>&lt;!-- EVENT event_name --&gt;</code></p>
+ <p>Using the above example, files named <code>event_name.html</code> located within extensions will be injected into the location of the event.</p>
+
+ <h4>Template event naming guidelines:</h4>
+ <ul>
+ <li>An event name must be all lowercase, with each word separated by an underscore.</li>
+ <li>An event name must briefly describe the location and purpose of the event.</li>
+ <li>
+ An event name must end with one of the following suffixes:
+ <ul>
+ <li><code>_prepend</code> - 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.</li>
+ <li><code>_append</code> - 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.</li>
+ <li><code>_before</code> - This event adds content directly before the specified block</li>
+ <li><code>_after</code> - This event adds content directly after the specified block</li>
+ </ul>
+ </li>
+ </ul>
+
+ <h4>Template event documentation</h4>
+ <p>Events must be documented in <code>phpBB/docs/events.md</code> in alphabetical order based on the event name. The format is as follows:</p>
+
+ <ul><li>An event found in only one template file:
+ <div class="codebox"><pre>event_name
+===
+* Location: styles/&lt;style_name&gt;/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
+</pre></div></li>
+ <li>An event found in multiple template files:
+ <div class="codebox"><pre>event_name
+===
+* Locations:
+ + first/file/path.html
+ + second/file/path.html
+* Purpose: Same as above.
+* Since: 3.1.0-b1
+</pre></div>
+ <li>An event that is found multiple times in a file should have the number of instances in parenthesis next to the filename.
+ <div class="codebox"><pre>event_name
+===
+* Locations:
+ + first/file/path.html (2)
+ + second/file/path.html
+* Purpose: Same as above.
+* Since: 3.1.0-b1
+</pre></div></li>
+ <li>An actual example event documentation:
+ <div class="codebox"><pre>forumlist_body_last_post_title_prepend
+====
+* 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.
+* Since: 3.1.0-a1
+</pre></div></ul><br />
+
</div>
<div class="back2top"><a href="#wrap" class="top">Back to Top</a></div>
- <span class="corners-bottom"><span></span></span></div>
+ </div>
</div>
<hr />
@@ -1570,7 +1757,7 @@ div
<a name="charsets"></a><h2>5. Character Sets and Encodings</h2>
<div class="paragraph">
- <div class="inner"><span class="corners-top"><span></span></span>
+ <div class="inner">
<div class="content">
@@ -1584,16 +1771,16 @@ div
<p>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 <code>utf8_recode()</code> function supplied with phpBB. It supports a variety of other character sets and encodings, a full list can be found below.</p>
-<p>With <code>request_var()</code> 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 <code>$multibyte</code>. You should allow multibyte characters in posts, PMs, topic titles, forum names, etc. but it's not necessary for internal uses like a <code>$mode</code> variable which should only hold a predefined list of ASCII strings anyway.</p>
+<p>With <code>$request->variable()</code> 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 <code>$multibyte</code>. You should allow multibyte characters in posts, PMs, topic titles, forum names, etc. but it's not necessary for internal uses like a <code>$mode</code> variable which should only hold a predefined list of ASCII strings anyway.</p>
<div class="codebox"><pre>
// an input string containing a multibyte character
$_REQUEST['multibyte_string'] = 'K&#228;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', '');
</pre></div>
<p>This code snippet will generate the following output:</p>
@@ -1603,19 +1790,6 @@ K&#228;se
K??se
</pre></div>
-<h4>Unicode Normalization</h4>
-
-<p>If you retrieve user input with multibyte characters you should additionally normalize the string using <code>utf8_normalize_nfc()</code> 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 &#197; can be represented either as <code>U+00C5</code> (LATIN CAPITAL LETTER A WITH RING ABOVE) or as <code>U+212B</code> (ANGSTROM SIGN). phpBB uses Normalization Form Canonical Composition (NFC) for all text. So the correct version of the above example would look like this:</p>
-
-<div class="codebox"><pre>
-$_REQUEST['multibyte_string'] = 'K&#228;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', '');
-</pre></div>
-
<h4>Case Folding</h4>
<p>Case insensitive comparison of strings is no longer possible with <code>strtolower</code> or <code>strtoupper</code> as some characters have multiple lower case or multiple upper case forms depending on their position in a word. The <code>utf8_strtolower</code> and the <code>utf8_strtoupper</code> 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 <code>utf8_case_fold_nfc()</code>.</p>
@@ -1646,7 +1820,7 @@ if (utf8_case_fold_nfc($string1) == utf8_case_fold_nfc($string2))
<div class="back2top"><a href="#wrap" class="top">Back to Top</a></div>
- <span class="corners-bottom"><span></span></span></div>
+ </div>
</div>
<hr />
@@ -1654,7 +1828,7 @@ if (utf8_case_fold_nfc($string1) == utf8_case_fold_nfc($string2))
<a name="translation"></a><h2>6. Translation (<abbr title="Internationalisation">i18n</abbr>/<abbr title="Localisation">L10n</abbr>) Guidelines</h2>
<div class="paragraph">
- <div class="inner"><span class="corners-top"><span></span></span>
+ <div class="inner">
<div class="content">
@@ -1668,7 +1842,7 @@ if (utf8_case_fold_nfc($string1) == utf8_case_fold_nfc($string2))
<p>With phpBB3, the output encoding for the forum in now UTF-8, a Universal Character Encoding by the Unicode Consortium that is by design a superset to US-ASCII and ISO-8859-1. By using one character set which simultaenously supports all scripts which previously would have required different encodings (eg: ISO-8859-1 to ISO-8859-15 (Latin, Greek, Cyrillic, Thai, Hebrew, Arabic); GB2312 (Simplified Chinese); Big5 (Traditional Chinese), EUC-JP (Japanese), EUC-KR (Korean), VISCII (Vietnamese); et cetera), we remove the need to convert between encodings and improves the accessibility of multilingual forums.</p>
- <p>The impact is that the language files for phpBB must now also be encoded as UTF-8, with a caveat that the files must <strong>not contain</strong> a <acronym title="Byte-Order-Mark">BOM</acronym> for compatibility reasons with non-Unicode aware versions of PHP. For those with forums using the Latin character set (ie: most European languages), this change is transparent since UTF-8 is superset to US-ASCII and ISO-8859-1.</p>
+ <p>The impact is that the language files for phpBB must now also be encoded as UTF-8, with a caveat that the files must <strong>not contain</strong> a <abbr title="Byte-Order-Mark">BOM</abbr> for compatibility reasons with non-Unicode aware versions of PHP. For those with forums using the Latin character set (ie: most European languages), this change is transparent since UTF-8 is superset to US-ASCII and ISO-8859-1.</p>
<h4>Language Tag:</h4>
@@ -1678,8 +1852,8 @@ if (utf8_case_fold_nfc($string1) == utf8_case_fold_nfc($string2))
<p>Most language tags consist of a two- or three-letter language subtag (from <a href="http://www.loc.gov/standards/iso639-2/php/English_list.php">ISO 639-1/ISO 639-2</a>). Sometimes, this is followed by a two-letter or three-digit region subtag (from <a href="http://www.iso.ch/iso/en/prods-services/iso3166ma/02iso-3166-code-lists/list-en1.html">ISO 3166-1 alpha-2</a> or <a href="http://unstats.un.org/unsd/methods/m49/m49.htm">UN M.49</a>). Some examples are:</p>
- <table summary="Examples of various possible language tags as described by RFC 4646 and RFC 4647">
- <caption>Language tag examples</caption>
+ <table>
+ <caption>Examples of various possible language tags as described by RFC 4646 and RFC 4647</caption>
<thead>
<tr>
<th scope="col">Language tag</th>
@@ -1730,8 +1904,8 @@ if (utf8_case_fold_nfc($string1) == utf8_case_fold_nfc($string2))
<p>Next is the <a href="http://www.unicode.org/iso15924/iso15924-codes.html">ISO 15924</a> language script code and when one should or shouldn't use it. For example, whilst <code>en-Latn</code> is syntaxically correct for describing English written with Latin script, real world English writing is <strong>more-or-less exclusively in the Latin script</strong>. For such languages like English that are written in a single script, the <a href="http://www.iana.org/assignments/language-subtag-registry"><abbr title="Internet Assigned Numbers Authority">IANA</abbr> Language Subtag Registry</a> has a "Suppress-Script" field meaning the script code <strong>should be ommitted</strong> unless a specific language tag requires a specific script code. Some languages are <strong>written in more than one script</strong> and in such cases, the script code <strong>is encouraged</strong> since an end-user may be able to read their language in one script, but not the other. Some examples are:</p>
- <table summary="Examples of using a language subtag in combination with a script subtag">
- <caption>Language subtag + script subtag examples</caption>
+ <table>
+ <caption>Examples of using a language subtag in combination with a script subtag</caption>
<thead>
<tr>
<th scope="col">Language tag</th>
@@ -1797,8 +1971,8 @@ if (utf8_case_fold_nfc($string1) == utf8_case_fold_nfc($string2))
<p>Examples of English using marco-geographical regions:</p>
- <table summary="Examples for English of ISO 3166-1 alpha-2 vs. UN M.49 code">
- <caption>Coding for English using macro-geographical regions</caption>
+ <table>
+ <caption>Coding for English using macro-geographical regions (examples for English of ISO 3166-1 alpha-2 vs. UN M.49 code)</caption>
<thead>
<tr>
<th scope="col">ISO 639-1/ISO 639-2 + ISO 3166-1 alpha-2</th>
@@ -1823,8 +1997,8 @@ if (utf8_case_fold_nfc($string1) == utf8_case_fold_nfc($string2))
<p>Examples of Spanish using marco-geographical regions:</p>
- <table summary="Examples for Spanish of ISO 3166-1 alpha-2 vs. UN M.49 code">
- <caption>Coding for Spanish macro-geographical regions</caption>
+ <table>
+ <caption>Coding for Spanish macro-geographical regions (examples for Spanish of ISO 3166-1 alpha-2 vs. UN M.49 code)</caption>
<thead>
<tr>
<th scope="col">ISO 639-1/ISO 639-2 + ISO 3166-1 alpha-2</th>
@@ -1852,7 +2026,7 @@ if (utf8_case_fold_nfc($string1) == utf8_case_fold_nfc($string2))
<p>Example of where the <a href="http://www.iso.ch/iso/en/prods-services/iso3166ma/02iso-3166-code-lists/list-en1.html">ISO 3166-1 alpha-2</a> is ambiguous and why <a href="http://unstats.un.org/unsd/methods/m49/m49.htm">UN M.49</a> might be preferred:</p>
- <table summary="Example where the ISO 3166-1 alpha-2 is ambiguous">
+ <table>
<caption>Coding for ambiguous ISO 3166-1 alpha-2 regions</caption>
<thead>
<tr>
@@ -1908,7 +2082,7 @@ if (utf8_case_fold_nfc($string1) == utf8_case_fold_nfc($string2))
<p><a href="http://tools.ietf.org/html/rfc4646">RFC 4646</a> anticipates features which shall be available in (currently draft) <a href="http://www.sil.org/iso639-3/">ISO 639-3</a> which aims to provide as complete enumeration of languages as possible, including living, extinct, ancient and constructed languages, whether majour, minor or unwritten. A new feature of <a href="http://www.sil.org/iso639-3/">ISO 639-3</a> compared to the previous two revisions is the concept of <a href="http://www.sil.org/iso639-3/macrolanguages.asp">macrolanguages</a> where Arabic and Chinese are two such examples. In such cases, their respective codes of <code>ar</code> and <code>zh</code> is very vague as to which dialect/topolect is used or perhaps some terse classical variant which may be difficult for all but very educated users. For such macrolanguages, it is recommended that the sub-language tag is used as a suffix to the macrolanguage tag, eg:</p>
- <table summary="Examples of macrolanguages used with sub-language subtags">
+ <table>
<caption>Macrolanguage subtag + sub-language subtag examples</caption>
<thead>
<tr>
@@ -1952,7 +2126,7 @@ if (utf8_case_fold_nfc($string1) == utf8_case_fold_nfc($string2))
<p>For phpBB, the language tags are <strong>not</strong> used in their raw form and instead converted to all lower-case and have the hyphen <code>-</code> replaced with an underscore <code>_</code> where appropriate, with some examples below:</p>
- <table summary="Normalisation of language tags for usage in phpBB">
+ <table>
<caption>Language tag normalisation examples</caption>
<thead>
<tr>
@@ -2006,7 +2180,7 @@ if (utf8_case_fold_nfc($string1) == utf8_case_fold_nfc($string2))
<p>For the English language description, the language name is always first and any additional attributes required to describe the subtags within the language code are then listed in order separated with commas and enclosed within parentheses, eg:</p>
- <table summary="English language description examples of iso.txt for usage in phpBB">
+ <table>
<caption>English language description examples for iso.txt</caption>
<thead>
<tr>
@@ -2058,7 +2232,7 @@ if (utf8_case_fold_nfc($string1) == utf8_case_fold_nfc($string2))
<p>The various Unicode control characters for bi-directional text and their HTML enquivalents where appropriate are as follows:</p>
- <table summary="Table of the various Unicode bidirectional control characters">
+ <table>
<caption>Unicode bidirectional control characters &amp; HTML elements/entities</caption>
<thead>
<tr>
@@ -2124,7 +2298,7 @@ if (utf8_case_fold_nfc($string1) == utf8_case_fold_nfc($string2))
<p>For <code>iso.txt</code>, the directionality of the text can be explicitly set using special Unicode characters via any of the three methods provided by left-to-right/right-to-left markers/embeds/overrides, as without them, the ordering of characters will be incorrect, eg:</p>
- <table summary="Effect of using Unicode bidirectional control characters within iso.txt">
+ <table>
<caption>Unicode bidirectional control characters iso.txt</caption>
<thead>
<tr>
@@ -2172,7 +2346,7 @@ if (utf8_case_fold_nfc($string1) == utf8_case_fold_nfc($string2))
<p>Within some cases, there may be mixed scripts of a left-to-right and right-to-left direction, so using <code>LRE</code> &amp; <code>RLE</code> with <code>PDF</code> may be more appropriate. Lastly, in very rare instances where directionality must be forced, then use <code>LRO</code> &amp; <code>RLO</code> with <code>PDF</code>.</p>
<p>For further information on authoring techniques of bi-directional text, please see the W3C tutorial on <a href="http://www.w3.org/International/tutorials/bidi-xhtml/">authoring techniques for XHTML pages with bi-directional text</a>.</p>
- <h4>Working with placeholders:</h4>
+ <a name="placeholders"></a><h3>6.iii. Working with placeholders</h3>
<p>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 &quot;Page <em>X</em> of <em>Y</em>&quot;, whilst in English this could just be coded as:</p>
@@ -2181,8 +2355,8 @@ if (utf8_case_fold_nfc($string1) == utf8_case_fold_nfc($string2))
'PAGE_OF' =&gt; 'Page %s of %s',
/* Just grabbing the replacements as they
come and hope they are in the right order */
- ...
- </pre></div>
+ ...</pre>
+ </div>
<p>&hellip; a clearer way to show explicit replacement ordering is to do:</p>
@@ -2191,8 +2365,8 @@ if (utf8_case_fold_nfc($string1) == utf8_case_fold_nfc($string2))
'PAGE_OF' =&gt; 'Page %1$s of %2$s',
/* Explicit ordering of the replacements,
even if they are the same order as English */
- ...
- </pre></div>
+ ...</pre>
+ </div>
<p>Why bother at all? Because some languages, the string transliterated back to English might read something like:</p>
@@ -2201,10 +2375,62 @@ if (utf8_case_fold_nfc($string1) == utf8_case_fold_nfc($string2))
'PAGE_OF' =&gt; 'Total of %2$s pages, currently on page %1$s',
/* Explicit ordering of the replacements,
reversed compared to English as the total comes first */
+ ...</pre>
+ </div>
+
+ <a name="usingplurals"></a><h3>6.iv. Using plurals</h3>
+
+ <p>
+ The english language is very simple when it comes to plurals.<br />
+ You have <code>0 elephants</code>, <code>1 elephant</code>, or <code>2+ elephants</code>. So basically you have 2 different forms: one singular and one plural.<br />
+ But for some other languages this is quite more difficult. Let's take the Bosnian language as another example:<br />
+ You have <code>[1/21/31] slon</code>, <code>[2/3/4] slona</code>, <code>[0/5/6] slonova</code> and <code>[7/8/9/11] ...</code> and some more difficult rules.
+ </p>
+
+ <p>The <a href="https://wiki.phpbb.com/Plural_Rules">plural system</a> takes care of this and can be used as follows:</p>
+
+ <p>The PHP code will basically look like this:</p>
+
+ <div class="codebox"><pre>
+ ...
+ $user->lang('NUMBER_OF_ELEPHANTS', $number_of_elephants);
+ ...</pre>
+ </div>
+
+ <p>And the English translation would be:</p>
+
+ <div class="codebox"><pre>
+ ...
+ '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
+ ),
+ ...</pre>
+ </div>
+
+ <p>While the Bosnian translation can have more cases:</p>
+
+ <div class="codebox"><pre>
...
- </pre></div>
+ '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 => ...
+ ),
+ ...</pre>
+ </div>
- <a name="writingstyle"></a><h3>6.iii. Writing Style</h3>
+ <p><strong>NOTE:</strong> It is okay to use plurals for an unknown number compared to a single item, when the number is not known and displayed:</p>
+ <div class="codebox"><pre>
+ ...
+ 'MODERATOR' => 'Moderator', // Your board has 1 moderator
+ 'MODERATORS' => 'Moderators', // Your board has multiple moderators
+ ...</pre>
+ </div>
+
+ <a name="writingstyle"></a><h3>6.v. Writing Style</h3>
<h4>Miscellaneous tips &amp; hints:</h4>
@@ -2216,8 +2442,8 @@ if (utf8_case_fold_nfc($string1) == utf8_case_fold_nfc($string2))
...
'CONV_ERROR_NO_AVATAR_PATH'
=&gt; 'Note to developer: you must specify $convertor['avatar_path'] to use %s.',
- ...
- </pre></div>
+ ...</pre>
+ </div>
<p class="good">// Good - Literal straight quotes should be escaped with a backslash, ie: \</p>
@@ -2225,8 +2451,8 @@ if (utf8_case_fold_nfc($string1) == utf8_case_fold_nfc($string2))
...
'CONV_ERROR_NO_AVATAR_PATH'
=&gt; 'Note to developer: you must specify $convertor[\'avatar_path\'] to use %s.',
- ...
- </pre></div>
+ ...</pre>
+ </div>
<p>However, because phpBB3 now uses UTF-8 as its sole encoding, we can actually use this to our advantage and not have to remember to escape a straight quote when we don't have to:</p>
@@ -2235,24 +2461,24 @@ if (utf8_case_fold_nfc($string1) == utf8_case_fold_nfc($string2))
<div class="codebox"><pre>
...
'USE_PERMISSIONS' =&gt; 'Test out user's permissions',
- ...
- </pre></div>
+ ...</pre>
+ </div>
<p class="good">// Okay - However, non-programmers wouldn't type "user\'s" automatically</p>
<div class="codebox"><pre>
...
'USE_PERMISSIONS' =&gt; 'Test out user\'s permissions',
- ...
- </pre></div>
+ ...</pre>
+ </div>
<p class="good">// Best - Use the Unicode Right-Single-Quotation-Mark character</p>
<div class="codebox"><pre>
...
'USE_PERMISSIONS' =&gt; 'Test out user&rsquo;s permissions',
- ...
- </pre></div>
+ ...</pre>
+ </div>
<p>The <code>&quot;</code> (straight double quote), <code>&lt;</code> (less-than sign) and <code>&gt;</code> (greater-than sign) characters can all be used as displayed glyphs or as part of HTML markup, for example:</p>
@@ -2260,28 +2486,28 @@ if (utf8_case_fold_nfc($string1) == utf8_case_fold_nfc($string2))
<div class="codebox"><pre>
...
-'FOO_BAR' =&gt; 'PHP version &lt; 4.3.3.&lt;br /&gt;
+'FOO_BAR' =&gt; 'PHP version &lt; 5.3.3.&lt;br /&gt;
Visit &quot;Downloads&quot; at &lt;a href=&quot;http://www.php.net/&quot;&gt;www.php.net&lt;/a&gt;.',
- ...
- </pre></div>
+ ...</pre>
+ </div>
<p class="good">// Okay - No more invalid HTML, but &quot;&amp;quot;&quot; is rather clumsy</p>
<div class="codebox"><pre>
...
-'FOO_BAR' =&gt; 'PHP version &amp;lt; 4.3.3.&lt;br /&gt;
+'FOO_BAR' =&gt; 'PHP version &amp;lt; 5.3.3.&lt;br /&gt;
Visit &amp;quot;Downloads&amp;quot; at &lt;a href=&quot;http://www.php.net/&quot;&gt;www.php.net&lt;/a&gt;.',
- ...
- </pre></div>
+ ...</pre>
+ </div>
<p class="good">// Best - No more invalid HTML, and usage of correct typographical quotation marks</p>
<div class="codebox"><pre>
...
-'FOO_BAR' =&gt; 'PHP version &amp;lt; 4.3.3.&lt;br /&gt;
+'FOO_BAR' =&gt; 'PHP version &amp;lt; 5.3.3.&lt;br /&gt;
Visit &ldquo;Downloads&rdquo; at &lt;a href=&quot;http://www.php.net/&quot;&gt;www.php.net&lt;/a&gt;.',
- ...
- </pre></div>
+ ...</pre>
+ </div>
<p>Lastly, the <code>&amp;</code> (ampersand) must always be entitised regardless of where it is used:</p>
@@ -2290,16 +2516,16 @@ if (utf8_case_fold_nfc($string1) == utf8_case_fold_nfc($string2))
<div class="codebox"><pre>
...
'FOO_BAR' =&gt; '&lt;a href=&quot;http://somedomain.tld/?foo=1&amp;bar=2&quot;&gt;Foo &amp; Bar&lt;/a&gt;.',
- ...
- </pre></div>
+ ...</pre>
+ </div>
<p class="good">// Good - Valid HTML, amperands are correctly entitised in all cases</p>
<div class="codebox"><pre>
...
'FOO_BAR' =&gt; '&lt;a href=&quot;http://somedomain.tld/?foo=1&amp;amp;bar=2&quot;&gt;Foo &amp;amp; Bar&lt;/a&gt;.',
- ...
- </pre></div>
+ ...</pre>
+ </div>
<p>As for how these charcters are entered depends very much on choice of Operating System, current language locale/keyboard configuration and native abilities of the text editor used to edit phpBB language files. Please see <a href="http://en.wikipedia.org/wiki/Unicode#Input_methods">http://en.wikipedia.org/wiki/Unicode#Input_methods</a> for more information.</p>
@@ -2311,7 +2537,7 @@ if (utf8_case_fold_nfc($string1) == utf8_case_fold_nfc($string2))
<div class="back2top"><a href="#wrap" class="top">Back to Top</a></div>
- <span class="corners-bottom"><span></span></span></div>
+ </div>
</div>
<hr />
@@ -2319,17 +2545,17 @@ if (utf8_case_fold_nfc($string1) == utf8_case_fold_nfc($string2))
<a name="disclaimer"></a><h2>7. Copyright and disclaimer</h2>
<div class="paragraph">
- <div class="inner"><span class="corners-top"><span></span></span>
+ <div class="inner">
<div class="content">
- <p>This application is opensource software released under the <a href="http://opensource.org/licenses/gpl-2.0.php">GNU General Public License v2</a>. Please see source code and the docs directory for more details. This package and its contents are Copyright (c) <a href="https://www.phpbb.com/">phpBB Group</a>, All Rights Reserved.</p>
+ <p>phpBB is free software, released under the terms of the <a href="http://opensource.org/licenses/gpl-2.0.php">GNU General Public License, version 2 (GPL-2.0)</a>. Copyright © <a href="https://www.phpbb.com">phpBB Limited</a>. For full copyright and license information, please see the docs/CREDITS.txt file.</p>
</div>
<div class="back2top"><a href="#wrap" class="top">Back to Top</a></div>
- <span class="corners-bottom"><span></span></span></div>
+ </div>
</div>
<!-- END DOCUMENT -->
@@ -2340,7 +2566,7 @@ if (utf8_case_fold_nfc($string1) == utf8_case_fold_nfc($string2))
</div></div>
<div>
- <a id="bottom" name="bottom" accesskey="z"></a>
+ <a id="bottom" accesskey="z"></a>
</div>
</body>