@@ -22,57 +22,57 @@ discard block |
||
| 22 | 22 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 23 | 23 | */ |
| 24 | 24 | |
| 25 | - echo "<h1>PHP QR Code</h1><hr/>"; |
|
| 25 | + echo "<h1>PHP QR Code</h1><hr/>"; |
|
| 26 | 26 | |
| 27 | - //set it to writable location, a place for temp generated PNG files |
|
| 28 | - $PNG_TEMP_DIR = dirname(__FILE__).DIRECTORY_SEPARATOR.'temp'.DIRECTORY_SEPARATOR; |
|
| 27 | + //set it to writable location, a place for temp generated PNG files |
|
| 28 | + $PNG_TEMP_DIR = dirname(__FILE__).DIRECTORY_SEPARATOR.'temp'.DIRECTORY_SEPARATOR; |
|
| 29 | 29 | |
| 30 | - //html PNG location prefix |
|
| 31 | - $PNG_WEB_DIR = 'temp/'; |
|
| 30 | + //html PNG location prefix |
|
| 31 | + $PNG_WEB_DIR = 'temp/'; |
|
| 32 | 32 | |
| 33 | - include "qrlib.php"; |
|
| 33 | + include "qrlib.php"; |
|
| 34 | 34 | |
| 35 | - //ofcourse we need rights to create temp dir |
|
| 36 | - if (!file_exists($PNG_TEMP_DIR)) |
|
| 37 | - mkdir($PNG_TEMP_DIR); |
|
| 35 | + //ofcourse we need rights to create temp dir |
|
| 36 | + if (!file_exists($PNG_TEMP_DIR)) |
|
| 37 | + mkdir($PNG_TEMP_DIR); |
|
| 38 | 38 | |
| 39 | 39 | |
| 40 | - $filename = $PNG_TEMP_DIR.'test.png'; |
|
| 40 | + $filename = $PNG_TEMP_DIR.'test.png'; |
|
| 41 | 41 | |
| 42 | - //processing form input |
|
| 43 | - //remember to sanitize user input in real-life solution !!! |
|
| 44 | - $errorCorrectionLevel = 'L'; |
|
| 45 | - if (isset($_REQUEST['level']) && in_array($_REQUEST['level'], array('L','M','Q','H')))
|
|
| 46 | - $errorCorrectionLevel = $_REQUEST['level']; |
|
| 42 | + //processing form input |
|
| 43 | + //remember to sanitize user input in real-life solution !!! |
|
| 44 | + $errorCorrectionLevel = 'L'; |
|
| 45 | + if (isset($_REQUEST['level']) && in_array($_REQUEST['level'], array('L','M','Q','H')))
|
|
| 46 | + $errorCorrectionLevel = $_REQUEST['level']; |
|
| 47 | 47 | |
| 48 | - $matrixPointSize = 4; |
|
| 49 | - if (isset($_REQUEST['size'])) |
|
| 50 | - $matrixPointSize = min(max((int)$_REQUEST['size'], 1), 10); |
|
| 48 | + $matrixPointSize = 4; |
|
| 49 | + if (isset($_REQUEST['size'])) |
|
| 50 | + $matrixPointSize = min(max((int)$_REQUEST['size'], 1), 10); |
|
| 51 | 51 | |
| 52 | 52 | |
| 53 | - if (isset($_REQUEST['data'])) {
|
|
| 53 | + if (isset($_REQUEST['data'])) {
|
|
| 54 | 54 | |
| 55 | - //it's very important! |
|
| 56 | - if (trim($_REQUEST['data']) == '') |
|
| 57 | - die('data cannot be empty! <a href="?">back</a>');
|
|
| 55 | + //it's very important! |
|
| 56 | + if (trim($_REQUEST['data']) == '') |
|
| 57 | + die('data cannot be empty! <a href="?">back</a>');
|
|
| 58 | 58 | |
| 59 | - // user data |
|
| 60 | - $filename = $PNG_TEMP_DIR.'test'.md5($_REQUEST['data'].'|'.$errorCorrectionLevel.'|'.$matrixPointSize).'.png'; |
|
| 61 | - QRcode::png($_REQUEST['data'], $filename, $errorCorrectionLevel, $matrixPointSize, 2); |
|
| 59 | + // user data |
|
| 60 | + $filename = $PNG_TEMP_DIR.'test'.md5($_REQUEST['data'].'|'.$errorCorrectionLevel.'|'.$matrixPointSize).'.png'; |
|
| 61 | + QRcode::png($_REQUEST['data'], $filename, $errorCorrectionLevel, $matrixPointSize, 2); |
|
| 62 | 62 | |
| 63 | - } else {
|
|
| 63 | + } else {
|
|
| 64 | 64 | |
| 65 | - //default data |
|
| 66 | - echo 'You can provide data in GET parameter: <a href="?data=like_that">like that</a><hr/>'; |
|
| 67 | - QRcode::png('PHP QR Code :)', $filename, $errorCorrectionLevel, $matrixPointSize, 2);
|
|
| 65 | + //default data |
|
| 66 | + echo 'You can provide data in GET parameter: <a href="?data=like_that">like that</a><hr/>'; |
|
| 67 | + QRcode::png('PHP QR Code :)', $filename, $errorCorrectionLevel, $matrixPointSize, 2);
|
|
| 68 | 68 | |
| 69 | - } |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - //display generated file |
|
| 72 | - echo '<img src="'.$PNG_WEB_DIR.basename($filename).'" /><hr/>'; |
|
| 71 | + //display generated file |
|
| 72 | + echo '<img src="'.$PNG_WEB_DIR.basename($filename).'" /><hr/>'; |
|
| 73 | 73 | |
| 74 | - //config form |
|
| 75 | - echo '<form action="index.php" method="post"> |
|
| 74 | + //config form |
|
| 75 | + echo '<form action="index.php" method="post"> |
|
| 76 | 76 | Data: <input name="data" value="'.(isset($_REQUEST['data'])?htmlspecialchars($_REQUEST['data']):'PHP QR Code :)').'" /> |
| 77 | 77 | ECC: <select name="level"> |
| 78 | 78 | <option value="L"'.(($errorCorrectionLevel=='L')?' selected':'').'>L - smallest</option> |
@@ -82,13 +82,13 @@ discard block |
||
| 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 | - echo '</select> |
|
| 88 | + echo '</select> |
|
| 89 | 89 | <input type="submit" value="GENERATE"></form><hr/>'; |
| 90 | 90 | |
| 91 | - // benchmark |
|
| 92 | - QRtools::timeBenchmark(); |
|
| 91 | + // benchmark |
|
| 92 | + QRtools::timeBenchmark(); |
|
| 93 | 93 | |
| 94 | - |
|
| 95 | 94 | \ No newline at end of file |
| 95 | + |
|
| 96 | 96 | \ 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/>'; |
@@ -22,151 +22,151 @@ |
||
| 22 | 22 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 23 | 23 | */ |
| 24 | 24 | |
| 25 | - class QRtools {
|
|
| 25 | + class QRtools {
|
|
| 26 | 26 | |
| 27 | - //---------------------------------------------------------------------- |
|
| 28 | - public static function binarize($frame) |
|
| 29 | - {
|
|
| 30 | - $len = count($frame); |
|
| 31 | - foreach ($frame as &$frameLine) {
|
|
| 27 | + //---------------------------------------------------------------------- |
|
| 28 | + public static function binarize($frame) |
|
| 29 | + {
|
|
| 30 | + $len = count($frame); |
|
| 31 | + foreach ($frame as &$frameLine) {
|
|
| 32 | 32 | |
| 33 | - for($i=0; $i<$len; $i++) {
|
|
| 34 | - $frameLine[$i] = (ord($frameLine[$i])&1)?'1':'0'; |
|
| 35 | - } |
|
| 36 | - } |
|
| 33 | + for($i=0; $i<$len; $i++) {
|
|
| 34 | + $frameLine[$i] = (ord($frameLine[$i])&1)?'1':'0'; |
|
| 35 | + } |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | - return $frame; |
|
| 39 | - } |
|
| 38 | + return $frame; |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - //---------------------------------------------------------------------- |
|
| 42 | - public static function tcpdfBarcodeArray($code, $mode = 'QR,L', $tcPdfVersion = '4.5.037') |
|
| 43 | - {
|
|
| 44 | - $barcode_array = array(); |
|
| 41 | + //---------------------------------------------------------------------- |
|
| 42 | + public static function tcpdfBarcodeArray($code, $mode = 'QR,L', $tcPdfVersion = '4.5.037') |
|
| 43 | + {
|
|
| 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 | - $eccLevel = 'L'; |
|
| 49 | + $eccLevel = 'L'; |
|
| 50 | 50 | |
| 51 | - if (count($mode) > 1) {
|
|
| 52 | - $eccLevel = $mode[1]; |
|
| 53 | - } |
|
| 51 | + if (count($mode) > 1) {
|
|
| 52 | + $eccLevel = $mode[1]; |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - $qrTab = QRcode::text($code, false, $eccLevel); |
|
| 56 | - $size = count($qrTab); |
|
| 55 | + $qrTab = QRcode::text($code, false, $eccLevel); |
|
| 56 | + $size = count($qrTab); |
|
| 57 | 57 | |
| 58 | - $barcode_array['num_rows'] = $size; |
|
| 59 | - $barcode_array['num_cols'] = $size; |
|
| 60 | - $barcode_array['bcode'] = array(); |
|
| 58 | + $barcode_array['num_rows'] = $size; |
|
| 59 | + $barcode_array['num_cols'] = $size; |
|
| 60 | + $barcode_array['bcode'] = array(); |
|
| 61 | 61 | |
| 62 | - foreach ($qrTab as $line) {
|
|
| 63 | - $arrAdd = array(); |
|
| 64 | - foreach(str_split($line) as $char) |
|
| 65 | - $arrAdd[] = ($char=='1')?1:0; |
|
| 66 | - $barcode_array['bcode'][] = $arrAdd; |
|
| 67 | - } |
|
| 62 | + foreach ($qrTab as $line) {
|
|
| 63 | + $arrAdd = array(); |
|
| 64 | + foreach(str_split($line) as $char) |
|
| 65 | + $arrAdd[] = ($char=='1')?1:0; |
|
| 66 | + $barcode_array['bcode'][] = $arrAdd; |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | - return $barcode_array; |
|
| 70 | - } |
|
| 69 | + return $barcode_array; |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - //---------------------------------------------------------------------- |
|
| 73 | - public static function clearCache() |
|
| 74 | - {
|
|
| 75 | - self::$frames = array(); |
|
| 76 | - } |
|
| 72 | + //---------------------------------------------------------------------- |
|
| 73 | + public static function clearCache() |
|
| 74 | + {
|
|
| 75 | + self::$frames = array(); |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | - //---------------------------------------------------------------------- |
|
| 79 | - public static function buildCache() |
|
| 80 | - {
|
|
| 78 | + //---------------------------------------------------------------------- |
|
| 79 | + public static function buildCache() |
|
| 80 | + {
|
|
| 81 | 81 | QRtools::markTime('before_build_cache');
|
| 82 | 82 | |
| 83 | 83 | $mask = new QRmask(); |
| 84 | - for ($a=1; $a <= QRSPEC_VERSION_MAX; $a++) {
|
|
| 85 | - $frame = QRspec::newFrame($a); |
|
| 86 | - if (QR_IMAGE) {
|
|
| 87 | - $fileName = QR_CACHE_DIR.'frame_'.$a.'.png'; |
|
| 88 | - QRimage::png(self::binarize($frame), $fileName, 1, 0); |
|
| 89 | - } |
|
| 84 | + for ($a=1; $a <= QRSPEC_VERSION_MAX; $a++) {
|
|
| 85 | + $frame = QRspec::newFrame($a); |
|
| 86 | + if (QR_IMAGE) {
|
|
| 87 | + $fileName = QR_CACHE_DIR.'frame_'.$a.'.png'; |
|
| 88 | + QRimage::png(self::binarize($frame), $fileName, 1, 0); |
|
| 89 | + } |
|
| 90 | 90 | |
| 91 | 91 | $width = count($frame); |
| 92 | 92 | $bitMask = array_fill(0, $width, array_fill(0, $width, 0)); |
| 93 | 93 | for ($maskNo=0; $maskNo<8; $maskNo++) |
| 94 | 94 | $mask->makeMaskNo($maskNo, $width, $frame, $bitMask, true); |
| 95 | - } |
|
| 95 | + } |
|
| 96 | 96 | |
| 97 | 97 | QRtools::markTime('after_build_cache');
|
| 98 | - } |
|
| 98 | + } |
|
| 99 | 99 | |
| 100 | - //---------------------------------------------------------------------- |
|
| 101 | - public static function log($outfile, $err) |
|
| 102 | - {
|
|
| 103 | - if (QR_LOG_DIR !== false) {
|
|
| 104 | - if ($err != '') {
|
|
| 105 | - if ($outfile !== false) {
|
|
| 106 | - file_put_contents(QR_LOG_DIR.basename($outfile).'-errors.txt', date('Y-m-d H:i:s').': '.$err, FILE_APPEND);
|
|
| 107 | - } else {
|
|
| 108 | - file_put_contents(QR_LOG_DIR.'errors.txt', date('Y-m-d H:i:s').': '.$err, FILE_APPEND);
|
|
| 109 | - } |
|
| 110 | - } |
|
| 111 | - } |
|
| 112 | - } |
|
| 100 | + //---------------------------------------------------------------------- |
|
| 101 | + public static function log($outfile, $err) |
|
| 102 | + {
|
|
| 103 | + if (QR_LOG_DIR !== false) {
|
|
| 104 | + if ($err != '') {
|
|
| 105 | + if ($outfile !== false) {
|
|
| 106 | + file_put_contents(QR_LOG_DIR.basename($outfile).'-errors.txt', date('Y-m-d H:i:s').': '.$err, FILE_APPEND);
|
|
| 107 | + } else {
|
|
| 108 | + file_put_contents(QR_LOG_DIR.'errors.txt', date('Y-m-d H:i:s').': '.$err, FILE_APPEND);
|
|
| 109 | + } |
|
| 110 | + } |
|
| 111 | + } |
|
| 112 | + } |
|
| 113 | 113 | |
| 114 | - //---------------------------------------------------------------------- |
|
| 115 | - public static function dumpMask($frame) |
|
| 116 | - {
|
|
| 117 | - $width = count($frame); |
|
| 118 | - for($y=0;$y<$width;$y++) {
|
|
| 119 | - for($x=0;$x<$width;$x++) {
|
|
| 120 | - echo ord($frame[$y][$x]).','; |
|
| 121 | - } |
|
| 122 | - } |
|
| 123 | - } |
|
| 114 | + //---------------------------------------------------------------------- |
|
| 115 | + public static function dumpMask($frame) |
|
| 116 | + {
|
|
| 117 | + $width = count($frame); |
|
| 118 | + for($y=0;$y<$width;$y++) {
|
|
| 119 | + for($x=0;$x<$width;$x++) {
|
|
| 120 | + echo ord($frame[$y][$x]).','; |
|
| 121 | + } |
|
| 122 | + } |
|
| 123 | + } |
|
| 124 | 124 | |
| 125 | - //---------------------------------------------------------------------- |
|
| 126 | - public static function markTime($markerId) |
|
| 127 | - {
|
|
| 128 | - list($usec, $sec) = explode(" ", microtime());
|
|
| 129 | - $time = ((float)$usec + (float)$sec); |
|
| 125 | + //---------------------------------------------------------------------- |
|
| 126 | + public static function markTime($markerId) |
|
| 127 | + {
|
|
| 128 | + list($usec, $sec) = explode(" ", microtime());
|
|
| 129 | + $time = ((float)$usec + (float)$sec); |
|
| 130 | 130 | |
| 131 | - if (!isset($GLOBALS['qr_time_bench'])) |
|
| 132 | - $GLOBALS['qr_time_bench'] = array(); |
|
| 131 | + if (!isset($GLOBALS['qr_time_bench'])) |
|
| 132 | + $GLOBALS['qr_time_bench'] = array(); |
|
| 133 | 133 | |
| 134 | - $GLOBALS['qr_time_bench'][$markerId] = $time; |
|
| 135 | - } |
|
| 134 | + $GLOBALS['qr_time_bench'][$markerId] = $time; |
|
| 135 | + } |
|
| 136 | 136 | |
| 137 | - //---------------------------------------------------------------------- |
|
| 138 | - public static function timeBenchmark() |
|
| 139 | - {
|
|
| 140 | - self::markTime('finish');
|
|
| 137 | + //---------------------------------------------------------------------- |
|
| 138 | + public static function timeBenchmark() |
|
| 139 | + {
|
|
| 140 | + self::markTime('finish');
|
|
| 141 | 141 | |
| 142 | - $lastTime = 0; |
|
| 143 | - $startTime = 0; |
|
| 144 | - $p = 0; |
|
| 142 | + $lastTime = 0; |
|
| 143 | + $startTime = 0; |
|
| 144 | + $p = 0; |
|
| 145 | 145 | |
| 146 | - echo '<table cellpadding="3" cellspacing="1"> |
|
| 146 | + echo '<table cellpadding="3" cellspacing="1"> |
|
| 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) {
|
|
| 151 | - if ($p > 0) {
|
|
| 152 | - echo '<tr><th style="text-align:right">till '.$markerId.': </th><td>'.number_format($thisTime-$lastTime, 6).'s</td></tr>'; |
|
| 153 | - } else {
|
|
| 154 | - $startTime = $thisTime; |
|
| 155 | - } |
|
| 150 | + foreach($GLOBALS['qr_time_bench'] as $markerId=>$thisTime) {
|
|
| 151 | + if ($p > 0) {
|
|
| 152 | + echo '<tr><th style="text-align:right">till '.$markerId.': </th><td>'.number_format($thisTime-$lastTime, 6).'s</td></tr>'; |
|
| 153 | + } else {
|
|
| 154 | + $startTime = $thisTime; |
|
| 155 | + } |
|
| 156 | 156 | |
| 157 | - $p++; |
|
| 158 | - $lastTime = $thisTime; |
|
| 159 | - } |
|
| 157 | + $p++; |
|
| 158 | + $lastTime = $thisTime; |
|
| 159 | + } |
|
| 160 | 160 | |
| 161 | - echo '</tbody><tfoot> |
|
| 161 | + echo '</tbody><tfoot> |
|
| 162 | 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 | + } |
|
| 166 | 166 | |
| 167 | - } |
|
| 167 | + } |
|
| 168 | 168 | |
| 169 | - //########################################################################## |
|
| 169 | + //########################################################################## |
|
| 170 | 170 | |
| 171 | - QRtools::markTime('start');
|
|
| 172 | - |
|
| 173 | 171 | \ No newline at end of file |
| 172 | + QRtools::markTime('start');
|
|
| 173 | + |
|
| 174 | 174 | \ No newline at end of file |
@@ -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 | } |
@@ -22,74 +22,74 @@ |
||
| 22 | 22 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 23 | 23 | */ |
| 24 | 24 | |
| 25 | - define('QR_IMAGE', true);
|
|
| 25 | + define('QR_IMAGE', true);
|
|
| 26 | 26 | |
| 27 | - class QRimage {
|
|
| 27 | + class QRimage {
|
|
| 28 | 28 | |
| 29 | - //---------------------------------------------------------------------- |
|
| 30 | - public static function png($frame, $filename = false, $pixelPerPoint = 4, $outerFrame = 4,$saveandprint=FALSE) |
|
| 31 | - {
|
|
| 32 | - $image = self::image($frame, $pixelPerPoint, $outerFrame); |
|
| 29 | + //---------------------------------------------------------------------- |
|
| 30 | + public static function png($frame, $filename = false, $pixelPerPoint = 4, $outerFrame = 4,$saveandprint=FALSE) |
|
| 31 | + {
|
|
| 32 | + $image = self::image($frame, $pixelPerPoint, $outerFrame); |
|
| 33 | 33 | |
| 34 | - if ($filename === false) {
|
|
| 35 | - Header("Content-type: image/png");
|
|
| 36 | - ImagePng($image); |
|
| 37 | - } else {
|
|
| 38 | - if($saveandprint===TRUE){
|
|
| 39 | - ImagePng($image, $filename); |
|
| 40 | - header("Content-type: image/png");
|
|
| 41 | - ImagePng($image); |
|
| 42 | - }else{
|
|
| 43 | - ImagePng($image, $filename); |
|
| 44 | - } |
|
| 45 | - } |
|
| 34 | + if ($filename === false) {
|
|
| 35 | + Header("Content-type: image/png");
|
|
| 36 | + ImagePng($image); |
|
| 37 | + } else {
|
|
| 38 | + if($saveandprint===TRUE){
|
|
| 39 | + ImagePng($image, $filename); |
|
| 40 | + header("Content-type: image/png");
|
|
| 41 | + ImagePng($image); |
|
| 42 | + }else{
|
|
| 43 | + ImagePng($image, $filename); |
|
| 44 | + } |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - ImageDestroy($image); |
|
| 48 | - } |
|
| 47 | + ImageDestroy($image); |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - //---------------------------------------------------------------------- |
|
| 51 | - public static function jpg($frame, $filename = false, $pixelPerPoint = 8, $outerFrame = 4, $q = 85) |
|
| 52 | - {
|
|
| 53 | - $image = self::image($frame, $pixelPerPoint, $outerFrame); |
|
| 50 | + //---------------------------------------------------------------------- |
|
| 51 | + public static function jpg($frame, $filename = false, $pixelPerPoint = 8, $outerFrame = 4, $q = 85) |
|
| 52 | + {
|
|
| 53 | + $image = self::image($frame, $pixelPerPoint, $outerFrame); |
|
| 54 | 54 | |
| 55 | - if ($filename === false) {
|
|
| 56 | - Header("Content-type: image/jpeg");
|
|
| 57 | - ImageJpeg($image, null, $q); |
|
| 58 | - } else {
|
|
| 59 | - ImageJpeg($image, $filename, $q); |
|
| 60 | - } |
|
| 55 | + if ($filename === false) {
|
|
| 56 | + Header("Content-type: image/jpeg");
|
|
| 57 | + ImageJpeg($image, null, $q); |
|
| 58 | + } else {
|
|
| 59 | + ImageJpeg($image, $filename, $q); |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - ImageDestroy($image); |
|
| 63 | - } |
|
| 62 | + ImageDestroy($image); |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - //---------------------------------------------------------------------- |
|
| 66 | - private static function image($frame, $pixelPerPoint = 4, $outerFrame = 4) |
|
| 67 | - {
|
|
| 68 | - $h = count($frame); |
|
| 69 | - $w = strlen($frame[0]); |
|
| 65 | + //---------------------------------------------------------------------- |
|
| 66 | + private static function image($frame, $pixelPerPoint = 4, $outerFrame = 4) |
|
| 67 | + {
|
|
| 68 | + $h = count($frame); |
|
| 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 | - imagefill($base_image, 0, 0, $col[0]); |
|
| 79 | + imagefill($base_image, 0, 0, $col[0]); |
|
| 80 | 80 | |
| 81 | - for($y=0; $y<$h; $y++) {
|
|
| 82 | - for($x=0; $x<$w; $x++) {
|
|
| 83 | - if ($frame[$y][$x] == '1') {
|
|
| 84 | - ImageSetPixel($base_image,$x+$outerFrame,$y+$outerFrame,$col[1]); |
|
| 85 | - } |
|
| 86 | - } |
|
| 87 | - } |
|
| 81 | + for($y=0; $y<$h; $y++) {
|
|
| 82 | + for($x=0; $x<$w; $x++) {
|
|
| 83 | + if ($frame[$y][$x] == '1') {
|
|
| 84 | + ImageSetPixel($base_image,$x+$outerFrame,$y+$outerFrame,$col[1]); |
|
| 85 | + } |
|
| 86 | + } |
|
| 87 | + } |
|
| 88 | 88 | |
| 89 | - $target_image =ImageCreate($imgW * $pixelPerPoint, $imgH * $pixelPerPoint); |
|
| 90 | - ImageCopyResized($target_image, $base_image, 0, 0, 0, 0, $imgW * $pixelPerPoint, $imgH * $pixelPerPoint, $imgW, $imgH); |
|
| 91 | - ImageDestroy($base_image); |
|
| 89 | + $target_image =ImageCreate($imgW * $pixelPerPoint, $imgH * $pixelPerPoint); |
|
| 90 | + ImageCopyResized($target_image, $base_image, 0, 0, 0, 0, $imgW * $pixelPerPoint, $imgH * $pixelPerPoint, $imgW, $imgH); |
|
| 91 | + ImageDestroy($base_image); |
|
| 92 | 92 | |
| 93 | - return $target_image; |
|
| 94 | - } |
|
| 95 | - } |
|
| 96 | 93 | \ No newline at end of file |
| 94 | + return $target_image; |
|
| 95 | + } |
|
| 96 | + } |
|
| 97 | 97 | \ No newline at end of file |
@@ -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 | } |
@@ -70,17 +70,17 @@ discard block |
||
| 70 | 70 | /* not really important, this one; perhaps I could've put it inline with |
| 71 | 71 | * the rest. */ |
| 72 | 72 | function find_match($curlscore,$curcscore,$curgtlang,$langval,$charval, |
| 73 | - $gtlang) |
|
| 73 | + $gtlang) |
|
| 74 | 74 | { |
| 75 | 75 | if($curlscore < $langval) { |
| 76 | - $curlscore=$langval; |
|
| 77 | - $curcscore=$charval; |
|
| 78 | - $curgtlang=$gtlang; |
|
| 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; |
|
| 83 | - } |
|
| 80 | + if($curcscore < $charval) { |
|
| 81 | + $curcscore=$charval; |
|
| 82 | + $curgtlang=$gtlang; |
|
| 83 | + } |
|
| 84 | 84 | } |
| 85 | 85 | return array($curlscore, $curcscore, $curgtlang); |
| 86 | 86 | } |
@@ -88,22 +88,22 @@ discard block |
||
| 88 | 88 | function al2gt($gettextlangs, $mime) { |
| 89 | 89 | /* default to "everything is acceptable", as RFC2616 specifies */ |
| 90 | 90 | $acceptLang=(($_SERVER["HTTP_ACCEPT_LANGUAGE"] == '') ? '*' : |
| 91 | - $_SERVER["HTTP_ACCEPT_LANGUAGE"]); |
|
| 91 | + $_SERVER["HTTP_ACCEPT_LANGUAGE"]); |
|
| 92 | 92 | $acceptChar=(($_SERVER["HTTP_ACCEPT_CHARSET"] == '') ? '*' : |
| 93 | - $_SERVER["HTTP_ACCEPT_CHARSET"]); |
|
| 93 | + $_SERVER["HTTP_ACCEPT_CHARSET"]); |
|
| 94 | 94 | $alparts=@preg_split("/,/",$acceptLang); |
| 95 | 95 | $acparts=@preg_split("/,/",$acceptChar); |
| 96 | 96 | |
| 97 | 97 | /* Parse the contents of the Accept-Language header.*/ |
| 98 | 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]; |
|
| 104 | - } else { |
|
| 105 | - $alscores[$part]=1; |
|
| 106 | - } |
|
| 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]; |
|
| 104 | + } else { |
|
| 105 | + $alscores[$part]=1; |
|
| 106 | + } |
|
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | /* Do the same for the Accept-Charset header. */ |
@@ -119,17 +119,17 @@ discard block |
||
| 119 | 119 | $acscores["ISO-8859-1"]=2; |
| 120 | 120 | |
| 121 | 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]; |
|
| 127 | - } else { |
|
| 128 | - $acscores[strtoupper($part)]=1; |
|
| 129 | - } |
|
| 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]; |
|
| 127 | + } else { |
|
| 128 | + $acscores[strtoupper($part)]=1; |
|
| 129 | + } |
|
| 130 | 130 | } |
| 131 | 131 | if($acscores["ISO-8859-1"]==2) { |
| 132 | - $acscores["ISO-8859-1"]=(isset($acscores["*"])?$acscores["*"]:1); |
|
| 132 | + $acscores["ISO-8859-1"]=(isset($acscores["*"])?$acscores["*"]:1); |
|
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | /* |
@@ -142,31 +142,31 @@ discard block |
||
| 142 | 142 | $curgtlang=NULL; |
| 143 | 143 | foreach($gettextlangs as $gtlang) { |
| 144 | 144 | |
| 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); |
|
| 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); |
|
| 150 | 150 | |
| 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["*"])); |
|
| 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["*"])); |
|
| 158 | 158 | |
| 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], |
|
| 163 | - $tval[1], $gtlang); |
|
| 164 | - $curlscore=$arr[0]; |
|
| 165 | - $curcscore=$arr[1]; |
|
| 166 | - $curgtlang=$arr[2]; |
|
| 167 | - $found=TRUE; |
|
| 168 | - } |
|
| 169 | - } |
|
| 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], |
|
| 163 | + $tval[1], $gtlang); |
|
| 164 | + $curlscore=$arr[0]; |
|
| 165 | + $curcscore=$arr[1]; |
|
| 166 | + $curgtlang=$arr[2]; |
|
| 167 | + $found=TRUE; |
|
| 168 | + } |
|
| 169 | + } |
|
| 170 | 170 | } |
| 171 | 171 | |
| 172 | 172 | /* We must re-parse the gettext-string now, since we may have found it |
@@ -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"); |
@@ -74,38 +74,38 @@ discard block |
||
| 74 | 74 | $charset = NULL; |
| 75 | 75 | $modifier = NULL; |
| 76 | 76 | if ($locale) { |
| 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)) { |
|
| 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"]; |
|
| 87 | - |
|
| 88 | - if ($modifier) { |
|
| 89 | - if ($country) { |
|
| 90 | - if ($charset) |
|
| 91 | - array_push($locale_names, "${lang}_$country.$charset@$modifier"); |
|
| 92 | - array_push($locale_names, "${lang}_$country@$modifier"); |
|
| 93 | - } elseif ($charset) |
|
| 94 | - array_push($locale_names, "${lang}.$charset@$modifier"); |
|
| 95 | - array_push($locale_names, "$lang@$modifier"); |
|
| 96 | - } |
|
| 97 | - if ($country) { |
|
| 98 | - if ($charset) |
|
| 99 | - array_push($locale_names, "${lang}_$country.$charset"); |
|
| 100 | - array_push($locale_names, "${lang}_$country"); |
|
| 101 | - } elseif ($charset) |
|
| 102 | - array_push($locale_names, "${lang}.$charset"); |
|
| 103 | - array_push($locale_names, $lang); |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - // 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); |
|
| 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)) { |
|
| 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"]; |
|
| 87 | + |
|
| 88 | + if ($modifier) { |
|
| 89 | + if ($country) { |
|
| 90 | + if ($charset) |
|
| 91 | + array_push($locale_names, "${lang}_$country.$charset@$modifier"); |
|
| 92 | + array_push($locale_names, "${lang}_$country@$modifier"); |
|
| 93 | + } elseif ($charset) |
|
| 94 | + array_push($locale_names, "${lang}.$charset@$modifier"); |
|
| 95 | + array_push($locale_names, "$lang@$modifier"); |
|
| 96 | + } |
|
| 97 | + if ($country) { |
|
| 98 | + if ($charset) |
|
| 99 | + array_push($locale_names, "${lang}_$country.$charset"); |
|
| 100 | + array_push($locale_names, "${lang}_$country"); |
|
| 101 | + } elseif ($charset) |
|
| 102 | + array_push($locale_names, "${lang}.$charset"); |
|
| 103 | + array_push($locale_names, $lang); |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + // 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); |
|
| 109 | 109 | } |
| 110 | 110 | return $locale_names; |
| 111 | 111 | } |
@@ -114,60 +114,60 @@ discard block |
||
| 114 | 114 | * Utility function to get a StreamReader for the given text domain. |
| 115 | 115 | */ |
| 116 | 116 | function _get_reader($domain=null, $category=5, $enable_cache=true) { |
| 117 | - global $text_domains, $default_domain, $LC_CATEGORIES; |
|
| 118 | - if (!isset($domain)) $domain = $default_domain; |
|
| 119 | - if (!isset($text_domains[$domain]->l10n)) { |
|
| 120 | - // get the current locale |
|
| 121 | - $locale = _setlocale(LC_MESSAGES, 0); |
|
| 122 | - $bound_path = isset($text_domains[$domain]->path) ? |
|
| 123 | - $text_domains[$domain]->path : './'; |
|
| 124 | - $subpath = $LC_CATEGORIES[$category] ."/$domain.mo"; |
|
| 125 | - |
|
| 126 | - $locale_names = get_list_of_locales($locale); |
|
| 127 | - $input = null; |
|
| 128 | - foreach ($locale_names as $locale) { |
|
| 129 | - $full_path = $bound_path . $locale . "/" . $subpath; |
|
| 130 | - if (file_exists($full_path)) { |
|
| 131 | - $input = new FileReader($full_path); |
|
| 132 | - break; |
|
| 133 | - } |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - if (!array_key_exists($domain, $text_domains)) { |
|
| 137 | - // Initialize an empty domain object. |
|
| 138 | - $text_domains[$domain] = new domain(); |
|
| 139 | - } |
|
| 140 | - $text_domains[$domain]->l10n = new gettext_reader($input, |
|
| 141 | - $enable_cache); |
|
| 142 | - } |
|
| 143 | - return $text_domains[$domain]->l10n; |
|
| 117 | + global $text_domains, $default_domain, $LC_CATEGORIES; |
|
| 118 | + if (!isset($domain)) $domain = $default_domain; |
|
| 119 | + if (!isset($text_domains[$domain]->l10n)) { |
|
| 120 | + // get the current locale |
|
| 121 | + $locale = _setlocale(LC_MESSAGES, 0); |
|
| 122 | + $bound_path = isset($text_domains[$domain]->path) ? |
|
| 123 | + $text_domains[$domain]->path : './'; |
|
| 124 | + $subpath = $LC_CATEGORIES[$category] ."/$domain.mo"; |
|
| 125 | + |
|
| 126 | + $locale_names = get_list_of_locales($locale); |
|
| 127 | + $input = null; |
|
| 128 | + foreach ($locale_names as $locale) { |
|
| 129 | + $full_path = $bound_path . $locale . "/" . $subpath; |
|
| 130 | + if (file_exists($full_path)) { |
|
| 131 | + $input = new FileReader($full_path); |
|
| 132 | + break; |
|
| 133 | + } |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + if (!array_key_exists($domain, $text_domains)) { |
|
| 137 | + // Initialize an empty domain object. |
|
| 138 | + $text_domains[$domain] = new domain(); |
|
| 139 | + } |
|
| 140 | + $text_domains[$domain]->l10n = new gettext_reader($input, |
|
| 141 | + $enable_cache); |
|
| 142 | + } |
|
| 143 | + return $text_domains[$domain]->l10n; |
|
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | /** |
| 147 | 147 | * Returns whether we are using our emulated gettext API or PHP built-in one. |
| 148 | 148 | */ |
| 149 | 149 | function locale_emulation() { |
| 150 | - global $EMULATEGETTEXT; |
|
| 151 | - return $EMULATEGETTEXT; |
|
| 150 | + global $EMULATEGETTEXT; |
|
| 151 | + return $EMULATEGETTEXT; |
|
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | /** |
| 155 | 155 | * Checks if the current locale is supported on this system. |
| 156 | 156 | */ |
| 157 | 157 | function _check_locale_and_function($function=false) { |
| 158 | - global $EMULATEGETTEXT; |
|
| 159 | - if ($function and !function_exists($function)) |
|
| 160 | - return false; |
|
| 161 | - return !$EMULATEGETTEXT; |
|
| 158 | + global $EMULATEGETTEXT; |
|
| 159 | + if ($function and !function_exists($function)) |
|
| 160 | + return false; |
|
| 161 | + return !$EMULATEGETTEXT; |
|
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | /** |
| 165 | 165 | * Get the codeset for the given domain. |
| 166 | 166 | */ |
| 167 | 167 | function _get_codeset($domain=null) { |
| 168 | - global $text_domains, $default_domain, $LC_CATEGORIES; |
|
| 169 | - if (!isset($domain)) $domain = $default_domain; |
|
| 170 | - return (isset($text_domains[$domain]->codeset))? $text_domains[$domain]->codeset : ini_get('mbstring.internal_encoding'); |
|
| 168 | + global $text_domains, $default_domain, $LC_CATEGORIES; |
|
| 169 | + if (!isset($domain)) $domain = $default_domain; |
|
| 170 | + return (isset($text_domains[$domain]->codeset))? $text_domains[$domain]->codeset : ini_get('mbstring.internal_encoding'); |
|
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | /** |
@@ -176,9 +176,9 @@ discard block |
||
| 176 | 176 | function _encode($text) { |
| 177 | 177 | $target_encoding = _get_codeset(); |
| 178 | 178 | if (function_exists("mb_detect_encoding")) { |
| 179 | - $source_encoding = mb_detect_encoding($text); |
|
| 180 | - if ($source_encoding != $target_encoding) |
|
| 181 | - $text = mb_convert_encoding($text, $target_encoding, $source_encoding); |
|
| 179 | + $source_encoding = mb_detect_encoding($text); |
|
| 180 | + if ($source_encoding != $target_encoding) |
|
| 181 | + $text = mb_convert_encoding($text, $target_encoding, $source_encoding); |
|
| 182 | 182 | } |
| 183 | 183 | return $text; |
| 184 | 184 | } |
@@ -191,185 +191,185 @@ discard block |
||
| 191 | 191 | */ |
| 192 | 192 | function _get_default_locale($locale) { |
| 193 | 193 | if ($locale == '') // emulate variable support |
| 194 | - return getenv('LANG'); |
|
| 194 | + return getenv('LANG'); |
|
| 195 | 195 | else |
| 196 | - return $locale; |
|
| 196 | + return $locale; |
|
| 197 | 197 | } |
| 198 | 198 | |
| 199 | 199 | /** |
| 200 | 200 | * Sets a requested locale, if needed emulates it. |
| 201 | 201 | */ |
| 202 | 202 | function _setlocale($category, $locale) { |
| 203 | - global $CURRENTLOCALE, $EMULATEGETTEXT; |
|
| 204 | - 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 |
|
| 209 | - // even if we tried to read locale without setting it first |
|
| 210 | - return _setlocale($category, $CURRENTLOCALE); |
|
| 211 | - } else { |
|
| 212 | - if (function_exists('setlocale')) { |
|
| 213 | - $ret = setlocale($category, $locale); |
|
| 214 | - if (($locale == '' and !$ret) or // failed setting it by env |
|
| 215 | - ($locale != '' and $ret != $locale)) { // failed setting it |
|
| 216 | - // Failed setting it according to environment. |
|
| 217 | - $CURRENTLOCALE = _get_default_locale($locale); |
|
| 218 | - $EMULATEGETTEXT = 1; |
|
| 219 | - } else { |
|
| 220 | - $CURRENTLOCALE = $ret; |
|
| 221 | - $EMULATEGETTEXT = 0; |
|
| 222 | - } |
|
| 223 | - } else { |
|
| 224 | - // No function setlocale(), emulate it all. |
|
| 225 | - $CURRENTLOCALE = _get_default_locale($locale); |
|
| 226 | - $EMULATEGETTEXT = 1; |
|
| 227 | - } |
|
| 228 | - // Allow locale to be changed on the go for one translation domain. |
|
| 229 | - global $text_domains, $default_domain; |
|
| 230 | - if (array_key_exists($default_domain, $text_domains)) { |
|
| 231 | - unset($text_domains[$default_domain]->l10n); |
|
| 232 | - } |
|
| 233 | - return $CURRENTLOCALE; |
|
| 234 | - } |
|
| 203 | + global $CURRENTLOCALE, $EMULATEGETTEXT; |
|
| 204 | + 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 |
|
| 209 | + // even if we tried to read locale without setting it first |
|
| 210 | + return _setlocale($category, $CURRENTLOCALE); |
|
| 211 | + } else { |
|
| 212 | + if (function_exists('setlocale')) { |
|
| 213 | + $ret = setlocale($category, $locale); |
|
| 214 | + if (($locale == '' and !$ret) or // failed setting it by env |
|
| 215 | + ($locale != '' and $ret != $locale)) { // failed setting it |
|
| 216 | + // Failed setting it according to environment. |
|
| 217 | + $CURRENTLOCALE = _get_default_locale($locale); |
|
| 218 | + $EMULATEGETTEXT = 1; |
|
| 219 | + } else { |
|
| 220 | + $CURRENTLOCALE = $ret; |
|
| 221 | + $EMULATEGETTEXT = 0; |
|
| 222 | + } |
|
| 223 | + } else { |
|
| 224 | + // No function setlocale(), emulate it all. |
|
| 225 | + $CURRENTLOCALE = _get_default_locale($locale); |
|
| 226 | + $EMULATEGETTEXT = 1; |
|
| 227 | + } |
|
| 228 | + // Allow locale to be changed on the go for one translation domain. |
|
| 229 | + global $text_domains, $default_domain; |
|
| 230 | + if (array_key_exists($default_domain, $text_domains)) { |
|
| 231 | + unset($text_domains[$default_domain]->l10n); |
|
| 232 | + } |
|
| 233 | + return $CURRENTLOCALE; |
|
| 234 | + } |
|
| 235 | 235 | } |
| 236 | 236 | |
| 237 | 237 | /** |
| 238 | 238 | * Sets the path for a domain. |
| 239 | 239 | */ |
| 240 | 240 | function _bindtextdomain($domain, $path) { |
| 241 | - global $text_domains; |
|
| 242 | - // ensure $path ends with a slash ('/' should work for both, but lets still play nice) |
|
| 243 | - if (substr(php_uname(), 0, 7) == "Windows") { |
|
| 244 | - if ($path[strlen($path)-1] != '\\' and $path[strlen($path)-1] != '/') |
|
| 245 | - $path .= '\\'; |
|
| 246 | - } else { |
|
| 247 | - if ($path[strlen($path)-1] != '/') |
|
| 248 | - $path .= '/'; |
|
| 249 | - } |
|
| 250 | - if (!array_key_exists($domain, $text_domains)) { |
|
| 251 | - // Initialize an empty domain object. |
|
| 252 | - $text_domains[$domain] = new domain(); |
|
| 253 | - } |
|
| 254 | - $text_domains[$domain]->path = $path; |
|
| 241 | + global $text_domains; |
|
| 242 | + // ensure $path ends with a slash ('/' should work for both, but lets still play nice) |
|
| 243 | + if (substr(php_uname(), 0, 7) == "Windows") { |
|
| 244 | + if ($path[strlen($path)-1] != '\\' and $path[strlen($path)-1] != '/') |
|
| 245 | + $path .= '\\'; |
|
| 246 | + } else { |
|
| 247 | + if ($path[strlen($path)-1] != '/') |
|
| 248 | + $path .= '/'; |
|
| 249 | + } |
|
| 250 | + if (!array_key_exists($domain, $text_domains)) { |
|
| 251 | + // Initialize an empty domain object. |
|
| 252 | + $text_domains[$domain] = new domain(); |
|
| 253 | + } |
|
| 254 | + $text_domains[$domain]->path = $path; |
|
| 255 | 255 | } |
| 256 | 256 | |
| 257 | 257 | /** |
| 258 | 258 | * Specify the character encoding in which the messages from the DOMAIN message catalog will be returned. |
| 259 | 259 | */ |
| 260 | 260 | function _bind_textdomain_codeset($domain, $codeset) { |
| 261 | - global $text_domains; |
|
| 262 | - $text_domains[$domain]->codeset = $codeset; |
|
| 261 | + global $text_domains; |
|
| 262 | + $text_domains[$domain]->codeset = $codeset; |
|
| 263 | 263 | } |
| 264 | 264 | |
| 265 | 265 | /** |
| 266 | 266 | * Sets the default domain. |
| 267 | 267 | */ |
| 268 | 268 | function _textdomain($domain) { |
| 269 | - global $default_domain; |
|
| 270 | - $default_domain = $domain; |
|
| 269 | + global $default_domain; |
|
| 270 | + $default_domain = $domain; |
|
| 271 | 271 | } |
| 272 | 272 | |
| 273 | 273 | /** |
| 274 | 274 | * Lookup a message in the current domain. |
| 275 | 275 | */ |
| 276 | 276 | function _gettext($msgid) { |
| 277 | - $l10n = _get_reader(); |
|
| 278 | - return _encode($l10n->translate($msgid)); |
|
| 277 | + $l10n = _get_reader(); |
|
| 278 | + return _encode($l10n->translate($msgid)); |
|
| 279 | 279 | } |
| 280 | 280 | |
| 281 | 281 | /** |
| 282 | 282 | * Alias for gettext. |
| 283 | 283 | */ |
| 284 | 284 | function __($msgid) { |
| 285 | - return _gettext($msgid); |
|
| 285 | + return _gettext($msgid); |
|
| 286 | 286 | } |
| 287 | 287 | |
| 288 | 288 | /** |
| 289 | 289 | * Plural version of gettext. |
| 290 | 290 | */ |
| 291 | 291 | function _ngettext($singular, $plural, $number) { |
| 292 | - $l10n = _get_reader(); |
|
| 293 | - return _encode($l10n->ngettext($singular, $plural, $number)); |
|
| 292 | + $l10n = _get_reader(); |
|
| 293 | + return _encode($l10n->ngettext($singular, $plural, $number)); |
|
| 294 | 294 | } |
| 295 | 295 | |
| 296 | 296 | /** |
| 297 | 297 | * Override the current domain. |
| 298 | 298 | */ |
| 299 | 299 | function _dgettext($domain, $msgid) { |
| 300 | - $l10n = _get_reader($domain); |
|
| 301 | - return _encode($l10n->translate($msgid)); |
|
| 300 | + $l10n = _get_reader($domain); |
|
| 301 | + return _encode($l10n->translate($msgid)); |
|
| 302 | 302 | } |
| 303 | 303 | |
| 304 | 304 | /** |
| 305 | 305 | * Plural version of dgettext. |
| 306 | 306 | */ |
| 307 | 307 | function _dngettext($domain, $singular, $plural, $number) { |
| 308 | - $l10n = _get_reader($domain); |
|
| 309 | - return _encode($l10n->ngettext($singular, $plural, $number)); |
|
| 308 | + $l10n = _get_reader($domain); |
|
| 309 | + return _encode($l10n->ngettext($singular, $plural, $number)); |
|
| 310 | 310 | } |
| 311 | 311 | |
| 312 | 312 | /** |
| 313 | 313 | * Overrides the domain and category for a single lookup. |
| 314 | 314 | */ |
| 315 | 315 | function _dcgettext($domain, $msgid, $category) { |
| 316 | - $l10n = _get_reader($domain, $category); |
|
| 317 | - return _encode($l10n->translate($msgid)); |
|
| 316 | + $l10n = _get_reader($domain, $category); |
|
| 317 | + return _encode($l10n->translate($msgid)); |
|
| 318 | 318 | } |
| 319 | 319 | /** |
| 320 | 320 | * Plural version of dcgettext. |
| 321 | 321 | */ |
| 322 | 322 | function _dcngettext($domain, $singular, $plural, $number, $category) { |
| 323 | - $l10n = _get_reader($domain, $category); |
|
| 324 | - return _encode($l10n->ngettext($singular, $plural, $number)); |
|
| 323 | + $l10n = _get_reader($domain, $category); |
|
| 324 | + return _encode($l10n->ngettext($singular, $plural, $number)); |
|
| 325 | 325 | } |
| 326 | 326 | |
| 327 | 327 | /** |
| 328 | 328 | * Context version of gettext. |
| 329 | 329 | */ |
| 330 | 330 | function _pgettext($context, $msgid) { |
| 331 | - $l10n = _get_reader(); |
|
| 332 | - return _encode($l10n->pgettext($context, $msgid)); |
|
| 331 | + $l10n = _get_reader(); |
|
| 332 | + return _encode($l10n->pgettext($context, $msgid)); |
|
| 333 | 333 | } |
| 334 | 334 | |
| 335 | 335 | /** |
| 336 | 336 | * Override the current domain in a context gettext call. |
| 337 | 337 | */ |
| 338 | 338 | function _dpgettext($domain, $context, $msgid) { |
| 339 | - $l10n = _get_reader($domain); |
|
| 340 | - return _encode($l10n->pgettext($context, $msgid)); |
|
| 339 | + $l10n = _get_reader($domain); |
|
| 340 | + return _encode($l10n->pgettext($context, $msgid)); |
|
| 341 | 341 | } |
| 342 | 342 | |
| 343 | 343 | /** |
| 344 | 344 | * Overrides the domain and category for a single context-based lookup. |
| 345 | 345 | */ |
| 346 | 346 | function _dcpgettext($domain, $context, $msgid, $category) { |
| 347 | - $l10n = _get_reader($domain, $category); |
|
| 348 | - return _encode($l10n->pgettext($context, $msgid)); |
|
| 347 | + $l10n = _get_reader($domain, $category); |
|
| 348 | + return _encode($l10n->pgettext($context, $msgid)); |
|
| 349 | 349 | } |
| 350 | 350 | |
| 351 | 351 | /** |
| 352 | 352 | * Context version of ngettext. |
| 353 | 353 | */ |
| 354 | 354 | function _npgettext($context, $singular, $plural) { |
| 355 | - $l10n = _get_reader(); |
|
| 356 | - return _encode($l10n->npgettext($context, $singular, $plural)); |
|
| 355 | + $l10n = _get_reader(); |
|
| 356 | + return _encode($l10n->npgettext($context, $singular, $plural)); |
|
| 357 | 357 | } |
| 358 | 358 | |
| 359 | 359 | /** |
| 360 | 360 | * Override the current domain in a context ngettext call. |
| 361 | 361 | */ |
| 362 | 362 | function _dnpgettext($domain, $context, $singular, $plural) { |
| 363 | - $l10n = _get_reader($domain); |
|
| 364 | - return _encode($l10n->npgettext($context, $singular, $plural)); |
|
| 363 | + $l10n = _get_reader($domain); |
|
| 364 | + return _encode($l10n->npgettext($context, $singular, $plural)); |
|
| 365 | 365 | } |
| 366 | 366 | |
| 367 | 367 | /** |
| 368 | 368 | * Overrides the domain and category for a plural context-based lookup. |
| 369 | 369 | */ |
| 370 | 370 | function _dcnpgettext($domain, $context, $singular, $plural, $category) { |
| 371 | - $l10n = _get_reader($domain, $category); |
|
| 372 | - return _encode($l10n->npgettext($context, $singular, $plural)); |
|
| 371 | + $l10n = _get_reader($domain, $category); |
|
| 372 | + return _encode($l10n->npgettext($context, $singular, $plural)); |
|
| 373 | 373 | } |
| 374 | 374 | |
| 375 | 375 | |
@@ -380,99 +380,99 @@ discard block |
||
| 380 | 380 | // custom impl otherwise. |
| 381 | 381 | |
| 382 | 382 | function T_setlocale($category, $locale) { |
| 383 | - return _setlocale($category, $locale); |
|
| 383 | + return _setlocale($category, $locale); |
|
| 384 | 384 | } |
| 385 | 385 | |
| 386 | 386 | function T_bindtextdomain($domain, $path) { |
| 387 | - if (_check_locale_and_function()) return bindtextdomain($domain, $path); |
|
| 388 | - else return _bindtextdomain($domain, $path); |
|
| 387 | + if (_check_locale_and_function()) return bindtextdomain($domain, $path); |
|
| 388 | + else return _bindtextdomain($domain, $path); |
|
| 389 | 389 | } |
| 390 | 390 | function T_bind_textdomain_codeset($domain, $codeset) { |
| 391 | - // 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); |
|
| 391 | + // 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 | 395 | } |
| 396 | 396 | function T_textdomain($domain) { |
| 397 | - if (_check_locale_and_function()) return textdomain($domain); |
|
| 398 | - else return _textdomain($domain); |
|
| 397 | + if (_check_locale_and_function()) return textdomain($domain); |
|
| 398 | + else return _textdomain($domain); |
|
| 399 | 399 | } |
| 400 | 400 | function T_gettext($msgid) { |
| 401 | - if (_check_locale_and_function()) return gettext($msgid); |
|
| 402 | - else return _gettext($msgid); |
|
| 401 | + if (_check_locale_and_function()) return gettext($msgid); |
|
| 402 | + else return _gettext($msgid); |
|
| 403 | 403 | } |
| 404 | 404 | function T_($msgid) { |
| 405 | - if (_check_locale_and_function()) return _($msgid); |
|
| 406 | - return __($msgid); |
|
| 405 | + if (_check_locale_and_function()) return _($msgid); |
|
| 406 | + return __($msgid); |
|
| 407 | 407 | } |
| 408 | 408 | 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); |
|
| 409 | + if (_check_locale_and_function()) |
|
| 410 | + return ngettext($singular, $plural, $number); |
|
| 411 | + else return _ngettext($singular, $plural, $number); |
|
| 412 | 412 | } |
| 413 | 413 | function T_dgettext($domain, $msgid) { |
| 414 | - if (_check_locale_and_function()) return dgettext($domain, $msgid); |
|
| 415 | - else return _dgettext($domain, $msgid); |
|
| 414 | + if (_check_locale_and_function()) return dgettext($domain, $msgid); |
|
| 415 | + else return _dgettext($domain, $msgid); |
|
| 416 | 416 | } |
| 417 | 417 | 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); |
|
| 418 | + if (_check_locale_and_function()) |
|
| 419 | + return dngettext($domain, $singular, $plural, $number); |
|
| 420 | + else return _dngettext($domain, $singular, $plural, $number); |
|
| 421 | 421 | } |
| 422 | 422 | 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); |
|
| 423 | + if (_check_locale_and_function()) |
|
| 424 | + return dcgettext($domain, $msgid, $category); |
|
| 425 | + else return _dcgettext($domain, $msgid, $category); |
|
| 426 | 426 | } |
| 427 | 427 | 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); |
|
| 428 | + if (_check_locale_and_function()) |
|
| 429 | + return dcngettext($domain, $singular, $plural, $number, $category); |
|
| 430 | + else return _dcngettext($domain, $singular, $plural, $number, $category); |
|
| 431 | 431 | } |
| 432 | 432 | |
| 433 | 433 | function T_pgettext($context, $msgid) { |
| 434 | 434 | if (_check_locale_and_function('pgettext')) |
| 435 | - return pgettext($context, $msgid); |
|
| 435 | + return pgettext($context, $msgid); |
|
| 436 | 436 | else |
| 437 | - return _pgettext($context, $msgid); |
|
| 437 | + return _pgettext($context, $msgid); |
|
| 438 | 438 | } |
| 439 | 439 | |
| 440 | 440 | function T_dpgettext($domain, $context, $msgid) { |
| 441 | 441 | if (_check_locale_and_function('dpgettext')) |
| 442 | - return dpgettext($domain, $context, $msgid); |
|
| 442 | + return dpgettext($domain, $context, $msgid); |
|
| 443 | 443 | else |
| 444 | - return _dpgettext($domain, $context, $msgid); |
|
| 444 | + return _dpgettext($domain, $context, $msgid); |
|
| 445 | 445 | } |
| 446 | 446 | |
| 447 | 447 | function T_dcpgettext($domain, $context, $msgid, $category) { |
| 448 | 448 | if (_check_locale_and_function('dcpgettext')) |
| 449 | - return dcpgettext($domain, $context, $msgid, $category); |
|
| 449 | + return dcpgettext($domain, $context, $msgid, $category); |
|
| 450 | 450 | else |
| 451 | - return _dcpgettext($domain, $context, $msgid, $category); |
|
| 451 | + return _dcpgettext($domain, $context, $msgid, $category); |
|
| 452 | 452 | } |
| 453 | 453 | |
| 454 | 454 | 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); |
|
| 455 | + if (_check_locale_and_function('npgettext')) |
|
| 456 | + return npgettext($context, $singular, $plural, $number); |
|
| 457 | + else |
|
| 458 | + return _npgettext($context, $singular, $plural, $number); |
|
| 459 | 459 | } |
| 460 | 460 | |
| 461 | 461 | function T_dnpgettext($domain, $context, $singular, $plural, $number) { |
| 462 | 462 | if (_check_locale_and_function('dnpgettext')) |
| 463 | - return dnpgettext($domain, $context, $singular, $plural, $number); |
|
| 463 | + return dnpgettext($domain, $context, $singular, $plural, $number); |
|
| 464 | 464 | else |
| 465 | - return _dnpgettext($domain, $context, $singular, $plural, $number); |
|
| 465 | + return _dnpgettext($domain, $context, $singular, $plural, $number); |
|
| 466 | 466 | } |
| 467 | 467 | |
| 468 | 468 | function T_dcnpgettext($domain, $context, $singular, $plural, |
| 469 | - $number, $category) { |
|
| 470 | - if (_check_locale_and_function('dcnpgettext')) |
|
| 471 | - return dcnpgettext($domain, $context, $singular, |
|
| 472 | - $plural, $number, $category); |
|
| 473 | - else |
|
| 474 | - return _dcnpgettext($domain, $context, $singular, |
|
| 475 | - $plural, $number, $category); |
|
| 469 | + $number, $category) { |
|
| 470 | + if (_check_locale_and_function('dcnpgettext')) |
|
| 471 | + return dcnpgettext($domain, $context, $singular, |
|
| 472 | + $plural, $number, $category); |
|
| 473 | + else |
|
| 474 | + return _dcnpgettext($domain, $context, $singular, |
|
| 475 | + $plural, $number, $category); |
|
| 476 | 476 | } |
| 477 | 477 | |
| 478 | 478 | |
@@ -480,56 +480,56 @@ discard block |
||
| 480 | 480 | // Wrappers used as a drop in replacement for the standard gettext functions |
| 481 | 481 | |
| 482 | 482 | if (!function_exists('gettext')) { |
| 483 | - function bindtextdomain($domain, $path) { |
|
| 484 | - return _bindtextdomain($domain, $path); |
|
| 485 | - } |
|
| 486 | - function bind_textdomain_codeset($domain, $codeset) { |
|
| 487 | - return _bind_textdomain_codeset($domain, $codeset); |
|
| 488 | - } |
|
| 489 | - function textdomain($domain) { |
|
| 490 | - return _textdomain($domain); |
|
| 491 | - } |
|
| 492 | - function gettext($msgid) { |
|
| 493 | - return _gettext($msgid); |
|
| 494 | - } |
|
| 495 | - function _($msgid) { |
|
| 496 | - return __($msgid); |
|
| 497 | - } |
|
| 498 | - function ngettext($singular, $plural, $number) { |
|
| 499 | - return _ngettext($singular, $plural, $number); |
|
| 500 | - } |
|
| 501 | - function dgettext($domain, $msgid) { |
|
| 502 | - return _dgettext($domain, $msgid); |
|
| 503 | - } |
|
| 504 | - function dngettext($domain, $singular, $plural, $number) { |
|
| 505 | - return _dngettext($domain, $singular, $plural, $number); |
|
| 506 | - } |
|
| 507 | - function dcgettext($domain, $msgid, $category) { |
|
| 508 | - return _dcgettext($domain, $msgid, $category); |
|
| 509 | - } |
|
| 510 | - function dcngettext($domain, $singular, $plural, $number, $category) { |
|
| 511 | - return _dcngettext($domain, $singular, $plural, $number, $category); |
|
| 512 | - } |
|
| 513 | - function pgettext($context, $msgid) { |
|
| 514 | - return _pgettext($context, $msgid); |
|
| 515 | - } |
|
| 516 | - function npgettext($context, $singular, $plural, $number) { |
|
| 517 | - return _npgettext($context, $singular, $plural, $number); |
|
| 518 | - } |
|
| 519 | - function dpgettext($domain, $context, $msgid) { |
|
| 520 | - return _dpgettext($domain, $context, $msgid); |
|
| 521 | - } |
|
| 522 | - function dnpgettext($domain, $context, $singular, $plural, $number) { |
|
| 523 | - return _dnpgettext($domain, $context, $singular, $plural, $number); |
|
| 524 | - } |
|
| 525 | - function dcpgettext($domain, $context, $msgid, $category) { |
|
| 526 | - return _dcpgettext($domain, $context, $msgid, $category); |
|
| 527 | - } |
|
| 528 | - function dcnpgettext($domain, $context, $singular, $plural, |
|
| 529 | - $number, $category) { |
|
| 530 | - return _dcnpgettext($domain, $context, $singular, $plural, |
|
| 531 | - $number, $category); |
|
| 532 | - } |
|
| 483 | + function bindtextdomain($domain, $path) { |
|
| 484 | + return _bindtextdomain($domain, $path); |
|
| 485 | + } |
|
| 486 | + function bind_textdomain_codeset($domain, $codeset) { |
|
| 487 | + return _bind_textdomain_codeset($domain, $codeset); |
|
| 488 | + } |
|
| 489 | + function textdomain($domain) { |
|
| 490 | + return _textdomain($domain); |
|
| 491 | + } |
|
| 492 | + function gettext($msgid) { |
|
| 493 | + return _gettext($msgid); |
|
| 494 | + } |
|
| 495 | + function _($msgid) { |
|
| 496 | + return __($msgid); |
|
| 497 | + } |
|
| 498 | + function ngettext($singular, $plural, $number) { |
|
| 499 | + return _ngettext($singular, $plural, $number); |
|
| 500 | + } |
|
| 501 | + function dgettext($domain, $msgid) { |
|
| 502 | + return _dgettext($domain, $msgid); |
|
| 503 | + } |
|
| 504 | + function dngettext($domain, $singular, $plural, $number) { |
|
| 505 | + return _dngettext($domain, $singular, $plural, $number); |
|
| 506 | + } |
|
| 507 | + function dcgettext($domain, $msgid, $category) { |
|
| 508 | + return _dcgettext($domain, $msgid, $category); |
|
| 509 | + } |
|
| 510 | + function dcngettext($domain, $singular, $plural, $number, $category) { |
|
| 511 | + return _dcngettext($domain, $singular, $plural, $number, $category); |
|
| 512 | + } |
|
| 513 | + function pgettext($context, $msgid) { |
|
| 514 | + return _pgettext($context, $msgid); |
|
| 515 | + } |
|
| 516 | + function npgettext($context, $singular, $plural, $number) { |
|
| 517 | + return _npgettext($context, $singular, $plural, $number); |
|
| 518 | + } |
|
| 519 | + function dpgettext($domain, $context, $msgid) { |
|
| 520 | + return _dpgettext($domain, $context, $msgid); |
|
| 521 | + } |
|
| 522 | + function dnpgettext($domain, $context, $singular, $plural, $number) { |
|
| 523 | + return _dnpgettext($domain, $context, $singular, $plural, $number); |
|
| 524 | + } |
|
| 525 | + function dcpgettext($domain, $context, $msgid, $category) { |
|
| 526 | + return _dcpgettext($domain, $context, $msgid, $category); |
|
| 527 | + } |
|
| 528 | + function dcnpgettext($domain, $context, $singular, $plural, |
|
| 529 | + $number, $category) { |
|
| 530 | + return _dcnpgettext($domain, $context, $singular, $plural, |
|
| 531 | + $number, $category); |
|
| 532 | + } |
|
| 533 | 533 | } |
| 534 | 534 | |
| 535 | 535 | ?> |
@@ -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)) { |
@@ -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 | |
@@ -26,22 +26,22 @@ discard block |
||
| 26 | 26 | class StreamReader { |
| 27 | 27 | // should return a string [FIXME: perhaps return array of bytes?] |
| 28 | 28 | function read($bytes) { |
| 29 | - return false; |
|
| 29 | + return false; |
|
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | // should return new position |
| 33 | 33 | function seekto($position) { |
| 34 | - return false; |
|
| 34 | + return false; |
|
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | // returns current position |
| 38 | 38 | function currentpos() { |
| 39 | - return false; |
|
| 39 | + return false; |
|
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | // returns length of entire stream (limit for seekto()s) |
| 43 | 43 | function length() { |
| 44 | - return false; |
|
| 44 | + return false; |
|
| 45 | 45 | } |
| 46 | 46 | }; |
| 47 | 47 | |
@@ -50,32 +50,32 @@ discard block |
||
| 50 | 50 | var $_str; |
| 51 | 51 | |
| 52 | 52 | function StringReader($str='') { |
| 53 | - $this->_str = $str; |
|
| 54 | - $this->_pos = 0; |
|
| 53 | + $this->_str = $str; |
|
| 54 | + $this->_pos = 0; |
|
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | function read($bytes) { |
| 58 | - $data = substr($this->_str, $this->_pos, $bytes); |
|
| 59 | - $this->_pos += $bytes; |
|
| 60 | - if (strlen($this->_str)<$this->_pos) |
|
| 61 | - $this->_pos = strlen($this->_str); |
|
| 58 | + $data = substr($this->_str, $this->_pos, $bytes); |
|
| 59 | + $this->_pos += $bytes; |
|
| 60 | + if (strlen($this->_str)<$this->_pos) |
|
| 61 | + $this->_pos = strlen($this->_str); |
|
| 62 | 62 | |
| 63 | - return $data; |
|
| 63 | + return $data; |
|
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | function seekto($pos) { |
| 67 | - $this->_pos = $pos; |
|
| 68 | - if (strlen($this->_str)<$this->_pos) |
|
| 69 | - $this->_pos = strlen($this->_str); |
|
| 70 | - return $this->_pos; |
|
| 67 | + $this->_pos = $pos; |
|
| 68 | + if (strlen($this->_str)<$this->_pos) |
|
| 69 | + $this->_pos = strlen($this->_str); |
|
| 70 | + return $this->_pos; |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | function currentpos() { |
| 74 | - return $this->_pos; |
|
| 74 | + return $this->_pos; |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | function length() { |
| 78 | - return strlen($this->_str); |
|
| 78 | + return strlen($this->_str); |
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | }; |
@@ -87,55 +87,55 @@ discard block |
||
| 87 | 87 | var $_length; |
| 88 | 88 | |
| 89 | 89 | function FileReader($filename) { |
| 90 | - if (file_exists($filename)) { |
|
| 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) { |
|
| 96 | - $this->error = 3; // Cannot read file, probably permissions |
|
| 97 | - return false; |
|
| 98 | - } |
|
| 99 | - } else { |
|
| 100 | - $this->error = 2; // File doesn't exist |
|
| 101 | - return false; |
|
| 102 | - } |
|
| 92 | + $this->_length=filesize($filename); |
|
| 93 | + $this->_pos = 0; |
|
| 94 | + $this->_fd = fopen($filename,'rb'); |
|
| 95 | + if (!$this->_fd) { |
|
| 96 | + $this->error = 3; // Cannot read file, probably permissions |
|
| 97 | + return false; |
|
| 98 | + } |
|
| 99 | + } else { |
|
| 100 | + $this->error = 2; // File doesn't exist |
|
| 101 | + return false; |
|
| 102 | + } |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | function read($bytes) { |
| 106 | - if ($bytes) { |
|
| 107 | - fseek($this->_fd, $this->_pos); |
|
| 106 | + if ($bytes) { |
|
| 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) { |
|
| 113 | - $chunk = fread($this->_fd, $bytes); |
|
| 114 | - $data .= $chunk; |
|
| 115 | - $bytes -= strlen($chunk); |
|
| 116 | - } |
|
| 117 | - $this->_pos = ftell($this->_fd); |
|
| 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 | + $chunk = fread($this->_fd, $bytes); |
|
| 114 | + $data .= $chunk; |
|
| 115 | + $bytes -= strlen($chunk); |
|
| 116 | + } |
|
| 117 | + $this->_pos = ftell($this->_fd); |
|
| 118 | 118 | |
| 119 | - return $data; |
|
| 120 | - } else return ''; |
|
| 119 | + return $data; |
|
| 120 | + } else return ''; |
|
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | function seekto($pos) { |
| 124 | - fseek($this->_fd, $pos); |
|
| 125 | - $this->_pos = ftell($this->_fd); |
|
| 126 | - return $this->_pos; |
|
| 124 | + fseek($this->_fd, $pos); |
|
| 125 | + $this->_pos = ftell($this->_fd); |
|
| 126 | + return $this->_pos; |
|
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | function currentpos() { |
| 130 | - return $this->_pos; |
|
| 130 | + return $this->_pos; |
|
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | function length() { |
| 134 | - return $this->_length; |
|
| 134 | + return $this->_length; |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | function close() { |
| 138 | - fclose($this->_fd); |
|
| 138 | + fclose($this->_fd); |
|
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | }; |
@@ -144,22 +144,22 @@ discard block |
||
| 144 | 144 | // over it (it assumes knowledge of StringReader internals) |
| 145 | 145 | class CachedFileReader extends StringReader { |
| 146 | 146 | function CachedFileReader($filename) { |
| 147 | - if (file_exists($filename)) { |
|
| 148 | - |
|
| 149 | - $length=filesize($filename); |
|
| 150 | - $fd = fopen($filename,'rb'); |
|
| 151 | - |
|
| 152 | - if (!$fd) { |
|
| 153 | - $this->error = 3; // Cannot read file, probably permissions |
|
| 154 | - return false; |
|
| 155 | - } |
|
| 156 | - $this->_str = fread($fd, $length); |
|
| 157 | - fclose($fd); |
|
| 158 | - |
|
| 159 | - } else { |
|
| 160 | - $this->error = 2; // File doesn't exist |
|
| 161 | - return false; |
|
| 162 | - } |
|
| 147 | + if (file_exists($filename)) { |
|
| 148 | + |
|
| 149 | + $length=filesize($filename); |
|
| 150 | + $fd = fopen($filename,'rb'); |
|
| 151 | + |
|
| 152 | + if (!$fd) { |
|
| 153 | + $this->error = 3; // Cannot read file, probably permissions |
|
| 154 | + return false; |
|
| 155 | + } |
|
| 156 | + $this->_str = fread($fd, $length); |
|
| 157 | + fclose($fd); |
|
| 158 | + |
|
| 159 | + } else { |
|
| 160 | + $this->error = 2; // File doesn't exist |
|
| 161 | + return false; |
|
| 162 | + } |
|
| 163 | 163 | } |
| 164 | 164 | }; |
| 165 | 165 | |
@@ -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 |
@@ -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) { |
@@ -61,19 +61,19 @@ discard block |
||
| 61 | 61 | * @return Integer from the Stream |
| 62 | 62 | */ |
| 63 | 63 | function readint() { |
| 64 | - if ($this->BYTEORDER == 0) { |
|
| 65 | - // low endian |
|
| 66 | - $input=unpack('V', $this->STREAM->read(4)); |
|
| 67 | - return array_shift($input); |
|
| 68 | - } else { |
|
| 69 | - // big endian |
|
| 70 | - $input=unpack('N', $this->STREAM->read(4)); |
|
| 71 | - return array_shift($input); |
|
| 72 | - } |
|
| 73 | - } |
|
| 64 | + if ($this->BYTEORDER == 0) { |
|
| 65 | + // low endian |
|
| 66 | + $input=unpack('V', $this->STREAM->read(4)); |
|
| 67 | + return array_shift($input); |
|
| 68 | + } else { |
|
| 69 | + // big endian |
|
| 70 | + $input=unpack('N', $this->STREAM->read(4)); |
|
| 71 | + return array_shift($input); |
|
| 72 | + } |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | 75 | function read($bytes) { |
| 76 | - return $this->STREAM->read($bytes); |
|
| 76 | + return $this->STREAM->read($bytes); |
|
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | /** |
@@ -83,13 +83,13 @@ discard block |
||
| 83 | 83 | * @return Array of Integers |
| 84 | 84 | */ |
| 85 | 85 | function readintarray($count) { |
| 86 | - if ($this->BYTEORDER == 0) { |
|
| 87 | - // low endian |
|
| 88 | - return unpack('V'.$count, $this->STREAM->read(4 * $count)); |
|
| 89 | - } else { |
|
| 90 | - // big endian |
|
| 91 | - return unpack('N'.$count, $this->STREAM->read(4 * $count)); |
|
| 92 | - } |
|
| 86 | + if ($this->BYTEORDER == 0) { |
|
| 87 | + // low endian |
|
| 88 | + return unpack('V'.$count, $this->STREAM->read(4 * $count)); |
|
| 89 | + } else { |
|
| 90 | + // big endian |
|
| 91 | + return unpack('N'.$count, $this->STREAM->read(4 * $count)); |
|
| 92 | + } |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | /** |
@@ -99,35 +99,35 @@ discard block |
||
| 99 | 99 | * @param boolean enable_cache Enable or disable caching of strings (default on) |
| 100 | 100 | */ |
| 101 | 101 | function __construct($Reader, $enable_cache = true) { |
| 102 | - // If there isn't a StreamReader, turn on short circuit mode. |
|
| 103 | - if (! $Reader || isset($Reader->error) ) { |
|
| 104 | - $this->short_circuit = true; |
|
| 105 | - return; |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - // Caching can be turned off |
|
| 109 | - $this->enable_cache = $enable_cache; |
|
| 110 | - |
|
| 111 | - $MAGIC1 = "\x95\x04\x12\xde"; |
|
| 112 | - $MAGIC2 = "\xde\x12\x04\x95"; |
|
| 113 | - |
|
| 114 | - $this->STREAM = $Reader; |
|
| 115 | - $magic = $this->read(4); |
|
| 116 | - if ($magic == $MAGIC1) { |
|
| 117 | - $this->BYTEORDER = 1; |
|
| 118 | - } elseif ($magic == $MAGIC2) { |
|
| 119 | - $this->BYTEORDER = 0; |
|
| 120 | - } else { |
|
| 121 | - $this->error = 1; // not MO file |
|
| 122 | - return false; |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - // FIXME: Do we care about revision? We should. |
|
| 126 | - $revision = $this->readint(); |
|
| 127 | - |
|
| 128 | - $this->total = $this->readint(); |
|
| 129 | - $this->originals = $this->readint(); |
|
| 130 | - $this->translations = $this->readint(); |
|
| 102 | + // If there isn't a StreamReader, turn on short circuit mode. |
|
| 103 | + if (! $Reader || isset($Reader->error) ) { |
|
| 104 | + $this->short_circuit = true; |
|
| 105 | + return; |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + // Caching can be turned off |
|
| 109 | + $this->enable_cache = $enable_cache; |
|
| 110 | + |
|
| 111 | + $MAGIC1 = "\x95\x04\x12\xde"; |
|
| 112 | + $MAGIC2 = "\xde\x12\x04\x95"; |
|
| 113 | + |
|
| 114 | + $this->STREAM = $Reader; |
|
| 115 | + $magic = $this->read(4); |
|
| 116 | + if ($magic == $MAGIC1) { |
|
| 117 | + $this->BYTEORDER = 1; |
|
| 118 | + } elseif ($magic == $MAGIC2) { |
|
| 119 | + $this->BYTEORDER = 0; |
|
| 120 | + } else { |
|
| 121 | + $this->error = 1; // not MO file |
|
| 122 | + return false; |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + // FIXME: Do we care about revision? We should. |
|
| 126 | + $revision = $this->readint(); |
|
| 127 | + |
|
| 128 | + $this->total = $this->readint(); |
|
| 129 | + $this->originals = $this->readint(); |
|
| 130 | + $this->translations = $this->readint(); |
|
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | /** |
@@ -138,32 +138,32 @@ discard block |
||
| 138 | 138 | * @access private |
| 139 | 139 | */ |
| 140 | 140 | function load_tables() { |
| 141 | - if (is_array($this->cache_translations) && |
|
| 142 | - is_array($this->table_originals) && |
|
| 143 | - is_array($this->table_translations)) |
|
| 144 | - return; |
|
| 145 | - |
|
| 146 | - /* get original and translations tables */ |
|
| 147 | - if (!is_array($this->table_originals)) { |
|
| 148 | - $this->STREAM->seekto($this->originals); |
|
| 149 | - $this->table_originals = $this->readintarray($this->total * 2); |
|
| 150 | - } |
|
| 151 | - if (!is_array($this->table_translations)) { |
|
| 152 | - $this->STREAM->seekto($this->translations); |
|
| 153 | - $this->table_translations = $this->readintarray($this->total * 2); |
|
| 154 | - } |
|
| 155 | - |
|
| 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++) { |
|
| 160 | - $this->STREAM->seekto($this->table_originals[$i * 2 + 2]); |
|
| 161 | - $original = $this->STREAM->read($this->table_originals[$i * 2 + 1]); |
|
| 162 | - $this->STREAM->seekto($this->table_translations[$i * 2 + 2]); |
|
| 163 | - $translation = $this->STREAM->read($this->table_translations[$i * 2 + 1]); |
|
| 164 | - $this->cache_translations[$original] = $translation; |
|
| 165 | - } |
|
| 166 | - } |
|
| 141 | + if (is_array($this->cache_translations) && |
|
| 142 | + is_array($this->table_originals) && |
|
| 143 | + is_array($this->table_translations)) |
|
| 144 | + return; |
|
| 145 | + |
|
| 146 | + /* get original and translations tables */ |
|
| 147 | + if (!is_array($this->table_originals)) { |
|
| 148 | + $this->STREAM->seekto($this->originals); |
|
| 149 | + $this->table_originals = $this->readintarray($this->total * 2); |
|
| 150 | + } |
|
| 151 | + if (!is_array($this->table_translations)) { |
|
| 152 | + $this->STREAM->seekto($this->translations); |
|
| 153 | + $this->table_translations = $this->readintarray($this->total * 2); |
|
| 154 | + } |
|
| 155 | + |
|
| 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++) { |
|
| 160 | + $this->STREAM->seekto($this->table_originals[$i * 2 + 2]); |
|
| 161 | + $original = $this->STREAM->read($this->table_originals[$i * 2 + 1]); |
|
| 162 | + $this->STREAM->seekto($this->table_translations[$i * 2 + 2]); |
|
| 163 | + $translation = $this->STREAM->read($this->table_translations[$i * 2 + 1]); |
|
| 164 | + $this->cache_translations[$original] = $translation; |
|
| 165 | + } |
|
| 166 | + } |
|
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | /** |
@@ -174,13 +174,13 @@ discard block |
||
| 174 | 174 | * @return string Requested string if found, otherwise '' |
| 175 | 175 | */ |
| 176 | 176 | function get_original_string($num) { |
| 177 | - $length = $this->table_originals[$num * 2 + 1]; |
|
| 178 | - $offset = $this->table_originals[$num * 2 + 2]; |
|
| 179 | - if (! $length) |
|
| 180 | - return ''; |
|
| 181 | - $this->STREAM->seekto($offset); |
|
| 182 | - $data = $this->STREAM->read($length); |
|
| 183 | - return (string)$data; |
|
| 177 | + $length = $this->table_originals[$num * 2 + 1]; |
|
| 178 | + $offset = $this->table_originals[$num * 2 + 2]; |
|
| 179 | + if (! $length) |
|
| 180 | + return ''; |
|
| 181 | + $this->STREAM->seekto($offset); |
|
| 182 | + $data = $this->STREAM->read($length); |
|
| 183 | + return (string)$data; |
|
| 184 | 184 | } |
| 185 | 185 | |
| 186 | 186 | /** |
@@ -191,13 +191,13 @@ discard block |
||
| 191 | 191 | * @return string Requested string if found, otherwise '' |
| 192 | 192 | */ |
| 193 | 193 | function get_translation_string($num) { |
| 194 | - $length = $this->table_translations[$num * 2 + 1]; |
|
| 195 | - $offset = $this->table_translations[$num * 2 + 2]; |
|
| 196 | - if (! $length) |
|
| 197 | - return ''; |
|
| 198 | - $this->STREAM->seekto($offset); |
|
| 199 | - $data = $this->STREAM->read($length); |
|
| 200 | - return (string)$data; |
|
| 194 | + $length = $this->table_translations[$num * 2 + 1]; |
|
| 195 | + $offset = $this->table_translations[$num * 2 + 2]; |
|
| 196 | + if (! $length) |
|
| 197 | + return ''; |
|
| 198 | + $this->STREAM->seekto($offset); |
|
| 199 | + $data = $this->STREAM->read($length); |
|
| 200 | + return (string)$data; |
|
| 201 | 201 | } |
| 202 | 202 | |
| 203 | 203 | /** |
@@ -210,35 +210,35 @@ discard block |
||
| 210 | 210 | * @return int string number (offset in originals table) |
| 211 | 211 | */ |
| 212 | 212 | function find_string($string, $start = -1, $end = -1) { |
| 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; |
|
| 217 | - } |
|
| 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) |
|
| 222 | - return $start; |
|
| 223 | - else |
|
| 224 | - return -1; |
|
| 225 | - } else if ($start > $end) { |
|
| 226 | - // start > end -> turn around and start over |
|
| 227 | - return $this->find_string($string, $end, $start); |
|
| 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) |
|
| 233 | - // string is exactly in the middle => return it |
|
| 234 | - return $half; |
|
| 235 | - else if ($cmp < 0) |
|
| 236 | - // The string is in the upper half |
|
| 237 | - return $this->find_string($string, $start, $half); |
|
| 238 | - else |
|
| 239 | - // The string is in the lower half |
|
| 240 | - return $this->find_string($string, $half, $end); |
|
| 241 | - } |
|
| 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; |
|
| 217 | + } |
|
| 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) |
|
| 222 | + return $start; |
|
| 223 | + else |
|
| 224 | + return -1; |
|
| 225 | + } else if ($start > $end) { |
|
| 226 | + // start > end -> turn around and start over |
|
| 227 | + return $this->find_string($string, $end, $start); |
|
| 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) |
|
| 233 | + // string is exactly in the middle => return it |
|
| 234 | + return $half; |
|
| 235 | + else if ($cmp < 0) |
|
| 236 | + // The string is in the upper half |
|
| 237 | + return $this->find_string($string, $start, $half); |
|
| 238 | + else |
|
| 239 | + // The string is in the lower half |
|
| 240 | + return $this->find_string($string, $half, $end); |
|
| 241 | + } |
|
| 242 | 242 | } |
| 243 | 243 | |
| 244 | 244 | /** |
@@ -249,24 +249,24 @@ discard block |
||
| 249 | 249 | * @return string translated string (or original, if not found) |
| 250 | 250 | */ |
| 251 | 251 | function translate($string) { |
| 252 | - if ($this->short_circuit) |
|
| 253 | - return $string; |
|
| 254 | - $this->load_tables(); |
|
| 255 | - |
|
| 256 | - if ($this->enable_cache) { |
|
| 257 | - // 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; |
|
| 262 | - } else { |
|
| 263 | - // Caching not enabled, try to find string |
|
| 264 | - $num = $this->find_string($string); |
|
| 265 | - if ($num == -1) |
|
| 266 | - return $string; |
|
| 267 | - else |
|
| 268 | - return $this->get_translation_string($num); |
|
| 269 | - } |
|
| 252 | + if ($this->short_circuit) |
|
| 253 | + return $string; |
|
| 254 | + $this->load_tables(); |
|
| 255 | + |
|
| 256 | + if ($this->enable_cache) { |
|
| 257 | + // 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; |
|
| 262 | + } else { |
|
| 263 | + // Caching not enabled, try to find string |
|
| 264 | + $num = $this->find_string($string); |
|
| 265 | + if ($num == -1) |
|
| 266 | + return $string; |
|
| 267 | + else |
|
| 268 | + return $this->get_translation_string($num); |
|
| 269 | + } |
|
| 270 | 270 | } |
| 271 | 271 | |
| 272 | 272 | /** |
@@ -276,32 +276,32 @@ discard block |
||
| 276 | 276 | * @return string sanitized plural form expression |
| 277 | 277 | */ |
| 278 | 278 | function sanitize_plural_expression($expr) { |
| 279 | - // Get rid of disallowed characters. |
|
| 280 | - $expr = preg_replace('@[^a-zA-Z0-9_:;\(\)\?\|\&=!<>+*/\%-]@', '', $expr); |
|
| 281 | - |
|
| 282 | - // Add parenthesis for tertiary '?' operator. |
|
| 283 | - $expr .= ';'; |
|
| 284 | - $res = ''; |
|
| 285 | - $p = 0; |
|
| 286 | - for ($i = 0; $i < strlen($expr); $i++) { |
|
| 287 | - $ch = $expr[$i]; |
|
| 288 | - switch ($ch) { |
|
| 289 | - case '?': |
|
| 290 | - $res .= ' ? ('; |
|
| 291 | - $p++; |
|
| 292 | - break; |
|
| 293 | - case ':': |
|
| 294 | - $res .= ') : ('; |
|
| 295 | - break; |
|
| 296 | - case ';': |
|
| 297 | - $res .= str_repeat( ')', $p) . ';'; |
|
| 298 | - $p = 0; |
|
| 299 | - break; |
|
| 300 | - default: |
|
| 301 | - $res .= $ch; |
|
| 302 | - } |
|
| 303 | - } |
|
| 304 | - return $res; |
|
| 279 | + // Get rid of disallowed characters. |
|
| 280 | + $expr = preg_replace('@[^a-zA-Z0-9_:;\(\)\?\|\&=!<>+*/\%-]@', '', $expr); |
|
| 281 | + |
|
| 282 | + // Add parenthesis for tertiary '?' operator. |
|
| 283 | + $expr .= ';'; |
|
| 284 | + $res = ''; |
|
| 285 | + $p = 0; |
|
| 286 | + for ($i = 0; $i < strlen($expr); $i++) { |
|
| 287 | + $ch = $expr[$i]; |
|
| 288 | + switch ($ch) { |
|
| 289 | + case '?': |
|
| 290 | + $res .= ' ? ('; |
|
| 291 | + $p++; |
|
| 292 | + break; |
|
| 293 | + case ':': |
|
| 294 | + $res .= ') : ('; |
|
| 295 | + break; |
|
| 296 | + case ';': |
|
| 297 | + $res .= str_repeat( ')', $p) . ';'; |
|
| 298 | + $p = 0; |
|
| 299 | + break; |
|
| 300 | + default: |
|
| 301 | + $res .= $ch; |
|
| 302 | + } |
|
| 303 | + } |
|
| 304 | + return $res; |
|
| 305 | 305 | } |
| 306 | 306 | |
| 307 | 307 | /** |
@@ -311,11 +311,11 @@ discard block |
||
| 311 | 311 | * @return string verbatim plural form header field |
| 312 | 312 | */ |
| 313 | 313 | 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;"; |
|
| 318 | - return $expr; |
|
| 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;"; |
|
| 318 | + return $expr; |
|
| 319 | 319 | } |
| 320 | 320 | |
| 321 | 321 | /** |
@@ -325,21 +325,21 @@ discard block |
||
| 325 | 325 | * @return string plural form header |
| 326 | 326 | */ |
| 327 | 327 | function get_plural_forms() { |
| 328 | - // lets assume message number 0 is header |
|
| 329 | - // this is true, right? |
|
| 330 | - $this->load_tables(); |
|
| 331 | - |
|
| 332 | - // cache header field for plural forms |
|
| 333 | - if (! is_string($this->pluralheader)) { |
|
| 334 | - if ($this->enable_cache) { |
|
| 335 | - $header = $this->cache_translations[""]; |
|
| 336 | - } else { |
|
| 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); |
|
| 341 | - } |
|
| 342 | - return $this->pluralheader; |
|
| 328 | + // lets assume message number 0 is header |
|
| 329 | + // this is true, right? |
|
| 330 | + $this->load_tables(); |
|
| 331 | + |
|
| 332 | + // cache header field for plural forms |
|
| 333 | + if (! is_string($this->pluralheader)) { |
|
| 334 | + if ($this->enable_cache) { |
|
| 335 | + $header = $this->cache_translations[""]; |
|
| 336 | + } else { |
|
| 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); |
|
| 341 | + } |
|
| 342 | + return $this->pluralheader; |
|
| 343 | 343 | } |
| 344 | 344 | |
| 345 | 345 | /** |
@@ -350,21 +350,21 @@ discard block |
||
| 350 | 350 | * @return int array index of the right plural form |
| 351 | 351 | */ |
| 352 | 352 | function select_string($n) { |
| 353 | - if (!is_int($n)) { |
|
| 354 | - throw new InvalidArgumentException( |
|
| 355 | - "Select_string only accepts integers: " . $n); |
|
| 356 | - } |
|
| 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); |
|
| 361 | - |
|
| 362 | - $total = 0; |
|
| 363 | - $plural = 0; |
|
| 364 | - |
|
| 365 | - eval("$string"); |
|
| 366 | - if ($plural >= $total) $plural = $total - 1; |
|
| 367 | - return $plural; |
|
| 353 | + if (!is_int($n)) { |
|
| 354 | + throw new InvalidArgumentException( |
|
| 355 | + "Select_string only accepts integers: " . $n); |
|
| 356 | + } |
|
| 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); |
|
| 361 | + |
|
| 362 | + $total = 0; |
|
| 363 | + $plural = 0; |
|
| 364 | + |
|
| 365 | + eval("$string"); |
|
| 366 | + if ($plural >= $total) $plural = $total - 1; |
|
| 367 | + return $plural; |
|
| 368 | 368 | } |
| 369 | 369 | |
| 370 | 370 | /** |
@@ -377,58 +377,58 @@ discard block |
||
| 377 | 377 | * @return translated plural form |
| 378 | 378 | */ |
| 379 | 379 | function ngettext($single, $plural, $number) { |
| 380 | - if ($this->short_circuit) { |
|
| 381 | - if ($number != 1) |
|
| 382 | - return $plural; |
|
| 383 | - else |
|
| 384 | - return $single; |
|
| 385 | - } |
|
| 386 | - |
|
| 387 | - // find out the appropriate form |
|
| 388 | - $select = $this->select_string($number); |
|
| 389 | - |
|
| 390 | - // this should contains all strings separated by NULLs |
|
| 391 | - $key = $single . chr(0) . $plural; |
|
| 392 | - |
|
| 393 | - |
|
| 394 | - if ($this->enable_cache) { |
|
| 395 | - if (! array_key_exists($key, $this->cache_translations)) { |
|
| 396 | - return ($number != 1) ? $plural : $single; |
|
| 397 | - } else { |
|
| 398 | - $result = $this->cache_translations[$key]; |
|
| 399 | - $list = explode(chr(0), $result); |
|
| 400 | - return $list[$select]; |
|
| 401 | - } |
|
| 402 | - } else { |
|
| 403 | - $num = $this->find_string($key); |
|
| 404 | - if ($num == -1) { |
|
| 405 | - return ($number != 1) ? $plural : $single; |
|
| 406 | - } else { |
|
| 407 | - $result = $this->get_translation_string($num); |
|
| 408 | - $list = explode(chr(0), $result); |
|
| 409 | - return $list[$select]; |
|
| 410 | - } |
|
| 411 | - } |
|
| 380 | + if ($this->short_circuit) { |
|
| 381 | + if ($number != 1) |
|
| 382 | + return $plural; |
|
| 383 | + else |
|
| 384 | + return $single; |
|
| 385 | + } |
|
| 386 | + |
|
| 387 | + // find out the appropriate form |
|
| 388 | + $select = $this->select_string($number); |
|
| 389 | + |
|
| 390 | + // this should contains all strings separated by NULLs |
|
| 391 | + $key = $single . chr(0) . $plural; |
|
| 392 | + |
|
| 393 | + |
|
| 394 | + if ($this->enable_cache) { |
|
| 395 | + if (! array_key_exists($key, $this->cache_translations)) { |
|
| 396 | + return ($number != 1) ? $plural : $single; |
|
| 397 | + } else { |
|
| 398 | + $result = $this->cache_translations[$key]; |
|
| 399 | + $list = explode(chr(0), $result); |
|
| 400 | + return $list[$select]; |
|
| 401 | + } |
|
| 402 | + } else { |
|
| 403 | + $num = $this->find_string($key); |
|
| 404 | + if ($num == -1) { |
|
| 405 | + return ($number != 1) ? $plural : $single; |
|
| 406 | + } else { |
|
| 407 | + $result = $this->get_translation_string($num); |
|
| 408 | + $list = explode(chr(0), $result); |
|
| 409 | + return $list[$select]; |
|
| 410 | + } |
|
| 411 | + } |
|
| 412 | 412 | } |
| 413 | 413 | |
| 414 | 414 | function pgettext($context, $msgid) { |
| 415 | - $key = $context . chr(4) . $msgid; |
|
| 416 | - $ret = $this->translate($key); |
|
| 417 | - if (strpos($ret, "\004") !== FALSE) { |
|
| 418 | - return $msgid; |
|
| 419 | - } else { |
|
| 420 | - return $ret; |
|
| 421 | - } |
|
| 415 | + $key = $context . chr(4) . $msgid; |
|
| 416 | + $ret = $this->translate($key); |
|
| 417 | + if (strpos($ret, "\004") !== FALSE) { |
|
| 418 | + return $msgid; |
|
| 419 | + } else { |
|
| 420 | + return $ret; |
|
| 421 | + } |
|
| 422 | 422 | } |
| 423 | 423 | |
| 424 | 424 | function npgettext($context, $singular, $plural, $number) { |
| 425 | - $key = $context . chr(4) . $singular; |
|
| 426 | - $ret = $this->ngettext($key, $plural, $number); |
|
| 427 | - if (strpos($ret, "\004") !== FALSE) { |
|
| 428 | - return $singular; |
|
| 429 | - } else { |
|
| 430 | - return $ret; |
|
| 431 | - } |
|
| 425 | + $key = $context . chr(4) . $singular; |
|
| 426 | + $ret = $this->ngettext($key, $plural, $number); |
|
| 427 | + if (strpos($ret, "\004") !== FALSE) { |
|
| 428 | + return $singular; |
|
| 429 | + } else { |
|
| 430 | + return $ret; |
|
| 431 | + } |
|
| 432 | 432 | |
| 433 | 433 | } |
| 434 | 434 | } |
@@ -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; |
@@ -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 |
@@ -93,9 +93,9 @@ discard block |
||
| 93 | 93 | <?php |
| 94 | 94 | foreach (PluginHost::getInstance()->get_plugins() as $n => $p) { |
| 95 | 95 | if (method_exists($p, "get_js")) { |
| 96 | - $script = $p->get_js(); |
|
| 96 | + $script = $p->get_js(); |
|
| 97 | 97 | |
| 98 | - if ($script) { |
|
| 98 | + if ($script) { |
|
| 99 | 99 | echo "try { |
| 100 | 100 | $script |
| 101 | 101 | } catch (e) { |
@@ -146,10 +146,10 @@ 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) { |
|
| 150 | - echo $p->hook_feed_tree(); |
|
| 151 | - } |
|
| 152 | - ?> |
|
| 149 | + foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_FEED_TREE) as $p) { |
|
| 150 | + echo $p->hook_feed_tree(); |
|
| 151 | + } |
|
| 152 | + ?> |
|
| 153 | 153 | <div id="feedTree"></div> |
| 154 | 154 | </div> |
| 155 | 155 | |
@@ -167,10 +167,10 @@ discard block |
||
| 167 | 167 | title="<?php echo __('Updates are available from Git.') ?>">new_releases</i> |
| 168 | 168 | |
| 169 | 169 | <?php |
| 170 | - foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_MAIN_TOOLBAR_BUTTON) as $p) { |
|
| 171 | - echo $p->hook_main_toolbar_button(); |
|
| 172 | - } |
|
| 173 | - ?> |
|
| 170 | + foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_MAIN_TOOLBAR_BUTTON) as $p) { |
|
| 171 | + echo $p->hook_main_toolbar_button(); |
|
| 172 | + } |
|
| 173 | + ?> |
|
| 174 | 174 | |
| 175 | 175 | <form id="toolbar-headlines" action="" style="order : 10" onsubmit='return false'> |
| 176 | 176 | |
@@ -220,10 +220,10 @@ discard block |
||
| 220 | 220 | <div class="action-chooser" style="order : 30"> |
| 221 | 221 | |
| 222 | 222 | <?php |
| 223 | - foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_TOOLBAR_BUTTON) as $p) { |
|
| 224 | - echo $p->hook_toolbar_button(); |
|
| 225 | - } |
|
| 226 | - ?> |
|
| 223 | + foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_TOOLBAR_BUTTON) as $p) { |
|
| 224 | + echo $p->hook_toolbar_button(); |
|
| 225 | + } |
|
| 226 | + ?> |
|
| 227 | 227 | |
| 228 | 228 | <div dojoType="fox.form.DropDownButton" class="action-button" title="<?php echo __('Actions...') ?>"> |
| 229 | 229 | <span><i class="material-icons">menu</i></span> |
@@ -242,10 +242,10 @@ discard block |
||
| 242 | 242 | <div dojoType="dijit.MenuItem" onclick="App.onActionSelected('qmcHKhelp')"><?php echo __('Keyboard shortcuts help') ?></div> |
| 243 | 243 | |
| 244 | 244 | <?php |
| 245 | - foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_ACTION_ITEM) as $p) { |
|
| 246 | - echo $p->hook_action_item(); |
|
| 247 | - } |
|
| 248 | - ?> |
|
| 245 | + foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_ACTION_ITEM) as $p) { |
|
| 246 | + echo $p->hook_action_item(); |
|
| 247 | + } |
|
| 248 | + ?> |
|
| 249 | 249 | |
| 250 | 250 | <?php if (!$_SESSION["hide_logout"]) { ?> |
| 251 | 251 | <div dojoType="dijit.MenuItem" onclick="App.onActionSelected('qmcLogout')"><?php echo __('Logout') ?></div> |
@@ -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"; |
@@ -19,7 +19,9 @@ |
||
| 19 | 19 | require_once "config.php"; |
| 20 | 20 | require_once "db-prefs.php"; |
| 21 | 21 | |
| 22 | - if (!init_plugins()) return; |
|
| 22 | + if (!init_plugins()) { |
|
| 23 | + return; |
|
| 24 | + } |
|
| 23 | 25 | |
| 24 | 26 | login_sequence(); |
| 25 | 27 | |
@@ -13,7 +13,7 @@ |
||
| 13 | 13 | } |
| 14 | 14 | |
| 15 | 15 | function get_js() { |
| 16 | - return file_get_contents(__DIR__ . "/init.js"); |
|
| 16 | + return file_get_contents(__DIR__."/init.js"); |
|
| 17 | 17 | } |
| 18 | 18 | |
| 19 | 19 | function api_version() { |