Verzeichnisstruktur phpBB-3.1.0


Veröffentlicht
27.10.2014

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

(Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

coding-guidelines.html

Zuletzt modifiziert: 09.10.2024, 12:51 - Dateigröße: 111.78 KiB


0001  <!DOCTYPE html>
0002  <html dir="ltr" lang="en">
0003  <head>
0004  <meta charset="utf-8">
0005  <meta name="keywords" content="" />
0006  <meta name="description" content="Ascraeus coding guidelines document" />
0007  <title>phpBB3 &bull; Coding Guidelines</title>
0008   
0009  <link href="stylesheet.css" rel="stylesheet" type="text/css" media="screen, projection" />
0010   
0011  </head>
0012   
0013  <body id="phpbb" class="section-docs">
0014   
0015  <div id="wrap">
0016      <a id="top" name="top" accesskey="t"></a>
0017      <div id="page-header">
0018          <div class="headerbar">
0019              <div class="inner"><span class="corners-top"><span></span></span>
0020   
0021              <div id="doc-description">
0022                  <a href="../index.php" id="logo"><img src="site_logo.gif" alt="" /></a>
0023                  <h1>Coding Guidelines</h1>
0024                  <p>Ascraeus coding guidelines document</p>
0025                  <p style="display: none;"><a href="#start_here">Skip</a></p>
0026              </div>
0027   
0028              <span class="corners-bottom"><span></span></span></div>
0029          </div>
0030      </div>
0031   
0032      <a name="start_here"></a>
0033   
0034      <div id="page-body">
0035   
0036  <!-- BEGIN DOCUMENT -->
0037   
0038  <p>These are the phpBB Coding Guidelines for Ascraeus, all attempts should be made to follow them as closely as possible.</p>
0039   
0040  <h1>Coding Guidelines</h1>
0041   
0042      <div class="paragraph menu">
0043          <div class="inner"><span class="corners-top"><span></span></span>
0044   
0045          <div class="content">
0046   
0047  <ol>
0048      <li><a href="#defaults">Defaults</a>
0049      <ol style="list-style-type: lower-roman;">
0050          <li><a href="#editorsettings">Editor Settings</a></li>
0051          <li><a href="#fileheader">File Header</a></li>
0052          <li><a href="#locations">File Locations</a></li>
0053          <li><a href="#constants">Special Constants</a></li>
0054      </ol>
0055      </li>
0056      <li><a href="#code">Code Layout/Guidelines</a>
0057      <ol style="list-style-type: lower-roman;">
0058          <li><a href="#namingvars">Variable/Function/Class Naming</a></li>
0059          <li><a href="#codelayout">Code Layout</a></li>
0060          <li><a href="#sql">SQL/SQL Layout</a></li>
0061          <li><a href="#optimizing">Optimizations</a></li>
0062          <li><a href="#general">General Guidelines</a></li>
0063          <li><a href="#phprestrictions">Restrictions on the Use of PHP</a></li>
0064      </ol>
0065      </li>
0066      <li><a href="#styling">Styling</a>
0067      <ol style="list-style-type: lower-roman;">
0068          <li><a href="#cfgfiles">Style Config Files</a></li>
0069          <li><a href="#genstyling">General Styling Rules</a></li>
0070      </ol></li>
0071      <li><a href="#templating">Templating</a>
0072      <ol style="list-style-type: lower-roman;">
0073          <li><a href="#templates">General Templating</a></li>
0074          <li><a href="#stylestree">Styles Tree</a></li>
0075          <li><a href="#template-events">Template Events</a></li>
0076      </ol></li>
0077      <li><a href="#charsets">Character Sets and Encodings</a></li>
0078      <li><a href="#translation">Translation (<abbr title="Internationalisation">i18n</abbr>/<abbr title="Localisation">L10n</abbr>) Guidelines</a>
0079      <ol style="list-style-type: lower-roman;">
0080          <li><a href="#standardisation">Standardisation</a></li>
0081          <li><a href="#otherconsiderations">Other considerations</a></li>
0082          <li><a href="#placeholders">Working with placeholders</a></li>
0083          <li><a href="#usingplurals">Using plurals</a></li>
0084          <li><a href="#writingstyle">Writing Style</a></li>
0085      </ol>
0086      </li>
0087      <li><a href="#disclaimer">Copyright and disclaimer</a></li>
0088  </ol>
0089   
0090          </div>
0091   
0092          <span class="corners-bottom"><span></span></span></div>
0093      </div>
0094   
0095      <hr />
0096   
0097  <a name="defaults"></a><h2>1. Defaults</h2>
0098   
0099      <div class="paragraph">
0100          <div class="inner"><span class="corners-top"><span></span></span>
0101   
0102          <div class="content">
0103   
0104  <a name="editorsettings"></a><h3>1.i. Editor Settings</h3>
0105   
0106      <h4>Tabs vs Spaces:</h4>
0107      <p>In order to make this as simple as possible, we will be using tabs, not spaces. We enforce 4 (four) spaces for one tab - therefore you need to set your tab width within your editor to 4 spaces. Make sure that when you <strong>save</strong> the file, it's saving tabs and not spaces. This way, we can each have the code be displayed the way we like it, without breaking the layout of the actual files.</p>
0108      <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>
0109   
0110      <div class="codebox"><pre>
0111  {TAB}$mode{TAB}{TAB}= $request->variable('mode', '');
0112  {TAB}$search_id{TAB}= $request->variable('search_id', '');
0113      </pre></div>
0114   
0115      <p>If entered with tabs (replace the {TAB}) both equal signs need to be on the same column.</p>
0116   
0117      <h3>Linefeeds:</h3>
0118      <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>
0119   
0120      <a name="fileheader"></a><h3>1.ii. File Layout</h3>
0121   
0122      <h4>Standard header for new files:</h4>
0123      <p>This template of the header must be included at the start of all phpBB files: </p>
0124   
0125      <div class="codebox"><pre>
0126  /**
0127  *
0128  * This file is part of the phpBB Forum Software package.
0129  *
0130  * @copyright (c) phpBB Limited &lt;https://www.phpbb.com&gt;
0131  * @license GNU General Public License, version 2 (GPL-2.0)
0132  *
0133  * For full copyright and license information, please see
0134  * the docs/CREDITS.txt file.
0135  *
0136  */
0137      </pre></div>
0138   
0139      <p>Please see the <a href="#locations">File Locations section</a> for the correct package name.</p>
0140   
0141      <h4>PHP closing tags</h4>
0142   
0143      <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>
0144   
0145      <h4>Newline at end of file</h4>
0146   
0147      <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>
0148   
0149      <h4>Files containing inline code:</h4>
0150   
0151      <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>
0152   
0153      <div class="codebox"><pre>
0154  /**
0155  * {HEADER}
0156  */
0157   
0158  /**
0159  */
0160  {CODE}
0161      </pre></div>
0162   
0163      <h4>Files containing only functions:</h4>
0164   
0165      <p>Do not forget to comment the functions (especially the first function following the header). Each function should have at least a comment of what this function does. For more complex functions it is recommended to document the parameters too.</p>
0166   
0167      <h4>Files containing only classes:</h4>
0168   
0169      <p>Do not forget to comment the class. Classes need a separate @package definition, it is the same as the header package name. Apart from this special case the above statement for files containing only functions needs to be applied to classes and it's methods too.</p>
0170   
0171      <h4>Code following the header but only functions/classes file:</h4>
0172   
0173      <p>If this case is true, the best method to avoid documentation confusions is adding an ignore command, for example:</p>
0174   
0175      <div class="codebox"><pre>
0176  /**
0177  * {HEADER}
0178  */
0179   
0180  /**
0181  * @ignore
0182  */
0183  Small code snipped, mostly one or two defines or an if statement
0184   
0185  /**
0186  * {DOCUMENTATION}
0187  */
0188  class ...
0189      </pre></div>
0190   
0191      <a name="locations"></a><h3>1.iii. File Locations</h3>
0192   
0193      <p>Functions used by more than one page should be placed in functions.php, functions specific to one page should be placed on that page (at the bottom) or within the relevant sections functions file. Some files in <code>/includes</code> are holding functions responsible for special sections, for example uploading files, displaying &quot;things&quot;, user related functions and so forth.</p>
0194   
0195      <p>The following packages are defined, and related new features/functions should be placed within the mentioned files/locations, as well as specifying the correct package name. The package names are bold within this list:</p>
0196   
0197      <ul>
0198          <li><strong>phpBB3</strong><br />Core files and all files not assigned to a separate package</li>
0199          <li><strong>acm</strong><br /><code>/phpbb/cache</code><br />Cache System</li>
0200          <li><strong>acp</strong><br /><code>/adm</code>, <code>/includes/acp</code>, <code>/includes/functions_admin.php</code><br />Administration Control Panel</li>
0201          <li><strong>dbal</strong><br /><code>/phpbb/db</code>, <code>/includes/db</code><br />Database Abstraction Layer.
0202              <ul>
0203                  <li><code>/phpbb/db/driver/</code><br />Database Abstraction Layer classes</li>
0204                  <li><code>/phpbb/db/migration/</code><br />Migrations are used for updating the database from one release to another</li>
0205              </ul>
0206          </li>
0207          <li><strong>diff</strong><br /><code>/includes/diff</code><br />Diff Engine</li>
0208          <li><strong>docs</strong><br /><code>/docs</code><br />phpBB Documentation</li>
0209          <li><strong>images</strong><br /><code>/images</code><br />All global images not connected to styles</li>
0210          <li><strong>install</strong><br /><code>/install</code><br />Installation System</li>
0211          <li><strong>language</strong><br /><code>/language</code><br />All language files</li>
0212          <li><strong>login</strong><br /><code>/phpbb/auth</code><br />Login Authentication Plugins</li>
0213          <li><strong>VC</strong><br /><code>/includes/captcha</code><br />CAPTCHA</li>
0214          <li><strong>mcp</strong><br /><code>mcp.php</code>, <code>/includes/mcp</code>, <code>report.php</code><br />Moderator Control Panel</li>
0215          <li><strong>ucp</strong><br /><code>ucp.php</code>, <code>/includes/ucp</code><br />User Control Panel</li>
0216          <li><strong>utf</strong><br /><code>/includes/utf</code><br />UTF8-related functions/classes</li>
0217          <li><strong>search</strong><br /><code>/phpbb/search</code>, <code>search.php</code><br />Search System</li>
0218          <li><strong>styles</strong><br /><code>/styles</code><br />phpBB Styles/Templates/Themes</li>
0219      </ul>
0220   
0221      <a name="constants"></a><h3>1.iv. Special Constants</h3>
0222   
0223      <p>There are some special constants application developers are able to utilize to bend some of phpBB's internal functionality to suit their needs.</p>
0224   
0225      <div class="codebox"><pre>
0226  PHPBB_MSG_HANDLER          (overwrite message handler)
0227  PHPBB_DB_NEW_LINK          (overwrite new_link parameter for sql_connect)
0228  PHPBB_ROOT_PATH            (overwrite $phpbb_root_path)
0229  PHPBB_ADMIN_PATH           (overwrite $phpbb_admin_path)
0230  PHPBB_USE_BOARD_URL_PATH   (use generate_board_url() for image paths instead of $phpbb_root_path)
0231  PHPBB_DISABLE_ACP_EDITOR   (disable ACP style editor for templates)
0232  PHPBB_DISABLE_CONFIG_CHECK (disable ACP config.php writeable check)
0233   
0234  PHPBB_ACM_MEMCACHE_PORT     (overwrite memcached port, default is 11211)
0235  PHPBB_ACM_MEMCACHE_COMPRESS (overwrite memcached compress setting, default is disabled)
0236  PHPBB_ACM_MEMCACHE_HOST     (overwrite memcached host name, default is localhost)
0237   
0238  PHPBB_ACM_REDIS_HOST        (overwrite redis host name, default is localhost)
0239  PHPBB_ACM_REDIS_PORT        (overwrite redis port, default is 6379)
0240  PHPBB_ACM_REDIS_PASSWORD    (overwrite redis password, default is empty)
0241  PHPBB_ACM_REDIS_DB          (overwrite redis default database)
0242   
0243  PHPBB_QA                   (Set board to QA-Mode, which means the updater also checks for RC-releases)
0244  </pre></div>
0245   
0246  <h4>PHPBB_USE_BOARD_URL_PATH</h4>
0247   
0248  <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>
0249   
0250  <ul>
0251      <li>/phpbb/user.php - \phpbb\user::img()</li>
0252      <li>/includes/functions_content.php - smiley_text()</li>
0253  </ul>
0254   
0255  <p>Path locations for the following template variables are affected by this too:</p>
0256   
0257  <ul>
0258      <li>{T_ASSETS_PATH} - assets (non-style specific, static resources)</li>
0259      <li>{T_THEME_PATH} - styles/xxx/theme</li>
0260      <li>{T_TEMPLATE_PATH} - styles/xxx/template</li>
0261      <li>{T_SUPER_TEMPLATE_PATH} - styles/xxx/template</li>
0262      <li>{T_IMAGES_PATH} - images/</li>
0263      <li>{T_SMILIES_PATH} - $config['smilies_path']/</li>
0264      <li>{T_AVATAR_PATH} - $config['avatar_path']/</li>
0265      <li>{T_AVATAR_GALLERY_PATH} - $config['avatar_gallery_path']/</li>
0266      <li>{T_ICONS_PATH} - $config['icons_path']/</li>
0267      <li>{T_RANKS_PATH} - $config['ranks_path']/</li>
0268      <li>{T_UPLOAD_PATH} - $config['upload_path']/</li>
0269      <li>{T_STYLESHEET_LINK} - styles/xxx/theme/stylesheet.css</li>
0270      <li>New template variable {BOARD_URL} for the board url + script path.</li>
0271  </ul>
0272   
0273          </div>
0274   
0275          <div class="back2top"><a href="#wrap" class="top">Back to Top</a></div>
0276   
0277          <span class="corners-bottom"><span></span></span></div>
0278      </div>
0279   
0280      <hr />
0281   
0282  <a name="code"></a><h2>2. Code Layout/Guidelines</h2>
0283   
0284      <div class="paragraph">
0285          <div class="inner"><span class="corners-top"><span></span></span>
0286   
0287          <div class="content">
0288   
0289      <p>Please note that these guidelines apply to all php, html, javascript and css files.</p>
0290   
0291      <a name="namingvars"></a><h3>2.i. Variable/Function/Class Naming</h3>
0292   
0293      <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>
0294   
0295      <h4>Variable Names:</h4>
0296      <p>In PHP, variable names should be in all lowercase, with words separated by an underscore, example:</p>
0297   
0298      <div class="indent">
0299          <p><code>$current_user</code> is right, but <code>$currentuser</code> and <code> $currentUser</code> are not.</p>
0300      </div>
0301      
0302      <p>In JavaScript, variable names should use camel case:</p>
0303      
0304      <div class="indent">
0305          <p><code>currentUser</code> is right, but <code>currentuser</code> and <code>current_user</code> are not.</p>
0306      </div>
0307   
0308      <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>
0309   
0310      <h4>Loop Indices:</h4>
0311      <p>The <em>only</em> situation where a one-character variable name is allowed is when it's the index for some looping construct. In this case, the index of the outer loop should always be $i. If there's a loop inside that loop, its index should be $j, followed by $k, and so on. If the loop is being indexed by some already-existing variable with a meaningful name, this guideline does not apply, example:</p>
0312   
0313      <div class="codebox"><pre>
0314  for ($i = 0; $i &lt; $outer_size; $i++)
0315  {
0316     for ($j = 0; $j &lt; $inner_size; $j++)
0317     {
0318        foo($i, $j);
0319     }
0320  }
0321      </pre></div>
0322   
0323      <h4>Function Names:</h4>
0324      <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>
0325   
0326      <h4>Function Arguments:</h4>
0327      <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>
0328   
0329      <h4>Class Names:</h4>
0330   
0331      <p>Apart from following the rules for function names, all classes should meet the following conditions:</p>
0332      <ul>
0333          <li>Every class must be defined in a separate file.</li>
0334          <li>The classes have to be located in a subdirectory of <code>phpbb/</code>.</li>
0335          <li>Classnames must be namespaced with <code>\phpbb\</code> to avoid name clashes.</li>
0336          <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>
0337          <li>Directories should typically be a singular noun (e.g. <code>dir</code> in the example below, not <code>dirs</code>.</li>
0338      </ul>
0339   
0340      <p>So given the following example directory structure you would result in the below listed lookups</p>
0341      <div class="codebox"><pre>
0342  phpbb/
0343    class_name.php
0344    dir/
0345      class_name.php
0346        subdir/
0347          class_name.php
0348      </pre></div>
0349   
0350      <div class="codebox"><pre>
0351  \phpbb\class_name            - phpbb/class_name.php
0352  \phpbb\dir\class_name        - phpbb/dir/class_name.php
0353  \phpbb\dir\subdir\class_name - phpbb/dir/subdir/class_name.php
0354      </pre></div>
0355   
0356   
0357      <h4>Summary:</h4>
0358      <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>
0359   
0360      <h4>Special Namings: </h4>
0361      <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>
0362   
0363      <a name="codelayout"></a><h3>2.ii. Code Layout</h3>
0364   
0365      <h4>Always include the braces:</h4>
0366      <p>This is another case of being too lazy to type 2 extra characters causing problems with code clarity. Even if the body of some construct is only one line long, do <em>not</em> drop the braces. Just don't, examples:</p>
0367   
0368      <p class="bad">// These are all wrong. </p>
0369   
0370      <div class="codebox"><pre>
0371  if (condition) do_stuff();
0372   
0373  if (condition)
0374      do_stuff();
0375   
0376  while (condition)
0377      do_stuff();
0378   
0379  for ($i = 0; $i &lt; size; $i++)
0380      do_stuff($i);
0381      </pre></div>
0382   
0383      <p class="good">// These are all right. </p>
0384      <div class="codebox"><pre>
0385  if (condition)
0386  {
0387      do_stuff();
0388  }
0389   
0390  while (condition)
0391  {
0392      do_stuff();
0393  }
0394   
0395  for ($i = 0; $i &lt; size; $i++)
0396  {
0397      do_stuff();
0398  }
0399      </pre></div>
0400   
0401      <h4>Where to put the braces:</h4>
0402      <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>
0403   
0404      <div class="codebox"><pre>
0405  if (condition)
0406  {
0407      while (condition2)
0408      {
0409          ...
0410      }
0411  }
0412  else
0413  {
0414      ...
0415  }
0416   
0417  for ($i = 0; $i &lt; $size; $i++)
0418  {
0419      ...
0420  }
0421   
0422  while (condition)
0423  {
0424      ...
0425  }
0426   
0427  function do_stuff()
0428  {
0429      ...
0430  }
0431      </pre></div>
0432      
0433      <p>In JavaScript code, braces always go on the same line:</p>
0434   
0435      <div class="codebox"><pre>
0436  if (condition) {
0437      while (condition2) {
0438          ...
0439      }
0440  } else {
0441      ...
0442  }
0443   
0444  for (var i = 0; i &lt; size; i++) {
0445      ...
0446  }
0447   
0448  while (condition) {
0449      ...
0450  }
0451   
0452  function do_stuff() {
0453      ...
0454  }
0455      </pre></div>
0456   
0457      <h4>Use spaces between tokens:</h4>
0458      <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>
0459   
0460      <p>// Each pair shows the wrong way followed by the right way. </p>
0461   
0462      <div class="codebox"><pre>
0463  $i=0;
0464  $i = 0;
0465   
0466  if($i&lt;7) ...
0467  if ($i &lt; 7) ...
0468   
0469  if ( ($i &lt; 7)&amp;&amp;($j &gt; 8) ) ...
0470  if ($i &lt; 7 &amp;&amp; $j &gt; 8) ...
0471   
0472  do_stuff( $i, 'foo', $b );
0473  do_stuff($i, 'foo', $b);
0474   
0475  for($i=0; $i&lt;$size; $i++) ...
0476  for ($i = 0; $i &lt; $size; $i++) ...
0477   
0478  $i=($j &lt; $size)?0:1;
0479  $i = ($j &lt; $size) ? 0 : 1;
0480      </pre></div>
0481   
0482      <h4>Operator precedence:</h4>
0483      <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>
0484   
0485      <p class="bad">// what's the result? who knows. </p>
0486      <div class="codebox"><pre>
0487  $bool = ($i &lt; 7 &amp;&amp; $j &gt; 8 || $k == 4);
0488      </pre></div>
0489   
0490      <p class="bad">// now you can be certain what I'm doing here.</p>
0491      <div class="codebox"><pre>
0492  $bool = (($i &lt; 7) &amp;&amp; (($j &lt; 8) || ($k == 4)));
0493      </pre></div>
0494   
0495      <p class="good">// But this one is even better, because it is easier on the eye but the intention is preserved</p>
0496      <div class="codebox"><pre>
0497  $bool = ($i &lt; 7 &amp;&amp; ($j &lt; 8 || $k == 4));
0498      </pre></div>
0499   
0500      <h4>Quoting strings:</h4>
0501      <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>
0502      <p>Also, if you are using a string variable as part of a function call, you do not need to enclose that variable in quotes. Again, this will just make unnecessary work for the parser. Note, however, that nearly all of the escape sequences that exist for double-quoted strings will not work with single-quoted strings. Be careful, and feel free to break this guideline if it's making your code easier to read, examples:</p>
0503   
0504      <p class="bad">// wrong </p>
0505      <div class="codebox"><pre>
0506  $str = "This is a really long string with no variables for the parser to find.";
0507   
0508  do_stuff("$str");
0509      </pre></div>
0510   
0511      <p class="good">// right</p>
0512      <div class="codebox"><pre>
0513  $str = 'This is a really long string with no variables for the parser to find.';
0514   
0515  do_stuff($str);
0516      </pre></div>
0517   
0518      <p class="bad">// Sometimes single quotes are just not right</p>
0519      <div class="codebox"><pre>
0520  $post_url = $phpbb_root_path . 'posting.' . $phpEx . '?mode=' . $mode . '&amp;amp;start=' . $start;
0521      </pre></div>
0522   
0523      <p class="good">// Double quotes are sometimes needed to not overcrowd the line with concatenations.</p>
0524      <div class="codebox"><pre>
0525  $post_url = "{$phpbb_root_path}posting.$phpEx?mode=$mode&amp;amp;start=$start";
0526      </pre></div>
0527   
0528      <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>
0529   
0530      <h4>Commas after every array element:</h4>
0531      <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>
0532   
0533      <p class="bad">// wrong</p>
0534      <div class="codebox"><pre>
0535  $foo = array(
0536      'bar' => 42,
0537      'boo' => 23
0538  );
0539      </pre></div>
0540   
0541      <p class="good">// right </p>
0542      <div class="codebox"><pre>
0543  $foo = array(
0544      'bar' => 42,
0545      'boo' => 23,
0546  );
0547      </pre></div>
0548   
0549   
0550      <h4>Associative array keys:</h4>
0551      <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>
0552   
0553      <p class="bad">// wrong</p>
0554      <div class="codebox"><pre>
0555  $foo = $assoc_array[blah];
0556      </pre></div>
0557   
0558      <p class="good">// right </p>
0559      <div class="codebox"><pre>
0560  $foo = $assoc_array['blah'];
0561      </pre></div>
0562   
0563      <p class="bad">// wrong</p>
0564      <div class="codebox"><pre>
0565  $foo = $assoc_array["$var"];
0566      </pre></div>
0567   
0568      <p class="good">// right </p>
0569      <div class="codebox"><pre>
0570  $foo = $assoc_array[$var];
0571      </pre></div>
0572   
0573      <h4>Comments:</h4>
0574      <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>
0575   
0576      <h4>Magic numbers:</h4>
0577      <p>Don't use them. Use named constants for any literal value other than obvious special cases. Basically, it's ok to check if an array has 0 elements by using the literal 0. It's not ok to assign some special meaning to a number and then use it everywhere as a literal. This hurts readability AND maintainability. The constants <code>true</code> and <code>false</code> should be used in place of the literals 1 and 0 -- even though they have the same values (but not type!), it's more obvious what the actual logic is when you use the named constants. Typecast variables where it is needed, do not rely on the correct variable type (PHP is currently very loose on typecasting which can lead to security problems if a developer does not keep a very close eye on it).</p>
0578   
0579      <h4>Shortcut operators:</h4>
0580      <p>The only shortcut operators that cause readability problems are the shortcut increment <code>$i++</code> and decrement <code>$j--</code> operators. These operators should not be used as part of an expression. They can, however, be used on their own line. Using them in expressions is just not worth the headaches when debugging, examples:</p>
0581   
0582      <p class="bad">// wrong </p>
0583      <div class="codebox"><pre>
0584  $array[++$i] = $j;
0585  $array[$i++] = $k;
0586      </pre></div>
0587   
0588      <p class="good">// right </p>
0589      <div class="codebox"><pre>
0590  $i++;
0591  $array[$i] = $j;
0592   
0593  $array[$i] = $k;
0594  $i++;
0595      </pre></div>
0596   
0597      <h4>Inline conditionals:</h4>
0598      <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>
0599   
0600      <p class="bad">// Bad place to use them</p>
0601      <div class="codebox"><pre>
0602  ($i &lt; $size &amp;&amp; $j &gt; $size) ? do_stuff($foo) : do_stuff($bar);
0603      </pre></div>
0604   
0605      <p class="good">// OK place to use them </p>
0606      <div class="codebox"><pre>
0607  $min = ($i &lt; $j) ? $i : $j;
0608      </pre></div>
0609   
0610      <h4>Don't use uninitialized variables.</h4>
0611      <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>
0612   
0613      <p class="bad">// Wrong </p>
0614      <div class="codebox"><pre>
0615  if ($forum) ...
0616      </pre></div>
0617   
0618      <p class="good">// Right </p>
0619      <div class="codebox"><pre>
0620  if (isset($forum)) ...
0621      </pre></div>
0622   
0623      <p class="good">// Also possible</p>
0624      <div class="codebox"><pre>
0625  if (isset($forum) &amp;&amp; $forum == 5)
0626      </pre></div>
0627   
0628      <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>
0629   
0630      <h4>Switch statements:</h4>
0631      <p>Switch/case code blocks can get a bit long sometimes. To have some level of notice and being in-line with the opening/closing brace requirement (where they are on the same line for better readability), this also applies to switch/case code blocks and the breaks. An example:</p>
0632   
0633      <p class="bad">// Wrong </p>
0634      <div class="codebox"><pre>
0635  switch ($mode)
0636  {
0637      case 'mode1':
0638          // I am doing something here
0639          break;
0640      case 'mode2':
0641          // I am doing something completely different here
0642          break;
0643  }
0644      </pre></div>
0645   
0646      <p class="good">// Good </p>
0647      <div class="codebox"><pre>
0648  switch ($mode)
0649  {
0650      case 'mode1':
0651          // I am doing something here
0652      break;
0653   
0654      case 'mode2':
0655          // I am doing something completely different here
0656      break;
0657   
0658      default:
0659          // Always assume that a case was not caught
0660      break;
0661  }
0662      </pre></div>
0663   
0664      <p class="good">// Also good, if you have more code between the case and the break </p>
0665      <div class="codebox"><pre>
0666  switch ($mode)
0667  {
0668      case 'mode1':
0669   
0670          // I am doing something here
0671   
0672      break;
0673   
0674      case 'mode2':
0675   
0676          // I am doing something completely different here
0677   
0678      break;
0679   
0680      default:
0681   
0682          // Always assume that a case was not caught
0683   
0684      break;
0685  }
0686      </pre></div>
0687   
0688      <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>
0689   
0690      <p>If no break is intended, please add a comment instead. An example:</p>
0691   
0692      <p class="good">// Example with no break </p>
0693      <div class="codebox"><pre>
0694  switch ($mode)
0695  {
0696      case 'mode1':
0697   
0698          // I am doing something here
0699   
0700      // no break here
0701   
0702      case 'mode2':
0703   
0704          // I am doing something completely different here
0705   
0706      break;
0707   
0708      default:
0709   
0710          // Always assume that a case was not caught
0711   
0712      break;
0713  }
0714      </pre></div>
0715   
0716      <h4>Class Members</h4>
0717      <p>Use the explicit visibility qualifiers <code>public</code>, <code>private</code> and <code>protected</code> for all properties instead of <code>var</code>.
0718   
0719      <p>Place the <code>static</code> qualifier before the visibility qualifiers.</p>
0720   
0721      <p class="bad">//Wrong </p>
0722      <div class="codebox"><pre>
0723  var $x;
0724  private static function f()
0725      </pre></div>
0726   
0727      <p class="good">// Right </p>
0728      <div class="codebox"><pre>
0729  public $x;
0730  static private function f()
0731      </pre></div>
0732   
0733      <h4>Constants</h4>
0734      <p>Prefer class constants over global constants created with <code>define()</code>.</p>
0735   
0736      <a name="sql"></a><h3>2.iii. SQL/SQL Layout</h3>
0737   
0738      <h4>Common SQL Guidelines: </h4>
0739      <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>
0740      <p>All SQL commands should utilise the DataBase Abstraction Layer (DBAL)</p>
0741   
0742      <h4>SQL code layout:</h4>
0743      <p>SQL Statements are often unreadable without some formatting, since they tend to be big at times. Though the formatting of sql statements adds a lot to the readability of code. SQL statements should be formatted in the following way, basically writing keywords: </p>
0744   
0745      <div class="codebox"><pre>
0746  $sql = 'SELECT *
0747  &lt;-one tab-&gt;FROM ' . SOME_TABLE . '
0748  &lt;-one tab-&gt;WHERE a = 1
0749  &lt;-two tabs-&gt;AND (b = 2
0750  &lt;-three tabs-&gt;OR b = 3)
0751  &lt;-one tab-&gt;ORDER BY b';
0752      </pre></div>
0753   
0754      <p>Here the example with the tabs applied:</p>
0755   
0756      <div class="codebox"><pre>
0757  $sql = 'SELECT *
0758      FROM ' . SOME_TABLE . '
0759      WHERE a = 1
0760          AND (b = 2
0761              OR b = 3)
0762      ORDER BY b';
0763      </pre></div>
0764   
0765      <h4>SQL Quotes: </h4>
0766      <p>Use double quotes where applicable. (The variables in these examples are typecasted to integers beforehand.) Examples: </p>
0767   
0768      <p class="bad">// These are wrong.</p>
0769      <div class="codebox"><pre>
0770  "UPDATE " . SOME_TABLE . " SET something = something_else WHERE a = $b";
0771   
0772  'UPDATE ' . SOME_TABLE . ' SET something = ' . $user_id . ' WHERE a = ' . $something;
0773      </pre></div>
0774   
0775      <p class="good">// These are right. </p>
0776   
0777      <div class="codebox"><pre>
0778  'UPDATE ' . SOME_TABLE . " SET something = something_else WHERE a = $b";
0779   
0780  'UPDATE ' . SOME_TABLE . " SET something = $user_id WHERE a = $something";
0781      </pre></div>
0782   
0783      <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>
0784   
0785      <h4>Avoid DB specific SQL: </h4>
0786      <p>The &quot;not equals operator&quot;, as defined by the SQL:2003 standard, is &quot;&lt;&gt;&quot;</p>
0787   
0788      <p class="bad">// This is wrong.</p>
0789      <div class="codebox"><pre>
0790  $sql = 'SELECT *
0791      FROM ' . SOME_TABLE . '
0792      WHERE a != 2';
0793      </pre></div>
0794   
0795      <p class="good">// This is right. </p>
0796      <div class="codebox"><pre>
0797  $sql = 'SELECT *
0798      FROM ' . SOME_TABLE . '
0799      WHERE a &lt;&gt; 2';
0800      </pre></div>
0801   
0802      <h4>Common DBAL methods: </h4>
0803   
0804      <h4>sql_escape():</h4>
0805   
0806      <p>Always use <code>$db-&gt;sql_escape()</code> if you need to check for a string within an SQL statement (even if you are sure the variable cannot contain single quotes - never trust your input), for example:</p>
0807   
0808      <div class="codebox"><pre>
0809  $sql = 'SELECT *
0810      FROM ' . SOME_TABLE . "
0811      WHERE username = '" . $db-&gt;sql_escape($username) . "'";
0812      </pre></div>
0813   
0814      <h4>sql_query_limit():</h4>
0815   
0816      <p>We do not add limit statements to the sql query, but instead use <code>$db-&gt;sql_query_limit()</code>. You basically pass the query, the total number of lines to retrieve and the offset.</p>
0817   
0818      <p><strong>Note: </strong> Since Oracle handles limits differently and because of how we implemented this handling you need to take special care if you use <code>sql_query_limit</code> with an sql query retrieving data from more than one table.</p>
0819   
0820      <p>Make sure when using something like "SELECT x.*, y.jars" that there is not a column named jars in x; make sure that there is no overlap between an implicit column and the explicit columns.</p>
0821   
0822      <h4>sql_build_array():</h4>
0823   
0824      <p>If you need to UPDATE or INSERT data, make use of the <code>$db-&gt;sql_build_array()</code> function. This function already escapes strings and checks other types, so there is no need to do this here. The data to be inserted should go into an array - <code>$sql_ary</code> - or directly within the statement if one or two variables needs to be inserted/updated. An example of an insert statement would be:</p>
0825   
0826      <div class="codebox"><pre>
0827  $sql_ary = array(
0828      'somedata'        =&gt; $my_string,
0829      'otherdata'        =&gt; $an_int,
0830      'moredata'        =&gt; $another_int,
0831  );
0832   
0833  $db-&gt;sql_query('INSERT INTO ' . SOME_TABLE . ' ' . $db-&gt;sql_build_array('INSERT', $sql_ary));
0834      </pre></div>
0835   
0836      <p>To complete the example, this is how an update statement would look like:</p>
0837   
0838      <div class="codebox"><pre>
0839  $sql_ary = array(
0840      'somedata'        =&gt; $my_string,
0841      'otherdata'        =&gt; $an_int,
0842      'moredata'        =&gt; $another_int,
0843  );
0844   
0845  $sql = 'UPDATE ' . SOME_TABLE . '
0846      SET ' . $db-&gt;sql_build_array('UPDATE', $sql_ary) . '
0847      WHERE user_id = ' . (int) $user_id;
0848  $db-&gt;sql_query($sql);
0849      </pre></div>
0850   
0851      <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>
0852   
0853      <h4>sql_multi_insert():</h4>
0854   
0855      <p>If you want to insert multiple statements at once, please use the separate <code>sql_multi_insert()</code> method. An example:</p>
0856   
0857      <div class="codebox"><pre>
0858  $sql_ary = array();
0859   
0860  $sql_ary[] = array(
0861      'somedata'        =&gt; $my_string_1,
0862      'otherdata'        =&gt; $an_int_1,
0863      'moredata'        =&gt; $another_int_1,
0864  );
0865   
0866  $sql_ary[] = array(
0867      'somedata'        =&gt; $my_string_2,
0868      'otherdata'        =&gt; $an_int_2,
0869      'moredata'        =&gt; $another_int_2,
0870  );
0871   
0872  $db->sql_multi_insert(SOME_TABLE, $sql_ary);
0873      </pre></div>
0874   
0875      <h4>sql_in_set():</h4>
0876   
0877      <p>The <code>$db-&gt;sql_in_set()</code> function should be used for building <code>IN ()</code> and <code>NOT IN ()</code> constructs. Since (specifically) MySQL tend to be faster if for one value to be compared the <code>=</code> and <code>&lt;&gt;</code> operator is used, we let the DBAL decide what to do. A typical example of doing a positive match against a number of values would be:</p>
0878   
0879      <div class="codebox"><pre>
0880  $sql = 'SELECT *
0881      FROM ' . FORUMS_TABLE . '
0882      WHERE ' . $db-&gt;sql_in_set('forum_id', $forum_ids);
0883  $db-&gt;sql_query($sql);
0884      </pre></div>
0885   
0886      <p>Based on the number of values in $forum_ids, the query can look differently.</p>
0887   
0888      <p class="good">// SQL Statement if $forum_ids = array(1, 2, 3);</p>
0889   
0890      <div class="codebox"><pre>
0891  SELECT FROM phpbb_forums WHERE forum_id IN (1, 2, 3)
0892      </pre></div>
0893   
0894      <p class="good">// SQL Statement if $forum_ids = array(1) or $forum_ids = 1</p>
0895   
0896      <div class="codebox"><pre>
0897  SELECT FROM phpbb_forums WHERE forum_id = 1
0898      </pre></div>
0899   
0900      <p>Of course the same is possible for doing a negative match against a number of values:</p>
0901   
0902      <div class="codebox"><pre>
0903  $sql = 'SELECT *
0904      FROM ' . FORUMS_TABLE . '
0905      WHERE ' . $db-&gt;sql_in_set('forum_id', $forum_ids, <strong>true</strong>);
0906  $db-&gt;sql_query($sql);
0907      </pre></div>
0908   
0909      <p>Based on the number of values in $forum_ids, the query can look differently here too.</p>
0910   
0911      <p class="good">// SQL Statement if $forum_ids = array(1, 2, 3);</p>
0912   
0913      <div class="codebox"><pre>
0914  SELECT FROM phpbb_forums WHERE forum_id <strong>NOT</strong> IN (1, 2, 3)
0915      </pre></div>
0916   
0917      <p class="good">// SQL Statement if $forum_ids = array(1) or $forum_ids = 1</p>
0918   
0919      <div class="codebox"><pre>
0920  SELECT FROM phpbb_forums WHERE forum_id <strong>&lt;&gt;</strong> 1
0921      </pre></div>
0922   
0923      <p>If the given array is empty, an error will be produced.</p>
0924   
0925      <h4>sql_build_query():</h4>
0926   
0927      <p>The <code>$db-&gt;sql_build_query()</code> function is responsible for building sql statements for SELECT and SELECT DISTINCT queries if you need to JOIN on more than one table or retrieve data from more than one table while doing a JOIN. This needs to be used to make sure the resulting statement is working on all supported db's. Instead of explaining every possible combination, I will give a short example:</p>
0928   
0929      <div class="codebox"><pre>
0930  $sql_array = array(
0931      'SELECT'    =&gt; 'f.*, ft.mark_time',
0932   
0933      'FROM'        =&gt; array(
0934          FORUMS_WATCH_TABLE    =&gt; 'fw',
0935          FORUMS_TABLE        =&gt; 'f',
0936      ),
0937   
0938      'LEFT_JOIN'    =&gt; array(
0939          array(
0940              'FROM'    =&gt; array(FORUMS_TRACK_TABLE =&gt; 'ft'),
0941              'ON'    =&gt; 'ft.user_id = ' . $user-&gt;data['user_id'] . ' AND ft.forum_id = f.forum_id',
0942          ),
0943      ),
0944   
0945      'WHERE'        =&gt; 'fw.user_id = ' . $user-&gt;data['user_id'] . '
0946          AND f.forum_id = fw.forum_id',
0947   
0948      'ORDER_BY'    =&gt; 'left_id',
0949  );
0950   
0951  $sql = $db-&gt;sql_build_query('SELECT', $sql_array);
0952      </pre></div>
0953   
0954      <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>
0955   
0956      <div class="codebox"><pre>
0957  $sql_array = array(
0958      'SELECT'    =&gt; 'f.*',
0959   
0960      'FROM'        =&gt; array(
0961          FORUMS_WATCH_TABLE    =&gt; 'fw',
0962          FORUMS_TABLE        =&gt; 'f',
0963      ),
0964   
0965      'WHERE'        =&gt; 'fw.user_id = ' . $user-&gt;data['user_id'] . '
0966          AND f.forum_id = fw.forum_id',
0967   
0968      'ORDER_BY'    =&gt; 'left_id',
0969  );
0970   
0971  if ($config['load_db_lastread'])
0972  {
0973      $sql_array['LEFT_JOIN'] = array(
0974          array(
0975              'FROM'    =&gt; array(FORUMS_TRACK_TABLE =&gt; 'ft'),
0976              'ON'    =&gt; 'ft.user_id = ' . $user-&gt;data['user_id'] . ' AND ft.forum_id = f.forum_id',
0977          ),
0978      );
0979   
0980      $sql_array['SELECT'] .= ', ft.mark_time ';
0981  }
0982  else
0983  {
0984      // Here we read the cookie data
0985  }
0986   
0987  $sql = $db-&gt;sql_build_query('SELECT', $sql_array);
0988      </pre></div>
0989   
0990      <a name="optimizing"></a><h3>2.iv. Optimizations</h3>
0991   
0992      <h4>Operations in loop definition: </h4>
0993      <p>Always try to optimize your loops if operations are going on at the comparing part, since this part is executed every time the loop is parsed through. For assignments a descriptive name should be chosen. Example:</p>
0994   
0995      <p class="bad">// On every iteration the sizeof function is called</p>
0996      <div class="codebox"><pre>
0997  for ($i = 0; $i &lt; sizeof($post_data); $i++)
0998  {
0999      do_something();
1000  }
1001      </pre></div>
1002   
1003      <p class="good">// You are able to assign the (not changing) result within the loop itself</p>
1004      <div class="codebox"><pre>
1005  for ($i = 0, $size = sizeof($post_data); $i &lt; $size; $i++)
1006  {
1007      do_something();
1008  }
1009      </pre></div>
1010   
1011      <h4>Use of in_array(): </h4>
1012      <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>
1013   
1014   
1015      <a name="general"></a><h3>2.v. General Guidelines</h3>
1016   
1017      <h4>General things:</h4>
1018      <p>Never trust user input (this also applies to server variables as well as cookies).</p>
1019      <p>Try to sanitize values returned from a function.</p>
1020      <p>Try to sanitize given function variables within your function.</p>
1021      <p>The auth class should be used for all authorisation checking.</p>
1022      <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>
1023   
1024      <h4>Variables: </h4>
1025      <p>Make use of the <code>\phpbb\request\request</code> class for everything.</p>
1026      <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>
1027   
1028      <p class="bad">// Old method, do not use it</p>
1029      <div class="codebox"><pre>
1030  $start = (isset($HTTP_GET_VARS['start'])) ? intval($HTTP_GET_VARS['start']) : intval($HTTP_POST_VARS['start']);
1031  $submit = (isset($HTTP_POST_VARS['submit'])) ? true : false;
1032      </pre></div>
1033   
1034      <p class="good">// Use request var and define a default variable (use the correct type)</p>
1035      <div class="codebox"><pre>
1036  $start = $request->variable('start', 0);
1037  $submit = $request->is_set_post('submit');
1038      </pre></div>
1039   
1040      <p class="bad">// $start is an int, the following use of $request->variable() therefore is not allowed</p>
1041      <div class="codebox"><pre>
1042  $start = $request->variable('start', '0');
1043      </pre></div>
1044   
1045      <p class="good">// Getting an array, keys are integers, value defaults to 0</p>
1046      <div class="codebox"><pre>
1047  $mark_array = $request->variable('mark', array(0));
1048      </pre></div>
1049   
1050      <p class="good">// Getting an array, keys are strings, value defaults to 0</p>
1051      <div class="codebox"><pre>
1052  $action_ary = $request->variable('action', array('' =&gt; 0));
1053      </pre></div>
1054   
1055      <h4>Login checks/redirection: </h4>
1056      <p>To show a forum login box use <code>login_forum_box($forum_data)</code>, else use the <code>login_box()</code> function.</p>
1057   
1058      <p><code>$forum_data</code> should contain at least the <code>forum_id</code> and <code>forum_password</code> fields. If the field <code>forum_name</code> is available, then it is displayed on the forum login page.</p>
1059   
1060      <p>The <code>login_box()</code> function can have a redirect as the first parameter. As a thumb of rule, specify an empty string if you want to redirect to the users current location, else do not add the <code>$SID</code> to the redirect string (for example within the ucp/login we redirect to the board index because else the user would be redirected to the login screen).</p>
1061   
1062      <h4>Sensitive Operations: </h4>
1063      <p>For sensitive operations always let the user confirm the action. For the confirmation screens, make use of the <code>confirm_box()</code> function.</p>
1064   
1065      <h4>Altering Operations: </h4>
1066      <p>For operations altering the state of the database, for instance posting, always verify the form token, unless you are already using <code>confirm_box()</code>. To do so, make use of the <code>add_form_key()</code> and <code>check_form_key()</code> functions. </p>
1067      <div class="codebox"><pre>
1068      add_form_key('my_form');
1069   
1070      if ($submit)
1071      {
1072          if (!check_form_key('my_form'))
1073          {
1074              trigger_error('FORM_INVALID');
1075          }
1076      }
1077      </pre></div>
1078   
1079      <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>
1080   
1081   
1082      <h4>Sessions: </h4>
1083      <p>Sessions should be initiated on each page, as near the top as possible using the following code:</p>
1084   
1085      <div class="codebox"><pre>
1086  $user-&gt;session_begin();
1087  $auth-&gt;acl($user-&gt;data);
1088  $user-&gt;setup();
1089      </pre></div>
1090   
1091      <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>
1092   
1093      <h4>Errors and messages: </h4>
1094      <p>All messages/errors should be outputted by calling <code>trigger_error()</code> using the appropriate message type and language string. Example:</p>
1095   
1096      <div class="codebox"><pre>
1097  trigger_error('NO_FORUM');
1098      </pre></div>
1099   
1100      <div class="codebox"><pre>
1101  trigger_error($user-&gt;lang['NO_FORUM']);
1102      </pre></div>
1103   
1104      <div class="codebox"><pre>
1105  trigger_error('NO_MODE', E_USER_ERROR);
1106      </pre></div>
1107   
1108      <h4>Url formatting</h4>
1109   
1110      <p>All urls pointing to internal files need to be prepended by the <code>$phpbb_root_path</code> variable. Within the administration control panel all urls pointing to internal files need to be prepended by the <code>$phpbb_admin_path</code> variable. This makes sure the path is always correct and users being able to just rename the admin folder and the acp still working as intended (though some links will fail and the code need to be slightly adjusted).</p>
1111   
1112      <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>
1113   
1114      <div class="codebox"><pre>
1115  append_sid(&quot;{$phpbb_root_path}memberlist.$phpEx&quot;, 'mode=group&amp;amp;g=' . $row['group_id'])
1116      </pre></div>
1117   
1118      <h4>General function usage: </h4>
1119   
1120      <p>Some of these functions are only chosen over others because of personal preference and have no benefit other than maintaining consistency throughout the code.</p>
1121   
1122      <ul>
1123          <li>
1124              <p>Use <code>sizeof</code> instead of <code>count</code></p>
1125          </li>
1126          <li>
1127              <p>Use <code>strpos</code> instead of <code>strstr</code></p>
1128          </li>
1129          <li>
1130              <p>Use <code>else if</code> instead of <code>elseif</code></p>
1131          </li>
1132          <li>
1133              <p>Use <code>false</code> (lowercase) instead of <code>FALSE</code></p>
1134          </li>
1135          <li>
1136              <p>Use <code>true</code> (lowercase) instead of <code>TRUE</code></p>
1137          </li>
1138      </ul>
1139   
1140      <h4>Exiting</h4>
1141   
1142      <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>
1143   
1144      <a name="phprestrictions"></a><h3>2.vi. Restrictions on the Use of PHP</h3>
1145   
1146      <h4>Dynamic code execution:</h4>
1147   
1148      <p>Never execute dynamic PHP code (generated or in a constant string) using any of the following PHP functions:</p>
1149   
1150      <ul>
1151          <li><strong>eval</strong></li>
1152          <li><strong>create_function</strong></li>
1153          <li><strong>preg_replace</strong> with the <strong>e</strong> modifier in the pattern</li>
1154      </ul>
1155   
1156      <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>
1157   
1158      <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>
1159   
1160      <h4>Other functions, operators, statements and keywords:</h4>
1161   
1162      <p>The following PHP statements should also not be used in phpBB:</p>
1163   
1164      <ul>
1165          <li><strong>goto</strong></li>
1166      </ul>
1167   
1168          </div>
1169   
1170          <div class="back2top"><a href="#wrap" class="top">Back to Top</a></div>
1171   
1172          <span class="corners-bottom"><span></span></span></div>
1173      </div>
1174   
1175      <hr />
1176   
1177  <a name="styling"></a><h2>3. Styling</h2>
1178      <div class="paragraph">
1179          <div class="inner"><span class="corners-top"><span></span></span>
1180   
1181          <div class="content">
1182      <a name="cfgfiles"></a><h3>3.i. Style Config Files</h3>
1183      <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>
1184      <div class="codebox"><pre>
1185  # General Information about this style
1186  name = prosilver_duplicate
1187  copyright = © phpBB Limited, 2007
1188  style_version = 3.1.0
1189  phpbb_version = 3.1.0
1190   
1191  # Defining a different template bitfield
1192  # template_bitfield = lNg=
1193   
1194  # Parent style
1195  # Set value to empty or to this style's name if this style does not have a parent style
1196  parent = prosilver
1197      </pre></div>
1198      <a name="genstyling"></a><h3>3.2. General Styling Rules</h3>
1199  <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>
1200   
1201  <p>The outer table class <code>forumline</code> has gone and is replaced with <code>tablebg</code>.</p>
1202  <p>When writing <code>&lt;table&gt;</code> the order <code>&lt;table class="" cellspacing="" cellpadding="" border="" align=""&gt;</code> creates consistency and allows everyone to easily see which table produces which "look". The same applies to most other tags for which additional parameters can be set, consistency is the major aim here.</p>
1203  <p>Each block level element should be indented by one tab, same for tabular elements, e.g. <code>&lt;tr&gt;</code> <code>&lt;td&gt;</code> etc., whereby the intendiation of <code>&lt;table&gt;</code> and the following/ending <code>&lt;tr&gt;</code> should be on the same line. This applies not to div elements of course.</p>
1204  <p>Don't use <code>&lt;span&gt;</code> more than is essential ... the CSS is such that text sizes are dependent on the parent class. So writing <code>&lt;span class="gensmall"&gt;&lt;span class="gensmall"&gt;TEST&lt;/span&gt;&lt;/span&gt;</code> will result in very very small text. Similarly don't use span at all if another element can contain the class definition, e.g.</p>
1205   
1206  <div class="codebox"><pre>
1207  &lt;td&gt;&lt;span class=&quot;gensmall&quot;&gt;TEST&lt;/span&gt;&lt;/td&gt;
1208  </pre></div>
1209   
1210  <p>can just as well become:</p>
1211  <div class="codebox"><pre>
1212  &lt;td class=&quot;gensmall&quot;&gt;TEST&lt;/td&gt;
1213  </pre></div>
1214   
1215  <p>Try to match text class types with existing useage, e.g. don't use the nav class where viewtopic uses gensmall for example.</p>
1216   
1217  <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>
1218   
1219  <p>Remember block level ordering is important.</p>
1220   
1221  <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>
1222   
1223  <p><strong>Use div container/css for styling and table for data representation.</strong></p>
1224   
1225  <p>The separate catXXXX and thXXX classes are gone. When defining a header cell just use <code>&lt;th&gt;</code> rather than <code>&lt;th class="thHead"&gt;</code> etc. Similarly for cat, don't use <code>&lt;td class="catLeft"&gt;</code> use <code>&lt;td class="cat"&gt;</code> etc.</p>
1226   
1227  <p>Try to retain consistency of basic layout and class useage, i.e. _EXPLAIN text should generally be placed below the title it explains, e.g. <code>{L_POST_USERNAME}&lt;br /&gt;&lt;span class="gensmall"&gt;{L_POST_USERNAME_EXPLAIN}&lt;/span&gt;</code> is the typical way of handling this ... there may be exceptions and this isn't a hard and fast rule.</p>
1228   
1229  <p>Try to keep template conditional and other statements tabbed in line with the block to which they refer.</p>
1230   
1231  <p class="good">this is correct</p>
1232  <div class="codebox"><pre>
1233  <span class="comment">&lt;!-- BEGIN test --&gt;</span>
1234      &lt;tr&gt;
1235          &lt;td&gt;&#123;test.TEXT&#125;&lt;/td&gt;
1236      &lt;/tr&gt;
1237  <span class="comment">&lt;!-- END test --&gt;</span>
1238  </pre></div>
1239   
1240  <p class="good">this is also correct:</p>
1241  <div class="codebox"><pre>
1242  <span class="comment">&lt;!-- BEGIN test --&gt;</span>
1243  &lt;tr&gt;
1244      &lt;td&gt;&#123;test.TEXT&#125;&lt;/td&gt;
1245  &lt;/tr&gt;
1246  <span class="comment">&lt;!-- END test --&gt;</span>
1247  </pre></div>
1248   
1249  <p>it gives immediate feedback on exactly what is looping - decide which way to use based on the readability.</p>
1250   
1251          </div>
1252   
1253          <div class="back2top"><a href="#wrap" class="top">Back to Top</a></div>
1254   
1255          <span class="corners-bottom"><span></span></span></div>
1256      </div>
1257   
1258      <hr />
1259   
1260  <a name="templating"></a><h2>4. Templating</h2>
1261      <div class="paragraph">
1262          <div class="inner"><span class="corners-top"><span></span></span>
1263   
1264          <div class="content">
1265      <a name="templates"></a><h3>4.i. General Templating</h3>
1266   
1267  <h4>File naming</h4>
1268  <p>Firstly templates now take the suffix &quot;.html&quot; rather than &quot;.tpl&quot;. This was done simply to make the lives of some people easier wrt syntax highlighting, etc.</p>
1269   
1270  <h4>Variables</h4>
1271  <p>All template variables should be named appropriately (using underscores for spaces), language entries should be prefixed with L_, system data with S_, urls with U_, javascript urls with UA_, language to be put in javascript statements with LA_, all other variables should be presented 'as is'.</p>
1272   
1273  <p>L_* template variables are automatically mapped to the corresponding language entry if the code does not set (and therefore overwrite) this variable specifically and if the language entry exists. For example <code>{L_USERNAME}</code> maps to <code>$user-&gt;lang['USERNAME']</code>. The LA_* template variables are handled within the same way, but properly escaped so they can be put in javascript code. This should reduce the need to assign loads of new language variables in MODifications.
1274  </p>
1275   
1276  <h4>Blocks/Loops</h4>
1277  <p>The basic block level loop remains and takes the form:</p>
1278  <div class="codebox"><pre>
1279  <span class="comment">&lt;!-- BEGIN loopname --&gt;</span>
1280      markup, {loopname&#46;X_YYYYY}, etc&#46;
1281  <span class="comment">&lt;!-- END loopname --&gt;</span>
1282  </pre></div>
1283   
1284  <p>A bit later loops will be explained further. To not irritate you we will explain conditionals as well as other statements first.</p>
1285   
1286  <h4>Including files</h4>
1287  <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>
1288   
1289  <div class="codebox"><pre>
1290  <span class="comment">&lt;!-- INCLUDE filename --&gt;</span>
1291  </pre></div>
1292   
1293  <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>
1294   
1295  <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>
1296  <div class="codebox"><pre>
1297  <span class="comment">&lt;!-- INCLUDE {FILE_VAR} --&gt;</span>
1298  </pre></div>
1299   
1300  <p>Template defined variables can also be utilised.</p>
1301   
1302  <div class="codebox"><pre>
1303  <span class="comment">&lt;!-- DEFINE $SOME_VAR = 'my_file.html' --&gt;</span>
1304  <span class="comment">&lt;!-- INCLUDE {$SOME_VAR} --&gt;</span>
1305  </pre></div>
1306   
1307  <h4>PHP</h4>
1308  <p>A contentious decision has seen the ability to include PHP within the template introduced. This is achieved by enclosing the PHP within relevant tags:</p>
1309   
1310  <div class="codebox"><pre>
1311  <span class="comment">&lt;!-- PHP --&gt;</span>
1312      echo &quot;hello!&quot;;
1313  <span class="comment">&lt;!-- ENDPHP --&gt;</span>
1314  </pre></div>
1315   
1316  <p>You may also include PHP from an external file using:</p>
1317   
1318  <div class="codebox"><pre>
1319  <span class="comment">&lt;!-- INCLUDEPHP somefile&#46;php --&gt;</span>
1320  </pre></div>
1321   
1322  <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>
1323   
1324  <h4>Conditionals/Control structures</h4>
1325  <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>
1326   
1327  <div class="codebox"><pre>
1328  <span class="comment">&lt;!-- IF expr --&gt;</span>
1329      markup
1330  <span class="comment">&lt;!-- ENDIF --&gt;</span>
1331  </pre></div>
1332   
1333  <p>expr can take many forms, for example:</p>
1334   
1335  <div class="codebox"><pre>
1336  <span class="comment">&lt;!-- IF loop&#46;S_ROW_COUNT is even --&gt;</span>
1337      markup
1338  <span class="comment">&lt;!-- ENDIF --&gt;</span>
1339  </pre></div>
1340   
1341  <p>This will output the markup if the S_ROW_COUNT variable in the current iteration of loop is an even value (i.e. the expr is TRUE). You can use various comparison methods (standard as well as equivalent textual versions noted in square brackets) including (<code>not, or, and, eq, neq, is</code> should be used if possible for better readability):</p>
1342   
1343  <div class="codebox"><pre>
1344  == [eq]
1345  != [neq, ne]
1346  &lt;&gt; (same as !=)
1347  !== (not equivalent in value and type)
1348  === (equivalent in value and type)
1349  &gt; [gt]
1350  &lt; [lt]
1351  &gt;= [gte]
1352  &lt;= [lte]
1353  &amp;&amp; [and]
1354  || [or]
1355  % [mod]
1356  ! [not]
1357  +
1358  -
1359  *
1360  /
1361  ,
1362  &lt;&lt; (bitwise shift left)
1363  &gt;&gt; (bitwise shift right)
1364  | (bitwise or)
1365  ^ (bitwise xor)
1366  &amp; (bitwise and)
1367  ~ (bitwise not)
1368  is (can be used to join comparison operations)
1369  </pre></div>
1370   
1371  <p>Basic parenthesis can also be used to enforce good old BODMAS rules. Additionally some basic comparison types are defined:</p>
1372   
1373  <div class="codebox"><pre>
1374  even
1375  odd
1376  div
1377  </pre></div>
1378   
1379  <p>Beyond the simple use of IF you can also do a sequence of comparisons using the following:</p>
1380   
1381  <div class="codebox"><pre>
1382  <span class="comment">&lt;!-- IF expr1 --&gt;</span>
1383      markup
1384  <span class="comment">&lt;!-- ELSEIF expr2 --&gt;</span>
1385      markup
1386      &#46;
1387      &#46;
1388      &#46;
1389  <span class="comment">&lt;!-- ELSEIF exprN --&gt;</span>
1390      markup
1391  <span class="comment">&lt;!-- ELSE --&gt;</span>
1392      markup
1393  <span class="comment">&lt;!-- ENDIF --&gt;</span>
1394  </pre></div>
1395   
1396  <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>
1397   
1398  <div class="codebox"><pre>
1399  &lt;table&gt;
1400      <span class="comment">&lt;!-- IF loop&#46;S_ROW_COUNT is even --&gt;</span>
1401          &lt;tr class=&quot;row1&quot;&gt;
1402      <span class="comment">&lt;!-- ELSE --&gt;</span>
1403          &lt;tr class=&quot;row2&quot;&gt;
1404      <span class="comment">&lt;!-- ENDIF --&gt;</span>
1405      &lt;td&gt;HELLO!&lt;/td&gt;
1406  &lt;/tr&gt;
1407  &lt;/table&gt;
1408  </pre></div>
1409   
1410  <p>This will cause the row cell to be output using class row1 when the row count is even, and class row2 otherwise. The S_ROW_COUNT parameter gets assigned to loops by default. Another example would be the following: </p>
1411   
1412  <div class="codebox"><pre>
1413  &lt;table&gt;
1414      <span class="comment">&lt;!-- IF loop&#46;S_ROW_COUNT &gt; 10 --&gt;</span>
1415          &lt;tr bgcolor=&quot;#FF0000&quot;&gt;
1416      <span class="comment">&lt;!-- ELSEIF loop&#46;S_ROW_COUNT &gt; 5 --&gt;</span>
1417          &lt;tr bgcolor=&quot;#00FF00&quot;&gt;
1418      <span class="comment">&lt;!-- ELSEIF loop&#46;S_ROW_COUNT &gt; 2 --&gt;</span>
1419          &lt;tr bgcolor=&quot;#0000FF&quot;&gt;
1420      <span class="comment">&lt;!-- ELSE --&gt;</span>
1421          &lt;tr bgcolor=&quot;#FF00FF&quot;&gt;
1422      <span class="comment">&lt;!-- ENDIF --&gt;</span>
1423      &lt;td&gt;hello!&lt;/td&gt;
1424  &lt;/tr&gt;
1425  &lt;/table&gt;
1426  </pre></div>
1427   
1428  <p>This will output the row cell in purple for the first two rows, blue for rows 2 to 5, green for rows 5 to 10 and red for remainder. So, you could produce a &quot;nice&quot; gradient effect, for example.<br /><br />What else can you do? Well, you could use IF to do common checks on for example the login state of a user:</p>
1429   
1430  <div class="codebox"><pre>
1431  <span class="comment">&lt;!-- IF S_USER_LOGGED_IN --&gt;</span>
1432      markup
1433  <span class="comment">&lt;!-- ENDIF --&gt;</span>
1434  </pre></div>
1435   
1436  <p>This replaces the existing (fudged) method in 2.0.x using a zero length array and BEGIN/END.</p>
1437   
1438  <h4>Extended syntax for Blocks/Loops</h4>
1439   
1440  <p>Back to our loops - they had been extended with the following additions. Firstly you can set the start and end points of the loop. For example:</p>
1441   
1442  <div class="codebox"><pre>
1443  <span class="comment">&lt;!-- BEGIN loopname(2) --&gt;</span>
1444      markup
1445  <span class="comment">&lt;!-- END loopname --&gt;</span>
1446  </pre></div>
1447   
1448  <p>Will start the loop on the third entry (note that indexes start at zero). Extensions of this are:
1449  <br /><br />
1450  <code>loopname(2)</code>: Will start the loop on the 3rd entry<br />
1451  <code>loopname(-2)</code>: Will start the loop two entries from the end<br />
1452  <code>loopname(3,4)</code>: Will start the loop on the fourth entry and end it on the fifth<br />
1453  <code>loopname(3,-4)</code>: Will start the loop on the fourth entry and end it four from last<br />
1454  </p>
1455   
1456  <p>A further extension to begin is BEGINELSE:</p>
1457   
1458  <div class="codebox"><pre>
1459  <span class="comment">&lt;!-- BEGIN loop --&gt;</span>
1460      markup
1461  <span class="comment">&lt;!-- BEGINELSE --&gt;</span>
1462      markup
1463  <span class="comment">&lt;!-- END loop --&gt;</span>
1464  </pre></div>
1465   
1466  <p>This will cause the markup between <code>BEGINELSE</code> and <code>END</code> to be output if the loop contains no values. This is useful for forums with no topics (for example) ... in some ways it replaces &quot;bits of&quot; the existing &quot;switch_&quot; type control (the rest being replaced by conditionals).</p>
1467   
1468  <p>Another way of checking if a loop contains values is by prefixing the loops name with a dot:</p>
1469   
1470  <div class="codebox"><pre>
1471  <span class="comment">&lt;!-- IF .loop --&gt;</span>
1472      <span class="comment">&lt;!-- BEGIN loop --&gt;</span>
1473          markup
1474      <span class="comment">&lt;!-- END loop --&gt;</span>
1475  <span class="comment">&lt;!-- ELSE --&gt;</span>
1476      markup
1477  <span class="comment">&lt;!-- ENDIF --&gt;</span>
1478  </pre></div>
1479   
1480  <p>You are even able to check the number of items within a loop by comparing it with values within the IF condition:</p>
1481   
1482  <div class="codebox"><pre>
1483  <span class="comment">&lt;!-- IF .loop &gt; 2 --&gt;</span>
1484      <span class="comment">&lt;!-- BEGIN loop --&gt;</span>
1485          markup
1486      <span class="comment">&lt;!-- END loop --&gt;</span>
1487  <span class="comment">&lt;!-- ELSE --&gt;</span>
1488      markup
1489  <span class="comment">&lt;!-- ENDIF --&gt;</span>
1490  </pre></div>
1491   
1492  <p>Nesting loops cause the conditionals needing prefixed with all loops from the outer one to the inner most. An illustration of this:</p>
1493   
1494  <div class="codebox"><pre>
1495  <span class="comment">&lt;!-- BEGIN firstloop --&gt;</span>
1496      {firstloop.MY_VARIABLE_FROM_FIRSTLOOP}
1497   
1498      <span class="comment">&lt;!-- BEGIN secondloop --&gt;</span>
1499          {firstloop.secondloop.MY_VARIABLE_FROM_SECONDLOOP}
1500      <span class="comment">&lt;!-- END secondloop --&gt;</span>
1501  <span class="comment">&lt;!-- END firstloop --&gt;</span>
1502  </pre></div>
1503   
1504  <p>Sometimes it is necessary to break out of nested loops to be able to call another loop within the current iteration. This sounds a little bit confusing and it is not used very often. The following (rather complex) example shows this quite good - it also shows how you test for the first and last row in a loop (i will explain the example in detail further down):</p>
1505   
1506  <div class="codebox"><pre>
1507  <span class="comment">&lt;!-- BEGIN l_block1 --&gt;</span>
1508      <span class="comment">&lt;!-- IF l_block1.S_SELECTED --&gt;</span>
1509          &lt;strong&gt;{l_block1.L_TITLE}&lt;/strong&gt;
1510          <span class="comment">&lt;!-- IF S_PRIVMSGS --&gt;</span>
1511   
1512              <span class="comment">&lt;!-- the ! at the beginning of the loop name forces the loop to be not a nested one of l_block1 --&gt;</span>
1513              <span class="comment">&lt;!-- BEGIN !folder --&gt;</span>
1514                  <span class="comment">&lt;!-- IF folder.S_FIRST_ROW --&gt;</span>
1515                      &lt;ul class=&quot;nav&quot;&gt;
1516                  <span class="comment">&lt;!-- ENDIF --&gt;</span>
1517   
1518                  &lt;li&gt;&lt;a href=&quot;{folder.U_FOLDER}&quot;&gt;{folder.FOLDER_NAME}&lt;/a&gt;&lt;/li&gt;
1519   
1520                  <span class="comment">&lt;!-- IF folder.S_LAST_ROW --&gt;</span>
1521                      &lt;/ul&gt;
1522                  <span class="comment">&lt;!-- ENDIF --&gt;</span>
1523              <span class="comment">&lt;!-- END !folder --&gt;</span>
1524   
1525          <span class="comment">&lt;!-- ENDIF --&gt;</span>
1526   
1527          &lt;ul class=&quot;nav&quot;&gt;
1528          <span class="comment">&lt;!-- BEGIN l_block2 --&gt;</span>
1529              &lt;li&gt;
1530                  <span class="comment">&lt;!-- IF l_block1.l_block2.S_SELECTED --&gt;</span>
1531                      &lt;strong&gt;{l_block1.l_block2.L_TITLE}&lt;/strong&gt;
1532                  <span class="comment">&lt;!-- ELSE --&gt;</span>
1533                      &lt;a href=&quot;{l_block1.l_block2.U_TITLE}&quot;&gt;{l_block1.l_block2.L_TITLE}&lt;/a&gt;
1534                  <span class="comment">&lt;!-- ENDIF --&gt;</span>
1535              &lt;/li&gt;
1536          <span class="comment">&lt;!-- END l_block2 --&gt;</span>
1537          &lt;/ul&gt;
1538      <span class="comment">&lt;!-- ELSE --&gt;</span>
1539          &lt;a class=&quot;nav&quot; href=&quot;{l_block1.U_TITLE}&quot;&gt;{l_block1.L_TITLE}&lt;/a&gt;
1540      <span class="comment">&lt;!-- ENDIF --&gt;</span>
1541  <span class="comment">&lt;!-- END l_block1 --&gt;</span>
1542  </pre></div>
1543   
1544  <p>Let us first concentrate on this part of the example:</p>
1545   
1546  <div class="codebox"><pre>
1547  <span class="comment">&lt;!-- BEGIN l_block1 --&gt;</span>
1548      <span class="comment">&lt;!-- IF l_block1.S_SELECTED --&gt;</span>
1549          markup
1550      <span class="comment">&lt;!-- ELSE --&gt;</span>
1551          &lt;a class=&quot;nav&quot; href=&quot;{l_block1.U_TITLE}&quot;&gt;{l_block1.L_TITLE}&lt;/a&gt;
1552      <span class="comment">&lt;!-- ENDIF --&gt;</span>
1553  <span class="comment">&lt;!-- END l_block1 --&gt;</span>
1554  </pre></div>
1555   
1556  <p>Here we open the loop l_block1 and do some things if the value S_SELECTED within the current loop iteration is true, else we write the blocks link and title. Here, you see <code>{l_block1.L_TITLE}</code> referenced - you remember that L_* variables get automatically assigned the corresponding language entry? This is true, but not within loops. The L_TITLE variable within the loop l_block1 is assigned within the code itself.</p>
1557   
1558  <p>Let's have a closer look at the markup:</p>
1559   
1560  <div class="codebox"><pre>
1561  <span class="comment">&lt;!-- BEGIN l_block1 --&gt;</span>
1562  .
1563  .
1564      <span class="comment">&lt;!-- IF S_PRIVMSGS --&gt;</span>
1565   
1566          <span class="comment">&lt;!-- BEGIN !folder --&gt;</span>
1567              <span class="comment">&lt;!-- IF folder.S_FIRST_ROW --&gt;</span>
1568                  &lt;ul class=&quot;nav&quot;&gt;
1569              <span class="comment">&lt;!-- ENDIF --&gt;</span>
1570   
1571              &lt;li&gt;&lt;a href=&quot;{folder.U_FOLDER}&quot;&gt;{folder.FOLDER_NAME}&lt;/a&gt;&lt;/li&gt;
1572   
1573              <span class="comment">&lt;!-- IF folder.S_LAST_ROW --&gt;</span>
1574                  &lt;/ul&gt;
1575              <span class="comment">&lt;!-- ENDIF --&gt;</span>
1576          <span class="comment">&lt;!-- END !folder --&gt;</span>
1577   
1578      <span class="comment">&lt;!-- ENDIF --&gt;</span>
1579  .
1580  .
1581  <span class="comment">&lt;!-- END l_block1 --&gt;</span>
1582  </pre></div>
1583   
1584  <p>The <code>&lt;!-- IF S_PRIVMSGS --&gt;</code> statement clearly checks a global variable and not one within the loop, since the loop is not given here. So, if S_PRIVMSGS is true we execute the shown markup. Now, you see the <code>&lt;!-- BEGIN !folder --&gt;</code> statement. The exclamation mark is responsible for instructing the template engine to iterate through the main loop folder. So, we are now within the loop folder - with <code>&lt;!-- BEGIN folder --&gt;</code> we would have been within the loop <code>l_block1.folder</code> automatically as is the case with l_block2:</p>
1585   
1586  <div class="codebox"><pre>
1587  <span class="comment">&lt;!-- BEGIN l_block1 --&gt;</span>
1588  .
1589  .
1590      &lt;ul class=&quot;nav&quot;&gt;
1591      <span class="comment">&lt;!-- BEGIN l_block2 --&gt;</span>
1592          &lt;li&gt;
1593              <span class="comment">&lt;!-- IF l_block1.l_block2.S_SELECTED --&gt;</span>
1594                  &lt;strong&gt;{l_block1.l_block2.L_TITLE}&lt;/strong&gt;
1595              <span class="comment">&lt;!-- ELSE --&gt;</span>
1596                  &lt;a href=&quot;{l_block1.l_block2.U_TITLE}&quot;&gt;{l_block1.l_block2.L_TITLE}&lt;/a&gt;
1597              <span class="comment">&lt;!-- ENDIF --&gt;</span>
1598          &lt;/li&gt;
1599      <span class="comment">&lt;!-- END l_block2 --&gt;</span>
1600      &lt;/ul&gt;
1601  .
1602  .
1603  <span class="comment">&lt;!-- END l_block1 --&gt;</span>
1604  </pre></div>
1605   
1606  <p>You see the difference? The loop l_block2 is a member of the loop l_block1 but the loop folder is a main loop.</p>
1607   
1608  <p>Now back to our folder loop:</p>
1609   
1610  <div class="codebox"><pre>
1611  <span class="comment">&lt;!-- IF folder.S_FIRST_ROW --&gt;</span>
1612      &lt;ul class=&quot;nav&quot;&gt;
1613  <span class="comment">&lt;!-- ENDIF --&gt;</span>
1614   
1615  &lt;li&gt;&lt;a href=&quot;{folder.U_FOLDER}&quot;&gt;{folder.FOLDER_NAME}&lt;/a&gt;&lt;/li&gt;
1616   
1617  <span class="comment">&lt;!-- IF folder.S_LAST_ROW --&gt;</span>
1618      &lt;/ul&gt;
1619  <span class="comment">&lt;!-- ENDIF --&gt;</span>
1620  </pre></div>
1621   
1622  <p>You may have wondered what the comparison to S_FIRST_ROW and S_LAST_ROW is about. If you haven't guessed already - it is checking for the first iteration of the loop with <code>S_FIRST_ROW</code> and the last iteration with <code>S_LAST_ROW</code>. This can come in handy quite often if you want to open or close design elements, like the above list. Let us imagine a folder loop build with three iterations, it would go this way:</p>
1623   
1624  <div class="codebox"><pre>
1625  &lt;ul class=&quot;nav&quot;&gt; <span class="comment">&lt;!-- written on first iteration --&gt;</span>
1626      &lt;li&gt;first element&lt;/li&gt; <span class="comment">&lt;!-- written on first iteration --&gt;</span>
1627      &lt;li&gt;second element&lt;/li&gt; <span class="comment">&lt;!-- written on second iteration --&gt;</span>
1628      &lt;li&gt;third element&lt;/li&gt; <span class="comment">&lt;!-- written on third iteration --&gt;</span>
1629  &lt;/ul&gt; <span class="comment">&lt;!-- written on third iteration --&gt;</span>
1630  </pre></div>
1631   
1632  <p>As you can see, all three elements are written down as well as the markup for the first iteration and the last one. Sometimes you want to omit writing the general markup - for example:</p>
1633   
1634  <div class="codebox"><pre>
1635  <span class="comment">&lt;!-- IF folder.S_FIRST_ROW --&gt;</span>
1636      &lt;ul class=&quot;nav&quot;&gt;
1637  <span class="comment">&lt;!-- ELSEIF folder.S_LAST_ROW --&gt;</span>
1638      &lt;/ul&gt;
1639  <span class="comment">&lt;!-- ELSE --&gt;</span>
1640      &lt;li&gt;&lt;a href=&quot;{folder.U_FOLDER}&quot;&gt;{folder.FOLDER_NAME}&lt;/a&gt;&lt;/li&gt;
1641  <span class="comment">&lt;!-- ENDIF --&gt;</span>
1642  </pre></div>
1643   
1644  <p>would result in the following markup:</p>
1645   
1646  <div class="codebox"><pre>
1647  &lt;ul class=&quot;nav&quot;&gt; <span class="comment">&lt;!-- written on first iteration --&gt;</span>
1648      &lt;li&gt;second element&lt;/li&gt; <span class="comment">&lt;!-- written on second iteration --&gt;</span>
1649  &lt;/ul&gt; <span class="comment">&lt;!-- written on third iteration --&gt;</span>
1650  </pre></div>
1651   
1652  <p>Just always remember that processing is taking place from top to bottom.</p>
1653   
1654      <h4>Forms</h4>
1655          <p>If a form is used for a non-trivial operation (i.e. more than a jumpbox), then it should include the <code>{S_FORM_TOKEN}</code> template variable.</p>
1656          <div class="codebox"><pre>
1657  &lt;form method=&quot;post&quot; id=&quot;mcp&quot; action=&quot;{U_POST_ACTION}&quot;&gt;
1658   
1659      &lt;fieldset class="submit-buttons"&gt;
1660          &lt;input type=&quot;reset&quot; value=&quot;{L_RESET}&quot; name=&quot;reset&quot; class=&quot;button2&quot; /&gt;&nbsp;
1661          &lt;input type=&quot;submit&quot; name=&quot;action[add_warning]&quot; value=&quot;{L_SUBMIT}&quot; class=&quot;button1&quot; /&gt;
1662          {S_FORM_TOKEN}
1663      &lt;/fieldset&gt;
1664  &lt;/form&gt;
1665          </pre></div><br />
1666   
1667      <a name="stylestree"></a><h3>4.ii. Styles Tree</h3>
1668          <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>
1669   
1670          <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>
1671   
1672          <p>We strongly encourage the use of parent styles for styles based on the bundled styles, as it will ease the update procedure.</p>
1673   
1674          <div class="codebox"><pre>
1675  # General Information about this style
1676  name = Custom Style
1677  copyright = © phpBB Limited, 2007
1678  style_version = 3.1.0-b1
1679  phpbb_version = 3.1.0-b1
1680   
1681  # Defining a different template bitfield
1682  # template_bitfield = lNg=
1683   
1684  # Parent style
1685  # Set value to empty or to this style's name if this style does not have a parent style
1686  parent = prosilver
1687          </pre></div>
1688   
1689          <a name="template-events"></a><h3>4.iii. Template Events</h3>
1690          <p>Template events must follow this format: <code>&lt;!-- EVENT event_name --&gt;</code></p>
1691          <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>
1692   
1693          <h4>Template event naming guidelines:</h4>
1694          <ul>
1695              <li>An event name must be all lowercase, with each word separated by an underscore.</li>
1696              <li>An event name must briefly describe the location and purpose of the event.</li>
1697              <li>
1698                  An event name must end with one of the following suffixes:
1699                  <ul>
1700                      <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>
1701                      <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>
1702                      <li><code>_before</code> - This event adds content directly before the specified block</li>
1703                      <li><code>_after</code> - This event adds content directly after the specified block</li>
1704                  </ul>
1705              </li>
1706          </ul>
1707   
1708          <h4>Template event documentation</h4>
1709          <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>
1710   
1711          <ul><li>An event found in only one template file:
1712          <div class="codebox"><pre>event_name
1713  ===
1714  * Location: styles/&lt;style_name&gt;/template/filename.html
1715  * Purpose: A brief description of what this event should be used for.
1716  This may span multiple lines.
1717  * Since: Version since when the event was added
1718  </pre></div></li>
1719          <li>An event found in multiple template files:
1720          <div class="codebox"><pre>event_name
1721  ===
1722  * Locations:
1723      + first/file/path.html
1724      + second/file/path.html
1725  * Purpose: Same as above.
1726  * Since: 3.1.0-b1
1727  </pre></div>
1728          <li>An event that is found multiple times in a file should have the number of instances in parenthesis next to the filename.
1729          <div class="codebox"><pre>event_name
1730  ===
1731  * Locations:
1732      + first/file/path.html (2)
1733      + second/file/path.html
1734  * Purpose: Same as above.
1735  * Since: 3.1.0-b1
1736  </pre></div></li>
1737          <li>An actual example event documentation:
1738          <div class="codebox"><pre>forumlist_body_last_post_title_prepend
1739  ====
1740  * Locations:
1741      + styles/prosilver/template/forumlist_body.html
1742      + styles/subsilver2/template/forumlist_body.html
1743  * Purpose: Add content before the post title of the latest post in a forum on the forum list.
1744  * Since: 3.1.0-a1
1745  </pre></div></ul><br />
1746   
1747          </div>
1748   
1749          <div class="back2top"><a href="#wrap" class="top">Back to Top</a></div>
1750   
1751          <span class="corners-bottom"><span></span></span></div>
1752      </div>
1753   
1754      <hr />
1755   
1756   
1757   
1758  <a name="charsets"></a><h2>5. Character Sets and Encodings</h2>
1759   
1760      <div class="paragraph">
1761          <div class="inner"><span class="corners-top"><span></span></span>
1762   
1763          <div class="content">
1764   
1765   
1766   
1767  <h4>What are Unicode, UCS and UTF-8?</h4>
1768  <p>The <a href="http://en.wikipedia.org/wiki/Universal_Character_Set">Universal Character Set (UCS)</a> described in ISO/IEC 10646 consists of a large amount of characters. Each of them has a unique name and a code point which is an integer number. <a href="http://en.wikipedia.org/wiki/Unicode">Unicode</a> - which is an industry standard - complements the Universal Character Set with further information about the characters' properties and alternative character encodings. More information on Unicode can be found on the <a href="http://www.unicode.org/">Unicode Consortium's website</a>. One of the Unicode encodings is the <a href="http://en.wikipedia.org/wiki/UTF-8">8-bit Unicode Transformation Format (UTF-8)</a>. It encodes characters with up to four bytes aiming for maximum compatibility with the <a href="http://en.wikipedia.org/wiki/ASCII">American Standard Code for Information Interchange</a> which is a 7-bit encoding of a relatively small subset of the UCS.</p>
1769   
1770  <h4>phpBB's use of Unicode</h4>
1771  <p>Unfortunately PHP does not faciliate the use of Unicode prior to version 6. Most functions simply treat strings as sequences of bytes assuming that each character takes up exactly one byte. This behaviour still allows for storing UTF-8 encoded text in PHP strings but many operations on strings have unexpected results. To circumvent this problem we have created some alternative functions to PHP's native string operations which use code points instead of bytes. These functions can be found in <code>/includes/utf/utf_tools.php</code>. They are also covered in the <a href="http://area51.phpbb.com/docs/code/">phpBB3 Sourcecode Documentation</a>. A lot of native PHP functions still work with UTF-8 as long as you stick to certain restrictions. For example <code>explode</code> still works as long as the first and the last character of the delimiter string are ASCII characters.</p>
1772   
1773  <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>
1774   
1775  <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>
1776   
1777  <div class="codebox"><pre>
1778  // an input string containing a multibyte character
1779  $_REQUEST['multibyte_string'] = 'K&#228;se';
1780   
1781  // print request variable as a UTF-8 string allowing multibyte characters
1782  echo $request->variable('multibyte_string', '', true);
1783  // print request variable as ASCII string
1784  echo $request->variable('multibyte_string', '');
1785  </pre></div>
1786   
1787  <p>This code snippet will generate the following output:</p>
1788   
1789  <div class="codebox"><pre>
1790  K&#228;se
1791  K??se
1792  </pre></div>
1793   
1794  <h4>Case Folding</h4>
1795   
1796  <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>
1797   
1798  <p class="bad">// Bad - The strings might be the same even if strtolower differs</p>
1799   
1800  <div class="codebox"><pre>
1801  if (strtolower($string1) == strtolower($string2))
1802  {
1803      echo '$string1 and $string2 are equal or differ in case';
1804  }
1805  </pre></div>
1806   
1807  <p class="good">// Good - Case folding is really case insensitive</p>
1808   
1809  <div class="codebox"><pre>
1810  if (utf8_case_fold_nfc($string1) == utf8_case_fold_nfc($string2))
1811  {
1812      echo '$string1 and $string2 are equal or differ in case';
1813  }
1814  </pre></div>
1815   
1816  <h4>Confusables Detection</h4>
1817   
1818  <p>phpBB offers a special method <code>utf8_clean_string</code> which can be used to make sure string identifiers are unique. This method uses Normalization Form Compatibility Composition (NFKC) instead of NFC and replaces similarly looking characters with a particular representative of the equivalence class. This method is currently used for usernames and group names to avoid confusion with similarly looking names.</p>
1819   
1820          </div>
1821   
1822          <div class="back2top"><a href="#wrap" class="top">Back to Top</a></div>
1823   
1824          <span class="corners-bottom"><span></span></span></div>
1825      </div>
1826   
1827      <hr />
1828   
1829  <a name="translation"></a><h2>6. Translation (<abbr title="Internationalisation">i18n</abbr>/<abbr title="Localisation">L10n</abbr>) Guidelines</h2>
1830   
1831      <div class="paragraph">
1832          <div class="inner"><span class="corners-top"><span></span></span>
1833   
1834          <div class="content">
1835   
1836      <a name="standardisation"></a><h3>6.i. Standardisation</h3>
1837   
1838      <h4>Reason:</h4>
1839   
1840      <p>phpBB is one of the most translated open-source projects, with the current stable version being available in over 60 localisations. Whilst the ad hoc approach to the naming of language packs has worked, for phpBB3 and beyond we hope to make this process saner which will allow for better interoperation with current and future web browsers.</p>
1841   
1842      <h4>Encoding:</h4>
1843   
1844      <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>
1845   
1846      <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>
1847   
1848      <h4>Language Tag:</h4>
1849   
1850      <p>The <abbr title="Internet Engineering Task Force">IETF</abbr> recently published <a href="http://tools.ietf.org/html/rfc4646">RFC 4646</a> for tags used to identify languages, which in combination with <a href="http://tools.ietf.org/html/rfc4647">RFC 4647</a> obseletes the older <a href="http://tools.ietf.org/html/rfc3066">RFC 3006</a> and older-still <a href="http://tools.ietf.org/html/rfc1766">RFC 1766</a>. <a href="http://tools.ietf.org/html/rfc4646">RFC 4646</a> uses <a href="http://www.loc.gov/standards/iso639-2/php/English_list.php">ISO 639-1/ISO 639-2</a>, <a href="http://www.iso.ch/iso/en/prods-services/iso3166ma/02iso-3166-code-lists/list-en1.html">ISO 3166-1 alpha-2</a>, <a href="http://www.unicode.org/iso15924/iso15924-codes.html">ISO 15924</a> and <a href="http://unstats.un.org/unsd/methods/m49/m49.htm">UN M.49</a> to define a language tag. Each complete tag is composed of subtags which are not case sensitive and can also be empty.</p>
1851   
1852      <p>Ordering of the subtags in the case that they are all non-empty is: <code>language</code>-<code>script</code>-<code>region</code>-<code>variant</code>-<code>extension</code>-<code>privateuse</code>. Should any subtag be empty, its corresponding hyphen would also be ommited. Thus, the language tag for English will be <code>en</code> <strong>and not</strong> <code>en-----</code>.</p>
1853   
1854      <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>
1855   
1856      <table>
1857      <caption>Examples of various possible language tags as described by RFC 4646 and RFC 4647</caption>
1858      <thead>
1859      <tr>
1860          <th scope="col">Language tag</th>
1861          <th scope="col">Description</th>
1862          <th scope="col">Component subtags</th>
1863      </tr>
1864      </thead>
1865      <tbody>
1866      <tr>
1867          <td><code>en</code></td>
1868          <td>English</td>
1869          <td><code>language</code></td>
1870      </tr>
1871      <tr>
1872          <td><code>mas</code></td>
1873          <td>Masai</td>
1874          <td><code>language</code></td>
1875      </tr>
1876      <tr>
1877          <td><code>fr-CA</code></td>
1878          <td>French as used in Canada</td>
1879          <td><code>language</code>+<code>region</code></td>
1880      </tr>
1881      <tr>
1882          <td><code>en-833</code></td>
1883          <td>English as used in the Isle of Man</td>
1884          <td><code>language</code>+<code>region</code></td>
1885      </tr>
1886      <tr>
1887          <td><code>zh-Hans</code></td>
1888          <td>Chinese written with Simplified script</td>
1889          <td><code>language</code>+<code>script</code></td>
1890      </tr>
1891      <tr>
1892          <td><code>zh-Hant-HK</code></td>
1893          <td>Chinese written with Traditional script as used in Hong Kong</td>
1894          <td><code>language</code>+<code>script</code>+<code>region</code></td>
1895      </tr>
1896      <tr>
1897          <td><code>de-AT-1996</code></td>
1898          <td>German as used in Austria with 1996 orthography</td>
1899          <td><code>language</code>+<code>region</code>+<code>variant</code></td>
1900      </tr>
1901      </tbody>
1902      </table>
1903   
1904      <p>The ultimate aim of a language tag is to convey the needed <strong>useful distingushing information</strong>, whilst keeping it as <strong>short as possible</strong>. So for example, use <code>en</code>, <code>fr</code> and <code>ja</code> as opposed to <code>en-GB</code>, <code>fr-FR</code> and <code>ja-JP</code>, since we know English, French and Japanese are the native language of Great Britain, France and Japan respectively.</p>
1905   
1906      <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>
1907   
1908      <table>
1909      <caption>Examples of using a language subtag in combination with a script subtag</caption>
1910      <thead>
1911      <tr>
1912          <th scope="col">Language tag</th>
1913          <th scope="col">Description</th>
1914          <th scope="col">Component subtags</th>
1915      </tr>
1916      </thead>
1917      <tbody>
1918      <tr>
1919          <td><code>en-Brai</code></td>
1920          <td>English written in Braille script</td>
1921          <td><code>language</code>+<code>script</code></td>
1922      </tr>
1923      <tr>
1924          <td><code>en-Dsrt</code></td>
1925          <td>English written in Deseret (Mormon) script</td>
1926          <td><code>language</code>+<code>script</code></td>
1927      </tr>
1928      <tr>
1929          <td><code>sr-Latn</code></td>
1930          <td>Serbian written in Latin script</td>
1931          <td><code>language</code>+<code>script</code></td>
1932      </tr>
1933      <tr>
1934          <td><code>sr-Cyrl</code></td>
1935          <td>Serbian written in Cyrillic script</td>
1936          <td><code>language</code>+<code>script</code></td>
1937      </tr>
1938      <tr>
1939          <td><code>mn-Mong</code></td>
1940          <td>Mongolian written in Mongolian script</td>
1941          <td><code>language</code>+<code>script</code></td>
1942      </tr>
1943      <tr>
1944          <td><code>mn-Cyrl</code></td>
1945          <td>Mongolian written in Cyrillic script</td>
1946          <td><code>language</code>+<code>script</code></td>
1947      </tr>
1948      <tr>
1949          <td><code>mn-Phag</code></td>
1950          <td>Mongolian written in Phags-pa script</td>
1951          <td><code>language</code>+<code>script</code></td>
1952      </tr>
1953      <tr>
1954          <td><code>az-Cyrl-AZ</code></td>
1955          <td>Azerbaijani written in Cyrillic script as used in Azerbaijan</td>
1956          <td><code>language</code>+<code>script</code>+<code>region</code></td>
1957      </tr>
1958      <tr>
1959          <td><code>az-Latn-AZ</code></td>
1960          <td>Azerbaijani written in Latin script as used in Azerbaijan</td>
1961          <td><code>language</code>+<code>script</code>+<code>region</code></td>
1962      </tr>
1963      <tr>
1964          <td><code>az-Arab-IR</code></td>
1965          <td>Azerbaijani written in Arabic script as used in Iran</td>
1966          <td><code>language</code>+<code>script</code>+<code>region</code></td>
1967      </tr>
1968      </tbody>
1969      </table>
1970   
1971      <p>Usage of the three-digit <a href="http://unstats.un.org/unsd/methods/m49/m49.htm">UN M.49</a> code over the two-letter <a href="http://www.iso.ch/iso/en/prods-services/iso3166ma/02iso-3166-code-lists/list-en1.html">ISO 3166-1 alpha-2</a> code should hapen if a macro-geographical entity is required and/or 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.</p>
1972   
1973      <p>Examples of English using marco-geographical regions:</p>
1974   
1975      <table>
1976      <caption>Coding for English using macro-geographical regions (examples for English of ISO 3166-1 alpha-2 vs. UN M.49 code)</caption>
1977      <thead>
1978      <tr>
1979          <th scope="col">ISO 639-1/ISO 639-2 + ISO 3166-1 alpha-2</th>
1980          <th scope="col" colspan="2">ISO 639-1/ISO 639-2 + UN M.49 (Example macro regions)</th>
1981      </tr>
1982      </thead>
1983      <tbody>
1984      <tr>
1985          <td><dl><dt><code>en-AU</code></dt><dd>English as used in <strong>Australia</strong></dd></dl></td>
1986          <td rowspan="2"><dl><dt><code>en-053</code></dt><dd>English as used in <strong>Australia &amp; New Zealand</strong></dd></dl></td>
1987          <td rowspan="3"><dl><dt><code>en-009</code></dt><dd>English as used in <strong>Oceania</strong></dd></dl></td>
1988      </tr>
1989      <tr>
1990          <td><dl><dt><code>en-NZ</code></dt><dd>English as used in <strong>New Zealand</strong></dd></dl></td>
1991      </tr>
1992      <tr>
1993          <td><dl><dt><code>en-FJ</code></dt><dd>English as used in <strong>Fiji</strong></dd></dl></td>
1994          <td><dl><dt><code>en-054 </code></dt><dd>English as used in <strong>Melanesia</strong></dd></dl></td>
1995      </tr>
1996      </tbody>
1997      </table>
1998   
1999      <p>Examples of Spanish using marco-geographical regions:</p>
2000   
2001      <table>
2002      <caption>Coding for Spanish macro-geographical regions (examples for Spanish of ISO 3166-1 alpha-2 vs. UN M.49 code)</caption>
2003      <thead>
2004      <tr>
2005          <th scope="col">ISO 639-1/ISO 639-2 + ISO 3166-1 alpha-2</th>
2006          <th scope="col" colspan="2">ISO 639-1/ISO 639-2 + UN M.49 (Example macro regions)</th>
2007      </tr>
2008      </thead>
2009      <tbody>
2010      <tr>
2011          <td><dl><dt><code>es-PR</code></dt><dd>Spanish as used in <strong>Puerto Rico</strong></dd></dl></td>
2012          <td rowspan="3"><dl><dt><code>es-419</code></dt><dd>Spanish as used in <strong>Latin America &amp; the Caribbean</strong></dd></dl></td>
2013          <td rowspan="4"><dl><dt><code>es-019</code></dt><dd>Spanish as used in <strong>the Americas</strong></dd></dl></td>
2014      </tr>
2015      <tr>
2016          <td><dl><dt><code>es-HN</code></dt><dd>Spanish as used in <strong>Honduras</strong></dd></dl></td>
2017      </tr>
2018      <tr>
2019          <td><dl><dt><code>es-AR</code></dt><dd>Spanish as used in <strong>Argentina</strong></dd></dl></td>
2020      </tr>
2021      <tr>
2022          <td><dl><dt><code>es-US</code></dt><dd>Spanish as used in <strong>United States of America</strong></dd></dl></td>
2023          <td><dl><dt><code>es-021</code></dt><dd>Spanish as used in <strong>North America</strong></dd></dl></td>
2024      </tr>
2025      </tbody>
2026      </table>
2027   
2028      <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>
2029   
2030      <table>
2031      <caption>Coding for ambiguous ISO 3166-1 alpha-2 regions</caption>
2032      <thead>
2033      <tr>
2034          <th scope="col" colspan="2"><code>CS</code> assignment pre-1994</th>
2035          <th scope="col" colspan="2"><code>CS</code> assignment post-1994</th>
2036      </tr>
2037      </thead>
2038      <tbody>
2039      <tr>
2040          <td colspan="2">
2041          <dl>
2042          <dt><code>CS</code></dt><dd><strong>Czechoslovakia</strong> (ISO 3166-1)</dd>
2043          <dt><code>200</code></dt><dd><strong>Czechoslovakia</strong> (UN M.49)</dd>
2044          </dl>
2045          </td>
2046          <td colspan="2">
2047          <dl>
2048          <dt><code>CS</code></dt><dd><strong>Serbian &amp; Montenegro</strong> (ISO 3166-1)</dd>
2049          <dt><code>891</code></dt><dd><strong>Serbian &amp; Montenegro</strong> (UN M.49)</dd>
2050          </dl>
2051          </td>
2052      </tr>
2053      <tr>
2054          <td>
2055          <dl>
2056          <dt><code>CZ</code></dt><dd><strong>Czech Republic</strong> (ISO 3166-1)</dd>
2057          <dt><code>203</code></dt><dd><strong>Czech Republic</strong> (UN M.49)</dd>
2058          </dl>
2059          </td>
2060          <td>
2061          <dl>
2062          <dt><code>SK</code></dt><dd><strong>Slovakia</strong> (ISO 3166-1)</dd>
2063          <dt><code>703</code></dt><dd><strong>Slovakia</strong> (UN M.49)</dd>
2064          </dl>
2065          </td>
2066          <td>
2067          <dl>
2068          <dt><code>RS</code></dt><dd><strong>Serbia</strong> (ISO 3166-1)</dd>
2069          <dt><code>688</code></dt><dd><strong>Serbia</strong> (UN M.49)</dd>
2070          </dl>
2071          </td>
2072          <td>
2073          <dl>
2074          <dt><code>ME</code></dt><dd><strong>Montenegro</strong> (ISO 3166-1)</dd>
2075          <dt><code>499</code></dt><dd><strong>Montenegro</strong> (UN M.49)</dd>
2076          </dl>
2077          </td>
2078      </tr>
2079      </tbody>
2080      </table>
2081   
2082      <h4>Macro-languages &amp; Topolects:</h4>
2083   
2084      <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>
2085   
2086      <table>
2087      <caption>Macrolanguage subtag + sub-language subtag examples</caption>
2088      <thead>
2089      <tr>
2090          <th scope="col">Language tag</th>
2091          <th scope="col">Description</th>
2092          <th scope="col">Component subtags</th>
2093      </tr>
2094      </thead>
2095      <tbody>
2096      <tr>
2097          <td><code>zh-cmn</code></td>
2098          <td>Mandarin (Putonghau/Guoyu) Chinese</td>
2099          <td><code>macrolanguage</code>+<code>sublanguage</code></td>
2100      </tr>
2101      <tr>
2102          <td><code>zh-yue</code></td>
2103          <td>Yue (Cantonese) Chinese</td>
2104          <td><code>macrolanguage</code>+<code>sublanguage</code></td>
2105      </tr>
2106      <tr>
2107          <td><code>zh-cmn-Hans</code></td>
2108          <td>Mandarin (Putonghau/Guoyu) Chinese written in Simplified script</td>
2109          <td><code>macrolanguage</code>+<code>sublanguage</code>+<code>script</code></td>
2110      </tr>
2111      <tr>
2112          <td><code>zh-cmn-Hant</code></td>
2113          <td>Mandarin (Putonghau/Guoyu) Chinese written in Traditional script</td>
2114          <td><code>macrolanguage</code>+<code>sublanguage</code>+<code>script</code></td>
2115      </tr>
2116      <tr>
2117          <td><code>zh-nan-Latn-TW</code></td>
2118          <td>Minnan (Hoklo) Chinese written in Latin script (POJ Romanisation) as used in Taiwan</td>
2119          <td><code>macrolanguage</code>+<code>sublanguage</code>+<code>script</code>+<code>region</code></td>
2120      </tr>
2121      </tbody>
2122      </table>
2123   
2124      <a name="otherconsiderations"></a><h3>6.ii. Other considerations</h3>
2125   
2126      <h4>Normalisation of language tags for phpBB:</h4>
2127   
2128      <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>
2129   
2130      <table>
2131      <caption>Language tag normalisation examples</caption>
2132      <thead>
2133      <tr>
2134          <th scope="col">Raw language tag</th>
2135          <th scope="col">Description</th>
2136          <th scope="col">Value of <code>USER_LANG</code><br />in <code>./common.php</code></th>
2137          <th scope="col">Language pack directory<br />name in <code>/language/</code></th>
2138      </tr>
2139      </thead>
2140      <tbody>
2141      <tr>
2142          <td><code>en</code></td>
2143          <td>British English</td>
2144          <td><code>en</code></td>
2145          <td><code>en</code></td>
2146      </tr>
2147      <tr>
2148          <td><code>de-AT</code></td>
2149          <td>German as used in Austria</td>
2150          <td><code>de-at</code></td>
2151          <td><code>de_at</code></td>
2152      </tr>
2153      <tr>
2154          <td><code>es-419</code></td>
2155          <td>Spanish as used in Latin America &amp; Caribbean</td>
2156          <td><code>en-419</code></td>
2157          <td><code>en_419</code></td>
2158      </tr>
2159      <tr>
2160          <td><code>zh-yue-Hant-HK</code></td>
2161          <td>Cantonese written in Traditional script as used in Hong Kong</td>
2162          <td><code>zh-yue-hant-hk</code></td>
2163          <td><code>zh_yue_hant_hk</code></td>
2164      </tr>
2165      </tbody>
2166      </table>
2167   
2168      <h4>How to use <code>iso.txt</code>:</h4>
2169   
2170      <p>The <code>iso.txt</code> file is a small UTF-8 encoded plain-text file which consists of three lines:</p>
2171   
2172      <ol>
2173          <li><code>Language's English name</code></li>
2174          <li><code>Language's local name</code></li>
2175          <li><code>Authors information</code></li>
2176      </ol>
2177   
2178      <p><code>iso.txt</code> is automatically generated by the language pack submission system on phpBB.com. You don't have to create this file yourself if you plan on releasing your language pack on phpBB.com, but do keep in mind that phpBB itself does require this file to be present.</p>
2179   
2180      <p>Because language tags themselves are meant to be machine read, they can be rather obtuse to humans and why descriptive strings as provided by <code>iso.txt</code> are needed. Whilst <code>en-US</code> could be fairly easily deduced to be "English as used in the United States", <code>de-CH</code> is more difficult less one happens to know that <code>de</code> is from "<span lang="de">Deutsch</span>", German for "German" and <code>CH</code> is the abbreviation of the official Latin name for Switzerland, "<span lang="la">Confoederatio Helvetica</span>".</p>
2181   
2182      <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>
2183   
2184      <table>
2185      <caption>English language description examples for iso.txt</caption>
2186      <thead>
2187      <tr>
2188          <th scope="col">Raw language tag</th>
2189          <th scope="col">English description within <code>iso.txt</code></th>
2190      </tr>
2191      </thead>
2192      <tbody>
2193      <tr>
2194          <td><code>en</code></td>
2195          <td>British English</td>
2196      </tr>
2197      <tr>
2198          <td><code>en-US</code></td>
2199          <td>English (United States)</td>
2200      </tr>
2201      <tr>
2202          <td><code>en-053</code></td>
2203          <td>English (Australia &amp; New Zealand)</td>
2204      </tr>
2205      <tr>
2206          <td><code>de</code></td>
2207          <td>German</td>
2208      </tr>
2209      <tr>
2210          <td><code>de-CH-1996</code></td>
2211          <td>German (Switzerland, 1996 orthography)</td>
2212      </tr>
2213      <tr>
2214          <td><code>gws-1996</code></td>
2215          <td>Swiss German (1996 orthography)</td>
2216      </tr>
2217      <tr>
2218          <td><code>zh-cmn-Hans-CN</code></td>
2219          <td>Mandarin Chinese (Simplified, Mainland China)</td>
2220      </tr>
2221      <tr>
2222          <td><code>zh-yue-Hant-HK</code></td>
2223          <td>Cantonese Chinese (Traditional, Hong Kong)</td>
2224      </tr>
2225      </tbody>
2226      </table>
2227   
2228      <p>For the localised language description, just translate the English version though use whatever appropriate punctuation typical for your own locale, assuming the language uses punctuation at all.</p>
2229   
2230      <h4>Unicode bi-directional considerations:</h4>
2231   
2232      <p>Because phpBB is now UTF-8, all translators must take into account that certain strings may be shown when the directionality of the document is either opposite to normal or is ambiguous.</p>
2233   
2234      <p>The various Unicode control characters for bi-directional text and their HTML enquivalents where appropriate are as follows:</p>
2235   
2236      <table>
2237      <caption>Unicode bidirectional control characters &amp; HTML elements/entities</caption>
2238      <thead>
2239      <tr>
2240          <th scope="col">Unicode character<br />abbreviation</th>
2241          <th scope="col">Unicode<br />code-point</th>
2242          <th scope="col">Unicode character<br />name</th>
2243          <th scope="col">Equivalent HTML<br />markup/entity</th>
2244          <th scope="col">Raw character<br />(enclosed between '')</th>
2245      </tr>
2246      </thead>
2247      <tbody>
2248      <tr>
2249          <td><code>LRM</code></td>
2250          <td><code>U+200E</code></td>
2251          <td>Left-to-Right Mark</td>
2252          <td><code>&amp;lrm;</code></td>
2253          <td>'&#x200E;'</td>
2254      </tr>
2255      <tr>
2256          <td><code>RLM</code></td>
2257          <td><code>U+200F</code></td>
2258          <td>Right-to-Left Mark</td>
2259          <td><code>&amp;rlm;</code></td>
2260          <td>'&#x200F;'</td>
2261      </tr>
2262      <tr>
2263          <td><code>LRE</code></td>
2264          <td><code>U+202A</code></td>
2265          <td>Left-to-Right Embedding</td>
2266          <td><code>dir=&quot;ltr&quot;</code></td>
2267          <td>'&#x202A;'</td>
2268      </tr>
2269      <tr>
2270          <td><code>RLE</code></td>
2271          <td><code>U+202B</code></td>
2272          <td>Right-to-Left Embedding</td>
2273          <td><code>dir=&quot;rtl&quot;</code></td>
2274          <td>'&#x202B;'</td>
2275      </tr>
2276      <tr>
2277          <td><code>PDF</code></td>
2278          <td><code>U+202C</code></td>
2279          <td>Pop Directional Formatting</td>
2280          <td><code>&lt;/bdo&gt;</code></td>
2281          <td>'&#x202C;'</td>
2282      </tr>
2283      <tr>
2284          <td><code>LRO</code></td>
2285          <td><code>U+202D</code></td>
2286          <td>Left-to-Right Override</td>
2287          <td><code>&lt;bdo dir=&quot;ltr&quot;&gt;</code></td>
2288          <td>'&#x202D;'</td>
2289      </tr>
2290      <tr>
2291          <td><code>RLO</code></td>
2292          <td><code>U+202E</code></td>
2293          <td>Right-to-Left Override</td>
2294          <td><code>&lt;bdo dir=&quot;rtl&quot;&gt;</code></td>
2295          <td>'&#x202E;'</td>
2296      </tr>
2297      </tbody>
2298      </table>
2299   
2300      <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>
2301   
2302      <table>
2303      <caption>Unicode bidirectional control characters iso.txt</caption>
2304      <thead>
2305      <tr>
2306          <th scope="col">Directionality</th>
2307          <th scope="col">Raw character view</th>
2308          <th scope="col">Display of localised<br />description in <code>iso.txt</code></th>
2309          <th scope="col">Ordering</th>
2310      </tr>
2311      </thead>
2312      <tbody>
2313      <tr>
2314          <td><code>dir=&quot;ltr&quot;</code></td>
2315          <td>English (Australia &amp; New Zealand)</td>
2316          <td dir="ltr">English (Australia &amp; New Zealand)</td>
2317          <td class="good">Correct</td>
2318      </tr>
2319      <tr>
2320          <td><code>dir=&quot;rtl&quot;</code></td>
2321          <td>English (Australia &amp; New Zealand)</td>
2322          <td dir="rtl">English (Australia &amp; New Zealand)</td>
2323          <td class="bad">Incorrect</td>
2324      </tr>
2325      <tr>
2326          <td><code>dir=&quot;rtl&quot;</code> with <code>LRM</code></td>
2327          <td>English (Australia &amp; New Zealand)<code>U+200E</code></td>
2328          <td dir="rtl">English (Australia &amp; New Zealand)&#x200E;</td>
2329          <td class="good">Correct</td>
2330      </tr>
2331      <tr>
2332          <td><code>dir=&quot;rtl&quot;</code> with <code>LRE</code> &amp; <code>PDF</code></td>
2333          <td><code>U+202A</code>English (Australia &amp; New Zealand)<code>U+202C</code></td>
2334          <td dir="rtl">&#x202A;English (Australia &amp; New Zealand)&#x202C;</td>
2335          <td class="good">Correct</td>
2336      </tr>
2337      <tr>
2338          <td><code>dir=&quot;rtl&quot;</code> with <code>LRO</code> &amp; <code>PDF</code></td>
2339          <td><code>U+202D</code>English (Australia &amp; New Zealand)<code>U+202C</code></td>
2340          <td dir="rtl">&#x202D;English (Australia &amp; New Zealand)&#x202C;</td>
2341          <td class="good">Correct</td>
2342      </tr>
2343      </tbody>
2344      </table>
2345   
2346      <p>In choosing which of the three methods to use, in the majority of cases, the <code>LRM</code> or <code>RLM</code> to put a &quot;strong&quot; character to fully enclose an ambiguous punctuation character and thus make it inherit the correct directionality is sufficient.</p>
2347      <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>
2348      <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>
2349   
2350      <a name="placeholders"></a><h3>6.iii. Working with placeholders</h3>
2351   
2352      <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>
2353   
2354      <div class="codebox"><pre>
2355      ...
2356  'PAGE_OF'    =&gt;    'Page %s of %s',
2357          /* Just grabbing the replacements as they
2358          come and hope they are in the right order */
2359      ...
2360      </pre></div>
2361   
2362      <p>&hellip; a clearer way to show explicit replacement ordering is to do:</p>
2363   
2364      <div class="codebox"><pre>
2365      ...
2366  'PAGE_OF'    =&gt;    'Page %1$s of %2$s',
2367          /* Explicit ordering of the replacements,
2368          even if they are the same order as English */
2369      ...
2370      </pre></div>
2371   
2372      <p>Why bother at all? Because some languages, the string transliterated back to English might read something like:</p>
2373   
2374      <div class="codebox"><pre>
2375      ...
2376  'PAGE_OF'    =&gt;    'Total of %2$s pages, currently on page %1$s',
2377          /* Explicit ordering of the replacements,
2378          reversed compared to English as the total comes first */
2379      ...
2380      </pre></div>
2381   
2382      <a name="usingplurals"></a><h3>6.iv. Using plurals</h3>
2383   
2384      <p>
2385          The english language is very simple when it comes to plurals.<br />
2386          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 />
2387          But for some other languages this is quite more difficult. Let's take the Bosnian language as another example:<br />
2388          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.
2389      </p>
2390   
2391      <p>The <a href="https://wiki.phpbb.com/Plural_Rules">plural system</a> takes care of this and can be used as follows:</p>
2392   
2393      <p>The PHP code will basically look like this:</p>
2394   
2395      <div class="codebox"><pre>
2396      ...
2397      $user->lang('NUMBER_OF_ELEPHANTS', $number_of_elephants);
2398      ...
2399      </pre></div>
2400   
2401      <p>And the English translation would be:</p>
2402   
2403      <div class="codebox"><pre>
2404      ...
2405      'NUMBER_OF_ELEPHANTS'    => array(
2406          0    => 'You have no elephants', // Optional special case for 0
2407          1    => 'You have 1 elephant', // Singular
2408          2    => 'You have %d elephants', // Plural
2409      ),
2410      ...
2411      </pre></div>
2412   
2413      <p>While the Bosnian translation can have more cases:</p>
2414   
2415      <div class="codebox"><pre>
2416      ...
2417      'NUMBER_OF_ELEPHANTS'    => array(
2418          0    => 'You have no slonova', // Optional special case for 0
2419          1    => 'You have %d slon', // Used for 1, 21, 31, ..
2420          2    => 'You have %d slona', // Used for 5, 6,
2421          3    => ...
2422      ),
2423      ...
2424      </pre></div>
2425   
2426      <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>
2427      <div class="codebox"><pre>
2428      ...
2429      'MODERATOR'    => 'Moderator',  // Your board has 1 moderator
2430      'MODERATORS'    => 'Moderators', // Your board has multiple moderators
2431      ...
2432      </pre></div>
2433   
2434      <a name="writingstyle"></a><h3>6.v. Writing Style</h3>
2435   
2436      <h4>Miscellaneous tips &amp; hints:</h4>
2437   
2438      <p>As the language files are PHP files, where the various strings for phpBB are stored within an array which in turn are used for display within an HTML page, rules of syntax for both must be considered. Potentially problematic characters are: <code>'</code> (straight quote/apostrophe), <code>&quot;</code> (straight double quote), <code>&lt;</code> (less-than sign), <code>&gt;</code> (greater-than sign) and <code>&amp;</code> (ampersand).</p>
2439   
2440      <p class="bad">// Bad - The un-escapsed straight-quote/apostrophe will throw a PHP parse error</p>
2441   
2442      <div class="codebox"><pre>
2443      ...
2444  'CONV_ERROR_NO_AVATAR_PATH'
2445      =&gt;    'Note to developer: you must specify $convertor['avatar_path'] to use %s.',
2446      ...
2447      </pre></div>
2448   
2449      <p class="good">// Good - Literal straight quotes should be escaped with a backslash, ie: \</p>
2450   
2451      <div class="codebox"><pre>
2452      ...
2453  'CONV_ERROR_NO_AVATAR_PATH'
2454      =&gt;    'Note to developer: you must specify $convertor[\'avatar_path\'] to use %s.',
2455      ...
2456      </pre></div>
2457   
2458      <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>
2459   
2460      <p class="bad">// Bad - The un-escapsed straight-quote/apostrophe will throw a PHP parse error</p>
2461   
2462      <div class="codebox"><pre>
2463      ...
2464  'USE_PERMISSIONS'    =&gt;    'Test out user's permissions',
2465      ...
2466      </pre></div>
2467   
2468      <p class="good">// Okay - However, non-programmers wouldn't type "user\'s" automatically</p>
2469   
2470      <div class="codebox"><pre>
2471      ...
2472  'USE_PERMISSIONS'    =&gt;    'Test out user\'s permissions',
2473      ...
2474      </pre></div>
2475   
2476      <p class="good">// Best - Use the Unicode Right-Single-Quotation-Mark character</p>
2477   
2478      <div class="codebox"><pre>
2479      ...
2480  'USE_PERMISSIONS'    =&gt;    'Test out user&rsquo;s permissions',
2481      ...
2482      </pre></div>
2483   
2484      <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>
2485   
2486      <p class="bad">// Bad - Invalid HTML, as segments not part of elements are not entitised</p>
2487   
2488      <div class="codebox"><pre>
2489      ...
2490  'FOO_BAR'    =&gt;    'PHP version &lt; 5.3.3.&lt;br /&gt;
2491      Visit &quot;Downloads&quot; at &lt;a href=&quot;http://www.php.net/&quot;&gt;www.php.net&lt;/a&gt;.',
2492      ...
2493      </pre></div>
2494   
2495      <p class="good">// Okay - No more invalid HTML, but &quot;&amp;quot;&quot; is rather clumsy</p>
2496   
2497      <div class="codebox"><pre>
2498      ...
2499  'FOO_BAR'    =&gt;    'PHP version &amp;lt; 5.3.3.&lt;br /&gt;
2500      Visit &amp;quot;Downloads&amp;quot; at &lt;a href=&quot;http://www.php.net/&quot;&gt;www.php.net&lt;/a&gt;.',
2501      ...
2502      </pre></div>
2503   
2504      <p class="good">// Best - No more invalid HTML, and usage of correct typographical quotation marks</p>
2505   
2506      <div class="codebox"><pre>
2507      ...
2508  'FOO_BAR'    =&gt;    'PHP version &amp;lt; 5.3.3.&lt;br /&gt;
2509      Visit &ldquo;Downloads&rdquo; at &lt;a href=&quot;http://www.php.net/&quot;&gt;www.php.net&lt;/a&gt;.',
2510      ...
2511      </pre></div>
2512   
2513      <p>Lastly, the <code>&amp;</code> (ampersand) must always be entitised regardless of where it is used:</p>
2514   
2515      <p class="bad">// Bad - Invalid HTML, none of the ampersands are entitised</p>
2516   
2517      <div class="codebox"><pre>
2518      ...
2519  'FOO_BAR'    =&gt;    '&lt;a href=&quot;http://somedomain.tld/?foo=1&amp;bar=2&quot;&gt;Foo &amp; Bar&lt;/a&gt;.',
2520      ...
2521      </pre></div>
2522   
2523      <p class="good">// Good - Valid HTML, amperands are correctly entitised in all cases</p>
2524   
2525      <div class="codebox"><pre>
2526      ...
2527  '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;.',
2528      ...
2529      </pre></div>
2530   
2531      <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>
2532   
2533      <h4>Spelling, punctuation, grammar, et cetera:</h4>
2534   
2535      <p>The default language pack bundled with phpBB is <strong>British English</strong> using <a href="http://www.cambridge.org/">Cambridge University Press</a> spelling and is assigned the language code <code>en</code>. The style and tone of writing tends towards formal and translations <strong>should</strong> emulate this style, at least for the variant using the most compact language code. Less formal translations or those with colloquialisms <strong>must</strong> be denoted as such via either an <code>extension</code> or <code>privateuse</code> tag within its language code.</p>
2536   
2537          </div>
2538   
2539          <div class="back2top"><a href="#wrap" class="top">Back to Top</a></div>
2540   
2541          <span class="corners-bottom"><span></span></span></div>
2542      </div>
2543   
2544      <hr />
2545   
2546  <a name="disclaimer"></a><h2>7. Copyright and disclaimer</h2>
2547   
2548      <div class="paragraph">
2549          <div class="inner"><span class="corners-top"><span></span></span>
2550   
2551          <div class="content">
2552   
2553      <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>
2554   
2555          </div>
2556   
2557          <div class="back2top"><a href="#wrap" class="top">Back to Top</a></div>
2558   
2559          <span class="corners-bottom"><span></span></span></div>
2560      </div>
2561   
2562  <!-- END DOCUMENT -->
2563   
2564      <div id="page-footer">
2565          <div class="version">&nbsp;</div>
2566      </div>
2567  </div></div>
2568   
2569  <div>
2570      <a id="bottom" name="bottom" accesskey="z"></a>
2571  </div>
2572   
2573  </body>
2574  </html>
2575