mirror of
https://github.com/PrivateBin/PrivateBin.git
synced 2024-03-22 13:10:41 +08:00
re-use logic from _getExpiredPastes()
Scrutinizer pointed out that the dieerr() function isn't available in this class. Code does work when invoked by migrate script, but this way it would also work in other contexts.
This commit is contained in:
parent
8ede84f000
commit
a799351db3
|
@ -410,37 +410,46 @@ class Filesystem extends AbstractData
|
||||||
public function getAllPastes()
|
public function getAllPastes()
|
||||||
{
|
{
|
||||||
$pastes = array();
|
$pastes = array();
|
||||||
$subdirs = scandir($this->_path);
|
$firstLevel = array_filter(
|
||||||
if ($subdirs === false) {
|
scandir($this->_path),
|
||||||
dieerr('Unable to list directory ' . $this->_path);
|
'PrivateBin\Data\Filesystem::_isFirstLevelDir'
|
||||||
}
|
);
|
||||||
$subdirs = preg_grep('/^[^.].$/', $subdirs);
|
if (count($firstLevel) > 0) {
|
||||||
|
foreach ($firstLevel as $firstKey) {
|
||||||
|
$secondLevel = array_filter(
|
||||||
|
scandir($this->_path . DIRECTORY_SEPARATOR . $firstKey),
|
||||||
|
'PrivateBin\Data\Filesystem::_isSecondLevelDir'
|
||||||
|
);
|
||||||
|
|
||||||
foreach ($subdirs as $subdir) {
|
// skip this folder
|
||||||
$subpath = $this->_path . DIRECTORY_SEPARATOR . $subdir;
|
if (count($secondLevel) == 0) {
|
||||||
|
continue;
|
||||||
$subsubdirs = scandir($subpath);
|
|
||||||
if ($subsubdirs === false) {
|
|
||||||
dieerr('Unable to list directory ' . $subpath);
|
|
||||||
}
|
|
||||||
$subsubdirs = preg_grep('/^[^.].$/', $subsubdirs);
|
|
||||||
foreach ($subsubdirs as $subsubdir) {
|
|
||||||
$subsubpath = $subpath . DIRECTORY_SEPARATOR . $subsubdir;
|
|
||||||
|
|
||||||
$files = scandir($subsubpath);
|
|
||||||
if ($files === false) {
|
|
||||||
dieerr('Unable to list directory ' . $subsubpath);
|
|
||||||
}
|
|
||||||
$files = preg_grep('/\.php$/', $files);
|
|
||||||
|
|
||||||
foreach ($files as $file) {
|
|
||||||
if (substr($file, 0, 4) === $subdir . $subsubdir) {
|
|
||||||
$pastes[] = substr($file, 0, strlen($file) - 4);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
foreach ($secondLevel as $secondKey) {
|
||||||
|
$path = $this->_path . DIRECTORY_SEPARATOR . $firstKey .
|
||||||
|
DIRECTORY_SEPARATOR . $secondKey;
|
||||||
|
if (!is_dir($path)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$thirdLevel = array_filter(
|
||||||
|
array_map(
|
||||||
|
function ($filename) {
|
||||||
|
return strlen($filename) >= 20 ?
|
||||||
|
substr($filename, 0, -4) :
|
||||||
|
$filename;
|
||||||
|
},
|
||||||
|
scandir($path)
|
||||||
|
),
|
||||||
|
'PrivateBin\\Model\\Paste::isValidId'
|
||||||
|
);
|
||||||
|
if (count($thirdLevel) == 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$pastes += $thirdLevel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return $pastes;
|
return $pastes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user