Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First release
- Loading branch information
0 parents
commit 7e21b02
Showing
41 changed files
with
2,378 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.idea/ | ||
.DS_Store | ||
# ignore generated documentation | ||
*GENERATED* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace WEBFONTS\Webfonts\Controller; | ||
|
||
use Psr\Http\Message\ServerRequestInterface; | ||
use TYPO3\CMS\Core\Http\JsonResponse; | ||
use TYPO3\CMS\Core\Utility\GeneralUtility; | ||
use TYPO3\CMS\Fluid\View\StandaloneView; | ||
|
||
abstract class AjaxJsonController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController | ||
{ | ||
|
||
/** | ||
* Helper method to initialize a standalone view instance. | ||
* | ||
* @param ServerRequestInterface $request | ||
* @param string $templatePath | ||
* @return StandaloneView | ||
* @internal param string $template | ||
*/ | ||
protected function initializeStandaloneView(ServerRequestInterface $request, string $templatePath): StandaloneView | ||
{ | ||
$viewRootPath = GeneralUtility::getFileAbsFileName('EXT:webfonts/Resources/Private/'); | ||
$view = GeneralUtility::makeInstance(StandaloneView::class); | ||
$view->getRequest()->setControllerExtensionName('Webfonts'); | ||
$view->setTemplatePathAndFilename($viewRootPath . 'Templates/' . $templatePath); | ||
$view->setLayoutRootPaths([$viewRootPath . 'Layouts/']); | ||
$view->setPartialRootPaths([$viewRootPath . 'Partials/']); | ||
return $view; | ||
} | ||
|
||
|
||
protected function jsonResponse(array $payload, int $httpStatus = 200, string $message = 'OK') | ||
{ | ||
$response = new JsonResponse([ | ||
'status' => $httpStatus, | ||
'message' => $message, | ||
'time' => time(), | ||
'payload' => $payload | ||
]); | ||
return $response->withStatus($httpStatus); | ||
} | ||
|
||
protected function errorResponse(int $error, int $httpStatus, string $message) | ||
{ | ||
$response = new JsonResponse([ | ||
'status' => $httpStatus, | ||
'message' => $message, | ||
'time' => time(), | ||
'error' => $error | ||
]); | ||
|
||
return $response->withStatus($httpStatus); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace WEBFONTS\Webfonts\Controller; | ||
|
||
use TYPO3\CMS\Core\Page\PageRenderer; | ||
use TYPO3\CMS\Core\Utility\GeneralUtility; | ||
use WEBFONTS\Webfonts\Exception\WebfontsException; | ||
use WEBFONTS\Webfonts\Google\GoogleFontInstallationManager; | ||
|
||
class AutoSetupController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController | ||
{ | ||
|
||
|
||
function autoSetupAction() | ||
{ | ||
if (!isset($this->settings['fonts']) || !is_array($this->settings['fonts'])) { | ||
return ''; | ||
} | ||
|
||
foreach ($this->settings['fonts'] as $font) { | ||
$this->installFont($font); | ||
} | ||
|
||
return ''; | ||
} | ||
|
||
private function installFont($font) | ||
{ | ||
if (!isset($font['id'])) { | ||
throw new WebfontsException('Cannot load font parameter \'id\' is missing.', 1586327403); | ||
} | ||
if (!isset($font['provider'])) { | ||
throw new WebfontsException('Cannot load font parameter \'provider\' is missing.', 1586327404); | ||
} | ||
if (!isset($font['charsets'])) { | ||
throw new WebfontsException('Cannot load font parameter \'charsets\' is missing.', 1586327405); | ||
} | ||
if (!isset($font['variants'])) { | ||
throw new WebfontsException('Cannot load font parameter \'subsets\' is missing.', 1586327406); | ||
} | ||
|
||
$id = $font['id']; | ||
$provider = $font['provider']; | ||
$charsets = $font['charsets']; | ||
$variants = $font['variants']; | ||
|
||
if ($provider === 'google_webfonts') { | ||
|
||
$installManager = GoogleFontInstallationManager::getInstance(); | ||
if (!$installManager->hasInstalled($id, $provider, $variants, $charsets)) { | ||
|
||
$requiredVariants = array_map('trim', explode(',', $variants)); | ||
$requiredSubsets = array_map('trim', explode(',', $charsets)); | ||
|
||
$installManager->installFont( | ||
$id, | ||
$provider, | ||
$requiredVariants, | ||
$requiredSubsets | ||
); | ||
|
||
} | ||
|
||
$pageRenderer = GeneralUtility::makeInstance(PageRenderer::class); | ||
$pageRenderer->addCssLibrary('fileadmin/tx_webfonts/fonts/google_webfonts/' . $id . '/import.css'); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace WEBFONTS\Webfonts\Controller; | ||
|
||
|
||
use Psr\Http\Message\ResponseInterface; | ||
use Psr\Http\Message\ServerRequestInterface; | ||
use TYPO3\CMS\Core\Http\JsonResponse; | ||
use WEBFONTS\Webfonts\Google\GoogleFont; | ||
use WEBFONTS\Webfonts\Google\GoogleFontInstallationManager; | ||
use WEBFONTS\Webfonts\Google\GoogleWebfontHelperClient; | ||
|
||
class GoogleWebfontAjaxController extends AjaxJsonController | ||
{ | ||
|
||
/** | ||
* Provides the HTML template for the modal and settings for the requested font | ||
* | ||
* @param ServerRequestInterface $request | ||
* @return ResponseInterface | ||
*/ | ||
public function listAction(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface | ||
{ | ||
$fontsArr = GoogleWebfontHelperClient::jsonFontList(); | ||
|
||
$list = []; | ||
foreach ($fontsArr as $font) { | ||
$list[] = new GoogleFont($font); | ||
} | ||
|
||
return $this->jsonResponse( | ||
[ | ||
'fonts' => $list, | ||
'state' => 0, | ||
] | ||
); | ||
} | ||
|
||
/** | ||
* Install and uninstall fonts | ||
* Providing an empty list as body, will result in font uninstallation | ||
* | ||
* @param ServerRequestInterface $request | ||
* @return ResponseInterface | ||
*/ | ||
public function installAction(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface | ||
{ | ||
if (!isset($request->getQueryParams()['id'])) { | ||
return $this->errorResponse(1586072448, 403, 'Font not provided'); | ||
} | ||
|
||
$id = $request->getQueryParams()['id']; | ||
$provider = $request->getQueryParams()['provider']; | ||
$body = $request->getParsedBody(); | ||
|
||
$variants = $body['variants']; | ||
$subsets = $body['charsets']; | ||
|
||
$installationHandler = GoogleFontInstallationManager::getInstance(); | ||
|
||
if ($subsets === null || $variants === null || count($variants) === 0 || count($subsets) === 0) { // uninstall | ||
$installationHandler->deleteFont($id, $provider); | ||
$state = 2; | ||
} else { | ||
$installationHandler->installFont($id, $provider, $variants, $subsets); | ||
$state = 1; | ||
} | ||
|
||
// send back the installed fonts | ||
$fontsArr = GoogleWebfontHelperClient::jsonFontList(); | ||
|
||
$list = []; | ||
foreach ($fontsArr as $font) { | ||
if ($font['id'] === $id) { | ||
$list[] = new GoogleFont($font); | ||
break; | ||
} | ||
} | ||
|
||
return $this->jsonResponse( | ||
[ | ||
'fonts' => $list, | ||
'state' => $state | ||
] | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace WEBFONTS\Webfonts\Controller; | ||
|
||
use TYPO3\CMS\Core\Page\PageRenderer; | ||
use TYPO3\CMS\Core\Utility\GeneralUtility; | ||
use TYPO3\CMS\Extbase\Mvc\View\ViewInterface; | ||
|
||
class WebfontsController extends \VUEJS\Vuejs\Controller\VueBackendController | ||
{ | ||
|
||
protected function initializeView(ViewInterface $view) | ||
{ | ||
parent::initializeView($view); | ||
|
||
// register view as requireJS module | ||
$pageRenderer = GeneralUtility::makeInstance(PageRenderer::class); | ||
|
||
$pageRenderer->addCssFile('EXT:webfonts/Resources/Public/Css/Contrib/Pretty-Checkbox/pretty-checkbox.min.css'); | ||
$pageRenderer->addCssFile('EXT:webfonts/Resources/Public/Css/pretty-checkbox.css'); | ||
$pageRenderer->addCssFile('EXT:webfonts/Resources/Public/Css/modal.css'); | ||
$pageRenderer->addCssFile('EXT:webfonts/Resources/Public/Css/styles.css'); | ||
|
||
$this->view->getModuleTemplate()->getDocHeaderComponent()->disable(); | ||
|
||
} | ||
|
||
|
||
public function mainAction() | ||
{ | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace WEBFONTS\Webfonts\Exception; | ||
|
||
class WebfontsException extends \TYPO3\CMS\Extbase\Exception | ||
{ | ||
|
||
} |
Oops, something went wrong.