@@ -101,6 +101,7 @@ |
||
101 | 101 | |
102 | 102 | /** |
103 | 103 | * @param boolean whether this transaction is active |
104 | + * @param boolean $value |
|
104 | 105 | */ |
105 | 106 | protected function setActive($value) |
106 | 107 | { |
@@ -63,8 +63,7 @@ discard block |
||
63 | 63 | { |
64 | 64 | $this->_connection->getPdoInstance()->commit(); |
65 | 65 | $this->_active=false; |
66 | - } |
|
67 | - else |
|
66 | + } else |
|
68 | 67 | throw new TDbException('dbtransaction_transaction_inactive'); |
69 | 68 | } |
70 | 69 | |
@@ -78,8 +77,7 @@ discard block |
||
78 | 77 | { |
79 | 78 | $this->_connection->getPdoInstance()->rollBack(); |
80 | 79 | $this->_active=false; |
81 | - } |
|
82 | - else |
|
80 | + } else |
|
83 | 81 | throw new TDbException('dbtransaction_transaction_inactive'); |
84 | 82 | } |
85 | 83 |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | * |
119 | 119 | * @static |
120 | 120 | * @access public |
121 | - * @return mixed Returns true on success or PEAR_Error on failure. |
|
121 | + * @return boolean Returns true on success or PEAR_Error on failure. |
|
122 | 122 | * @param string $pofile path to GNU PO file |
123 | 123 | * @param string $mofile path to GNU MO file |
124 | 124 | */ |
@@ -260,7 +260,7 @@ discard block |
||
260 | 260 | * toMO |
261 | 261 | * |
262 | 262 | * @access protected |
263 | - * @return object File_Gettext_MO |
|
263 | + * @return TGettext_MO File_Gettext_MO |
|
264 | 264 | */ |
265 | 265 | function toMO() |
266 | 266 | { |
@@ -274,7 +274,7 @@ discard block |
||
274 | 274 | * toPO |
275 | 275 | * |
276 | 276 | * @access protected |
277 | - * @return object File_Gettext_PO |
|
277 | + * @return TGettext_PO File_Gettext_PO |
|
278 | 278 | */ |
279 | 279 | function toPO() |
280 | 280 | { |
@@ -58,229 +58,229 @@ |
||
58 | 58 | */ |
59 | 59 | class TGettext |
60 | 60 | { |
61 | - /** |
|
62 | - * strings |
|
63 | - * |
|
64 | - * associative array with all [msgid => msgstr] entries |
|
65 | - * |
|
66 | - * @access protected |
|
67 | - * @var array |
|
68 | - */ |
|
69 | - protected $strings = array(); |
|
61 | + /** |
|
62 | + * strings |
|
63 | + * |
|
64 | + * associative array with all [msgid => msgstr] entries |
|
65 | + * |
|
66 | + * @access protected |
|
67 | + * @var array |
|
68 | + */ |
|
69 | + protected $strings = array(); |
|
70 | 70 | |
71 | - /** |
|
72 | - * meta |
|
73 | - * |
|
74 | - * associative array containing meta |
|
75 | - * information like project name or content type |
|
76 | - * |
|
77 | - * @access protected |
|
78 | - * @var array |
|
79 | - */ |
|
80 | - protected $meta = array(); |
|
71 | + /** |
|
72 | + * meta |
|
73 | + * |
|
74 | + * associative array containing meta |
|
75 | + * information like project name or content type |
|
76 | + * |
|
77 | + * @access protected |
|
78 | + * @var array |
|
79 | + */ |
|
80 | + protected $meta = array(); |
|
81 | 81 | |
82 | - /** |
|
83 | - * file path |
|
84 | - * |
|
85 | - * @access protected |
|
86 | - * @var string |
|
87 | - */ |
|
88 | - protected $file = ''; |
|
82 | + /** |
|
83 | + * file path |
|
84 | + * |
|
85 | + * @access protected |
|
86 | + * @var string |
|
87 | + */ |
|
88 | + protected $file = ''; |
|
89 | 89 | |
90 | - /** |
|
91 | - * Factory |
|
92 | - * |
|
93 | - * @static |
|
94 | - * @access public |
|
95 | - * @return object Returns File_Gettext_PO or File_Gettext_MO on success |
|
96 | - * or PEAR_Error on failure. |
|
97 | - * @param string $format MO or PO |
|
98 | - * @param string $file path to GNU gettext file |
|
99 | - */ |
|
100 | - static function factory($format, $file = '') |
|
101 | - { |
|
102 | - $format = strToUpper($format); |
|
103 | - $filename = dirname(__FILE__).'/'.$format.'.php'; |
|
104 | - if(is_file($filename) == false) |
|
105 | - throw new Exception ("Class file $file not found"); |
|
90 | + /** |
|
91 | + * Factory |
|
92 | + * |
|
93 | + * @static |
|
94 | + * @access public |
|
95 | + * @return object Returns File_Gettext_PO or File_Gettext_MO on success |
|
96 | + * or PEAR_Error on failure. |
|
97 | + * @param string $format MO or PO |
|
98 | + * @param string $file path to GNU gettext file |
|
99 | + */ |
|
100 | + static function factory($format, $file = '') |
|
101 | + { |
|
102 | + $format = strToUpper($format); |
|
103 | + $filename = dirname(__FILE__).'/'.$format.'.php'; |
|
104 | + if(is_file($filename) == false) |
|
105 | + throw new Exception ("Class file $file not found"); |
|
106 | 106 | |
107 | - include_once $filename; |
|
108 | - $class = 'TGettext_' . $format; |
|
107 | + include_once $filename; |
|
108 | + $class = 'TGettext_' . $format; |
|
109 | 109 | |
110 | - return new $class($file); |
|
111 | - } |
|
110 | + return new $class($file); |
|
111 | + } |
|
112 | 112 | |
113 | - /** |
|
114 | - * poFile2moFile |
|
115 | - * |
|
116 | - * That's a simple fake of the 'msgfmt' console command. It reads the |
|
117 | - * contents of a GNU PO file and saves them to a GNU MO file. |
|
118 | - * |
|
119 | - * @static |
|
120 | - * @access public |
|
121 | - * @return mixed Returns true on success or PEAR_Error on failure. |
|
122 | - * @param string $pofile path to GNU PO file |
|
123 | - * @param string $mofile path to GNU MO file |
|
124 | - */ |
|
125 | - static function poFile2moFile($pofile, $mofile) |
|
126 | - { |
|
127 | - if (!is_file($pofile)) { |
|
128 | - throw new Exception("File $pofile doesn't exist."); |
|
129 | - } |
|
113 | + /** |
|
114 | + * poFile2moFile |
|
115 | + * |
|
116 | + * That's a simple fake of the 'msgfmt' console command. It reads the |
|
117 | + * contents of a GNU PO file and saves them to a GNU MO file. |
|
118 | + * |
|
119 | + * @static |
|
120 | + * @access public |
|
121 | + * @return mixed Returns true on success or PEAR_Error on failure. |
|
122 | + * @param string $pofile path to GNU PO file |
|
123 | + * @param string $mofile path to GNU MO file |
|
124 | + */ |
|
125 | + static function poFile2moFile($pofile, $mofile) |
|
126 | + { |
|
127 | + if (!is_file($pofile)) { |
|
128 | + throw new Exception("File $pofile doesn't exist."); |
|
129 | + } |
|
130 | 130 | |
131 | - include_once dirname(__FILE__).'/PO.php'; |
|
131 | + include_once dirname(__FILE__).'/PO.php'; |
|
132 | 132 | |
133 | - $PO = new TGettext_PO($pofile); |
|
134 | - if (true !== ($e = $PO->load())) { |
|
135 | - return $e; |
|
136 | - } |
|
133 | + $PO = new TGettext_PO($pofile); |
|
134 | + if (true !== ($e = $PO->load())) { |
|
135 | + return $e; |
|
136 | + } |
|
137 | 137 | |
138 | - $MO = $PO->toMO(); |
|
139 | - if (true !== ($e = $MO->save($mofile))) { |
|
140 | - return $e; |
|
141 | - } |
|
142 | - unset($PO, $MO); |
|
138 | + $MO = $PO->toMO(); |
|
139 | + if (true !== ($e = $MO->save($mofile))) { |
|
140 | + return $e; |
|
141 | + } |
|
142 | + unset($PO, $MO); |
|
143 | 143 | |
144 | - return true; |
|
145 | - } |
|
144 | + return true; |
|
145 | + } |
|
146 | 146 | |
147 | - /** |
|
148 | - * prepare |
|
149 | - * |
|
150 | - * @static |
|
151 | - * @access protected |
|
152 | - * @return string |
|
153 | - * @param string $string |
|
154 | - * @param bool $reverse |
|
155 | - */ |
|
156 | - static function prepare($string, $reverse = false) |
|
157 | - { |
|
158 | - if ($reverse) { |
|
159 | - $smap = array('"', "\n", "\t", "\r"); |
|
160 | - $rmap = array('\"', '\\n"' . "\n" . '"', '\\t', '\\r'); |
|
161 | - return (string) str_replace($smap, $rmap, $string); |
|
162 | - } else { |
|
163 | - $string = preg_replace('/"\s+"/', '', $string); |
|
164 | - $smap = array('\\n', '\\r', '\\t', '\"'); |
|
165 | - $rmap = array("\n", "\r", "\t", '"'); |
|
166 | - return (string) str_replace($smap, $rmap, $string); |
|
167 | - } |
|
168 | - } |
|
147 | + /** |
|
148 | + * prepare |
|
149 | + * |
|
150 | + * @static |
|
151 | + * @access protected |
|
152 | + * @return string |
|
153 | + * @param string $string |
|
154 | + * @param bool $reverse |
|
155 | + */ |
|
156 | + static function prepare($string, $reverse = false) |
|
157 | + { |
|
158 | + if ($reverse) { |
|
159 | + $smap = array('"', "\n", "\t", "\r"); |
|
160 | + $rmap = array('\"', '\\n"' . "\n" . '"', '\\t', '\\r'); |
|
161 | + return (string) str_replace($smap, $rmap, $string); |
|
162 | + } else { |
|
163 | + $string = preg_replace('/"\s+"/', '', $string); |
|
164 | + $smap = array('\\n', '\\r', '\\t', '\"'); |
|
165 | + $rmap = array("\n", "\r", "\t", '"'); |
|
166 | + return (string) str_replace($smap, $rmap, $string); |
|
167 | + } |
|
168 | + } |
|
169 | 169 | |
170 | - /** |
|
171 | - * meta2array |
|
172 | - * |
|
173 | - * @static |
|
174 | - * @access public |
|
175 | - * @return array |
|
176 | - * @param string $meta |
|
177 | - */ |
|
178 | - static function meta2array($meta) |
|
179 | - { |
|
180 | - $array = array(); |
|
181 | - foreach (explode("\n", $meta) as $info) { |
|
182 | - if ($info = trim($info)) { |
|
183 | - list($key, $value) = explode(':', $info, 2); |
|
184 | - $array[trim($key)] = trim($value); |
|
185 | - } |
|
186 | - } |
|
187 | - return $array; |
|
188 | - } |
|
170 | + /** |
|
171 | + * meta2array |
|
172 | + * |
|
173 | + * @static |
|
174 | + * @access public |
|
175 | + * @return array |
|
176 | + * @param string $meta |
|
177 | + */ |
|
178 | + static function meta2array($meta) |
|
179 | + { |
|
180 | + $array = array(); |
|
181 | + foreach (explode("\n", $meta) as $info) { |
|
182 | + if ($info = trim($info)) { |
|
183 | + list($key, $value) = explode(':', $info, 2); |
|
184 | + $array[trim($key)] = trim($value); |
|
185 | + } |
|
186 | + } |
|
187 | + return $array; |
|
188 | + } |
|
189 | 189 | |
190 | - /** |
|
191 | - * toArray |
|
192 | - * |
|
193 | - * Returns meta info and strings as an array of a structure like that: |
|
194 | - * <code> |
|
195 | - * array( |
|
196 | - * 'meta' => array( |
|
197 | - * 'Content-Type' => 'text/plain; charset=iso-8859-1', |
|
198 | - * 'Last-Translator' => 'Michael Wallner <[email protected]>', |
|
199 | - * 'PO-Revision-Date' => '2004-07-21 17:03+0200', |
|
200 | - * 'Language-Team' => 'German <[email protected]>', |
|
201 | - * ), |
|
202 | - * 'strings' => array( |
|
203 | - * 'All rights reserved' => 'Alle Rechte vorbehalten', |
|
204 | - * 'Welcome' => 'Willkommen', |
|
205 | - * // ... |
|
206 | - * ) |
|
207 | - * ) |
|
208 | - * </code> |
|
209 | - * |
|
210 | - * @see fromArray() |
|
211 | - * @access protected |
|
212 | - * @return array |
|
213 | - */ |
|
214 | - function toArray() |
|
215 | - { |
|
216 | - return array('meta' => $this->meta, 'strings' => $this->strings); |
|
217 | - } |
|
190 | + /** |
|
191 | + * toArray |
|
192 | + * |
|
193 | + * Returns meta info and strings as an array of a structure like that: |
|
194 | + * <code> |
|
195 | + * array( |
|
196 | + * 'meta' => array( |
|
197 | + * 'Content-Type' => 'text/plain; charset=iso-8859-1', |
|
198 | + * 'Last-Translator' => 'Michael Wallner <[email protected]>', |
|
199 | + * 'PO-Revision-Date' => '2004-07-21 17:03+0200', |
|
200 | + * 'Language-Team' => 'German <[email protected]>', |
|
201 | + * ), |
|
202 | + * 'strings' => array( |
|
203 | + * 'All rights reserved' => 'Alle Rechte vorbehalten', |
|
204 | + * 'Welcome' => 'Willkommen', |
|
205 | + * // ... |
|
206 | + * ) |
|
207 | + * ) |
|
208 | + * </code> |
|
209 | + * |
|
210 | + * @see fromArray() |
|
211 | + * @access protected |
|
212 | + * @return array |
|
213 | + */ |
|
214 | + function toArray() |
|
215 | + { |
|
216 | + return array('meta' => $this->meta, 'strings' => $this->strings); |
|
217 | + } |
|
218 | 218 | |
219 | - /** |
|
220 | - * fromArray |
|
221 | - * |
|
222 | - * Assigns meta info and strings from an array of a structure like that: |
|
223 | - * <code> |
|
224 | - * array( |
|
225 | - * 'meta' => array( |
|
226 | - * 'Content-Type' => 'text/plain; charset=iso-8859-1', |
|
227 | - * 'Last-Translator' => 'Michael Wallner <[email protected]>', |
|
228 | - * 'PO-Revision-Date' => date('Y-m-d H:iO'), |
|
229 | - * 'Language-Team' => 'German <[email protected]>', |
|
230 | - * ), |
|
231 | - * 'strings' => array( |
|
232 | - * 'All rights reserved' => 'Alle Rechte vorbehalten', |
|
233 | - * 'Welcome' => 'Willkommen', |
|
234 | - * // ... |
|
235 | - * ) |
|
236 | - * ) |
|
237 | - * </code> |
|
238 | - * |
|
239 | - * @see toArray() |
|
240 | - * @access protected |
|
241 | - * @return bool |
|
242 | - * @param array $array |
|
243 | - */ |
|
244 | - function fromArray($array) |
|
245 | - { |
|
246 | - if (!array_key_exists('strings', $array)) { |
|
247 | - if (count($array) != 2) { |
|
248 | - return false; |
|
249 | - } else { |
|
250 | - list($this->meta, $this->strings) = $array; |
|
251 | - } |
|
252 | - } else { |
|
253 | - $this->meta = @$array['meta']; |
|
254 | - $this->strings = @$array['strings']; |
|
255 | - } |
|
256 | - return true; |
|
257 | - } |
|
219 | + /** |
|
220 | + * fromArray |
|
221 | + * |
|
222 | + * Assigns meta info and strings from an array of a structure like that: |
|
223 | + * <code> |
|
224 | + * array( |
|
225 | + * 'meta' => array( |
|
226 | + * 'Content-Type' => 'text/plain; charset=iso-8859-1', |
|
227 | + * 'Last-Translator' => 'Michael Wallner <[email protected]>', |
|
228 | + * 'PO-Revision-Date' => date('Y-m-d H:iO'), |
|
229 | + * 'Language-Team' => 'German <[email protected]>', |
|
230 | + * ), |
|
231 | + * 'strings' => array( |
|
232 | + * 'All rights reserved' => 'Alle Rechte vorbehalten', |
|
233 | + * 'Welcome' => 'Willkommen', |
|
234 | + * // ... |
|
235 | + * ) |
|
236 | + * ) |
|
237 | + * </code> |
|
238 | + * |
|
239 | + * @see toArray() |
|
240 | + * @access protected |
|
241 | + * @return bool |
|
242 | + * @param array $array |
|
243 | + */ |
|
244 | + function fromArray($array) |
|
245 | + { |
|
246 | + if (!array_key_exists('strings', $array)) { |
|
247 | + if (count($array) != 2) { |
|
248 | + return false; |
|
249 | + } else { |
|
250 | + list($this->meta, $this->strings) = $array; |
|
251 | + } |
|
252 | + } else { |
|
253 | + $this->meta = @$array['meta']; |
|
254 | + $this->strings = @$array['strings']; |
|
255 | + } |
|
256 | + return true; |
|
257 | + } |
|
258 | 258 | |
259 | - /** |
|
260 | - * toMO |
|
261 | - * |
|
262 | - * @access protected |
|
263 | - * @return object File_Gettext_MO |
|
264 | - */ |
|
265 | - function toMO() |
|
266 | - { |
|
267 | - include_once dirname(__FILE__).'/MO.php'; |
|
268 | - $MO = new TGettext_MO; |
|
269 | - $MO->fromArray($this->toArray()); |
|
270 | - return $MO; |
|
271 | - } |
|
259 | + /** |
|
260 | + * toMO |
|
261 | + * |
|
262 | + * @access protected |
|
263 | + * @return object File_Gettext_MO |
|
264 | + */ |
|
265 | + function toMO() |
|
266 | + { |
|
267 | + include_once dirname(__FILE__).'/MO.php'; |
|
268 | + $MO = new TGettext_MO; |
|
269 | + $MO->fromArray($this->toArray()); |
|
270 | + return $MO; |
|
271 | + } |
|
272 | 272 | |
273 | - /** |
|
274 | - * toPO |
|
275 | - * |
|
276 | - * @access protected |
|
277 | - * @return object File_Gettext_PO |
|
278 | - */ |
|
279 | - function toPO() |
|
280 | - { |
|
281 | - include_once dirname(__FILE__).'/PO.php'; |
|
282 | - $PO = new TGettext_PO; |
|
283 | - $PO->fromArray($this->toArray()); |
|
284 | - return $PO; |
|
285 | - } |
|
273 | + /** |
|
274 | + * toPO |
|
275 | + * |
|
276 | + * @access protected |
|
277 | + * @return object File_Gettext_PO |
|
278 | + */ |
|
279 | + function toPO() |
|
280 | + { |
|
281 | + include_once dirname(__FILE__).'/PO.php'; |
|
282 | + $PO = new TGettext_PO; |
|
283 | + $PO->fromArray($this->toArray()); |
|
284 | + return $PO; |
|
285 | + } |
|
286 | 286 | } |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | * @access protected |
67 | 67 | * @var array |
68 | 68 | */ |
69 | - protected $strings = array(); |
|
69 | + protected $strings=array(); |
|
70 | 70 | |
71 | 71 | /** |
72 | 72 | * meta |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | * @access protected |
78 | 78 | * @var array |
79 | 79 | */ |
80 | - protected $meta = array(); |
|
80 | + protected $meta=array(); |
|
81 | 81 | |
82 | 82 | /** |
83 | 83 | * file path |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | * @access protected |
86 | 86 | * @var string |
87 | 87 | */ |
88 | - protected $file = ''; |
|
88 | + protected $file=''; |
|
89 | 89 | |
90 | 90 | /** |
91 | 91 | * Factory |
@@ -97,15 +97,15 @@ discard block |
||
97 | 97 | * @param string $format MO or PO |
98 | 98 | * @param string $file path to GNU gettext file |
99 | 99 | */ |
100 | - static function factory($format, $file = '') |
|
100 | + static function factory($format, $file='') |
|
101 | 101 | { |
102 | - $format = strToUpper($format); |
|
103 | - $filename = dirname(__FILE__).'/'.$format.'.php'; |
|
104 | - if(is_file($filename) == false) |
|
105 | - throw new Exception ("Class file $file not found"); |
|
102 | + $format=strToUpper($format); |
|
103 | + $filename=dirname(__FILE__).'/'.$format.'.php'; |
|
104 | + if(is_file($filename)==false) |
|
105 | + throw new Exception("Class file $file not found"); |
|
106 | 106 | |
107 | 107 | include_once $filename; |
108 | - $class = 'TGettext_' . $format; |
|
108 | + $class='TGettext_'.$format; |
|
109 | 109 | |
110 | 110 | return new $class($file); |
111 | 111 | } |
@@ -124,19 +124,19 @@ discard block |
||
124 | 124 | */ |
125 | 125 | static function poFile2moFile($pofile, $mofile) |
126 | 126 | { |
127 | - if (!is_file($pofile)) { |
|
127 | + if(!is_file($pofile)) { |
|
128 | 128 | throw new Exception("File $pofile doesn't exist."); |
129 | 129 | } |
130 | 130 | |
131 | 131 | include_once dirname(__FILE__).'/PO.php'; |
132 | 132 | |
133 | - $PO = new TGettext_PO($pofile); |
|
134 | - if (true !== ($e = $PO->load())) { |
|
133 | + $PO=new TGettext_PO($pofile); |
|
134 | + if(true!==($e=$PO->load())) { |
|
135 | 135 | return $e; |
136 | 136 | } |
137 | 137 | |
138 | - $MO = $PO->toMO(); |
|
139 | - if (true !== ($e = $MO->save($mofile))) { |
|
138 | + $MO=$PO->toMO(); |
|
139 | + if(true!==($e=$MO->save($mofile))) { |
|
140 | 140 | return $e; |
141 | 141 | } |
142 | 142 | unset($PO, $MO); |
@@ -153,16 +153,16 @@ discard block |
||
153 | 153 | * @param string $string |
154 | 154 | * @param bool $reverse |
155 | 155 | */ |
156 | - static function prepare($string, $reverse = false) |
|
156 | + static function prepare($string, $reverse=false) |
|
157 | 157 | { |
158 | - if ($reverse) { |
|
159 | - $smap = array('"', "\n", "\t", "\r"); |
|
160 | - $rmap = array('\"', '\\n"' . "\n" . '"', '\\t', '\\r'); |
|
158 | + if($reverse) { |
|
159 | + $smap=array('"', "\n", "\t", "\r"); |
|
160 | + $rmap=array('\"', '\\n"'."\n".'"', '\\t', '\\r'); |
|
161 | 161 | return (string) str_replace($smap, $rmap, $string); |
162 | 162 | } else { |
163 | - $string = preg_replace('/"\s+"/', '', $string); |
|
164 | - $smap = array('\\n', '\\r', '\\t', '\"'); |
|
165 | - $rmap = array("\n", "\r", "\t", '"'); |
|
163 | + $string=preg_replace('/"\s+"/', '', $string); |
|
164 | + $smap=array('\\n', '\\r', '\\t', '\"'); |
|
165 | + $rmap=array("\n", "\r", "\t", '"'); |
|
166 | 166 | return (string) str_replace($smap, $rmap, $string); |
167 | 167 | } |
168 | 168 | } |
@@ -177,11 +177,11 @@ discard block |
||
177 | 177 | */ |
178 | 178 | static function meta2array($meta) |
179 | 179 | { |
180 | - $array = array(); |
|
181 | - foreach (explode("\n", $meta) as $info) { |
|
182 | - if ($info = trim($info)) { |
|
183 | - list($key, $value) = explode(':', $info, 2); |
|
184 | - $array[trim($key)] = trim($value); |
|
180 | + $array=array(); |
|
181 | + foreach(explode("\n", $meta) as $info) { |
|
182 | + if($info=trim($info)) { |
|
183 | + list($key, $value)=explode(':', $info, 2); |
|
184 | + $array[trim($key)]=trim($value); |
|
185 | 185 | } |
186 | 186 | } |
187 | 187 | return $array; |
@@ -243,15 +243,15 @@ discard block |
||
243 | 243 | */ |
244 | 244 | function fromArray($array) |
245 | 245 | { |
246 | - if (!array_key_exists('strings', $array)) { |
|
247 | - if (count($array) != 2) { |
|
246 | + if(!array_key_exists('strings', $array)) { |
|
247 | + if(count($array)!=2) { |
|
248 | 248 | return false; |
249 | 249 | } else { |
250 | - list($this->meta, $this->strings) = $array; |
|
250 | + list($this->meta, $this->strings)=$array; |
|
251 | 251 | } |
252 | 252 | } else { |
253 | - $this->meta = @$array['meta']; |
|
254 | - $this->strings = @$array['strings']; |
|
253 | + $this->meta=@$array['meta']; |
|
254 | + $this->strings=@$array['strings']; |
|
255 | 255 | } |
256 | 256 | return true; |
257 | 257 | } |
@@ -265,7 +265,7 @@ discard block |
||
265 | 265 | function toMO() |
266 | 266 | { |
267 | 267 | include_once dirname(__FILE__).'/MO.php'; |
268 | - $MO = new TGettext_MO; |
|
268 | + $MO=new TGettext_MO; |
|
269 | 269 | $MO->fromArray($this->toArray()); |
270 | 270 | return $MO; |
271 | 271 | } |
@@ -279,7 +279,7 @@ discard block |
||
279 | 279 | function toPO() |
280 | 280 | { |
281 | 281 | include_once dirname(__FILE__).'/PO.php'; |
282 | - $PO = new TGettext_PO; |
|
282 | + $PO=new TGettext_PO; |
|
283 | 283 | $PO->fromArray($this->toArray()); |
284 | 284 | return $PO; |
285 | 285 | } |
@@ -109,6 +109,7 @@ |
||
109 | 109 | /** |
110 | 110 | * Set the culture for this particular message source. |
111 | 111 | * @param string the Culture name. |
112 | + * @return void |
|
112 | 113 | */ |
113 | 114 | function setCulture($culture); |
114 | 115 |
@@ -47,7 +47,7 @@ |
||
47 | 47 | * @param string a catalogue to load |
48 | 48 | * @return boolean true if loaded, false otherwise. |
49 | 49 | */ |
50 | - function load($catalogue = 'messages'); |
|
50 | + function load($catalogue='messages'); |
|
51 | 51 | |
52 | 52 | /** |
53 | 53 | * Get the translation table. This includes all the loaded sections. |
@@ -99,9 +99,7 @@ |
||
99 | 99 | * Get the data from the cache. |
100 | 100 | * @param string $catalogue The translation section. |
101 | 101 | * @param string $culture The translation locale, e.g. "en_AU". |
102 | - * @param string $filename If the source is a file, this file's modified |
|
103 | - * time is newer than the cache's modified time, no cache hit. |
|
104 | - * @return mixed Boolean FALSE if no cache hit. Otherwise, translation |
|
102 | + * @return false|string Boolean FALSE if no cache hit. Otherwise, translation |
|
105 | 103 | * table data for the specified section and locale. |
106 | 104 | */ |
107 | 105 | public function get($catalogue, $culture, $lastmodified=0) |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | /** |
29 | 29 | * Caceh life time, default is 1 year. |
30 | 30 | */ |
31 | - protected $lifetime = 3153600; |
|
31 | + protected $lifetime=3153600; |
|
32 | 32 | |
33 | 33 | |
34 | 34 | /** |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | */ |
38 | 38 | public function __construct($cacheDir) |
39 | 39 | { |
40 | - $cacheDir = $cacheDir.'/'; |
|
40 | + $cacheDir=$cacheDir.'/'; |
|
41 | 41 | |
42 | 42 | if(!is_dir($cacheDir)) |
43 | 43 | throw new Exception( |
@@ -48,13 +48,13 @@ discard block |
||
48 | 48 | 'The cache directory '.$cacheDir.' must be writable '. |
49 | 49 | 'by the server.'); |
50 | 50 | |
51 | - $options = array( |
|
51 | + $options=array( |
|
52 | 52 | 'cacheDir' => $cacheDir, |
53 | 53 | 'lifeTime' => $this->getLifeTime(), |
54 | 54 | 'automaticSerialization' => true |
55 | 55 | ); |
56 | 56 | |
57 | - $this->cache = new TCache_Lite($options); |
|
57 | + $this->cache=new TCache_Lite($options); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | /** |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | */ |
73 | 73 | public function setLifeTime($time) |
74 | 74 | { |
75 | - $this->lifetime = (int)$time; |
|
75 | + $this->lifetime=(int) $time; |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | /** |
@@ -106,18 +106,18 @@ discard block |
||
106 | 106 | */ |
107 | 107 | public function get($catalogue, $culture, $lastmodified=0) |
108 | 108 | { |
109 | - $ID = $this->getID($catalogue, $culture); |
|
110 | - $group = $this->getGroup($catalogue, $culture); |
|
109 | + $ID=$this->getID($catalogue, $culture); |
|
110 | + $group=$this->getGroup($catalogue, $culture); |
|
111 | 111 | |
112 | 112 | $this->cache->_setFileName($ID, $group); |
113 | 113 | |
114 | - $cache = $this->cache->getCacheFile(); |
|
114 | + $cache=$this->cache->getCacheFile(); |
|
115 | 115 | |
116 | - if(is_file($cache) == false) |
|
116 | + if(is_file($cache)==false) |
|
117 | 117 | return false; |
118 | 118 | |
119 | 119 | |
120 | - $lastmodified = (int)$lastmodified; |
|
120 | + $lastmodified=(int) $lastmodified; |
|
121 | 121 | |
122 | 122 | if($lastmodified <= 0 || $lastmodified > filemtime($cache)) |
123 | 123 | return false; |
@@ -136,8 +136,8 @@ discard block |
||
136 | 136 | */ |
137 | 137 | public function save($data, $catalogue, $culture) |
138 | 138 | { |
139 | - $ID = $this->getID($catalogue, $culture); |
|
140 | - $group = $this->getGroup($catalogue, $culture); |
|
139 | + $ID=$this->getID($catalogue, $culture); |
|
140 | + $group=$this->getGroup($catalogue, $culture); |
|
141 | 141 | |
142 | 142 | //echo '## Cache save: "'.$ID.'" : "'.$group.'"'; |
143 | 143 | //echo "<br>\n"; |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | */ |
153 | 153 | public function clean($catalogue, $culture) |
154 | 154 | { |
155 | - $group = $this->getGroup($catalogue, $culture); |
|
155 | + $group=$this->getGroup($catalogue, $culture); |
|
156 | 156 | $this->cache->clean($group); |
157 | 157 | } |
158 | 158 |
@@ -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) |
@@ -111,15 +111,15 @@ |
||
111 | 111 | /** |
112 | 112 | * Factory method to instantiate a new MessageSource depending on the |
113 | 113 | * source type. The allowed source types are 'XLIFF', 'PHP', 'gettext' and |
114 | - * 'Database'. The source parameter depends on the source type. |
|
115 | - * For 'gettext', 'PHP' and 'XLIFF', 'source' should point to the directory |
|
116 | - * where the messages are stored. |
|
117 | - * For 'Database', 'source' must be a valid connection id. |
|
118 | - * If a deprecated 'SQLite' type is used, 'source' must contain |
|
119 | - * a valid DSN. |
|
114 | + * 'Database'. The source parameter depends on the source type. |
|
115 | + * For 'gettext', 'PHP' and 'XLIFF', 'source' should point to the directory |
|
116 | + * where the messages are stored. |
|
117 | + * For 'Database', 'source' must be a valid connection id. |
|
118 | + * If a deprecated 'SQLite' type is used, 'source' must contain |
|
119 | + * a valid DSN. |
|
120 | 120 | * |
121 | - * Custom message source are possible by supplying the a filename parameter |
|
122 | - * in the factory method. |
|
121 | + * Custom message source are possible by supplying the a filename parameter |
|
122 | + * in the factory method. |
|
123 | 123 | * |
124 | 124 | * @param string the message source type. |
125 | 125 | * @param string the location of the resource or the ConnectionID. |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | * Array of translation messages. |
84 | 84 | * @var array |
85 | 85 | */ |
86 | - protected $messages = array(); |
|
86 | + protected $messages=array(); |
|
87 | 87 | |
88 | 88 | /** |
89 | 89 | * The source of message translations. |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | */ |
98 | 98 | protected $cache; |
99 | 99 | |
100 | - protected $untranslated = array(); |
|
100 | + protected $untranslated=array(); |
|
101 | 101 | |
102 | 102 | /** |
103 | 103 | * Private constructor. MessageSource must be initialized using |
@@ -129,23 +129,23 @@ discard block |
||
129 | 129 | */ |
130 | 130 | static function &factory($type, $source='.', $filename='') |
131 | 131 | { |
132 | - $types = array('XLIFF','PHP','gettext','Database','SQLite'); |
|
132 | + $types=array('XLIFF', 'PHP', 'gettext', 'Database', 'SQLite'); |
|
133 | 133 | |
134 | 134 | if(empty($filename) && !in_array($type, $types)) |
135 | 135 | throw new Exception('Invalid type "'.$type.'", valid types are '. |
136 | 136 | implode(', ', $types)); |
137 | 137 | |
138 | - $class = 'MessageSource_'.$type; |
|
138 | + $class='MessageSource_'.$type; |
|
139 | 139 | |
140 | 140 | if(empty($filename)) |
141 | - $filename = dirname(__FILE__).'/'.$class.'.php'; |
|
141 | + $filename=dirname(__FILE__).'/'.$class.'.php'; |
|
142 | 142 | |
143 | - if(is_file($filename) == false) |
|
143 | + if(is_file($filename)==false) |
|
144 | 144 | throw new Exception("File $filename not found"); |
145 | 145 | |
146 | 146 | include_once $filename; |
147 | 147 | |
148 | - $obj = new $class($source); |
|
148 | + $obj=new $class($source); |
|
149 | 149 | |
150 | 150 | return $obj; |
151 | 151 | } |
@@ -171,36 +171,36 @@ discard block |
||
171 | 171 | */ |
172 | 172 | function load($catalogue='messages') |
173 | 173 | { |
174 | - $variants = $this->getCatalogueList($catalogue); |
|
174 | + $variants=$this->getCatalogueList($catalogue); |
|
175 | 175 | |
176 | - $this->messages = array(); |
|
176 | + $this->messages=array(); |
|
177 | 177 | |
178 | 178 | foreach($variants as $variant) |
179 | 179 | { |
180 | - $source = $this->getSource($variant); |
|
180 | + $source=$this->getSource($variant); |
|
181 | 181 | |
182 | - if($this->isValidSource($source) == false) continue; |
|
182 | + if($this->isValidSource($source)==false) continue; |
|
183 | 183 | |
184 | - $loadData = true; |
|
184 | + $loadData=true; |
|
185 | 185 | |
186 | 186 | if($this->cache) |
187 | 187 | { |
188 | - $data = $this->cache->get($variant, |
|
188 | + $data=$this->cache->get($variant, |
|
189 | 189 | $this->culture, $this->getLastModified($source)); |
190 | 190 | |
191 | 191 | if(is_array($data)) |
192 | 192 | { |
193 | - $this->messages[$variant] = $data; |
|
194 | - $loadData = false; |
|
193 | + $this->messages[$variant]=$data; |
|
194 | + $loadData=false; |
|
195 | 195 | } |
196 | 196 | unset($data); |
197 | 197 | } |
198 | 198 | if($loadData) |
199 | 199 | { |
200 | - $data = &$this->loadData($source); |
|
200 | + $data=&$this->loadData($source); |
|
201 | 201 | if(is_array($data)) |
202 | 202 | { |
203 | - $this->messages[$variant] = $data; |
|
203 | + $this->messages[$variant]=$data; |
|
204 | 204 | if($this->cache) |
205 | 205 | $this->cache->save($data, $variant, $this->culture); |
206 | 206 | } |
@@ -236,7 +236,7 @@ discard block |
||
236 | 236 | */ |
237 | 237 | public function setCache(MessageCache $cache) |
238 | 238 | { |
239 | - $this->cache = $cache; |
|
239 | + $this->cache=$cache; |
|
240 | 240 | } |
241 | 241 | |
242 | 242 | /** |
@@ -247,7 +247,7 @@ discard block |
||
247 | 247 | public function append($message) |
248 | 248 | { |
249 | 249 | if(!in_array($message, $this->untranslated)) |
250 | - $this->untranslated[] = $message; |
|
250 | + $this->untranslated[]=$message; |
|
251 | 251 | } |
252 | 252 | |
253 | 253 | /** |
@@ -256,7 +256,7 @@ discard block |
||
256 | 256 | */ |
257 | 257 | public function setCulture($culture) |
258 | 258 | { |
259 | - $this->culture = $culture; |
|
259 | + $this->culture=$culture; |
|
260 | 260 | } |
261 | 261 | |
262 | 262 | /** |
@@ -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) { |
@@ -45,23 +45,23 @@ discard block |
||
45 | 45 | * Message data filename extension. |
46 | 46 | * @var string |
47 | 47 | */ |
48 | - protected $dataExt = '.mo'; |
|
48 | + protected $dataExt='.mo'; |
|
49 | 49 | |
50 | 50 | /** |
51 | 51 | * PO data filename extension |
52 | 52 | * @var string |
53 | 53 | */ |
54 | - protected $poExt = '.po'; |
|
54 | + protected $poExt='.po'; |
|
55 | 55 | |
56 | 56 | /** |
57 | 57 | * Separator between culture name and source. |
58 | 58 | * @var string |
59 | 59 | */ |
60 | - protected $dataSeparator = '.'; |
|
60 | + protected $dataSeparator='.'; |
|
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,17 +72,17 @@ 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 | - $result = $mo->toArray(); |
|
77 | + $result=$mo->toArray(); |
|
78 | 78 | |
79 | - $results = array(); |
|
79 | + $results=array(); |
|
80 | 80 | $count=0; |
81 | 81 | foreach($result['strings'] as $source => $target) |
82 | 82 | { |
83 | - $results[$source][] = $target; //target |
|
84 | - $results[$source][] = $count++; //id |
|
85 | - $results[$source][] = ''; //comments |
|
83 | + $results[$source][]=$target; //target |
|
84 | + $results[$source][]=$count++; //id |
|
85 | + $results[$source][]=''; //comments |
|
86 | 86 | } |
87 | 87 | return $results; |
88 | 88 | } |
@@ -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 | - $catalogues = array($source); |
|
135 | + $catalogues=array($source); |
|
136 | 136 | |
137 | - $variant = null; |
|
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 | 141 | if(isset($variants[$i]{0})) |
142 | 142 | { |
143 | - $variant .= ($variant)?'_'.$variants[$i]:$variants[$i]; |
|
144 | - $catalogues[] = $catalogue.$this->dataSeparator. |
|
143 | + $variant.=($variant) ? '_'.$variants[$i] : $variants[$i]; |
|
144 | + $catalogues[]=$catalogue.$this->dataSeparator. |
|
145 | 145 | $variant.$this->dataExt; |
146 | 146 | } |
147 | 147 | } |
148 | - $byDir = $this->getCatalogueByDir($catalogue); |
|
149 | - $catalogues = array_merge($byDir,array_reverse($catalogues)); |
|
148 | + $byDir=$this->getCatalogueByDir($catalogue); |
|
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); |
|
164 | - $catalogues = array(); |
|
163 | + $variants=explode('_', $this->culture); |
|
164 | + $catalogues=array(); |
|
165 | 165 | |
166 | - $variant = null; |
|
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 | 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); |
@@ -186,14 +186,14 @@ discard block |
||
186 | 186 | */ |
187 | 187 | private function getVariants($catalogue='messages') |
188 | 188 | { |
189 | - if($catalogue === null) { |
|
190 | - $catalogue = 'messages'; |
|
189 | + if($catalogue===null) { |
|
190 | + $catalogue='messages'; |
|
191 | 191 | } |
192 | 192 | |
193 | 193 | foreach($this->getCatalogueList($catalogue) as $variant) |
194 | 194 | { |
195 | - $file = $this->getSource($variant); |
|
196 | - $po = $this->getPOFile($file); |
|
195 | + $file=$this->getSource($variant); |
|
196 | + $po=$this->getPOFile($file); |
|
197 | 197 | if(is_file($file) || is_file($po)) |
198 | 198 | return array($variant, $file, $po); |
199 | 199 | } |
@@ -202,7 +202,7 @@ discard block |
||
202 | 202 | |
203 | 203 | private function getPOFile($MOFile) |
204 | 204 | { |
205 | - $filebase = substr($MOFile, 0, strlen($MOFile)-strlen($this->dataExt)); |
|
205 | + $filebase=substr($MOFile, 0, strlen($MOFile) - strlen($this->dataExt)); |
|
206 | 206 | return $filebase.$this->poExt; |
207 | 207 | } |
208 | 208 | |
@@ -215,46 +215,46 @@ discard block |
||
215 | 215 | */ |
216 | 216 | function save($catalogue='messages') |
217 | 217 | { |
218 | - $messages = $this->untranslated; |
|
218 | + $messages=$this->untranslated; |
|
219 | 219 | |
220 | 220 | if(count($messages) <= 0) return false; |
221 | 221 | |
222 | - $variants = $this->getVariants($catalogue); |
|
222 | + $variants=$this->getVariants($catalogue); |
|
223 | 223 | |
224 | 224 | if($variants) |
225 | - list($variant, $MOFile, $POFile) = $variants; |
|
225 | + list($variant, $MOFile, $POFile)=$variants; |
|
226 | 226 | else |
227 | - list($variant, $MOFile, $POFile) = $this->createMessageTemplate($catalogue); |
|
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 | - $strings = array(); |
|
235 | + $strings=array(); |
|
236 | 236 | foreach($messages as $message) |
237 | - $strings[$message] = ''; |
|
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 | - $result = $po->toArray(); |
|
242 | + $result=$po->toArray(); |
|
243 | 243 | |
244 | - $existing = count($result['strings']); |
|
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 | - $new = count($result['strings']); |
|
249 | + $new=count($result['strings']); |
|
250 | 250 | |
251 | 251 | if($new > $existing) |
252 | 252 | { |
253 | 253 | //change the date 2004-12-25 12:26 |
254 | - $result['meta']['PO-Revision-Date'] = @date('Y-m-d H:i:s'); |
|
254 | + $result['meta']['PO-Revision-Date']=@date('Y-m-d H:i:s'); |
|
255 | 255 | |
256 | 256 | $po->fromArray($result); |
257 | - $mo = $po->toMO(); |
|
257 | + $mo=$po->toMO(); |
|
258 | 258 | if($po->save() && $mo->save($MOFile)) |
259 | 259 | { |
260 | 260 | if(!empty($this->cache)) |
@@ -275,30 +275,30 @@ discard block |
||
275 | 275 | */ |
276 | 276 | function delete($message, $catalogue='messages') |
277 | 277 | { |
278 | - $variants = $this->getVariants($catalogue); |
|
278 | + $variants=$this->getVariants($catalogue); |
|
279 | 279 | if($variants) |
280 | - list($variant, $MOFile, $POFile) = $variants; |
|
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 | - $result = $po->toArray(); |
|
291 | + $result=$po->toArray(); |
|
292 | 292 | |
293 | 293 | foreach($result['strings'] as $string => $value) |
294 | 294 | { |
295 | - if($string == $message) |
|
295 | + if($string==$message) |
|
296 | 296 | { |
297 | - $result['meta']['PO-Revision-Date'] = @date('Y-m-d H:i:s'); |
|
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 | - $mo = $po->toMO(); |
|
301 | + $mo=$po->toMO(); |
|
302 | 302 | if($po->save() && $mo->save($MOFile)) |
303 | 303 | { |
304 | 304 | if(!empty($this->cache)) |
@@ -323,31 +323,31 @@ discard block |
||
323 | 323 | */ |
324 | 324 | function update($text, $target, $comments, $catalogue='messages') |
325 | 325 | { |
326 | - $variants = $this->getVariants($catalogue); |
|
326 | + $variants=$this->getVariants($catalogue); |
|
327 | 327 | if($variants) |
328 | - list($variant, $MOFile, $POFile) = $variants; |
|
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 | - $result = $po->toArray(); |
|
340 | + $result=$po->toArray(); |
|
341 | 341 | |
342 | 342 | foreach($result['strings'] as $string => $value) |
343 | 343 | { |
344 | - if($string == $text) |
|
344 | + if($string==$text) |
|
345 | 345 | { |
346 | - $result['strings'][$string] = $target; |
|
347 | - $result['meta']['PO-Revision-Date'] = @date('Y-m-d H:i:s'); |
|
346 | + $result['strings'][$string]=$target; |
|
347 | + $result['meta']['PO-Revision-Date']=@date('Y-m-d H:i:s'); |
|
348 | 348 | |
349 | 349 | $po->fromArray($result); |
350 | - $mo = $po->toMO(); |
|
350 | + $mo=$po->toMO(); |
|
351 | 351 | |
352 | 352 | if($po->save() && $mo->save($MOFile)) |
353 | 353 | { |
@@ -379,42 +379,42 @@ 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; |
|
385 | - $files = scandir($dir); |
|
384 | + $dir=$dir ? $dir : $this->source; |
|
385 | + $files=scandir($dir); |
|
386 | 386 | |
387 | - $catalogue = array(); |
|
387 | + $catalogue=array(); |
|
388 | 388 | |
389 | 389 | foreach($files as $file) |
390 | 390 | { |
391 | 391 | if(is_dir($dir.'/'.$file) |
392 | - && preg_match('/^[a-z]{2}(_[A-Z]{2,3})?$/',$file)) |
|
392 | + && preg_match('/^[a-z]{2}(_[A-Z]{2,3})?$/', $file)) |
|
393 | 393 | { |
394 | 394 | |
395 | - $catalogue = array_merge($catalogue, |
|
395 | + $catalogue=array_merge($catalogue, |
|
396 | 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); |
|
406 | - $culture = $variant; |
|
407 | - $cat = $name; |
|
404 | + $name=substr($file, 0, $pos); |
|
405 | + $dot=strrpos($name, $this->dataSeparator); |
|
406 | + $culture=$variant; |
|
407 | + $cat=$name; |
|
408 | 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 | - $details[0] = $cat; |
|
414 | - $details[1] = $culture; |
|
413 | + $details[0]=$cat; |
|
414 | + $details[1]=$culture; |
|
415 | 415 | |
416 | 416 | |
417 | - $catalogue[] = $details; |
|
417 | + $catalogue[]=$details; |
|
418 | 418 | } |
419 | 419 | } |
420 | 420 | sort($catalogue); |
@@ -424,29 +424,29 @@ discard block |
||
424 | 424 | |
425 | 425 | protected function createMessageTemplate($catalogue) |
426 | 426 | { |
427 | - if($catalogue === null) { |
|
428 | - $catalogue = 'messages'; |
|
427 | + if($catalogue===null) { |
|
428 | + $catalogue='messages'; |
|
429 | 429 | } |
430 | - $variants = $this->getCatalogueList($catalogue); |
|
431 | - $variant = array_shift($variants); |
|
432 | - $mo_file = $this->getSource($variant); |
|
433 | - $po_file = $this->getPOFile($mo_file); |
|
430 | + $variants=$this->getCatalogueList($catalogue); |
|
431 | + $variant=array_shift($variants); |
|
432 | + $mo_file=$this->getSource($variant); |
|
433 | + $po_file=$this->getPOFile($mo_file); |
|
434 | 434 | |
435 | - $dir = dirname($mo_file); |
|
435 | + $dir=dirname($mo_file); |
|
436 | 436 | if(!is_dir($dir)) |
437 | 437 | { |
438 | 438 | @mkdir($dir); |
439 | - @chmod($dir,PRADO_CHMOD); |
|
439 | + @chmod($dir, PRADO_CHMOD); |
|
440 | 440 | } |
441 | 441 | if(!is_dir($dir)) |
442 | 442 | throw new TException("Unable to create directory $dir"); |
443 | 443 | |
444 | - $po = TGettext::factory('PO',$po_file); |
|
445 | - $result['meta']['PO-Revision-Date'] = @date('Y-m-d H:i:s'); |
|
446 | - $result['strings'] = array(); |
|
444 | + $po=TGettext::factory('PO', $po_file); |
|
445 | + $result['meta']['PO-Revision-Date']=@date('Y-m-d H:i:s'); |
|
446 | + $result['strings']=array(); |
|
447 | 447 | |
448 | 448 | $po->fromArray($result); |
449 | - $mo = $po->toMO(); |
|
449 | + $mo=$po->toMO(); |
|
450 | 450 | if($po->save() && $mo->save($mo_file)) |
451 | 451 | return array($variant, $mo_file, $po_file); |
452 | 452 | else |
@@ -260,8 +260,7 @@ discard block |
||
260 | 260 | if(!empty($this->cache)) |
261 | 261 | $this->cache->clean($variant, $this->culture); |
262 | 262 | return true; |
263 | - } |
|
264 | - else |
|
263 | + } else |
|
265 | 264 | return false; |
266 | 265 | } |
267 | 266 | return false; |
@@ -304,8 +303,7 @@ discard block |
||
304 | 303 | if(!empty($this->cache)) |
305 | 304 | $this->cache->clean($variant, $this->culture); |
306 | 305 | return true; |
307 | - } |
|
308 | - else |
|
306 | + } else |
|
309 | 307 | return false; |
310 | 308 | } |
311 | 309 | } |
@@ -354,8 +352,7 @@ discard block |
||
354 | 352 | if(!empty($this->cache)) |
355 | 353 | $this->cache->clean($variant, $this->culture); |
356 | 354 | return true; |
357 | - } |
|
358 | - else |
|
355 | + } else |
|
359 | 356 | return false; |
360 | 357 | } |
361 | 358 | } |
@@ -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) { |
@@ -43,13 +43,13 @@ discard block |
||
43 | 43 | * Message data filename extension. |
44 | 44 | * @var string |
45 | 45 | */ |
46 | - protected $dataExt = '.xml'; |
|
46 | + protected $dataExt='.xml'; |
|
47 | 47 | |
48 | 48 | /** |
49 | 49 | * Separator between culture name and source. |
50 | 50 | * @var string |
51 | 51 | */ |
52 | - protected $dataSeparator = '.'; |
|
52 | + protected $dataSeparator='.'; |
|
53 | 53 | |
54 | 54 | /** |
55 | 55 | * Constructor. |
@@ -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,20 +69,20 @@ 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 | |
76 | - $translationUnit = $XML->xpath('//trans-unit'); |
|
76 | + $translationUnit=$XML->xpath('//trans-unit'); |
|
77 | 77 | |
78 | - $translations = array(); |
|
78 | + $translations=array(); |
|
79 | 79 | |
80 | 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; |
@@ -127,28 +127,28 @@ discard block |
||
127 | 127 | */ |
128 | 128 | protected function getCatalogueList($catalogue) |
129 | 129 | { |
130 | - $variants = explode('_',$this->culture); |
|
131 | - $source = $catalogue.$this->dataExt; |
|
132 | - $catalogues = array($source); |
|
133 | - $variant = null; |
|
130 | + $variants=explode('_', $this->culture); |
|
131 | + $source=$catalogue.$this->dataExt; |
|
132 | + $catalogues=array($source); |
|
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 | 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 | - $byDir = $this->getCatalogueByDir($catalogue); |
|
145 | - $catalogues = array_merge($byDir,array_reverse($catalogues)); |
|
146 | - $files = array(); |
|
144 | + $byDir=$this->getCatalogueByDir($catalogue); |
|
145 | + $catalogues=array_merge($byDir, array_reverse($catalogues)); |
|
146 | + $files=array(); |
|
147 | 147 | |
148 | 148 | foreach($catalogues as $file) |
149 | 149 | { |
150 | - $files[] = $file; |
|
151 | - $files[] = preg_replace('/\.xml$/', '.xlf', $file); |
|
150 | + $files[]=$file; |
|
151 | + $files[]=preg_replace('/\.xml$/', '.xlf', $file); |
|
152 | 152 | } |
153 | 153 | |
154 | 154 | return $files; |
@@ -163,16 +163,16 @@ discard block |
||
163 | 163 | */ |
164 | 164 | private function getCatalogueByDir($catalogue) |
165 | 165 | { |
166 | - $variants = explode('_',$this->culture); |
|
167 | - $catalogues = array(); |
|
168 | - $variant = null; |
|
166 | + $variants=explode('_', $this->culture); |
|
167 | + $catalogues=array(); |
|
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 | 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,38 +196,38 @@ 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; |
|
202 | - $files = scandir($dir); |
|
203 | - $catalogue = array(); |
|
201 | + $dir=$dir ? $dir : $this->source; |
|
202 | + $files=scandir($dir); |
|
203 | + $catalogue=array(); |
|
204 | 204 | |
205 | 205 | foreach($files as $file) |
206 | 206 | { |
207 | - if(is_dir($dir.'/'.$file) && preg_match('/^[a-z]{2}(_[A-Z]{2,3})?$/',$file)) { |
|
208 | - $catalogue = array_merge( |
|
207 | + if(is_dir($dir.'/'.$file) && preg_match('/^[a-z]{2}(_[A-Z]{2,3})?$/', $file)) { |
|
208 | + $catalogue=array_merge( |
|
209 | 209 | $catalogue, |
210 | 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); |
|
219 | - $culture = $variant; |
|
220 | - $cat = $name; |
|
217 | + $name=substr($file, 0, $pos); |
|
218 | + $dot=strrpos($name, $this->dataSeparator); |
|
219 | + $culture=$variant; |
|
220 | + $cat=$name; |
|
221 | 221 | |
222 | 222 | if(is_int($dot)) |
223 | 223 | { |
224 | - $culture = substr($name, $dot+1, strlen($name)); |
|
225 | - $cat = substr($name, 0, $dot); |
|
224 | + $culture=substr($name, $dot + 1, strlen($name)); |
|
225 | + $cat=substr($name, 0, $dot); |
|
226 | 226 | } |
227 | 227 | |
228 | - $details[0] = $cat; |
|
229 | - $details[1] = $culture; |
|
230 | - $catalogue[] = $details; |
|
228 | + $details[0]=$cat; |
|
229 | + $details[1]=$culture; |
|
230 | + $catalogue[]=$details; |
|
231 | 231 | } |
232 | 232 | } |
233 | 233 | sort($catalogue); |
@@ -244,13 +244,13 @@ discard block |
||
244 | 244 | */ |
245 | 245 | private function getVariants($catalogue='messages') |
246 | 246 | { |
247 | - if($catalogue === null) { |
|
248 | - $catalogue = 'messages'; |
|
247 | + if($catalogue===null) { |
|
248 | + $catalogue='messages'; |
|
249 | 249 | } |
250 | 250 | |
251 | 251 | foreach($this->getCatalogueList($catalogue) as $variant) |
252 | 252 | { |
253 | - $file = $this->getSource($variant); |
|
253 | + $file=$this->getSource($variant); |
|
254 | 254 | if(is_file($file)) { |
255 | 255 | return array($variant, $file); |
256 | 256 | } |
@@ -267,48 +267,48 @@ discard block |
||
267 | 267 | */ |
268 | 268 | public function save($catalogue='messages') |
269 | 269 | { |
270 | - $messages = $this->untranslated; |
|
270 | + $messages=$this->untranslated; |
|
271 | 271 | if(count($messages) <= 0) { |
272 | 272 | return false; |
273 | 273 | } |
274 | 274 | |
275 | - $variants = $this->getVariants($catalogue); |
|
275 | + $variants=$this->getVariants($catalogue); |
|
276 | 276 | |
277 | 277 | if($variants) { |
278 | - list($variant, $filename) = $variants; |
|
278 | + list($variant, $filename)=$variants; |
|
279 | 279 | } else { |
280 | - list($variant, $filename) = $this->createMessageTemplate($catalogue); |
|
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 | |
287 | 287 | //create a new dom, import the existing xml |
288 | - $dom = new DOMDocument(); |
|
288 | + $dom=new DOMDocument(); |
|
289 | 289 | $dom->load($filename); |
290 | 290 | |
291 | 291 | //find the body element |
292 | - $xpath = new DomXPath($dom); |
|
293 | - $body = $xpath->query('//body')->item(0); |
|
292 | + $xpath=new DomXPath($dom); |
|
293 | + $body=$xpath->query('//body')->item(0); |
|
294 | 294 | |
295 | - $lastNodes = $xpath->query('//trans-unit[last()]'); |
|
295 | + $lastNodes=$xpath->query('//trans-unit[last()]'); |
|
296 | 296 | if(($last=$lastNodes->item(0))!==null) { |
297 | - $count = (int)$last->getAttribute('id'); |
|
297 | + $count=(int) $last->getAttribute('id'); |
|
298 | 298 | } else { |
299 | - $count = 0; |
|
299 | + $count=0; |
|
300 | 300 | } |
301 | 301 | |
302 | 302 | //for each message add it to the XML file using DOM |
303 | 303 | foreach($messages as $message) |
304 | 304 | { |
305 | - $unit = $dom->createElement('trans-unit'); |
|
306 | - $unit->setAttribute('id',++$count); |
|
305 | + $unit=$dom->createElement('trans-unit'); |
|
306 | + $unit->setAttribute('id', ++$count); |
|
307 | 307 | |
308 | - $source = $dom->createElement('source'); |
|
308 | + $source=$dom->createElement('source'); |
|
309 | 309 | $source->appendChild($dom->createCDATASection($message)); |
310 | 310 | |
311 | - $target = $dom->createElement('target'); |
|
311 | + $target=$dom->createElement('target'); |
|
312 | 312 | $target->appendChild($dom->createCDATASection('')); |
313 | 313 | |
314 | 314 | $unit->appendChild($dom->createTextNode("\n")); |
@@ -323,7 +323,7 @@ discard block |
||
323 | 323 | } |
324 | 324 | |
325 | 325 | |
326 | - $fileNode = $xpath->query('//file')->item(0); |
|
326 | + $fileNode=$xpath->query('//file')->item(0); |
|
327 | 327 | $fileNode->setAttribute('date', @date('Y-m-d\TH:i:s\Z')); |
328 | 328 | |
329 | 329 | //save it and clear the cache for this variant |
@@ -345,68 +345,68 @@ discard block |
||
345 | 345 | */ |
346 | 346 | public function update($text, $target, $comments, $catalogue='messages') |
347 | 347 | { |
348 | - $variants = $this->getVariants($catalogue); |
|
348 | + $variants=$this->getVariants($catalogue); |
|
349 | 349 | |
350 | 350 | if($variants) { |
351 | - list($variant, $filename) = $variants; |
|
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 | |
360 | 360 | //create a new dom, import the existing xml |
361 | - $dom = DOMDocument::load($filename); |
|
361 | + $dom=DOMDocument::load($filename); |
|
362 | 362 | |
363 | 363 | //find the body element |
364 | - $xpath = new DomXPath($dom); |
|
365 | - $units = $xpath->query('//trans-unit'); |
|
364 | + $xpath=new DomXPath($dom); |
|
365 | + $units=$xpath->query('//trans-unit'); |
|
366 | 366 | |
367 | 367 | //for each of the existin units |
368 | 368 | foreach($units as $unit) |
369 | 369 | { |
370 | - $found = false; |
|
371 | - $targetted = false; |
|
372 | - $commented = false; |
|
370 | + $found=false; |
|
371 | + $targetted=false; |
|
372 | + $commented=false; |
|
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 | 376 | foreach($unit->childNodes as $node) |
377 | 377 | { |
378 | 378 | //source node |
379 | - if($node->nodeName == 'source' && $node->firstChild->wholeText == $text) { |
|
380 | - $found = true; |
|
379 | + if($node->nodeName=='source' && $node->firstChild->wholeText==$text) { |
|
380 | + $found=true; |
|
381 | 381 | } |
382 | 382 | |
383 | 383 | //found source, get the target and notes |
384 | 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 | - $node->nodeValue = $target; |
|
390 | - $targetted = true; |
|
389 | + $node->nodeValue=$target; |
|
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 | - $node->nodeValue = $comments; |
|
397 | - $commented = true; |
|
396 | + $node->nodeValue=$comments; |
|
397 | + $commented=true; |
|
398 | 398 | } |
399 | 399 | } |
400 | 400 | } |
401 | 401 | |
402 | 402 | //append a target |
403 | 403 | if($found && !$targetted) { |
404 | - $unit->appendChild($dom->createElement('target',$target)); |
|
404 | + $unit->appendChild($dom->createElement('target', $target)); |
|
405 | 405 | } |
406 | 406 | |
407 | 407 | //append a note |
408 | 408 | if($found && !$commented && !empty($comments)) { |
409 | - $unit->appendChild($dom->createElement('note',$comments)); |
|
409 | + $unit->appendChild($dom->createElement('note', $comments)); |
|
410 | 410 | } |
411 | 411 | |
412 | 412 | //finished searching |
@@ -415,10 +415,10 @@ discard block |
||
415 | 415 | } |
416 | 416 | } |
417 | 417 | |
418 | - $fileNode = $xpath->query('//file')->item(0); |
|
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 | 423 | if(!empty($this->cache)) { |
424 | 424 | $this->cache->clean($variant, $this->culture); |
@@ -438,23 +438,23 @@ discard block |
||
438 | 438 | */ |
439 | 439 | public function delete($message, $catalogue='messages') |
440 | 440 | { |
441 | - $variants = $this->getVariants($catalogue); |
|
441 | + $variants=$this->getVariants($catalogue); |
|
442 | 442 | if($variants) { |
443 | - list($variant, $filename) = $variants; |
|
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 | |
452 | 452 | //create a new dom, import the existing xml |
453 | - $dom = DOMDocument::load($filename); |
|
453 | + $dom=DOMDocument::load($filename); |
|
454 | 454 | |
455 | 455 | //find the body element |
456 | - $xpath = new DomXPath($dom); |
|
457 | - $units = $xpath->query('//trans-unit'); |
|
456 | + $xpath=new DomXPath($dom); |
|
457 | + $units=$xpath->query('//trans-unit'); |
|
458 | 458 | |
459 | 459 | //for each of the existin units |
460 | 460 | foreach($units as $unit) |
@@ -464,14 +464,14 @@ discard block |
||
464 | 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 | - $fileNode = $xpath->query('//file')->item(0); |
|
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)) { |
|
474 | + if(false!==$dom->save($filename)) { |
|
475 | 475 | if(!empty($this->cache)) { |
476 | 476 | $this->cache->clean($variant, $this->culture); |
477 | 477 | } |
@@ -488,18 +488,18 @@ discard block |
||
488 | 488 | |
489 | 489 | protected function createMessageTemplate($catalogue) |
490 | 490 | { |
491 | - if($catalogue === null) { |
|
492 | - $catalogue = 'messages'; |
|
491 | + if($catalogue===null) { |
|
492 | + $catalogue='messages'; |
|
493 | 493 | } |
494 | 494 | |
495 | - $variants = $this->getCatalogueList($catalogue); |
|
496 | - $variant = array_shift($variants); |
|
497 | - $file = $this->getSource($variant); |
|
498 | - $dir = dirname($file); |
|
495 | + $variants=$this->getCatalogueList($catalogue); |
|
496 | + $variant=array_shift($variants); |
|
497 | + $file=$this->getSource($variant); |
|
498 | + $dir=dirname($file); |
|
499 | 499 | |
500 | 500 | if(!is_dir($dir)) { |
501 | 501 | @mkdir($dir); |
502 | - @chmod($dir,PRADO_CHMOD); |
|
502 | + @chmod($dir, PRADO_CHMOD); |
|
503 | 503 | } |
504 | 504 | |
505 | 505 | if(!is_dir($dir)) { |
@@ -514,8 +514,8 @@ discard block |
||
514 | 514 | |
515 | 515 | protected function getTemplate($catalogue) |
516 | 516 | { |
517 | - $date = @date('c'); |
|
518 | - $xml = <<<EOD |
|
517 | + $date=@date('c'); |
|
518 | + $xml=<<<EOD |
|
519 | 519 | <?xml version="1.0" encoding="UTF-8"?> |
520 | 520 | <xliff version="1.0"> |
521 | 521 | <file source-language="EN" target-language="{$this->culture}" datatype="plaintext" original="$catalogue" date="$date" product-name="$catalogue"> |
@@ -19,7 +19,6 @@ |
||
19 | 19 | namespace Prado\I18N\core; |
20 | 20 | |
21 | 21 | use DOMDocument; |
22 | -use DOMXPath; |
|
23 | 22 | use Prado\Exceptions\TException; |
24 | 23 | use Prado\Exceptions\TIOException; |
25 | 24 |
@@ -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 | { |
@@ -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 |
@@ -46,575 +46,575 @@ |
||
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 __construct($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 __construct($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 | 252 | } |
253 | 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 | - } |
|
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); |
|
536 | - if ($this->_readControl) { |
|
537 | - $hashControl = @fread($fp, 32); |
|
538 | - $length = $length - 32; |
|
539 | - } |
|
540 | - $data = @fread($fp, $length); |
|
541 | - if ($this->_fileLocking) @flock($fp, LOCK_UN); |
|
542 | - @fclose($fp); |
|
543 | - if ($this->_readControl) { |
|
544 | - $hashData = $this->_hash($data, $this->_readControlType); |
|
545 | - if ($hashData != $hashControl) { |
|
546 | - @touch($this->_file, time() - 2*abs($this->_lifeTime)); |
|
547 | - return false; |
|
548 | - } |
|
549 | - } |
|
550 | - return $data; |
|
551 | - } |
|
552 | - $this->raiseError('Cache_Lite : Unable to read cache !', -2); |
|
553 | - return false; |
|
554 | - } |
|
555 | - |
|
556 | - /** |
|
557 | - * Write the given data in the cache file |
|
558 | - * |
|
559 | - * @param string $data data to put in cache |
|
560 | - * @return boolean true if ok |
|
561 | - * @access private |
|
562 | - */ |
|
563 | - function _write($data) |
|
564 | - { |
|
565 | - $fp = @fopen($this->_file, "wb"); |
|
566 | - if ($fp) { |
|
567 | - if ($this->_fileLocking) @flock($fp, LOCK_EX); |
|
568 | - if ($this->_readControl) { |
|
569 | - @fwrite($fp, $this->_hash($data, $this->_readControlType), 32); |
|
570 | - } |
|
571 | - $len = strlen($data); |
|
572 | - @fwrite($fp, $data, $len); |
|
573 | - if ($this->_fileLocking) @flock($fp, LOCK_UN); |
|
574 | - @fclose($fp); |
|
575 | - return true; |
|
576 | - } |
|
577 | - $this->raiseError('Cache_Lite : Unable to write cache !', -1); |
|
578 | - return false; |
|
579 | - } |
|
580 | - |
|
581 | - /** |
|
582 | - * Write the given data in the cache file and control it just after to avoid |
|
583 | - * corrupted cache entries |
|
584 | - * |
|
585 | - * @param string $data data to put in cache |
|
586 | - * @return boolean true if the test is ok |
|
587 | - * @access private |
|
588 | - */ |
|
589 | - function _writeAndControl($data) |
|
590 | - { |
|
591 | - $this->_write($data); |
|
592 | - $dataRead = $this->_read($data); |
|
593 | - return ($dataRead==$data); |
|
594 | - } |
|
595 | - |
|
596 | - /** |
|
597 | - * Make a control key with the string containing datas |
|
598 | - * |
|
599 | - * @param string $data data |
|
600 | - * @param string $controlType type of control 'md5', 'crc32' or 'strlen' |
|
601 | - * @return string control key |
|
602 | - * @access private |
|
603 | - */ |
|
604 | - function _hash($data, $controlType) |
|
605 | - { |
|
606 | - switch ($controlType) { |
|
607 | - case 'md5': |
|
608 | - return md5($data); |
|
609 | - case 'crc32': |
|
610 | - return sprintf('% 32d', crc32($data)); |
|
611 | - case 'strlen': |
|
612 | - return sprintf('% 32d', strlen($data)); |
|
613 | - default: |
|
614 | - $this->raiseError('Unknown controlType ! '. |
|
615 | - '(available values are only \'md5\', \'crc32\', \'strlen\')', -5); |
|
616 | - } |
|
617 | - } |
|
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); |
|
536 | + if ($this->_readControl) { |
|
537 | + $hashControl = @fread($fp, 32); |
|
538 | + $length = $length - 32; |
|
539 | + } |
|
540 | + $data = @fread($fp, $length); |
|
541 | + if ($this->_fileLocking) @flock($fp, LOCK_UN); |
|
542 | + @fclose($fp); |
|
543 | + if ($this->_readControl) { |
|
544 | + $hashData = $this->_hash($data, $this->_readControlType); |
|
545 | + if ($hashData != $hashControl) { |
|
546 | + @touch($this->_file, time() - 2*abs($this->_lifeTime)); |
|
547 | + return false; |
|
548 | + } |
|
549 | + } |
|
550 | + return $data; |
|
551 | + } |
|
552 | + $this->raiseError('Cache_Lite : Unable to read cache !', -2); |
|
553 | + return false; |
|
554 | + } |
|
555 | + |
|
556 | + /** |
|
557 | + * Write the given data in the cache file |
|
558 | + * |
|
559 | + * @param string $data data to put in cache |
|
560 | + * @return boolean true if ok |
|
561 | + * @access private |
|
562 | + */ |
|
563 | + function _write($data) |
|
564 | + { |
|
565 | + $fp = @fopen($this->_file, "wb"); |
|
566 | + if ($fp) { |
|
567 | + if ($this->_fileLocking) @flock($fp, LOCK_EX); |
|
568 | + if ($this->_readControl) { |
|
569 | + @fwrite($fp, $this->_hash($data, $this->_readControlType), 32); |
|
570 | + } |
|
571 | + $len = strlen($data); |
|
572 | + @fwrite($fp, $data, $len); |
|
573 | + if ($this->_fileLocking) @flock($fp, LOCK_UN); |
|
574 | + @fclose($fp); |
|
575 | + return true; |
|
576 | + } |
|
577 | + $this->raiseError('Cache_Lite : Unable to write cache !', -1); |
|
578 | + return false; |
|
579 | + } |
|
580 | + |
|
581 | + /** |
|
582 | + * Write the given data in the cache file and control it just after to avoid |
|
583 | + * corrupted cache entries |
|
584 | + * |
|
585 | + * @param string $data data to put in cache |
|
586 | + * @return boolean true if the test is ok |
|
587 | + * @access private |
|
588 | + */ |
|
589 | + function _writeAndControl($data) |
|
590 | + { |
|
591 | + $this->_write($data); |
|
592 | + $dataRead = $this->_read($data); |
|
593 | + return ($dataRead==$data); |
|
594 | + } |
|
595 | + |
|
596 | + /** |
|
597 | + * Make a control key with the string containing datas |
|
598 | + * |
|
599 | + * @param string $data data |
|
600 | + * @param string $controlType type of control 'md5', 'crc32' or 'strlen' |
|
601 | + * @return string control key |
|
602 | + * @access private |
|
603 | + */ |
|
604 | + function _hash($data, $controlType) |
|
605 | + { |
|
606 | + switch ($controlType) { |
|
607 | + case 'md5': |
|
608 | + return md5($data); |
|
609 | + case 'crc32': |
|
610 | + return sprintf('% 32d', crc32($data)); |
|
611 | + case 'strlen': |
|
612 | + return sprintf('% 32d', strlen($data)); |
|
613 | + default: |
|
614 | + $this->raiseError('Unknown controlType ! '. |
|
615 | + '(available values are only \'md5\', \'crc32\', \'strlen\')', -5); |
|
616 | + } |
|
617 | + } |
|
618 | 618 | |
619 | 619 | } |
620 | 620 |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | * |
55 | 55 | * @var string $_cacheDir |
56 | 56 | */ |
57 | - protected $_cacheDir = '/tmp/'; |
|
57 | + protected $_cacheDir='/tmp/'; |
|
58 | 58 | |
59 | 59 | /** |
60 | 60 | * Enable / disable caching |
@@ -63,14 +63,14 @@ discard block |
||
63 | 63 | * |
64 | 64 | * @var boolean $_caching |
65 | 65 | */ |
66 | - protected $_caching = true; |
|
66 | + protected $_caching=true; |
|
67 | 67 | |
68 | 68 | /** |
69 | 69 | * Cache lifetime (in seconds) |
70 | 70 | * |
71 | 71 | * @var int $_lifeTime |
72 | 72 | */ |
73 | - protected $_lifeTime = 3600; |
|
73 | + protected $_lifeTime=3600; |
|
74 | 74 | |
75 | 75 | /** |
76 | 76 | * Enable / disable fileLocking |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | * |
80 | 80 | * @var boolean $_fileLocking |
81 | 81 | */ |
82 | - protected $_fileLocking = true; |
|
82 | + protected $_fileLocking=true; |
|
83 | 83 | |
84 | 84 | /** |
85 | 85 | * Timestamp of the last valid cache |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | * |
106 | 106 | * @var boolean $_writeControl |
107 | 107 | */ |
108 | - protected $_writeControl = true; |
|
108 | + protected $_writeControl=true; |
|
109 | 109 | |
110 | 110 | /** |
111 | 111 | * Enable / disable read control |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | * |
116 | 116 | * @var boolean $_writeControl |
117 | 117 | */ |
118 | - protected $_readControl = true; |
|
118 | + protected $_readControl=true; |
|
119 | 119 | |
120 | 120 | /** |
121 | 121 | * Type of read control (only if read control is enabled) |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | * |
129 | 129 | * @var boolean $_readControlType |
130 | 130 | */ |
131 | - protected $_readControlType = 'crc32'; |
|
131 | + protected $_readControlType='crc32'; |
|
132 | 132 | |
133 | 133 | /** |
134 | 134 | * Current cache id |
@@ -151,7 +151,7 @@ discard block |
||
151 | 151 | * |
152 | 152 | * @var boolean $_memoryCaching |
153 | 153 | */ |
154 | - protected $_memoryCaching = false; |
|
154 | + protected $_memoryCaching=false; |
|
155 | 155 | |
156 | 156 | /** |
157 | 157 | * Enable / Disable "Only Memory Caching" |
@@ -159,28 +159,28 @@ discard block |
||
159 | 159 | * |
160 | 160 | * @var boolean $_onlyMemoryCaching |
161 | 161 | */ |
162 | - protected $_onlyMemoryCaching = false; |
|
162 | + protected $_onlyMemoryCaching=false; |
|
163 | 163 | |
164 | 164 | /** |
165 | 165 | * Memory caching array |
166 | 166 | * |
167 | 167 | * @var array $_memoryCachingArray |
168 | 168 | */ |
169 | - protected $_memoryCachingArray = array(); |
|
169 | + protected $_memoryCachingArray=array(); |
|
170 | 170 | |
171 | 171 | /** |
172 | 172 | * Memory caching counter |
173 | 173 | * |
174 | 174 | * @var int $memoryCachingCounter |
175 | 175 | */ |
176 | - protected $_memoryCachingCounter = 0; |
|
176 | + protected $_memoryCachingCounter=0; |
|
177 | 177 | |
178 | 178 | /** |
179 | 179 | * Memory caching limit |
180 | 180 | * |
181 | 181 | * @var int $memoryCachingLimit |
182 | 182 | */ |
183 | - protected $_memoryCachingLimit = 1000; |
|
183 | + protected $_memoryCachingLimit=1000; |
|
184 | 184 | |
185 | 185 | /** |
186 | 186 | * File Name protection |
@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | * |
193 | 193 | * @var boolean $fileNameProtection |
194 | 194 | */ |
195 | - protected $_fileNameProtection = true; |
|
195 | + protected $_fileNameProtection=true; |
|
196 | 196 | |
197 | 197 | /** |
198 | 198 | * Enable / disable automatic serialization |
@@ -202,7 +202,7 @@ discard block |
||
202 | 202 | * |
203 | 203 | * @var boolean $_serialize |
204 | 204 | */ |
205 | - protected $_automaticSerialization = false; |
|
205 | + protected $_automaticSerialization=false; |
|
206 | 206 | |
207 | 207 | // --- Public methods --- |
208 | 208 | |
@@ -228,9 +228,9 @@ discard block |
||
228 | 228 | * @param array $options options |
229 | 229 | * @access public |
230 | 230 | */ |
231 | - function __construct($options = array(null)) |
|
231 | + function __construct($options=array(null)) |
|
232 | 232 | { |
233 | - $availableOptions = array( 'automaticSerialization', |
|
233 | + $availableOptions=array('automaticSerialization', |
|
234 | 234 | 'fileNameProtection', |
235 | 235 | 'memoryCaching', |
236 | 236 | 'onlyMemoryCaching', |
@@ -244,11 +244,11 @@ discard block |
||
244 | 244 | 'readControlType'); |
245 | 245 | foreach($options as $key => $value) { |
246 | 246 | if(in_array($key, $availableOptions)) { |
247 | - $property = '_'.$key; |
|
248 | - $this->$property = $value; |
|
247 | + $property='_'.$key; |
|
248 | + $this->$property=$value; |
|
249 | 249 | } |
250 | 250 | } |
251 | - $this->_refreshTime = time() - $this->_lifeTime; |
|
251 | + $this->_refreshTime=time() - $this->_lifeTime; |
|
252 | 252 | } |
253 | 253 | |
254 | 254 | /** |
@@ -261,41 +261,41 @@ discard block |
||
261 | 261 | * @return string data of the cache (or false if no cache available) |
262 | 262 | * @access public |
263 | 263 | */ |
264 | - function get($id, $group = 'default', $doNotTestCacheValidity = false) |
|
264 | + function get($id, $group='default', $doNotTestCacheValidity=false) |
|
265 | 265 | { |
266 | - $this->_id = $id; |
|
267 | - $this->_group = $group; |
|
268 | - $data = false; |
|
269 | - if ($this->_caching) { |
|
266 | + $this->_id=$id; |
|
267 | + $this->_group=$group; |
|
268 | + $data=false; |
|
269 | + if($this->_caching) { |
|
270 | 270 | $this->_setFileName($id, $group); |
271 | - if ($this->_memoryCaching) { |
|
272 | - if (isset($this->_memoryCachingArray[$this->_file])) { |
|
273 | - if ($this->_automaticSerialization) { |
|
271 | + if($this->_memoryCaching) { |
|
272 | + if(isset($this->_memoryCachingArray[$this->_file])) { |
|
273 | + if($this->_automaticSerialization) { |
|
274 | 274 | return unserialize( |
275 | 275 | $this->_memoryCachingArray[$this->_file]); |
276 | 276 | } else { |
277 | 277 | return $this->_memoryCachingArray[$this->_file]; |
278 | 278 | } |
279 | 279 | } else { |
280 | - if ($this->_onlyMemoryCaching) { |
|
280 | + if($this->_onlyMemoryCaching) { |
|
281 | 281 | return false; |
282 | 282 | } |
283 | 283 | } |
284 | 284 | } |
285 | - if ($doNotTestCacheValidity) { |
|
286 | - if (file_exists($this->_file)) { |
|
287 | - $data = $this->_read(); |
|
285 | + if($doNotTestCacheValidity) { |
|
286 | + if(file_exists($this->_file)) { |
|
287 | + $data=$this->_read(); |
|
288 | 288 | } |
289 | 289 | } else { |
290 | - if (@filemtime($this->_file) > $this->_refreshTime) { |
|
291 | - $data = $this->_read(); |
|
290 | + if(@filemtime($this->_file) > $this->_refreshTime) { |
|
291 | + $data=$this->_read(); |
|
292 | 292 | } |
293 | 293 | } |
294 | - if (($data) and ($this->_memoryCaching)) { |
|
294 | + if(($data) and ($this->_memoryCaching)) { |
|
295 | 295 | $this->_memoryCacheAdd($this->_file, $data); |
296 | 296 | } |
297 | - if ($this->_automaticSerialization && is_string($data)) { |
|
298 | - $data = unserialize($data); |
|
297 | + if($this->_automaticSerialization && is_string($data)) { |
|
298 | + $data=unserialize($data); |
|
299 | 299 | } |
300 | 300 | return $data; |
301 | 301 | } |
@@ -312,24 +312,24 @@ discard block |
||
312 | 312 | * @return boolean true if no problem |
313 | 313 | * @access public |
314 | 314 | */ |
315 | - function save($data, $id = null, $group = 'default') |
|
315 | + function save($data, $id=null, $group='default') |
|
316 | 316 | { |
317 | - if ($this->_caching) { |
|
318 | - if ($this->_automaticSerialization) { |
|
319 | - $data = serialize($data); |
|
317 | + if($this->_caching) { |
|
318 | + if($this->_automaticSerialization) { |
|
319 | + $data=serialize($data); |
|
320 | 320 | } |
321 | - if (isset($id)) { |
|
321 | + if(isset($id)) { |
|
322 | 322 | $this->_setFileName($id, $group); |
323 | 323 | } |
324 | - if ($this->_memoryCaching) { |
|
324 | + if($this->_memoryCaching) { |
|
325 | 325 | $this->_memoryCacheAdd($this->_file, $data); |
326 | - if ($this->_onlyMemoryCaching) { |
|
326 | + if($this->_onlyMemoryCaching) { |
|
327 | 327 | return true; |
328 | 328 | } |
329 | 329 | } |
330 | - if ($this->_writeControl) { |
|
331 | - if (!$this->_writeAndControl($data)) { |
|
332 | - @touch($this->_file, time() - 2*abs($this->_lifeTime)); |
|
330 | + if($this->_writeControl) { |
|
331 | + if(!$this->_writeAndControl($data)) { |
|
332 | + @touch($this->_file, time() - 2 * abs($this->_lifeTime)); |
|
333 | 333 | return false; |
334 | 334 | } else { |
335 | 335 | return true; |
@@ -349,10 +349,10 @@ discard block |
||
349 | 349 | * @return boolean true if no problem |
350 | 350 | * @access public |
351 | 351 | */ |
352 | - function remove($id, $group = 'default') |
|
352 | + function remove($id, $group='default') |
|
353 | 353 | { |
354 | 354 | $this->_setFileName($id, $group); |
355 | - if (!@unlink($this->_file)) { |
|
355 | + if(!@unlink($this->_file)) { |
|
356 | 356 | $this->raiseError('TCache_Lite : Unable to remove cache !', -3); |
357 | 357 | return false; |
358 | 358 | } |
@@ -369,35 +369,35 @@ discard block |
||
369 | 369 | * @return boolean true if no problem |
370 | 370 | * @access public |
371 | 371 | */ |
372 | - function clean($group = false) |
|
372 | + function clean($group=false) |
|
373 | 373 | { |
374 | - if ($this->_fileNameProtection) { |
|
375 | - $motif = ($group) ? 'cache_'.md5($group).'_' : 'cache_'; |
|
374 | + if($this->_fileNameProtection) { |
|
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 | - if ($this->_memoryCaching) { |
|
380 | - while (list($key, $value) = each($this->_memoryCaching)) { |
|
381 | - if (strpos($key, $motif, 0)) { |
|
379 | + if($this->_memoryCaching) { |
|
380 | + while(list($key, $value)=each($this->_memoryCaching)) { |
|
381 | + if(strpos($key, $motif, 0)) { |
|
382 | 382 | unset($this->_memoryCaching[$key]); |
383 | - $this->_memoryCachingCounter = |
|
383 | + $this->_memoryCachingCounter= |
|
384 | 384 | $this->_memoryCachingCounter - 1; |
385 | 385 | } |
386 | 386 | } |
387 | - if ($this->_onlyMemoryCaching) { |
|
387 | + if($this->_onlyMemoryCaching) { |
|
388 | 388 | return true; |
389 | 389 | } |
390 | 390 | } |
391 | - if (!($dh = opendir($this->_cacheDir))) { |
|
391 | + if(!($dh=opendir($this->_cacheDir))) { |
|
392 | 392 | $this->raiseError('TCache_Lite : Unable to open cache directory !'); |
393 | 393 | return false; |
394 | 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)) { |
|
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 | 401 | $this->raiseError('Cache_Lite : Unable to remove cache !', -3); |
402 | 402 | return false; |
403 | 403 | } |
@@ -416,22 +416,22 @@ discard block |
||
416 | 416 | */ |
417 | 417 | function setLifeTime($newLifeTime) |
418 | 418 | { |
419 | - $this->_lifeTime = $newLifeTime; |
|
420 | - $this->_refreshTime = time() - $newLifeTime; |
|
419 | + $this->_lifeTime=$newLifeTime; |
|
420 | + $this->_refreshTime=time() - $newLifeTime; |
|
421 | 421 | } |
422 | 422 | |
423 | 423 | /** |
424 | 424 | * |
425 | 425 | * @access public |
426 | 426 | */ |
427 | - function saveMemoryCachingState($id, $group = 'default') |
|
427 | + function saveMemoryCachingState($id, $group='default') |
|
428 | 428 | { |
429 | - if ($this->_caching) { |
|
430 | - $array = array( |
|
429 | + if($this->_caching) { |
|
430 | + $array=array( |
|
431 | 431 | 'counter' => $this->_memoryCachingCounter, |
432 | 432 | 'array' => $this->_memoryCachingState |
433 | 433 | ); |
434 | - $data = serialize($array); |
|
434 | + $data=serialize($array); |
|
435 | 435 | $this->save($data, $id, $group); |
436 | 436 | } |
437 | 437 | } |
@@ -440,15 +440,15 @@ discard block |
||
440 | 440 | * |
441 | 441 | * @access public |
442 | 442 | */ |
443 | - function getMemoryCachingState($id, $group = 'default', |
|
444 | - $doNotTestCacheValidity = false) |
|
443 | + function getMemoryCachingState($id, $group='default', |
|
444 | + $doNotTestCacheValidity=false) |
|
445 | 445 | { |
446 | - if ($this->_caching) { |
|
447 | - if ($data = $this->get($id, $group, $doNotTestCacheValidity)) |
|
446 | + if($this->_caching) { |
|
447 | + if($data=$this->get($id, $group, $doNotTestCacheValidity)) |
|
448 | 448 | { |
449 | - $array = unserialize($data); |
|
450 | - $this->_memoryCachingCounter = $array['counter']; |
|
451 | - $this->_memoryCachingArray = $array['array']; |
|
449 | + $array=unserialize($data); |
|
450 | + $this->_memoryCachingCounter=$array['counter']; |
|
451 | + $this->_memoryCachingArray=$array['array']; |
|
452 | 452 | } |
453 | 453 | } |
454 | 454 | } |
@@ -488,12 +488,12 @@ discard block |
||
488 | 488 | */ |
489 | 489 | function _memoryCacheAdd($id, $data) |
490 | 490 | { |
491 | - $this->_memoryCachingArray[$this->_file] = $data; |
|
492 | - if ($this->_memoryCachingCounter >= $this->_memoryCachingLimit) { |
|
493 | - list($key, $value) = each($this->_memoryCachingArray); |
|
491 | + $this->_memoryCachingArray[$this->_file]=$data; |
|
492 | + if($this->_memoryCachingCounter >= $this->_memoryCachingLimit) { |
|
493 | + list($key, $value)=each($this->_memoryCachingArray); |
|
494 | 494 | unset($this->_memoryCachingArray[$key]); |
495 | 495 | } else { |
496 | - $this->_memoryCachingCounter = $this->_memoryCachingCounter + 1; |
|
496 | + $this->_memoryCachingCounter=$this->_memoryCachingCounter + 1; |
|
497 | 497 | } |
498 | 498 | } |
499 | 499 | |
@@ -506,11 +506,11 @@ discard block |
||
506 | 506 | */ |
507 | 507 | function _setFileName($id, $group) |
508 | 508 | { |
509 | - if ($this->_fileNameProtection) { |
|
510 | - $this->_file = ($this->_cacheDir.'cache_'.md5($group).'_' |
|
509 | + if($this->_fileNameProtection) { |
|
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 | |
@@ -527,23 +527,23 @@ discard block |
||
527 | 527 | */ |
528 | 528 | function _read() |
529 | 529 | { |
530 | - $fp = @fopen($this->_file, "rb"); |
|
531 | - if ($this->_fileLocking) @flock($fp, LOCK_SH); |
|
532 | - if ($fp) { |
|
530 | + $fp=@fopen($this->_file, "rb"); |
|
531 | + if($this->_fileLocking) @flock($fp, LOCK_SH); |
|
532 | + if($fp) { |
|
533 | 533 | // because the filesize can be cached by PHP itself... |
534 | 534 | clearstatcache(); |
535 | - $length = @filesize($this->_file); |
|
536 | - if ($this->_readControl) { |
|
537 | - $hashControl = @fread($fp, 32); |
|
538 | - $length = $length - 32; |
|
535 | + $length=@filesize($this->_file); |
|
536 | + if($this->_readControl) { |
|
537 | + $hashControl=@fread($fp, 32); |
|
538 | + $length=$length - 32; |
|
539 | 539 | } |
540 | - $data = @fread($fp, $length); |
|
541 | - if ($this->_fileLocking) @flock($fp, LOCK_UN); |
|
540 | + $data=@fread($fp, $length); |
|
541 | + if($this->_fileLocking) @flock($fp, LOCK_UN); |
|
542 | 542 | @fclose($fp); |
543 | - if ($this->_readControl) { |
|
544 | - $hashData = $this->_hash($data, $this->_readControlType); |
|
545 | - if ($hashData != $hashControl) { |
|
546 | - @touch($this->_file, time() - 2*abs($this->_lifeTime)); |
|
543 | + if($this->_readControl) { |
|
544 | + $hashData=$this->_hash($data, $this->_readControlType); |
|
545 | + if($hashData!=$hashControl) { |
|
546 | + @touch($this->_file, time() - 2 * abs($this->_lifeTime)); |
|
547 | 547 | return false; |
548 | 548 | } |
549 | 549 | } |
@@ -562,15 +562,15 @@ discard block |
||
562 | 562 | */ |
563 | 563 | function _write($data) |
564 | 564 | { |
565 | - $fp = @fopen($this->_file, "wb"); |
|
566 | - if ($fp) { |
|
567 | - if ($this->_fileLocking) @flock($fp, LOCK_EX); |
|
568 | - if ($this->_readControl) { |
|
565 | + $fp=@fopen($this->_file, "wb"); |
|
566 | + if($fp) { |
|
567 | + if($this->_fileLocking) @flock($fp, LOCK_EX); |
|
568 | + if($this->_readControl) { |
|
569 | 569 | @fwrite($fp, $this->_hash($data, $this->_readControlType), 32); |
570 | 570 | } |
571 | - $len = strlen($data); |
|
571 | + $len=strlen($data); |
|
572 | 572 | @fwrite($fp, $data, $len); |
573 | - if ($this->_fileLocking) @flock($fp, LOCK_UN); |
|
573 | + if($this->_fileLocking) @flock($fp, LOCK_UN); |
|
574 | 574 | @fclose($fp); |
575 | 575 | return true; |
576 | 576 | } |
@@ -589,7 +589,7 @@ discard block |
||
589 | 589 | function _writeAndControl($data) |
590 | 590 | { |
591 | 591 | $this->_write($data); |
592 | - $dataRead = $this->_read($data); |
|
592 | + $dataRead=$this->_read($data); |
|
593 | 593 | return ($dataRead==$data); |
594 | 594 | } |
595 | 595 | |
@@ -603,7 +603,7 @@ discard block |
||
603 | 603 | */ |
604 | 604 | function _hash($data, $controlType) |
605 | 605 | { |
606 | - switch ($controlType) { |
|
606 | + switch($controlType) { |
|
607 | 607 | case 'md5': |
608 | 608 | return md5($data); |
609 | 609 | case 'crc32': |
@@ -224,6 +224,9 @@ discard block |
||
224 | 224 | return $v_block; |
225 | 225 | } |
226 | 226 | |
227 | + /** |
|
228 | + * @param double $p_len |
|
229 | + */ |
|
227 | 230 | private function _jumpBlock($p_len=null) |
228 | 231 | { |
229 | 232 | if (is_resource($this->_file)) { |
@@ -317,6 +320,12 @@ discard block |
||
317 | 320 | return true; |
318 | 321 | } |
319 | 322 | |
323 | + /** |
|
324 | + * @param string $p_path |
|
325 | + * @param string $p_mode |
|
326 | + * @param integer $p_file_list |
|
327 | + * @param string $p_remove_path |
|
328 | + */ |
|
320 | 329 | protected function _extractList($p_path, &$p_list_detail, $p_mode, |
321 | 330 | $p_file_list, $p_remove_path) |
322 | 331 | { |
@@ -60,14 +60,14 @@ discard block |
||
60 | 60 | */ |
61 | 61 | public function __construct($p_tarname) |
62 | 62 | { |
63 | - $this->_tarname = $p_tarname; |
|
63 | + $this->_tarname=$p_tarname; |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | public function __destruct() |
67 | 67 | { |
68 | 68 | $this->_close(); |
69 | 69 | // ----- Look for a local copy to delete |
70 | - if ($this->_temp_tarname != '') |
|
70 | + if($this->_temp_tarname!='') |
|
71 | 71 | @unlink($this->_temp_tarname); |
72 | 72 | } |
73 | 73 | |
@@ -110,11 +110,11 @@ discard block |
||
110 | 110 | */ |
111 | 111 | protected function extractModify($p_path, $p_remove_path) |
112 | 112 | { |
113 | - $v_result = true; |
|
114 | - $v_list_detail = array(); |
|
113 | + $v_result=true; |
|
114 | + $v_list_detail=array(); |
|
115 | 115 | |
116 | - if ($v_result = $this->_openRead()) { |
|
117 | - $v_result = $this->_extractList($p_path, $v_list_detail, |
|
116 | + if($v_result=$this->_openRead()) { |
|
117 | + $v_result=$this->_extractList($p_path, $v_list_detail, |
|
118 | 118 | "complete", 0, $p_remove_path); |
119 | 119 | $this->_close(); |
120 | 120 | } |
@@ -129,8 +129,8 @@ discard block |
||
129 | 129 | |
130 | 130 | private function _isArchive($p_filename=null) |
131 | 131 | { |
132 | - if ($p_filename == null) { |
|
133 | - $p_filename = $this->_tarname; |
|
132 | + if($p_filename==null) { |
|
133 | + $p_filename=$this->_tarname; |
|
134 | 134 | } |
135 | 135 | clearstatcache(); |
136 | 136 | return @is_file($p_filename); |
@@ -138,39 +138,39 @@ discard block |
||
138 | 138 | |
139 | 139 | private function _openRead() |
140 | 140 | { |
141 | - if (strtolower(substr($this->_tarname, 0, 7)) == 'http://') { |
|
141 | + if(strtolower(substr($this->_tarname, 0, 7))=='http://') { |
|
142 | 142 | |
143 | 143 | // ----- Look if a local copy need to be done |
144 | - if ($this->_temp_tarname == '') { |
|
145 | - $this->_temp_tarname = uniqid('tar').'.tmp'; |
|
146 | - if (!$v_file_from = @fopen($this->_tarname, 'rb')) { |
|
144 | + if($this->_temp_tarname=='') { |
|
145 | + $this->_temp_tarname=uniqid('tar').'.tmp'; |
|
146 | + if(!$v_file_from=@fopen($this->_tarname, 'rb')) { |
|
147 | 147 | $this->_error('Unable to open in read mode \'' |
148 | 148 | .$this->_tarname.'\''); |
149 | - $this->_temp_tarname = ''; |
|
149 | + $this->_temp_tarname=''; |
|
150 | 150 | return false; |
151 | 151 | } |
152 | - if (!$v_file_to = @fopen($this->_temp_tarname, 'wb')) { |
|
152 | + if(!$v_file_to=@fopen($this->_temp_tarname, 'wb')) { |
|
153 | 153 | $this->_error('Unable to open in write mode \'' |
154 | 154 | .$this->_temp_tarname.'\''); |
155 | - $this->_temp_tarname = ''; |
|
155 | + $this->_temp_tarname=''; |
|
156 | 156 | return false; |
157 | 157 | } |
158 | - while ($v_data = @fread($v_file_from, 1024)) |
|
158 | + while($v_data=@fread($v_file_from, 1024)) |
|
159 | 159 | @fwrite($v_file_to, $v_data); |
160 | 160 | @fclose($v_file_from); |
161 | 161 | @fclose($v_file_to); |
162 | 162 | } |
163 | 163 | |
164 | 164 | // ----- File to open if the local copy |
165 | - $v_filename = $this->_temp_tarname; |
|
165 | + $v_filename=$this->_temp_tarname; |
|
166 | 166 | |
167 | 167 | } else |
168 | 168 | // ----- File to open if the normal Tar file |
169 | - $v_filename = $this->_tarname; |
|
169 | + $v_filename=$this->_tarname; |
|
170 | 170 | |
171 | - $this->_file = @fopen($v_filename, "rb"); |
|
171 | + $this->_file=@fopen($v_filename, "rb"); |
|
172 | 172 | |
173 | - if ($this->_file == 0) { |
|
173 | + if($this->_file==0) { |
|
174 | 174 | $this->_error('Unable to open in read mode \''.$v_filename.'\''); |
175 | 175 | return false; |
176 | 176 | } |
@@ -181,17 +181,17 @@ discard block |
||
181 | 181 | private function _close() |
182 | 182 | { |
183 | 183 | //if (isset($this->_file)) { |
184 | - if (is_resource($this->_file)) |
|
184 | + if(is_resource($this->_file)) |
|
185 | 185 | { |
186 | 186 | @fclose($this->_file); |
187 | - $this->_file = 0; |
|
187 | + $this->_file=0; |
|
188 | 188 | } |
189 | 189 | |
190 | 190 | // ----- Look if a local copy need to be erase |
191 | 191 | // Note that it might be interesting to keep the url for a time : ToDo |
192 | - if ($this->_temp_tarname != '') { |
|
192 | + if($this->_temp_tarname!='') { |
|
193 | 193 | @unlink($this->_temp_tarname); |
194 | - $this->_temp_tarname = ''; |
|
194 | + $this->_temp_tarname=''; |
|
195 | 195 | } |
196 | 196 | |
197 | 197 | return true; |
@@ -202,76 +202,76 @@ discard block |
||
202 | 202 | $this->_close(); |
203 | 203 | |
204 | 204 | // ----- Look for a local copy |
205 | - if ($this->_temp_tarname != '') { |
|
205 | + if($this->_temp_tarname!='') { |
|
206 | 206 | // ----- Remove the local copy but not the remote tarname |
207 | 207 | @unlink($this->_temp_tarname); |
208 | - $this->_temp_tarname = ''; |
|
208 | + $this->_temp_tarname=''; |
|
209 | 209 | } else { |
210 | 210 | // ----- Remove the local tarname file |
211 | 211 | @unlink($this->_tarname); |
212 | 212 | } |
213 | - $this->_tarname = ''; |
|
213 | + $this->_tarname=''; |
|
214 | 214 | |
215 | 215 | return true; |
216 | 216 | } |
217 | 217 | |
218 | 218 | private function _readBlock() |
219 | 219 | { |
220 | - $v_block = null; |
|
221 | - if (is_resource($this->_file)) { |
|
222 | - $v_block = @fread($this->_file, 512); |
|
220 | + $v_block=null; |
|
221 | + if(is_resource($this->_file)) { |
|
222 | + $v_block=@fread($this->_file, 512); |
|
223 | 223 | } |
224 | 224 | return $v_block; |
225 | 225 | } |
226 | 226 | |
227 | 227 | private function _jumpBlock($p_len=null) |
228 | 228 | { |
229 | - if (is_resource($this->_file)) { |
|
230 | - if ($p_len === null) |
|
231 | - $p_len = 1; |
|
229 | + if(is_resource($this->_file)) { |
|
230 | + if($p_len===null) |
|
231 | + $p_len=1; |
|
232 | 232 | |
233 | - @fseek($this->_file, @ftell($this->_file)+($p_len*512)); |
|
233 | + @fseek($this->_file, @ftell($this->_file) + ($p_len * 512)); |
|
234 | 234 | } |
235 | 235 | return true; |
236 | 236 | } |
237 | 237 | |
238 | 238 | private function _readHeader($v_binary_data, &$v_header) |
239 | 239 | { |
240 | - if (strlen($v_binary_data)==0) { |
|
241 | - $v_header['filename'] = ''; |
|
240 | + if(strlen($v_binary_data)==0) { |
|
241 | + $v_header['filename']=''; |
|
242 | 242 | return true; |
243 | 243 | } |
244 | 244 | |
245 | - if (strlen($v_binary_data) != 512) { |
|
246 | - $v_header['filename'] = ''; |
|
245 | + if(strlen($v_binary_data)!=512) { |
|
246 | + $v_header['filename']=''; |
|
247 | 247 | $this->_error('Invalid block size : '.strlen($v_binary_data)); |
248 | 248 | return false; |
249 | 249 | } |
250 | 250 | |
251 | 251 | // ----- Calculate the checksum |
252 | - $v_checksum = 0; |
|
252 | + $v_checksum=0; |
|
253 | 253 | // ..... First part of the header |
254 | - for ($i=0; $i<148; $i++) |
|
255 | - $v_checksum+=ord(substr($v_binary_data,$i,1)); |
|
254 | + for($i=0; $i < 148; $i++) |
|
255 | + $v_checksum+=ord(substr($v_binary_data, $i, 1)); |
|
256 | 256 | // ..... Ignore the checksum value and replace it by ' ' (space) |
257 | - for ($i=148; $i<156; $i++) |
|
258 | - $v_checksum += ord(' '); |
|
257 | + for($i=148; $i < 156; $i++) |
|
258 | + $v_checksum+=ord(' '); |
|
259 | 259 | // ..... Last part of the header |
260 | - for ($i=156; $i<512; $i++) |
|
261 | - $v_checksum+=ord(substr($v_binary_data,$i,1)); |
|
260 | + for($i=156; $i < 512; $i++) |
|
261 | + $v_checksum+=ord(substr($v_binary_data, $i, 1)); |
|
262 | 262 | |
263 | - $v_data = unpack("a100filename/a8mode/a8uid/a8gid/a12size/a12mtime/" |
|
263 | + $v_data=unpack("a100filename/a8mode/a8uid/a8gid/a12size/a12mtime/" |
|
264 | 264 | ."a8checksum/a1typeflag/a100link/a6magic/a2version/" |
265 | 265 | ."a32uname/a32gname/a8devmajor/a8devminor", |
266 | 266 | $v_binary_data); |
267 | 267 | |
268 | 268 | // ----- Extract the checksum |
269 | - $v_header['checksum'] = OctDec(trim($v_data['checksum'])); |
|
270 | - if ($v_header['checksum'] != $v_checksum) { |
|
271 | - $v_header['filename'] = ''; |
|
269 | + $v_header['checksum']=OctDec(trim($v_data['checksum'])); |
|
270 | + if($v_header['checksum']!=$v_checksum) { |
|
271 | + $v_header['filename']=''; |
|
272 | 272 | |
273 | 273 | // ----- Look for last block (empty block) |
274 | - if (($v_checksum == 256) && ($v_header['checksum'] == 0)) |
|
274 | + if(($v_checksum==256) && ($v_header['checksum']==0)) |
|
275 | 275 | return true; |
276 | 276 | |
277 | 277 | $this->_error('Invalid checksum for file "'.$v_data['filename'] |
@@ -281,38 +281,38 @@ discard block |
||
281 | 281 | } |
282 | 282 | |
283 | 283 | // ----- Extract the properties |
284 | - $v_header['filename'] = trim($v_data['filename']); |
|
285 | - $v_header['mode'] = OctDec(trim($v_data['mode'])); |
|
286 | - $v_header['uid'] = OctDec(trim($v_data['uid'])); |
|
287 | - $v_header['gid'] = OctDec(trim($v_data['gid'])); |
|
288 | - $v_header['size'] = OctDec(trim($v_data['size'])); |
|
289 | - $v_header['mtime'] = OctDec(trim($v_data['mtime'])); |
|
290 | - if (($v_header['typeflag'] = $v_data['typeflag']) == "5") { |
|
291 | - $v_header['size'] = 0; |
|
284 | + $v_header['filename']=trim($v_data['filename']); |
|
285 | + $v_header['mode']=OctDec(trim($v_data['mode'])); |
|
286 | + $v_header['uid']=OctDec(trim($v_data['uid'])); |
|
287 | + $v_header['gid']=OctDec(trim($v_data['gid'])); |
|
288 | + $v_header['size']=OctDec(trim($v_data['size'])); |
|
289 | + $v_header['mtime']=OctDec(trim($v_data['mtime'])); |
|
290 | + if(($v_header['typeflag']=$v_data['typeflag'])=="5") { |
|
291 | + $v_header['size']=0; |
|
292 | 292 | } |
293 | 293 | return true; |
294 | 294 | } |
295 | 295 | |
296 | 296 | private function _readLongHeader(&$v_header) |
297 | 297 | { |
298 | - $v_filename = ''; |
|
299 | - $n = floor($v_header['size']/512); |
|
300 | - for ($i=0; $i<$n; $i++) { |
|
301 | - $v_content = $this->_readBlock(); |
|
302 | - $v_filename .= $v_content; |
|
298 | + $v_filename=''; |
|
299 | + $n=floor($v_header['size'] / 512); |
|
300 | + for($i=0; $i < $n; $i++) { |
|
301 | + $v_content=$this->_readBlock(); |
|
302 | + $v_filename.=$v_content; |
|
303 | 303 | } |
304 | - if (($v_header['size'] % 512) != 0) { |
|
305 | - $v_content = $this->_readBlock(); |
|
306 | - $v_filename .= $v_content; |
|
304 | + if(($v_header['size'] % 512)!=0) { |
|
305 | + $v_content=$this->_readBlock(); |
|
306 | + $v_filename.=$v_content; |
|
307 | 307 | } |
308 | 308 | |
309 | 309 | // ----- Read the next header |
310 | - $v_binary_data = $this->_readBlock(); |
|
310 | + $v_binary_data=$this->_readBlock(); |
|
311 | 311 | |
312 | - if (!$this->_readHeader($v_binary_data, $v_header)) |
|
312 | + if(!$this->_readHeader($v_binary_data, $v_header)) |
|
313 | 313 | return false; |
314 | 314 | |
315 | - $v_header['filename'] = $v_filename; |
|
315 | + $v_header['filename']=$v_filename; |
|
316 | 316 | |
317 | 317 | return true; |
318 | 318 | } |
@@ -321,34 +321,34 @@ discard block |
||
321 | 321 | $p_file_list, $p_remove_path) |
322 | 322 | { |
323 | 323 | $v_result=true; |
324 | - $v_nb = 0; |
|
325 | - $v_extract_all = true; |
|
326 | - $v_listing = false; |
|
327 | - |
|
328 | - $p_path = $this->_translateWinPath($p_path, false); |
|
329 | - if ($p_path == '' || (substr($p_path, 0, 1) != '/' |
|
330 | - && substr($p_path, 0, 3) != "../" && !strpos($p_path, ':'))) { |
|
331 | - $p_path = "./".$p_path; |
|
324 | + $v_nb=0; |
|
325 | + $v_extract_all=true; |
|
326 | + $v_listing=false; |
|
327 | + |
|
328 | + $p_path=$this->_translateWinPath($p_path, false); |
|
329 | + if($p_path=='' || (substr($p_path, 0, 1)!='/' |
|
330 | + && substr($p_path, 0, 3)!="../" && !strpos($p_path, ':'))) { |
|
331 | + $p_path="./".$p_path; |
|
332 | 332 | } |
333 | - $p_remove_path = $this->_translateWinPath($p_remove_path); |
|
333 | + $p_remove_path=$this->_translateWinPath($p_remove_path); |
|
334 | 334 | |
335 | 335 | // ----- Look for path to remove format (should end by /) |
336 | - if (($p_remove_path != '') && (substr($p_remove_path, -1) != '/')) |
|
337 | - $p_remove_path .= '/'; |
|
338 | - $p_remove_path_size = strlen($p_remove_path); |
|
336 | + if(($p_remove_path!='') && (substr($p_remove_path, -1)!='/')) |
|
337 | + $p_remove_path.='/'; |
|
338 | + $p_remove_path_size=strlen($p_remove_path); |
|
339 | 339 | |
340 | - switch ($p_mode) { |
|
340 | + switch($p_mode) { |
|
341 | 341 | case "complete" : |
342 | - $v_extract_all = true; |
|
343 | - $v_listing = false; |
|
342 | + $v_extract_all=true; |
|
343 | + $v_listing=false; |
|
344 | 344 | break; |
345 | 345 | case "partial" : |
346 | - $v_extract_all = false; |
|
347 | - $v_listing = false; |
|
346 | + $v_extract_all=false; |
|
347 | + $v_listing=false; |
|
348 | 348 | break; |
349 | 349 | case "list" : |
350 | - $v_extract_all = false; |
|
351 | - $v_listing = true; |
|
350 | + $v_extract_all=false; |
|
351 | + $v_listing=true; |
|
352 | 352 | break; |
353 | 353 | default : |
354 | 354 | $this->_error('Invalid extract mode ('.$p_mode.')'); |
@@ -357,103 +357,103 @@ discard block |
||
357 | 357 | |
358 | 358 | clearstatcache(); |
359 | 359 | |
360 | - while (strlen($v_binary_data = $this->_readBlock()) != 0) |
|
360 | + while(strlen($v_binary_data=$this->_readBlock())!=0) |
|
361 | 361 | { |
362 | - $v_extract_file = false; |
|
363 | - $v_extraction_stopped = 0; |
|
362 | + $v_extract_file=false; |
|
363 | + $v_extraction_stopped=0; |
|
364 | 364 | |
365 | - if (!$this->_readHeader($v_binary_data, $v_header)) |
|
365 | + if(!$this->_readHeader($v_binary_data, $v_header)) |
|
366 | 366 | return false; |
367 | 367 | |
368 | - if ($v_header['filename'] == '') { |
|
368 | + if($v_header['filename']=='') { |
|
369 | 369 | continue; |
370 | 370 | } |
371 | 371 | |
372 | 372 | // ----- Look for long filename |
373 | - if ($v_header['typeflag'] == 'L') { |
|
374 | - if (!$this->_readLongHeader($v_header)) |
|
373 | + if($v_header['typeflag']=='L') { |
|
374 | + if(!$this->_readLongHeader($v_header)) |
|
375 | 375 | return false; |
376 | 376 | } |
377 | 377 | |
378 | - if ((!$v_extract_all) && (is_array($p_file_list))) { |
|
378 | + if((!$v_extract_all) && (is_array($p_file_list))) { |
|
379 | 379 | // ----- By default no unzip if the file is not found |
380 | - $v_extract_file = false; |
|
380 | + $v_extract_file=false; |
|
381 | 381 | |
382 | - for ($i=0; $i<sizeof($p_file_list); $i++) { |
|
382 | + for($i=0; $i < sizeof($p_file_list); $i++) { |
|
383 | 383 | // ----- Look if it is a directory |
384 | - if (substr($p_file_list[$i], -1) == '/') { |
|
384 | + if(substr($p_file_list[$i], -1)=='/') { |
|
385 | 385 | // ----- Look if the directory is in the filename path |
386 | - if ((strlen($v_header['filename']) > strlen($p_file_list[$i])) |
|
386 | + if((strlen($v_header['filename']) > strlen($p_file_list[$i])) |
|
387 | 387 | && (substr($v_header['filename'], 0, strlen($p_file_list[$i])) |
388 | 388 | == $p_file_list[$i])) { |
389 | - $v_extract_file = true; |
|
389 | + $v_extract_file=true; |
|
390 | 390 | break; |
391 | 391 | } |
392 | 392 | } |
393 | 393 | |
394 | 394 | // ----- It is a file, so compare the file names |
395 | - elseif ($p_file_list[$i] == $v_header['filename']) { |
|
396 | - $v_extract_file = true; |
|
395 | + elseif($p_file_list[$i]==$v_header['filename']) { |
|
396 | + $v_extract_file=true; |
|
397 | 397 | break; |
398 | 398 | } |
399 | 399 | } |
400 | 400 | } else { |
401 | - $v_extract_file = true; |
|
401 | + $v_extract_file=true; |
|
402 | 402 | } |
403 | 403 | |
404 | 404 | // ----- Look if this file need to be extracted |
405 | - if (($v_extract_file) && (!$v_listing)) |
|
405 | + if(($v_extract_file) && (!$v_listing)) |
|
406 | 406 | { |
407 | - if (($p_remove_path != '') |
|
407 | + if(($p_remove_path!='') |
|
408 | 408 | && (substr($v_header['filename'], 0, $p_remove_path_size) |
409 | 409 | == $p_remove_path)) |
410 | - $v_header['filename'] = substr($v_header['filename'], |
|
410 | + $v_header['filename']=substr($v_header['filename'], |
|
411 | 411 | $p_remove_path_size); |
412 | - if (($p_path != './') && ($p_path != '/')) { |
|
413 | - while (substr($p_path, -1) == '/') |
|
414 | - $p_path = substr($p_path, 0, strlen($p_path)-1); |
|
412 | + if(($p_path!='./') && ($p_path!='/')) { |
|
413 | + while(substr($p_path, -1)=='/') |
|
414 | + $p_path=substr($p_path, 0, strlen($p_path) - 1); |
|
415 | 415 | |
416 | - if (substr($v_header['filename'], 0, 1) == '/') |
|
417 | - $v_header['filename'] = $p_path.$v_header['filename']; |
|
416 | + if(substr($v_header['filename'], 0, 1)=='/') |
|
417 | + $v_header['filename']=$p_path.$v_header['filename']; |
|
418 | 418 | else |
419 | - $v_header['filename'] = $p_path.'/'.$v_header['filename']; |
|
419 | + $v_header['filename']=$p_path.'/'.$v_header['filename']; |
|
420 | 420 | } |
421 | - if (file_exists($v_header['filename'])) { |
|
422 | - if ( (@is_dir($v_header['filename'])) |
|
423 | - && ($v_header['typeflag'] == '')) { |
|
421 | + if(file_exists($v_header['filename'])) { |
|
422 | + if((@is_dir($v_header['filename'])) |
|
423 | + && ($v_header['typeflag']=='')) { |
|
424 | 424 | $this->_error('File '.$v_header['filename'] |
425 | 425 | .' already exists as a directory'); |
426 | 426 | return false; |
427 | 427 | } |
428 | - if ( ($this->_isArchive($v_header['filename'])) |
|
429 | - && ($v_header['typeflag'] == "5")) { |
|
428 | + if(($this->_isArchive($v_header['filename'])) |
|
429 | + && ($v_header['typeflag']=="5")) { |
|
430 | 430 | $this->_error('Directory '.$v_header['filename'] |
431 | 431 | .' already exists as a file'); |
432 | 432 | return false; |
433 | 433 | } |
434 | - if (!is_writeable($v_header['filename'])) { |
|
434 | + if(!is_writeable($v_header['filename'])) { |
|
435 | 435 | $this->_error('File '.$v_header['filename'] |
436 | 436 | .' already exists and is write protected'); |
437 | 437 | return false; |
438 | 438 | } |
439 | - if (filemtime($v_header['filename']) > $v_header['mtime']) { |
|
439 | + if(filemtime($v_header['filename']) > $v_header['mtime']) { |
|
440 | 440 | // To be completed : An error or silent no replace ? |
441 | 441 | } |
442 | 442 | } |
443 | 443 | |
444 | 444 | // ----- Check the directory availability and create it if necessary |
445 | - elseif (($v_result |
|
446 | - = $this->_dirCheck(($v_header['typeflag'] == "5" |
|
447 | - ?$v_header['filename'] |
|
448 | - :dirname($v_header['filename'])))) != 1) { |
|
445 | + elseif(($v_result |
|
446 | + = $this->_dirCheck(($v_header['typeflag']=="5" |
|
447 | + ? $v_header['filename'] |
|
448 | + :dirname($v_header['filename']))))!=1) { |
|
449 | 449 | $this->_error('Unable to create path for '.$v_header['filename']); |
450 | 450 | return false; |
451 | 451 | } |
452 | 452 | |
453 | - if ($v_extract_file) { |
|
454 | - if ($v_header['typeflag'] == "5") { |
|
455 | - if (!@file_exists($v_header['filename'])) { |
|
456 | - if (!@mkdir($v_header['filename'], PRADO_CHMOD)) { |
|
453 | + if($v_extract_file) { |
|
454 | + if($v_header['typeflag']=="5") { |
|
455 | + if(!@file_exists($v_header['filename'])) { |
|
456 | + if(!@mkdir($v_header['filename'], PRADO_CHMOD)) { |
|
457 | 457 | $this->_error('Unable to create directory {' |
458 | 458 | .$v_header['filename'].'}'); |
459 | 459 | return false; |
@@ -461,18 +461,18 @@ discard block |
||
461 | 461 | chmod($v_header['filename'], PRADO_CHMOD); |
462 | 462 | } |
463 | 463 | } else { |
464 | - if (($v_dest_file = @fopen($v_header['filename'], "wb")) == 0) { |
|
464 | + if(($v_dest_file=@fopen($v_header['filename'], "wb"))==0) { |
|
465 | 465 | $this->_error('Error while opening {'.$v_header['filename'] |
466 | 466 | .'} in write binary mode'); |
467 | 467 | return false; |
468 | 468 | } else { |
469 | - $n = floor($v_header['size']/512); |
|
470 | - for ($i=0; $i<$n; $i++) { |
|
471 | - $v_content = $this->_readBlock(); |
|
469 | + $n=floor($v_header['size'] / 512); |
|
470 | + for($i=0; $i < $n; $i++) { |
|
471 | + $v_content=$this->_readBlock(); |
|
472 | 472 | fwrite($v_dest_file, $v_content, 512); |
473 | 473 | } |
474 | - if (($v_header['size'] % 512) != 0) { |
|
475 | - $v_content = $this->_readBlock(); |
|
474 | + if(($v_header['size'] % 512)!=0) { |
|
475 | + $v_content=$this->_readBlock(); |
|
476 | 476 | fwrite($v_dest_file, $v_content, ($v_header['size'] % 512)); |
477 | 477 | } |
478 | 478 | |
@@ -486,7 +486,7 @@ discard block |
||
486 | 486 | |
487 | 487 | // ----- Check the file size |
488 | 488 | clearstatcache(); |
489 | - if (filesize($v_header['filename']) != $v_header['size']) { |
|
489 | + if(filesize($v_header['filename'])!=$v_header['size']) { |
|
490 | 490 | $this->_error('Extracted file '.$v_header['filename'] |
491 | 491 | .' does not have the correct file size \'' |
492 | 492 | .filesize($v_header['filename']) |
@@ -496,10 +496,10 @@ discard block |
||
496 | 496 | } |
497 | 497 | } |
498 | 498 | } else { |
499 | - $this->_jumpBlock(ceil(($v_header['size']/512))); |
|
499 | + $this->_jumpBlock(ceil(($v_header['size'] / 512))); |
|
500 | 500 | } |
501 | 501 | } else { |
502 | - $this->_jumpBlock(ceil(($v_header['size']/512))); |
|
502 | + $this->_jumpBlock(ceil(($v_header['size'] / 512))); |
|
503 | 503 | } |
504 | 504 | |
505 | 505 | /* TBC : Seems to be unused ... |
@@ -509,15 +509,15 @@ discard block |
||
509 | 509 | $v_end_of_file = @feof($this->_file); |
510 | 510 | */ |
511 | 511 | |
512 | - if ($v_listing || $v_extract_file || $v_extraction_stopped) { |
|
512 | + if($v_listing || $v_extract_file || $v_extraction_stopped) { |
|
513 | 513 | // ----- Log extracted files |
514 | - if (($v_file_dir = dirname($v_header['filename'])) |
|
514 | + if(($v_file_dir=dirname($v_header['filename'])) |
|
515 | 515 | == $v_header['filename']) |
516 | - $v_file_dir = ''; |
|
517 | - if ((substr($v_header['filename'], 0, 1) == '/') && ($v_file_dir == '')) |
|
518 | - $v_file_dir = '/'; |
|
516 | + $v_file_dir=''; |
|
517 | + if((substr($v_header['filename'], 0, 1)=='/') && ($v_file_dir=='')) |
|
518 | + $v_file_dir='/'; |
|
519 | 519 | |
520 | - $p_list_detail[$v_nb++] = $v_header; |
|
520 | + $p_list_detail[$v_nb++]=$v_header; |
|
521 | 521 | } |
522 | 522 | } |
523 | 523 | |
@@ -534,36 +534,36 @@ discard block |
||
534 | 534 | */ |
535 | 535 | protected function _dirCheck($p_dir) |
536 | 536 | { |
537 | - if ((@is_dir($p_dir)) || ($p_dir == '')) |
|
537 | + if((@is_dir($p_dir)) || ($p_dir=='')) |
|
538 | 538 | return true; |
539 | 539 | |
540 | - $p_parent_dir = dirname($p_dir); |
|
540 | + $p_parent_dir=dirname($p_dir); |
|
541 | 541 | |
542 | - if (($p_parent_dir != $p_dir) && |
|
543 | - ($p_parent_dir != '') && |
|
542 | + if(($p_parent_dir!=$p_dir) && |
|
543 | + ($p_parent_dir!='') && |
|
544 | 544 | (!$this->_dirCheck($p_parent_dir))) |
545 | 545 | return false; |
546 | 546 | |
547 | - if (!@mkdir($p_dir, PRADO_CHMOD)) { |
|
547 | + if(!@mkdir($p_dir, PRADO_CHMOD)) { |
|
548 | 548 | $this->_error("Unable to create directory '$p_dir'"); |
549 | 549 | return false; |
550 | 550 | } |
551 | - chmod($p_dir,PRADO_CHMOD); |
|
551 | + chmod($p_dir, PRADO_CHMOD); |
|
552 | 552 | |
553 | 553 | return true; |
554 | 554 | } |
555 | 555 | |
556 | 556 | protected function _translateWinPath($p_path, $p_remove_disk_letter=true) |
557 | 557 | { |
558 | - if (substr(PHP_OS, 0, 3) == 'WIN') { |
|
558 | + if(substr(PHP_OS, 0, 3)=='WIN') { |
|
559 | 559 | // ----- Look for potential disk letter |
560 | - if ( ($p_remove_disk_letter) |
|
561 | - && (($v_position = strpos($p_path, ':')) != false)) { |
|
562 | - $p_path = substr($p_path, $v_position+1); |
|
560 | + if(($p_remove_disk_letter) |
|
561 | + && (($v_position=strpos($p_path, ':'))!=false)) { |
|
562 | + $p_path=substr($p_path, $v_position + 1); |
|
563 | 563 | } |
564 | 564 | // ----- Change potential windows directory separator |
565 | - if ((strpos($p_path, '\\') > 0) || (substr($p_path, 0,1) == '\\')) { |
|
566 | - $p_path = strtr($p_path, '\\', '/'); |
|
565 | + if((strpos($p_path, '\\') > 0) || (substr($p_path, 0, 1)=='\\')) { |
|
566 | + $p_path=strtr($p_path, '\\', '/'); |
|
567 | 567 | } |
568 | 568 | } |
569 | 569 | return $p_path; |
@@ -155,8 +155,9 @@ discard block |
||
155 | 155 | $this->_temp_tarname = ''; |
156 | 156 | return false; |
157 | 157 | } |
158 | - while ($v_data = @fread($v_file_from, 1024)) |
|
159 | - @fwrite($v_file_to, $v_data); |
|
158 | + while ($v_data = @fread($v_file_from, 1024)) { |
|
159 | + @fwrite($v_file_to, $v_data); |
|
160 | + } |
|
160 | 161 | @fclose($v_file_from); |
161 | 162 | @fclose($v_file_to); |
162 | 163 | } |
@@ -410,8 +411,9 @@ discard block |
||
410 | 411 | $v_header['filename'] = substr($v_header['filename'], |
411 | 412 | $p_remove_path_size); |
412 | 413 | if (($p_path != './') && ($p_path != '/')) { |
413 | - while (substr($p_path, -1) == '/') |
|
414 | - $p_path = substr($p_path, 0, strlen($p_path)-1); |
|
414 | + while (substr($p_path, -1) == '/') { |
|
415 | + $p_path = substr($p_path, 0, strlen($p_path)-1); |
|
416 | + } |
|
415 | 417 | |
416 | 418 | if (substr($v_header['filename'], 0, 1) == '/') |
417 | 419 | $v_header['filename'] = $p_path.$v_header['filename']; |
@@ -37,537 +37,537 @@ |
||
37 | 37 | */ |
38 | 38 | class TTarFileExtractor |
39 | 39 | { |
40 | - /** |
|
41 | - * @var string Name of the Tar |
|
42 | - */ |
|
43 | - private $_tarname=''; |
|
44 | - |
|
45 | - /** |
|
46 | - * @var file descriptor |
|
47 | - */ |
|
48 | - private $_file=0; |
|
49 | - |
|
50 | - /** |
|
51 | - * @var string Local Tar name of a remote Tar (http:// or ftp://) |
|
52 | - */ |
|
53 | - private $_temp_tarname=''; |
|
54 | - |
|
55 | - /** |
|
56 | - * Archive_Tar Class constructor. This flavour of the constructor only |
|
57 | - * declare a new Archive_Tar object, identifying it by the name of the |
|
58 | - * tar file. |
|
59 | - * |
|
60 | - * @param string $p_tarname The name of the tar archive to create |
|
61 | - * @access public |
|
62 | - */ |
|
63 | - public function __construct($p_tarname) |
|
64 | - { |
|
65 | - $this->_tarname = $p_tarname; |
|
66 | - } |
|
67 | - |
|
68 | - public function __destruct() |
|
69 | - { |
|
70 | - $this->_close(); |
|
71 | - // ----- Look for a local copy to delete |
|
72 | - if ($this->_temp_tarname != '') |
|
73 | - @unlink($this->_temp_tarname); |
|
74 | - } |
|
75 | - |
|
76 | - public function extract($p_path='') |
|
77 | - { |
|
78 | - return $this->extractModify($p_path, ''); |
|
79 | - } |
|
80 | - |
|
81 | - /** |
|
82 | - * This method extract all the content of the archive in the directory |
|
83 | - * indicated by $p_path. When relevant the memorized path of the |
|
84 | - * files/dir can be modified by removing the $p_remove_path path at the |
|
85 | - * beginning of the file/dir path. |
|
86 | - * While extracting a file, if the directory path does not exists it is |
|
87 | - * created. |
|
88 | - * While extracting a file, if the file already exists it is replaced |
|
89 | - * without looking for last modification date. |
|
90 | - * While extracting a file, if the file already exists and is write |
|
91 | - * protected, the extraction is aborted. |
|
92 | - * While extracting a file, if a directory with the same name already |
|
93 | - * exists, the extraction is aborted. |
|
94 | - * While extracting a directory, if a file with the same name already |
|
95 | - * exists, the extraction is aborted. |
|
96 | - * While extracting a file/directory if the destination directory exist |
|
97 | - * and is write protected, or does not exist but can not be created, |
|
98 | - * the extraction is aborted. |
|
99 | - * If after extraction an extracted file does not show the correct |
|
100 | - * stored file size, the extraction is aborted. |
|
101 | - * When the extraction is aborted, a PEAR error text is set and false |
|
102 | - * is returned. However the result can be a partial extraction that may |
|
103 | - * need to be manually cleaned. |
|
104 | - * |
|
105 | - * @param string $p_path The path of the directory where the |
|
106 | - * files/dir need to by extracted. |
|
107 | - * @param string $p_remove_path Part of the memorized path that can be |
|
108 | - * removed if present at the beginning of |
|
109 | - * the file/dir path. |
|
110 | - * @return boolean true on success, false on error. |
|
111 | - * @access public |
|
112 | - */ |
|
113 | - protected function extractModify($p_path, $p_remove_path) |
|
114 | - { |
|
115 | - $v_result = true; |
|
116 | - $v_list_detail = array(); |
|
117 | - |
|
118 | - if ($v_result = $this->_openRead()) { |
|
119 | - $v_result = $this->_extractList($p_path, $v_list_detail, |
|
120 | - "complete", 0, $p_remove_path); |
|
121 | - $this->_close(); |
|
122 | - } |
|
123 | - |
|
124 | - return $v_result; |
|
125 | - } |
|
126 | - |
|
127 | - protected function _error($p_message) |
|
128 | - { |
|
40 | + /** |
|
41 | + * @var string Name of the Tar |
|
42 | + */ |
|
43 | + private $_tarname=''; |
|
44 | + |
|
45 | + /** |
|
46 | + * @var file descriptor |
|
47 | + */ |
|
48 | + private $_file=0; |
|
49 | + |
|
50 | + /** |
|
51 | + * @var string Local Tar name of a remote Tar (http:// or ftp://) |
|
52 | + */ |
|
53 | + private $_temp_tarname=''; |
|
54 | + |
|
55 | + /** |
|
56 | + * Archive_Tar Class constructor. This flavour of the constructor only |
|
57 | + * declare a new Archive_Tar object, identifying it by the name of the |
|
58 | + * tar file. |
|
59 | + * |
|
60 | + * @param string $p_tarname The name of the tar archive to create |
|
61 | + * @access public |
|
62 | + */ |
|
63 | + public function __construct($p_tarname) |
|
64 | + { |
|
65 | + $this->_tarname = $p_tarname; |
|
66 | + } |
|
67 | + |
|
68 | + public function __destruct() |
|
69 | + { |
|
70 | + $this->_close(); |
|
71 | + // ----- Look for a local copy to delete |
|
72 | + if ($this->_temp_tarname != '') |
|
73 | + @unlink($this->_temp_tarname); |
|
74 | + } |
|
75 | + |
|
76 | + public function extract($p_path='') |
|
77 | + { |
|
78 | + return $this->extractModify($p_path, ''); |
|
79 | + } |
|
80 | + |
|
81 | + /** |
|
82 | + * This method extract all the content of the archive in the directory |
|
83 | + * indicated by $p_path. When relevant the memorized path of the |
|
84 | + * files/dir can be modified by removing the $p_remove_path path at the |
|
85 | + * beginning of the file/dir path. |
|
86 | + * While extracting a file, if the directory path does not exists it is |
|
87 | + * created. |
|
88 | + * While extracting a file, if the file already exists it is replaced |
|
89 | + * without looking for last modification date. |
|
90 | + * While extracting a file, if the file already exists and is write |
|
91 | + * protected, the extraction is aborted. |
|
92 | + * While extracting a file, if a directory with the same name already |
|
93 | + * exists, the extraction is aborted. |
|
94 | + * While extracting a directory, if a file with the same name already |
|
95 | + * exists, the extraction is aborted. |
|
96 | + * While extracting a file/directory if the destination directory exist |
|
97 | + * and is write protected, or does not exist but can not be created, |
|
98 | + * the extraction is aborted. |
|
99 | + * If after extraction an extracted file does not show the correct |
|
100 | + * stored file size, the extraction is aborted. |
|
101 | + * When the extraction is aborted, a PEAR error text is set and false |
|
102 | + * is returned. However the result can be a partial extraction that may |
|
103 | + * need to be manually cleaned. |
|
104 | + * |
|
105 | + * @param string $p_path The path of the directory where the |
|
106 | + * files/dir need to by extracted. |
|
107 | + * @param string $p_remove_path Part of the memorized path that can be |
|
108 | + * removed if present at the beginning of |
|
109 | + * the file/dir path. |
|
110 | + * @return boolean true on success, false on error. |
|
111 | + * @access public |
|
112 | + */ |
|
113 | + protected function extractModify($p_path, $p_remove_path) |
|
114 | + { |
|
115 | + $v_result = true; |
|
116 | + $v_list_detail = array(); |
|
117 | + |
|
118 | + if ($v_result = $this->_openRead()) { |
|
119 | + $v_result = $this->_extractList($p_path, $v_list_detail, |
|
120 | + "complete", 0, $p_remove_path); |
|
121 | + $this->_close(); |
|
122 | + } |
|
123 | + |
|
124 | + return $v_result; |
|
125 | + } |
|
126 | + |
|
127 | + protected function _error($p_message) |
|
128 | + { |
|
129 | 129 | throw new \Exception($p_message); |
130 | - } |
|
131 | - |
|
132 | - private function _isArchive($p_filename=null) |
|
133 | - { |
|
134 | - if ($p_filename == null) { |
|
135 | - $p_filename = $this->_tarname; |
|
136 | - } |
|
137 | - clearstatcache(); |
|
138 | - return @is_file($p_filename); |
|
139 | - } |
|
140 | - |
|
141 | - private function _openRead() |
|
142 | - { |
|
143 | - if (strtolower(substr($this->_tarname, 0, 7)) == 'http://') { |
|
144 | - |
|
145 | - // ----- Look if a local copy need to be done |
|
146 | - if ($this->_temp_tarname == '') { |
|
147 | - $this->_temp_tarname = uniqid('tar').'.tmp'; |
|
148 | - if (!$v_file_from = @fopen($this->_tarname, 'rb')) { |
|
149 | - $this->_error('Unable to open in read mode \'' |
|
150 | - .$this->_tarname.'\''); |
|
151 | - $this->_temp_tarname = ''; |
|
152 | - return false; |
|
153 | - } |
|
154 | - if (!$v_file_to = @fopen($this->_temp_tarname, 'wb')) { |
|
155 | - $this->_error('Unable to open in write mode \'' |
|
156 | - .$this->_temp_tarname.'\''); |
|
157 | - $this->_temp_tarname = ''; |
|
158 | - return false; |
|
159 | - } |
|
160 | - while ($v_data = @fread($v_file_from, 1024)) |
|
161 | - @fwrite($v_file_to, $v_data); |
|
162 | - @fclose($v_file_from); |
|
163 | - @fclose($v_file_to); |
|
164 | - } |
|
165 | - |
|
166 | - // ----- File to open if the local copy |
|
167 | - $v_filename = $this->_temp_tarname; |
|
168 | - |
|
169 | - } else |
|
170 | - // ----- File to open if the normal Tar file |
|
171 | - $v_filename = $this->_tarname; |
|
130 | + } |
|
131 | + |
|
132 | + private function _isArchive($p_filename=null) |
|
133 | + { |
|
134 | + if ($p_filename == null) { |
|
135 | + $p_filename = $this->_tarname; |
|
136 | + } |
|
137 | + clearstatcache(); |
|
138 | + return @is_file($p_filename); |
|
139 | + } |
|
140 | + |
|
141 | + private function _openRead() |
|
142 | + { |
|
143 | + if (strtolower(substr($this->_tarname, 0, 7)) == 'http://') { |
|
144 | + |
|
145 | + // ----- Look if a local copy need to be done |
|
146 | + if ($this->_temp_tarname == '') { |
|
147 | + $this->_temp_tarname = uniqid('tar').'.tmp'; |
|
148 | + if (!$v_file_from = @fopen($this->_tarname, 'rb')) { |
|
149 | + $this->_error('Unable to open in read mode \'' |
|
150 | + .$this->_tarname.'\''); |
|
151 | + $this->_temp_tarname = ''; |
|
152 | + return false; |
|
153 | + } |
|
154 | + if (!$v_file_to = @fopen($this->_temp_tarname, 'wb')) { |
|
155 | + $this->_error('Unable to open in write mode \'' |
|
156 | + .$this->_temp_tarname.'\''); |
|
157 | + $this->_temp_tarname = ''; |
|
158 | + return false; |
|
159 | + } |
|
160 | + while ($v_data = @fread($v_file_from, 1024)) |
|
161 | + @fwrite($v_file_to, $v_data); |
|
162 | + @fclose($v_file_from); |
|
163 | + @fclose($v_file_to); |
|
164 | + } |
|
165 | + |
|
166 | + // ----- File to open if the local copy |
|
167 | + $v_filename = $this->_temp_tarname; |
|
168 | + |
|
169 | + } else |
|
170 | + // ----- File to open if the normal Tar file |
|
171 | + $v_filename = $this->_tarname; |
|
172 | 172 | |
173 | 173 | $this->_file = @fopen($v_filename, "rb"); |
174 | 174 | |
175 | - if ($this->_file == 0) { |
|
176 | - $this->_error('Unable to open in read mode \''.$v_filename.'\''); |
|
177 | - return false; |
|
178 | - } |
|
175 | + if ($this->_file == 0) { |
|
176 | + $this->_error('Unable to open in read mode \''.$v_filename.'\''); |
|
177 | + return false; |
|
178 | + } |
|
179 | 179 | |
180 | - return true; |
|
181 | - } |
|
180 | + return true; |
|
181 | + } |
|
182 | 182 | |
183 | - private function _close() |
|
184 | - { |
|
185 | - //if (isset($this->_file)) { |
|
186 | - if (is_resource($this->_file)) |
|
183 | + private function _close() |
|
184 | + { |
|
185 | + //if (isset($this->_file)) { |
|
186 | + if (is_resource($this->_file)) |
|
187 | 187 | { |
188 | - @fclose($this->_file); |
|
189 | - $this->_file = 0; |
|
190 | - } |
|
191 | - |
|
192 | - // ----- Look if a local copy need to be erase |
|
193 | - // Note that it might be interesting to keep the url for a time : ToDo |
|
194 | - if ($this->_temp_tarname != '') { |
|
195 | - @unlink($this->_temp_tarname); |
|
196 | - $this->_temp_tarname = ''; |
|
197 | - } |
|
198 | - |
|
199 | - return true; |
|
200 | - } |
|
201 | - |
|
202 | - private function _cleanFile() |
|
203 | - { |
|
204 | - $this->_close(); |
|
205 | - |
|
206 | - // ----- Look for a local copy |
|
207 | - if ($this->_temp_tarname != '') { |
|
208 | - // ----- Remove the local copy but not the remote tarname |
|
209 | - @unlink($this->_temp_tarname); |
|
210 | - $this->_temp_tarname = ''; |
|
211 | - } else { |
|
212 | - // ----- Remove the local tarname file |
|
213 | - @unlink($this->_tarname); |
|
214 | - } |
|
215 | - $this->_tarname = ''; |
|
216 | - |
|
217 | - return true; |
|
218 | - } |
|
219 | - |
|
220 | - private function _readBlock() |
|
221 | - { |
|
222 | - $v_block = null; |
|
223 | - if (is_resource($this->_file)) { |
|
224 | - $v_block = @fread($this->_file, 512); |
|
225 | - } |
|
226 | - return $v_block; |
|
227 | - } |
|
228 | - |
|
229 | - private function _jumpBlock($p_len=null) |
|
230 | - { |
|
231 | - if (is_resource($this->_file)) { |
|
232 | - if ($p_len === null) |
|
233 | - $p_len = 1; |
|
234 | - |
|
235 | - @fseek($this->_file, @ftell($this->_file)+($p_len*512)); |
|
236 | - } |
|
237 | - return true; |
|
238 | - } |
|
239 | - |
|
240 | - private function _readHeader($v_binary_data, &$v_header) |
|
241 | - { |
|
242 | - if (strlen($v_binary_data)==0) { |
|
243 | - $v_header['filename'] = ''; |
|
244 | - return true; |
|
245 | - } |
|
246 | - |
|
247 | - if (strlen($v_binary_data) != 512) { |
|
248 | - $v_header['filename'] = ''; |
|
249 | - $this->_error('Invalid block size : '.strlen($v_binary_data)); |
|
250 | - return false; |
|
251 | - } |
|
252 | - |
|
253 | - // ----- Calculate the checksum |
|
254 | - $v_checksum = 0; |
|
255 | - // ..... First part of the header |
|
256 | - for ($i=0; $i<148; $i++) |
|
257 | - $v_checksum+=ord(substr($v_binary_data,$i,1)); |
|
258 | - // ..... Ignore the checksum value and replace it by ' ' (space) |
|
259 | - for ($i=148; $i<156; $i++) |
|
260 | - $v_checksum += ord(' '); |
|
261 | - // ..... Last part of the header |
|
262 | - for ($i=156; $i<512; $i++) |
|
263 | - $v_checksum+=ord(substr($v_binary_data,$i,1)); |
|
264 | - |
|
265 | - $v_data = unpack("a100filename/a8mode/a8uid/a8gid/a12size/a12mtime/" |
|
266 | - ."a8checksum/a1typeflag/a100link/a6magic/a2version/" |
|
188 | + @fclose($this->_file); |
|
189 | + $this->_file = 0; |
|
190 | + } |
|
191 | + |
|
192 | + // ----- Look if a local copy need to be erase |
|
193 | + // Note that it might be interesting to keep the url for a time : ToDo |
|
194 | + if ($this->_temp_tarname != '') { |
|
195 | + @unlink($this->_temp_tarname); |
|
196 | + $this->_temp_tarname = ''; |
|
197 | + } |
|
198 | + |
|
199 | + return true; |
|
200 | + } |
|
201 | + |
|
202 | + private function _cleanFile() |
|
203 | + { |
|
204 | + $this->_close(); |
|
205 | + |
|
206 | + // ----- Look for a local copy |
|
207 | + if ($this->_temp_tarname != '') { |
|
208 | + // ----- Remove the local copy but not the remote tarname |
|
209 | + @unlink($this->_temp_tarname); |
|
210 | + $this->_temp_tarname = ''; |
|
211 | + } else { |
|
212 | + // ----- Remove the local tarname file |
|
213 | + @unlink($this->_tarname); |
|
214 | + } |
|
215 | + $this->_tarname = ''; |
|
216 | + |
|
217 | + return true; |
|
218 | + } |
|
219 | + |
|
220 | + private function _readBlock() |
|
221 | + { |
|
222 | + $v_block = null; |
|
223 | + if (is_resource($this->_file)) { |
|
224 | + $v_block = @fread($this->_file, 512); |
|
225 | + } |
|
226 | + return $v_block; |
|
227 | + } |
|
228 | + |
|
229 | + private function _jumpBlock($p_len=null) |
|
230 | + { |
|
231 | + if (is_resource($this->_file)) { |
|
232 | + if ($p_len === null) |
|
233 | + $p_len = 1; |
|
234 | + |
|
235 | + @fseek($this->_file, @ftell($this->_file)+($p_len*512)); |
|
236 | + } |
|
237 | + return true; |
|
238 | + } |
|
239 | + |
|
240 | + private function _readHeader($v_binary_data, &$v_header) |
|
241 | + { |
|
242 | + if (strlen($v_binary_data)==0) { |
|
243 | + $v_header['filename'] = ''; |
|
244 | + return true; |
|
245 | + } |
|
246 | + |
|
247 | + if (strlen($v_binary_data) != 512) { |
|
248 | + $v_header['filename'] = ''; |
|
249 | + $this->_error('Invalid block size : '.strlen($v_binary_data)); |
|
250 | + return false; |
|
251 | + } |
|
252 | + |
|
253 | + // ----- Calculate the checksum |
|
254 | + $v_checksum = 0; |
|
255 | + // ..... First part of the header |
|
256 | + for ($i=0; $i<148; $i++) |
|
257 | + $v_checksum+=ord(substr($v_binary_data,$i,1)); |
|
258 | + // ..... Ignore the checksum value and replace it by ' ' (space) |
|
259 | + for ($i=148; $i<156; $i++) |
|
260 | + $v_checksum += ord(' '); |
|
261 | + // ..... Last part of the header |
|
262 | + for ($i=156; $i<512; $i++) |
|
263 | + $v_checksum+=ord(substr($v_binary_data,$i,1)); |
|
264 | + |
|
265 | + $v_data = unpack("a100filename/a8mode/a8uid/a8gid/a12size/a12mtime/" |
|
266 | + ."a8checksum/a1typeflag/a100link/a6magic/a2version/" |
|
267 | 267 | ."a32uname/a32gname/a8devmajor/a8devminor", |
268 | 268 | $v_binary_data); |
269 | 269 | |
270 | - // ----- Extract the checksum |
|
271 | - $v_header['checksum'] = OctDec(trim($v_data['checksum'])); |
|
272 | - if ($v_header['checksum'] != $v_checksum) { |
|
273 | - $v_header['filename'] = ''; |
|
270 | + // ----- Extract the checksum |
|
271 | + $v_header['checksum'] = OctDec(trim($v_data['checksum'])); |
|
272 | + if ($v_header['checksum'] != $v_checksum) { |
|
273 | + $v_header['filename'] = ''; |
|
274 | 274 | |
275 | - // ----- Look for last block (empty block) |
|
276 | - if (($v_checksum == 256) && ($v_header['checksum'] == 0)) |
|
277 | - return true; |
|
275 | + // ----- Look for last block (empty block) |
|
276 | + if (($v_checksum == 256) && ($v_header['checksum'] == 0)) |
|
277 | + return true; |
|
278 | 278 | |
279 | - $this->_error('Invalid checksum for file "'.$v_data['filename'] |
|
280 | - .'" : '.$v_checksum.' calculated, ' |
|
279 | + $this->_error('Invalid checksum for file "'.$v_data['filename'] |
|
280 | + .'" : '.$v_checksum.' calculated, ' |
|
281 | 281 | .$v_header['checksum'].' expected'); |
282 | - return false; |
|
283 | - } |
|
284 | - |
|
285 | - // ----- Extract the properties |
|
286 | - $v_header['filename'] = trim($v_data['filename']); |
|
287 | - $v_header['mode'] = OctDec(trim($v_data['mode'])); |
|
288 | - $v_header['uid'] = OctDec(trim($v_data['uid'])); |
|
289 | - $v_header['gid'] = OctDec(trim($v_data['gid'])); |
|
290 | - $v_header['size'] = OctDec(trim($v_data['size'])); |
|
291 | - $v_header['mtime'] = OctDec(trim($v_data['mtime'])); |
|
292 | - if (($v_header['typeflag'] = $v_data['typeflag']) == "5") { |
|
293 | - $v_header['size'] = 0; |
|
294 | - } |
|
295 | - return true; |
|
296 | - } |
|
297 | - |
|
298 | - private function _readLongHeader(&$v_header) |
|
299 | - { |
|
300 | - $v_filename = ''; |
|
301 | - $n = floor($v_header['size']/512); |
|
302 | - for ($i=0; $i<$n; $i++) { |
|
303 | - $v_content = $this->_readBlock(); |
|
304 | - $v_filename .= $v_content; |
|
305 | - } |
|
306 | - if (($v_header['size'] % 512) != 0) { |
|
307 | - $v_content = $this->_readBlock(); |
|
308 | - $v_filename .= $v_content; |
|
309 | - } |
|
310 | - |
|
311 | - // ----- Read the next header |
|
312 | - $v_binary_data = $this->_readBlock(); |
|
313 | - |
|
314 | - if (!$this->_readHeader($v_binary_data, $v_header)) |
|
315 | - return false; |
|
316 | - |
|
317 | - $v_header['filename'] = $v_filename; |
|
318 | - |
|
319 | - return true; |
|
320 | - } |
|
321 | - |
|
322 | - protected function _extractList($p_path, &$p_list_detail, $p_mode, |
|
323 | - $p_file_list, $p_remove_path) |
|
324 | - { |
|
325 | - $v_result=true; |
|
326 | - $v_nb = 0; |
|
327 | - $v_extract_all = true; |
|
328 | - $v_listing = false; |
|
329 | - |
|
330 | - $p_path = $this->_translateWinPath($p_path, false); |
|
331 | - if ($p_path == '' || (substr($p_path, 0, 1) != '/' |
|
332 | - && substr($p_path, 0, 3) != "../" && !strpos($p_path, ':'))) { |
|
333 | - $p_path = "./".$p_path; |
|
334 | - } |
|
335 | - $p_remove_path = $this->_translateWinPath($p_remove_path); |
|
336 | - |
|
337 | - // ----- Look for path to remove format (should end by /) |
|
338 | - if (($p_remove_path != '') && (substr($p_remove_path, -1) != '/')) |
|
339 | - $p_remove_path .= '/'; |
|
340 | - $p_remove_path_size = strlen($p_remove_path); |
|
341 | - |
|
342 | - switch ($p_mode) { |
|
343 | - case "complete" : |
|
344 | - $v_extract_all = true; |
|
345 | - $v_listing = false; |
|
346 | - break; |
|
347 | - case "partial" : |
|
348 | - $v_extract_all = false; |
|
349 | - $v_listing = false; |
|
350 | - break; |
|
351 | - case "list" : |
|
352 | - $v_extract_all = false; |
|
353 | - $v_listing = true; |
|
354 | - break; |
|
355 | - default : |
|
356 | - $this->_error('Invalid extract mode ('.$p_mode.')'); |
|
357 | - return false; |
|
358 | - } |
|
359 | - |
|
360 | - clearstatcache(); |
|
361 | - |
|
362 | - while (strlen($v_binary_data = $this->_readBlock()) != 0) |
|
363 | - { |
|
364 | - $v_extract_file = false; |
|
365 | - $v_extraction_stopped = 0; |
|
366 | - |
|
367 | - if (!$this->_readHeader($v_binary_data, $v_header)) |
|
368 | - return false; |
|
369 | - |
|
370 | - if ($v_header['filename'] == '') { |
|
371 | - continue; |
|
372 | - } |
|
373 | - |
|
374 | - // ----- Look for long filename |
|
375 | - if ($v_header['typeflag'] == 'L') { |
|
376 | - if (!$this->_readLongHeader($v_header)) |
|
377 | - return false; |
|
378 | - } |
|
379 | - |
|
380 | - if ((!$v_extract_all) && (is_array($p_file_list))) { |
|
381 | - // ----- By default no unzip if the file is not found |
|
382 | - $v_extract_file = false; |
|
383 | - |
|
384 | - for ($i=0; $i<sizeof($p_file_list); $i++) { |
|
385 | - // ----- Look if it is a directory |
|
386 | - if (substr($p_file_list[$i], -1) == '/') { |
|
387 | - // ----- Look if the directory is in the filename path |
|
388 | - if ((strlen($v_header['filename']) > strlen($p_file_list[$i])) |
|
389 | - && (substr($v_header['filename'], 0, strlen($p_file_list[$i])) |
|
390 | - == $p_file_list[$i])) { |
|
391 | - $v_extract_file = true; |
|
392 | - break; |
|
393 | - } |
|
394 | - } |
|
395 | - |
|
396 | - // ----- It is a file, so compare the file names |
|
397 | - elseif ($p_file_list[$i] == $v_header['filename']) { |
|
398 | - $v_extract_file = true; |
|
399 | - break; |
|
400 | - } |
|
401 | - } |
|
402 | - } else { |
|
403 | - $v_extract_file = true; |
|
404 | - } |
|
405 | - |
|
406 | - // ----- Look if this file need to be extracted |
|
407 | - if (($v_extract_file) && (!$v_listing)) |
|
408 | - { |
|
409 | - if (($p_remove_path != '') |
|
410 | - && (substr($v_header['filename'], 0, $p_remove_path_size) |
|
411 | - == $p_remove_path)) |
|
412 | - $v_header['filename'] = substr($v_header['filename'], |
|
413 | - $p_remove_path_size); |
|
414 | - if (($p_path != './') && ($p_path != '/')) { |
|
415 | - while (substr($p_path, -1) == '/') |
|
416 | - $p_path = substr($p_path, 0, strlen($p_path)-1); |
|
417 | - |
|
418 | - if (substr($v_header['filename'], 0, 1) == '/') |
|
419 | - $v_header['filename'] = $p_path.$v_header['filename']; |
|
420 | - else |
|
421 | - $v_header['filename'] = $p_path.'/'.$v_header['filename']; |
|
422 | - } |
|
423 | - if (file_exists($v_header['filename'])) { |
|
424 | - if ( (@is_dir($v_header['filename'])) |
|
425 | - && ($v_header['typeflag'] == '')) { |
|
426 | - $this->_error('File '.$v_header['filename'] |
|
427 | - .' already exists as a directory'); |
|
428 | - return false; |
|
429 | - } |
|
430 | - if ( ($this->_isArchive($v_header['filename'])) |
|
431 | - && ($v_header['typeflag'] == "5")) { |
|
432 | - $this->_error('Directory '.$v_header['filename'] |
|
433 | - .' already exists as a file'); |
|
434 | - return false; |
|
435 | - } |
|
436 | - if (!is_writeable($v_header['filename'])) { |
|
437 | - $this->_error('File '.$v_header['filename'] |
|
438 | - .' already exists and is write protected'); |
|
439 | - return false; |
|
440 | - } |
|
441 | - if (filemtime($v_header['filename']) > $v_header['mtime']) { |
|
442 | - // To be completed : An error or silent no replace ? |
|
443 | - } |
|
444 | - } |
|
445 | - |
|
446 | - // ----- Check the directory availability and create it if necessary |
|
447 | - elseif (($v_result |
|
448 | - = $this->_dirCheck(($v_header['typeflag'] == "5" |
|
449 | - ?$v_header['filename'] |
|
282 | + return false; |
|
283 | + } |
|
284 | + |
|
285 | + // ----- Extract the properties |
|
286 | + $v_header['filename'] = trim($v_data['filename']); |
|
287 | + $v_header['mode'] = OctDec(trim($v_data['mode'])); |
|
288 | + $v_header['uid'] = OctDec(trim($v_data['uid'])); |
|
289 | + $v_header['gid'] = OctDec(trim($v_data['gid'])); |
|
290 | + $v_header['size'] = OctDec(trim($v_data['size'])); |
|
291 | + $v_header['mtime'] = OctDec(trim($v_data['mtime'])); |
|
292 | + if (($v_header['typeflag'] = $v_data['typeflag']) == "5") { |
|
293 | + $v_header['size'] = 0; |
|
294 | + } |
|
295 | + return true; |
|
296 | + } |
|
297 | + |
|
298 | + private function _readLongHeader(&$v_header) |
|
299 | + { |
|
300 | + $v_filename = ''; |
|
301 | + $n = floor($v_header['size']/512); |
|
302 | + for ($i=0; $i<$n; $i++) { |
|
303 | + $v_content = $this->_readBlock(); |
|
304 | + $v_filename .= $v_content; |
|
305 | + } |
|
306 | + if (($v_header['size'] % 512) != 0) { |
|
307 | + $v_content = $this->_readBlock(); |
|
308 | + $v_filename .= $v_content; |
|
309 | + } |
|
310 | + |
|
311 | + // ----- Read the next header |
|
312 | + $v_binary_data = $this->_readBlock(); |
|
313 | + |
|
314 | + if (!$this->_readHeader($v_binary_data, $v_header)) |
|
315 | + return false; |
|
316 | + |
|
317 | + $v_header['filename'] = $v_filename; |
|
318 | + |
|
319 | + return true; |
|
320 | + } |
|
321 | + |
|
322 | + protected function _extractList($p_path, &$p_list_detail, $p_mode, |
|
323 | + $p_file_list, $p_remove_path) |
|
324 | + { |
|
325 | + $v_result=true; |
|
326 | + $v_nb = 0; |
|
327 | + $v_extract_all = true; |
|
328 | + $v_listing = false; |
|
329 | + |
|
330 | + $p_path = $this->_translateWinPath($p_path, false); |
|
331 | + if ($p_path == '' || (substr($p_path, 0, 1) != '/' |
|
332 | + && substr($p_path, 0, 3) != "../" && !strpos($p_path, ':'))) { |
|
333 | + $p_path = "./".$p_path; |
|
334 | + } |
|
335 | + $p_remove_path = $this->_translateWinPath($p_remove_path); |
|
336 | + |
|
337 | + // ----- Look for path to remove format (should end by /) |
|
338 | + if (($p_remove_path != '') && (substr($p_remove_path, -1) != '/')) |
|
339 | + $p_remove_path .= '/'; |
|
340 | + $p_remove_path_size = strlen($p_remove_path); |
|
341 | + |
|
342 | + switch ($p_mode) { |
|
343 | + case "complete" : |
|
344 | + $v_extract_all = true; |
|
345 | + $v_listing = false; |
|
346 | + break; |
|
347 | + case "partial" : |
|
348 | + $v_extract_all = false; |
|
349 | + $v_listing = false; |
|
350 | + break; |
|
351 | + case "list" : |
|
352 | + $v_extract_all = false; |
|
353 | + $v_listing = true; |
|
354 | + break; |
|
355 | + default : |
|
356 | + $this->_error('Invalid extract mode ('.$p_mode.')'); |
|
357 | + return false; |
|
358 | + } |
|
359 | + |
|
360 | + clearstatcache(); |
|
361 | + |
|
362 | + while (strlen($v_binary_data = $this->_readBlock()) != 0) |
|
363 | + { |
|
364 | + $v_extract_file = false; |
|
365 | + $v_extraction_stopped = 0; |
|
366 | + |
|
367 | + if (!$this->_readHeader($v_binary_data, $v_header)) |
|
368 | + return false; |
|
369 | + |
|
370 | + if ($v_header['filename'] == '') { |
|
371 | + continue; |
|
372 | + } |
|
373 | + |
|
374 | + // ----- Look for long filename |
|
375 | + if ($v_header['typeflag'] == 'L') { |
|
376 | + if (!$this->_readLongHeader($v_header)) |
|
377 | + return false; |
|
378 | + } |
|
379 | + |
|
380 | + if ((!$v_extract_all) && (is_array($p_file_list))) { |
|
381 | + // ----- By default no unzip if the file is not found |
|
382 | + $v_extract_file = false; |
|
383 | + |
|
384 | + for ($i=0; $i<sizeof($p_file_list); $i++) { |
|
385 | + // ----- Look if it is a directory |
|
386 | + if (substr($p_file_list[$i], -1) == '/') { |
|
387 | + // ----- Look if the directory is in the filename path |
|
388 | + if ((strlen($v_header['filename']) > strlen($p_file_list[$i])) |
|
389 | + && (substr($v_header['filename'], 0, strlen($p_file_list[$i])) |
|
390 | + == $p_file_list[$i])) { |
|
391 | + $v_extract_file = true; |
|
392 | + break; |
|
393 | + } |
|
394 | + } |
|
395 | + |
|
396 | + // ----- It is a file, so compare the file names |
|
397 | + elseif ($p_file_list[$i] == $v_header['filename']) { |
|
398 | + $v_extract_file = true; |
|
399 | + break; |
|
400 | + } |
|
401 | + } |
|
402 | + } else { |
|
403 | + $v_extract_file = true; |
|
404 | + } |
|
405 | + |
|
406 | + // ----- Look if this file need to be extracted |
|
407 | + if (($v_extract_file) && (!$v_listing)) |
|
408 | + { |
|
409 | + if (($p_remove_path != '') |
|
410 | + && (substr($v_header['filename'], 0, $p_remove_path_size) |
|
411 | + == $p_remove_path)) |
|
412 | + $v_header['filename'] = substr($v_header['filename'], |
|
413 | + $p_remove_path_size); |
|
414 | + if (($p_path != './') && ($p_path != '/')) { |
|
415 | + while (substr($p_path, -1) == '/') |
|
416 | + $p_path = substr($p_path, 0, strlen($p_path)-1); |
|
417 | + |
|
418 | + if (substr($v_header['filename'], 0, 1) == '/') |
|
419 | + $v_header['filename'] = $p_path.$v_header['filename']; |
|
420 | + else |
|
421 | + $v_header['filename'] = $p_path.'/'.$v_header['filename']; |
|
422 | + } |
|
423 | + if (file_exists($v_header['filename'])) { |
|
424 | + if ( (@is_dir($v_header['filename'])) |
|
425 | + && ($v_header['typeflag'] == '')) { |
|
426 | + $this->_error('File '.$v_header['filename'] |
|
427 | + .' already exists as a directory'); |
|
428 | + return false; |
|
429 | + } |
|
430 | + if ( ($this->_isArchive($v_header['filename'])) |
|
431 | + && ($v_header['typeflag'] == "5")) { |
|
432 | + $this->_error('Directory '.$v_header['filename'] |
|
433 | + .' already exists as a file'); |
|
434 | + return false; |
|
435 | + } |
|
436 | + if (!is_writeable($v_header['filename'])) { |
|
437 | + $this->_error('File '.$v_header['filename'] |
|
438 | + .' already exists and is write protected'); |
|
439 | + return false; |
|
440 | + } |
|
441 | + if (filemtime($v_header['filename']) > $v_header['mtime']) { |
|
442 | + // To be completed : An error or silent no replace ? |
|
443 | + } |
|
444 | + } |
|
445 | + |
|
446 | + // ----- Check the directory availability and create it if necessary |
|
447 | + elseif (($v_result |
|
448 | + = $this->_dirCheck(($v_header['typeflag'] == "5" |
|
449 | + ?$v_header['filename'] |
|
450 | 450 | :dirname($v_header['filename'])))) != 1) { |
451 | - $this->_error('Unable to create path for '.$v_header['filename']); |
|
452 | - return false; |
|
453 | - } |
|
454 | - |
|
455 | - if ($v_extract_file) { |
|
456 | - if ($v_header['typeflag'] == "5") { |
|
457 | - if (!@file_exists($v_header['filename'])) { |
|
458 | - if (!@mkdir($v_header['filename'], PRADO_CHMOD)) { |
|
459 | - $this->_error('Unable to create directory {' |
|
460 | - .$v_header['filename'].'}'); |
|
461 | - return false; |
|
462 | - } |
|
463 | - chmod($v_header['filename'], PRADO_CHMOD); |
|
464 | - } |
|
465 | - } else { |
|
466 | - if (($v_dest_file = @fopen($v_header['filename'], "wb")) == 0) { |
|
467 | - $this->_error('Error while opening {'.$v_header['filename'] |
|
468 | - .'} in write binary mode'); |
|
469 | - return false; |
|
470 | - } else { |
|
471 | - $n = floor($v_header['size']/512); |
|
472 | - for ($i=0; $i<$n; $i++) { |
|
473 | - $v_content = $this->_readBlock(); |
|
474 | - fwrite($v_dest_file, $v_content, 512); |
|
475 | - } |
|
476 | - if (($v_header['size'] % 512) != 0) { |
|
477 | - $v_content = $this->_readBlock(); |
|
478 | - fwrite($v_dest_file, $v_content, ($v_header['size'] % 512)); |
|
479 | - } |
|
480 | - |
|
481 | - @fclose($v_dest_file); |
|
482 | - |
|
483 | - // ----- Change the file mode, mtime |
|
484 | - @touch($v_header['filename'], $v_header['mtime']); |
|
485 | - // To be completed |
|
486 | - //chmod($v_header[filename], DecOct($v_header[mode])); |
|
487 | - } |
|
488 | - |
|
489 | - // ----- Check the file size |
|
490 | - clearstatcache(); |
|
491 | - if (filesize($v_header['filename']) != $v_header['size']) { |
|
492 | - $this->_error('Extracted file '.$v_header['filename'] |
|
493 | - .' does not have the correct file size \'' |
|
451 | + $this->_error('Unable to create path for '.$v_header['filename']); |
|
452 | + return false; |
|
453 | + } |
|
454 | + |
|
455 | + if ($v_extract_file) { |
|
456 | + if ($v_header['typeflag'] == "5") { |
|
457 | + if (!@file_exists($v_header['filename'])) { |
|
458 | + if (!@mkdir($v_header['filename'], PRADO_CHMOD)) { |
|
459 | + $this->_error('Unable to create directory {' |
|
460 | + .$v_header['filename'].'}'); |
|
461 | + return false; |
|
462 | + } |
|
463 | + chmod($v_header['filename'], PRADO_CHMOD); |
|
464 | + } |
|
465 | + } else { |
|
466 | + if (($v_dest_file = @fopen($v_header['filename'], "wb")) == 0) { |
|
467 | + $this->_error('Error while opening {'.$v_header['filename'] |
|
468 | + .'} in write binary mode'); |
|
469 | + return false; |
|
470 | + } else { |
|
471 | + $n = floor($v_header['size']/512); |
|
472 | + for ($i=0; $i<$n; $i++) { |
|
473 | + $v_content = $this->_readBlock(); |
|
474 | + fwrite($v_dest_file, $v_content, 512); |
|
475 | + } |
|
476 | + if (($v_header['size'] % 512) != 0) { |
|
477 | + $v_content = $this->_readBlock(); |
|
478 | + fwrite($v_dest_file, $v_content, ($v_header['size'] % 512)); |
|
479 | + } |
|
480 | + |
|
481 | + @fclose($v_dest_file); |
|
482 | + |
|
483 | + // ----- Change the file mode, mtime |
|
484 | + @touch($v_header['filename'], $v_header['mtime']); |
|
485 | + // To be completed |
|
486 | + //chmod($v_header[filename], DecOct($v_header[mode])); |
|
487 | + } |
|
488 | + |
|
489 | + // ----- Check the file size |
|
490 | + clearstatcache(); |
|
491 | + if (filesize($v_header['filename']) != $v_header['size']) { |
|
492 | + $this->_error('Extracted file '.$v_header['filename'] |
|
493 | + .' does not have the correct file size \'' |
|
494 | 494 | .filesize($v_header['filename']) |
495 | 495 | .'\' ('.$v_header['size'] |
496 | 496 | .' expected). Archive may be corrupted.'); |
497 | - return false; |
|
498 | - } |
|
499 | - } |
|
500 | - } else { |
|
501 | - $this->_jumpBlock(ceil(($v_header['size']/512))); |
|
502 | - } |
|
503 | - } else { |
|
504 | - $this->_jumpBlock(ceil(($v_header['size']/512))); |
|
505 | - } |
|
506 | - |
|
507 | - /* TBC : Seems to be unused ... |
|
497 | + return false; |
|
498 | + } |
|
499 | + } |
|
500 | + } else { |
|
501 | + $this->_jumpBlock(ceil(($v_header['size']/512))); |
|
502 | + } |
|
503 | + } else { |
|
504 | + $this->_jumpBlock(ceil(($v_header['size']/512))); |
|
505 | + } |
|
506 | + |
|
507 | + /* TBC : Seems to be unused ... |
|
508 | 508 | if ($this->_compress) |
509 | 509 | $v_end_of_file = @gzeof($this->_file); |
510 | 510 | else |
511 | 511 | $v_end_of_file = @feof($this->_file); |
512 | 512 | */ |
513 | 513 | |
514 | - if ($v_listing || $v_extract_file || $v_extraction_stopped) { |
|
515 | - // ----- Log extracted files |
|
516 | - if (($v_file_dir = dirname($v_header['filename'])) |
|
517 | - == $v_header['filename']) |
|
518 | - $v_file_dir = ''; |
|
519 | - if ((substr($v_header['filename'], 0, 1) == '/') && ($v_file_dir == '')) |
|
520 | - $v_file_dir = '/'; |
|
521 | - |
|
522 | - $p_list_detail[$v_nb++] = $v_header; |
|
523 | - } |
|
524 | - } |
|
525 | - |
|
526 | - return true; |
|
527 | - } |
|
528 | - |
|
529 | - /** |
|
530 | - * Check if a directory exists and create it (including parent |
|
531 | - * dirs) if not. |
|
532 | - * |
|
533 | - * @param string $p_dir directory to check |
|
534 | - * |
|
535 | - * @return bool true if the directory exists or was created |
|
536 | - */ |
|
537 | - protected function _dirCheck($p_dir) |
|
538 | - { |
|
539 | - if ((@is_dir($p_dir)) || ($p_dir == '')) |
|
540 | - return true; |
|
541 | - |
|
542 | - $p_parent_dir = dirname($p_dir); |
|
543 | - |
|
544 | - if (($p_parent_dir != $p_dir) && |
|
545 | - ($p_parent_dir != '') && |
|
546 | - (!$this->_dirCheck($p_parent_dir))) |
|
547 | - return false; |
|
548 | - |
|
549 | - if (!@mkdir($p_dir, PRADO_CHMOD)) { |
|
550 | - $this->_error("Unable to create directory '$p_dir'"); |
|
551 | - return false; |
|
552 | - } |
|
553 | - chmod($p_dir,PRADO_CHMOD); |
|
554 | - |
|
555 | - return true; |
|
556 | - } |
|
557 | - |
|
558 | - protected function _translateWinPath($p_path, $p_remove_disk_letter=true) |
|
559 | - { |
|
560 | - if (substr(PHP_OS, 0, 3) == 'WIN') { |
|
561 | - // ----- Look for potential disk letter |
|
562 | - if ( ($p_remove_disk_letter) |
|
563 | - && (($v_position = strpos($p_path, ':')) != false)) { |
|
564 | - $p_path = substr($p_path, $v_position+1); |
|
565 | - } |
|
566 | - // ----- Change potential windows directory separator |
|
567 | - if ((strpos($p_path, '\\') > 0) || (substr($p_path, 0,1) == '\\')) { |
|
568 | - $p_path = strtr($p_path, '\\', '/'); |
|
569 | - } |
|
570 | - } |
|
571 | - return $p_path; |
|
572 | - } |
|
514 | + if ($v_listing || $v_extract_file || $v_extraction_stopped) { |
|
515 | + // ----- Log extracted files |
|
516 | + if (($v_file_dir = dirname($v_header['filename'])) |
|
517 | + == $v_header['filename']) |
|
518 | + $v_file_dir = ''; |
|
519 | + if ((substr($v_header['filename'], 0, 1) == '/') && ($v_file_dir == '')) |
|
520 | + $v_file_dir = '/'; |
|
521 | + |
|
522 | + $p_list_detail[$v_nb++] = $v_header; |
|
523 | + } |
|
524 | + } |
|
525 | + |
|
526 | + return true; |
|
527 | + } |
|
528 | + |
|
529 | + /** |
|
530 | + * Check if a directory exists and create it (including parent |
|
531 | + * dirs) if not. |
|
532 | + * |
|
533 | + * @param string $p_dir directory to check |
|
534 | + * |
|
535 | + * @return bool true if the directory exists or was created |
|
536 | + */ |
|
537 | + protected function _dirCheck($p_dir) |
|
538 | + { |
|
539 | + if ((@is_dir($p_dir)) || ($p_dir == '')) |
|
540 | + return true; |
|
541 | + |
|
542 | + $p_parent_dir = dirname($p_dir); |
|
543 | + |
|
544 | + if (($p_parent_dir != $p_dir) && |
|
545 | + ($p_parent_dir != '') && |
|
546 | + (!$this->_dirCheck($p_parent_dir))) |
|
547 | + return false; |
|
548 | + |
|
549 | + if (!@mkdir($p_dir, PRADO_CHMOD)) { |
|
550 | + $this->_error("Unable to create directory '$p_dir'"); |
|
551 | + return false; |
|
552 | + } |
|
553 | + chmod($p_dir,PRADO_CHMOD); |
|
554 | + |
|
555 | + return true; |
|
556 | + } |
|
557 | + |
|
558 | + protected function _translateWinPath($p_path, $p_remove_disk_letter=true) |
|
559 | + { |
|
560 | + if (substr(PHP_OS, 0, 3) == 'WIN') { |
|
561 | + // ----- Look for potential disk letter |
|
562 | + if ( ($p_remove_disk_letter) |
|
563 | + && (($v_position = strpos($p_path, ':')) != false)) { |
|
564 | + $p_path = substr($p_path, $v_position+1); |
|
565 | + } |
|
566 | + // ----- Change potential windows directory separator |
|
567 | + if ((strpos($p_path, '\\') > 0) || (substr($p_path, 0,1) == '\\')) { |
|
568 | + $p_path = strtr($p_path, '\\', '/'); |
|
569 | + } |
|
570 | + } |
|
571 | + return $p_path; |
|
572 | + } |
|
573 | 573 | } |