Skip to content

Commit

Permalink
[TASK] Make ready for 8
Browse files Browse the repository at this point in the history
  • Loading branch information
georgringer committed Oct 1, 2016
1 parent ad362af commit df548ee
Show file tree
Hide file tree
Showing 21 changed files with 1,525 additions and 1,307 deletions.
80 changes: 80 additions & 0 deletions Build/.php_cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/

/**
* This file represents the configuration for Code Sniffing PSR-2-related
* automatic checks of coding guidelines
* Install @fabpot's great php-cs-fixer tool via
*
* $ composer global require friendsofphp/php-cs-fixer
*
* And then simply run
*
* $ php-cs-fixer fix --config-file Build/.php_cs
*
* inside the TYPO3 directory. Warning: This may take up to 10 minutes.
*
* For more information read:
* http://www.php-fig.org/psr/psr-2/
* http://cs.sensiolabs.org
*/

if (PHP_SAPI !== 'cli') {
die('This script supports command line usage only. Please check your command.');
}
// Define in which folders to search and which folders to exclude
// Exclude some directories that are excluded by Git anyways to speed up the sniffing
$finder = Symfony\CS\Finder\DefaultFinder::create()
->in(__DIR__ . '/../');

// Return a Code Sniffing configuration using
// all sniffers needed for PSR-2
// and additionally:
// - Remove leading slashes in use clauses.
// - PHP single-line arrays should not have trailing comma.
// - Single-line whitespace before closing semicolon are prohibited.
// - Remove unused use statements in the PHP source code
// - Ensure Concatenation to have at least one whitespace around
// - Remove trailing whitespace at the end of blank lines.
return Symfony\CS\Config\Config::create()
->level(Symfony\CS\FixerInterface::PSR2_LEVEL)
->fixers([
// If changes to the fixers are done, please sync them with typo3/sysext/core/Build/Scripts/cglFixMyCommit.sh
'remove_leading_slash_use',
'single_array_no_trailing_comma',
'spaces_before_semicolon',
'unused_use',
'concat_with_spaces',
'whitespacy_lines',
'ordered_use',
'single_quote',
'duplicate_semicolon',
'extra_empty_lines',
'phpdoc_no_package',
'phpdoc_scalar',
'no_empty_lines_after_phpdocs',
'short_array_syntax',
'array_element_white_space_after_comma',
'function_typehint_space',
'hash_to_slash_comment',
'join_function',
'lowercase_cast',
'namespace_no_leading_whitespace',
'native_function_casing',
'no_empty_statement',
'self_accessor',
'short_bool_cast',
'unneeded_control_parentheses'
])
->finder($finder);
300 changes: 151 additions & 149 deletions Classes/Controller/ModFuncController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,154 +21,156 @@
use TYPO3\CMS\Backend\Module\AbstractFunctionModule;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
use TYPO3\CMS\Fluid\View\StandaloneView;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Fluid\View\StandaloneView;

