summaryrefslogtreewebsitecommitdiff
path: root/src/web/_controller/_meta.php
blob: 4500175a280ead5053608bebef01273ce490e05d (plain)
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php /* Copyright (c) 2024 Freya Murphy */
class _meta_controller extends Controller {

	public function robots(): void
	{
		header("Content-Type: text/plain");
		$sitemap = $this->get_url('sitemap.xml');

		echo "User-agent: *\n";
		echo "Disallow:\n";
		echo "Crawl-delay: 5\n";
		echo "Disallow: /_comments/\n";
		echo "Disallow: /pacbattle/\n";
		echo "Disallow: /bucket/\n";
		echo "Sitemap: {$sitemap}\n";
	}

	private function sitemap_page(string $url, string $priority): void
	{
		echo "<url>\n";
		echo "<loc>{$this->get_url($url)}</loc>\n";
		echo "<priority>{$priority}</priority>\n";
		echo "</url>";
	}

	public function sitemap(): void
	{
		header("Content-Type: application/xml");

		echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
		echo "<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\n";

		$this->sitemap_page('home', 1);
		$this->sitemap_page('projects', 0.8);
		$this->sitemap_page('blog', 0.8);

		$this->load_lang('blog');
		$blog_modal = $this->load_model('blog');
		$blog = $blog_modal->get_data()['blog'];

		foreach ($blog as $name => $_) {
			$name = substr($name, 0, -3);
			$this->sitemap_page("blog/post/{$name}", 0.5);
		}

		echo "</urlset>\n";
	}

	public function manifest(): void
	{
		$json = array(
			'short_name' => lang('domain'),
			'name' => lang('domain'),
			'icons' => [
				array(
					'src' => $this->get_url('public/icons/logo512.png'),
					'type' => 'image/png',
					'sizes' => '512x512',
					'purpose' => 'any maskable'
				)
			],
			'id' => $this->get_url('home'),
			'start_url' => $this->get_url('home'),
			'background_color' => lang('theme_color'),
			'display' => 'standalone',
			'scope' => lang('base_path'),
			'theme_color' => lang('theme_color'),
			'shortcuts' => [],
			'description' => lang('default_short_desc'),
			'screenshots' => []
		);

		header('Content-type: application/json');
		echo json_encode($json);
	}

}