├── .gitignore
├── .scrutinizer.yml
├── LICENSE
├── README.md
├── composer.json
├── composer.lock
├── phpunit.xml.dist
├── src
└── View.php
└── tests
├── bootstrap.php
├── files
├── line_comments.txt
└── no_line_comments.txt
└── unit
├── JsCommentRemovalTest.php
└── _bootstrap.php
/.gitignore:
--------------------------------------------------------------------------------
1 | # yii console command
2 | /yii
3 |
4 | # phpstorm project files
5 | .idea
6 |
7 | # netbeans project files
8 | nbproject
9 |
10 | # zend studio for eclipse project files
11 | .buildpath
12 | .project
13 | .settings
14 |
15 | # windows thumbnail cache
16 | Thumbs.db
17 |
18 | # composer vendor dir
19 | /vendor
20 |
21 | # composer itself is not needed
22 | composer.phar
23 |
24 | # Mac DS_Store Files
25 | .DS_Store
26 |
27 | # phpunit itself is not needed
28 | phpunit.phar
29 | # local phpunit config
30 | /phpunit.xml
31 |
--------------------------------------------------------------------------------
/.scrutinizer.yml:
--------------------------------------------------------------------------------
1 | filter:
2 | excluded_paths: [vendor/*]
3 | checks:
4 | php:
5 | code_rating: true
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2015 Oleg Gheorghita
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
23 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # yii2-htmlcompress [](LICENSE) [](https://scrutinizer-ci.com/g/ogheo/yii2-htmlcompress/)
2 |
3 | Compress HTML output into a single line
4 |
5 | ## Install
6 |
7 | The preferred way to install this extension is through [composer](http://getcomposer.org/download/).
8 |
9 | try
10 |
11 | ```
12 | composer require "ogheo/yii2-htmlcompress:*"
13 | ```
14 |
15 | or add
16 |
17 | ```
18 | "ogheo/yii2-htmlcompress": "*"
19 | ```
20 |
21 | to the require section of your `composer.json` file.
22 |
23 | ## Configure
24 |
25 | ```
26 | return [
27 | // ...
28 | 'components' => [
29 | // ...
30 | 'view' => [
31 | 'class' => '\ogheo\htmlcompress\View',
32 | 'compress' => YII_ENV_DEV ? false : true,
33 | // ...
34 | ]
35 | ]
36 | ];
37 | ```
38 |
39 | By default extension is disabled on DEV environment and enabled on PROD.
40 |
41 | Enjoy ;)
42 |
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "ogheo/yii2-htmlcompress",
3 | "description": "Compress HTML output into a single line",
4 | "keywords": ["yii2", "html", "compress", "minify", "minimize", "output", "view"],
5 | "type": "yii2-extension",
6 | "license": "MIT",
7 | "homepage": "https://github.com/ogheo/yii2-htmlcompress",
8 | "authors": [
9 | {
10 | "name": "Oleg Gheorghita",
11 | "email": "oleg.gheo@gmail.com"
12 | }
13 | ],
14 | "require": {
15 | "yiisoft/yii2": "*"
16 | },
17 | "autoload": {
18 | "psr-4": {
19 | "ogheo\\htmlcompress\\": "src"
20 | }
21 | }
22 | }
--------------------------------------------------------------------------------
/composer.lock:
--------------------------------------------------------------------------------
1 | {
2 | "_readme": [
3 | "This file locks the dependencies of your project to a known state",
4 | "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
5 | "This file is @generated automatically"
6 | ],
7 | "hash": "4f285a59bc0ab0e23bf5fa69b6340efe",
8 | "content-hash": "cf87c7f0a625f9b6e8970b7313821224",
9 | "packages": [
10 | {
11 | "name": "bower-asset/jquery",
12 | "version": "2.2.4",
13 | "source": {
14 | "type": "git",
15 | "url": "https://github.com/jquery/jquery-dist.git",
16 | "reference": "c0185ab7c75aab88762c5aae780b9d83b80eda72"
17 | },
18 | "dist": {
19 | "type": "zip",
20 | "url": "https://api.github.com/repos/jquery/jquery-dist/zipball/c0185ab7c75aab88762c5aae780b9d83b80eda72",
21 | "reference": "c0185ab7c75aab88762c5aae780b9d83b80eda72",
22 | "shasum": ""
23 | },
24 | "type": "bower-asset-library",
25 | "extra": {
26 | "bower-asset-main": "dist/jquery.js",
27 | "bower-asset-ignore": [
28 | "package.json"
29 | ]
30 | },
31 | "license": [
32 | "MIT"
33 | ],
34 | "keywords": [
35 | "browser",
36 | "javascript",
37 | "jquery",
38 | "library"
39 | ]
40 | },
41 | {
42 | "name": "bower-asset/jquery.inputmask",
43 | "version": "3.3.7",
44 | "source": {
45 | "type": "git",
46 | "url": "https://github.com/RobinHerbots/Inputmask.git",
47 | "reference": "9835731cb78cac749734d94a1cb5bd70da4d3b10"
48 | },
49 | "dist": {
50 | "type": "zip",
51 | "url": "https://api.github.com/repos/RobinHerbots/Inputmask/zipball/9835731cb78cac749734d94a1cb5bd70da4d3b10",
52 | "reference": "9835731cb78cac749734d94a1cb5bd70da4d3b10",
53 | "shasum": ""
54 | },
55 | "require": {
56 | "bower-asset/jquery": ">=1.7"
57 | },
58 | "type": "bower-asset-library",
59 | "extra": {
60 | "bower-asset-main": [
61 | "./dist/inputmask/inputmask.js",
62 | "./dist/inputmask/inputmask.extensions.js",
63 | "./dist/inputmask/inputmask.date.extensions.js",
64 | "./dist/inputmask/inputmask.numeric.extensions.js",
65 | "./dist/inputmask/inputmask.phone.extensions.js",
66 | "./dist/inputmask/jquery.inputmask.js",
67 | "./dist/inputmask/global/document.js",
68 | "./dist/inputmask/global/window.js",
69 | "./dist/inputmask/phone-codes/phone.js",
70 | "./dist/inputmask/phone-codes/phone-be.js",
71 | "./dist/inputmask/phone-codes/phone-nl.js",
72 | "./dist/inputmask/phone-codes/phone-ru.js",
73 | "./dist/inputmask/phone-codes/phone-uk.js",
74 | "./dist/inputmask/dependencyLibs/inputmask.dependencyLib.jqlite.js",
75 | "./dist/inputmask/dependencyLibs/inputmask.dependencyLib.jquery.js",
76 | "./dist/inputmask/dependencyLibs/inputmask.dependencyLib.js",
77 | "./dist/inputmask/bindings/inputmask.binding.js"
78 | ],
79 | "bower-asset-ignore": [
80 | "**/*",
81 | "!dist/*",
82 | "!dist/inputmask/*",
83 | "!dist/min/*",
84 | "!dist/min/inputmask/*"
85 | ]
86 | },
87 | "license": [
88 | "http://opensource.org/licenses/mit-license.php"
89 | ],
90 | "description": "Inputmask is a javascript library which creates an input mask. Inputmask can run against vanilla javascript, jQuery and jqlite.",
91 | "keywords": [
92 | "form",
93 | "input",
94 | "inputmask",
95 | "jquery",
96 | "mask",
97 | "plugins"
98 | ]
99 | },
100 | {
101 | "name": "bower-asset/punycode",
102 | "version": "v1.3.2",
103 | "source": {
104 | "type": "git",
105 | "url": "https://github.com/bestiejs/punycode.js.git",
106 | "reference": "38c8d3131a82567bfef18da09f7f4db68c84f8a3"
107 | },
108 | "dist": {
109 | "type": "zip",
110 | "url": "https://api.github.com/repos/bestiejs/punycode.js/zipball/38c8d3131a82567bfef18da09f7f4db68c84f8a3",
111 | "reference": "38c8d3131a82567bfef18da09f7f4db68c84f8a3",
112 | "shasum": ""
113 | },
114 | "type": "bower-asset-library",
115 | "extra": {
116 | "bower-asset-main": "punycode.js",
117 | "bower-asset-ignore": [
118 | "coverage",
119 | "tests",
120 | ".*",
121 | "component.json",
122 | "Gruntfile.js",
123 | "node_modules",
124 | "package.json"
125 | ]
126 | }
127 | },
128 | {
129 | "name": "bower-asset/yii2-pjax",
130 | "version": "v2.0.6",
131 | "source": {
132 | "type": "git",
133 | "url": "https://github.com/yiisoft/jquery-pjax.git",
134 | "reference": "60728da6ade5879e807a49ce59ef9a72039b8978"
135 | },
136 | "dist": {
137 | "type": "zip",
138 | "url": "https://api.github.com/repos/yiisoft/jquery-pjax/zipball/60728da6ade5879e807a49ce59ef9a72039b8978",
139 | "reference": "60728da6ade5879e807a49ce59ef9a72039b8978",
140 | "shasum": ""
141 | },
142 | "require": {
143 | "bower-asset/jquery": ">=1.8"
144 | },
145 | "type": "bower-asset-library",
146 | "extra": {
147 | "bower-asset-main": "./jquery.pjax.js",
148 | "bower-asset-ignore": [
149 | ".travis.yml",
150 | "Gemfile",
151 | "Gemfile.lock",
152 | "CONTRIBUTING.md",
153 | "vendor/",
154 | "script/",
155 | "test/"
156 | ]
157 | },
158 | "license": [
159 | "MIT"
160 | ]
161 | },
162 | {
163 | "name": "cebe/markdown",
164 | "version": "1.1.1",
165 | "source": {
166 | "type": "git",
167 | "url": "https://github.com/cebe/markdown.git",
168 | "reference": "c30eb5e01fe021cc5bba2f9ee0eeef96d4931166"
169 | },
170 | "dist": {
171 | "type": "zip",
172 | "url": "https://api.github.com/repos/cebe/markdown/zipball/c30eb5e01fe021cc5bba2f9ee0eeef96d4931166",
173 | "reference": "c30eb5e01fe021cc5bba2f9ee0eeef96d4931166",
174 | "shasum": ""
175 | },
176 | "require": {
177 | "lib-pcre": "*",
178 | "php": ">=5.4.0"
179 | },
180 | "require-dev": {
181 | "cebe/indent": "*",
182 | "facebook/xhprof": "*@dev",
183 | "phpunit/phpunit": "4.1.*"
184 | },
185 | "bin": [
186 | "bin/markdown"
187 | ],
188 | "type": "library",
189 | "extra": {
190 | "branch-alias": {
191 | "dev-master": "1.1.x-dev"
192 | }
193 | },
194 | "autoload": {
195 | "psr-4": {
196 | "cebe\\markdown\\": ""
197 | }
198 | },
199 | "notification-url": "https://packagist.org/downloads/",
200 | "license": [
201 | "MIT"
202 | ],
203 | "authors": [
204 | {
205 | "name": "Carsten Brandt",
206 | "email": "mail@cebe.cc",
207 | "homepage": "http://cebe.cc/",
208 | "role": "Creator"
209 | }
210 | ],
211 | "description": "A super fast, highly extensible markdown parser for PHP",
212 | "homepage": "https://github.com/cebe/markdown#readme",
213 | "keywords": [
214 | "extensible",
215 | "fast",
216 | "gfm",
217 | "markdown",
218 | "markdown-extra"
219 | ],
220 | "time": "2016-09-14 20:40:20"
221 | },
222 | {
223 | "name": "ezyang/htmlpurifier",
224 | "version": "v4.9.3",
225 | "source": {
226 | "type": "git",
227 | "url": "https://github.com/ezyang/htmlpurifier.git",
228 | "reference": "95e1bae3182efc0f3422896a3236e991049dac69"
229 | },
230 | "dist": {
231 | "type": "zip",
232 | "url": "https://api.github.com/repos/ezyang/htmlpurifier/zipball/95e1bae3182efc0f3422896a3236e991049dac69",
233 | "reference": "95e1bae3182efc0f3422896a3236e991049dac69",
234 | "shasum": ""
235 | },
236 | "require": {
237 | "php": ">=5.2"
238 | },
239 | "require-dev": {
240 | "simpletest/simpletest": "^1.1"
241 | },
242 | "type": "library",
243 | "autoload": {
244 | "psr-0": {
245 | "HTMLPurifier": "library/"
246 | },
247 | "files": [
248 | "library/HTMLPurifier.composer.php"
249 | ]
250 | },
251 | "notification-url": "https://packagist.org/downloads/",
252 | "license": [
253 | "LGPL"
254 | ],
255 | "authors": [
256 | {
257 | "name": "Edward Z. Yang",
258 | "email": "admin@htmlpurifier.org",
259 | "homepage": "http://ezyang.com"
260 | }
261 | ],
262 | "description": "Standards compliant HTML filter written in PHP",
263 | "homepage": "http://htmlpurifier.org/",
264 | "keywords": [
265 | "html"
266 | ],
267 | "time": "2017-06-03 02:28:16"
268 | },
269 | {
270 | "name": "yiisoft/yii2",
271 | "version": "2.0.12",
272 | "source": {
273 | "type": "git",
274 | "url": "https://github.com/yiisoft/yii2-framework.git",
275 | "reference": "70acbecc75cb26b6cd66d16be0b06e4b73db190d"
276 | },
277 | "dist": {
278 | "type": "zip",
279 | "url": "https://api.github.com/repos/yiisoft/yii2-framework/zipball/70acbecc75cb26b6cd66d16be0b06e4b73db190d",
280 | "reference": "70acbecc75cb26b6cd66d16be0b06e4b73db190d",
281 | "shasum": ""
282 | },
283 | "require": {
284 | "bower-asset/jquery": "2.2.*@stable | 2.1.*@stable | 1.11.*@stable | 1.12.*@stable",
285 | "bower-asset/jquery.inputmask": "~3.2.2 | ~3.3.5",
286 | "bower-asset/punycode": "1.3.*",
287 | "bower-asset/yii2-pjax": "~2.0.1",
288 | "cebe/markdown": "~1.0.0 | ~1.1.0",
289 | "ext-ctype": "*",
290 | "ext-mbstring": "*",
291 | "ezyang/htmlpurifier": "~4.6",
292 | "lib-pcre": "*",
293 | "php": ">=5.4.0",
294 | "yiisoft/yii2-composer": "~2.0.4"
295 | },
296 | "bin": [
297 | "yii"
298 | ],
299 | "type": "library",
300 | "extra": {
301 | "branch-alias": {
302 | "dev-master": "2.0.x-dev"
303 | }
304 | },
305 | "autoload": {
306 | "psr-4": {
307 | "yii\\": ""
308 | }
309 | },
310 | "notification-url": "https://packagist.org/downloads/",
311 | "license": [
312 | "BSD-3-Clause"
313 | ],
314 | "authors": [
315 | {
316 | "name": "Qiang Xue",
317 | "email": "qiang.xue@gmail.com",
318 | "homepage": "http://www.yiiframework.com/",
319 | "role": "Founder and project lead"
320 | },
321 | {
322 | "name": "Alexander Makarov",
323 | "email": "sam@rmcreative.ru",
324 | "homepage": "http://rmcreative.ru/",
325 | "role": "Core framework development"
326 | },
327 | {
328 | "name": "Maurizio Domba",
329 | "homepage": "http://mdomba.info/",
330 | "role": "Core framework development"
331 | },
332 | {
333 | "name": "Carsten Brandt",
334 | "email": "mail@cebe.cc",
335 | "homepage": "http://cebe.cc/",
336 | "role": "Core framework development"
337 | },
338 | {
339 | "name": "Timur Ruziev",
340 | "email": "resurtm@gmail.com",
341 | "homepage": "http://resurtm.com/",
342 | "role": "Core framework development"
343 | },
344 | {
345 | "name": "Paul Klimov",
346 | "email": "klimov.paul@gmail.com",
347 | "role": "Core framework development"
348 | },
349 | {
350 | "name": "Dmitry Naumenko",
351 | "email": "d.naumenko.a@gmail.com",
352 | "role": "Core framework development"
353 | },
354 | {
355 | "name": "Boudewijn Vahrmeijer",
356 | "email": "info@dynasource.eu",
357 | "homepage": "http://dynasource.eu",
358 | "role": "Core framework development"
359 | }
360 | ],
361 | "description": "Yii PHP Framework Version 2",
362 | "homepage": "http://www.yiiframework.com/",
363 | "keywords": [
364 | "framework",
365 | "yii2"
366 | ],
367 | "time": "2017-06-05 14:33:41"
368 | },
369 | {
370 | "name": "yiisoft/yii2-composer",
371 | "version": "2.0.5",
372 | "source": {
373 | "type": "git",
374 | "url": "https://github.com/yiisoft/yii2-composer.git",
375 | "reference": "3f4923c2bde6caf3f5b88cc22fdd5770f52f8df2"
376 | },
377 | "dist": {
378 | "type": "zip",
379 | "url": "https://api.github.com/repos/yiisoft/yii2-composer/zipball/3f4923c2bde6caf3f5b88cc22fdd5770f52f8df2",
380 | "reference": "3f4923c2bde6caf3f5b88cc22fdd5770f52f8df2",
381 | "shasum": ""
382 | },
383 | "require": {
384 | "composer-plugin-api": "^1.0"
385 | },
386 | "require-dev": {
387 | "composer/composer": "^1.0"
388 | },
389 | "type": "composer-plugin",
390 | "extra": {
391 | "class": "yii\\composer\\Plugin",
392 | "branch-alias": {
393 | "dev-master": "2.0.x-dev"
394 | }
395 | },
396 | "autoload": {
397 | "psr-4": {
398 | "yii\\composer\\": ""
399 | }
400 | },
401 | "notification-url": "https://packagist.org/downloads/",
402 | "license": [
403 | "BSD-3-Clause"
404 | ],
405 | "authors": [
406 | {
407 | "name": "Qiang Xue",
408 | "email": "qiang.xue@gmail.com"
409 | }
410 | ],
411 | "description": "The composer plugin for Yii extension installer",
412 | "keywords": [
413 | "composer",
414 | "extension installer",
415 | "yii2"
416 | ],
417 | "time": "2016-12-20 13:26:02"
418 | }
419 | ],
420 | "packages-dev": [],
421 | "aliases": [],
422 | "minimum-stability": "stable",
423 | "stability-flags": [],
424 | "prefer-stable": false,
425 | "prefer-lowest": false,
426 | "platform": [],
427 | "platform-dev": []
428 | }
429 |
--------------------------------------------------------------------------------
/phpunit.xml.dist:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
12 | ./tests
13 |
14 |
15 |
--------------------------------------------------------------------------------
/src/View.php:
--------------------------------------------------------------------------------
1 | compress === true) {
26 | \Yii::$app->response->on(\yii\web\Response::EVENT_BEFORE_SEND, function (\yii\base\Event $Event) {
27 | $Response = $Event->sender;
28 | if ($Response->format === \yii\web\Response::FORMAT_HTML) {
29 | if (!empty($Response->data)) {
30 | $Response->data = self::compress($Response->data);
31 | }
32 | if (!empty($Response->content)) {
33 | $Response->content = self::compress($Response->content);
34 | }
35 | }
36 | });
37 | }
38 | }
39 |
40 | /**
41 | * HTML compress function.
42 | *
43 | * @param $html
44 | * @return mixed
45 | */
46 | public static function compress($html)
47 | {
48 | $filters = array(
49 | // remove javascript comments
50 | '/(?:'), '');
13 | }
14 |
15 | public function testUrlWithoutRemoveInsideQuotehttp()
16 | {
17 | $this->assertEquals(View::compress(''), '');
18 | }
19 |
20 | public function testUrlWithoutRemoveInsideApostrofe()
21 | {
22 | $this->assertEquals(View::compress(''), '');
23 | }
24 |
25 | public function testUrlWithoutRemoveInsideQuotehttps()
26 | {
27 | $this->assertEquals(View::compress(''), '');
28 | }
29 |
30 | public function testUrlWithoutRemoveUrlWithoutHttpInsideQuote()
31 | {
32 | $this->assertEquals(View::compress(''), '');
33 | }
34 |
35 | public function testUrlWithoutRemoveUrlWithoutHttpInsideApostrofe()
36 | {
37 | $this->assertEquals(View::compress(''), '');
38 | }
39 |
40 | public function testUrlWithoutRemoveUrlObject()
41 | {
42 | $this->assertEquals(View::compress(''),
50 | '');
51 | }
52 |
53 |
54 | public function testUrlWithRemoveCommentInStartOfAPage()
55 | {
56 | $this->assertEquals(View::compress(''), '');
57 | }
58 |
59 | public function testUrlWithRemoveCommentWithSpace()
60 | {
61 | $this->assertEquals(View::compress(''), '');
62 | }
63 |
64 | public function testUrlWithRemoveCommentWithUrlSpace()
65 | {
66 | $this->assertEquals(View::compress(''), '');
67 | }
68 |
69 | public function testUrlWithRemoveCommentWithUrlWithoutSpace()
70 | {
71 | $this->assertEquals(View::compress(''), '');
72 | }
73 |
74 | public function testUrlWithRemoveCommentUrlCheck()
75 | {
76 | $this->assertEquals(View::compress(''), '');
77 | }
78 | public function testUrlWithoutRemoveCommentUrlCheckInsideString()
79 | {
80 | $this->assertEquals(View::compress(''), '');
81 | }
82 |
83 | public function testUrlWithoutRemoveCommentDoubleUrlCheckInsideString()
84 | {
85 | $this->assertEquals(View::compress(''), '');
86 | }
87 |
88 | public function testUrlWithRemoveCommentAfterString()
89 | {
90 | $this->assertEquals(View::compress(''), '');
91 | }
92 |
93 | public function testUrlWithoutRemoveCommentTwoSeparateUrlStrings()
94 | {
95 | $this->assertEquals(View::compress(''), '');
96 | }
97 |
98 | public function testUrlWithRemoveCommentRandomString()
99 | {
100 | $this->assertEquals(View::compress(''), '');
101 | }
102 | }
--------------------------------------------------------------------------------
/tests/unit/_bootstrap.php:
--------------------------------------------------------------------------------
1 |