class ModFuncController extends AbstractFunctionModule {

/** @var StandaloneView */
protected $view;

/** @var string */
protected $templatePath = 'EXT:page_speed/Resources/Private/Templates/';

/** @var UrlService */
protected $urlService;

/** @var PageSpeedRepository */
protected $pageSpeedRepository;

/** @var Configuration */
protected $configuration;

/** @var int */
protected $pageId = 0;

public function __construct() {
$this->view = GeneralUtility::makeInstance(StandaloneView::class);
$this->view->getRequest()->setControllerExtensionName('lowlevel');
$this->pageId = (int)GeneralUtility::_GET('id');
$this->urlService = new UrlService();
$this->pageSpeedRepository = new PageSpeedRepository();
$this->configuration = new Configuration();

$this->addScripts();
}

/**
* Function menu initialization
*
* @return array Menu array
*/
public function modMenu() {
$languages = array();
$languageRecords = $this->getDatabaseConnection()->exec_SELECTgetRows('uid,title', 'sys_language', 'hidden=0', '', 'title');
if (is_array($languageRecords) && !empty($languageRecords)) {
$languages[] = 'Default';
foreach ($languageRecords as $language) {
$languages[$language['uid']] = $language['title'];
}
}

$modMenuAdd = array(
'language' => $languages
);
return $modMenuAdd;
}


public function main() {
$result = $error = $url = NULL;

$this->view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName($this->templatePath . 'Main.html'));


if ($this->configuration->isValid()) {
try {
$this->checkPageId();
$url = $this->urlService->getFullUrl($this->pageId, $this->pObj->MOD_SETTINGS);

if (GeneralUtility::_GET('clear')) {
$this->pageSpeedRepository->clearByIdentifier($url);
$this->view->assign('cacheCleared', TRUE);
}

$result = $this->pageSpeedRepository->findByIdentifier($url);

} catch (\HTTP_Request2_ConnectionException $e) {
$error = 'error.http_request.connection';
// todo add log
} catch (\RuntimeException $e) {
$error = $e->getMessage();
}

} else {
$error = 'error.invalid.key';
}

$this->view->assignMultiple(array(
'lll' => 'LLL:EXT:page_speed/Resources/Private/Language/locallang.xlf:',
'menu' => $this->modifyFuncMenu(BackendUtility::getFuncMenu(
$this->pObj->id,
'SET[language]',
$this->pObj->MOD_SETTINGS['language'],
$this->pObj->MOD_MENU['language']
), 'language'),
'configuration' => $this->configuration,
'result' => $result,
'url' => $url,
'error' => $error,
'pageId' => $this->pageId
));

return $this->view->render();
}

/**
* Check if the page id is valid
*
* @return void
*/
protected function checkPageId() {
if ($this->pageId === 0) {
throw new \UnexpectedValueException('error.page.idIsZero');
}
$row = $this->getDatabaseConnection()->exec_SELECTgetSingleRow('*', 'pages', 'uid=' . $this->pageId);

if (!GeneralUtility::inList($GLOBALS['TYPO3_CONF_VARS']['FE']['content_doktypes'], $row['doktype'])) {
throw new \UnexpectedValueException('error.page.doktype');
}
if ($row['hidden'] == 1 || $row['deleted'] == 1) {
throw new \UnexpectedValueException('error.page.hidden');
}
if (!empty($row['fe_group'])) {
throw new \UnexpectedValueException('error.page.restricted');
}
}

/**
* Hack some bootstrap logic into the core
*
* @param string $code
* @param string $id
* @return string
*/
protected function modifyFuncMenu($code, $id) {
return str_replace('<select', '<select class="form-control" id="' . htmlspecialchars($id) . '"', $code);
}

