-
Notifications
You must be signed in to change notification settings - Fork 0
/
local_page.php
45 lines (34 loc) · 1.2 KB
/
local_page.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
<?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['filename'])) {
$filename = $_POST['filename'];
if (empty($errors)) {
$disk = Filesystem::disk('pages');
try {
$content = $disk->read($filename);
$tools = new HtmlTools($content);
$statistics = $tools->getTagStatistics();
} catch (CantResolveContentException $e) {
$errors[] = sprintf(
'Unable to get tag statistics from "%s" (%s), try another file',
$e->getPath(),
$e->getMessage()
);
}
}
}
$filename ??= '';
$filename = htmlspecialchars($filename);
$form = <<<HTML
<a href="/">By URL</a> | <a href="/local_page.php" class="active">By Local Filename</a>
<form action="$_SERVER[REQUEST_URI]" method="post">
<label for="url">Filename in local "pages" directory:</label>
<input type="text" name="filename" placeholder="test.html" value="$filename">
<input type="submit" value="Submit">
</form>
HTML;
require 'template.php';