mirror of
https://github.com/LinkStackOrg/LinkStack.git
synced 2025-05-04 03:48:53 +02:00
Refactor theme extraction logic in UserController
This commit is contained in:
parent
46343005af
commit
d69558aefd
@ -753,30 +753,46 @@ class UserController extends Controller
|
|||||||
|
|
||||||
if (!empty($zipfile) && Auth::user()->role == 'admin') {
|
if (!empty($zipfile) && Auth::user()->role == 'admin') {
|
||||||
|
|
||||||
$zipfile->move(base_path('/themes'), "temp.zip");
|
$themesPath = base_path('themes');
|
||||||
|
$tmpPath = base_path() . '/themes/temp.zip';
|
||||||
|
$zipfile->move($themesPath, "temp.zip");
|
||||||
|
|
||||||
$zip = new ZipArchive;
|
$zip = new ZipArchive;
|
||||||
$zip->open(base_path() . '/themes/temp.zip');
|
$zip->open($tmpPath);
|
||||||
$zip->extractTo(base_path() . '/themes');
|
$zip->extractTo($themesPath);
|
||||||
$zip->close();
|
$zip->close();
|
||||||
unlink(base_path() . '/themes/temp.zip');
|
unlink($tmpPath);
|
||||||
|
|
||||||
// Removes version numbers from folder.
|
// Removes version numbers from folder.
|
||||||
|
|
||||||
$folder = base_path('themes');
|
|
||||||
$regex = '/[0-9.-]/';
|
$regex = '/[0-9.-]/';
|
||||||
$files = scandir($folder);
|
$files = scandir($themesPath);
|
||||||
$files = array_diff($files, array('.', '..'));
|
$files = array_diff($files, array('.', '..'));
|
||||||
|
|
||||||
foreach ($files as $file) {
|
foreach ($files as $file) {
|
||||||
|
|
||||||
$basename = basename($file);
|
$basename = basename($file);
|
||||||
if (preg_match($regex, $basename)) {
|
$filePath = $themesPath . '/' . $basename;
|
||||||
$newBasename = preg_replace($regex, '', $basename);
|
|
||||||
$newPath = $folder . '/' . $newBasename;
|
if (!is_dir($filePath)) {
|
||||||
File::copyDirectory($file, $newPath);
|
|
||||||
File::deleteDirectory($file);
|
try {
|
||||||
|
File::delete($filePath);
|
||||||
|
} catch (exception $e) {}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (preg_match($regex, $basename)) {
|
||||||
|
|
||||||
|
$newBasename = preg_replace($regex, '', $basename);
|
||||||
|
$newPath = $themesPath . '/' . $newBasename;
|
||||||
|
File::copyDirectory($filePath, $newPath);
|
||||||
|
File::deleteDirectory($filePath);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user