/**
* Add JS and CSS files
*
* @return void
*/
protected function addScripts() {
$path = ExtensionManagementUtility::extRelPath('page_speed') . 'Resources/Public/';
$this->getDocumentTemplate()->addStyleSheet('page_speed', $path . 'Styles/speed.css');
$jsFiles = array('js/main.js', 'Contrib/amcharts/amcharts.js', 'Contrib/amcharts/gauge.js', 'Contrib/amcharts/serial.js', 'Contrib/amcharts/themes/dark.js');
foreach ($jsFiles as $file) {
$this->getDocumentTemplate()->loadJavascriptLib($path . $file);
}
}

}
class ModFuncController extends AbstractFunctionModule
{

/** @var StandaloneView */
protected $view;

/** @var string */
protected $templatePath = 'EXT:page_speed/Resources/Private/Templates/';

/** @var UrlService */
protected $urlService;

/** @var PageSpeedRepository */
protected $pageSpeedRepository;

/** @var Configuration */
protected $configuration;

/** @var int */
protected $pageId = 0;

public function __construct()
{
$this->view = GeneralUtility::makeInstance(StandaloneView::class);
$this->view->getRequest()->setControllerExtensionName('lowlevel');
$this->pageId = (int)GeneralUtility::_GET('id');
$this->urlService = new UrlService();
$this->pageSpeedRepository = new PageSpeedRepository();
$this->configuration = new Configuration();

$this->addScripts();
}

/**
* Function menu initialization
*
* @return array Menu array
*/
public function modMenu()
{
$languages = [];
$languageRecords = $this->getDatabaseConnection()->exec_SELECTgetRows('uid,title', 'sys_language', 'hidden=0', '', 'title');
if (is_array($languageRecords) && !empty($languageRecords)) {
$languages[] = 'Default';
foreach ($languageRecords as $language) {
$languages[$language['uid']] = $language['title'];
}
}

$modMenuAdd = [
'language' => $languages
];
return $modMenuAdd;
}

public function main()
{
$result = $error = $url = null;

$this->view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName($this->templatePath . 'Main.html'));

if ($this->configuration->isValid()) {
try {
$this->checkPageId();
$url = $this->urlService->getFullUrl($this->pageId, $this->pObj->MOD_SETTINGS);

if (GeneralUtility::_GET('clear')) {
$this->pageSpeedRepository->clearByIdentifier($url);
$this->view->assign('cacheCleared', true);
}

$result = $this->pageSpeedRepository->findByIdentifier($url);
} catch (\HTTP_Request2_ConnectionException $e) {
$error = 'error.http_request.connection';
// todo add log
} catch (\RuntimeException $e) {
$error = $e->getMessage();
}
} else {
$error = 'error.invalid.key';
}

$this->view->assignMultiple([
'lll' => 'LLL:EXT:page_speed/Resources/Private/Language/locallang.xlf:',
'menu' => $this->modifyFuncMenu(BackendUtility::getFuncMenu(
$this->pObj->id,
'SET[language]',
$this->pObj->MOD_SETTINGS['language'],
$this->pObj->MOD_MENU['language']
), 'language'),
'configuration' => $this->configuration,
'result' => $result,
'url' => $url,
'error' => $error,
'pageId' => $this->pageId
]);

return $this->view->render();
}

/**
* Check if the page id is valid
*
* @return void
*/
protected function checkPageId()
{
if ($this->pageId === 0) {
throw new \UnexpectedValueException('error.page.idIsZero');
}
$row = $this->getDatabaseConnection()->exec_SELECTgetSingleRow('*', 'pages', 'uid=' . $this->pageId);

if (!GeneralUtility::inList($GLOBALS['TYPO3_CONF_VARS']['FE']['content_doktypes'], $row['doktype'])) {
throw new \UnexpectedValueException('error.page.doktype');
}
if ($row['hidden'] == 1 || $row['deleted'] == 1) {
throw new \UnexpectedValueException('error.page.hidden');
}
if (!empty($row['fe_group'])) {
throw new \UnexpectedValueException('error.page.restricted');
}
}

/**
* Hack some bootstrap logic into the core
*
* @param string $code
* @param string $id
* @return string
*/
protected function modifyFuncMenu($code, $id)
{
return str_replace('<select', '<select class="form-control" id="' . htmlspecialchars($id) . '"', $code);
}

/**
* Add JS and CSS files
*
* @return void
*/
protected function addScripts()
{
$path = ExtensionManagementUtility::extRelPath('page_speed') . 'Resources/Public/';
$this->getDocumentTemplate()->addStyleSheet('page_speed', $path . 'Styles/speed.css');
$jsFiles = ['js/main.js', 'Contrib/amcharts/amcharts.js', 'Contrib/amcharts/gauge.js', 'Contrib/amcharts/serial.js', 'Contrib/amcharts/themes/dark.js'];
foreach ($jsFiles as $file) {
$this->getDocumentTemplate()->loadJavascriptLib($path . $file);
}
}
}
Loading

0 comments on commit df548ee

Please sign in to comment.