forked from akiyatkin/files
/
get.php
94 lines (79 loc) · 2.32 KB
/
get.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
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
<?php
/*
Copyright 2008-2010 ITLife, Ltd. Togliatti, Samara Oblast, Russian Federation. http://itlife-studio.ru
History
23.04.2010
Скрипт получает src без расширения и без цифры сортировки.... а возвращает html
25.04.2010
Добавлено кэширование modified
09.05.2010
Добавлена поддерж php файлов и возможность передачи get параметров запрашиваемому файлу
*/
//..'xls'=>'?-pages/xls/xls.php?src='
namespace infrajs\doc;
use infrajs\path\Path;
use infrajs\ans\Ans;
use infrajs\access\Access;
use infrajs\load\Load;
$isrc = Ans::GET('src');//Path::toutf(urldecode($_SERVER['QUERY_STRING']));
$isrc = Path::pretty($isrc);
Access::modified();
$fdata = Load::srcInfo($isrc);
$src = Access::cache('files_get_php', function ($isrc) {
$src = Path::theme($isrc);
if ($src) return $isrc;
$fdata = Load::srcInfo($isrc);
$folder = Path::theme($fdata['folder']);
if (!Path::theme($folder)) {
return false;
}
array_map(function ($file) use (&$result, $fdata) {
if ($file[0] == '.') {
return;
}
$file=Path::toutf($file);
$fd = Load::nameInfo($file);
if ($fdata['id'] && $fdata['id'] != $fd['id']) {
return;
}
if ($fdata['name'] && $fdata['name'] != $fd['name']) {
return;
}
if ($fdata['ext'] && $fdata['ext'] != $fd['ext']) {
return;
} elseif ($result) {
//Расширение не указано и уже есть результат
//Исключение.. расширение tpl самое авторитетное
if ($fd['ext'] != 'tpl') {
return;
}
}
$result = $file;
}, scandir(Path::theme($folder)));
if (!$result) {
return false;
}
return $folder.$result;
}, array($fdata['path']), isset($_GET['re']));
$ans = array('src' => $isrc);
if (!$src) {
if (!Load::isphp()) header('HTTP/1.0 404 Not Found');
return;
}
$src = Path::theme($src);
$fdata = Load::srcInfo($src);
if (in_array($fdata['ext'], array('docx'))) {
$txt = Docx::get($isrc);
return Ans::txt($txt);
}
if (in_array($fdata['ext'], array('mht'))) {
$txt = Mht::get($isrc);
return Ans::txt($txt);
}
if (in_array($fdata['ext'], array('tpl', 'html', 'htm','php'))) {
$txt = Load::loadTEXT($isrc);
return Ans::txt($txt);
}
if (!Load::isphp()) {
header('HTTP/1.0 400 Bad Request');
}