Completed
Push — master ( 041c4d...dec97d )
by Tim
03:47
created

RemoveBlurScript::manipulate()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
ccs 0
cts 5
cp 0
rs 9.4285
cc 2
eloc 5
nc 2
nop 2
crap 6
1
<?php
2
/**
3
 * RemoveBlurScript
4
 *
5
 * @author  Tim Lochmüller
6
 */
7
8
namespace HTML\Sourceopt\Manipulation;
9
10
/**
11
 * TYPO3 adds to each page a small script:
12
 *                <script language="javascript">
13
 *                <!--
14
 *                browserName = navigator.appName;
15
 *                browserVer = parseInt(navigator.appVersion);
16
 *                var msie4 = (browserName == "Microsoft Internet Explorer" && browserVer >= 4);
17
 *                if ((browserName == "Netscape" && browserVer >= 3) || msie4 || browserName=="Konqueror") {version = "n3";} else {version = "n2";}
18
 *                function blurLink(theObject){
19
 *                if (msie4){theObject.blur();}
20
 *                }
21
 *                // -->
22
 *                </script>
23
 * Obviously used for client-side browserdetection - but thats not necessary if your page doesn't use JS
24
 */
25
class RemoveBlurScript implements ManipulationInterface
26
{
27
28
    /**
29
     * @param string $html          The original HTML
30
     * @param array  $configuration Configuration
31
     *
32
     * @return string the manipulated HTML
33
     */
34
    public function manipulate($html, array $configuration = [])
35
    {
36
        if (strlen($html) < 100000) {
37
            $pattern = '/<script (type="text\/javascript"|language="javascript")>.+?Konqueror.+function blurLink.+theObject.blur.+?<\/script>/is';
38
            $html = preg_replace($pattern, '', $html); // in head
39
        }
40
        return str_replace(' onfocus="blurLink(this);"', '', $html); // in body
41
    }
42
}
43