1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
|
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Coding Guidelines</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<meta name="resource-type" content="document" />
<meta name="description" lang="en" content="Olympus coding guidelines document" />
<meta name="keywords" lang="en" content="" />
<meta name="author" content="phpBB Group" />
<meta name="copyright" content="phpBB Group" />
<meta name="MSSmartTagsPreventParsing" content="true" />
<style type="text/css">
<!--
/* The original "subSilver" theme for phpBB2 Created by subBlue design :: http://www.subBlue.com */
body {
background-color: white;
font-family: Verdana, Arial, Helvetica, sans-serif;
margin: 0;
border: 0;
padding: 0;
}
img {
border: 0;
}
p {
font-size: 8pt;
}
hr {
height: 0;
border: solid #D1D7DC 0;
border-top-width: 1px;
}
#title, h1 {
font: bold 18pt 'Trebuchet MS', Verdana, sans-serif;
text-decoration: none;
line-height: 120%;
}
h2 {
font: bold 12pt Arial, Helvetica, sans-serif;
text-decoration: none;
line-height: 120%;
}
h3 {
font: bold 10pt Arial, Helvetica, sans-serif;
text-decoration: none;
line-height: 120%;
}
.paragraph {
margin-left: 20px;
}
.paragraph table {
font-size: 8pt;
border-collapse: collapse;
border: 1px solid #006699;
}
.paragraph table caption {
display: none;
}
.paragraph table thead {
background-color: #D1D7DC;
}
.paragraph table td, .paragraph table th {
border: 1px solid #006699;
padding: 0.5em;
}
.paragraph table td dl {
margin: 0;
padding: 0;
}
.paragraph table td dl dt {
float: left;
clear: both;
margin-right: 1em;
}
/* Structure */
#logo {
background: #fff url(header_bg.jpg) repeat-x top right;
height: 60px;
}
#title {
color: #12749b;
float: right;
margin: 10px 10px 0;
}
#main {
margin-left: 25px;
margin-right: 25px;
}
.good {
color: green;
}
.bad {
color: red;
}
#footer {
margin-left: 75px;
font-size: 70%;
color: #006600;
}
code {
color: #006600;
font-weight: normal;
font-family: 'Courier New', monospace;
border-color: #D1D7DC;
border-width: 1px;
border-style: solid;
background-color: #FAFAFA;
}
.indent p {
padding-left: 20px;
font-size: 90%;
}
/* Anchors */
a {
font-size: 70%;
}
a:link, a:active, a:visited {
color: #006699;
text-decoration: none;
}
a:hover {
color: #DD6900;
text-decoration: underline;
}
a.nav {
color: #006699;
text-decoration: none;
}
a.nav:hover {
text-decoration: underline;
}
p a {
font-size: 100%;
}
.menu {
font-size: 80%;
}
.menu li a {
font-size: 100%;
}
.comment {
color: green;
}
//-->
</style>
</head>
<body>
<div id="logo">
<div id="title">Coding Guidelines</div>
<img src="header_left.jpg" alt="phpBB Logo" />
</div>
<a name="top"></a><div id="main">
<!-- BEGIN DOCUMENT -->
<p>These are the phpBB Coding Guidelines for Olympus, all attempts should be made to follow them as closely as possible.<br />This document is (c) 2006 phpBB Group, copying or redistribution is not allowed without permission.</p>
<h1>Coding Guidelines</h1>
<ol class="menu">
<li><a href="#defaults">Defaults</a>
<ol type="i">
<li><a href="#editorsettings">Editor Settings</a></li>
<li><a href="#fileheader">File Header</a></li>
<li><a href="#locations">File Locations</a></li>
</ol>
</li>
<li><a href="#code">Code Layout/Guidelines</a>
<ol type="i">
<li><a href="#namingvars">Variable/Function Naming</a></li>
<li><a href="#codelayout">Code Layout</a></li>
<li><a href="#sql">SQL/SQL Layout</a></li>
<li><a href="#optimizing">Optimizations</a></li>
<li><a href="#general">General Guidelines</a></li>
</ol>
</li>
<li><a href="#styling">Styling</a></li>
<li><a href="#templating">Templating</a></li>
<li><a href="#translation">Translation (<abbr title="Internationalisation">i18n</abbr>/<abbr title="Localisation">L10n</abbr>) Guidelines</a>
<ol type="i">
<li><a href="#standardisation">Standardisation</a></li>
<li><a href="#otherconsiderations">Other considerations</a></li>
<li><a href="#writingstyle">Writing Style</a></li>
</ol>
</li>
<li><a href="#changes">Guidelines Changelog</a></li>
</ol>
<hr />
<a name="defaults"></a><h1>1. Defaults</h1>
<a name="editorsettings"></a><b>1.i. Editor Settings</b>
<br /><br />
<div class="paragraph">
<h3>Tabs vs Spaces:</h3>
<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 <b>save</b> 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>
<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>
<blockquote><pre>
{TAB}$mode{TAB}{TAB}= request_var('mode', '');
{TAB}$search_id{TAB}= request_var('search_id', '');
</pre></blockquote>
<p>If entered with tabs (replace the {TAB}) both equal signs need to be on the same column.</p>
<h3>Linefeeds:</h3>
<p>Ensure that your editor is saving files in the UNIX format. This means lines are terminated with a newline, not with a CR/LF combo as they are on Win32, or whatever the Mac uses. Any decent editor should be able to do this, but it might not always be the default. Know your editor. If you want advice on Windows text editors, just ask one of the developers. Some of them do their editing on Win32.</p>
</div>
<a href="#top">Top</a>
<br /><br />
<a name="fileheader"></a><b>1.ii. File Header</b>
<br /><br />
<div class="paragraph">
<h3>Standard header for new files:</h3>
<p>This template of the header must be included at the start of all phpBB files: </p>
<blockquote><pre>
/**
*
* @package {PACKAGENAME}
* @version $Id: $
* @copyright (c) 2006 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/
</pre></blockquote>
<p>Please see the <a href="#locations">File Locations section</a> for the correct package name.</p>
<h3>Files containing inline code:</h3>
<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>
<blockquote><pre>
/**
* {HEADER}
*/
/**
*/
{CODE}
</pre></blockquote>
<h3>Files containing only functions:</h3>
<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>
<h3>Files containing only classes:</h3>
<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>
<h3>Code following the header but only functions/classes file:</h3>
<p>If this case is true, the best method to avoid documentation confusions is adding an ignore command, for example:</p>
<blockquote><pre>
/**
* {HEADER}
*/
/**
* @ignore
*/
Small code snipped, mostly one or two defines or an if statement
/**
* {DOCUMENTATION}
*/
class ...
</pre></blockquote>
</div>
<a href="#top">Top</a>
<br /><br />
<a name="locations"></a><b>1.iii. File Locations</b>
<br /><br />
<div class="paragraph">
<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>
<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>
<ul class="menu">
<li><b>phpBB3</b><br />Core files and all files not assigned to a separate package</li>
<li><b>acm</b><br /><code>/includes/acm</code>, <code>/includes/cache.php</code><br />Cache System</li>
<li><b>acp</b><br /><code>/adm</code>, <code>/includes/acp</code>, <code>/includes/functions_admin.php</code><br />Administration Control Panel</li>
<li><b>dbal</b><br /><code>/includes/db</code><br />Database Abstraction Layer.<br />Base class is <code>dbal</code>
<ul>
<li><code>/includes/db/dbal.php</code><br />Base DBAL class, defining the overall framework as well as common detominators</li>
<li><code>/includes/db/firebird.php</code><br />Firebird/Interbase Database Abstraction Layer</li>
<li><code>/includes/db/msssql.php</code><br />MSSQL Database Abstraction Layer</li>
<li><code>/includes/db/mssql_odbc.php</code><br />MSSQL ODBC Database Abstraction Layer for MSSQL</li>
<li><code>/includes/db/mysql.php</code><br />MySQL Database Abstraction Layer for MySQL 3.x/4.0.x</li>
<li><code>/includes/db/mysql4.php</code><br />MySQL4 Database Abstraction Layer for MySQL 4.1.x/5.x</li>
<li><code>/includes/db/mysqli.php</code><br />MySQLi Database Abstraction Layer</li>
<li><code>/includes/db/oracle.php</code><br />Oracle Database Abstraction Layer</li>
<li><code>/includes/db/postgres.php</code><br />PostgreSQL Database Abstraction Layer</li>
<li><code>/includes/db/sqlite.php</code><br />Sqlite Database Abstraction Layer</li>
</ul>
</li>
<li><b>docs</b><br /><code>/docs</code><br />phpBB Documentation</li>
<li><b>images</b><br /><code>/images</code><br />All global images not connected to styles</li>
<li><b>install</b><br /><code>/install</code><br />Installation System</li>
<li><b>language</b><br /><code>/language</code><br />All language files</li>
<li><b>login</b><br /><code>/includes/auth</code><br />Login Authentication Plugins</li>
<li><b>VC</b><br /><code>/includes/captcha</code><br />CAPTCHA</li>
<li><b>mcp</b><br /><code>mcp.php</code>, <code>/includes/mcp</code>, <code>report.php</code><br />Moderator Control Panel</li>
<li><b>ucp</b><br /><code>ucp.php</code>, <code>/includes/ucp</code><br />User Control Panel</li>
<li><b>search</b><br /><code>/includes/search</code>, <code>search.php</code><br />Search System</li>
<li><b>styles</b><br /><code>/styles</code>, <code>style.php</code><br />phpBB Styles/Templates/Themes/Imagesets</li>
</ul>
</div>
<a href="#top">Top</a>
<br /><br />
<hr />
<a name="code"></a><h1>2. Code Layout/Guidelines</h1>
<p>Please note that these Guidelines applies to all php, html, javascript and css files.</p>
<a name="namingvars"></a><b>2.i. Variable/Function Naming</b>
<br /><br />
<div class="paragraph">
<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>
<h3>Variable Names:</h3>
<p>Variable names should be in all lowercase, with words separated by an underscore, example:</p>
<div class="indent">
<p><code>$current_user</code> is right, but <code>$currentuser</code> and <code> $currentUser</code> are not.</p>
</div>
<p>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>
<h3>Loop Indices:</h3>
<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>
<blockquote><pre>
for ($i = 0; $i < $outer_size; $i++)
{
for ($j = 0; $j < $inner_size; $j++)
{
foo($i, $j);
}
}
</pre></blockquote>
<h3>Function Names:</h3>
<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>
<h3>Function Arguments:</h3>
<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>
<h3>Summary:</h3>
<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>
<h3>Special Namings: </h3>
<p>For all emoticons use the term <code>smiley</code> in singular and <code>smilies</code> in plural.</p>
</div>
<a href="#top">Top</a>
<br /><br />
<a name="codelayout"></a><b>2.ii. Code Layout</b>
<br /><br />
<div class="paragraph">
<h3>Always include the braces:</h3>
<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>
<p class="bad">// These are all wrong. </p>
<blockquote><pre>
if (condition) do_stuff();
if (condition)
do_stuff();
while (condition)
do_stuff();
for ($i = 0; $i < size; $i++)
do_stuff($i);
</pre></blockquote>
<p class="good">// These are all right. </p>
<blockquote><pre>
if (condition)
{
do_stuff();
}
while (condition)
{
do_stuff();
}
for ($i = 0; $i < size; $i++)
{
do_stuff();
}
</pre></blockquote>
<h3>Where to put the braces:</h3>
<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>
<blockquote><pre>
if (condition)
{
while (condition2)
{
...
}
}
else
{
...
}
for ($i = 0; $i < $size; $i++)
{
...
}
while (condition)
{
...
}
function do_stuff()
{
...
}
</pre></blockquote>
<h3>Use spaces between tokens:</h3>
<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>
<p>// Each pair shows the wrong way followed by the right way. </p>
<blockquote><pre>
$i=0;
$i = 0;
if($i<7) ...
if ($i < 7) ...
if ( ($i < 7)&&($j > 8) ) ...
if ($i < 7 && $j > 8) ...
do_stuff( $i, 'foo', $b );
do_stuff($i, 'foo', $b);
for($i=0; $i<$size; $i++) ...
for ($i = 0; $i < $size; $i++) ...
$i=($j < $size)?0:1;
$i = ($j < $size) ? 0 : 1;
</pre></blockquote>
<h3>Operator precedence:</h3>
<p>Do you know the exact precedence of all the operators in PHP? Neither do I. Don't guess. Always make it obvious by using brackets to force the precedence of an equation so you know what it does. Remember to not over-use this, as it may harden the readability. Basically, do not enclose single expressions. Examples:</p>
<p class="bad">// what's the result? who knows. </p>
<blockquote><pre>
$bool = ($i < 7 && $j > 8 || $k == 4);
</pre></blockquote>
<p class="bad">// now you can be certain what I'm doing here.</p>
<blockquote><pre>
$bool = (($i < 7) && (($j < 8) || ($k == 4)));
</pre></blockquote>
<p class="good">// But this one is even better, because it is easier on the eye but the intention is preserved</p>
<blockquote><pre>
$bool = ($i < 7 && ($j < 8 || $k == 4));
</pre></blockquote>
<h3>Quoting strings:</h3>
<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>
<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>
<p class="bad">// wrong </p>
<blockquote><pre>
$str = "This is a really long string with no variables for the parser to find.";
do_stuff("$str");
</pre></blockquote>
<p class="good">// right</p>
<blockquote><pre>
$str = 'This is a really long string with no variables for the parser to find.';
do_stuff($str);
</pre></blockquote>
<p class="bad">// Sometimes single quotes are just not right</p>
<blockquote><pre>
$post_url = $phpbb_root_path . 'posting.' . $phpEx . '?mode=' . $mode . '&amp;start=' . $start;
</pre></blockquote>
<p class="good">// Double quotes are sometimes needed to not overcroud the line with concentinations</p>
<blockquote><pre>
$post_url = "{$phpbb_root_path}posting.$phpEx?mode=$mode&amp;start=$start";
</pre></blockquote>
<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>
<h3>Associative array keys:</h3>
<p>In PHP, it's legal to use a literal string as a key to an associative array without quoting that string. We don't want to do this -- the string should always be quoted to avoid confusion. Note that this is only when we're using a literal, not when we're using a variable, examples:</p>
<p class="bad">// wrong</p>
<blockquote><pre>
$foo = $assoc_array[blah];
</pre></blockquote>
<p class="good">// right </p>
<blockquote><pre>
$foo = $assoc_array['blah'];
</pre></blockquote>
<p class="bad">// wrong</p>
<blockquote><pre>
$foo = $assoc_array["$var"];
</pre></blockquote>
<p class="good">// right </p>
<blockquote><pre>
$foo = $assoc_array[$var];
</pre></blockquote>
<h3>Comments:</h3>
<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>
<h3>Magic numbers:</h3>
<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>
<h3>Shortcut operators:</h3>
<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>
<p class="bad">// wrong </p>
<blockquote><pre>
$array[++$i] = $j;
$array[$i++] = $k;
</pre></blockquote>
<p class="good">// right </p>
<blockquote><pre>
$i++;
$array[$i] = $j;
$array[$i] = $k;
$i++;
</pre></blockquote>
<h3>Inline conditionals:</h3>
<p>Inline conditionals should only be used to do very simple things. Preferably, they will only be used to do assignments, and not for function calls or anything complex at all. They can be harmful to readability if used incorrectly, so don't fall in love with saving typing by using them, examples:</p>
<p class="bad">// Bad place to use them</p>
<blockquote><pre>
($i < $size && $j > $size) ? do_stuff($foo) : do_stuff($bar);
</pre></blockquote>
<p class="good">// OK place to use them </p>
<blockquote><pre>
$min = ($i < $j) ? $i : $j;
</pre></blockquote>
<h3>Don't use uninitialized variables.</h3>
<p>For phpBB3, we intend to use a higher level of run-time error reporting. This will mean that the use of an uninitialized variable will be reported as a warning. These warnings can be avoided by using the built-in isset() function to check whether a variable has been set - but preferably the variable is always existing. For checking if an array has a key set this can come in handy though, examples:</p>
<p class="bad">// Wrong </p>
<blockquote><pre>
if ($forum) ...
</pre></blockquote>
<p class="good">// Right </p>
<blockquote><pre>
if (isset($forum)) ...
</pre></blockquote>
<p class="good">// Also possible</p>
<blockquote><pre>
if (isset($forum) && $forum == 5)
</pre></blockquote>
<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>
<h3>Switch statements:</h3>
<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>
<p class="bad">// Wrong </p>
<blockquote><pre>
switch ($mode)
{
case 'mode1':
// I am doing something here
break;
case 'mode2':
// I am doing something completely different here
break;
}
</pre></blockquote>
<p class="good">// Good </p>
<blockquote><pre>
switch ($mode)
{
case 'mode1':
// I am doing something here
break;
case 'mode2':
// I am doing something completely different here
break;
default:
// Always assume that the case got not catched
break;
}
</pre></blockquote>
<p class="good">// Also good, if you have more code between the case and the break </p>
<blockquote><pre>
switch ($mode)
{
case 'mode1':
// I am doing something here
break;
case 'mode2':
// I am doing something completely different here
break;
default:
// Always assume that the case got not catched
break;
}
</pre></blockquote>
<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>
<p>If no break is intended, please add a comment instead. An example:</p>
<p class="good">// Example with no break </p>
<blockquote><pre>
switch ($mode)
{
case 'mode1':
// I am doing something here
// no break here
case 'mode2':
// I am doing something completely different here
break;
default:
// Always assume that the case got not catched
break;
}
</pre></blockquote>
</div>
<a href="#top">Top</a>
<br /><br />
<a name="sql"></a><b>2.iii. SQL/SQL Layout</b>
<br /><br />
<div class="paragraph">
<h3>Common SQL Guidelines: </h3>
<p>All SQL should be cross-DB compatible, if DB specific SQL is used alternatives must be provided which work on all supported DB's (MySQL3/4/5, MSSQL (7.0 and 2000), PostgreSQL (7.0+), Firebird, SQLite, Oracle8, ODBC (generalised if possible)).</p>
<p>All SQL commands should utilise the DataBase Abstraction Layer (DBAL)</p>
<h3>SQL code layout:</h3>
<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>
<blockquote><pre>
$sql = 'SELECT *
<-one tab->FROM ' . SOME_TABLE . '
<-one tab->WHERE a = 1
<-two tabs->AND (b = 2
<-three tabs->OR b = 3)
<-one tab->ORDER BY b';
</pre></blockquote>
<p>Here the example with the tabs applied:</p>
<blockquote><pre>
$sql = 'SELECT *
FROM ' . SOME_TABLE . '
WHERE a = 1
AND (b = 2
OR b = 3)
ORDER BY b';
</pre></blockquote>
<h3>SQL Quotes: </h3>
<p>Double quotes where applicable (The variables in these examples are typecasted to integers before) ... examples: </p>
<p class="bad">// These are wrong.</p>
<blockquote><pre>
"UPDATE " . SOME_TABLE . " SET something = something_else WHERE a = $b";
'UPDATE ' . SOME_TABLE . ' SET something = ' . $user_id . ' WHERE a = ' . $something;
</pre></blockquote>
<p class="good">// These are right. </p>
<blockquote><pre>
'UPDATE ' . SOME_TABLE . " SET something = something_else WHERE a = $b";
'UPDATE ' . SOME_TABLE . " SET something = $user_id WHERE a = $something";
</pre></blockquote>
<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>
<h3>Common DBAL methods: </h3>
<h3>sql_escape():</h3>
<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 can not contain single quotes - never trust your input), for example:</p>
<blockquote><pre>
$sql = 'SELECT *
FROM ' . SOME_TABLE . "
WHERE username = '" . $db->sql_escape($username) . "'";
</pre></blockquote>
<h3>sql_query_limit():</h3>
<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>
<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>
<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>
<h3>sql_build_array():</h3>
<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 one or two variables needs to be inserted/updated. An example of an insert statement would be:</p>
<blockquote><pre>
$sql_ary = array(
'somedata' => $my_string,
'otherdata' => $an_int,
'moredata' => $another_int
);
$db->sql_query('INSERT INTO ' . SOME_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
</pre></blockquote>
<p>To complete the example, this is how an update statement would look like:</p>
<blockquote><pre>
$sql_ary = array(
'somedata' => $my_string,
'otherdata' => $an_int,
'moredata' => $another_int
);
$sql = 'UPDATE ' . SOME_TABLE . '
SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
WHERE user_id = ' . (int) $user_id;
$db->sql_query($sql);
</pre></blockquote>
<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>MULTI_INSERT</code> (for returning extended inserts), <code>UPDATE</code> (example above) and <code>SELECT</code> (for building WHERE statement [AND logic]).</p>
<h3>sql_in_set():</h3>
<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>
<blockquote><pre>
$sql = 'SELECT *
FROM ' . FORUMS_TABLE . '
WHERE ' . $db->sql_in_set('forum_id', $forum_ids);
$db->sql_query($sql);
</pre></blockquote>
<p>Based on the number of values in $forum_ids, the query can look differently.</p>
<p class="good">// SQL Statement if $forum_ids = array(1, 2, 3);</p>
<blockquote><pre>
SELECT FROM phpbb_forums WHERE forum_id IN (1, 2, 3)
</pre></blockquote>
<p class="good">// SQL Statement if $forum_ids = array(1) or $forum_ids = 1</p>
<blockquote><pre>
SELECT FROM phpbb_forums WHERE forum_id = 1
</pre></blockquote>
<p>Of course the same is possible for doing a negative match against a number of values:</p>
<blockquote><pre>
$sql = 'SELECT *
FROM ' . FORUMS_TABLE . '
WHERE ' . $db->sql_in_set('forum_id', $forum_ids, <strong>true</strong>);
$db->sql_query($sql);
</pre></blockquote>
<p>Based on the number of values in $forum_ids, the query can look differently here too.</p>
<p class="good">// SQL Statement if $forum_ids = array(1, 2, 3);</p>
<blockquote><pre>
SELECT FROM phpbb_forums WHERE forum_id <strong>NOT</strong> IN (1, 2, 3)
</pre></blockquote>
<p class="good">// SQL Statement if $forum_ids = array(1) or $forum_ids = 1</p>
<blockquote><pre>
SELECT FROM phpbb_forums WHERE forum_id <strong><></strong> 1
</pre></blockquote>
<p>If the given array is empty, an error will be produced.</p>
<h3>sql_build_query():</h3>
<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>
<blockquote><pre>
$sql_array = array(
'SELECT' => 'f.*, ft.mark_time',
'FROM' => array(
FORUMS_WATCH_TABLE => 'fw',
FORUMS_TABLE => 'f'
),
'LEFT_JOIN' => array(
array(
'FROM' => array(FORUMS_TRACK_TABLE => 'ft'),
'ON' => 'ft.user_id = ' . $user->data['user_id'] . ' AND ft.forum_id = f.forum_id'
)
),
'WHERE' => 'fw.user_id = ' . $user->data['user_id'] . '
AND f.forum_id = fw.forum_id',
'ORDER_BY' => 'left_id'
);
$sql = $db->sql_build_query('SELECT', $sql_array);
</pre></blockquote>
<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>
<blockquote><pre>
$sql_array = array(
'SELECT' => 'f.*',
'FROM' => array(
FORUMS_WATCH_TABLE => 'fw',
FORUMS_TABLE => 'f'
),
'WHERE' => 'fw.user_id = ' . $user->data['user_id'] . '
AND f.forum_id = fw.forum_id',
'ORDER_BY' => 'left_id'
);
if ($config['load_db_lastread'])
{
$sql_array['LEFT_JOIN'] = array(
array(
'FROM' => array(FORUMS_TRACK_TABLE => 'ft'),
'ON' => 'ft.user_id = ' . $user->data['user_id'] . ' AND ft.forum_id = f.forum_id'
)
);
$sql_array['SELECT'] .= ', ft.mark_time ';
}
else
{
// Here we read the cookie data
}
$sql = $db->sql_build_query('SELECT', $sql_array);
</pre></blockquote>
</div>
<a href="#top">Top</a>
<br /><br />
<a name="optimizing"></a><b>2.iv. Optimizations</b>
<br /><br />
<div class="paragraph">
<h3>Operations in loop definition: </h3>
<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>
<p class="bad">// On every iteration the sizeof function is called</p>
<blockquote><pre>
for ($i = 0; $i < sizeof($post_data); $i++)
{
do_something();
}
</pre></blockquote>
<p class="good">// You are able to assign the (not changing) result within the loop itself</p>
<blockquote><pre>
for ($i = 0, $size = sizeof($post_data); $i < $size; $i++)
{
do_something();
}
</pre></blockquote>
<h3>Use of in_array(): </h3>
<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>
</div>
<a href="#top">Top</a>
<br /><br />
<a name="general"></a><b>2.v. General Guidelines</b>
<br /><br />
<div class="paragraph">
<h3>General things:</h3>
<p>Never trust user input (this also applies to server variables as well as cookies).</p>
<p>Try to sanitize values returned from a function.</p>
<p>Try to sanitize given function variables within your function.</p>
<p>The auth class should be used for all authorisation checking.</p>
<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>
<h3>Variables: </h3>
<p>Make use of the <code>request_var()</code> function for anything except for submit or single checking params. </p>
<p>The request_var function determines the type to set from the second parameter (which determines the default value too). If you need to get a scalar variable type, you need to tell this the request_var function explicitly. Examples:</p>
<p class="bad">// Old method, do not use it</p>
<blockquote><pre>
$start = (isset($HTTP_GET_VARS['start'])) ? intval($HTTP_GET_VARS['start']) : intval($HTTP_POST_VARS['start']);
$submit = (isset($HTTP_POST_VARS['submit'])) ? true : false;
</pre></blockquote>
<p class="good">// Use request var and define a default variable (use the correct type)</p>
<blockquote><pre>
$start = request_var('start', 0);
$submit = (isset($_POST['submit'])) ? true : false;
</pre></blockquote>
<p class="bad">// $start is an int, the following use of request_var therefore is not allowed</p>
<blockquote><pre>
$start = request_var('start', '0');
</pre></blockquote>
<p class="good">// Getting an array, keys are integers, value defaults to 0</p>
<blockquote><pre>
$mark_array = request_var('mark', array(0));
</pre></blockquote>
<p class="good">// Getting an array, keys are strings, value defaults to 0</p>
<blockquote><pre>
$action_ary = request_var('action', array('' => 0));
</pre></blockquote>
<h3>Login checks/redirection: </h3>
<p>To show a forum login box use <code>login_forum_box($forum_data)</code>, else use the <code>login_box()</code> function.</p>
<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>
<h3>Sensitive Operations: </h3>
<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>
<h3>Sessions: </h3>
<p>Sessions should be initiated on each page, as near the top as possible using the following code:</p>
<blockquote><pre>
$user->session_begin();
$auth->acl($user->data);
$user->setup();
</pre></blockquote>
<p>The <code>$user->setup()</code> call can be used to pass on additional language definition and a custom style (used in viewforum).</p>
<h3>Errors and messages: </h3>
<p>All messages/errors should be outputed by calling <code>trigger_error()</code> using the appropriate message type and language string. Example:</p>
<blockquote><pre>
trigger_error('NO_FORUM');
</pre></blockquote>
<blockquote><pre>
trigger_error($user->lang['NO_FORUM']);
</pre></blockquote>
<blockquote><pre>
trigger_error('NO_APPROPRIATE_MODE', E_USER_ERROR);
</pre></blockquote>
<h3>Url formatting</h3>
<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>
<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>
<blockquote><pre>
append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=group&amp;g=' . $row['group_id'])
</pre></blockquote>
<h3>General function usage: </h3>
<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>
<ul>
<li>
<p>Use <code>sizeof</code> instead of <code>count</code></p>
</li>
<li>
<p>Use <code>strpos</code> instead of <code>strstr</code></p>
</li>
<li>
<p>Use <code>else if</code> instead of <code>elseif</code></p>
</li>
<li>
<p>Use <code>false</code> (lowercase) instead of <code>FALSE</code></p>
</li>
<li>
<p>Use <code>true</code> (lowercase) instead of <code>TRUE</code></p>
</li>
</ul>
</div>
<a href="#top">Top</a>
<br /><br />
<hr />
<a name="styling"></a><h1>3. Styling</h1>
<div class="paragraph">
<h3>General things</h3>
<p>Templates should be produced in a consistent manner. Where appropriate they should be based off an existing copy, e.g. index, viewforum or viewtopic (the combination of which implement a range of conditional and variable forms). Please also note that the intendation and coding guidelines also apply to templates where possible.</p>
<p>The outer table class <code>forumline</code> has gone and is replaced with <code>tablebg</code>.</p>
<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>
<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>
<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>
<blockquote><pre>
<td><span class="gensmall">TEST</span></td>
</pre></blockquote>
<p>can just as well become:</p>
<blockquote><pre>
<td class="gensmall">TEST</td>
</pre></blockquote>
<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>
<p>Row colours/classes are now defined by the template, use an <code>IF S_ROW_COUNT</code> switch, see viewtopic or viewforum for an example.</p>
<p>Remember block level ordering is important ... while not all pages validate as XHTML 1.0 Strict compliant it is something we're trying to work too.</p>
<p>Use a standard cellpadding of 2 and cellspacing of 0 on outer tables. Inner tables can vary from 0 to 3 or even 4 depending on the need.</p>
<p><strong>Use div container/css for styling and table for data representation.</strong></p>
<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>
<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>
<p>Try to keep template conditional and other statements tabbed in line with the block to which they refer.</p>
<p class="good">this is correct</p>
<blockquote><pre>
<span class="comment"><!-- BEGIN test --></span>
<tr>
<td>{test.TEXT}</td>
</tr>
<span class="comment"><!-- END test --></span>
</pre></blockquote>
<p class="good">this is also correct:</p>
<blockquote><pre>
<span class="comment"><!-- BEGIN test --></span>
<tr>
<td>{test.TEXT}</td>
</tr>
<span class="comment"><!-- END test --></span>
</pre></blockquote>
<p>it gives immediate feedback on exactly what is looping - decide which way to use based on the readability.</p>
</div>
<a href="#top">Top</a>
<br /><br />
<hr />
<a name="templating"></a><h1>4. Templating</h1>
<div class="paragraph">
<h3>File naming</h3>
<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>
<h3>Variables</h3>
<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>
<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 Mods.
</p>
<h3>Blocks/Loops</h3>
<p>The basic block level loop remains and takes the form:</p>
<blockquote><pre>
<span class="comment"><!-- BEGIN loopname --></span>
markup, {loopname.X_YYYYY}, etc.
<span class="comment"><!-- END loopname --></span>
</pre></blockquote>
<p>A bit later loops will be explained further. To not irretate you we will explain conditionals as well as other statements first.</p>
<h3>Including files</h3>
<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>
<blockquote><pre>
<span class="comment"><!-- INCLUDE filename --></span>
</pre></blockquote>
<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>
<h3>PHP</h3>
<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>
<blockquote><pre>
<span class="comment"><!-- PHP --></span>
echo "hello!";
<span class="comment"><!-- ENDPHP --></span>
</pre></blockquote>
<p>You may also include PHP from an external file using:</p>
<blockquote><pre>
<span class="comment"><!-- INCLUDEPHP somefile.php --></span>
</pre></blockquote>
<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>
<h3>Conditionals/Control structures</h3>
<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>
<blockquote><pre>
<span class="comment"><!-- IF expr --></span>
markup
<span class="comment"><!-- ENDIF --></span>
</pre></blockquote>
<p>expr can take many forms, for example:</p>
<blockquote><pre>
<span class="comment"><!-- IF loop.S_ROW_COUNT is even --></span>
markup
<span class="comment"><!-- ENDIF --></span>
</pre></blockquote>
<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>
<blockquote><pre>
== [eq]
!= [neq, ne]
<> (same as !=)
!== (not equivalent in value and type)
=== (equivalent in value and type)
> [gt]
< [lt]
>= [gte]
<= [lte]
&& [and]
|| [or]
% [mod]
! [not]
+
-
*
/
,
<< (bitwise shift left)
>> (bitwise shift right)
| (bitwise or)
^ (bitwise xor)
& (bitwise and)
~ (bitwise not)
is (can be used to join comparison operations)
</pre></blockquote>
<p>Basic parenthesis can also be used to enforce good old BODMAS rules. Additionally some basic comparison types are defined:</p>
<blockquote><pre>
even
odd
div
</pre></blockquote>
<p>Beyond the simple use of IF you can also do a sequence of comparisons using the following:</p>
<blockquote><pre>
<span class="comment"><!-- IF expr1 --></span>
markup
<span class="comment"><!-- ELSEIF expr2 --></span>
markup
.
.
.
<span class="comment"><!-- ELSEIF exprN --></span>
markup
<span class="comment"><!-- ELSE --></span>
markup
<span class="comment"><!-- ENDIF --></span>
</pre></blockquote>
<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>
<blockquote><pre>
<table>
<span class="comment"><!-- IF loop.S_ROW_COUNT is even --></span>
<tr class="row1">
<span class="comment"><!-- ELSE --></span>
<tr class="row2">
<span class="comment"><!-- ENDIF --></span>
<td>HELLO!</td>
</tr>
</table>
</pre></blockquote>
<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>
<blockquote><pre>
<table>
<span class="comment"><!-- IF loop.S_ROW_COUNT > 10 --></span>
<tr bgcolor="#FF0000">
<span class="comment"><!-- ELSEIF loop.S_ROW_COUNT > 5 --></span>
<tr bgcolor="#00FF00">
<span class="comment"><!-- ELSEIF loop.S_ROW_COUNT > 2 --></span>
<tr bgcolor="#0000FF">
<span class="comment"><!-- ELSE --></span>
<tr bgcolor="#FF00FF">
<span class="comment"><!-- ENDIF --></span>
<td>hello!</td>
</tr>
</table>
</pre></blockquote>
<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>
<blockquote><pre>
<span class="comment"><!-- IF S_USER_LOGGED_IN --></span>
markup
<span class="comment"><!-- ENDIF --></span>
</pre></blockquote>
<p>This replaces the existing (fudged) method in 2.0.x using a zero length array and BEGIN/END.</p>
<h3>Extended syntax for Blocks/Loops</h3>
<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>
<blockquote><pre>
<span class="comment"><!-- BEGIN loopname(2) --></span>
markup
<span class="comment"><!-- END loopname --></span>
</pre></blockquote>
<p>Will start the loop on the third entry (note that indexes start at zero). Extensions of this are:
<br /><br />
<code>loopname(2)</code>: Will start the loop on the 3rd entry<br />
<code>loopname(-2)</code>: Will start the loop two entries from the end<br />
<code>loopname(3,4)</code>: Will start the loop on the fourth entry and end it on the fifth<br />
<code>loopname(3,-4)</code>: Will start the loop on the fourth entry and end it four from last<br />
</p>
<p>A further extension to begin is BEGINELSE:</p>
<blockquote><pre>
<span class="comment"><!-- BEGIN loop --></span>
markup
<span class="comment"><!-- BEGINELSE --></span>
markup
<span class="comment"><!-- END loop --></span>
</pre></blockquote>
<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>
<p>Another way of checking if a loop contains values is by prefixing the loops name with a dot:</p>
<blockquote><pre>
<span class="comment"><!-- IF .loop --></span>
<span class="comment"><!-- BEGIN loop --></span>
markup
<span class="comment"><!-- END loop --></span>
<span class="comment"><!-- ELSE --></span>
markup
<span class="comment"><!-- ENDIF --></span>
</pre></blockquote>
<p>You are even able to check the number of items within a loop by comparing it with values within the IF condition:</p>
<blockquote><pre>
<span class="comment"><!-- IF .loop > 2 --></span>
<span class="comment"><!-- BEGIN loop --></span>
markup
<span class="comment"><!-- END loop --></span>
<span class="comment"><!-- ELSE --></span>
markup
<span class="comment"><!-- ENDIF --></span>
</pre></blockquote>
<p>Nesting loops cause the conditionals needing prefixed with all loops from the outer one to the inner most. An illustration of this:</p>
<blockquote><pre>
<span class="comment"><!-- BEGIN firstloop --></span>
{firstloop.MY_VARIABLE_FROM_FIRSTLOOP}
<span class="comment"><!-- BEGIN secondloop --></span>
{firstloop.secondloop.MY_VARIABLE_FROM_SECONDLOOP}
<span class="comment"><!-- END secondloop --></span>
<span class="comment"><!-- END firstloop --></span>
</pre></blockquote>
<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>
<blockquote><pre>
<span class="comment"><!-- BEGIN l_block1 --></span>
<span class="comment"><!-- IF l_block1.S_SELECTED --></span>
<strong>{l_block1.L_TITLE}</strong>
<span class="comment"><!-- IF S_PRIVMSGS --></span>
<span class="comment"><!-- the ! at the beginning of the loop name forces the loop to be not a nested one of l_block1 --></span>
<span class="comment"><!-- BEGIN !folder --></span>
<span class="comment"><!-- IF folder.S_FIRST_ROW --></span>
<ul class="nav">
<span class="comment"><!-- ENDIF --></span>
<li><a href="{folder.U_FOLDER}">{folder.FOLDER_NAME}</a></li>
<span class="comment"><!-- IF folder.S_LAST_ROW --></span>
</ul>
<span class="comment"><!-- ENDIF --></span>
<span class="comment"><!-- END !folder --></span>
<span class="comment"><!-- ENDIF --></span>
<ul class="nav">
<span class="comment"><!-- BEGIN l_block2 --></span>
<li>
<span class="comment"><!-- IF l_block1.l_block2.S_SELECTED --></span>
<strong>{l_block1.l_block2.L_TITLE}</strong>
<span class="comment"><!-- ELSE --></span>
<a href="{l_block1.l_block2.U_TITLE}">{l_block1.l_block2.L_TITLE}</a>
<span class="comment"><!-- ENDIF --></span>
</li>
<span class="comment"><!-- END l_block2 --></span>
</ul>
<span class="comment"><!-- ELSE --></span>
<a class="nav" href="{l_block1.U_TITLE}">{l_block1.L_TITLE}</a>
<span class="comment"><!-- ENDIF --></span>
<span class="comment"><!-- END l_block1 --></span>
</pre></blockquote>
<p>Let us first concentrate on this part of the example:</p>
<blockquote><pre>
<span class="comment"><!-- BEGIN l_block1 --></span>
<span class="comment"><!-- IF l_block1.S_SELECTED --></span>
markup
<span class="comment"><!-- ELSE --></span>
<a class="nav" href="{l_block1.U_TITLE}">{l_block1.L_TITLE}</a>
<span class="comment"><!-- ENDIF --></span>
<span class="comment"><!-- END l_block1 --></span>
</pre></blockquote>
<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>
<p>Let's have a closer look to the markup:</p>
<blockquote><pre>
<span class="comment"><!-- BEGIN l_block1 --></span>
.
.
<span class="comment"><!-- IF S_PRIVMSGS --></span>
<span class="comment"><!-- BEGIN !folder --></span>
<span class="comment"><!-- IF folder.S_FIRST_ROW --></span>
<ul class="nav">
<span class="comment"><!-- ENDIF --></span>
<li><a href="{folder.U_FOLDER}">{folder.FOLDER_NAME}</a></li>
<span class="comment"><!-- IF folder.S_LAST_ROW --></span>
</ul>
<span class="comment"><!-- ENDIF --></span>
<span class="comment"><!-- END !folder --></span>
<span class="comment"><!-- ENDIF --></span>
.
.
<span class="comment"><!-- END l_block1 --></span>
</pre></blockquote>
<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>
<blockquote><pre>
<span class="comment"><!-- BEGIN l_block1 --></span>
.
.
<ul class="nav">
<span class="comment"><!-- BEGIN l_block2 --></span>
<li>
<span class="comment"><!-- IF l_block1.l_block2.S_SELECTED --></span>
<strong>{l_block1.l_block2.L_TITLE}</strong>
<span class="comment"><!-- ELSE --></span>
<a href="{l_block1.l_block2.U_TITLE}">{l_block1.l_block2.L_TITLE}</a>
<span class="comment"><!-- ENDIF --></span>
</li>
<span class="comment"><!-- END l_block2 --></span>
</ul>
.
.
<span class="comment"><!-- END l_block1 --></span>
</pre></blockquote>
<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>
<p>Now back to our folder loop:</p>
<blockquote><pre>
<span class="comment"><!-- IF folder.S_FIRST_ROW --></span>
<ul class="nav">
<span class="comment"><!-- ENDIF --></span>
<li><a href="{folder.U_FOLDER}">{folder.FOLDER_NAME}</a></li>
<span class="comment"><!-- IF folder.S_LAST_ROW --></span>
</ul>
<span class="comment"><!-- ENDIF --></span>
</pre></blockquote>
<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>
<blockquote><pre>
<ul class="nav"> <span class="comment"><!-- written on first iteration --></span>
<li>first element</li> <span class="comment"><!-- written on first iteration --></span>
<li>second element</li> <span class="comment"><!-- written on second iteration --></span>
<li>third element</li> <span class="comment"><!-- written on third iteration --></span>
</ul> <span class="comment"><!-- written on third iteration --></span>
</pre></blockquote>
<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>
<blockquote><pre>
<span class="comment"><!-- IF folder.S_FIRST_ROW --></span>
<ul class="nav">
<span class="comment"><!-- ELSEIF folder.S_LAST_ROW --></span>
</ul>
<span class="comment"><!-- ELSE --></span>
<li><a href="{folder.U_FOLDER}">{folder.FOLDER_NAME}</a></li>
<span class="comment"><!-- ENDIF --></span>
</pre></blockquote>
<p>would result in the following markup:</p>
<blockquote><pre>
<ul class="nav"> <span class="comment"><!-- written on first iteration --></span>
<li>second element</li> <span class="comment"><!-- written on second iteration --></span>
</ul> <span class="comment"><!-- written on third iteration --></span>
</pre></blockquote>
<p>Just always remember that processing is taking place from up to down.</p>
</div>
<a href="#top">Top</a>
<br /><br />
<hr />
<a name="translation"></a><h1>5. Translation (<abbr title="Internationalisation">i18n</abbr>/<abbr title="Localisation">L10n</abbr>) Guidelines</h1>
<a name="standardisation"></a><b>5.i. Standardisation</b>
<br /><br />
<div class="paragraph">
<h3>Reason:</h3>
<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>
<h3>Encoding:</h3>
<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>
<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>
<h3>Language Tag:</h3>
<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>
<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>
<p>Most language tags consist of a two- or three-letter language subtag (from <a href="http://www.loc.gov/standards/iso639-2/php/English_list.php">ISO 639-1/ISO 639-2</a>). Sometimes, this is followed by a two-letter or three-digit region subtag (from <a href="http://www.iso.ch/iso/en/prods-services/iso3166ma/02iso-3166-code-lists/list-en1.html">ISO 3166-1 alpha-2</a> or <a href="http://unstats.un.org/unsd/methods/m49/m49.htm">UN M.49</a>). Some examples are:</p>
<table summary="Examples of various possible language tags as described by RFC 4646 and RFC 4647">
<caption>Language tag examples</caption>
<thead>
<tr>
<th scope="col">Language tag</th>
<th scope="col">Description</th>
<th scope="col">Component subtags</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>en</code></td>
<td>English</td>
<td><code>language</code></td>
</tr>
<tr>
<td><code>mas</code></td>
<td>Masai</td>
<td><code>language</code></td>
</tr>
<tr>
<td><code>fr-CA</code></td>
<td>French as used in Canada</td>
<td><code>language</code>+<code>region</code></td>
</tr>
<tr>
<td><code>en-833</code></td>
<td>English as used in the Isle of Man</td>
<td><code>language</code>+<code>region</code></td>
</tr>
<tr>
<td><code>zh-Hans</code></td>
<td>Chinese written with Simplified script</td>
<td><code>language</code>+<code>script</code></td>
</tr>
<tr>
<td><code>zh-Hant-HK</code></td>
<td>Chinese written with Traditional script as used in Hong Kong</td>
<td><code>language</code>+<code>script</code>+<code>region</code></td>
</tr>
<tr>
<td><code>de-AT-1996</code></td>
<td>German as used in Austria with 1996 orthography</td>
<td><code>language</code>+<code>region</code>+<code>variant</code></td>
</tr>
</tbody>
</table>
<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>
<p>Next is the <a href="http://www.unicode.org/iso15924/iso15924-codes.html">ISO 15924</a> language script code and when one should or shouldn't use it. For example, whilst <code>en-Latn</code> is syntaxically correct for describing English written with Latin script, real world English writing is <strong>more-or-less exclusively in the Latin script</strong>. For such languages like English that are written in a single script, the <a href="http://www.iana.org/assignments/language-subtag-registry"><abbr title="Internet Assigned Numbers Authority">IANA</abbr> Language Subtag Registry</a> has a "Suppress-Script" field meaning the script code <strong>should be ommitted</strong> unless a specific language tag requires a specific script code. Some languages are <strong>written in more than one script</strong> and in such cases, the script code <strong>is encouraged</strong> since an end-user may be able to read their language in one script, but not the other. Some examples are:</p>
<table summary="Examples of using a language subtag in combination with a script subtag">
<caption>Language subtag + script subtag examples</caption>
<thead>
<tr>
<th scope="col">Language tag</th>
<th scope="col">Description</th>
<th scope="col">Component subtags</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>en-Brai</code></td>
<td>English written in Braille script</td>
<td><code>language</code>+<code>script</code></td>
</tr>
<tr>
<td><code>en-Dsrt</code></td>
<td>English written in Deseret (Mormon) script</td>
<td><code>language</code>+<code>script</code></td>
</tr>
<tr>
<td><code>sr-Latn</code></td>
<td>Serbian written in Latin script</td>
<td><code>language</code>+<code>script</code></td>
</tr>
<tr>
<td><code>sr-Cyrl</code></td>
<td>Serbian written in Cyrillic script</td>
<td><code>language</code>+<code>script</code></td>
</tr>
<tr>
<td><code>mn-Mong</code></td>
<td>Mongolian written in Mongolian script</td>
<td><code>language</code>+<code>script</code></td>
</tr>
<tr>
<td><code>mn-Cyrl</code></td>
<td>Mongolian written in Cyrillic script</td>
<td><code>language</code>+<code>script</code></td>
</tr>
<tr>
<td><code>mn-Phag</code></td>
<td>Mongolian written in Phags-pa script</td>
<td><code>language</code>+<code>script</code></td>
</tr>
<tr>
<td><code>az-Cyrl-AZ</code></td>
<td>Azerbaijani written in Cyrillic script as used in Azerbaijan</td>
<td><code>language</code>+<code>script</code>+<code>region</code></td>
</tr>
<td><code>az-Latn-AZ</code></td>
<td>Azerbaijani written in Latin script as used in Azerbaijan</td>
<td><code>language</code>+<code>script</code>+<code>region</code></td>
</tr>
<tr>
<td><code>az-Arab-IR</code></td>
<td>Azerbaijani written in Arabic script as used in Iran</td>
<td><code>language</code>+<code>script</code>+<code>region</code></td>
</tr>
</tbody>
</table>
<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>
<p>Examples of English using marco-geographical regions:</p>
<table summary="Examples for English of ISO 3166-1 alpha-2 vs. UN M.49 code">
<caption>Coding for English using macro-geographical regions</caption>
<thead>
<tr>
<th scope="col">ISO 639-1/ISO 639-2 + ISO 3166-1 alpha-2</th>
<th scope="col" colspan="2">ISO 639-1/ISO 639-2 + UN M.49 (Example macro regions)</th>
</tr>
</thead>
<tbody>
<tr>
<td><dl><dt><code>en-AU</code></dt><dd>English as used in <strong>Australia</strong></dd></dl></td>
<td rowspan="2"><dl><dt><code>en-053</code></dt><dd>English as used in <strong>Australia & New Zealand</strong></dd></dl></td>
<td rowspan="3"><dl><dt><code>en-009</code></dt><dd>English as used in <strong>Oceania</strong></dd></dl></td>
</tr>
<tr>
<td><dl><dt><code>en-NZ</code></dt><dd>English as used in <strong>New Zealand</strong></dd></dl></td>
</tr>
<tr>
<td><dl><dt><code>en-FJ</code></dt><dd>English as used in <strong>Fiji</strong></dd></dl></td>
<td><dl><dt><code>en-054 </code></dt><dd>English as used in <strong>Melanesia</strong></dd></dl></td>
</tr>
</tbody>
</table>
<p>Examples of Spanish using marco-geographical regions:</p>
<table summary="Examples for Spanish of ISO 3166-1 alpha-2 vs. UN M.49 code">
<caption>Coding for Spanish macro-geographical regions</caption>
<thead>
<tr>
<th scope="col">ISO 639-1/ISO 639-2 + ISO 3166-1 alpha-2</th>
<th scope="col" colspan="2">ISO 639-1/ISO 639-2 + UN M.49 (Example macro regions)</th>
</tr>
</thead>
<tbody>
<tr>
<td><dl><dt><code>es-PR</code></dt><dd>Spanish as used in <strong>Puerto Rico</strong></dd></dl></td>
<td rowspan="3"><dl><dt><code>es-419</code></dt><dd>Spanish as used in <strong>Latin America & the Caribbean</strong></dd></dl></td>
<td rowspan="4"><dl><dt><code>es-019</code></dt><dd>Spanish as used in <strong>the Americas</strong></dd></dl></td>
</tr>
<tr>
<td><dl><dt><code>es-HN</code></dt><dd>Spanish as used in <strong>Honduras</strong></dd></dl></td>
</tr>
<tr>
<td><dl><dt><code>es-AR</code></dt><dd>Spanish as used in <strong>Argentina</strong></dd></dl></td>
</tr>
<tr>
<td><dl><dt><code>es-US</code></dt><dd>Spanish as used in <strong>United States of America</strong></dd></dl></td>
<td><dl><dt><code>es-021</code></dt><dd>Spanish as used in <strong>North America</strong></dd></dl></td>
</tr>
</tbody>
</table>
<p>Example of where the <a href="http://www.iso.ch/iso/en/prods-services/iso3166ma/02iso-3166-code-lists/list-en1.html">ISO 3166-1 alpha-2</a> is ambiguous and why <a href="http://unstats.un.org/unsd/methods/m49/m49.htm">UN M.49</a> might be preferred:</p>
<table summary="Example where the ISO 3166-1 alpha-2 is ambiguous">
<caption>Coding for ambiguous ISO 3166-1 alpha-2 regions</caption>
<thead>
<tr>
<th scope="col" colspan="2"><code>CS</code> assignment pre-1994</th>
<th scope="col" colspan="2"><code>CS</code> assignment post-1994</th>
</tr>
</thead>
<tbody>
<tr>
<td colspan="2">
<dl>
<dt><code>CS</code></dt><dd><strong>Czechoslovakia</strong> (ISO 3166-1)</dd>
<dt><code>200</code></dt><dd><strong>Czechoslovakia</strong> (UN M.49)</dd>
</dl>
</td>
<td colspan="2">
<dl>
<dt><code>CS</code></dt><dd><strong>Serbian & Montenegro</strong> (ISO 3166-1)</dd>
<dt><code>891</code></dt><dd><strong>Serbian & Montenegro</strong> (UN M.49)</dd>
</dl>
</td>
</tr>
<tr>
<td>
<dl>
<dt><code>CZ</code></dt><dd><strong>Czech Republic</strong> (ISO 3166-1)</dd>
<dt><code>203</code></dt><dd><strong>Czech Republic</strong> (UN M.49)</dd>
</dl>
</td>
<td>
<dl>
<dt><code>SK</code></dt><dd><strong>Slovakia</strong> (ISO 3166-1)</dd>
<dt><code>703</code></dt><dd><strong>Slovakia</strong> (UN M.49)</dd>
</dl>
</td>
<td>
<dl>
<dt><code>RS</code></dt><dd><strong>Serbia</strong> (ISO 3166-1)</dd>
<dt><code>688</code></dt><dd><strong>Serbia</strong> (UN M.49)</dd>
</dl>
</td>
<td>
<dl>
<dt><code>ME</code></dt><dd><strong>Montenegro</strong> (ISO 3166-1)</dd>
<dt><code>499</code></dt><dd><strong>Montenegro</strong> (UN M.49)</dd>
</dl>
</td>
</tr>
</tbody>
</table>
<h3>Macro-languages & Topolects:</h3>
<p><a href="http://tools.ietf.org/html/rfc4646">RFC 4646</a> anticipates features which shall be available in (currently draft) <a href="http://www.sil.org/iso639-3/">ISO 639-3</a> which aims to provide as complete enumeration of languages as possible, including living, extinct, ancient and constructed languages, whether majour, minor or unwritten. A new feature of <a href="http://www.sil.org/iso639-3/">ISO 639-3</a> compared to the previous two revisions is the concept of <a href="http://www.sil.org/iso639-3/macrolanguages.asp">macrolanguages</a> where Arabic and Chinese are two such examples. In such cases, their respective codes of <code>ar</code> and <code>zh</code> is very vague as to which dialect/topolect is used or perhaps some terse classical variant which may be difficult for all but very educated users. For such macrolanguages, it is recommended that the sub-language tag is used as a suffix to the macrolanguage tag, eg:</p>
<table summary="Examples of macrolanguages used with sub-language subtags">
<caption>Macrolanguage subtag + sub-language subtag examples</caption>
<thead>
<tr>
<th scope="col">Language tag</th>
<th scope="col">Description</th>
<th scope="col">Component subtags</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>zh-cmn</code></td>
<td>Mandarin (Putonghau/Guoyu) Chinese</td>
<td><code>macrolanguage</code>+<code>sublanguage</code></td>
</tr>
<tr>
<td><code>zh-yue</code></td>
<td>Yue (Cantonese) Chinese</td>
<td><code>macrolanguage</code>+<code>sublanguage</code></td>
</tr>
<tr>
<td><code>zh-cmn-Hans</code></td>
<td>Mandarin (Putonghau/Guoyu) Chinese written in Simplified script</td>
<td><code>macrolanguage</code>+<code>sublanguage</code>+<code>script</code></td>
</tr>
<tr>
<td><code>zh-cmn-Hant</code></td>
<td>Mandarin (Putonghau/Guoyu) Chinese written in Traditional script</td>
<td><code>macrolanguage</code>+<code>sublanguage</code>+<code>script</code></td>
</tr>
<tr>
<td><code>zh-nan-Latn-TW</code></td>
<td>Minnan (Hoklo) Chinese written in Latin script (POJ Romanisation) as used in Taiwan</td>
<td><code>macrolanguage</code>+<code>sublanguage</code>+<code>script</code>+<code>region</code></td>
</tr>
</tbody>
</table>
</div>
<a href="#top">Top</a>
<br /><br />
<a name="otherconsiderations"></a><b>5.ii. Other considerations</b>
<br /><br />
<div class="paragraph">
<h3>Normalisation of language tags for phpBB:</h3>
<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 appropiate, with some examples below:</p>
<table summary="Normalisation of language tags for usage in phpBB">
<caption>Language tag normalisation examples</caption>
<thead>
<tr>
<th scope="col">Raw language tag</th>
<th scope="col">Description</th>
<th scope="col">Value of <code>USER_LANG</code><br />in <code>./common.php</code></th>
<th scope="col">Language pack directory<br />name in <code>/language/</code></th>
</tr>
</thead>
<tbody>
<tr>
<td><code>en</code></td>
<td>British English</td>
<td><code>en</code></td>
<td><code>en</code></td>
</tr>
<tr>
<td><code>de-AT</code></td>
<td>German as used in Austria</td>
<td><code>de-at</code></td>
<td><code>de_at</code></td>
</tr>
<tr>
<td><code>es-419</code></td>
<td>Spanish as used in Latin America & Caribbean</td>
<td><code>en-419</code></td>
<td><code>en_419</code></td>
</tr>
<tr>
<td><code>zh-yue-Hant-HK</code></td>
<td>Cantonese written in Traditional script as used in Hong Kong</td>
<td><code>zh-yue-hant-hk</code></td>
<td><code>zh_yue_hant_hk</code></td>
</tr>
</tbody>
</table>
<h3>How to use <code>iso.txt</code>:</h3>
<p>The <code>iso.txt</code> file is a small UTF-8 encoded plain-text file which consists of three lines:</p>
<ol class="menu">
<li><code>Language's English name</code></li>
<li><code>Language's local name</code></li>
<li><code>Authors information</code></li>
</ol>
<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>
<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>
<p>For the English language description, the language name is always first and any additional attributes required to describe the subtags within the language code are then listed in order separated with commas and enclosed within parentheses, eg:</p>
<table summary="English language description examples of iso.txt for usage in phpBB">
<caption>English language description examples for iso.txt</caption>
<thead>
<tr>
<th scope="col">Raw language tag</th>
<th scope="col">English description within <code>iso.txt</code></th>
</tr>
</thead>
<tbody>
<tr>
<td><code>en</code></td>
<td>British English</td>
</tr>
<tr>
<td><code>en-US</code></td>
<td>English (United States)</td>
</tr>
<tr>
<td><code>en-053</code></td>
<td>English (Australia & New Zealand)</td>
</tr>
<tr>
<td><code>de</code></td>
<td>German</td>
</tr>
<tr>
<td><code>de-CH-1996</code></td>
<td>German (Switzerland, 1996 orthography)</td>
</tr>
<tr>
<td><code>gws-1996</code></td>
<td>Swiss German (1996 orthography)</td>
</tr>
<tr>
<td><code>zh-cmn-Hans-CN</code></td>
<td>Mandarin Chinese (Simplified, Mainland China)</td>
</tr>
<tr>
<td><code>zh-yue-Hant-HK</code></td>
<td>Cantonese Chinese (Traditional, Hong Kong)</td>
</tr>
</tbody>
</table>
<p>For the localised language description, just translate the English version though use whatever appropiate punctuation typical for your own locale, assuming the language uses punctuation at all.</p>
<h3>Unicode bi-directional considerations:</h3>
<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>
<p>The various Unicode control characters for bi-directional text and their HTML enquivalents where appropiate are as follows:</p>
<table summary="Table of the various Unicode bidirectional control characters">
<caption>Unicode bidirectional control characters & HTML elements/entities</caption>
<thead>
<tr>
<th scope="col">Unicode character<br />abbreviation</th>
<th scope="col">Unicode<br />code-point</th>
<th scope="col">Unicode character<br />name</th>
<th scope="col">Equivalent HTML<br />markup/entity</th>
<th scope="col">Raw character<br />(enclosed between '')</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>LRM</code></td>
<td><code>U+200E</code></td>
<td>Left-to-Right Mark</td>
<td><code>&lrm;</code></td>
<td>'‎'</td>
</tr>
<tr>
<td><code>RLM</code></td>
<td><code>U+200F</code></td>
<td>Right-to-Left Mark</td>
<td><code>&rlm;</code></td>
<td>'‏'</td>
</tr>
<tr>
<td><code>LRE</code></td>
<td><code>U+202A</code></td>
<td>Left-to-Right Embedding</td>
<td><code>dir="ltr"</code></td>
<td>'‪'</td>
</tr>
<tr>
<td><code>RLE</code></td>
<td><code>U+202B</code></td>
<td>Right-to-Left Embedding</td>
<td><code>dir="rtl"</code></td>
<td>'‫'</td>
</tr>
<tr>
<td><code>PDF</code></td>
<td><code>U+202C</code></td>
<td>Pop Directional Formatting</td>
<td><code></bdo></code></td>
<td>'‬'</td>
</tr>
<td><code>LRO</code></td>
<td><code>U+202D</code></td>
<td>Left-to-Right Override</td>
<td><code><bdo dir="ltr"></code></td>
<td>'‭'</td>
</tr>
<tr>
<td><code>RLO</code></td>
<td><code>U+202E</code></td>
<td>Right-to-Left Override</td>
<td><code><bdo dir="rtl"></code></td>
<td>'‮'</td>
</tr>
</tbody>
</table>
<p>For <code>iso.txt</code>, the directionality of the text can be explicitly set using special Unicode characters via any of the three methods provided by left-to-right/right-to-left markers/embeds/overrides, as without them, the ordering of characters will be incorrect, eg:</p>
<table summary="Effect of using Unicode bidirectional control characters within iso.txt">
<caption>Unicode bidirectional control characters iso.txt</caption>
<thead>
<tr>
<th scope="col">Directionality</th>
<th scope="col">Raw character view</th>
<th scope="col">Display of localised<br />description in <code>iso.txt</code></th>
<th scope="col">Ordering</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>dir="ltr"</code></td>
<td>English (Australia & New Zealand)</td>
<td dir="ltr">English (Australia & New Zealand)</td>
<td class="good">Correct</td>
</tr>
<tr>
<td><code>dir="rtl"</code></td>
<td>English (Australia & New Zealand)</td>
<td dir="rtl">English (Australia & New Zealand)</td>
<td class="bad">Incorrect</td>
</tr>
<tr>
<td><code>dir="rtl"</code> with <code>LRM</code></td>
<td>English (Australia & New Zealand)<code>U+200E</code></td>
<td dir="rtl">English (Australia & New Zealand)‎</td>
<td class="good">Correct</td>
</tr>
<tr>
<td><code>dir="rtl"</code> with <code>LRE</code> & <code>PDF</code></td>
<td><code>U+202A</code>English (Australia & New Zealand)<code>U+202C</code></td>
<td dir="rtl">‪English (Australia & New Zealand)‬</td>
<td class="good">Correct</td>
</tr>
<tr>
<td><code>dir="rtl"</code> with <code>LRO</code> & <code>PDF</code></td>
<td><code>U+202D</code>English (Australia & New Zealand)<code>U+202C</code></td>
<td dir="rtl">‭English (Australia & New Zealand)‬</td>
<td class="good">Correct</td>
</tr>
</tbody>
</table>
<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>
<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 appropiate. Lastly, in very rare instances where directionality must be forced, then use <code>LRO</code> & <code>RLO</code> with <code>PDF</code>.</p>
<p>For further information on authoring techniques of bi-directional text, please see the W3C tutorial on <a href="http://www.w3.org/International/tutorials/bidi-xhtml/">authoring techniques for XHTML pages with bi-directional text</a>.</p>
<h3>Working with placeholders:</h3>
<p>As phpBB is translated into languages with different ordering rules to that of English, it is possible to show specific values in any order deemed appropiate. Take for example the extremely simple "Page <em>X</em> of <em>Y</em>", whilst in English this could just be coded as:</p>
<blockquote><pre>
...
'PAGE_OF' => 'Page %s of %s',
/* Just grabbing the replacements as they
come and hope they are in the right order */
...
</pre></blockquote>
<p>… a clearer way to show explicit replacement ordering is to do:</p>
<blockquote><pre>
...
'PAGE_OF' => 'Page %1$s of %2$s',
/* Explicit ordering of the replacements,
even if they are the same order as English */
...
</pre></blockquote>
<p>Why bother at all? Because some languages, the string transliterated back to English might read something like:</p>
<blockquote><pre>
...
'PAGE_OF' => 'Total of %2$s pages, currently on page %1$s',
/* Explicit ordering of the replacements,
reversed compared to English as the total comes first */
...
</pre></blockquote>
</div>
<a href="#top">Top</a>
<br /><br />
<a name="writingstyle"></a><b>5.iii. Writing Style</b>
<br /><br />
<div class="paragraph">
<h3>Miscellaneous tips & hints:</h3>
<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>
<p class="bad">// Bad - The un-escapsed straight-quote/apostrophe will throw a PHP parse error
<blockquote><pre>
...
'CONV_ERROR_NO_AVATAR_PATH'
=> 'Note to developer: you must specify $convertor['avatar_path'] to use %s.',
...
</pre></blockquote>
<p class="good">// Good - Literal straight quotes should be escaped with a backslash, ie: \
<blockquote><pre>
...
'CONV_ERROR_NO_AVATAR_PATH'
=> 'Note to developer: you must specify $convertor[\'avatar_path\'] to use %s.',
...
</pre></blockquote>
<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>
<p class="bad">// Bad - The un-escapsed straight-quote/apostrophe will throw a PHP parse error
<blockquote><pre>
...
'USE_PERMISSIONS' => 'Test out user's permissions',
...
</pre></blockquote>
<p class="good">// Okay - However, non-programmers wouldn't type "user\'s" automatically
<blockquote><pre>
...
'USE_PERMISSIONS' => 'Test out user\'s permissions',
...
</pre></blockquote>
<p class="good">// Best - Use the Unicode Right-Single-Quotation-Mark character
<blockquote><pre>
...
'USE_PERMISSIONS' => 'Test out user’s permissions',
...
</pre></blockquote>
<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>
<p class="bad">// Bad - Invalid HTML, as segments not part of elements are not entitised
<blockquote><pre>
...
'FOO_BAR' => 'PHP version < 4.3.3.<br />
Visit "Downloads" at <a href="http://www.php.net/">www.php.net</a>.',
...
</pre></blockquote>
<p class="good">// Okay - No more invalid HTML, but "&quot;" is rather clumsy
<blockquote><pre>
...
'FOO_BAR' => 'PHP version &lt; 4.3.3.<br />
Visit &quot;Downloads&quot; at <a href="http://www.php.net/">www.php.net</a>.',
...
</pre></blockquote>
<p class="good">// Best - No more invalid HTML, and usage of correct typographical quotation marks
<blockquote><pre>
...
'FOO_BAR' => 'PHP version &lt; 4.3.3.<br />
Visit “Downloads” at <a href="http://www.php.net/">www.php.net</a>.',
...
</pre></blockquote>
<p>Lastly, the <code>&</code> (ampersand) must always be entitised regardless of where it is used:</p>
<p class="bad">// Bad - Invalid HTML, none of the ampersands are entitised
<blockquote><pre>
...
'FOO_BAR' => '<a href="http://somedomain.tld/?foo=1&bar=2">Foo & Bar</a>.',
...
</pre></blockquote>
<p class="good">// Good - Valid HTML, amperands are correctly entitised in all cases
<blockquote><pre>
...
'FOO_BAR' => '<a href="http://somedomain.tld/?foo=1&amp;bar=2">Foo &amp; Bar</a>.',
...
</pre></blockquote>
<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>
<h3>Spelling, punctuation, grammar, et cetera:</h3>
<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>
</div>
<a href="#top">Top</a>
<br /><br />
<hr />
<a name="changes"></a><h1>6. Guidelines Changelog</h1>
<div class="paragraph">
<h2>Revision 1.16</h2>
<ul class="menu">
<li>Added <a href="#translation">5. 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>
</ul>
<h2>Revision 1.11-1.15</h2>
<ul class="menu">
<li>Various document formatting, spelling, punctuation, grammar bugs.</li>
</ul>
<h2>Revision 1.9-1.10</h2>
<ul class="menu">
<li>Added sql_query_limit to <a href="#sql">2.iii. SQL/SQL Layout</a>.</li>
</ul>
<h2>Revision 1.8</h2>
<ul class="menu">
<li>Some adjustements to wordings</li>
<li>Updated paragraph <a href="#locations">1.iii. File Locations</a> to reflect recent changes</li>
<li>Extended paragraph <a href="#codelayout">2.ii. Code Layout</a>.</li>
<li>Added sql_in_set and sql_build_query explanation to <a href="#sql">2.iii. SQL/SQL Layout</a>.</li>
<li>Updated paragraph <a href="#styling">3. Styling</a>.</li>
<li>Updated paragraph <a href="#templating">4. Templating</a> to explain loop checking, loop breaking and other changes we recently made.</li>
</ul>
<h2>Revision 1.5</h2>
<ul class="menu">
<li>Changed General function usage paragraph in <a href="#general">2.v. General Guidelines</a></li>
</ul>
</div>
<a href="#top">Top</a>
<!-- END DOCUMENT -->
</div>
<div id="footer"> $Id$
<br /><br />
</div>
</body>
</html>
|