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

RemoveBlurScript   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 18
wmc 2
lcom 0
cbo 0
ccs 0
cts 5
cp 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A manipulate() 0 8 2
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