-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathviewsource.php
62 lines (50 loc) · 1.4 KB
/
viewsource.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
include_once('../includes/geshi.php');
function markupLinks($html,$uri)
{
preg_match('/https?:\/\/\S+?(?=\/)/i', $uri, $matches);
$baseUri = $matches[0];
$regex = array('/(?<=")(https?:\/\/\S+)(?=")/i', // Absolute paths: "http://asdf.com/asdf.php?id=x&ad=y"
'/(?<=")(\/\S+)(?=")/i'); // Relative paths: "/scripts/regex-1.1.min.js"
$replc = array('<a href="$1">$1</a>',
"<a href=\"$baseUri$1\">$1</a>");
return preg_replace($regex, $replc, $html);
}
$uri = $_GET['uri'];
if ($_POST)
{
$data = $_POST['DOM'];
$htmlenc = urldecode($data);
$geshi = new GeSHi($htmlenc, 'html5');
$geshi->enable_keyword_links(false);
$geshi->enable_classes();
$htmlenc = $geshi->parse_code();
// Substitute tabs for 4 spaces
$htmlenc = str_replace("\t", ' ', $htmlenc);
// Trim trailing spaces
$htmlenc = preg_replace("/[ \t]+$/", '', $htmlenc);
// Markup URIs and paths as links
$htmlenc = markupLinks($htmlenc,$uri);
// Print geshi stylesheet
$stylesheet = $geshi->get_stylesheet();
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<title>Source of <?php echo htmlspecialchars($uri); ?></title>
<style>
pre {
overflow: auto;
white-space: pre-wrap;
word-wrap: break-word;
}
<?php echo $stylesheet; ?>
</style>
</head>
<body>
<?php echo $htmlenc; ?>
</body>
</html>