mirror of
https://github.com/wallabag/wallabag.git
synced 2025-08-01 17:38:38 +00:00
Refactor
This commit is contained in:
parent
b6a3c8866a
commit
2f26729c84
14 changed files with 391 additions and 339 deletions
|
@ -10,11 +10,6 @@
|
|||
|
||||
final class Tools
|
||||
{
|
||||
private function __construct()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize PHP environment
|
||||
*/
|
||||
|
@ -393,4 +388,40 @@ final class Tools
|
|||
return isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH']==='XMLHttpRequest';
|
||||
}
|
||||
|
||||
/*
|
||||
* Empty cache folder
|
||||
*/
|
||||
public static function emptyCache()
|
||||
{
|
||||
$files = new RecursiveIteratorIterator(
|
||||
new RecursiveDirectoryIterator(CACHE, RecursiveDirectoryIterator::SKIP_DOTS),
|
||||
RecursiveIteratorIterator::CHILD_FIRST
|
||||
);
|
||||
|
||||
foreach ($files as $fileInfo) {
|
||||
$todo = ($fileInfo->isDir() ? 'rmdir' : 'unlink');
|
||||
$todo($fileInfo->getRealPath());
|
||||
}
|
||||
|
||||
Tools::logm('empty cache');
|
||||
Tools::redirect();
|
||||
}
|
||||
|
||||
public static function generateToken()
|
||||
{
|
||||
if (ini_get('open_basedir') === '') {
|
||||
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
|
||||
// alternative to /dev/urandom for Windows
|
||||
$token = substr(base64_encode(uniqid(mt_rand(), true)), 0, 20);
|
||||
} else {
|
||||
$token = substr(base64_encode(file_get_contents('/dev/urandom', false, null, 0, 20)), 0, 15);
|
||||
}
|
||||
}
|
||||
else {
|
||||
$token = substr(base64_encode(uniqid(mt_rand(), true)), 0, 20);
|
||||
}
|
||||
|
||||
return str_replace('+', '', $token);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue