diff options
author | Nicolas LÅ“uillet <nicolas@loeuillet.org> | 2014-07-12 19:01:11 +0200 |
---|---|---|
committer | Nicolas LÅ“uillet <nicolas@loeuillet.org> | 2014-07-12 19:01:11 +0200 |
commit | 2f26729c841a68669a1baf799091cb2c6c9f585a (patch) | |
tree | e1e388bb73c7533aad85bf1f672f867b62b247e4 /inc/poche/Tools.class.php | |
parent | b6a3c8866a4cb88b009e7ba45c5e223e0fdae188 (diff) | |
download | wallabag-2f26729c841a68669a1baf799091cb2c6c9f585a.tar.gz wallabag-2f26729c841a68669a1baf799091cb2c6c9f585a.tar.zst wallabag-2f26729c841a68669a1baf799091cb2c6c9f585a.zip |
Refactor
Diffstat (limited to 'inc/poche/Tools.class.php')
-rwxr-xr-x | inc/poche/Tools.class.php | 41 |
1 files changed, 36 insertions, 5 deletions
diff --git a/inc/poche/Tools.class.php b/inc/poche/Tools.class.php index 762e4446..63137d76 100755 --- a/inc/poche/Tools.class.php +++ b/inc/poche/Tools.class.php | |||
@@ -10,11 +10,6 @@ | |||
10 | 10 | ||
11 | final class Tools | 11 | final class Tools |
12 | { | 12 | { |
13 | private function __construct() | ||
14 | { | ||
15 | |||
16 | } | ||
17 | |||
18 | /** | 13 | /** |
19 | * Initialize PHP environment | 14 | * Initialize PHP environment |
20 | */ | 15 | */ |
@@ -393,4 +388,40 @@ final class Tools | |||
393 | return isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH']==='XMLHttpRequest'; | 388 | return isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH']==='XMLHttpRequest'; |
394 | } | 389 | } |
395 | 390 | ||
391 | /* | ||
392 | * Empty cache folder | ||
393 | */ | ||
394 | public static function emptyCache() | ||
395 | { | ||
396 | $files = new RecursiveIteratorIterator( | ||
397 | new RecursiveDirectoryIterator(CACHE, RecursiveDirectoryIterator::SKIP_DOTS), | ||
398 | RecursiveIteratorIterator::CHILD_FIRST | ||
399 | ); | ||
400 | |||
401 | foreach ($files as $fileInfo) { | ||
402 | $todo = ($fileInfo->isDir() ? 'rmdir' : 'unlink'); | ||
403 | $todo($fileInfo->getRealPath()); | ||
404 | } | ||
405 | |||
406 | Tools::logm('empty cache'); | ||
407 | Tools::redirect(); | ||
408 | } | ||
409 | |||
410 | public static function generateToken() | ||
411 | { | ||
412 | if (ini_get('open_basedir') === '') { | ||
413 | if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { | ||
414 | // alternative to /dev/urandom for Windows | ||
415 | $token = substr(base64_encode(uniqid(mt_rand(), true)), 0, 20); | ||
416 | } else { | ||
417 | $token = substr(base64_encode(file_get_contents('/dev/urandom', false, null, 0, 20)), 0, 15); | ||
418 | } | ||
419 | } | ||
420 | else { | ||
421 | $token = substr(base64_encode(uniqid(mt_rand(), true)), 0, 20); | ||
422 | } | ||
423 | |||
424 | return str_replace('+', '', $token); | ||
425 | } | ||
426 | |||
396 | } | 427 | } |