|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* PHP version 5.4 |
|
4
|
|
|
* |
|
5
|
|
|
* Output link checker report in txt or html format |
|
6
|
|
|
* |
|
7
|
|
|
* @category GLICER |
|
8
|
|
|
* @package GlLinkChecker |
|
9
|
|
|
* @author Emmanuel ROECKER |
|
10
|
|
|
* @author Rym BOUCHAGOUR |
|
11
|
|
|
* @copyright 2015 GLICER |
|
12
|
|
|
* @license MIT |
|
13
|
|
|
* @link http://dev.glicer.com/ |
|
14
|
|
|
* |
|
15
|
|
|
* Created : 04/04/15 |
|
16
|
|
|
* File : GlLinkCheckerReport.php |
|
17
|
|
|
* |
|
18
|
|
|
*/ |
|
19
|
|
|
|
|
20
|
|
|
namespace GlLinkChecker; |
|
21
|
|
|
|
|
22
|
|
|
use Symfony\Component\Console\Output\StreamOutput; |
|
23
|
|
|
|
|
24
|
|
|
class GlLinkCheckerReport |
|
25
|
|
|
{ |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* write array result in a temp txt file |
|
29
|
|
|
* |
|
30
|
|
|
* @param string $name |
|
31
|
|
|
* @param array $result |
|
32
|
|
|
* |
|
33
|
|
|
* @return string |
|
34
|
|
|
*/ |
|
35
|
|
|
public static function toTmpTxt($name, $result) |
|
36
|
|
|
{ |
|
37
|
|
|
$resultfile = sys_get_temp_dir() . "/" . uniqid($name) . ".txt"; |
|
38
|
|
|
$resultoutput = new StreamOutput(fopen($resultfile, 'a', false)); |
|
39
|
|
|
$resultoutput->write("\xEF\xBB\xBF"); //add ut8 bom to txt file |
|
40
|
|
|
$resultoutput->write(print_r($result, true)); |
|
41
|
|
|
|
|
42
|
|
|
return $resultfile; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* write links test result in a temp html file |
|
47
|
|
|
* |
|
48
|
|
|
* @param string $name |
|
49
|
|
|
* @param GlLinkCheckerError[] $result |
|
50
|
|
|
* |
|
51
|
|
|
* @return string |
|
52
|
|
|
*/ |
|
53
|
|
|
public static function toTmpHtml($name, $result) |
|
54
|
|
|
{ |
|
55
|
|
|
$resultfile = sys_get_temp_dir() . "/" . uniqid($name) . ".html"; |
|
56
|
|
|
$html = self::toHtml($name, $result); |
|
57
|
|
|
file_put_contents($resultfile, $html); |
|
58
|
|
|
|
|
59
|
|
|
return $resultfile; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* render report in html format |
|
64
|
|
|
* |
|
65
|
|
|
* @param string $title |
|
66
|
|
|
* @param GlLinkCheckerError[] $links |
|
67
|
|
|
* |
|
68
|
|
|
* @return string |
|
69
|
|
|
*/ |
|
70
|
|
|
private static function toHtml($title,array $links) |
|
71
|
|
|
{ |
|
72
|
|
|
$html = '<!DOCTYPE HTML>'; |
|
73
|
|
|
$html .= '<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8">'; |
|
74
|
|
|
$html .= '<title>' . $title . '</title>'; |
|
75
|
|
|
$html .= '<style>'; |
|
76
|
|
|
$html .= '.error { color: red }'; |
|
77
|
|
|
|
|
78
|
|
|
$html .= '.tooltip |
|
79
|
|
|
{ |
|
80
|
|
|
display: inline; |
|
81
|
|
|
position: relative; |
|
82
|
|
|
text-decoration: none; |
|
83
|
|
|
top: 0px; |
|
84
|
|
|
left: 0px; |
|
85
|
|
|
}'; |
|
86
|
|
|
|
|
87
|
|
|
$html .= '.tooltip:hover:after |
|
88
|
|
|
{ |
|
89
|
|
|
background: #333; |
|
90
|
|
|
background: rgba(0,0,0,.8); |
|
91
|
|
|
border-radius: 5px; |
|
92
|
|
|
top: -5px; |
|
93
|
|
|
color: #fff; |
|
94
|
|
|
content: attr(data-tooltip); |
|
95
|
|
|
left: 160px; |
|
96
|
|
|
padding: 5px 15px; |
|
97
|
|
|
position: absolute; |
|
98
|
|
|
z-index: 98; |
|
99
|
|
|
width: 150px; |
|
100
|
|
|
}'; |
|
101
|
|
|
$html .= '</style>'; |
|
102
|
|
|
$html .= '</head><body>'; |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* @var GlLinkCheckerError $link |
|
106
|
|
|
*/ |
|
107
|
|
|
foreach ($links as $link) { |
|
108
|
|
|
$html .= '<div class="link">'; |
|
109
|
|
|
$url = $link->getLink(); |
|
110
|
|
|
$files = " -> " . implode(" ", $link->getFiles()); |
|
111
|
|
|
$errors = $link->getErrorMessages(); |
|
112
|
|
|
|
|
113
|
|
|
if (count($errors) <= 0) { |
|
114
|
|
|
$html .= '<a href="' . $url . '">' . $url . '</a>' . $files; |
|
115
|
|
|
$html .= '</div>'; |
|
116
|
|
|
continue; |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
$tooltip = implode(' ', $errors); |
|
120
|
|
|
$html .= '<a href="' . $url . '" class="error tooltip" data-tooltip="' . $tooltip . '">' . $url . '</a>' . $link->getStatusCode( |
|
121
|
|
|
) . $files; |
|
122
|
|
|
$html .= '</div>'; |
|
123
|
|
|
} |
|
124
|
|
|
$html .= '<br><br><br></body></html>'; |
|
125
|
|
|
|
|
126
|
|
|
return $html; |
|
127
|
|
|
} |
|
128
|
|
|
} |
|
129
|
|
|
|