1 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
---|
2 | <html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en" xml:lang="en">
|
---|
3 | <head>
|
---|
4 |
|
---|
5 | <meta http-equiv="content-type" content="text/html; charset=utf-8" />
|
---|
6 | <meta http-equiv="content-style-type" content="text/css" />
|
---|
7 | <meta http-equiv="content-language" content="en" />
|
---|
8 | <meta http-equiv="imagetoolbar" content="no" />
|
---|
9 | <meta name="resource-type" content="document" />
|
---|
10 | <meta name="distribution" content="global" />
|
---|
11 | <meta name="copyright" content="2007 phpBB Group" />
|
---|
12 | <meta name="keywords" content="" />
|
---|
13 | <meta name="description" content="Olympus coding guidelines document" />
|
---|
14 | <title>phpBB3 • Coding Guidelines</title>
|
---|
15 |
|
---|
16 | <link href="stylesheet.css" rel="stylesheet" type="text/css" media="screen, projection" />
|
---|
17 |
|
---|
18 | </head>
|
---|
19 |
|
---|
20 | <body id="phpbb" class="section-docs">
|
---|
21 |
|
---|
22 | <div id="wrap">
|
---|
23 | <a id="top" name="top" accesskey="t"></a>
|
---|
24 | <div id="page-header">
|
---|
25 | <div class="headerbar">
|
---|
26 | <div class="inner"><span class="corners-top"><span></span></span>
|
---|
27 |
|
---|
28 | <div id="doc-description">
|
---|
29 | <a href="../index.php" id="logo"><img src="site_logo.gif" alt="" /></a>
|
---|
30 | <h1>Coding Guidelines</h1>
|
---|
31 | <p>Olympus coding guidelines document</p>
|
---|
32 | <p style="display: none;"><a href="#start_here">Skip</a></p>
|
---|
33 | </div>
|
---|
34 |
|
---|
35 | <span class="corners-bottom"><span></span></span></div>
|
---|
36 | </div>
|
---|
37 | </div>
|
---|
38 |
|
---|
39 | <a name="start_here"></a>
|
---|
40 |
|
---|
41 | <div id="page-body">
|
---|
42 |
|
---|
43 | <!-- BEGIN DOCUMENT -->
|
---|
44 |
|
---|
45 | <p>These are the phpBB Coding Guidelines for Olympus, all attempts should be made to follow them as closely as possible.</p>
|
---|
46 |
|
---|
47 | <h1>Coding Guidelines</h1>
|
---|
48 |
|
---|
49 | <div class="paragraph menu">
|
---|
50 | <div class="inner"><span class="corners-top"><span></span></span>
|
---|
51 |
|
---|
52 | <div class="content">
|
---|
53 |
|
---|
54 | <ol>
|
---|
55 | <li><a href="#defaults">Defaults</a>
|
---|
56 | <ol style="list-style-type: lower-roman;">
|
---|
57 | <li><a href="#editorsettings">Editor Settings</a></li>
|
---|
58 | <li><a href="#fileheader">File Header</a></li>
|
---|
59 | <li><a href="#locations">File Locations</a></li>
|
---|
60 | <li><a href="#constants">Special Constants</a></li>
|
---|
61 | </ol>
|
---|
62 | </li>
|
---|
63 | <li><a href="#code">Code Layout/Guidelines</a>
|
---|
64 | <ol style="list-style-type: lower-roman;">
|
---|
65 | <li><a href="#namingvars">Variable/Function Naming</a></li>
|
---|
66 | <li><a href="#codelayout">Code Layout</a></li>
|
---|
67 | <li><a href="#sql">SQL/SQL Layout</a></li>
|
---|
68 | <li><a href="#optimizing">Optimizations</a></li>
|
---|
69 | <li><a href="#general">General Guidelines</a></li>
|
---|
70 | </ol>
|
---|
71 | </li>
|
---|
72 | <li><a href="#styling">Styling</a>
|
---|
73 | <ol style="list-style-type: lower-roman;">
|
---|
74 | <li><a href="#cfgfiles">Style Config Files</a></li>
|
---|
75 | <li><a href="#genstyling">General Styling Rules</a></li>
|
---|
76 | </ol></li>
|
---|
77 | <li><a href="#templating">Templating</a>
|
---|
78 | <ol style="list-style-type: lower-roman;">
|
---|
79 | <li><a href="#templates">General Templating</a></li>
|
---|
80 | <li><a href="#inheritance">Template Inheritance</a></li>
|
---|
81 | </ol></li>
|
---|
82 | <li><a href="#charsets">Character Sets and Encodings</a></li>
|
---|
83 | <li><a href="#translation">Translation (<abbr title="Internationalisation">i18n</abbr>/<abbr title="Localisation">L10n</abbr>) Guidelines</a>
|
---|
84 | <ol style="list-style-type: lower-roman;">
|
---|
85 | <li><a href="#standardisation">Standardisation</a></li>
|
---|
86 | <li><a href="#otherconsiderations">Other considerations</a></li>
|
---|
87 | <li><a href="#writingstyle">Writing Style</a></li>
|
---|
88 | </ol>
|
---|
89 | </li>
|
---|
90 | <li><a href="#vcs">VCS Guidelines</a>
|
---|
91 | <ol style="list-style-type: lower-roman;">
|
---|
92 | <li><a href="#repostruct">Repository structure</a></li>
|
---|
93 | <li><a href="#commitmessage">Commit messages</a></li>
|
---|
94 | </ol>
|
---|
95 | </li>
|
---|
96 | <li><a href="#changes">Guidelines Changelog</a></li>
|
---|
97 | <li><a href="#disclaimer">Copyright and disclaimer</a></li>
|
---|
98 | </ol>
|
---|
99 |
|
---|
100 | </div>
|
---|
101 |
|
---|
102 | <span class="corners-bottom"><span></span></span></div>
|
---|
103 | </div>
|
---|
104 |
|
---|
105 | <hr />
|
---|
106 |
|
---|
107 | <a name="defaults"></a><h2>1. Defaults</h2>
|
---|
108 |
|
---|
109 | <div class="paragraph">
|
---|
110 | <div class="inner"><span class="corners-top"><span></span></span>
|
---|
111 |
|
---|
112 | <div class="content">
|
---|
113 |
|
---|
114 | <a name="editorsettings"></a><h3>1.i. Editor Settings</h3>
|
---|
115 |
|
---|
116 | <h4>Tabs vs Spaces:</h4>
|
---|
117 | <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>
|
---|
118 | <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>
|
---|
119 |
|
---|
120 | <div class="codebox"><pre>
|
---|
121 | {TAB}$mode{TAB}{TAB}= request_var('mode', '');
|
---|
122 | {TAB}$search_id{TAB}= request_var('search_id', '');
|
---|
123 | </pre></div>
|
---|
124 |
|
---|
125 | <p>If entered with tabs (replace the {TAB}) both equal signs need to be on the same column.</p>
|
---|
126 |
|
---|
127 | <h3>Linefeeds:</h3>
|
---|
128 | <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>
|
---|
129 |
|
---|
130 | <a name="fileheader"></a><h3>1.ii. File Header</h3>
|
---|
131 |
|
---|
132 | <h4>Standard header for new files:</h4>
|
---|
133 | <p>This template of the header must be included at the start of all phpBB files: </p>
|
---|
134 |
|
---|
135 | <div class="codebox"><pre>
|
---|
136 | /**
|
---|
137 | *
|
---|
138 | * @package {PACKAGENAME}
|
---|
139 | * @version $Id: $
|
---|
140 | * @copyright (c) 2007 phpBB Group
|
---|
141 | * @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
---|
142 | *
|
---|
143 | */
|
---|
144 | </pre></div>
|
---|
145 |
|
---|
146 | <p>Please see the <a href="#locations">File Locations section</a> for the correct package name.</p>
|
---|
147 |
|
---|
148 | <h4>Files containing inline code:</h4>
|
---|
149 |
|
---|
150 | <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>
|
---|
151 |
|
---|
152 | <div class="codebox"><pre>
|
---|
153 | /**
|
---|
154 | * {HEADER}
|
---|
155 | */
|
---|
156 |
|
---|
157 | /**
|
---|
158 | */
|
---|
159 | {CODE}
|
---|
160 | </pre></div>
|
---|
161 |
|
---|
162 | <h4>Files containing only functions:</h4>
|
---|
163 |
|
---|
164 | <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>
|
---|
165 |
|
---|
166 | <h4>Files containing only classes:</h4>
|
---|
167 |
|
---|
168 | <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>
|
---|
169 |
|
---|
170 | <h4>Code following the header but only functions/classes file:</h4>
|
---|
171 |
|
---|
172 | <p>If this case is true, the best method to avoid documentation confusions is adding an ignore command, for example:</p>
|
---|
173 |
|
---|
174 | <div class="codebox"><pre>
|
---|
175 | /**
|
---|
176 | * {HEADER}
|
---|
177 | */
|
---|
178 |
|
---|
179 | /**
|
---|
180 | * @ignore
|
---|
181 | */
|
---|
182 | Small code snipped, mostly one or two defines or an if statement
|
---|
183 |
|
---|
184 | /**
|
---|
185 | * {DOCUMENTATION}
|
---|
186 | */
|
---|
187 | class ...
|
---|
188 | </pre></div>
|
---|
189 |
|
---|
190 | <a name="locations"></a><h3>1.iii. File Locations</h3>
|
---|
191 |
|
---|
192 | <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 "things", user related functions and so forth.</p>
|
---|
193 |
|
---|
194 | <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>
|
---|
195 |
|
---|
196 | <ul>
|
---|
197 | <li><strong>phpBB3</strong><br />Core files and all files not assigned to a separate package</li>
|
---|
198 | <li><strong>acm</strong><br /><code>/includes/acm</code>, <code>/includes/cache.php</code><br />Cache System</li>
|
---|
199 | <li><strong>acp</strong><br /><code>/adm</code>, <code>/includes/acp</code>, <code>/includes/functions_admin.php</code><br />Administration Control Panel</li>
|
---|
200 | <li><strong>dbal</strong><br /><code>/includes/db</code><br />Database Abstraction Layer.<br />Base class is <code>dbal</code>
|
---|
201 | <ul>
|
---|
202 | <li><code>/includes/db/dbal.php</code><br />Base DBAL class, defining the overall framework</li>
|
---|
203 | <li><code>/includes/db/firebird.php</code><br />Firebird/Interbase Database Abstraction Layer</li>
|
---|
204 | <li><code>/includes/db/msssql.php</code><br />MSSQL Database Abstraction Layer</li>
|
---|
205 | <li><code>/includes/db/mssql_odbc.php</code><br />MSSQL ODBC Database Abstraction Layer for MSSQL</li>
|
---|
206 | <li><code>/includes/db/mysql.php</code><br />MySQL Database Abstraction Layer for MySQL 3.x/4.0.x/4.1.x/5.x</li>
|
---|
207 | <li><code>/includes/db/mysqli.php</code><br />MySQLi Database Abstraction Layer</li>
|
---|
208 | <li><code>/includes/db/oracle.php</code><br />Oracle Database Abstraction Layer</li>
|
---|
209 | <li><code>/includes/db/postgres.php</code><br />PostgreSQL Database Abstraction Layer</li>
|
---|
210 | <li><code>/includes/db/sqlite.php</code><br />Sqlite Database Abstraction Layer</li>
|
---|
211 | </ul>
|
---|
212 | </li>
|
---|
213 | <li><strong>diff</strong><br /><code>/includes/diff</code><br />Diff Engine</li>
|
---|
214 | <li><strong>docs</strong><br /><code>/docs</code><br />phpBB Documentation</li>
|
---|
215 | <li><strong>images</strong><br /><code>/images</code><br />All global images not connected to styles</li>
|
---|
216 | <li><strong>install</strong><br /><code>/install</code><br />Installation System</li>
|
---|
217 | <li><strong>language</strong><br /><code>/language</code><br />All language files</li>
|
---|
218 | <li><strong>login</strong><br /><code>/includes/auth</code><br />Login Authentication Plugins</li>
|
---|
219 | <li><strong>VC</strong><br /><code>/includes/captcha</code><br />CAPTCHA</li>
|
---|
220 | <li><strong>mcp</strong><br /><code>mcp.php</code>, <code>/includes/mcp</code>, <code>report.php</code><br />Moderator Control Panel</li>
|
---|
221 | <li><strong>ucp</strong><br /><code>ucp.php</code>, <code>/includes/ucp</code><br />User Control Panel</li>
|
---|
222 | <li><strong>utf</strong><br /><code>/includes/utf</code><br />UTF8-related functions/classes</li>
|
---|
223 | <li><strong>search</strong><br /><code>/includes/search</code>, <code>search.php</code><br />Search System</li>
|
---|
224 | <li><strong>styles</strong><br /><code>/styles</code>, <code>style.php</code><br />phpBB Styles/Templates/Themes/Imagesets</li>
|
---|
225 | </ul>
|
---|
226 |
|
---|
227 | <a name="constants"></a><h3>1.iv. Special Constants</h3>
|
---|
228 |
|
---|
229 | <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>
|
---|
230 |
|
---|
231 | <div class="codebox"><pre>
|
---|
232 | PHPBB_MSG_HANDLER (overwrite message handler)
|
---|
233 | PHPBB_DB_NEW_LINK (overwrite new_link parameter for sql_connect)
|
---|
234 | PHPBB_ROOT_PATH (overwrite $phpbb_root_path)
|
---|
235 | PHPBB_ADMIN_PATH (overwrite $phpbb_admin_path)
|
---|
236 | PHPBB_USE_BOARD_URL_PATH (use generate_board_url() for image paths instead of $phpbb_root_path)
|
---|
237 | PHPBB_DISABLE_ACP_EDITOR (disable ACP style editor for templates)
|
---|
238 | PHPBB_DISABLE_CONFIG_CHECK (disable ACP config.php writeable check)
|
---|
239 |
|
---|
240 | PHPBB_ACM_MEMCACHE_PORT (overwrite memcached port, default is 11211)
|
---|
241 | PHPBB_ACM_MEMCACHE_COMPRESS (overwrite memcached compress setting, default is disabled)
|
---|
242 | PHPBB_ACM_MEMCACHE_HOST (overwrite memcached host name, default is localhost)
|
---|
243 |
|
---|
244 | PHPBB_QA (Set board to QA-Mode, which means the updater also checks for RC-releases)
|
---|
245 | </pre></div>
|
---|
246 |
|
---|
247 | <h4>PHPBB_USE_BOARD_URL_PATH</h4>
|
---|
248 |
|
---|
249 | <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>
|
---|
250 |
|
---|
251 | <ul>
|
---|
252 | <li>/includes/session.php - user::img()</li>
|
---|
253 | <li>/includes/functions_content.php - smiley_text()</li>
|
---|
254 | </ul>
|
---|
255 |
|
---|
256 | <p>Path locations for the following template variables are affected by this too:</p>
|
---|
257 |
|
---|
258 | <ul>
|
---|
259 | <li>{T_THEME_PATH} - styles/xxx/theme</li>
|
---|
260 | <li>{T_TEMPLATE_PATH} - styles/xxx/template</li>
|
---|
261 | <li>{T_SUPER_TEMPLATE_PATH} - styles/xxx/template</li>
|
---|
262 | <li>{T_IMAGESET_PATH} - styles/xxx/imageset</li>
|
---|
263 | <li>{T_IMAGESET_LANG_PATH} - styles/xxx/imageset/yy</li>
|
---|
264 | <li>{T_IMAGES_PATH} - images/</li>
|
---|
265 | <li>{T_SMILIES_PATH} - $config['smilies_path']/</li>
|
---|
266 | <li>{T_AVATAR_PATH} - $config['avatar_path']/</li>
|
---|
267 | <li>{T_AVATAR_GALLERY_PATH} - $config['avatar_gallery_path']/</li>
|
---|
268 | <li>{T_ICONS_PATH} - $config['icons_path']/</li>
|
---|
269 | <li>{T_RANKS_PATH} - $config['ranks_path']/</li>
|
---|
270 | <li>{T_UPLOAD_PATH} - $config['upload_path']/</li>
|
---|
271 | <li>{T_STYLESHEET_LINK} - styles/xxx/theme/stylesheet.css (or link to style.php if css is parsed dynamically)</li>
|
---|
272 | <li>New template variable {BOARD_URL} for the board url + script path.</li>
|
---|
273 | </ul>
|
---|
274 |
|
---|
275 | </div>
|
---|
276 |
|
---|
277 | <div class="back2top"><a href="#wrap" class="top">Back to Top</a></div>
|
---|
278 |
|
---|
279 | <span class="corners-bottom"><span></span></span></div>
|
---|
280 | </div>
|
---|
281 |
|
---|
282 | <hr />
|
---|
283 |
|
---|
284 | <a name="code"></a><h2>2. Code Layout/Guidelines</h2>
|
---|
285 |
|
---|
286 | <div class="paragraph">
|
---|
287 | <div class="inner"><span class="corners-top"><span></span></span>
|
---|
288 |
|
---|
289 | <div class="content">
|
---|
290 |
|
---|
291 | <p>Please note that these Guidelines applies to all php, html, javascript and css files.</p>
|
---|
292 |
|
---|
293 | <a name="namingvars"></a><h3>2.i. Variable/Function Naming</h3>
|
---|
294 |
|
---|
295 | <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>
|
---|
296 |
|
---|
297 | <h4>Variable Names:</h4>
|
---|
298 | <p>Variable names should be in all lowercase, with words separated by an underscore, example:</p>
|
---|
299 |
|
---|
300 | <div class="indent">
|
---|
301 | <p><code>$current_user</code> is right, but <code>$currentuser</code> and <code> $currentUser</code> are not.</p>
|
---|
302 | </div>
|
---|
303 |
|
---|
304 | <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>
|
---|
305 |
|
---|
306 | <h4>Loop Indices:</h4>
|
---|
307 | <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>
|
---|
308 |
|
---|
309 | <div class="codebox"><pre>
|
---|
310 | for ($i = 0; $i < $outer_size; $i++)
|
---|
311 | {
|
---|
312 | for ($j = 0; $j < $inner_size; $j++)
|
---|
313 | {
|
---|
314 | foo($i, $j);
|
---|
315 | }
|
---|
316 | }
|
---|
317 | </pre></div>
|
---|
318 |
|
---|
319 | <h4>Function Names:</h4>
|
---|
320 | <p>Functions should also be named descriptively. We're not programming in C here, we don't want to write functions called things like "stristr()". Again, all lower-case names with words separated by a single underscore character. Function names should preferably have a verb in them somewhere. Good function names are <code>print_login_status()</code>, <code>get_user_data()</code>, etc. </p>
|
---|
321 |
|
---|
322 | <h4>Function Arguments:</h4>
|
---|
323 | <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>
|
---|
324 |
|
---|
325 | <h4>Summary:</h4>
|
---|
326 | <p>The basic philosophy here is to not hurt code clarity for the sake of laziness. This has to be balanced by a little bit of common sense, though; <code>print_login_status_for_a_given_user()</code> goes too far, for example -- that function would be better named <code>print_user_login_status()</code>, or just <code>print_login_status()</code>.</p>
|
---|
327 |
|
---|
328 | <h4>Special Namings: </h4>
|
---|
329 | <p>For all emoticons use the term <code>smiley</code> in singular and <code>smilies</code> in plural.</p>
|
---|
330 |
|
---|
331 | <a name="codelayout"></a><h3>2.ii. Code Layout</h3>
|
---|
332 |
|
---|
333 | <h4>Always include the braces:</h4>
|
---|
334 | <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>
|
---|
335 |
|
---|
336 | <p class="bad">// These are all wrong. </p>
|
---|
337 |
|
---|
338 | <div class="codebox"><pre>
|
---|
339 | if (condition) do_stuff();
|
---|
340 |
|
---|
341 | if (condition)
|
---|
342 | do_stuff();
|
---|
343 |
|
---|
344 | while (condition)
|
---|
345 | do_stuff();
|
---|
346 |
|
---|
347 | for ($i = 0; $i < size; $i++)
|
---|
348 | do_stuff($i);
|
---|
349 | </pre></div>
|
---|
350 |
|
---|
351 | <p class="good">// These are all right. </p>
|
---|
352 | <div class="codebox"><pre>
|
---|
353 | if (condition)
|
---|
354 | {
|
---|
355 | do_stuff();
|
---|
356 | }
|
---|
357 |
|
---|
358 | while (condition)
|
---|
359 | {
|
---|
360 | do_stuff();
|
---|
361 | }
|
---|
362 |
|
---|
363 | for ($i = 0; $i < size; $i++)
|
---|
364 | {
|
---|
365 | do_stuff();
|
---|
366 | }
|
---|
367 | </pre></div>
|
---|
368 |
|
---|
369 | <h4>Where to put the braces:</h4>
|
---|
370 | <p>This one is a bit of a holy war, but we're going to use a style that can be summed up in one sentence: Braces always go on their own line. The closing brace should also always be at the same column as the corresponding opening brace, examples:</p>
|
---|
371 |
|
---|
372 | <div class="codebox"><pre>
|
---|
373 | if (condition)
|
---|
374 | {
|
---|
375 | while (condition2)
|
---|
376 | {
|
---|
377 | ...
|
---|
378 | }
|
---|
379 | }
|
---|
380 | else
|
---|
381 | {
|
---|
382 | ...
|
---|
383 | }
|
---|
384 |
|
---|
385 | for ($i = 0; $i < $size; $i++)
|
---|
386 | {
|
---|
387 | ...
|
---|
388 | }
|
---|
389 |
|
---|
390 | while (condition)
|
---|
391 | {
|
---|
392 | ...
|
---|
393 | }
|
---|
394 |
|
---|
395 | function do_stuff()
|
---|
396 | {
|
---|
397 | ...
|
---|
398 | }
|
---|
399 | </pre></div>
|
---|
400 |
|
---|
401 | <h4>Use spaces between tokens:</h4>
|
---|
402 | <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>
|
---|
403 |
|
---|
404 | <p>// Each pair shows the wrong way followed by the right way. </p>
|
---|
405 |
|
---|
406 | <div class="codebox"><pre>
|
---|
407 | $i=0;
|
---|
408 | $i = 0;
|
---|
409 |
|
---|
410 | if($i<7) ...
|
---|
411 | if ($i < 7) ...
|
---|
412 |
|
---|
413 | if ( ($i < 7)&&($j > 8) ) ...
|
---|
414 | if ($i < 7 && $j > 8) ...
|
---|
415 |
|
---|
416 | do_stuff( $i, 'foo', $b );
|
---|
417 | do_stuff($i, 'foo', $b);
|
---|
418 |
|
---|
419 | for($i=0; $i<$size; $i++) ...
|
---|
420 | for ($i = 0; $i < $size; $i++) ...
|
---|
421 |
|
---|
422 | $i=($j < $size)?0:1;
|
---|
423 | $i = ($j < $size) ? 0 : 1;
|
---|
424 | </pre></div>
|
---|
425 |
|
---|
426 | <h4>Operator precedence:</h4>
|
---|
427 | <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>
|
---|
428 |
|
---|
429 | <p class="bad">// what's the result? who knows. </p>
|
---|
430 | <div class="codebox"><pre>
|
---|
431 | $bool = ($i < 7 && $j > 8 || $k == 4);
|
---|
432 | </pre></div>
|
---|
433 |
|
---|
434 | <p class="bad">// now you can be certain what I'm doing here.</p>
|
---|
435 | <div class="codebox"><pre>
|
---|
436 | $bool = (($i < 7) && (($j < 8) || ($k == 4)));
|
---|
437 | </pre></div>
|
---|
438 |
|
---|
439 | <p class="good">// But this one is even better, because it is easier on the eye but the intention is preserved</p>
|
---|
440 | <div class="codebox"><pre>
|
---|
441 | $bool = ($i < 7 && ($j < 8 || $k == 4));
|
---|
442 | </pre></div>
|
---|
443 |
|
---|
444 | <h4>Quoting strings:</h4>
|
---|
445 | <p>There are two different ways to quote strings in PHP - either with single quotes or with double quotes. The main difference is that the parser does variable interpolation in double-quoted strings, but not in single quoted strings. Because of this, you should <em>always</em> use single quotes <em>unless</em> you specifically need variable interpolation to be done on that string. This way, we can save the parser the trouble of parsing a bunch of strings where no interpolation needs to be done.</p>
|
---|
446 | <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>
|
---|
447 |
|
---|
448 | <p class="bad">// wrong </p>
|
---|
449 | <div class="codebox"><pre>
|
---|
450 | $str = "This is a really long string with no variables for the parser to find.";
|
---|
451 |
|
---|
452 | do_stuff("$str");
|
---|
453 | </pre></div>
|
---|
454 |
|
---|
455 | <p class="good">// right</p>
|
---|
456 | <div class="codebox"><pre>
|
---|
457 | $str = 'This is a really long string with no variables for the parser to find.';
|
---|
458 |
|
---|
459 | do_stuff($str);
|
---|
460 | </pre></div>
|
---|
461 |
|
---|
462 | <p class="bad">// Sometimes single quotes are just not right</p>
|
---|
463 | <div class="codebox"><pre>
|
---|
464 | $post_url = $phpbb_root_path . 'posting.' . $phpEx . '?mode=' . $mode . '&amp;start=' . $start;
|
---|
465 | </pre></div>
|
---|
466 |
|
---|
467 | <p class="good">// Double quotes are sometimes needed to not overcroud the line with concentinations</p>
|
---|
468 | <div class="codebox"><pre>
|
---|
469 | $post_url = "{$phpbb_root_path}posting.$phpEx?mode=$mode&amp;start=$start";
|
---|
470 | </pre></div>
|
---|
471 |
|
---|
472 | <p>In SQL Statements mixing single and double quotes is partly allowed (following the guidelines listed here about SQL Formatting), else it should be tryed to only use one method - mostly single quotes.</p>
|
---|
473 |
|
---|
474 | <h4>Associative array keys:</h4>
|
---|
475 | <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>
|
---|
476 |
|
---|
477 | <p class="bad">// wrong</p>
|
---|
478 | <div class="codebox"><pre>
|
---|
479 | $foo = $assoc_array[blah];
|
---|
480 | </pre></div>
|
---|
481 |
|
---|
482 | <p class="good">// right </p>
|
---|
483 | <div class="codebox"><pre>
|
---|
484 | $foo = $assoc_array['blah'];
|
---|
485 | </pre></div>
|
---|
486 |
|
---|
487 | <p class="bad">// wrong</p>
|
---|
488 | <div class="codebox"><pre>
|
---|
489 | $foo = $assoc_array["$var"];
|
---|
490 | </pre></div>
|
---|
491 |
|
---|
492 | <p class="good">// right </p>
|
---|
493 | <div class="codebox"><pre>
|
---|
494 | $foo = $assoc_array[$var];
|
---|
495 | </pre></div>
|
---|
496 |
|
---|
497 | <h4>Comments:</h4>
|
---|
498 | <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>
|
---|
499 |
|
---|
500 | <h4>Magic numbers:</h4>
|
---|
501 | <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 have a very close eye to it).</p>
|
---|
502 |
|
---|
503 | <h4>Shortcut operators:</h4>
|
---|
504 | <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>
|
---|
505 |
|
---|
506 | <p class="bad">// wrong </p>
|
---|
507 | <div class="codebox"><pre>
|
---|
508 | $array[++$i] = $j;
|
---|
509 | $array[$i++] = $k;
|
---|
510 | </pre></div>
|
---|
511 |
|
---|
512 | <p class="good">// right </p>
|
---|
513 | <div class="codebox"><pre>
|
---|
514 | $i++;
|
---|
515 | $array[$i] = $j;
|
---|
516 |
|
---|
517 | $array[$i] = $k;
|
---|
518 | $i++;
|
---|
519 | </pre></div>
|
---|
520 |
|
---|
521 | <h4>Inline conditionals:</h4>
|
---|
522 | <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>
|
---|
523 |
|
---|
524 | <p class="bad">// Bad place to use them</p>
|
---|
525 | <div class="codebox"><pre>
|
---|
526 | ($i < $size && $j > $size) ? do_stuff($foo) : do_stuff($bar);
|
---|
527 | </pre></div>
|
---|
528 |
|
---|
529 | <p class="good">// OK place to use them </p>
|
---|
530 | <div class="codebox"><pre>
|
---|
531 | $min = ($i < $j) ? $i : $j;
|
---|
532 | </pre></div>
|
---|
533 |
|
---|
534 | <h4>Don't use uninitialized variables.</h4>
|
---|
535 | <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>
|
---|
536 |
|
---|
537 | <p class="bad">// Wrong </p>
|
---|
538 | <div class="codebox"><pre>
|
---|
539 | if ($forum) ...
|
---|
540 | </pre></div>
|
---|
541 |
|
---|
542 | <p class="good">// Right </p>
|
---|
543 | <div class="codebox"><pre>
|
---|
544 | if (isset($forum)) ...
|
---|
545 | </pre></div>
|
---|
546 |
|
---|
547 | <p class="good">// Also possible</p>
|
---|
548 | <div class="codebox"><pre>
|
---|
549 | if (isset($forum) && $forum == 5)
|
---|
550 | </pre></div>
|
---|
551 |
|
---|
552 | <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) && sizeof($array) > 0</code> - this can be written in a shorter way as <code>!empty($array)</code>.</p>
|
---|
553 |
|
---|
554 | <h4>Switch statements:</h4>
|
---|
555 | <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>
|
---|
556 |
|
---|
557 | <p class="bad">// Wrong </p>
|
---|
558 | <div class="codebox"><pre>
|
---|
559 | switch ($mode)
|
---|
560 | {
|
---|
561 | case 'mode1':
|
---|
562 | // I am doing something here
|
---|
563 | break;
|
---|
564 | case 'mode2':
|
---|
565 | // I am doing something completely different here
|
---|
566 | break;
|
---|
567 | }
|
---|
568 | </pre></div>
|
---|
569 |
|
---|
570 | <p class="good">// Good </p>
|
---|
571 | <div class="codebox"><pre>
|
---|
572 | switch ($mode)
|
---|
573 | {
|
---|
574 | case 'mode1':
|
---|
575 | // I am doing something here
|
---|
576 | break;
|
---|
577 |
|
---|
578 | case 'mode2':
|
---|
579 | // I am doing something completely different here
|
---|
580 | break;
|
---|
581 |
|
---|
582 | default:
|
---|
583 | // Always assume that a case was not caught
|
---|
584 | break;
|
---|
585 | }
|
---|
586 | </pre></div>
|
---|
587 |
|
---|
588 | <p class="good">// Also good, if you have more code between the case and the break </p>
|
---|
589 | <div class="codebox"><pre>
|
---|
590 | switch ($mode)
|
---|
591 | {
|
---|
592 | case 'mode1':
|
---|
593 |
|
---|
594 | // I am doing something here
|
---|
595 |
|
---|
596 | break;
|
---|
597 |
|
---|
598 | case 'mode2':
|
---|
599 |
|
---|
600 | // I am doing something completely different here
|
---|
601 |
|
---|
602 | break;
|
---|
603 |
|
---|
604 | default:
|
---|
605 |
|
---|
606 | // Always assume that a case was not caught
|
---|
607 |
|
---|
608 | break;
|
---|
609 | }
|
---|
610 | </pre></div>
|
---|
611 |
|
---|
612 | <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>
|
---|
613 |
|
---|
614 | <p>If no break is intended, please add a comment instead. An example:</p>
|
---|
615 |
|
---|
616 | <p class="good">// Example with no break </p>
|
---|
617 | <div class="codebox"><pre>
|
---|
618 | switch ($mode)
|
---|
619 | {
|
---|
620 | case 'mode1':
|
---|
621 |
|
---|
622 | // I am doing something here
|
---|
623 |
|
---|
624 | // no break here
|
---|
625 |
|
---|
626 | case 'mode2':
|
---|
627 |
|
---|
628 | // I am doing something completely different here
|
---|
629 |
|
---|
630 | break;
|
---|
631 |
|
---|
632 | default:
|
---|
633 |
|
---|
634 | // Always assume that a case was not caught
|
---|
635 |
|
---|
636 | break;
|
---|
637 | }
|
---|
638 | </pre></div>
|
---|
639 |
|
---|
640 | <a name="sql"></a><h3>2.iii. SQL/SQL Layout</h3>
|
---|
641 |
|
---|
642 | <h4>Common SQL Guidelines: </h4>
|
---|
643 | <p>All SQL should be cross-DB compatible, if DB specific SQL is used alternatives must be provided which work on all supported DB's (MySQL3/4/5, MSSQL (7.0 and 2000), PostgreSQL (7.0+), Firebird, SQLite, Oracle8, ODBC (generalised if possible)).</p>
|
---|
644 | <p>All SQL commands should utilise the DataBase Abstraction Layer (DBAL)</p>
|
---|
645 |
|
---|
646 | <h4>SQL code layout:</h4>
|
---|
647 | <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>
|
---|
648 |
|
---|
649 | <div class="codebox"><pre>
|
---|
650 | $sql = 'SELECT *
|
---|
651 | <-one tab->FROM ' . SOME_TABLE . '
|
---|
652 | <-one tab->WHERE a = 1
|
---|
653 | <-two tabs->AND (b = 2
|
---|
654 | <-three tabs->OR b = 3)
|
---|
655 | <-one tab->ORDER BY b';
|
---|
656 | </pre></div>
|
---|
657 |
|
---|
658 | <p>Here the example with the tabs applied:</p>
|
---|
659 |
|
---|
660 | <div class="codebox"><pre>
|
---|
661 | $sql = 'SELECT *
|
---|
662 | FROM ' . SOME_TABLE . '
|
---|
663 | WHERE a = 1
|
---|
664 | AND (b = 2
|
---|
665 | OR b = 3)
|
---|
666 | ORDER BY b';
|
---|
667 | </pre></div>
|
---|
668 |
|
---|
669 | <h4>SQL Quotes: </h4>
|
---|
670 | <p>Double quotes where applicable (The variables in these examples are typecasted to integers before) ... examples: </p>
|
---|
671 |
|
---|
672 | <p class="bad">// These are wrong.</p>
|
---|
673 | <div class="codebox"><pre>
|
---|
674 | "UPDATE " . SOME_TABLE . " SET something = something_else WHERE a = $b";
|
---|
675 |
|
---|
676 | 'UPDATE ' . SOME_TABLE . ' SET something = ' . $user_id . ' WHERE a = ' . $something;
|
---|
677 | </pre></div>
|
---|
678 |
|
---|
679 | <p class="good">// These are right. </p>
|
---|
680 |
|
---|
681 | <div class="codebox"><pre>
|
---|
682 | 'UPDATE ' . SOME_TABLE . " SET something = something_else WHERE a = $b";
|
---|
683 |
|
---|
684 | 'UPDATE ' . SOME_TABLE . " SET something = $user_id WHERE a = $something";
|
---|
685 | </pre></div>
|
---|
686 |
|
---|
687 | <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>
|
---|
688 |
|
---|
689 | <h4>Avoid DB specific SQL: </h4>
|
---|
690 | <p>The "not equals operator", as defined by the SQL:2003 standard, is "<>"</p>
|
---|
691 |
|
---|
692 | <p class="bad">// This is wrong.</p>
|
---|
693 | <div class="codebox"><pre>
|
---|
694 | $sql = 'SELECT *
|
---|
695 | FROM ' . SOME_TABLE . '
|
---|
696 | WHERE a != 2';
|
---|
697 | </pre></div>
|
---|
698 |
|
---|
699 | <p class="good">// This is right. </p>
|
---|
700 | <div class="codebox"><pre>
|
---|
701 | $sql = 'SELECT *
|
---|
702 | FROM ' . SOME_TABLE . '
|
---|
703 | WHERE a <> 2';
|
---|
704 | </pre></div>
|
---|
705 |
|
---|
706 | <h4>Common DBAL methods: </h4>
|
---|
707 |
|
---|
708 | <h4>sql_escape():</h4>
|
---|
709 |
|
---|
710 | <p>Always use <code>$db->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>
|
---|
711 |
|
---|
712 | <div class="codebox"><pre>
|
---|
713 | $sql = 'SELECT *
|
---|
714 | FROM ' . SOME_TABLE . "
|
---|
715 | WHERE username = '" . $db->sql_escape($username) . "'";
|
---|
716 | </pre></div>
|
---|
717 |
|
---|
718 | <h4>sql_query_limit():</h4>
|
---|
719 |
|
---|
720 | <p>We do not add limit statements to the sql query, but instead use <code>$db->sql_query_limit()</code>. You basically pass the query, the total number of lines to retrieve and the offset.</p>
|
---|
721 |
|
---|
722 | <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>
|
---|
723 |
|
---|
724 | <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>
|
---|
725 |
|
---|
726 | <h4>sql_build_array():</h4>
|
---|
727 |
|
---|
728 | <p>If you need to UPDATE or INSERT data, make use of the <code>$db->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>
|
---|
729 |
|
---|
730 | <div class="codebox"><pre>
|
---|
731 | $sql_ary = array(
|
---|
732 | 'somedata' => $my_string,
|
---|
733 | 'otherdata' => $an_int,
|
---|
734 | 'moredata' => $another_int
|
---|
735 | );
|
---|
736 |
|
---|
737 | $db->sql_query('INSERT INTO ' . SOME_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
|
---|
738 | </pre></div>
|
---|
739 |
|
---|
740 | <p>To complete the example, this is how an update statement would look like:</p>
|
---|
741 |
|
---|
742 | <div class="codebox"><pre>
|
---|
743 | $sql_ary = array(
|
---|
744 | 'somedata' => $my_string,
|
---|
745 | 'otherdata' => $an_int,
|
---|
746 | 'moredata' => $another_int
|
---|
747 | );
|
---|
748 |
|
---|
749 | $sql = 'UPDATE ' . SOME_TABLE . '
|
---|
750 | SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
|
---|
751 | WHERE user_id = ' . (int) $user_id;
|
---|
752 | $db->sql_query($sql);
|
---|
753 | </pre></div>
|
---|
754 |
|
---|
755 | <p>The <code>$db->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>
|
---|
756 |
|
---|
757 | <h4>sql_multi_insert():</h4>
|
---|
758 |
|
---|
759 | <p>If you want to insert multiple statements at once, please use the separate <code>sql_multi_insert()</code> method. An example:</p>
|
---|
760 |
|
---|
761 | <div class="codebox"><pre>
|
---|
762 | $sql_ary = array();
|
---|
763 |
|
---|
764 | $sql_ary[] = array(
|
---|
765 | 'somedata' => $my_string_1,
|
---|
766 | 'otherdata' => $an_int_1,
|
---|
767 | 'moredata' => $another_int_1,
|
---|
768 | );
|
---|
769 |
|
---|
770 | $sql_ary[] = array(
|
---|
771 | 'somedata' => $my_string_2,
|
---|
772 | 'otherdata' => $an_int_2,
|
---|
773 | 'moredata' => $another_int_2,
|
---|
774 | );
|
---|
775 |
|
---|
776 | $db->sql_multi_insert(SOME_TABLE, $sql_ary);
|
---|
777 | </pre></div>
|
---|
778 |
|
---|
779 | <h4>sql_in_set():</h4>
|
---|
780 |
|
---|
781 | <p>The <code>$db->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><></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>
|
---|
782 |
|
---|
783 | <div class="codebox"><pre>
|
---|
784 | $sql = 'SELECT *
|
---|
785 | FROM ' . FORUMS_TABLE . '
|
---|
786 | WHERE ' . $db->sql_in_set('forum_id', $forum_ids);
|
---|
787 | $db->sql_query($sql);
|
---|
788 | </pre></div>
|
---|
789 |
|
---|
790 | <p>Based on the number of values in $forum_ids, the query can look differently.</p>
|
---|
791 |
|
---|
792 | <p class="good">// SQL Statement if $forum_ids = array(1, 2, 3);</p>
|
---|
793 |
|
---|
794 | <div class="codebox"><pre>
|
---|
795 | SELECT FROM phpbb_forums WHERE forum_id IN (1, 2, 3)
|
---|
796 | </pre></div>
|
---|
797 |
|
---|
798 | <p class="good">// SQL Statement if $forum_ids = array(1) or $forum_ids = 1</p>
|
---|
799 |
|
---|
800 | <div class="codebox"><pre>
|
---|
801 | SELECT FROM phpbb_forums WHERE forum_id = 1
|
---|
802 | </pre></div>
|
---|
803 |
|
---|
804 | <p>Of course the same is possible for doing a negative match against a number of values:</p>
|
---|
805 |
|
---|
806 | <div class="codebox"><pre>
|
---|
807 | $sql = 'SELECT *
|
---|
808 | FROM ' . FORUMS_TABLE . '
|
---|
809 | WHERE ' . $db->sql_in_set('forum_id', $forum_ids, <strong>true</strong>);
|
---|
810 | $db->sql_query($sql);
|
---|
811 | </pre></div>
|
---|
812 |
|
---|
813 | <p>Based on the number of values in $forum_ids, the query can look differently here too.</p>
|
---|
814 |
|
---|
815 | <p class="good">// SQL Statement if $forum_ids = array(1, 2, 3);</p>
|
---|
816 |
|
---|
817 | <div class="codebox"><pre>
|
---|
818 | SELECT FROM phpbb_forums WHERE forum_id <strong>NOT</strong> IN (1, 2, 3)
|
---|
819 | </pre></div>
|
---|
820 |
|
---|
821 | <p class="good">// SQL Statement if $forum_ids = array(1) or $forum_ids = 1</p>
|
---|
822 |
|
---|
823 | <div class="codebox"><pre>
|
---|
824 | SELECT FROM phpbb_forums WHERE forum_id <strong><></strong> 1
|
---|
825 | </pre></div>
|
---|
826 |
|
---|
827 | <p>If the given array is empty, an error will be produced.</p>
|
---|
828 |
|
---|
829 | <h4>sql_build_query():</h4>
|
---|
830 |
|
---|
831 | <p>The <code>$db->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 retrieving 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>
|
---|
832 |
|
---|
833 | <div class="codebox"><pre>
|
---|
834 | $sql_array = array(
|
---|
835 | 'SELECT' => 'f.*, ft.mark_time',
|
---|
836 |
|
---|
837 | 'FROM' => array(
|
---|
838 | FORUMS_WATCH_TABLE => 'fw',
|
---|
839 | FORUMS_TABLE => 'f'
|
---|
840 | ),
|
---|
841 |
|
---|
842 | 'LEFT_JOIN' => array(
|
---|
843 | array(
|
---|
844 | 'FROM' => array(FORUMS_TRACK_TABLE => 'ft'),
|
---|
845 | 'ON' => 'ft.user_id = ' . $user->data['user_id'] . ' AND ft.forum_id = f.forum_id'
|
---|
846 | )
|
---|
847 | ),
|
---|
848 |
|
---|
849 | 'WHERE' => 'fw.user_id = ' . $user->data['user_id'] . '
|
---|
850 | AND f.forum_id = fw.forum_id',
|
---|
851 |
|
---|
852 | 'ORDER_BY' => 'left_id'
|
---|
853 | );
|
---|
854 |
|
---|
855 | $sql = $db->sql_build_query('SELECT', $sql_array);
|
---|
856 | </pre></div>
|
---|
857 |
|
---|
858 | <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>
|
---|
859 |
|
---|
860 | <div class="codebox"><pre>
|
---|
861 | $sql_array = array(
|
---|
862 | 'SELECT' => 'f.*',
|
---|
863 |
|
---|
864 | 'FROM' => array(
|
---|
865 | FORUMS_WATCH_TABLE => 'fw',
|
---|
866 | FORUMS_TABLE => 'f'
|
---|
867 | ),
|
---|
868 |
|
---|
869 | 'WHERE' => 'fw.user_id = ' . $user->data['user_id'] . '
|
---|
870 | AND f.forum_id = fw.forum_id',
|
---|
871 |
|
---|
872 | 'ORDER_BY' => 'left_id'
|
---|
873 | );
|
---|
874 |
|
---|
875 | if ($config['load_db_lastread'])
|
---|
876 | {
|
---|
877 | $sql_array['LEFT_JOIN'] = array(
|
---|
878 | array(
|
---|
879 | 'FROM' => array(FORUMS_TRACK_TABLE => 'ft'),
|
---|
880 | 'ON' => 'ft.user_id = ' . $user->data['user_id'] . ' AND ft.forum_id = f.forum_id'
|
---|
881 | )
|
---|
882 | );
|
---|
883 |
|
---|
884 | $sql_array['SELECT'] .= ', ft.mark_time ';
|
---|
885 | }
|
---|
886 | else
|
---|
887 | {
|
---|
888 | // Here we read the cookie data
|
---|
889 | }
|
---|
890 |
|
---|
891 | $sql = $db->sql_build_query('SELECT', $sql_array);
|
---|
892 | </pre></div>
|
---|
893 |
|
---|
894 | <a name="optimizing"></a><h3>2.iv. Optimizations</h3>
|
---|
895 |
|
---|
896 | <h4>Operations in loop definition: </h4>
|
---|
897 | <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>
|
---|
898 |
|
---|
899 | <p class="bad">// On every iteration the sizeof function is called</p>
|
---|
900 | <div class="codebox"><pre>
|
---|
901 | for ($i = 0; $i < sizeof($post_data); $i++)
|
---|
902 | {
|
---|
903 | do_something();
|
---|
904 | }
|
---|
905 | </pre></div>
|
---|
906 |
|
---|
907 | <p class="good">// You are able to assign the (not changing) result within the loop itself</p>
|
---|
908 | <div class="codebox"><pre>
|
---|
909 | for ($i = 0, $size = sizeof($post_data); $i < $size; $i++)
|
---|
910 | {
|
---|
911 | do_something();
|
---|
912 | }
|
---|
913 | </pre></div>
|
---|
914 |
|
---|
915 | <h4>Use of in_array(): </h4>
|
---|
916 | <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 noticable, but if checked against a huge array within a loop those checks alone can be a bunch of 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>
|
---|
917 |
|
---|
918 |
|
---|
919 | <a name="general"></a><h3>2.v. General Guidelines</h3>
|
---|
920 |
|
---|
921 | <h4>General things:</h4>
|
---|
922 | <p>Never trust user input (this also applies to server variables as well as cookies).</p>
|
---|
923 | <p>Try to sanitize values returned from a function.</p>
|
---|
924 | <p>Try to sanitize given function variables within your function.</p>
|
---|
925 | <p>The auth class should be used for all authorisation checking.</p>
|
---|
926 | <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>
|
---|
927 |
|
---|
928 | <h4>Variables: </h4>
|
---|
929 | <p>Make use of the <code>request_var()</code> function for anything except for submit or single checking params. </p>
|
---|
930 | <p>The request_var function determines the type to set from the second parameter (which determines the default value too). If you need to get a scalar variable type, you need to tell this the request_var function explicitly. Examples:</p>
|
---|
931 |
|
---|
932 | <p class="bad">// Old method, do not use it</p>
|
---|
933 | <div class="codebox"><pre>
|
---|
934 | $start = (isset($HTTP_GET_VARS['start'])) ? intval($HTTP_GET_VARS['start']) : intval($HTTP_POST_VARS['start']);
|
---|
935 | $submit = (isset($HTTP_POST_VARS['submit'])) ? true : false;
|
---|
936 | </pre></div>
|
---|
937 |
|
---|
938 | <p class="good">// Use request var and define a default variable (use the correct type)</p>
|
---|
939 | <div class="codebox"><pre>
|
---|
940 | $start = request_var('start', 0);
|
---|
941 | $submit = (isset($_POST['submit'])) ? true : false;
|
---|
942 | </pre></div>
|
---|
943 |
|
---|
944 | <p class="bad">// $start is an int, the following use of request_var therefore is not allowed</p>
|
---|
945 | <div class="codebox"><pre>
|
---|
946 | $start = request_var('start', '0');
|
---|
947 | </pre></div>
|
---|
948 |
|
---|
949 | <p class="good">// Getting an array, keys are integers, value defaults to 0</p>
|
---|
950 | <div class="codebox"><pre>
|
---|
951 | $mark_array = request_var('mark', array(0));
|
---|
952 | </pre></div>
|
---|
953 |
|
---|
954 | <p class="good">// Getting an array, keys are strings, value defaults to 0</p>
|
---|
955 | <div class="codebox"><pre>
|
---|
956 | $action_ary = request_var('action', array('' => 0));
|
---|
957 | </pre></div>
|
---|
958 |
|
---|
959 | <h4>Login checks/redirection: </h4>
|
---|
960 | <p>To show a forum login box use <code>login_forum_box($forum_data)</code>, else use the <code>login_box()</code> function.</p>
|
---|
961 |
|
---|
962 | <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>
|
---|
963 |
|
---|
964 | <h4>Sensitive Operations: </h4>
|
---|
965 | <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>
|
---|
966 |
|
---|
967 | <h4>Altering Operations: </h4>
|
---|
968 | <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>
|
---|
969 | <div class="codebox"><pre>
|
---|
970 | add_form_key('my_form');
|
---|
971 |
|
---|
972 | if ($submit)
|
---|
973 | {
|
---|
974 | if (!check_form_key('my_form'))
|
---|
975 | {
|
---|
976 | trigger_error('FORM_INVALID');
|
---|
977 | }
|
---|
978 | }
|
---|
979 | </pre></div>
|
---|
980 |
|
---|
981 | <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>
|
---|
982 |
|
---|
983 |
|
---|
984 | <h4>Sessions: </h4>
|
---|
985 | <p>Sessions should be initiated on each page, as near the top as possible using the following code:</p>
|
---|
986 |
|
---|
987 | <div class="codebox"><pre>
|
---|
988 | $user->session_begin();
|
---|
989 | $auth->acl($user->data);
|
---|
990 | $user->setup();
|
---|
991 | </pre></div>
|
---|
992 |
|
---|
993 | <p>The <code>$user->setup()</code> call can be used to pass on additional language definition and a custom style (used in viewforum).</p>
|
---|
994 |
|
---|
995 | <h4>Errors and messages: </h4>
|
---|
996 | <p>All messages/errors should be outputed by calling <code>trigger_error()</code> using the appropriate message type and language string. Example:</p>
|
---|
997 |
|
---|
998 | <div class="codebox"><pre>
|
---|
999 | trigger_error('NO_FORUM');
|
---|
1000 | </pre></div>
|
---|
1001 |
|
---|
1002 | <div class="codebox"><pre>
|
---|
1003 | trigger_error($user->lang['NO_FORUM']);
|
---|
1004 | </pre></div>
|
---|
1005 |
|
---|
1006 | <div class="codebox"><pre>
|
---|
1007 | trigger_error('NO_MODE', E_USER_ERROR);
|
---|
1008 | </pre></div>
|
---|
1009 |
|
---|
1010 | <h4>Url formatting</h4>
|
---|
1011 |
|
---|
1012 | <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>
|
---|
1013 |
|
---|
1014 | <p>The <code>append_sid()</code> function from 2.0.x is available too, though 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>
|
---|
1015 |
|
---|
1016 | <div class="codebox"><pre>
|
---|
1017 | append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=group&amp;g=' . $row['group_id'])
|
---|
1018 | </pre></div>
|
---|
1019 |
|
---|
1020 | <h4>General function usage: </h4>
|
---|
1021 |
|
---|
1022 | <p>Some of these functions are only chosen over others because of personal preference and having no other benefit than to be consistant over the code.</p>
|
---|
1023 |
|
---|
1024 | <ul>
|
---|
1025 | <li>
|
---|
1026 | <p>Use <code>sizeof</code> instead of <code>count</code></p>
|
---|
1027 | </li>
|
---|
1028 | <li>
|
---|
1029 | <p>Use <code>strpos</code> instead of <code>strstr</code></p>
|
---|
1030 | </li>
|
---|
1031 | <li>
|
---|
1032 | <p>Use <code>else if</code> instead of <code>elseif</code></p>
|
---|
1033 | </li>
|
---|
1034 | <li>
|
---|
1035 | <p>Use <code>false</code> (lowercase) instead of <code>FALSE</code></p>
|
---|
1036 | </li>
|
---|
1037 | <li>
|
---|
1038 | <p>Use <code>true</code> (lowercase) instead of <code>TRUE</code></p>
|
---|
1039 | </li>
|
---|
1040 | </ul>
|
---|
1041 |
|
---|
1042 | <h4>Exiting</h4>
|
---|
1043 |
|
---|
1044 | <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>
|
---|
1045 |
|
---|
1046 | </div>
|
---|
1047 |
|
---|
1048 | <div class="back2top"><a href="#wrap" class="top">Back to Top</a></div>
|
---|
1049 |
|
---|
1050 | <span class="corners-bottom"><span></span></span></div>
|
---|
1051 | </div>
|
---|
1052 |
|
---|
1053 | <hr />
|
---|
1054 |
|
---|
1055 | <a name="styling"></a><h2>3. Styling</h2>
|
---|
1056 | <div class="paragraph">
|
---|
1057 | <div class="inner"><span class="corners-top"><span></span></span>
|
---|
1058 |
|
---|
1059 | <div class="content">
|
---|
1060 | <a name="cfgfiles"></a><h3>3.i. Style Config Files</h3>
|
---|
1061 | <p>Style cfg files are simple name-value lists with the information necessary for installing a style. Similar cfg files exist for templates, themes and imagesets. These follow the same principle and will not be introduced individually. Styles can use installed components by using the required_theme/required_template/required_imageset entries. The important part of the style configuration file is assigning an unique name.</p>
|
---|
1062 | <div class="codebox"><pre>
|
---|
1063 | # General Information about this style
|
---|
1064 | name = prosilver_duplicate
|
---|
1065 | copyright = © phpBB Group, 2007
|
---|
1066 | version = 3.0.3
|
---|
1067 | required_template = prosilver
|
---|
1068 | required_theme = prosilver
|
---|
1069 | required_imageset = prosilver
|
---|
1070 | </pre></div>
|
---|
1071 | <a name="genstyling"></a><h3>3.2. General Styling Rules</h3>
|
---|
1072 | <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 intendation and coding guidelines also apply to templates where possible.</p>
|
---|
1073 |
|
---|
1074 | <p>The outer table class <code>forumline</code> has gone and is replaced with <code>tablebg</code>.</p>
|
---|
1075 | <p>When writing <code><table></code> the order <code><table class="" cellspacing="" cellpadding="" border="" align=""></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>
|
---|
1076 | <p>Each block level element should be indented by one tab, same for tabular elements, e.g. <code><tr></code> <code><td></code> etc., whereby the intendiation of <code><table></code> and the following/ending <code><tr></code> should be on the same line. This applies not to div elements of course.</p>
|
---|
1077 | <p>Don't use <code><span></code> more than is essential ... the CSS is such that text sizes are dependent on the parent class. So writing <code><span class="gensmall"><span class="gensmall">TEST</span></span></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>
|
---|
1078 |
|
---|
1079 | <div class="codebox"><pre>
|
---|
1080 | <td><span class="gensmall">TEST</span></td>
|
---|
1081 | </pre></div>
|
---|
1082 |
|
---|
1083 | <p>can just as well become:</p>
|
---|
1084 | <div class="codebox"><pre>
|
---|
1085 | <td class="gensmall">TEST</td>
|
---|
1086 | </pre></div>
|
---|
1087 |
|
---|
1088 | <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>
|
---|
1089 |
|
---|
1090 | <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>
|
---|
1091 |
|
---|
1092 | <p>Remember block level ordering is important ... while not all pages validate as XHTML 1.0 Strict compliant it is something we're trying to work too.</p>
|
---|
1093 |
|
---|
1094 | <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>
|
---|
1095 |
|
---|
1096 | <p><strong>Use div container/css for styling and table for data representation.</strong></p>
|
---|
1097 |
|
---|
1098 | <p>The separate catXXXX and thXXX classes are gone. When defining a header cell just use <code><th></code> rather than <code><th class="thHead"></code> etc. Similarly for cat, don't use <code><td class="catLeft"></code> use <code><td class="cat"></code> etc.</p>
|
---|
1099 |
|
---|
1100 | <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}<br /><span class="gensmall">{L_POST_USERNAME_EXPLAIN}</span></code> is the typical way of handling this ... there may be exceptions and this isn't a hard and fast rule.</p>
|
---|
1101 |
|
---|
1102 | <p>Try to keep template conditional and other statements tabbed in line with the block to which they refer.</p>
|
---|
1103 |
|
---|
1104 | <p class="good">this is correct</p>
|
---|
1105 | <div class="codebox"><pre>
|
---|
1106 | <span class="comment"><!-- BEGIN test --></span>
|
---|
1107 | <tr>
|
---|
1108 | <td>{test.TEXT}</td>
|
---|
1109 | </tr>
|
---|
1110 | <span class="comment"><!-- END test --></span>
|
---|
1111 | </pre></div>
|
---|
1112 |
|
---|
1113 | <p class="good">this is also correct:</p>
|
---|
1114 | <div class="codebox"><pre>
|
---|
1115 | <span class="comment"><!-- BEGIN test --></span>
|
---|
1116 | <tr>
|
---|
1117 | <td>{test.TEXT}</td>
|
---|
1118 | </tr>
|
---|
1119 | <span class="comment"><!-- END test --></span>
|
---|
1120 | </pre></div>
|
---|
1121 |
|
---|
1122 | <p>it gives immediate feedback on exactly what is looping - decide which way to use based on the readability.</p>
|
---|
1123 |
|
---|
1124 | </div>
|
---|
1125 |
|
---|
1126 | <div class="back2top"><a href="#wrap" class="top">Back to Top</a></div>
|
---|
1127 |
|
---|
1128 | <span class="corners-bottom"><span></span></span></div>
|
---|
1129 | </div>
|
---|
1130 |
|
---|
1131 | <hr />
|
---|
1132 |
|
---|
1133 | <a name="templating"></a><h2>4. Templating</h2>
|
---|
1134 | <div class="paragraph">
|
---|
1135 | <div class="inner"><span class="corners-top"><span></span></span>
|
---|
1136 |
|
---|
1137 | <div class="content">
|
---|
1138 | <a name="templates"></a><h3>4.i. General Templating</h3>
|
---|
1139 |
|
---|
1140 | <h4>File naming</h4>
|
---|
1141 | <p>Firstly templates now take the suffix ".html" rather than ".tpl". This was done simply to make the lifes of some people easier wrt syntax highlighting, etc.</p>
|
---|
1142 |
|
---|
1143 | <h4>Variables</h4>
|
---|
1144 | <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>
|
---|
1145 |
|
---|
1146 | <p>L_* template variables are automatically tried to be mapped to the corresponding language entry if the code does not set (and therefore overwrite) this variable specifically. For example <code>{L_USERNAME}</code> maps to <code>$user->lang['USERNAME']</code>. The LA_* template variables are handled within the same way, but properly escaped to be put in javascript code. This should reduce the need to assign loads of new lang vars in Modifications.
|
---|
1147 | </p>
|
---|
1148 |
|
---|
1149 | <h4>Blocks/Loops</h4>
|
---|
1150 | <p>The basic block level loop remains and takes the form:</p>
|
---|
1151 | <div class="codebox"><pre>
|
---|
1152 | <span class="comment"><!-- BEGIN loopname --></span>
|
---|
1153 | markup, {loopname.X_YYYYY}, etc.
|
---|
1154 | <span class="comment"><!-- END loopname --></span>
|
---|
1155 | </pre></div>
|
---|
1156 |
|
---|
1157 | <p>A bit later loops will be explained further. To not irritate you we will explain conditionals as well as other statements first.</p>
|
---|
1158 |
|
---|
1159 | <h4>Including files</h4>
|
---|
1160 | <p>Something that existed in 2.0.x which no longer exists in 3.0.x is the ability to assign a template to a variable. This was used (for example) to output the jumpbox. Instead (perhaps better, perhaps not but certainly more flexible) we now have INCLUDE. This takes the simple form:</p>
|
---|
1161 |
|
---|
1162 | <div class="codebox"><pre>
|
---|
1163 | <span class="comment"><!-- INCLUDE filename --></span>
|
---|
1164 | </pre></div>
|
---|
1165 |
|
---|
1166 | <p>You will note in the 3.0 templates the major sources start with <code><!-- INCLUDE overall_header.html --></code> or <code><!-- INCLUDE simple_header.html --></code>, etc. In 2.0.x control of "which" header to use was defined entirely within the code. In 3.0.x the template designer can output what they like. Note that you can introduce new templates (i.e. other than those in the default set) using this system and include them as you wish ... perhaps useful for a common "menu" bar or some such. No need to modify loads of files as with 2.0.x.</p>
|
---|
1167 |
|
---|
1168 | <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>
|
---|
1169 | <div class="codebox"><pre>
|
---|
1170 | <span class="comment"><!-- INCLUDE {FILE_VAR} --></span>
|
---|
1171 | </pre></div>
|
---|
1172 |
|
---|
1173 | <p>Template defined variables can also be utilised.</p>
|
---|
1174 |
|
---|
1175 | <div class="codebox"><pre>
|
---|
1176 | <span class="comment"><!-- DEFINE $SOME_VAR = 'my_file.html' --></span>
|
---|
1177 | <span class="comment"><!-- INCLUDE {$SOME_VAR} --></span>
|
---|
1178 | </pre></div>
|
---|
1179 |
|
---|
1180 | <h4>PHP</h4>
|
---|
1181 | <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>
|
---|
1182 |
|
---|
1183 | <div class="codebox"><pre>
|
---|
1184 | <span class="comment"><!-- PHP --></span>
|
---|
1185 | echo "hello!";
|
---|
1186 | <span class="comment"><!-- ENDPHP --></span>
|
---|
1187 | </pre></div>
|
---|
1188 |
|
---|
1189 | <p>You may also include PHP from an external file using:</p>
|
---|
1190 |
|
---|
1191 | <div class="codebox"><pre>
|
---|
1192 | <span class="comment"><!-- INCLUDEPHP somefile.php --></span>
|
---|
1193 | </pre></div>
|
---|
1194 |
|
---|
1195 | <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="http://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>
|
---|
1196 |
|
---|
1197 | <h4>Conditionals/Control structures</h4>
|
---|
1198 | <p>The most significant addition to 3.0.x are conditions or control structures, "if something then do this else do that". 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>
|
---|
1199 |
|
---|
1200 | <div class="codebox"><pre>
|
---|
1201 | <span class="comment"><!-- IF expr --></span>
|
---|
1202 | markup
|
---|
1203 | <span class="comment"><!-- ENDIF --></span>
|
---|
1204 | </pre></div>
|
---|
1205 |
|
---|
1206 | <p>expr can take many forms, for example:</p>
|
---|
1207 |
|
---|
1208 | <div class="codebox"><pre>
|
---|
1209 | <span class="comment"><!-- IF loop.S_ROW_COUNT is even --></span>
|
---|
1210 | markup
|
---|
1211 | <span class="comment"><!-- ENDIF --></span>
|
---|
1212 | </pre></div>
|
---|
1213 |
|
---|
1214 | <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>
|
---|
1215 |
|
---|
1216 | <div class="codebox"><pre>
|
---|
1217 | == [eq]
|
---|
1218 | != [neq, ne]
|
---|
1219 | <> (same as !=)
|
---|
1220 | !== (not equivalent in value and type)
|
---|
1221 | === (equivalent in value and type)
|
---|
1222 | > [gt]
|
---|
1223 | < [lt]
|
---|
1224 | >= [gte]
|
---|
1225 | <= [lte]
|
---|
1226 | && [and]
|
---|
1227 | || [or]
|
---|
1228 | % [mod]
|
---|
1229 | ! [not]
|
---|
1230 | +
|
---|
1231 | -
|
---|
1232 | *
|
---|
1233 | /
|
---|
1234 | ,
|
---|
1235 | << (bitwise shift left)
|
---|
1236 | >> (bitwise shift right)
|
---|
1237 | | (bitwise or)
|
---|
1238 | ^ (bitwise xor)
|
---|
1239 | & (bitwise and)
|
---|
1240 | ~ (bitwise not)
|
---|
1241 | is (can be used to join comparison operations)
|
---|
1242 | </pre></div>
|
---|
1243 |
|
---|
1244 | <p>Basic parenthesis can also be used to enforce good old BODMAS rules. Additionally some basic comparison types are defined:</p>
|
---|
1245 |
|
---|
1246 | <div class="codebox"><pre>
|
---|
1247 | even
|
---|
1248 | odd
|
---|
1249 | div
|
---|
1250 | </pre></div>
|
---|
1251 |
|
---|
1252 | <p>Beyond the simple use of IF you can also do a sequence of comparisons using the following:</p>
|
---|
1253 |
|
---|
1254 | <div class="codebox"><pre>
|
---|
1255 | <span class="comment"><!-- IF expr1 --></span>
|
---|
1256 | markup
|
---|
1257 | <span class="comment"><!-- ELSEIF expr2 --></span>
|
---|
1258 | markup
|
---|
1259 | .
|
---|
1260 | .
|
---|
1261 | .
|
---|
1262 | <span class="comment"><!-- ELSEIF exprN --></span>
|
---|
1263 | markup
|
---|
1264 | <span class="comment"><!-- ELSE --></span>
|
---|
1265 | markup
|
---|
1266 | <span class="comment"><!-- ENDIF --></span>
|
---|
1267 | </pre></div>
|
---|
1268 |
|
---|
1269 | <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 "everything else".<br /><br />So what can you do with all this? Well take for example the colouration of rows in viewforum. In 2.0.x row colours were predefined within the source as either row color1, row color2 or row class1, row class2. In 3.0.x this is moved to the template, it may look a little daunting at first but remember control flows from top to bottom and it's not too difficult:</p>
|
---|
1270 |
|
---|
1271 | <div class="codebox"><pre>
|
---|
1272 | <table>
|
---|
1273 | <span class="comment"><!-- IF loop.S_ROW_COUNT is even --></span>
|
---|
1274 | <tr class="row1">
|
---|
1275 | <span class="comment"><!-- ELSE --></span>
|
---|
1276 | <tr class="row2">
|
---|
1277 | <span class="comment"><!-- ENDIF --></span>
|
---|
1278 | <td>HELLO!</td>
|
---|
1279 | </tr>
|
---|
1280 | </table>
|
---|
1281 | </pre></div>
|
---|
1282 |
|
---|
1283 | <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>
|
---|
1284 |
|
---|
1285 | <div class="codebox"><pre>
|
---|
1286 | <table>
|
---|
1287 | <span class="comment"><!-- IF loop.S_ROW_COUNT > 10 --></span>
|
---|
1288 | <tr bgcolor="#FF0000">
|
---|
1289 | <span class="comment"><!-- ELSEIF loop.S_ROW_COUNT > 5 --></span>
|
---|
1290 | <tr bgcolor="#00FF00">
|
---|
1291 | <span class="comment"><!-- ELSEIF loop.S_ROW_COUNT > 2 --></span>
|
---|
1292 | <tr bgcolor="#0000FF">
|
---|
1293 | <span class="comment"><!-- ELSE --></span>
|
---|
1294 | <tr bgcolor="#FF00FF">
|
---|
1295 | <span class="comment"><!-- ENDIF --></span>
|
---|
1296 | <td>hello!</td>
|
---|
1297 | </tr>
|
---|
1298 | </table>
|
---|
1299 | </pre></div>
|
---|
1300 |
|
---|
1301 | <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 "nice" 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>
|
---|
1302 |
|
---|
1303 | <div class="codebox"><pre>
|
---|
1304 | <span class="comment"><!-- IF S_USER_LOGGED_IN --></span>
|
---|
1305 | markup
|
---|
1306 | <span class="comment"><!-- ENDIF --></span>
|
---|
1307 | </pre></div>
|
---|
1308 |
|
---|
1309 | <p>This replaces the existing (fudged) method in 2.0.x using a zero length array and BEGIN/END.</p>
|
---|
1310 |
|
---|
1311 | <h4>Extended syntax for Blocks/Loops</h4>
|
---|
1312 |
|
---|
1313 | <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>
|
---|
1314 |
|
---|
1315 | <div class="codebox"><pre>
|
---|
1316 | <span class="comment"><!-- BEGIN loopname(2) --></span>
|
---|
1317 | markup
|
---|
1318 | <span class="comment"><!-- END loopname --></span>
|
---|
1319 | </pre></div>
|
---|
1320 |
|
---|
1321 | <p>Will start the loop on the third entry (note that indexes start at zero). Extensions of this are:
|
---|
1322 | <br /><br />
|
---|
1323 | <code>loopname(2)</code>: Will start the loop on the 3rd entry<br />
|
---|
1324 | <code>loopname(-2)</code>: Will start the loop two entries from the end<br />
|
---|
1325 | <code>loopname(3,4)</code>: Will start the loop on the fourth entry and end it on the fifth<br />
|
---|
1326 | <code>loopname(3,-4)</code>: Will start the loop on the fourth entry and end it four from last<br />
|
---|
1327 | </p>
|
---|
1328 |
|
---|
1329 | <p>A further extension to begin is BEGINELSE:</p>
|
---|
1330 |
|
---|
1331 | <div class="codebox"><pre>
|
---|
1332 | <span class="comment"><!-- BEGIN loop --></span>
|
---|
1333 | markup
|
---|
1334 | <span class="comment"><!-- BEGINELSE --></span>
|
---|
1335 | markup
|
---|
1336 | <span class="comment"><!-- END loop --></span>
|
---|
1337 | </pre></div>
|
---|
1338 |
|
---|
1339 | <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 "bits of" the existing "switch_" type control (the rest being replaced by conditionals).</p>
|
---|
1340 |
|
---|
1341 | <p>Another way of checking if a loop contains values is by prefixing the loops name with a dot:</p>
|
---|
1342 |
|
---|
1343 | <div class="codebox"><pre>
|
---|
1344 | <span class="comment"><!-- IF .loop --></span>
|
---|
1345 | <span class="comment"><!-- BEGIN loop --></span>
|
---|
1346 | markup
|
---|
1347 | <span class="comment"><!-- END loop --></span>
|
---|
1348 | <span class="comment"><!-- ELSE --></span>
|
---|
1349 | markup
|
---|
1350 | <span class="comment"><!-- ENDIF --></span>
|
---|
1351 | </pre></div>
|
---|
1352 |
|
---|
1353 | <p>You are even able to check the number of items within a loop by comparing it with values within the IF condition:</p>
|
---|
1354 |
|
---|
1355 | <div class="codebox"><pre>
|
---|
1356 | <span class="comment"><!-- IF .loop > 2 --></span>
|
---|
1357 | <span class="comment"><!-- BEGIN loop --></span>
|
---|
1358 | markup
|
---|
1359 | <span class="comment"><!-- END loop --></span>
|
---|
1360 | <span class="comment"><!-- ELSE --></span>
|
---|
1361 | markup
|
---|
1362 | <span class="comment"><!-- ENDIF --></span>
|
---|
1363 | </pre></div>
|
---|
1364 |
|
---|
1365 | <p>Nesting loops cause the conditionals needing prefixed with all loops from the outer one to the inner most. An illustration of this:</p>
|
---|
1366 |
|
---|
1367 | <div class="codebox"><pre>
|
---|
1368 | <span class="comment"><!-- BEGIN firstloop --></span>
|
---|
1369 | {firstloop.MY_VARIABLE_FROM_FIRSTLOOP}
|
---|
1370 |
|
---|
1371 | <span class="comment"><!-- BEGIN secondloop --></span>
|
---|
1372 | {firstloop.secondloop.MY_VARIABLE_FROM_SECONDLOOP}
|
---|
1373 | <span class="comment"><!-- END secondloop --></span>
|
---|
1374 | <span class="comment"><!-- END firstloop --></span>
|
---|
1375 | </pre></div>
|
---|
1376 |
|
---|
1377 | <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>
|
---|
1378 |
|
---|
1379 | <div class="codebox"><pre>
|
---|
1380 | <span class="comment"><!-- BEGIN l_block1 --></span>
|
---|
1381 | <span class="comment"><!-- IF l_block1.S_SELECTED --></span>
|
---|
1382 | <strong>{l_block1.L_TITLE}</strong>
|
---|
1383 | <span class="comment"><!-- IF S_PRIVMSGS --></span>
|
---|
1384 |
|
---|
1385 | <span class="comment"><!-- the ! at the beginning of the loop name forces the loop to be not a nested one of l_block1 --></span>
|
---|
1386 | <span class="comment"><!-- BEGIN !folder --></span>
|
---|
1387 | <span class="comment"><!-- IF folder.S_FIRST_ROW --></span>
|
---|
1388 | <ul class="nav">
|
---|
1389 | <span class="comment"><!-- ENDIF --></span>
|
---|
1390 |
|
---|
1391 | <li><a href="{folder.U_FOLDER}">{folder.FOLDER_NAME}</a></li>
|
---|
1392 |
|
---|
1393 | <span class="comment"><!-- IF folder.S_LAST_ROW --></span>
|
---|
1394 | </ul>
|
---|
1395 | <span class="comment"><!-- ENDIF --></span>
|
---|
1396 | <span class="comment"><!-- END !folder --></span>
|
---|
1397 |
|
---|
1398 | <span class="comment"><!-- ENDIF --></span>
|
---|
1399 |
|
---|
1400 | <ul class="nav">
|
---|
1401 | <span class="comment"><!-- BEGIN l_block2 --></span>
|
---|
1402 | <li>
|
---|
1403 | <span class="comment"><!-- IF l_block1.l_block2.S_SELECTED --></span>
|
---|
1404 | <strong>{l_block1.l_block2.L_TITLE}</strong>
|
---|
1405 | <span class="comment"><!-- ELSE --></span>
|
---|
1406 | <a href="{l_block1.l_block2.U_TITLE}">{l_block1.l_block2.L_TITLE}</a>
|
---|
1407 | <span class="comment"><!-- ENDIF --></span>
|
---|
1408 | </li>
|
---|
1409 | <span class="comment"><!-- END l_block2 --></span>
|
---|
1410 | </ul>
|
---|
1411 | <span class="comment"><!-- ELSE --></span>
|
---|
1412 | <a class="nav" href="{l_block1.U_TITLE}">{l_block1.L_TITLE}</a>
|
---|
1413 | <span class="comment"><!-- ENDIF --></span>
|
---|
1414 | <span class="comment"><!-- END l_block1 --></span>
|
---|
1415 | </pre></div>
|
---|
1416 |
|
---|
1417 | <p>Let us first concentrate on this part of the example:</p>
|
---|
1418 |
|
---|
1419 | <div class="codebox"><pre>
|
---|
1420 | <span class="comment"><!-- BEGIN l_block1 --></span>
|
---|
1421 | <span class="comment"><!-- IF l_block1.S_SELECTED --></span>
|
---|
1422 | markup
|
---|
1423 | <span class="comment"><!-- ELSE --></span>
|
---|
1424 | <a class="nav" href="{l_block1.U_TITLE}">{l_block1.L_TITLE}</a>
|
---|
1425 | <span class="comment"><!-- ENDIF --></span>
|
---|
1426 | <span class="comment"><!-- END l_block1 --></span>
|
---|
1427 | </pre></div>
|
---|
1428 |
|
---|
1429 | <p>Here we open the loop l_block1 and doing 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>
|
---|
1430 |
|
---|
1431 | <p>Let's have a closer look to the markup:</p>
|
---|
1432 |
|
---|
1433 | <div class="codebox"><pre>
|
---|
1434 | <span class="comment"><!-- BEGIN l_block1 --></span>
|
---|
1435 | .
|
---|
1436 | .
|
---|
1437 | <span class="comment"><!-- IF S_PRIVMSGS --></span>
|
---|
1438 |
|
---|
1439 | <span class="comment"><!-- BEGIN !folder --></span>
|
---|
1440 | <span class="comment"><!-- IF folder.S_FIRST_ROW --></span>
|
---|
1441 | <ul class="nav">
|
---|
1442 | <span class="comment"><!-- ENDIF --></span>
|
---|
1443 |
|
---|
1444 | <li><a href="{folder.U_FOLDER}">{folder.FOLDER_NAME}</a></li>
|
---|
1445 |
|
---|
1446 | <span class="comment"><!-- IF folder.S_LAST_ROW --></span>
|
---|
1447 | </ul>
|
---|
1448 | <span class="comment"><!-- ENDIF --></span>
|
---|
1449 | <span class="comment"><!-- END !folder --></span>
|
---|
1450 |
|
---|
1451 | <span class="comment"><!-- ENDIF --></span>
|
---|
1452 | .
|
---|
1453 | .
|
---|
1454 | <span class="comment"><!-- END l_block1 --></span>
|
---|
1455 | </pre></div>
|
---|
1456 |
|
---|
1457 | <p>The <code><!-- IF S_PRIVMSGS --></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><!-- BEGIN !folder --></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><!-- BEGIN folder --></code> we would have been within the loop <code>l_block1.folder</code> automatically as is the case with l_block2:</p>
|
---|
1458 |
|
---|
1459 | <div class="codebox"><pre>
|
---|
1460 | <span class="comment"><!-- BEGIN l_block1 --></span>
|
---|
1461 | .
|
---|
1462 | .
|
---|
1463 | <ul class="nav">
|
---|
1464 | <span class="comment"><!-- BEGIN l_block2 --></span>
|
---|
1465 | <li>
|
---|
1466 | <span class="comment"><!-- IF l_block1.l_block2.S_SELECTED --></span>
|
---|
1467 | <strong>{l_block1.l_block2.L_TITLE}</strong>
|
---|
1468 | <span class="comment"><!-- ELSE --></span>
|
---|
1469 | <a href="{l_block1.l_block2.U_TITLE}">{l_block1.l_block2.L_TITLE}</a>
|
---|
1470 | <span class="comment"><!-- ENDIF --></span>
|
---|
1471 | </li>
|
---|
1472 | <span class="comment"><!-- END l_block2 --></span>
|
---|
1473 | </ul>
|
---|
1474 | .
|
---|
1475 | .
|
---|
1476 | <span class="comment"><!-- END l_block1 --></span>
|
---|
1477 | </pre></div>
|
---|
1478 |
|
---|
1479 | <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>
|
---|
1480 |
|
---|
1481 | <p>Now back to our folder loop:</p>
|
---|
1482 |
|
---|
1483 | <div class="codebox"><pre>
|
---|
1484 | <span class="comment"><!-- IF folder.S_FIRST_ROW --></span>
|
---|
1485 | <ul class="nav">
|
---|
1486 | <span class="comment"><!-- ENDIF --></span>
|
---|
1487 |
|
---|
1488 | <li><a href="{folder.U_FOLDER}">{folder.FOLDER_NAME}</a></li>
|
---|
1489 |
|
---|
1490 | <span class="comment"><!-- IF folder.S_LAST_ROW --></span>
|
---|
1491 | </ul>
|
---|
1492 | <span class="comment"><!-- ENDIF --></span>
|
---|
1493 | </pre></div>
|
---|
1494 |
|
---|
1495 | <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>
|
---|
1496 |
|
---|
1497 | <div class="codebox"><pre>
|
---|
1498 | <ul class="nav"> <span class="comment"><!-- written on first iteration --></span>
|
---|
1499 | <li>first element</li> <span class="comment"><!-- written on first iteration --></span>
|
---|
1500 | <li>second element</li> <span class="comment"><!-- written on second iteration --></span>
|
---|
1501 | <li>third element</li> <span class="comment"><!-- written on third iteration --></span>
|
---|
1502 | </ul> <span class="comment"><!-- written on third iteration --></span>
|
---|
1503 | </pre></div>
|
---|
1504 |
|
---|
1505 | <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>
|
---|
1506 |
|
---|
1507 | <div class="codebox"><pre>
|
---|
1508 | <span class="comment"><!-- IF folder.S_FIRST_ROW --></span>
|
---|
1509 | <ul class="nav">
|
---|
1510 | <span class="comment"><!-- ELSEIF folder.S_LAST_ROW --></span>
|
---|
1511 | </ul>
|
---|
1512 | <span class="comment"><!-- ELSE --></span>
|
---|
1513 | <li><a href="{folder.U_FOLDER}">{folder.FOLDER_NAME}</a></li>
|
---|
1514 | <span class="comment"><!-- ENDIF --></span>
|
---|
1515 | </pre></div>
|
---|
1516 |
|
---|
1517 | <p>would result in the following markup:</p>
|
---|
1518 |
|
---|
1519 | <div class="codebox"><pre>
|
---|
1520 | <ul class="nav"> <span class="comment"><!-- written on first iteration --></span>
|
---|
1521 | <li>second element</li> <span class="comment"><!-- written on second iteration --></span>
|
---|
1522 | </ul> <span class="comment"><!-- written on third iteration --></span>
|
---|
1523 | </pre></div>
|
---|
1524 |
|
---|
1525 | <p>Just always remember that processing is taking place from up to down.</p>
|
---|
1526 |
|
---|
1527 | <h4>Forms</h4>
|
---|
1528 | <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>
|
---|
1529 | <div class="codebox"><pre>
|
---|
1530 | <form method="post" id="mcp" action="{U_POST_ACTION}">
|
---|
1531 |
|
---|
1532 | <fieldset class="submit-buttons">
|
---|
1533 | <input type="reset" value="{L_RESET}" name="reset" class="button2" />
|
---|
1534 | <input type="submit" name="action[add_warning]" value="{L_SUBMIT}" class="button1" />
|
---|
1535 | {S_FORM_TOKEN}
|
---|
1536 | </fieldset>
|
---|
1537 | </form>
|
---|
1538 | </pre></div><br />
|
---|
1539 |
|
---|
1540 | <a name="inheritance"></a><h3>4.ii. Template Inheritance</h3>
|
---|
1541 | <p>When basing a new template on an existing one, it is not necessary to provide all template files. By declaring the template to be "<strong>inheriting</strong>" in the template configuration file.</p>
|
---|
1542 |
|
---|
1543 | <p>The limitation on this is that the base style has to be installed and complete, meaning that it is not itself inheriting.</p>
|
---|
1544 |
|
---|
1545 | <p>The effect of doing so is that the template engine will use the files in the new template where they exist, but fall back to files in the base template otherwise. Declaring a style to be inheriting also causes it to use some of the configuration settings of the base style, notably database storage.</p>
|
---|
1546 |
|
---|
1547 | <p>We strongly encourage the use of inheritance for styles based on the bundled styles, as it will ease the update procedure.</p>
|
---|
1548 |
|
---|
1549 | <div class="codebox"><pre>
|
---|
1550 | # General Information about this template
|
---|
1551 | name = inherits
|
---|
1552 | copyright = © phpBB Group, 2007
|
---|
1553 | version = 3.0.3
|
---|
1554 |
|
---|
1555 | # Defining a different template bitfield
|
---|
1556 | template_bitfield = lNg=
|
---|
1557 |
|
---|
1558 | # Are we inheriting?
|
---|
1559 | inherit_from = prosilver
|
---|
1560 | </pre></div>
|
---|
1561 |
|
---|
1562 | </div>
|
---|
1563 |
|
---|
1564 | <div class="back2top"><a href="#wrap" class="top">Back to Top</a></div>
|
---|
1565 |
|
---|
1566 | <span class="corners-bottom"><span></span></span></div>
|
---|
1567 | </div>
|
---|
1568 |
|
---|
1569 | <hr />
|
---|
1570 |
|
---|
1571 |
|
---|
1572 |
|
---|
1573 | <a name="charsets"></a><h2>5. Character Sets and Encodings</h2>
|
---|
1574 |
|
---|
1575 | <div class="paragraph">
|
---|
1576 | <div class="inner"><span class="corners-top"><span></span></span>
|
---|
1577 |
|
---|
1578 | <div class="content">
|
---|
1579 |
|
---|
1580 |
|
---|
1581 |
|
---|
1582 | <h4>What are Unicode, UCS and UTF-8?</h4>
|
---|
1583 | <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>
|
---|
1584 |
|
---|
1585 | <h4>phpBB's use of Unicode</h4>
|
---|
1586 | <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>
|
---|
1587 |
|
---|
1588 | <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>
|
---|
1589 |
|
---|
1590 | <p>With <code>request_var()</code> you can either allow all UCS characters in user input or restrict user input to ASCII characters. This feature is controlled by the function's third parameter called <code>$multibyte</code>. You should allow multibyte characters in posts, PMs, topic titles, forum names, etc. but it's not necessary for internal uses like a <code>$mode</code> variable which should only hold a predefined list of ASCII strings anyway.</p>
|
---|
1591 |
|
---|
1592 | <div class="codebox"><pre>
|
---|
1593 | // an input string containing a multibyte character
|
---|
1594 | $_REQUEST['multibyte_string'] = 'Käse';
|
---|
1595 |
|
---|
1596 | // print request variable as a UTF-8 string allowing multibyte characters
|
---|
1597 | echo request_var('multibyte_string', '', true);
|
---|
1598 | // print request variable as ASCII string
|
---|
1599 | echo request_var('multibyte_string', '');
|
---|
1600 | </pre></div>
|
---|
1601 |
|
---|
1602 | <p>This code snippet will generate the following output:</p>
|
---|
1603 |
|
---|
1604 | <div class="codebox"><pre>
|
---|
1605 | Käse
|
---|
1606 | K??se
|
---|
1607 | </pre></div>
|
---|
1608 |
|
---|
1609 | <h4>Unicode Normalization</h4>
|
---|
1610 |
|
---|
1611 | <p>If you retrieve user input with multibyte characters you should additionally normalize the string using <code>utf8_normalize_nfc()</code> before you work with it. This is necessary to make sure that equal characters can only occur in one particular binary representation. For example the character Å can be represented either as <code>U+00C5</code> (LATIN CAPITAL LETTER A WITH RING ABOVE) or as <code>U+212B</code> (ANGSTROM SIGN). phpBB uses Normalization Form Canonical Composition (NFC) for all text. So the correct version of the above example would look like this:</p>
|
---|
1612 |
|
---|
1613 | <div class="codebox"><pre>
|
---|
1614 | $_REQUEST['multibyte_string'] = 'Käse';
|
---|
1615 |
|
---|
1616 | // normalize multibyte strings
|
---|
1617 | echo utf8_normalize_nfc(request_var('multibyte_string', '', true));
|
---|
1618 | // ASCII strings do not need to be normalized
|
---|
1619 | echo request_var('multibyte_string', '');
|
---|
1620 | </pre></div>
|
---|
1621 |
|
---|
1622 | <h4>Case Folding</h4>
|
---|
1623 |
|
---|
1624 | <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>
|
---|
1625 |
|
---|
1626 | <p class="bad">// Bad - The strings might be the same even if strtolower differs</p>
|
---|
1627 |
|
---|
1628 | <div class="codebox"><pre>
|
---|
1629 | if (strtolower($string1) == strtolower($string2))
|
---|
1630 | {
|
---|
1631 | echo '$string1 and $string2 are equal or differ in case';
|
---|
1632 | }
|
---|
1633 | </pre></div>
|
---|
1634 |
|
---|
1635 | <p class="good">// Good - Case folding is really case insensitive</p>
|
---|
1636 |
|
---|
1637 | <div class="codebox"><pre>
|
---|
1638 | if (utf8_case_fold_nfc($string1) == utf8_case_fold_nfc($string2))
|
---|
1639 | {
|
---|
1640 | echo '$string1 and $string2 are equal or differ in case';
|
---|
1641 | }
|
---|
1642 | </pre></div>
|
---|
1643 |
|
---|
1644 | <h4>Confusables Detection</h4>
|
---|
1645 |
|
---|
1646 | <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>
|
---|
1647 |
|
---|
1648 | </div>
|
---|
1649 |
|
---|
1650 | <div class="back2top"><a href="#wrap" class="top">Back to Top</a></div>
|
---|
1651 |
|
---|
1652 | <span class="corners-bottom"><span></span></span></div>
|
---|
1653 | </div>
|
---|
1654 |
|
---|
1655 | <hr />
|
---|
1656 |
|
---|
1657 | <a name="translation"></a><h2>6. Translation (<abbr title="Internationalisation">i18n</abbr>/<abbr title="Localisation">L10n</abbr>) Guidelines</h2>
|
---|
1658 |
|
---|
1659 | <div class="paragraph">
|
---|
1660 | <div class="inner"><span class="corners-top"><span></span></span>
|
---|
1661 |
|
---|
1662 | <div class="content">
|
---|
1663 |
|
---|
1664 | <a name="standardisation"></a><h3>6.i. Standardisation</h3>
|
---|
1665 |
|
---|
1666 | <h4>Reason:</h4>
|
---|
1667 |
|
---|
1668 | <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>
|
---|
1669 |
|
---|
1670 | <h4>Encoding:</h4>
|
---|
1671 |
|
---|
1672 | <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), this removes the need to convert between encodings and improves the accessibility of multilingual forums.</p>
|
---|
1673 |
|
---|
1674 | <p>The impact is that the language files for phpBB must now also be encoded as UTF-8, with a caveat that the files must <strong>not contain</strong> a <acronym title="Byte-Order-Mark">BOM</acronym> for compatibility reasons with non-Unicode aware versions of PHP. For those with forums using the Latin character set (ie: most European languages), this change is transparent since UTF-8 is superset to US-ASCII and ISO-8859-1.</p>
|
---|
1675 |
|
---|
1676 | <h4>Language Tag:</h4>
|
---|
1677 |
|
---|
1678 | <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>
|
---|
1679 |
|
---|
1680 | <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>
|
---|
1681 |
|
---|
1682 | <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>
|
---|
1683 |
|
---|
1684 | <table summary="Examples of various possible language tags as described by RFC 4646 and RFC 4647">
|
---|
1685 | <caption>Language tag examples</caption>
|
---|
1686 | <thead>
|
---|
1687 | <tr>
|
---|
1688 | <th scope="col">Language tag</th>
|
---|
1689 | <th scope="col">Description</th>
|
---|
1690 | <th scope="col">Component subtags</th>
|
---|
1691 | </tr>
|
---|
1692 | </thead>
|
---|
1693 | <tbody>
|
---|
1694 | <tr>
|
---|
1695 | <td><code>en</code></td>
|
---|
1696 | <td>English</td>
|
---|
1697 | <td><code>language</code></td>
|
---|
1698 | </tr>
|
---|
1699 | <tr>
|
---|
1700 | <td><code>mas</code></td>
|
---|
1701 | <td>Masai</td>
|
---|
1702 | <td><code>language</code></td>
|
---|
1703 | </tr>
|
---|
1704 | <tr>
|
---|
1705 | <td><code>fr-CA</code></td>
|
---|
1706 | <td>French as used in Canada</td>
|
---|
1707 | <td><code>language</code>+<code>region</code></td>
|
---|
1708 | </tr>
|
---|
1709 | <tr>
|
---|
1710 | <td><code>en-833</code></td>
|
---|
1711 | <td>English as used in the Isle of Man</td>
|
---|
1712 | <td><code>language</code>+<code>region</code></td>
|
---|
1713 | </tr>
|
---|
1714 | <tr>
|
---|
1715 | <td><code>zh-Hans</code></td>
|
---|
1716 | <td>Chinese written with Simplified script</td>
|
---|
1717 | <td><code>language</code>+<code>script</code></td>
|
---|
1718 | </tr>
|
---|
1719 | <tr>
|
---|
1720 | <td><code>zh-Hant-HK</code></td>
|
---|
1721 | <td>Chinese written with Traditional script as used in Hong Kong</td>
|
---|
1722 | <td><code>language</code>+<code>script</code>+<code>region</code></td>
|
---|
1723 | </tr>
|
---|
1724 | <tr>
|
---|
1725 | <td><code>de-AT-1996</code></td>
|
---|
1726 | <td>German as used in Austria with 1996 orthography</td>
|
---|
1727 | <td><code>language</code>+<code>region</code>+<code>variant</code></td>
|
---|
1728 | </tr>
|
---|
1729 | </tbody>
|
---|
1730 | </table>
|
---|
1731 |
|
---|
1732 | <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>
|
---|
1733 |
|
---|
1734 | <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>
|
---|
1735 |
|
---|
1736 | <table summary="Examples of using a language subtag in combination with a script subtag">
|
---|
1737 | <caption>Language subtag + script subtag examples</caption>
|
---|
1738 | <thead>
|
---|
1739 | <tr>
|
---|
1740 | <th scope="col">Language tag</th>
|
---|
1741 | <th scope="col">Description</th>
|
---|
1742 | <th scope="col">Component subtags</th>
|
---|
1743 | </tr>
|
---|
1744 | </thead>
|
---|
1745 | <tbody>
|
---|
1746 | <tr>
|
---|
1747 | <td><code>en-Brai</code></td>
|
---|
1748 | <td>English written in Braille script</td>
|
---|
1749 | <td><code>language</code>+<code>script</code></td>
|
---|
1750 | </tr>
|
---|
1751 | <tr>
|
---|
1752 | <td><code>en-Dsrt</code></td>
|
---|
1753 | <td>English written in Deseret (Mormon) script</td>
|
---|
1754 | <td><code>language</code>+<code>script</code></td>
|
---|
1755 | </tr>
|
---|
1756 | <tr>
|
---|
1757 | <td><code>sr-Latn</code></td>
|
---|
1758 | <td>Serbian written in Latin script</td>
|
---|
1759 | <td><code>language</code>+<code>script</code></td>
|
---|
1760 | </tr>
|
---|
1761 | <tr>
|
---|
1762 | <td><code>sr-Cyrl</code></td>
|
---|
1763 | <td>Serbian written in Cyrillic script</td>
|
---|
1764 | <td><code>language</code>+<code>script</code></td>
|
---|
1765 | </tr>
|
---|
1766 | <tr>
|
---|
1767 | <td><code>mn-Mong</code></td>
|
---|
1768 | <td>Mongolian written in Mongolian script</td>
|
---|
1769 | <td><code>language</code>+<code>script</code></td>
|
---|
1770 | </tr>
|
---|
1771 | <tr>
|
---|
1772 | <td><code>mn-Cyrl</code></td>
|
---|
1773 | <td>Mongolian written in Cyrillic script</td>
|
---|
1774 | <td><code>language</code>+<code>script</code></td>
|
---|
1775 | </tr>
|
---|
1776 | <tr>
|
---|
1777 | <td><code>mn-Phag</code></td>
|
---|
1778 | <td>Mongolian written in Phags-pa script</td>
|
---|
1779 | <td><code>language</code>+<code>script</code></td>
|
---|
1780 | </tr>
|
---|
1781 | <tr>
|
---|
1782 | <td><code>az-Cyrl-AZ</code></td>
|
---|
1783 | <td>Azerbaijani written in Cyrillic script as used in Azerbaijan</td>
|
---|
1784 | <td><code>language</code>+<code>script</code>+<code>region</code></td>
|
---|
1785 | </tr>
|
---|
1786 | <tr>
|
---|
1787 | <td><code>az-Latn-AZ</code></td>
|
---|
1788 | <td>Azerbaijani written in Latin script as used in Azerbaijan</td>
|
---|
1789 | <td><code>language</code>+<code>script</code>+<code>region</code></td>
|
---|
1790 | </tr>
|
---|
1791 | <tr>
|
---|
1792 | <td><code>az-Arab-IR</code></td>
|
---|
1793 | <td>Azerbaijani written in Arabic script as used in Iran</td>
|
---|
1794 | <td><code>language</code>+<code>script</code>+<code>region</code></td>
|
---|
1795 | </tr>
|
---|
1796 | </tbody>
|
---|
1797 | </table>
|
---|
1798 |
|
---|
1799 | <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>
|
---|
1800 |
|
---|
1801 | <p>Examples of English using marco-geographical regions:</p>
|
---|
1802 |
|
---|
1803 | <table summary="Examples for English of ISO 3166-1 alpha-2 vs. UN M.49 code">
|
---|
1804 | <caption>Coding for English using macro-geographical regions</caption>
|
---|
1805 | <thead>
|
---|
1806 | <tr>
|
---|
1807 | <th scope="col">ISO 639-1/ISO 639-2 + ISO 3166-1 alpha-2</th>
|
---|
1808 | <th scope="col" colspan="2">ISO 639-1/ISO 639-2 + UN M.49 (Example macro regions)</th>
|
---|
1809 | </tr>
|
---|
1810 | </thead>
|
---|
1811 | <tbody>
|
---|
1812 | <tr>
|
---|
1813 | <td><dl><dt><code>en-AU</code></dt><dd>English as used in <strong>Australia</strong></dd></dl></td>
|
---|
1814 | <td rowspan="2"><dl><dt><code>en-053</code></dt><dd>English as used in <strong>Australia & New Zealand</strong></dd></dl></td>
|
---|
1815 | <td rowspan="3"><dl><dt><code>en-009</code></dt><dd>English as used in <strong>Oceania</strong></dd></dl></td>
|
---|
1816 | </tr>
|
---|
1817 | <tr>
|
---|
1818 | <td><dl><dt><code>en-NZ</code></dt><dd>English as used in <strong>New Zealand</strong></dd></dl></td>
|
---|
1819 | </tr>
|
---|
1820 | <tr>
|
---|
1821 | <td><dl><dt><code>en-FJ</code></dt><dd>English as used in <strong>Fiji</strong></dd></dl></td>
|
---|
1822 | <td><dl><dt><code>en-054 </code></dt><dd>English as used in <strong>Melanesia</strong></dd></dl></td>
|
---|
1823 | </tr>
|
---|
1824 | </tbody>
|
---|
1825 | </table>
|
---|
1826 |
|
---|
1827 | <p>Examples of Spanish using marco-geographical regions:</p>
|
---|
1828 |
|
---|
1829 | <table summary="Examples for Spanish of ISO 3166-1 alpha-2 vs. UN M.49 code">
|
---|
1830 | <caption>Coding for Spanish macro-geographical regions</caption>
|
---|
1831 | <thead>
|
---|
1832 | <tr>
|
---|
1833 | <th scope="col">ISO 639-1/ISO 639-2 + ISO 3166-1 alpha-2</th>
|
---|
1834 | <th scope="col" colspan="2">ISO 639-1/ISO 639-2 + UN M.49 (Example macro regions)</th>
|
---|
1835 | </tr>
|
---|
1836 | </thead>
|
---|
1837 | <tbody>
|
---|
1838 | <tr>
|
---|
1839 | <td><dl><dt><code>es-PR</code></dt><dd>Spanish as used in <strong>Puerto Rico</strong></dd></dl></td>
|
---|
1840 | <td rowspan="3"><dl><dt><code>es-419</code></dt><dd>Spanish as used in <strong>Latin America & the Caribbean</strong></dd></dl></td>
|
---|
1841 | <td rowspan="4"><dl><dt><code>es-019</code></dt><dd>Spanish as used in <strong>the Americas</strong></dd></dl></td>
|
---|
1842 | </tr>
|
---|
1843 | <tr>
|
---|
1844 | <td><dl><dt><code>es-HN</code></dt><dd>Spanish as used in <strong>Honduras</strong></dd></dl></td>
|
---|
1845 | </tr>
|
---|
1846 | <tr>
|
---|
1847 | <td><dl><dt><code>es-AR</code></dt><dd>Spanish as used in <strong>Argentina</strong></dd></dl></td>
|
---|
1848 | </tr>
|
---|
1849 | <tr>
|
---|
1850 | <td><dl><dt><code>es-US</code></dt><dd>Spanish as used in <strong>United States of America</strong></dd></dl></td>
|
---|
1851 | <td><dl><dt><code>es-021</code></dt><dd>Spanish as used in <strong>North America</strong></dd></dl></td>
|
---|
1852 | </tr>
|
---|
1853 | </tbody>
|
---|
1854 | </table>
|
---|
1855 |
|
---|
1856 | <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>
|
---|
1857 |
|
---|
1858 | <table summary="Example where the ISO 3166-1 alpha-2 is ambiguous">
|
---|
1859 | <caption>Coding for ambiguous ISO 3166-1 alpha-2 regions</caption>
|
---|
1860 | <thead>
|
---|
1861 | <tr>
|
---|
1862 | <th scope="col" colspan="2"><code>CS</code> assignment pre-1994</th>
|
---|
1863 | <th scope="col" colspan="2"><code>CS</code> assignment post-1994</th>
|
---|
1864 | </tr>
|
---|
1865 | </thead>
|
---|
1866 | <tbody>
|
---|
1867 | <tr>
|
---|
1868 | <td colspan="2">
|
---|
1869 | <dl>
|
---|
1870 | <dt><code>CS</code></dt><dd><strong>Czechoslovakia</strong> (ISO 3166-1)</dd>
|
---|
1871 | <dt><code>200</code></dt><dd><strong>Czechoslovakia</strong> (UN M.49)</dd>
|
---|
1872 | </dl>
|
---|
1873 | </td>
|
---|
1874 | <td colspan="2">
|
---|
1875 | <dl>
|
---|
1876 | <dt><code>CS</code></dt><dd><strong>Serbian & Montenegro</strong> (ISO 3166-1)</dd>
|
---|
1877 | <dt><code>891</code></dt><dd><strong>Serbian & Montenegro</strong> (UN M.49)</dd>
|
---|
1878 | </dl>
|
---|
1879 | </td>
|
---|
1880 | </tr>
|
---|
1881 | <tr>
|
---|
1882 | <td>
|
---|
1883 | <dl>
|
---|
1884 | <dt><code>CZ</code></dt><dd><strong>Czech Republic</strong> (ISO 3166-1)</dd>
|
---|
1885 | <dt><code>203</code></dt><dd><strong>Czech Republic</strong> (UN M.49)</dd>
|
---|
1886 | </dl>
|
---|
1887 | </td>
|
---|
1888 | <td>
|
---|
1889 | <dl>
|
---|
1890 | <dt><code>SK</code></dt><dd><strong>Slovakia</strong> (ISO 3166-1)</dd>
|
---|
1891 | <dt><code>703</code></dt><dd><strong>Slovakia</strong> (UN M.49)</dd>
|
---|
1892 | </dl>
|
---|
1893 | </td>
|
---|
1894 | <td>
|
---|
1895 | <dl>
|
---|
1896 | <dt><code>RS</code></dt><dd><strong>Serbia</strong> (ISO 3166-1)</dd>
|
---|
1897 | <dt><code>688</code></dt><dd><strong>Serbia</strong> (UN M.49)</dd>
|
---|
1898 | </dl>
|
---|
1899 | </td>
|
---|
1900 | <td>
|
---|
1901 | <dl>
|
---|
1902 | <dt><code>ME</code></dt><dd><strong>Montenegro</strong> (ISO 3166-1)</dd>
|
---|
1903 | <dt><code>499</code></dt><dd><strong>Montenegro</strong> (UN M.49)</dd>
|
---|
1904 | </dl>
|
---|
1905 | </td>
|
---|
1906 | </tr>
|
---|
1907 | </tbody>
|
---|
1908 | </table>
|
---|
1909 |
|
---|
1910 | <h4>Macro-languages & Topolects:</h4>
|
---|
1911 |
|
---|
1912 | <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>
|
---|
1913 |
|
---|
1914 | <table summary="Examples of macrolanguages used with sub-language subtags">
|
---|
1915 | <caption>Macrolanguage subtag + sub-language subtag examples</caption>
|
---|
1916 | <thead>
|
---|
1917 | <tr>
|
---|
1918 | <th scope="col">Language tag</th>
|
---|
1919 | <th scope="col">Description</th>
|
---|
1920 | <th scope="col">Component subtags</th>
|
---|
1921 | </tr>
|
---|
1922 | </thead>
|
---|
1923 | <tbody>
|
---|
1924 | <tr>
|
---|
1925 | <td><code>zh-cmn</code></td>
|
---|
1926 | <td>Mandarin (Putonghau/Guoyu) Chinese</td>
|
---|
1927 | <td><code>macrolanguage</code>+<code>sublanguage</code></td>
|
---|
1928 | </tr>
|
---|
1929 | <tr>
|
---|
1930 | <td><code>zh-yue</code></td>
|
---|
1931 | <td>Yue (Cantonese) Chinese</td>
|
---|
1932 | <td><code>macrolanguage</code>+<code>sublanguage</code></td>
|
---|
1933 | </tr>
|
---|
1934 | <tr>
|
---|
1935 | <td><code>zh-cmn-Hans</code></td>
|
---|
1936 | <td>Mandarin (Putonghau/Guoyu) Chinese written in Simplified script</td>
|
---|
1937 | <td><code>macrolanguage</code>+<code>sublanguage</code>+<code>script</code></td>
|
---|
1938 | </tr>
|
---|
1939 | <tr>
|
---|
1940 | <td><code>zh-cmn-Hant</code></td>
|
---|
1941 | <td>Mandarin (Putonghau/Guoyu) Chinese written in Traditional script</td>
|
---|
1942 | <td><code>macrolanguage</code>+<code>sublanguage</code>+<code>script</code></td>
|
---|
1943 | </tr>
|
---|
1944 | <tr>
|
---|
1945 | <td><code>zh-nan-Latn-TW</code></td>
|
---|
1946 | <td>Minnan (Hoklo) Chinese written in Latin script (POJ Romanisation) as used in Taiwan</td>
|
---|
1947 | <td><code>macrolanguage</code>+<code>sublanguage</code>+<code>script</code>+<code>region</code></td>
|
---|
1948 | </tr>
|
---|
1949 | </tbody>
|
---|
1950 | </table>
|
---|
1951 |
|
---|
1952 | <a name="otherconsiderations"></a><h3>6.ii. Other considerations</h3>
|
---|
1953 |
|
---|
1954 | <h4>Normalisation of language tags for phpBB:</h4>
|
---|
1955 |
|
---|
1956 | <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>
|
---|
1957 |
|
---|
1958 | <table summary="Normalisation of language tags for usage in phpBB">
|
---|
1959 | <caption>Language tag normalisation examples</caption>
|
---|
1960 | <thead>
|
---|
1961 | <tr>
|
---|
1962 | <th scope="col">Raw language tag</th>
|
---|
1963 | <th scope="col">Description</th>
|
---|
1964 | <th scope="col">Value of <code>USER_LANG</code><br />in <code>./common.php</code></th>
|
---|
1965 | <th scope="col">Language pack directory<br />name in <code>/language/</code></th>
|
---|
1966 | </tr>
|
---|
1967 | </thead>
|
---|
1968 | <tbody>
|
---|
1969 | <tr>
|
---|
1970 | <td><code>en</code></td>
|
---|
1971 | <td>British English</td>
|
---|
1972 | <td><code>en</code></td>
|
---|
1973 | <td><code>en</code></td>
|
---|
1974 | </tr>
|
---|
1975 | <tr>
|
---|
1976 | <td><code>de-AT</code></td>
|
---|
1977 | <td>German as used in Austria</td>
|
---|
1978 | <td><code>de-at</code></td>
|
---|
1979 | <td><code>de_at</code></td>
|
---|
1980 | </tr>
|
---|
1981 | <tr>
|
---|
1982 | <td><code>es-419</code></td>
|
---|
1983 | <td>Spanish as used in Latin America & Caribbean</td>
|
---|
1984 | <td><code>en-419</code></td>
|
---|
1985 | <td><code>en_419</code></td>
|
---|
1986 | </tr>
|
---|
1987 | <tr>
|
---|
1988 | <td><code>zh-yue-Hant-HK</code></td>
|
---|
1989 | <td>Cantonese written in Traditional script as used in Hong Kong</td>
|
---|
1990 | <td><code>zh-yue-hant-hk</code></td>
|
---|
1991 | <td><code>zh_yue_hant_hk</code></td>
|
---|
1992 | </tr>
|
---|
1993 | </tbody>
|
---|
1994 | </table>
|
---|
1995 |
|
---|
1996 | <h4>How to use <code>iso.txt</code>:</h4>
|
---|
1997 |
|
---|
1998 | <p>The <code>iso.txt</code> file is a small UTF-8 encoded plain-text file which consists of three lines:</p>
|
---|
1999 |
|
---|
2000 | <ol>
|
---|
2001 | <li><code>Language's English name</code></li>
|
---|
2002 | <li><code>Language's local name</code></li>
|
---|
2003 | <li><code>Authors information</code></li>
|
---|
2004 | </ol>
|
---|
2005 |
|
---|
2006 | <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>
|
---|
2007 |
|
---|
2008 | <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>
|
---|
2009 |
|
---|
2010 | <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>
|
---|
2011 |
|
---|
2012 | <table summary="English language description examples of iso.txt for usage in phpBB">
|
---|
2013 | <caption>English language description examples for iso.txt</caption>
|
---|
2014 | <thead>
|
---|
2015 | <tr>
|
---|
2016 | <th scope="col">Raw language tag</th>
|
---|
2017 | <th scope="col">English description within <code>iso.txt</code></th>
|
---|
2018 | </tr>
|
---|
2019 | </thead>
|
---|
2020 | <tbody>
|
---|
2021 | <tr>
|
---|
2022 | <td><code>en</code></td>
|
---|
2023 | <td>British English</td>
|
---|
2024 | </tr>
|
---|
2025 | <tr>
|
---|
2026 | <td><code>en-US</code></td>
|
---|
2027 | <td>English (United States)</td>
|
---|
2028 | </tr>
|
---|
2029 | <tr>
|
---|
2030 | <td><code>en-053</code></td>
|
---|
2031 | <td>English (Australia & New Zealand)</td>
|
---|
2032 | </tr>
|
---|
2033 | <tr>
|
---|
2034 | <td><code>de</code></td>
|
---|
2035 | <td>German</td>
|
---|
2036 | </tr>
|
---|
2037 | <tr>
|
---|
2038 | <td><code>de-CH-1996</code></td>
|
---|
2039 | <td>German (Switzerland, 1996 orthography)</td>
|
---|
2040 | </tr>
|
---|
2041 | <tr>
|
---|
2042 | <td><code>gws-1996</code></td>
|
---|
2043 | <td>Swiss German (1996 orthography)</td>
|
---|
2044 | </tr>
|
---|
2045 | <tr>
|
---|
2046 | <td><code>zh-cmn-Hans-CN</code></td>
|
---|
2047 | <td>Mandarin Chinese (Simplified, Mainland China)</td>
|
---|
2048 | </tr>
|
---|
2049 | <tr>
|
---|
2050 | <td><code>zh-yue-Hant-HK</code></td>
|
---|
2051 | <td>Cantonese Chinese (Traditional, Hong Kong)</td>
|
---|
2052 | </tr>
|
---|
2053 | </tbody>
|
---|
2054 | </table>
|
---|
2055 |
|
---|
2056 | <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>
|
---|
2057 |
|
---|
2058 | <h4>Unicode bi-directional considerations:</h4>
|
---|
2059 |
|
---|
2060 | <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>
|
---|
2061 |
|
---|
2062 | <p>The various Unicode control characters for bi-directional text and their HTML enquivalents where appropriate are as follows:</p>
|
---|
2063 |
|
---|
2064 | <table summary="Table of the various Unicode bidirectional control characters">
|
---|
2065 | <caption>Unicode bidirectional control characters & HTML elements/entities</caption>
|
---|
2066 | <thead>
|
---|
2067 | <tr>
|
---|
2068 | <th scope="col">Unicode character<br />abbreviation</th>
|
---|
2069 | <th scope="col">Unicode<br />code-point</th>
|
---|
2070 | <th scope="col">Unicode character<br />name</th>
|
---|
2071 | <th scope="col">Equivalent HTML<br />markup/entity</th>
|
---|
2072 | <th scope="col">Raw character<br />(enclosed between '')</th>
|
---|
2073 | </tr>
|
---|
2074 | </thead>
|
---|
2075 | <tbody>
|
---|
2076 | <tr>
|
---|
2077 | <td><code>LRM</code></td>
|
---|
2078 | <td><code>U+200E</code></td>
|
---|
2079 | <td>Left-to-Right Mark</td>
|
---|
2080 | <td><code>&lrm;</code></td>
|
---|
2081 | <td>'‎'</td>
|
---|
2082 | </tr>
|
---|
2083 | <tr>
|
---|
2084 | <td><code>RLM</code></td>
|
---|
2085 | <td><code>U+200F</code></td>
|
---|
2086 | <td>Right-to-Left Mark</td>
|
---|
2087 | <td><code>&rlm;</code></td>
|
---|
2088 | <td>'‏'</td>
|
---|
2089 | </tr>
|
---|
2090 | <tr>
|
---|
2091 | <td><code>LRE</code></td>
|
---|
2092 | <td><code>U+202A</code></td>
|
---|
2093 | <td>Left-to-Right Embedding</td>
|
---|
2094 | <td><code>dir="ltr"</code></td>
|
---|
2095 | <td>'‪'</td>
|
---|
2096 | </tr>
|
---|
2097 | <tr>
|
---|
2098 | <td><code>RLE</code></td>
|
---|
2099 | <td><code>U+202B</code></td>
|
---|
2100 | <td>Right-to-Left Embedding</td>
|
---|
2101 | <td><code>dir="rtl"</code></td>
|
---|
2102 | <td>'‫'</td>
|
---|
2103 | </tr>
|
---|
2104 | <tr>
|
---|
2105 | <td><code>PDF</code></td>
|
---|
2106 | <td><code>U+202C</code></td>
|
---|
2107 | <td>Pop Directional Formatting</td>
|
---|
2108 | <td><code></bdo></code></td>
|
---|
2109 | <td>'‬'</td>
|
---|
2110 | </tr>
|
---|
2111 | <tr>
|
---|
2112 | <td><code>LRO</code></td>
|
---|
2113 | <td><code>U+202D</code></td>
|
---|
2114 | <td>Left-to-Right Override</td>
|
---|
2115 | <td><code><bdo dir="ltr"></code></td>
|
---|
2116 | <td>'‭'</td>
|
---|
2117 | </tr>
|
---|
2118 | <tr>
|
---|
2119 | <td><code>RLO</code></td>
|
---|
2120 | <td><code>U+202E</code></td>
|
---|
2121 | <td>Right-to-Left Override</td>
|
---|
2122 | <td><code><bdo dir="rtl"></code></td>
|
---|
2123 | <td>'‮'</td>
|
---|
2124 | </tr>
|
---|
2125 | </tbody>
|
---|
2126 | </table>
|
---|
2127 |
|
---|
2128 | <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>
|
---|
2129 |
|
---|
2130 | <table summary="Effect of using Unicode bidirectional control characters within iso.txt">
|
---|
2131 | <caption>Unicode bidirectional control characters iso.txt</caption>
|
---|
2132 | <thead>
|
---|
2133 | <tr>
|
---|
2134 | <th scope="col">Directionality</th>
|
---|
2135 | <th scope="col">Raw character view</th>
|
---|
2136 | <th scope="col">Display of localised<br />description in <code>iso.txt</code></th>
|
---|
2137 | <th scope="col">Ordering</th>
|
---|
2138 | </tr>
|
---|
2139 | </thead>
|
---|
2140 | <tbody>
|
---|
2141 | <tr>
|
---|
2142 | <td><code>dir="ltr"</code></td>
|
---|
2143 | <td>English (Australia & New Zealand)</td>
|
---|
2144 | <td dir="ltr">English (Australia & New Zealand)</td>
|
---|
2145 | <td class="good">Correct</td>
|
---|
2146 | </tr>
|
---|
2147 | <tr>
|
---|
2148 | <td><code>dir="rtl"</code></td>
|
---|
2149 | <td>English (Australia & New Zealand)</td>
|
---|
2150 | <td dir="rtl">English (Australia & New Zealand)</td>
|
---|
2151 | <td class="bad">Incorrect</td>
|
---|
2152 | </tr>
|
---|
2153 | <tr>
|
---|
2154 | <td><code>dir="rtl"</code> with <code>LRM</code></td>
|
---|
2155 | <td>English (Australia & New Zealand)<code>U+200E</code></td>
|
---|
2156 | <td dir="rtl">English (Australia & New Zealand)‎</td>
|
---|
2157 | <td class="good">Correct</td>
|
---|
2158 | </tr>
|
---|
2159 | <tr>
|
---|
2160 | <td><code>dir="rtl"</code> with <code>LRE</code> & <code>PDF</code></td>
|
---|
2161 | <td><code>U+202A</code>English (Australia & New Zealand)<code>U+202C</code></td>
|
---|
2162 | <td dir="rtl">‪English (Australia & New Zealand)‬</td>
|
---|
2163 | <td class="good">Correct</td>
|
---|
2164 | </tr>
|
---|
2165 | <tr>
|
---|
2166 | <td><code>dir="rtl"</code> with <code>LRO</code> & <code>PDF</code></td>
|
---|
2167 | <td><code>U+202D</code>English (Australia & New Zealand)<code>U+202C</code></td>
|
---|
2168 | <td dir="rtl">‭English (Australia & New Zealand)‬</td>
|
---|
2169 | <td class="good">Correct</td>
|
---|
2170 | </tr>
|
---|
2171 | </tbody>
|
---|
2172 | </table>
|
---|
2173 |
|
---|
2174 | <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 "strong" character to fully enclose an ambiguous punctuation character and thus make it inherit the correct directionality is sufficient.</p>
|
---|
2175 | <p>Within some cases, there may be mixed scripts of a left-to-right and right-to-left direction, so using <code>LRE</code> & <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> & <code>RLO</code> with <code>PDF</code>.</p>
|
---|
2176 | <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>
|
---|
2177 |
|
---|
2178 | <h4>Working with placeholders:</h4>
|
---|
2179 |
|
---|
2180 | <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 "Page <em>X</em> of <em>Y</em>", whilst in English this could just be coded as:</p>
|
---|
2181 |
|
---|
2182 | <div class="codebox"><pre>
|
---|
2183 | ...
|
---|
2184 | 'PAGE_OF' => 'Page %s of %s',
|
---|
2185 | /* Just grabbing the replacements as they
|
---|
2186 | come and hope they are in the right order */
|
---|
2187 | ...
|
---|
2188 | </pre></div>
|
---|
2189 |
|
---|
2190 | <p>… a clearer way to show explicit replacement ordering is to do:</p>
|
---|
2191 |
|
---|
2192 | <div class="codebox"><pre>
|
---|
2193 | ...
|
---|
2194 | 'PAGE_OF' => 'Page %1$s of %2$s',
|
---|
2195 | /* Explicit ordering of the replacements,
|
---|
2196 | even if they are the same order as English */
|
---|
2197 | ...
|
---|
2198 | </pre></div>
|
---|
2199 |
|
---|
2200 | <p>Why bother at all? Because some languages, the string transliterated back to English might read something like:</p>
|
---|
2201 |
|
---|
2202 | <div class="codebox"><pre>
|
---|
2203 | ...
|
---|
2204 | 'PAGE_OF' => 'Total of %2$s pages, currently on page %1$s',
|
---|
2205 | /* Explicit ordering of the replacements,
|
---|
2206 | reversed compared to English as the total comes first */
|
---|
2207 | ...
|
---|
2208 | </pre></div>
|
---|
2209 |
|
---|
2210 | <a name="writingstyle"></a><h3>6.iii. Writing Style</h3>
|
---|
2211 |
|
---|
2212 | <h4>Miscellaneous tips & hints:</h4>
|
---|
2213 |
|
---|
2214 | <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>"</code> (straight double quote), <code><</code> (less-than sign), <code>></code> (greater-than sign) and <code>&</code> (ampersand).</p>
|
---|
2215 |
|
---|
2216 | <p class="bad">// Bad - The un-escapsed straight-quote/apostrophe will throw a PHP parse error</p>
|
---|
2217 |
|
---|
2218 | <div class="codebox"><pre>
|
---|
2219 | ...
|
---|
2220 | 'CONV_ERROR_NO_AVATAR_PATH'
|
---|
2221 | => 'Note to developer: you must specify $convertor['avatar_path'] to use %s.',
|
---|
2222 | ...
|
---|
2223 | </pre></div>
|
---|
2224 |
|
---|
2225 | <p class="good">// Good - Literal straight quotes should be escaped with a backslash, ie: \</p>
|
---|
2226 |
|
---|
2227 | <div class="codebox"><pre>
|
---|
2228 | ...
|
---|
2229 | 'CONV_ERROR_NO_AVATAR_PATH'
|
---|
2230 | => 'Note to developer: you must specify $convertor[\'avatar_path\'] to use %s.',
|
---|
2231 | ...
|
---|
2232 | </pre></div>
|
---|
2233 |
|
---|
2234 | <p>However, because phpBB3 now uses UTF-8 as its sole encoding, we can actually use this to our advantage and not have to remember to escape a straight quote when we don't have to:</p>
|
---|
2235 |
|
---|
2236 | <p class="bad">// Bad - The un-escapsed straight-quote/apostrophe will throw a PHP parse error</p>
|
---|
2237 |
|
---|
2238 | <div class="codebox"><pre>
|
---|
2239 | ...
|
---|
2240 | 'USE_PERMISSIONS' => 'Test out user's permissions',
|
---|
2241 | ...
|
---|
2242 | </pre></div>
|
---|
2243 |
|
---|
2244 | <p class="good">// Okay - However, non-programmers wouldn't type "user\'s" automatically</p>
|
---|
2245 |
|
---|
2246 | <div class="codebox"><pre>
|
---|
2247 | ...
|
---|
2248 | 'USE_PERMISSIONS' => 'Test out user\'s permissions',
|
---|
2249 | ...
|
---|
2250 | </pre></div>
|
---|
2251 |
|
---|
2252 | <p class="good">// Best - Use the Unicode Right-Single-Quotation-Mark character</p>
|
---|
2253 |
|
---|
2254 | <div class="codebox"><pre>
|
---|
2255 | ...
|
---|
2256 | 'USE_PERMISSIONS' => 'Test out user’s permissions',
|
---|
2257 | ...
|
---|
2258 | </pre></div>
|
---|
2259 |
|
---|
2260 | <p>The <code>"</code> (straight double quote), <code><</code> (less-than sign) and <code>></code> (greater-than sign) characters can all be used as displayed glyphs or as part of HTML markup, for example:</p>
|
---|
2261 |
|
---|
2262 | <p class="bad">// Bad - Invalid HTML, as segments not part of elements are not entitised</p>
|
---|
2263 |
|
---|
2264 | <div class="codebox"><pre>
|
---|
2265 | ...
|
---|
2266 | 'FOO_BAR' => 'PHP version < 4.3.3.<br />
|
---|
2267 | Visit "Downloads" at <a href="http://www.php.net/">www.php.net</a>.',
|
---|
2268 | ...
|
---|
2269 | </pre></div>
|
---|
2270 |
|
---|
2271 | <p class="good">// Okay - No more invalid HTML, but "&quot;" is rather clumsy</p>
|
---|
2272 |
|
---|
2273 | <div class="codebox"><pre>
|
---|
2274 | ...
|
---|
2275 | 'FOO_BAR' => 'PHP version &lt; 4.3.3.<br />
|
---|
2276 | Visit &quot;Downloads&quot; at <a href="http://www.php.net/">www.php.net</a>.',
|
---|
2277 | ...
|
---|
2278 | </pre></div>
|
---|
2279 |
|
---|
2280 | <p class="good">// Best - No more invalid HTML, and usage of correct typographical quotation marks</p>
|
---|
2281 |
|
---|
2282 | <div class="codebox"><pre>
|
---|
2283 | ...
|
---|
2284 | 'FOO_BAR' => 'PHP version &lt; 4.3.3.<br />
|
---|
2285 | Visit “Downloads” at <a href="http://www.php.net/">www.php.net</a>.',
|
---|
2286 | ...
|
---|
2287 | </pre></div>
|
---|
2288 |
|
---|
2289 | <p>Lastly, the <code>&</code> (ampersand) must always be entitised regardless of where it is used:</p>
|
---|
2290 |
|
---|
2291 | <p class="bad">// Bad - Invalid HTML, none of the ampersands are entitised</p>
|
---|
2292 |
|
---|
2293 | <div class="codebox"><pre>
|
---|
2294 | ...
|
---|
2295 | 'FOO_BAR' => '<a href="http://somedomain.tld/?foo=1&bar=2">Foo & Bar</a>.',
|
---|
2296 | ...
|
---|
2297 | </pre></div>
|
---|
2298 |
|
---|
2299 | <p class="good">// Good - Valid HTML, amperands are correctly entitised in all cases</p>
|
---|
2300 |
|
---|
2301 | <div class="codebox"><pre>
|
---|
2302 | ...
|
---|
2303 | 'FOO_BAR' => '<a href="http://somedomain.tld/?foo=1&amp;bar=2">Foo &amp; Bar</a>.',
|
---|
2304 | ...
|
---|
2305 | </pre></div>
|
---|
2306 |
|
---|
2307 | <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>
|
---|
2308 |
|
---|
2309 | <h4>Spelling, punctuation, grammar, et cetera:</h4>
|
---|
2310 |
|
---|
2311 | <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>
|
---|
2312 |
|
---|
2313 | </div>
|
---|
2314 |
|
---|
2315 | <div class="back2top"><a href="#wrap" class="top">Back to Top</a></div>
|
---|
2316 |
|
---|
2317 | <span class="corners-bottom"><span></span></span></div>
|
---|
2318 | </div>
|
---|
2319 |
|
---|
2320 | <hr />
|
---|
2321 |
|
---|
2322 | <a name="vcs"></a><h2>7. VCS Guidelines</h2>
|
---|
2323 |
|
---|
2324 | <div class="paragraph">
|
---|
2325 | <div class="inner"><span class="corners-top"><span></span></span>
|
---|
2326 |
|
---|
2327 | <div class="content">
|
---|
2328 |
|
---|
2329 | <p>The version control system for phpBB3 is subversion. The repository is available at <a href="http://code.phpbb.com/svn/phpbb" title="repository">http://code.phpbb.com/svn/phpbb</a>.</p>
|
---|
2330 |
|
---|
2331 | <a name="repostruct"></a><h3>7.i. Repository Structure</h3>
|
---|
2332 |
|
---|
2333 | <ul>
|
---|
2334 | <li><strong>trunk</strong><br />The latest unstable development version with new features etc. Contains the actual board in <code>/trunk/phpBB</code></li>
|
---|
2335 | <li><strong>branches</strong><br />Development branches of stable phpBB releases. Copied from <code>/trunk</code> at the time of release.
|
---|
2336 | <ul>
|
---|
2337 | <li><strong>phpBB3.0</strong><code>/branches/phpBB-3_0_0/phpBB</code><br />Development branch of the stable 3.0 line. Bug fixes are applied here.</li>
|
---|
2338 | <li><strong>phpBB2</strong><code>/branches/phpBB-2_0_0/phpBB</code><br />Old phpBB2 development branch.</li>
|
---|
2339 | </ul>
|
---|
2340 | </li>
|
---|
2341 | <li><strong>tags</strong><br />Released versions. Copies of trunk or the respective branch, made at the time of release.
|
---|
2342 | <ul>
|
---|
2343 | <li><code>/tags/release_3_0_BX</code><br />Beta release X of the 3.0 line.</li>
|
---|
2344 | <li><code>/tags/release_3_0_RCX</code><br />Release candidate X of the 3.0 line.</li>
|
---|
2345 | <li><code>/tags/release_3_0_X-RCY</code><br />Release candidate Y of the stable 3.0.X release.</li>
|
---|
2346 | <li><code>/tags/release_3_0_X</code><br />Stable <strong>3.0.X</strong> release.</li>
|
---|
2347 | <li><code>/tags/release_2_0_X</code><br />Old stable 2.0.X release.</li>
|
---|
2348 | </ul>
|
---|
2349 | </li>
|
---|
2350 | </ul>
|
---|
2351 |
|
---|
2352 | <a name="commitmessage"></a><h3>7.ii. Commit Messages</h3>
|
---|
2353 |
|
---|
2354 | <p>The commit message should contain a brief explanation of all changes made within the commit. Often identical to the changelog entry. A bug ticket can be referenced by specifying the ticket ID with a hash, e.g. #12345. A reference to another revision should simply be prefixed with r, e.g. r12345.</p>
|
---|
2355 |
|
---|
2356 | <p>Junior Developers need to have their patches approved by a development team member first. The commit message must end in a line with the following format:</p>
|
---|
2357 |
|
---|
2358 | <div class="codebox"><pre>
|
---|
2359 | Authorised by: developer1[, developer2[, ...]]
|
---|
2360 | </pre></div>
|
---|
2361 |
|
---|
2362 | </div>
|
---|
2363 |
|
---|
2364 | <div class="back2top"><a href="#wrap" class="top">Back to Top</a></div>
|
---|
2365 |
|
---|
2366 | <span class="corners-bottom"><span></span></span></div>
|
---|
2367 | </div>
|
---|
2368 |
|
---|
2369 | <hr />
|
---|
2370 |
|
---|
2371 | <a name="changes"></a><h2>8. Guidelines Changelog</h2>
|
---|
2372 | <div class="paragraph">
|
---|
2373 | <div class="inner"><span class="corners-top"><span></span></span>
|
---|
2374 |
|
---|
2375 | <div class="content">
|
---|
2376 | <h3>Revision 10007</h3>
|
---|
2377 |
|
---|
2378 | <ul>
|
---|
2379 | <li>Added <a href="#constants">Special Constants</a> section.</li>
|
---|
2380 | </ul>
|
---|
2381 |
|
---|
2382 | <h3>Revision 9817</h3>
|
---|
2383 |
|
---|
2384 | <ul>
|
---|
2385 | <li>Added VCS section.</li>
|
---|
2386 | </ul>
|
---|
2387 |
|
---|
2388 | <h3>Revision 8732</h3>
|
---|
2389 |
|
---|
2390 | <ul>
|
---|
2391 | <li>Added cfg files.</li>
|
---|
2392 | <li>Added template <a href="#inheritance">inheritance</a>.</li>
|
---|
2393 | </ul>
|
---|
2394 |
|
---|
2395 | <h3>Revision 8596+</h3>
|
---|
2396 |
|
---|
2397 | <ul>
|
---|
2398 | <li>Removed sql_build_array('MULTI_INSERT'... statements.</li>
|
---|
2399 | <li>Added sql_multi_insert() explanation.</li>
|
---|
2400 | </ul>
|
---|
2401 |
|
---|
2402 | <h3>Revision 1.31</h3>
|
---|
2403 |
|
---|
2404 | <ul>
|
---|
2405 | <li>Added add_form_key and check_form_key. </li>
|
---|
2406 | </ul>
|
---|
2407 |
|
---|
2408 | <h3>Revision 1.24</h3>
|
---|
2409 |
|
---|
2410 | <ul>
|
---|
2411 | <li>Added <a href="#translation">5. Character Sets and Encodings</a> section to explain the recommended treatment of strings in phpBB.</li>
|
---|
2412 | </ul>
|
---|
2413 |
|
---|
2414 | <h3>Revision 1.16</h3>
|
---|
2415 |
|
---|
2416 | <ul>
|
---|
2417 | <li>Added <a href="#translation">6. Translation (<abbr title="Internationalisation">i18n</abbr>/<abbr title="Localisation">L10n</abbr>) Guidelines</a> section to explain expected format and authoring considerations for language packs that are to be created for phpBB.</li>
|
---|
2418 | </ul>
|
---|
2419 |
|
---|
2420 | <h3>Revision 1.11-1.15</h3>
|
---|
2421 |
|
---|
2422 | <ul>
|
---|
2423 | <li>Various document formatting, spelling, punctuation, grammar bugs.</li>
|
---|
2424 | </ul>
|
---|
2425 |
|
---|
2426 | <h3>Revision 1.9-1.10</h3>
|
---|
2427 |
|
---|
2428 | <ul>
|
---|
2429 | <li>Added sql_query_limit to <a href="#sql">2.iii. SQL/SQL Layout</a>.</li>
|
---|
2430 | </ul>
|
---|
2431 |
|
---|
2432 | <h3>Revision 1.8</h3>
|
---|
2433 |
|
---|
2434 | <ul>
|
---|
2435 | <li>Some adjustements to wordings</li>
|
---|
2436 | <li>Updated paragraph <a href="#locations">1.iii. File Locations</a> to reflect recent changes</li>
|
---|
2437 | <li>Extended paragraph <a href="#codelayout">2.ii. Code Layout</a>.</li>
|
---|
2438 | <li>Added sql_in_set and sql_build_query explanation to <a href="#sql">2.iii. SQL/SQL Layout</a>.</li>
|
---|
2439 | <li>Updated paragraph <a href="#styling">3. Styling</a>.</li>
|
---|
2440 | <li>Updated paragraph <a href="#templating">4. Templating</a> to explain loop checking, loop breaking and other changes we recently made.</li>
|
---|
2441 | </ul>
|
---|
2442 |
|
---|
2443 | <h3>Revision 1.5</h3>
|
---|
2444 |
|
---|
2445 | <ul>
|
---|
2446 | <li>Changed General function usage paragraph in <a href="#general">2.v. General Guidelines</a></li>
|
---|
2447 | </ul>
|
---|
2448 |
|
---|
2449 |
|
---|
2450 | </div>
|
---|
2451 |
|
---|
2452 | <div class="back2top"><a href="#wrap" class="top">Back to Top</a></div>
|
---|
2453 |
|
---|
2454 | <span class="corners-bottom"><span></span></span></div>
|
---|
2455 | </div>
|
---|
2456 |
|
---|
2457 | <hr />
|
---|
2458 |
|
---|
2459 | <a name="disclaimer"></a><h2>9. Copyright and disclaimer</h2>
|
---|
2460 |
|
---|
2461 | <div class="paragraph">
|
---|
2462 | <div class="inner"><span class="corners-top"><span></span></span>
|
---|
2463 |
|
---|
2464 | <div class="content">
|
---|
2465 |
|
---|
2466 | <p>This application is opensource software released under the <a href="http://opensource.org/licenses/gpl-license.php">GPL</a>. Please see source code and the docs directory for more details. This package and its contents are Copyright (c) 2000, 2002, 2005, 2007 <a href="http://www.phpbb.com/">phpBB Group</a>, All Rights Reserved.</p>
|
---|
2467 |
|
---|
2468 | </div>
|
---|
2469 |
|
---|
2470 | <div class="back2top"><a href="#wrap" class="top">Back to Top</a></div>
|
---|
2471 |
|
---|
2472 | <span class="corners-bottom"><span></span></span></div>
|
---|
2473 | </div>
|
---|
2474 |
|
---|
2475 | <!-- END DOCUMENT -->
|
---|
2476 |
|
---|
2477 | <div id="page-footer">
|
---|
2478 | <div class="version"> $Id$ </div>
|
---|
2479 | </div>
|
---|
2480 | </div></div>
|
---|
2481 |
|
---|
2482 | <div>
|
---|
2483 | <a id="bottom" name="bottom" accesskey="z"></a>
|
---|
2484 | </div>
|
---|
2485 |
|
---|
2486 | </body>
|
---|
2487 | </html>
|
---|