forked from zyx0814/dzzoffice
-
Notifications
You must be signed in to change notification settings - Fork 0
/
share.php
114 lines (105 loc) · 2.97 KB
/
share.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
<?php
/* //分享地址支持下载(a=down),预览(a=view)和流
* @copyright Leyun internet Technology(Shanghai)Co.,Ltd
* @license http://www.dzzoffice.com/licenses/license.txt
* @package DzzOffice
* @link http://www.dzzoffice.com
* @author zyx(zyx@dzz.cc)
*/
define('APPTYPEID', 200);
require './core/class/class_core.php';
require './dzz/function/dzz_core.php';
$dzz = C::app();
$dzz->init();
if(!$path=dzzdecode(trim($_GET['s']))){
exit('Access Denied');
}
if($_GET['a']=='down'){
IO::download($path);
exit();
}elseif($_GET['a']=='view'){
$icoarr=IO::getMeta($path);
if($icoarr['type']=='video'){
@header("Location: $icoarr[url]");
exit();
}
$imageexts=array('jpg','jpeg','png','gif'); //图片使用;
$filename=$icoarr['name'];//rtrim($_GET['n'],'.dzz');
$ext=$icoarr['ext'];//strtolower(substr(strrchr($filename, '.'), 1, 10));
if(!$ext) $ext=preg_replace("/\?.+/i",'',strtolower(substr(strrchr(rtrim($url,'.dzz'), '.'), 1, 10)));
if(in_array($ext,$imageexts)){
$url=$_G['siteurl'].'index.php?mod=io&op=thumbnail&original=1&path='.$_GET['s'];
@header("Location: $url");
exit();
}elseif($ext=='mp3'){
$url=$_G['siteurl'].'index.php?mod=sound&path='.$_GET['s'];
@header("Location: $url");
exit();
}elseif($icoarr['type']=='dzzdoc'){
$url=$_G['siteurl'].'index.php?mod=document&icoid='.$_GET['s'];
@header("Location: $url");
exit();
}
$bzarr=explode(':',$icoarr['rbz']?$icoarr['rbz']:$icoarr['bz']);
$bz=$bzarr[0];
$extall=C::t('app_open')->fetch_all_ext();
$exts=array();
foreach($extall as $value){
if(!isset($exts[$value['ext']]) || $value['isdefault']) $exts[$value['ext']]=$value;
}
if(isset($exts[$bz.':'.$ext])){
$data=$exts[$bz.':'.$ext];
}elseif($exts[$ext]){
$data=$exts[$ext];
}elseif($exts[$icoarr['type']]){
$data=$exts[$icoarr['type']];
}else $data=array();
if($data){
$url=$data['url'];
if(strpos($url,'dzzjs:')!==false){//dzzjs形式时
@header("Location: $icoarr[url]");
exit();
}else{
//替换参数
$url=preg_replace("/{(\w+)}/ie", "cansu_replace('\\1')", $url);
//添加path参数;
if(strpos($url,'?')!==false && strpos($url,'path=')===false){
$url.='&path='.$_GET['s'];
}
@header("Location: $url");
exit();
}
}else{//没有可用的打开方式,转入下载;
IO::download($path);
exit();
}
}
//获取文件流地址
if(!$url=(IO::getStream($path))){
exit('获取文件失败');
}
if(is_array($url)) exit($url['error']);
//如果是阻止运行的后缀名时,直接调用;
if($ext && in_array($ext,$_G['setting']['unRunExts'])){
$mime='text/plain';
}else{
$mime=dzz_mime::get_type($ext);
}
@set_time_limit(0);
@header('Content-Type: '.$mime);
@ob_end_clean();
@readfile($url);
@flush();
@ob_flush();
exit();
function cansu_replace($key){
global $_GET,$icoarr;
if($key=='path'){
return $_GET['s'];
}else if($key=='icoid'){
return 'preview_'.random(5);
}elseif(isset($icoarr[$key])){
return urlencode($icoarr[$key]);
}else return '';
}
?>