-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathcontent.php
More file actions
107 lines (93 loc) · 3.25 KB
/
content.php
File metadata and controls
107 lines (93 loc) · 3.25 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?php
/** This file is part of load.link (https://github.com/deuiore/load.link).
* View the LICENSE file for full license information.
**/
class Content
{
const STATIC_PATH = 'static/';
protected $page;
public function __construct($route)
{
$pathinfo = pathinfo($route);
$link = $pathinfo['filename'];
$extension = (isset($pathinfo['extension'])) ? $pathinfo['extension']
: '';
$item = DB::get()->getLink($link);
/* 404 -*/
if (!$item)
{
$error = new Err(Err::NOT_FOUND);
$this->page = $error->getPage();
return;
}
/* Redirect */
if ($item['mime'] == 'wwwserver/redirection')
{
$this->page = new Page();
$this->page->setResponseCode(303);
$this->page->addHeader('Location: ' . $item['name']);
return;
}
/* Syntax Highlighter */
if (Config::get()->getValue('ui', 'syntax_highlighter')
&& $extension != 'raw')
{
$original_ext = pathinfo($item['name'], PATHINFO_EXTENSION);
if (in_array($original_ext, Utils::getLanguagesExtensionsList()))
{
$this->page = new Page('syntax_highlighter');
$language = Utils::detectLanguageFromExtension($original_ext);
$this->page->set(array(
'static_path' =>
Config::get()->getValue('routing', 'baseurl')
. self::STATIC_PATH,
'name' => $item['name'],
'text' => file_get_contents($item['path']),
'language' => $language,
'raw_url' => Router::getURL() . $link . '.raw'
));
return;
}
}
/* Media player */
if (Config::get()->getValue('ui', 'media_player')
&& $extension != 'raw')
{
if (in_array($item['mime'], Utils::getMediaFormatsList()))
{
$this->page = new Page('media_player');
$this->page->set(array(
'static_path' =>
Config::get()->getValue('routing', 'baseurl')
. self::STATIC_PATH,
'type' => explode('/', $item['mime'])[0],
'name' => $item['name'],
'mime' => $item['mime'],
'raw_url' => Router::getURL() . $link . '.raw'
));
return;
}
}
/* Default, just display the file as is */
$this->page = new Page();
$this->page->setFile($item);
}
public function getPage()
{
return $this->page;
}
public static function getStaticPage($path)
{
$file = Path::get('theme') . self::STATIC_PATH . $path;
if (strpos($path, '..') || !file_exists($file))
{
$error = new Err(Err::NOT_FOUND);
return $error->getPage();
}
$page = new Page();
$page->addHeader('Content-Type: ' . Utils::detectMime($file));
$page->addHeader('Content-Length: ' . filesize($file));
$page->setBuffer(file_get_contents($file));
return $page;
}
}