-
Notifications
You must be signed in to change notification settings - Fork 0
/
admin.inc.php
155 lines (141 loc) · 3.74 KB
/
admin.inc.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<?php
use infrajs\path\Path;
use infrajs\access\Access;
use infrajs\load\Load;
function autoedit_theme($isrc)
{
$src = Access::cache('autoedit_theme', function ($isrc) {
$src = Path::theme($isrc);
if ($src) return $src;
$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 Path::theme($folder.$result);
}, array($isrc), isset($_GET['re']));
return $src;
}
function autoedit_createPath($p, $path = '')
{
//путь до файла или дирректории со * или без, возвращается тот же путь без звёздочки
//Если путь приходит от пользователя нужно проверять и префикс infra/data добавляется автоматически чтобы ограничить места создания
//if(preg_match("/\/\./",$ifolder))return err($ans,'Path should not contain points at the beginning of filename /.');
//if(!preg_match("/^\*/",$ifolder))return err($ans,'First symbol should be the asterisk *.');
if (is_string($p)) {
$p = Path::resolve($p);
$p = explode('/', $p);
$f = array_pop($p);//достали файл или пустой элемент у дирректории
$f = Path::tofs($f);
} else {
$f = '';
}
$dir = array_shift($p);//Создаём первую папку в адресе
$dir = Path::tofs($dir);
if ($dir) {
if (!is_dir($path.$dir)) {
$r = mkdir($path.$dir);
} else {
$r = true;
}
if ($r) {
return autoedit_createPath($p, $path.$dir.'/').$f;
} else {
throw Exception('Ошибка при работе с файловой системой');
}
}
return $path.$dir.'/'.$f;
}
function autoedit_ext($file)
{
if (!$file) {
return '';
}
$ext = preg_match('/\.(\w{0,4})$/', $file, $match);
$ext = $match[1];
return $ext;
}
function autoedit_folder($file)
{
$s = explode('/', $file);
$name = array_pop($s);
$folder = implode('/', $s);
if ($folder != '-') {
$folder .= '/';
}
return $folder;
}
function autoedit_takepath($file = false)
{
$takepath = Path::resolve('!admin_takefiles/');
if ($file === false) {
return $takepath;
}
$file=autoedit_theme($file);
$path = $takepath.preg_replace('/[\\/\\\\\*]/', '_', Path::tofs($file)).'.js';
return $path;
}
function autoedit_ismytake($file)
{
$takepath = autoedit_takepath($file);
$take = Load::loadJSON($takepath);
if (!$take) {
return true;
}
if ($take['ip'] != $_SERVER['REMOTE_ADDR'] || $take['browser'] != $_SERVER['HTTP_USER_AGENT']) {
return false;
}
return true;
}
if (!function_exists('err')) {
function err($ans, $msg)
{
$ans['msg'] = $msg;
echo Load::json_encode($ans);
}
}
function autoedit_backup($file)
{
}
function cpdir($src, $dst)
{
$dir = opendir($src);
mkdir($dst);
while (false !== ($file = readdir($dir))) {
if (($file != '.') && ($file != '..')) {
if (is_dir($src.'/'.$file)) {
cpdir($src.'/'.$file, $dst.'/'.$file);
} else {
copy($src.'/'.$file, $dst.'/'.$file);
}
}
}
closedir($dir);
return true;
}