Skip to content

Commit

Permalink
improved downloading theme files support
Browse files Browse the repository at this point in the history
  • Loading branch information
iMokhles committed May 29, 2019
1 parent 0a5701e commit 265f34b
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 63 deletions.
80 changes: 31 additions & 49 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/Command/MultiAuthListThemes.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function handle()
public static function githubLinksForFreeThemes() {
return [
'adminlte2' => 'https://github.com/ColorlibHQ/AdminLTE/archive/master.zip',
'tabler' => 'https://github.com/tabler/tabler/archive/dev.zip',
'tabler' => 'https://github.com/tabler/tabler/archive/master.zip',
];
}

Expand Down
41 changes: 28 additions & 13 deletions src/Command/MultiAuthPrepare.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,12 @@ public function handle()
$this->installProjectConfig($admin_theme);
$this->progressBar->advance();

$this->line(" installing admin panel files under public folder...");
$this->installPublicFilesIfNeeded($admin_theme);
$this->progressBar->advance();
if (array_key_exists($admin_theme, MultiAuthListThemes::listFreeThemes())) {
$this->line(" installing admin panel files under public folder...");
$this->installPublicFilesIfNeeded($admin_theme);
$this->progressBar->advance();
}


$this->line(" installing prologue alert...");
$this->installPrologueAlert();
Expand Down Expand Up @@ -984,17 +987,29 @@ public function installProjectConfig($theme_name = 'adminlte2')
*/
public function installPublicFilesIfNeeded($theme_name = 'adminlte2') {

$githubLink = $this->getGitLinkForFreeTheme($theme_name);
if (!is_null($githubLink) && is_string($githubLink)) {
$zipFileName = basename($githubLink);
$zipFile = file_get_contents($githubLink);
$downloadZipPath = $this->getPublicFolderPath().DIRECTORY_SEPARATOR.$theme_name;
if (!file_exists($downloadZipPath)) {
mkdir($downloadZipPath);
$publicPath = $this->getPublicFolderPath();
$themePublicPath = $publicPath.DIRECTORY_SEPARATOR.$theme_name;
if (!file_exists($themePublicPath) && !(new \FilesystemIterator($themePublicPath))->valid()) {
$githubLink = $this->getGitLinkForFreeTheme($theme_name);
if (!is_null($githubLink) && is_string($githubLink)) {
$zipFileName = basename($githubLink);
$zipFile = file_get_contents($githubLink);
$publicPath = $this->getPublicFolderPath();
$zipFilePath = $publicPath.DIRECTORY_SEPARATOR.$zipFileName;
file_put_contents($zipFilePath, $zipFile);
$extracted = $this->unzipThemeFile($zipFilePath, $publicPath);
if ($extracted) {
$renamed = false;
if ($theme_name === 'adminlte2') {
$adminLte2Path = $publicPath.DIRECTORY_SEPARATOR."AdminLTE-master";
$renamed = rename($adminLte2Path, $themePublicPath);
} else if ($theme_name === 'tabler') {
$tablerPath = $publicPath.DIRECTORY_SEPARATOR."tabler-master";
$renamed = rename($tablerPath, $themePublicPath);
}
return $renamed;
}
}
$zipFilePath = $downloadZipPath.DIRECTORY_SEPARATOR.$zipFileName;
file_put_contents($zipFilePath, $zipFile);
return $this->unzipThemeFile($zipFilePath, $downloadZipPath);
}
return false;
}
Expand Down

0 comments on commit 265f34b

Please sign in to comment.