forked from zhufenghua1998/bp3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
394 lines (365 loc) · 15.5 KB
/
index.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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
<?php
require('./functions.php');
force_login(array("user"=>$user,"tryLogin"=>1));
$tagType = $_GET['tagType'] ?? 'dir';
// 多账户处理
$u = isset($_GET['u']) ? (int)$_GET['u'] : $uk; //【用uk而不要用index,因为index可能切换顺序而导致数据不正确,而uk则可以始终不变】
if($u<0){ $u= $uk; } // 如果为负数,也为uk
$disks = $config['disks'] ?? '';
$hideFile = $config['control']['hideFile'] ?? "";
$hideDir = $config['control']['hideDir'] ?? "";
$hideDirs[$uk] = $hideDir;
$hideFiles[$uk] = $hideFile;
$pre_dirs[$uk] = $pre_dir;
$pre_dir_shows[$uk] = $config['control']['pre_dir_show'] && $config['control']['pre_dir_show'] ? $config['control']['pre_dir_show'] : ( isset($config['control']['show_name']) && $config['control']['show_name'] ? $config['control']['show_name'] : "主账户");
$pre_dir_icon[$uk] = $config['control']['pre_dir_icon'] && $config['control']['pre_dir_icon'] ? $config['control']['pre_dir_icon'] : "";
//存在多账户
if(is_array($disks)){
$disks_count = count($disks);
// 尝试获取该账户
$disks_u = $disks[$u] ?? null;
if(is_array($disks_u)){
// 取得多账户前置目录、及其token
$pre_dir = $disks_u['pre_dir'] ?? "";
$pre_dir_show = $disks_u['pre_dir_show'] ?? "";
$access_token = $disks_u['access_token'];
$hideFile = $disks_u['hideFile'] ?? '';
$hideDir = $disks_u['hideDir'] ?? '';
$uk = $disks_u['uk'];
}
// 多账户解析失败,默认u=uk
else{
$u = $uk;
}
$us_count = $disks_count+1; // 多账户+主账户
$us = array();
$us[$uk] = isset($config['control']['show_name']) && !empty($config['control']['show_name']) ? $config['control']['show_name'] : "主账户";
foreach ($disks as $kk => $disk){
$us[$kk] = isset($disk['show_name']) && !empty($disk['show_name']) ? $disk['show_name'] : "账户".$kk;
//获取所有的隐藏目录和文件列表
$hideDirs[$kk] = $disk['hideDir'] ?? '';
$hideFiles[$kk] = $disk['hideFile'] ?? '';
$pre_dirs[$kk] = $disk['pre_dir'] ?? "";
$pre_dir_shows[$kk] = $disk['pre_dir_show'] ?? "";
$pre_dir_icon[$kk] = $disk['pre_dir_icon'] ?? "";
}
}
//不存在多账户
else{
$us_count = $uk;
$us = array($uk=>"主账户");
}
$bp3_tag->assign("u",$u);
// 多目录处理
$tag = isset($_GET['tag']) ? (int)$_GET['tag'] : 1;
if($tag<0){ $tag= 1; } // 如果为负数,也为1
//取出所有账户的所有目录
$allPredirs = array(); //格式:array ( u=> array('$name1','$name2') )
$allDirs_count = 0; //计算所有的目录
foreach ($pre_dirs as $pre_dirs_k => $pre_dirs_v){
//非根目录,可能有多个
if(!empty($pre_dirs_v)){
$pre_dirs_v_arr = explode("||",$pre_dirs_v); //所有的前置目录
$pre_dir_shows_v_arr = explode("||",$pre_dir_shows[$pre_dirs_k]); //前置目录对应的自定义名称
$pre_dir_icon_v_arr = explode("||",$pre_dir_icon[$pre_dirs_k]); //前置目录对应的自定义名称
//遍历判断名称是否存在,如果不存在则截取目录名
$newNames = array();
foreach ($pre_dirs_v_arr as $pre_dirs_v_arr_k => $pre_dirs_v_arr_v){
$allDirs_count++;
//该项有名称
if(isset($pre_dir_shows_v_arr[$pre_dirs_v_arr_k]) && $pre_dir_shows_v_arr[$pre_dirs_v_arr_k]){
$newNames[$pre_dirs_v_arr_k] = array(
'name'=>$pre_dir_shows_v_arr[$pre_dirs_v_arr_k],
'icon'=> BASE_URL . ( isset($pre_dir_icon_v_arr[$pre_dirs_v_arr_k]) && $pre_dir_icon_v_arr[$pre_dirs_v_arr_k] ? $pre_dir_icon_v_arr[$pre_dirs_v_arr_k] : "/static/img/icon/folder.png" )
);
}
//截取目录名称作为该项名称
else{
$newNames[$pre_dirs_v_arr_k] = array(
'name'=>substr($pre_dirs_v_arr_v,strrpos($pre_dirs_v_arr_v,"/")+1,strlen($pre_dirs_v_arr_v)),
'icon'=>BASE_URL. ( isset($pre_dir_icon_v_arr[$pre_dirs_v_arr_k]) && $pre_dir_icon_v_arr[$pre_dirs_v_arr_k] ? $pre_dir_icon_v_arr[$pre_dirs_v_arr_k] : "/static/img/icon/folder.png" )
);
}
}
$allPredirs[$pre_dirs_k] = $newNames;
}
//仅根目录
else{
$showname = isset($pre_dir_shows[$pre_dirs_k]) && $pre_dir_shows[$pre_dirs_k] ? $pre_dir_shows[$pre_dirs_k] : $us[$pre_dirs_k];
$allPredirs[$pre_dirs_k] = array( array("name"=>$showname, "icon"=>BASE_URL. ( isset($pre_dir_icon[$pre_dirs_k]) && $pre_dir_icon[$pre_dirs_k] ? $pre_dir_icon[$pre_dirs_k] : "/static/img/icon/folder.png") ) );
$allDirs_count ++;
}
}
$bp3_tag->assign("allPredirs",$allPredirs);
$bp3_tag->assign("allDirs_count",$allDirs_count);
$tags = explode("||",$pre_dir);
$tags_count = count($tags);
if($tag>$tags_count){ $tag=1; } // 如果指定的目录不存在,也为1
$pre_dir = $tags[$tag-1]; // 取得对应的前置目录
$bp3_tag->assign("tag",$tag);
//是否使用数据库
$config['useDb'] = $config['useDb'] ?? 0;
if($config['useDb'] && $config['useDbPre']){
$db = 1;
}else{
$db = 0;
}
// 捕获dir查询参数
$dir = isset($_GET['dir']) ? $_GET['dir'] : ''; // 少了前缀
// 捕获查询参数
$key = $_GET['s'] ?? null;
// 捕获分页参数
$page = $_GET['page'] ?? 1;
$pageSize = $_GET['pageSize'] ?? 20;
//是否使用sqlite
$baseDb = $config['baseDb'] ?? array();
$baseDb = in_array($uk,$baseDb);
if($baseDb){
$baseDb = $config['bindDb'][$uk];
}
//是否禁用db【该账户】
$unUseDb = $config['unUseDb'] ?? array();
$unUseDb = in_array($uk,$unUseDb) ? 1 : 0;
$recursion = $_GET['recursion'] ?? 2; //2、递归根目录,1.递归当前文件夹,0.当前文件夹不递归【这里的根目录是前台的根目录】
$bp3_tag->assign("recursion",$recursion);
$fileType = $_GET['fileType'] ?? 1; //1.全部,2.文件夹,3.文件
$bp3_tag->assign("fileType",$fileType);
$orderType = $_GET['orderType'] ?? 1; //1.默认,2.文件名升序,3.更新时间倒序
$bp3_tag->assign("orderType",$orderType);
if($db && !$unUseDb){
$bp3_tag->assign("db",1);
}else{
$bp3_tag->assign("db",0);
}
$allSearch = $config['allSearch'] ?? 0; //混合搜索
if($db && !$unUseDb && !$baseDb && $allSearch){ //allSearch时,前置目录无效
$pre_dir = "";
$real_dir = "/";
}
// data数据,优先查询,然后是dir
if($key){
//根目录全部,直接变成pre_dir
if($recursion==2){
if($pre_dir==""){
$dir = "/";
$real_dir="/";
}else{
$real_dir = $pre_dir;
}
$recursion = 1;
}
//当前目录全部、或当前目录?
else{
$recursion = $recursion ? 1 : 0;
if(!$dir){
// 前台目录为空
if($pre_dir==""){
$dir = "/";
$real_dir="/";
}
// 取得前台目录
else{
$real_dir = $pre_dir;
}
}
// 传递了dir
else{
$real_dir = $pre_dir.$dir;
}
}
if($tagType=='dir'){
$data = api(array('method'=>'m_file_search','module'=>'baidu','recursion'=>$recursion,'pre_dir'=>$real_dir,'page'=>$page,'pageSize'=>$pageSize,'key'=>$key,'access_token'=>$access_token,'db'=>$db,'uk'=>$uk,'baseDb'=>$baseDb,'unUseDb'=>$unUseDb,'recursion'=>$recursion,'fileType'=>$fileType,'orderType'=>$orderType));
}else{
$data = array('list'=>array(),'pageInfo'=>array('totalCount'=>0,'totalPage'=>1,'page'=>1,'pageSize'=>20));
}
}else{
//处理得到真实的dir
//没有传递dir
if(!$dir){
// 前台目录为空
if($pre_dir==""){
$dir = "/";
$real_dir="/";
}
// 取得前台目录
else{
$real_dir = $pre_dir;
}
}
// 传递了dir
else{
$real_dir = $pre_dir.$dir;
}
if($tagType=='dir'){
$data = api(array('method'=>'m_file_list','module'=>'baidu','dir'=>$real_dir,'page'=>$page,'pageSize'=>$pageSize,'access_token'=>$access_token,'db'=>$db,'uk'=>$uk,'baseDb'=>$baseDb,'unUseDb'=>$unUseDb));
}else{
$data = array('list'=>array(),'pageInfo'=>array('totalCount'=>0,'totalPage'=>1,'page'=>1,'pageSize'=>20));
}
}
//前台应该展示的“真实路径”
$pre_real_dir = substr($real_dir,strlen($pre_dir));
$bp3_tag->assign("dir",$pre_real_dir);
// 是否还有下一页(仅搜索接口)
$has_more = $data['has_more'] ?? null;
$pageInfo = $data['pageInfo'] ?? array();
$bp3_tag->assign("pageInfo",json_encode($pageInfo));
// 当前目录非空,生成导航数组
if($pre_real_dir!=""){
$dirs = explode('/',$pre_real_dir); // 取得路径
$dir_path = ''; // 新的访问路径
$dir_paths = [null,]; // 存储新路径组
for($i=1;$i<count($dirs);$i++){
if($dirs[$i]==""){
continue;
}
$dir_path.='/';
$dir_path.=$dirs[$i];
$dir_paths[$i] = $dir_path;
$dir_link = urlencode($dir_path);
$item = ["enc"=>$dir_link,"name"=>$dirs[$i]];
$nav[] = $item;
}
}
$nav = $nav ?? array();
$bp3_tag->assign("nav",$nav);
$bp3_tag->assign("nav_count",count($nav));
$bp3_tag->assign("key",$key);
$loadThumb = isset($config['loadThumb']) ? $config['loadThumb'] : 1; //是否加载缩略图?
// 处理data
$hideFile = explode(",",$hideFile);
if(!empty($hideDir)){
$hideDir = explode("||",$hideDir);
}
foreach ($data['list'] as $k=> & $row){
if(isset($row['uk'])){
$hideFile = $hideFiles[$row['uk']] ?? '';
$hideDir = $hideDirs[$row['uk']] ?? '';
$hideFile = explode(",",$hideFile);
if(!empty($hideDir)){
$hideDir = explode("||",$hideDir);
}
}
// 隐藏文件夹列表
if(!empty($hideDir)){
$flag = false;
foreach ($hideDir as $val){
if(substr($row['path'],0,strlen($val)) == $val){
$flag = true;
break;
}
}
if($flag){
unset($data['list'][$k]);
continue;
}
}
if($row['isdir']==1){
// 去掉前缀
$path = substr($row['path'],strlen($pre_dir));
// 编码后的地址
$encode_path = urlencode($path);
// 存储变更
$row['path'] = $path;
$row['encode_path'] = $encode_path;
}else{
// 隐藏文件列表
if(!empty($hideFile) && in_array($row['fs_id'],$hideFile)){
unset($data['list'][$k]);
continue;
}
// 显示大小
$row['show_size'] = height_show_size($row['size']);
// 去掉前缀的title
$row['title'] = substr($row['path'],strlen($pre_dir));
//强制加uk
$row['uk'] = $row['uk'] ?? $u;
//根据文件的后缀,选择对应的icon
$iconPath = CFG_STATIC_URL."/img/icon/file.png";
$fileExt = str::fileExtName($row['path']);
if($fileExt=="zip" || $fileExt=="rar" || $fileExt=="7z" || $fileExt=="jar"){
$iconPath = CFG_STATIC_URL."/img/icon/zip.png";
}
elseif($fileExt=="mp3" || $fileExt=="flac"){
$iconPath = CFG_STATIC_URL."/img/icon/mp3.png";
}
elseif($fileExt=="pdf"){
$iconPath = CFG_STATIC_URL."/img/icon/pdf.png";
}
elseif($fileExt=="doc" || $fileExt=="docx"){
$iconPath = CFG_STATIC_URL."/img/icon/word.png";
}
elseif($fileExt=="xls" || $fileExt=="xlsx"){
$iconPath = CFG_STATIC_URL."/img/icon/xls.png";
}
elseif($fileExt=="ppt" || $fileExt=="pptx"){
$iconPath = CFG_STATIC_URL."/img/icon/ppt.png";
}
elseif($fileExt=="txt" || $fileExt=="md" || $fileExt=="py" || $fileExt=="php" || $fileExt=="js" || $fileExt=="css" || $fileExt=="html"){
$iconPath = CFG_STATIC_URL."/img/icon/code.png";
}
elseif($fileExt=="exe"){
$iconPath = CFG_STATIC_URL."/img/icon/exe.png";
}
$row['icon'] = $iconPath;
if(!$loadThumb){
unset($row['thumbs']);
}
}
}
$bp3_tag->assign("close_dload",$close_dload);
$bp3_tag->assign("close_dlink",$close_dlink);
$bp3_tag->assign("data",$data);
$bp3_tag->assign("login_url",$login_url);
//轮播图
$barners = isset($config['barners']) && $config['barners'] ? $config['barners'] : array();
if(empty($barners)){
$barners = array(
[
'path' => '/static/img/carousel/1.png',
'title' => "$title - $subtitle",
'link' => ''
],
[
'path' => '/static/img/carousel/2.png',
'title' => "$title - $subtitle",
'link' => ''
],
[
'path' => '/static/img/carousel/3.png',
'title' => "$title - $subtitle",
'link' => ''
]
);
}
$bp3_tag->assign("barners",$barners);
$bp3_tag->assign("hideIndexNavbar",$config['hideIndexNavbar'] ?? 0);
$bp3_tag->assign("tagType",$tagType);
//取出所有的page
$pageIndex = 1;
$pageList = array();
$pageDir = BASE_ROOT."/temp/pages/";
$pageContent = '';
$selectPageIndex = $_GET['tag'] ?? '1';
while(file_exists($pageDir."$pageIndex.html")){
$pageImg = file_exists($pageDir."$pageIndex.png") ? BASE_URL."/temp/pages/$pageIndex.png" : BASE_URL.'/static/img/icon/folder.png';
$pageName = file_exists($pageDir."$pageIndex.txt") ? file_get_contents($pageDir."$pageIndex.txt") : '页面'.$pageIndex;
$pageList[$pageIndex] = array('name'=>$pageName,"icon"=>$pageImg);
if($pageIndex == $selectPageIndex){
$pageContent = $bp3_tag->fetch($pageDir."$pageIndex.html");
}
$pageIndex++;
}
$bp3_tag->assign("pageList",$pageList);
$bp3_tag->assign("pageContent",$pageContent);
//取出所有的links
$linkDir = BASE_ROOT."/temp/links/";
$linkList = array();
$linkIndex = 1;
while(file_exists($linkDir."$linkIndex.json")){
$linkItem = file_get_contents($linkDir."$linkIndex.json");
$linkItem = json_decode($linkItem,true);
$linkList[] = $linkItem;
$linkIndex ++;
}
$bp3_tag->assign("linkList",$linkList);
display();