@@ -99,9 +99,7 @@ |
||
99 | 99 | * Get the data from the cache. |
100 | 100 | * @param string $catalogue The translation section. |
101 | 101 | * @param string $culture The translation locale, e.g. "en_AU". |
102 | - * @param string $filename If the source is a file, this file's modified |
|
103 | - * time is newer than the cache's modified time, no cache hit. |
|
104 | - * @return mixed Boolean FALSE if no cache hit. Otherwise, translation |
|
102 | + * @return false|string Boolean FALSE if no cache hit. Otherwise, translation |
|
105 | 103 | * table data for the specified section and locale. |
106 | 104 | */ |
107 | 105 | public function get($catalogue, $culture, $lastmodified=0) |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | /** |
9 | 9 | * Load the cache lite library. |
10 | 10 | */ |
11 | -require_once(dirname(__FILE__).'/TCache_Lite.php'); |
|
11 | +require_once(dirname(__FILE__) . '/TCache_Lite.php'); |
|
12 | 12 | |
13 | 13 | /** |
14 | 14 | * Cache the translation table into the file system. |
@@ -37,15 +37,15 @@ discard block |
||
37 | 37 | */ |
38 | 38 | public function __construct($cacheDir) |
39 | 39 | { |
40 | - $cacheDir = $cacheDir.'/'; |
|
40 | + $cacheDir = $cacheDir . '/'; |
|
41 | 41 | |
42 | - if(!is_dir($cacheDir)) |
|
42 | + if (!is_dir($cacheDir)) |
|
43 | 43 | throw new Exception( |
44 | - 'The cache directory '.$cacheDir.' does not exists.'. |
|
44 | + 'The cache directory ' . $cacheDir . ' does not exists.' . |
|
45 | 45 | 'The cache directory must be writable by the server.'); |
46 | - if(!is_writable($cacheDir)) |
|
46 | + if (!is_writable($cacheDir)) |
|
47 | 47 | throw new Exception( |
48 | - 'The cache directory '.$cacheDir.' must be writable '. |
|
48 | + 'The cache directory ' . $cacheDir . ' must be writable ' . |
|
49 | 49 | 'by the server.'); |
50 | 50 | |
51 | 51 | $options = array( |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | */ |
73 | 73 | public function setLifeTime($time) |
74 | 74 | { |
75 | - $this->lifetime = (int)$time; |
|
75 | + $this->lifetime = (int) $time; |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | /** |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | */ |
83 | 83 | protected function getID($catalogue, $culture) |
84 | 84 | { |
85 | - return $catalogue.':'.$culture; |
|
85 | + return $catalogue . ':' . $culture; |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | /** |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | */ |
93 | 93 | protected function getGroup($catalogue, $culture) |
94 | 94 | { |
95 | - return $catalogue.':'.get_class($this); |
|
95 | + return $catalogue . ':' . get_class($this); |
|
96 | 96 | } |
97 | 97 | |
98 | 98 | /** |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | * @return mixed Boolean FALSE if no cache hit. Otherwise, translation |
105 | 105 | * table data for the specified section and locale. |
106 | 106 | */ |
107 | - public function get($catalogue, $culture, $lastmodified=0) |
|
107 | + public function get($catalogue, $culture, $lastmodified = 0) |
|
108 | 108 | { |
109 | 109 | $ID = $this->getID($catalogue, $culture); |
110 | 110 | $group = $this->getGroup($catalogue, $culture); |
@@ -113,13 +113,13 @@ discard block |
||
113 | 113 | |
114 | 114 | $cache = $this->cache->getCacheFile(); |
115 | 115 | |
116 | - if(is_file($cache) == false) |
|
116 | + if (is_file($cache) == false) |
|
117 | 117 | return false; |
118 | 118 | |
119 | 119 | |
120 | - $lastmodified = (int)$lastmodified; |
|
120 | + $lastmodified = (int) $lastmodified; |
|
121 | 121 | |
122 | - if($lastmodified <= 0 || $lastmodified > filemtime($cache)) |
|
122 | + if ($lastmodified <= 0 || $lastmodified > filemtime($cache)) |
|
123 | 123 | return false; |
124 | 124 | |
125 | 125 | //echo '@@ Cache hit: "'.$ID.'" : "'.$group.'"'; |
@@ -39,14 +39,16 @@ discard block |
||
39 | 39 | { |
40 | 40 | $cacheDir = $cacheDir.'/'; |
41 | 41 | |
42 | - if(!is_dir($cacheDir)) |
|
43 | - throw new Exception( |
|
42 | + if(!is_dir($cacheDir)) { |
|
43 | + throw new Exception( |
|
44 | 44 | 'The cache directory '.$cacheDir.' does not exists.'. |
45 | 45 | 'The cache directory must be writable by the server.'); |
46 | - if(!is_writable($cacheDir)) |
|
47 | - throw new Exception( |
|
46 | + } |
|
47 | + if(!is_writable($cacheDir)) { |
|
48 | + throw new Exception( |
|
48 | 49 | 'The cache directory '.$cacheDir.' must be writable '. |
49 | 50 | 'by the server.'); |
51 | + } |
|
50 | 52 | |
51 | 53 | $options = array( |
52 | 54 | 'cacheDir' => $cacheDir, |
@@ -113,14 +115,16 @@ discard block |
||
113 | 115 | |
114 | 116 | $cache = $this->cache->getCacheFile(); |
115 | 117 | |
116 | - if(is_file($cache) == false) |
|
117 | - return false; |
|
118 | + if(is_file($cache) == false) { |
|
119 | + return false; |
|
120 | + } |
|
118 | 121 | |
119 | 122 | |
120 | 123 | $lastmodified = (int)$lastmodified; |
121 | 124 | |
122 | - if($lastmodified <= 0 || $lastmodified > filemtime($cache)) |
|
123 | - return false; |
|
125 | + if($lastmodified <= 0 || $lastmodified > filemtime($cache)) { |
|
126 | + return false; |
|
127 | + } |
|
124 | 128 | |
125 | 129 | //echo '@@ Cache hit: "'.$ID.'" : "'.$group.'"'; |
126 | 130 | //echo "<br>\n"; |
@@ -111,6 +111,7 @@ discard block |
||
111 | 111 | /** |
112 | 112 | * Sets the charset for message output. |
113 | 113 | * @param string charset, default is UTF-8 |
114 | + * @param string $charset |
|
114 | 115 | */ |
115 | 116 | public function setCharset($charset) |
116 | 117 | { |
@@ -171,9 +172,9 @@ discard block |
||
171 | 172 | |
172 | 173 | /** |
173 | 174 | * Do string translation. |
174 | - * @param string the string to translate. |
|
175 | + * @param string string string to translate. |
|
175 | 176 | * @param array a list of string to substitute. |
176 | - * @param string get the translation from a particular message |
|
177 | + * @param string string the translation from a particular message |
|
177 | 178 | * catalogue. |
178 | 179 | * @return string translated string. |
179 | 180 | */ |
@@ -20,12 +20,12 @@ discard block |
||
20 | 20 | /** |
21 | 21 | * Get the MessageSource classes. |
22 | 22 | */ |
23 | -require_once(dirname(__FILE__).'/MessageSource.php'); |
|
23 | +require_once(dirname(__FILE__) . '/MessageSource.php'); |
|
24 | 24 | |
25 | 25 | /** |
26 | 26 | * Get the encoding utilities |
27 | 27 | */ |
28 | -require_once(dirname(__FILE__).'/util.php'); |
|
28 | +require_once(dirname(__FILE__) . '/util.php'); |
|
29 | 29 | |
30 | 30 | /** |
31 | 31 | * MessageFormat class. |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | * The prefix and suffix to append to untranslated messages. |
82 | 82 | * @var array |
83 | 83 | */ |
84 | - protected $postscript = array('',''); |
|
84 | + protected $postscript = array('', ''); |
|
85 | 85 | |
86 | 86 | /** |
87 | 87 | * Set the default catalogue. |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | * @param MessageSource the source of translation messages. |
103 | 103 | * @param string charset for the message output. |
104 | 104 | */ |
105 | - function __construct(IMessageSource $source, $charset='UTF-8') |
|
105 | + function __construct(IMessageSource $source, $charset = 'UTF-8') |
|
106 | 106 | { |
107 | 107 | $this->source = $source; |
108 | 108 | $this->setCharset($charset); |
@@ -135,10 +135,10 @@ discard block |
||
135 | 135 | */ |
136 | 136 | protected function loadCatalogue($catalogue) |
137 | 137 | { |
138 | - if(in_array($catalogue,$this->catagloues)) |
|
138 | + if (in_array($catalogue, $this->catagloues)) |
|
139 | 139 | return; |
140 | 140 | |
141 | - if($this->source->load($catalogue)) |
|
141 | + if ($this->source->load($catalogue)) |
|
142 | 142 | { |
143 | 143 | $this->messages[$catalogue] = $this->source->read(); |
144 | 144 | $this->catagloues[] = $catalogue; |
@@ -158,14 +158,14 @@ discard block |
||
158 | 158 | * catalogue. |
159 | 159 | * @return string translated string. |
160 | 160 | */ |
161 | - public function format($string,$args=array(), $catalogue=null, $charset=null) |
|
161 | + public function format($string, $args = array(), $catalogue = null, $charset = null) |
|
162 | 162 | { |
163 | - if(empty($charset)) $charset = $this->getCharset(); |
|
163 | + if (empty($charset)) $charset = $this->getCharset(); |
|
164 | 164 | |
165 | 165 | //force args as UTF-8 |
166 | - foreach($args as $k => $v) |
|
166 | + foreach ($args as $k => $v) |
|
167 | 167 | $args[$k] = I18N_toUTF8($v, $charset); |
168 | - $s = $this->formatString(I18N_toUTF8($string, $charset),$args,$catalogue); |
|
168 | + $s = $this->formatString(I18N_toUTF8($string, $charset), $args, $catalogue); |
|
169 | 169 | return I18N_toEncoding($s, $charset); |
170 | 170 | } |
171 | 171 | |
@@ -177,11 +177,11 @@ discard block |
||
177 | 177 | * catalogue. |
178 | 178 | * @return string translated string. |
179 | 179 | */ |
180 | - protected function formatString($string, $args=array(), $catalogue=null) |
|
180 | + protected function formatString($string, $args = array(), $catalogue = null) |
|
181 | 181 | { |
182 | - if(empty($catalogue)) |
|
182 | + if (empty($catalogue)) |
|
183 | 183 | { |
184 | - if(empty($this->Catalogue)) |
|
184 | + if (empty($this->Catalogue)) |
|
185 | 185 | $catalogue = 'messages'; |
186 | 186 | else |
187 | 187 | $catalogue = $this->Catalogue; |
@@ -189,29 +189,29 @@ discard block |
||
189 | 189 | |
190 | 190 | $this->loadCatalogue($catalogue); |
191 | 191 | |
192 | - if(empty($args)) |
|
192 | + if (empty($args)) |
|
193 | 193 | $args = array(); |
194 | 194 | |
195 | - foreach($this->messages[$catalogue] as $variant) |
|
195 | + foreach ($this->messages[$catalogue] as $variant) |
|
196 | 196 | { |
197 | 197 | // foreach of the translation units |
198 | - foreach($variant as $source => $result) |
|
198 | + foreach ($variant as $source => $result) |
|
199 | 199 | { |
200 | 200 | // we found it, so return the target translation |
201 | - if($source == $string) |
|
201 | + if ($source == $string) |
|
202 | 202 | { |
203 | 203 | //check if it contains only strings. |
204 | - if(is_string($result)) |
|
204 | + if (is_string($result)) |
|
205 | 205 | $target = $result; |
206 | 206 | else |
207 | 207 | { |
208 | 208 | $target = $result[0]; |
209 | 209 | } |
210 | 210 | //found, but untranslated |
211 | - if(empty($target)) |
|
211 | + if (empty($target)) |
|
212 | 212 | { |
213 | - return $this->postscript[0]. |
|
214 | - strtr($string, $args). |
|
213 | + return $this->postscript[0] . |
|
214 | + strtr($string, $args) . |
|
215 | 215 | $this->postscript[1]; |
216 | 216 | } |
217 | 217 | else |
@@ -223,8 +223,8 @@ discard block |
||
223 | 223 | // well we did not find the translation string. |
224 | 224 | $this->source->append($string); |
225 | 225 | |
226 | - return $this->postscript[0]. |
|
227 | - strtr($string, $args). |
|
226 | + return $this->postscript[0] . |
|
227 | + strtr($string, $args) . |
|
228 | 228 | $this->postscript[1]; |
229 | 229 | } |
230 | 230 | |
@@ -245,7 +245,7 @@ discard block |
||
245 | 245 | */ |
246 | 246 | function setUntranslatedPS($postscript) |
247 | 247 | { |
248 | - if(is_array($postscript) && count($postscript)>=2) |
|
248 | + if (is_array($postscript) && count($postscript) >= 2) |
|
249 | 249 | { |
250 | 250 | $this->postscript[0] = $postscript[0]; |
251 | 251 | $this->postscript[1] = $postscript[1]; |
@@ -135,8 +135,9 @@ discard block |
||
135 | 135 | */ |
136 | 136 | protected function loadCatalogue($catalogue) |
137 | 137 | { |
138 | - if(in_array($catalogue,$this->catagloues)) |
|
139 | - return; |
|
138 | + if(in_array($catalogue,$this->catagloues)) { |
|
139 | + return; |
|
140 | + } |
|
140 | 141 | |
141 | 142 | if($this->source->load($catalogue)) |
142 | 143 | { |
@@ -160,11 +161,14 @@ discard block |
||
160 | 161 | */ |
161 | 162 | public function format($string,$args=array(), $catalogue=null, $charset=null) |
162 | 163 | { |
163 | - if(empty($charset)) $charset = $this->getCharset(); |
|
164 | + if(empty($charset)) { |
|
165 | + $charset = $this->getCharset(); |
|
166 | + } |
|
164 | 167 | |
165 | 168 | //force args as UTF-8 |
166 | - foreach($args as $k => $v) |
|
167 | - $args[$k] = I18N_toUTF8($v, $charset); |
|
169 | + foreach($args as $k => $v) { |
|
170 | + $args[$k] = I18N_toUTF8($v, $charset); |
|
171 | + } |
|
168 | 172 | $s = $this->formatString(I18N_toUTF8($string, $charset),$args,$catalogue); |
169 | 173 | return I18N_toEncoding($s, $charset); |
170 | 174 | } |
@@ -181,16 +185,18 @@ discard block |
||
181 | 185 | { |
182 | 186 | if(empty($catalogue)) |
183 | 187 | { |
184 | - if(empty($this->Catalogue)) |
|
185 | - $catalogue = 'messages'; |
|
186 | - else |
|
187 | - $catalogue = $this->Catalogue; |
|
188 | + if(empty($this->Catalogue)) { |
|
189 | + $catalogue = 'messages'; |
|
190 | + } else { |
|
191 | + $catalogue = $this->Catalogue; |
|
192 | + } |
|
188 | 193 | } |
189 | 194 | |
190 | 195 | $this->loadCatalogue($catalogue); |
191 | 196 | |
192 | - if(empty($args)) |
|
193 | - $args = array(); |
|
197 | + if(empty($args)) { |
|
198 | + $args = array(); |
|
199 | + } |
|
194 | 200 | |
195 | 201 | foreach($this->messages[$catalogue] as $variant) |
196 | 202 | { |
@@ -201,9 +207,9 @@ discard block |
||
201 | 207 | if($source == $string) |
202 | 208 | { |
203 | 209 | //check if it contains only strings. |
204 | - if(is_string($result)) |
|
205 | - $target = $result; |
|
206 | - else |
|
210 | + if(is_string($result)) { |
|
211 | + $target = $result; |
|
212 | + } else |
|
207 | 213 | { |
208 | 214 | $target = $result[0]; |
209 | 215 | } |
@@ -213,9 +219,9 @@ discard block |
||
213 | 219 | return $this->postscript[0]. |
214 | 220 | strtr($string, $args). |
215 | 221 | $this->postscript[1]; |
222 | + } else { |
|
223 | + return strtr($target, $args); |
|
216 | 224 | } |
217 | - else |
|
218 | - return strtr($target, $args); |
|
219 | 225 | } |
220 | 226 | } |
221 | 227 | } |
@@ -252,6 +252,7 @@ discard block |
||
252 | 252 | /** |
253 | 253 | * Set the culture for this message source. |
254 | 254 | * @param string culture name |
255 | + * @param string $culture |
|
255 | 256 | */ |
256 | 257 | public function setCulture($culture) |
257 | 258 | { |
@@ -270,6 +271,7 @@ discard block |
||
270 | 271 | /** |
271 | 272 | * Get the last modified unix-time for this particular catalogue+variant. |
272 | 273 | * @param string catalogue+variant |
274 | + * @param string $source |
|
273 | 275 | * @return int last modified in unix-time format. |
274 | 276 | */ |
275 | 277 | protected function getLastModified($source) |
@@ -281,6 +283,7 @@ discard block |
||
281 | 283 | * Load the message for a particular catalogue+variant. |
282 | 284 | * This methods needs to implemented by subclasses. |
283 | 285 | * @param string catalogue+variant. |
286 | + * @param string $variant |
|
284 | 287 | * @return array of translation messages. |
285 | 288 | */ |
286 | 289 | protected function &loadData($variant) |
@@ -301,6 +304,7 @@ discard block |
||
301 | 304 | /** |
302 | 305 | * Determine if the source is valid. |
303 | 306 | * @param string catalogue+variant |
307 | + * @param string $source |
|
304 | 308 | * @return boolean true if valid, false otherwise. |
305 | 309 | */ |
306 | 310 | protected function isValidSource($source) |
@@ -312,6 +316,7 @@ discard block |
||
312 | 316 | * Get all the variants of a particular catalogue. |
313 | 317 | * This method must be implemented by subclasses. |
314 | 318 | * @param string catalogue name |
319 | + * @param string $catalogue |
|
315 | 320 | * @return array list of all variants for this catalogue. |
316 | 321 | */ |
317 | 322 | protected function getCatalogueList($catalogue) |
@@ -110,15 +110,15 @@ |
||
110 | 110 | /** |
111 | 111 | * Factory method to instantiate a new MessageSource depending on the |
112 | 112 | * source type. The allowed source types are 'XLIFF', 'gettext' and |
113 | - * 'Database'. The source parameter depends on the source type. |
|
114 | - * For 'gettext' and 'XLIFF', 'source' should point to the directory |
|
115 | - * where the messages are stored. |
|
116 | - * For 'Database', 'source' must be a valid connection id. |
|
117 | - * If one of the deprecated types 'MySQL' or 'SQLite' is used, |
|
118 | - * 'source' must contain a valid DSN. |
|
113 | + * 'Database'. The source parameter depends on the source type. |
|
114 | + * For 'gettext' and 'XLIFF', 'source' should point to the directory |
|
115 | + * where the messages are stored. |
|
116 | + * For 'Database', 'source' must be a valid connection id. |
|
117 | + * If one of the deprecated types 'MySQL' or 'SQLite' is used, |
|
118 | + * 'source' must contain a valid DSN. |
|
119 | 119 | * |
120 | - * Custom message source are possible by supplying the a filename parameter |
|
121 | - * in the factory method. |
|
120 | + * Custom message source are possible by supplying the a filename parameter |
|
121 | + * in the factory method. |
|
122 | 122 | * |
123 | 123 | * @param string the message source type. |
124 | 124 | * @param string the location of the resource or the ConnectionID. |
@@ -20,12 +20,12 @@ discard block |
||
20 | 20 | /** |
21 | 21 | * Get the IMessageSource interface. |
22 | 22 | */ |
23 | -require_once(dirname(__FILE__).'/IMessageSource.php'); |
|
23 | +require_once(dirname(__FILE__) . '/IMessageSource.php'); |
|
24 | 24 | |
25 | 25 | /** |
26 | 26 | * Get the MessageCache class file. |
27 | 27 | */ |
28 | -require_once(dirname(__FILE__).'/MessageCache.php'); |
|
28 | +require_once(dirname(__FILE__) . '/MessageCache.php'); |
|
29 | 29 | |
30 | 30 | /** |
31 | 31 | * Abstract MessageSource class. |
@@ -126,25 +126,25 @@ discard block |
||
126 | 126 | * @return MessageSource a new message source of the specified type. |
127 | 127 | * @throws InvalidMessageSourceTypeException |
128 | 128 | */ |
129 | - static function &factory($type, $source='.', $filename='') |
|
129 | + static function &factory($type, $source = '.', $filename = '') |
|
130 | 130 | { |
131 | - $types = array('XLIFF','gettext','Database','MySQL','SQLite'); |
|
131 | + $types = array('XLIFF', 'gettext', 'Database', 'MySQL', 'SQLite'); |
|
132 | 132 | |
133 | - if(empty($filename) && !in_array($type, $types)) |
|
134 | - throw new Exception('Invalid type "'.$type.'", valid types are '. |
|
133 | + if (empty($filename) && !in_array($type, $types)) |
|
134 | + throw new Exception('Invalid type "' . $type . '", valid types are ' . |
|
135 | 135 | implode(', ', $types)); |
136 | 136 | |
137 | - $class = 'MessageSource_'.$type; |
|
137 | + $class = 'MessageSource_' . $type; |
|
138 | 138 | |
139 | - if(empty($filename)) |
|
140 | - $filename = dirname(__FILE__).'/'.$class.'.php'; |
|
139 | + if (empty($filename)) |
|
140 | + $filename = dirname(__FILE__) . '/' . $class . '.php'; |
|
141 | 141 | |
142 | - if(is_file($filename) == false) |
|
142 | + if (is_file($filename) == false) |
|
143 | 143 | throw new Exception("File $filename not found"); |
144 | 144 | |
145 | 145 | include_once $filename; |
146 | 146 | |
147 | - $obj = new $class($source); |
|
147 | + $obj = new $class($source); |
|
148 | 148 | |
149 | 149 | return $obj; |
150 | 150 | } |
@@ -168,39 +168,39 @@ discard block |
||
168 | 168 | * @return boolean true if loaded, false otherwise. |
169 | 169 | * @see read() |
170 | 170 | */ |
171 | - function load($catalogue='messages') |
|
171 | + function load($catalogue = 'messages') |
|
172 | 172 | { |
173 | 173 | $variants = $this->getCatalogueList($catalogue); |
174 | 174 | |
175 | 175 | $this->messages = array(); |
176 | 176 | |
177 | - foreach($variants as $variant) |
|
177 | + foreach ($variants as $variant) |
|
178 | 178 | { |
179 | 179 | $source = $this->getSource($variant); |
180 | 180 | |
181 | - if($this->isValidSource($source) == false) continue; |
|
181 | + if ($this->isValidSource($source) == false) continue; |
|
182 | 182 | |
183 | 183 | $loadData = true; |
184 | 184 | |
185 | - if($this->cache) |
|
185 | + if ($this->cache) |
|
186 | 186 | { |
187 | 187 | $data = $this->cache->get($variant, |
188 | 188 | $this->culture, $this->getLastModified($source)); |
189 | 189 | |
190 | - if(is_array($data)) |
|
190 | + if (is_array($data)) |
|
191 | 191 | { |
192 | 192 | $this->messages[$variant] = $data; |
193 | 193 | $loadData = false; |
194 | 194 | } |
195 | 195 | unset($data); |
196 | 196 | } |
197 | - if($loadData) |
|
197 | + if ($loadData) |
|
198 | 198 | { |
199 | 199 | $data = &$this->loadData($source); |
200 | - if(is_array($data)) |
|
200 | + if (is_array($data)) |
|
201 | 201 | { |
202 | 202 | $this->messages[$variant] = $data; |
203 | - if($this->cache) |
|
203 | + if ($this->cache) |
|
204 | 204 | $this->cache->save($data, $variant, $this->culture); |
205 | 205 | } |
206 | 206 | unset($data); |
@@ -245,7 +245,7 @@ discard block |
||
245 | 245 | */ |
246 | 246 | public function append($message) |
247 | 247 | { |
248 | - if(!in_array($message, $this->untranslated)) |
|
248 | + if (!in_array($message, $this->untranslated)) |
|
249 | 249 | $this->untranslated[] = $message; |
250 | 250 | } |
251 | 251 |
@@ -130,17 +130,20 @@ discard block |
||
130 | 130 | { |
131 | 131 | $types = array('XLIFF','gettext','Database','MySQL','SQLite'); |
132 | 132 | |
133 | - if(empty($filename) && !in_array($type, $types)) |
|
134 | - throw new Exception('Invalid type "'.$type.'", valid types are '. |
|
133 | + if(empty($filename) && !in_array($type, $types)) { |
|
134 | + throw new Exception('Invalid type "'.$type.'", valid types are '. |
|
135 | 135 | implode(', ', $types)); |
136 | + } |
|
136 | 137 | |
137 | 138 | $class = 'MessageSource_'.$type; |
138 | 139 | |
139 | - if(empty($filename)) |
|
140 | - $filename = dirname(__FILE__).'/'.$class.'.php'; |
|
140 | + if(empty($filename)) { |
|
141 | + $filename = dirname(__FILE__).'/'.$class.'.php'; |
|
142 | + } |
|
141 | 143 | |
142 | - if(is_file($filename) == false) |
|
143 | - throw new Exception("File $filename not found"); |
|
144 | + if(is_file($filename) == false) { |
|
145 | + throw new Exception("File $filename not found"); |
|
146 | + } |
|
144 | 147 | |
145 | 148 | include_once $filename; |
146 | 149 | |
@@ -178,7 +181,9 @@ discard block |
||
178 | 181 | { |
179 | 182 | $source = $this->getSource($variant); |
180 | 183 | |
181 | - if($this->isValidSource($source) == false) continue; |
|
184 | + if($this->isValidSource($source) == false) { |
|
185 | + continue; |
|
186 | + } |
|
182 | 187 | |
183 | 188 | $loadData = true; |
184 | 189 | |
@@ -200,8 +205,9 @@ discard block |
||
200 | 205 | if(is_array($data)) |
201 | 206 | { |
202 | 207 | $this->messages[$variant] = $data; |
203 | - if($this->cache) |
|
204 | - $this->cache->save($data, $variant, $this->culture); |
|
208 | + if($this->cache) { |
|
209 | + $this->cache->save($data, $variant, $this->culture); |
|
210 | + } |
|
205 | 211 | } |
206 | 212 | unset($data); |
207 | 213 | } |
@@ -245,8 +251,9 @@ discard block |
||
245 | 251 | */ |
246 | 252 | public function append($message) |
247 | 253 | { |
248 | - if(!in_array($message, $this->untranslated)) |
|
249 | - $this->untranslated[] = $message; |
|
254 | + if(!in_array($message, $this->untranslated)) { |
|
255 | + $this->untranslated[] = $message; |
|
256 | + } |
|
250 | 257 | } |
251 | 258 | |
252 | 259 | /** |
@@ -60,6 +60,7 @@ discard block |
||
60 | 60 | /** |
61 | 61 | * Creates the DB connection. |
62 | 62 | * @param string the module ID for TDataSourceConfig |
63 | + * @param string $connectionID |
|
63 | 64 | * @return TDbConnection the created DB connection |
64 | 65 | * @throws TConfigurationException if module ID is invalid or empty |
65 | 66 | */ |
@@ -185,7 +186,7 @@ discard block |
||
185 | 186 | |
186 | 187 | /** |
187 | 188 | * Update the catalogue last modified time. |
188 | - * @return boolean true if updated, false otherwise. |
|
189 | + * @return integer true if updated, false otherwise. |
|
189 | 190 | */ |
190 | 191 | private function updateCatalogueTime($cat_id, $variant) |
191 | 192 | { |
@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | /** |
18 | 18 | * Get the MessageSource class file. |
19 | 19 | */ |
20 | -require_once(dirname(__FILE__).'/MessageSource.php'); |
|
20 | +require_once(dirname(__FILE__) . '/MessageSource.php'); |
|
21 | 21 | |
22 | 22 | /** |
23 | 23 | * MessageSource_Database class. |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | */ |
31 | 31 | class MessageSource_Database extends MessageSource |
32 | 32 | { |
33 | - private $_connID=''; |
|
33 | + private $_connID = ''; |
|
34 | 34 | private $_conn; |
35 | 35 | |
36 | 36 | /** |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | */ |
42 | 42 | function __construct($source) |
43 | 43 | { |
44 | - $this->_connID= (string)$source; |
|
44 | + $this->_connID = (string) $source; |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | /** |
@@ -49,9 +49,9 @@ discard block |
||
49 | 49 | */ |
50 | 50 | public function getDbConnection() |
51 | 51 | { |
52 | - if($this->_conn===null) |
|
52 | + if ($this->_conn === null) |
|
53 | 53 | { |
54 | - $this->_conn=$this->createDbConnection($this->_connID); |
|
54 | + $this->_conn = $this->createDbConnection($this->_connID); |
|
55 | 55 | $this->_conn->setActive(true); |
56 | 56 | } |
57 | 57 | return $this->_conn; |
@@ -65,13 +65,13 @@ discard block |
||
65 | 65 | */ |
66 | 66 | protected function createDbConnection($connectionID) |
67 | 67 | { |
68 | - if($connectionID!=='') |
|
68 | + if ($connectionID !== '') |
|
69 | 69 | { |
70 | - $conn=Prado::getApplication()->getModule($connectionID); |
|
71 | - if($conn instanceof TDataSourceConfig) |
|
70 | + $conn = Prado::getApplication()->getModule($connectionID); |
|
71 | + if ($conn instanceof TDataSourceConfig) |
|
72 | 72 | return $conn->getDbConnection(); |
73 | 73 | else |
74 | - throw new TConfigurationException('messagesource_connectionid_invalid',$connectionID); |
|
74 | + throw new TConfigurationException('messagesource_connectionid_invalid', $connectionID); |
|
75 | 75 | } |
76 | 76 | else |
77 | 77 | throw new TConfigurationException('messagesource_connectionid_required'); |
@@ -85,19 +85,19 @@ discard block |
||
85 | 85 | */ |
86 | 86 | protected function &loadData($variant) |
87 | 87 | { |
88 | - $command=$this->getDBConnection()->createCommand( |
|
88 | + $command = $this->getDBConnection()->createCommand( |
|
89 | 89 | 'SELECT t.id, t.source, t.target, t.comments |
90 | 90 | FROM trans_unit t, catalogue c |
91 | 91 | WHERE c.cat_id = t.cat_id |
92 | 92 | AND c.name = :variant |
93 | 93 | ORDER BY id ASC'); |
94 | - $command->bindParameter(':variant',$variant,PDO::PARAM_STR); |
|
95 | - $dataReader=$command->query(); |
|
94 | + $command->bindParameter(':variant', $variant, PDO::PARAM_STR); |
|
95 | + $dataReader = $command->query(); |
|
96 | 96 | |
97 | 97 | $result = array(); |
98 | 98 | |
99 | 99 | foreach ($dataReader as $row) |
100 | - $result[$row['source']] = array($row['target'],$row['id'],$row['comments']); |
|
100 | + $result[$row['source']] = array($row['target'], $row['id'], $row['comments']); |
|
101 | 101 | |
102 | 102 | return $result; |
103 | 103 | } |
@@ -110,10 +110,10 @@ discard block |
||
110 | 110 | */ |
111 | 111 | protected function getLastModified($source) |
112 | 112 | { |
113 | - $command=$this->getDBConnection()->createCommand( |
|
113 | + $command = $this->getDBConnection()->createCommand( |
|
114 | 114 | 'SELECT date_modified FROM catalogue WHERE name = :source'); |
115 | - $command->bindParameter(':source',$source,PDO::PARAM_STR); |
|
116 | - $result=$command->queryScalar(); |
|
115 | + $command->bindParameter(':source', $source, PDO::PARAM_STR); |
|
116 | + $result = $command->queryScalar(); |
|
117 | 117 | return $result ? $result : 0; |
118 | 118 | } |
119 | 119 | |
@@ -126,10 +126,10 @@ discard block |
||
126 | 126 | */ |
127 | 127 | protected function isValidSource($variant) |
128 | 128 | { |
129 | - $command=$this->getDBConnection()->createCommand( |
|
129 | + $command = $this->getDBConnection()->createCommand( |
|
130 | 130 | 'SELECT COUNT(*) FROM catalogue WHERE name = :variant'); |
131 | - $command->bindParameter(':variant',$variant,PDO::PARAM_STR); |
|
132 | - return $command->queryScalar()==1; |
|
131 | + $command->bindParameter(':variant', $variant, PDO::PARAM_STR); |
|
132 | + return $command->queryScalar() == 1; |
|
133 | 133 | } |
134 | 134 | |
135 | 135 | /** |
@@ -139,18 +139,18 @@ discard block |
||
139 | 139 | */ |
140 | 140 | protected function getCatalogueList($catalogue) |
141 | 141 | { |
142 | - $variants = explode('_',$this->culture); |
|
142 | + $variants = explode('_', $this->culture); |
|
143 | 143 | |
144 | 144 | $catalogues = array($catalogue); |
145 | 145 | |
146 | 146 | $variant = null; |
147 | 147 | |
148 | - for($i = 0, $k = count($variants); $i < $k; ++$i) |
|
148 | + for ($i = 0, $k = count($variants); $i < $k; ++$i) |
|
149 | 149 | { |
150 | - if(isset($variants[$i]{0})) |
|
150 | + if (isset($variants[$i]{0})) |
|
151 | 151 | { |
152 | - $variant .= ($variant)?'_'.$variants[$i]:$variants[$i]; |
|
153 | - $catalogues[] = $catalogue.'.'.$variant; |
|
152 | + $variant .= ($variant) ? '_' . $variants[$i] : $variants[$i]; |
|
153 | + $catalogues[] = $catalogue . '.' . $variant; |
|
154 | 154 | } |
155 | 155 | } |
156 | 156 | return array_reverse($catalogues); |
@@ -161,24 +161,24 @@ discard block |
||
161 | 161 | * @param string catalogue |
162 | 162 | * @return array catalogue details, array($cat_id, $variant, $count). |
163 | 163 | */ |
164 | - private function getCatalogueDetails($catalogue='messages') |
|
164 | + private function getCatalogueDetails($catalogue = 'messages') |
|
165 | 165 | { |
166 | - if(empty($catalogue)) |
|
166 | + if (empty($catalogue)) |
|
167 | 167 | $catalogue = 'messages'; |
168 | 168 | |
169 | - $variant = $catalogue.'.'.$this->culture; |
|
169 | + $variant = $catalogue . '.' . $this->culture; |
|
170 | 170 | |
171 | - $command=$this->getDBConnection()->createCommand( |
|
171 | + $command = $this->getDBConnection()->createCommand( |
|
172 | 172 | 'SELECT cat_id FROM catalogue WHERE name = :variant'); |
173 | - $command->bindParameter(':variant',$variant,PDO::PARAM_STR); |
|
174 | - $cat_id=$command->queryScalar(); |
|
173 | + $command->bindParameter(':variant', $variant, PDO::PARAM_STR); |
|
174 | + $cat_id = $command->queryScalar(); |
|
175 | 175 | |
176 | - if ($cat_id===null) return false; |
|
176 | + if ($cat_id === null) return false; |
|
177 | 177 | |
178 | - $command=$this->getDBConnection()->createCommand( |
|
178 | + $command = $this->getDBConnection()->createCommand( |
|
179 | 179 | 'SELECT COUNT(msg_id) FROM trans_unit WHERE cat_id = :catid '); |
180 | - $command->bindParameter(':catid',$cat_id,PDO::PARAM_INT); |
|
181 | - $count=$command->queryScalar(); |
|
180 | + $command->bindParameter(':catid', $cat_id, PDO::PARAM_INT); |
|
181 | + $count = $command->queryScalar(); |
|
182 | 182 | |
183 | 183 | return array($cat_id, $variant, $count); |
184 | 184 | } |
@@ -190,13 +190,13 @@ discard block |
||
190 | 190 | private function updateCatalogueTime($cat_id, $variant) |
191 | 191 | { |
192 | 192 | $time = time(); |
193 | - $command=$this->getDBConnection()->createCommand( |
|
193 | + $command = $this->getDBConnection()->createCommand( |
|
194 | 194 | 'UPDATE catalogue SET date_modified = :moddate WHERE cat_id = :catid'); |
195 | - $command->bindParameter(':moddate',$time,PDO::PARAM_INT); |
|
196 | - $command->bindParameter(':catid',$cat_id,PDO::PARAM_INT); |
|
197 | - $result=$command->execute(); |
|
195 | + $command->bindParameter(':moddate', $time, PDO::PARAM_INT); |
|
196 | + $command->bindParameter(':catid', $cat_id, PDO::PARAM_INT); |
|
197 | + $result = $command->execute(); |
|
198 | 198 | |
199 | - if(!empty($this->cache)) |
|
199 | + if (!empty($this->cache)) |
|
200 | 200 | $this->cache->clean($variant, $this->culture); |
201 | 201 | |
202 | 202 | return $result; |
@@ -209,37 +209,37 @@ discard block |
||
209 | 209 | * @param string the catalogue to add to |
210 | 210 | * @return boolean true if saved successfuly, false otherwise. |
211 | 211 | */ |
212 | - function save($catalogue='messages') |
|
212 | + function save($catalogue = 'messages') |
|
213 | 213 | { |
214 | 214 | $messages = $this->untranslated; |
215 | 215 | |
216 | - if(count($messages) <= 0) return false; |
|
216 | + if (count($messages) <= 0) return false; |
|
217 | 217 | |
218 | 218 | $details = $this->getCatalogueDetails($catalogue); |
219 | 219 | |
220 | - if($details) |
|
220 | + if ($details) |
|
221 | 221 | list($cat_id, $variant, $count) = $details; |
222 | 222 | else |
223 | 223 | return false; |
224 | 224 | |
225 | - if($cat_id <= 0) return false; |
|
225 | + if ($cat_id <= 0) return false; |
|
226 | 226 | $inserted = 0; |
227 | 227 | |
228 | 228 | $time = time(); |
229 | 229 | |
230 | - $command=$this->getDBConnection()->createCommand( |
|
230 | + $command = $this->getDBConnection()->createCommand( |
|
231 | 231 | 'INSERT INTO trans_unit (cat_id,id,source,date_added) VALUES (:catid,:id,:source,:dateadded)'); |
232 | - $command->bindParameter(':catid',$cat_id,PDO::PARAM_INT); |
|
233 | - $command->bindParameter(':id',$count,PDO::PARAM_INT); |
|
234 | - $command->bindParameter(':source',$message,PDO::PARAM_STR); |
|
235 | - $command->bindParameter(':dateadded',$time,PDO::PARAM_INT); |
|
236 | - foreach($messages as $message) |
|
232 | + $command->bindParameter(':catid', $cat_id, PDO::PARAM_INT); |
|
233 | + $command->bindParameter(':id', $count, PDO::PARAM_INT); |
|
234 | + $command->bindParameter(':source', $message, PDO::PARAM_STR); |
|
235 | + $command->bindParameter(':dateadded', $time, PDO::PARAM_INT); |
|
236 | + foreach ($messages as $message) |
|
237 | 237 | { |
238 | 238 | if (empty($message)) continue; |
239 | 239 | $count++; $inserted++; |
240 | 240 | $command->execute(); |
241 | 241 | } |
242 | - if($inserted > 0) |
|
242 | + if ($inserted > 0) |
|
243 | 243 | $this->updateCatalogueTime($cat_id, $variant); |
244 | 244 | |
245 | 245 | return $inserted > 0; |
@@ -251,20 +251,20 @@ discard block |
||
251 | 251 | * @param string the catalogue to delete from. |
252 | 252 | * @return boolean true if deleted, false otherwise. |
253 | 253 | */ |
254 | - function delete($message, $catalogue='messages') |
|
254 | + function delete($message, $catalogue = 'messages') |
|
255 | 255 | { |
256 | 256 | $details = $this->getCatalogueDetails($catalogue); |
257 | - if($details) |
|
257 | + if ($details) |
|
258 | 258 | list($cat_id, $variant, $count) = $details; |
259 | 259 | else |
260 | 260 | return false; |
261 | 261 | |
262 | - $command=$this->getDBConnection()->createCommand( |
|
262 | + $command = $this->getDBConnection()->createCommand( |
|
263 | 263 | 'DELETE FROM trans_unit WHERE cat_id = :catid AND source = :message'); |
264 | - $command->bindParameter(':catid',$cat_id,PDO::PARAM_INT); |
|
265 | - $command->bindParameter(':message',$message,PDO::PARAM_STR); |
|
264 | + $command->bindParameter(':catid', $cat_id, PDO::PARAM_INT); |
|
265 | + $command->bindParameter(':message', $message, PDO::PARAM_STR); |
|
266 | 266 | |
267 | - return ($command->execute()==1) ? $this->updateCatalogueTime($cat_id, $variant) : false; |
|
267 | + return ($command->execute() == 1) ? $this->updateCatalogueTime($cat_id, $variant) : false; |
|
268 | 268 | |
269 | 269 | } |
270 | 270 | |
@@ -276,25 +276,25 @@ discard block |
||
276 | 276 | * @param string the catalogue of the translation. |
277 | 277 | * @return boolean true if translation was updated, false otherwise. |
278 | 278 | */ |
279 | - function update($text, $target, $comments, $catalogue='messages') |
|
279 | + function update($text, $target, $comments, $catalogue = 'messages') |
|
280 | 280 | { |
281 | 281 | $details = $this->getCatalogueDetails($catalogue); |
282 | - if($details) |
|
282 | + if ($details) |
|
283 | 283 | list($cat_id, $variant, $count) = $details; |
284 | 284 | else |
285 | 285 | return false; |
286 | 286 | |
287 | 287 | $time = time(); |
288 | - $command=$this->getDBConnection()->createCommand( |
|
288 | + $command = $this->getDBConnection()->createCommand( |
|
289 | 289 | 'UPDATE trans_unit SET target = :target, comments = :comments, date_modified = :datemod |
290 | 290 | WHERE cat_id = :catid AND source = :source'); |
291 | - $command->bindParameter(':target',$target,PDO::PARAM_STR); |
|
292 | - $command->bindParameter(':comments',$comments,PDO::PARAM_STR); |
|
293 | - $command->bindParameter(':datemod',$time,PDO::PARAM_INT); |
|
294 | - $command->bindParameter(':catid',$cat_id,PDO::PARAM_INT); |
|
295 | - $command->bindParameter(':source',$text,PDO::PARAM_STR); |
|
291 | + $command->bindParameter(':target', $target, PDO::PARAM_STR); |
|
292 | + $command->bindParameter(':comments', $comments, PDO::PARAM_STR); |
|
293 | + $command->bindParameter(':datemod', $time, PDO::PARAM_INT); |
|
294 | + $command->bindParameter(':catid', $cat_id, PDO::PARAM_INT); |
|
295 | + $command->bindParameter(':source', $text, PDO::PARAM_STR); |
|
296 | 296 | |
297 | - return ($command->execute()==1) ? $this->updateCatalogueTime($cat_id, $variant) : false; |
|
297 | + return ($command->execute() == 1) ? $this->updateCatalogueTime($cat_id, $variant) : false; |
|
298 | 298 | } |
299 | 299 | |
300 | 300 | /** |
@@ -303,15 +303,15 @@ discard block |
||
303 | 303 | */ |
304 | 304 | function catalogues() |
305 | 305 | { |
306 | - $command=$this->getDBConnection()->createCommand( 'SELECT name FROM catalogue ORDER BY name'); |
|
307 | - $dataReader=$command->query(); |
|
306 | + $command = $this->getDBConnection()->createCommand('SELECT name FROM catalogue ORDER BY name'); |
|
307 | + $dataReader = $command->query(); |
|
308 | 308 | |
309 | 309 | $result = array(); |
310 | 310 | |
311 | 311 | foreach ($dataReader as $row) |
312 | 312 | { |
313 | - $details = explode('.',$row[0]); |
|
314 | - if(!isset($details[1])) $details[1] = null; |
|
313 | + $details = explode('.', $row[0]); |
|
314 | + if (!isset($details[1])) $details[1] = null; |
|
315 | 315 | |
316 | 316 | $result[] = $details; |
317 | 317 | } |
@@ -68,13 +68,14 @@ discard block |
||
68 | 68 | if($connectionID!=='') |
69 | 69 | { |
70 | 70 | $conn=Prado::getApplication()->getModule($connectionID); |
71 | - if($conn instanceof TDataSourceConfig) |
|
72 | - return $conn->getDbConnection(); |
|
73 | - else |
|
74 | - throw new TConfigurationException('messagesource_connectionid_invalid',$connectionID); |
|
71 | + if($conn instanceof TDataSourceConfig) { |
|
72 | + return $conn->getDbConnection(); |
|
73 | + } else { |
|
74 | + throw new TConfigurationException('messagesource_connectionid_invalid',$connectionID); |
|
75 | + } |
|
76 | + } else { |
|
77 | + throw new TConfigurationException('messagesource_connectionid_required'); |
|
75 | 78 | } |
76 | - else |
|
77 | - throw new TConfigurationException('messagesource_connectionid_required'); |
|
78 | 79 | } |
79 | 80 | |
80 | 81 | /** |
@@ -96,8 +97,9 @@ discard block |
||
96 | 97 | |
97 | 98 | $result = array(); |
98 | 99 | |
99 | - foreach ($dataReader as $row) |
|
100 | - $result[$row['source']] = array($row['target'],$row['id'],$row['comments']); |
|
100 | + foreach ($dataReader as $row) { |
|
101 | + $result[$row['source']] = array($row['target'],$row['id'],$row['comments']); |
|
102 | + } |
|
101 | 103 | |
102 | 104 | return $result; |
103 | 105 | } |
@@ -163,8 +165,9 @@ discard block |
||
163 | 165 | */ |
164 | 166 | private function getCatalogueDetails($catalogue='messages') |
165 | 167 | { |
166 | - if(empty($catalogue)) |
|
167 | - $catalogue = 'messages'; |
|
168 | + if(empty($catalogue)) { |
|
169 | + $catalogue = 'messages'; |
|
170 | + } |
|
168 | 171 | |
169 | 172 | $variant = $catalogue.'.'.$this->culture; |
170 | 173 | |
@@ -173,7 +176,9 @@ discard block |
||
173 | 176 | $command->bindParameter(':variant',$variant,PDO::PARAM_STR); |
174 | 177 | $cat_id=$command->queryScalar(); |
175 | 178 | |
176 | - if ($cat_id===null) return false; |
|
179 | + if ($cat_id===null) { |
|
180 | + return false; |
|
181 | + } |
|
177 | 182 | |
178 | 183 | $command=$this->getDBConnection()->createCommand( |
179 | 184 | 'SELECT COUNT(msg_id) FROM trans_unit WHERE cat_id = :catid '); |
@@ -196,8 +201,9 @@ discard block |
||
196 | 201 | $command->bindParameter(':catid',$cat_id,PDO::PARAM_INT); |
197 | 202 | $result=$command->execute(); |
198 | 203 | |
199 | - if(!empty($this->cache)) |
|
200 | - $this->cache->clean($variant, $this->culture); |
|
204 | + if(!empty($this->cache)) { |
|
205 | + $this->cache->clean($variant, $this->culture); |
|
206 | + } |
|
201 | 207 | |
202 | 208 | return $result; |
203 | 209 | } |
@@ -213,16 +219,21 @@ discard block |
||
213 | 219 | { |
214 | 220 | $messages = $this->untranslated; |
215 | 221 | |
216 | - if(count($messages) <= 0) return false; |
|
222 | + if(count($messages) <= 0) { |
|
223 | + return false; |
|
224 | + } |
|
217 | 225 | |
218 | 226 | $details = $this->getCatalogueDetails($catalogue); |
219 | 227 | |
220 | - if($details) |
|
221 | - list($cat_id, $variant, $count) = $details; |
|
222 | - else |
|
223 | - return false; |
|
228 | + if($details) { |
|
229 | + list($cat_id, $variant, $count) = $details; |
|
230 | + } else { |
|
231 | + return false; |
|
232 | + } |
|
224 | 233 | |
225 | - if($cat_id <= 0) return false; |
|
234 | + if($cat_id <= 0) { |
|
235 | + return false; |
|
236 | + } |
|
226 | 237 | $inserted = 0; |
227 | 238 | |
228 | 239 | $time = time(); |
@@ -235,12 +246,15 @@ discard block |
||
235 | 246 | $command->bindParameter(':dateadded',$time,PDO::PARAM_INT); |
236 | 247 | foreach($messages as $message) |
237 | 248 | { |
238 | - if (empty($message)) continue; |
|
249 | + if (empty($message)) { |
|
250 | + continue; |
|
251 | + } |
|
239 | 252 | $count++; $inserted++; |
240 | 253 | $command->execute(); |
241 | 254 | } |
242 | - if($inserted > 0) |
|
243 | - $this->updateCatalogueTime($cat_id, $variant); |
|
255 | + if($inserted > 0) { |
|
256 | + $this->updateCatalogueTime($cat_id, $variant); |
|
257 | + } |
|
244 | 258 | |
245 | 259 | return $inserted > 0; |
246 | 260 | } |
@@ -254,10 +268,11 @@ discard block |
||
254 | 268 | function delete($message, $catalogue='messages') |
255 | 269 | { |
256 | 270 | $details = $this->getCatalogueDetails($catalogue); |
257 | - if($details) |
|
258 | - list($cat_id, $variant, $count) = $details; |
|
259 | - else |
|
260 | - return false; |
|
271 | + if($details) { |
|
272 | + list($cat_id, $variant, $count) = $details; |
|
273 | + } else { |
|
274 | + return false; |
|
275 | + } |
|
261 | 276 | |
262 | 277 | $command=$this->getDBConnection()->createCommand( |
263 | 278 | 'DELETE FROM trans_unit WHERE cat_id = :catid AND source = :message'); |
@@ -279,10 +294,11 @@ discard block |
||
279 | 294 | function update($text, $target, $comments, $catalogue='messages') |
280 | 295 | { |
281 | 296 | $details = $this->getCatalogueDetails($catalogue); |
282 | - if($details) |
|
283 | - list($cat_id, $variant, $count) = $details; |
|
284 | - else |
|
285 | - return false; |
|
297 | + if($details) { |
|
298 | + list($cat_id, $variant, $count) = $details; |
|
299 | + } else { |
|
300 | + return false; |
|
301 | + } |
|
286 | 302 | |
287 | 303 | $time = time(); |
288 | 304 | $command=$this->getDBConnection()->createCommand( |
@@ -311,7 +327,9 @@ discard block |
||
311 | 327 | foreach ($dataReader as $row) |
312 | 328 | { |
313 | 329 | $details = explode('.',$row[0]); |
314 | - if(!isset($details[1])) $details[1] = null; |
|
330 | + if(!isset($details[1])) { |
|
331 | + $details[1] = null; |
|
332 | + } |
|
315 | 333 | |
316 | 334 | $result[] = $details; |
317 | 335 | } |
@@ -200,6 +200,9 @@ discard block |
||
200 | 200 | return false; |
201 | 201 | } |
202 | 202 | |
203 | + /** |
|
204 | + * @param string $MOFile |
|
205 | + */ |
|
203 | 206 | private function getPOFile($MOFile) |
204 | 207 | { |
205 | 208 | $filebase = substr($MOFile, 0, strlen($MOFile)-strlen($this->dataExt)); |
@@ -422,6 +425,9 @@ discard block |
||
422 | 425 | return $catalogue; |
423 | 426 | } |
424 | 427 | |
428 | + /** |
|
429 | + * @param string $catalogue |
|
430 | + */ |
|
425 | 431 | protected function createMessageTemplate($catalogue) |
426 | 432 | { |
427 | 433 | if($catalogue === null) { |
@@ -20,12 +20,12 @@ discard block |
||
20 | 20 | /** |
21 | 21 | * Get the MessageSource class file. |
22 | 22 | */ |
23 | -require_once(dirname(__FILE__).'/MessageSource.php'); |
|
23 | +require_once(dirname(__FILE__) . '/MessageSource.php'); |
|
24 | 24 | |
25 | 25 | /** |
26 | 26 | * Get the Gettext class. |
27 | 27 | */ |
28 | -require_once(dirname(__FILE__).'/Gettext/TGettext.php'); |
|
28 | +require_once(dirname(__FILE__) . '/Gettext/TGettext.php'); |
|
29 | 29 | |
30 | 30 | /** |
31 | 31 | * MessageSource_gettext class. |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | |
62 | 62 | function __construct($source) |
63 | 63 | { |
64 | - $this->source = (string)$source; |
|
64 | + $this->source = (string) $source; |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | |
@@ -72,13 +72,13 @@ discard block |
||
72 | 72 | */ |
73 | 73 | protected function &loadData($filename) |
74 | 74 | { |
75 | - $mo = TGettext::factory('MO',$filename); |
|
75 | + $mo = TGettext::factory('MO', $filename); |
|
76 | 76 | $mo->load(); |
77 | 77 | $result = $mo->toArray(); |
78 | 78 | |
79 | 79 | $results = array(); |
80 | - $count=0; |
|
81 | - foreach($result['strings'] as $source => $target) |
|
80 | + $count = 0; |
|
81 | + foreach ($result['strings'] as $source => $target) |
|
82 | 82 | { |
83 | 83 | $results[$source][] = $target; //target |
84 | 84 | $results[$source][] = $count++; //id |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | */ |
106 | 106 | protected function getSource($variant) |
107 | 107 | { |
108 | - return $this->source.'/'.$variant; |
|
108 | + return $this->source . '/' . $variant; |
|
109 | 109 | } |
110 | 110 | |
111 | 111 | /** |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | */ |
117 | 117 | protected function getLastModified($source) |
118 | 118 | { |
119 | - if(is_file($source)) |
|
119 | + if (is_file($source)) |
|
120 | 120 | return filemtime($source); |
121 | 121 | else |
122 | 122 | return 0; |
@@ -129,24 +129,24 @@ discard block |
||
129 | 129 | */ |
130 | 130 | protected function getCatalogueList($catalogue) |
131 | 131 | { |
132 | - $variants = explode('_',$this->culture); |
|
133 | - $source = $catalogue.$this->dataExt; |
|
132 | + $variants = explode('_', $this->culture); |
|
133 | + $source = $catalogue . $this->dataExt; |
|
134 | 134 | |
135 | 135 | $catalogues = array($source); |
136 | 136 | |
137 | 137 | $variant = null; |
138 | 138 | |
139 | - for($i = 0, $k = count($variants); $i < $k; ++$i) |
|
139 | + for ($i = 0, $k = count($variants); $i < $k; ++$i) |
|
140 | 140 | { |
141 | - if(isset($variants[$i]{0})) |
|
141 | + if (isset($variants[$i]{0})) |
|
142 | 142 | { |
143 | - $variant .= ($variant)?'_'.$variants[$i]:$variants[$i]; |
|
144 | - $catalogues[] = $catalogue.$this->dataSeparator. |
|
145 | - $variant.$this->dataExt; |
|
143 | + $variant .= ($variant) ? '_' . $variants[$i] : $variants[$i]; |
|
144 | + $catalogues[] = $catalogue . $this->dataSeparator . |
|
145 | + $variant . $this->dataExt; |
|
146 | 146 | } |
147 | 147 | } |
148 | 148 | $byDir = $this->getCatalogueByDir($catalogue); |
149 | - $catalogues = array_merge($byDir,array_reverse($catalogues)); |
|
149 | + $catalogues = array_merge($byDir, array_reverse($catalogues)); |
|
150 | 150 | return $catalogues; |
151 | 151 | } |
152 | 152 | |
@@ -160,17 +160,17 @@ discard block |
||
160 | 160 | */ |
161 | 161 | private function getCatalogueByDir($catalogue) |
162 | 162 | { |
163 | - $variants = explode('_',$this->culture); |
|
163 | + $variants = explode('_', $this->culture); |
|
164 | 164 | $catalogues = array(); |
165 | 165 | |
166 | 166 | $variant = null; |
167 | 167 | |
168 | - for($i = 0, $k = count($variants); $i < $k; ++$i) |
|
168 | + for ($i = 0, $k = count($variants); $i < $k; ++$i) |
|
169 | 169 | { |
170 | - if(isset($variants[$i]{0})) |
|
170 | + if (isset($variants[$i]{0})) |
|
171 | 171 | { |
172 | - $variant .= ($variant)?'_'.$variants[$i]:$variants[$i]; |
|
173 | - $catalogues[] = $variant.'/'.$catalogue.$this->dataExt; |
|
172 | + $variant .= ($variant) ? '_' . $variants[$i] : $variants[$i]; |
|
173 | + $catalogues[] = $variant . '/' . $catalogue . $this->dataExt; |
|
174 | 174 | } |
175 | 175 | } |
176 | 176 | return array_reverse($catalogues); |
@@ -184,17 +184,17 @@ discard block |
||
184 | 184 | * @see update() |
185 | 185 | * @see delete() |
186 | 186 | */ |
187 | - private function getVariants($catalogue='messages') |
|
187 | + private function getVariants($catalogue = 'messages') |
|
188 | 188 | { |
189 | - if($catalogue === null) { |
|
189 | + if ($catalogue === null) { |
|
190 | 190 | $catalogue = 'messages'; |
191 | 191 | } |
192 | 192 | |
193 | - foreach($this->getCatalogueList($catalogue) as $variant) |
|
193 | + foreach ($this->getCatalogueList($catalogue) as $variant) |
|
194 | 194 | { |
195 | 195 | $file = $this->getSource($variant); |
196 | 196 | $po = $this->getPOFile($file); |
197 | - if(is_file($file) || is_file($po)) |
|
197 | + if (is_file($file) || is_file($po)) |
|
198 | 198 | return array($variant, $file, $po); |
199 | 199 | } |
200 | 200 | return false; |
@@ -202,8 +202,8 @@ discard block |
||
202 | 202 | |
203 | 203 | private function getPOFile($MOFile) |
204 | 204 | { |
205 | - $filebase = substr($MOFile, 0, strlen($MOFile)-strlen($this->dataExt)); |
|
206 | - return $filebase.$this->poExt; |
|
205 | + $filebase = substr($MOFile, 0, strlen($MOFile) - strlen($this->dataExt)); |
|
206 | + return $filebase . $this->poExt; |
|
207 | 207 | } |
208 | 208 | |
209 | 209 | /** |
@@ -213,51 +213,51 @@ discard block |
||
213 | 213 | * @param string the catalogue to add to |
214 | 214 | * @return boolean true if saved successfuly, false otherwise. |
215 | 215 | */ |
216 | - function save($catalogue='messages') |
|
216 | + function save($catalogue = 'messages') |
|
217 | 217 | { |
218 | 218 | $messages = $this->untranslated; |
219 | 219 | |
220 | - if(count($messages) <= 0) return false; |
|
220 | + if (count($messages) <= 0) return false; |
|
221 | 221 | |
222 | 222 | $variants = $this->getVariants($catalogue); |
223 | 223 | |
224 | - if($variants) |
|
224 | + if ($variants) |
|
225 | 225 | list($variant, $MOFile, $POFile) = $variants; |
226 | 226 | else |
227 | 227 | list($variant, $MOFile, $POFile) = $this->createMessageTemplate($catalogue); |
228 | 228 | |
229 | - if(is_writable($MOFile) == false) |
|
229 | + if (is_writable($MOFile) == false) |
|
230 | 230 | throw new TIOException("Unable to save to file {$MOFile}, file must be writable."); |
231 | - if(is_writable($POFile) == false) |
|
231 | + if (is_writable($POFile) == false) |
|
232 | 232 | throw new TIOException("Unable to save to file {$POFile}, file must be writable."); |
233 | 233 | |
234 | 234 | //set the strings as untranslated. |
235 | 235 | $strings = array(); |
236 | - foreach($messages as $message) |
|
236 | + foreach ($messages as $message) |
|
237 | 237 | $strings[$message] = ''; |
238 | 238 | |
239 | 239 | //load the PO |
240 | - $po = TGettext::factory('PO',$POFile); |
|
240 | + $po = TGettext::factory('PO', $POFile); |
|
241 | 241 | $po->load(); |
242 | 242 | $result = $po->toArray(); |
243 | 243 | |
244 | 244 | $existing = count($result['strings']); |
245 | 245 | |
246 | 246 | //add to strings to the existing message list |
247 | - $result['strings'] = array_merge($result['strings'],$strings); |
|
247 | + $result['strings'] = array_merge($result['strings'], $strings); |
|
248 | 248 | |
249 | 249 | $new = count($result['strings']); |
250 | 250 | |
251 | - if($new > $existing) |
|
251 | + if ($new > $existing) |
|
252 | 252 | { |
253 | 253 | //change the date 2004-12-25 12:26 |
254 | 254 | $result['meta']['PO-Revision-Date'] = @date('Y-m-d H:i:s'); |
255 | 255 | |
256 | 256 | $po->fromArray($result); |
257 | 257 | $mo = $po->toMO(); |
258 | - if($po->save() && $mo->save($MOFile)) |
|
258 | + if ($po->save() && $mo->save($MOFile)) |
|
259 | 259 | { |
260 | - if(!empty($this->cache)) |
|
260 | + if (!empty($this->cache)) |
|
261 | 261 | $this->cache->clean($variant, $this->culture); |
262 | 262 | return true; |
263 | 263 | } |
@@ -273,35 +273,35 @@ discard block |
||
273 | 273 | * @param string the catalogue to delete from. |
274 | 274 | * @return boolean true if deleted, false otherwise. |
275 | 275 | */ |
276 | - function delete($message, $catalogue='messages') |
|
276 | + function delete($message, $catalogue = 'messages') |
|
277 | 277 | { |
278 | 278 | $variants = $this->getVariants($catalogue); |
279 | - if($variants) |
|
279 | + if ($variants) |
|
280 | 280 | list($variant, $MOFile, $POFile) = $variants; |
281 | 281 | else |
282 | 282 | return false; |
283 | 283 | |
284 | - if(is_writable($MOFile) == false) |
|
284 | + if (is_writable($MOFile) == false) |
|
285 | 285 | throw new TIOException("Unable to modify file {$MOFile}, file must be writable."); |
286 | - if(is_writable($POFile) == false) |
|
286 | + if (is_writable($POFile) == false) |
|
287 | 287 | throw new TIOException("Unable to modify file {$POFile}, file must be writable."); |
288 | 288 | |
289 | - $po = TGettext::factory('PO',$POFile); |
|
289 | + $po = TGettext::factory('PO', $POFile); |
|
290 | 290 | $po->load(); |
291 | 291 | $result = $po->toArray(); |
292 | 292 | |
293 | - foreach($result['strings'] as $string => $value) |
|
293 | + foreach ($result['strings'] as $string => $value) |
|
294 | 294 | { |
295 | - if($string == $message) |
|
295 | + if ($string == $message) |
|
296 | 296 | { |
297 | 297 | $result['meta']['PO-Revision-Date'] = @date('Y-m-d H:i:s'); |
298 | 298 | unset($result['strings'][$string]); |
299 | 299 | |
300 | 300 | $po->fromArray($result); |
301 | 301 | $mo = $po->toMO(); |
302 | - if($po->save() && $mo->save($MOFile)) |
|
302 | + if ($po->save() && $mo->save($MOFile)) |
|
303 | 303 | { |
304 | - if(!empty($this->cache)) |
|
304 | + if (!empty($this->cache)) |
|
305 | 305 | $this->cache->clean($variant, $this->culture); |
306 | 306 | return true; |
307 | 307 | } |
@@ -321,27 +321,27 @@ discard block |
||
321 | 321 | * @param string the catalogue of the translation. |
322 | 322 | * @return boolean true if translation was updated, false otherwise. |
323 | 323 | */ |
324 | - function update($text, $target, $comments, $catalogue='messages') |
|
324 | + function update($text, $target, $comments, $catalogue = 'messages') |
|
325 | 325 | { |
326 | 326 | $variants = $this->getVariants($catalogue); |
327 | - if($variants) |
|
327 | + if ($variants) |
|
328 | 328 | list($variant, $MOFile, $POFile) = $variants; |
329 | 329 | else |
330 | 330 | return false; |
331 | 331 | |
332 | - if(is_writable($MOFile) == false) |
|
332 | + if (is_writable($MOFile) == false) |
|
333 | 333 | throw new TIOException("Unable to update file {$MOFile}, file must be writable."); |
334 | - if(is_writable($POFile) == false) |
|
334 | + if (is_writable($POFile) == false) |
|
335 | 335 | throw new TIOException("Unable to update file {$POFile}, file must be writable."); |
336 | 336 | |
337 | 337 | |
338 | - $po = TGettext::factory('PO',$POFile); |
|
338 | + $po = TGettext::factory('PO', $POFile); |
|
339 | 339 | $po->load(); |
340 | 340 | $result = $po->toArray(); |
341 | 341 | |
342 | - foreach($result['strings'] as $string => $value) |
|
342 | + foreach ($result['strings'] as $string => $value) |
|
343 | 343 | { |
344 | - if($string == $text) |
|
344 | + if ($string == $text) |
|
345 | 345 | { |
346 | 346 | $result['strings'][$string] = $target; |
347 | 347 | $result['meta']['PO-Revision-Date'] = @date('Y-m-d H:i:s'); |
@@ -349,9 +349,9 @@ discard block |
||
349 | 349 | $po->fromArray($result); |
350 | 350 | $mo = $po->toMO(); |
351 | 351 | |
352 | - if($po->save() && $mo->save($MOFile)) |
|
352 | + if ($po->save() && $mo->save($MOFile)) |
|
353 | 353 | { |
354 | - if(!empty($this->cache)) |
|
354 | + if (!empty($this->cache)) |
|
355 | 355 | $this->cache->clean($variant, $this->culture); |
356 | 356 | return true; |
357 | 357 | } |
@@ -379,36 +379,36 @@ discard block |
||
379 | 379 | * E.g. array('messages','en_AU') |
380 | 380 | * @return array list of catalogues |
381 | 381 | */ |
382 | - protected function getCatalogues($dir=null,$variant=null) |
|
382 | + protected function getCatalogues($dir = null, $variant = null) |
|
383 | 383 | { |
384 | - $dir = $dir?$dir:$this->source; |
|
384 | + $dir = $dir ? $dir : $this->source; |
|
385 | 385 | $files = scandir($dir); |
386 | 386 | |
387 | 387 | $catalogue = array(); |
388 | 388 | |
389 | - foreach($files as $file) |
|
389 | + foreach ($files as $file) |
|
390 | 390 | { |
391 | - if(is_dir($dir.'/'.$file) |
|
392 | - && preg_match('/^[a-z]{2}(_[A-Z]{2,3})?$/',$file)) |
|
391 | + if (is_dir($dir . '/' . $file) |
|
392 | + && preg_match('/^[a-z]{2}(_[A-Z]{2,3})?$/', $file)) |
|
393 | 393 | { |
394 | 394 | |
395 | 395 | $catalogue = array_merge($catalogue, |
396 | - $this->getCatalogues($dir.'/'.$file, $file)); |
|
396 | + $this->getCatalogues($dir . '/' . $file, $file)); |
|
397 | 397 | } |
398 | 398 | |
399 | - $pos = strpos($file,$this->dataExt); |
|
399 | + $pos = strpos($file, $this->dataExt); |
|
400 | 400 | |
401 | - if($pos >0 |
|
402 | - && substr($file,-1*strlen($this->dataExt)) == $this->dataExt) |
|
401 | + if ($pos > 0 |
|
402 | + && substr($file, -1 * strlen($this->dataExt)) == $this->dataExt) |
|
403 | 403 | { |
404 | - $name = substr($file,0,$pos); |
|
405 | - $dot = strrpos($name,$this->dataSeparator); |
|
404 | + $name = substr($file, 0, $pos); |
|
405 | + $dot = strrpos($name, $this->dataSeparator); |
|
406 | 406 | $culture = $variant; |
407 | 407 | $cat = $name; |
408 | - if(is_int($dot)) |
|
408 | + if (is_int($dot)) |
|
409 | 409 | { |
410 | - $culture = substr($name, $dot+1,strlen($name)); |
|
411 | - $cat = substr($name,0,$dot); |
|
410 | + $culture = substr($name, $dot + 1, strlen($name)); |
|
411 | + $cat = substr($name, 0, $dot); |
|
412 | 412 | } |
413 | 413 | $details[0] = $cat; |
414 | 414 | $details[1] = $culture; |
@@ -424,7 +424,7 @@ discard block |
||
424 | 424 | |
425 | 425 | protected function createMessageTemplate($catalogue) |
426 | 426 | { |
427 | - if($catalogue === null) { |
|
427 | + if ($catalogue === null) { |
|
428 | 428 | $catalogue = 'messages'; |
429 | 429 | } |
430 | 430 | $variants = $this->getCatalogueList($catalogue); |
@@ -433,21 +433,21 @@ discard block |
||
433 | 433 | $po_file = $this->getPOFile($mo_file); |
434 | 434 | |
435 | 435 | $dir = dirname($mo_file); |
436 | - if(!is_dir($dir)) |
|
436 | + if (!is_dir($dir)) |
|
437 | 437 | { |
438 | 438 | @mkdir($dir); |
439 | - @chmod($dir,PRADO_CHMOD); |
|
439 | + @chmod($dir, PRADO_CHMOD); |
|
440 | 440 | } |
441 | - if(!is_dir($dir)) |
|
441 | + if (!is_dir($dir)) |
|
442 | 442 | throw new TException("Unable to create directory $dir"); |
443 | 443 | |
444 | - $po = TGettext::factory('PO',$po_file); |
|
444 | + $po = TGettext::factory('PO', $po_file); |
|
445 | 445 | $result['meta']['PO-Revision-Date'] = @date('Y-m-d H:i:s'); |
446 | 446 | $result['strings'] = array(); |
447 | 447 | |
448 | 448 | $po->fromArray($result); |
449 | 449 | $mo = $po->toMO(); |
450 | - if($po->save() && $mo->save($mo_file)) |
|
450 | + if ($po->save() && $mo->save($mo_file)) |
|
451 | 451 | return array($variant, $mo_file, $po_file); |
452 | 452 | else |
453 | 453 | throw new TException("Unable to create file $po_file and $mo_file"); |
@@ -116,10 +116,11 @@ discard block |
||
116 | 116 | */ |
117 | 117 | protected function getLastModified($source) |
118 | 118 | { |
119 | - if(is_file($source)) |
|
120 | - return filemtime($source); |
|
121 | - else |
|
122 | - return 0; |
|
119 | + if(is_file($source)) { |
|
120 | + return filemtime($source); |
|
121 | + } else { |
|
122 | + return 0; |
|
123 | + } |
|
123 | 124 | } |
124 | 125 | |
125 | 126 | /** |
@@ -194,8 +195,9 @@ discard block |
||
194 | 195 | { |
195 | 196 | $file = $this->getSource($variant); |
196 | 197 | $po = $this->getPOFile($file); |
197 | - if(is_file($file) || is_file($po)) |
|
198 | - return array($variant, $file, $po); |
|
198 | + if(is_file($file) || is_file($po)) { |
|
199 | + return array($variant, $file, $po); |
|
200 | + } |
|
199 | 201 | } |
200 | 202 | return false; |
201 | 203 | } |
@@ -217,24 +219,30 @@ discard block |
||
217 | 219 | { |
218 | 220 | $messages = $this->untranslated; |
219 | 221 | |
220 | - if(count($messages) <= 0) return false; |
|
222 | + if(count($messages) <= 0) { |
|
223 | + return false; |
|
224 | + } |
|
221 | 225 | |
222 | 226 | $variants = $this->getVariants($catalogue); |
223 | 227 | |
224 | - if($variants) |
|
225 | - list($variant, $MOFile, $POFile) = $variants; |
|
226 | - else |
|
227 | - list($variant, $MOFile, $POFile) = $this->createMessageTemplate($catalogue); |
|
228 | + if($variants) { |
|
229 | + list($variant, $MOFile, $POFile) = $variants; |
|
230 | + } else { |
|
231 | + list($variant, $MOFile, $POFile) = $this->createMessageTemplate($catalogue); |
|
232 | + } |
|
228 | 233 | |
229 | - if(is_writable($MOFile) == false) |
|
230 | - throw new TIOException("Unable to save to file {$MOFile}, file must be writable."); |
|
231 | - if(is_writable($POFile) == false) |
|
232 | - throw new TIOException("Unable to save to file {$POFile}, file must be writable."); |
|
234 | + if(is_writable($MOFile) == false) { |
|
235 | + throw new TIOException("Unable to save to file {$MOFile}, file must be writable."); |
|
236 | + } |
|
237 | + if(is_writable($POFile) == false) { |
|
238 | + throw new TIOException("Unable to save to file {$POFile}, file must be writable."); |
|
239 | + } |
|
233 | 240 | |
234 | 241 | //set the strings as untranslated. |
235 | 242 | $strings = array(); |
236 | - foreach($messages as $message) |
|
237 | - $strings[$message] = ''; |
|
243 | + foreach($messages as $message) { |
|
244 | + $strings[$message] = ''; |
|
245 | + } |
|
238 | 246 | |
239 | 247 | //load the PO |
240 | 248 | $po = TGettext::factory('PO',$POFile); |
@@ -257,12 +265,13 @@ discard block |
||
257 | 265 | $mo = $po->toMO(); |
258 | 266 | if($po->save() && $mo->save($MOFile)) |
259 | 267 | { |
260 | - if(!empty($this->cache)) |
|
261 | - $this->cache->clean($variant, $this->culture); |
|
268 | + if(!empty($this->cache)) { |
|
269 | + $this->cache->clean($variant, $this->culture); |
|
270 | + } |
|
262 | 271 | return true; |
272 | + } else { |
|
273 | + return false; |
|
263 | 274 | } |
264 | - else |
|
265 | - return false; |
|
266 | 275 | } |
267 | 276 | return false; |
268 | 277 | } |
@@ -276,15 +285,18 @@ discard block |
||
276 | 285 | function delete($message, $catalogue='messages') |
277 | 286 | { |
278 | 287 | $variants = $this->getVariants($catalogue); |
279 | - if($variants) |
|
280 | - list($variant, $MOFile, $POFile) = $variants; |
|
281 | - else |
|
282 | - return false; |
|
288 | + if($variants) { |
|
289 | + list($variant, $MOFile, $POFile) = $variants; |
|
290 | + } else { |
|
291 | + return false; |
|
292 | + } |
|
283 | 293 | |
284 | - if(is_writable($MOFile) == false) |
|
285 | - throw new TIOException("Unable to modify file {$MOFile}, file must be writable."); |
|
286 | - if(is_writable($POFile) == false) |
|
287 | - throw new TIOException("Unable to modify file {$POFile}, file must be writable."); |
|
294 | + if(is_writable($MOFile) == false) { |
|
295 | + throw new TIOException("Unable to modify file {$MOFile}, file must be writable."); |
|
296 | + } |
|
297 | + if(is_writable($POFile) == false) { |
|
298 | + throw new TIOException("Unable to modify file {$POFile}, file must be writable."); |
|
299 | + } |
|
288 | 300 | |
289 | 301 | $po = TGettext::factory('PO',$POFile); |
290 | 302 | $po->load(); |
@@ -301,12 +313,13 @@ discard block |
||
301 | 313 | $mo = $po->toMO(); |
302 | 314 | if($po->save() && $mo->save($MOFile)) |
303 | 315 | { |
304 | - if(!empty($this->cache)) |
|
305 | - $this->cache->clean($variant, $this->culture); |
|
316 | + if(!empty($this->cache)) { |
|
317 | + $this->cache->clean($variant, $this->culture); |
|
318 | + } |
|
306 | 319 | return true; |
320 | + } else { |
|
321 | + return false; |
|
307 | 322 | } |
308 | - else |
|
309 | - return false; |
|
310 | 323 | } |
311 | 324 | } |
312 | 325 | |
@@ -324,15 +337,18 @@ discard block |
||
324 | 337 | function update($text, $target, $comments, $catalogue='messages') |
325 | 338 | { |
326 | 339 | $variants = $this->getVariants($catalogue); |
327 | - if($variants) |
|
328 | - list($variant, $MOFile, $POFile) = $variants; |
|
329 | - else |
|
330 | - return false; |
|
340 | + if($variants) { |
|
341 | + list($variant, $MOFile, $POFile) = $variants; |
|
342 | + } else { |
|
343 | + return false; |
|
344 | + } |
|
331 | 345 | |
332 | - if(is_writable($MOFile) == false) |
|
333 | - throw new TIOException("Unable to update file {$MOFile}, file must be writable."); |
|
334 | - if(is_writable($POFile) == false) |
|
335 | - throw new TIOException("Unable to update file {$POFile}, file must be writable."); |
|
346 | + if(is_writable($MOFile) == false) { |
|
347 | + throw new TIOException("Unable to update file {$MOFile}, file must be writable."); |
|
348 | + } |
|
349 | + if(is_writable($POFile) == false) { |
|
350 | + throw new TIOException("Unable to update file {$POFile}, file must be writable."); |
|
351 | + } |
|
336 | 352 | |
337 | 353 | |
338 | 354 | $po = TGettext::factory('PO',$POFile); |
@@ -351,12 +367,13 @@ discard block |
||
351 | 367 | |
352 | 368 | if($po->save() && $mo->save($MOFile)) |
353 | 369 | { |
354 | - if(!empty($this->cache)) |
|
355 | - $this->cache->clean($variant, $this->culture); |
|
370 | + if(!empty($this->cache)) { |
|
371 | + $this->cache->clean($variant, $this->culture); |
|
372 | + } |
|
356 | 373 | return true; |
374 | + } else { |
|
375 | + return false; |
|
357 | 376 | } |
358 | - else |
|
359 | - return false; |
|
360 | 377 | } |
361 | 378 | } |
362 | 379 | |
@@ -438,8 +455,9 @@ discard block |
||
438 | 455 | @mkdir($dir); |
439 | 456 | @chmod($dir,PRADO_CHMOD); |
440 | 457 | } |
441 | - if(!is_dir($dir)) |
|
442 | - throw new TException("Unable to create directory $dir"); |
|
458 | + if(!is_dir($dir)) { |
|
459 | + throw new TException("Unable to create directory $dir"); |
|
460 | + } |
|
443 | 461 | |
444 | 462 | $po = TGettext::factory('PO',$po_file); |
445 | 463 | $result['meta']['PO-Revision-Date'] = @date('Y-m-d H:i:s'); |
@@ -447,10 +465,11 @@ discard block |
||
447 | 465 | |
448 | 466 | $po->fromArray($result); |
449 | 467 | $mo = $po->toMO(); |
450 | - if($po->save() && $mo->save($mo_file)) |
|
451 | - return array($variant, $mo_file, $po_file); |
|
452 | - else |
|
453 | - throw new TException("Unable to create file $po_file and $mo_file"); |
|
468 | + if($po->save() && $mo->save($mo_file)) { |
|
469 | + return array($variant, $mo_file, $po_file); |
|
470 | + } else { |
|
471 | + throw new TException("Unable to create file $po_file and $mo_file"); |
|
472 | + } |
|
454 | 473 | } |
455 | 474 | } |
456 | 475 |
@@ -61,6 +61,7 @@ discard block |
||
61 | 61 | * Constructor. |
62 | 62 | * Create a new message source using MySQL. |
63 | 63 | * @param string MySQL datasource, in PEAR's DB DSN format. |
64 | + * @param string $source |
|
64 | 65 | * @see MessageSource::factory(); |
65 | 66 | */ |
66 | 67 | function __construct($source) |
@@ -271,7 +272,9 @@ discard block |
||
271 | 272 | |
272 | 273 | /** |
273 | 274 | * Update the catalogue last modified time. |
274 | - * @return boolean true if updated, false otherwise. |
|
275 | + * @param integer $cat_id |
|
276 | + * @param string $variant |
|
277 | + * @return resource true if updated, false otherwise. |
|
275 | 278 | */ |
276 | 279 | private function updateCatalogueTime($cat_id, $variant) |
277 | 280 | { |
@@ -92,43 +92,43 @@ |
||
92 | 92 | */ |
93 | 93 | $dsninfo = $this->dns; |
94 | 94 | |
95 | - if (isset($dsninfo['protocol']) && $dsninfo['protocol'] == 'unix') |
|
96 | - $dbhost = ':' . $dsninfo['socket']; |
|
97 | - else |
|
98 | - { |
|
95 | + if (isset($dsninfo['protocol']) && $dsninfo['protocol'] == 'unix') |
|
96 | + $dbhost = ':' . $dsninfo['socket']; |
|
97 | + else |
|
98 | + { |
|
99 | 99 | $dbhost = $dsninfo['hostspec'] ? $dsninfo['hostspec'] : 'localhost'; |
100 | - if (!empty($dsninfo['port'])) |
|
101 | - $dbhost .= ':' . $dsninfo['port']; |
|
102 | - } |
|
103 | - $user = $dsninfo['username']; |
|
104 | - $pw = $dsninfo['password']; |
|
105 | - |
|
106 | - $connect_function = 'mysql_connect'; |
|
107 | - |
|
108 | - if ($dbhost && $user && $pw) |
|
109 | - $conn = @$connect_function($dbhost, $user, $pw); |
|
110 | - elseif ($dbhost && $user) |
|
111 | - $conn = @$connect_function($dbhost, $user); |
|
112 | - elseif ($dbhost) |
|
113 | - $conn = @$connect_function($dbhost); |
|
114 | - else |
|
115 | - $conn = false; |
|
116 | - |
|
117 | - if (empty($conn)) |
|
118 | - { |
|
119 | - throw new Exception('Error in connecting to '.$dsninfo); |
|
120 | - } |
|
121 | - |
|
122 | - if ($dsninfo['database']) |
|
123 | - { |
|
124 | - if (!@mysql_select_db($dsninfo['database'], $conn)) |
|
125 | - throw new Exception('Error in connecting database, dns:'. |
|
126 | - $dsninfo); |
|
127 | - } |
|
128 | - else |
|
129 | - throw new Exception('Please provide a database for message'. |
|
130 | - ' translation.'); |
|
131 | - return $conn; |
|
100 | + if (!empty($dsninfo['port'])) |
|
101 | + $dbhost .= ':' . $dsninfo['port']; |
|
102 | + } |
|
103 | + $user = $dsninfo['username']; |
|
104 | + $pw = $dsninfo['password']; |
|
105 | + |
|
106 | + $connect_function = 'mysql_connect'; |
|
107 | + |
|
108 | + if ($dbhost && $user && $pw) |
|
109 | + $conn = @$connect_function($dbhost, $user, $pw); |
|
110 | + elseif ($dbhost && $user) |
|
111 | + $conn = @$connect_function($dbhost, $user); |
|
112 | + elseif ($dbhost) |
|
113 | + $conn = @$connect_function($dbhost); |
|
114 | + else |
|
115 | + $conn = false; |
|
116 | + |
|
117 | + if (empty($conn)) |
|
118 | + { |
|
119 | + throw new Exception('Error in connecting to '.$dsninfo); |
|
120 | + } |
|
121 | + |
|
122 | + if ($dsninfo['database']) |
|
123 | + { |
|
124 | + if (!@mysql_select_db($dsninfo['database'], $conn)) |
|
125 | + throw new Exception('Error in connecting database, dns:'. |
|
126 | + $dsninfo); |
|
127 | + } |
|
128 | + else |
|
129 | + throw new Exception('Please provide a database for message'. |
|
130 | + ' translation.'); |
|
131 | + return $conn; |
|
132 | 132 | } |
133 | 133 | |
134 | 134 | /** |
@@ -20,12 +20,12 @@ discard block |
||
20 | 20 | /** |
21 | 21 | * Get the MessageSource class file. |
22 | 22 | */ |
23 | -require_once(dirname(__FILE__).'/MessageSource.php'); |
|
23 | +require_once(dirname(__FILE__) . '/MessageSource.php'); |
|
24 | 24 | |
25 | 25 | /** |
26 | 26 | * Get the I18N utility file, contains the DSN parser. |
27 | 27 | */ |
28 | -require_once(dirname(__FILE__).'/util.php'); |
|
28 | +require_once(dirname(__FILE__) . '/util.php'); |
|
29 | 29 | |
30 | 30 | /** |
31 | 31 | * MessageSource_MySQL class. |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | */ |
66 | 66 | function __construct($source) |
67 | 67 | { |
68 | - $this->source = (string)$source; |
|
68 | + $this->source = (string) $source; |
|
69 | 69 | $this->dns = parseDSN($this->source); |
70 | 70 | $this->db = $this->connect(); |
71 | 71 | } |
@@ -116,17 +116,17 @@ discard block |
||
116 | 116 | |
117 | 117 | if (empty($conn)) |
118 | 118 | { |
119 | - throw new Exception('Error in connecting to '.$dsninfo); |
|
119 | + throw new Exception('Error in connecting to ' . $dsninfo); |
|
120 | 120 | } |
121 | 121 | |
122 | 122 | if ($dsninfo['database']) |
123 | 123 | { |
124 | 124 | if (!@mysql_select_db($dsninfo['database'], $conn)) |
125 | - throw new Exception('Error in connecting database, dns:'. |
|
125 | + throw new Exception('Error in connecting database, dns:' . |
|
126 | 126 | $dsninfo); |
127 | 127 | } |
128 | 128 | else |
129 | - throw new Exception('Please provide a database for message'. |
|
129 | + throw new Exception('Please provide a database for message' . |
|
130 | 130 | ' translation.'); |
131 | 131 | return $conn; |
132 | 132 | } |
@@ -157,11 +157,11 @@ discard block |
||
157 | 157 | AND c.name = '{$variant}' |
158 | 158 | ORDER BY id ASC"; |
159 | 159 | |
160 | - $rs = mysql_query($statement,$this->db); |
|
160 | + $rs = mysql_query($statement, $this->db); |
|
161 | 161 | |
162 | 162 | $result = array(); |
163 | 163 | |
164 | - while($row = mysql_fetch_array($rs,MYSQL_NUM)) |
|
164 | + while ($row = mysql_fetch_array($rs, MYSQL_NUM)) |
|
165 | 165 | { |
166 | 166 | $source = $row[1]; |
167 | 167 | $result[$source][] = $row[2]; //target |
@@ -186,7 +186,7 @@ discard block |
||
186 | 186 | "SELECT date_modified FROM catalogue WHERE name = '{$source}'", |
187 | 187 | $this->db); |
188 | 188 | |
189 | - $result = $rs ? (int)mysql_result($rs,0) : 0; |
|
189 | + $result = $rs ? (int) mysql_result($rs, 0) : 0; |
|
190 | 190 | |
191 | 191 | return $result; |
192 | 192 | } |
@@ -199,13 +199,13 @@ discard block |
||
199 | 199 | */ |
200 | 200 | protected function isValidSource($variant) |
201 | 201 | { |
202 | - $variant = mysql_real_escape_string ($variant); |
|
202 | + $variant = mysql_real_escape_string($variant); |
|
203 | 203 | |
204 | 204 | $rs = mysql_query( |
205 | 205 | "SELECT COUNT(*) FROM catalogue WHERE name = '{$variant}'", |
206 | 206 | $this->db); |
207 | 207 | |
208 | - $row = mysql_fetch_array($rs,MYSQL_NUM); |
|
208 | + $row = mysql_fetch_array($rs, MYSQL_NUM); |
|
209 | 209 | |
210 | 210 | $result = $row && $row[0] == '1'; |
211 | 211 | |
@@ -219,18 +219,18 @@ discard block |
||
219 | 219 | */ |
220 | 220 | protected function getCatalogueList($catalogue) |
221 | 221 | { |
222 | - $variants = explode('_',$this->culture); |
|
222 | + $variants = explode('_', $this->culture); |
|
223 | 223 | |
224 | 224 | $catalogues = array($catalogue); |
225 | 225 | |
226 | 226 | $variant = null; |
227 | 227 | |
228 | - for($i = 0, $k = count($variants); $i < $k; ++$i) |
|
228 | + for ($i = 0, $k = count($variants); $i < $k; ++$i) |
|
229 | 229 | { |
230 | - if(isset($variants[$i]{0})) |
|
230 | + if (isset($variants[$i]{0})) |
|
231 | 231 | { |
232 | - $variant .= ($variant)?'_'.$variants[$i]:$variants[$i]; |
|
233 | - $catalogues[] = $catalogue.'.'.$variant; |
|
232 | + $variant .= ($variant) ? '_' . $variants[$i] : $variants[$i]; |
|
233 | + $catalogues[] = $catalogue . '.' . $variant; |
|
234 | 234 | } |
235 | 235 | } |
236 | 236 | return array_reverse($catalogues); |
@@ -241,22 +241,22 @@ discard block |
||
241 | 241 | * @param string catalogue |
242 | 242 | * @return array catalogue details, array($cat_id, $variant, $count). |
243 | 243 | */ |
244 | - private function getCatalogueDetails($catalogue='messages') |
|
244 | + private function getCatalogueDetails($catalogue = 'messages') |
|
245 | 245 | { |
246 | - if(empty($catalogue)) |
|
246 | + if (empty($catalogue)) |
|
247 | 247 | $catalogue = 'messages'; |
248 | 248 | |
249 | - $variant = $catalogue.'.'.$this->culture; |
|
249 | + $variant = $catalogue . '.' . $this->culture; |
|
250 | 250 | |
251 | 251 | $name = mysql_real_escape_string($this->getSource($variant)); |
252 | 252 | |
253 | 253 | $rs = mysql_query("SELECT cat_id |
254 | 254 | FROM catalogue WHERE name = '{$name}'", $this->db); |
255 | 255 | |
256 | - if(mysql_num_rows($rs) != 1) |
|
256 | + if (mysql_num_rows($rs) != 1) |
|
257 | 257 | return false; |
258 | 258 | |
259 | - $cat_id = (int)mysql_result($rs,0); |
|
259 | + $cat_id = (int) mysql_result($rs, 0); |
|
260 | 260 | |
261 | 261 | //first get the catalogue ID |
262 | 262 | $rs = mysql_query( |
@@ -264,7 +264,7 @@ discard block |
||
264 | 264 | FROM trans_unit |
265 | 265 | WHERE cat_id = {$cat_id}", $this->db); |
266 | 266 | |
267 | - $count = (int)mysql_result($rs,0); |
|
267 | + $count = (int) mysql_result($rs, 0); |
|
268 | 268 | |
269 | 269 | return array($cat_id, $variant, $count); |
270 | 270 | } |
@@ -281,7 +281,7 @@ discard block |
||
281 | 281 | SET date_modified = {$time} |
282 | 282 | WHERE cat_id = {$cat_id}", $this->db); |
283 | 283 | |
284 | - if(!empty($this->cache)) |
|
284 | + if (!empty($this->cache)) |
|
285 | 285 | $this->cache->clean($variant, $this->culture); |
286 | 286 | |
287 | 287 | return $result; |
@@ -294,25 +294,25 @@ discard block |
||
294 | 294 | * @param string the catalogue to add to |
295 | 295 | * @return boolean true if saved successfuly, false otherwise. |
296 | 296 | */ |
297 | - function save($catalogue='messages') |
|
297 | + function save($catalogue = 'messages') |
|
298 | 298 | { |
299 | 299 | $messages = $this->untranslated; |
300 | 300 | |
301 | - if(count($messages) <= 0) return false; |
|
301 | + if (count($messages) <= 0) return false; |
|
302 | 302 | |
303 | 303 | $details = $this->getCatalogueDetails($catalogue); |
304 | 304 | |
305 | - if($details) |
|
305 | + if ($details) |
|
306 | 306 | list($cat_id, $variant, $count) = $details; |
307 | 307 | else |
308 | 308 | return false; |
309 | 309 | |
310 | - if($cat_id <= 0) return false; |
|
310 | + if ($cat_id <= 0) return false; |
|
311 | 311 | $inserted = 0; |
312 | 312 | |
313 | 313 | $time = time(); |
314 | 314 | |
315 | - foreach($messages as $message) |
|
315 | + foreach ($messages as $message) |
|
316 | 316 | { |
317 | 317 | $count++; $inserted++; |
318 | 318 | $message = mysql_real_escape_string($message); |
@@ -321,7 +321,7 @@ discard block |
||
321 | 321 | ({$cat_id}, {$count},'{$message}',$time)"; |
322 | 322 | mysql_query($statement, $this->db); |
323 | 323 | } |
324 | - if($inserted > 0) |
|
324 | + if ($inserted > 0) |
|
325 | 325 | $this->updateCatalogueTime($cat_id, $variant); |
326 | 326 | |
327 | 327 | return $inserted > 0; |
@@ -333,10 +333,10 @@ discard block |
||
333 | 333 | * @param string the catalogue to delete from. |
334 | 334 | * @return boolean true if deleted, false otherwise. |
335 | 335 | */ |
336 | - function delete($message, $catalogue='messages') |
|
336 | + function delete($message, $catalogue = 'messages') |
|
337 | 337 | { |
338 | 338 | $details = $this->getCatalogueDetails($catalogue); |
339 | - if($details) |
|
339 | + if ($details) |
|
340 | 340 | list($cat_id, $variant, $count) = $details; |
341 | 341 | else |
342 | 342 | return false; |
@@ -349,7 +349,7 @@ discard block |
||
349 | 349 | |
350 | 350 | mysql_query($statement, $this->db); |
351 | 351 | |
352 | - if(mysql_affected_rows($this->db) == 1) |
|
352 | + if (mysql_affected_rows($this->db) == 1) |
|
353 | 353 | $deleted = $this->updateCatalogueTime($cat_id, $variant); |
354 | 354 | |
355 | 355 | return $deleted; |
@@ -364,10 +364,10 @@ discard block |
||
364 | 364 | * @param string the catalogue of the translation. |
365 | 365 | * @return boolean true if translation was updated, false otherwise. |
366 | 366 | */ |
367 | - function update($text, $target, $comments, $catalogue='messages') |
|
367 | + function update($text, $target, $comments, $catalogue = 'messages') |
|
368 | 368 | { |
369 | 369 | $details = $this->getCatalogueDetails($catalogue); |
370 | - if($details) |
|
370 | + if ($details) |
|
371 | 371 | list($cat_id, $variant, $count) = $details; |
372 | 372 | else |
373 | 373 | return false; |
@@ -388,7 +388,7 @@ discard block |
||
388 | 388 | $updated = false; |
389 | 389 | |
390 | 390 | mysql_query($statement, $this->db); |
391 | - if(mysql_affected_rows($this->db) == 1) |
|
391 | + if (mysql_affected_rows($this->db) == 1) |
|
392 | 392 | $updated = $this->updateCatalogueTime($cat_id, $variant); |
393 | 393 | |
394 | 394 | return $updated; |
@@ -403,10 +403,10 @@ discard block |
||
403 | 403 | $statement = 'SELECT name FROM catalogue ORDER BY name'; |
404 | 404 | $rs = mysql_query($statement, $this->db); |
405 | 405 | $result = array(); |
406 | - while($row = mysql_fetch_array($rs,MYSQL_NUM)) |
|
406 | + while ($row = mysql_fetch_array($rs, MYSQL_NUM)) |
|
407 | 407 | { |
408 | - $details = explode('.',$row[0]); |
|
409 | - if(!isset($details[1])) $details[1] = null; |
|
408 | + $details = explode('.', $row[0]); |
|
409 | + if (!isset($details[1])) $details[1] = null; |
|
410 | 410 | |
411 | 411 | $result[] = $details; |
412 | 412 | } |
@@ -92,27 +92,29 @@ discard block |
||
92 | 92 | */ |
93 | 93 | $dsninfo = $this->dns; |
94 | 94 | |
95 | - if (isset($dsninfo['protocol']) && $dsninfo['protocol'] == 'unix') |
|
96 | - $dbhost = ':' . $dsninfo['socket']; |
|
97 | - else |
|
95 | + if (isset($dsninfo['protocol']) && $dsninfo['protocol'] == 'unix') { |
|
96 | + $dbhost = ':' . $dsninfo['socket']; |
|
97 | + } else |
|
98 | 98 | { |
99 | 99 | $dbhost = $dsninfo['hostspec'] ? $dsninfo['hostspec'] : 'localhost'; |
100 | - if (!empty($dsninfo['port'])) |
|
101 | - $dbhost .= ':' . $dsninfo['port']; |
|
100 | + if (!empty($dsninfo['port'])) { |
|
101 | + $dbhost .= ':' . $dsninfo['port']; |
|
102 | + } |
|
102 | 103 | } |
103 | 104 | $user = $dsninfo['username']; |
104 | 105 | $pw = $dsninfo['password']; |
105 | 106 | |
106 | 107 | $connect_function = 'mysql_connect'; |
107 | 108 | |
108 | - if ($dbhost && $user && $pw) |
|
109 | - $conn = @$connect_function($dbhost, $user, $pw); |
|
110 | - elseif ($dbhost && $user) |
|
111 | - $conn = @$connect_function($dbhost, $user); |
|
112 | - elseif ($dbhost) |
|
113 | - $conn = @$connect_function($dbhost); |
|
114 | - else |
|
115 | - $conn = false; |
|
109 | + if ($dbhost && $user && $pw) { |
|
110 | + $conn = @$connect_function($dbhost, $user, $pw); |
|
111 | + } elseif ($dbhost && $user) { |
|
112 | + $conn = @$connect_function($dbhost, $user); |
|
113 | + } elseif ($dbhost) { |
|
114 | + $conn = @$connect_function($dbhost); |
|
115 | + } else { |
|
116 | + $conn = false; |
|
117 | + } |
|
116 | 118 | |
117 | 119 | if (empty($conn)) |
118 | 120 | { |
@@ -121,13 +123,14 @@ discard block |
||
121 | 123 | |
122 | 124 | if ($dsninfo['database']) |
123 | 125 | { |
124 | - if (!@mysql_select_db($dsninfo['database'], $conn)) |
|
125 | - throw new Exception('Error in connecting database, dns:'. |
|
126 | + if (!@mysql_select_db($dsninfo['database'], $conn)) { |
|
127 | + throw new Exception('Error in connecting database, dns:'. |
|
126 | 128 | $dsninfo); |
127 | - } |
|
128 | - else |
|
129 | - throw new Exception('Please provide a database for message'. |
|
129 | + } |
|
130 | + } else { |
|
131 | + throw new Exception('Please provide a database for message'. |
|
130 | 132 | ' translation.'); |
133 | + } |
|
131 | 134 | return $conn; |
132 | 135 | } |
133 | 136 | |
@@ -243,8 +246,9 @@ discard block |
||
243 | 246 | */ |
244 | 247 | private function getCatalogueDetails($catalogue='messages') |
245 | 248 | { |
246 | - if(empty($catalogue)) |
|
247 | - $catalogue = 'messages'; |
|
249 | + if(empty($catalogue)) { |
|
250 | + $catalogue = 'messages'; |
|
251 | + } |
|
248 | 252 | |
249 | 253 | $variant = $catalogue.'.'.$this->culture; |
250 | 254 | |
@@ -253,8 +257,9 @@ discard block |
||
253 | 257 | $rs = mysql_query("SELECT cat_id |
254 | 258 | FROM catalogue WHERE name = '{$name}'", $this->db); |
255 | 259 | |
256 | - if(mysql_num_rows($rs) != 1) |
|
257 | - return false; |
|
260 | + if(mysql_num_rows($rs) != 1) { |
|
261 | + return false; |
|
262 | + } |
|
258 | 263 | |
259 | 264 | $cat_id = (int)mysql_result($rs,0); |
260 | 265 | |
@@ -281,8 +286,9 @@ discard block |
||
281 | 286 | SET date_modified = {$time} |
282 | 287 | WHERE cat_id = {$cat_id}", $this->db); |
283 | 288 | |
284 | - if(!empty($this->cache)) |
|
285 | - $this->cache->clean($variant, $this->culture); |
|
289 | + if(!empty($this->cache)) { |
|
290 | + $this->cache->clean($variant, $this->culture); |
|
291 | + } |
|
286 | 292 | |
287 | 293 | return $result; |
288 | 294 | } |
@@ -298,16 +304,21 @@ discard block |
||
298 | 304 | { |
299 | 305 | $messages = $this->untranslated; |
300 | 306 | |
301 | - if(count($messages) <= 0) return false; |
|
307 | + if(count($messages) <= 0) { |
|
308 | + return false; |
|
309 | + } |
|
302 | 310 | |
303 | 311 | $details = $this->getCatalogueDetails($catalogue); |
304 | 312 | |
305 | - if($details) |
|
306 | - list($cat_id, $variant, $count) = $details; |
|
307 | - else |
|
308 | - return false; |
|
313 | + if($details) { |
|
314 | + list($cat_id, $variant, $count) = $details; |
|
315 | + } else { |
|
316 | + return false; |
|
317 | + } |
|
309 | 318 | |
310 | - if($cat_id <= 0) return false; |
|
319 | + if($cat_id <= 0) { |
|
320 | + return false; |
|
321 | + } |
|
311 | 322 | $inserted = 0; |
312 | 323 | |
313 | 324 | $time = time(); |
@@ -321,8 +332,9 @@ discard block |
||
321 | 332 | ({$cat_id}, {$count},'{$message}',$time)"; |
322 | 333 | mysql_query($statement, $this->db); |
323 | 334 | } |
324 | - if($inserted > 0) |
|
325 | - $this->updateCatalogueTime($cat_id, $variant); |
|
335 | + if($inserted > 0) { |
|
336 | + $this->updateCatalogueTime($cat_id, $variant); |
|
337 | + } |
|
326 | 338 | |
327 | 339 | return $inserted > 0; |
328 | 340 | } |
@@ -336,10 +348,11 @@ discard block |
||
336 | 348 | function delete($message, $catalogue='messages') |
337 | 349 | { |
338 | 350 | $details = $this->getCatalogueDetails($catalogue); |
339 | - if($details) |
|
340 | - list($cat_id, $variant, $count) = $details; |
|
341 | - else |
|
342 | - return false; |
|
351 | + if($details) { |
|
352 | + list($cat_id, $variant, $count) = $details; |
|
353 | + } else { |
|
354 | + return false; |
|
355 | + } |
|
343 | 356 | |
344 | 357 | $text = mysql_real_escape_string($message); |
345 | 358 | |
@@ -349,8 +362,9 @@ discard block |
||
349 | 362 | |
350 | 363 | mysql_query($statement, $this->db); |
351 | 364 | |
352 | - if(mysql_affected_rows($this->db) == 1) |
|
353 | - $deleted = $this->updateCatalogueTime($cat_id, $variant); |
|
365 | + if(mysql_affected_rows($this->db) == 1) { |
|
366 | + $deleted = $this->updateCatalogueTime($cat_id, $variant); |
|
367 | + } |
|
354 | 368 | |
355 | 369 | return $deleted; |
356 | 370 | |
@@ -367,10 +381,11 @@ discard block |
||
367 | 381 | function update($text, $target, $comments, $catalogue='messages') |
368 | 382 | { |
369 | 383 | $details = $this->getCatalogueDetails($catalogue); |
370 | - if($details) |
|
371 | - list($cat_id, $variant, $count) = $details; |
|
372 | - else |
|
373 | - return false; |
|
384 | + if($details) { |
|
385 | + list($cat_id, $variant, $count) = $details; |
|
386 | + } else { |
|
387 | + return false; |
|
388 | + } |
|
374 | 389 | |
375 | 390 | $comments = mysql_real_escape_string($comments); |
376 | 391 | $target = mysql_real_escape_string($target); |
@@ -388,8 +403,9 @@ discard block |
||
388 | 403 | $updated = false; |
389 | 404 | |
390 | 405 | mysql_query($statement, $this->db); |
391 | - if(mysql_affected_rows($this->db) == 1) |
|
392 | - $updated = $this->updateCatalogueTime($cat_id, $variant); |
|
406 | + if(mysql_affected_rows($this->db) == 1) { |
|
407 | + $updated = $this->updateCatalogueTime($cat_id, $variant); |
|
408 | + } |
|
393 | 409 | |
394 | 410 | return $updated; |
395 | 411 | } |
@@ -406,7 +422,9 @@ discard block |
||
406 | 422 | while($row = mysql_fetch_array($rs,MYSQL_NUM)) |
407 | 423 | { |
408 | 424 | $details = explode('.',$row[0]); |
409 | - if(!isset($details[1])) $details[1] = null; |
|
425 | + if(!isset($details[1])) { |
|
426 | + $details[1] = null; |
|
427 | + } |
|
410 | 428 | |
411 | 429 | $result[] = $details; |
412 | 430 | } |
@@ -198,7 +198,9 @@ |
||
198 | 198 | |
199 | 199 | /** |
200 | 200 | * Update the catalogue last modified time. |
201 | - * @return boolean true if updated, false otherwise. |
|
201 | + * @param integer $cat_id |
|
202 | + * @param string $variant |
|
203 | + * @return SQLiteResult true if updated, false otherwise. |
|
202 | 204 | */ |
203 | 205 | private function updateCatalogueTime($cat_id, $variant, $db) |
204 | 206 | { |
@@ -20,12 +20,12 @@ discard block |
||
20 | 20 | /** |
21 | 21 | * Get the MessageSource class file. |
22 | 22 | */ |
23 | -require_once(dirname(__FILE__).'/MessageSource.php'); |
|
23 | +require_once(dirname(__FILE__) . '/MessageSource.php'); |
|
24 | 24 | |
25 | 25 | /** |
26 | 26 | * Get the I18N utility file, contains the DSN parser. |
27 | 27 | */ |
28 | -require_once(dirname(__FILE__).'/util.php'); |
|
28 | +require_once(dirname(__FILE__) . '/util.php'); |
|
29 | 29 | |
30 | 30 | /** |
31 | 31 | * MessageSource_SQLite class. |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | */ |
55 | 55 | function __construct($source) |
56 | 56 | { |
57 | - $dsn = parseDSN((string)$source); |
|
57 | + $dsn = parseDSN((string) $source); |
|
58 | 58 | $this->source = $dsn['database']; |
59 | 59 | } |
60 | 60 | |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | |
81 | 81 | $result = array(); |
82 | 82 | |
83 | - while($row = sqlite_fetch_array($rs,SQLITE_NUM)) |
|
83 | + while ($row = sqlite_fetch_array($rs, SQLITE_NUM)) |
|
84 | 84 | { |
85 | 85 | $source = $row[1]; |
86 | 86 | $result[$source][] = $row[2]; //target |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | "SELECT date_modified FROM catalogue WHERE name = '{$source}'", |
110 | 110 | $db); |
111 | 111 | |
112 | - $result = $rs ? (int)sqlite_fetch_single($rs) : 0; |
|
112 | + $result = $rs ? (int) sqlite_fetch_single($rs) : 0; |
|
113 | 113 | |
114 | 114 | sqlite_close($db); |
115 | 115 | |
@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | $rs = sqlite_query( |
130 | 130 | "SELECT COUNT(*) FROM catalogue WHERE name = '{$variant}'", |
131 | 131 | $db); |
132 | - $result = $rs && (int)sqlite_fetch_single($rs); |
|
132 | + $result = $rs && (int) sqlite_fetch_single($rs); |
|
133 | 133 | sqlite_close($db); |
134 | 134 | |
135 | 135 | return $result; |
@@ -142,18 +142,18 @@ discard block |
||
142 | 142 | */ |
143 | 143 | protected function getCatalogueList($catalogue) |
144 | 144 | { |
145 | - $variants = explode('_',$this->culture); |
|
145 | + $variants = explode('_', $this->culture); |
|
146 | 146 | |
147 | 147 | $catalogues = array($catalogue); |
148 | 148 | |
149 | 149 | $variant = null; |
150 | 150 | |
151 | - for($i = 0, $k = count($variants); $i < $k; ++$i) |
|
151 | + for ($i = 0, $k = count($variants); $i < $k; ++$i) |
|
152 | 152 | { |
153 | - if(isset($variants[$i]{0})) |
|
153 | + if (isset($variants[$i]{0})) |
|
154 | 154 | { |
155 | - $variant .= ($variant)?'_'.$variants[$i]:$variants[$i]; |
|
156 | - $catalogues[] = $catalogue.'.'.$variant; |
|
155 | + $variant .= ($variant) ? '_' . $variants[$i] : $variants[$i]; |
|
156 | + $catalogues[] = $catalogue . '.' . $variant; |
|
157 | 157 | } |
158 | 158 | } |
159 | 159 | return array_reverse($catalogues); |
@@ -164,12 +164,12 @@ discard block |
||
164 | 164 | * @param string catalogue |
165 | 165 | * @return array catalogue details, array($cat_id, $variant, $count). |
166 | 166 | */ |
167 | - private function getCatalogueDetails($catalogue='messages') |
|
167 | + private function getCatalogueDetails($catalogue = 'messages') |
|
168 | 168 | { |
169 | - if(empty($catalogue)) |
|
169 | + if (empty($catalogue)) |
|
170 | 170 | $catalogue = 'messages'; |
171 | 171 | |
172 | - $variant = $catalogue.'.'.$this->culture; |
|
172 | + $variant = $catalogue . '.' . $this->culture; |
|
173 | 173 | |
174 | 174 | $name = sqlite_escape_string($this->getSource($variant)); |
175 | 175 | |
@@ -178,10 +178,10 @@ discard block |
||
178 | 178 | $rs = sqlite_query("SELECT cat_id |
179 | 179 | FROM catalogue WHERE name = '{$name}'", $db); |
180 | 180 | |
181 | - if(sqlite_num_rows($rs) != 1) |
|
181 | + if (sqlite_num_rows($rs) != 1) |
|
182 | 182 | return false; |
183 | 183 | |
184 | - $cat_id = (int)sqlite_fetch_single($rs); |
|
184 | + $cat_id = (int) sqlite_fetch_single($rs); |
|
185 | 185 | |
186 | 186 | //first get the catalogue ID |
187 | 187 | $rs = sqlite_query( |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | FROM trans_unit |
190 | 190 | WHERE cat_id = {$cat_id}", $db); |
191 | 191 | |
192 | - $count = (int)sqlite_fetch_single($rs); |
|
192 | + $count = (int) sqlite_fetch_single($rs); |
|
193 | 193 | |
194 | 194 | sqlite_close($db); |
195 | 195 | |
@@ -208,7 +208,7 @@ discard block |
||
208 | 208 | SET date_modified = {$time} |
209 | 209 | WHERE cat_id = {$cat_id}", $db); |
210 | 210 | |
211 | - if(!empty($this->cache)) |
|
211 | + if (!empty($this->cache)) |
|
212 | 212 | $this->cache->clean($variant, $this->culture); |
213 | 213 | |
214 | 214 | return $result; |
@@ -221,37 +221,37 @@ discard block |
||
221 | 221 | * @param string the catalogue to add to |
222 | 222 | * @return boolean true if saved successfuly, false otherwise. |
223 | 223 | */ |
224 | - function save($catalogue='messages') |
|
224 | + function save($catalogue = 'messages') |
|
225 | 225 | { |
226 | 226 | $messages = $this->untranslated; |
227 | 227 | |
228 | - if(count($messages) <= 0) return false; |
|
228 | + if (count($messages) <= 0) return false; |
|
229 | 229 | |
230 | 230 | $details = $this->getCatalogueDetails($catalogue); |
231 | 231 | |
232 | - if($details) |
|
232 | + if ($details) |
|
233 | 233 | list($cat_id, $variant, $count) = $details; |
234 | 234 | else |
235 | 235 | return false; |
236 | 236 | |
237 | - if($cat_id <= 0) return false; |
|
237 | + if ($cat_id <= 0) return false; |
|
238 | 238 | $inserted = 0; |
239 | 239 | |
240 | 240 | $db = sqlite_open($this->source); |
241 | 241 | $time = time(); |
242 | 242 | |
243 | - foreach($messages as $message) |
|
243 | + foreach ($messages as $message) |
|
244 | 244 | { |
245 | 245 | $message = sqlite_escape_string($message); |
246 | 246 | $statement = "INSERT INTO trans_unit |
247 | 247 | (cat_id,id,source,date_added) VALUES |
248 | 248 | ({$cat_id}, {$count},'{$message}',$time)"; |
249 | - if(sqlite_query($statement, $db)) |
|
249 | + if (sqlite_query($statement, $db)) |
|
250 | 250 | { |
251 | 251 | $count++; $inserted++; |
252 | 252 | } |
253 | 253 | } |
254 | - if($inserted > 0) |
|
254 | + if ($inserted > 0) |
|
255 | 255 | $this->updateCatalogueTime($cat_id, $variant, $db); |
256 | 256 | |
257 | 257 | sqlite_close($db); |
@@ -267,10 +267,10 @@ discard block |
||
267 | 267 | * @param string the catalogue of the translation. |
268 | 268 | * @return boolean true if translation was updated, false otherwise. |
269 | 269 | */ |
270 | - function update($text, $target, $comments, $catalogue='messages') |
|
270 | + function update($text, $target, $comments, $catalogue = 'messages') |
|
271 | 271 | { |
272 | 272 | $details = $this->getCatalogueDetails($catalogue); |
273 | - if($details) |
|
273 | + if ($details) |
|
274 | 274 | list($cat_id, $variant, $count) = $details; |
275 | 275 | else |
276 | 276 | return false; |
@@ -292,7 +292,7 @@ discard block |
||
292 | 292 | |
293 | 293 | $updated = false; |
294 | 294 | |
295 | - if(sqlite_query($statement, $db)) |
|
295 | + if (sqlite_query($statement, $db)) |
|
296 | 296 | $updated = $this->updateCatalogueTime($cat_id, $variant, $db); |
297 | 297 | |
298 | 298 | sqlite_close($db); |
@@ -306,10 +306,10 @@ discard block |
||
306 | 306 | * @param string the catalogue to delete from. |
307 | 307 | * @return boolean true if deleted, false otherwise. |
308 | 308 | */ |
309 | - function delete($message, $catalogue='messages') |
|
309 | + function delete($message, $catalogue = 'messages') |
|
310 | 310 | { |
311 | 311 | $details = $this->getCatalogueDetails($catalogue); |
312 | - if($details) |
|
312 | + if ($details) |
|
313 | 313 | list($cat_id, $variant, $count) = $details; |
314 | 314 | else |
315 | 315 | return false; |
@@ -321,7 +321,7 @@ discard block |
||
321 | 321 | cat_id = {$cat_id} AND source = '{$message}'"; |
322 | 322 | $deleted = false; |
323 | 323 | |
324 | - if(sqlite_query($statement, $db)) |
|
324 | + if (sqlite_query($statement, $db)) |
|
325 | 325 | $deleted = $this->updateCatalogueTime($cat_id, $variant, $db); |
326 | 326 | |
327 | 327 | sqlite_close($db); |
@@ -339,10 +339,10 @@ discard block |
||
339 | 339 | $statement = 'SELECT name FROM catalogue ORDER BY name'; |
340 | 340 | $rs = sqlite_query($statement, $db); |
341 | 341 | $result = array(); |
342 | - while($row = sqlite_fetch_array($rs,SQLITE_NUM)) |
|
342 | + while ($row = sqlite_fetch_array($rs, SQLITE_NUM)) |
|
343 | 343 | { |
344 | - $details = explode('.',$row[0]); |
|
345 | - if(!isset($details[1])) $details[1] = null; |
|
344 | + $details = explode('.', $row[0]); |
|
345 | + if (!isset($details[1])) $details[1] = null; |
|
346 | 346 | |
347 | 347 | $result[] = $details; |
348 | 348 | } |
@@ -166,8 +166,9 @@ discard block |
||
166 | 166 | */ |
167 | 167 | private function getCatalogueDetails($catalogue='messages') |
168 | 168 | { |
169 | - if(empty($catalogue)) |
|
170 | - $catalogue = 'messages'; |
|
169 | + if(empty($catalogue)) { |
|
170 | + $catalogue = 'messages'; |
|
171 | + } |
|
171 | 172 | |
172 | 173 | $variant = $catalogue.'.'.$this->culture; |
173 | 174 | |
@@ -178,8 +179,9 @@ discard block |
||
178 | 179 | $rs = sqlite_query("SELECT cat_id |
179 | 180 | FROM catalogue WHERE name = '{$name}'", $db); |
180 | 181 | |
181 | - if(sqlite_num_rows($rs) != 1) |
|
182 | - return false; |
|
182 | + if(sqlite_num_rows($rs) != 1) { |
|
183 | + return false; |
|
184 | + } |
|
183 | 185 | |
184 | 186 | $cat_id = (int)sqlite_fetch_single($rs); |
185 | 187 | |
@@ -208,8 +210,9 @@ discard block |
||
208 | 210 | SET date_modified = {$time} |
209 | 211 | WHERE cat_id = {$cat_id}", $db); |
210 | 212 | |
211 | - if(!empty($this->cache)) |
|
212 | - $this->cache->clean($variant, $this->culture); |
|
213 | + if(!empty($this->cache)) { |
|
214 | + $this->cache->clean($variant, $this->culture); |
|
215 | + } |
|
213 | 216 | |
214 | 217 | return $result; |
215 | 218 | } |
@@ -225,16 +228,21 @@ discard block |
||
225 | 228 | { |
226 | 229 | $messages = $this->untranslated; |
227 | 230 | |
228 | - if(count($messages) <= 0) return false; |
|
231 | + if(count($messages) <= 0) { |
|
232 | + return false; |
|
233 | + } |
|
229 | 234 | |
230 | 235 | $details = $this->getCatalogueDetails($catalogue); |
231 | 236 | |
232 | - if($details) |
|
233 | - list($cat_id, $variant, $count) = $details; |
|
234 | - else |
|
235 | - return false; |
|
237 | + if($details) { |
|
238 | + list($cat_id, $variant, $count) = $details; |
|
239 | + } else { |
|
240 | + return false; |
|
241 | + } |
|
236 | 242 | |
237 | - if($cat_id <= 0) return false; |
|
243 | + if($cat_id <= 0) { |
|
244 | + return false; |
|
245 | + } |
|
238 | 246 | $inserted = 0; |
239 | 247 | |
240 | 248 | $db = sqlite_open($this->source); |
@@ -251,8 +259,9 @@ discard block |
||
251 | 259 | $count++; $inserted++; |
252 | 260 | } |
253 | 261 | } |
254 | - if($inserted > 0) |
|
255 | - $this->updateCatalogueTime($cat_id, $variant, $db); |
|
262 | + if($inserted > 0) { |
|
263 | + $this->updateCatalogueTime($cat_id, $variant, $db); |
|
264 | + } |
|
256 | 265 | |
257 | 266 | sqlite_close($db); |
258 | 267 | |
@@ -270,10 +279,11 @@ discard block |
||
270 | 279 | function update($text, $target, $comments, $catalogue='messages') |
271 | 280 | { |
272 | 281 | $details = $this->getCatalogueDetails($catalogue); |
273 | - if($details) |
|
274 | - list($cat_id, $variant, $count) = $details; |
|
275 | - else |
|
276 | - return false; |
|
282 | + if($details) { |
|
283 | + list($cat_id, $variant, $count) = $details; |
|
284 | + } else { |
|
285 | + return false; |
|
286 | + } |
|
277 | 287 | |
278 | 288 | $comments = sqlite_escape_string($comments); |
279 | 289 | $target = sqlite_escape_string($target); |
@@ -292,8 +302,9 @@ discard block |
||
292 | 302 | |
293 | 303 | $updated = false; |
294 | 304 | |
295 | - if(sqlite_query($statement, $db)) |
|
296 | - $updated = $this->updateCatalogueTime($cat_id, $variant, $db); |
|
305 | + if(sqlite_query($statement, $db)) { |
|
306 | + $updated = $this->updateCatalogueTime($cat_id, $variant, $db); |
|
307 | + } |
|
297 | 308 | |
298 | 309 | sqlite_close($db); |
299 | 310 | |
@@ -309,10 +320,11 @@ discard block |
||
309 | 320 | function delete($message, $catalogue='messages') |
310 | 321 | { |
311 | 322 | $details = $this->getCatalogueDetails($catalogue); |
312 | - if($details) |
|
313 | - list($cat_id, $variant, $count) = $details; |
|
314 | - else |
|
315 | - return false; |
|
323 | + if($details) { |
|
324 | + list($cat_id, $variant, $count) = $details; |
|
325 | + } else { |
|
326 | + return false; |
|
327 | + } |
|
316 | 328 | |
317 | 329 | $db = sqlite_open($this->source); |
318 | 330 | $text = sqlite_escape_string($message); |
@@ -321,8 +333,9 @@ discard block |
||
321 | 333 | cat_id = {$cat_id} AND source = '{$message}'"; |
322 | 334 | $deleted = false; |
323 | 335 | |
324 | - if(sqlite_query($statement, $db)) |
|
325 | - $deleted = $this->updateCatalogueTime($cat_id, $variant, $db); |
|
336 | + if(sqlite_query($statement, $db)) { |
|
337 | + $deleted = $this->updateCatalogueTime($cat_id, $variant, $db); |
|
338 | + } |
|
326 | 339 | |
327 | 340 | sqlite_close($db); |
328 | 341 | |
@@ -342,7 +355,9 @@ discard block |
||
342 | 355 | while($row = sqlite_fetch_array($rs,SQLITE_NUM)) |
343 | 356 | { |
344 | 357 | $details = explode('.',$row[0]); |
345 | - if(!isset($details[1])) $details[1] = null; |
|
358 | + if(!isset($details[1])) { |
|
359 | + $details[1] = null; |
|
360 | + } |
|
346 | 361 | |
347 | 362 | $result[] = $details; |
348 | 363 | } |
@@ -486,6 +486,9 @@ |
||
486 | 486 | return false; |
487 | 487 | } |
488 | 488 | |
489 | + /** |
|
490 | + * @param string $catalogue |
|
491 | + */ |
|
489 | 492 | protected function createMessageTemplate($catalogue) |
490 | 493 | { |
491 | 494 | if($catalogue === null) { |
@@ -290,7 +290,7 @@ |
||
290 | 290 | |
291 | 291 | //find the body element |
292 | 292 | $xpath = new DomXPath($dom); |
293 | - $body = $xpath->query('//body')->item(0); |
|
293 | + $body = $xpath->query('//body')->item(0); |
|
294 | 294 | |
295 | 295 | $lastNodes = $xpath->query('//trans-unit[last()]'); |
296 | 296 | if(($last=$lastNodes->item(0))!==null) { |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | /** |
21 | 21 | * Get the MessageSource class file. |
22 | 22 | */ |
23 | -require_once(dirname(__FILE__).'/MessageSource.php'); |
|
23 | +require_once(dirname(__FILE__) . '/MessageSource.php'); |
|
24 | 24 | |
25 | 25 | /** |
26 | 26 | * MessageSource_XLIFF class. |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | */ |
59 | 59 | function __construct($source) |
60 | 60 | { |
61 | - $this->source = (string)$source; |
|
61 | + $this->source = (string) $source; |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | /** |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | protected function &loadData($filename) |
70 | 70 | { |
71 | 71 | //load it. |
72 | - if(false === ($XML = simplexml_load_file($filename))) { |
|
72 | + if (false === ($XML = simplexml_load_file($filename))) { |
|
73 | 73 | return false; |
74 | 74 | } |
75 | 75 | |
@@ -77,12 +77,12 @@ discard block |
||
77 | 77 | |
78 | 78 | $translations = array(); |
79 | 79 | |
80 | - foreach($translationUnit as $unit) |
|
80 | + foreach ($translationUnit as $unit) |
|
81 | 81 | { |
82 | - $source = (string)$unit->source; |
|
83 | - $translations[$source][] = (string)$unit->target; |
|
84 | - $translations[$source][] = (string)$unit['id']; |
|
85 | - $translations[$source][] = (string)$unit->note; |
|
82 | + $source = (string) $unit->source; |
|
83 | + $translations[$source][] = (string) $unit->target; |
|
84 | + $translations[$source][] = (string) $unit['id']; |
|
85 | + $translations[$source][] = (string) $unit->note; |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | return $translations; |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | */ |
108 | 108 | protected function getSource($variant) |
109 | 109 | { |
110 | - return $this->source.'/'.$variant; |
|
110 | + return $this->source . '/' . $variant; |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | /** |
@@ -127,25 +127,25 @@ discard block |
||
127 | 127 | */ |
128 | 128 | protected function getCatalogueList($catalogue) |
129 | 129 | { |
130 | - $variants = explode('_',$this->culture); |
|
131 | - $source = $catalogue.$this->dataExt; |
|
130 | + $variants = explode('_', $this->culture); |
|
131 | + $source = $catalogue . $this->dataExt; |
|
132 | 132 | $catalogues = array($source); |
133 | 133 | $variant = null; |
134 | 134 | |
135 | - for($i = 0, $k = count($variants); $i < $k; ++$i) |
|
135 | + for ($i = 0, $k = count($variants); $i < $k; ++$i) |
|
136 | 136 | { |
137 | - if(isset($variants[$i]{0})) |
|
137 | + if (isset($variants[$i]{0})) |
|
138 | 138 | { |
139 | - $variant .= ($variant)?'_'.$variants[$i]:$variants[$i]; |
|
140 | - $catalogues[] = $catalogue.$this->dataSeparator.$variant.$this->dataExt; |
|
139 | + $variant .= ($variant) ? '_' . $variants[$i] : $variants[$i]; |
|
140 | + $catalogues[] = $catalogue . $this->dataSeparator . $variant . $this->dataExt; |
|
141 | 141 | } |
142 | 142 | } |
143 | 143 | |
144 | 144 | $byDir = $this->getCatalogueByDir($catalogue); |
145 | - $catalogues = array_merge($byDir,array_reverse($catalogues)); |
|
145 | + $catalogues = array_merge($byDir, array_reverse($catalogues)); |
|
146 | 146 | $files = array(); |
147 | 147 | |
148 | - foreach($catalogues as $file) |
|
148 | + foreach ($catalogues as $file) |
|
149 | 149 | { |
150 | 150 | $files[] = $file; |
151 | 151 | $files[] = preg_replace('/\.xml$/', '.xlf', $file); |
@@ -163,16 +163,16 @@ discard block |
||
163 | 163 | */ |
164 | 164 | private function getCatalogueByDir($catalogue) |
165 | 165 | { |
166 | - $variants = explode('_',$this->culture); |
|
166 | + $variants = explode('_', $this->culture); |
|
167 | 167 | $catalogues = array(); |
168 | 168 | $variant = null; |
169 | 169 | |
170 | - for($i = 0, $k = count($variants); $i < $k; ++$i) |
|
170 | + for ($i = 0, $k = count($variants); $i < $k; ++$i) |
|
171 | 171 | { |
172 | - if(isset($variants[$i]{0})) |
|
172 | + if (isset($variants[$i]{0})) |
|
173 | 173 | { |
174 | - $variant .= ($variant)?'_'.$variants[$i]:$variants[$i]; |
|
175 | - $catalogues[] = $variant.'/'.$catalogue.$this->dataExt; |
|
174 | + $variant .= ($variant) ? '_' . $variants[$i] : $variants[$i]; |
|
175 | + $catalogues[] = $variant . '/' . $catalogue . $this->dataExt; |
|
176 | 176 | } |
177 | 177 | } |
178 | 178 | |
@@ -196,32 +196,32 @@ discard block |
||
196 | 196 | * E.g. array('messages','en_AU') |
197 | 197 | * @return array list of catalogues |
198 | 198 | */ |
199 | - protected function getCatalogues($dir=null,$variant=null) |
|
199 | + protected function getCatalogues($dir = null, $variant = null) |
|
200 | 200 | { |
201 | - $dir = $dir?$dir:$this->source; |
|
201 | + $dir = $dir ? $dir : $this->source; |
|
202 | 202 | $files = scandir($dir); |
203 | 203 | $catalogue = array(); |
204 | 204 | |
205 | - foreach($files as $file) |
|
205 | + foreach ($files as $file) |
|
206 | 206 | { |
207 | - if(is_dir($dir.'/'.$file) && preg_match('/^[a-z]{2}(_[A-Z]{2,3})?$/',$file)) { |
|
207 | + if (is_dir($dir . '/' . $file) && preg_match('/^[a-z]{2}(_[A-Z]{2,3})?$/', $file)) { |
|
208 | 208 | $catalogue = array_merge( |
209 | 209 | $catalogue, |
210 | - $this->getCatalogues($dir.'/'.$file, $file) |
|
210 | + $this->getCatalogues($dir . '/' . $file, $file) |
|
211 | 211 | ); |
212 | 212 | } |
213 | 213 | |
214 | - $pos = strpos($file,$this->dataExt); |
|
215 | - if($pos >0 && substr($file, -1*strlen($this->dataExt)) == $this->dataExt) |
|
214 | + $pos = strpos($file, $this->dataExt); |
|
215 | + if ($pos > 0 && substr($file, -1 * strlen($this->dataExt)) == $this->dataExt) |
|
216 | 216 | { |
217 | - $name = substr($file,0,$pos); |
|
218 | - $dot = strrpos($name,$this->dataSeparator); |
|
217 | + $name = substr($file, 0, $pos); |
|
218 | + $dot = strrpos($name, $this->dataSeparator); |
|
219 | 219 | $culture = $variant; |
220 | 220 | $cat = $name; |
221 | 221 | |
222 | - if(is_int($dot)) |
|
222 | + if (is_int($dot)) |
|
223 | 223 | { |
224 | - $culture = substr($name, $dot+1, strlen($name)); |
|
224 | + $culture = substr($name, $dot + 1, strlen($name)); |
|
225 | 225 | $cat = substr($name, 0, $dot); |
226 | 226 | } |
227 | 227 | |
@@ -242,16 +242,16 @@ discard block |
||
242 | 242 | * @see update() |
243 | 243 | * @see delete() |
244 | 244 | */ |
245 | - private function getVariants($catalogue='messages') |
|
245 | + private function getVariants($catalogue = 'messages') |
|
246 | 246 | { |
247 | - if($catalogue === null) { |
|
247 | + if ($catalogue === null) { |
|
248 | 248 | $catalogue = 'messages'; |
249 | 249 | } |
250 | 250 | |
251 | - foreach($this->getCatalogueList($catalogue) as $variant) |
|
251 | + foreach ($this->getCatalogueList($catalogue) as $variant) |
|
252 | 252 | { |
253 | 253 | $file = $this->getSource($variant); |
254 | - if(is_file($file)) { |
|
254 | + if (is_file($file)) { |
|
255 | 255 | return array($variant, $file); |
256 | 256 | } |
257 | 257 | } |
@@ -265,22 +265,22 @@ discard block |
||
265 | 265 | * @param string the catalogue to add to |
266 | 266 | * @return boolean true if saved successfuly, false otherwise. |
267 | 267 | */ |
268 | - public function save($catalogue='messages') |
|
268 | + public function save($catalogue = 'messages') |
|
269 | 269 | { |
270 | 270 | $messages = $this->untranslated; |
271 | - if(count($messages) <= 0) { |
|
271 | + if (count($messages) <= 0) { |
|
272 | 272 | return false; |
273 | 273 | } |
274 | 274 | |
275 | 275 | $variants = $this->getVariants($catalogue); |
276 | 276 | |
277 | - if($variants) { |
|
277 | + if ($variants) { |
|
278 | 278 | list($variant, $filename) = $variants; |
279 | 279 | } else { |
280 | 280 | list($variant, $filename) = $this->createMessageTemplate($catalogue); |
281 | 281 | } |
282 | 282 | |
283 | - if(is_writable($filename) == false) { |
|
283 | + if (is_writable($filename) == false) { |
|
284 | 284 | throw new TIOException("Unable to save to file {$filename}, file must be writable."); |
285 | 285 | } |
286 | 286 | |
@@ -293,17 +293,17 @@ discard block |
||
293 | 293 | $body = $xpath->query('//body')->item(0); |
294 | 294 | |
295 | 295 | $lastNodes = $xpath->query('//trans-unit[last()]'); |
296 | - if(($last=$lastNodes->item(0))!==null) { |
|
297 | - $count = (int)$last->getAttribute('id'); |
|
296 | + if (($last = $lastNodes->item(0)) !== null) { |
|
297 | + $count = (int) $last->getAttribute('id'); |
|
298 | 298 | } else { |
299 | 299 | $count = 0; |
300 | 300 | } |
301 | 301 | |
302 | 302 | //for each message add it to the XML file using DOM |
303 | - foreach($messages as $message) |
|
303 | + foreach ($messages as $message) |
|
304 | 304 | { |
305 | 305 | $unit = $dom->createElement('trans-unit'); |
306 | - $unit->setAttribute('id',++$count); |
|
306 | + $unit->setAttribute('id', ++$count); |
|
307 | 307 | |
308 | 308 | $source = $dom->createElement('source'); |
309 | 309 | $source->appendChild($dom->createCDATASection($message)); |
@@ -328,7 +328,7 @@ discard block |
||
328 | 328 | |
329 | 329 | //save it and clear the cache for this variant |
330 | 330 | $dom->save($filename); |
331 | - if(!empty($this->cache)) { |
|
331 | + if (!empty($this->cache)) { |
|
332 | 332 | $this->cache->clean($variant, $this->culture); |
333 | 333 | } |
334 | 334 | |
@@ -343,17 +343,17 @@ discard block |
||
343 | 343 | * @param string the catalogue to save to. |
344 | 344 | * @return boolean true if translation was updated, false otherwise. |
345 | 345 | */ |
346 | - public function update($text, $target, $comments, $catalogue='messages') |
|
346 | + public function update($text, $target, $comments, $catalogue = 'messages') |
|
347 | 347 | { |
348 | 348 | $variants = $this->getVariants($catalogue); |
349 | 349 | |
350 | - if($variants) { |
|
350 | + if ($variants) { |
|
351 | 351 | list($variant, $filename) = $variants; |
352 | 352 | } else { |
353 | 353 | return false; |
354 | 354 | } |
355 | 355 | |
356 | - if(is_writable($filename) == false) { |
|
356 | + if (is_writable($filename) == false) { |
|
357 | 357 | throw new TIOException("Unable to update file {$filename}, file must be writable."); |
358 | 358 | } |
359 | 359 | |
@@ -365,7 +365,7 @@ discard block |
||
365 | 365 | $units = $xpath->query('//trans-unit'); |
366 | 366 | |
367 | 367 | //for each of the existin units |
368 | - foreach($units as $unit) |
|
368 | + foreach ($units as $unit) |
|
369 | 369 | { |
370 | 370 | $found = false; |
371 | 371 | $targetted = false; |
@@ -373,25 +373,25 @@ discard block |
||
373 | 373 | |
374 | 374 | //in each unit, need to find the source, target and comment nodes |
375 | 375 | //it will assume that the source is before the target. |
376 | - foreach($unit->childNodes as $node) |
|
376 | + foreach ($unit->childNodes as $node) |
|
377 | 377 | { |
378 | 378 | //source node |
379 | - if($node->nodeName == 'source' && $node->firstChild->wholeText == $text) { |
|
379 | + if ($node->nodeName == 'source' && $node->firstChild->wholeText == $text) { |
|
380 | 380 | $found = true; |
381 | 381 | } |
382 | 382 | |
383 | 383 | //found source, get the target and notes |
384 | - if($found) |
|
384 | + if ($found) |
|
385 | 385 | { |
386 | 386 | //set the new translated string |
387 | - if($node->nodeName == 'target') |
|
387 | + if ($node->nodeName == 'target') |
|
388 | 388 | { |
389 | 389 | $node->nodeValue = $target; |
390 | 390 | $targetted = true; |
391 | 391 | } |
392 | 392 | |
393 | 393 | //set the notes |
394 | - if(!empty($comments) && $node->nodeName == 'note') |
|
394 | + if (!empty($comments) && $node->nodeName == 'note') |
|
395 | 395 | { |
396 | 396 | $node->nodeValue = $comments; |
397 | 397 | $commented = true; |
@@ -400,17 +400,17 @@ discard block |
||
400 | 400 | } |
401 | 401 | |
402 | 402 | //append a target |
403 | - if($found && !$targetted) { |
|
404 | - $unit->appendChild($dom->createElement('target',$target)); |
|
403 | + if ($found && !$targetted) { |
|
404 | + $unit->appendChild($dom->createElement('target', $target)); |
|
405 | 405 | } |
406 | 406 | |
407 | 407 | //append a note |
408 | - if($found && !$commented && !empty($comments)) { |
|
409 | - $unit->appendChild($dom->createElement('note',$comments)); |
|
408 | + if ($found && !$commented && !empty($comments)) { |
|
409 | + $unit->appendChild($dom->createElement('note', $comments)); |
|
410 | 410 | } |
411 | 411 | |
412 | 412 | //finished searching |
413 | - if($found) { |
|
413 | + if ($found) { |
|
414 | 414 | break; |
415 | 415 | } |
416 | 416 | } |
@@ -418,9 +418,9 @@ discard block |
||
418 | 418 | $fileNode = $xpath->query('//file')->item(0); |
419 | 419 | $fileNode->setAttribute('date', @date('Y-m-d\TH:i:s\Z')); |
420 | 420 | |
421 | - if($dom->save($filename) >0) |
|
421 | + if ($dom->save($filename) > 0) |
|
422 | 422 | { |
423 | - if(!empty($this->cache)) { |
|
423 | + if (!empty($this->cache)) { |
|
424 | 424 | $this->cache->clean($variant, $this->culture); |
425 | 425 | } |
426 | 426 | |
@@ -436,16 +436,16 @@ discard block |
||
436 | 436 | * @param string the catalogue to delete from. |
437 | 437 | * @return boolean true if deleted, false otherwise. |
438 | 438 | */ |
439 | - public function delete($message, $catalogue='messages') |
|
439 | + public function delete($message, $catalogue = 'messages') |
|
440 | 440 | { |
441 | 441 | $variants = $this->getVariants($catalogue); |
442 | - if($variants) { |
|
442 | + if ($variants) { |
|
443 | 443 | list($variant, $filename) = $variants; |
444 | 444 | } else { |
445 | 445 | return false; |
446 | 446 | } |
447 | 447 | |
448 | - if(is_writable($filename) == false) { |
|
448 | + if (is_writable($filename) == false) { |
|
449 | 449 | throw new TIOException("Unable to modify file {$filename}, file must be writable."); |
450 | 450 | } |
451 | 451 | |
@@ -457,22 +457,22 @@ discard block |
||
457 | 457 | $units = $xpath->query('//trans-unit'); |
458 | 458 | |
459 | 459 | //for each of the existin units |
460 | - foreach($units as $unit) |
|
460 | + foreach ($units as $unit) |
|
461 | 461 | { |
462 | 462 | //in each unit, need to find the source, target and comment nodes |
463 | 463 | //it will assume that the source is before the target. |
464 | - foreach($unit->childNodes as $node) |
|
464 | + foreach ($unit->childNodes as $node) |
|
465 | 465 | { |
466 | 466 | //source node |
467 | - if($node->nodeName == 'source' && $node->firstChild->wholeText == $message) |
|
467 | + if ($node->nodeName == 'source' && $node->firstChild->wholeText == $message) |
|
468 | 468 | { |
469 | 469 | //we found it, remove and save the xml file. |
470 | 470 | $unit->parentNode->removeChild($unit); |
471 | 471 | $fileNode = $xpath->query('//file')->item(0); |
472 | 472 | $fileNode->setAttribute('date', @date('Y-m-d\TH:i:s\Z')); |
473 | 473 | |
474 | - if(false !== $dom->save($filename)) { |
|
475 | - if(!empty($this->cache)) { |
|
474 | + if (false !== $dom->save($filename)) { |
|
475 | + if (!empty($this->cache)) { |
|
476 | 476 | $this->cache->clean($variant, $this->culture); |
477 | 477 | } |
478 | 478 | return true; |
@@ -488,7 +488,7 @@ discard block |
||
488 | 488 | |
489 | 489 | protected function createMessageTemplate($catalogue) |
490 | 490 | { |
491 | - if($catalogue === null) { |
|
491 | + if ($catalogue === null) { |
|
492 | 492 | $catalogue = 'messages'; |
493 | 493 | } |
494 | 494 | |
@@ -497,12 +497,12 @@ discard block |
||
497 | 497 | $file = $this->getSource($variant); |
498 | 498 | $dir = dirname($file); |
499 | 499 | |
500 | - if(!is_dir($dir)) { |
|
500 | + if (!is_dir($dir)) { |
|
501 | 501 | @mkdir($dir); |
502 | - @chmod($dir,PRADO_CHMOD); |
|
502 | + @chmod($dir, PRADO_CHMOD); |
|
503 | 503 | } |
504 | 504 | |
505 | - if(!is_dir($dir)) { |
|
505 | + if (!is_dir($dir)) { |
|
506 | 506 | throw new TException("Unable to create directory $dir"); |
507 | 507 | } |
508 | 508 |
@@ -86,6 +86,7 @@ discard block |
||
86 | 86 | * a CultureInfo or NumberFormatInfo instance will instantiated a instance |
87 | 87 | * for that particular culture. |
88 | 88 | * @param mixed either null, a CultureInfo, a NumberFormatInfo, or string |
89 | + * @param string $formatInfo |
|
89 | 90 | * @return NumberFormat |
90 | 91 | */ |
91 | 92 | function __construct($formatInfo=null) |
@@ -232,7 +233,7 @@ discard block |
||
232 | 233 | |
233 | 234 | /** |
234 | 235 | * Format the decimal places. |
235 | - * @param string the decimal number in string form. |
|
236 | + * @param string string decimal number in string form. |
|
236 | 237 | * @return string formatted decimal places. |
237 | 238 | */ |
238 | 239 | protected function formatDecimal($string) |
@@ -280,6 +281,7 @@ discard block |
||
280 | 281 | * Set the pattern to format against. The default patterns |
281 | 282 | * are retrieved from the NumberFormatInfo instance. |
282 | 283 | * @param string the requested patterns. |
284 | + * @param string $pattern |
|
283 | 285 | * @return string a number format pattern. |
284 | 286 | */ |
285 | 287 | protected function setPattern($pattern) |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | |
77 | 77 | /** |
78 | 78 | * The DateTimeFormatInfo, containing culture specific patterns and names. |
79 | - * @var DateTimeFormatInfo |
|
79 | + * @var DateTimeFormatInfo |
|
80 | 80 | */ |
81 | 81 | protected $formatInfo; |
82 | 82 | |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | function format($number, $pattern='d', $currency='USD', $charset='UTF-8') |
117 | 117 | { |
118 | 118 | $oldLocale=setLocale(LC_NUMERIC, '0'); |
119 | - setlocale(LC_NUMERIC, 'C'); |
|
119 | + setlocale(LC_NUMERIC, 'C'); |
|
120 | 120 | |
121 | 121 | $this->setPattern($pattern); |
122 | 122 |
@@ -20,13 +20,13 @@ discard block |
||
20 | 20 | /** |
21 | 21 | * Get the NumberFormatInfo class file. |
22 | 22 | */ |
23 | -require_once(dirname(__FILE__).'/NumberFormatInfo.php'); |
|
23 | +require_once(dirname(__FILE__) . '/NumberFormatInfo.php'); |
|
24 | 24 | |
25 | 25 | |
26 | 26 | /** |
27 | 27 | * Get the encoding utilities |
28 | 28 | */ |
29 | -require_once(dirname(__FILE__).'/util.php'); |
|
29 | +require_once(dirname(__FILE__) . '/util.php'); |
|
30 | 30 | |
31 | 31 | |
32 | 32 | /** |
@@ -88,13 +88,13 @@ discard block |
||
88 | 88 | * @param mixed either null, a CultureInfo, a NumberFormatInfo, or string |
89 | 89 | * @return NumberFormat |
90 | 90 | */ |
91 | - function __construct($formatInfo=null) |
|
91 | + function __construct($formatInfo = null) |
|
92 | 92 | { |
93 | - if($formatInfo === null) |
|
93 | + if ($formatInfo === null) |
|
94 | 94 | $this->formatInfo = NumberFormatInfo::getInvariantInfo(); |
95 | - else if($formatInfo instanceof CultureInfo) |
|
95 | + else if ($formatInfo instanceof CultureInfo) |
|
96 | 96 | $this->formatInfo = $formatInfo->NumberFormat; |
97 | - else if($formatInfo instanceof NumberFormatInfo) |
|
97 | + else if ($formatInfo instanceof NumberFormatInfo) |
|
98 | 98 | $this->formatInfo = $formatInfo; |
99 | 99 | else |
100 | 100 | $this->formatInfo = |
@@ -113,44 +113,44 @@ discard block |
||
113 | 113 | * "USD" represents the US Dollar and "EUR" represents the Euro currency. |
114 | 114 | * @return string formatted number string |
115 | 115 | */ |
116 | - function format($number, $pattern='d', $currency='USD', $charset='UTF-8') |
|
116 | + function format($number, $pattern = 'd', $currency = 'USD', $charset = 'UTF-8') |
|
117 | 117 | { |
118 | - $oldLocale=setLocale(LC_NUMERIC, '0'); |
|
118 | + $oldLocale = setLocale(LC_NUMERIC, '0'); |
|
119 | 119 | setlocale(LC_NUMERIC, 'C'); |
120 | 120 | |
121 | 121 | $this->setPattern($pattern); |
122 | 122 | |
123 | - if(strtolower($pattern) == 'p') |
|
123 | + if (strtolower($pattern) == 'p') |
|
124 | 124 | $number = $number * 100; |
125 | 125 | |
126 | - $string = (string)$number; |
|
126 | + $string = (string) $number; |
|
127 | 127 | |
128 | 128 | $decimal = $this->formatDecimal($string); |
129 | 129 | $integer = $this->formatInteger(abs($number)); |
130 | 130 | |
131 | - if(strlen($decimal)>0) |
|
132 | - $result = $integer.$decimal; |
|
131 | + if (strlen($decimal) > 0) |
|
132 | + $result = $integer . $decimal; |
|
133 | 133 | else |
134 | 134 | $result = $integer; |
135 | 135 | |
136 | 136 | //get the suffix |
137 | - if($number >= 0) |
|
137 | + if ($number >= 0) |
|
138 | 138 | $suffix = $this->formatInfo->PositivePattern; |
139 | - else if($number < 0) |
|
139 | + else if ($number < 0) |
|
140 | 140 | $suffix = $this->formatInfo->NegativePattern; |
141 | 141 | else |
142 | - $suffix = array("",""); |
|
142 | + $suffix = array("", ""); |
|
143 | 143 | |
144 | 144 | //append and prepend suffix |
145 | - $result = $suffix[0].$result.$suffix[1]; |
|
145 | + $result = $suffix[0] . $result . $suffix[1]; |
|
146 | 146 | |
147 | 147 | //replace currency sign |
148 | 148 | $symbol = @$this->formatInfo->getCurrencySymbol($currency); |
149 | - if($symbol === null) { |
|
149 | + if ($symbol === null) { |
|
150 | 150 | $symbol = $currency; |
151 | 151 | } |
152 | 152 | |
153 | - $result = str_replace('¤',$symbol, $result); |
|
153 | + $result = str_replace('¤', $symbol, $result); |
|
154 | 154 | |
155 | 155 | setlocale(LC_NUMERIC, $oldLocale); |
156 | 156 | |
@@ -164,20 +164,20 @@ discard block |
||
164 | 164 | */ |
165 | 165 | protected function formatInteger($string) |
166 | 166 | { |
167 | - $string = (string)$string; |
|
167 | + $string = (string) $string; |
|
168 | 168 | |
169 | 169 | $decimalDigits = $this->formatInfo->DecimalDigits; |
170 | 170 | //if not decimal digits, assume 0 decimal points. |
171 | - if(is_int($decimalDigits) && $decimalDigits > 0) |
|
172 | - $string = (string)round(floatval($string),$decimalDigits); |
|
171 | + if (is_int($decimalDigits) && $decimalDigits > 0) |
|
172 | + $string = (string) round(floatval($string), $decimalDigits); |
|
173 | 173 | $dp = strpos($string, '.'); |
174 | - if(is_int($dp)) |
|
174 | + if (is_int($dp)) |
|
175 | 175 | $string = substr($string, 0, $dp); |
176 | 176 | $integer = ''; |
177 | 177 | |
178 | 178 | $digitSize = $this->formatInfo->getDigitSize(); |
179 | 179 | |
180 | - $string = str_pad($string, $digitSize, '0',STR_PAD_LEFT); |
|
180 | + $string = str_pad($string, $digitSize, '0', STR_PAD_LEFT); |
|
181 | 181 | |
182 | 182 | $len = strlen($string); |
183 | 183 | |
@@ -189,24 +189,24 @@ discard block |
||
189 | 189 | $multiGroup = is_int($groupSize[1]); |
190 | 190 | $count = 0; |
191 | 191 | |
192 | - if(is_int($groupSize[0])) |
|
192 | + if (is_int($groupSize[0])) |
|
193 | 193 | { |
194 | 194 | //now for the integer groupings |
195 | - for($i=0; $i<$len; $i++) |
|
195 | + for ($i = 0; $i < $len; $i++) |
|
196 | 196 | { |
197 | - $char = $string{$len-$i-1}; |
|
197 | + $char = $string{$len - $i - 1}; |
|
198 | 198 | |
199 | - if($multiGroup && $count == 0) |
|
199 | + if ($multiGroup && $count == 0) |
|
200 | 200 | { |
201 | - if($i != 0 && $i%$groupSize[0] == 0) |
|
201 | + if ($i != 0 && $i % $groupSize[0] == 0) |
|
202 | 202 | { |
203 | 203 | $integer = $groupSeparator . $integer; |
204 | 204 | $count++; |
205 | 205 | } |
206 | 206 | } |
207 | - else if($multiGroup && $count >= 1) |
|
207 | + else if ($multiGroup && $count >= 1) |
|
208 | 208 | { |
209 | - if($i != 0 && ($i-$groupSize[0])%$groupSize[1] == 0) |
|
209 | + if ($i != 0 && ($i - $groupSize[0]) % $groupSize[1] == 0) |
|
210 | 210 | { |
211 | 211 | $integer = $groupSeparator . $integer; |
212 | 212 | $count++; |
@@ -214,7 +214,7 @@ discard block |
||
214 | 214 | } |
215 | 215 | else |
216 | 216 | { |
217 | - if($i != 0 && $i%$groupSize[0] == 0) |
|
217 | + if ($i != 0 && $i % $groupSize[0] == 0) |
|
218 | 218 | { |
219 | 219 | $integer = $groupSeparator . $integer; |
220 | 220 | $count++; |
@@ -245,33 +245,33 @@ discard block |
||
245 | 245 | |
246 | 246 | //do the correct rounding here |
247 | 247 | //$string = round(floatval($string), $decimalDigits); |
248 | - if(is_int($dp)) |
|
248 | + if (is_int($dp)) |
|
249 | 249 | { |
250 | - if($decimalDigits == -1) |
|
250 | + if ($decimalDigits == -1) |
|
251 | 251 | { |
252 | - $decimal = substr($string, $dp+1); |
|
252 | + $decimal = substr($string, $dp + 1); |
|
253 | 253 | } |
254 | - else if(is_int($decimalDigits)) |
|
254 | + else if (is_int($decimalDigits)) |
|
255 | 255 | { |
256 | - $float = round((float)$string, $decimalDigits); |
|
257 | - if(strpos((string)$float, '.') === false) |
|
256 | + $float = round((float) $string, $decimalDigits); |
|
257 | + if (strpos((string) $float, '.') === false) |
|
258 | 258 | { |
259 | - $decimal = str_pad($decimal,$decimalDigits,'0'); |
|
259 | + $decimal = str_pad($decimal, $decimalDigits, '0'); |
|
260 | 260 | } |
261 | 261 | else |
262 | 262 | { |
263 | - $decimal = substr($float, strpos($float,'.')+1); |
|
264 | - if(strlen($decimal)<$decimalDigits) |
|
265 | - $decimal = str_pad($decimal,$decimalDigits,'0'); |
|
263 | + $decimal = substr($float, strpos($float, '.') + 1); |
|
264 | + if (strlen($decimal) < $decimalDigits) |
|
265 | + $decimal = str_pad($decimal, $decimalDigits, '0'); |
|
266 | 266 | } |
267 | 267 | } |
268 | 268 | else |
269 | 269 | return $decimal; |
270 | 270 | |
271 | - return $decimalSeparator.$decimal; |
|
271 | + return $decimalSeparator . $decimal; |
|
272 | 272 | } |
273 | 273 | else if ($decimalDigits > 0) |
274 | - return $decimalSeparator.str_pad($decimal,$decimalDigits,'0'); |
|
274 | + return $decimalSeparator . str_pad($decimal, $decimalDigits, '0'); |
|
275 | 275 | |
276 | 276 | return $decimal; |
277 | 277 | } |
@@ -284,7 +284,7 @@ discard block |
||
284 | 284 | */ |
285 | 285 | protected function setPattern($pattern) |
286 | 286 | { |
287 | - switch($pattern) |
|
287 | + switch ($pattern) |
|
288 | 288 | { |
289 | 289 | case 'c': |
290 | 290 | case 'C': |
@@ -90,15 +90,16 @@ discard block |
||
90 | 90 | */ |
91 | 91 | function __construct($formatInfo=null) |
92 | 92 | { |
93 | - if($formatInfo === null) |
|
94 | - $this->formatInfo = NumberFormatInfo::getInvariantInfo(); |
|
95 | - else if($formatInfo instanceof CultureInfo) |
|
96 | - $this->formatInfo = $formatInfo->NumberFormat; |
|
97 | - else if($formatInfo instanceof NumberFormatInfo) |
|
98 | - $this->formatInfo = $formatInfo; |
|
99 | - else |
|
100 | - $this->formatInfo = |
|
93 | + if($formatInfo === null) { |
|
94 | + $this->formatInfo = NumberFormatInfo::getInvariantInfo(); |
|
95 | + } else if($formatInfo instanceof CultureInfo) { |
|
96 | + $this->formatInfo = $formatInfo->NumberFormat; |
|
97 | + } else if($formatInfo instanceof NumberFormatInfo) { |
|
98 | + $this->formatInfo = $formatInfo; |
|
99 | + } else { |
|
100 | + $this->formatInfo = |
|
101 | 101 | NumberFormatInfo::getInstance($formatInfo); |
102 | + } |
|
102 | 103 | } |
103 | 104 | |
104 | 105 | /** |
@@ -120,26 +121,29 @@ discard block |
||
120 | 121 | |
121 | 122 | $this->setPattern($pattern); |
122 | 123 | |
123 | - if(strtolower($pattern) == 'p') |
|
124 | - $number = $number * 100; |
|
124 | + if(strtolower($pattern) == 'p') { |
|
125 | + $number = $number * 100; |
|
126 | + } |
|
125 | 127 | |
126 | 128 | $string = (string)$number; |
127 | 129 | |
128 | 130 | $decimal = $this->formatDecimal($string); |
129 | 131 | $integer = $this->formatInteger(abs($number)); |
130 | 132 | |
131 | - if(strlen($decimal)>0) |
|
132 | - $result = $integer.$decimal; |
|
133 | - else |
|
134 | - $result = $integer; |
|
133 | + if(strlen($decimal)>0) { |
|
134 | + $result = $integer.$decimal; |
|
135 | + } else { |
|
136 | + $result = $integer; |
|
137 | + } |
|
135 | 138 | |
136 | 139 | //get the suffix |
137 | - if($number >= 0) |
|
138 | - $suffix = $this->formatInfo->PositivePattern; |
|
139 | - else if($number < 0) |
|
140 | - $suffix = $this->formatInfo->NegativePattern; |
|
141 | - else |
|
142 | - $suffix = array("",""); |
|
140 | + if($number >= 0) { |
|
141 | + $suffix = $this->formatInfo->PositivePattern; |
|
142 | + } else if($number < 0) { |
|
143 | + $suffix = $this->formatInfo->NegativePattern; |
|
144 | + } else { |
|
145 | + $suffix = array("",""); |
|
146 | + } |
|
143 | 147 | |
144 | 148 | //append and prepend suffix |
145 | 149 | $result = $suffix[0].$result.$suffix[1]; |
@@ -168,11 +172,13 @@ discard block |
||
168 | 172 | |
169 | 173 | $decimalDigits = $this->formatInfo->DecimalDigits; |
170 | 174 | //if not decimal digits, assume 0 decimal points. |
171 | - if(is_int($decimalDigits) && $decimalDigits > 0) |
|
172 | - $string = (string)round(floatval($string),$decimalDigits); |
|
175 | + if(is_int($decimalDigits) && $decimalDigits > 0) { |
|
176 | + $string = (string)round(floatval($string),$decimalDigits); |
|
177 | + } |
|
173 | 178 | $dp = strpos($string, '.'); |
174 | - if(is_int($dp)) |
|
175 | - $string = substr($string, 0, $dp); |
|
179 | + if(is_int($dp)) { |
|
180 | + $string = substr($string, 0, $dp); |
|
181 | + } |
|
176 | 182 | $integer = ''; |
177 | 183 | |
178 | 184 | $digitSize = $this->formatInfo->getDigitSize(); |
@@ -203,16 +209,14 @@ discard block |
||
203 | 209 | $integer = $groupSeparator . $integer; |
204 | 210 | $count++; |
205 | 211 | } |
206 | - } |
|
207 | - else if($multiGroup && $count >= 1) |
|
212 | + } else if($multiGroup && $count >= 1) |
|
208 | 213 | { |
209 | 214 | if($i != 0 && ($i-$groupSize[0])%$groupSize[1] == 0) |
210 | 215 | { |
211 | 216 | $integer = $groupSeparator . $integer; |
212 | 217 | $count++; |
213 | 218 | } |
214 | - } |
|
215 | - else |
|
219 | + } else |
|
216 | 220 | { |
217 | 221 | if($i != 0 && $i%$groupSize[0] == 0) |
218 | 222 | { |
@@ -223,9 +227,9 @@ discard block |
||
223 | 227 | |
224 | 228 | $integer = $char . $integer; |
225 | 229 | } |
230 | + } else { |
|
231 | + $integer = $string; |
|
226 | 232 | } |
227 | - else |
|
228 | - $integer = $string; |
|
229 | 233 | |
230 | 234 | return $integer; |
231 | 235 | } |
@@ -250,28 +254,27 @@ discard block |
||
250 | 254 | if($decimalDigits == -1) |
251 | 255 | { |
252 | 256 | $decimal = substr($string, $dp+1); |
253 | - } |
|
254 | - else if(is_int($decimalDigits)) |
|
257 | + } else if(is_int($decimalDigits)) |
|
255 | 258 | { |
256 | 259 | $float = round((float)$string, $decimalDigits); |
257 | 260 | if(strpos((string)$float, '.') === false) |
258 | 261 | { |
259 | 262 | $decimal = str_pad($decimal,$decimalDigits,'0'); |
260 | - } |
|
261 | - else |
|
263 | + } else |
|
262 | 264 | { |
263 | 265 | $decimal = substr($float, strpos($float,'.')+1); |
264 | - if(strlen($decimal)<$decimalDigits) |
|
265 | - $decimal = str_pad($decimal,$decimalDigits,'0'); |
|
266 | + if(strlen($decimal)<$decimalDigits) { |
|
267 | + $decimal = str_pad($decimal,$decimalDigits,'0'); |
|
268 | + } |
|
266 | 269 | } |
270 | + } else { |
|
271 | + return $decimal; |
|
267 | 272 | } |
268 | - else |
|
269 | - return $decimal; |
|
270 | 273 | |
271 | 274 | return $decimalSeparator.$decimal; |
275 | + } else if ($decimalDigits > 0) { |
|
276 | + return $decimalSeparator.str_pad($decimal,$decimalDigits,'0'); |
|
272 | 277 | } |
273 | - else if ($decimalDigits > 0) |
|
274 | - return $decimalSeparator.str_pad($decimal,$decimalDigits,'0'); |
|
275 | 278 | |
276 | 279 | return $decimal; |
277 | 280 | } |