@@ -22,6 +22,6 @@ |
||
| 22 | 22 | public function manipulate($html, array $configuration = []) |
| 23 | 23 | { |
| 24 | 24 | $regex = '<meta name=["\']?generator["\']? [^>]+>'; |
| 25 | - return preg_replace('/' . $regex . '/is', '', $html); |
|
| 25 | + return preg_replace('/'.$regex.'/is', '', $html); |
|
| 26 | 26 | } |
| 27 | 27 | } |
@@ -38,11 +38,11 @@ |
||
| 38 | 38 | { |
| 39 | 39 | $response = $handler->handle($request); |
| 40 | 40 | |
| 41 | - if(!($response instanceof NullResponse) |
|
| 41 | + if (!($response instanceof NullResponse) |
|
| 42 | 42 | && $GLOBALS['TSFE'] instanceof TypoScriptFrontendController |
| 43 | 43 | && $GLOBALS['TSFE']->isOutputting() |
| 44 | 44 | && false !== (bool) $GLOBALS['TSFE']->config['config']['sourceopt.']['enabled'] |
| 45 | - ){ |
|
| 45 | + ) { |
|
| 46 | 46 | $processedHtml = $this->cleanHtmlService->clean( |
| 47 | 47 | $response->getBody()->__toString(), |
| 48 | 48 | $GLOBALS['TSFE']->config['config']['sourceopt.'] |
@@ -27,11 +27,11 @@ |
||
| 27 | 27 | { |
| 28 | 28 | $response = $handler->handle($request); |
| 29 | 29 | |
| 30 | - if(!($response instanceof NullResponse) |
|
| 30 | + if (!($response instanceof NullResponse) |
|
| 31 | 31 | && $GLOBALS['TSFE'] instanceof TypoScriptFrontendController |
| 32 | 32 | && $GLOBALS['TSFE']->isOutputting() |
| 33 | 33 | && false !== (bool) $GLOBALS['TSFE']->config['config']['svgstore.']['enabled'] |
| 34 | - ){ |
|
| 34 | + ) { |
|
| 35 | 35 | $processedHtml = GeneralUtility::makeInstance(\HTML\Sourceopt\Service\SvgStoreService::class) |
| 36 | 36 | ->process($response->getBody()->__toString()); |
| 37 | 37 | |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | { |
| 69 | 69 | if (!empty($config)) { |
| 70 | 70 | if ($config['formatHtml'] && is_numeric($config['formatHtml'])) { |
| 71 | - $this->formatType = (int)$config['formatHtml']; |
|
| 71 | + $this->formatType = (int) $config['formatHtml']; |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | if ($config['formatHtml.']['tabSize'] && is_numeric($config['formatHtml.']['tabSize'])) { |
@@ -76,14 +76,14 @@ discard block |
||
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | if (isset($config['formatHtml.']['debugComment'])) { |
| 79 | - $this->debugComment = (bool)$config['formatHtml.']['debugComment']; |
|
| 79 | + $this->debugComment = (bool) $config['formatHtml.']['debugComment']; |
|
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | if (isset($config['headerComment'])) { |
| 83 | 83 | $this->headerComment = $config['headerComment']; |
| 84 | 84 | } |
| 85 | 85 | |
| 86 | - if (isset($config['dropEmptySpaceChar']) && (bool)$config['dropEmptySpaceChar']) { |
|
| 86 | + if (isset($config['dropEmptySpaceChar']) && (bool) $config['dropEmptySpaceChar']) { |
|
| 87 | 87 | $this->emptySpaceChar = ''; |
| 88 | 88 | } |
| 89 | 89 | } |
@@ -107,11 +107,11 @@ discard block |
||
| 107 | 107 | |
| 108 | 108 | $manipulations = []; |
| 109 | 109 | |
| 110 | - if (isset($config['removeGenerator']) && (bool)$config['removeGenerator']) { |
|
| 110 | + if (isset($config['removeGenerator']) && (bool) $config['removeGenerator']) { |
|
| 111 | 111 | $manipulations['removeGenerator'] = GeneralUtility::makeInstance(RemoveGenerator::class); |
| 112 | 112 | } |
| 113 | 113 | |
| 114 | - if (isset($config['removeComments']) && (bool)$config['removeComments']) { |
|
| 114 | + if (isset($config['removeComments']) && (bool) $config['removeComments']) { |
|
| 115 | 115 | $manipulations['removeComments'] = GeneralUtility::makeInstance(RemoveComments::class); |
| 116 | 116 | } |
| 117 | 117 | |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | |
| 122 | 122 | foreach ($manipulations as $key => $manipulation) { |
| 123 | 123 | /** @var ManipulationInterface $manipulation */ |
| 124 | - $configuration = isset($config[$key . '.']) && is_array($config[$key . '.']) ? $config[$key . '.'] : []; |
|
| 124 | + $configuration = isset($config[$key.'.']) && is_array($config[$key.'.']) ? $config[$key.'.'] : []; |
|
| 125 | 125 | $html = $manipulation->manipulate($html, $configuration); |
| 126 | 126 | } |
| 127 | 127 | |
@@ -184,7 +184,7 @@ discard block |
||
| 184 | 184 | $functionalBoxElements = 'dd|dt|frameset|li|tbody|td|tfoot|th|thead|tr|colgroup'; |
| 185 | 185 | $usableBoxElements = 'applet|button|del|iframe|ins|map|object|script'; |
| 186 | 186 | $imagineBoxElements = 'html|body|head|meta|title|link|script|base|!--'; |
| 187 | - $allBoxLikeElements = '(?>' . $trueBoxElements . '|' . $functionalBoxElements . '|' . $usableBoxElements . '|' . $imagineBoxElements . ')'; |
|
| 187 | + $allBoxLikeElements = '(?>'.$trueBoxElements.'|'.$functionalBoxElements.'|'.$usableBoxElements.'|'.$imagineBoxElements.')'; |
|
| 188 | 188 | $esteticBoxLikeElements = '(?>html|head|body|meta name|title|div|table|h1|h2|h3|h4|h5|h6|p|form|pre|center|!--)'; |
| 189 | 189 | $structureBoxLikeElements = '(?>html|head|body|div|!--)'; |
| 190 | 190 | |
@@ -193,7 +193,7 @@ discard block |
||
| 193 | 193 | '/(<(?:[^<>]+(?:"[^"]*"|\'[^\']*\')?)+>)/', |
| 194 | 194 | $html, |
| 195 | 195 | -1, |
| 196 | - PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY |
|
| 196 | + PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY |
|
| 197 | 197 | ); |
| 198 | 198 | |
| 199 | 199 | if ($htmlArrayTemp === false) { |
@@ -223,52 +223,52 @@ discard block |
||
| 223 | 223 | } elseif ($this->formatType == 2 && ( // minimalistic line break |
| 224 | 224 | # this element has a line break before itself |
| 225 | 225 | preg_match( |
| 226 | - '/<' . $structureBoxLikeElements . '(.*)>/Usi', |
|
| 226 | + '/<'.$structureBoxLikeElements.'(.*)>/Usi', |
|
| 227 | 227 | $htmlArray[$x] |
| 228 | 228 | ) || preg_match( |
| 229 | - '/<' . $structureBoxLikeElements . '(.*) \/>/Usi', |
|
| 229 | + '/<'.$structureBoxLikeElements.'(.*) \/>/Usi', |
|
| 230 | 230 | $htmlArray[$x] |
| 231 | 231 | ) || # one element before is a element that has a line break after |
| 232 | 232 | preg_match( |
| 233 | - '/<\/' . $structureBoxLikeElements . '(.*)>/Usi', |
|
| 233 | + '/<\/'.$structureBoxLikeElements.'(.*)>/Usi', |
|
| 234 | 234 | $htmlArray[$x - 1] |
| 235 | 235 | ) || substr( |
| 236 | 236 | $htmlArray[$x - 1], |
| 237 | 237 | 0, |
| 238 | 238 | 4 |
| 239 | - ) == '<!--' || preg_match('/<' . $structureBoxLikeElements . '(.*) \/>/Usi', $htmlArray[$x - 1])) |
|
| 239 | + ) == '<!--' || preg_match('/<'.$structureBoxLikeElements.'(.*) \/>/Usi', $htmlArray[$x - 1])) |
|
| 240 | 240 | ) { |
| 241 | 241 | $newline = true; |
| 242 | 242 | } elseif ($this->formatType == 3 && ( // aestetic line break |
| 243 | 243 | # this element has a line break before itself |
| 244 | 244 | preg_match( |
| 245 | - '/<' . $esteticBoxLikeElements . '(.*)>/Usi', |
|
| 245 | + '/<'.$esteticBoxLikeElements.'(.*)>/Usi', |
|
| 246 | 246 | $htmlArray[$x] |
| 247 | 247 | ) || preg_match( |
| 248 | - '/<' . $esteticBoxLikeElements . '(.*) \/>/Usi', |
|
| 248 | + '/<'.$esteticBoxLikeElements.'(.*) \/>/Usi', |
|
| 249 | 249 | $htmlArray[$x] |
| 250 | 250 | ) || # one element before is a element that has a line break after |
| 251 | - preg_match('/<\/' . $esteticBoxLikeElements . '(.*)>/Usi', $htmlArray[$x - 1]) || substr( |
|
| 251 | + preg_match('/<\/'.$esteticBoxLikeElements.'(.*)>/Usi', $htmlArray[$x - 1]) || substr( |
|
| 252 | 252 | $htmlArray[$x - 1], |
| 253 | 253 | 0, |
| 254 | 254 | 4 |
| 255 | - ) == '<!--' || preg_match('/<' . $esteticBoxLikeElements . '(.*) \/>/Usi', $htmlArray[$x - 1])) |
|
| 255 | + ) == '<!--' || preg_match('/<'.$esteticBoxLikeElements.'(.*) \/>/Usi', $htmlArray[$x - 1])) |
|
| 256 | 256 | ) { |
| 257 | 257 | $newline = true; |
| 258 | 258 | } elseif ($this->formatType >= 4 && ( // logical line break |
| 259 | 259 | # this element has a line break before itself |
| 260 | 260 | preg_match( |
| 261 | - '/<' . $allBoxLikeElements . '(.*)>/Usi', |
|
| 261 | + '/<'.$allBoxLikeElements.'(.*)>/Usi', |
|
| 262 | 262 | $htmlArray[$x] |
| 263 | 263 | ) || preg_match( |
| 264 | - '/<' . $allBoxLikeElements . '(.*) \/>/Usi', |
|
| 264 | + '/<'.$allBoxLikeElements.'(.*) \/>/Usi', |
|
| 265 | 265 | $htmlArray[$x] |
| 266 | 266 | ) || # one element before is a element that has a line break after |
| 267 | - preg_match('/<\/' . $allBoxLikeElements . '(.*)>/Usi', $htmlArray[$x - 1]) || substr( |
|
| 267 | + preg_match('/<\/'.$allBoxLikeElements.'(.*)>/Usi', $htmlArray[$x - 1]) || substr( |
|
| 268 | 268 | $htmlArray[$x - 1], |
| 269 | 269 | 0, |
| 270 | 270 | 4 |
| 271 | - ) == '<!--' || preg_match('/<' . $allBoxLikeElements . '(.*) \/>/Usi', $htmlArray[$x - 1])) |
|
| 271 | + ) == '<!--' || preg_match('/<'.$allBoxLikeElements.'(.*) \/>/Usi', $htmlArray[$x - 1])) |
|
| 272 | 272 | ) { |
| 273 | 273 | $newline = true; |
| 274 | 274 | } |
@@ -426,6 +426,6 @@ discard block |
||
| 426 | 426 | */ |
| 427 | 427 | public function includeHeaderComment(&$html) |
| 428 | 428 | { |
| 429 | - $html = preg_replace('/^(-->)$/m', "\n\t" . $this->headerComment . "\n$1", $html); |
|
| 429 | + $html = preg_replace('/^(-->)$/m', "\n\t".$this->headerComment."\n$1", $html); |
|
| 430 | 430 | } |
| 431 | 431 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | * |
| 18 | 18 | * @var string |
| 19 | 19 | */ |
| 20 | - protected $outputDir = '/typo3temp/assets/svg/';// fallback |
|
| 20 | + protected $outputDir = '/typo3temp/assets/svg/'; // fallback |
|
| 21 | 21 | |
| 22 | 22 | public function __construct() |
| 23 | 23 | { |
@@ -25,11 +25,11 @@ discard block |
||
| 25 | 25 | #$this->defs = []; # https://bugs.chromium.org/p/chromium/issues/detail?id=751733#c14 |
| 26 | 26 | $this->svgs = []; |
| 27 | 27 | |
| 28 | - $this->sitePath = \TYPO3\CMS\Core\Core\Environment::getPublicPath();// [^/]$ |
|
| 28 | + $this->sitePath = \TYPO3\CMS\Core\Core\Environment::getPublicPath(); // [^/]$ |
|
| 29 | 29 | |
| 30 | - if(isset($GLOBALS['TSFE']->config['config']['svgstore.']['outputDir']) && !empty($GLOBALS['TSFE']->config['config']['svgstore.']['outputDir'])) |
|
| 30 | + if (isset($GLOBALS['TSFE']->config['config']['svgstore.']['outputDir']) && !empty($GLOBALS['TSFE']->config['config']['svgstore.']['outputDir'])) |
|
| 31 | 31 | { |
| 32 | - $this->outputDir = '/typo3temp/'.$GLOBALS['TSFE']->config['config']['svgstore.']['outputDir']; |
|
| 32 | + $this->outputDir = '/typo3temp/'.$GLOBALS['TSFE']->config['config']['svgstore.']['outputDir']; |
|
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | $this->connPool = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\ConnectionPool::class); |
@@ -40,43 +40,43 @@ discard block |
||
| 40 | 40 | $this->spritePath = $this->svgCache->get('spritePath'); |
| 41 | 41 | $this->svgFileArr = $this->svgCache->get('svgFileArr'); |
| 42 | 42 | |
| 43 | - if(empty($this->spritePath) && !$this->populateCache()) |
|
| 43 | + if (empty($this->spritePath) && !$this->populateCache()) |
|
| 44 | 44 | { |
| 45 | 45 | throw new \Exception('could not write file: '.$this->sitePath.$this->spritePath); |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | - if(!file_exists($this->sitePath.$this->spritePath)) |
|
| 48 | + if (!file_exists($this->sitePath.$this->spritePath)) |
|
| 49 | 49 | { |
| 50 | 50 | throw new \Exception('file does not exists: '.$this->sitePath.$this->spritePath); |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | - if(!preg_match('/(?<head>.+?<\/head>)(?<body>.+)/s',$html,$html) && count($html) == 5) |
|
| 53 | + if (!preg_match('/(?<head>.+?<\/head>)(?<body>.+)/s', $html, $html) && count($html) == 5) |
|
| 54 | 54 | { |
| 55 | 55 | throw new \Exception('fix HTML!'); |
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | // https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img#attributes |
| 59 | - $html['body'] = preg_replace_callback('/<img(?<pre>[^>]*)src="(?<src>\/[^"]+\.svg)"(?<post>[^>]*?)[\s\/]*>/s',function(array $matches): string// ^[/] |
|
| 59 | + $html['body'] = preg_replace_callback('/<img(?<pre>[^>]*)src="(?<src>\/[^"]+\.svg)"(?<post>[^>]*?)[\s\/]*>/s', function(array $matches): string// ^[/] |
|
| 60 | 60 | { |
| 61 | - if(!isset($this->svgFileArr[$matches['src']]))// check usage |
|
| 61 | + if (!isset($this->svgFileArr[$matches['src']]))// check usage |
|
| 62 | 62 | { |
| 63 | 63 | return $matches[0]; |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | - $attr = preg_replace('/\s(?:alt|ismap|loading|title|sizes|srcset|usemap)="[^"]*"/','',$matches['pre'].$matches['post']);// cleanup |
|
| 66 | + $attr = preg_replace('/\s(?:alt|ismap|loading|title|sizes|srcset|usemap)="[^"]*"/', '', $matches['pre'].$matches['post']); // cleanup |
|
| 67 | 67 | |
| 68 | 68 | return sprintf('<svg%s %s><use href="%s#%s"/></svg>', $this->svgFileArr[$matches['src']]['attr'], $attr, $this->spritePath, $this->convertFilePath($matches['src'])); |
| 69 | 69 | },$html['body']); |
| 70 | 70 | |
| 71 | 71 | // https://developer.mozilla.org/en-US/docs/Web/HTML/Element/object#attributes |
| 72 | - $html['body'] = preg_replace_callback('/<object(?<pre>[^>]*)data="(?<data>\/[^"]+\.svg)"(?<post>[^>]*?)[\s\/]*>(?:<\/object>)/s',function(array $matches): string// ^[/] |
|
| 72 | + $html['body'] = preg_replace_callback('/<object(?<pre>[^>]*)data="(?<data>\/[^"]+\.svg)"(?<post>[^>]*?)[\s\/]*>(?:<\/object>)/s', function(array $matches): string// ^[/] |
|
| 73 | 73 | { |
| 74 | - if(!isset($this->svgFileArr[$matches['data']]))// check usage |
|
| 74 | + if (!isset($this->svgFileArr[$matches['data']]))// check usage |
|
| 75 | 75 | { |
| 76 | 76 | return $matches[0]; |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | - $attr = preg_replace('/\s(?:form|name|type|usemap)="[^"]*"/','',$matches['pre'].$matches['post']);// cleanup |
|
| 79 | + $attr = preg_replace('/\s(?:form|name|type|usemap)="[^"]*"/', '', $matches['pre'].$matches['post']); // cleanup |
|
| 80 | 80 | |
| 81 | 81 | return sprintf('<svg%s %s><use href="%s#%s"/></svg>', $this->svgFileArr[$matches['src']]['attr'], $attr, $this->spritePath, $this->convertFilePath($matches['data'])); |
| 82 | 82 | },$html['body']); |
@@ -86,21 +86,21 @@ discard block |
||
| 86 | 86 | |
| 87 | 87 | private function convertFilePath(string $path): string |
| 88 | 88 | { |
| 89 | - return preg_replace('/.svg$|[^\w\-]/','',str_replace('/','-',ltrim($path,'/')));// ^[^/] |
|
| 89 | + return preg_replace('/.svg$|[^\w\-]/', '', str_replace('/', '-', ltrim($path, '/'))); // ^[^/] |
|
| 90 | 90 | } |
| 91 | 91 | private function addFileToSpriteArr(string $hash, string $path): ?array |
| 92 | 92 | { |
| 93 | - if(1 === preg_match('/;base64/',$svg = file_get_contents($this->sitePath.$path)))// noop! |
|
| 93 | + if (1 === preg_match('/;base64/', $svg = file_get_contents($this->sitePath.$path)))// noop! |
|
| 94 | 94 | { |
| 95 | 95 | return null; |
| 96 | 96 | } |
| 97 | 97 | |
| 98 | - if(1 === preg_match('/<(?:style|defs|url\()/',$svg))# check links @ __construct |
|
| 98 | + if (1 === preg_match('/<(?:style|defs|url\()/', $svg))# check links @ __construct |
|
| 99 | 99 | { |
| 100 | 100 | return null; |
| 101 | 101 | } |
| 102 | 102 | |
| 103 | - $svg = preg_replace('/<\/svg>.*|xlink:|\s(?:(?:width|height|version|xmlns)|(?:[a-z\-]+\:[a-z\-]+))="[^"]*"/s','',$svg);// clean !?: \s+(?<atr>[\w\-]+)=["\'](?<val>[^"\']+)["\'] |
|
| 103 | + $svg = preg_replace('/<\/svg>.*|xlink:|\s(?:(?:width|height|version|xmlns)|(?:[a-z\-]+\:[a-z\-]+))="[^"]*"/s', '', $svg); // clean !?: \s+(?<atr>[\w\-]+)=["\'](?<val>[^"\']+)["\'] |
|
| 104 | 104 | |
| 105 | 105 | #$svg = preg_replace('/((?:id|class)=")/','$1'.$hash.'__',$svg);// extend IDs |
| 106 | 106 | #$svg = preg_replace('/(href="|url\()#/','$1#'.$hash.'__',$svg);// recover IDs |
@@ -118,9 +118,9 @@ discard block |
||
| 118 | 118 | # return ''; |
| 119 | 119 | #},$svg); |
| 120 | 120 | |
| 121 | - $this->svgs[] = preg_replace('/.*<svg((?:(?!id=)[^>])+)(?:id="[^"]*")?([^>]*>)/s','id="'.$this->convertFilePath($path).'"$1$2',$svg, 1);// change ID; |
|
| 121 | + $this->svgs[] = preg_replace('/.*<svg((?:(?!id=)[^>])+)(?:id="[^"]*")?([^>]*>)/s', 'id="'.$this->convertFilePath($path).'"$1$2', $svg, 1); // change ID; |
|
| 122 | 122 | |
| 123 | - return preg_match('/\s+viewBox="\s*([+-]?[\d\.]+(?:\s+[+-]?[\d\.]+){3})\s*"/',$svg,$match) ? ['attr' => ' viewBox="'.preg_replace('/\s+/',' ',$match[1]).'"', 'hash' => $hash] : null; |
|
| 123 | + return preg_match('/\s+viewBox="\s*([+-]?[\d\.]+(?:\s+[+-]?[\d\.]+){3})\s*"/', $svg, $match) ? ['attr' => ' viewBox="'.preg_replace('/\s+/', ' ', $match[1]).'"', 'hash' => $hash] : null; |
|
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | private function populateCache(): bool |
@@ -129,55 +129,54 @@ discard block |
||
| 129 | 129 | $svgFileArr = $this->getSvgFilesArrayFromDB(array_keys($storageArr)); |
| 130 | 130 | |
| 131 | 131 | $this->svgFileArr = []; |
| 132 | - foreach($svgFileArr as $index => $row) |
|
| 132 | + foreach ($svgFileArr as $index => $row) |
|
| 133 | 133 | { |
| 134 | - if(!$this->svgFileArr[($row['path'] = '/'.$storageArr[$row['storage']].$row['identifier'])] = $this->addFileToSpriteArr($row['sha1'], $row['path']))// ^[/] |
|
| 134 | + if (!$this->svgFileArr[($row['path'] = '/'.$storageArr[$row['storage']].$row['identifier'])] = $this->addFileToSpriteArr($row['sha1'], $row['path']))// ^[/] |
|
| 135 | 135 | { |
| 136 | 136 | unset($this->svgFileArr[$row['path']]); |
| 137 | 137 | } |
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | |
| 141 | - $svg = preg_replace_callback |
|
| 142 | - ( |
|
| 143 | - '/<use(?<pre>.*?)(?:xlink:)?href="(?<href>\/.+?\.svg)#[^"]+"(?<post>.*?)[\s\/]*>(?:<\/use>)?/s',function(array $matches): string |
|
| 141 | + $svg = preg_replace_callback( |
|
| 142 | + '/<use(?<pre>.*?)(?:xlink:)?href="(?<href>\/.+?\.svg)#[^"]+"(?<post>.*?)[\s\/]*>(?:<\/use>)?/s', function(array $matches): string |
|
| 144 | 143 | { |
| 145 | 144 | return sprintf('<use%s href="#%s"/>', $matches['pre'].$matches['post'], $this->convertFilePath($matches['href'])); |
| 146 | 145 | } |
| 147 | 146 | ,'<svg xmlns="http://www.w3.org/2000/svg">' |
| 148 | 147 | #."\n<style>\n".implode("\n",$this->styl)."\n</style>" |
| 149 | 148 | #."\n<defs>\n".implode("\n",$this->defs)."\n</defs>" |
| 150 | - ."\n<symbol ".implode("</symbol>\n<symbol ",$this->svgs)."</symbol>\n" |
|
| 149 | + ."\n<symbol ".implode("</symbol>\n<symbol ", $this->svgs)."</symbol>\n" |
|
| 151 | 150 | .'</svg>' |
| 152 | 151 | ); |
| 153 | 152 | |
| 154 | 153 | #unset($this->styl);// save MEM |
| 155 | 154 | #unset($this->defs);// save MEM |
| 156 | - unset($this->svgs);// save MEM |
|
| 155 | + unset($this->svgs); // save MEM |
|
| 157 | 156 | |
| 158 | - if(is_int($var = $GLOBALS['TSFE']->config['config']['sourceopt.']['formatHtml']) && $var == 1) |
|
| 157 | + if (is_int($var = $GLOBALS['TSFE']->config['config']['sourceopt.']['formatHtml']) && $var == 1) |
|
| 159 | 158 | { |
| 160 | - $svg = preg_replace('/[\n\r\t\v\0]|\s{2,}/','',$svg); |
|
| 159 | + $svg = preg_replace('/[\n\r\t\v\0]|\s{2,}/', '', $svg); |
|
| 161 | 160 | } |
| 162 | 161 | |
| 163 | - $svg = preg_replace('/<([a-z]+)\s*(\/|>\s*<\/\1)>\s*/i','',$svg);// remove emtpy |
|
| 164 | - $svg = preg_replace('/<((circle|ellipse|line|path|polygon|polyline|rect|stop|use)\s[^>]+?)\s*>\s*<\/\2>/','<$1/>',$svg);// shorten/minify |
|
| 162 | + $svg = preg_replace('/<([a-z]+)\s*(\/|>\s*<\/\1)>\s*/i', '', $svg); // remove emtpy |
|
| 163 | + $svg = preg_replace('/<((circle|ellipse|line|path|polygon|polyline|rect|stop|use)\s[^>]+?)\s*>\s*<\/\2>/', '<$1/>', $svg); // shorten/minify |
|
| 165 | 164 | |
| 166 | 165 | |
| 167 | - if(!is_dir($this->sitePath.$this->outputDir)) |
|
| 166 | + if (!is_dir($this->sitePath.$this->outputDir)) |
|
| 168 | 167 | { |
| 169 | 168 | GeneralUtility::mkdir_deep($this->sitePath.$this->outputDir); |
| 170 | 169 | } |
| 171 | 170 | |
| 172 | - $this->spritePath = $this->outputDir.hash('sha1',serialize($this->svgFileArr)).'.svg'; |
|
| 173 | - if(false === file_put_contents($this->sitePath.$this->spritePath,$svg)) |
|
| 171 | + $this->spritePath = $this->outputDir.hash('sha1', serialize($this->svgFileArr)).'.svg'; |
|
| 172 | + if (false === file_put_contents($this->sitePath.$this->spritePath, $svg)) |
|
| 174 | 173 | { |
| 175 | 174 | return false; |
| 176 | 175 | } |
| 177 | - unset($svg);// save MEM |
|
| 176 | + unset($svg); // save MEM |
|
| 178 | 177 | |
| 179 | - $this->svgCache->set('svgFileArr',$this->svgFileArr); |
|
| 180 | - $this->svgCache->set('spritePath',$this->spritePath); |
|
| 178 | + $this->svgCache->set('svgFileArr', $this->svgFileArr); |
|
| 179 | + $this->svgCache->set('spritePath', $this->spritePath); |
|
| 181 | 180 | |
| 182 | 181 | return true; |
| 183 | 182 | } |
@@ -185,34 +184,34 @@ discard block |
||
| 185 | 184 | private function getStorageArrayFromDB(): array |
| 186 | 185 | { |
| 187 | 186 | $storageResources = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\StorageRepository::class)->findAll(); |
| 188 | - foreach($storageResources as $storage) |
|
| 187 | + foreach ($storageResources as $storage) |
|
| 189 | 188 | { |
| 190 | - if($storage->getConfiguration()['pathType'] == 'relative') |
|
| 189 | + if ($storage->getConfiguration()['pathType'] == 'relative') |
|
| 191 | 190 | { |
| 192 | - $storageResources[$storage->getUid()] = rtrim($storage->getConfiguration()['basePath'],'/');// [^/]$ |
|
| 191 | + $storageResources[$storage->getUid()] = rtrim($storage->getConfiguration()['basePath'], '/'); // [^/]$ |
|
| 193 | 192 | } |
| 194 | 193 | } |
| 195 | 194 | |
| 196 | - unset($storageResources[0]);// keep! |
|
| 195 | + unset($storageResources[0]); // keep! |
|
| 197 | 196 | return $storageResources; |
| 198 | 197 | } |
| 199 | 198 | private function getSvgFilesArrayFromDB(array $storageIds): array |
| 200 | 199 | { |
| 201 | 200 | return ($queryBuilder = $this->connPool->getQueryBuilderForTable('sys_file')) |
| 202 | - ->select('sys_file.storage','sys_file.identifier','sys_file.sha1') |
|
| 201 | + ->select('sys_file.storage', 'sys_file.identifier', 'sys_file.sha1') |
|
| 203 | 202 | ->from('sys_file') |
| 204 | - ->innerJoin('sys_file','sys_file_reference','sys_file_reference', |
|
| 203 | + ->innerJoin('sys_file', 'sys_file_reference', 'sys_file_reference', |
|
| 205 | 204 | $queryBuilder->expr()->eq('sys_file_reference.uid_local', |
| 206 | 205 | $queryBuilder->quoteIdentifier('sys_file.uid')) |
| 207 | 206 | ) |
| 208 | 207 | ->where( |
| 209 | - $queryBuilder->expr()->in('sys_file.storage', $queryBuilder->createNamedParameter($storageIds,\TYPO3\CMS\Core\Database\Connection::PARAM_INT_ARRAY)), |
|
| 208 | + $queryBuilder->expr()->in('sys_file.storage', $queryBuilder->createNamedParameter($storageIds, \TYPO3\CMS\Core\Database\Connection::PARAM_INT_ARRAY)), |
|
| 210 | 209 | $queryBuilder->expr()->eq('sys_file.mime_type', $queryBuilder->createNamedParameter('image/svg+xml')), |
| 211 | - $queryBuilder->expr()->lt('sys_file.size', $queryBuilder->createNamedParameter($GLOBALS['TSFE']->config['config']['svgstore.']['fileSize'])), |
|
| 210 | + $queryBuilder->expr()->lt('sys_file.size', $queryBuilder->createNamedParameter($GLOBALS['TSFE']->config['config']['svgstore.']['fileSize'])), |
|
| 212 | 211 | ) |
| 213 | 212 | ->groupBy('sys_file.uid') |
| 214 | 213 | ->orderBy('sys_file.uid') |
| 215 | 214 | ->execute() |
| 216 | - ->fetchAll();// TODO; use stdClass |
|
| 215 | + ->fetchAll(); // TODO; use stdClass |
|
| 217 | 216 | } |
| 218 | 217 | } |