-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
55 lines (41 loc) · 1.5 KB
/
index.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
<?php
use Parser\Filesystem\Filesystem;
use Parser\Site\HtmlTools;
use Parser\Exceptions\CantResolveContentException;
require __DIR__ . '/src/bootstrap/app.php';
$errors = [];
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['url'])) {
$url = $_POST['url'];
$parseUrl = parse_url($url);
if (!isset($parseUrl['scheme'])) {
$errors[] = 'Please enter URL with valid scheme (https://, http://)';
}
if (empty($errors)) {
$disk = Filesystem::customDisk('temp_http', [
'driver' => 'http',
'root' => $parseUrl['scheme'] . '://' . $parseUrl['host']
]);
try {
$content = $disk->read($parseUrl['path'] ?? '/');
$tools = new HtmlTools($content);
$statistics = $tools->getTagStatistics();
} catch (CantResolveContentException $e) {
$errors[] = sprintf(
'Unable to get tag statistics from "%s" (%s), try later or use another site',
$e->getPath(),
$e->getMessage()
);
}
}
}
$url ??= '';
$url = htmlspecialchars($url);
$form = <<<HTML
<a href="/" class="active">By URL</a> | <a href="/local_page.php">By Local Filename</a>
<form action="$_SERVER[REQUEST_URI]" method="post">
<label for="url">URL:</label>
<input type="text" name="url" placeholder="https://github.com" value="$url">
<input type="submit" value="Submit">
</form>
HTML;
require 'template.php';