@@ -5,13 +5,13 @@ |
||
5 | 5 | * Config file, feel free to modify |
6 | 6 | */ |
7 | 7 | |
8 | - define('QR_CACHEABLE', true); // use cache - more disk reads but less CPU power, masks and format templates are stored there |
|
9 | - define('QR_CACHE_DIR', dirname(__FILE__).DIRECTORY_SEPARATOR.'cache'.DIRECTORY_SEPARATOR); // used when QR_CACHEABLE === true |
|
10 | - define('QR_LOG_DIR', dirname(__FILE__).DIRECTORY_SEPARATOR); // default error logs dir |
|
8 | + define('QR_CACHEABLE', true); // use cache - more disk reads but less CPU power, masks and format templates are stored there |
|
9 | + define('QR_CACHE_DIR', dirname(__FILE__).DIRECTORY_SEPARATOR.'cache'.DIRECTORY_SEPARATOR); // used when QR_CACHEABLE === true |
|
10 | + define('QR_LOG_DIR', dirname(__FILE__).DIRECTORY_SEPARATOR); // default error logs dir |
|
11 | 11 | |
12 | - define('QR_FIND_BEST_MASK', true); // if true, estimates best mask (spec. default, but extremally slow; set to false to significant performance boost but (propably) worst quality code |
|
13 | - define('QR_FIND_FROM_RANDOM', false); // if false, checks all masks available, otherwise value tells count of masks need to be checked, mask id are got randomly |
|
14 | - define('QR_DEFAULT_MASK', 2); // when QR_FIND_BEST_MASK === false |
|
12 | + define('QR_FIND_BEST_MASK', true); // if true, estimates best mask (spec. default, but extremally slow; set to false to significant performance boost but (propably) worst quality code |
|
13 | + define('QR_FIND_FROM_RANDOM', false); // if false, checks all masks available, otherwise value tells count of masks need to be checked, mask id are got randomly |
|
14 | + define('QR_DEFAULT_MASK', 2); // when QR_FIND_BEST_MASK === false |
|
15 | 15 | |
16 | - define('QR_PNG_MAXIMUM_SIZE', 1024); // maximum allowed png image width (in pixels), tune to make sure GD and PHP can handle such big images |
|
16 | + define('QR_PNG_MAXIMUM_SIZE', 1024); // maximum allowed png image width (in pixels), tune to make sure GD and PHP can handle such big images |
|
17 | 17 | |
18 | 18 | \ No newline at end of file |
@@ -14,4 +14,4 @@ |
||
14 | 14 | define('QR_DEFAULT_MASK', 2); // when QR_FIND_BEST_MASK === false |
15 | 15 | |
16 | 16 | define('QR_PNG_MAXIMUM_SIZE', 1024); // maximum allowed png image width (in pixels), tune to make sure GD and PHP can handle such big images |
17 | - |
|
18 | 17 | \ No newline at end of file |
18 | + |
|
19 | 19 | \ No newline at end of file |
@@ -42,12 +42,12 @@ discard block |
||
42 | 42 | //processing form input |
43 | 43 | //remember to sanitize user input in real-life solution !!! |
44 | 44 | $errorCorrectionLevel = 'L'; |
45 | - if (isset($_REQUEST['level']) && in_array($_REQUEST['level'], array('L','M','Q','H'))) |
|
45 | + if (isset($_REQUEST['level']) && in_array($_REQUEST['level'], array('L', 'M', 'Q', 'H'))) |
|
46 | 46 | $errorCorrectionLevel = $_REQUEST['level']; |
47 | 47 | |
48 | 48 | $matrixPointSize = 4; |
49 | 49 | if (isset($_REQUEST['size'])) |
50 | - $matrixPointSize = min(max((int)$_REQUEST['size'], 1), 10); |
|
50 | + $matrixPointSize = min(max((int) $_REQUEST['size'], 1), 10); |
|
51 | 51 | |
52 | 52 | |
53 | 53 | if (isset($_REQUEST['data'])) { |
@@ -73,17 +73,17 @@ discard block |
||
73 | 73 | |
74 | 74 | //config form |
75 | 75 | echo '<form action="index.php" method="post"> |
76 | - Data: <input name="data" value="'.(isset($_REQUEST['data'])?htmlspecialchars($_REQUEST['data']):'PHP QR Code :)').'" /> |
|
76 | + Data: <input name="data" value="'.(isset($_REQUEST['data']) ?htmlspecialchars($_REQUEST['data']) : 'PHP QR Code :)').'" /> |
|
77 | 77 | ECC: <select name="level"> |
78 | - <option value="L"'.(($errorCorrectionLevel=='L')?' selected':'').'>L - smallest</option> |
|
79 | - <option value="M"'.(($errorCorrectionLevel=='M')?' selected':'').'>M</option> |
|
80 | - <option value="Q"'.(($errorCorrectionLevel=='Q')?' selected':'').'>Q</option> |
|
81 | - <option value="H"'.(($errorCorrectionLevel=='H')?' selected':'').'>H - best</option> |
|
78 | + <option value="L"'.(($errorCorrectionLevel == 'L') ? ' selected' : '').'>L - smallest</option> |
|
79 | + <option value="M"'.(($errorCorrectionLevel == 'M') ? ' selected' : '').'>M</option> |
|
80 | + <option value="Q"'.(($errorCorrectionLevel == 'Q') ? ' selected' : '').'>Q</option> |
|
81 | + <option value="H"'.(($errorCorrectionLevel == 'H') ? ' selected' : '').'>H - best</option> |
|
82 | 82 | </select> |
83 | 83 | Size: <select name="size">'; |
84 | 84 | |
85 | - for($i=1;$i<=10;$i++) |
|
86 | - echo '<option value="'.$i.'"'.(($matrixPointSize==$i)?' selected':'').'>'.$i.'</option>'; |
|
85 | + for ($i = 1; $i <= 10; $i++) |
|
86 | + echo '<option value="'.$i.'"'.(($matrixPointSize == $i) ? ' selected' : '').'>'.$i.'</option>'; |
|
87 | 87 | |
88 | 88 | echo '</select> |
89 | 89 | <input type="submit" value="GENERATE"></form><hr/>'; |
@@ -33,8 +33,9 @@ discard block |
||
33 | 33 | include "qrlib.php"; |
34 | 34 | |
35 | 35 | //ofcourse we need rights to create temp dir |
36 | - if (!file_exists($PNG_TEMP_DIR)) |
|
37 | - mkdir($PNG_TEMP_DIR); |
|
36 | + if (!file_exists($PNG_TEMP_DIR)) { |
|
37 | + mkdir($PNG_TEMP_DIR); |
|
38 | + } |
|
38 | 39 | |
39 | 40 | |
40 | 41 | $filename = $PNG_TEMP_DIR.'test.png'; |
@@ -42,19 +43,22 @@ discard block |
||
42 | 43 | //processing form input |
43 | 44 | //remember to sanitize user input in real-life solution !!! |
44 | 45 | $errorCorrectionLevel = 'L'; |
45 | - if (isset($_REQUEST['level']) && in_array($_REQUEST['level'], array('L','M','Q','H'))) |
|
46 | - $errorCorrectionLevel = $_REQUEST['level']; |
|
46 | + if (isset($_REQUEST['level']) && in_array($_REQUEST['level'], array('L','M','Q','H'))) { |
|
47 | + $errorCorrectionLevel = $_REQUEST['level']; |
|
48 | + } |
|
47 | 49 | |
48 | 50 | $matrixPointSize = 4; |
49 | - if (isset($_REQUEST['size'])) |
|
50 | - $matrixPointSize = min(max((int)$_REQUEST['size'], 1), 10); |
|
51 | + if (isset($_REQUEST['size'])) { |
|
52 | + $matrixPointSize = min(max((int)$_REQUEST['size'], 1), 10); |
|
53 | + } |
|
51 | 54 | |
52 | 55 | |
53 | 56 | if (isset($_REQUEST['data'])) { |
54 | 57 | |
55 | 58 | //it's very important! |
56 | - if (trim($_REQUEST['data']) == '') |
|
57 | - die('data cannot be empty! <a href="?">back</a>'); |
|
59 | + if (trim($_REQUEST['data']) == '') { |
|
60 | + die('data cannot be empty! <a href="?">back</a>'); |
|
61 | + } |
|
58 | 62 | |
59 | 63 | // user data |
60 | 64 | $filename = $PNG_TEMP_DIR.'test'.md5($_REQUEST['data'].'|'.$errorCorrectionLevel.'|'.$matrixPointSize).'.png'; |
@@ -82,8 +86,9 @@ discard block |
||
82 | 86 | </select> |
83 | 87 | Size: <select name="size">'; |
84 | 88 | |
85 | - for($i=1;$i<=10;$i++) |
|
86 | - echo '<option value="'.$i.'"'.(($matrixPointSize==$i)?' selected':'').'>'.$i.'</option>'; |
|
89 | + for($i=1;$i<=10;$i++) { |
|
90 | + echo '<option value="'.$i.'"'.(($matrixPointSize==$i)?' selected':'').'>'.$i.'</option>'; |
|
91 | + } |
|
87 | 92 | |
88 | 93 | echo '</select> |
89 | 94 | <input type="submit" value="GENERATE"></form><hr/>'; |
@@ -30,8 +30,8 @@ discard block |
||
30 | 30 | $len = count($frame); |
31 | 31 | foreach ($frame as &$frameLine) { |
32 | 32 | |
33 | - for($i=0; $i<$len; $i++) { |
|
34 | - $frameLine[$i] = (ord($frameLine[$i])&1)?'1':'0'; |
|
33 | + for ($i = 0; $i < $len; $i++) { |
|
34 | + $frameLine[$i] = (ord($frameLine[$i]) & 1) ? '1' : '0'; |
|
35 | 35 | } |
36 | 36 | } |
37 | 37 | |
@@ -61,8 +61,8 @@ discard block |
||
61 | 61 | |
62 | 62 | foreach ($qrTab as $line) { |
63 | 63 | $arrAdd = array(); |
64 | - foreach(str_split($line) as $char) |
|
65 | - $arrAdd[] = ($char=='1')?1:0; |
|
64 | + foreach (str_split($line) as $char) |
|
65 | + $arrAdd[] = ($char == '1') ? 1 : 0; |
|
66 | 66 | $barcode_array['bcode'][] = $arrAdd; |
67 | 67 | } |
68 | 68 | |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | QRtools::markTime('before_build_cache'); |
82 | 82 | |
83 | 83 | $mask = new QRmask(); |
84 | - for ($a=1; $a <= QRSPEC_VERSION_MAX; $a++) { |
|
84 | + for ($a = 1; $a <= QRSPEC_VERSION_MAX; $a++) { |
|
85 | 85 | $frame = QRspec::newFrame($a); |
86 | 86 | if (QR_IMAGE) { |
87 | 87 | $fileName = QR_CACHE_DIR.'frame_'.$a.'.png'; |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | |
91 | 91 | $width = count($frame); |
92 | 92 | $bitMask = array_fill(0, $width, array_fill(0, $width, 0)); |
93 | - for ($maskNo=0; $maskNo<8; $maskNo++) |
|
93 | + for ($maskNo = 0; $maskNo < 8; $maskNo++) |
|
94 | 94 | $mask->makeMaskNo($maskNo, $width, $frame, $bitMask, true); |
95 | 95 | } |
96 | 96 | |
@@ -115,8 +115,8 @@ discard block |
||
115 | 115 | public static function dumpMask($frame) |
116 | 116 | { |
117 | 117 | $width = count($frame); |
118 | - for($y=0;$y<$width;$y++) { |
|
119 | - for($x=0;$x<$width;$x++) { |
|
118 | + for ($y = 0; $y < $width; $y++) { |
|
119 | + for ($x = 0; $x < $width; $x++) { |
|
120 | 120 | echo ord($frame[$y][$x]).','; |
121 | 121 | } |
122 | 122 | } |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | public static function markTime($markerId) |
127 | 127 | { |
128 | 128 | list($usec, $sec) = explode(" ", microtime()); |
129 | - $time = ((float)$usec + (float)$sec); |
|
129 | + $time = ((float) $usec + (float) $sec); |
|
130 | 130 | |
131 | 131 | if (!isset($GLOBALS['qr_time_bench'])) |
132 | 132 | $GLOBALS['qr_time_bench'] = array(); |
@@ -147,9 +147,9 @@ discard block |
||
147 | 147 | <thead><tr style="border-bottom:1px solid silver"><td colspan="2" style="text-align:center">BENCHMARK</td></tr></thead> |
148 | 148 | <tbody>'; |
149 | 149 | |
150 | - foreach($GLOBALS['qr_time_bench'] as $markerId=>$thisTime) { |
|
150 | + foreach ($GLOBALS['qr_time_bench'] as $markerId=>$thisTime) { |
|
151 | 151 | if ($p > 0) { |
152 | - echo '<tr><th style="text-align:right">till '.$markerId.': </th><td>'.number_format($thisTime-$lastTime, 6).'s</td></tr>'; |
|
152 | + echo '<tr><th style="text-align:right">till '.$markerId.': </th><td>'.number_format($thisTime - $lastTime, 6).'s</td></tr>'; |
|
153 | 153 | } else { |
154 | 154 | $startTime = $thisTime; |
155 | 155 | } |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | } |
160 | 160 | |
161 | 161 | echo '</tbody><tfoot> |
162 | - <tr style="border-top:2px solid black"><th style="text-align:right">TOTAL: </th><td>'.number_format($lastTime-$startTime, 6).'s</td></tr> |
|
162 | + <tr style="border-top:2px solid black"><th style="text-align:right">TOTAL: </th><td>'.number_format($lastTime - $startTime, 6).'s</td></tr> |
|
163 | 163 | </tfoot> |
164 | 164 | </table>'; |
165 | 165 | } |
@@ -43,8 +43,9 @@ discard block |
||
43 | 43 | { |
44 | 44 | $barcode_array = array(); |
45 | 45 | |
46 | - if (!is_array($mode)) |
|
47 | - $mode = explode(',', $mode); |
|
46 | + if (!is_array($mode)) { |
|
47 | + $mode = explode(',', $mode); |
|
48 | + } |
|
48 | 49 | |
49 | 50 | $eccLevel = 'L'; |
50 | 51 | |
@@ -61,8 +62,9 @@ discard block |
||
61 | 62 | |
62 | 63 | foreach ($qrTab as $line) { |
63 | 64 | $arrAdd = array(); |
64 | - foreach(str_split($line) as $char) |
|
65 | - $arrAdd[] = ($char=='1')?1:0; |
|
65 | + foreach(str_split($line) as $char) { |
|
66 | + $arrAdd[] = ($char=='1')?1:0; |
|
67 | + } |
|
66 | 68 | $barcode_array['bcode'][] = $arrAdd; |
67 | 69 | } |
68 | 70 | |
@@ -90,8 +92,9 @@ discard block |
||
90 | 92 | |
91 | 93 | $width = count($frame); |
92 | 94 | $bitMask = array_fill(0, $width, array_fill(0, $width, 0)); |
93 | - for ($maskNo=0; $maskNo<8; $maskNo++) |
|
94 | - $mask->makeMaskNo($maskNo, $width, $frame, $bitMask, true); |
|
95 | + for ($maskNo=0; $maskNo<8; $maskNo++) { |
|
96 | + $mask->makeMaskNo($maskNo, $width, $frame, $bitMask, true); |
|
97 | + } |
|
95 | 98 | } |
96 | 99 | |
97 | 100 | QRtools::markTime('after_build_cache'); |
@@ -128,8 +131,9 @@ discard block |
||
128 | 131 | list($usec, $sec) = explode(" ", microtime()); |
129 | 132 | $time = ((float)$usec + (float)$sec); |
130 | 133 | |
131 | - if (!isset($GLOBALS['qr_time_bench'])) |
|
132 | - $GLOBALS['qr_time_bench'] = array(); |
|
134 | + if (!isset($GLOBALS['qr_time_bench'])) { |
|
135 | + $GLOBALS['qr_time_bench'] = array(); |
|
136 | + } |
|
133 | 137 | |
134 | 138 | $GLOBALS['qr_time_bench'][$markerId] = $time; |
135 | 139 | } |
@@ -78,9 +78,9 @@ discard block |
||
78 | 78 | //---------------------------------------------------------------------- |
79 | 79 | public static function buildCache() |
80 | 80 | { |
81 | - QRtools::markTime('before_build_cache'); |
|
81 | + QRtools::markTime('before_build_cache'); |
|
82 | 82 | |
83 | - $mask = new QRmask(); |
|
83 | + $mask = new QRmask(); |
|
84 | 84 | for ($a=1; $a <= QRSPEC_VERSION_MAX; $a++) { |
85 | 85 | $frame = QRspec::newFrame($a); |
86 | 86 | if (QR_IMAGE) { |
@@ -88,13 +88,13 @@ discard block |
||
88 | 88 | QRimage::png(self::binarize($frame), $fileName, 1, 0); |
89 | 89 | } |
90 | 90 | |
91 | - $width = count($frame); |
|
92 | - $bitMask = array_fill(0, $width, array_fill(0, $width, 0)); |
|
93 | - for ($maskNo=0; $maskNo<8; $maskNo++) |
|
94 | - $mask->makeMaskNo($maskNo, $width, $frame, $bitMask, true); |
|
91 | + $width = count($frame); |
|
92 | + $bitMask = array_fill(0, $width, array_fill(0, $width, 0)); |
|
93 | + for ($maskNo=0; $maskNo<8; $maskNo++) |
|
94 | + $mask->makeMaskNo($maskNo, $width, $frame, $bitMask, true); |
|
95 | 95 | } |
96 | 96 | |
97 | - QRtools::markTime('after_build_cache'); |
|
97 | + QRtools::markTime('after_build_cache'); |
|
98 | 98 | } |
99 | 99 | |
100 | 100 | //---------------------------------------------------------------------- |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | class QRimage { |
28 | 28 | |
29 | 29 | //---------------------------------------------------------------------- |
30 | - public static function png($frame, $filename = false, $pixelPerPoint = 4, $outerFrame = 4,$saveandprint=FALSE) |
|
30 | + public static function png($frame, $filename = false, $pixelPerPoint = 4, $outerFrame = 4, $saveandprint = FALSE) |
|
31 | 31 | { |
32 | 32 | $image = self::image($frame, $pixelPerPoint, $outerFrame); |
33 | 33 | |
@@ -35,11 +35,11 @@ discard block |
||
35 | 35 | Header("Content-type: image/png"); |
36 | 36 | ImagePng($image); |
37 | 37 | } else { |
38 | - if($saveandprint===TRUE){ |
|
38 | + if ($saveandprint === TRUE) { |
|
39 | 39 | ImagePng($image, $filename); |
40 | 40 | header("Content-type: image/png"); |
41 | 41 | ImagePng($image); |
42 | - }else{ |
|
42 | + } else { |
|
43 | 43 | ImagePng($image, $filename); |
44 | 44 | } |
45 | 45 | } |
@@ -68,25 +68,25 @@ discard block |
||
68 | 68 | $h = count($frame); |
69 | 69 | $w = strlen($frame[0]); |
70 | 70 | |
71 | - $imgW = $w + 2*$outerFrame; |
|
72 | - $imgH = $h + 2*$outerFrame; |
|
71 | + $imgW = $w + 2 * $outerFrame; |
|
72 | + $imgH = $h + 2 * $outerFrame; |
|
73 | 73 | |
74 | - $base_image =ImageCreate($imgW, $imgH); |
|
74 | + $base_image = ImageCreate($imgW, $imgH); |
|
75 | 75 | |
76 | - $col[0] = ImageColorAllocate($base_image,255,255,255); |
|
77 | - $col[1] = ImageColorAllocate($base_image,0,0,0); |
|
76 | + $col[0] = ImageColorAllocate($base_image, 255, 255, 255); |
|
77 | + $col[1] = ImageColorAllocate($base_image, 0, 0, 0); |
|
78 | 78 | |
79 | 79 | imagefill($base_image, 0, 0, $col[0]); |
80 | 80 | |
81 | - for($y=0; $y<$h; $y++) { |
|
82 | - for($x=0; $x<$w; $x++) { |
|
81 | + for ($y = 0; $y < $h; $y++) { |
|
82 | + for ($x = 0; $x < $w; $x++) { |
|
83 | 83 | if ($frame[$y][$x] == '1') { |
84 | - ImageSetPixel($base_image,$x+$outerFrame,$y+$outerFrame,$col[1]); |
|
84 | + ImageSetPixel($base_image, $x + $outerFrame, $y + $outerFrame, $col[1]); |
|
85 | 85 | } |
86 | 86 | } |
87 | 87 | } |
88 | 88 | |
89 | - $target_image =ImageCreate($imgW * $pixelPerPoint, $imgH * $pixelPerPoint); |
|
89 | + $target_image = ImageCreate($imgW * $pixelPerPoint, $imgH * $pixelPerPoint); |
|
90 | 90 | ImageCopyResized($target_image, $base_image, 0, 0, 0, 0, $imgW * $pixelPerPoint, $imgH * $pixelPerPoint, $imgW, $imgH); |
91 | 91 | ImageDestroy($base_image); |
92 | 92 |
@@ -39,7 +39,7 @@ |
||
39 | 39 | ImagePng($image, $filename); |
40 | 40 | header("Content-type: image/png"); |
41 | 41 | ImagePng($image); |
42 | - }else{ |
|
42 | + } else{ |
|
43 | 43 | ImagePng($image, $filename); |
44 | 44 | } |
45 | 45 | } |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | class QRimage { |
28 | 28 | |
29 | 29 | //---------------------------------------------------------------------- |
30 | - public static function png($frame, $filename = false, $pixelPerPoint = 4, $outerFrame = 4,$saveandprint=FALSE) |
|
30 | + public static function png($frame, $filename = false, $pixelPerPoint = 4, $outerFrame = 4,$saveandprint=false) |
|
31 | 31 | { |
32 | 32 | $image = self::image($frame, $pixelPerPoint, $outerFrame); |
33 | 33 | |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | Header("Content-type: image/png"); |
36 | 36 | ImagePng($image); |
37 | 37 | } else { |
38 | - if($saveandprint===TRUE){ |
|
38 | + if($saveandprint===true){ |
|
39 | 39 | ImagePng($image, $filename); |
40 | 40 | header("Content-type: image/png"); |
41 | 41 | ImagePng($image); |
@@ -69,17 +69,17 @@ discard block |
||
69 | 69 | |
70 | 70 | /* not really important, this one; perhaps I could've put it inline with |
71 | 71 | * the rest. */ |
72 | -function find_match($curlscore,$curcscore,$curgtlang,$langval,$charval, |
|
72 | +function find_match($curlscore, $curcscore, $curgtlang, $langval, $charval, |
|
73 | 73 | $gtlang) |
74 | 74 | { |
75 | - if($curlscore < $langval) { |
|
76 | - $curlscore=$langval; |
|
77 | - $curcscore=$charval; |
|
78 | - $curgtlang=$gtlang; |
|
75 | + if ($curlscore < $langval) { |
|
76 | + $curlscore = $langval; |
|
77 | + $curcscore = $charval; |
|
78 | + $curgtlang = $gtlang; |
|
79 | 79 | } else if ($curlscore == $langval) { |
80 | - if($curcscore < $charval) { |
|
81 | - $curcscore=$charval; |
|
82 | - $curgtlang=$gtlang; |
|
80 | + if ($curcscore < $charval) { |
|
81 | + $curcscore = $charval; |
|
82 | + $curgtlang = $gtlang; |
|
83 | 83 | } |
84 | 84 | } |
85 | 85 | return array($curlscore, $curcscore, $curgtlang); |
@@ -87,22 +87,20 @@ discard block |
||
87 | 87 | |
88 | 88 | function al2gt($gettextlangs, $mime) { |
89 | 89 | /* default to "everything is acceptable", as RFC2616 specifies */ |
90 | - $acceptLang=(($_SERVER["HTTP_ACCEPT_LANGUAGE"] == '') ? '*' : |
|
91 | - $_SERVER["HTTP_ACCEPT_LANGUAGE"]); |
|
92 | - $acceptChar=(($_SERVER["HTTP_ACCEPT_CHARSET"] == '') ? '*' : |
|
93 | - $_SERVER["HTTP_ACCEPT_CHARSET"]); |
|
94 | - $alparts=@preg_split("/,/",$acceptLang); |
|
95 | - $acparts=@preg_split("/,/",$acceptChar); |
|
90 | + $acceptLang = (($_SERVER["HTTP_ACCEPT_LANGUAGE"] == '') ? '*' : $_SERVER["HTTP_ACCEPT_LANGUAGE"]); |
|
91 | + $acceptChar = (($_SERVER["HTTP_ACCEPT_CHARSET"] == '') ? '*' : $_SERVER["HTTP_ACCEPT_CHARSET"]); |
|
92 | + $alparts = @preg_split("/,/", $acceptLang); |
|
93 | + $acparts = @preg_split("/,/", $acceptChar); |
|
96 | 94 | |
97 | 95 | /* Parse the contents of the Accept-Language header.*/ |
98 | - foreach($alparts as $part) { |
|
99 | - $part=trim($part); |
|
100 | - if(preg_match("/;/", $part)) { |
|
101 | - $lang=@preg_split("/;/",$part); |
|
102 | - $score=@preg_split("/=/",$lang[1]); |
|
103 | - $alscores[$lang[0]]=$score[1]; |
|
96 | + foreach ($alparts as $part) { |
|
97 | + $part = trim($part); |
|
98 | + if (preg_match("/;/", $part)) { |
|
99 | + $lang = @preg_split("/;/", $part); |
|
100 | + $score = @preg_split("/=/", $lang[1]); |
|
101 | + $alscores[$lang[0]] = $score[1]; |
|
104 | 102 | } else { |
105 | - $alscores[$part]=1; |
|
103 | + $alscores[$part] = 1; |
|
106 | 104 | } |
107 | 105 | } |
108 | 106 | |
@@ -116,20 +114,20 @@ discard block |
||
116 | 114 | * Making it 2 for the time being, so that we |
117 | 115 | * can distinguish between "not specified" and "specified as 1" later |
118 | 116 | * on. */ |
119 | - $acscores["ISO-8859-1"]=2; |
|
117 | + $acscores["ISO-8859-1"] = 2; |
|
120 | 118 | |
121 | - foreach($acparts as $part) { |
|
122 | - $part=trim($part); |
|
123 | - if(preg_match("/;/", $part)) { |
|
124 | - $cs=@preg_split("/;/",$part); |
|
125 | - $score=@preg_split("/=/",$cs[1]); |
|
126 | - $acscores[strtoupper($cs[0])]=$score[1]; |
|
119 | + foreach ($acparts as $part) { |
|
120 | + $part = trim($part); |
|
121 | + if (preg_match("/;/", $part)) { |
|
122 | + $cs = @preg_split("/;/", $part); |
|
123 | + $score = @preg_split("/=/", $cs[1]); |
|
124 | + $acscores[strtoupper($cs[0])] = $score[1]; |
|
127 | 125 | } else { |
128 | - $acscores[strtoupper($part)]=1; |
|
126 | + $acscores[strtoupper($part)] = 1; |
|
129 | 127 | } |
130 | 128 | } |
131 | - if($acscores["ISO-8859-1"]==2) { |
|
132 | - $acscores["ISO-8859-1"]=(isset($acscores["*"])?$acscores["*"]:1); |
|
129 | + if ($acscores["ISO-8859-1"] == 2) { |
|
130 | + $acscores["ISO-8859-1"] = (isset($acscores["*"]) ? $acscores["*"] : 1); |
|
133 | 131 | } |
134 | 132 | |
135 | 133 | /* |
@@ -137,18 +135,18 @@ discard block |
||
137 | 135 | * with the highest score, excluding the ones with a charset the user |
138 | 136 | * did not include. |
139 | 137 | */ |
140 | - $curlscore=0; |
|
141 | - $curcscore=0; |
|
142 | - $curgtlang=NULL; |
|
143 | - foreach($gettextlangs as $gtlang) { |
|
138 | + $curlscore = 0; |
|
139 | + $curcscore = 0; |
|
140 | + $curgtlang = NULL; |
|
141 | + foreach ($gettextlangs as $gtlang) { |
|
144 | 142 | |
145 | - $tmp1=preg_replace("/\_/","-",$gtlang); |
|
146 | - $tmp2=@preg_split("/\./",$tmp1); |
|
147 | - $allang=strtolower($tmp2[0]); |
|
148 | - $gtcs=strtoupper($tmp2[1]); |
|
149 | - $noct=@preg_split("/-/",$allang); |
|
143 | + $tmp1 = preg_replace("/\_/", "-", $gtlang); |
|
144 | + $tmp2 = @preg_split("/\./", $tmp1); |
|
145 | + $allang = strtolower($tmp2[0]); |
|
146 | + $gtcs = strtoupper($tmp2[1]); |
|
147 | + $noct = @preg_split("/-/", $allang); |
|
150 | 148 | |
151 | - $testvals=array( |
|
149 | + $testvals = array( |
|
152 | 150 | array(@$alscores[$allang], @$acscores[$gtcs]), |
153 | 151 | array(@$alscores[$noct[0]], @$acscores[$gtcs]), |
154 | 152 | array(@$alscores[$allang], @$acscores["*"]), |
@@ -156,15 +154,15 @@ discard block |
||
156 | 154 | array(@$alscores["*"], @$acscores[$gtcs]), |
157 | 155 | array(@$alscores["*"], @$acscores["*"])); |
158 | 156 | |
159 | - $found=FALSE; |
|
160 | - foreach($testvals as $tval) { |
|
161 | - if(!$found && isset($tval[0]) && isset($tval[1])) { |
|
162 | - $arr=find_match($curlscore, $curcscore, $curgtlang, $tval[0], |
|
157 | + $found = FALSE; |
|
158 | + foreach ($testvals as $tval) { |
|
159 | + if (!$found && isset($tval[0]) && isset($tval[1])) { |
|
160 | + $arr = find_match($curlscore, $curcscore, $curgtlang, $tval[0], |
|
163 | 161 | $tval[1], $gtlang); |
164 | - $curlscore=$arr[0]; |
|
165 | - $curcscore=$arr[1]; |
|
166 | - $curgtlang=$arr[2]; |
|
167 | - $found=TRUE; |
|
162 | + $curlscore = $arr[0]; |
|
163 | + $curcscore = $arr[1]; |
|
164 | + $curgtlang = $arr[2]; |
|
165 | + $found = TRUE; |
|
168 | 166 | } |
169 | 167 | } |
170 | 168 | } |
@@ -172,10 +170,10 @@ discard block |
||
172 | 170 | /* We must re-parse the gettext-string now, since we may have found it |
173 | 171 | * through a "*" qualifier.*/ |
174 | 172 | |
175 | - $gtparts=@preg_split("/\./",$curgtlang); |
|
176 | - $tmp=strtolower($gtparts[0]); |
|
177 | - $lang=preg_replace("/\_/", "-", $tmp); |
|
178 | - $charset=$gtparts[1]; |
|
173 | + $gtparts = @preg_split("/\./", $curgtlang); |
|
174 | + $tmp = strtolower($gtparts[0]); |
|
175 | + $lang = preg_replace("/\_/", "-", $tmp); |
|
176 | + $charset = $gtparts[1]; |
|
179 | 177 | |
180 | 178 | header("Content-Language: $lang"); |
181 | 179 | header("Content-Type: $mime; charset=$charset"); |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | */ |
140 | 140 | $curlscore=0; |
141 | 141 | $curcscore=0; |
142 | - $curgtlang=NULL; |
|
142 | + $curgtlang=null; |
|
143 | 143 | foreach($gettextlangs as $gtlang) { |
144 | 144 | |
145 | 145 | $tmp1=preg_replace("/\_/","-",$gtlang); |
@@ -156,7 +156,7 @@ discard block |
||
156 | 156 | array(@$alscores["*"], @$acscores[$gtcs]), |
157 | 157 | array(@$alscores["*"], @$acscores["*"])); |
158 | 158 | |
159 | - $found=FALSE; |
|
159 | + $found=false; |
|
160 | 160 | foreach($testvals as $tval) { |
161 | 161 | if(!$found && isset($tval[0]) && isset($tval[1])) { |
162 | 162 | $arr=find_match($curlscore, $curcscore, $curgtlang, $tval[0], |
@@ -164,7 +164,7 @@ discard block |
||
164 | 164 | $curlscore=$arr[0]; |
165 | 165 | $curcscore=$arr[1]; |
166 | 166 | $curgtlang=$arr[2]; |
167 | - $found=TRUE; |
|
167 | + $found=true; |
|
168 | 168 | } |
169 | 169 | } |
170 | 170 | } |
@@ -72,43 +72,43 @@ discard block |
||
72 | 72 | function find_match($curlscore,$curcscore,$curgtlang,$langval,$charval, |
73 | 73 | $gtlang) |
74 | 74 | { |
75 | - if($curlscore < $langval) { |
|
75 | + if($curlscore < $langval) { |
|
76 | 76 | $curlscore=$langval; |
77 | 77 | $curcscore=$charval; |
78 | 78 | $curgtlang=$gtlang; |
79 | - } else if ($curlscore == $langval) { |
|
79 | + } else if ($curlscore == $langval) { |
|
80 | 80 | if($curcscore < $charval) { |
81 | - $curcscore=$charval; |
|
82 | - $curgtlang=$gtlang; |
|
81 | + $curcscore=$charval; |
|
82 | + $curgtlang=$gtlang; |
|
83 | 83 | } |
84 | - } |
|
85 | - return array($curlscore, $curcscore, $curgtlang); |
|
84 | + } |
|
85 | + return array($curlscore, $curcscore, $curgtlang); |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | function al2gt($gettextlangs, $mime) { |
89 | - /* default to "everything is acceptable", as RFC2616 specifies */ |
|
90 | - $acceptLang=(($_SERVER["HTTP_ACCEPT_LANGUAGE"] == '') ? '*' : |
|
89 | + /* default to "everything is acceptable", as RFC2616 specifies */ |
|
90 | + $acceptLang=(($_SERVER["HTTP_ACCEPT_LANGUAGE"] == '') ? '*' : |
|
91 | 91 | $_SERVER["HTTP_ACCEPT_LANGUAGE"]); |
92 | - $acceptChar=(($_SERVER["HTTP_ACCEPT_CHARSET"] == '') ? '*' : |
|
92 | + $acceptChar=(($_SERVER["HTTP_ACCEPT_CHARSET"] == '') ? '*' : |
|
93 | 93 | $_SERVER["HTTP_ACCEPT_CHARSET"]); |
94 | - $alparts=@preg_split("/,/",$acceptLang); |
|
95 | - $acparts=@preg_split("/,/",$acceptChar); |
|
94 | + $alparts=@preg_split("/,/",$acceptLang); |
|
95 | + $acparts=@preg_split("/,/",$acceptChar); |
|
96 | 96 | |
97 | - /* Parse the contents of the Accept-Language header.*/ |
|
98 | - foreach($alparts as $part) { |
|
97 | + /* Parse the contents of the Accept-Language header.*/ |
|
98 | + foreach($alparts as $part) { |
|
99 | 99 | $part=trim($part); |
100 | 100 | if(preg_match("/;/", $part)) { |
101 | - $lang=@preg_split("/;/",$part); |
|
102 | - $score=@preg_split("/=/",$lang[1]); |
|
103 | - $alscores[$lang[0]]=$score[1]; |
|
101 | + $lang=@preg_split("/;/",$part); |
|
102 | + $score=@preg_split("/=/",$lang[1]); |
|
103 | + $alscores[$lang[0]]=$score[1]; |
|
104 | 104 | } else { |
105 | - $alscores[$part]=1; |
|
105 | + $alscores[$part]=1; |
|
106 | + } |
|
106 | 107 | } |
107 | - } |
|
108 | 108 | |
109 | - /* Do the same for the Accept-Charset header. */ |
|
109 | + /* Do the same for the Accept-Charset header. */ |
|
110 | 110 | |
111 | - /* RFC2616: ``If no "*" is present in an Accept-Charset field, then |
|
111 | + /* RFC2616: ``If no "*" is present in an Accept-Charset field, then |
|
112 | 112 | * all character sets not explicitly mentioned get a quality value of |
113 | 113 | * 0, except for ISO-8859-1, which gets a quality value of 1 if not |
114 | 114 | * explicitly mentioned.'' |
@@ -116,31 +116,31 @@ discard block |
||
116 | 116 | * Making it 2 for the time being, so that we |
117 | 117 | * can distinguish between "not specified" and "specified as 1" later |
118 | 118 | * on. */ |
119 | - $acscores["ISO-8859-1"]=2; |
|
119 | + $acscores["ISO-8859-1"]=2; |
|
120 | 120 | |
121 | - foreach($acparts as $part) { |
|
121 | + foreach($acparts as $part) { |
|
122 | 122 | $part=trim($part); |
123 | 123 | if(preg_match("/;/", $part)) { |
124 | - $cs=@preg_split("/;/",$part); |
|
125 | - $score=@preg_split("/=/",$cs[1]); |
|
126 | - $acscores[strtoupper($cs[0])]=$score[1]; |
|
124 | + $cs=@preg_split("/;/",$part); |
|
125 | + $score=@preg_split("/=/",$cs[1]); |
|
126 | + $acscores[strtoupper($cs[0])]=$score[1]; |
|
127 | 127 | } else { |
128 | - $acscores[strtoupper($part)]=1; |
|
128 | + $acscores[strtoupper($part)]=1; |
|
129 | + } |
|
129 | 130 | } |
130 | - } |
|
131 | - if($acscores["ISO-8859-1"]==2) { |
|
131 | + if($acscores["ISO-8859-1"]==2) { |
|
132 | 132 | $acscores["ISO-8859-1"]=(isset($acscores["*"])?$acscores["*"]:1); |
133 | - } |
|
133 | + } |
|
134 | 134 | |
135 | - /* |
|
135 | + /* |
|
136 | 136 | * Loop through the available languages/encodings, and pick the one |
137 | 137 | * with the highest score, excluding the ones with a charset the user |
138 | 138 | * did not include. |
139 | 139 | */ |
140 | - $curlscore=0; |
|
141 | - $curcscore=0; |
|
142 | - $curgtlang=NULL; |
|
143 | - foreach($gettextlangs as $gtlang) { |
|
140 | + $curlscore=0; |
|
141 | + $curcscore=0; |
|
142 | + $curgtlang=NULL; |
|
143 | + foreach($gettextlangs as $gtlang) { |
|
144 | 144 | |
145 | 145 | $tmp1=preg_replace("/\_/","-",$gtlang); |
146 | 146 | $tmp2=@preg_split("/\./",$tmp1); |
@@ -149,38 +149,38 @@ discard block |
||
149 | 149 | $noct=@preg_split("/-/",$allang); |
150 | 150 | |
151 | 151 | $testvals=array( |
152 | - array(@$alscores[$allang], @$acscores[$gtcs]), |
|
153 | - array(@$alscores[$noct[0]], @$acscores[$gtcs]), |
|
154 | - array(@$alscores[$allang], @$acscores["*"]), |
|
155 | - array(@$alscores[$noct[0]], @$acscores["*"]), |
|
156 | - array(@$alscores["*"], @$acscores[$gtcs]), |
|
157 | - array(@$alscores["*"], @$acscores["*"])); |
|
152 | + array(@$alscores[$allang], @$acscores[$gtcs]), |
|
153 | + array(@$alscores[$noct[0]], @$acscores[$gtcs]), |
|
154 | + array(@$alscores[$allang], @$acscores["*"]), |
|
155 | + array(@$alscores[$noct[0]], @$acscores["*"]), |
|
156 | + array(@$alscores["*"], @$acscores[$gtcs]), |
|
157 | + array(@$alscores["*"], @$acscores["*"])); |
|
158 | 158 | |
159 | 159 | $found=FALSE; |
160 | 160 | foreach($testvals as $tval) { |
161 | - if(!$found && isset($tval[0]) && isset($tval[1])) { |
|
161 | + if(!$found && isset($tval[0]) && isset($tval[1])) { |
|
162 | 162 | $arr=find_match($curlscore, $curcscore, $curgtlang, $tval[0], |
163 | - $tval[1], $gtlang); |
|
163 | + $tval[1], $gtlang); |
|
164 | 164 | $curlscore=$arr[0]; |
165 | 165 | $curcscore=$arr[1]; |
166 | 166 | $curgtlang=$arr[2]; |
167 | 167 | $found=TRUE; |
168 | - } |
|
168 | + } |
|
169 | + } |
|
169 | 170 | } |
170 | - } |
|
171 | 171 | |
172 | - /* We must re-parse the gettext-string now, since we may have found it |
|
172 | + /* We must re-parse the gettext-string now, since we may have found it |
|
173 | 173 | * through a "*" qualifier.*/ |
174 | 174 | |
175 | - $gtparts=@preg_split("/\./",$curgtlang); |
|
176 | - $tmp=strtolower($gtparts[0]); |
|
177 | - $lang=preg_replace("/\_/", "-", $tmp); |
|
178 | - $charset=$gtparts[1]; |
|
175 | + $gtparts=@preg_split("/\./",$curgtlang); |
|
176 | + $tmp=strtolower($gtparts[0]); |
|
177 | + $lang=preg_replace("/\_/", "-", $tmp); |
|
178 | + $charset=$gtparts[1]; |
|
179 | 179 | |
180 | - header("Content-Language: $lang"); |
|
181 | - header("Content-Type: $mime; charset=$charset"); |
|
180 | + header("Content-Language: $lang"); |
|
181 | + header("Content-Type: $mime; charset=$charset"); |
|
182 | 182 | |
183 | - return $curgtlang; |
|
183 | + return $curgtlang; |
|
184 | 184 | } |
185 | 185 | |
186 | 186 | ?> |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | // LC_MESSAGES is not available if php-gettext is not loaded |
36 | 36 | // while the other constants are already available from session extension. |
37 | 37 | if (!defined('LC_MESSAGES')) { |
38 | - define('LC_MESSAGES', 5); |
|
38 | + define('LC_MESSAGES', 5); |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | require('streams.php'); |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | if (preg_match("/^(?P<lang>[a-z]{2,3})" // language code |
78 | 78 | ."(?:_(?P<country>[A-Z]{2}))?" // country code |
79 | 79 | ."(?:\.(?P<charset>[-A-Za-z0-9_]+))?" // charset |
80 | - ."(?:@(?P<modifier>[-A-Za-z0-9_]+))?$/", // @ modifier |
|
80 | + ."(?:@(?P<modifier>[-A-Za-z0-9_]+))?$/", // @ modifier |
|
81 | 81 | $locale, $matches)) { |
82 | 82 | |
83 | 83 | if (isset($matches["lang"])) $lang = $matches["lang"]; |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | /** |
114 | 114 | * Utility function to get a StreamReader for the given text domain. |
115 | 115 | */ |
116 | -function _get_reader($domain=null, $category=5, $enable_cache=true) { |
|
116 | +function _get_reader($domain = null, $category = 5, $enable_cache = true) { |
|
117 | 117 | global $text_domains, $default_domain, $LC_CATEGORIES; |
118 | 118 | if (!isset($domain)) $domain = $default_domain; |
119 | 119 | if (!isset($text_domains[$domain]->l10n)) { |
@@ -121,12 +121,12 @@ discard block |
||
121 | 121 | $locale = _setlocale(LC_MESSAGES, 0); |
122 | 122 | $bound_path = isset($text_domains[$domain]->path) ? |
123 | 123 | $text_domains[$domain]->path : './'; |
124 | - $subpath = $LC_CATEGORIES[$category] ."/$domain.mo"; |
|
124 | + $subpath = $LC_CATEGORIES[$category]."/$domain.mo"; |
|
125 | 125 | |
126 | 126 | $locale_names = get_list_of_locales($locale); |
127 | 127 | $input = null; |
128 | 128 | foreach ($locale_names as $locale) { |
129 | - $full_path = $bound_path . $locale . "/" . $subpath; |
|
129 | + $full_path = $bound_path.$locale."/".$subpath; |
|
130 | 130 | if (file_exists($full_path)) { |
131 | 131 | $input = new FileReader($full_path); |
132 | 132 | break; |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | /** |
155 | 155 | * Checks if the current locale is supported on this system. |
156 | 156 | */ |
157 | -function _check_locale_and_function($function=false) { |
|
157 | +function _check_locale_and_function($function = false) { |
|
158 | 158 | global $EMULATEGETTEXT; |
159 | 159 | if ($function and !function_exists($function)) |
160 | 160 | return false; |
@@ -164,10 +164,10 @@ discard block |
||
164 | 164 | /** |
165 | 165 | * Get the codeset for the given domain. |
166 | 166 | */ |
167 | -function _get_codeset($domain=null) { |
|
167 | +function _get_codeset($domain = null) { |
|
168 | 168 | global $text_domains, $default_domain, $LC_CATEGORIES; |
169 | 169 | if (!isset($domain)) $domain = $default_domain; |
170 | - return (isset($text_domains[$domain]->codeset))? $text_domains[$domain]->codeset : ini_get('mbstring.internal_encoding'); |
|
170 | + return (isset($text_domains[$domain]->codeset)) ? $text_domains[$domain]->codeset : ini_get('mbstring.internal_encoding'); |
|
171 | 171 | } |
172 | 172 | |
173 | 173 | /** |
@@ -241,10 +241,10 @@ discard block |
||
241 | 241 | global $text_domains; |
242 | 242 | // ensure $path ends with a slash ('/' should work for both, but lets still play nice) |
243 | 243 | if (substr(php_uname(), 0, 7) == "Windows") { |
244 | - if ($path[strlen($path)-1] != '\\' and $path[strlen($path)-1] != '/') |
|
244 | + if ($path[strlen($path) - 1] != '\\' and $path[strlen($path) - 1] != '/') |
|
245 | 245 | $path .= '\\'; |
246 | 246 | } else { |
247 | - if ($path[strlen($path)-1] != '/') |
|
247 | + if ($path[strlen($path) - 1] != '/') |
|
248 | 248 | $path .= '/'; |
249 | 249 | } |
250 | 250 | if (!array_key_exists($domain, $text_domains)) { |
@@ -69,10 +69,10 @@ |
||
69 | 69 | * sr_CS.UTF-8@latin, sr_CS@latin, sr@latin, sr_CS.UTF-8, sr_CS, sr. |
70 | 70 | */ |
71 | 71 | $locale_names = array(); |
72 | - $lang = NULL; |
|
73 | - $country = NULL; |
|
74 | - $charset = NULL; |
|
75 | - $modifier = NULL; |
|
72 | + $lang = null; |
|
73 | + $country = null; |
|
74 | + $charset = null; |
|
75 | + $modifier = null; |
|
76 | 76 | if ($locale) { |
77 | 77 | if (preg_match("/^(?P<lang>[a-z]{2,3})" // language code |
78 | 78 | ."(?:_(?P<country>[A-Z]{2}))?" // country code |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | // LC_MESSAGES is not available if php-gettext is not loaded |
36 | 36 | // while the other constants are already available from session extension. |
37 | 37 | if (!defined('LC_MESSAGES')) { |
38 | - define('LC_MESSAGES', 5); |
|
38 | + define('LC_MESSAGES', 5); |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | require('streams.php'); |
@@ -53,9 +53,9 @@ discard block |
||
53 | 53 | |
54 | 54 | /* Class to hold a single domain included in $text_domains. */ |
55 | 55 | class domain { |
56 | - var $l10n; |
|
57 | - var $path; |
|
58 | - var $codeset; |
|
56 | + var $l10n; |
|
57 | + var $path; |
|
58 | + var $codeset; |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | // Utility functions |
@@ -64,50 +64,50 @@ discard block |
||
64 | 64 | * Return a list of locales to try for any POSIX-style locale specification. |
65 | 65 | */ |
66 | 66 | function get_list_of_locales($locale) { |
67 | - /* Figure out all possible locale names and start with the most |
|
67 | + /* Figure out all possible locale names and start with the most |
|
68 | 68 | * specific ones. I.e. for sr_CS.UTF-8@latin, look through all of |
69 | 69 | * sr_CS.UTF-8@latin, sr_CS@latin, sr@latin, sr_CS.UTF-8, sr_CS, sr. |
70 | 70 | */ |
71 | - $locale_names = array(); |
|
72 | - $lang = NULL; |
|
73 | - $country = NULL; |
|
74 | - $charset = NULL; |
|
75 | - $modifier = NULL; |
|
76 | - if ($locale) { |
|
71 | + $locale_names = array(); |
|
72 | + $lang = NULL; |
|
73 | + $country = NULL; |
|
74 | + $charset = NULL; |
|
75 | + $modifier = NULL; |
|
76 | + if ($locale) { |
|
77 | 77 | if (preg_match("/^(?P<lang>[a-z]{2,3})" // language code |
78 | - ."(?:_(?P<country>[A-Z]{2}))?" // country code |
|
79 | - ."(?:\.(?P<charset>[-A-Za-z0-9_]+))?" // charset |
|
80 | - ."(?:@(?P<modifier>[-A-Za-z0-9_]+))?$/", // @ modifier |
|
81 | - $locale, $matches)) { |
|
78 | + ."(?:_(?P<country>[A-Z]{2}))?" // country code |
|
79 | + ."(?:\.(?P<charset>[-A-Za-z0-9_]+))?" // charset |
|
80 | + ."(?:@(?P<modifier>[-A-Za-z0-9_]+))?$/", // @ modifier |
|
81 | + $locale, $matches)) { |
|
82 | 82 | |
83 | - if (isset($matches["lang"])) $lang = $matches["lang"]; |
|
84 | - if (isset($matches["country"])) $country = $matches["country"]; |
|
85 | - if (isset($matches["charset"])) $charset = $matches["charset"]; |
|
86 | - if (isset($matches["modifier"])) $modifier = $matches["modifier"]; |
|
83 | + if (isset($matches["lang"])) $lang = $matches["lang"]; |
|
84 | + if (isset($matches["country"])) $country = $matches["country"]; |
|
85 | + if (isset($matches["charset"])) $charset = $matches["charset"]; |
|
86 | + if (isset($matches["modifier"])) $modifier = $matches["modifier"]; |
|
87 | 87 | |
88 | - if ($modifier) { |
|
88 | + if ($modifier) { |
|
89 | 89 | if ($country) { |
90 | - if ($charset) |
|
90 | + if ($charset) |
|
91 | 91 | array_push($locale_names, "${lang}_$country.$charset@$modifier"); |
92 | - array_push($locale_names, "${lang}_$country@$modifier"); |
|
92 | + array_push($locale_names, "${lang}_$country@$modifier"); |
|
93 | 93 | } elseif ($charset) |
94 | 94 | array_push($locale_names, "${lang}.$charset@$modifier"); |
95 | 95 | array_push($locale_names, "$lang@$modifier"); |
96 | - } |
|
97 | - if ($country) { |
|
96 | + } |
|
97 | + if ($country) { |
|
98 | 98 | if ($charset) |
99 | - array_push($locale_names, "${lang}_$country.$charset"); |
|
99 | + array_push($locale_names, "${lang}_$country.$charset"); |
|
100 | 100 | array_push($locale_names, "${lang}_$country"); |
101 | - } elseif ($charset) |
|
102 | - array_push($locale_names, "${lang}.$charset"); |
|
103 | - array_push($locale_names, $lang); |
|
101 | + } elseif ($charset) |
|
102 | + array_push($locale_names, "${lang}.$charset"); |
|
103 | + array_push($locale_names, $lang); |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | // If the locale name doesn't match POSIX style, just include it as-is. |
107 | 107 | if (!in_array($locale, $locale_names)) |
108 | - array_push($locale_names, $locale); |
|
109 | - } |
|
110 | - return $locale_names; |
|
108 | + array_push($locale_names, $locale); |
|
109 | + } |
|
110 | + return $locale_names; |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | /** |
@@ -126,19 +126,19 @@ discard block |
||
126 | 126 | $locale_names = get_list_of_locales($locale); |
127 | 127 | $input = null; |
128 | 128 | foreach ($locale_names as $locale) { |
129 | - $full_path = $bound_path . $locale . "/" . $subpath; |
|
130 | - if (file_exists($full_path)) { |
|
129 | + $full_path = $bound_path . $locale . "/" . $subpath; |
|
130 | + if (file_exists($full_path)) { |
|
131 | 131 | $input = new FileReader($full_path); |
132 | 132 | break; |
133 | - } |
|
133 | + } |
|
134 | 134 | } |
135 | 135 | |
136 | 136 | if (!array_key_exists($domain, $text_domains)) { |
137 | - // Initialize an empty domain object. |
|
138 | - $text_domains[$domain] = new domain(); |
|
137 | + // Initialize an empty domain object. |
|
138 | + $text_domains[$domain] = new domain(); |
|
139 | 139 | } |
140 | 140 | $text_domains[$domain]->l10n = new gettext_reader($input, |
141 | - $enable_cache); |
|
141 | + $enable_cache); |
|
142 | 142 | } |
143 | 143 | return $text_domains[$domain]->l10n; |
144 | 144 | } |
@@ -174,13 +174,13 @@ discard block |
||
174 | 174 | * Convert the given string to the encoding set by bind_textdomain_codeset. |
175 | 175 | */ |
176 | 176 | function _encode($text) { |
177 | - $target_encoding = _get_codeset(); |
|
178 | - if (function_exists("mb_detect_encoding")) { |
|
177 | + $target_encoding = _get_codeset(); |
|
178 | + if (function_exists("mb_detect_encoding")) { |
|
179 | 179 | $source_encoding = mb_detect_encoding($text); |
180 | 180 | if ($source_encoding != $target_encoding) |
181 | - $text = mb_convert_encoding($text, $target_encoding, $source_encoding); |
|
182 | - } |
|
183 | - return $text; |
|
181 | + $text = mb_convert_encoding($text, $target_encoding, $source_encoding); |
|
182 | + } |
|
183 | + return $text; |
|
184 | 184 | } |
185 | 185 | |
186 | 186 | |
@@ -190,9 +190,9 @@ discard block |
||
190 | 190 | * Returns passed in $locale, or environment variable $LANG if $locale == ''. |
191 | 191 | */ |
192 | 192 | function _get_default_locale($locale) { |
193 | - if ($locale == '') // emulate variable support |
|
193 | + if ($locale == '') // emulate variable support |
|
194 | 194 | return getenv('LANG'); |
195 | - else |
|
195 | + else |
|
196 | 196 | return $locale; |
197 | 197 | } |
198 | 198 | |
@@ -210,20 +210,20 @@ discard block |
||
210 | 210 | return _setlocale($category, $CURRENTLOCALE); |
211 | 211 | } else { |
212 | 212 | if (function_exists('setlocale')) { |
213 | - $ret = setlocale($category, $locale); |
|
214 | - if (($locale == '' and !$ret) or // failed setting it by env |
|
213 | + $ret = setlocale($category, $locale); |
|
214 | + if (($locale == '' and !$ret) or // failed setting it by env |
|
215 | 215 | ($locale != '' and $ret != $locale)) { // failed setting it |
216 | 216 | // Failed setting it according to environment. |
217 | 217 | $CURRENTLOCALE = _get_default_locale($locale); |
218 | 218 | $EMULATEGETTEXT = 1; |
219 | - } else { |
|
219 | + } else { |
|
220 | 220 | $CURRENTLOCALE = $ret; |
221 | 221 | $EMULATEGETTEXT = 0; |
222 | - } |
|
222 | + } |
|
223 | 223 | } else { |
224 | - // No function setlocale(), emulate it all. |
|
225 | - $CURRENTLOCALE = _get_default_locale($locale); |
|
226 | - $EMULATEGETTEXT = 1; |
|
224 | + // No function setlocale(), emulate it all. |
|
225 | + $CURRENTLOCALE = _get_default_locale($locale); |
|
226 | + $EMULATEGETTEXT = 1; |
|
227 | 227 | } |
228 | 228 | // Allow locale to be changed on the go for one translation domain. |
229 | 229 | global $text_domains, $default_domain; |
@@ -241,15 +241,15 @@ discard block |
||
241 | 241 | global $text_domains; |
242 | 242 | // ensure $path ends with a slash ('/' should work for both, but lets still play nice) |
243 | 243 | if (substr(php_uname(), 0, 7) == "Windows") { |
244 | - if ($path[strlen($path)-1] != '\\' and $path[strlen($path)-1] != '/') |
|
244 | + if ($path[strlen($path)-1] != '\\' and $path[strlen($path)-1] != '/') |
|
245 | 245 | $path .= '\\'; |
246 | 246 | } else { |
247 | - if ($path[strlen($path)-1] != '/') |
|
247 | + if ($path[strlen($path)-1] != '/') |
|
248 | 248 | $path .= '/'; |
249 | 249 | } |
250 | 250 | if (!array_key_exists($domain, $text_domains)) { |
251 | - // Initialize an empty domain object. |
|
252 | - $text_domains[$domain] = new domain(); |
|
251 | + // Initialize an empty domain object. |
|
252 | + $text_domains[$domain] = new domain(); |
|
253 | 253 | } |
254 | 254 | $text_domains[$domain]->path = $path; |
255 | 255 | } |
@@ -426,29 +426,29 @@ discard block |
||
426 | 426 | } |
427 | 427 | function T_dcngettext($domain, $singular, $plural, $number, $category) { |
428 | 428 | if (_check_locale_and_function()) |
429 | - return dcngettext($domain, $singular, $plural, $number, $category); |
|
429 | + return dcngettext($domain, $singular, $plural, $number, $category); |
|
430 | 430 | else return _dcngettext($domain, $singular, $plural, $number, $category); |
431 | 431 | } |
432 | 432 | |
433 | 433 | function T_pgettext($context, $msgid) { |
434 | - if (_check_locale_and_function('pgettext')) |
|
435 | - return pgettext($context, $msgid); |
|
436 | - else |
|
437 | - return _pgettext($context, $msgid); |
|
434 | + if (_check_locale_and_function('pgettext')) |
|
435 | + return pgettext($context, $msgid); |
|
436 | + else |
|
437 | + return _pgettext($context, $msgid); |
|
438 | 438 | } |
439 | 439 | |
440 | 440 | function T_dpgettext($domain, $context, $msgid) { |
441 | - if (_check_locale_and_function('dpgettext')) |
|
442 | - return dpgettext($domain, $context, $msgid); |
|
443 | - else |
|
444 | - return _dpgettext($domain, $context, $msgid); |
|
441 | + if (_check_locale_and_function('dpgettext')) |
|
442 | + return dpgettext($domain, $context, $msgid); |
|
443 | + else |
|
444 | + return _dpgettext($domain, $context, $msgid); |
|
445 | 445 | } |
446 | 446 | |
447 | 447 | function T_dcpgettext($domain, $context, $msgid, $category) { |
448 | - if (_check_locale_and_function('dcpgettext')) |
|
449 | - return dcpgettext($domain, $context, $msgid, $category); |
|
450 | - else |
|
451 | - return _dcpgettext($domain, $context, $msgid, $category); |
|
448 | + if (_check_locale_and_function('dcpgettext')) |
|
449 | + return dcpgettext($domain, $context, $msgid, $category); |
|
450 | + else |
|
451 | + return _dcpgettext($domain, $context, $msgid, $category); |
|
452 | 452 | } |
453 | 453 | |
454 | 454 | function T_npgettext($context, $singular, $plural, $number) { |
@@ -459,17 +459,17 @@ discard block |
||
459 | 459 | } |
460 | 460 | |
461 | 461 | function T_dnpgettext($domain, $context, $singular, $plural, $number) { |
462 | - if (_check_locale_and_function('dnpgettext')) |
|
463 | - return dnpgettext($domain, $context, $singular, $plural, $number); |
|
464 | - else |
|
465 | - return _dnpgettext($domain, $context, $singular, $plural, $number); |
|
462 | + if (_check_locale_and_function('dnpgettext')) |
|
463 | + return dnpgettext($domain, $context, $singular, $plural, $number); |
|
464 | + else |
|
465 | + return _dnpgettext($domain, $context, $singular, $plural, $number); |
|
466 | 466 | } |
467 | 467 | |
468 | 468 | function T_dcnpgettext($domain, $context, $singular, $plural, |
469 | - $number, $category) { |
|
469 | + $number, $category) { |
|
470 | 470 | if (_check_locale_and_function('dcnpgettext')) |
471 | 471 | return dcnpgettext($domain, $context, $singular, |
472 | - $plural, $number, $category); |
|
472 | + $plural, $number, $category); |
|
473 | 473 | else |
474 | 474 | return _dcnpgettext($domain, $context, $singular, |
475 | 475 | $plural, $number, $category); |
@@ -526,9 +526,9 @@ discard block |
||
526 | 526 | return _dcpgettext($domain, $context, $msgid, $category); |
527 | 527 | } |
528 | 528 | function dcnpgettext($domain, $context, $singular, $plural, |
529 | - $number, $category) { |
|
530 | - return _dcnpgettext($domain, $context, $singular, $plural, |
|
531 | - $number, $category); |
|
529 | + $number, $category) { |
|
530 | + return _dcnpgettext($domain, $context, $singular, $plural, |
|
531 | + $number, $category); |
|
532 | 532 | } |
533 | 533 | } |
534 | 534 |
@@ -80,32 +80,45 @@ discard block |
||
80 | 80 | ."(?:@(?P<modifier>[-A-Za-z0-9_]+))?$/", // @ modifier |
81 | 81 | $locale, $matches)) { |
82 | 82 | |
83 | - if (isset($matches["lang"])) $lang = $matches["lang"]; |
|
84 | - if (isset($matches["country"])) $country = $matches["country"]; |
|
85 | - if (isset($matches["charset"])) $charset = $matches["charset"]; |
|
86 | - if (isset($matches["modifier"])) $modifier = $matches["modifier"]; |
|
83 | + if (isset($matches["lang"])) { |
|
84 | + $lang = $matches["lang"]; |
|
85 | + } |
|
86 | + if (isset($matches["country"])) { |
|
87 | + $country = $matches["country"]; |
|
88 | + } |
|
89 | + if (isset($matches["charset"])) { |
|
90 | + $charset = $matches["charset"]; |
|
91 | + } |
|
92 | + if (isset($matches["modifier"])) { |
|
93 | + $modifier = $matches["modifier"]; |
|
94 | + } |
|
87 | 95 | |
88 | 96 | if ($modifier) { |
89 | 97 | if ($country) { |
90 | - if ($charset) |
|
91 | - array_push($locale_names, "${lang}_$country.$charset@$modifier"); |
|
98 | + if ($charset) { |
|
99 | + array_push($locale_names, "${lang}_$country.$charset@$modifier"); |
|
100 | + } |
|
92 | 101 | array_push($locale_names, "${lang}_$country@$modifier"); |
93 | - } elseif ($charset) |
|
94 | - array_push($locale_names, "${lang}.$charset@$modifier"); |
|
102 | + } elseif ($charset) { |
|
103 | + array_push($locale_names, "${lang}.$charset@$modifier"); |
|
104 | + } |
|
95 | 105 | array_push($locale_names, "$lang@$modifier"); |
96 | 106 | } |
97 | 107 | if ($country) { |
98 | - if ($charset) |
|
99 | - array_push($locale_names, "${lang}_$country.$charset"); |
|
108 | + if ($charset) { |
|
109 | + array_push($locale_names, "${lang}_$country.$charset"); |
|
110 | + } |
|
100 | 111 | array_push($locale_names, "${lang}_$country"); |
101 | - } elseif ($charset) |
|
102 | - array_push($locale_names, "${lang}.$charset"); |
|
112 | + } elseif ($charset) { |
|
113 | + array_push($locale_names, "${lang}.$charset"); |
|
114 | + } |
|
103 | 115 | array_push($locale_names, $lang); |
104 | 116 | } |
105 | 117 | |
106 | 118 | // If the locale name doesn't match POSIX style, just include it as-is. |
107 | - if (!in_array($locale, $locale_names)) |
|
108 | - array_push($locale_names, $locale); |
|
119 | + if (!in_array($locale, $locale_names)) { |
|
120 | + array_push($locale_names, $locale); |
|
121 | + } |
|
109 | 122 | } |
110 | 123 | return $locale_names; |
111 | 124 | } |
@@ -115,7 +128,9 @@ discard block |
||
115 | 128 | */ |
116 | 129 | function _get_reader($domain=null, $category=5, $enable_cache=true) { |
117 | 130 | global $text_domains, $default_domain, $LC_CATEGORIES; |
118 | - if (!isset($domain)) $domain = $default_domain; |
|
131 | + if (!isset($domain)) { |
|
132 | + $domain = $default_domain; |
|
133 | + } |
|
119 | 134 | if (!isset($text_domains[$domain]->l10n)) { |
120 | 135 | // get the current locale |
121 | 136 | $locale = _setlocale(LC_MESSAGES, 0); |
@@ -156,8 +171,9 @@ discard block |
||
156 | 171 | */ |
157 | 172 | function _check_locale_and_function($function=false) { |
158 | 173 | global $EMULATEGETTEXT; |
159 | - if ($function and !function_exists($function)) |
|
160 | - return false; |
|
174 | + if ($function and !function_exists($function)) { |
|
175 | + return false; |
|
176 | + } |
|
161 | 177 | return !$EMULATEGETTEXT; |
162 | 178 | } |
163 | 179 | |
@@ -166,7 +182,9 @@ discard block |
||
166 | 182 | */ |
167 | 183 | function _get_codeset($domain=null) { |
168 | 184 | global $text_domains, $default_domain, $LC_CATEGORIES; |
169 | - if (!isset($domain)) $domain = $default_domain; |
|
185 | + if (!isset($domain)) { |
|
186 | + $domain = $default_domain; |
|
187 | + } |
|
170 | 188 | return (isset($text_domains[$domain]->codeset))? $text_domains[$domain]->codeset : ini_get('mbstring.internal_encoding'); |
171 | 189 | } |
172 | 190 | |
@@ -177,8 +195,9 @@ discard block |
||
177 | 195 | $target_encoding = _get_codeset(); |
178 | 196 | if (function_exists("mb_detect_encoding")) { |
179 | 197 | $source_encoding = mb_detect_encoding($text); |
180 | - if ($source_encoding != $target_encoding) |
|
181 | - $text = mb_convert_encoding($text, $target_encoding, $source_encoding); |
|
198 | + if ($source_encoding != $target_encoding) { |
|
199 | + $text = mb_convert_encoding($text, $target_encoding, $source_encoding); |
|
200 | + } |
|
182 | 201 | } |
183 | 202 | return $text; |
184 | 203 | } |
@@ -190,11 +209,13 @@ discard block |
||
190 | 209 | * Returns passed in $locale, or environment variable $LANG if $locale == ''. |
191 | 210 | */ |
192 | 211 | function _get_default_locale($locale) { |
193 | - if ($locale == '') // emulate variable support |
|
212 | + if ($locale == '') { |
|
213 | + // emulate variable support |
|
194 | 214 | return getenv('LANG'); |
195 | - else |
|
196 | - return $locale; |
|
197 | -} |
|
215 | + } else { |
|
216 | + return $locale; |
|
217 | + } |
|
218 | + } |
|
198 | 219 | |
199 | 220 | /** |
200 | 221 | * Sets a requested locale, if needed emulates it. |
@@ -202,12 +223,13 @@ discard block |
||
202 | 223 | function _setlocale($category, $locale) { |
203 | 224 | global $CURRENTLOCALE, $EMULATEGETTEXT; |
204 | 225 | if ($locale === 0) { // use === to differentiate between string "0" |
205 | - if ($CURRENTLOCALE != '') |
|
206 | - return $CURRENTLOCALE; |
|
207 | - else |
|
208 | - // obey LANG variable, maybe extend to support all of LC_* vars |
|
226 | + if ($CURRENTLOCALE != '') { |
|
227 | + return $CURRENTLOCALE; |
|
228 | + } else { |
|
229 | + // obey LANG variable, maybe extend to support all of LC_* vars |
|
209 | 230 | // even if we tried to read locale without setting it first |
210 | 231 | return _setlocale($category, $CURRENTLOCALE); |
232 | + } |
|
211 | 233 | } else { |
212 | 234 | if (function_exists('setlocale')) { |
213 | 235 | $ret = setlocale($category, $locale); |
@@ -241,11 +263,13 @@ discard block |
||
241 | 263 | global $text_domains; |
242 | 264 | // ensure $path ends with a slash ('/' should work for both, but lets still play nice) |
243 | 265 | if (substr(php_uname(), 0, 7) == "Windows") { |
244 | - if ($path[strlen($path)-1] != '\\' and $path[strlen($path)-1] != '/') |
|
245 | - $path .= '\\'; |
|
266 | + if ($path[strlen($path)-1] != '\\' and $path[strlen($path)-1] != '/') { |
|
267 | + $path .= '\\'; |
|
268 | + } |
|
246 | 269 | } else { |
247 | - if ($path[strlen($path)-1] != '/') |
|
248 | - $path .= '/'; |
|
270 | + if ($path[strlen($path)-1] != '/') { |
|
271 | + $path .= '/'; |
|
272 | + } |
|
249 | 273 | } |
250 | 274 | if (!array_key_exists($domain, $text_domains)) { |
251 | 275 | // Initialize an empty domain object. |
@@ -384,96 +408,126 @@ discard block |
||
384 | 408 | } |
385 | 409 | |
386 | 410 | function T_bindtextdomain($domain, $path) { |
387 | - if (_check_locale_and_function()) return bindtextdomain($domain, $path); |
|
388 | - else return _bindtextdomain($domain, $path); |
|
389 | -} |
|
411 | + if (_check_locale_and_function()) { |
|
412 | + return bindtextdomain($domain, $path); |
|
413 | + } else { |
|
414 | + return _bindtextdomain($domain, $path); |
|
415 | + } |
|
416 | + } |
|
390 | 417 | function T_bind_textdomain_codeset($domain, $codeset) { |
391 | 418 | // bind_textdomain_codeset is available only in PHP 4.2.0+ |
392 | - if (_check_locale_and_function('bind_textdomain_codeset')) |
|
393 | - return bind_textdomain_codeset($domain, $codeset); |
|
394 | - else return _bind_textdomain_codeset($domain, $codeset); |
|
395 | -} |
|
419 | + if (_check_locale_and_function('bind_textdomain_codeset')) { |
|
420 | + return bind_textdomain_codeset($domain, $codeset); |
|
421 | + } else { |
|
422 | + return _bind_textdomain_codeset($domain, $codeset); |
|
423 | + } |
|
424 | + } |
|
396 | 425 | function T_textdomain($domain) { |
397 | - if (_check_locale_and_function()) return textdomain($domain); |
|
398 | - else return _textdomain($domain); |
|
399 | -} |
|
426 | + if (_check_locale_and_function()) { |
|
427 | + return textdomain($domain); |
|
428 | + } else { |
|
429 | + return _textdomain($domain); |
|
430 | + } |
|
431 | + } |
|
400 | 432 | function T_gettext($msgid) { |
401 | - if (_check_locale_and_function()) return gettext($msgid); |
|
402 | - else return _gettext($msgid); |
|
403 | -} |
|
433 | + if (_check_locale_and_function()) { |
|
434 | + return gettext($msgid); |
|
435 | + } else { |
|
436 | + return _gettext($msgid); |
|
437 | + } |
|
438 | + } |
|
404 | 439 | function T_($msgid) { |
405 | - if (_check_locale_and_function()) return _($msgid); |
|
440 | + if (_check_locale_and_function()) { |
|
441 | + return _($msgid); |
|
442 | + } |
|
406 | 443 | return __($msgid); |
407 | 444 | } |
408 | 445 | function T_ngettext($singular, $plural, $number) { |
409 | - if (_check_locale_and_function()) |
|
410 | - return ngettext($singular, $plural, $number); |
|
411 | - else return _ngettext($singular, $plural, $number); |
|
412 | -} |
|
446 | + if (_check_locale_and_function()) { |
|
447 | + return ngettext($singular, $plural, $number); |
|
448 | + } else { |
|
449 | + return _ngettext($singular, $plural, $number); |
|
450 | + } |
|
451 | + } |
|
413 | 452 | function T_dgettext($domain, $msgid) { |
414 | - if (_check_locale_and_function()) return dgettext($domain, $msgid); |
|
415 | - else return _dgettext($domain, $msgid); |
|
416 | -} |
|
453 | + if (_check_locale_and_function()) { |
|
454 | + return dgettext($domain, $msgid); |
|
455 | + } else { |
|
456 | + return _dgettext($domain, $msgid); |
|
457 | + } |
|
458 | + } |
|
417 | 459 | function T_dngettext($domain, $singular, $plural, $number) { |
418 | - if (_check_locale_and_function()) |
|
419 | - return dngettext($domain, $singular, $plural, $number); |
|
420 | - else return _dngettext($domain, $singular, $plural, $number); |
|
421 | -} |
|
460 | + if (_check_locale_and_function()) { |
|
461 | + return dngettext($domain, $singular, $plural, $number); |
|
462 | + } else { |
|
463 | + return _dngettext($domain, $singular, $plural, $number); |
|
464 | + } |
|
465 | + } |
|
422 | 466 | function T_dcgettext($domain, $msgid, $category) { |
423 | - if (_check_locale_and_function()) |
|
424 | - return dcgettext($domain, $msgid, $category); |
|
425 | - else return _dcgettext($domain, $msgid, $category); |
|
426 | -} |
|
467 | + if (_check_locale_and_function()) { |
|
468 | + return dcgettext($domain, $msgid, $category); |
|
469 | + } else { |
|
470 | + return _dcgettext($domain, $msgid, $category); |
|
471 | + } |
|
472 | + } |
|
427 | 473 | function T_dcngettext($domain, $singular, $plural, $number, $category) { |
428 | - if (_check_locale_and_function()) |
|
429 | - return dcngettext($domain, $singular, $plural, $number, $category); |
|
430 | - else return _dcngettext($domain, $singular, $plural, $number, $category); |
|
431 | -} |
|
474 | + if (_check_locale_and_function()) { |
|
475 | + return dcngettext($domain, $singular, $plural, $number, $category); |
|
476 | + } else { |
|
477 | + return _dcngettext($domain, $singular, $plural, $number, $category); |
|
478 | + } |
|
479 | + } |
|
432 | 480 | |
433 | 481 | function T_pgettext($context, $msgid) { |
434 | - if (_check_locale_and_function('pgettext')) |
|
435 | - return pgettext($context, $msgid); |
|
436 | - else |
|
437 | - return _pgettext($context, $msgid); |
|
438 | -} |
|
482 | + if (_check_locale_and_function('pgettext')) { |
|
483 | + return pgettext($context, $msgid); |
|
484 | + } else { |
|
485 | + return _pgettext($context, $msgid); |
|
486 | + } |
|
487 | + } |
|
439 | 488 | |
440 | 489 | function T_dpgettext($domain, $context, $msgid) { |
441 | - if (_check_locale_and_function('dpgettext')) |
|
442 | - return dpgettext($domain, $context, $msgid); |
|
443 | - else |
|
444 | - return _dpgettext($domain, $context, $msgid); |
|
445 | -} |
|
490 | + if (_check_locale_and_function('dpgettext')) { |
|
491 | + return dpgettext($domain, $context, $msgid); |
|
492 | + } else { |
|
493 | + return _dpgettext($domain, $context, $msgid); |
|
494 | + } |
|
495 | + } |
|
446 | 496 | |
447 | 497 | function T_dcpgettext($domain, $context, $msgid, $category) { |
448 | - if (_check_locale_and_function('dcpgettext')) |
|
449 | - return dcpgettext($domain, $context, $msgid, $category); |
|
450 | - else |
|
451 | - return _dcpgettext($domain, $context, $msgid, $category); |
|
452 | -} |
|
498 | + if (_check_locale_and_function('dcpgettext')) { |
|
499 | + return dcpgettext($domain, $context, $msgid, $category); |
|
500 | + } else { |
|
501 | + return _dcpgettext($domain, $context, $msgid, $category); |
|
502 | + } |
|
503 | + } |
|
453 | 504 | |
454 | 505 | function T_npgettext($context, $singular, $plural, $number) { |
455 | - if (_check_locale_and_function('npgettext')) |
|
456 | - return npgettext($context, $singular, $plural, $number); |
|
457 | - else |
|
458 | - return _npgettext($context, $singular, $plural, $number); |
|
459 | -} |
|
506 | + if (_check_locale_and_function('npgettext')) { |
|
507 | + return npgettext($context, $singular, $plural, $number); |
|
508 | + } else { |
|
509 | + return _npgettext($context, $singular, $plural, $number); |
|
510 | + } |
|
511 | + } |
|
460 | 512 | |
461 | 513 | function T_dnpgettext($domain, $context, $singular, $plural, $number) { |
462 | - if (_check_locale_and_function('dnpgettext')) |
|
463 | - return dnpgettext($domain, $context, $singular, $plural, $number); |
|
464 | - else |
|
465 | - return _dnpgettext($domain, $context, $singular, $plural, $number); |
|
466 | -} |
|
514 | + if (_check_locale_and_function('dnpgettext')) { |
|
515 | + return dnpgettext($domain, $context, $singular, $plural, $number); |
|
516 | + } else { |
|
517 | + return _dnpgettext($domain, $context, $singular, $plural, $number); |
|
518 | + } |
|
519 | + } |
|
467 | 520 | |
468 | 521 | function T_dcnpgettext($domain, $context, $singular, $plural, |
469 | 522 | $number, $category) { |
470 | - if (_check_locale_and_function('dcnpgettext')) |
|
471 | - return dcnpgettext($domain, $context, $singular, |
|
523 | + if (_check_locale_and_function('dcnpgettext')) { |
|
524 | + return dcnpgettext($domain, $context, $singular, |
|
472 | 525 | $plural, $number, $category); |
473 | - else |
|
474 | - return _dcnpgettext($domain, $context, $singular, |
|
526 | + } else { |
|
527 | + return _dcnpgettext($domain, $context, $singular, |
|
475 | 528 | $plural, $number, $category); |
476 | -} |
|
529 | + } |
|
530 | + } |
|
477 | 531 | |
478 | 532 | |
479 | 533 |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | var $_pos; |
50 | 50 | var $_str; |
51 | 51 | |
52 | - function StringReader($str='') { |
|
52 | + function StringReader($str = '') { |
|
53 | 53 | $this->_str = $str; |
54 | 54 | $this->_pos = 0; |
55 | 55 | } |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | function read($bytes) { |
58 | 58 | $data = substr($this->_str, $this->_pos, $bytes); |
59 | 59 | $this->_pos += $bytes; |
60 | - if (strlen($this->_str)<$this->_pos) |
|
60 | + if (strlen($this->_str) < $this->_pos) |
|
61 | 61 | $this->_pos = strlen($this->_str); |
62 | 62 | |
63 | 63 | return $data; |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | |
66 | 66 | function seekto($pos) { |
67 | 67 | $this->_pos = $pos; |
68 | - if (strlen($this->_str)<$this->_pos) |
|
68 | + if (strlen($this->_str) < $this->_pos) |
|
69 | 69 | $this->_pos = strlen($this->_str); |
70 | 70 | return $this->_pos; |
71 | 71 | } |
@@ -89,9 +89,9 @@ discard block |
||
89 | 89 | function FileReader($filename) { |
90 | 90 | if (file_exists($filename)) { |
91 | 91 | |
92 | - $this->_length=filesize($filename); |
|
92 | + $this->_length = filesize($filename); |
|
93 | 93 | $this->_pos = 0; |
94 | - $this->_fd = fopen($filename,'rb'); |
|
94 | + $this->_fd = fopen($filename, 'rb'); |
|
95 | 95 | if (!$this->_fd) { |
96 | 96 | $this->error = 3; // Cannot read file, probably permissions |
97 | 97 | return false; |
@@ -146,8 +146,8 @@ discard block |
||
146 | 146 | function CachedFileReader($filename) { |
147 | 147 | if (file_exists($filename)) { |
148 | 148 | |
149 | - $length=filesize($filename); |
|
150 | - $fd = fopen($filename,'rb'); |
|
149 | + $length = filesize($filename); |
|
150 | + $fd = fopen($filename, 'rb'); |
|
151 | 151 | |
152 | 152 | if (!$fd) { |
153 | 153 | $this->error = 3; // Cannot read file, probably permissions |
@@ -21,146 +21,146 @@ |
||
21 | 21 | */ |
22 | 22 | |
23 | 23 | |
24 | - // Simple class to wrap file streams, string streams, etc. |
|
25 | - // seek is essential, and it should be byte stream |
|
24 | + // Simple class to wrap file streams, string streams, etc. |
|
25 | + // seek is essential, and it should be byte stream |
|
26 | 26 | class StreamReader { |
27 | - // should return a string [FIXME: perhaps return array of bytes?] |
|
28 | - function read($bytes) { |
|
27 | + // should return a string [FIXME: perhaps return array of bytes?] |
|
28 | + function read($bytes) { |
|
29 | 29 | return false; |
30 | - } |
|
30 | + } |
|
31 | 31 | |
32 | - // should return new position |
|
33 | - function seekto($position) { |
|
32 | + // should return new position |
|
33 | + function seekto($position) { |
|
34 | 34 | return false; |
35 | - } |
|
35 | + } |
|
36 | 36 | |
37 | - // returns current position |
|
38 | - function currentpos() { |
|
37 | + // returns current position |
|
38 | + function currentpos() { |
|
39 | 39 | return false; |
40 | - } |
|
40 | + } |
|
41 | 41 | |
42 | - // returns length of entire stream (limit for seekto()s) |
|
43 | - function length() { |
|
42 | + // returns length of entire stream (limit for seekto()s) |
|
43 | + function length() { |
|
44 | 44 | return false; |
45 | - } |
|
45 | + } |
|
46 | 46 | }; |
47 | 47 | |
48 | 48 | class StringReader { |
49 | - var $_pos; |
|
50 | - var $_str; |
|
49 | + var $_pos; |
|
50 | + var $_str; |
|
51 | 51 | |
52 | - function StringReader($str='') { |
|
52 | + function StringReader($str='') { |
|
53 | 53 | $this->_str = $str; |
54 | 54 | $this->_pos = 0; |
55 | - } |
|
55 | + } |
|
56 | 56 | |
57 | - function read($bytes) { |
|
57 | + function read($bytes) { |
|
58 | 58 | $data = substr($this->_str, $this->_pos, $bytes); |
59 | 59 | $this->_pos += $bytes; |
60 | 60 | if (strlen($this->_str)<$this->_pos) |
61 | - $this->_pos = strlen($this->_str); |
|
61 | + $this->_pos = strlen($this->_str); |
|
62 | 62 | |
63 | 63 | return $data; |
64 | - } |
|
64 | + } |
|
65 | 65 | |
66 | - function seekto($pos) { |
|
66 | + function seekto($pos) { |
|
67 | 67 | $this->_pos = $pos; |
68 | 68 | if (strlen($this->_str)<$this->_pos) |
69 | - $this->_pos = strlen($this->_str); |
|
69 | + $this->_pos = strlen($this->_str); |
|
70 | 70 | return $this->_pos; |
71 | - } |
|
71 | + } |
|
72 | 72 | |
73 | - function currentpos() { |
|
73 | + function currentpos() { |
|
74 | 74 | return $this->_pos; |
75 | - } |
|
75 | + } |
|
76 | 76 | |
77 | - function length() { |
|
77 | + function length() { |
|
78 | 78 | return strlen($this->_str); |
79 | - } |
|
79 | + } |
|
80 | 80 | |
81 | 81 | }; |
82 | 82 | |
83 | 83 | |
84 | 84 | class FileReader { |
85 | - var $_pos; |
|
86 | - var $_fd; |
|
87 | - var $_length; |
|
85 | + var $_pos; |
|
86 | + var $_fd; |
|
87 | + var $_length; |
|
88 | 88 | |
89 | - function FileReader($filename) { |
|
89 | + function FileReader($filename) { |
|
90 | 90 | if (file_exists($filename)) { |
91 | 91 | |
92 | - $this->_length=filesize($filename); |
|
93 | - $this->_pos = 0; |
|
94 | - $this->_fd = fopen($filename,'rb'); |
|
95 | - if (!$this->_fd) { |
|
92 | + $this->_length=filesize($filename); |
|
93 | + $this->_pos = 0; |
|
94 | + $this->_fd = fopen($filename,'rb'); |
|
95 | + if (!$this->_fd) { |
|
96 | 96 | $this->error = 3; // Cannot read file, probably permissions |
97 | 97 | return false; |
98 | - } |
|
98 | + } |
|
99 | 99 | } else { |
100 | - $this->error = 2; // File doesn't exist |
|
101 | - return false; |
|
100 | + $this->error = 2; // File doesn't exist |
|
101 | + return false; |
|
102 | + } |
|
102 | 103 | } |
103 | - } |
|
104 | 104 | |
105 | - function read($bytes) { |
|
105 | + function read($bytes) { |
|
106 | 106 | if ($bytes) { |
107 | - fseek($this->_fd, $this->_pos); |
|
107 | + fseek($this->_fd, $this->_pos); |
|
108 | 108 | |
109 | - // PHP 5.1.1 does not read more than 8192 bytes in one fread() |
|
110 | - // the discussions at PHP Bugs suggest it's the intended behaviour |
|
111 | - $data = ''; |
|
112 | - while ($bytes > 0) { |
|
109 | + // PHP 5.1.1 does not read more than 8192 bytes in one fread() |
|
110 | + // the discussions at PHP Bugs suggest it's the intended behaviour |
|
111 | + $data = ''; |
|
112 | + while ($bytes > 0) { |
|
113 | 113 | $chunk = fread($this->_fd, $bytes); |
114 | 114 | $data .= $chunk; |
115 | 115 | $bytes -= strlen($chunk); |
116 | - } |
|
117 | - $this->_pos = ftell($this->_fd); |
|
116 | + } |
|
117 | + $this->_pos = ftell($this->_fd); |
|
118 | 118 | |
119 | - return $data; |
|
119 | + return $data; |
|
120 | 120 | } else return ''; |
121 | - } |
|
121 | + } |
|
122 | 122 | |
123 | - function seekto($pos) { |
|
123 | + function seekto($pos) { |
|
124 | 124 | fseek($this->_fd, $pos); |
125 | 125 | $this->_pos = ftell($this->_fd); |
126 | 126 | return $this->_pos; |
127 | - } |
|
127 | + } |
|
128 | 128 | |
129 | - function currentpos() { |
|
129 | + function currentpos() { |
|
130 | 130 | return $this->_pos; |
131 | - } |
|
131 | + } |
|
132 | 132 | |
133 | - function length() { |
|
133 | + function length() { |
|
134 | 134 | return $this->_length; |
135 | - } |
|
135 | + } |
|
136 | 136 | |
137 | - function close() { |
|
137 | + function close() { |
|
138 | 138 | fclose($this->_fd); |
139 | - } |
|
139 | + } |
|
140 | 140 | |
141 | 141 | }; |
142 | 142 | |
143 | 143 | // Preloads entire file in memory first, then creates a StringReader |
144 | 144 | // over it (it assumes knowledge of StringReader internals) |
145 | 145 | class CachedFileReader extends StringReader { |
146 | - function CachedFileReader($filename) { |
|
146 | + function CachedFileReader($filename) { |
|
147 | 147 | if (file_exists($filename)) { |
148 | 148 | |
149 | - $length=filesize($filename); |
|
150 | - $fd = fopen($filename,'rb'); |
|
149 | + $length=filesize($filename); |
|
150 | + $fd = fopen($filename,'rb'); |
|
151 | 151 | |
152 | - if (!$fd) { |
|
152 | + if (!$fd) { |
|
153 | 153 | $this->error = 3; // Cannot read file, probably permissions |
154 | 154 | return false; |
155 | - } |
|
156 | - $this->_str = fread($fd, $length); |
|
157 | - fclose($fd); |
|
155 | + } |
|
156 | + $this->_str = fread($fd, $length); |
|
157 | + fclose($fd); |
|
158 | 158 | |
159 | 159 | } else { |
160 | - $this->error = 2; // File doesn't exist |
|
161 | - return false; |
|
160 | + $this->error = 2; // File doesn't exist |
|
161 | + return false; |
|
162 | + } |
|
162 | 163 | } |
163 | - } |
|
164 | 164 | }; |
165 | 165 | |
166 | 166 |
@@ -57,16 +57,18 @@ discard block |
||
57 | 57 | function read($bytes) { |
58 | 58 | $data = substr($this->_str, $this->_pos, $bytes); |
59 | 59 | $this->_pos += $bytes; |
60 | - if (strlen($this->_str)<$this->_pos) |
|
61 | - $this->_pos = strlen($this->_str); |
|
60 | + if (strlen($this->_str)<$this->_pos) { |
|
61 | + $this->_pos = strlen($this->_str); |
|
62 | + } |
|
62 | 63 | |
63 | 64 | return $data; |
64 | 65 | } |
65 | 66 | |
66 | 67 | function seekto($pos) { |
67 | 68 | $this->_pos = $pos; |
68 | - if (strlen($this->_str)<$this->_pos) |
|
69 | - $this->_pos = strlen($this->_str); |
|
69 | + if (strlen($this->_str)<$this->_pos) { |
|
70 | + $this->_pos = strlen($this->_str); |
|
71 | + } |
|
70 | 72 | return $this->_pos; |
71 | 73 | } |
72 | 74 | |
@@ -117,7 +119,9 @@ discard block |
||
117 | 119 | $this->_pos = ftell($this->_fd); |
118 | 120 | |
119 | 121 | return $data; |
120 | - } else return ''; |
|
122 | + } else { |
|
123 | + return ''; |
|
124 | + } |
|
121 | 125 | } |
122 | 126 | |
123 | 127 | function seekto($pos) { |
@@ -38,17 +38,17 @@ discard block |
||
38 | 38 | var $error = 0; // public variable that holds error code (0 if no error) |
39 | 39 | |
40 | 40 | //private: |
41 | - var $BYTEORDER = 0; // 0: low endian, 1: big endian |
|
41 | + var $BYTEORDER = 0; // 0: low endian, 1: big endian |
|
42 | 42 | var $STREAM = NULL; |
43 | 43 | var $short_circuit = false; |
44 | 44 | var $enable_cache = false; |
45 | - var $originals = NULL; // offset of original table |
|
46 | - var $translations = NULL; // offset of translation table |
|
47 | - var $pluralheader = NULL; // cache header field for plural forms |
|
48 | - var $total = 0; // total string count |
|
49 | - var $table_originals = NULL; // table for original strings (offsets) |
|
50 | - var $table_translations = NULL; // table for translated strings (offsets) |
|
51 | - var $cache_translations = NULL; // original -> translation mapping |
|
45 | + var $originals = NULL; // offset of original table |
|
46 | + var $translations = NULL; // offset of translation table |
|
47 | + var $pluralheader = NULL; // cache header field for plural forms |
|
48 | + var $total = 0; // total string count |
|
49 | + var $table_originals = NULL; // table for original strings (offsets) |
|
50 | + var $table_translations = NULL; // table for translated strings (offsets) |
|
51 | + var $cache_translations = NULL; // original -> translation mapping |
|
52 | 52 | |
53 | 53 | |
54 | 54 | /* Methods */ |
@@ -63,11 +63,11 @@ discard block |
||
63 | 63 | function readint() { |
64 | 64 | if ($this->BYTEORDER == 0) { |
65 | 65 | // low endian |
66 | - $input=unpack('V', $this->STREAM->read(4)); |
|
66 | + $input = unpack('V', $this->STREAM->read(4)); |
|
67 | 67 | return array_shift($input); |
68 | 68 | } else { |
69 | 69 | // big endian |
70 | - $input=unpack('N', $this->STREAM->read(4)); |
|
70 | + $input = unpack('N', $this->STREAM->read(4)); |
|
71 | 71 | return array_shift($input); |
72 | 72 | } |
73 | 73 | } |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | */ |
101 | 101 | function __construct($Reader, $enable_cache = true) { |
102 | 102 | // If there isn't a StreamReader, turn on short circuit mode. |
103 | - if (! $Reader || isset($Reader->error) ) { |
|
103 | + if (!$Reader || isset($Reader->error)) { |
|
104 | 104 | $this->short_circuit = true; |
105 | 105 | return; |
106 | 106 | } |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | } |
155 | 155 | |
156 | 156 | if ($this->enable_cache) { |
157 | - $this->cache_translations = array (); |
|
157 | + $this->cache_translations = array(); |
|
158 | 158 | /* read all strings in the cache */ |
159 | 159 | for ($i = 0; $i < $this->total; $i++) { |
160 | 160 | $this->STREAM->seekto($this->table_originals[$i * 2 + 2]); |
@@ -176,11 +176,11 @@ discard block |
||
176 | 176 | function get_original_string($num) { |
177 | 177 | $length = $this->table_originals[$num * 2 + 1]; |
178 | 178 | $offset = $this->table_originals[$num * 2 + 2]; |
179 | - if (! $length) |
|
179 | + if (!$length) |
|
180 | 180 | return ''; |
181 | 181 | $this->STREAM->seekto($offset); |
182 | 182 | $data = $this->STREAM->read($length); |
183 | - return (string)$data; |
|
183 | + return (string) $data; |
|
184 | 184 | } |
185 | 185 | |
186 | 186 | /** |
@@ -193,11 +193,11 @@ discard block |
||
193 | 193 | function get_translation_string($num) { |
194 | 194 | $length = $this->table_translations[$num * 2 + 1]; |
195 | 195 | $offset = $this->table_translations[$num * 2 + 2]; |
196 | - if (! $length) |
|
196 | + if (!$length) |
|
197 | 197 | return ''; |
198 | 198 | $this->STREAM->seekto($offset); |
199 | 199 | $data = $this->STREAM->read($length); |
200 | - return (string)$data; |
|
200 | + return (string) $data; |
|
201 | 201 | } |
202 | 202 | |
203 | 203 | /** |
@@ -227,7 +227,7 @@ discard block |
||
227 | 227 | return $this->find_string($string, $end, $start); |
228 | 228 | } else { |
229 | 229 | // Divide table in two parts |
230 | - $half = (int)(($start + $end) / 2); |
|
230 | + $half = (int) (($start + $end) / 2); |
|
231 | 231 | $cmp = strcmp($string, $this->get_original_string($half)); |
232 | 232 | if ($cmp == 0) |
233 | 233 | // string is exactly in the middle => return it |
@@ -294,7 +294,7 @@ discard block |
||
294 | 294 | $res .= ') : ('; |
295 | 295 | break; |
296 | 296 | case ';': |
297 | - $res .= str_repeat( ')', $p) . ';'; |
|
297 | + $res .= str_repeat(')', $p).';'; |
|
298 | 298 | $p = 0; |
299 | 299 | break; |
300 | 300 | default: |
@@ -330,7 +330,7 @@ discard block |
||
330 | 330 | $this->load_tables(); |
331 | 331 | |
332 | 332 | // cache header field for plural forms |
333 | - if (! is_string($this->pluralheader)) { |
|
333 | + if (!is_string($this->pluralheader)) { |
|
334 | 334 | if ($this->enable_cache) { |
335 | 335 | $header = $this->cache_translations[""]; |
336 | 336 | } else { |
@@ -352,12 +352,12 @@ discard block |
||
352 | 352 | function select_string($n) { |
353 | 353 | if (!is_int($n)) { |
354 | 354 | throw new InvalidArgumentException( |
355 | - "Select_string only accepts integers: " . $n); |
|
355 | + "Select_string only accepts integers: ".$n); |
|
356 | 356 | } |
357 | 357 | $string = $this->get_plural_forms(); |
358 | - $string = str_replace('nplurals',"\$total",$string); |
|
359 | - $string = str_replace("n",$n,$string); |
|
360 | - $string = str_replace('plural',"\$plural",$string); |
|
358 | + $string = str_replace('nplurals', "\$total", $string); |
|
359 | + $string = str_replace("n", $n, $string); |
|
360 | + $string = str_replace('plural', "\$plural", $string); |
|
361 | 361 | |
362 | 362 | $total = 0; |
363 | 363 | $plural = 0; |
@@ -388,11 +388,11 @@ discard block |
||
388 | 388 | $select = $this->select_string($number); |
389 | 389 | |
390 | 390 | // this should contains all strings separated by NULLs |
391 | - $key = $single . chr(0) . $plural; |
|
391 | + $key = $single.chr(0).$plural; |
|
392 | 392 | |
393 | 393 | |
394 | 394 | if ($this->enable_cache) { |
395 | - if (! array_key_exists($key, $this->cache_translations)) { |
|
395 | + if (!array_key_exists($key, $this->cache_translations)) { |
|
396 | 396 | return ($number != 1) ? $plural : $single; |
397 | 397 | } else { |
398 | 398 | $result = $this->cache_translations[$key]; |
@@ -412,7 +412,7 @@ discard block |
||
412 | 412 | } |
413 | 413 | |
414 | 414 | function pgettext($context, $msgid) { |
415 | - $key = $context . chr(4) . $msgid; |
|
415 | + $key = $context.chr(4).$msgid; |
|
416 | 416 | $ret = $this->translate($key); |
417 | 417 | if (strpos($ret, "\004") !== FALSE) { |
418 | 418 | return $msgid; |
@@ -422,7 +422,7 @@ discard block |
||
422 | 422 | } |
423 | 423 | |
424 | 424 | function npgettext($context, $singular, $plural, $number) { |
425 | - $key = $context . chr(4) . $singular; |
|
425 | + $key = $context.chr(4).$singular; |
|
426 | 426 | $ret = $this->ngettext($key, $plural, $number); |
427 | 427 | if (strpos($ret, "\004") !== FALSE) { |
428 | 428 | return $singular; |
@@ -39,16 +39,16 @@ discard block |
||
39 | 39 | |
40 | 40 | //private: |
41 | 41 | var $BYTEORDER = 0; // 0: low endian, 1: big endian |
42 | - var $STREAM = NULL; |
|
42 | + var $STREAM = null; |
|
43 | 43 | var $short_circuit = false; |
44 | 44 | var $enable_cache = false; |
45 | - var $originals = NULL; // offset of original table |
|
46 | - var $translations = NULL; // offset of translation table |
|
47 | - var $pluralheader = NULL; // cache header field for plural forms |
|
45 | + var $originals = null; // offset of original table |
|
46 | + var $translations = null; // offset of translation table |
|
47 | + var $pluralheader = null; // cache header field for plural forms |
|
48 | 48 | var $total = 0; // total string count |
49 | - var $table_originals = NULL; // table for original strings (offsets) |
|
50 | - var $table_translations = NULL; // table for translated strings (offsets) |
|
51 | - var $cache_translations = NULL; // original -> translation mapping |
|
49 | + var $table_originals = null; // table for original strings (offsets) |
|
50 | + var $table_translations = null; // table for translated strings (offsets) |
|
51 | + var $cache_translations = null; // original -> translation mapping |
|
52 | 52 | |
53 | 53 | |
54 | 54 | /* Methods */ |
@@ -414,7 +414,7 @@ discard block |
||
414 | 414 | function pgettext($context, $msgid) { |
415 | 415 | $key = $context . chr(4) . $msgid; |
416 | 416 | $ret = $this->translate($key); |
417 | - if (strpos($ret, "\004") !== FALSE) { |
|
417 | + if (strpos($ret, "\004") !== false) { |
|
418 | 418 | return $msgid; |
419 | 419 | } else { |
420 | 420 | return $ret; |
@@ -424,7 +424,7 @@ discard block |
||
424 | 424 | function npgettext($context, $singular, $plural, $number) { |
425 | 425 | $key = $context . chr(4) . $singular; |
426 | 426 | $ret = $this->ngettext($key, $plural, $number); |
427 | - if (strpos($ret, "\004") !== FALSE) { |
|
427 | + if (strpos($ret, "\004") !== false) { |
|
428 | 428 | return $singular; |
429 | 429 | } else { |
430 | 430 | return $ret; |
@@ -34,75 +34,75 @@ discard block |
||
34 | 34 | * that you don't want to keep in memory) |
35 | 35 | */ |
36 | 36 | class gettext_reader { |
37 | - //public: |
|
38 | - var $error = 0; // public variable that holds error code (0 if no error) |
|
39 | - |
|
40 | - //private: |
|
41 | - var $BYTEORDER = 0; // 0: low endian, 1: big endian |
|
42 | - var $STREAM = NULL; |
|
43 | - var $short_circuit = false; |
|
44 | - var $enable_cache = false; |
|
45 | - var $originals = NULL; // offset of original table |
|
46 | - var $translations = NULL; // offset of translation table |
|
47 | - var $pluralheader = NULL; // cache header field for plural forms |
|
48 | - var $total = 0; // total string count |
|
49 | - var $table_originals = NULL; // table for original strings (offsets) |
|
50 | - var $table_translations = NULL; // table for translated strings (offsets) |
|
51 | - var $cache_translations = NULL; // original -> translation mapping |
|
52 | - |
|
53 | - |
|
54 | - /* Methods */ |
|
55 | - |
|
56 | - |
|
57 | - /** |
|
58 | - * Reads a 32bit Integer from the Stream |
|
59 | - * |
|
60 | - * @access private |
|
61 | - * @return Integer from the Stream |
|
62 | - */ |
|
63 | - function readint() { |
|
64 | - if ($this->BYTEORDER == 0) { |
|
37 | + //public: |
|
38 | + var $error = 0; // public variable that holds error code (0 if no error) |
|
39 | + |
|
40 | + //private: |
|
41 | + var $BYTEORDER = 0; // 0: low endian, 1: big endian |
|
42 | + var $STREAM = NULL; |
|
43 | + var $short_circuit = false; |
|
44 | + var $enable_cache = false; |
|
45 | + var $originals = NULL; // offset of original table |
|
46 | + var $translations = NULL; // offset of translation table |
|
47 | + var $pluralheader = NULL; // cache header field for plural forms |
|
48 | + var $total = 0; // total string count |
|
49 | + var $table_originals = NULL; // table for original strings (offsets) |
|
50 | + var $table_translations = NULL; // table for translated strings (offsets) |
|
51 | + var $cache_translations = NULL; // original -> translation mapping |
|
52 | + |
|
53 | + |
|
54 | + /* Methods */ |
|
55 | + |
|
56 | + |
|
57 | + /** |
|
58 | + * Reads a 32bit Integer from the Stream |
|
59 | + * |
|
60 | + * @access private |
|
61 | + * @return Integer from the Stream |
|
62 | + */ |
|
63 | + function readint() { |
|
64 | + if ($this->BYTEORDER == 0) { |
|
65 | 65 | // low endian |
66 | 66 | $input=unpack('V', $this->STREAM->read(4)); |
67 | 67 | return array_shift($input); |
68 | - } else { |
|
68 | + } else { |
|
69 | 69 | // big endian |
70 | 70 | $input=unpack('N', $this->STREAM->read(4)); |
71 | 71 | return array_shift($input); |
72 | - } |
|
72 | + } |
|
73 | 73 | } |
74 | 74 | |
75 | - function read($bytes) { |
|
75 | + function read($bytes) { |
|
76 | 76 | return $this->STREAM->read($bytes); |
77 | - } |
|
78 | - |
|
79 | - /** |
|
80 | - * Reads an array of Integers from the Stream |
|
81 | - * |
|
82 | - * @param int count How many elements should be read |
|
83 | - * @return Array of Integers |
|
84 | - */ |
|
85 | - function readintarray($count) { |
|
77 | + } |
|
78 | + |
|
79 | + /** |
|
80 | + * Reads an array of Integers from the Stream |
|
81 | + * |
|
82 | + * @param int count How many elements should be read |
|
83 | + * @return Array of Integers |
|
84 | + */ |
|
85 | + function readintarray($count) { |
|
86 | 86 | if ($this->BYTEORDER == 0) { |
87 | 87 | // low endian |
88 | 88 | return unpack('V'.$count, $this->STREAM->read(4 * $count)); |
89 | - } else { |
|
89 | + } else { |
|
90 | 90 | // big endian |
91 | 91 | return unpack('N'.$count, $this->STREAM->read(4 * $count)); |
92 | - } |
|
93 | - } |
|
94 | - |
|
95 | - /** |
|
96 | - * Constructor |
|
97 | - * |
|
98 | - * @param object Reader the StreamReader object |
|
99 | - * @param boolean enable_cache Enable or disable caching of strings (default on) |
|
100 | - */ |
|
101 | - function __construct($Reader, $enable_cache = true) { |
|
92 | + } |
|
93 | + } |
|
94 | + |
|
95 | + /** |
|
96 | + * Constructor |
|
97 | + * |
|
98 | + * @param object Reader the StreamReader object |
|
99 | + * @param boolean enable_cache Enable or disable caching of strings (default on) |
|
100 | + */ |
|
101 | + function __construct($Reader, $enable_cache = true) { |
|
102 | 102 | // If there isn't a StreamReader, turn on short circuit mode. |
103 | 103 | if (! $Reader || isset($Reader->error) ) { |
104 | - $this->short_circuit = true; |
|
105 | - return; |
|
104 | + $this->short_circuit = true; |
|
105 | + return; |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | // Caching can be turned off |
@@ -114,12 +114,12 @@ discard block |
||
114 | 114 | $this->STREAM = $Reader; |
115 | 115 | $magic = $this->read(4); |
116 | 116 | if ($magic == $MAGIC1) { |
117 | - $this->BYTEORDER = 1; |
|
117 | + $this->BYTEORDER = 1; |
|
118 | 118 | } elseif ($magic == $MAGIC2) { |
119 | - $this->BYTEORDER = 0; |
|
119 | + $this->BYTEORDER = 0; |
|
120 | 120 | } else { |
121 | - $this->error = 1; // not MO file |
|
122 | - return false; |
|
121 | + $this->error = 1; // not MO file |
|
122 | + return false; |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | // FIXME: Do we care about revision? We should. |
@@ -128,154 +128,154 @@ discard block |
||
128 | 128 | $this->total = $this->readint(); |
129 | 129 | $this->originals = $this->readint(); |
130 | 130 | $this->translations = $this->readint(); |
131 | - } |
|
132 | - |
|
133 | - /** |
|
134 | - * Loads the translation tables from the MO file into the cache |
|
135 | - * If caching is enabled, also loads all strings into a cache |
|
136 | - * to speed up translation lookups |
|
137 | - * |
|
138 | - * @access private |
|
139 | - */ |
|
140 | - function load_tables() { |
|
131 | + } |
|
132 | + |
|
133 | + /** |
|
134 | + * Loads the translation tables from the MO file into the cache |
|
135 | + * If caching is enabled, also loads all strings into a cache |
|
136 | + * to speed up translation lookups |
|
137 | + * |
|
138 | + * @access private |
|
139 | + */ |
|
140 | + function load_tables() { |
|
141 | 141 | if (is_array($this->cache_translations) && |
142 | 142 | is_array($this->table_originals) && |
143 | 143 | is_array($this->table_translations)) |
144 | - return; |
|
144 | + return; |
|
145 | 145 | |
146 | 146 | /* get original and translations tables */ |
147 | 147 | if (!is_array($this->table_originals)) { |
148 | - $this->STREAM->seekto($this->originals); |
|
149 | - $this->table_originals = $this->readintarray($this->total * 2); |
|
148 | + $this->STREAM->seekto($this->originals); |
|
149 | + $this->table_originals = $this->readintarray($this->total * 2); |
|
150 | 150 | } |
151 | 151 | if (!is_array($this->table_translations)) { |
152 | - $this->STREAM->seekto($this->translations); |
|
153 | - $this->table_translations = $this->readintarray($this->total * 2); |
|
152 | + $this->STREAM->seekto($this->translations); |
|
153 | + $this->table_translations = $this->readintarray($this->total * 2); |
|
154 | 154 | } |
155 | 155 | |
156 | 156 | if ($this->enable_cache) { |
157 | - $this->cache_translations = array (); |
|
158 | - /* read all strings in the cache */ |
|
159 | - for ($i = 0; $i < $this->total; $i++) { |
|
157 | + $this->cache_translations = array (); |
|
158 | + /* read all strings in the cache */ |
|
159 | + for ($i = 0; $i < $this->total; $i++) { |
|
160 | 160 | $this->STREAM->seekto($this->table_originals[$i * 2 + 2]); |
161 | 161 | $original = $this->STREAM->read($this->table_originals[$i * 2 + 1]); |
162 | 162 | $this->STREAM->seekto($this->table_translations[$i * 2 + 2]); |
163 | 163 | $translation = $this->STREAM->read($this->table_translations[$i * 2 + 1]); |
164 | 164 | $this->cache_translations[$original] = $translation; |
165 | - } |
|
165 | + } |
|
166 | + } |
|
166 | 167 | } |
167 | - } |
|
168 | - |
|
169 | - /** |
|
170 | - * Returns a string from the "originals" table |
|
171 | - * |
|
172 | - * @access private |
|
173 | - * @param int num Offset number of original string |
|
174 | - * @return string Requested string if found, otherwise '' |
|
175 | - */ |
|
176 | - function get_original_string($num) { |
|
168 | + |
|
169 | + /** |
|
170 | + * Returns a string from the "originals" table |
|
171 | + * |
|
172 | + * @access private |
|
173 | + * @param int num Offset number of original string |
|
174 | + * @return string Requested string if found, otherwise '' |
|
175 | + */ |
|
176 | + function get_original_string($num) { |
|
177 | 177 | $length = $this->table_originals[$num * 2 + 1]; |
178 | 178 | $offset = $this->table_originals[$num * 2 + 2]; |
179 | 179 | if (! $length) |
180 | - return ''; |
|
180 | + return ''; |
|
181 | 181 | $this->STREAM->seekto($offset); |
182 | 182 | $data = $this->STREAM->read($length); |
183 | 183 | return (string)$data; |
184 | - } |
|
185 | - |
|
186 | - /** |
|
187 | - * Returns a string from the "translations" table |
|
188 | - * |
|
189 | - * @access private |
|
190 | - * @param int num Offset number of original string |
|
191 | - * @return string Requested string if found, otherwise '' |
|
192 | - */ |
|
193 | - function get_translation_string($num) { |
|
184 | + } |
|
185 | + |
|
186 | + /** |
|
187 | + * Returns a string from the "translations" table |
|
188 | + * |
|
189 | + * @access private |
|
190 | + * @param int num Offset number of original string |
|
191 | + * @return string Requested string if found, otherwise '' |
|
192 | + */ |
|
193 | + function get_translation_string($num) { |
|
194 | 194 | $length = $this->table_translations[$num * 2 + 1]; |
195 | 195 | $offset = $this->table_translations[$num * 2 + 2]; |
196 | 196 | if (! $length) |
197 | - return ''; |
|
197 | + return ''; |
|
198 | 198 | $this->STREAM->seekto($offset); |
199 | 199 | $data = $this->STREAM->read($length); |
200 | 200 | return (string)$data; |
201 | - } |
|
202 | - |
|
203 | - /** |
|
204 | - * Binary search for string |
|
205 | - * |
|
206 | - * @access private |
|
207 | - * @param string string |
|
208 | - * @param int start (internally used in recursive function) |
|
209 | - * @param int end (internally used in recursive function) |
|
210 | - * @return int string number (offset in originals table) |
|
211 | - */ |
|
212 | - function find_string($string, $start = -1, $end = -1) { |
|
201 | + } |
|
202 | + |
|
203 | + /** |
|
204 | + * Binary search for string |
|
205 | + * |
|
206 | + * @access private |
|
207 | + * @param string string |
|
208 | + * @param int start (internally used in recursive function) |
|
209 | + * @param int end (internally used in recursive function) |
|
210 | + * @return int string number (offset in originals table) |
|
211 | + */ |
|
212 | + function find_string($string, $start = -1, $end = -1) { |
|
213 | 213 | if (($start == -1) or ($end == -1)) { |
214 | - // find_string is called with only one parameter, set start end end |
|
215 | - $start = 0; |
|
216 | - $end = $this->total; |
|
214 | + // find_string is called with only one parameter, set start end end |
|
215 | + $start = 0; |
|
216 | + $end = $this->total; |
|
217 | 217 | } |
218 | 218 | if (abs($start - $end) <= 1) { |
219 | - // We're done, now we either found the string, or it doesn't exist |
|
220 | - $txt = $this->get_original_string($start); |
|
221 | - if ($string == $txt) |
|
219 | + // We're done, now we either found the string, or it doesn't exist |
|
220 | + $txt = $this->get_original_string($start); |
|
221 | + if ($string == $txt) |
|
222 | 222 | return $start; |
223 | - else |
|
223 | + else |
|
224 | 224 | return -1; |
225 | 225 | } else if ($start > $end) { |
226 | - // start > end -> turn around and start over |
|
227 | - return $this->find_string($string, $end, $start); |
|
226 | + // start > end -> turn around and start over |
|
227 | + return $this->find_string($string, $end, $start); |
|
228 | 228 | } else { |
229 | - // Divide table in two parts |
|
230 | - $half = (int)(($start + $end) / 2); |
|
231 | - $cmp = strcmp($string, $this->get_original_string($half)); |
|
232 | - if ($cmp == 0) |
|
229 | + // Divide table in two parts |
|
230 | + $half = (int)(($start + $end) / 2); |
|
231 | + $cmp = strcmp($string, $this->get_original_string($half)); |
|
232 | + if ($cmp == 0) |
|
233 | 233 | // string is exactly in the middle => return it |
234 | 234 | return $half; |
235 | - else if ($cmp < 0) |
|
235 | + else if ($cmp < 0) |
|
236 | 236 | // The string is in the upper half |
237 | 237 | return $this->find_string($string, $start, $half); |
238 | - else |
|
238 | + else |
|
239 | 239 | // The string is in the lower half |
240 | 240 | return $this->find_string($string, $half, $end); |
241 | 241 | } |
242 | - } |
|
243 | - |
|
244 | - /** |
|
245 | - * Translates a string |
|
246 | - * |
|
247 | - * @access public |
|
248 | - * @param string string to be translated |
|
249 | - * @return string translated string (or original, if not found) |
|
250 | - */ |
|
251 | - function translate($string) { |
|
242 | + } |
|
243 | + |
|
244 | + /** |
|
245 | + * Translates a string |
|
246 | + * |
|
247 | + * @access public |
|
248 | + * @param string string to be translated |
|
249 | + * @return string translated string (or original, if not found) |
|
250 | + */ |
|
251 | + function translate($string) { |
|
252 | 252 | if ($this->short_circuit) |
253 | - return $string; |
|
253 | + return $string; |
|
254 | 254 | $this->load_tables(); |
255 | 255 | |
256 | 256 | if ($this->enable_cache) { |
257 | - // Caching enabled, get translated string from cache |
|
258 | - if (array_key_exists($string, $this->cache_translations)) |
|
257 | + // Caching enabled, get translated string from cache |
|
258 | + if (array_key_exists($string, $this->cache_translations)) |
|
259 | 259 | return $this->cache_translations[$string]; |
260 | - else |
|
260 | + else |
|
261 | 261 | return $string; |
262 | 262 | } else { |
263 | - // Caching not enabled, try to find string |
|
264 | - $num = $this->find_string($string); |
|
265 | - if ($num == -1) |
|
263 | + // Caching not enabled, try to find string |
|
264 | + $num = $this->find_string($string); |
|
265 | + if ($num == -1) |
|
266 | 266 | return $string; |
267 | - else |
|
267 | + else |
|
268 | 268 | return $this->get_translation_string($num); |
269 | 269 | } |
270 | - } |
|
271 | - |
|
272 | - /** |
|
273 | - * Sanitize plural form expression for use in PHP eval call. |
|
274 | - * |
|
275 | - * @access private |
|
276 | - * @return string sanitized plural form expression |
|
277 | - */ |
|
278 | - function sanitize_plural_expression($expr) { |
|
270 | + } |
|
271 | + |
|
272 | + /** |
|
273 | + * Sanitize plural form expression for use in PHP eval call. |
|
274 | + * |
|
275 | + * @access private |
|
276 | + * @return string sanitized plural form expression |
|
277 | + */ |
|
278 | + function sanitize_plural_expression($expr) { |
|
279 | 279 | // Get rid of disallowed characters. |
280 | 280 | $expr = preg_replace('@[^a-zA-Z0-9_:;\(\)\?\|\&=!<>+*/\%-]@', '', $expr); |
281 | 281 | |
@@ -284,74 +284,74 @@ discard block |
||
284 | 284 | $res = ''; |
285 | 285 | $p = 0; |
286 | 286 | for ($i = 0; $i < strlen($expr); $i++) { |
287 | - $ch = $expr[$i]; |
|
288 | - switch ($ch) { |
|
289 | - case '?': |
|
287 | + $ch = $expr[$i]; |
|
288 | + switch ($ch) { |
|
289 | + case '?': |
|
290 | 290 | $res .= ' ? ('; |
291 | 291 | $p++; |
292 | 292 | break; |
293 | - case ':': |
|
293 | + case ':': |
|
294 | 294 | $res .= ') : ('; |
295 | 295 | break; |
296 | - case ';': |
|
296 | + case ';': |
|
297 | 297 | $res .= str_repeat( ')', $p) . ';'; |
298 | 298 | $p = 0; |
299 | 299 | break; |
300 | - default: |
|
300 | + default: |
|
301 | 301 | $res .= $ch; |
302 | - } |
|
302 | + } |
|
303 | 303 | } |
304 | 304 | return $res; |
305 | - } |
|
306 | - |
|
307 | - /** |
|
308 | - * Parse full PO header and extract only plural forms line. |
|
309 | - * |
|
310 | - * @access private |
|
311 | - * @return string verbatim plural form header field |
|
312 | - */ |
|
313 | - function extract_plural_forms_header_from_po_header($header) { |
|
305 | + } |
|
306 | + |
|
307 | + /** |
|
308 | + * Parse full PO header and extract only plural forms line. |
|
309 | + * |
|
310 | + * @access private |
|
311 | + * @return string verbatim plural form header field |
|
312 | + */ |
|
313 | + function extract_plural_forms_header_from_po_header($header) { |
|
314 | 314 | if (preg_match("/(^|\n)plural-forms: ([^\n]*)\n/i", $header, $regs)) |
315 | - $expr = $regs[2]; |
|
315 | + $expr = $regs[2]; |
|
316 | 316 | else |
317 | - $expr = "nplurals=2; plural=n == 1 ? 0 : 1;"; |
|
317 | + $expr = "nplurals=2; plural=n == 1 ? 0 : 1;"; |
|
318 | 318 | return $expr; |
319 | - } |
|
320 | - |
|
321 | - /** |
|
322 | - * Get possible plural forms from MO header |
|
323 | - * |
|
324 | - * @access private |
|
325 | - * @return string plural form header |
|
326 | - */ |
|
327 | - function get_plural_forms() { |
|
319 | + } |
|
320 | + |
|
321 | + /** |
|
322 | + * Get possible plural forms from MO header |
|
323 | + * |
|
324 | + * @access private |
|
325 | + * @return string plural form header |
|
326 | + */ |
|
327 | + function get_plural_forms() { |
|
328 | 328 | // lets assume message number 0 is header |
329 | 329 | // this is true, right? |
330 | 330 | $this->load_tables(); |
331 | 331 | |
332 | 332 | // cache header field for plural forms |
333 | 333 | if (! is_string($this->pluralheader)) { |
334 | - if ($this->enable_cache) { |
|
334 | + if ($this->enable_cache) { |
|
335 | 335 | $header = $this->cache_translations[""]; |
336 | - } else { |
|
336 | + } else { |
|
337 | 337 | $header = $this->get_translation_string(0); |
338 | - } |
|
339 | - $expr = $this->extract_plural_forms_header_from_po_header($header); |
|
340 | - $this->pluralheader = $this->sanitize_plural_expression($expr); |
|
338 | + } |
|
339 | + $expr = $this->extract_plural_forms_header_from_po_header($header); |
|
340 | + $this->pluralheader = $this->sanitize_plural_expression($expr); |
|
341 | 341 | } |
342 | 342 | return $this->pluralheader; |
343 | - } |
|
344 | - |
|
345 | - /** |
|
346 | - * Detects which plural form to take |
|
347 | - * |
|
348 | - * @access private |
|
349 | - * @param n count |
|
350 | - * @return int array index of the right plural form |
|
351 | - */ |
|
352 | - function select_string($n) { |
|
343 | + } |
|
344 | + |
|
345 | + /** |
|
346 | + * Detects which plural form to take |
|
347 | + * |
|
348 | + * @access private |
|
349 | + * @param n count |
|
350 | + * @return int array index of the right plural form |
|
351 | + */ |
|
352 | + function select_string($n) { |
|
353 | 353 | if (!is_int($n)) { |
354 | - throw new InvalidArgumentException( |
|
354 | + throw new InvalidArgumentException( |
|
355 | 355 | "Select_string only accepts integers: " . $n); |
356 | 356 | } |
357 | 357 | $string = $this->get_plural_forms(); |
@@ -365,22 +365,22 @@ discard block |
||
365 | 365 | eval("$string"); |
366 | 366 | if ($plural >= $total) $plural = $total - 1; |
367 | 367 | return $plural; |
368 | - } |
|
369 | - |
|
370 | - /** |
|
371 | - * Plural version of gettext |
|
372 | - * |
|
373 | - * @access public |
|
374 | - * @param string single |
|
375 | - * @param string plural |
|
376 | - * @param string number |
|
377 | - * @return translated plural form |
|
378 | - */ |
|
379 | - function ngettext($single, $plural, $number) { |
|
368 | + } |
|
369 | + |
|
370 | + /** |
|
371 | + * Plural version of gettext |
|
372 | + * |
|
373 | + * @access public |
|
374 | + * @param string single |
|
375 | + * @param string plural |
|
376 | + * @param string number |
|
377 | + * @return translated plural form |
|
378 | + */ |
|
379 | + function ngettext($single, $plural, $number) { |
|
380 | 380 | if ($this->short_circuit) { |
381 | - if ($number != 1) |
|
381 | + if ($number != 1) |
|
382 | 382 | return $plural; |
383 | - else |
|
383 | + else |
|
384 | 384 | return $single; |
385 | 385 | } |
386 | 386 | |
@@ -392,45 +392,45 @@ discard block |
||
392 | 392 | |
393 | 393 | |
394 | 394 | if ($this->enable_cache) { |
395 | - if (! array_key_exists($key, $this->cache_translations)) { |
|
395 | + if (! array_key_exists($key, $this->cache_translations)) { |
|
396 | 396 | return ($number != 1) ? $plural : $single; |
397 | - } else { |
|
397 | + } else { |
|
398 | 398 | $result = $this->cache_translations[$key]; |
399 | 399 | $list = explode(chr(0), $result); |
400 | 400 | return $list[$select]; |
401 | - } |
|
401 | + } |
|
402 | 402 | } else { |
403 | - $num = $this->find_string($key); |
|
404 | - if ($num == -1) { |
|
403 | + $num = $this->find_string($key); |
|
404 | + if ($num == -1) { |
|
405 | 405 | return ($number != 1) ? $plural : $single; |
406 | - } else { |
|
406 | + } else { |
|
407 | 407 | $result = $this->get_translation_string($num); |
408 | 408 | $list = explode(chr(0), $result); |
409 | 409 | return $list[$select]; |
410 | - } |
|
410 | + } |
|
411 | + } |
|
411 | 412 | } |
412 | - } |
|
413 | 413 | |
414 | - function pgettext($context, $msgid) { |
|
414 | + function pgettext($context, $msgid) { |
|
415 | 415 | $key = $context . chr(4) . $msgid; |
416 | 416 | $ret = $this->translate($key); |
417 | 417 | if (strpos($ret, "\004") !== FALSE) { |
418 | - return $msgid; |
|
418 | + return $msgid; |
|
419 | 419 | } else { |
420 | - return $ret; |
|
420 | + return $ret; |
|
421 | + } |
|
421 | 422 | } |
422 | - } |
|
423 | 423 | |
424 | - function npgettext($context, $singular, $plural, $number) { |
|
424 | + function npgettext($context, $singular, $plural, $number) { |
|
425 | 425 | $key = $context . chr(4) . $singular; |
426 | 426 | $ret = $this->ngettext($key, $plural, $number); |
427 | 427 | if (strpos($ret, "\004") !== FALSE) { |
428 | - return $singular; |
|
428 | + return $singular; |
|
429 | 429 | } else { |
430 | - return $ret; |
|
430 | + return $ret; |
|
431 | 431 | } |
432 | 432 | |
433 | - } |
|
433 | + } |
|
434 | 434 | } |
435 | 435 | |
436 | 436 | ?> |
@@ -140,8 +140,9 @@ discard block |
||
140 | 140 | function load_tables() { |
141 | 141 | if (is_array($this->cache_translations) && |
142 | 142 | is_array($this->table_originals) && |
143 | - is_array($this->table_translations)) |
|
144 | - return; |
|
143 | + is_array($this->table_translations)) { |
|
144 | + return; |
|
145 | + } |
|
145 | 146 | |
146 | 147 | /* get original and translations tables */ |
147 | 148 | if (!is_array($this->table_originals)) { |
@@ -176,8 +177,9 @@ discard block |
||
176 | 177 | function get_original_string($num) { |
177 | 178 | $length = $this->table_originals[$num * 2 + 1]; |
178 | 179 | $offset = $this->table_originals[$num * 2 + 2]; |
179 | - if (! $length) |
|
180 | - return ''; |
|
180 | + if (! $length) { |
|
181 | + return ''; |
|
182 | + } |
|
181 | 183 | $this->STREAM->seekto($offset); |
182 | 184 | $data = $this->STREAM->read($length); |
183 | 185 | return (string)$data; |
@@ -193,8 +195,9 @@ discard block |
||
193 | 195 | function get_translation_string($num) { |
194 | 196 | $length = $this->table_translations[$num * 2 + 1]; |
195 | 197 | $offset = $this->table_translations[$num * 2 + 2]; |
196 | - if (! $length) |
|
197 | - return ''; |
|
198 | + if (! $length) { |
|
199 | + return ''; |
|
200 | + } |
|
198 | 201 | $this->STREAM->seekto($offset); |
199 | 202 | $data = $this->STREAM->read($length); |
200 | 203 | return (string)$data; |
@@ -218,10 +221,11 @@ discard block |
||
218 | 221 | if (abs($start - $end) <= 1) { |
219 | 222 | // We're done, now we either found the string, or it doesn't exist |
220 | 223 | $txt = $this->get_original_string($start); |
221 | - if ($string == $txt) |
|
222 | - return $start; |
|
223 | - else |
|
224 | - return -1; |
|
224 | + if ($string == $txt) { |
|
225 | + return $start; |
|
226 | + } else { |
|
227 | + return -1; |
|
228 | + } |
|
225 | 229 | } else if ($start > $end) { |
226 | 230 | // start > end -> turn around and start over |
227 | 231 | return $this->find_string($string, $end, $start); |
@@ -229,15 +233,16 @@ discard block |
||
229 | 233 | // Divide table in two parts |
230 | 234 | $half = (int)(($start + $end) / 2); |
231 | 235 | $cmp = strcmp($string, $this->get_original_string($half)); |
232 | - if ($cmp == 0) |
|
233 | - // string is exactly in the middle => return it |
|
236 | + if ($cmp == 0) { |
|
237 | + // string is exactly in the middle => return it |
|
234 | 238 | return $half; |
235 | - else if ($cmp < 0) |
|
236 | - // The string is in the upper half |
|
239 | + } else if ($cmp < 0) { |
|
240 | + // The string is in the upper half |
|
237 | 241 | return $this->find_string($string, $start, $half); |
238 | - else |
|
239 | - // The string is in the lower half |
|
242 | + } else { |
|
243 | + // The string is in the lower half |
|
240 | 244 | return $this->find_string($string, $half, $end); |
245 | + } |
|
241 | 246 | } |
242 | 247 | } |
243 | 248 | |
@@ -249,23 +254,26 @@ discard block |
||
249 | 254 | * @return string translated string (or original, if not found) |
250 | 255 | */ |
251 | 256 | function translate($string) { |
252 | - if ($this->short_circuit) |
|
253 | - return $string; |
|
257 | + if ($this->short_circuit) { |
|
258 | + return $string; |
|
259 | + } |
|
254 | 260 | $this->load_tables(); |
255 | 261 | |
256 | 262 | if ($this->enable_cache) { |
257 | 263 | // Caching enabled, get translated string from cache |
258 | - if (array_key_exists($string, $this->cache_translations)) |
|
259 | - return $this->cache_translations[$string]; |
|
260 | - else |
|
261 | - return $string; |
|
264 | + if (array_key_exists($string, $this->cache_translations)) { |
|
265 | + return $this->cache_translations[$string]; |
|
266 | + } else { |
|
267 | + return $string; |
|
268 | + } |
|
262 | 269 | } else { |
263 | 270 | // Caching not enabled, try to find string |
264 | 271 | $num = $this->find_string($string); |
265 | - if ($num == -1) |
|
266 | - return $string; |
|
267 | - else |
|
268 | - return $this->get_translation_string($num); |
|
272 | + if ($num == -1) { |
|
273 | + return $string; |
|
274 | + } else { |
|
275 | + return $this->get_translation_string($num); |
|
276 | + } |
|
269 | 277 | } |
270 | 278 | } |
271 | 279 | |
@@ -311,10 +319,11 @@ discard block |
||
311 | 319 | * @return string verbatim plural form header field |
312 | 320 | */ |
313 | 321 | function extract_plural_forms_header_from_po_header($header) { |
314 | - if (preg_match("/(^|\n)plural-forms: ([^\n]*)\n/i", $header, $regs)) |
|
315 | - $expr = $regs[2]; |
|
316 | - else |
|
317 | - $expr = "nplurals=2; plural=n == 1 ? 0 : 1;"; |
|
322 | + if (preg_match("/(^|\n)plural-forms: ([^\n]*)\n/i", $header, $regs)) { |
|
323 | + $expr = $regs[2]; |
|
324 | + } else { |
|
325 | + $expr = "nplurals=2; plural=n == 1 ? 0 : 1;"; |
|
326 | + } |
|
318 | 327 | return $expr; |
319 | 328 | } |
320 | 329 | |
@@ -363,7 +372,9 @@ discard block |
||
363 | 372 | $plural = 0; |
364 | 373 | |
365 | 374 | eval("$string"); |
366 | - if ($plural >= $total) $plural = $total - 1; |
|
375 | + if ($plural >= $total) { |
|
376 | + $plural = $total - 1; |
|
377 | + } |
|
367 | 378 | return $plural; |
368 | 379 | } |
369 | 380 | |
@@ -378,10 +389,11 @@ discard block |
||
378 | 389 | */ |
379 | 390 | function ngettext($single, $plural, $number) { |
380 | 391 | if ($this->short_circuit) { |
381 | - if ($number != 1) |
|
382 | - return $plural; |
|
383 | - else |
|
384 | - return $single; |
|
392 | + if ($number != 1) { |
|
393 | + return $plural; |
|
394 | + } else { |
|
395 | + return $single; |
|
396 | + } |
|
385 | 397 | } |
386 | 398 | |
387 | 399 | // find out the appropriate form |
@@ -12,11 +12,11 @@ |
||
12 | 12 | // we need a separate check here because functions.php might get parsed |
13 | 13 | // incorrectly before 5.3 because of :: syntax. |
14 | 14 | if (version_compare(PHP_VERSION, '5.6.0', '<')) { |
15 | - print "<b>Fatal Error</b>: PHP version 5.6.0 or newer required. You're using " . PHP_VERSION . ".\n"; |
|
15 | + print "<b>Fatal Error</b>: PHP version 5.6.0 or newer required. You're using ".PHP_VERSION.".\n"; |
|
16 | 16 | exit; |
17 | 17 | } |
18 | 18 | |
19 | - set_include_path(dirname(__FILE__) ."/include" . PATH_SEPARATOR . |
|
19 | + set_include_path(dirname(__FILE__)."/include".PATH_SEPARATOR. |
|
20 | 20 | get_include_path()); |
21 | 21 | |
22 | 22 | require_once "autoload.php"; |
@@ -1,36 +1,36 @@ discard block |
||
1 | 1 | <?php |
2 | - if (file_exists("install") && !file_exists("config.php")) { |
|
3 | - header("Location: install/"); |
|
4 | - } |
|
2 | + if (file_exists("install") && !file_exists("config.php")) { |
|
3 | + header("Location: install/"); |
|
4 | + } |
|
5 | 5 | |
6 | - if (!file_exists("config.php")) { |
|
7 | - print "<b>Fatal Error</b>: You forgot to copy |
|
6 | + if (!file_exists("config.php")) { |
|
7 | + print "<b>Fatal Error</b>: You forgot to copy |
|
8 | 8 | <b>config.php-dist</b> to <b>config.php</b> and edit it.\n"; |
9 | - exit; |
|
10 | - } |
|
9 | + exit; |
|
10 | + } |
|
11 | 11 | |
12 | - // we need a separate check here because functions.php might get parsed |
|
13 | - // incorrectly before 5.3 because of :: syntax. |
|
14 | - if (version_compare(PHP_VERSION, '5.6.0', '<')) { |
|
15 | - print "<b>Fatal Error</b>: PHP version 5.6.0 or newer required. You're using " . PHP_VERSION . ".\n"; |
|
16 | - exit; |
|
17 | - } |
|
12 | + // we need a separate check here because functions.php might get parsed |
|
13 | + // incorrectly before 5.3 because of :: syntax. |
|
14 | + if (version_compare(PHP_VERSION, '5.6.0', '<')) { |
|
15 | + print "<b>Fatal Error</b>: PHP version 5.6.0 or newer required. You're using " . PHP_VERSION . ".\n"; |
|
16 | + exit; |
|
17 | + } |
|
18 | 18 | |
19 | - set_include_path(dirname(__FILE__) ."/include" . PATH_SEPARATOR . |
|
20 | - get_include_path()); |
|
19 | + set_include_path(dirname(__FILE__) ."/include" . PATH_SEPARATOR . |
|
20 | + get_include_path()); |
|
21 | 21 | |
22 | - require_once "autoload.php"; |
|
23 | - require_once "sessions.php"; |
|
24 | - require_once "functions.php"; |
|
25 | - require_once "sanity_check.php"; |
|
26 | - require_once "config.php"; |
|
27 | - require_once "db-prefs.php"; |
|
22 | + require_once "autoload.php"; |
|
23 | + require_once "sessions.php"; |
|
24 | + require_once "functions.php"; |
|
25 | + require_once "sanity_check.php"; |
|
26 | + require_once "config.php"; |
|
27 | + require_once "db-prefs.php"; |
|
28 | 28 | |
29 | - if (!init_plugins()) return; |
|
29 | + if (!init_plugins()) return; |
|
30 | 30 | |
31 | - login_sequence(); |
|
31 | + login_sequence(); |
|
32 | 32 | |
33 | - header('Content-Type: text/html; charset=utf-8'); |
|
33 | + header('Content-Type: text/html; charset=utf-8'); |
|
34 | 34 | |
35 | 35 | ?> |
36 | 36 | <!DOCTYPE html> |
@@ -40,23 +40,23 @@ discard block |
||
40 | 40 | <meta name="viewport" content="initial-scale=1,width=device-width" /> |
41 | 41 | |
42 | 42 | <?php if ($_SESSION["uid"]) { |
43 | - $theme = get_pref("USER_CSS_THEME", false, false); |
|
44 | - if ($theme && theme_exists("$theme")) { |
|
45 | - echo stylesheet_tag(get_theme_path($theme), 'theme_css'); |
|
46 | - } |
|
47 | - } |
|
43 | + $theme = get_pref("USER_CSS_THEME", false, false); |
|
44 | + if ($theme && theme_exists("$theme")) { |
|
45 | + echo stylesheet_tag(get_theme_path($theme), 'theme_css'); |
|
46 | + } |
|
47 | + } |
|
48 | 48 | |
49 | - print_user_stylesheet() |
|
49 | + print_user_stylesheet() |
|
50 | 50 | |
51 | - ?> |
|
51 | + ?> |
|
52 | 52 | <style type="text/css"> |
53 | 53 | <?php |
54 | - foreach (PluginHost::getInstance()->get_plugins() as $n => $p) { |
|
55 | - if (method_exists($p, "get_css")) { |
|
56 | - echo $p->get_css(); |
|
57 | - } |
|
58 | - } |
|
59 | - ?> |
|
54 | + foreach (PluginHost::getInstance()->get_plugins() as $n => $p) { |
|
55 | + if (method_exists($p, "get_css")) { |
|
56 | + echo $p->get_css(); |
|
57 | + } |
|
58 | + } |
|
59 | + ?> |
|
60 | 60 | </style> |
61 | 61 | |
62 | 62 | <link rel="shortcut icon" type="image/png" href="images/favicon.png"/> |
@@ -73,17 +73,17 @@ discard block |
||
73 | 73 | </script> |
74 | 74 | |
75 | 75 | <?php |
76 | - foreach (array("lib/prototype.js", |
|
77 | - "lib/scriptaculous/scriptaculous.js?load=effects,controls", |
|
78 | - "lib/dojo/dojo.js", |
|
79 | - "lib/dojo/tt-rss-layer.js", |
|
80 | - "js/tt-rss.js", |
|
81 | - "js/common.js", |
|
82 | - "errors.php?mode=js") as $jsfile) { |
|
76 | + foreach (array("lib/prototype.js", |
|
77 | + "lib/scriptaculous/scriptaculous.js?load=effects,controls", |
|
78 | + "lib/dojo/dojo.js", |
|
79 | + "lib/dojo/tt-rss-layer.js", |
|
80 | + "js/tt-rss.js", |
|
81 | + "js/common.js", |
|
82 | + "errors.php?mode=js") as $jsfile) { |
|
83 | 83 | |
84 | - echo javascript_tag($jsfile); |
|
84 | + echo javascript_tag($jsfile); |
|
85 | 85 | |
86 | - } ?> |
|
86 | + } ?> |
|
87 | 87 | |
88 | 88 | <script type="text/javascript"> |
89 | 89 | require({cache:{}}); |
@@ -91,22 +91,22 @@ discard block |
||
91 | 91 | |
92 | 92 | <script type="text/javascript"> |
93 | 93 | <?php |
94 | - foreach (PluginHost::getInstance()->get_plugins() as $n => $p) { |
|
95 | - if (method_exists($p, "get_js")) { |
|
96 | - $script = $p->get_js(); |
|
94 | + foreach (PluginHost::getInstance()->get_plugins() as $n => $p) { |
|
95 | + if (method_exists($p, "get_js")) { |
|
96 | + $script = $p->get_js(); |
|
97 | 97 | |
98 | - if ($script) { |
|
99 | - echo "try { |
|
98 | + if ($script) { |
|
99 | + echo "try { |
|
100 | 100 | $script |
101 | 101 | } catch (e) { |
102 | 102 | console.warn('failed to initialize plugin JS: $n', e); |
103 | 103 | }"; |
104 | - } |
|
105 | - } |
|
106 | - } |
|
104 | + } |
|
105 | + } |
|
106 | + } |
|
107 | 107 | |
108 | - init_js_translations(); |
|
109 | - ?> |
|
108 | + init_js_translations(); |
|
109 | + ?> |
|
110 | 110 | </script> |
111 | 111 | |
112 | 112 | <style type="text/css"> |
@@ -146,9 +146,9 @@ discard block |
||
146 | 146 | <img src='images/indicator_tiny.gif'/> |
147 | 147 | <?php echo __("Loading, please wait..."); ?></div> |
148 | 148 | <?php |
149 | - foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_FEED_TREE) as $p) { |
|
149 | + foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_FEED_TREE) as $p) { |
|
150 | 150 | echo $p->hook_feed_tree(); |
151 | - } |
|
151 | + } |
|
152 | 152 | ?> |
153 | 153 | <div id="feedTree"></div> |
154 | 154 | </div> |
@@ -221,7 +221,7 @@ discard block |
||
221 | 221 | |
222 | 222 | <?php |
223 | 223 | foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_TOOLBAR_BUTTON) as $p) { |
224 | - echo $p->hook_toolbar_button(); |
|
224 | + echo $p->hook_toolbar_button(); |
|
225 | 225 | } |
226 | 226 | ?> |
227 | 227 | |
@@ -243,7 +243,7 @@ discard block |
||
243 | 243 | |
244 | 244 | <?php |
245 | 245 | foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_ACTION_ITEM) as $p) { |
246 | - echo $p->hook_action_item(); |
|
246 | + echo $p->hook_action_item(); |
|
247 | 247 | } |
248 | 248 | ?> |
249 | 249 |
@@ -26,7 +26,9 @@ |
||
26 | 26 | require_once "config.php"; |
27 | 27 | require_once "db-prefs.php"; |
28 | 28 | |
29 | - if (!init_plugins()) return; |
|
29 | + if (!init_plugins()) { |
|
30 | + return; |
|
31 | + } |
|
30 | 32 | |
31 | 33 | login_sequence(); |
32 | 34 |