@@ -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 | } |
@@ -170,6 +170,7 @@ |
||
170 | 170 | * @param int the number formatting type, it should be |
171 | 171 | * NumberFormatInfo::DECIMAL, NumberFormatInfo::CURRENCY, |
172 | 172 | * NumberFormatInfo::PERCENTAGE, or NumberFormatInfo::SCIENTIFIC |
173 | + * @param integer $type |
|
173 | 174 | * @return NumberFormatInfo NumberFormatInfo for the specified |
174 | 175 | * culture. |
175 | 176 | * @see getCurrencyInstance(); |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | /** |
123 | 123 | * Set the pattern for a specific number pattern. The validate patterns |
124 | 124 | * NumberFormatInfo::DECIMAL, NumberFormatInfo::CURRENCY, |
125 | - * NumberFormatInfo::PERCENTAGE, or NumberFormatInfo::SCIENTIFIC |
|
125 | + * NumberFormatInfo::PERCENTAGE, or NumberFormatInfo::SCIENTIFIC |
|
126 | 126 | * @param int pattern type. |
127 | 127 | */ |
128 | 128 | public function setPattern($type=NumberFormatInfo::DECIMAL) |
@@ -152,94 +152,94 @@ discard block |
||
152 | 152 | * (invariant). |
153 | 153 | * @return NumberFormatInfo default NumberFormatInfo. |
154 | 154 | */ |
155 | - public static function getInvariantInfo($type=NumberFormatInfo::DECIMAL) |
|
156 | - { |
|
157 | - static $invariant; |
|
155 | + public static function getInvariantInfo($type=NumberFormatInfo::DECIMAL) |
|
156 | + { |
|
157 | + static $invariant; |
|
158 | 158 | if($invariant === null) |
159 | - { |
|
160 | - $culture = CultureInfo::getInvariantCulture(); |
|
161 | - $invariant = $culture->NumberFormat; |
|
162 | - $invariant->setPattern($type); |
|
163 | - } |
|
159 | + { |
|
160 | + $culture = CultureInfo::getInvariantCulture(); |
|
161 | + $invariant = $culture->NumberFormat; |
|
162 | + $invariant->setPattern($type); |
|
163 | + } |
|
164 | 164 | return $invariant; |
165 | - } |
|
166 | - |
|
167 | - /** |
|
168 | - * Returns the NumberFormatInfo associated with the specified culture. |
|
169 | - * @param CultureInfo the culture that gets the NumberFormat property. |
|
170 | - * @param int the number formatting type, it should be |
|
171 | - * NumberFormatInfo::DECIMAL, NumberFormatInfo::CURRENCY, |
|
172 | - * NumberFormatInfo::PERCENTAGE, or NumberFormatInfo::SCIENTIFIC |
|
173 | - * @return NumberFormatInfo NumberFormatInfo for the specified |
|
174 | - * culture. |
|
175 | - * @see getCurrencyInstance(); |
|
176 | - * @see getPercentageInstance(); |
|
177 | - * @see getScientificInstance(); |
|
178 | - */ |
|
179 | - public static function getInstance($culture=null, |
|
180 | - $type=NumberFormatInfo::DECIMAL) |
|
181 | - { |
|
165 | + } |
|
166 | + |
|
167 | + /** |
|
168 | + * Returns the NumberFormatInfo associated with the specified culture. |
|
169 | + * @param CultureInfo the culture that gets the NumberFormat property. |
|
170 | + * @param int the number formatting type, it should be |
|
171 | + * NumberFormatInfo::DECIMAL, NumberFormatInfo::CURRENCY, |
|
172 | + * NumberFormatInfo::PERCENTAGE, or NumberFormatInfo::SCIENTIFIC |
|
173 | + * @return NumberFormatInfo NumberFormatInfo for the specified |
|
174 | + * culture. |
|
175 | + * @see getCurrencyInstance(); |
|
176 | + * @see getPercentageInstance(); |
|
177 | + * @see getScientificInstance(); |
|
178 | + */ |
|
179 | + public static function getInstance($culture=null, |
|
180 | + $type=NumberFormatInfo::DECIMAL) |
|
181 | + { |
|
182 | 182 | if ($culture instanceof CultureInfo) |
183 | 183 | { |
184 | - $formatInfo = $culture->NumberFormat; |
|
185 | - $formatInfo->setPattern($type); |
|
186 | - return $formatInfo; |
|
184 | + $formatInfo = $culture->NumberFormat; |
|
185 | + $formatInfo->setPattern($type); |
|
186 | + return $formatInfo; |
|
187 | 187 | } |
188 | - else if(is_string($culture)) |
|
189 | - { |
|
190 | - $cultureInfo = new CultureInfo($culture); |
|
191 | - $formatInfo = $cultureInfo->NumberFormat; |
|
192 | - $formatInfo->setPattern($type); |
|
193 | - return $formatInfo; |
|
194 | - } |
|
195 | - else |
|
196 | - { |
|
197 | - $cultureInfo = new CultureInfo(); |
|
198 | - $formatInfo = $cultureInfo->NumberFormat; |
|
199 | - $formatInfo->setPattern($type); |
|
200 | - return $formatInfo; |
|
201 | - } |
|
202 | - } |
|
203 | - |
|
204 | - /** |
|
205 | - * Returns the currency format info associated with the specified culture. |
|
206 | - * @param CultureInfo the culture that gets the NumberFormat property. |
|
207 | - * @return NumberFormatInfo NumberFormatInfo for the specified |
|
208 | - * culture. |
|
209 | - */ |
|
210 | - public static function getCurrencyInstance($culture=null) |
|
211 | - { |
|
212 | - return self::getInstance($culture, self::CURRENCY); |
|
213 | - } |
|
214 | - |
|
215 | - /** |
|
216 | - * Returns the percentage format info associated with the specified culture. |
|
217 | - * @param CultureInfo the culture that gets the NumberFormat property. |
|
218 | - * @return NumberFormatInfo NumberFormatInfo for the specified |
|
219 | - * culture. |
|
220 | - */ |
|
221 | - public static function getPercentageInstance($culture=null) |
|
222 | - { |
|
223 | - return self::getInstance($culture, self::PERCENTAGE); |
|
224 | - } |
|
225 | - |
|
226 | - /** |
|
227 | - * Returns the scientific format info associated with the specified culture. |
|
228 | - * @param CultureInfo the culture that gets the NumberFormat property. |
|
229 | - * @return NumberFormatInfo NumberFormatInfo for the specified |
|
230 | - * culture. |
|
231 | - */ |
|
232 | - public static function getScientificInstance($culture=null) |
|
233 | - { |
|
234 | - return self::getInstance($culture, self::SCIENTIFIC); |
|
235 | - } |
|
236 | - |
|
237 | - /** |
|
238 | - * Parse the given pattern and return a list of known properties. |
|
239 | - * @param string a number pattern. |
|
240 | - * @return array list of pattern properties. |
|
241 | - */ |
|
242 | - protected function parsePattern($pattern) |
|
188 | + else if(is_string($culture)) |
|
189 | + { |
|
190 | + $cultureInfo = new CultureInfo($culture); |
|
191 | + $formatInfo = $cultureInfo->NumberFormat; |
|
192 | + $formatInfo->setPattern($type); |
|
193 | + return $formatInfo; |
|
194 | + } |
|
195 | + else |
|
196 | + { |
|
197 | + $cultureInfo = new CultureInfo(); |
|
198 | + $formatInfo = $cultureInfo->NumberFormat; |
|
199 | + $formatInfo->setPattern($type); |
|
200 | + return $formatInfo; |
|
201 | + } |
|
202 | + } |
|
203 | + |
|
204 | + /** |
|
205 | + * Returns the currency format info associated with the specified culture. |
|
206 | + * @param CultureInfo the culture that gets the NumberFormat property. |
|
207 | + * @return NumberFormatInfo NumberFormatInfo for the specified |
|
208 | + * culture. |
|
209 | + */ |
|
210 | + public static function getCurrencyInstance($culture=null) |
|
211 | + { |
|
212 | + return self::getInstance($culture, self::CURRENCY); |
|
213 | + } |
|
214 | + |
|
215 | + /** |
|
216 | + * Returns the percentage format info associated with the specified culture. |
|
217 | + * @param CultureInfo the culture that gets the NumberFormat property. |
|
218 | + * @return NumberFormatInfo NumberFormatInfo for the specified |
|
219 | + * culture. |
|
220 | + */ |
|
221 | + public static function getPercentageInstance($culture=null) |
|
222 | + { |
|
223 | + return self::getInstance($culture, self::PERCENTAGE); |
|
224 | + } |
|
225 | + |
|
226 | + /** |
|
227 | + * Returns the scientific format info associated with the specified culture. |
|
228 | + * @param CultureInfo the culture that gets the NumberFormat property. |
|
229 | + * @return NumberFormatInfo NumberFormatInfo for the specified |
|
230 | + * culture. |
|
231 | + */ |
|
232 | + public static function getScientificInstance($culture=null) |
|
233 | + { |
|
234 | + return self::getInstance($culture, self::SCIENTIFIC); |
|
235 | + } |
|
236 | + |
|
237 | + /** |
|
238 | + * Parse the given pattern and return a list of known properties. |
|
239 | + * @param string a number pattern. |
|
240 | + * @return array list of pattern properties. |
|
241 | + */ |
|
242 | + protected function parsePattern($pattern) |
|
243 | 243 | { |
244 | 244 | $pattern = explode(';',$pattern); |
245 | 245 | |
@@ -355,296 +355,296 @@ discard block |
||
355 | 355 | } |
356 | 356 | |
357 | 357 | |
358 | - /** |
|
359 | - * Indicates the number of decimal places. |
|
360 | - * @return int number of decimal places. |
|
361 | - */ |
|
362 | - function getDecimalDigits() |
|
363 | - { |
|
364 | - return $this->pattern['decimalPoints']; |
|
365 | - } |
|
366 | - |
|
367 | - /** |
|
368 | - * Set the number of decimal places. |
|
369 | - * @param int number of decimal places. |
|
370 | - */ |
|
371 | - function setDecimalDigits($value) |
|
372 | - { |
|
373 | - return $this->pattern['decimalPoints'] = $value; |
|
374 | - } |
|
375 | - |
|
376 | - function getDigitSize() |
|
377 | - { |
|
378 | - return $this->pattern['digitSize']; |
|
379 | - } |
|
380 | - |
|
381 | - function setDigitSize($value) |
|
382 | - { |
|
383 | - $this->pattern['digitSize'] = $value; |
|
384 | - } |
|
385 | - |
|
386 | - /** |
|
387 | - * Gets the string to use as the decimal separator. |
|
388 | - * @return string decimal separator. |
|
389 | - */ |
|
390 | - function getDecimalSeparator() |
|
391 | - { |
|
392 | - return $this->data['NumberElements'][0]; |
|
393 | - } |
|
394 | - |
|
395 | - /** |
|
396 | - * Set the string to use as the decimal separator. |
|
397 | - * @param string the decimal point |
|
398 | - */ |
|
399 | - function setDecimalSeparator($value) |
|
400 | - { |
|
401 | - return $this->data['NumberElements'][0] = $value; |
|
402 | - } |
|
403 | - |
|
404 | - /** |
|
405 | - * Gets the string that separates groups of digits to the left |
|
406 | - * of the decimal in currency values. |
|
407 | - * @param parameter |
|
408 | - * @return string currency group separator. |
|
409 | - */ |
|
410 | - function getGroupSeparator() |
|
411 | - { |
|
412 | - return $this->data['NumberElements'][1]; |
|
413 | - } |
|
414 | - |
|
415 | - /** |
|
416 | - * Set the string to use as the group separator. |
|
417 | - * @param string the group separator. |
|
418 | - */ |
|
419 | - function setGroupSeparator($value) |
|
420 | - { |
|
421 | - return $this->data['NumberElements'][1] = $value; |
|
422 | - } |
|
423 | - |
|
424 | - /** |
|
425 | - * Gets the number of digits in each group to the left of the decimal |
|
426 | - * There can be two grouping sizes, this fucntion |
|
427 | - * returns <b>array(group1, group2)</b>, if there is only 1 grouping size, |
|
428 | - * group2 will be false. |
|
429 | - * @return array grouping size(s). |
|
430 | - */ |
|
431 | - function getGroupSizes() |
|
432 | - { |
|
433 | - $group1 = $this->pattern['groupSize1']; |
|
434 | - $group2 = $this->pattern['groupSize2']; |
|
435 | - |
|
436 | - return array($group1, $group2); |
|
437 | - } |
|
438 | - |
|
439 | - /** |
|
440 | - * Set the number of digits in each group to the left of the decimal. |
|
441 | - * There can be two grouping sizes, the value should |
|
442 | - * be an <b>array(group1, group2)</b>, if there is only 1 grouping size, |
|
443 | - * group2 should be false. |
|
444 | - * @param array grouping size(s). |
|
445 | - */ |
|
446 | - function setGroupSizes($groupSize) |
|
447 | - { |
|
358 | + /** |
|
359 | + * Indicates the number of decimal places. |
|
360 | + * @return int number of decimal places. |
|
361 | + */ |
|
362 | + function getDecimalDigits() |
|
363 | + { |
|
364 | + return $this->pattern['decimalPoints']; |
|
365 | + } |
|
366 | + |
|
367 | + /** |
|
368 | + * Set the number of decimal places. |
|
369 | + * @param int number of decimal places. |
|
370 | + */ |
|
371 | + function setDecimalDigits($value) |
|
372 | + { |
|
373 | + return $this->pattern['decimalPoints'] = $value; |
|
374 | + } |
|
375 | + |
|
376 | + function getDigitSize() |
|
377 | + { |
|
378 | + return $this->pattern['digitSize']; |
|
379 | + } |
|
380 | + |
|
381 | + function setDigitSize($value) |
|
382 | + { |
|
383 | + $this->pattern['digitSize'] = $value; |
|
384 | + } |
|
385 | + |
|
386 | + /** |
|
387 | + * Gets the string to use as the decimal separator. |
|
388 | + * @return string decimal separator. |
|
389 | + */ |
|
390 | + function getDecimalSeparator() |
|
391 | + { |
|
392 | + return $this->data['NumberElements'][0]; |
|
393 | + } |
|
394 | + |
|
395 | + /** |
|
396 | + * Set the string to use as the decimal separator. |
|
397 | + * @param string the decimal point |
|
398 | + */ |
|
399 | + function setDecimalSeparator($value) |
|
400 | + { |
|
401 | + return $this->data['NumberElements'][0] = $value; |
|
402 | + } |
|
403 | + |
|
404 | + /** |
|
405 | + * Gets the string that separates groups of digits to the left |
|
406 | + * of the decimal in currency values. |
|
407 | + * @param parameter |
|
408 | + * @return string currency group separator. |
|
409 | + */ |
|
410 | + function getGroupSeparator() |
|
411 | + { |
|
412 | + return $this->data['NumberElements'][1]; |
|
413 | + } |
|
414 | + |
|
415 | + /** |
|
416 | + * Set the string to use as the group separator. |
|
417 | + * @param string the group separator. |
|
418 | + */ |
|
419 | + function setGroupSeparator($value) |
|
420 | + { |
|
421 | + return $this->data['NumberElements'][1] = $value; |
|
422 | + } |
|
423 | + |
|
424 | + /** |
|
425 | + * Gets the number of digits in each group to the left of the decimal |
|
426 | + * There can be two grouping sizes, this fucntion |
|
427 | + * returns <b>array(group1, group2)</b>, if there is only 1 grouping size, |
|
428 | + * group2 will be false. |
|
429 | + * @return array grouping size(s). |
|
430 | + */ |
|
431 | + function getGroupSizes() |
|
432 | + { |
|
433 | + $group1 = $this->pattern['groupSize1']; |
|
434 | + $group2 = $this->pattern['groupSize2']; |
|
435 | + |
|
436 | + return array($group1, $group2); |
|
437 | + } |
|
438 | + |
|
439 | + /** |
|
440 | + * Set the number of digits in each group to the left of the decimal. |
|
441 | + * There can be two grouping sizes, the value should |
|
442 | + * be an <b>array(group1, group2)</b>, if there is only 1 grouping size, |
|
443 | + * group2 should be false. |
|
444 | + * @param array grouping size(s). |
|
445 | + */ |
|
446 | + function setGroupSizes($groupSize) |
|
447 | + { |
|
448 | 448 | $this->pattern['groupSize1'] = $groupSize[0]; |
449 | 449 | $this->pattern['groupSize2'] = $groupSize[1]; |
450 | - } |
|
451 | - |
|
452 | - /** |
|
453 | - * Gets the format pattern for negative values. |
|
454 | - * The negative pattern is composed of a prefix, and postfix. |
|
455 | - * This function returns <b>array(prefix, postfix)</b>. |
|
456 | - * @return arary negative pattern. |
|
457 | - */ |
|
458 | - function getNegativePattern() |
|
459 | - { |
|
460 | - $prefix = $this->pattern['negPref']; |
|
461 | - $postfix = $this->pattern['negPost']; |
|
462 | - return array($prefix, $postfix); |
|
463 | - } |
|
464 | - |
|
465 | - /** |
|
466 | - * Set the format pattern for negative values. |
|
467 | - * The negative pattern is composed of a prefix, and postfix in the form |
|
468 | - * <b>array(prefix, postfix)</b>. |
|
469 | - * @param arary negative pattern. |
|
470 | - */ |
|
471 | - function setNegativePattern($pattern) |
|
472 | - { |
|
473 | - $this->pattern['negPref'] = $pattern[0]; |
|
474 | - $this->pattern['negPost'] = $pattern[1]; |
|
475 | - } |
|
476 | - |
|
477 | - /** |
|
478 | - * Gets the format pattern for positive values. |
|
479 | - * The positive pattern is composed of a prefix, and postfix. |
|
480 | - * This function returns <b>array(prefix, postfix)</b>. |
|
481 | - * @return arary positive pattern. |
|
482 | - */ |
|
483 | - function getPositivePattern() |
|
484 | - { |
|
485 | - $prefix = $this->pattern['posPref']; |
|
486 | - $postfix = $this->pattern['posPost']; |
|
487 | - return array($prefix, $postfix); |
|
488 | - } |
|
489 | - |
|
490 | - /** |
|
491 | - * Set the format pattern for positive values. |
|
492 | - * The positive pattern is composed of a prefix, and postfix in the form |
|
493 | - * <b>array(prefix, postfix)</b>. |
|
494 | - * @param arary positive pattern. |
|
495 | - */ |
|
496 | - function setPositivePattern($pattern) |
|
497 | - { |
|
498 | - $this->pattern['posPref'] = $pattern[0]; |
|
499 | - $this->pattern['posPost'] = $pattern[1]; |
|
500 | - } |
|
501 | - |
|
502 | - /** |
|
503 | - * Gets the string to use as the currency symbol. |
|
504 | - * @return string currency symbol. |
|
505 | - */ |
|
506 | - function getCurrencySymbol($currency='USD') |
|
507 | - { |
|
508 | - if(isset($this->pattern['symbol'])) |
|
450 | + } |
|
451 | + |
|
452 | + /** |
|
453 | + * Gets the format pattern for negative values. |
|
454 | + * The negative pattern is composed of a prefix, and postfix. |
|
455 | + * This function returns <b>array(prefix, postfix)</b>. |
|
456 | + * @return arary negative pattern. |
|
457 | + */ |
|
458 | + function getNegativePattern() |
|
459 | + { |
|
460 | + $prefix = $this->pattern['negPref']; |
|
461 | + $postfix = $this->pattern['negPost']; |
|
462 | + return array($prefix, $postfix); |
|
463 | + } |
|
464 | + |
|
465 | + /** |
|
466 | + * Set the format pattern for negative values. |
|
467 | + * The negative pattern is composed of a prefix, and postfix in the form |
|
468 | + * <b>array(prefix, postfix)</b>. |
|
469 | + * @param arary negative pattern. |
|
470 | + */ |
|
471 | + function setNegativePattern($pattern) |
|
472 | + { |
|
473 | + $this->pattern['negPref'] = $pattern[0]; |
|
474 | + $this->pattern['negPost'] = $pattern[1]; |
|
475 | + } |
|
476 | + |
|
477 | + /** |
|
478 | + * Gets the format pattern for positive values. |
|
479 | + * The positive pattern is composed of a prefix, and postfix. |
|
480 | + * This function returns <b>array(prefix, postfix)</b>. |
|
481 | + * @return arary positive pattern. |
|
482 | + */ |
|
483 | + function getPositivePattern() |
|
484 | + { |
|
485 | + $prefix = $this->pattern['posPref']; |
|
486 | + $postfix = $this->pattern['posPost']; |
|
487 | + return array($prefix, $postfix); |
|
488 | + } |
|
489 | + |
|
490 | + /** |
|
491 | + * Set the format pattern for positive values. |
|
492 | + * The positive pattern is composed of a prefix, and postfix in the form |
|
493 | + * <b>array(prefix, postfix)</b>. |
|
494 | + * @param arary positive pattern. |
|
495 | + */ |
|
496 | + function setPositivePattern($pattern) |
|
497 | + { |
|
498 | + $this->pattern['posPref'] = $pattern[0]; |
|
499 | + $this->pattern['posPost'] = $pattern[1]; |
|
500 | + } |
|
501 | + |
|
502 | + /** |
|
503 | + * Gets the string to use as the currency symbol. |
|
504 | + * @return string currency symbol. |
|
505 | + */ |
|
506 | + function getCurrencySymbol($currency='USD') |
|
507 | + { |
|
508 | + if(isset($this->pattern['symbol'])) |
|
509 | 509 | return $this->pattern['symbol']; |
510 | - else |
|
511 | - return $this->data['Currencies'][$currency][0]; |
|
512 | - } |
|
513 | - |
|
514 | - |
|
515 | - /** |
|
516 | - * Set the string to use as the currency symbol. |
|
517 | - * @param string currency symbol. |
|
518 | - */ |
|
519 | - function setCurrencySymbol($symbol) |
|
520 | - { |
|
521 | - $this->pattern['symbol'] = $symbol; |
|
522 | - } |
|
523 | - |
|
524 | - /** |
|
525 | - * Gets the string that represents negative infinity. |
|
526 | - * @return string negative infinity. |
|
527 | - */ |
|
528 | - function getNegativeInfinitySymbol() |
|
529 | - { |
|
510 | + else |
|
511 | + return $this->data['Currencies'][$currency][0]; |
|
512 | + } |
|
513 | + |
|
514 | + |
|
515 | + /** |
|
516 | + * Set the string to use as the currency symbol. |
|
517 | + * @param string currency symbol. |
|
518 | + */ |
|
519 | + function setCurrencySymbol($symbol) |
|
520 | + { |
|
521 | + $this->pattern['symbol'] = $symbol; |
|
522 | + } |
|
523 | + |
|
524 | + /** |
|
525 | + * Gets the string that represents negative infinity. |
|
526 | + * @return string negative infinity. |
|
527 | + */ |
|
528 | + function getNegativeInfinitySymbol() |
|
529 | + { |
|
530 | 530 | return $this->pattern['negInfty']; |
531 | - } |
|
532 | - |
|
533 | - /** |
|
534 | - * Set the string that represents negative infinity. |
|
535 | - * @param string negative infinity. |
|
536 | - */ |
|
537 | - function setNegativeInfinitySymbol($value) |
|
538 | - { |
|
531 | + } |
|
532 | + |
|
533 | + /** |
|
534 | + * Set the string that represents negative infinity. |
|
535 | + * @param string negative infinity. |
|
536 | + */ |
|
537 | + function setNegativeInfinitySymbol($value) |
|
538 | + { |
|
539 | 539 | $this->pattern['negInfty'] = $value; |
540 | - } |
|
541 | - |
|
542 | - /** |
|
543 | - * Gets the string that represents positive infinity. |
|
544 | - * @return string positive infinity. |
|
545 | - */ |
|
546 | - function getPositiveInfinitySymbol() |
|
547 | - { |
|
540 | + } |
|
541 | + |
|
542 | + /** |
|
543 | + * Gets the string that represents positive infinity. |
|
544 | + * @return string positive infinity. |
|
545 | + */ |
|
546 | + function getPositiveInfinitySymbol() |
|
547 | + { |
|
548 | 548 | return $this->pattern['posInfty']; |
549 | - } |
|
550 | - |
|
551 | - /** |
|
552 | - * Set the string that represents positive infinity. |
|
553 | - * @param string positive infinity. |
|
554 | - */ |
|
555 | - function setPositiveInfinitySymbol($value) |
|
556 | - { |
|
549 | + } |
|
550 | + |
|
551 | + /** |
|
552 | + * Set the string that represents positive infinity. |
|
553 | + * @param string positive infinity. |
|
554 | + */ |
|
555 | + function setPositiveInfinitySymbol($value) |
|
556 | + { |
|
557 | 557 | $this->pattern['posInfty'] = $value; |
558 | - } |
|
559 | - |
|
560 | - /** |
|
561 | - * Gets the string that denotes that the associated number is negative. |
|
562 | - * @return string negative sign. |
|
563 | - */ |
|
564 | - function getNegativeSign() |
|
565 | - { |
|
566 | - return $this->data['NumberElements'][6]; |
|
567 | - } |
|
568 | - |
|
569 | - /** |
|
570 | - * Set the string that denotes that the associated number is negative. |
|
571 | - * @param string negative sign. |
|
572 | - */ |
|
573 | - function setNegativeSign($value) |
|
574 | - { |
|
575 | - $this->data['NumberElements'][6] = $value; |
|
576 | - } |
|
577 | - |
|
578 | - /** |
|
579 | - * Gets the string that denotes that the associated number is positive. |
|
580 | - * @return string positive sign. |
|
581 | - */ |
|
582 | - function getPositiveSign() |
|
583 | - { |
|
584 | - return $this->data['NumberElements'][11]; |
|
585 | - } |
|
586 | - |
|
587 | - /** |
|
588 | - * Set the string that denotes that the associated number is positive. |
|
589 | - * @param string positive sign. |
|
590 | - */ |
|
591 | - function setPositiveSign($value) |
|
592 | - { |
|
593 | - $this->data['NumberElements'][11] = $value; |
|
594 | - } |
|
595 | - |
|
596 | - /** |
|
597 | - * Gets the string that represents the IEEE NaN (not a number) value. |
|
598 | - * @return string NaN symbol. |
|
599 | - */ |
|
600 | - function getNaNSymbol() |
|
601 | - { |
|
602 | - return $this->data['NumberElements'][10]; |
|
603 | - } |
|
604 | - |
|
605 | - /** |
|
606 | - * Set the string that represents the IEEE NaN (not a number) value. |
|
607 | - * @param string NaN symbol. |
|
608 | - */ |
|
609 | - function setNaNSymbol($value) |
|
610 | - { |
|
611 | - $this->data['NumberElements'][10] = $value; |
|
612 | - } |
|
613 | - |
|
614 | - /** |
|
615 | - * Gets the string to use as the percent symbol. |
|
616 | - * @return string percent symbol. |
|
617 | - */ |
|
618 | - function getPercentSymbol() |
|
619 | - { |
|
620 | - return $this->data['NumberElements'][3]; |
|
621 | - } |
|
622 | - |
|
623 | - /** |
|
624 | - * Set the string to use as the percent symbol. |
|
625 | - * @param string percent symbol. |
|
626 | - */ |
|
627 | - function setPercentSymbol($value) |
|
628 | - { |
|
629 | - $this->data['NumberElements'][3] = $value; |
|
630 | - } |
|
631 | - |
|
632 | - /** |
|
633 | - * Gets the string to use as the per mille symbol. |
|
634 | - * @return string percent symbol. |
|
635 | - */ |
|
636 | - function getPerMilleSymbol() |
|
637 | - { |
|
638 | - return $this->data['NumberElements'][8]; |
|
639 | - } |
|
640 | - |
|
641 | - /** |
|
642 | - * Set the string to use as the per mille symbol. |
|
643 | - * @param string percent symbol. |
|
644 | - */ |
|
645 | - function setPerMilleSymbol($value) |
|
646 | - { |
|
647 | - $this->data['NumberElements'][8] = $value; |
|
648 | - } |
|
558 | + } |
|
559 | + |
|
560 | + /** |
|
561 | + * Gets the string that denotes that the associated number is negative. |
|
562 | + * @return string negative sign. |
|
563 | + */ |
|
564 | + function getNegativeSign() |
|
565 | + { |
|
566 | + return $this->data['NumberElements'][6]; |
|
567 | + } |
|
568 | + |
|
569 | + /** |
|
570 | + * Set the string that denotes that the associated number is negative. |
|
571 | + * @param string negative sign. |
|
572 | + */ |
|
573 | + function setNegativeSign($value) |
|
574 | + { |
|
575 | + $this->data['NumberElements'][6] = $value; |
|
576 | + } |
|
577 | + |
|
578 | + /** |
|
579 | + * Gets the string that denotes that the associated number is positive. |
|
580 | + * @return string positive sign. |
|
581 | + */ |
|
582 | + function getPositiveSign() |
|
583 | + { |
|
584 | + return $this->data['NumberElements'][11]; |
|
585 | + } |
|
586 | + |
|
587 | + /** |
|
588 | + * Set the string that denotes that the associated number is positive. |
|
589 | + * @param string positive sign. |
|
590 | + */ |
|
591 | + function setPositiveSign($value) |
|
592 | + { |
|
593 | + $this->data['NumberElements'][11] = $value; |
|
594 | + } |
|
595 | + |
|
596 | + /** |
|
597 | + * Gets the string that represents the IEEE NaN (not a number) value. |
|
598 | + * @return string NaN symbol. |
|
599 | + */ |
|
600 | + function getNaNSymbol() |
|
601 | + { |
|
602 | + return $this->data['NumberElements'][10]; |
|
603 | + } |
|
604 | + |
|
605 | + /** |
|
606 | + * Set the string that represents the IEEE NaN (not a number) value. |
|
607 | + * @param string NaN symbol. |
|
608 | + */ |
|
609 | + function setNaNSymbol($value) |
|
610 | + { |
|
611 | + $this->data['NumberElements'][10] = $value; |
|
612 | + } |
|
613 | + |
|
614 | + /** |
|
615 | + * Gets the string to use as the percent symbol. |
|
616 | + * @return string percent symbol. |
|
617 | + */ |
|
618 | + function getPercentSymbol() |
|
619 | + { |
|
620 | + return $this->data['NumberElements'][3]; |
|
621 | + } |
|
622 | + |
|
623 | + /** |
|
624 | + * Set the string to use as the percent symbol. |
|
625 | + * @param string percent symbol. |
|
626 | + */ |
|
627 | + function setPercentSymbol($value) |
|
628 | + { |
|
629 | + $this->data['NumberElements'][3] = $value; |
|
630 | + } |
|
631 | + |
|
632 | + /** |
|
633 | + * Gets the string to use as the per mille symbol. |
|
634 | + * @return string percent symbol. |
|
635 | + */ |
|
636 | + function getPerMilleSymbol() |
|
637 | + { |
|
638 | + return $this->data['NumberElements'][8]; |
|
639 | + } |
|
640 | + |
|
641 | + /** |
|
642 | + * Set the string to use as the per mille symbol. |
|
643 | + * @param string percent symbol. |
|
644 | + */ |
|
645 | + function setPerMilleSymbol($value) |
|
646 | + { |
|
647 | + $this->data['NumberElements'][8] = $value; |
|
648 | + } |
|
649 | 649 | } |
650 | 650 |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | /** |
21 | 21 | * Get the CultureInfo class file. |
22 | 22 | */ |
23 | -require_once(dirname(__FILE__).'/CultureInfo.php'); |
|
23 | +require_once(dirname(__FILE__) . '/CultureInfo.php'); |
|
24 | 24 | |
25 | 25 | /** |
26 | 26 | * NumberFormatInfo class |
@@ -78,11 +78,11 @@ discard block |
||
78 | 78 | */ |
79 | 79 | public function __get($name) |
80 | 80 | { |
81 | - $getProperty = 'get'.$name; |
|
82 | - if(in_array($getProperty, $this->properties)) |
|
81 | + $getProperty = 'get' . $name; |
|
82 | + if (in_array($getProperty, $this->properties)) |
|
83 | 83 | return $this->$getProperty(); |
84 | 84 | else |
85 | - throw new Exception('Property '.$name.' does not exists.'); |
|
85 | + throw new Exception('Property ' . $name . ' does not exists.'); |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | /** |
@@ -91,11 +91,11 @@ discard block |
||
91 | 91 | */ |
92 | 92 | public function __set($name, $value) |
93 | 93 | { |
94 | - $setProperty = 'set'.$name; |
|
95 | - if(in_array($setProperty, $this->properties)) |
|
94 | + $setProperty = 'set' . $name; |
|
95 | + if (in_array($setProperty, $this->properties)) |
|
96 | 96 | $this->$setProperty($value); |
97 | 97 | else |
98 | - throw new Exception('Property '.$name.' can not be set.'); |
|
98 | + throw new Exception('Property ' . $name . ' can not be set.'); |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | /** |
@@ -107,11 +107,11 @@ discard block |
||
107 | 107 | * @param array ICU data for date time formatting. |
108 | 108 | * @see getInstance() |
109 | 109 | */ |
110 | - public function __construct($data=array(), $type=NumberFormatInfo::DECIMAL) |
|
110 | + public function __construct($data = array(), $type = NumberFormatInfo::DECIMAL) |
|
111 | 111 | { |
112 | 112 | $this->properties = get_class_methods($this); |
113 | 113 | |
114 | - if(empty($data)) |
|
114 | + if (empty($data)) |
|
115 | 115 | throw new Exception('Please provide the ICU data to initialize.'); |
116 | 116 | |
117 | 117 | $this->data = $data; |
@@ -125,20 +125,20 @@ discard block |
||
125 | 125 | * NumberFormatInfo::PERCENTAGE, or NumberFormatInfo::SCIENTIFIC |
126 | 126 | * @param int pattern type. |
127 | 127 | */ |
128 | - public function setPattern($type=NumberFormatInfo::DECIMAL) |
|
128 | + public function setPattern($type = NumberFormatInfo::DECIMAL) |
|
129 | 129 | { |
130 | - if(is_int($type)) |
|
130 | + if (is_int($type)) |
|
131 | 131 | $this->pattern = |
132 | 132 | $this->parsePattern($this->data['NumberPatterns'][$type]); |
133 | 133 | else |
134 | 134 | $this->pattern = $this->parsePattern($type); |
135 | 135 | |
136 | 136 | $this->pattern['negInfty'] = |
137 | - $this->data['NumberElements'][6]. |
|
137 | + $this->data['NumberElements'][6] . |
|
138 | 138 | $this->data['NumberElements'][9]; |
139 | 139 | |
140 | 140 | $this->pattern['posInfty'] = |
141 | - $this->data['NumberElements'][11]. |
|
141 | + $this->data['NumberElements'][11] . |
|
142 | 142 | $this->data['NumberElements'][9]; |
143 | 143 | } |
144 | 144 | |
@@ -152,10 +152,10 @@ discard block |
||
152 | 152 | * (invariant). |
153 | 153 | * @return NumberFormatInfo default NumberFormatInfo. |
154 | 154 | */ |
155 | - public static function getInvariantInfo($type=NumberFormatInfo::DECIMAL) |
|
155 | + public static function getInvariantInfo($type = NumberFormatInfo::DECIMAL) |
|
156 | 156 | { |
157 | 157 | static $invariant; |
158 | - if($invariant === null) |
|
158 | + if ($invariant === null) |
|
159 | 159 | { |
160 | 160 | $culture = CultureInfo::getInvariantCulture(); |
161 | 161 | $invariant = $culture->NumberFormat; |
@@ -176,8 +176,8 @@ discard block |
||
176 | 176 | * @see getPercentageInstance(); |
177 | 177 | * @see getScientificInstance(); |
178 | 178 | */ |
179 | - public static function getInstance($culture=null, |
|
180 | - $type=NumberFormatInfo::DECIMAL) |
|
179 | + public static function getInstance($culture = null, |
|
180 | + $type = NumberFormatInfo::DECIMAL) |
|
181 | 181 | { |
182 | 182 | if ($culture instanceof CultureInfo) |
183 | 183 | { |
@@ -185,7 +185,7 @@ discard block |
||
185 | 185 | $formatInfo->setPattern($type); |
186 | 186 | return $formatInfo; |
187 | 187 | } |
188 | - else if(is_string($culture)) |
|
188 | + else if (is_string($culture)) |
|
189 | 189 | { |
190 | 190 | $cultureInfo = new CultureInfo($culture); |
191 | 191 | $formatInfo = $cultureInfo->NumberFormat; |
@@ -207,7 +207,7 @@ discard block |
||
207 | 207 | * @return NumberFormatInfo NumberFormatInfo for the specified |
208 | 208 | * culture. |
209 | 209 | */ |
210 | - public static function getCurrencyInstance($culture=null) |
|
210 | + public static function getCurrencyInstance($culture = null) |
|
211 | 211 | { |
212 | 212 | return self::getInstance($culture, self::CURRENCY); |
213 | 213 | } |
@@ -218,7 +218,7 @@ discard block |
||
218 | 218 | * @return NumberFormatInfo NumberFormatInfo for the specified |
219 | 219 | * culture. |
220 | 220 | */ |
221 | - public static function getPercentageInstance($culture=null) |
|
221 | + public static function getPercentageInstance($culture = null) |
|
222 | 222 | { |
223 | 223 | return self::getInstance($culture, self::PERCENTAGE); |
224 | 224 | } |
@@ -229,7 +229,7 @@ discard block |
||
229 | 229 | * @return NumberFormatInfo NumberFormatInfo for the specified |
230 | 230 | * culture. |
231 | 231 | */ |
232 | - public static function getScientificInstance($culture=null) |
|
232 | + public static function getScientificInstance($culture = null) |
|
233 | 233 | { |
234 | 234 | return self::getInstance($culture, self::SCIENTIFIC); |
235 | 235 | } |
@@ -241,10 +241,10 @@ discard block |
||
241 | 241 | */ |
242 | 242 | protected function parsePattern($pattern) |
243 | 243 | { |
244 | - $pattern = explode(';',$pattern); |
|
244 | + $pattern = explode(';', $pattern); |
|
245 | 245 | |
246 | 246 | $negative = null; |
247 | - if(count($pattern) > 1) |
|
247 | + if (count($pattern) > 1) |
|
248 | 248 | $negative = $pattern[1]; |
249 | 249 | $pattern = $pattern[0]; |
250 | 250 | |
@@ -254,13 +254,13 @@ discard block |
||
254 | 254 | $hash = '#'; |
255 | 255 | |
256 | 256 | //find the first group point, and decimal point |
257 | - $groupPos1 = strrpos($pattern,$comma); |
|
258 | - $decimalPos = strrpos($pattern,$dot); |
|
257 | + $groupPos1 = strrpos($pattern, $comma); |
|
258 | + $decimalPos = strrpos($pattern, $dot); |
|
259 | 259 | |
260 | 260 | $groupPos2 = false; |
261 | 261 | $groupSize1 = false; |
262 | 262 | $groupSize2 = false; |
263 | - $decimalPoints = is_int($decimalPos)?-1:false; |
|
263 | + $decimalPoints = is_int($decimalPos) ?-1 : false; |
|
264 | 264 | |
265 | 265 | $info['negPref'] = $this->data['NumberElements'][6]; |
266 | 266 | $info['negPost'] = ''; |
@@ -269,7 +269,7 @@ discard block |
||
269 | 269 | $info['positive'] = $pattern; |
270 | 270 | |
271 | 271 | //find the negative prefix and postfix |
272 | - if($negative) |
|
272 | + if ($negative) |
|
273 | 273 | { |
274 | 274 | $prefixPostfix = $this->getPrePostfix($negative); |
275 | 275 | $info['negPref'] = $prefixPostfix[0]; |
@@ -282,24 +282,24 @@ discard block |
||
282 | 282 | |
283 | 283 | //var_dump($pattern); |
284 | 284 | //var_dump($decimalPos); |
285 | - if(is_int($groupPos1)) |
|
285 | + if (is_int($groupPos1)) |
|
286 | 286 | { |
287 | 287 | //get the second group |
288 | - $groupPos2 = strrpos(substr($pattern,0,$groupPos1),$comma); |
|
288 | + $groupPos2 = strrpos(substr($pattern, 0, $groupPos1), $comma); |
|
289 | 289 | |
290 | 290 | //get the number of decimal digits |
291 | - if(is_int($decimalPos)) |
|
291 | + if (is_int($decimalPos)) |
|
292 | 292 | { |
293 | - $groupSize1 = $decimalPos - $groupPos1-1; |
|
293 | + $groupSize1 = $decimalPos - $groupPos1 - 1; |
|
294 | 294 | |
295 | 295 | } |
296 | 296 | else |
297 | 297 | { |
298 | 298 | //no decimal point, so traverse from the back |
299 | 299 | //to find the groupsize 1. |
300 | - for($i=strlen($pattern)-1; $i>=0; $i--) |
|
300 | + for ($i = strlen($pattern) - 1; $i >= 0; $i--) |
|
301 | 301 | { |
302 | - if($pattern{$i} == $digit || $pattern{$i}==$hash) |
|
302 | + if ($pattern{$i} == $digit || $pattern{$i} == $hash) |
|
303 | 303 | { |
304 | 304 | $groupSize1 = $i - $groupPos1; |
305 | 305 | break; |
@@ -308,16 +308,16 @@ discard block |
||
308 | 308 | } |
309 | 309 | |
310 | 310 | //get the second group size |
311 | - if(is_int($groupPos2)) |
|
312 | - $groupSize2 = $groupPos1 - $groupPos2-1; |
|
311 | + if (is_int($groupPos2)) |
|
312 | + $groupSize2 = $groupPos1 - $groupPos2 - 1; |
|
313 | 313 | } |
314 | 314 | |
315 | - if(is_int($decimalPos)) |
|
315 | + if (is_int($decimalPos)) |
|
316 | 316 | { |
317 | - for($i=strlen($pattern)-1; $i>=0; $i--) |
|
317 | + for ($i = strlen($pattern) - 1; $i >= 0; $i--) |
|
318 | 318 | { |
319 | - if($pattern{$i} == $dot) break; |
|
320 | - if($pattern{$i} == $digit) |
|
319 | + if ($pattern{$i} == $dot) break; |
|
320 | + if ($pattern{$i} == $digit) |
|
321 | 321 | { |
322 | 322 | $decimalPoints = $i - $decimalPos; |
323 | 323 | break; |
@@ -325,12 +325,12 @@ discard block |
||
325 | 325 | } |
326 | 326 | } |
327 | 327 | |
328 | - if(is_int($decimalPos)) |
|
329 | - $digitPattern = substr($pattern,0,$decimalPos); |
|
328 | + if (is_int($decimalPos)) |
|
329 | + $digitPattern = substr($pattern, 0, $decimalPos); |
|
330 | 330 | else |
331 | - $digitPattern = $pattern; |
|
331 | + $digitPattern = $pattern; |
|
332 | 332 | |
333 | - $digitPattern = preg_replace('/[^0]/','',$digitPattern); |
|
333 | + $digitPattern = preg_replace('/[^0]/', '', $digitPattern); |
|
334 | 334 | |
335 | 335 | $info['groupPos1'] = $groupPos1; |
336 | 336 | $info['groupSize1'] = $groupSize1; |
@@ -351,7 +351,7 @@ discard block |
||
351 | 351 | { |
352 | 352 | $regexp = '/[#,\.0]+/'; |
353 | 353 | $result = preg_split($regexp, $pattern); |
354 | - return array($result[0],$result[1]); |
|
354 | + return array($result[0], $result[1]); |
|
355 | 355 | } |
356 | 356 | |
357 | 357 | |
@@ -503,9 +503,9 @@ discard block |
||
503 | 503 | * Gets the string to use as the currency symbol. |
504 | 504 | * @return string currency symbol. |
505 | 505 | */ |
506 | - function getCurrencySymbol($currency='USD') |
|
506 | + function getCurrencySymbol($currency = 'USD') |
|
507 | 507 | { |
508 | - if(isset($this->pattern['symbol'])) |
|
508 | + if (isset($this->pattern['symbol'])) |
|
509 | 509 | return $this->pattern['symbol']; |
510 | 510 | else |
511 | 511 | return $this->data['Currencies'][$currency][0]; |
@@ -79,10 +79,11 @@ discard block |
||
79 | 79 | public function __get($name) |
80 | 80 | { |
81 | 81 | $getProperty = 'get'.$name; |
82 | - if(in_array($getProperty, $this->properties)) |
|
83 | - return $this->$getProperty(); |
|
84 | - else |
|
85 | - throw new Exception('Property '.$name.' does not exists.'); |
|
82 | + if(in_array($getProperty, $this->properties)) { |
|
83 | + return $this->$getProperty(); |
|
84 | + } else { |
|
85 | + throw new Exception('Property '.$name.' does not exists.'); |
|
86 | + } |
|
86 | 87 | } |
87 | 88 | |
88 | 89 | /** |
@@ -92,10 +93,11 @@ discard block |
||
92 | 93 | public function __set($name, $value) |
93 | 94 | { |
94 | 95 | $setProperty = 'set'.$name; |
95 | - if(in_array($setProperty, $this->properties)) |
|
96 | - $this->$setProperty($value); |
|
97 | - else |
|
98 | - throw new Exception('Property '.$name.' can not be set.'); |
|
96 | + if(in_array($setProperty, $this->properties)) { |
|
97 | + $this->$setProperty($value); |
|
98 | + } else { |
|
99 | + throw new Exception('Property '.$name.' can not be set.'); |
|
100 | + } |
|
99 | 101 | } |
100 | 102 | |
101 | 103 | /** |
@@ -111,8 +113,9 @@ discard block |
||
111 | 113 | { |
112 | 114 | $this->properties = get_class_methods($this); |
113 | 115 | |
114 | - if(empty($data)) |
|
115 | - throw new Exception('Please provide the ICU data to initialize.'); |
|
116 | + if(empty($data)) { |
|
117 | + throw new Exception('Please provide the ICU data to initialize.'); |
|
118 | + } |
|
116 | 119 | |
117 | 120 | $this->data = $data; |
118 | 121 | |
@@ -127,11 +130,12 @@ discard block |
||
127 | 130 | */ |
128 | 131 | public function setPattern($type=NumberFormatInfo::DECIMAL) |
129 | 132 | { |
130 | - if(is_int($type)) |
|
131 | - $this->pattern = |
|
133 | + if(is_int($type)) { |
|
134 | + $this->pattern = |
|
132 | 135 | $this->parsePattern($this->data['NumberPatterns'][$type]); |
133 | - else |
|
134 | - $this->pattern = $this->parsePattern($type); |
|
136 | + } else { |
|
137 | + $this->pattern = $this->parsePattern($type); |
|
138 | + } |
|
135 | 139 | |
136 | 140 | $this->pattern['negInfty'] = |
137 | 141 | $this->data['NumberElements'][6]. |
@@ -184,15 +188,13 @@ discard block |
||
184 | 188 | $formatInfo = $culture->NumberFormat; |
185 | 189 | $formatInfo->setPattern($type); |
186 | 190 | return $formatInfo; |
187 | - } |
|
188 | - else if(is_string($culture)) |
|
191 | + } else if(is_string($culture)) |
|
189 | 192 | { |
190 | 193 | $cultureInfo = new CultureInfo($culture); |
191 | 194 | $formatInfo = $cultureInfo->NumberFormat; |
192 | 195 | $formatInfo->setPattern($type); |
193 | 196 | return $formatInfo; |
194 | - } |
|
195 | - else |
|
197 | + } else |
|
196 | 198 | { |
197 | 199 | $cultureInfo = new CultureInfo(); |
198 | 200 | $formatInfo = $cultureInfo->NumberFormat; |
@@ -244,8 +246,9 @@ discard block |
||
244 | 246 | $pattern = explode(';',$pattern); |
245 | 247 | |
246 | 248 | $negative = null; |
247 | - if(count($pattern) > 1) |
|
248 | - $negative = $pattern[1]; |
|
249 | + if(count($pattern) > 1) { |
|
250 | + $negative = $pattern[1]; |
|
251 | + } |
|
249 | 252 | $pattern = $pattern[0]; |
250 | 253 | |
251 | 254 | $comma = ','; |
@@ -292,8 +295,7 @@ discard block |
||
292 | 295 | { |
293 | 296 | $groupSize1 = $decimalPos - $groupPos1-1; |
294 | 297 | |
295 | - } |
|
296 | - else |
|
298 | + } else |
|
297 | 299 | { |
298 | 300 | //no decimal point, so traverse from the back |
299 | 301 | //to find the groupsize 1. |
@@ -308,15 +310,18 @@ discard block |
||
308 | 310 | } |
309 | 311 | |
310 | 312 | //get the second group size |
311 | - if(is_int($groupPos2)) |
|
312 | - $groupSize2 = $groupPos1 - $groupPos2-1; |
|
313 | + if(is_int($groupPos2)) { |
|
314 | + $groupSize2 = $groupPos1 - $groupPos2-1; |
|
315 | + } |
|
313 | 316 | } |
314 | 317 | |
315 | 318 | if(is_int($decimalPos)) |
316 | 319 | { |
317 | 320 | for($i=strlen($pattern)-1; $i>=0; $i--) |
318 | 321 | { |
319 | - if($pattern{$i} == $dot) break; |
|
322 | + if($pattern{$i} == $dot) { |
|
323 | + break; |
|
324 | + } |
|
320 | 325 | if($pattern{$i} == $digit) |
321 | 326 | { |
322 | 327 | $decimalPoints = $i - $decimalPos; |
@@ -325,10 +330,11 @@ discard block |
||
325 | 330 | } |
326 | 331 | } |
327 | 332 | |
328 | - if(is_int($decimalPos)) |
|
329 | - $digitPattern = substr($pattern,0,$decimalPos); |
|
330 | - else |
|
331 | - $digitPattern = $pattern; |
|
333 | + if(is_int($decimalPos)) { |
|
334 | + $digitPattern = substr($pattern,0,$decimalPos); |
|
335 | + } else { |
|
336 | + $digitPattern = $pattern; |
|
337 | + } |
|
332 | 338 | |
333 | 339 | $digitPattern = preg_replace('/[^0]/','',$digitPattern); |
334 | 340 | |
@@ -505,10 +511,11 @@ discard block |
||
505 | 511 | */ |
506 | 512 | function getCurrencySymbol($currency='USD') |
507 | 513 | { |
508 | - if(isset($this->pattern['symbol'])) |
|
509 | - return $this->pattern['symbol']; |
|
510 | - else |
|
511 | - return $this->data['Currencies'][$currency][0]; |
|
514 | + if(isset($this->pattern['symbol'])) { |
|
515 | + return $this->pattern['symbol']; |
|
516 | + } else { |
|
517 | + return $this->data['Currencies'][$currency][0]; |
|
518 | + } |
|
512 | 519 | } |
513 | 520 | |
514 | 521 |
@@ -485,6 +485,8 @@ |
||
485 | 485 | /** |
486 | 486 | * |
487 | 487 | * @access private |
488 | + * @param string $id |
|
489 | + * @param string $data |
|
488 | 490 | */ |
489 | 491 | function _memoryCacheAdd($id, $data) |
490 | 492 | { |
@@ -46,582 +46,582 @@ |
||
46 | 46 | class TCache_Lite |
47 | 47 | { |
48 | 48 | |
49 | - // --- Private properties --- |
|
50 | - |
|
51 | - /** |
|
52 | - * Directory where to put the cache files |
|
53 | - * (make sure to add a trailing slash) |
|
54 | - * |
|
55 | - * @var string $_cacheDir |
|
56 | - */ |
|
57 | - protected $_cacheDir = '/tmp/'; |
|
58 | - |
|
59 | - /** |
|
60 | - * Enable / disable caching |
|
61 | - * |
|
62 | - * (can be very usefull for the debug of cached scripts) |
|
63 | - * |
|
64 | - * @var boolean $_caching |
|
65 | - */ |
|
66 | - protected $_caching = true; |
|
67 | - |
|
68 | - /** |
|
69 | - * Cache lifetime (in seconds) |
|
70 | - * |
|
71 | - * @var int $_lifeTime |
|
72 | - */ |
|
73 | - protected $_lifeTime = 3600; |
|
74 | - |
|
75 | - /** |
|
76 | - * Enable / disable fileLocking |
|
77 | - * |
|
78 | - * (can avoid cache corruption under bad circumstances) |
|
79 | - * |
|
80 | - * @var boolean $_fileLocking |
|
81 | - */ |
|
82 | - protected $_fileLocking = true; |
|
83 | - |
|
84 | - /** |
|
85 | - * Timestamp of the last valid cache |
|
86 | - * |
|
87 | - * @var int $_refreshTime |
|
88 | - */ |
|
89 | - protected $_refreshTime; |
|
90 | - |
|
91 | - /** |
|
92 | - * File name (with path) |
|
93 | - * |
|
94 | - * @var string $_file |
|
95 | - */ |
|
96 | - protected $_file; |
|
97 | - |
|
98 | - /** |
|
99 | - * Enable / disable write control (the cache is read just after writing |
|
100 | - * to detect corrupt entries) |
|
101 | - * |
|
102 | - * Enable write control will lightly slow the cache writing but not the |
|
103 | - * cache reading. Write control can detect some corrupt cache files but |
|
104 | - * maybe it's not a perfect control |
|
105 | - * |
|
106 | - * @var boolean $_writeControl |
|
107 | - */ |
|
108 | - protected $_writeControl = true; |
|
109 | - |
|
110 | - /** |
|
111 | - * Enable / disable read control |
|
112 | - * |
|
113 | - * If enabled, a control key is embeded in cache file and this key is |
|
114 | - * compared with the one calculated after the reading. |
|
115 | - * |
|
116 | - * @var boolean $_writeControl |
|
117 | - */ |
|
118 | - protected $_readControl = true; |
|
119 | - |
|
120 | - /** |
|
121 | - * Type of read control (only if read control is enabled) |
|
122 | - * |
|
123 | - * Available values are : |
|
124 | - * 'md5' for a md5 hash control (best but slowest) |
|
125 | - * 'crc32' for a crc32 hash control (lightly less safe but faster, |
|
126 | - * better choice) |
|
127 | - * 'strlen' for a length only test (fastest) |
|
128 | - * |
|
129 | - * @var boolean $_readControlType |
|
130 | - */ |
|
131 | - protected $_readControlType = 'crc32'; |
|
132 | - |
|
133 | - /** |
|
134 | - * Current cache id |
|
135 | - * |
|
136 | - * @var string $_id |
|
137 | - */ |
|
138 | - protected $_id; |
|
139 | - |
|
140 | - /** |
|
141 | - * Current cache group |
|
142 | - * |
|
143 | - * @var string $_group |
|
144 | - */ |
|
145 | - protected $_group; |
|
146 | - |
|
147 | - /** |
|
148 | - * Enable / Disable "Memory Caching" |
|
149 | - * |
|
150 | - * NB : There is no lifetime for memory caching ! |
|
151 | - * |
|
152 | - * @var boolean $_memoryCaching |
|
153 | - */ |
|
154 | - protected $_memoryCaching = false; |
|
155 | - |
|
156 | - /** |
|
157 | - * Enable / Disable "Only Memory Caching" |
|
158 | - * (be carefull, memory caching is "beta quality") |
|
159 | - * |
|
160 | - * @var boolean $_onlyMemoryCaching |
|
161 | - */ |
|
162 | - protected $_onlyMemoryCaching = false; |
|
163 | - |
|
164 | - /** |
|
165 | - * Memory caching array |
|
166 | - * |
|
167 | - * @var array $_memoryCachingArray |
|
168 | - */ |
|
169 | - protected $_memoryCachingArray = array(); |
|
170 | - |
|
171 | - /** |
|
172 | - * Memory caching counter |
|
173 | - * |
|
174 | - * @var int $memoryCachingCounter |
|
175 | - */ |
|
176 | - protected $_memoryCachingCounter = 0; |
|
177 | - |
|
178 | - /** |
|
179 | - * Memory caching limit |
|
180 | - * |
|
181 | - * @var int $memoryCachingLimit |
|
182 | - */ |
|
183 | - protected $_memoryCachingLimit = 1000; |
|
184 | - |
|
185 | - /** |
|
186 | - * File Name protection |
|
187 | - * |
|
188 | - * if set to true, you can use any cache id or group name |
|
189 | - * if set to false, it can be faster but cache ids and group names |
|
190 | - * will be used directly in cache file names so be carefull with |
|
191 | - * special characters... |
|
192 | - * |
|
193 | - * @var boolean $fileNameProtection |
|
194 | - */ |
|
195 | - protected $_fileNameProtection = true; |
|
196 | - |
|
197 | - /** |
|
198 | - * Enable / disable automatic serialization |
|
199 | - * |
|
200 | - * it can be used to save directly datas which aren't strings |
|
201 | - * (but it's slower) |
|
202 | - * |
|
203 | - * @var boolean $_serialize |
|
204 | - */ |
|
205 | - protected $_automaticSerialization = false; |
|
206 | - |
|
207 | - // --- Public methods --- |
|
208 | - |
|
209 | - /** |
|
210 | - * Constructor |
|
211 | - * |
|
212 | - * $options is an assoc. Available options are : |
|
213 | - * $options = array( |
|
214 | - * 'cacheDir' => directory where to put the cache files (string), |
|
215 | - * 'caching' => enable / disable caching (boolean), |
|
216 | - * 'lifeTime' => cache lifetime in seconds (int), |
|
217 | - * 'fileLocking' => enable / disable fileLocking (boolean), |
|
218 | - * 'writeControl' => enable / disable write control (boolean), |
|
219 | - * 'readControl' => enable / disable read control (boolean), |
|
220 | - * 'readControlType' => type of read control 'crc32', 'md5', 'strlen', |
|
221 | - * 'memoryCaching' => enable / disable memory caching (boolean), |
|
222 | - * 'onlyMemoryCaching' => enable / disable only memory caching (boolean), |
|
223 | - * 'memoryCachingLimit' => max nbr of records in memory caching (int), |
|
224 | - * 'fileNameProtection' => enable / disable file name protection (boolean), |
|
225 | - * 'automaticSerialization' => enable / disable serialization (boolean) |
|
226 | - * ); |
|
227 | - * |
|
228 | - * @param array $options options |
|
229 | - * @access public |
|
230 | - */ |
|
231 | - function TCache_Lite($options = array(null)) |
|
232 | - { |
|
233 | - $availableOptions = array( 'automaticSerialization', |
|
234 | - 'fileNameProtection', |
|
235 | - 'memoryCaching', |
|
236 | - 'onlyMemoryCaching', |
|
237 | - 'memoryCachingLimit', |
|
238 | - 'cacheDir', |
|
239 | - 'caching', |
|
240 | - 'lifeTime', |
|
241 | - 'fileLocking', |
|
242 | - 'writeControl', |
|
243 | - 'readControl', |
|
244 | - 'readControlType'); |
|
245 | - foreach($options as $key => $value) { |
|
246 | - if(in_array($key, $availableOptions)) { |
|
247 | - $property = '_'.$key; |
|
248 | - $this->$property = $value; |
|
249 | - } |
|
250 | - } |
|
251 | - $this->_refreshTime = time() - $this->_lifeTime; |
|
49 | + // --- Private properties --- |
|
50 | + |
|
51 | + /** |
|
52 | + * Directory where to put the cache files |
|
53 | + * (make sure to add a trailing slash) |
|
54 | + * |
|
55 | + * @var string $_cacheDir |
|
56 | + */ |
|
57 | + protected $_cacheDir = '/tmp/'; |
|
58 | + |
|
59 | + /** |
|
60 | + * Enable / disable caching |
|
61 | + * |
|
62 | + * (can be very usefull for the debug of cached scripts) |
|
63 | + * |
|
64 | + * @var boolean $_caching |
|
65 | + */ |
|
66 | + protected $_caching = true; |
|
67 | + |
|
68 | + /** |
|
69 | + * Cache lifetime (in seconds) |
|
70 | + * |
|
71 | + * @var int $_lifeTime |
|
72 | + */ |
|
73 | + protected $_lifeTime = 3600; |
|
74 | + |
|
75 | + /** |
|
76 | + * Enable / disable fileLocking |
|
77 | + * |
|
78 | + * (can avoid cache corruption under bad circumstances) |
|
79 | + * |
|
80 | + * @var boolean $_fileLocking |
|
81 | + */ |
|
82 | + protected $_fileLocking = true; |
|
83 | + |
|
84 | + /** |
|
85 | + * Timestamp of the last valid cache |
|
86 | + * |
|
87 | + * @var int $_refreshTime |
|
88 | + */ |
|
89 | + protected $_refreshTime; |
|
90 | + |
|
91 | + /** |
|
92 | + * File name (with path) |
|
93 | + * |
|
94 | + * @var string $_file |
|
95 | + */ |
|
96 | + protected $_file; |
|
97 | + |
|
98 | + /** |
|
99 | + * Enable / disable write control (the cache is read just after writing |
|
100 | + * to detect corrupt entries) |
|
101 | + * |
|
102 | + * Enable write control will lightly slow the cache writing but not the |
|
103 | + * cache reading. Write control can detect some corrupt cache files but |
|
104 | + * maybe it's not a perfect control |
|
105 | + * |
|
106 | + * @var boolean $_writeControl |
|
107 | + */ |
|
108 | + protected $_writeControl = true; |
|
109 | + |
|
110 | + /** |
|
111 | + * Enable / disable read control |
|
112 | + * |
|
113 | + * If enabled, a control key is embeded in cache file and this key is |
|
114 | + * compared with the one calculated after the reading. |
|
115 | + * |
|
116 | + * @var boolean $_writeControl |
|
117 | + */ |
|
118 | + protected $_readControl = true; |
|
119 | + |
|
120 | + /** |
|
121 | + * Type of read control (only if read control is enabled) |
|
122 | + * |
|
123 | + * Available values are : |
|
124 | + * 'md5' for a md5 hash control (best but slowest) |
|
125 | + * 'crc32' for a crc32 hash control (lightly less safe but faster, |
|
126 | + * better choice) |
|
127 | + * 'strlen' for a length only test (fastest) |
|
128 | + * |
|
129 | + * @var boolean $_readControlType |
|
130 | + */ |
|
131 | + protected $_readControlType = 'crc32'; |
|
132 | + |
|
133 | + /** |
|
134 | + * Current cache id |
|
135 | + * |
|
136 | + * @var string $_id |
|
137 | + */ |
|
138 | + protected $_id; |
|
139 | + |
|
140 | + /** |
|
141 | + * Current cache group |
|
142 | + * |
|
143 | + * @var string $_group |
|
144 | + */ |
|
145 | + protected $_group; |
|
146 | + |
|
147 | + /** |
|
148 | + * Enable / Disable "Memory Caching" |
|
149 | + * |
|
150 | + * NB : There is no lifetime for memory caching ! |
|
151 | + * |
|
152 | + * @var boolean $_memoryCaching |
|
153 | + */ |
|
154 | + protected $_memoryCaching = false; |
|
155 | + |
|
156 | + /** |
|
157 | + * Enable / Disable "Only Memory Caching" |
|
158 | + * (be carefull, memory caching is "beta quality") |
|
159 | + * |
|
160 | + * @var boolean $_onlyMemoryCaching |
|
161 | + */ |
|
162 | + protected $_onlyMemoryCaching = false; |
|
163 | + |
|
164 | + /** |
|
165 | + * Memory caching array |
|
166 | + * |
|
167 | + * @var array $_memoryCachingArray |
|
168 | + */ |
|
169 | + protected $_memoryCachingArray = array(); |
|
170 | + |
|
171 | + /** |
|
172 | + * Memory caching counter |
|
173 | + * |
|
174 | + * @var int $memoryCachingCounter |
|
175 | + */ |
|
176 | + protected $_memoryCachingCounter = 0; |
|
177 | + |
|
178 | + /** |
|
179 | + * Memory caching limit |
|
180 | + * |
|
181 | + * @var int $memoryCachingLimit |
|
182 | + */ |
|
183 | + protected $_memoryCachingLimit = 1000; |
|
184 | + |
|
185 | + /** |
|
186 | + * File Name protection |
|
187 | + * |
|
188 | + * if set to true, you can use any cache id or group name |
|
189 | + * if set to false, it can be faster but cache ids and group names |
|
190 | + * will be used directly in cache file names so be carefull with |
|
191 | + * special characters... |
|
192 | + * |
|
193 | + * @var boolean $fileNameProtection |
|
194 | + */ |
|
195 | + protected $_fileNameProtection = true; |
|
196 | + |
|
197 | + /** |
|
198 | + * Enable / disable automatic serialization |
|
199 | + * |
|
200 | + * it can be used to save directly datas which aren't strings |
|
201 | + * (but it's slower) |
|
202 | + * |
|
203 | + * @var boolean $_serialize |
|
204 | + */ |
|
205 | + protected $_automaticSerialization = false; |
|
206 | + |
|
207 | + // --- Public methods --- |
|
208 | + |
|
209 | + /** |
|
210 | + * Constructor |
|
211 | + * |
|
212 | + * $options is an assoc. Available options are : |
|
213 | + * $options = array( |
|
214 | + * 'cacheDir' => directory where to put the cache files (string), |
|
215 | + * 'caching' => enable / disable caching (boolean), |
|
216 | + * 'lifeTime' => cache lifetime in seconds (int), |
|
217 | + * 'fileLocking' => enable / disable fileLocking (boolean), |
|
218 | + * 'writeControl' => enable / disable write control (boolean), |
|
219 | + * 'readControl' => enable / disable read control (boolean), |
|
220 | + * 'readControlType' => type of read control 'crc32', 'md5', 'strlen', |
|
221 | + * 'memoryCaching' => enable / disable memory caching (boolean), |
|
222 | + * 'onlyMemoryCaching' => enable / disable only memory caching (boolean), |
|
223 | + * 'memoryCachingLimit' => max nbr of records in memory caching (int), |
|
224 | + * 'fileNameProtection' => enable / disable file name protection (boolean), |
|
225 | + * 'automaticSerialization' => enable / disable serialization (boolean) |
|
226 | + * ); |
|
227 | + * |
|
228 | + * @param array $options options |
|
229 | + * @access public |
|
230 | + */ |
|
231 | + function TCache_Lite($options = array(null)) |
|
232 | + { |
|
233 | + $availableOptions = array( 'automaticSerialization', |
|
234 | + 'fileNameProtection', |
|
235 | + 'memoryCaching', |
|
236 | + 'onlyMemoryCaching', |
|
237 | + 'memoryCachingLimit', |
|
238 | + 'cacheDir', |
|
239 | + 'caching', |
|
240 | + 'lifeTime', |
|
241 | + 'fileLocking', |
|
242 | + 'writeControl', |
|
243 | + 'readControl', |
|
244 | + 'readControlType'); |
|
245 | + foreach($options as $key => $value) { |
|
246 | + if(in_array($key, $availableOptions)) { |
|
247 | + $property = '_'.$key; |
|
248 | + $this->$property = $value; |
|
249 | + } |
|
250 | + } |
|
251 | + $this->_refreshTime = time() - $this->_lifeTime; |
|
252 | + } |
|
253 | + |
|
254 | + /** |
|
255 | + * Test if a cache is available and (if yes) return it |
|
256 | + * |
|
257 | + * @param string $id cache id |
|
258 | + * @param string $group name of the cache group |
|
259 | + * @param boolean $doNotTestCacheValidity if set to true, the cache |
|
260 | + * validity won't be tested |
|
261 | + * @return string data of the cache (or false if no cache available) |
|
262 | + * @access public |
|
263 | + */ |
|
264 | + function get($id, $group = 'default', $doNotTestCacheValidity = false) |
|
265 | + { |
|
266 | + $this->_id = $id; |
|
267 | + $this->_group = $group; |
|
268 | + $data = false; |
|
269 | + if ($this->_caching) { |
|
270 | + $this->_setFileName($id, $group); |
|
271 | + if ($this->_memoryCaching) { |
|
272 | + if (isset($this->_memoryCachingArray[$this->_file])) { |
|
273 | + if ($this->_automaticSerialization) { |
|
274 | + return unserialize( |
|
275 | + $this->_memoryCachingArray[$this->_file]); |
|
276 | + } else { |
|
277 | + return $this->_memoryCachingArray[$this->_file]; |
|
278 | + } |
|
279 | + } else { |
|
280 | + if ($this->_onlyMemoryCaching) { |
|
281 | + return false; |
|
282 | + } |
|
283 | + } |
|
284 | + } |
|
285 | + if ($doNotTestCacheValidity) { |
|
286 | + if (file_exists($this->_file)) { |
|
287 | + $data = $this->_read(); |
|
288 | + } |
|
289 | + } else { |
|
290 | + if (@filemtime($this->_file) > $this->_refreshTime) { |
|
291 | + $data = $this->_read(); |
|
292 | + } |
|
293 | + } |
|
294 | + if (($data) and ($this->_memoryCaching)) { |
|
295 | + $this->_memoryCacheAdd($this->_file, $data); |
|
296 | + } |
|
297 | + if ($this->_automaticSerialization && is_string($data)) { |
|
298 | + $data = unserialize($data); |
|
299 | + } |
|
300 | + return $data; |
|
301 | + } |
|
302 | + return false; |
|
303 | + } |
|
304 | + |
|
305 | + /** |
|
306 | + * Save some data in a cache file |
|
307 | + * |
|
308 | + * @param string $data data to put in cache (can be another type than strings |
|
309 | + * if automaticSerialization is on) |
|
310 | + * @param string $id cache id |
|
311 | + * @param string $group name of the cache group |
|
312 | + * @return boolean true if no problem |
|
313 | + * @access public |
|
314 | + */ |
|
315 | + function save($data, $id = null, $group = 'default') |
|
316 | + { |
|
317 | + if ($this->_caching) { |
|
318 | + if ($this->_automaticSerialization) { |
|
319 | + $data = serialize($data); |
|
320 | + } |
|
321 | + if (isset($id)) { |
|
322 | + $this->_setFileName($id, $group); |
|
323 | + } |
|
324 | + if ($this->_memoryCaching) { |
|
325 | + $this->_memoryCacheAdd($this->_file, $data); |
|
326 | + if ($this->_onlyMemoryCaching) { |
|
327 | + return true; |
|
328 | + } |
|
329 | + } |
|
330 | + if ($this->_writeControl) { |
|
331 | + if (!$this->_writeAndControl($data)) { |
|
332 | + @touch($this->_file, time() - 2*abs($this->_lifeTime)); |
|
333 | + return false; |
|
334 | + } else { |
|
335 | + return true; |
|
336 | + } |
|
337 | + } else { |
|
338 | + return $this->_write($data); |
|
339 | + } |
|
340 | + } |
|
341 | + return false; |
|
342 | + } |
|
343 | + |
|
344 | + /** |
|
345 | + * Remove a cache file |
|
346 | + * |
|
347 | + * @param string $id cache id |
|
348 | + * @param string $group name of the cache group |
|
349 | + * @return boolean true if no problem |
|
350 | + * @access public |
|
351 | + */ |
|
352 | + function remove($id, $group = 'default') |
|
353 | + { |
|
354 | + $this->_setFileName($id, $group); |
|
355 | + if (!@unlink($this->_file)) { |
|
356 | + $this->raiseError('TCache_Lite : Unable to remove cache !', -3); |
|
357 | + return false; |
|
358 | + } |
|
359 | + return true; |
|
360 | + } |
|
361 | + |
|
362 | + /** |
|
363 | + * Clean the cache |
|
364 | + * |
|
365 | + * if no group is specified all cache files will be destroyed |
|
366 | + * else only cache files of the specified group will be destroyed |
|
367 | + * |
|
368 | + * @param string $group name of the cache group |
|
369 | + * @return boolean true if no problem |
|
370 | + * @access public |
|
371 | + */ |
|
372 | + function clean($group = false) |
|
373 | + { |
|
374 | + if ($this->_fileNameProtection) { |
|
375 | + $motif = ($group) ? 'cache_'.md5($group).'_' : 'cache_'; |
|
376 | + } else { |
|
377 | + $motif = ($group) ? 'cache_'.$group.'_' : 'cache_'; |
|
378 | + } |
|
379 | + if ($this->_memoryCaching) { |
|
380 | + while (list($key, $value) = each($this->_memoryCaching)) { |
|
381 | + if (strpos($key, $motif, 0)) { |
|
382 | + unset($this->_memoryCaching[$key]); |
|
383 | + $this->_memoryCachingCounter = |
|
384 | + $this->_memoryCachingCounter - 1; |
|
385 | + } |
|
386 | + } |
|
387 | + if ($this->_onlyMemoryCaching) { |
|
388 | + return true; |
|
389 | + } |
|
390 | + } |
|
391 | + if (!($dh = opendir($this->_cacheDir))) { |
|
392 | + $this->raiseError('TCache_Lite : Unable to open cache directory !'); |
|
393 | + return false; |
|
394 | + } |
|
395 | + while ($file = readdir($dh)) { |
|
396 | + if (($file != '.') && ($file != '..')) { |
|
397 | + $file = $this->_cacheDir . $file; |
|
398 | + if (is_file($file)) { |
|
399 | + if (strpos($file, $motif, 0)) { |
|
400 | + if (!@unlink($file)) { |
|
401 | + $this->raiseError('Cache_Lite : Unable to remove cache !', -3); |
|
402 | + return false; |
|
403 | + } |
|
404 | + } |
|
405 | + } |
|
406 | + } |
|
407 | + } |
|
408 | + return true; |
|
409 | + } |
|
410 | + |
|
411 | + /** |
|
412 | + * Set a new life time |
|
413 | + * |
|
414 | + * @param int $newLifeTime new life time (in seconds) |
|
415 | + * @access public |
|
416 | + */ |
|
417 | + function setLifeTime($newLifeTime) |
|
418 | + { |
|
419 | + $this->_lifeTime = $newLifeTime; |
|
420 | + $this->_refreshTime = time() - $newLifeTime; |
|
421 | + } |
|
422 | + |
|
423 | + /** |
|
424 | + * |
|
425 | + * @access public |
|
426 | + */ |
|
427 | + function saveMemoryCachingState($id, $group = 'default') |
|
428 | + { |
|
429 | + if ($this->_caching) { |
|
430 | + $array = array( |
|
431 | + 'counter' => $this->_memoryCachingCounter, |
|
432 | + 'array' => $this->_memoryCachingState |
|
433 | + ); |
|
434 | + $data = serialize($array); |
|
435 | + $this->save($data, $id, $group); |
|
436 | + } |
|
252 | 437 | } |
253 | 438 | |
254 | - /** |
|
255 | - * Test if a cache is available and (if yes) return it |
|
256 | - * |
|
257 | - * @param string $id cache id |
|
258 | - * @param string $group name of the cache group |
|
259 | - * @param boolean $doNotTestCacheValidity if set to true, the cache |
|
260 | - * validity won't be tested |
|
261 | - * @return string data of the cache (or false if no cache available) |
|
262 | - * @access public |
|
263 | - */ |
|
264 | - function get($id, $group = 'default', $doNotTestCacheValidity = false) |
|
265 | - { |
|
266 | - $this->_id = $id; |
|
267 | - $this->_group = $group; |
|
268 | - $data = false; |
|
269 | - if ($this->_caching) { |
|
270 | - $this->_setFileName($id, $group); |
|
271 | - if ($this->_memoryCaching) { |
|
272 | - if (isset($this->_memoryCachingArray[$this->_file])) { |
|
273 | - if ($this->_automaticSerialization) { |
|
274 | - return unserialize( |
|
275 | - $this->_memoryCachingArray[$this->_file]); |
|
276 | - } else { |
|
277 | - return $this->_memoryCachingArray[$this->_file]; |
|
278 | - } |
|
279 | - } else { |
|
280 | - if ($this->_onlyMemoryCaching) { |
|
281 | - return false; |
|
282 | - } |
|
283 | - } |
|
284 | - } |
|
285 | - if ($doNotTestCacheValidity) { |
|
286 | - if (file_exists($this->_file)) { |
|
287 | - $data = $this->_read(); |
|
288 | - } |
|
289 | - } else { |
|
290 | - if (@filemtime($this->_file) > $this->_refreshTime) { |
|
291 | - $data = $this->_read(); |
|
292 | - } |
|
293 | - } |
|
294 | - if (($data) and ($this->_memoryCaching)) { |
|
295 | - $this->_memoryCacheAdd($this->_file, $data); |
|
296 | - } |
|
297 | - if ($this->_automaticSerialization && is_string($data)) { |
|
298 | - $data = unserialize($data); |
|
299 | - } |
|
300 | - return $data; |
|
301 | - } |
|
302 | - return false; |
|
303 | - } |
|
304 | - |
|
305 | - /** |
|
306 | - * Save some data in a cache file |
|
307 | - * |
|
308 | - * @param string $data data to put in cache (can be another type than strings |
|
309 | - * if automaticSerialization is on) |
|
310 | - * @param string $id cache id |
|
311 | - * @param string $group name of the cache group |
|
312 | - * @return boolean true if no problem |
|
313 | - * @access public |
|
314 | - */ |
|
315 | - function save($data, $id = null, $group = 'default') |
|
316 | - { |
|
317 | - if ($this->_caching) { |
|
318 | - if ($this->_automaticSerialization) { |
|
319 | - $data = serialize($data); |
|
320 | - } |
|
321 | - if (isset($id)) { |
|
322 | - $this->_setFileName($id, $group); |
|
323 | - } |
|
324 | - if ($this->_memoryCaching) { |
|
325 | - $this->_memoryCacheAdd($this->_file, $data); |
|
326 | - if ($this->_onlyMemoryCaching) { |
|
327 | - return true; |
|
328 | - } |
|
329 | - } |
|
330 | - if ($this->_writeControl) { |
|
331 | - if (!$this->_writeAndControl($data)) { |
|
332 | - @touch($this->_file, time() - 2*abs($this->_lifeTime)); |
|
333 | - return false; |
|
334 | - } else { |
|
335 | - return true; |
|
336 | - } |
|
337 | - } else { |
|
338 | - return $this->_write($data); |
|
339 | - } |
|
340 | - } |
|
341 | - return false; |
|
342 | - } |
|
343 | - |
|
344 | - /** |
|
345 | - * Remove a cache file |
|
346 | - * |
|
347 | - * @param string $id cache id |
|
348 | - * @param string $group name of the cache group |
|
349 | - * @return boolean true if no problem |
|
350 | - * @access public |
|
351 | - */ |
|
352 | - function remove($id, $group = 'default') |
|
353 | - { |
|
354 | - $this->_setFileName($id, $group); |
|
355 | - if (!@unlink($this->_file)) { |
|
356 | - $this->raiseError('TCache_Lite : Unable to remove cache !', -3); |
|
357 | - return false; |
|
358 | - } |
|
359 | - return true; |
|
360 | - } |
|
361 | - |
|
362 | - /** |
|
363 | - * Clean the cache |
|
364 | - * |
|
365 | - * if no group is specified all cache files will be destroyed |
|
366 | - * else only cache files of the specified group will be destroyed |
|
367 | - * |
|
368 | - * @param string $group name of the cache group |
|
369 | - * @return boolean true if no problem |
|
370 | - * @access public |
|
371 | - */ |
|
372 | - function clean($group = false) |
|
373 | - { |
|
374 | - if ($this->_fileNameProtection) { |
|
375 | - $motif = ($group) ? 'cache_'.md5($group).'_' : 'cache_'; |
|
376 | - } else { |
|
377 | - $motif = ($group) ? 'cache_'.$group.'_' : 'cache_'; |
|
378 | - } |
|
379 | - if ($this->_memoryCaching) { |
|
380 | - while (list($key, $value) = each($this->_memoryCaching)) { |
|
381 | - if (strpos($key, $motif, 0)) { |
|
382 | - unset($this->_memoryCaching[$key]); |
|
383 | - $this->_memoryCachingCounter = |
|
384 | - $this->_memoryCachingCounter - 1; |
|
385 | - } |
|
386 | - } |
|
387 | - if ($this->_onlyMemoryCaching) { |
|
388 | - return true; |
|
389 | - } |
|
390 | - } |
|
391 | - if (!($dh = opendir($this->_cacheDir))) { |
|
392 | - $this->raiseError('TCache_Lite : Unable to open cache directory !'); |
|
393 | - return false; |
|
394 | - } |
|
395 | - while ($file = readdir($dh)) { |
|
396 | - if (($file != '.') && ($file != '..')) { |
|
397 | - $file = $this->_cacheDir . $file; |
|
398 | - if (is_file($file)) { |
|
399 | - if (strpos($file, $motif, 0)) { |
|
400 | - if (!@unlink($file)) { |
|
401 | - $this->raiseError('Cache_Lite : Unable to remove cache !', -3); |
|
402 | - return false; |
|
403 | - } |
|
404 | - } |
|
405 | - } |
|
406 | - } |
|
407 | - } |
|
408 | - return true; |
|
409 | - } |
|
410 | - |
|
411 | - /** |
|
412 | - * Set a new life time |
|
413 | - * |
|
414 | - * @param int $newLifeTime new life time (in seconds) |
|
415 | - * @access public |
|
416 | - */ |
|
417 | - function setLifeTime($newLifeTime) |
|
418 | - { |
|
419 | - $this->_lifeTime = $newLifeTime; |
|
420 | - $this->_refreshTime = time() - $newLifeTime; |
|
421 | - } |
|
422 | - |
|
423 | - /** |
|
424 | - * |
|
425 | - * @access public |
|
426 | - */ |
|
427 | - function saveMemoryCachingState($id, $group = 'default') |
|
428 | - { |
|
429 | - if ($this->_caching) { |
|
430 | - $array = array( |
|
431 | - 'counter' => $this->_memoryCachingCounter, |
|
432 | - 'array' => $this->_memoryCachingState |
|
433 | - ); |
|
434 | - $data = serialize($array); |
|
435 | - $this->save($data, $id, $group); |
|
436 | - } |
|
437 | - } |
|
438 | - |
|
439 | - /** |
|
440 | - * |
|
441 | - * @access public |
|
442 | - */ |
|
443 | - function getMemoryCachingState($id, $group = 'default', |
|
444 | - $doNotTestCacheValidity = false) |
|
445 | - { |
|
446 | - if ($this->_caching) { |
|
447 | - if ($data = $this->get($id, $group, $doNotTestCacheValidity)) |
|
448 | - { |
|
449 | - $array = unserialize($data); |
|
450 | - $this->_memoryCachingCounter = $array['counter']; |
|
451 | - $this->_memoryCachingArray = $array['array']; |
|
452 | - } |
|
453 | - } |
|
454 | - } |
|
455 | - |
|
456 | - /** |
|
457 | - * Return the cache last modification time |
|
458 | - * |
|
459 | - * BE CAREFUL : THIS METHOD IS FOR HACKING ONLY ! |
|
460 | - * |
|
461 | - * @return int last modification time |
|
462 | - */ |
|
463 | - function lastModified() { |
|
464 | - return filemtime($this->cache->_file); |
|
465 | - } |
|
466 | - |
|
467 | - /** |
|
468 | - * Trigger a PEAR error |
|
469 | - * |
|
470 | - * To improve performances, the PEAR.php file is included dynamically. |
|
471 | - * The file is so included only when an error is triggered. So, in most |
|
472 | - * cases, the file isn't included and perfs are much better. |
|
473 | - * |
|
474 | - * @param string $msg error message |
|
475 | - * @param int $code error code |
|
476 | - * @access public |
|
477 | - */ |
|
478 | - function raiseError($msg, $code) |
|
479 | - { |
|
480 | - throw new Exception($msg); |
|
481 | - } |
|
482 | - |
|
483 | - // --- Private methods --- |
|
484 | - |
|
485 | - /** |
|
486 | - * |
|
487 | - * @access private |
|
488 | - */ |
|
489 | - function _memoryCacheAdd($id, $data) |
|
490 | - { |
|
491 | - $this->_memoryCachingArray[$this->_file] = $data; |
|
492 | - if ($this->_memoryCachingCounter >= $this->_memoryCachingLimit) { |
|
493 | - list($key, $value) = each($this->_memoryCachingArray); |
|
494 | - unset($this->_memoryCachingArray[$key]); |
|
495 | - } else { |
|
496 | - $this->_memoryCachingCounter = $this->_memoryCachingCounter + 1; |
|
497 | - } |
|
498 | - } |
|
499 | - |
|
500 | - /** |
|
501 | - * Make a file name (with path) |
|
502 | - * |
|
503 | - * @param string $id cache id |
|
504 | - * @param string $group name of the group |
|
505 | - * @access private |
|
506 | - */ |
|
507 | - function _setFileName($id, $group) |
|
508 | - { |
|
509 | - if ($this->_fileNameProtection) { |
|
510 | - $this->_file = ($this->_cacheDir.'cache_'.md5($group).'_' |
|
511 | - .md5($id)); |
|
512 | - } else { |
|
513 | - $this->_file = $this->_cacheDir.'cache_'.$group.'_'.$id; |
|
514 | - } |
|
515 | - } |
|
516 | - |
|
517 | - function getCacheFile() |
|
518 | - { |
|
519 | - return $this->_file; |
|
520 | - } |
|
521 | - |
|
522 | - /** |
|
523 | - * Read the cache file and return the content |
|
524 | - * |
|
525 | - * @return string content of the cache file |
|
526 | - * @access private |
|
527 | - */ |
|
528 | - function _read() |
|
529 | - { |
|
530 | - $fp = @fopen($this->_file, "rb"); |
|
531 | - if ($this->_fileLocking) @flock($fp, LOCK_SH); |
|
532 | - if ($fp) { |
|
533 | - // because the filesize can be cached by PHP itself... |
|
534 | - clearstatcache(); |
|
535 | - $length = @filesize($this->_file); |
|
439 | + /** |
|
440 | + * |
|
441 | + * @access public |
|
442 | + */ |
|
443 | + function getMemoryCachingState($id, $group = 'default', |
|
444 | + $doNotTestCacheValidity = false) |
|
445 | + { |
|
446 | + if ($this->_caching) { |
|
447 | + if ($data = $this->get($id, $group, $doNotTestCacheValidity)) |
|
448 | + { |
|
449 | + $array = unserialize($data); |
|
450 | + $this->_memoryCachingCounter = $array['counter']; |
|
451 | + $this->_memoryCachingArray = $array['array']; |
|
452 | + } |
|
453 | + } |
|
454 | + } |
|
455 | + |
|
456 | + /** |
|
457 | + * Return the cache last modification time |
|
458 | + * |
|
459 | + * BE CAREFUL : THIS METHOD IS FOR HACKING ONLY ! |
|
460 | + * |
|
461 | + * @return int last modification time |
|
462 | + */ |
|
463 | + function lastModified() { |
|
464 | + return filemtime($this->cache->_file); |
|
465 | + } |
|
466 | + |
|
467 | + /** |
|
468 | + * Trigger a PEAR error |
|
469 | + * |
|
470 | + * To improve performances, the PEAR.php file is included dynamically. |
|
471 | + * The file is so included only when an error is triggered. So, in most |
|
472 | + * cases, the file isn't included and perfs are much better. |
|
473 | + * |
|
474 | + * @param string $msg error message |
|
475 | + * @param int $code error code |
|
476 | + * @access public |
|
477 | + */ |
|
478 | + function raiseError($msg, $code) |
|
479 | + { |
|
480 | + throw new Exception($msg); |
|
481 | + } |
|
482 | + |
|
483 | + // --- Private methods --- |
|
484 | + |
|
485 | + /** |
|
486 | + * |
|
487 | + * @access private |
|
488 | + */ |
|
489 | + function _memoryCacheAdd($id, $data) |
|
490 | + { |
|
491 | + $this->_memoryCachingArray[$this->_file] = $data; |
|
492 | + if ($this->_memoryCachingCounter >= $this->_memoryCachingLimit) { |
|
493 | + list($key, $value) = each($this->_memoryCachingArray); |
|
494 | + unset($this->_memoryCachingArray[$key]); |
|
495 | + } else { |
|
496 | + $this->_memoryCachingCounter = $this->_memoryCachingCounter + 1; |
|
497 | + } |
|
498 | + } |
|
499 | + |
|
500 | + /** |
|
501 | + * Make a file name (with path) |
|
502 | + * |
|
503 | + * @param string $id cache id |
|
504 | + * @param string $group name of the group |
|
505 | + * @access private |
|
506 | + */ |
|
507 | + function _setFileName($id, $group) |
|
508 | + { |
|
509 | + if ($this->_fileNameProtection) { |
|
510 | + $this->_file = ($this->_cacheDir.'cache_'.md5($group).'_' |
|
511 | + .md5($id)); |
|
512 | + } else { |
|
513 | + $this->_file = $this->_cacheDir.'cache_'.$group.'_'.$id; |
|
514 | + } |
|
515 | + } |
|
516 | + |
|
517 | + function getCacheFile() |
|
518 | + { |
|
519 | + return $this->_file; |
|
520 | + } |
|
521 | + |
|
522 | + /** |
|
523 | + * Read the cache file and return the content |
|
524 | + * |
|
525 | + * @return string content of the cache file |
|
526 | + * @access private |
|
527 | + */ |
|
528 | + function _read() |
|
529 | + { |
|
530 | + $fp = @fopen($this->_file, "rb"); |
|
531 | + if ($this->_fileLocking) @flock($fp, LOCK_SH); |
|
532 | + if ($fp) { |
|
533 | + // because the filesize can be cached by PHP itself... |
|
534 | + clearstatcache(); |
|
535 | + $length = @filesize($this->_file); |
|
536 | 536 | if(version_compare(PHP_VERSION, '5.3.0', 'lt')) |
537 | 537 | { |
538 | - $mqr = get_magic_quotes_runtime(); |
|
539 | - set_magic_quotes_runtime(0); |
|
538 | + $mqr = get_magic_quotes_runtime(); |
|
539 | + set_magic_quotes_runtime(0); |
|
540 | + } |
|
541 | + if ($this->_readControl) { |
|
542 | + $hashControl = @fread($fp, 32); |
|
543 | + $length = $length - 32; |
|
540 | 544 | } |
541 | - if ($this->_readControl) { |
|
542 | - $hashControl = @fread($fp, 32); |
|
543 | - $length = $length - 32; |
|
544 | - } |
|
545 | - $data = @fread($fp, $length); |
|
545 | + $data = @fread($fp, $length); |
|
546 | 546 | if(isset($mqr)) |
547 | - set_magic_quotes_runtime($mqr); |
|
548 | - if ($this->_fileLocking) @flock($fp, LOCK_UN); |
|
549 | - @fclose($fp); |
|
550 | - if ($this->_readControl) { |
|
551 | - $hashData = $this->_hash($data, $this->_readControlType); |
|
552 | - if ($hashData != $hashControl) { |
|
553 | - @touch($this->_file, time() - 2*abs($this->_lifeTime)); |
|
554 | - return false; |
|
555 | - } |
|
556 | - } |
|
557 | - return $data; |
|
558 | - } |
|
559 | - $this->raiseError('Cache_Lite : Unable to read cache !', -2); |
|
560 | - return false; |
|
561 | - } |
|
562 | - |
|
563 | - /** |
|
564 | - * Write the given data in the cache file |
|
565 | - * |
|
566 | - * @param string $data data to put in cache |
|
567 | - * @return boolean true if ok |
|
568 | - * @access private |
|
569 | - */ |
|
570 | - function _write($data) |
|
571 | - { |
|
572 | - $fp = @fopen($this->_file, "wb"); |
|
573 | - if ($fp) { |
|
574 | - if ($this->_fileLocking) @flock($fp, LOCK_EX); |
|
575 | - if ($this->_readControl) { |
|
576 | - @fwrite($fp, $this->_hash($data, $this->_readControlType), 32); |
|
577 | - } |
|
578 | - $len = strlen($data); |
|
579 | - @fwrite($fp, $data, $len); |
|
580 | - if ($this->_fileLocking) @flock($fp, LOCK_UN); |
|
581 | - @fclose($fp); |
|
582 | - return true; |
|
583 | - } |
|
584 | - $this->raiseError('Cache_Lite : Unable to write cache !', -1); |
|
585 | - return false; |
|
586 | - } |
|
587 | - |
|
588 | - /** |
|
589 | - * Write the given data in the cache file and control it just after to avoid |
|
590 | - * corrupted cache entries |
|
591 | - * |
|
592 | - * @param string $data data to put in cache |
|
593 | - * @return boolean true if the test is ok |
|
594 | - * @access private |
|
595 | - */ |
|
596 | - function _writeAndControl($data) |
|
597 | - { |
|
598 | - $this->_write($data); |
|
599 | - $dataRead = $this->_read($data); |
|
600 | - return ($dataRead==$data); |
|
601 | - } |
|
602 | - |
|
603 | - /** |
|
604 | - * Make a control key with the string containing datas |
|
605 | - * |
|
606 | - * @param string $data data |
|
607 | - * @param string $controlType type of control 'md5', 'crc32' or 'strlen' |
|
608 | - * @return string control key |
|
609 | - * @access private |
|
610 | - */ |
|
611 | - function _hash($data, $controlType) |
|
612 | - { |
|
613 | - switch ($controlType) { |
|
614 | - case 'md5': |
|
615 | - return md5($data); |
|
616 | - case 'crc32': |
|
617 | - return sprintf('% 32d', crc32($data)); |
|
618 | - case 'strlen': |
|
619 | - return sprintf('% 32d', strlen($data)); |
|
620 | - default: |
|
621 | - $this->raiseError('Unknown controlType ! '. |
|
622 | - '(available values are only \'md5\', \'crc32\', \'strlen\')', -5); |
|
623 | - } |
|
624 | - } |
|
547 | + set_magic_quotes_runtime($mqr); |
|
548 | + if ($this->_fileLocking) @flock($fp, LOCK_UN); |
|
549 | + @fclose($fp); |
|
550 | + if ($this->_readControl) { |
|
551 | + $hashData = $this->_hash($data, $this->_readControlType); |
|
552 | + if ($hashData != $hashControl) { |
|
553 | + @touch($this->_file, time() - 2*abs($this->_lifeTime)); |
|
554 | + return false; |
|
555 | + } |
|
556 | + } |
|
557 | + return $data; |
|
558 | + } |
|
559 | + $this->raiseError('Cache_Lite : Unable to read cache !', -2); |
|
560 | + return false; |
|
561 | + } |
|
562 | + |
|
563 | + /** |
|
564 | + * Write the given data in the cache file |
|
565 | + * |
|
566 | + * @param string $data data to put in cache |
|
567 | + * @return boolean true if ok |
|
568 | + * @access private |
|
569 | + */ |
|
570 | + function _write($data) |
|
571 | + { |
|
572 | + $fp = @fopen($this->_file, "wb"); |
|
573 | + if ($fp) { |
|
574 | + if ($this->_fileLocking) @flock($fp, LOCK_EX); |
|
575 | + if ($this->_readControl) { |
|
576 | + @fwrite($fp, $this->_hash($data, $this->_readControlType), 32); |
|
577 | + } |
|
578 | + $len = strlen($data); |
|
579 | + @fwrite($fp, $data, $len); |
|
580 | + if ($this->_fileLocking) @flock($fp, LOCK_UN); |
|
581 | + @fclose($fp); |
|
582 | + return true; |
|
583 | + } |
|
584 | + $this->raiseError('Cache_Lite : Unable to write cache !', -1); |
|
585 | + return false; |
|
586 | + } |
|
587 | + |
|
588 | + /** |
|
589 | + * Write the given data in the cache file and control it just after to avoid |
|
590 | + * corrupted cache entries |
|
591 | + * |
|
592 | + * @param string $data data to put in cache |
|
593 | + * @return boolean true if the test is ok |
|
594 | + * @access private |
|
595 | + */ |
|
596 | + function _writeAndControl($data) |
|
597 | + { |
|
598 | + $this->_write($data); |
|
599 | + $dataRead = $this->_read($data); |
|
600 | + return ($dataRead==$data); |
|
601 | + } |
|
602 | + |
|
603 | + /** |
|
604 | + * Make a control key with the string containing datas |
|
605 | + * |
|
606 | + * @param string $data data |
|
607 | + * @param string $controlType type of control 'md5', 'crc32' or 'strlen' |
|
608 | + * @return string control key |
|
609 | + * @access private |
|
610 | + */ |
|
611 | + function _hash($data, $controlType) |
|
612 | + { |
|
613 | + switch ($controlType) { |
|
614 | + case 'md5': |
|
615 | + return md5($data); |
|
616 | + case 'crc32': |
|
617 | + return sprintf('% 32d', crc32($data)); |
|
618 | + case 'strlen': |
|
619 | + return sprintf('% 32d', strlen($data)); |
|
620 | + default: |
|
621 | + $this->raiseError('Unknown controlType ! '. |
|
622 | + '(available values are only \'md5\', \'crc32\', \'strlen\')', -5); |
|
623 | + } |
|
624 | + } |
|
625 | 625 | |
626 | 626 | } |
627 | 627 |
@@ -611,15 +611,15 @@ |
||
611 | 611 | function _hash($data, $controlType) |
612 | 612 | { |
613 | 613 | switch ($controlType) { |
614 | - case 'md5': |
|
615 | - return md5($data); |
|
616 | - case 'crc32': |
|
617 | - return sprintf('% 32d', crc32($data)); |
|
618 | - case 'strlen': |
|
619 | - return sprintf('% 32d', strlen($data)); |
|
620 | - default: |
|
621 | - $this->raiseError('Unknown controlType ! '. |
|
622 | - '(available values are only \'md5\', \'crc32\', \'strlen\')', -5); |
|
614 | + case 'md5': |
|
615 | + return md5($data); |
|
616 | + case 'crc32': |
|
617 | + return sprintf('% 32d', crc32($data)); |
|
618 | + case 'strlen': |
|
619 | + return sprintf('% 32d', strlen($data)); |
|
620 | + default: |
|
621 | + $this->raiseError('Unknown controlType ! '. |
|
622 | + '(available values are only \'md5\', \'crc32\', \'strlen\')', -5); |
|
623 | 623 | } |
624 | 624 | } |
625 | 625 |
@@ -230,7 +230,7 @@ discard block |
||
230 | 230 | */ |
231 | 231 | function TCache_Lite($options = array(null)) |
232 | 232 | { |
233 | - $availableOptions = array( 'automaticSerialization', |
|
233 | + $availableOptions = array('automaticSerialization', |
|
234 | 234 | 'fileNameProtection', |
235 | 235 | 'memoryCaching', |
236 | 236 | 'onlyMemoryCaching', |
@@ -242,9 +242,9 @@ discard block |
||
242 | 242 | 'writeControl', |
243 | 243 | 'readControl', |
244 | 244 | 'readControlType'); |
245 | - foreach($options as $key => $value) { |
|
246 | - if(in_array($key, $availableOptions)) { |
|
247 | - $property = '_'.$key; |
|
245 | + foreach ($options as $key => $value) { |
|
246 | + if (in_array($key, $availableOptions)) { |
|
247 | + $property = '_' . $key; |
|
248 | 248 | $this->$property = $value; |
249 | 249 | } |
250 | 250 | } |
@@ -329,7 +329,7 @@ discard block |
||
329 | 329 | } |
330 | 330 | if ($this->_writeControl) { |
331 | 331 | if (!$this->_writeAndControl($data)) { |
332 | - @touch($this->_file, time() - 2*abs($this->_lifeTime)); |
|
332 | + @touch($this->_file, time() - 2 * abs($this->_lifeTime)); |
|
333 | 333 | return false; |
334 | 334 | } else { |
335 | 335 | return true; |
@@ -372,9 +372,9 @@ discard block |
||
372 | 372 | function clean($group = false) |
373 | 373 | { |
374 | 374 | if ($this->_fileNameProtection) { |
375 | - $motif = ($group) ? 'cache_'.md5($group).'_' : 'cache_'; |
|
375 | + $motif = ($group) ? 'cache_' . md5($group) . '_' : 'cache_'; |
|
376 | 376 | } else { |
377 | - $motif = ($group) ? 'cache_'.$group.'_' : 'cache_'; |
|
377 | + $motif = ($group) ? 'cache_' . $group . '_' : 'cache_'; |
|
378 | 378 | } |
379 | 379 | if ($this->_memoryCaching) { |
380 | 380 | while (list($key, $value) = each($this->_memoryCaching)) { |
@@ -507,10 +507,10 @@ discard block |
||
507 | 507 | function _setFileName($id, $group) |
508 | 508 | { |
509 | 509 | if ($this->_fileNameProtection) { |
510 | - $this->_file = ($this->_cacheDir.'cache_'.md5($group).'_' |
|
510 | + $this->_file = ($this->_cacheDir . 'cache_' . md5($group) . '_' |
|
511 | 511 | .md5($id)); |
512 | 512 | } else { |
513 | - $this->_file = $this->_cacheDir.'cache_'.$group.'_'.$id; |
|
513 | + $this->_file = $this->_cacheDir . 'cache_' . $group . '_' . $id; |
|
514 | 514 | } |
515 | 515 | } |
516 | 516 | |
@@ -533,7 +533,7 @@ discard block |
||
533 | 533 | // because the filesize can be cached by PHP itself... |
534 | 534 | clearstatcache(); |
535 | 535 | $length = @filesize($this->_file); |
536 | - if(version_compare(PHP_VERSION, '5.3.0', 'lt')) |
|
536 | + if (version_compare(PHP_VERSION, '5.3.0', 'lt')) |
|
537 | 537 | { |
538 | 538 | $mqr = get_magic_quotes_runtime(); |
539 | 539 | set_magic_quotes_runtime(0); |
@@ -543,14 +543,14 @@ discard block |
||
543 | 543 | $length = $length - 32; |
544 | 544 | } |
545 | 545 | $data = @fread($fp, $length); |
546 | - if(isset($mqr)) |
|
546 | + if (isset($mqr)) |
|
547 | 547 | set_magic_quotes_runtime($mqr); |
548 | 548 | if ($this->_fileLocking) @flock($fp, LOCK_UN); |
549 | 549 | @fclose($fp); |
550 | 550 | if ($this->_readControl) { |
551 | 551 | $hashData = $this->_hash($data, $this->_readControlType); |
552 | 552 | if ($hashData != $hashControl) { |
553 | - @touch($this->_file, time() - 2*abs($this->_lifeTime)); |
|
553 | + @touch($this->_file, time() - 2 * abs($this->_lifeTime)); |
|
554 | 554 | return false; |
555 | 555 | } |
556 | 556 | } |
@@ -597,7 +597,7 @@ discard block |
||
597 | 597 | { |
598 | 598 | $this->_write($data); |
599 | 599 | $dataRead = $this->_read($data); |
600 | - return ($dataRead==$data); |
|
600 | + return ($dataRead == $data); |
|
601 | 601 | } |
602 | 602 | |
603 | 603 | /** |
@@ -618,7 +618,7 @@ discard block |
||
618 | 618 | case 'strlen': |
619 | 619 | return sprintf('% 32d', strlen($data)); |
620 | 620 | default: |
621 | - $this->raiseError('Unknown controlType ! '. |
|
621 | + $this->raiseError('Unknown controlType ! ' . |
|
622 | 622 | '(available values are only \'md5\', \'crc32\', \'strlen\')', -5); |
623 | 623 | } |
624 | 624 | } |
@@ -528,7 +528,9 @@ discard block |
||
528 | 528 | function _read() |
529 | 529 | { |
530 | 530 | $fp = @fopen($this->_file, "rb"); |
531 | - if ($this->_fileLocking) @flock($fp, LOCK_SH); |
|
531 | + if ($this->_fileLocking) { |
|
532 | + @flock($fp, LOCK_SH); |
|
533 | + } |
|
532 | 534 | if ($fp) { |
533 | 535 | // because the filesize can be cached by PHP itself... |
534 | 536 | clearstatcache(); |
@@ -543,9 +545,12 @@ discard block |
||
543 | 545 | $length = $length - 32; |
544 | 546 | } |
545 | 547 | $data = @fread($fp, $length); |
546 | - if(isset($mqr)) |
|
547 | - set_magic_quotes_runtime($mqr); |
|
548 | - if ($this->_fileLocking) @flock($fp, LOCK_UN); |
|
548 | + if(isset($mqr)) { |
|
549 | + set_magic_quotes_runtime($mqr); |
|
550 | + } |
|
551 | + if ($this->_fileLocking) { |
|
552 | + @flock($fp, LOCK_UN); |
|
553 | + } |
|
549 | 554 | @fclose($fp); |
550 | 555 | if ($this->_readControl) { |
551 | 556 | $hashData = $this->_hash($data, $this->_readControlType); |
@@ -571,13 +576,17 @@ discard block |
||
571 | 576 | { |
572 | 577 | $fp = @fopen($this->_file, "wb"); |
573 | 578 | if ($fp) { |
574 | - if ($this->_fileLocking) @flock($fp, LOCK_EX); |
|
579 | + if ($this->_fileLocking) { |
|
580 | + @flock($fp, LOCK_EX); |
|
581 | + } |
|
575 | 582 | if ($this->_readControl) { |
576 | 583 | @fwrite($fp, $this->_hash($data, $this->_readControlType), 32); |
577 | 584 | } |
578 | 585 | $len = strlen($data); |
579 | 586 | @fwrite($fp, $data, $len); |
580 | - if ($this->_fileLocking) @flock($fp, LOCK_UN); |
|
587 | + if ($this->_fileLocking) { |
|
588 | + @flock($fp, LOCK_UN); |
|
589 | + } |
|
581 | 590 | @fclose($fp); |
582 | 591 | return true; |
583 | 592 | } |