Skip to content

Commit

Permalink
Merge pull request #248 from t3solution/5.2.1
Browse files Browse the repository at this point in the history
New release v5.2.1
  • Loading branch information
t3solution committed Aug 19, 2022
2 parents 0cf8f9f + 1e1c49a commit f01e5bb
Show file tree
Hide file tree
Showing 19 changed files with 258 additions and 216 deletions.
9 changes: 6 additions & 3 deletions Classes/Backend/Preview/T3sbPreviewRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,15 @@ public function renderPageModulePreviewHeader(GridColumnItem $item): string
public function renderPageModulePreviewContent(GridColumnItem $item): string
{
$typo3Version = new Typo3Version();
$pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
if ($typo3Version->getMajorVersion() === 11) {
$pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
$pageRenderer->loadRequireJsModule(
'TYPO3/CMS/T3sbootstrap/Bootstrap',
'function() { console.log("Loaded bootstrap.js by t3sbootstrap."); }'
'function() { console.log("Loaded bootstrap.js by t3sbootstrap!"); }'
);
$pageRenderer->addCssFile('EXT:t3sbootstrap/Resources/Public/Backend/bestyles-v11.css');
} else {
$pageRenderer->addCssFile('EXT:t3sbootstrap/Resources/Public/Backend/bestyles-v10.css');
}
$content = parent::renderPageModulePreviewContent($item);
$context = $item->getContext();
Expand Down Expand Up @@ -336,7 +339,7 @@ public function renderPageModulePreviewContent(GridColumnItem $item): string
if (!empty($col['colPos'])) {
$records = $container->getChildrenByColPos($col['colPos']);
foreach ($records as $contentRecord) {
$columnItem = GeneralUtility::makeInstance(ContainerGridColumnItem::class, $context, $columnObject, $contentRecord, $container);
$columnItem = GeneralUtility::makeInstance(ContainerGridColumnItem::class, $context, $columnObject, $contentRecord, $container, false);
$columnObject->addItem($columnItem);
}
}
Expand Down
143 changes: 98 additions & 45 deletions Classes/Command/CdnToLocal.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

namespace T3SBS\T3sbootstrap\Command;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use TYPO3\CMS\Core\Utility\GeneralUtility;
Expand All @@ -20,11 +18,11 @@
*/
class CdnToLocal extends CommandBase
{

const localZipFile = 'googlefont.zip';
const localZipPath = 'fileadmin/T3SB/Resources/Public/CSS/googlefonts/';
const zipFilePath = 'https://google-webfonts-helper.herokuapp.com/api/fonts/';
const localGoogleFile = 'fileadmin/T3SB/Resources/Public/CSS/googlefonts.css';
const googleFilestyles = ['300', 'regular', '700'];

protected $configurationManager;

Expand All @@ -45,6 +43,7 @@ protected function configure()
}



/**
* Update all records
*
Expand Down Expand Up @@ -75,11 +74,10 @@ protected function execute(InputInterface $input, OutputInterface $output)
}
}
} else {
$settings['cdn']['fontawesome'] = '5.15.4';
$settings['cdn']['fontawesome'] = $settings['cdn']['fontawesome6latest'];
}

if ( !empty($settings['cdn']['googlefonts']) && empty($settings['cdn']['noZip']) ) {
self::getGoogleFonts($settings['cdn']['googlefonts']);
self::getGoogleFonts($settings['cdn']['googlefonts'], $settings['preloadGooleFonts']);
} else {
$localZipPath = GeneralUtility::getFileAbsFileName(self::localZipPath);
if ( is_dir($localZipPath) ) {
Expand Down Expand Up @@ -302,62 +300,117 @@ private function writeCustomFile($customPath, $customFileName, $cdnPath, $extend
}


private function getGoogleFonts($googleFonts) {
private function getGoogleFonts($googleFonts, $preloadGooleFonts) {
$localZipPath = GeneralUtility::getFileAbsFileName(self::localZipPath);
if ( is_dir($localZipPath) ) {
parent::rmDir($localZipPath);
}
mkdir($localZipPath, 0777, true);
$localZipFile = GeneralUtility::getFileAbsFileName(self::localZipPath.self::localZipFile);
$googleFontsArr = explode(',', $googleFonts);
$cFF = '';
foreach ($googleFontsArr as $key=>$font) {
foreach ($googleFontsArr as $font) {
$fontFamily = trim($font);
$font = str_replace(' ', '-', trim($font));
$zipFilename = strtolower($font).'?download=zip&subsets=latin&variants=regular';

$zipContent = GeneralUtility::getURL(self::zipFilePath . $zipFilename);
foreach ( self::googleFilestyles as $style ) {
$zipFilename = strtolower($font).'?download=zip&subsets=latin&variants='.$style;
$zipContent = GeneralUtility::getURL(self::zipFilePath . $zipFilename);
$fontArr[$fontFamily] = self::getGoogleFiles($zipContent, $localZipFile, $localZipPath);
}
}

if ($zipContent) {
GeneralUtility::writeFile($localZipFile, $zipContent);
$extractTo = $localZipPath;
$zip = new \ZipArchive;
if ($zip->open($localZipFile) === TRUE) {
$zip->extractTo($extractTo);
$zip->close();
} else {
throw new \InvalidArgumentException('Sorry ZIP creation failed at this time!', 1655291667);
}
$zipFile = GeneralUtility::getFileAbsFileName($localZipFile);
if (file_exists($zipFile)) unlink($zipFile);
$googleFiles = scandir($localZipPath);
$css = '';
foreach ($googleFiles as $googleFile) {
if ( str_ends_with($googleFile, 'woff') && $cFF != $fontFamily ) {
$googleFileArr[$key] = $googleFile;
$cFF = $fontFamily;
if ( is_array($fontArr)) {
foreach ($fontArr as $fontFamily=>$googlePath) {
$sliceArr[$fontFamily] = array_slice($googlePath, 0, 1);
}
$css = '';
$headerData = '';
foreach ($sliceArr as $fontFamily=>$googlePath) {
foreach ( self::googleFilestyles as $i=>$style ) {
$file = str_replace('300','', explode('.', $googlePath[0])[0]).trim($style);
$style = $style == 'regular' ? '400' : $style;
if (!empty($preloadGooleFonts)) {
$num = self::generateRandomString();
$s = $i + 1;
$headerData .= ' 22'.$num.$i.' = TEXT'.LF;
$headerData .= ' 22'.$num.$i.'.value = <link rel="preload" href="/fileadmin/T3SB/Resources/Public/CSS/googlefonts/'.
$file.'.woff" as="font" type="font/woff" crossorigin="anonymous">'.LF;
$headerData .= ' 22'.$num.$s.' = TEXT'.LF;
$headerData .= ' 22'.$num.$s.'.value = <link rel="preload" href="/fileadmin/T3SB/Resources/Public/CSS/googlefonts/'.
$file.'.woff2" as="font" type="font/woff2" crossorigin="anonymous">'.LF;
}

$css .= "@font-face {
font-family: '".$fontFamily."';
font-style: normal;
font-weight: ".$style.";
src: url('googlefonts/".$file.".eot');
src: local(''),
url('googlefonts/".$file.".eot?#iefix') format('embedded-opentype'),
url('googlefonts/".$file.".woff2') format('woff2'),
url('googlefonts/".$file.".woff') format('woff');
url('googlefonts/".$file.".ttf') format('truetype'),
url('googlefonts/".$file.".svg#".trim(str_replace(' ', '', $fontFamily))."') format('svg');
}".LF.LF;
}
} else {
throw new \InvalidArgumentException('Check the spelling of the google fonts!', 1657464667);
}

if (!empty($preloadGooleFonts)) {
$setup = 'page.headerData {'.LF.$headerData;
$setup .= '}';
$customDir = 'fileadmin/T3SB/Configuration/TypoScript/';
$customPath = GeneralUtility::getFileAbsFileName($customDir);
$customFileName = 'preloadGooleFonts.typoscript';
$customFile = $customPath.$customFileName;
if (file_exists($customFile)) {unlink($customFile);}
if (!is_dir($customPath)) {mkdir($customPath, 0777, true);}
GeneralUtility::writeFile($customFile, $setup);
}

if (!empty($css)) {
$cssFile = GeneralUtility::getFileAbsFileName(self::localGoogleFile);
if (file_exists($cssFile)) unlink($cssFile);
GeneralUtility::writeFile($cssFile, $css);
}
}
}

foreach ($googleFileArr as $key=>$googleFile) {
$css .= "@font-face {".LF."
font-family: '".trim($googleFontsArr[$key])."';".LF."
font-style: normal;".LF."
font-weight: 400;".LF."
src: local(''),".LF."
url('googlefonts/".$googleFile."') format('woff2'),".LF."
url('googlefonts/".$googleFile."') format('woff');".LF."
}".LF.LF;

private function getGoogleFiles($zipContent, $localZipFile, $localZipPath) {
if ($zipContent) {
GeneralUtility::writeFile($localZipFile, $zipContent);
$zip = new \ZipArchive;
if ($zip->open($localZipFile) === TRUE) {
$zip->extractTo($localZipPath);
$zip->close();
} else {
throw new \InvalidArgumentException('Sorry ZIP creation failed at this time!', 1655291469);
}
$zipFile = GeneralUtility::getFileAbsFileName($localZipFile);
if (file_exists($zipFile)) unlink($zipFile);
$googleFiles = scandir($localZipPath);
$css = '';
$googleFileArr = [];
foreach ($googleFiles as $googleFile) {
if ( str_ends_with($googleFile, 'woff') ) {
$googleFileArr[] = $googleFile;
}
}
} else {
throw new \InvalidArgumentException('Check the spelling of the google fonts!', 1657464667);
}
$cssFile = GeneralUtility::getFileAbsFileName(self::localGoogleFile);
if (file_exists($cssFile)) unlink($cssFile);
GeneralUtility::writeFile($cssFile, $css);

return $googleFileArr;
}


private function generateRandomString($length = 4) {
$characters = '0123456789';
$charactersLength = strlen($characters);
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, $charactersLength - 1)];
}
return $randomString;
}

}
}
4 changes: 1 addition & 3 deletions Classes/Command/CommandBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,4 @@ public function rmDir(string $path) : int
return 0;
}



}
}
1 change: 0 additions & 1 deletion Classes/Command/CustomScss.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ protected function execute(InputInterface $input, OutputInterface $output)
$customDir = !empty($settings['customScssPath']) ? $settings['customScssPath'] : 'fileadmin/T3SB/Resources/Public/SCSS/';
$customPath = GeneralUtility::getFileAbsFileName($customDir);


$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('pages');
$result = $queryBuilder
->select('*')
Expand Down
2 changes: 1 addition & 1 deletion Classes/Components/Card.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public function getProcessedData(array $processedData, array $flexconf, array $p
}
// parent equal Height
if ( !empty($parentflexconf['equalHeight']) ) {
$cardClass .= ' w-100';
$cardClass .= ' h-100';
}

$processedData['class'] = trim($cardClass);
Expand Down
2 changes: 1 addition & 1 deletion Classes/Controller/AbstractCompatibilityController.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function listAction(bool $deleted = FALSE, bool $created = FALSE, bool $u
$assignedOptions['deleted'] = $deleted;
$assignedOptions['created'] = $created;

if ( (int)$this->settings['customScss'] === 1 ) {
if ( !empty($this->settings['customScss']) && (int)$this->settings['customScss'] === 1 ) {
$customScss = parent::getCustomScss('custom-variables');
$assignedOptions['custom-variables'] = !empty($customScss['custom-variables']) ? $customScss['custom-variables'] : '';
$customScss = parent::getCustomScss('custom');
Expand Down
45 changes: 44 additions & 1 deletion Classes/Controller/AbstractController.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ public function initializeAction()
->execute()->fetchAll();

$pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
if ($typo3Version->getMajorVersion() === 11) {
$pageRenderer->addCssFile('EXT:t3sbootstrap/Resources/Public/Backend/bestyles-v11.css');
} else {
$pageRenderer->addCssFile('EXT:t3sbootstrap/Resources/Public/Backend/bestyles-v10.css');
}
$pageRenderer->loadRequireJsModule(
'TYPO3/CMS/T3sbootstrap/Bootstrap',
'function() { console.log("Loaded bootstrap.js by t3sbootstrap!"); }'
Expand Down Expand Up @@ -282,6 +287,17 @@ protected function writeConstants(): void
}
}

// outsourced setup
$setup = '';
$model = GeneralUtility::makeInstance(Config::class);
foreach ( $this->objectToArr($model) as $key=>$value) {
if ( !str_starts_with($key, '_') ) {
$setup .= 'page.10.settings.config.'.$key.' = {$bootstrap.config.'.$key.'}'.PHP_EOL;
}
}
$setup .= 'page.10.settings.config.navbarBreakpointWidth = {$bootstrap.config.navbarBreakpointWidth}'.PHP_EOL;

// outsourced constants
foreach ( $configurations as $config ) {
if ($config->getPid() == $config->getHomepageUid()) {
// is root page
Expand Down Expand Up @@ -319,12 +335,39 @@ protected function writeConstants(): void
if (!is_dir($customPath)) {
mkdir($customPath, 0777, true);
}

// constants
GeneralUtility::writeFile($customFile, $filecontent);

$customFileName = 't3sbsetup.typoscript';
$customFile = $customPath.$customFileName;

if (file_exists($customFile)) {
unlink($customFile);
}
if (!is_dir($customPath)) {
mkdir($customPath, 0777, true);
}
// setup
GeneralUtility::writeFile($customFile, $setup);

}
}


private function objectToArr($obj)
{
$result = [];
$cls = new \ReflectionClass($obj);
$props = $cls->getProperties();
foreach ($props as $key=>$prop)
{
$result[$prop->getName()] = 'get'.ucfirst($prop->getName());
}

return $result;
}


/**
* Get the data from DB
*/
Expand Down
Loading

0 comments on commit f01e5bb

Please sign in to comment.