@@ -58,10 +58,12 @@ discard block |
||
58 | 58 | // https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img#attributes |
59 | 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']])) { |
|
62 | + // check usage |
|
62 | 63 | { |
63 | 64 | return $matches[0]; |
64 | 65 | } |
66 | + } |
|
65 | 67 | |
66 | 68 | $attr = preg_replace('/\s(?:alt|ismap|loading|title|sizes|srcset|usemap)="[^"]*"/','',$matches['pre'].$matches['post']);// cleanup |
67 | 69 | |
@@ -71,10 +73,12 @@ discard block |
||
71 | 73 | // https://developer.mozilla.org/en-US/docs/Web/HTML/Element/object#attributes |
72 | 74 | $html['body'] = preg_replace_callback('/<object(?<pre>[^>]*)data="(?<data>\/[^"]+\.svg)"(?<post>[^>]*?)[\s\/]*>(?:<\/object>)/s',function(array $matches): string// ^[/] |
73 | 75 | { |
74 | - if(!isset($this->svgFileArr[$matches['data']]))// check usage |
|
76 | + if(!isset($this->svgFileArr[$matches['data']])) { |
|
77 | + // check usage |
|
75 | 78 | { |
76 | 79 | return $matches[0]; |
77 | 80 | } |
81 | + } |
|
78 | 82 | |
79 | 83 | $attr = preg_replace('/\s(?:form|name|type|usemap)="[^"]*"/','',$matches['pre'].$matches['post']);// cleanup |
80 | 84 | |
@@ -90,15 +94,19 @@ discard block |
||
90 | 94 | } |
91 | 95 | private function addFileToSpriteArr(string $hash, string $path): ?array |
92 | 96 | { |
93 | - if(1 === preg_match('/;base64/',$svg = file_get_contents($this->sitePath.$path)))// noop! |
|
97 | + if(1 === preg_match('/;base64/',$svg = file_get_contents($this->sitePath.$path))) { |
|
98 | + // noop! |
|
94 | 99 | { |
95 | 100 | return null; |
96 | 101 | } |
102 | + } |
|
97 | 103 | |
98 | - if(1 === preg_match('/<(?:style|defs|url\()/',$svg))# check links @ __construct |
|
104 | + if(1 === preg_match('/<(?:style|defs|url\()/',$svg)) { |
|
105 | + # check links @ __construct |
|
99 | 106 | { |
100 | 107 | return null; |
101 | 108 | } |
109 | + } |
|
102 | 110 | |
103 | 111 | $svg = preg_replace('/<\/svg>.*|xlink:|\s(?:(?:width|height|version|xmlns)|(?:[a-z\-]+\:[a-z\-]+))="[^"]*"/s','',$svg);// clean !?: \s+(?<atr>[\w\-]+)=["\'](?<val>[^"\']+)["\'] |
104 | 112 | |
@@ -131,10 +139,12 @@ discard block |
||
131 | 139 | $this->svgFileArr = []; |
132 | 140 | foreach($svgFileArr as $index => $row) |
133 | 141 | { |
134 | - if(!$this->svgFileArr[($row['path'] = '/'.$storageArr[$row['storage']].$row['identifier'])] = $this->addFileToSpriteArr($row['sha1'], $row['path']))// ^[/] |
|
142 | + if(!$this->svgFileArr[($row['path'] = '/'.$storageArr[$row['storage']].$row['identifier'])] = $this->addFileToSpriteArr($row['sha1'], $row['path'])) { |
|
143 | + // ^[/] |
|
135 | 144 | { |
136 | 145 | unset($this->svgFileArr[$row['path']]); |
137 | 146 | } |
147 | + } |
|
138 | 148 | } |
139 | 149 | |
140 | 150 |