@@ -170,37 +170,37 @@ discard block |
||
170 | 170 | */ |
171 | 171 | function my_rename($file_path, $new_file_name) { |
172 | 172 | |
173 | - $save_dir = getcwd(); |
|
174 | - $path = dirname($file_path); |
|
175 | - $old_file_name = basename($file_path); |
|
176 | - $new_file_name = api_replace_dangerous_char($new_file_name); |
|
177 | - |
|
178 | - // If no extension, take the old one |
|
179 | - if ((strpos($new_file_name, '.') === false) && ($dotpos = strrpos($old_file_name, '.'))) { |
|
180 | - $new_file_name .= substr($old_file_name, $dotpos); |
|
181 | - } |
|
182 | - |
|
183 | - // Note: still possible: 'xx.yy' -rename-> '.yy' -rename-> 'zz' |
|
184 | - // This is useful for folder names, where otherwise '.' would be sticky |
|
185 | - |
|
186 | - // Extension PHP is not allowed, change to PHPS |
|
187 | - $new_file_name = php2phps($new_file_name); |
|
188 | - |
|
189 | - if ($new_file_name == $old_file_name) { |
|
190 | - return $old_file_name; |
|
191 | - } |
|
192 | - |
|
193 | - if (strtolower($new_file_name) != strtolower($old_file_name) && check_name_exist($path.'/'.$new_file_name)) { |
|
194 | - return false; |
|
195 | - } |
|
196 | - // On a Windows server, it would be better not to do the above check |
|
197 | - // because it succeeds for some new names resembling the old name. |
|
198 | - // But on Unix/Linux the check must be done because rename overwrites. |
|
199 | - |
|
200 | - chdir($path); |
|
201 | - $res = rename($old_file_name, $new_file_name) ? $new_file_name : false; |
|
202 | - chdir($save_dir); |
|
203 | - return $res; |
|
173 | + $save_dir = getcwd(); |
|
174 | + $path = dirname($file_path); |
|
175 | + $old_file_name = basename($file_path); |
|
176 | + $new_file_name = api_replace_dangerous_char($new_file_name); |
|
177 | + |
|
178 | + // If no extension, take the old one |
|
179 | + if ((strpos($new_file_name, '.') === false) && ($dotpos = strrpos($old_file_name, '.'))) { |
|
180 | + $new_file_name .= substr($old_file_name, $dotpos); |
|
181 | + } |
|
182 | + |
|
183 | + // Note: still possible: 'xx.yy' -rename-> '.yy' -rename-> 'zz' |
|
184 | + // This is useful for folder names, where otherwise '.' would be sticky |
|
185 | + |
|
186 | + // Extension PHP is not allowed, change to PHPS |
|
187 | + $new_file_name = php2phps($new_file_name); |
|
188 | + |
|
189 | + if ($new_file_name == $old_file_name) { |
|
190 | + return $old_file_name; |
|
191 | + } |
|
192 | + |
|
193 | + if (strtolower($new_file_name) != strtolower($old_file_name) && check_name_exist($path.'/'.$new_file_name)) { |
|
194 | + return false; |
|
195 | + } |
|
196 | + // On a Windows server, it would be better not to do the above check |
|
197 | + // because it succeeds for some new names resembling the old name. |
|
198 | + // But on Unix/Linux the check must be done because rename overwrites. |
|
199 | + |
|
200 | + chdir($path); |
|
201 | + $res = rename($old_file_name, $new_file_name) ? $new_file_name : false; |
|
202 | + chdir($save_dir); |
|
203 | + return $res; |
|
204 | 204 | } |
205 | 205 | |
206 | 206 | /** |
@@ -217,38 +217,38 @@ discard block |
||
217 | 217 | */ |
218 | 218 | function move($source, $target, $forceMove = false, $moveContent = false) |
219 | 219 | { |
220 | - if (check_name_exist($source)) { |
|
221 | - $file_name = basename($source); |
|
220 | + if (check_name_exist($source)) { |
|
221 | + $file_name = basename($source); |
|
222 | 222 | $isWindowsOS = api_is_windows_os(); |
223 | 223 | $canExec = function_exists('exec'); |
224 | 224 | |
225 | - /* File case */ |
|
226 | - if (is_file($source)) { |
|
227 | - if ($forceMove && !$isWindowsOS && $canExec) { |
|
228 | - exec('mv ' . $source . ' ' . $target . '/' . $file_name); |
|
229 | - } else { |
|
230 | - copy($source, $target . '/' . $file_name); |
|
231 | - unlink($source); |
|
232 | - } |
|
233 | - return true; |
|
234 | - } elseif (is_dir($source)) { |
|
235 | - /* Directory */ |
|
236 | - if ($forceMove && !$isWindowsOS && $canExec) { |
|
237 | - if ($moveContent) { |
|
238 | - $base = basename($source); |
|
239 | - exec('mv '.$source.'/* '.$target.$base.'/'); |
|
240 | - exec('rm -rf '.$source); |
|
241 | - } else { |
|
242 | - exec('mv $source $target'); |
|
243 | - } |
|
244 | - } else { |
|
245 | - copyDirTo($source, $target); |
|
246 | - } |
|
247 | - return true; |
|
248 | - } |
|
249 | - } else { |
|
250 | - return false; |
|
251 | - } |
|
225 | + /* File case */ |
|
226 | + if (is_file($source)) { |
|
227 | + if ($forceMove && !$isWindowsOS && $canExec) { |
|
228 | + exec('mv ' . $source . ' ' . $target . '/' . $file_name); |
|
229 | + } else { |
|
230 | + copy($source, $target . '/' . $file_name); |
|
231 | + unlink($source); |
|
232 | + } |
|
233 | + return true; |
|
234 | + } elseif (is_dir($source)) { |
|
235 | + /* Directory */ |
|
236 | + if ($forceMove && !$isWindowsOS && $canExec) { |
|
237 | + if ($moveContent) { |
|
238 | + $base = basename($source); |
|
239 | + exec('mv '.$source.'/* '.$target.$base.'/'); |
|
240 | + exec('rm -rf '.$source); |
|
241 | + } else { |
|
242 | + exec('mv $source $target'); |
|
243 | + } |
|
244 | + } else { |
|
245 | + copyDirTo($source, $target); |
|
246 | + } |
|
247 | + return true; |
|
248 | + } |
|
249 | + } else { |
|
250 | + return false; |
|
251 | + } |
|
252 | 252 | } |
253 | 253 | |
254 | 254 | /** |
@@ -261,54 +261,54 @@ discard block |
||
261 | 261 | */ |
262 | 262 | function copyDirTo($orig_dir_path, $destination, $move = true) |
263 | 263 | { |
264 | - if ($orig_dir_path == $destination) { |
|
265 | - return false; |
|
266 | - } |
|
264 | + if ($orig_dir_path == $destination) { |
|
265 | + return false; |
|
266 | + } |
|
267 | 267 | |
268 | - $save_dir = getcwd(); |
|
269 | - // Extract directory name - create it at destination - update destination trail |
|
270 | - $dir_name = basename($orig_dir_path); |
|
268 | + $save_dir = getcwd(); |
|
269 | + // Extract directory name - create it at destination - update destination trail |
|
270 | + $dir_name = basename($orig_dir_path); |
|
271 | 271 | $dir_to_copy = array(); |
272 | - if (is_dir($orig_dir_path)) { |
|
273 | - if (!is_dir($destination.'/'.$dir_name)) { |
|
274 | - mkdir( |
|
275 | - $destination.'/'.$dir_name, |
|
276 | - api_get_permissions_for_new_directories() |
|
277 | - ); |
|
278 | - } |
|
279 | - $destination_trail = $destination.'/'.$dir_name; |
|
280 | - if (is_dir($destination)) { |
|
281 | - chdir($orig_dir_path) ; |
|
282 | - $handle = opendir($orig_dir_path); |
|
283 | - |
|
284 | - while ($element = readdir($handle)) { |
|
285 | - if ($element == '.' || $element == '..') { |
|
286 | - continue; // Skip the current and parent directories |
|
287 | - } elseif (is_file($element)) { |
|
288 | - copy($element, $destination_trail.'/'.$element); |
|
289 | - |
|
290 | - if ($move) { |
|
291 | - unlink($element) ; |
|
292 | - } |
|
293 | - } elseif (is_dir($element)) { |
|
294 | - $dir_to_copy[] = $orig_dir_path.'/'.$element; |
|
295 | - } |
|
296 | - } |
|
297 | - |
|
298 | - closedir($handle) ; |
|
299 | - |
|
300 | - if (sizeof($dir_to_copy) > 0) { |
|
301 | - foreach ($dir_to_copy as $this_dir) { |
|
302 | - copyDirTo($this_dir, $destination_trail, $move); // Recursivity |
|
303 | - } |
|
304 | - } |
|
305 | - |
|
306 | - if ($move) { |
|
307 | - rmdir($orig_dir_path) ; |
|
308 | - } |
|
309 | - chdir($save_dir); |
|
310 | - } |
|
311 | - } |
|
272 | + if (is_dir($orig_dir_path)) { |
|
273 | + if (!is_dir($destination.'/'.$dir_name)) { |
|
274 | + mkdir( |
|
275 | + $destination.'/'.$dir_name, |
|
276 | + api_get_permissions_for_new_directories() |
|
277 | + ); |
|
278 | + } |
|
279 | + $destination_trail = $destination.'/'.$dir_name; |
|
280 | + if (is_dir($destination)) { |
|
281 | + chdir($orig_dir_path) ; |
|
282 | + $handle = opendir($orig_dir_path); |
|
283 | + |
|
284 | + while ($element = readdir($handle)) { |
|
285 | + if ($element == '.' || $element == '..') { |
|
286 | + continue; // Skip the current and parent directories |
|
287 | + } elseif (is_file($element)) { |
|
288 | + copy($element, $destination_trail.'/'.$element); |
|
289 | + |
|
290 | + if ($move) { |
|
291 | + unlink($element) ; |
|
292 | + } |
|
293 | + } elseif (is_dir($element)) { |
|
294 | + $dir_to_copy[] = $orig_dir_path.'/'.$element; |
|
295 | + } |
|
296 | + } |
|
297 | + |
|
298 | + closedir($handle) ; |
|
299 | + |
|
300 | + if (sizeof($dir_to_copy) > 0) { |
|
301 | + foreach ($dir_to_copy as $this_dir) { |
|
302 | + copyDirTo($this_dir, $destination_trail, $move); // Recursivity |
|
303 | + } |
|
304 | + } |
|
305 | + |
|
306 | + if ($move) { |
|
307 | + rmdir($orig_dir_path) ; |
|
308 | + } |
|
309 | + chdir($save_dir); |
|
310 | + } |
|
311 | + } |
|
312 | 312 | } |
313 | 313 | |
314 | 314 | |
@@ -319,8 +319,8 @@ discard block |
||
319 | 319 | * @param string $filename filename |
320 | 320 | */ |
321 | 321 | function getextension($filename) { |
322 | - $bouts = explode('.', $filename); |
|
323 | - return array(array_pop($bouts), implode('.', $bouts)); |
|
322 | + $bouts = explode('.', $filename); |
|
323 | + return array(array_pop($bouts), implode('.', $bouts)); |
|
324 | 324 | } |
325 | 325 | |
326 | 326 | /** |
@@ -331,19 +331,19 @@ discard block |
||
331 | 331 | * @param boolean $recursive if true , include subdir in total |
332 | 332 | */ |
333 | 333 | function dirsize($root, $recursive = true) { |
334 | - $dir = @opendir($root); |
|
335 | - $size = 0; |
|
336 | - while ($file = @readdir($dir)) { |
|
337 | - if (!in_array($file, array('.', '..'))) { |
|
338 | - if (is_dir($root.'/'.$file)) { |
|
339 | - $size += $recursive ? dirsize($root.'/'.$file) : 0; |
|
340 | - } else { |
|
341 | - $size += @filesize($root.'/'.$file); |
|
342 | - } |
|
343 | - } |
|
344 | - } |
|
345 | - @closedir($dir); |
|
346 | - return $size; |
|
334 | + $dir = @opendir($root); |
|
335 | + $size = 0; |
|
336 | + while ($file = @readdir($dir)) { |
|
337 | + if (!in_array($file, array('.', '..'))) { |
|
338 | + if (is_dir($root.'/'.$file)) { |
|
339 | + $size += $recursive ? dirsize($root.'/'.$file) : 0; |
|
340 | + } else { |
|
341 | + $size += @filesize($root.'/'.$file); |
|
342 | + } |
|
343 | + } |
|
344 | + } |
|
345 | + @closedir($dir); |
|
346 | + return $size; |
|
347 | 347 | } |
348 | 348 | |
349 | 349 | /* CLASS FileManager */ |
@@ -362,7 +362,7 @@ discard block |
||
362 | 362 | */ |
363 | 363 | class FileManager |
364 | 364 | { |
365 | - /** |
|
365 | + /** |
|
366 | 366 | Returns a list of all directories, except the base dir, |
367 | 367 | of the current course. This function uses recursion. |
368 | 368 | |
@@ -370,131 +370,130 @@ discard block |
||
370 | 370 | |
371 | 371 | @author Roan Embrechts |
372 | 372 | @version 1.0.1 |
373 | - */ |
|
374 | - function list_all_directories($path) |
|
373 | + */ |
|
374 | + function list_all_directories($path) |
|
375 | 375 | { |
376 | - $result_array = array(); |
|
377 | - if (is_dir($path)) { |
|
378 | - $save_dir = getcwd(); |
|
379 | - chdir($path); |
|
380 | - $handle = opendir($path); |
|
381 | - while ($element = readdir($handle)) { |
|
382 | - if ($element == '.' || $element == '..') continue; |
|
376 | + $result_array = array(); |
|
377 | + if (is_dir($path)) { |
|
378 | + $save_dir = getcwd(); |
|
379 | + chdir($path); |
|
380 | + $handle = opendir($path); |
|
381 | + while ($element = readdir($handle)) { |
|
382 | + if ($element == '.' || $element == '..') continue; |
|
383 | 383 | // Skip the current and parent directories |
384 | - if (is_dir($element)) { |
|
385 | - $dir_array[] = $path.'/'.$element; |
|
386 | - } |
|
387 | - } |
|
388 | - closedir($handle); |
|
389 | - // Recursive operation if subdirectories exist |
|
390 | - $dir_number = sizeof($dir_array); |
|
391 | - if ($dir_number > 0) { |
|
392 | - for ($i = 0 ; $i < $dir_number ; $i++) { |
|
393 | - $sub_dir_array = FileManager::list_all_directories($dir_array[$i]); // Function recursivity |
|
394 | - if (is_array($dir_array) && is_array($sub_dir_array)) { |
|
395 | - $dir_array = array_merge($dir_array, $sub_dir_array); // Data merge |
|
396 | - } |
|
397 | - } |
|
398 | - } |
|
399 | - $result_array = $dir_array; |
|
400 | - chdir($save_dir) ; |
|
401 | - } |
|
402 | - return $result_array ; |
|
403 | - } |
|
404 | - |
|
405 | - /** |
|
384 | + if (is_dir($element)) { |
|
385 | + $dir_array[] = $path.'/'.$element; |
|
386 | + } |
|
387 | + } |
|
388 | + closedir($handle); |
|
389 | + // Recursive operation if subdirectories exist |
|
390 | + $dir_number = sizeof($dir_array); |
|
391 | + if ($dir_number > 0) { |
|
392 | + for ($i = 0 ; $i < $dir_number ; $i++) { |
|
393 | + $sub_dir_array = FileManager::list_all_directories($dir_array[$i]); // Function recursivity |
|
394 | + if (is_array($dir_array) && is_array($sub_dir_array)) { |
|
395 | + $dir_array = array_merge($dir_array, $sub_dir_array); // Data merge |
|
396 | + } |
|
397 | + } |
|
398 | + } |
|
399 | + $result_array = $dir_array; |
|
400 | + chdir($save_dir) ; |
|
401 | + } |
|
402 | + return $result_array ; |
|
403 | + } |
|
404 | + |
|
405 | + /** |
|
406 | 406 | This function receives a list of directories. |
407 | 407 | It returns a list of all files in these directories |
408 | 408 | |
409 | 409 | @author Roan Embrechts |
410 | 410 | @version 1.0 |
411 | - */ |
|
412 | - function list_all_files($dir_array) |
|
411 | + */ |
|
412 | + function list_all_files($dir_array) |
|
413 | 413 | { |
414 | - $element_array = array(); |
|
415 | - if (is_dir($dir_array)) { |
|
416 | - |
|
417 | - $save_dir = getcwd(); |
|
418 | - foreach ($dir_array as $directory) { |
|
419 | - chdir($directory); |
|
420 | - $handle = opendir($directory); |
|
421 | - while ($element = readdir($handle)) { |
|
422 | - if ($element == '.' || $element == '..' || $element == '.htaccess') continue; |
|
414 | + $element_array = array(); |
|
415 | + if (is_dir($dir_array)) { |
|
416 | + |
|
417 | + $save_dir = getcwd(); |
|
418 | + foreach ($dir_array as $directory) { |
|
419 | + chdir($directory); |
|
420 | + $handle = opendir($directory); |
|
421 | + while ($element = readdir($handle)) { |
|
422 | + if ($element == '.' || $element == '..' || $element == '.htaccess') continue; |
|
423 | 423 | // Skip the current and parent directories |
424 | - if (!is_dir($element)) { |
|
425 | - $element_array[] = $directory.'/'.$element; |
|
426 | - } |
|
427 | - } |
|
428 | - closedir($handle); |
|
429 | - chdir('..'); |
|
430 | - chdir($save_dir); |
|
431 | - } |
|
432 | - } |
|
433 | - |
|
434 | - return $element_array; |
|
435 | - } |
|
436 | - |
|
437 | - /** |
|
424 | + if (!is_dir($element)) { |
|
425 | + $element_array[] = $directory.'/'.$element; |
|
426 | + } |
|
427 | + } |
|
428 | + closedir($handle); |
|
429 | + chdir('..'); |
|
430 | + chdir($save_dir); |
|
431 | + } |
|
432 | + } |
|
433 | + |
|
434 | + return $element_array; |
|
435 | + } |
|
436 | + |
|
437 | + /** |
|
438 | 438 | Loads contents of file $filename into memory and returns them as a string. |
439 | 439 | Function kept for compatibility with older PHP versions. |
440 | 440 | Function is binary safe (is needed on Windows) |
441 | - */ |
|
442 | - function compat_load_file($file_name) |
|
441 | + */ |
|
442 | + function compat_load_file($file_name) |
|
443 | 443 | { |
444 | - $buffer = ''; |
|
445 | - if (file_exists($file_name)) { |
|
446 | - $fp = fopen($file_name, 'rb'); |
|
447 | - $buffer = fread ($fp, filesize($file_name)); |
|
448 | - fclose ($fp); |
|
449 | - } |
|
450 | - return $buffer; |
|
451 | - } |
|
452 | - |
|
453 | - /** |
|
454 | - * Adds file/folder to document table in database |
|
455 | - * improvement from set_default_settings (see below): |
|
456 | - * take all info from function parameters |
|
457 | - * no global variables needed |
|
458 | - * |
|
459 | - * NOTE $glued_table should already have backticks around it |
|
460 | - * (get it from the database library, and it is done automatically) |
|
461 | - * |
|
462 | - * @param path, filename, filetype, |
|
463 | - $glued_table, default_visibility |
|
444 | + $buffer = ''; |
|
445 | + if (file_exists($file_name)) { |
|
446 | + $fp = fopen($file_name, 'rb'); |
|
447 | + $buffer = fread ($fp, filesize($file_name)); |
|
448 | + fclose ($fp); |
|
449 | + } |
|
450 | + return $buffer; |
|
451 | + } |
|
464 | 452 | |
465 | - * action: Adds an entry to the document table with the default settings. |
|
466 | - * @author Olivier Cauberghe <[email protected]> |
|
467 | - * @author Roan Embrechts |
|
468 | - * @version 1.2 |
|
469 | - */ |
|
470 | - function set_default_settings($upload_path, $filename, $filetype = 'file', $glued_table, $default_visibility = 'v') |
|
453 | + /** |
|
454 | + * Adds file/folder to document table in database |
|
455 | + * improvement from set_default_settings (see below): |
|
456 | + * take all info from function parameters |
|
457 | + * no global variables needed |
|
458 | + * |
|
459 | + * NOTE $glued_table should already have backticks around it |
|
460 | + * (get it from the database library, and it is done automatically) |
|
461 | + * |
|
462 | + * @param path, filename, filetype, |
|
463 | + $glued_table, default_visibility |
|
464 | + * action: Adds an entry to the document table with the default settings. |
|
465 | + * @author Olivier Cauberghe <[email protected]> |
|
466 | + * @author Roan Embrechts |
|
467 | + * @version 1.2 |
|
468 | + */ |
|
469 | + function set_default_settings($upload_path, $filename, $filetype = 'file', $glued_table, $default_visibility = 'v') |
|
471 | 470 | { |
472 | - if (!$default_visibility) $default_visibility = 'v'; |
|
473 | - |
|
474 | - // Make sure path is not wrongly formed |
|
475 | - $upload_path = !empty($upload_path) ? "/$upload_path" : ''; |
|
476 | - |
|
477 | - $endchar = substr($filename, strlen($filename) - 1, 1); |
|
478 | - if ($endchar == "\\" || $endchar == '/') { |
|
479 | - $filename = substr($filename, 0, strlen($filename) - 1); |
|
480 | - } |
|
481 | - |
|
482 | - $full_file_name = $upload_path.'/'.$filename; |
|
483 | - $full_file_name = str_replace("//", '/', $full_file_name); |
|
484 | - |
|
485 | - $sql_query = "SELECT count(*) as number_existing FROM $glued_table WHERE path='$full_file_name'"; |
|
486 | - $sql_result = Database::query($sql_query); |
|
487 | - $result = Database::fetch_array($sql_result); |
|
488 | - // Determine which query to execute |
|
489 | - if ($result['number_existing'] > 0) { |
|
490 | - // Entry exists, update |
|
491 | - $query = "UPDATE $glued_table SET path='$full_file_name',visibility='$default_visibility', filetype='$filetype' |
|
471 | + if (!$default_visibility) $default_visibility = 'v'; |
|
472 | + |
|
473 | + // Make sure path is not wrongly formed |
|
474 | + $upload_path = !empty($upload_path) ? "/$upload_path" : ''; |
|
475 | + |
|
476 | + $endchar = substr($filename, strlen($filename) - 1, 1); |
|
477 | + if ($endchar == "\\" || $endchar == '/') { |
|
478 | + $filename = substr($filename, 0, strlen($filename) - 1); |
|
479 | + } |
|
480 | + |
|
481 | + $full_file_name = $upload_path.'/'.$filename; |
|
482 | + $full_file_name = str_replace("//", '/', $full_file_name); |
|
483 | + |
|
484 | + $sql_query = "SELECT count(*) as number_existing FROM $glued_table WHERE path='$full_file_name'"; |
|
485 | + $sql_result = Database::query($sql_query); |
|
486 | + $result = Database::fetch_array($sql_result); |
|
487 | + // Determine which query to execute |
|
488 | + if ($result['number_existing'] > 0) { |
|
489 | + // Entry exists, update |
|
490 | + $query = "UPDATE $glued_table SET path='$full_file_name',visibility='$default_visibility', filetype='$filetype' |
|
492 | 491 | WHERE path='$full_file_name'"; |
493 | - } else { |
|
494 | - // No entry exists, create new one |
|
495 | - $query = "INSERT INTO $glued_table (path,visibility,filetype) |
|
492 | + } else { |
|
493 | + // No entry exists, create new one |
|
494 | + $query = "INSERT INTO $glued_table (path,visibility,filetype) |
|
496 | 495 | VALUES ('$full_file_name','$default_visibility','$filetype')"; |
497 | - } |
|
498 | - Database::query($query); |
|
499 | - } |
|
496 | + } |
|
497 | + Database::query($query); |
|
498 | + } |
|
500 | 499 | } |
@@ -10,7 +10,7 @@ |
||
10 | 10 | |
11 | 11 | api_protect_course_script(); |
12 | 12 | if (!api_is_allowed_to_edit()) { |
13 | - api_not_allowed(); |
|
13 | + api_not_allowed(); |
|
14 | 14 | } |
15 | 15 | $course_info = api_get_course_info(); |
16 | 16 | $course_code = $course_info['code']; |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | return false; |
127 | 127 | } |
128 | 128 | } |
129 | - */ |
|
129 | + */ |
|
130 | 130 | |
131 | 131 | /* |
132 | 132 | * Creating a Room for the meeting |
@@ -256,10 +256,10 @@ discard block |
||
256 | 256 | return true; |
257 | 257 | } |
258 | 258 | |
259 | - /** |
|
260 | - * Gets the password for a specific meeting for the current user |
|
261 | - * @return string A moderator password if user is teacher, or the course code otherwise |
|
262 | - */ |
|
259 | + /** |
|
260 | + * Gets the password for a specific meeting for the current user |
|
261 | + * @return string A moderator password if user is teacher, or the course code otherwise |
|
262 | + */ |
|
263 | 263 | public function getMeetingUserPassword() |
264 | 264 | { |
265 | 265 | if ($this->isTeacher()) { |
@@ -538,7 +538,7 @@ discard block |
||
538 | 538 | // |
539 | 539 | // } |
540 | 540 | // |
541 | - //$item['created_at'] = api_convert_and_format_date($meetingDb['created_at']); |
|
541 | + //$item['created_at'] = api_convert_and_format_date($meetingDb['created_at']); |
|
542 | 542 | // //created_at |
543 | 543 | // |
544 | 544 | // $item['publish_url'] = api_get_self().'?action=publish&id='.$meetingDb['id']; |
@@ -15,36 +15,36 @@ discard block |
||
15 | 15 | class BlockSession extends Block |
16 | 16 | { |
17 | 17 | private $user_id; |
18 | - private $sessions; |
|
19 | - private $path; |
|
20 | - private $permission = array(DRH, SESSIONADMIN); |
|
18 | + private $sessions; |
|
19 | + private $path; |
|
20 | + private $permission = array(DRH, SESSIONADMIN); |
|
21 | 21 | |
22 | - /** |
|
23 | - * Constructor |
|
24 | - */ |
|
22 | + /** |
|
23 | + * Constructor |
|
24 | + */ |
|
25 | 25 | public function __construct ($user_id) |
26 | 26 | { |
27 | - $this->user_id = $user_id; |
|
28 | - $this->path = 'block_session'; |
|
29 | - if ($this->is_block_visible_for_user($user_id)) { |
|
27 | + $this->user_id = $user_id; |
|
28 | + $this->path = 'block_session'; |
|
29 | + if ($this->is_block_visible_for_user($user_id)) { |
|
30 | 30 | $this->sessions = SessionManager::get_sessions_followed_by_drh($user_id); |
31 | - } |
|
31 | + } |
|
32 | 32 | } |
33 | 33 | |
34 | - /** |
|
35 | - * This method check if a user is allowed to see the block inside dashboard interface |
|
36 | - * @param int User id |
|
37 | - * @return bool Is block visible for user |
|
38 | - */ |
|
34 | + /** |
|
35 | + * This method check if a user is allowed to see the block inside dashboard interface |
|
36 | + * @param int User id |
|
37 | + * @return bool Is block visible for user |
|
38 | + */ |
|
39 | 39 | public function is_block_visible_for_user($user_id) |
40 | 40 | { |
41 | - $user_info = api_get_user_info($user_id); |
|
42 | - $user_status = $user_info['status']; |
|
43 | - $is_block_visible_for_user = false; |
|
44 | - if (UserManager::is_admin($user_id) || in_array($user_status, $this->permission)) { |
|
45 | - $is_block_visible_for_user = true; |
|
46 | - } |
|
47 | - return $is_block_visible_for_user; |
|
41 | + $user_info = api_get_user_info($user_id); |
|
42 | + $user_status = $user_info['status']; |
|
43 | + $is_block_visible_for_user = false; |
|
44 | + if (UserManager::is_admin($user_id) || in_array($user_status, $this->permission)) { |
|
45 | + $is_block_visible_for_user = true; |
|
46 | + } |
|
47 | + return $is_block_visible_for_user; |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | /** |
@@ -55,14 +55,14 @@ discard block |
||
55 | 55 | public function get_block() |
56 | 56 | { |
57 | 57 | |
58 | - global $charset; |
|
58 | + global $charset; |
|
59 | 59 | |
60 | - $column = 2; |
|
61 | - $data = array(); |
|
60 | + $column = 2; |
|
61 | + $data = array(); |
|
62 | 62 | |
63 | - $content = $this->get_content_html(); |
|
63 | + $content = $this->get_content_html(); |
|
64 | 64 | |
65 | - $content_html = ' |
|
65 | + $content_html = ' |
|
66 | 66 | <div class="panel panel-default" id="intro"> |
67 | 67 | <div class="panel-heading"> |
68 | 68 | '.get_lang('SessionsInformation').' |
@@ -76,78 +76,78 @@ discard block |
||
76 | 76 | </div> |
77 | 77 | '; |
78 | 78 | |
79 | - $data['column'] = $column; |
|
80 | - $data['content_html'] = $content_html; |
|
79 | + $data['column'] = $column; |
|
80 | + $data['content_html'] = $content_html; |
|
81 | 81 | |
82 | - return $data; |
|
82 | + return $data; |
|
83 | 83 | } |
84 | 84 | |
85 | 85 | /** |
86 | - * This method return a content html, it's used inside get_block method for showing it inside dashboard interface |
|
87 | - * @return string content html |
|
88 | - */ |
|
86 | + * This method return a content html, it's used inside get_block method for showing it inside dashboard interface |
|
87 | + * @return string content html |
|
88 | + */ |
|
89 | 89 | public function get_content_html() |
90 | 90 | { |
91 | 91 | |
92 | - $content = ''; |
|
93 | - $sessions = $this->sessions; |
|
92 | + $content = ''; |
|
93 | + $sessions = $this->sessions; |
|
94 | 94 | |
95 | - //$content = '<div style="margin:10px;">'; |
|
96 | - $content .= '<h4>'.get_lang('YourSessionsList').'</h4>'; |
|
95 | + //$content = '<div style="margin:10px;">'; |
|
96 | + $content .= '<h4>'.get_lang('YourSessionsList').'</h4>'; |
|
97 | 97 | |
98 | - if (count($sessions) > 0) { |
|
99 | - $sessions_table = '<table class="data_table" width:"95%">'; |
|
100 | - $sessions_table .= '<tr> |
|
98 | + if (count($sessions) > 0) { |
|
99 | + $sessions_table = '<table class="data_table" width:"95%">'; |
|
100 | + $sessions_table .= '<tr> |
|
101 | 101 | <th >'.get_lang('Title').'</th> |
102 | 102 | <th >'.get_lang('Date').'</th> |
103 | 103 | <th width="100px">'.get_lang('NbCoursesPerSession').'</th> |
104 | 104 | </tr>'; |
105 | - $i = 1; |
|
106 | - foreach ($sessions as $session) { |
|
105 | + $i = 1; |
|
106 | + foreach ($sessions as $session) { |
|
107 | 107 | |
108 | - $session_id = intval($session['id']); |
|
109 | - $title = $session['name']; |
|
108 | + $session_id = intval($session['id']); |
|
109 | + $title = $session['name']; |
|
110 | 110 | |
111 | - if ($session['access_start_date'] != '0000-00-00 00:00:00' && $session['access_end_date'] != '0000-00-00 00:00:00') { |
|
112 | - $date = get_lang('From').' '.api_convert_and_format_date($session['access_start_date'], DATE_FORMAT_SHORT, date_default_timezone_get()).' '.get_lang('To').' '.api_convert_and_format_date($session['access_end_date'], DATE_FORMAT_SHORT, date_default_timezone_get()); |
|
113 | - } else { |
|
114 | - $date = ' - '; |
|
115 | - } |
|
111 | + if ($session['access_start_date'] != '0000-00-00 00:00:00' && $session['access_end_date'] != '0000-00-00 00:00:00') { |
|
112 | + $date = get_lang('From').' '.api_convert_and_format_date($session['access_start_date'], DATE_FORMAT_SHORT, date_default_timezone_get()).' '.get_lang('To').' '.api_convert_and_format_date($session['access_end_date'], DATE_FORMAT_SHORT, date_default_timezone_get()); |
|
113 | + } else { |
|
114 | + $date = ' - '; |
|
115 | + } |
|
116 | 116 | |
117 | - $count_courses_in_session = count(Tracking::get_courses_list_from_session($session_id)); |
|
117 | + $count_courses_in_session = count(Tracking::get_courses_list_from_session($session_id)); |
|
118 | 118 | |
119 | - if ($i%2 == 0) $class_tr = 'row_odd'; |
|
120 | - else $class_tr = 'row_even'; |
|
119 | + if ($i%2 == 0) $class_tr = 'row_odd'; |
|
120 | + else $class_tr = 'row_even'; |
|
121 | 121 | |
122 | - $sessions_table .= '<tr class="'.$class_tr.'"> |
|
122 | + $sessions_table .= '<tr class="'.$class_tr.'"> |
|
123 | 123 | <td>'.$title.'</td> |
124 | 124 | <td align="center">'.$date.'</td> |
125 | 125 | <td align="center">'.$count_courses_in_session.'</td> |
126 | 126 | </tr>'; |
127 | - $i++; |
|
128 | - } |
|
129 | - $sessions_table .= '</table>'; |
|
130 | - $content .= $sessions_table; |
|
131 | - } else { |
|
132 | - $content .= get_lang('ThereIsNoInformationAboutYourSessions'); |
|
133 | - } |
|
127 | + $i++; |
|
128 | + } |
|
129 | + $sessions_table .= '</table>'; |
|
130 | + $content .= $sessions_table; |
|
131 | + } else { |
|
132 | + $content .= get_lang('ThereIsNoInformationAboutYourSessions'); |
|
133 | + } |
|
134 | 134 | |
135 | - if (count($sessions) > 0) { |
|
136 | - $content .= '<div style="text-align:right;margin-top:10px;"><a href="'.api_get_path(WEB_CODE_PATH).'mySpace/session.php">'.get_lang('SeeMore').'</a></div>'; |
|
137 | - } |
|
135 | + if (count($sessions) > 0) { |
|
136 | + $content .= '<div style="text-align:right;margin-top:10px;"><a href="'.api_get_path(WEB_CODE_PATH).'mySpace/session.php">'.get_lang('SeeMore').'</a></div>'; |
|
137 | + } |
|
138 | 138 | |
139 | - //$content .= '</div>'; |
|
139 | + //$content .= '</div>'; |
|
140 | 140 | |
141 | - return $content; |
|
142 | - } |
|
141 | + return $content; |
|
142 | + } |
|
143 | 143 | |
144 | 144 | /** |
145 | - * Get number of sessions |
|
146 | - * @return int |
|
147 | - */ |
|
148 | - function get_number_of_sessions() |
|
145 | + * Get number of sessions |
|
146 | + * @return int |
|
147 | + */ |
|
148 | + function get_number_of_sessions() |
|
149 | 149 | { |
150 | - return count($this->sessions); |
|
151 | - } |
|
150 | + return count($this->sessions); |
|
151 | + } |
|
152 | 152 | |
153 | 153 | } |
@@ -43,70 +43,70 @@ |
||
43 | 43 | */ |
44 | 44 | class LoggerAppenderConsole extends LoggerAppender { |
45 | 45 | |
46 | - const STDOUT = 'php://stdout'; |
|
47 | - const STDERR = 'php://stderr'; |
|
46 | + const STDOUT = 'php://stdout'; |
|
47 | + const STDERR = 'php://stderr'; |
|
48 | 48 | |
49 | - /** |
|
50 | - * Can be 'php://stdout' or 'php://stderr'. But it's better to use keywords <b>STDOUT</b> and <b>STDERR</b> (case insensitive). |
|
51 | - * Default is STDOUT |
|
52 | - * @var string |
|
53 | - */ |
|
54 | - private $target = self::STDOUT; |
|
49 | + /** |
|
50 | + * Can be 'php://stdout' or 'php://stderr'. But it's better to use keywords <b>STDOUT</b> and <b>STDERR</b> (case insensitive). |
|
51 | + * Default is STDOUT |
|
52 | + * @var string |
|
53 | + */ |
|
54 | + private $target = self::STDOUT; |
|
55 | 55 | |
56 | - /** |
|
57 | - * @var boolean |
|
58 | - * @access private |
|
59 | - */ |
|
60 | - protected $requiresLayout = true; |
|
56 | + /** |
|
57 | + * @var boolean |
|
58 | + * @access private |
|
59 | + */ |
|
60 | + protected $requiresLayout = true; |
|
61 | 61 | |
62 | - /** |
|
63 | - * @var mixed the resource used to open stdout/stderr |
|
64 | - * @access private |
|
65 | - */ |
|
66 | - protected $fp = null; |
|
62 | + /** |
|
63 | + * @var mixed the resource used to open stdout/stderr |
|
64 | + * @access private |
|
65 | + */ |
|
66 | + protected $fp = null; |
|
67 | 67 | |
68 | - public function __destruct() { |
|
69 | - $this->close(); |
|
70 | - } |
|
68 | + public function __destruct() { |
|
69 | + $this->close(); |
|
70 | + } |
|
71 | 71 | |
72 | - /** |
|
73 | - * Set console target. |
|
74 | - * @param mixed $value a constant or a string |
|
75 | - */ |
|
76 | - public function setTarget($value) { |
|
77 | - $v = trim($value); |
|
78 | - if ($v == self::STDOUT || strtoupper($v) == 'STDOUT') { |
|
79 | - $this->target = self::STDOUT; |
|
80 | - } elseif ($v == self::STDERR || strtoupper($v) == 'STDERR') { |
|
81 | - $this->target = self::STDERR; |
|
82 | - } |
|
83 | - } |
|
72 | + /** |
|
73 | + * Set console target. |
|
74 | + * @param mixed $value a constant or a string |
|
75 | + */ |
|
76 | + public function setTarget($value) { |
|
77 | + $v = trim($value); |
|
78 | + if ($v == self::STDOUT || strtoupper($v) == 'STDOUT') { |
|
79 | + $this->target = self::STDOUT; |
|
80 | + } elseif ($v == self::STDERR || strtoupper($v) == 'STDERR') { |
|
81 | + $this->target = self::STDERR; |
|
82 | + } |
|
83 | + } |
|
84 | 84 | |
85 | - public function activateOptions() { |
|
86 | - $this->fp = fopen($this->target, 'w'); |
|
87 | - if(is_resource($this->fp) && $this->layout !== null) { |
|
88 | - fwrite($this->fp, $this->layout->getHeader()); |
|
89 | - } |
|
90 | - $this->closed = (bool)is_resource($this->fp) === false; |
|
91 | - } |
|
85 | + public function activateOptions() { |
|
86 | + $this->fp = fopen($this->target, 'w'); |
|
87 | + if(is_resource($this->fp) && $this->layout !== null) { |
|
88 | + fwrite($this->fp, $this->layout->getHeader()); |
|
89 | + } |
|
90 | + $this->closed = (bool)is_resource($this->fp) === false; |
|
91 | + } |
|
92 | 92 | |
93 | - /** |
|
94 | - * @see LoggerAppender::close() |
|
95 | - */ |
|
96 | - public function close() { |
|
97 | - if($this->closed != true) { |
|
98 | - if (is_resource($this->fp) && $this->layout !== null) { |
|
99 | - fwrite($this->fp, $this->layout->getFooter()); |
|
100 | - fclose($this->fp); |
|
101 | - } |
|
102 | - $this->closed = true; |
|
103 | - } |
|
104 | - } |
|
93 | + /** |
|
94 | + * @see LoggerAppender::close() |
|
95 | + */ |
|
96 | + public function close() { |
|
97 | + if($this->closed != true) { |
|
98 | + if (is_resource($this->fp) && $this->layout !== null) { |
|
99 | + fwrite($this->fp, $this->layout->getFooter()); |
|
100 | + fclose($this->fp); |
|
101 | + } |
|
102 | + $this->closed = true; |
|
103 | + } |
|
104 | + } |
|
105 | 105 | |
106 | - public function append(LoggerLoggingEvent $event) { |
|
107 | - if (is_resource($this->fp) && $this->layout !== null) { |
|
108 | - fwrite($this->fp, $this->layout->format($event)); |
|
109 | - } |
|
110 | - } |
|
106 | + public function append(LoggerLoggingEvent $event) { |
|
107 | + if (is_resource($this->fp) && $this->layout !== null) { |
|
108 | + fwrite($this->fp, $this->layout->format($event)); |
|
109 | + } |
|
110 | + } |
|
111 | 111 | } |
112 | 112 |
@@ -26,236 +26,236 @@ |
||
26 | 26 | */ |
27 | 27 | abstract class LoggerAppender { |
28 | 28 | |
29 | - /** |
|
30 | - * @var boolean closed appender flag |
|
31 | - */ |
|
32 | - protected $closed = false; |
|
29 | + /** |
|
30 | + * @var boolean closed appender flag |
|
31 | + */ |
|
32 | + protected $closed = false; |
|
33 | 33 | |
34 | - /** |
|
35 | - * The first filter in the filter chain |
|
36 | - * @var LoggerFilter |
|
37 | - */ |
|
38 | - protected $filter = null; |
|
34 | + /** |
|
35 | + * The first filter in the filter chain |
|
36 | + * @var LoggerFilter |
|
37 | + */ |
|
38 | + protected $filter = null; |
|
39 | 39 | |
40 | - /** |
|
41 | - * LoggerLayout for this appender. It can be null if appender has its own layout |
|
42 | - * @var LoggerLayout |
|
43 | - */ |
|
44 | - protected $layout = null; |
|
40 | + /** |
|
41 | + * LoggerLayout for this appender. It can be null if appender has its own layout |
|
42 | + * @var LoggerLayout |
|
43 | + */ |
|
44 | + protected $layout = null; |
|
45 | 45 | |
46 | - /** |
|
47 | - * @var string Appender name |
|
48 | - */ |
|
49 | - protected $name; |
|
46 | + /** |
|
47 | + * @var string Appender name |
|
48 | + */ |
|
49 | + protected $name; |
|
50 | 50 | |
51 | - /** |
|
52 | - * @var LoggerLevel There is no level threshold filtering by default. |
|
53 | - */ |
|
54 | - protected $threshold = null; |
|
51 | + /** |
|
52 | + * @var LoggerLevel There is no level threshold filtering by default. |
|
53 | + */ |
|
54 | + protected $threshold = null; |
|
55 | 55 | |
56 | - /** |
|
57 | - * @var boolean needs a layout formatting ? |
|
58 | - */ |
|
59 | - protected $requiresLayout = false; |
|
56 | + /** |
|
57 | + * @var boolean needs a layout formatting ? |
|
58 | + */ |
|
59 | + protected $requiresLayout = false; |
|
60 | 60 | |
61 | - /** |
|
62 | - * Constructor |
|
63 | - * |
|
64 | - * @param string $name appender name |
|
65 | - */ |
|
66 | - public function __construct($name = '') { |
|
67 | - $this->name = $name; |
|
68 | - } |
|
61 | + /** |
|
62 | + * Constructor |
|
63 | + * |
|
64 | + * @param string $name appender name |
|
65 | + */ |
|
66 | + public function __construct($name = '') { |
|
67 | + $this->name = $name; |
|
68 | + } |
|
69 | 69 | |
70 | - /** |
|
71 | - * Add a filter to the end of the filter list. |
|
72 | - * |
|
73 | - * @param LoggerFilter $newFilter add a new LoggerFilter |
|
74 | - */ |
|
75 | - public function addFilter($newFilter) { |
|
76 | - if($this->filter === null) { |
|
77 | - $this->filter = $newFilter; |
|
78 | - } else { |
|
79 | - $this->filter->addNext($newFilter); |
|
80 | - } |
|
81 | - } |
|
70 | + /** |
|
71 | + * Add a filter to the end of the filter list. |
|
72 | + * |
|
73 | + * @param LoggerFilter $newFilter add a new LoggerFilter |
|
74 | + */ |
|
75 | + public function addFilter($newFilter) { |
|
76 | + if($this->filter === null) { |
|
77 | + $this->filter = $newFilter; |
|
78 | + } else { |
|
79 | + $this->filter->addNext($newFilter); |
|
80 | + } |
|
81 | + } |
|
82 | 82 | |
83 | - /** |
|
84 | - * Clear the list of filters by removing all the filters in it. |
|
85 | - * @abstract |
|
86 | - */ |
|
87 | - public function clearFilters() { |
|
88 | - unset($this->filter); |
|
89 | - $this->filter = null; |
|
90 | - } |
|
83 | + /** |
|
84 | + * Clear the list of filters by removing all the filters in it. |
|
85 | + * @abstract |
|
86 | + */ |
|
87 | + public function clearFilters() { |
|
88 | + unset($this->filter); |
|
89 | + $this->filter = null; |
|
90 | + } |
|
91 | 91 | |
92 | - /** |
|
93 | - * Return the first filter in the filter chain for this Appender. |
|
94 | - * The return value may be <i>null</i> if no is filter is set. |
|
95 | - * @return LoggerFilter |
|
96 | - */ |
|
97 | - public function getFilter() { |
|
98 | - return $this->filter; |
|
99 | - } |
|
92 | + /** |
|
93 | + * Return the first filter in the filter chain for this Appender. |
|
94 | + * The return value may be <i>null</i> if no is filter is set. |
|
95 | + * @return LoggerFilter |
|
96 | + */ |
|
97 | + public function getFilter() { |
|
98 | + return $this->filter; |
|
99 | + } |
|
100 | 100 | |
101 | - /** |
|
102 | - * Return the first filter in the filter chain for this Appender. |
|
103 | - * The return value may be <i>null</i> if no is filter is set. |
|
104 | - * @return LoggerFilter |
|
105 | - */ |
|
106 | - public function getFirstFilter() { |
|
107 | - return $this->filter; |
|
108 | - } |
|
101 | + /** |
|
102 | + * Return the first filter in the filter chain for this Appender. |
|
103 | + * The return value may be <i>null</i> if no is filter is set. |
|
104 | + * @return LoggerFilter |
|
105 | + */ |
|
106 | + public function getFirstFilter() { |
|
107 | + return $this->filter; |
|
108 | + } |
|
109 | 109 | |
110 | 110 | |
111 | - /** |
|
112 | - * This method performs threshold checks and invokes filters before |
|
113 | - * delegating actual logging to the subclasses specific <i>append()</i> method. |
|
114 | - * @see LoggerAppender::doAppend() |
|
115 | - * @param LoggerLoggingEvent $event |
|
116 | - */ |
|
117 | - public function doAppend(LoggerLoggingEvent $event) { |
|
118 | - if($this->closed) { |
|
119 | - return; |
|
120 | - } |
|
111 | + /** |
|
112 | + * This method performs threshold checks and invokes filters before |
|
113 | + * delegating actual logging to the subclasses specific <i>append()</i> method. |
|
114 | + * @see LoggerAppender::doAppend() |
|
115 | + * @param LoggerLoggingEvent $event |
|
116 | + */ |
|
117 | + public function doAppend(LoggerLoggingEvent $event) { |
|
118 | + if($this->closed) { |
|
119 | + return; |
|
120 | + } |
|
121 | 121 | |
122 | - if(!$this->isAsSevereAsThreshold($event->getLevel())) { |
|
123 | - return; |
|
124 | - } |
|
122 | + if(!$this->isAsSevereAsThreshold($event->getLevel())) { |
|
123 | + return; |
|
124 | + } |
|
125 | 125 | |
126 | - $f = $this->getFirstFilter(); |
|
127 | - while($f !== null) { |
|
128 | - switch ($f->decide($event)) { |
|
129 | - case LoggerFilter::DENY: return; |
|
130 | - case LoggerFilter::ACCEPT: return $this->append($event); |
|
131 | - case LoggerFilter::NEUTRAL: $f = $f->getNext(); |
|
132 | - } |
|
133 | - } |
|
134 | - $this->append($event); |
|
135 | - } |
|
126 | + $f = $this->getFirstFilter(); |
|
127 | + while($f !== null) { |
|
128 | + switch ($f->decide($event)) { |
|
129 | + case LoggerFilter::DENY: return; |
|
130 | + case LoggerFilter::ACCEPT: return $this->append($event); |
|
131 | + case LoggerFilter::NEUTRAL: $f = $f->getNext(); |
|
132 | + } |
|
133 | + } |
|
134 | + $this->append($event); |
|
135 | + } |
|
136 | 136 | |
137 | - /** |
|
138 | - * Set the Layout for this appender. |
|
139 | - * @see LoggerAppender::setLayout() |
|
140 | - * @param LoggerLayout $layout |
|
141 | - */ |
|
142 | - public function setLayout($layout) { |
|
143 | - if($this->requiresLayout()) { |
|
144 | - $this->layout = $layout; |
|
145 | - } |
|
146 | - } |
|
137 | + /** |
|
138 | + * Set the Layout for this appender. |
|
139 | + * @see LoggerAppender::setLayout() |
|
140 | + * @param LoggerLayout $layout |
|
141 | + */ |
|
142 | + public function setLayout($layout) { |
|
143 | + if($this->requiresLayout()) { |
|
144 | + $this->layout = $layout; |
|
145 | + } |
|
146 | + } |
|
147 | 147 | |
148 | - /** |
|
149 | - * Returns this appender layout. |
|
150 | - * @see LoggerAppender::getLayout() |
|
151 | - * @return LoggerLayout |
|
152 | - */ |
|
153 | - public function getLayout() { |
|
154 | - return $this->layout; |
|
155 | - } |
|
148 | + /** |
|
149 | + * Returns this appender layout. |
|
150 | + * @see LoggerAppender::getLayout() |
|
151 | + * @return LoggerLayout |
|
152 | + */ |
|
153 | + public function getLayout() { |
|
154 | + return $this->layout; |
|
155 | + } |
|
156 | 156 | |
157 | - /** |
|
158 | - * Configurators call this method to determine if the appender |
|
159 | - * requires a layout. |
|
160 | - * |
|
161 | - * <p>If this method returns <i>true</i>, meaning that layout is required, |
|
162 | - * then the configurator will configure a layout using the configuration |
|
163 | - * information at its disposal. If this method returns <i>false</i>, |
|
164 | - * meaning that a layout is not required, then layout configuration will be |
|
165 | - * skipped even if there is available layout configuration |
|
166 | - * information at the disposal of the configurator.</p> |
|
167 | - * |
|
168 | - * <p>In the rather exceptional case, where the appender |
|
169 | - * implementation admits a layout but can also work without it, then |
|
170 | - * the appender should return <i>true</i>.</p> |
|
171 | - * |
|
172 | - * @see LoggerAppender::requiresLayout() |
|
173 | - * @return boolean |
|
174 | - */ |
|
175 | - public function requiresLayout() { |
|
176 | - return $this->requiresLayout; |
|
177 | - } |
|
157 | + /** |
|
158 | + * Configurators call this method to determine if the appender |
|
159 | + * requires a layout. |
|
160 | + * |
|
161 | + * <p>If this method returns <i>true</i>, meaning that layout is required, |
|
162 | + * then the configurator will configure a layout using the configuration |
|
163 | + * information at its disposal. If this method returns <i>false</i>, |
|
164 | + * meaning that a layout is not required, then layout configuration will be |
|
165 | + * skipped even if there is available layout configuration |
|
166 | + * information at the disposal of the configurator.</p> |
|
167 | + * |
|
168 | + * <p>In the rather exceptional case, where the appender |
|
169 | + * implementation admits a layout but can also work without it, then |
|
170 | + * the appender should return <i>true</i>.</p> |
|
171 | + * |
|
172 | + * @see LoggerAppender::requiresLayout() |
|
173 | + * @return boolean |
|
174 | + */ |
|
175 | + public function requiresLayout() { |
|
176 | + return $this->requiresLayout; |
|
177 | + } |
|
178 | 178 | |
179 | - /** |
|
180 | - * Get the name of this appender. |
|
181 | - * @see LoggerAppender::getName() |
|
182 | - * @return string |
|
183 | - */ |
|
184 | - public function getName() { |
|
185 | - return $this->name; |
|
186 | - } |
|
179 | + /** |
|
180 | + * Get the name of this appender. |
|
181 | + * @see LoggerAppender::getName() |
|
182 | + * @return string |
|
183 | + */ |
|
184 | + public function getName() { |
|
185 | + return $this->name; |
|
186 | + } |
|
187 | 187 | |
188 | 188 | /** |
189 | - * Set the name of this appender. |
|
190 | - * |
|
191 | - * The name is used by other components to identify this appender. |
|
192 | - * |
|
193 | - * |
|
194 | - * @param string $name |
|
195 | - */ |
|
196 | - public function setName($name) { |
|
197 | - $this->name = $name; |
|
198 | - } |
|
189 | + * Set the name of this appender. |
|
190 | + * |
|
191 | + * The name is used by other components to identify this appender. |
|
192 | + * |
|
193 | + * |
|
194 | + * @param string $name |
|
195 | + */ |
|
196 | + public function setName($name) { |
|
197 | + $this->name = $name; |
|
198 | + } |
|
199 | 199 | |
200 | - /** |
|
201 | - * Returns this appenders threshold level. |
|
202 | - * See the {@link setThreshold()} method for the meaning of this option. |
|
203 | - * @return LoggerLevel |
|
204 | - */ |
|
205 | - public function getThreshold() { |
|
206 | - return $this->threshold; |
|
207 | - } |
|
200 | + /** |
|
201 | + * Returns this appenders threshold level. |
|
202 | + * See the {@link setThreshold()} method for the meaning of this option. |
|
203 | + * @return LoggerLevel |
|
204 | + */ |
|
205 | + public function getThreshold() { |
|
206 | + return $this->threshold; |
|
207 | + } |
|
208 | 208 | |
209 | - /** |
|
210 | - * Set the threshold level of this appender. |
|
211 | - * |
|
212 | - * @param mixed $threshold can be a {@link LoggerLevel} object or a string. |
|
213 | - * @see LoggerOptionConverter::toLevel() |
|
214 | - */ |
|
215 | - public function setThreshold($threshold) { |
|
216 | - if(is_string($threshold)) { |
|
217 | - $this->threshold = LoggerOptionConverter::toLevel($threshold, null); |
|
218 | - } else if($threshold instanceof LoggerLevel) { |
|
219 | - $this->threshold = $threshold; |
|
220 | - } |
|
221 | - } |
|
209 | + /** |
|
210 | + * Set the threshold level of this appender. |
|
211 | + * |
|
212 | + * @param mixed $threshold can be a {@link LoggerLevel} object or a string. |
|
213 | + * @see LoggerOptionConverter::toLevel() |
|
214 | + */ |
|
215 | + public function setThreshold($threshold) { |
|
216 | + if(is_string($threshold)) { |
|
217 | + $this->threshold = LoggerOptionConverter::toLevel($threshold, null); |
|
218 | + } else if($threshold instanceof LoggerLevel) { |
|
219 | + $this->threshold = $threshold; |
|
220 | + } |
|
221 | + } |
|
222 | 222 | |
223 | - /** |
|
224 | - * Check whether the message level is below the appender's threshold. |
|
225 | - * |
|
226 | - * |
|
227 | - * If there is no threshold set, then the return value is always <i>true</i>. |
|
228 | - * @param LoggerLevel $level |
|
229 | - * @return boolean true if priority is greater or equal than threshold |
|
230 | - */ |
|
231 | - public function isAsSevereAsThreshold($level) { |
|
232 | - if($this->threshold === null) { |
|
233 | - return true; |
|
234 | - } |
|
235 | - return $level->isGreaterOrEqual($this->getThreshold()); |
|
236 | - } |
|
223 | + /** |
|
224 | + * Check whether the message level is below the appender's threshold. |
|
225 | + * |
|
226 | + * |
|
227 | + * If there is no threshold set, then the return value is always <i>true</i>. |
|
228 | + * @param LoggerLevel $level |
|
229 | + * @return boolean true if priority is greater or equal than threshold |
|
230 | + */ |
|
231 | + public function isAsSevereAsThreshold($level) { |
|
232 | + if($this->threshold === null) { |
|
233 | + return true; |
|
234 | + } |
|
235 | + return $level->isGreaterOrEqual($this->getThreshold()); |
|
236 | + } |
|
237 | 237 | |
238 | - /** |
|
239 | - * Derived appenders should override this method if option structure |
|
240 | - * requires it. |
|
241 | - */ |
|
242 | - abstract public function activateOptions(); |
|
238 | + /** |
|
239 | + * Derived appenders should override this method if option structure |
|
240 | + * requires it. |
|
241 | + */ |
|
242 | + abstract public function activateOptions(); |
|
243 | 243 | |
244 | - /** |
|
245 | - * Subclasses of {@link LoggerAppender} should implement |
|
246 | - * this method to perform actual logging. |
|
247 | - * |
|
248 | - * @param LoggerLoggingEvent $event |
|
249 | - * @see doAppend() |
|
250 | - * @abstract |
|
251 | - */ |
|
252 | - abstract protected function append(LoggerLoggingEvent $event); |
|
244 | + /** |
|
245 | + * Subclasses of {@link LoggerAppender} should implement |
|
246 | + * this method to perform actual logging. |
|
247 | + * |
|
248 | + * @param LoggerLoggingEvent $event |
|
249 | + * @see doAppend() |
|
250 | + * @abstract |
|
251 | + */ |
|
252 | + abstract protected function append(LoggerLoggingEvent $event); |
|
253 | 253 | |
254 | - /** |
|
255 | - * Release any resources allocated. |
|
256 | - * Subclasses of {@link LoggerAppender} should implement |
|
257 | - * this method to perform proper closing procedures. |
|
258 | - * @abstract |
|
259 | - */ |
|
260 | - abstract public function close(); |
|
254 | + /** |
|
255 | + * Release any resources allocated. |
|
256 | + * Subclasses of {@link LoggerAppender} should implement |
|
257 | + * this method to perform proper closing procedures. |
|
258 | + * @abstract |
|
259 | + */ |
|
260 | + abstract public function close(); |
|
261 | 261 | } |
@@ -44,19 +44,19 @@ discard block |
||
44 | 44 | * @since 0.4 |
45 | 45 | */ |
46 | 46 | class LoggerConfiguratorXml implements LoggerConfigurator { |
47 | - const APPENDER_STATE = 1000; |
|
48 | - const LAYOUT_STATE = 1010; |
|
49 | - const ROOT_STATE = 1020; |
|
50 | - const LOGGER_STATE = 1030; |
|
51 | - const FILTER_STATE = 1040; |
|
47 | + const APPENDER_STATE = 1000; |
|
48 | + const LAYOUT_STATE = 1010; |
|
49 | + const ROOT_STATE = 1020; |
|
50 | + const LOGGER_STATE = 1030; |
|
51 | + const FILTER_STATE = 1040; |
|
52 | 52 | |
53 | - const DEFAULT_FILENAME = './log4php.xml'; |
|
53 | + const DEFAULT_FILENAME = './log4php.xml'; |
|
54 | 54 | |
55 | - /** |
|
56 | - * @var string the default configuration document |
|
57 | - */ |
|
58 | - const DEFAULT_CONFIGURATION = |
|
59 | - '<?xml version="1.0" ?> |
|
55 | + /** |
|
56 | + * @var string the default configuration document |
|
57 | + */ |
|
58 | + const DEFAULT_CONFIGURATION = |
|
59 | + '<?xml version="1.0" ?> |
|
60 | 60 | <log4php:configuration threshold="all"> |
61 | 61 | <appender name="A1" class="LoggerAppenderEcho"> |
62 | 62 | <layout class="LoggerLayoutSimple" /> |
@@ -67,10 +67,10 @@ discard block |
||
67 | 67 | </root> |
68 | 68 | </log4php:configuration>'; |
69 | 69 | |
70 | - /** |
|
71 | - * @var string the elements namespace |
|
72 | - */ |
|
73 | - const XMLNS = 'HTTP://LOGGING.APACHE.ORG/LOG4PHP/'; |
|
70 | + /** |
|
71 | + * @var string the elements namespace |
|
72 | + */ |
|
73 | + const XMLNS = 'HTTP://LOGGING.APACHE.ORG/LOG4PHP/'; |
|
74 | 74 | |
75 | 75 | /** |
76 | 76 | * @var LoggerHierarchy |
@@ -29,193 +29,193 @@ discard block |
||
29 | 29 | */ |
30 | 30 | class LoggerOptionConverter { |
31 | 31 | |
32 | - const DELIM_START = '${'; |
|
33 | - const DELIM_STOP = '}'; |
|
34 | - const DELIM_START_LEN = 2; |
|
35 | - const DELIM_STOP_LEN = 1; |
|
32 | + const DELIM_START = '${'; |
|
33 | + const DELIM_STOP = '}'; |
|
34 | + const DELIM_START_LEN = 2; |
|
35 | + const DELIM_STOP_LEN = 1; |
|
36 | 36 | |
37 | - /** |
|
38 | - * Read a predefined var. |
|
39 | - * |
|
40 | - * It returns a value referenced by <var>$key</var> using this search criteria: |
|
41 | - * - if <var>$key</var> is a constant then return it. Else |
|
42 | - * - if <var>$key</var> is set in <var>$_ENV</var> then return it. Else |
|
43 | - * - return <var>$def</var>. |
|
44 | - * |
|
45 | - * @param string $key The key to search for. |
|
46 | - * @param string $def The default value to return. |
|
47 | - * @return string the string value of the system property, or the default |
|
48 | - * value if there is no property with that key. |
|
49 | - * |
|
50 | - * @static |
|
51 | - */ |
|
52 | - public static function getSystemProperty($key, $def) { |
|
53 | - if(defined($key)) { |
|
54 | - return (string)constant($key); |
|
55 | - } else if(isset($_SERVER[$key])) { |
|
56 | - return (string)$_SERVER[$key]; |
|
57 | - } else if(isset($_ENV[$key])) { |
|
58 | - return (string)$_ENV[$key]; |
|
59 | - } else { |
|
60 | - return $def; |
|
61 | - } |
|
62 | - } |
|
37 | + /** |
|
38 | + * Read a predefined var. |
|
39 | + * |
|
40 | + * It returns a value referenced by <var>$key</var> using this search criteria: |
|
41 | + * - if <var>$key</var> is a constant then return it. Else |
|
42 | + * - if <var>$key</var> is set in <var>$_ENV</var> then return it. Else |
|
43 | + * - return <var>$def</var>. |
|
44 | + * |
|
45 | + * @param string $key The key to search for. |
|
46 | + * @param string $def The default value to return. |
|
47 | + * @return string the string value of the system property, or the default |
|
48 | + * value if there is no property with that key. |
|
49 | + * |
|
50 | + * @static |
|
51 | + */ |
|
52 | + public static function getSystemProperty($key, $def) { |
|
53 | + if(defined($key)) { |
|
54 | + return (string)constant($key); |
|
55 | + } else if(isset($_SERVER[$key])) { |
|
56 | + return (string)$_SERVER[$key]; |
|
57 | + } else if(isset($_ENV[$key])) { |
|
58 | + return (string)$_ENV[$key]; |
|
59 | + } else { |
|
60 | + return $def; |
|
61 | + } |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * If <var>$value</var> is <i>true</i>, then <i>true</i> is |
|
66 | - * returned. If <var>$value</var> is <i>false</i>, then |
|
67 | - * <i>true</i> is returned. Otherwise, <var>$default</var> is |
|
68 | - * returned. |
|
69 | - * |
|
70 | - * <p>Case of value is unimportant.</p> |
|
71 | - * |
|
72 | - * @param string $value |
|
73 | - * @param boolean $default |
|
74 | - * @return boolean |
|
75 | - * |
|
76 | - * @static |
|
77 | - */ |
|
78 | - public static function toBoolean($value, $default=true) { |
|
79 | - if (is_null($value)) { |
|
80 | - return $default; |
|
81 | - } elseif (is_string($value)) { |
|
82 | - $trimmedVal = strtolower(trim($value)); |
|
64 | + /** |
|
65 | + * If <var>$value</var> is <i>true</i>, then <i>true</i> is |
|
66 | + * returned. If <var>$value</var> is <i>false</i>, then |
|
67 | + * <i>true</i> is returned. Otherwise, <var>$default</var> is |
|
68 | + * returned. |
|
69 | + * |
|
70 | + * <p>Case of value is unimportant.</p> |
|
71 | + * |
|
72 | + * @param string $value |
|
73 | + * @param boolean $default |
|
74 | + * @return boolean |
|
75 | + * |
|
76 | + * @static |
|
77 | + */ |
|
78 | + public static function toBoolean($value, $default=true) { |
|
79 | + if (is_null($value)) { |
|
80 | + return $default; |
|
81 | + } elseif (is_string($value)) { |
|
82 | + $trimmedVal = strtolower(trim($value)); |
|
83 | 83 | |
84 | 84 | if("1" == $trimmedVal or "true" == $trimmedVal or "yes" == $trimmedVal or "on" == $trimmedVal) { |
85 | - return true; |
|
85 | + return true; |
|
86 | 86 | } else if ("" == $trimmedVal or "0" == $trimmedVal or "false" == $trimmedVal or "no" == $trimmedVal or "off" == $trimmedVal) { |
87 | - return false; |
|
88 | - } |
|
89 | - } elseif (is_bool($value)) { |
|
90 | - return $value; |
|
91 | - } elseif (is_int($value)) { |
|
92 | - return !($value == 0); // true is everything but 0 like in C |
|
93 | - } |
|
87 | + return false; |
|
88 | + } |
|
89 | + } elseif (is_bool($value)) { |
|
90 | + return $value; |
|
91 | + } elseif (is_int($value)) { |
|
92 | + return !($value == 0); // true is everything but 0 like in C |
|
93 | + } |
|
94 | 94 | |
95 | - trigger_error("Could not convert ".var_export($value,1)." to boolean!", E_USER_WARNING); |
|
96 | - return $default; |
|
97 | - } |
|
95 | + trigger_error("Could not convert ".var_export($value,1)." to boolean!", E_USER_WARNING); |
|
96 | + return $default; |
|
97 | + } |
|
98 | 98 | |
99 | - /** |
|
100 | - * @param string $value |
|
101 | - * @param integer $default |
|
102 | - * @return integer |
|
103 | - * @static |
|
104 | - */ |
|
105 | - public static function toInt($value, $default) { |
|
106 | - $value = trim($value); |
|
107 | - if(is_numeric($value)) { |
|
108 | - return (int)$value; |
|
109 | - } else { |
|
110 | - return $default; |
|
111 | - } |
|
112 | - } |
|
99 | + /** |
|
100 | + * @param string $value |
|
101 | + * @param integer $default |
|
102 | + * @return integer |
|
103 | + * @static |
|
104 | + */ |
|
105 | + public static function toInt($value, $default) { |
|
106 | + $value = trim($value); |
|
107 | + if(is_numeric($value)) { |
|
108 | + return (int)$value; |
|
109 | + } else { |
|
110 | + return $default; |
|
111 | + } |
|
112 | + } |
|
113 | 113 | |
114 | - /** |
|
115 | - * Converts a standard or custom priority level to a Level |
|
116 | - * object. |
|
117 | - * |
|
118 | - * <p> If <var>$value</var> is of form "<b>level#full_file_classname</b>", |
|
119 | - * where <i>full_file_classname</i> means the class filename with path |
|
120 | - * but without php extension, then the specified class' <i>toLevel()</i> method |
|
121 | - * is called to process the specified level string; if no '#' |
|
122 | - * character is present, then the default {@link LoggerLevel} |
|
123 | - * class is used to process the level value.</p> |
|
124 | - * |
|
125 | - * <p>As a special case, if the <var>$value</var> parameter is |
|
126 | - * equal to the string "NULL", then the value <i>null</i> will |
|
127 | - * be returned.</p> |
|
128 | - * |
|
129 | - * <p>If any error occurs while converting the value to a level, |
|
130 | - * the <var>$defaultValue</var> parameter, which may be |
|
131 | - * <i>null</i>, is returned.</p> |
|
132 | - * |
|
133 | - * <p>Case of <var>$value</var> is insignificant for the level level, but is |
|
134 | - * significant for the class name part, if present.</p> |
|
135 | - * |
|
136 | - * @param string $value |
|
137 | - * @param LoggerLevel $defaultValue |
|
138 | - * @return LoggerLevel a {@link LoggerLevel} or null |
|
139 | - * @static |
|
140 | - */ |
|
141 | - public static function toLevel($value, $defaultValue) { |
|
142 | - if($value === null) { |
|
143 | - return $defaultValue; |
|
144 | - } |
|
145 | - $hashIndex = strpos($value, '#'); |
|
146 | - if($hashIndex === false) { |
|
147 | - if("NULL" == strtoupper($value)) { |
|
148 | - return null; |
|
149 | - } else { |
|
150 | - // no class name specified : use standard Level class |
|
151 | - return LoggerLevel::toLevel($value, $defaultValue); |
|
152 | - } |
|
153 | - } |
|
114 | + /** |
|
115 | + * Converts a standard or custom priority level to a Level |
|
116 | + * object. |
|
117 | + * |
|
118 | + * <p> If <var>$value</var> is of form "<b>level#full_file_classname</b>", |
|
119 | + * where <i>full_file_classname</i> means the class filename with path |
|
120 | + * but without php extension, then the specified class' <i>toLevel()</i> method |
|
121 | + * is called to process the specified level string; if no '#' |
|
122 | + * character is present, then the default {@link LoggerLevel} |
|
123 | + * class is used to process the level value.</p> |
|
124 | + * |
|
125 | + * <p>As a special case, if the <var>$value</var> parameter is |
|
126 | + * equal to the string "NULL", then the value <i>null</i> will |
|
127 | + * be returned.</p> |
|
128 | + * |
|
129 | + * <p>If any error occurs while converting the value to a level, |
|
130 | + * the <var>$defaultValue</var> parameter, which may be |
|
131 | + * <i>null</i>, is returned.</p> |
|
132 | + * |
|
133 | + * <p>Case of <var>$value</var> is insignificant for the level level, but is |
|
134 | + * significant for the class name part, if present.</p> |
|
135 | + * |
|
136 | + * @param string $value |
|
137 | + * @param LoggerLevel $defaultValue |
|
138 | + * @return LoggerLevel a {@link LoggerLevel} or null |
|
139 | + * @static |
|
140 | + */ |
|
141 | + public static function toLevel($value, $defaultValue) { |
|
142 | + if($value === null) { |
|
143 | + return $defaultValue; |
|
144 | + } |
|
145 | + $hashIndex = strpos($value, '#'); |
|
146 | + if($hashIndex === false) { |
|
147 | + if("NULL" == strtoupper($value)) { |
|
148 | + return null; |
|
149 | + } else { |
|
150 | + // no class name specified : use standard Level class |
|
151 | + return LoggerLevel::toLevel($value, $defaultValue); |
|
152 | + } |
|
153 | + } |
|
154 | 154 | |
155 | - $result = $defaultValue; |
|
155 | + $result = $defaultValue; |
|
156 | 156 | |
157 | - $clazz = substr($value, ($hashIndex + 1)); |
|
158 | - $levelName = substr($value, 0, $hashIndex); |
|
157 | + $clazz = substr($value, ($hashIndex + 1)); |
|
158 | + $levelName = substr($value, 0, $hashIndex); |
|
159 | 159 | |
160 | - // This is degenerate case but you never know. |
|
161 | - if("NULL" == strtoupper($levelName)) { |
|
162 | - return null; |
|
163 | - } |
|
160 | + // This is degenerate case but you never know. |
|
161 | + if("NULL" == strtoupper($levelName)) { |
|
162 | + return null; |
|
163 | + } |
|
164 | 164 | |
165 | - $clazz = basename($clazz); |
|
165 | + $clazz = basename($clazz); |
|
166 | 166 | |
167 | - if(class_exists($clazz)) { |
|
168 | - $result = @call_user_func(array($clazz, 'toLevel'), $levelName, $defaultValue); |
|
169 | - if(!$result instanceof LoggerLevel) { |
|
170 | - $result = $defaultValue; |
|
171 | - } |
|
172 | - } |
|
173 | - return $result; |
|
174 | - } |
|
167 | + if(class_exists($clazz)) { |
|
168 | + $result = @call_user_func(array($clazz, 'toLevel'), $levelName, $defaultValue); |
|
169 | + if(!$result instanceof LoggerLevel) { |
|
170 | + $result = $defaultValue; |
|
171 | + } |
|
172 | + } |
|
173 | + return $result; |
|
174 | + } |
|
175 | 175 | |
176 | - /** |
|
177 | - * @param string $value |
|
178 | - * @param float $default |
|
179 | - * @return float |
|
180 | - * |
|
181 | - * @static |
|
182 | - */ |
|
183 | - public static function toFileSize($value, $default) { |
|
184 | - if($value === null) { |
|
185 | - return $default; |
|
186 | - } |
|
176 | + /** |
|
177 | + * @param string $value |
|
178 | + * @param float $default |
|
179 | + * @return float |
|
180 | + * |
|
181 | + * @static |
|
182 | + */ |
|
183 | + public static function toFileSize($value, $default) { |
|
184 | + if($value === null) { |
|
185 | + return $default; |
|
186 | + } |
|
187 | 187 | |
188 | - $s = strtoupper(trim($value)); |
|
189 | - $multiplier = (float)1; |
|
190 | - if(($index = strpos($s, 'KB')) !== false) { |
|
191 | - $multiplier = 1024; |
|
192 | - $s = substr($s, 0, $index); |
|
193 | - } else if(($index = strpos($s, 'MB')) !== false) { |
|
194 | - $multiplier = 1024 * 1024; |
|
195 | - $s = substr($s, 0, $index); |
|
196 | - } else if(($index = strpos($s, 'GB')) !== false) { |
|
197 | - $multiplier = 1024 * 1024 * 1024; |
|
198 | - $s = substr($s, 0, $index); |
|
199 | - } |
|
200 | - if(is_numeric($s)) { |
|
201 | - return (float)$s * $multiplier; |
|
202 | - } |
|
203 | - return $default; |
|
204 | - } |
|
188 | + $s = strtoupper(trim($value)); |
|
189 | + $multiplier = (float)1; |
|
190 | + if(($index = strpos($s, 'KB')) !== false) { |
|
191 | + $multiplier = 1024; |
|
192 | + $s = substr($s, 0, $index); |
|
193 | + } else if(($index = strpos($s, 'MB')) !== false) { |
|
194 | + $multiplier = 1024 * 1024; |
|
195 | + $s = substr($s, 0, $index); |
|
196 | + } else if(($index = strpos($s, 'GB')) !== false) { |
|
197 | + $multiplier = 1024 * 1024 * 1024; |
|
198 | + $s = substr($s, 0, $index); |
|
199 | + } |
|
200 | + if(is_numeric($s)) { |
|
201 | + return (float)$s * $multiplier; |
|
202 | + } |
|
203 | + return $default; |
|
204 | + } |
|
205 | 205 | |
206 | - /** |
|
207 | - * Find the value corresponding to <var>$key</var> in |
|
208 | - * <var>$props</var>. Then perform variable substitution on the |
|
209 | - * found value. |
|
210 | - * |
|
211 | - * @param string $key |
|
212 | - * @param array $props |
|
213 | - * @return string |
|
214 | - * |
|
215 | - * @static |
|
216 | - */ |
|
217 | - public static function findAndSubst($key, $props) { |
|
218 | - $value = @$props[$key]; |
|
206 | + /** |
|
207 | + * Find the value corresponding to <var>$key</var> in |
|
208 | + * <var>$props</var>. Then perform variable substitution on the |
|
209 | + * found value. |
|
210 | + * |
|
211 | + * @param string $key |
|
212 | + * @param array $props |
|
213 | + * @return string |
|
214 | + * |
|
215 | + * @static |
|
216 | + */ |
|
217 | + public static function findAndSubst($key, $props) { |
|
218 | + $value = @$props[$key]; |
|
219 | 219 | |
220 | 220 | // If coming from the LoggerConfiguratorIni, some options were |
221 | 221 | // already mangled by parse_ini_file: |
@@ -233,90 +233,90 @@ discard block |
||
233 | 233 | // explicitly set by the user and is different from an option which |
234 | 234 | // has not been specified and therefore keeps its default value. |
235 | 235 | // |
236 | - // if(!empty($value)) { |
|
237 | - return LoggerOptionConverter::substVars($value, $props); |
|
238 | - // } |
|
236 | + // if(!empty($value)) { |
|
237 | + return LoggerOptionConverter::substVars($value, $props); |
|
238 | + // } |
|
239 | 239 | } |
240 | 240 | |
241 | - /** |
|
242 | - * Perform variable substitution in string <var>$val</var> from the |
|
243 | - * values of keys found with the {@link getSystemProperty()} method. |
|
244 | - * |
|
245 | - * <p>The variable substitution delimeters are <b>${</b> and <b>}</b>. |
|
246 | - * |
|
247 | - * <p>For example, if the "MY_CONSTANT" contains "value", then |
|
248 | - * the call |
|
249 | - * <code> |
|
250 | - * $s = LoggerOptionConverter::substituteVars("Value of key is ${MY_CONSTANT}."); |
|
251 | - * </code> |
|
252 | - * will set the variable <i>$s</i> to "Value of key is value.".</p> |
|
253 | - * |
|
254 | - * <p>If no value could be found for the specified key, then the |
|
255 | - * <var>$props</var> parameter is searched, if the value could not |
|
256 | - * be found there, then substitution defaults to the empty string.</p> |
|
257 | - * |
|
258 | - * <p>For example, if {@link getSystemProperty()} cannot find any value for the key |
|
259 | - * "inexistentKey", then the call |
|
260 | - * <code> |
|
261 | - * $s = LoggerOptionConverter::substVars("Value of inexistentKey is [${inexistentKey}]"); |
|
262 | - * </code> |
|
263 | - * will set <var>$s</var> to "Value of inexistentKey is []".</p> |
|
264 | - * |
|
265 | - * <p>A warn is thrown if <var>$val</var> contains a start delimeter "${" |
|
266 | - * which is not balanced by a stop delimeter "}" and an empty string is returned.</p> |
|
267 | - * |
|
268 | - * @author Avy Sharell |
|
269 | - * |
|
270 | - * @param string $val The string on which variable substitution is performed. |
|
271 | - * @param array $props |
|
272 | - * @return string |
|
273 | - * |
|
274 | - * @static |
|
275 | - */ |
|
276 | - // TODO: this method doesn't work correctly with key = true, it needs key = "true" which is odd |
|
277 | - public static function substVars($val, $props = null) { |
|
278 | - $sbuf = ''; |
|
279 | - $i = 0; |
|
280 | - while(true) { |
|
281 | - $j = strpos($val, self::DELIM_START, $i); |
|
282 | - if($j === false) { |
|
283 | - // no more variables |
|
284 | - if($i == 0) { // this is a simple string |
|
285 | - return $val; |
|
286 | - } else { // add the tail string which contails no variables and return the result. |
|
287 | - $sbuf .= substr($val, $i); |
|
288 | - return $sbuf; |
|
289 | - } |
|
290 | - } else { |
|
241 | + /** |
|
242 | + * Perform variable substitution in string <var>$val</var> from the |
|
243 | + * values of keys found with the {@link getSystemProperty()} method. |
|
244 | + * |
|
245 | + * <p>The variable substitution delimeters are <b>${</b> and <b>}</b>. |
|
246 | + * |
|
247 | + * <p>For example, if the "MY_CONSTANT" contains "value", then |
|
248 | + * the call |
|
249 | + * <code> |
|
250 | + * $s = LoggerOptionConverter::substituteVars("Value of key is ${MY_CONSTANT}."); |
|
251 | + * </code> |
|
252 | + * will set the variable <i>$s</i> to "Value of key is value.".</p> |
|
253 | + * |
|
254 | + * <p>If no value could be found for the specified key, then the |
|
255 | + * <var>$props</var> parameter is searched, if the value could not |
|
256 | + * be found there, then substitution defaults to the empty string.</p> |
|
257 | + * |
|
258 | + * <p>For example, if {@link getSystemProperty()} cannot find any value for the key |
|
259 | + * "inexistentKey", then the call |
|
260 | + * <code> |
|
261 | + * $s = LoggerOptionConverter::substVars("Value of inexistentKey is [${inexistentKey}]"); |
|
262 | + * </code> |
|
263 | + * will set <var>$s</var> to "Value of inexistentKey is []".</p> |
|
264 | + * |
|
265 | + * <p>A warn is thrown if <var>$val</var> contains a start delimeter "${" |
|
266 | + * which is not balanced by a stop delimeter "}" and an empty string is returned.</p> |
|
267 | + * |
|
268 | + * @author Avy Sharell |
|
269 | + * |
|
270 | + * @param string $val The string on which variable substitution is performed. |
|
271 | + * @param array $props |
|
272 | + * @return string |
|
273 | + * |
|
274 | + * @static |
|
275 | + */ |
|
276 | + // TODO: this method doesn't work correctly with key = true, it needs key = "true" which is odd |
|
277 | + public static function substVars($val, $props = null) { |
|
278 | + $sbuf = ''; |
|
279 | + $i = 0; |
|
280 | + while(true) { |
|
281 | + $j = strpos($val, self::DELIM_START, $i); |
|
282 | + if($j === false) { |
|
283 | + // no more variables |
|
284 | + if($i == 0) { // this is a simple string |
|
285 | + return $val; |
|
286 | + } else { // add the tail string which contails no variables and return the result. |
|
287 | + $sbuf .= substr($val, $i); |
|
288 | + return $sbuf; |
|
289 | + } |
|
290 | + } else { |
|
291 | 291 | |
292 | - $sbuf .= substr($val, $i, $j-$i); |
|
293 | - $k = strpos($val, self::DELIM_STOP, $j); |
|
294 | - if($k === false) { |
|
295 | - // LoggerOptionConverter::substVars() has no closing brace. Opening brace |
|
296 | - return ''; |
|
297 | - } else { |
|
298 | - $j += self::START_LEN; |
|
299 | - $key = substr($val, $j, $k - $j); |
|
300 | - // first try in System properties |
|
301 | - $replacement = LoggerOptionConverter::getSystemProperty($key, null); |
|
302 | - // then try props parameter |
|
303 | - if($replacement == null and $props !== null) { |
|
304 | - $replacement = @$props[$key]; |
|
305 | - } |
|
292 | + $sbuf .= substr($val, $i, $j-$i); |
|
293 | + $k = strpos($val, self::DELIM_STOP, $j); |
|
294 | + if($k === false) { |
|
295 | + // LoggerOptionConverter::substVars() has no closing brace. Opening brace |
|
296 | + return ''; |
|
297 | + } else { |
|
298 | + $j += self::START_LEN; |
|
299 | + $key = substr($val, $j, $k - $j); |
|
300 | + // first try in System properties |
|
301 | + $replacement = LoggerOptionConverter::getSystemProperty($key, null); |
|
302 | + // then try props parameter |
|
303 | + if($replacement == null and $props !== null) { |
|
304 | + $replacement = @$props[$key]; |
|
305 | + } |
|
306 | 306 | |
307 | - if(!empty($replacement)) { |
|
308 | - // Do variable substitution on the replacement string |
|
309 | - // such that we can solve "Hello ${x2}" as "Hello p1" |
|
310 | - // the where the properties are |
|
311 | - // x1=p1 |
|
312 | - // x2=${x1} |
|
313 | - $recursiveReplacement = LoggerOptionConverter::substVars($replacement, $props); |
|
314 | - $sbuf .= $recursiveReplacement; |
|
315 | - } |
|
316 | - $i = $k + self::DELIM_STOP_LEN; |
|
317 | - } |
|
318 | - } |
|
319 | - } |
|
320 | - } |
|
307 | + if(!empty($replacement)) { |
|
308 | + // Do variable substitution on the replacement string |
|
309 | + // such that we can solve "Hello ${x2}" as "Hello p1" |
|
310 | + // the where the properties are |
|
311 | + // x1=p1 |
|
312 | + // x2=${x1} |
|
313 | + $recursiveReplacement = LoggerOptionConverter::substVars($replacement, $props); |
|
314 | + $sbuf .= $recursiveReplacement; |
|
315 | + } |
|
316 | + $i = $k + self::DELIM_STOP_LEN; |
|
317 | + } |
|
318 | + } |
|
319 | + } |
|
320 | + } |
|
321 | 321 | |
322 | 322 | } |
@@ -50,19 +50,19 @@ |
||
50 | 50 | */ |
51 | 51 | class LoggerLayoutTTCC extends LoggerLayout { |
52 | 52 | |
53 | - /** |
|
54 | - * String constant designating no time information. Current value of |
|
55 | - * this constant is <b>NULL</b>. |
|
56 | - */ |
|
57 | - // TODO: not used? |
|
58 | - const LOG4PHP_LOGGER_LAYOUT_NULL_DATE_FORMAT = 'NULL'; |
|
53 | + /** |
|
54 | + * String constant designating no time information. Current value of |
|
55 | + * this constant is <b>NULL</b>. |
|
56 | + */ |
|
57 | + // TODO: not used? |
|
58 | + const LOG4PHP_LOGGER_LAYOUT_NULL_DATE_FORMAT = 'NULL'; |
|
59 | 59 | |
60 | - /** |
|
61 | - * String constant designating relative time. Current value of |
|
62 | - * this constant is <b>RELATIVE</b>. |
|
63 | - */ |
|
64 | - // TODO: not used? |
|
65 | - const LOG4PHP_LOGGER_LAYOUT_RELATIVE_TIME_DATE_FORMAT = 'RELATIVE'; |
|
60 | + /** |
|
61 | + * String constant designating relative time. Current value of |
|
62 | + * this constant is <b>RELATIVE</b>. |
|
63 | + */ |
|
64 | + // TODO: not used? |
|
65 | + const LOG4PHP_LOGGER_LAYOUT_RELATIVE_TIME_DATE_FORMAT = 'RELATIVE'; |
|
66 | 66 | |
67 | 67 | // Internal representation of options |
68 | 68 | protected $threadPrinting = true; |