├── .gitignore
├── README.md
├── check.php
├── discuz_3_0
├── install
│ ├── discuz_ftp.php
│ ├── forum_attachment.php
│ ├── forum_image.php
│ ├── function_attachment.php
│ ├── function_home.php
│ ├── function_post.php
│ └── portal_attachment.php
└── uninstall
│ ├── discuz_ftp.php
│ ├── forum_attachment.php
│ ├── forum_image.php
│ ├── function_attachment.php
│ ├── function_home.php
│ ├── function_post.php
│ └── portal_attachment.php
├── discuz_3_1
├── install
│ ├── discuz_ftp.php
│ ├── forum_attachment.php
│ ├── forum_image.php
│ ├── function_attachment.php
│ ├── function_home.php
│ ├── function_post.php
│ └── portal_attachment.php
└── uninstall
│ ├── discuz_ftp.php
│ ├── forum_attachment.php
│ ├── forum_image.php
│ ├── function_attachment.php
│ ├── function_home.php
│ ├── function_post.php
│ └── portal_attachment.php
├── discuz_3_2
├── install
│ ├── discuz_ftp.php
│ ├── forum_attachment.php
│ ├── forum_image.php
│ ├── function_attachment.php
│ ├── function_home.php
│ ├── function_post.php
│ └── portal_attachment.php
└── uninstall
│ ├── discuz_ftp.php
│ ├── forum_attachment.php
│ ├── forum_image.php
│ ├── function_attachment.php
│ ├── function_home.php
│ ├── function_post.php
│ └── portal_attachment.php
├── discuz_3_3
├── install
│ ├── discuz_ftp.php
│ ├── forum_attachment.php
│ ├── forum_image.php
│ ├── function_attachment.php
│ ├── function_home.php
│ ├── function_post.php
│ └── portal_attachment.php
└── uninstall
│ ├── discuz_ftp.php
│ ├── forum_attachment.php
│ ├── forum_image.php
│ ├── function_attachment.php
│ ├── function_home.php
│ ├── function_post.php
│ └── portal_attachment.php
├── discuz_3_4
├── install
│ ├── discuz_ftp.php
│ ├── forum_attachment.php
│ ├── forum_image.php
│ ├── function_attachment.php
│ ├── function_home.php
│ ├── function_post.php
│ └── portal_attachment.php
└── uninstall
│ ├── discuz_ftp.php
│ ├── forum_attachment.php
│ ├── forum_image.php
│ ├── function_attachment.php
│ ├── function_home.php
│ ├── function_post.php
│ └── portal_attachment.php
├── discuz_plugin_upyun_SC_GBK.xml
├── discuz_plugin_upyun_SC_UTF8.xml
├── discuz_plugin_upyun_TC_BIG5.xml
├── discuz_plugin_upyun_TC_UTF8.xml
├── function_upyun.php
├── install.php
├── sdk
├── upyun.class.php
└── upyun_multipart_upload
│ ├── File.php
│ ├── Signature.php
│ ├── Upload.php
│ └── Util
│ └── MultiPartPost.php
├── uninstall.php
└── upyun.class.php
/.gitignore:
--------------------------------------------------------------------------------
1 | .idea
2 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Discuz Plugin For UPYUN
2 | 支持 Discuz 版本:`X3` `X3.1` `X3.2` `X3.3`
3 |
4 | ### 特性
5 |
6 | - 单空间配置
7 | - 增加分块上传
8 | - Token 防盗链
9 |
10 | *不支持表单直接上传*
11 |
12 | ### 视频教程
13 |
14 | https://techs.b0.upaiyun.com/videos/cdnpage/Discuz.html
15 |
16 | ### 安装说明
17 |
18 | 1. 下载插件([点击这里](https://github.com/upyun/discuz-plugin/archive/master.zip))放到 Discuz `source/plugin` 目录下,并重命名目录为 `upyun`
19 |
20 | 2. 进入 Discuz 应用管理,选择应用“UPYUN 云加速” 点击安装。
21 |
22 | 3. 安装成功后先启用插件,再点击左侧插件列表的“UPYUN 云加速”进行设置
23 |
24 | 填写设置前请阅读以下注意事项:
25 | * 访问域名需要填写与 UPYUN 空间绑定的域名,并且 http 前缀开头,也可以使用空间的默认域名
26 | * 防盗链 TOKEN 和防盗链过期时间必须要 UPYUN 访问域名和站点域名一致时,才能填写。否则 Cookie 跨域,会导致附件链接无法访问,出现 403 的情况。如果访问域名填写的是 UPYUN 空间的默认域名,则不能填写防盗链 TOKEN 和过期时间
27 | * 表单 API 强烈建议填写,否则无法使用分块上传。分块上传能够有效增加大文件上传的稳定性和速度。
28 |
29 | 4. 最后进入 Discuz 全局 -> 上传设置 -> 基本设置:开启远程附件,其他 ftp 参数不需要设置
30 |
31 | ### 常见问题
32 | 1. 安装时提示文件无法写入
33 | 只需按照提示,执行命令即可。(注意:该命令会让文件被所有用户可读写,用户也可以自行调整)
34 |
35 | 2. 安装时提示文件已经被修改,请手动安装
36 |
37 | 由于插件需要修改以下七个系统原文件
38 | * source/module/forum/forum_attachment.php
39 | * source/module/portal/portal_attachment.php
40 | * source/class/discuz/discuz_ftp.php
41 | * source/function/function_attachment.php
42 | * source/function/function_home.php
43 | * source/function/function_post.php
44 | * source/module/forum/forum_image.php
45 |
46 | 在安装时,插件会提前检查这个六个文件是否被修改,防止覆盖您的自定义修改。建议您将自定义修改的系统文件先备份,然后使用 Discuz 相应版本的原文件暂时代替完成安装(例如 Discuz 3.1 版本的原文件可以通过 source/plugin/upyun/discuz_3_1/uninstall/ 目录下获取。 uninstall 目录保存了各个版本的系统原文件)。文件还原后,重新安装即可。安装完成后,可以将您的自定义修改再追加到新的文件中。(如果卸载插件,该文件会被还原为 Discuz 原文件,所以卸载完成后需要重新追加本地修改)。
47 |
48 | 代码中标记了`Begin of Insert UPYUN Code`表示本插件修改追加的内容
49 |
50 |
--------------------------------------------------------------------------------
/check.php:
--------------------------------------------------------------------------------
1 | set_error(0);
40 | loadcache('plugin');
41 | $this->upyun_config = getglobal('cache/plugin/upyun');
42 | $paths = parse_url($this->upyun_config['url']);
43 | $this->upyun_dir = isset($paths['path']) ? rtrim($paths['path'], '/') . '/' : '/';
44 | $this->config = !$config ? getglobal('setting/ftp') : $config;
45 | $this->enabled = false;
46 | $this->config['host'] = discuz_ftp::clear($this->config['host']);
47 | $this->config['port'] = intval($this->config['port']);
48 | $this->config['ssl'] = intval($this->config['ssl']);
49 | $this->config['bucketname'] = $this->config['host'];
50 | $this->config['username'] = discuz_ftp::clear($this->config['username']);
51 | $this->config['password'] = authcode($this->config['password'], 'DECODE', md5(getglobal('config/security/authkey')));
52 | $this->config['timeout'] = intval($this->config['timeout']);
53 | $this->config['api_access'] = $this->api_access[$this->config['port']];
54 | $this->connectid = true;
55 | $this->enabled = true;
56 | }
57 |
58 | function upload($source, $target) {
59 | try {
60 | $file = new UpyunMultiPartFile($source);
61 | } catch (Exception $e) {
62 | return 0;
63 | }
64 | if($file->getSize() > 1024 * 1024 && $this->upyun_config['form_api_key']) {
65 | $sign = new UpyunMultipartSignature($this->upyun_config['form_api_key']);
66 | $upload = new UpyunMultipartUpload($sign);
67 | $upload->setBucketName($this->upyun_config['bucket_name']);
68 | $upload->setBlockSize($upload->getBlockSizeAdaptive($file));
69 | try {
70 | $result = $upload->upload($file, array(
71 | 'path' => $this->upyun_dir . ltrim($target, '/')
72 | ));
73 | return $result;
74 | } catch(Exception $e) {
75 | return 0;
76 | }
77 | } else {
78 | $fh = fopen($source, 'rb');
79 | if(!$fh) {
80 | return 0;
81 | }
82 | $upyun = new UpYun(
83 | $this->upyun_config['bucket_name'],
84 | $this->upyun_config['operator_name'],
85 | $this->upyun_config['operator_pwd']
86 | );
87 | $rsp = $upyun->writeFile($this->upyun_dir . ltrim($target, '/'), $fh, true);
88 | return $rsp;
89 | }
90 | }
91 |
92 | function connect() {
93 | return 1;
94 | }
95 |
96 | function set_error($code = 0) {
97 | $this->_error = $code;
98 | }
99 |
100 | function error() {
101 | return $this->_error;
102 | }
103 |
104 | function clear($str) {
105 | return str_replace(array( "\n", "\r", '..'), '', $str);
106 | }
107 |
108 | function ftp_rmdir($directory) {
109 | return 1;
110 | }
111 |
112 | function ftp_size($remote_file) {
113 | $upyun = new UpYun(
114 | $this->upyun_config['bucket_name'],
115 | $this->upyun_config['operator_name'],
116 | $this->upyun_config['operator_pwd']
117 | );
118 | $remote_file = discuz_ftp::clear($remote_file);
119 | try{
120 | $rsp = $upyun->getFileInfo($this->upyun_dir . ltrim($remote_file, '/'));
121 | return $rsp['x-upyun-file-size'];
122 | }
123 | catch(Exception $e){
124 | return -1;
125 | }
126 | }
127 |
128 | function ftp_close() {
129 | return 1;
130 | }
131 |
132 | function ftp_delete($path) {
133 | $upyun = new UpYun(
134 | $this->upyun_config['bucket_name'],
135 | $this->upyun_config['operator_name'],
136 | $this->upyun_config['operator_pwd']
137 | );
138 | $path = discuz_ftp::clear($path);
139 | try{
140 | $rsp = $upyun->delete($this->upyun_dir . ltrim($path, '/'));
141 | return $rsp;
142 | }
143 | catch(Exception $e){
144 | return 0;
145 | }
146 | }
147 |
148 | function ftp_get($local_file, $remote_file, $mode, $resumepos = 0) {
149 | $upyun = new UpYun(
150 | $this->upyun_config['bucket_name'],
151 | $this->upyun_config['operator_name'],
152 | $this->upyun_config['operator_pwd']
153 | );
154 | $remote_file = discuz_ftp::clear($remote_file);
155 | $local_file = discuz_ftp::clear($local_file);
156 | try{
157 | if($fh = fopen($local_file,'wb')){
158 | $rsp = $upyun->readFile($this->upyun_dir . ltrim($remote_file, '/'), $fh);
159 | fclose($fh);
160 | return $rsp;
161 | }else{
162 | return 0;
163 | }
164 | }
165 | catch(Exception $e){
166 | return 0;
167 | }
168 | }
169 |
170 | }
171 |
--------------------------------------------------------------------------------
/discuz_3_0/install/forum_image.php:
--------------------------------------------------------------------------------
1 | fetch('aid:'.$daid, $daid, array(1, -1))) {
36 | if(!$dw && !$dh && $attach['tid'] != $id) {
37 | dheader('location: '.$_G['siteurl'].'static/image/common/none.gif');
38 | }
39 | dheader('Expires: '.gmdate('D, d M Y H:i:s', TIMESTAMP + 3600).' GMT');
40 | if($attach['remote']) {
41 | $sign = upyun_gen_sign('/forum/'.$attach['attachment']);
42 | $filename = $_G['setting']['ftp']['attachurl'].'forum/'.$attach['attachment'] . '?_upt=' . $sign;
43 | } else {
44 | $filename = $_G['setting']['attachdir'].'forum/'.$attach['attachment'];
45 | }
46 | require_once libfile('class/image');
47 | $img = new image;
48 | if($img->Thumb($filename, $thumbfile, $w, $h, $type)) {
49 | if($nocache) {
50 | dheader('Content-Type: image');
51 | @readfile($_G['setting']['attachdir'].$thumbfile);
52 | @unlink($_G['setting']['attachdir'].$thumbfile);
53 | } else {
54 | dheader('location: '.$attachurl.$thumbfile);
55 | }
56 | } else {
57 | dheader('Content-Type: image');
58 | @readfile($filename);
59 | }
60 | }
61 |
62 | ?>
--------------------------------------------------------------------------------
/discuz_3_0/install/function_attachment.php:
--------------------------------------------------------------------------------
1 | 'unknown.gif',
18 | 2 => 'binary.gif',
19 | 3 => 'zip.gif',
20 | 4 => 'rar.gif',
21 | 5 => 'msoffice.gif',
22 | 6 => 'text.gif',
23 | 7 => 'html.gif',
24 | 8 => 'real.gif',
25 | 9 => 'av.gif',
26 | 10 => 'flash.gif',
27 | 11 => 'image.gif',
28 | 12 => 'pdf.gif',
29 | 13 => 'torrent.gif'
30 | );
31 |
32 | if(is_numeric($type)) {
33 | $typeid = $type;
34 | } else {
35 | if(preg_match("/bittorrent|^torrent\t/", $type)) {
36 | $typeid = 13;
37 | } elseif(preg_match("/pdf|^pdf\t/", $type)) {
38 | $typeid = 12;
39 | } elseif(preg_match("/image|^(jpg|gif|png|bmp)\t/", $type)) {
40 | $typeid = 11;
41 | } elseif(preg_match("/flash|^(swf|fla|flv|swi)\t/", $type)) {
42 | $typeid = 10;
43 | } elseif(preg_match("/audio|video|^(wav|mid|mp3|m3u|wma|asf|asx|vqf|mpg|mpeg|avi|wmv)\t/", $type)) {
44 | $typeid = 9;
45 | } elseif(preg_match("/real|^(ra|rm|rv)\t/", $type)) {
46 | $typeid = 8;
47 | } elseif(preg_match("/htm|^(php|js|pl|cgi|asp)\t/", $type)) {
48 | $typeid = 7;
49 | } elseif(preg_match("/text|^(txt|rtf|wri|chm)\t/", $type)) {
50 | $typeid = 6;
51 | } elseif(preg_match("/word|powerpoint|^(doc|ppt)\t/", $type)) {
52 | $typeid = 5;
53 | } elseif(preg_match("/^rar\t/", $type)) {
54 | $typeid = 4;
55 | } elseif(preg_match("/compressed|^(zip|arj|arc|cab|lzh|lha|tar|gz)\t/", $type)) {
56 | $typeid = 3;
57 | } elseif(preg_match("/octet-stream|^(exe|com|bat|dll)\t/", $type)) {
58 | $typeid = 2;
59 | } elseif($type) {
60 | $typeid = 1;
61 | } else {
62 | $typeid = 0;
63 | }
64 | }
65 | if($returnval == 'html') {
66 | return '
';
67 | } elseif($returnval == 'id') {
68 | return $typeid;
69 | }
70 | }
71 |
72 | function parseattach($attachpids, $attachtags, &$postlist, $skipaids = array()) {
73 | global $_G;
74 | if(!$attachpids) {
75 | return;
76 | }
77 | $attachpids = is_array($attachpids) ? $attachpids : array($attachpids);
78 | $attachexists = FALSE;
79 | $skipattachcode = $aids = $payaids = $findattach = array();
80 | foreach(C::t('forum_attachment_n')->fetch_all_by_id('tid:'.$_G['tid'], 'pid', $attachpids) as $attach) {
81 | $attachexists = TRUE;
82 | if($skipaids && in_array($attach['aid'], $skipaids)) {
83 | $skipattachcode[$attach[pid]][] = "/\[attach\]$attach[aid]\[\/attach\]/i";
84 | continue;
85 | }
86 | $attached = 0;
87 | $extension = strtolower(fileext($attach['filename']));
88 | $attach['ext'] = $extension;
89 | $attach['imgalt'] = $attach['isimage'] ? strip_tags(str_replace('"', '\"', $attach['description'] ? $attach['description'] : $attach['filename'])) : '';
90 | $attach['attachicon'] = attachtype($extension."\t".$attach['filetype']);
91 | $attach['attachsize'] = sizecount($attach['filesize']);
92 | if($attach['isimage'] && !$_G['setting']['attachimgpost']) {
93 | $attach['isimage'] = 0;
94 | }
95 | $attach['attachimg'] = $attach['isimage'] && (!$attach['readperm'] || $_G['group']['readaccess'] >= $attach['readperm']) ? 1 : 0;
96 | if($attach['attachimg']) {
97 | $GLOBALS['aimgs'][$attach['pid']][] = $attach['aid'];
98 | }
99 | if($attach['price']) {
100 | if($_G['setting']['maxchargespan'] && TIMESTAMP - $attach['dateline'] >= $_G['setting']['maxchargespan'] * 3600) {
101 | C::t('forum_attachment_n')->update('tid:'.$_G['tid'], $attach['aid'], array('price' => 0));
102 | $attach['price'] = 0;
103 | } elseif(!$_G['forum_attachmentdown'] && $_G['uid'] != $attach['uid']) {
104 | $payaids[$attach['aid']] = $attach['pid'];
105 | }
106 | }
107 | $attach['payed'] = $_G['forum_attachmentdown'] || $_G['uid'] == $attach['uid'] ? 1 : 0;
108 | // comment by UPYUN
109 | //$attach['url'] = ($attach['remote'] ? $_G['setting']['ftp']['attachurl'] : $_G['setting']['attachurl']).'forum/';
110 | //Begin Of Upyun Insert Code
111 | $upyun_url_prefix =rtrim($_G['cache']['plugin']['upyun']['url'], '/') . '/';
112 | $attach['url'] = ($attach['remote'] ? $upyun_url_prefix : $_G['setting']['attachurl']).'forum/';
113 | //End Of Upyun Insert Code
114 | $attach['dbdateline'] = $attach['dateline'];
115 | $attach['dateline'] = dgmdate($attach['dateline'], 'u');
116 | $postlist[$attach['pid']]['attachments'][$attach['aid']] = $attach;
117 | if(!defined('IN_MOBILE_API') && !empty($attachtags[$attach['pid']]) && is_array($attachtags[$attach['pid']]) && in_array($attach['aid'], $attachtags[$attach['pid']])) {
118 | $findattach[$attach['pid']][$attach['aid']] = "/\[attach\]$attach[aid]\[\/attach\]/i";
119 | $attached = 1;
120 | }
121 |
122 | if(!$attached) {
123 | if($attach['isimage']) {
124 | $postlist[$attach['pid']]['imagelist'][] = $attach['aid'];
125 | $postlist[$attach['pid']]['imagelistcount']++;
126 | if($postlist[$attach['pid']]['first']) {
127 | $GLOBALS['firstimgs'][] = $attach['aid'];
128 | }
129 | } else {
130 | if(!$_G['forum_skipaidlist'] || !in_array($attach['aid'], $_G['forum_skipaidlist'])) {
131 | $postlist[$attach['pid']]['attachlist'][] = $attach['aid'];
132 | }
133 | }
134 | }
135 | $aids[] = $attach['aid'];
136 | }
137 | if($aids) {
138 | $attachs = C::t('forum_attachment')->fetch_all($aids);
139 | foreach($attachs as $aid => $attach) {
140 | if($postlist[$attach['pid']]) {
141 | $postlist[$attach['pid']]['attachments'][$attach['aid']]['downloads'] = $attach['downloads'];
142 | }
143 | }
144 | }
145 | if($payaids) {
146 | foreach(C::t('common_credit_log')->fetch_all_by_uid_operation_relatedid($_G['uid'], 'BAC', array_keys($payaids)) as $creditlog) {
147 | $postlist[$payaids[$creditlog['relatedid']]]['attachments'][$creditlog['relatedid']]['payed'] = 1;
148 | }
149 | }
150 | if(!empty($skipattachcode)) {
151 | foreach($skipattachcode as $pid => $findskipattach) {
152 | foreach($findskipattach as $findskip) {
153 | $postlist[$pid]['message'] = preg_replace($findskip, '', $postlist[$pid]['message']);
154 | }
155 | }
156 | }
157 |
158 | if($attachexists) {
159 | foreach($attachtags as $pid => $aids) {
160 | if($findattach[$pid]) {
161 | foreach($findattach[$pid] as $aid => $find) {
162 | $postlist[$pid]['message'] = preg_replace($find, attachinpost($postlist[$pid]['attachments'][$aid], $postlist[$pid]), $postlist[$pid]['message'], 1);
163 | $postlist[$pid]['message'] = preg_replace($find, '', $postlist[$pid]['message']);
164 | }
165 | }
166 | }
167 | } else {
168 | loadcache('posttableids');
169 | $posttableids = $_G['cache']['posttableids'] ? $_G['cache']['posttableids'] : array('0');
170 | foreach($posttableids as $id) {
171 | C::t('forum_post')->update($id, $attachpids, array('attachment' => '0'), true);
172 | }
173 | }
174 | }
175 |
176 | function attachwidth($width) {
177 | global $_G;
178 | if($_G['setting']['imagemaxwidth'] && $width) {
179 | return 'class="zoom" onclick="zoom(this, this.src, 0, 0, '.($_G['setting']['showexif'] ? 1 : 0).')" width="'.($width > $_G['setting']['imagemaxwidth'] ? $_G['setting']['imagemaxwidth'] : $width).'"';
180 | } else {
181 | return 'thumbImg="1"';
182 | }
183 | }
184 |
185 | function packaids($attach) {
186 | global $_G;
187 | return aidencode($attach['aid'], 0, $_G['tid']);
188 | }
189 |
190 | function showattach($post, $type = 0) {
191 | $type = !$type ? 'attachlist' : 'imagelist';
192 | $return = '';
193 | if(!empty($post[$type]) && is_array($post[$type])) {
194 | foreach($post[$type] as $aid) {
195 | if(!empty($post['attachments'][$aid])) {
196 | $return .= $type($post['attachments'][$aid], $post['first']);
197 | }
198 | }
199 | }
200 | return $return;
201 | }
202 |
203 | function getattachexif($aid, $path = '') {
204 | global $_G;
205 | $return = $filename = '';
206 | if(!$path) {
207 | if($attach = C::t('forum_attachment_n')->fetch('aid:'.$aid, $aid, array(1, -1))) {
208 | if($attach['remote']) {
209 | $filename = $_G['setting']['ftp']['attachurl'].'forum/'.$attach['attachment'];
210 | } else {
211 | $filename = $_G['setting']['attachdir'].'forum/'.$attach['attachment'];
212 | }
213 | }
214 | } else {
215 | $filename = $path;
216 | }
217 | if($filename) {
218 | require_once libfile('function/exif');
219 | $exif = getexif($filename);
220 | $keys = array(
221 | exif_lang('Model'),
222 | exif_lang('ShutterSpeedValue'),
223 | exif_lang('ApertureValue'),
224 | exif_lang('FocalLength'),
225 | exif_lang('ExposureTime'),
226 | exif_lang('DateTimeOriginal'),
227 | exif_lang('ISOSpeedRatings'),
228 | );
229 | foreach($exif as $key => $value) {
230 | if(in_array($key, $keys)) {
231 | $return .= "$key : $value
";
232 | }
233 | }
234 | }
235 | return $return;
236 | }
237 |
238 | ?>
--------------------------------------------------------------------------------
/discuz_3_0/install/portal_attachment.php:
--------------------------------------------------------------------------------
1 | fetch($id);
18 | if(empty($attach)) {
19 | showmessage('portal_attachment_noexist');
20 | }
21 |
22 | if($operation == 'delete') {
23 | if(!$_G['group']['allowmanagearticle'] && $_G['uid'] != $attach['uid']) {
24 | showmessage('portal_attachment_nopermission_delete');
25 | }
26 | if($aid) {
27 | C::t('portal_article_title')->update($aid, array('pic' => ''));
28 | }
29 | C::t('portal_attachment')->delete($id);
30 | pic_delete($attach['attachment'], 'portal', $attach['thumb'], $attach['remote']);
31 | showmessage('portal_image_noexist');
32 |
33 | } elseif($operation == 'getattach') {
34 |
35 | require_once libfile('function/attachment');
36 | if($attach['isimage']) {
37 | require_once libfile('function/home');
38 | $smallimg = pic_get($attach['attachment'], 'portal', $attach['thumb'], $attach['remote']);
39 | $bigimg = pic_get($attach['attachment'], 'portal', 0, $attach['remote']);
40 | $coverstr = addslashes(serialize(array('pic'=>'portal/'.$attach['attachment'], 'thumb'=>$attach['thumb'], 'remote'=>$attach['remote'])));
41 | }
42 | $attach['filetype'] = attachtype($attach['filetype']."\t".$attach['filetype']);
43 | $attach['filesize'] = sizecount($attach['filesize']);
44 | include template('portal/portal_attachment');
45 |
46 | exit;
47 |
48 | } else {
49 | $filename = $_G['setting']['attachdir'].'/portal/'.$attach['attachment'];
50 | if(!$attach['remote'] && !is_readable($filename)) {
51 | showmessage('attachment_nonexistence');
52 | }
53 |
54 | $readmod = 2;//read local file's function: 1=fread 2=readfile 3=fpassthru 4=fpassthru+multiple
55 | $range = 0;
56 | if($readmod == 4 && !empty($_SERVER['HTTP_RANGE'])) {
57 | list($range) = explode('-',(str_replace('bytes=', '', $_SERVER['HTTP_RANGE'])));
58 | }
59 |
60 | //Begin Of Upyun Insert Code
61 | include_once DISCUZ_ROOT . 'source/plugin/upyun/function_upyun.php';
62 | upyun_attachment_download($attach, 'portal');
63 | //End Of Upyun Insert Code
64 |
65 | $filesize = $attach['filesize'];
66 | $attach['filename'] = '"'.(strtolower(CHARSET) == 'utf-8' && strexists($_SERVER['HTTP_USER_AGENT'], 'MSIE') ? urlencode($attach['filename']) : $attach['filename']).'"';
67 |
68 | dheader('Date: '.gmdate('D, d M Y H:i:s', $attach['dateline']).' GMT');
69 | dheader('Last-Modified: '.gmdate('D, d M Y H:i:s', $attach['dateline']).' GMT');
70 | dheader('Content-Encoding: none');
71 | dheader('Content-Disposition: attachment; filename='.$attach['filename']);
72 | dheader('Content-Type: '.$attach['filetype']);
73 | dheader('Content-Length: '.$filesize);
74 |
75 | if($readmod == 4) {
76 | dheader('Accept-Ranges: bytes');
77 | if(!empty($_SERVER['HTTP_RANGE'])) {
78 | $rangesize = ($filesize - $range) > 0 ? ($filesize - $range) : 0;
79 | dheader('Content-Length: '.$rangesize);
80 | dheader('HTTP/1.1 206 Partial Content');
81 | dheader('Content-Range: bytes='.$range.'-'.($filesize-1).'/'.($filesize));
82 | }
83 | }
84 |
85 | $attach['remote'] ? getremotefile($attach['attachment']) : getlocalfile($filename, $readmod, $range);
86 | }
87 | function getremotefile($file) {
88 | global $_G;
89 | @set_time_limit(0);
90 | if(!@readfile($_G['setting']['ftp']['attachurl'].'portal/'.$file)) {
91 |
92 | $ftp = new discuz_ftp();
93 | if(!($_G['setting']['ftp']['connid'] = $ftp->connect())) {
94 | return FALSE;
95 | }
96 | $tmpfile = @tempnam($_G['setting']['attachdir'], '');
97 | if($ftp->ftp_get($_G['setting']['ftp']['connid'], $tmpfile, $file, FTP_BINARY)) {
98 | @readfile($tmpfile);
99 | @unlink($tmpfile);
100 | } else {
101 | @unlink($tmpfile);
102 | return FALSE;
103 | }
104 | }
105 | return TRUE;
106 | }
107 |
108 | function getlocalfile($filename, $readmod = 2, $range = 0) {
109 | if($readmod == 1 || $readmod == 3 || $readmod == 4) {
110 | if($fp = @fopen($filename, 'rb')) {
111 | @fseek($fp, $range);
112 | if(function_exists('fpassthru') && ($readmod == 3 || $readmod == 4)) {
113 | @fpassthru($fp);
114 | } else {
115 | echo @fread($fp, filesize($filename));
116 | }
117 | }
118 | @fclose($fp);
119 | } else {
120 | @readfile($filename);
121 | }
122 | @flush();
123 | @ob_flush();
124 | }
125 |
126 | ?>
--------------------------------------------------------------------------------
/discuz_3_0/uninstall/discuz_ftp.php:
--------------------------------------------------------------------------------
1 | set_error(0);
47 | $this->config = !$config ? getglobal('setting/ftp') : $config;
48 | $this->enabled = false;
49 | if(empty($this->config['on']) || empty($this->config['host'])) {
50 | $this->set_error(FTP_ERR_CONFIG_OFF);
51 | } else {
52 | $this->func = $this->config['ssl'] && function_exists('ftp_ssl_connect') ? 'ftp_ssl_connect' : 'ftp_connect';
53 | if($this->func == 'ftp_connect' && !function_exists('ftp_connect')) {
54 | $this->set_error(FTP_ERR_SERVER_DISABLED);
55 | } else {
56 | $this->config['host'] = discuz_ftp::clear($this->config['host']);
57 | $this->config['port'] = intval($this->config['port']);
58 | $this->config['ssl'] = intval($this->config['ssl']);
59 | $this->config['username'] = discuz_ftp::clear($this->config['username']);
60 | $this->config['password'] = authcode($this->config['password'], 'DECODE', md5(getglobal('config/security/authkey')));
61 | $this->config['timeout'] = intval($this->config['timeout']);
62 | $this->enabled = true;
63 | }
64 | }
65 | }
66 |
67 | function upload($source, $target) {
68 | if($this->error()) {
69 | return 0;
70 | }
71 | $old_dir = $this->ftp_pwd();
72 | $dirname = dirname($target);
73 | $filename = basename($target);
74 | if(!$this->ftp_chdir($dirname)) {
75 | if($this->ftp_mkdir($dirname)) {
76 | $this->ftp_chmod($dirname);
77 | if(!$this->ftp_chdir($dirname)) {
78 | $this->set_error(FTP_ERR_CHDIR);
79 | }
80 | $this->ftp_put('index.htm', getglobal('setting/attachdir').'/index.htm', FTP_BINARY);
81 | } else {
82 | $this->set_error(FTP_ERR_MKDIR);
83 | }
84 | }
85 |
86 | $res = 0;
87 | if(!$this->error()) {
88 | if($fp = @fopen($source, 'rb')) {
89 | $res = $this->ftp_fput($filename, $fp, FTP_BINARY);
90 | @fclose($fp);
91 | !$res && $this->set_error(FTP_ERR_TARGET_WRITE);
92 | } else {
93 | $this->set_error(FTP_ERR_SOURCE_READ);
94 | }
95 | }
96 |
97 | $this->ftp_chdir($old_dir);
98 |
99 | return $res ? 1 : 0;
100 | }
101 |
102 | function connect() {
103 | if(!$this->enabled || empty($this->config)) {
104 | return 0;
105 | } else {
106 | return $this->ftp_connect(
107 | $this->config['host'],
108 | $this->config['username'],
109 | $this->config['password'],
110 | $this->config['attachdir'],
111 | $this->config['port'],
112 | $this->config['timeout'],
113 | $this->config['ssl'],
114 | $this->config['pasv']
115 | );
116 | }
117 |
118 | }
119 |
120 | function ftp_connect($ftphost, $username, $password, $ftppath, $ftpport = 21, $timeout = 30, $ftpssl = 0, $ftppasv = 0) {
121 | $res = 0;
122 | $fun = $this->func;
123 | if($this->connectid = $fun($ftphost, $ftpport, 20)) {
124 |
125 | $timeout && $this->set_option(FTP_TIMEOUT_SEC, $timeout);
126 | if($this->ftp_login($username, $password)) {
127 | $this->ftp_pasv($ftppasv);
128 | if($this->ftp_chdir($ftppath)) {
129 | $res = $this->connectid;
130 | } else {
131 | $this->set_error(FTP_ERR_CHDIR);
132 | }
133 | } else {
134 | $this->set_error(FTP_ERR_USER_NO_LOGGIN);
135 | }
136 |
137 | } else {
138 | $this->set_error(FTP_ERR_CONNECT_TO_SERVER);
139 | }
140 |
141 | if($res > 0) {
142 | $this->set_error();
143 | $this->enabled = 1;
144 | } else {
145 | $this->enabled = 0;
146 | $this->ftp_close();
147 | }
148 |
149 | return $res;
150 |
151 | }
152 |
153 | function set_error($code = 0) {
154 | $this->_error = $code;
155 | }
156 |
157 | function error() {
158 | return $this->_error;
159 | }
160 |
161 | function clear($str) {
162 | return str_replace(array( "\n", "\r", '..'), '', $str);
163 | }
164 |
165 |
166 | function set_option($cmd, $value) {
167 | if(function_exists('ftp_set_option')) {
168 | return @ftp_set_option($this->connectid, $cmd, $value);
169 | }
170 | }
171 |
172 | function ftp_mkdir($directory) {
173 | $directory = discuz_ftp::clear($directory);
174 | $epath = explode('/', $directory);
175 | $dir = '';$comma = '';
176 | foreach($epath as $path) {
177 | $dir .= $comma.$path;
178 | $comma = '/';
179 | $return = @ftp_mkdir($this->connectid, $dir);
180 | $this->ftp_chmod($dir);
181 | }
182 | return $return;
183 | }
184 |
185 | function ftp_rmdir($directory) {
186 | $directory = discuz_ftp::clear($directory);
187 | return @ftp_rmdir($this->connectid, $directory);
188 | }
189 |
190 | function ftp_put($remote_file, $local_file, $mode = FTP_BINARY) {
191 | $remote_file = discuz_ftp::clear($remote_file);
192 | $local_file = discuz_ftp::clear($local_file);
193 | $mode = intval($mode);
194 | return @ftp_put($this->connectid, $remote_file, $local_file, $mode);
195 | }
196 |
197 | function ftp_fput($remote_file, $sourcefp, $mode = FTP_BINARY) {
198 | $remote_file = discuz_ftp::clear($remote_file);
199 | $mode = intval($mode);
200 | return @ftp_fput($this->connectid, $remote_file, $sourcefp, $mode);
201 | }
202 |
203 | function ftp_size($remote_file) {
204 | $remote_file = discuz_ftp::clear($remote_file);
205 | return @ftp_size($this->connectid, $remote_file);
206 | }
207 |
208 | function ftp_close() {
209 | return @ftp_close($this->connectid);
210 | }
211 |
212 | function ftp_delete($path) {
213 | $path = discuz_ftp::clear($path);
214 | return @ftp_delete($this->connectid, $path);
215 | }
216 |
217 | function ftp_get($local_file, $remote_file, $mode, $resumepos = 0) {
218 | $remote_file = discuz_ftp::clear($remote_file);
219 | $local_file = discuz_ftp::clear($local_file);
220 | $mode = intval($mode);
221 | $resumepos = intval($resumepos);
222 | return @ftp_get($this->connectid, $local_file, $remote_file, $mode, $resumepos);
223 | }
224 |
225 | function ftp_login($username, $password) {
226 | $username = $this->clear($username);
227 | $password = str_replace(array("\n", "\r"), array('', ''), $password);
228 | return @ftp_login($this->connectid, $username, $password);
229 | }
230 |
231 | function ftp_pasv($pasv) {
232 | return @ftp_pasv($this->connectid, $pasv ? true : false);
233 | }
234 |
235 | function ftp_chdir($directory) {
236 | $directory = discuz_ftp::clear($directory);
237 | return @ftp_chdir($this->connectid, $directory);
238 | }
239 |
240 | function ftp_site($cmd) {
241 | $cmd = discuz_ftp::clear($cmd);
242 | return @ftp_site($this->connectid, $cmd);
243 | }
244 |
245 | function ftp_chmod($filename, $mod = 0777) {
246 | $filename = discuz_ftp::clear($filename);
247 | if(function_exists('ftp_chmod')) {
248 | return @ftp_chmod($this->connectid, $mod, $filename);
249 | } else {
250 | return @ftp_site($this->connectid, 'CHMOD '.$mod.' '.$filename);
251 | }
252 | }
253 |
254 | function ftp_pwd() {
255 | return @ftp_pwd($this->connectid);
256 | }
257 |
258 | }
--------------------------------------------------------------------------------
/discuz_3_0/uninstall/forum_image.php:
--------------------------------------------------------------------------------
1 | fetch('aid:'.$daid, $daid, array(1, -1))) {
36 | if(!$dw && !$dh && $attach['tid'] != $id) {
37 | dheader('location: '.$_G['siteurl'].'static/image/common/none.gif');
38 | }
39 | dheader('Expires: '.gmdate('D, d M Y H:i:s', TIMESTAMP + 3600).' GMT');
40 | if($attach['remote']) {
41 | $filename = $_G['setting']['ftp']['attachurl'].'forum/'.$attach['attachment'];
42 | } else {
43 | $filename = $_G['setting']['attachdir'].'forum/'.$attach['attachment'];
44 | }
45 | require_once libfile('class/image');
46 | $img = new image;
47 | if($img->Thumb($filename, $thumbfile, $w, $h, $type)) {
48 | if($nocache) {
49 | dheader('Content-Type: image');
50 | @readfile($_G['setting']['attachdir'].$thumbfile);
51 | @unlink($_G['setting']['attachdir'].$thumbfile);
52 | } else {
53 | dheader('location: '.$attachurl.$thumbfile);
54 | }
55 | } else {
56 | dheader('Content-Type: image');
57 | @readfile($filename);
58 | }
59 | }
60 |
61 | ?>
--------------------------------------------------------------------------------
/discuz_3_0/uninstall/function_attachment.php:
--------------------------------------------------------------------------------
1 | 'unknown.gif',
18 | 2 => 'binary.gif',
19 | 3 => 'zip.gif',
20 | 4 => 'rar.gif',
21 | 5 => 'msoffice.gif',
22 | 6 => 'text.gif',
23 | 7 => 'html.gif',
24 | 8 => 'real.gif',
25 | 9 => 'av.gif',
26 | 10 => 'flash.gif',
27 | 11 => 'image.gif',
28 | 12 => 'pdf.gif',
29 | 13 => 'torrent.gif'
30 | );
31 |
32 | if(is_numeric($type)) {
33 | $typeid = $type;
34 | } else {
35 | if(preg_match("/bittorrent|^torrent\t/", $type)) {
36 | $typeid = 13;
37 | } elseif(preg_match("/pdf|^pdf\t/", $type)) {
38 | $typeid = 12;
39 | } elseif(preg_match("/image|^(jpg|gif|png|bmp)\t/", $type)) {
40 | $typeid = 11;
41 | } elseif(preg_match("/flash|^(swf|fla|flv|swi)\t/", $type)) {
42 | $typeid = 10;
43 | } elseif(preg_match("/audio|video|^(wav|mid|mp3|m3u|wma|asf|asx|vqf|mpg|mpeg|avi|wmv)\t/", $type)) {
44 | $typeid = 9;
45 | } elseif(preg_match("/real|^(ra|rm|rv)\t/", $type)) {
46 | $typeid = 8;
47 | } elseif(preg_match("/htm|^(php|js|pl|cgi|asp)\t/", $type)) {
48 | $typeid = 7;
49 | } elseif(preg_match("/text|^(txt|rtf|wri|chm)\t/", $type)) {
50 | $typeid = 6;
51 | } elseif(preg_match("/word|powerpoint|^(doc|ppt)\t/", $type)) {
52 | $typeid = 5;
53 | } elseif(preg_match("/^rar\t/", $type)) {
54 | $typeid = 4;
55 | } elseif(preg_match("/compressed|^(zip|arj|arc|cab|lzh|lha|tar|gz)\t/", $type)) {
56 | $typeid = 3;
57 | } elseif(preg_match("/octet-stream|^(exe|com|bat|dll)\t/", $type)) {
58 | $typeid = 2;
59 | } elseif($type) {
60 | $typeid = 1;
61 | } else {
62 | $typeid = 0;
63 | }
64 | }
65 | if($returnval == 'html') {
66 | return '
';
67 | } elseif($returnval == 'id') {
68 | return $typeid;
69 | }
70 | }
71 |
72 | function parseattach($attachpids, $attachtags, &$postlist, $skipaids = array()) {
73 | global $_G;
74 | if(!$attachpids) {
75 | return;
76 | }
77 | $attachpids = is_array($attachpids) ? $attachpids : array($attachpids);
78 | $attachexists = FALSE;
79 | $skipattachcode = $aids = $payaids = $findattach = array();
80 | foreach(C::t('forum_attachment_n')->fetch_all_by_id('tid:'.$_G['tid'], 'pid', $attachpids) as $attach) {
81 | $attachexists = TRUE;
82 | if($skipaids && in_array($attach['aid'], $skipaids)) {
83 | $skipattachcode[$attach[pid]][] = "/\[attach\]$attach[aid]\[\/attach\]/i";
84 | continue;
85 | }
86 | $attached = 0;
87 | $extension = strtolower(fileext($attach['filename']));
88 | $attach['ext'] = $extension;
89 | $attach['imgalt'] = $attach['isimage'] ? strip_tags(str_replace('"', '\"', $attach['description'] ? $attach['description'] : $attach['filename'])) : '';
90 | $attach['attachicon'] = attachtype($extension."\t".$attach['filetype']);
91 | $attach['attachsize'] = sizecount($attach['filesize']);
92 | if($attach['isimage'] && !$_G['setting']['attachimgpost']) {
93 | $attach['isimage'] = 0;
94 | }
95 | $attach['attachimg'] = $attach['isimage'] && (!$attach['readperm'] || $_G['group']['readaccess'] >= $attach['readperm']) ? 1 : 0;
96 | if($attach['attachimg']) {
97 | $GLOBALS['aimgs'][$attach['pid']][] = $attach['aid'];
98 | }
99 | if($attach['price']) {
100 | if($_G['setting']['maxchargespan'] && TIMESTAMP - $attach['dateline'] >= $_G['setting']['maxchargespan'] * 3600) {
101 | C::t('forum_attachment_n')->update('tid:'.$_G['tid'], $attach['aid'], array('price' => 0));
102 | $attach['price'] = 0;
103 | } elseif(!$_G['forum_attachmentdown'] && $_G['uid'] != $attach['uid']) {
104 | $payaids[$attach['aid']] = $attach['pid'];
105 | }
106 | }
107 | $attach['payed'] = $_G['forum_attachmentdown'] || $_G['uid'] == $attach['uid'] ? 1 : 0;
108 | $attach['url'] = ($attach['remote'] ? $_G['setting']['ftp']['attachurl'] : $_G['setting']['attachurl']).'forum/';
109 | $attach['dbdateline'] = $attach['dateline'];
110 | $attach['dateline'] = dgmdate($attach['dateline'], 'u');
111 | $postlist[$attach['pid']]['attachments'][$attach['aid']] = $attach;
112 | if(!defined('IN_MOBILE_API') && !empty($attachtags[$attach['pid']]) && is_array($attachtags[$attach['pid']]) && in_array($attach['aid'], $attachtags[$attach['pid']])) {
113 | $findattach[$attach['pid']][$attach['aid']] = "/\[attach\]$attach[aid]\[\/attach\]/i";
114 | $attached = 1;
115 | }
116 |
117 | if(!$attached) {
118 | if($attach['isimage']) {
119 | $postlist[$attach['pid']]['imagelist'][] = $attach['aid'];
120 | $postlist[$attach['pid']]['imagelistcount']++;
121 | if($postlist[$attach['pid']]['first']) {
122 | $GLOBALS['firstimgs'][] = $attach['aid'];
123 | }
124 | } else {
125 | if(!$_G['forum_skipaidlist'] || !in_array($attach['aid'], $_G['forum_skipaidlist'])) {
126 | $postlist[$attach['pid']]['attachlist'][] = $attach['aid'];
127 | }
128 | }
129 | }
130 | $aids[] = $attach['aid'];
131 | }
132 | if($aids) {
133 | $attachs = C::t('forum_attachment')->fetch_all($aids);
134 | foreach($attachs as $aid => $attach) {
135 | if($postlist[$attach['pid']]) {
136 | $postlist[$attach['pid']]['attachments'][$attach['aid']]['downloads'] = $attach['downloads'];
137 | }
138 | }
139 | }
140 | if($payaids) {
141 | foreach(C::t('common_credit_log')->fetch_all_by_uid_operation_relatedid($_G['uid'], 'BAC', array_keys($payaids)) as $creditlog) {
142 | $postlist[$payaids[$creditlog['relatedid']]]['attachments'][$creditlog['relatedid']]['payed'] = 1;
143 | }
144 | }
145 | if(!empty($skipattachcode)) {
146 | foreach($skipattachcode as $pid => $findskipattach) {
147 | foreach($findskipattach as $findskip) {
148 | $postlist[$pid]['message'] = preg_replace($findskip, '', $postlist[$pid]['message']);
149 | }
150 | }
151 | }
152 |
153 | if($attachexists) {
154 | foreach($attachtags as $pid => $aids) {
155 | if($findattach[$pid]) {
156 | foreach($findattach[$pid] as $aid => $find) {
157 | $postlist[$pid]['message'] = preg_replace($find, attachinpost($postlist[$pid]['attachments'][$aid], $postlist[$pid]), $postlist[$pid]['message'], 1);
158 | $postlist[$pid]['message'] = preg_replace($find, '', $postlist[$pid]['message']);
159 | }
160 | }
161 | }
162 | } else {
163 | loadcache('posttableids');
164 | $posttableids = $_G['cache']['posttableids'] ? $_G['cache']['posttableids'] : array('0');
165 | foreach($posttableids as $id) {
166 | C::t('forum_post')->update($id, $attachpids, array('attachment' => '0'), true);
167 | }
168 | }
169 | }
170 |
171 | function attachwidth($width) {
172 | global $_G;
173 | if($_G['setting']['imagemaxwidth'] && $width) {
174 | return 'class="zoom" onclick="zoom(this, this.src, 0, 0, '.($_G['setting']['showexif'] ? 1 : 0).')" width="'.($width > $_G['setting']['imagemaxwidth'] ? $_G['setting']['imagemaxwidth'] : $width).'"';
175 | } else {
176 | return 'thumbImg="1"';
177 | }
178 | }
179 |
180 | function packaids($attach) {
181 | global $_G;
182 | return aidencode($attach['aid'], 0, $_G['tid']);
183 | }
184 |
185 | function showattach($post, $type = 0) {
186 | $type = !$type ? 'attachlist' : 'imagelist';
187 | $return = '';
188 | if(!empty($post[$type]) && is_array($post[$type])) {
189 | foreach($post[$type] as $aid) {
190 | if(!empty($post['attachments'][$aid])) {
191 | $return .= $type($post['attachments'][$aid], $post['first']);
192 | }
193 | }
194 | }
195 | return $return;
196 | }
197 |
198 | function getattachexif($aid, $path = '') {
199 | global $_G;
200 | $return = $filename = '';
201 | if(!$path) {
202 | if($attach = C::t('forum_attachment_n')->fetch('aid:'.$aid, $aid, array(1, -1))) {
203 | if($attach['remote']) {
204 | $filename = $_G['setting']['ftp']['attachurl'].'forum/'.$attach['attachment'];
205 | } else {
206 | $filename = $_G['setting']['attachdir'].'forum/'.$attach['attachment'];
207 | }
208 | }
209 | } else {
210 | $filename = $path;
211 | }
212 | if($filename) {
213 | require_once libfile('function/exif');
214 | $exif = getexif($filename);
215 | $keys = array(
216 | exif_lang('Model'),
217 | exif_lang('ShutterSpeedValue'),
218 | exif_lang('ApertureValue'),
219 | exif_lang('FocalLength'),
220 | exif_lang('ExposureTime'),
221 | exif_lang('DateTimeOriginal'),
222 | exif_lang('ISOSpeedRatings'),
223 | );
224 | foreach($exif as $key => $value) {
225 | if(in_array($key, $keys)) {
226 | $return .= "$key : $value
";
227 | }
228 | }
229 | }
230 | return $return;
231 | }
232 |
233 | ?>
--------------------------------------------------------------------------------
/discuz_3_0/uninstall/portal_attachment.php:
--------------------------------------------------------------------------------
1 | fetch($id);
18 | if(empty($attach)) {
19 | showmessage('portal_attachment_noexist');
20 | }
21 |
22 | if($operation == 'delete') {
23 | if(!$_G['group']['allowmanagearticle'] && $_G['uid'] != $attach['uid']) {
24 | showmessage('portal_attachment_nopermission_delete');
25 | }
26 | if($aid) {
27 | C::t('portal_article_title')->update($aid, array('pic' => ''));
28 | }
29 | C::t('portal_attachment')->delete($id);
30 | pic_delete($attach['attachment'], 'portal', $attach['thumb'], $attach['remote']);
31 | showmessage('portal_image_noexist');
32 |
33 | } elseif($operation == 'getattach') {
34 |
35 | require_once libfile('function/attachment');
36 | if($attach['isimage']) {
37 | require_once libfile('function/home');
38 | $smallimg = pic_get($attach['attachment'], 'portal', $attach['thumb'], $attach['remote']);
39 | $bigimg = pic_get($attach['attachment'], 'portal', 0, $attach['remote']);
40 | $coverstr = addslashes(serialize(array('pic'=>'portal/'.$attach['attachment'], 'thumb'=>$attach['thumb'], 'remote'=>$attach['remote'])));
41 | }
42 | $attach['filetype'] = attachtype($attach['filetype']."\t".$attach['filetype']);
43 | $attach['filesize'] = sizecount($attach['filesize']);
44 | include template('portal/portal_attachment');
45 |
46 | exit;
47 |
48 | } else {
49 | $filename = $_G['setting']['attachdir'].'/portal/'.$attach['attachment'];
50 | if(!$attach['remote'] && !is_readable($filename)) {
51 | showmessage('attachment_nonexistence');
52 | }
53 |
54 | $readmod = 2;//read local file's function: 1=fread 2=readfile 3=fpassthru 4=fpassthru+multiple
55 | $range = 0;
56 | if($readmod == 4 && !empty($_SERVER['HTTP_RANGE'])) {
57 | list($range) = explode('-',(str_replace('bytes=', '', $_SERVER['HTTP_RANGE'])));
58 | }
59 |
60 | if($attach['remote'] && !$_G['setting']['ftp']['hideurl'] && $attach['isimage']) {
61 | dheader('location:'.$_G['setting']['ftp']['attachurl'].'portal/'.$attach['attachment']);
62 | }
63 |
64 | $filesize = $attach['filesize'];
65 | $attach['filename'] = '"'.(strtolower(CHARSET) == 'utf-8' && strexists($_SERVER['HTTP_USER_AGENT'], 'MSIE') ? urlencode($attach['filename']) : $attach['filename']).'"';
66 |
67 | dheader('Date: '.gmdate('D, d M Y H:i:s', $attach['dateline']).' GMT');
68 | dheader('Last-Modified: '.gmdate('D, d M Y H:i:s', $attach['dateline']).' GMT');
69 | dheader('Content-Encoding: none');
70 | dheader('Content-Disposition: attachment; filename='.$attach['filename']);
71 | dheader('Content-Type: '.$attach['filetype']);
72 | dheader('Content-Length: '.$filesize);
73 |
74 | if($readmod == 4) {
75 | dheader('Accept-Ranges: bytes');
76 | if(!empty($_SERVER['HTTP_RANGE'])) {
77 | $rangesize = ($filesize - $range) > 0 ? ($filesize - $range) : 0;
78 | dheader('Content-Length: '.$rangesize);
79 | dheader('HTTP/1.1 206 Partial Content');
80 | dheader('Content-Range: bytes='.$range.'-'.($filesize-1).'/'.($filesize));
81 | }
82 | }
83 |
84 | $attach['remote'] ? getremotefile($attach['attachment']) : getlocalfile($filename, $readmod, $range);
85 | }
86 | function getremotefile($file) {
87 | global $_G;
88 | @set_time_limit(0);
89 | if(!@readfile($_G['setting']['ftp']['attachurl'].'portal/'.$file)) {
90 |
91 | $ftp = new discuz_ftp();
92 | if(!($_G['setting']['ftp']['connid'] = $ftp->connect())) {
93 | return FALSE;
94 | }
95 | $tmpfile = @tempnam($_G['setting']['attachdir'], '');
96 | if($ftp->ftp_get($_G['setting']['ftp']['connid'], $tmpfile, $file, FTP_BINARY)) {
97 | @readfile($tmpfile);
98 | @unlink($tmpfile);
99 | } else {
100 | @unlink($tmpfile);
101 | return FALSE;
102 | }
103 | }
104 | return TRUE;
105 | }
106 |
107 | function getlocalfile($filename, $readmod = 2, $range = 0) {
108 | if($readmod == 1 || $readmod == 3 || $readmod == 4) {
109 | if($fp = @fopen($filename, 'rb')) {
110 | @fseek($fp, $range);
111 | if(function_exists('fpassthru') && ($readmod == 3 || $readmod == 4)) {
112 | @fpassthru($fp);
113 | } else {
114 | echo @fread($fp, filesize($filename));
115 | }
116 | }
117 | @fclose($fp);
118 | } else {
119 | @readfile($filename);
120 | }
121 | @flush();
122 | @ob_flush();
123 | }
124 |
125 | ?>
--------------------------------------------------------------------------------
/discuz_3_1/install/discuz_ftp.php:
--------------------------------------------------------------------------------
1 | set_error(0);
40 | loadcache('plugin');
41 | $this->upyun_config = getglobal('cache/plugin/upyun');
42 | $paths = parse_url($this->upyun_config['url']);
43 | $this->upyun_dir = isset($paths['path']) ? rtrim($paths['path'], '/') . '/' : '/';
44 | $this->config = !$config ? getglobal('setting/ftp') : $config;
45 | $this->enabled = false;
46 | $this->config['host'] = discuz_ftp::clear($this->config['host']);
47 | $this->config['port'] = intval($this->config['port']);
48 | $this->config['ssl'] = intval($this->config['ssl']);
49 | $this->config['bucketname'] = $this->config['host'];
50 | $this->config['username'] = discuz_ftp::clear($this->config['username']);
51 | $this->config['password'] = authcode($this->config['password'], 'DECODE', md5(getglobal('config/security/authkey')));
52 | $this->config['timeout'] = intval($this->config['timeout']);
53 | $this->config['api_access'] = $this->api_access[$this->config['port']];
54 | $this->connectid = true;
55 | $this->enabled = true;
56 | }
57 |
58 | function upload($source, $target) {
59 | try {
60 | $file = new UpyunMultiPartFile($source);
61 | } catch (Exception $e) {
62 | return 0;
63 | }
64 | if($file->getSize() > 1024 * 1024 && $this->upyun_config['form_api_key']) {
65 | $sign = new UpyunMultipartSignature($this->upyun_config['form_api_key']);
66 | $upload = new UpyunMultipartUpload($sign);
67 | $upload->setBucketName($this->upyun_config['bucket_name']);
68 | $upload->setBlockSize($upload->getBlockSizeAdaptive($file));
69 | try {
70 | $result = $upload->upload($file, array(
71 | 'path' => $this->upyun_dir . ltrim($target, '/')
72 | ));
73 | return $result;
74 | } catch(Exception $e) {
75 | return 0;
76 | }
77 | } else {
78 | $fh = fopen($source, 'rb');
79 | if(!$fh) {
80 | return 0;
81 | }
82 | $upyun = new UpYun(
83 | $this->upyun_config['bucket_name'],
84 | $this->upyun_config['operator_name'],
85 | $this->upyun_config['operator_pwd']
86 | );
87 | $rsp = $upyun->writeFile($this->upyun_dir . ltrim($target, '/'), $fh, true);
88 | return $rsp;
89 | }
90 | }
91 |
92 | function connect() {
93 | return 1;
94 | }
95 |
96 | function set_error($code = 0) {
97 | $this->_error = $code;
98 | }
99 |
100 | function error() {
101 | return $this->_error;
102 | }
103 |
104 | function clear($str) {
105 | return str_replace(array( "\n", "\r", '..'), '', $str);
106 | }
107 |
108 | function ftp_rmdir($directory) {
109 | return 1;
110 | }
111 |
112 | function ftp_size($remote_file) {
113 | $upyun = new UpYun(
114 | $this->upyun_config['bucket_name'],
115 | $this->upyun_config['operator_name'],
116 | $this->upyun_config['operator_pwd']
117 | );
118 | $remote_file = discuz_ftp::clear($remote_file);
119 | try{
120 | $rsp = $upyun->getFileInfo($this->upyun_dir . ltrim($remote_file, '/'));
121 | return $rsp['x-upyun-file-size'];
122 | }
123 | catch(Exception $e){
124 | return -1;
125 | }
126 | }
127 |
128 | function ftp_close() {
129 | return 1;
130 | }
131 |
132 | function ftp_delete($path) {
133 | $upyun = new UpYun(
134 | $this->upyun_config['bucket_name'],
135 | $this->upyun_config['operator_name'],
136 | $this->upyun_config['operator_pwd']
137 | );
138 | $path = discuz_ftp::clear($path);
139 | try{
140 | $rsp = $upyun->delete($this->upyun_dir . ltrim($path, '/'));
141 | return $rsp;
142 | }
143 | catch(Exception $e){
144 | return 0;
145 | }
146 | }
147 |
148 | function ftp_get($local_file, $remote_file, $mode, $resumepos = 0) {
149 | $upyun = new UpYun(
150 | $this->upyun_config['bucket_name'],
151 | $this->upyun_config['operator_name'],
152 | $this->upyun_config['operator_pwd']
153 | );
154 | $remote_file = discuz_ftp::clear($remote_file);
155 | $local_file = discuz_ftp::clear($local_file);
156 | try{
157 | if($fh = fopen($local_file,'wb')){
158 | $rsp = $upyun->readFile($this->upyun_dir . ltrim($remote_file, '/'), $fh);
159 | fclose($fh);
160 | return $rsp;
161 | }else{
162 | return 0;
163 | }
164 | }
165 | catch(Exception $e){
166 | return 0;
167 | }
168 | }
169 |
170 | }
171 |
--------------------------------------------------------------------------------
/discuz_3_1/install/forum_image.php:
--------------------------------------------------------------------------------
1 | fetch('aid:'.$daid, $daid, array(1, -1))) {
36 | if(!$dw && !$dh && $attach['tid'] != $id) {
37 | dheader('location: '.$_G['siteurl'].'static/image/common/none.gif');
38 | }
39 | dheader('Expires: '.gmdate('D, d M Y H:i:s', TIMESTAMP + 3600).' GMT');
40 | if($attach['remote']) {
41 | $sign = upyun_gen_sign('/forum/'.$attach['attachment']);
42 | $filename = $_G['setting']['ftp']['attachurl'].'forum/'.$attach['attachment'] . '?_upt=' . $sign;
43 | } else {
44 | $filename = $_G['setting']['attachdir'].'forum/'.$attach['attachment'];
45 | }
46 | require_once libfile('class/image');
47 | $img = new image;
48 | if($img->Thumb($filename, $thumbfile, $w, $h, $type)) {
49 | if($nocache) {
50 | dheader('Content-Type: image');
51 | @readfile($_G['setting']['attachdir'].$thumbfile);
52 | @unlink($_G['setting']['attachdir'].$thumbfile);
53 | } else {
54 | dheader('location: '.$attachurl.$thumbfile);
55 | }
56 | } else {
57 | dheader('Content-Type: image');
58 | @readfile($filename);
59 | }
60 | }
61 |
62 | ?>
--------------------------------------------------------------------------------
/discuz_3_1/install/function_attachment.php:
--------------------------------------------------------------------------------
1 | 'unknown.gif',
18 | 2 => 'binary.gif',
19 | 3 => 'zip.gif',
20 | 4 => 'rar.gif',
21 | 5 => 'msoffice.gif',
22 | 6 => 'text.gif',
23 | 7 => 'html.gif',
24 | 8 => 'real.gif',
25 | 9 => 'av.gif',
26 | 10 => 'flash.gif',
27 | 11 => 'image.gif',
28 | 12 => 'pdf.gif',
29 | 13 => 'torrent.gif'
30 | );
31 |
32 | if(is_numeric($type)) {
33 | $typeid = $type;
34 | } else {
35 | if(preg_match("/bittorrent|^torrent\t/", $type)) {
36 | $typeid = 13;
37 | } elseif(preg_match("/pdf|^pdf\t/", $type)) {
38 | $typeid = 12;
39 | } elseif(preg_match("/image|^(jpg|gif|png|bmp)\t/", $type)) {
40 | $typeid = 11;
41 | } elseif(preg_match("/flash|^(swf|fla|flv|swi)\t/", $type)) {
42 | $typeid = 10;
43 | } elseif(preg_match("/audio|video|^(wav|mid|mp3|m3u|wma|asf|asx|vqf|mpg|mpeg|avi|wmv)\t/", $type)) {
44 | $typeid = 9;
45 | } elseif(preg_match("/real|^(ra|rm|rv)\t/", $type)) {
46 | $typeid = 8;
47 | } elseif(preg_match("/htm|^(php|js|pl|cgi|asp)\t/", $type)) {
48 | $typeid = 7;
49 | } elseif(preg_match("/text|^(txt|rtf|wri|chm)\t/", $type)) {
50 | $typeid = 6;
51 | } elseif(preg_match("/word|powerpoint|^(doc|ppt)\t/", $type)) {
52 | $typeid = 5;
53 | } elseif(preg_match("/^rar\t/", $type)) {
54 | $typeid = 4;
55 | } elseif(preg_match("/compressed|^(zip|arj|arc|cab|lzh|lha|tar|gz)\t/", $type)) {
56 | $typeid = 3;
57 | } elseif(preg_match("/octet-stream|^(exe|com|bat|dll)\t/", $type)) {
58 | $typeid = 2;
59 | } elseif($type) {
60 | $typeid = 1;
61 | } else {
62 | $typeid = 0;
63 | }
64 | }
65 | if($returnval == 'html') {
66 | return '
';
67 | } elseif($returnval == 'id') {
68 | return $typeid;
69 | }
70 | }
71 |
72 | function parseattach($attachpids, $attachtags, &$postlist, $skipaids = array()) {
73 | global $_G;
74 | if(!$attachpids) {
75 | return;
76 | }
77 | $attachpids = is_array($attachpids) ? $attachpids : array($attachpids);
78 | $attachexists = FALSE;
79 | $skipattachcode = $aids = $payaids = $findattach = array();
80 | foreach(C::t('forum_attachment_n')->fetch_all_by_id('tid:'.$_G['tid'], 'pid', $attachpids) as $attach) {
81 | $attachexists = TRUE;
82 | if($skipaids && in_array($attach['aid'], $skipaids)) {
83 | $skipattachcode[$attach[pid]][] = "/\[attach\]$attach[aid]\[\/attach\]/i";
84 | continue;
85 | }
86 | $attached = 0;
87 | $extension = strtolower(fileext($attach['filename']));
88 | $attach['ext'] = $extension;
89 | $attach['imgalt'] = $attach['isimage'] ? strip_tags(str_replace('"', '\"', $attach['description'] ? $attach['description'] : $attach['filename'])) : '';
90 | $attach['attachicon'] = attachtype($extension."\t".$attach['filetype']);
91 | $attach['attachsize'] = sizecount($attach['filesize']);
92 | if($attach['isimage'] && !$_G['setting']['attachimgpost']) {
93 | $attach['isimage'] = 0;
94 | }
95 | $attach['attachimg'] = $attach['isimage'] && (!$attach['readperm'] || $_G['group']['readaccess'] >= $attach['readperm']) ? 1 : 0;
96 | if($attach['attachimg']) {
97 | $GLOBALS['aimgs'][$attach['pid']][] = $attach['aid'];
98 | }
99 | if($attach['price']) {
100 | if($_G['setting']['maxchargespan'] && TIMESTAMP - $attach['dateline'] >= $_G['setting']['maxchargespan'] * 3600) {
101 | C::t('forum_attachment_n')->update('tid:'.$_G['tid'], $attach['aid'], array('price' => 0));
102 | $attach['price'] = 0;
103 | } elseif(!$_G['forum_attachmentdown'] && $_G['uid'] != $attach['uid']) {
104 | $payaids[$attach['aid']] = $attach['pid'];
105 | }
106 | }
107 | $attach['payed'] = $_G['forum_attachmentdown'] || $_G['uid'] == $attach['uid'] ? 1 : 0;
108 | // comment by UPYUN
109 | //$attach['url'] = ($attach['remote'] ? $_G['setting']['ftp']['attachurl'] : $_G['setting']['attachurl']).'forum/';
110 | //Begin Of Upyun Insert Code
111 | $upyun_url_prefix =rtrim($_G['cache']['plugin']['upyun']['url'], '/') . '/';
112 | $attach['url'] = ($attach['remote'] ? $upyun_url_prefix : $_G['setting']['attachurl']).'forum/';
113 | //End Of Upyun Insert Code
114 | $attach['dbdateline'] = $attach['dateline'];
115 | $attach['dateline'] = dgmdate($attach['dateline'], 'u');
116 | $postlist[$attach['pid']]['attachments'][$attach['aid']] = $attach;
117 | if(!defined('IN_MOBILE_API') && !empty($attachtags[$attach['pid']]) && is_array($attachtags[$attach['pid']]) && in_array($attach['aid'], $attachtags[$attach['pid']])) {
118 | $findattach[$attach['pid']][$attach['aid']] = "/\[attach\]$attach[aid]\[\/attach\]/i";
119 | $attached = 1;
120 | }
121 |
122 | if(!$attached) {
123 | if($attach['isimage']) {
124 | $postlist[$attach['pid']]['imagelist'][] = $attach['aid'];
125 | $postlist[$attach['pid']]['imagelistcount']++;
126 | if($postlist[$attach['pid']]['first']) {
127 | $GLOBALS['firstimgs'][] = $attach['aid'];
128 | }
129 | } else {
130 | if(!$_G['forum_skipaidlist'] || !in_array($attach['aid'], $_G['forum_skipaidlist'])) {
131 | $postlist[$attach['pid']]['attachlist'][] = $attach['aid'];
132 | }
133 | }
134 | }
135 | $aids[] = $attach['aid'];
136 | }
137 | if($aids) {
138 | $attachs = C::t('forum_attachment')->fetch_all($aids);
139 | foreach($attachs as $aid => $attach) {
140 | if($postlist[$attach['pid']]) {
141 | $postlist[$attach['pid']]['attachments'][$attach['aid']]['downloads'] = $attach['downloads'];
142 | }
143 | }
144 | }
145 | if($payaids) {
146 | foreach(C::t('common_credit_log')->fetch_all_by_uid_operation_relatedid($_G['uid'], 'BAC', array_keys($payaids)) as $creditlog) {
147 | $postlist[$payaids[$creditlog['relatedid']]]['attachments'][$creditlog['relatedid']]['payed'] = 1;
148 | }
149 | }
150 | if(!empty($skipattachcode)) {
151 | foreach($skipattachcode as $pid => $findskipattach) {
152 | foreach($findskipattach as $findskip) {
153 | $postlist[$pid]['message'] = preg_replace($findskip, '', $postlist[$pid]['message']);
154 | }
155 | }
156 | }
157 |
158 | if($attachexists) {
159 | foreach($attachtags as $pid => $aids) {
160 | if($findattach[$pid]) {
161 | foreach($findattach[$pid] as $aid => $find) {
162 | $postlist[$pid]['message'] = preg_replace($find, attachinpost($postlist[$pid]['attachments'][$aid], $postlist[$pid]), $postlist[$pid]['message'], 1);
163 | $postlist[$pid]['message'] = preg_replace($find, '', $postlist[$pid]['message']);
164 | }
165 | }
166 | }
167 | } else {
168 | loadcache('posttableids');
169 | $posttableids = $_G['cache']['posttableids'] ? $_G['cache']['posttableids'] : array('0');
170 | foreach($posttableids as $id) {
171 | C::t('forum_post')->update($id, $attachpids, array('attachment' => '0'), true);
172 | }
173 | }
174 | }
175 |
176 | function attachwidth($width) {
177 | global $_G;
178 | if($_G['setting']['imagemaxwidth'] && $width) {
179 | return 'class="zoom" onclick="zoom(this, this.src, 0, 0, '.($_G['setting']['showexif'] ? 1 : 0).')" width="'.($width > $_G['setting']['imagemaxwidth'] ? $_G['setting']['imagemaxwidth'] : $width).'"';
180 | } else {
181 | return 'thumbImg="1"';
182 | }
183 | }
184 |
185 | function packaids($attach) {
186 | global $_G;
187 | return aidencode($attach['aid'], 0, $_G['tid']);
188 | }
189 |
190 | function showattach($post, $type = 0) {
191 | $type = !$type ? 'attachlist' : 'imagelist';
192 | $return = '';
193 | if(!empty($post[$type]) && is_array($post[$type])) {
194 | foreach($post[$type] as $aid) {
195 | if(!empty($post['attachments'][$aid])) {
196 | $return .= $type($post['attachments'][$aid], $post['first']);
197 | }
198 | }
199 | }
200 | return $return;
201 | }
202 |
203 | function getattachexif($aid, $path = '') {
204 | global $_G;
205 | $return = $filename = '';
206 | if(!$path) {
207 | if($attach = C::t('forum_attachment_n')->fetch('aid:'.$aid, $aid, array(1, -1))) {
208 | if($attach['remote']) {
209 | $filename = $_G['setting']['ftp']['attachurl'].'forum/'.$attach['attachment'];
210 | } else {
211 | $filename = $_G['setting']['attachdir'].'forum/'.$attach['attachment'];
212 | }
213 | }
214 | } else {
215 | $filename = $path;
216 | }
217 | if($filename) {
218 | require_once libfile('function/exif');
219 | $exif = getexif($filename);
220 | $keys = array(
221 | exif_lang('Model'),
222 | exif_lang('ShutterSpeedValue'),
223 | exif_lang('ApertureValue'),
224 | exif_lang('FocalLength'),
225 | exif_lang('ExposureTime'),
226 | exif_lang('DateTimeOriginal'),
227 | exif_lang('ISOSpeedRatings'),
228 | );
229 | foreach($exif as $key => $value) {
230 | if(in_array($key, $keys)) {
231 | $return .= "$key : $value
";
232 | }
233 | }
234 | }
235 | return $return;
236 | }
237 |
238 | ?>
--------------------------------------------------------------------------------
/discuz_3_1/install/portal_attachment.php:
--------------------------------------------------------------------------------
1 | fetch($id);
18 | if(empty($attach)) {
19 | showmessage('portal_attachment_noexist');
20 | }
21 |
22 | if($operation == 'delete') {
23 | if(!$_G['group']['allowmanagearticle'] && $_G['uid'] != $attach['uid']) {
24 | showmessage('portal_attachment_nopermission_delete');
25 | }
26 | if($aid) {
27 | C::t('portal_article_title')->update($aid, array('pic' => ''));
28 | }
29 | C::t('portal_attachment')->delete($id);
30 | pic_delete($attach['attachment'], 'portal', $attach['thumb'], $attach['remote']);
31 | showmessage('portal_image_noexist');
32 |
33 | } elseif($operation == 'getattach') {
34 |
35 | require_once libfile('function/attachment');
36 | if($attach['isimage']) {
37 | require_once libfile('function/home');
38 | $smallimg = pic_get($attach['attachment'], 'portal', $attach['thumb'], $attach['remote']);
39 | $bigimg = pic_get($attach['attachment'], 'portal', 0, $attach['remote']);
40 | $coverstr = addslashes(serialize(array('pic'=>'portal/'.$attach['attachment'], 'thumb'=>$attach['thumb'], 'remote'=>$attach['remote'])));
41 | }
42 | $attach['filetype'] = attachtype($attach['filetype']."\t".$attach['filetype']);
43 | $attach['filesize'] = sizecount($attach['filesize']);
44 | include template('portal/portal_attachment');
45 |
46 | exit;
47 |
48 | } else {
49 | $filename = $_G['setting']['attachdir'].'/portal/'.$attach['attachment'];
50 | if(!$attach['remote'] && !is_readable($filename)) {
51 | showmessage('attachment_nonexistence');
52 | }
53 |
54 | $readmod = 2;//read local file's function: 1=fread 2=readfile 3=fpassthru 4=fpassthru+multiple
55 | $range = 0;
56 | if($readmod == 4 && !empty($_SERVER['HTTP_RANGE'])) {
57 | list($range) = explode('-',(str_replace('bytes=', '', $_SERVER['HTTP_RANGE'])));
58 | }
59 |
60 | //Begin Of Upyun Insert Code
61 | include_once DISCUZ_ROOT . 'source/plugin/upyun/function_upyun.php';
62 | upyun_attachment_download($attach, 'portal');
63 | //End Of Upyun Insert Code
64 |
65 | $filesize = $attach['filesize'];
66 | $attach['filename'] = '"'.(strtolower(CHARSET) == 'utf-8' && strexists($_SERVER['HTTP_USER_AGENT'], 'MSIE') ? urlencode($attach['filename']) : $attach['filename']).'"';
67 |
68 | dheader('Date: '.gmdate('D, d M Y H:i:s', $attach['dateline']).' GMT');
69 | dheader('Last-Modified: '.gmdate('D, d M Y H:i:s', $attach['dateline']).' GMT');
70 | dheader('Content-Encoding: none');
71 | dheader('Content-Disposition: attachment; filename='.$attach['filename']);
72 | dheader('Content-Type: '.$attach['filetype']);
73 | dheader('Content-Length: '.$filesize);
74 |
75 | if($readmod == 4) {
76 | dheader('Accept-Ranges: bytes');
77 | if(!empty($_SERVER['HTTP_RANGE'])) {
78 | $rangesize = ($filesize - $range) > 0 ? ($filesize - $range) : 0;
79 | dheader('Content-Length: '.$rangesize);
80 | dheader('HTTP/1.1 206 Partial Content');
81 | dheader('Content-Range: bytes='.$range.'-'.($filesize-1).'/'.($filesize));
82 | }
83 | }
84 |
85 | $attach['remote'] ? getremotefile($attach['attachment']) : getlocalfile($filename, $readmod, $range);
86 | }
87 | function getremotefile($file) {
88 | global $_G;
89 | @set_time_limit(0);
90 | if(!@readfile($_G['setting']['ftp']['attachurl'].'portal/'.$file)) {
91 |
92 | $ftp = new discuz_ftp();
93 | if(!($_G['setting']['ftp']['connid'] = $ftp->connect())) {
94 | return FALSE;
95 | }
96 | $tmpfile = @tempnam($_G['setting']['attachdir'], '');
97 | if($ftp->ftp_get($_G['setting']['ftp']['connid'], $tmpfile, $file, FTP_BINARY)) {
98 | @readfile($tmpfile);
99 | @unlink($tmpfile);
100 | } else {
101 | @unlink($tmpfile);
102 | return FALSE;
103 | }
104 | }
105 | return TRUE;
106 | }
107 |
108 | function getlocalfile($filename, $readmod = 2, $range = 0) {
109 | if($readmod == 1 || $readmod == 3 || $readmod == 4) {
110 | if($fp = @fopen($filename, 'rb')) {
111 | @fseek($fp, $range);
112 | if(function_exists('fpassthru') && ($readmod == 3 || $readmod == 4)) {
113 | @fpassthru($fp);
114 | } else {
115 | echo @fread($fp, filesize($filename));
116 | }
117 | }
118 | @fclose($fp);
119 | } else {
120 | @readfile($filename);
121 | }
122 | @flush();
123 | @ob_flush();
124 | }
125 |
126 | ?>
--------------------------------------------------------------------------------
/discuz_3_1/uninstall/discuz_ftp.php:
--------------------------------------------------------------------------------
1 | set_error(0);
47 | $this->config = !$config ? getglobal('setting/ftp') : $config;
48 | $this->enabled = false;
49 | if(empty($this->config['on']) || empty($this->config['host'])) {
50 | $this->set_error(FTP_ERR_CONFIG_OFF);
51 | } else {
52 | $this->func = $this->config['ssl'] && function_exists('ftp_ssl_connect') ? 'ftp_ssl_connect' : 'ftp_connect';
53 | if($this->func == 'ftp_connect' && !function_exists('ftp_connect')) {
54 | $this->set_error(FTP_ERR_SERVER_DISABLED);
55 | } else {
56 | $this->config['host'] = discuz_ftp::clear($this->config['host']);
57 | $this->config['port'] = intval($this->config['port']);
58 | $this->config['ssl'] = intval($this->config['ssl']);
59 | $this->config['username'] = discuz_ftp::clear($this->config['username']);
60 | $this->config['password'] = authcode($this->config['password'], 'DECODE', md5(getglobal('config/security/authkey')));
61 | $this->config['timeout'] = intval($this->config['timeout']);
62 | $this->enabled = true;
63 | }
64 | }
65 | }
66 |
67 | function upload($source, $target) {
68 | if($this->error()) {
69 | return 0;
70 | }
71 | $old_dir = $this->ftp_pwd();
72 | $dirname = dirname($target);
73 | $filename = basename($target);
74 | if(!$this->ftp_chdir($dirname)) {
75 | if($this->ftp_mkdir($dirname)) {
76 | $this->ftp_chmod($dirname);
77 | if(!$this->ftp_chdir($dirname)) {
78 | $this->set_error(FTP_ERR_CHDIR);
79 | }
80 | $this->ftp_put('index.htm', getglobal('setting/attachdir').'/index.htm', FTP_BINARY);
81 | } else {
82 | $this->set_error(FTP_ERR_MKDIR);
83 | }
84 | }
85 |
86 | $res = 0;
87 | if(!$this->error()) {
88 | if($fp = @fopen($source, 'rb')) {
89 | $res = $this->ftp_fput($filename, $fp, FTP_BINARY);
90 | @fclose($fp);
91 | !$res && $this->set_error(FTP_ERR_TARGET_WRITE);
92 | } else {
93 | $this->set_error(FTP_ERR_SOURCE_READ);
94 | }
95 | }
96 |
97 | $this->ftp_chdir($old_dir);
98 |
99 | return $res ? 1 : 0;
100 | }
101 |
102 | function connect() {
103 | if(!$this->enabled || empty($this->config)) {
104 | return 0;
105 | } else {
106 | return $this->ftp_connect(
107 | $this->config['host'],
108 | $this->config['username'],
109 | $this->config['password'],
110 | $this->config['attachdir'],
111 | $this->config['port'],
112 | $this->config['timeout'],
113 | $this->config['ssl'],
114 | $this->config['pasv']
115 | );
116 | }
117 |
118 | }
119 |
120 | function ftp_connect($ftphost, $username, $password, $ftppath, $ftpport = 21, $timeout = 30, $ftpssl = 0, $ftppasv = 0) {
121 | $res = 0;
122 | $fun = $this->func;
123 | if($this->connectid = $fun($ftphost, $ftpport, 20)) {
124 |
125 | $timeout && $this->set_option(FTP_TIMEOUT_SEC, $timeout);
126 | if($this->ftp_login($username, $password)) {
127 | $this->ftp_pasv($ftppasv);
128 | if($this->ftp_chdir($ftppath)) {
129 | $res = $this->connectid;
130 | } else {
131 | $this->set_error(FTP_ERR_CHDIR);
132 | }
133 | } else {
134 | $this->set_error(FTP_ERR_USER_NO_LOGGIN);
135 | }
136 |
137 | } else {
138 | $this->set_error(FTP_ERR_CONNECT_TO_SERVER);
139 | }
140 |
141 | if($res > 0) {
142 | $this->set_error();
143 | $this->enabled = 1;
144 | } else {
145 | $this->enabled = 0;
146 | $this->ftp_close();
147 | }
148 |
149 | return $res;
150 |
151 | }
152 |
153 | function set_error($code = 0) {
154 | $this->_error = $code;
155 | }
156 |
157 | function error() {
158 | return $this->_error;
159 | }
160 |
161 | function clear($str) {
162 | return str_replace(array( "\n", "\r", '..'), '', $str);
163 | }
164 |
165 |
166 | function set_option($cmd, $value) {
167 | if(function_exists('ftp_set_option')) {
168 | return @ftp_set_option($this->connectid, $cmd, $value);
169 | }
170 | }
171 |
172 | function ftp_mkdir($directory) {
173 | $directory = discuz_ftp::clear($directory);
174 | $epath = explode('/', $directory);
175 | $dir = '';$comma = '';
176 | foreach($epath as $path) {
177 | $dir .= $comma.$path;
178 | $comma = '/';
179 | $return = @ftp_mkdir($this->connectid, $dir);
180 | $this->ftp_chmod($dir);
181 | }
182 | return $return;
183 | }
184 |
185 | function ftp_rmdir($directory) {
186 | $directory = discuz_ftp::clear($directory);
187 | return @ftp_rmdir($this->connectid, $directory);
188 | }
189 |
190 | function ftp_put($remote_file, $local_file, $mode = FTP_BINARY) {
191 | $remote_file = discuz_ftp::clear($remote_file);
192 | $local_file = discuz_ftp::clear($local_file);
193 | $mode = intval($mode);
194 | return @ftp_put($this->connectid, $remote_file, $local_file, $mode);
195 | }
196 |
197 | function ftp_fput($remote_file, $sourcefp, $mode = FTP_BINARY) {
198 | $remote_file = discuz_ftp::clear($remote_file);
199 | $mode = intval($mode);
200 | return @ftp_fput($this->connectid, $remote_file, $sourcefp, $mode);
201 | }
202 |
203 | function ftp_size($remote_file) {
204 | $remote_file = discuz_ftp::clear($remote_file);
205 | return @ftp_size($this->connectid, $remote_file);
206 | }
207 |
208 | function ftp_close() {
209 | return @ftp_close($this->connectid);
210 | }
211 |
212 | function ftp_delete($path) {
213 | $path = discuz_ftp::clear($path);
214 | return @ftp_delete($this->connectid, $path);
215 | }
216 |
217 | function ftp_get($local_file, $remote_file, $mode, $resumepos = 0) {
218 | $remote_file = discuz_ftp::clear($remote_file);
219 | $local_file = discuz_ftp::clear($local_file);
220 | $mode = intval($mode);
221 | $resumepos = intval($resumepos);
222 | return @ftp_get($this->connectid, $local_file, $remote_file, $mode, $resumepos);
223 | }
224 |
225 | function ftp_login($username, $password) {
226 | $username = $this->clear($username);
227 | $password = str_replace(array("\n", "\r"), array('', ''), $password);
228 | return @ftp_login($this->connectid, $username, $password);
229 | }
230 |
231 | function ftp_pasv($pasv) {
232 | return @ftp_pasv($this->connectid, $pasv ? true : false);
233 | }
234 |
235 | function ftp_chdir($directory) {
236 | $directory = discuz_ftp::clear($directory);
237 | return @ftp_chdir($this->connectid, $directory);
238 | }
239 |
240 | function ftp_site($cmd) {
241 | $cmd = discuz_ftp::clear($cmd);
242 | return @ftp_site($this->connectid, $cmd);
243 | }
244 |
245 | function ftp_chmod($filename, $mod = 0777) {
246 | $filename = discuz_ftp::clear($filename);
247 | if(function_exists('ftp_chmod')) {
248 | return @ftp_chmod($this->connectid, $mod, $filename);
249 | } else {
250 | return @ftp_site($this->connectid, 'CHMOD '.$mod.' '.$filename);
251 | }
252 | }
253 |
254 | function ftp_pwd() {
255 | return @ftp_pwd($this->connectid);
256 | }
257 |
258 | }
--------------------------------------------------------------------------------
/discuz_3_1/uninstall/forum_image.php:
--------------------------------------------------------------------------------
1 | fetch('aid:'.$daid, $daid, array(1, -1))) {
36 | if(!$dw && !$dh && $attach['tid'] != $id) {
37 | dheader('location: '.$_G['siteurl'].'static/image/common/none.gif');
38 | }
39 | dheader('Expires: '.gmdate('D, d M Y H:i:s', TIMESTAMP + 3600).' GMT');
40 | if($attach['remote']) {
41 | $filename = $_G['setting']['ftp']['attachurl'].'forum/'.$attach['attachment'];
42 | } else {
43 | $filename = $_G['setting']['attachdir'].'forum/'.$attach['attachment'];
44 | }
45 | require_once libfile('class/image');
46 | $img = new image;
47 | if($img->Thumb($filename, $thumbfile, $w, $h, $type)) {
48 | if($nocache) {
49 | dheader('Content-Type: image');
50 | @readfile($_G['setting']['attachdir'].$thumbfile);
51 | @unlink($_G['setting']['attachdir'].$thumbfile);
52 | } else {
53 | dheader('location: '.$attachurl.$thumbfile);
54 | }
55 | } else {
56 | dheader('Content-Type: image');
57 | @readfile($filename);
58 | }
59 | }
60 |
61 | ?>
--------------------------------------------------------------------------------
/discuz_3_1/uninstall/function_attachment.php:
--------------------------------------------------------------------------------
1 | 'unknown.gif',
18 | 2 => 'binary.gif',
19 | 3 => 'zip.gif',
20 | 4 => 'rar.gif',
21 | 5 => 'msoffice.gif',
22 | 6 => 'text.gif',
23 | 7 => 'html.gif',
24 | 8 => 'real.gif',
25 | 9 => 'av.gif',
26 | 10 => 'flash.gif',
27 | 11 => 'image.gif',
28 | 12 => 'pdf.gif',
29 | 13 => 'torrent.gif'
30 | );
31 |
32 | if(is_numeric($type)) {
33 | $typeid = $type;
34 | } else {
35 | if(preg_match("/bittorrent|^torrent\t/", $type)) {
36 | $typeid = 13;
37 | } elseif(preg_match("/pdf|^pdf\t/", $type)) {
38 | $typeid = 12;
39 | } elseif(preg_match("/image|^(jpg|gif|png|bmp)\t/", $type)) {
40 | $typeid = 11;
41 | } elseif(preg_match("/flash|^(swf|fla|flv|swi)\t/", $type)) {
42 | $typeid = 10;
43 | } elseif(preg_match("/audio|video|^(wav|mid|mp3|m3u|wma|asf|asx|vqf|mpg|mpeg|avi|wmv)\t/", $type)) {
44 | $typeid = 9;
45 | } elseif(preg_match("/real|^(ra|rm|rv)\t/", $type)) {
46 | $typeid = 8;
47 | } elseif(preg_match("/htm|^(php|js|pl|cgi|asp)\t/", $type)) {
48 | $typeid = 7;
49 | } elseif(preg_match("/text|^(txt|rtf|wri|chm)\t/", $type)) {
50 | $typeid = 6;
51 | } elseif(preg_match("/word|powerpoint|^(doc|ppt)\t/", $type)) {
52 | $typeid = 5;
53 | } elseif(preg_match("/^rar\t/", $type)) {
54 | $typeid = 4;
55 | } elseif(preg_match("/compressed|^(zip|arj|arc|cab|lzh|lha|tar|gz)\t/", $type)) {
56 | $typeid = 3;
57 | } elseif(preg_match("/octet-stream|^(exe|com|bat|dll)\t/", $type)) {
58 | $typeid = 2;
59 | } elseif($type) {
60 | $typeid = 1;
61 | } else {
62 | $typeid = 0;
63 | }
64 | }
65 | if($returnval == 'html') {
66 | return '
';
67 | } elseif($returnval == 'id') {
68 | return $typeid;
69 | }
70 | }
71 |
72 | function parseattach($attachpids, $attachtags, &$postlist, $skipaids = array()) {
73 | global $_G;
74 | if(!$attachpids) {
75 | return;
76 | }
77 | $attachpids = is_array($attachpids) ? $attachpids : array($attachpids);
78 | $attachexists = FALSE;
79 | $skipattachcode = $aids = $payaids = $findattach = array();
80 | foreach(C::t('forum_attachment_n')->fetch_all_by_id('tid:'.$_G['tid'], 'pid', $attachpids) as $attach) {
81 | $attachexists = TRUE;
82 | if($skipaids && in_array($attach['aid'], $skipaids)) {
83 | $skipattachcode[$attach[pid]][] = "/\[attach\]$attach[aid]\[\/attach\]/i";
84 | continue;
85 | }
86 | $attached = 0;
87 | $extension = strtolower(fileext($attach['filename']));
88 | $attach['ext'] = $extension;
89 | $attach['imgalt'] = $attach['isimage'] ? strip_tags(str_replace('"', '\"', $attach['description'] ? $attach['description'] : $attach['filename'])) : '';
90 | $attach['attachicon'] = attachtype($extension."\t".$attach['filetype']);
91 | $attach['attachsize'] = sizecount($attach['filesize']);
92 | if($attach['isimage'] && !$_G['setting']['attachimgpost']) {
93 | $attach['isimage'] = 0;
94 | }
95 | $attach['attachimg'] = $attach['isimage'] && (!$attach['readperm'] || $_G['group']['readaccess'] >= $attach['readperm']) ? 1 : 0;
96 | if($attach['attachimg']) {
97 | $GLOBALS['aimgs'][$attach['pid']][] = $attach['aid'];
98 | }
99 | if($attach['price']) {
100 | if($_G['setting']['maxchargespan'] && TIMESTAMP - $attach['dateline'] >= $_G['setting']['maxchargespan'] * 3600) {
101 | C::t('forum_attachment_n')->update('tid:'.$_G['tid'], $attach['aid'], array('price' => 0));
102 | $attach['price'] = 0;
103 | } elseif(!$_G['forum_attachmentdown'] && $_G['uid'] != $attach['uid']) {
104 | $payaids[$attach['aid']] = $attach['pid'];
105 | }
106 | }
107 | $attach['payed'] = $_G['forum_attachmentdown'] || $_G['uid'] == $attach['uid'] ? 1 : 0;
108 | $attach['url'] = ($attach['remote'] ? $_G['setting']['ftp']['attachurl'] : $_G['setting']['attachurl']).'forum/';
109 | $attach['dbdateline'] = $attach['dateline'];
110 | $attach['dateline'] = dgmdate($attach['dateline'], 'u');
111 | $postlist[$attach['pid']]['attachments'][$attach['aid']] = $attach;
112 | if(!defined('IN_MOBILE_API') && !empty($attachtags[$attach['pid']]) && is_array($attachtags[$attach['pid']]) && in_array($attach['aid'], $attachtags[$attach['pid']])) {
113 | $findattach[$attach['pid']][$attach['aid']] = "/\[attach\]$attach[aid]\[\/attach\]/i";
114 | $attached = 1;
115 | }
116 |
117 | if(!$attached) {
118 | if($attach['isimage']) {
119 | $postlist[$attach['pid']]['imagelist'][] = $attach['aid'];
120 | $postlist[$attach['pid']]['imagelistcount']++;
121 | if($postlist[$attach['pid']]['first']) {
122 | $GLOBALS['firstimgs'][] = $attach['aid'];
123 | }
124 | } else {
125 | if(!$_G['forum_skipaidlist'] || !in_array($attach['aid'], $_G['forum_skipaidlist'])) {
126 | $postlist[$attach['pid']]['attachlist'][] = $attach['aid'];
127 | }
128 | }
129 | }
130 | $aids[] = $attach['aid'];
131 | }
132 | if($aids) {
133 | $attachs = C::t('forum_attachment')->fetch_all($aids);
134 | foreach($attachs as $aid => $attach) {
135 | if($postlist[$attach['pid']]) {
136 | $postlist[$attach['pid']]['attachments'][$attach['aid']]['downloads'] = $attach['downloads'];
137 | }
138 | }
139 | }
140 | if($payaids) {
141 | foreach(C::t('common_credit_log')->fetch_all_by_uid_operation_relatedid($_G['uid'], 'BAC', array_keys($payaids)) as $creditlog) {
142 | $postlist[$payaids[$creditlog['relatedid']]]['attachments'][$creditlog['relatedid']]['payed'] = 1;
143 | }
144 | }
145 | if(!empty($skipattachcode)) {
146 | foreach($skipattachcode as $pid => $findskipattach) {
147 | foreach($findskipattach as $findskip) {
148 | $postlist[$pid]['message'] = preg_replace($findskip, '', $postlist[$pid]['message']);
149 | }
150 | }
151 | }
152 |
153 | if($attachexists) {
154 | foreach($attachtags as $pid => $aids) {
155 | if($findattach[$pid]) {
156 | foreach($findattach[$pid] as $aid => $find) {
157 | $postlist[$pid]['message'] = preg_replace($find, attachinpost($postlist[$pid]['attachments'][$aid], $postlist[$pid]), $postlist[$pid]['message'], 1);
158 | $postlist[$pid]['message'] = preg_replace($find, '', $postlist[$pid]['message']);
159 | }
160 | }
161 | }
162 | } else {
163 | loadcache('posttableids');
164 | $posttableids = $_G['cache']['posttableids'] ? $_G['cache']['posttableids'] : array('0');
165 | foreach($posttableids as $id) {
166 | C::t('forum_post')->update($id, $attachpids, array('attachment' => '0'), true);
167 | }
168 | }
169 | }
170 |
171 | function attachwidth($width) {
172 | global $_G;
173 | if($_G['setting']['imagemaxwidth'] && $width) {
174 | return 'class="zoom" onclick="zoom(this, this.src, 0, 0, '.($_G['setting']['showexif'] ? 1 : 0).')" width="'.($width > $_G['setting']['imagemaxwidth'] ? $_G['setting']['imagemaxwidth'] : $width).'"';
175 | } else {
176 | return 'thumbImg="1"';
177 | }
178 | }
179 |
180 | function packaids($attach) {
181 | global $_G;
182 | return aidencode($attach['aid'], 0, $_G['tid']);
183 | }
184 |
185 | function showattach($post, $type = 0) {
186 | $type = !$type ? 'attachlist' : 'imagelist';
187 | $return = '';
188 | if(!empty($post[$type]) && is_array($post[$type])) {
189 | foreach($post[$type] as $aid) {
190 | if(!empty($post['attachments'][$aid])) {
191 | $return .= $type($post['attachments'][$aid], $post['first']);
192 | }
193 | }
194 | }
195 | return $return;
196 | }
197 |
198 | function getattachexif($aid, $path = '') {
199 | global $_G;
200 | $return = $filename = '';
201 | if(!$path) {
202 | if($attach = C::t('forum_attachment_n')->fetch('aid:'.$aid, $aid, array(1, -1))) {
203 | if($attach['remote']) {
204 | $filename = $_G['setting']['ftp']['attachurl'].'forum/'.$attach['attachment'];
205 | } else {
206 | $filename = $_G['setting']['attachdir'].'forum/'.$attach['attachment'];
207 | }
208 | }
209 | } else {
210 | $filename = $path;
211 | }
212 | if($filename) {
213 | require_once libfile('function/exif');
214 | $exif = getexif($filename);
215 | $keys = array(
216 | exif_lang('Model'),
217 | exif_lang('ShutterSpeedValue'),
218 | exif_lang('ApertureValue'),
219 | exif_lang('FocalLength'),
220 | exif_lang('ExposureTime'),
221 | exif_lang('DateTimeOriginal'),
222 | exif_lang('ISOSpeedRatings'),
223 | );
224 | foreach($exif as $key => $value) {
225 | if(in_array($key, $keys)) {
226 | $return .= "$key : $value
";
227 | }
228 | }
229 | }
230 | return $return;
231 | }
232 |
233 | ?>
--------------------------------------------------------------------------------
/discuz_3_1/uninstall/portal_attachment.php:
--------------------------------------------------------------------------------
1 | fetch($id);
18 | if(empty($attach)) {
19 | showmessage('portal_attachment_noexist');
20 | }
21 |
22 | if($operation == 'delete') {
23 | if(!$_G['group']['allowmanagearticle'] && $_G['uid'] != $attach['uid']) {
24 | showmessage('portal_attachment_nopermission_delete');
25 | }
26 | if($aid) {
27 | C::t('portal_article_title')->update($aid, array('pic' => ''));
28 | }
29 | C::t('portal_attachment')->delete($id);
30 | pic_delete($attach['attachment'], 'portal', $attach['thumb'], $attach['remote']);
31 | showmessage('portal_image_noexist');
32 |
33 | } elseif($operation == 'getattach') {
34 |
35 | require_once libfile('function/attachment');
36 | if($attach['isimage']) {
37 | require_once libfile('function/home');
38 | $smallimg = pic_get($attach['attachment'], 'portal', $attach['thumb'], $attach['remote']);
39 | $bigimg = pic_get($attach['attachment'], 'portal', 0, $attach['remote']);
40 | $coverstr = addslashes(serialize(array('pic'=>'portal/'.$attach['attachment'], 'thumb'=>$attach['thumb'], 'remote'=>$attach['remote'])));
41 | }
42 | $attach['filetype'] = attachtype($attach['filetype']."\t".$attach['filetype']);
43 | $attach['filesize'] = sizecount($attach['filesize']);
44 | include template('portal/portal_attachment');
45 |
46 | exit;
47 |
48 | } else {
49 | $filename = $_G['setting']['attachdir'].'/portal/'.$attach['attachment'];
50 | if(!$attach['remote'] && !is_readable($filename)) {
51 | showmessage('attachment_nonexistence');
52 | }
53 |
54 | $readmod = 2;//read local file's function: 1=fread 2=readfile 3=fpassthru 4=fpassthru+multiple
55 | $range = 0;
56 | if($readmod == 4 && !empty($_SERVER['HTTP_RANGE'])) {
57 | list($range) = explode('-',(str_replace('bytes=', '', $_SERVER['HTTP_RANGE'])));
58 | }
59 |
60 | if($attach['remote'] && !$_G['setting']['ftp']['hideurl'] && $attach['isimage']) {
61 | dheader('location:'.$_G['setting']['ftp']['attachurl'].'portal/'.$attach['attachment']);
62 | }
63 |
64 | $filesize = $attach['filesize'];
65 | $attach['filename'] = '"'.(strtolower(CHARSET) == 'utf-8' && strexists($_SERVER['HTTP_USER_AGENT'], 'MSIE') ? urlencode($attach['filename']) : $attach['filename']).'"';
66 |
67 | dheader('Date: '.gmdate('D, d M Y H:i:s', $attach['dateline']).' GMT');
68 | dheader('Last-Modified: '.gmdate('D, d M Y H:i:s', $attach['dateline']).' GMT');
69 | dheader('Content-Encoding: none');
70 | dheader('Content-Disposition: attachment; filename='.$attach['filename']);
71 | dheader('Content-Type: '.$attach['filetype']);
72 | dheader('Content-Length: '.$filesize);
73 |
74 | if($readmod == 4) {
75 | dheader('Accept-Ranges: bytes');
76 | if(!empty($_SERVER['HTTP_RANGE'])) {
77 | $rangesize = ($filesize - $range) > 0 ? ($filesize - $range) : 0;
78 | dheader('Content-Length: '.$rangesize);
79 | dheader('HTTP/1.1 206 Partial Content');
80 | dheader('Content-Range: bytes='.$range.'-'.($filesize-1).'/'.($filesize));
81 | }
82 | }
83 |
84 | $attach['remote'] ? getremotefile($attach['attachment']) : getlocalfile($filename, $readmod, $range);
85 | }
86 | function getremotefile($file) {
87 | global $_G;
88 | @set_time_limit(0);
89 | if(!@readfile($_G['setting']['ftp']['attachurl'].'portal/'.$file)) {
90 |
91 | $ftp = new discuz_ftp();
92 | if(!($_G['setting']['ftp']['connid'] = $ftp->connect())) {
93 | return FALSE;
94 | }
95 | $tmpfile = @tempnam($_G['setting']['attachdir'], '');
96 | if($ftp->ftp_get($_G['setting']['ftp']['connid'], $tmpfile, $file, FTP_BINARY)) {
97 | @readfile($tmpfile);
98 | @unlink($tmpfile);
99 | } else {
100 | @unlink($tmpfile);
101 | return FALSE;
102 | }
103 | }
104 | return TRUE;
105 | }
106 |
107 | function getlocalfile($filename, $readmod = 2, $range = 0) {
108 | if($readmod == 1 || $readmod == 3 || $readmod == 4) {
109 | if($fp = @fopen($filename, 'rb')) {
110 | @fseek($fp, $range);
111 | if(function_exists('fpassthru') && ($readmod == 3 || $readmod == 4)) {
112 | @fpassthru($fp);
113 | } else {
114 | echo @fread($fp, filesize($filename));
115 | }
116 | }
117 | @fclose($fp);
118 | } else {
119 | @readfile($filename);
120 | }
121 | @flush();
122 | @ob_flush();
123 | }
124 |
125 | ?>
--------------------------------------------------------------------------------
/discuz_3_2/install/discuz_ftp.php:
--------------------------------------------------------------------------------
1 | set_error(0);
40 | loadcache('plugin');
41 | $this->upyun_config = getglobal('cache/plugin/upyun');
42 | $paths = parse_url($this->upyun_config['url']);
43 | $this->upyun_dir = isset($paths['path']) ? rtrim($paths['path'], '/') . '/' : '/';
44 | $this->config = !$config ? getglobal('setting/ftp') : $config;
45 | $this->enabled = false;
46 | $this->config['host'] = discuz_ftp::clear($this->config['host']);
47 | $this->config['port'] = intval($this->config['port']);
48 | $this->config['ssl'] = intval($this->config['ssl']);
49 | $this->config['bucketname'] = $this->config['host'];
50 | $this->config['username'] = discuz_ftp::clear($this->config['username']);
51 | $this->config['password'] = authcode($this->config['password'], 'DECODE', md5(getglobal('config/security/authkey')));
52 | $this->config['timeout'] = intval($this->config['timeout']);
53 | $this->config['api_access'] = $this->api_access[$this->config['port']];
54 | $this->connectid = true;
55 | $this->enabled = true;
56 | }
57 |
58 | function upload($source, $target) {
59 | try {
60 | $file = new UpyunMultiPartFile($source);
61 | } catch (Exception $e) {
62 | return 0;
63 | }
64 | if($file->getSize() > 1024 * 1024 && $this->upyun_config['form_api_key']) {
65 | $sign = new UpyunMultipartSignature($this->upyun_config['form_api_key']);
66 | $upload = new UpyunMultipartUpload($sign);
67 | $upload->setBucketName($this->upyun_config['bucket_name']);
68 | $upload->setBlockSize($upload->getBlockSizeAdaptive($file));
69 | try {
70 | $result = $upload->upload($file, array(
71 | 'path' => $this->upyun_dir . ltrim($target, '/')
72 | ));
73 | return $result;
74 | } catch(Exception $e) {
75 | return 0;
76 | }
77 | } else {
78 | $fh = fopen($source, 'rb');
79 | if(!$fh) {
80 | return 0;
81 | }
82 | $upyun = new UpYun(
83 | $this->upyun_config['bucket_name'],
84 | $this->upyun_config['operator_name'],
85 | $this->upyun_config['operator_pwd']
86 | );
87 | $rsp = $upyun->writeFile($this->upyun_dir . ltrim($target, '/'), $fh, true);
88 | return $rsp;
89 | }
90 | }
91 |
92 | function connect() {
93 | return 1;
94 | }
95 |
96 | function set_error($code = 0) {
97 | $this->_error = $code;
98 | }
99 |
100 | function error() {
101 | return $this->_error;
102 | }
103 |
104 | function clear($str) {
105 | return str_replace(array( "\n", "\r", '..'), '', $str);
106 | }
107 |
108 | function ftp_rmdir($directory) {
109 | return 1;
110 | }
111 |
112 | function ftp_size($remote_file) {
113 | $upyun = new UpYun(
114 | $this->upyun_config['bucket_name'],
115 | $this->upyun_config['operator_name'],
116 | $this->upyun_config['operator_pwd']
117 | );
118 | $remote_file = discuz_ftp::clear($remote_file);
119 | try{
120 | $rsp = $upyun->getFileInfo($this->upyun_dir . ltrim($remote_file, '/'));
121 | return $rsp['x-upyun-file-size'];
122 | }
123 | catch(Exception $e){
124 | return -1;
125 | }
126 | }
127 |
128 | function ftp_close() {
129 | return 1;
130 | }
131 |
132 | function ftp_delete($path) {
133 | $upyun = new UpYun(
134 | $this->upyun_config['bucket_name'],
135 | $this->upyun_config['operator_name'],
136 | $this->upyun_config['operator_pwd']
137 | );
138 | $path = discuz_ftp::clear($path);
139 | try{
140 | $rsp = $upyun->delete($this->upyun_dir . ltrim($path, '/'));
141 | return $rsp;
142 | }
143 | catch(Exception $e){
144 | return 0;
145 | }
146 | }
147 |
148 | function ftp_get($local_file, $remote_file, $mode, $resumepos = 0) {
149 | $upyun = new UpYun(
150 | $this->upyun_config['bucket_name'],
151 | $this->upyun_config['operator_name'],
152 | $this->upyun_config['operator_pwd']
153 | );
154 | $remote_file = discuz_ftp::clear($remote_file);
155 | $local_file = discuz_ftp::clear($local_file);
156 | try{
157 | if($fh = fopen($local_file,'wb')){
158 | $rsp = $upyun->readFile($this->upyun_dir . ltrim($remote_file, '/'), $fh);
159 | fclose($fh);
160 | return $rsp;
161 | }else{
162 | return 0;
163 | }
164 | }
165 | catch(Exception $e){
166 | return 0;
167 | }
168 | }
169 |
170 | }
171 |
--------------------------------------------------------------------------------
/discuz_3_2/install/forum_image.php:
--------------------------------------------------------------------------------
1 | fetch('aid:'.$daid, $daid, array(1, -1))) {
36 | if(!$dw && !$dh && $attach['tid'] != $id) {
37 | dheader('location: '.$_G['siteurl'].'static/image/common/none.gif');
38 | }
39 | dheader('Expires: '.gmdate('D, d M Y H:i:s', TIMESTAMP + 3600).' GMT');
40 | if($attach['remote']) {
41 | $sign = upyun_gen_sign('/forum/'.$attach['attachment']);
42 | $filename = $_G['setting']['ftp']['attachurl'].'forum/'.$attach['attachment'] . '?_upt=' . $sign;
43 | } else {
44 | $filename = $_G['setting']['attachdir'].'forum/'.$attach['attachment'];
45 | }
46 | require_once libfile('class/image');
47 | $img = new image;
48 | if($img->Thumb($filename, $thumbfile, $w, $h, $type)) {
49 | if($nocache) {
50 | dheader('Content-Type: image');
51 | @readfile($_G['setting']['attachdir'].$thumbfile);
52 | @unlink($_G['setting']['attachdir'].$thumbfile);
53 | } else {
54 | dheader('location: '.$attachurl.$thumbfile);
55 | }
56 | } else {
57 | dheader('Content-Type: image');
58 | @readfile($filename);
59 | }
60 | }
61 |
62 | ?>
--------------------------------------------------------------------------------
/discuz_3_2/install/portal_attachment.php:
--------------------------------------------------------------------------------
1 | fetch($id);
18 | if(empty($attach)) {
19 | showmessage('portal_attachment_noexist');
20 | }
21 |
22 | if($operation == 'delete') {
23 | if(!$_G['group']['allowmanagearticle'] && $_G['uid'] != $attach['uid']) {
24 | showmessage('portal_attachment_nopermission_delete');
25 | }
26 | if($aid) {
27 | C::t('portal_article_title')->update($aid, array('pic' => ''));
28 | }
29 | C::t('portal_attachment')->delete($id);
30 | pic_delete($attach['attachment'], 'portal', $attach['thumb'], $attach['remote']);
31 | showmessage('portal_image_noexist');
32 |
33 | } elseif($operation == 'getattach') {
34 |
35 | require_once libfile('function/attachment');
36 | if($attach['isimage']) {
37 | require_once libfile('function/home');
38 | $smallimg = pic_get($attach['attachment'], 'portal', $attach['thumb'], $attach['remote']);
39 | $bigimg = pic_get($attach['attachment'], 'portal', 0, $attach['remote']);
40 | $coverstr = addslashes(serialize(array('pic'=>'portal/'.$attach['attachment'], 'thumb'=>$attach['thumb'], 'remote'=>$attach['remote'])));
41 | }
42 | $attach['filetype'] = attachtype($attach['filetype']."\t".$attach['filetype']);
43 | $attach['filesize'] = sizecount($attach['filesize']);
44 | include template('portal/portal_attachment');
45 |
46 | exit;
47 |
48 | } else {
49 | $filename = $_G['setting']['attachdir'].'/portal/'.$attach['attachment'];
50 | if(!$attach['remote'] && !is_readable($filename)) {
51 | showmessage('attachment_nonexistence');
52 | }
53 |
54 | $readmod = 2;//read local file's function: 1=fread 2=readfile 3=fpassthru 4=fpassthru+multiple
55 | $range = 0;
56 | if($readmod == 4 && !empty($_SERVER['HTTP_RANGE'])) {
57 | list($range) = explode('-',(str_replace('bytes=', '', $_SERVER['HTTP_RANGE'])));
58 | }
59 |
60 | //Begin Of Upyun Insert Code
61 | include_once DISCUZ_ROOT . 'source/plugin/upyun/function_upyun.php';
62 | upyun_attachment_download($attach, 'portal');
63 | //End Of Upyun Insert Code
64 |
65 | $filesize = $attach['filesize'];
66 | $attach['filename'] = '"'.(strtolower(CHARSET) == 'utf-8' && strexists($_SERVER['HTTP_USER_AGENT'], 'MSIE') ? urlencode($attach['filename']) : $attach['filename']).'"';
67 |
68 | dheader('Date: '.gmdate('D, d M Y H:i:s', $attach['dateline']).' GMT');
69 | dheader('Last-Modified: '.gmdate('D, d M Y H:i:s', $attach['dateline']).' GMT');
70 | dheader('Content-Encoding: none');
71 | dheader('Content-Disposition: attachment; filename='.$attach['filename']);
72 | dheader('Content-Type: '.$attach['filetype']);
73 | dheader('Content-Length: '.$filesize);
74 |
75 | if($readmod == 4) {
76 | dheader('Accept-Ranges: bytes');
77 | if(!empty($_SERVER['HTTP_RANGE'])) {
78 | $rangesize = ($filesize - $range) > 0 ? ($filesize - $range) : 0;
79 | dheader('Content-Length: '.$rangesize);
80 | dheader('HTTP/1.1 206 Partial Content');
81 | dheader('Content-Range: bytes='.$range.'-'.($filesize-1).'/'.($filesize));
82 | }
83 | }
84 |
85 | $attach['remote'] ? getremotefile($attach['attachment']) : getlocalfile($filename, $readmod, $range);
86 | }
87 | function getremotefile($file) {
88 | global $_G;
89 | @set_time_limit(0);
90 | if(!@readfile($_G['setting']['ftp']['attachurl'].'portal/'.$file)) {
91 |
92 | $ftp = new discuz_ftp();
93 | if(!($_G['setting']['ftp']['connid'] = $ftp->connect())) {
94 | return FALSE;
95 | }
96 | $tmpfile = @tempnam($_G['setting']['attachdir'], '');
97 | if($ftp->ftp_get($_G['setting']['ftp']['connid'], $tmpfile, $file, FTP_BINARY)) {
98 | @readfile($tmpfile);
99 | @unlink($tmpfile);
100 | } else {
101 | @unlink($tmpfile);
102 | return FALSE;
103 | }
104 | }
105 | return TRUE;
106 | }
107 |
108 | function getlocalfile($filename, $readmod = 2, $range = 0) {
109 | if($readmod == 1 || $readmod == 3 || $readmod == 4) {
110 | if($fp = @fopen($filename, 'rb')) {
111 | @fseek($fp, $range);
112 | if(function_exists('fpassthru') && ($readmod == 3 || $readmod == 4)) {
113 | @fpassthru($fp);
114 | } else {
115 | echo @fread($fp, filesize($filename));
116 | }
117 | }
118 | @fclose($fp);
119 | } else {
120 | @readfile($filename);
121 | }
122 | @flush();
123 | @ob_flush();
124 | }
125 |
126 | ?>
--------------------------------------------------------------------------------
/discuz_3_2/uninstall/discuz_ftp.php:
--------------------------------------------------------------------------------
1 | set_error(0);
47 | $this->config = !$config ? getglobal('setting/ftp') : $config;
48 | $this->enabled = false;
49 | if(empty($this->config['on']) || empty($this->config['host'])) {
50 | $this->set_error(FTP_ERR_CONFIG_OFF);
51 | } else {
52 | $this->func = $this->config['ssl'] && function_exists('ftp_ssl_connect') ? 'ftp_ssl_connect' : 'ftp_connect';
53 | if($this->func == 'ftp_connect' && !function_exists('ftp_connect')) {
54 | $this->set_error(FTP_ERR_SERVER_DISABLED);
55 | } else {
56 | $this->config['host'] = discuz_ftp::clear($this->config['host']);
57 | $this->config['port'] = intval($this->config['port']);
58 | $this->config['ssl'] = intval($this->config['ssl']);
59 | $this->config['username'] = discuz_ftp::clear($this->config['username']);
60 | $this->config['password'] = authcode($this->config['password'], 'DECODE', md5(getglobal('config/security/authkey')));
61 | $this->config['timeout'] = intval($this->config['timeout']);
62 | $this->enabled = true;
63 | }
64 | }
65 | }
66 |
67 | function upload($source, $target) {
68 | if($this->error()) {
69 | return 0;
70 | }
71 | $old_dir = $this->ftp_pwd();
72 | $dirname = dirname($target);
73 | $filename = basename($target);
74 | if(!$this->ftp_chdir($dirname)) {
75 | if($this->ftp_mkdir($dirname)) {
76 | $this->ftp_chmod($dirname);
77 | if(!$this->ftp_chdir($dirname)) {
78 | $this->set_error(FTP_ERR_CHDIR);
79 | }
80 | $this->ftp_put('index.htm', getglobal('setting/attachdir').'/index.htm', FTP_BINARY);
81 | } else {
82 | $this->set_error(FTP_ERR_MKDIR);
83 | }
84 | }
85 |
86 | $res = 0;
87 | if(!$this->error()) {
88 | if($fp = @fopen($source, 'rb')) {
89 | $res = $this->ftp_fput($filename, $fp, FTP_BINARY);
90 | @fclose($fp);
91 | !$res && $this->set_error(FTP_ERR_TARGET_WRITE);
92 | } else {
93 | $this->set_error(FTP_ERR_SOURCE_READ);
94 | }
95 | }
96 |
97 | $this->ftp_chdir($old_dir);
98 |
99 | return $res ? 1 : 0;
100 | }
101 |
102 | function connect() {
103 | if(!$this->enabled || empty($this->config)) {
104 | return 0;
105 | } else {
106 | return $this->ftp_connect(
107 | $this->config['host'],
108 | $this->config['username'],
109 | $this->config['password'],
110 | $this->config['attachdir'],
111 | $this->config['port'],
112 | $this->config['timeout'],
113 | $this->config['ssl'],
114 | $this->config['pasv']
115 | );
116 | }
117 |
118 | }
119 |
120 | function ftp_connect($ftphost, $username, $password, $ftppath, $ftpport = 21, $timeout = 30, $ftpssl = 0, $ftppasv = 0) {
121 | $res = 0;
122 | $fun = $this->func;
123 | if($this->connectid = $fun($ftphost, $ftpport, 20)) {
124 |
125 | $timeout && $this->set_option(FTP_TIMEOUT_SEC, $timeout);
126 | if($this->ftp_login($username, $password)) {
127 | $this->ftp_pasv($ftppasv);
128 | if($this->ftp_chdir($ftppath)) {
129 | $res = $this->connectid;
130 | } else {
131 | $this->set_error(FTP_ERR_CHDIR);
132 | }
133 | } else {
134 | $this->set_error(FTP_ERR_USER_NO_LOGGIN);
135 | }
136 |
137 | } else {
138 | $this->set_error(FTP_ERR_CONNECT_TO_SERVER);
139 | }
140 |
141 | if($res > 0) {
142 | $this->set_error();
143 | $this->enabled = 1;
144 | } else {
145 | $this->enabled = 0;
146 | $this->ftp_close();
147 | }
148 |
149 | return $res;
150 |
151 | }
152 |
153 | function set_error($code = 0) {
154 | $this->_error = $code;
155 | }
156 |
157 | function error() {
158 | return $this->_error;
159 | }
160 |
161 | function clear($str) {
162 | return str_replace(array( "\n", "\r", '..'), '', $str);
163 | }
164 |
165 |
166 | function set_option($cmd, $value) {
167 | if(function_exists('ftp_set_option')) {
168 | return @ftp_set_option($this->connectid, $cmd, $value);
169 | }
170 | }
171 |
172 | function ftp_mkdir($directory) {
173 | $directory = discuz_ftp::clear($directory);
174 | $epath = explode('/', $directory);
175 | $dir = '';$comma = '';
176 | foreach($epath as $path) {
177 | $dir .= $comma.$path;
178 | $comma = '/';
179 | $return = @ftp_mkdir($this->connectid, $dir);
180 | $this->ftp_chmod($dir);
181 | }
182 | return $return;
183 | }
184 |
185 | function ftp_rmdir($directory) {
186 | $directory = discuz_ftp::clear($directory);
187 | return @ftp_rmdir($this->connectid, $directory);
188 | }
189 |
190 | function ftp_put($remote_file, $local_file, $mode = FTP_BINARY) {
191 | $remote_file = discuz_ftp::clear($remote_file);
192 | $local_file = discuz_ftp::clear($local_file);
193 | $mode = intval($mode);
194 | return @ftp_put($this->connectid, $remote_file, $local_file, $mode);
195 | }
196 |
197 | function ftp_fput($remote_file, $sourcefp, $mode = FTP_BINARY) {
198 | $remote_file = discuz_ftp::clear($remote_file);
199 | $mode = intval($mode);
200 | return @ftp_fput($this->connectid, $remote_file, $sourcefp, $mode);
201 | }
202 |
203 | function ftp_size($remote_file) {
204 | $remote_file = discuz_ftp::clear($remote_file);
205 | return @ftp_size($this->connectid, $remote_file);
206 | }
207 |
208 | function ftp_close() {
209 | return @ftp_close($this->connectid);
210 | }
211 |
212 | function ftp_delete($path) {
213 | $path = discuz_ftp::clear($path);
214 | return @ftp_delete($this->connectid, $path);
215 | }
216 |
217 | function ftp_get($local_file, $remote_file, $mode, $resumepos = 0) {
218 | $remote_file = discuz_ftp::clear($remote_file);
219 | $local_file = discuz_ftp::clear($local_file);
220 | $mode = intval($mode);
221 | $resumepos = intval($resumepos);
222 | return @ftp_get($this->connectid, $local_file, $remote_file, $mode, $resumepos);
223 | }
224 |
225 | function ftp_login($username, $password) {
226 | $username = $this->clear($username);
227 | $password = str_replace(array("\n", "\r"), array('', ''), $password);
228 | return @ftp_login($this->connectid, $username, $password);
229 | }
230 |
231 | function ftp_pasv($pasv) {
232 | return @ftp_pasv($this->connectid, $pasv ? true : false);
233 | }
234 |
235 | function ftp_chdir($directory) {
236 | $directory = discuz_ftp::clear($directory);
237 | return @ftp_chdir($this->connectid, $directory);
238 | }
239 |
240 | function ftp_site($cmd) {
241 | $cmd = discuz_ftp::clear($cmd);
242 | return @ftp_site($this->connectid, $cmd);
243 | }
244 |
245 | function ftp_chmod($filename, $mod = 0777) {
246 | $filename = discuz_ftp::clear($filename);
247 | if(function_exists('ftp_chmod')) {
248 | return @ftp_chmod($this->connectid, $mod, $filename);
249 | } else {
250 | return @ftp_site($this->connectid, 'CHMOD '.$mod.' '.$filename);
251 | }
252 | }
253 |
254 | function ftp_pwd() {
255 | return @ftp_pwd($this->connectid);
256 | }
257 |
258 | }
--------------------------------------------------------------------------------
/discuz_3_2/uninstall/forum_image.php:
--------------------------------------------------------------------------------
1 | fetch('aid:'.$daid, $daid, array(1, -1))) {
36 | if(!$dw && !$dh && $attach['tid'] != $id) {
37 | dheader('location: '.$_G['siteurl'].'static/image/common/none.gif');
38 | }
39 | dheader('Expires: '.gmdate('D, d M Y H:i:s', TIMESTAMP + 3600).' GMT');
40 | if($attach['remote']) {
41 | $filename = $_G['setting']['ftp']['attachurl'].'forum/'.$attach['attachment'];
42 | } else {
43 | $filename = $_G['setting']['attachdir'].'forum/'.$attach['attachment'];
44 | }
45 | require_once libfile('class/image');
46 | $img = new image;
47 | if($img->Thumb($filename, $thumbfile, $w, $h, $type)) {
48 | if($nocache) {
49 | dheader('Content-Type: image');
50 | @readfile($_G['setting']['attachdir'].$thumbfile);
51 | @unlink($_G['setting']['attachdir'].$thumbfile);
52 | } else {
53 | dheader('location: '.$attachurl.$thumbfile);
54 | }
55 | } else {
56 | dheader('Content-Type: image');
57 | @readfile($filename);
58 | }
59 | }
60 |
61 | ?>
--------------------------------------------------------------------------------
/discuz_3_2/uninstall/function_attachment.php:
--------------------------------------------------------------------------------
1 | 'unknown.gif',
18 | 2 => 'binary.gif',
19 | 3 => 'zip.gif',
20 | 4 => 'rar.gif',
21 | 5 => 'msoffice.gif',
22 | 6 => 'text.gif',
23 | 7 => 'html.gif',
24 | 8 => 'real.gif',
25 | 9 => 'av.gif',
26 | 10 => 'flash.gif',
27 | 11 => 'image.gif',
28 | 12 => 'pdf.gif',
29 | 13 => 'torrent.gif'
30 | );
31 |
32 | if(is_numeric($type)) {
33 | $typeid = $type;
34 | } else {
35 | if(preg_match("/bittorrent|^torrent\t/", $type)) {
36 | $typeid = 13;
37 | } elseif(preg_match("/pdf|^pdf\t/", $type)) {
38 | $typeid = 12;
39 | } elseif(preg_match("/image|^(jpg|gif|png|bmp)\t/", $type)) {
40 | $typeid = 11;
41 | } elseif(preg_match("/flash|^(swf|fla|flv|swi)\t/", $type)) {
42 | $typeid = 10;
43 | } elseif(preg_match("/audio|video|^(wav|mid|mp3|m3u|wma|asf|asx|vqf|mpg|mpeg|avi|wmv)\t/", $type)) {
44 | $typeid = 9;
45 | } elseif(preg_match("/real|^(ra|rm|rv)\t/", $type)) {
46 | $typeid = 8;
47 | } elseif(preg_match("/htm|^(php|js|pl|cgi|asp)\t/", $type)) {
48 | $typeid = 7;
49 | } elseif(preg_match("/text|^(txt|rtf|wri|chm)\t/", $type)) {
50 | $typeid = 6;
51 | } elseif(preg_match("/word|powerpoint|^(doc|ppt)\t/", $type)) {
52 | $typeid = 5;
53 | } elseif(preg_match("/^rar\t/", $type)) {
54 | $typeid = 4;
55 | } elseif(preg_match("/compressed|^(zip|arj|arc|cab|lzh|lha|tar|gz)\t/", $type)) {
56 | $typeid = 3;
57 | } elseif(preg_match("/octet-stream|^(exe|com|bat|dll)\t/", $type)) {
58 | $typeid = 2;
59 | } elseif($type) {
60 | $typeid = 1;
61 | } else {
62 | $typeid = 0;
63 | }
64 | }
65 | if($returnval == 'html') {
66 | return '
';
67 | } elseif($returnval == 'id') {
68 | return $typeid;
69 | }
70 | }
71 |
72 | function parseattach($attachpids, $attachtags, &$postlist, $skipaids = array()) {
73 | global $_G;
74 | if(!$attachpids) {
75 | return;
76 | }
77 | $attachpids = is_array($attachpids) ? $attachpids : array($attachpids);
78 | $attachexists = FALSE;
79 | $skipattachcode = $aids = $payaids = $findattach = array();
80 | foreach(C::t('forum_attachment_n')->fetch_all_by_id('tid:'.$_G['tid'], 'pid', $attachpids) as $attach) {
81 | $attachexists = TRUE;
82 | if($skipaids && in_array($attach['aid'], $skipaids)) {
83 | $skipattachcode[$attach[pid]][] = "/\[attach\]$attach[aid]\[\/attach\]/i";
84 | continue;
85 | }
86 | $attached = 0;
87 | $extension = strtolower(fileext($attach['filename']));
88 | $attach['ext'] = $extension;
89 | $attach['imgalt'] = $attach['isimage'] ? strip_tags(str_replace('"', '\"', $attach['description'] ? $attach['description'] : $attach['filename'])) : '';
90 | $attach['attachicon'] = attachtype($extension."\t".$attach['filetype']);
91 | $attach['attachsize'] = sizecount($attach['filesize']);
92 | if($attach['isimage'] && !$_G['setting']['attachimgpost']) {
93 | $attach['isimage'] = 0;
94 | }
95 | $attach['attachimg'] = $attach['isimage'] && (!$attach['readperm'] || $_G['group']['readaccess'] >= $attach['readperm']) ? 1 : 0;
96 | if($attach['attachimg']) {
97 | $GLOBALS['aimgs'][$attach['pid']][] = $attach['aid'];
98 | }
99 | if($attach['price']) {
100 | if($_G['setting']['maxchargespan'] && TIMESTAMP - $attach['dateline'] >= $_G['setting']['maxchargespan'] * 3600) {
101 | C::t('forum_attachment_n')->update('tid:'.$_G['tid'], $attach['aid'], array('price' => 0));
102 | $attach['price'] = 0;
103 | } elseif(!$_G['forum_attachmentdown'] && $_G['uid'] != $attach['uid']) {
104 | $payaids[$attach['aid']] = $attach['pid'];
105 | }
106 | }
107 | $attach['payed'] = $_G['forum_attachmentdown'] || $_G['uid'] == $attach['uid'] ? 1 : 0;
108 | $attach['url'] = ($attach['remote'] ? $_G['setting']['ftp']['attachurl'] : $_G['setting']['attachurl']).'forum/';
109 | $attach['dbdateline'] = $attach['dateline'];
110 | $attach['dateline'] = dgmdate($attach['dateline'], 'u');
111 | $postlist[$attach['pid']]['attachments'][$attach['aid']] = $attach;
112 | if(!defined('IN_MOBILE_API') && !empty($attachtags[$attach['pid']]) && is_array($attachtags[$attach['pid']]) && in_array($attach['aid'], $attachtags[$attach['pid']])) {
113 | $findattach[$attach['pid']][$attach['aid']] = "/\[attach\]$attach[aid]\[\/attach\]/i";
114 | $attached = 1;
115 | }
116 |
117 | if(!$attached) {
118 | if($attach['isimage']) {
119 | $postlist[$attach['pid']]['imagelist'][] = $attach['aid'];
120 | $postlist[$attach['pid']]['imagelistcount']++;
121 | if($postlist[$attach['pid']]['first']) {
122 | $GLOBALS['firstimgs'][] = $attach['aid'];
123 | }
124 | } else {
125 | if(!$_G['forum_skipaidlist'] || !in_array($attach['aid'], $_G['forum_skipaidlist'])) {
126 | $postlist[$attach['pid']]['attachlist'][] = $attach['aid'];
127 | }
128 | }
129 | }
130 | $aids[] = $attach['aid'];
131 | }
132 | if($aids) {
133 | $attachs = C::t('forum_attachment')->fetch_all($aids);
134 | foreach($attachs as $aid => $attach) {
135 | if($postlist[$attach['pid']]) {
136 | $postlist[$attach['pid']]['attachments'][$attach['aid']]['downloads'] = $attach['downloads'];
137 | }
138 | }
139 | }
140 | if($payaids) {
141 | foreach(C::t('common_credit_log')->fetch_all_by_uid_operation_relatedid($_G['uid'], 'BAC', array_keys($payaids)) as $creditlog) {
142 | $postlist[$payaids[$creditlog['relatedid']]]['attachments'][$creditlog['relatedid']]['payed'] = 1;
143 | }
144 | }
145 | if(!empty($skipattachcode)) {
146 | foreach($skipattachcode as $pid => $findskipattach) {
147 | foreach($findskipattach as $findskip) {
148 | $postlist[$pid]['message'] = preg_replace($findskip, '', $postlist[$pid]['message']);
149 | }
150 | }
151 | }
152 |
153 | if($attachexists) {
154 | foreach($attachtags as $pid => $aids) {
155 | if($findattach[$pid]) {
156 | foreach($findattach[$pid] as $aid => $find) {
157 | $postlist[$pid]['message'] = preg_replace($find, attachinpost($postlist[$pid]['attachments'][$aid], $postlist[$pid]), $postlist[$pid]['message'], 1);
158 | $postlist[$pid]['message'] = preg_replace($find, '', $postlist[$pid]['message']);
159 | }
160 | }
161 | }
162 | } else {
163 | loadcache('posttableids');
164 | $posttableids = $_G['cache']['posttableids'] ? $_G['cache']['posttableids'] : array('0');
165 | foreach($posttableids as $id) {
166 | C::t('forum_post')->update($id, $attachpids, array('attachment' => '0'), true);
167 | }
168 | }
169 | }
170 |
171 | function attachwidth($width) {
172 | global $_G;
173 | if($_G['setting']['imagemaxwidth'] && $width) {
174 | return 'class="zoom" onclick="zoom(this, this.src, 0, 0, '.($_G['setting']['showexif'] ? 1 : 0).')" width="'.($width > $_G['setting']['imagemaxwidth'] ? $_G['setting']['imagemaxwidth'] : $width).'"';
175 | } else {
176 | return 'thumbImg="1"';
177 | }
178 | }
179 |
180 | function packaids($attach) {
181 | global $_G;
182 | return aidencode($attach['aid'], 0, $_G['tid']);
183 | }
184 |
185 | function showattach($post, $type = 0) {
186 | $type = !$type ? 'attachlist' : 'imagelist';
187 | $return = '';
188 | if(!empty($post[$type]) && is_array($post[$type])) {
189 | foreach($post[$type] as $aid) {
190 | if(!empty($post['attachments'][$aid])) {
191 | $return .= $type($post['attachments'][$aid], $post['first']);
192 | }
193 | }
194 | }
195 | return $return;
196 | }
197 |
198 | function getattachexif($aid, $path = '') {
199 | global $_G;
200 | $return = $filename = '';
201 | if(!$path) {
202 | if($attach = C::t('forum_attachment_n')->fetch('aid:'.$aid, $aid, array(1, -1))) {
203 | if($attach['remote']) {
204 | $filename = $_G['setting']['ftp']['attachurl'].'forum/'.$attach['attachment'];
205 | } else {
206 | $filename = $_G['setting']['attachdir'].'forum/'.$attach['attachment'];
207 | }
208 | }
209 | } else {
210 | $filename = $path;
211 | }
212 | if($filename) {
213 | require_once libfile('function/exif');
214 | $exif = getexif($filename);
215 | $keys = array(
216 | exif_lang('Model'),
217 | exif_lang('ShutterSpeedValue'),
218 | exif_lang('ApertureValue'),
219 | exif_lang('FocalLength'),
220 | exif_lang('ExposureTime'),
221 | exif_lang('DateTimeOriginal'),
222 | exif_lang('ISOSpeedRatings'),
223 | );
224 | foreach($exif as $key => $value) {
225 | if(in_array($key, $keys)) {
226 | $return .= "$key : $value
";
227 | }
228 | }
229 | }
230 | return $return;
231 | }
232 |
233 | ?>
--------------------------------------------------------------------------------
/discuz_3_2/uninstall/portal_attachment.php:
--------------------------------------------------------------------------------
1 | fetch($id);
18 | if(empty($attach)) {
19 | showmessage('portal_attachment_noexist');
20 | }
21 |
22 | if($operation == 'delete') {
23 | if(!$_G['group']['allowmanagearticle'] && $_G['uid'] != $attach['uid']) {
24 | showmessage('portal_attachment_nopermission_delete');
25 | }
26 | if($aid) {
27 | C::t('portal_article_title')->update($aid, array('pic' => ''));
28 | }
29 | C::t('portal_attachment')->delete($id);
30 | pic_delete($attach['attachment'], 'portal', $attach['thumb'], $attach['remote']);
31 | showmessage('portal_image_noexist');
32 |
33 | } elseif($operation == 'getattach') {
34 |
35 | require_once libfile('function/attachment');
36 | if($attach['isimage']) {
37 | require_once libfile('function/home');
38 | $smallimg = pic_get($attach['attachment'], 'portal', $attach['thumb'], $attach['remote']);
39 | $bigimg = pic_get($attach['attachment'], 'portal', 0, $attach['remote']);
40 | $coverstr = addslashes(serialize(array('pic'=>'portal/'.$attach['attachment'], 'thumb'=>$attach['thumb'], 'remote'=>$attach['remote'])));
41 | }
42 | $attach['filetype'] = attachtype($attach['filetype']."\t".$attach['filetype']);
43 | $attach['filesize'] = sizecount($attach['filesize']);
44 | include template('portal/portal_attachment');
45 |
46 | exit;
47 |
48 | } else {
49 | $filename = $_G['setting']['attachdir'].'/portal/'.$attach['attachment'];
50 | if(!$attach['remote'] && !is_readable($filename)) {
51 | showmessage('attachment_nonexistence');
52 | }
53 |
54 | $readmod = 2;//read local file's function: 1=fread 2=readfile 3=fpassthru 4=fpassthru+multiple
55 | $range = 0;
56 | if($readmod == 4 && !empty($_SERVER['HTTP_RANGE'])) {
57 | list($range) = explode('-',(str_replace('bytes=', '', $_SERVER['HTTP_RANGE'])));
58 | }
59 |
60 | if($attach['remote'] && !$_G['setting']['ftp']['hideurl'] && $attach['isimage']) {
61 | dheader('location:'.$_G['setting']['ftp']['attachurl'].'portal/'.$attach['attachment']);
62 | }
63 |
64 | $filesize = $attach['filesize'];
65 | $attach['filename'] = '"'.(strtolower(CHARSET) == 'utf-8' && strexists($_SERVER['HTTP_USER_AGENT'], 'MSIE') ? urlencode($attach['filename']) : $attach['filename']).'"';
66 |
67 | dheader('Date: '.gmdate('D, d M Y H:i:s', $attach['dateline']).' GMT');
68 | dheader('Last-Modified: '.gmdate('D, d M Y H:i:s', $attach['dateline']).' GMT');
69 | dheader('Content-Encoding: none');
70 | dheader('Content-Disposition: attachment; filename='.$attach['filename']);
71 | dheader('Content-Type: '.$attach['filetype']);
72 | dheader('Content-Length: '.$filesize);
73 |
74 | if($readmod == 4) {
75 | dheader('Accept-Ranges: bytes');
76 | if(!empty($_SERVER['HTTP_RANGE'])) {
77 | $rangesize = ($filesize - $range) > 0 ? ($filesize - $range) : 0;
78 | dheader('Content-Length: '.$rangesize);
79 | dheader('HTTP/1.1 206 Partial Content');
80 | dheader('Content-Range: bytes='.$range.'-'.($filesize-1).'/'.($filesize));
81 | }
82 | }
83 |
84 | $attach['remote'] ? getremotefile($attach['attachment']) : getlocalfile($filename, $readmod, $range);
85 | }
86 | function getremotefile($file) {
87 | global $_G;
88 | @set_time_limit(0);
89 | if(!@readfile($_G['setting']['ftp']['attachurl'].'portal/'.$file)) {
90 |
91 | $ftp = new discuz_ftp();
92 | if(!($_G['setting']['ftp']['connid'] = $ftp->connect())) {
93 | return FALSE;
94 | }
95 | $tmpfile = @tempnam($_G['setting']['attachdir'], '');
96 | if($ftp->ftp_get($_G['setting']['ftp']['connid'], $tmpfile, $file, FTP_BINARY)) {
97 | @readfile($tmpfile);
98 | @unlink($tmpfile);
99 | } else {
100 | @unlink($tmpfile);
101 | return FALSE;
102 | }
103 | }
104 | return TRUE;
105 | }
106 |
107 | function getlocalfile($filename, $readmod = 2, $range = 0) {
108 | if($readmod == 1 || $readmod == 3 || $readmod == 4) {
109 | if($fp = @fopen($filename, 'rb')) {
110 | @fseek($fp, $range);
111 | if(function_exists('fpassthru') && ($readmod == 3 || $readmod == 4)) {
112 | @fpassthru($fp);
113 | } else {
114 | echo @fread($fp, filesize($filename));
115 | }
116 | }
117 | @fclose($fp);
118 | } else {
119 | @readfile($filename);
120 | }
121 | @flush();
122 | @ob_flush();
123 | }
124 |
125 | ?>
--------------------------------------------------------------------------------
/discuz_3_3/install/discuz_ftp.php:
--------------------------------------------------------------------------------
1 | set_error(0);
40 | loadcache('plugin');
41 | $this->upyun_config = getglobal('cache/plugin/upyun');
42 | $this->config = !$config ? getglobal('setting/ftp') : $config;
43 | $this->enabled = false;
44 | $this->config['host'] = discuz_ftp::clear($this->config['host']);
45 | $this->config['port'] = intval($this->config['port']);
46 | $this->config['ssl'] = intval($this->config['ssl']);
47 | $this->config['bucketname'] = $this->config['host'];
48 | $this->config['username'] = discuz_ftp::clear($this->config['username']);
49 | $this->config['password'] = authcode($this->config['password'], 'DECODE', md5(getglobal('config/security/authkey')));
50 | $this->config['timeout'] = intval($this->config['timeout']);
51 | $this->config['api_access'] = $this->api_access[$this->config['port']];
52 | $this->connectid = true;
53 | $this->enabled = true;
54 | }
55 |
56 | function upload($source, $target) {
57 | $file = new UpyunMultiPartFile($source);
58 | if($file->getSize() > 1024 * 1024 && $this->upyun_config['form_api_key']) {
59 | $sign = new UpyunMultipartSignature($this->upyun_config['form_api_key']);
60 | $upload = new UpyunMultipartUpload($sign);
61 | $upload->setBucketName($this->upyun_config['bucket_name']);
62 | $upload->setBlockSize($upload->getBlockSizeAdaptive($file));
63 | try {
64 | $result = $upload->upload($file, array(
65 | 'path' => '/' . ltrim($target, '/')
66 | ));
67 | return $result;
68 | } catch(Exception $e) {
69 | return 0;
70 | }
71 | } else {
72 | $fh = fopen($source, 'rb');
73 | if(!$fh) {
74 | return 0;
75 | }
76 | $upyun = new UpYun(
77 | $this->upyun_config['bucket_name'],
78 | $this->upyun_config['operator_name'],
79 | $this->upyun_config['operator_pwd']
80 | );
81 | $rsp = $upyun->writeFile('/'. ltrim($target, '/'), $fh, true);
82 | return $rsp;
83 | }
84 | }
85 |
86 | function connect() {
87 | return 1;
88 | }
89 |
90 | function set_error($code = 0) {
91 | $this->_error = $code;
92 | }
93 |
94 | function error() {
95 | return $this->_error;
96 | }
97 |
98 | function clear($str) {
99 | return str_replace(array( "\n", "\r", '..'), '', $str);
100 | }
101 |
102 | function ftp_rmdir($directory) {
103 | return 1;
104 | }
105 |
106 | function ftp_size($remote_file) {
107 | $upyun = new UpYun(
108 | $this->upyun_config['bucket_name'],
109 | $this->upyun_config['operator_name'],
110 | $this->upyun_config['operator_pwd']
111 | );
112 | $remote_file = discuz_ftp::clear($remote_file);
113 | try{
114 | $rsp = $upyun->getFileInfo('/' . ltrim($remote_file, '/'));
115 | return $rsp['x-upyun-file-size'];
116 | }
117 | catch(Exception $e){
118 | return -1;
119 | }
120 | }
121 |
122 | function ftp_close() {
123 | return 1;
124 | }
125 |
126 | function ftp_delete($path) {
127 | $upyun = new UpYun(
128 | $this->upyun_config['bucket_name'],
129 | $this->upyun_config['operator_name'],
130 | $this->upyun_config['operator_pwd']
131 | );
132 | $path = discuz_ftp::clear($path);
133 | try{
134 | $rsp = $upyun->delete('/' . ltrim($path, '/'));
135 | return $rsp;
136 | }
137 | catch(Exception $e){
138 | return 0;
139 | }
140 | }
141 |
142 | function ftp_get($local_file, $remote_file, $mode, $resumepos = 0) {
143 | $upyun = new UpYun(
144 | $this->upyun_config['bucket_name'],
145 | $this->upyun_config['operator_name'],
146 | $this->upyun_config['operator_pwd']
147 | );
148 | $remote_file = discuz_ftp::clear($remote_file);
149 | $local_file = discuz_ftp::clear($local_file);
150 | try{
151 | if($fh = fopen($local_file,'wb')){
152 | $rsp = $upyun->readFile('/'. ltrim($remote_file, '/'), $fh);
153 | fclose($fh);
154 | return $rsp;
155 | }else{
156 | return 0;
157 | }
158 | }
159 | catch(Exception $e){
160 | return 0;
161 | }
162 | }
163 |
164 | }
165 |
--------------------------------------------------------------------------------
/discuz_3_3/install/forum_image.php:
--------------------------------------------------------------------------------
1 | fetch('aid:'.$daid, $daid, array(1, -1))) {
36 | if(!$dw && !$dh && $attach['tid'] != $id) {
37 | dheader('location: '.$_G['siteurl'].'static/image/common/none.gif');
38 | }
39 | dheader('Expires: '.gmdate('D, d M Y H:i:s', TIMESTAMP + 3600).' GMT');
40 | if($attach['remote']) {
41 | $sign = upyun_gen_sign('/forum/'.$attach['attachment']);
42 | $filename = $_G['setting']['ftp']['attachurl'].'forum/'.$attach['attachment'] . '?_upt=' . $sign;
43 | } else {
44 | $filename = $_G['setting']['attachdir'].'forum/'.$attach['attachment'];
45 | }
46 | require_once libfile('class/image');
47 | $img = new image;
48 | if($img->Thumb($filename, $thumbfile, $w, $h, $type)) {
49 | if($nocache) {
50 | dheader('Content-Type: image');
51 | @readfile($_G['setting']['attachdir'].$thumbfile);
52 | @unlink($_G['setting']['attachdir'].$thumbfile);
53 | } else {
54 | dheader('location: '.$attachurl.$thumbfile);
55 | }
56 | } else {
57 | dheader('Content-Type: image');
58 | @readfile($filename);
59 | }
60 | }
61 |
62 | ?>
--------------------------------------------------------------------------------
/discuz_3_3/install/portal_attachment.php:
--------------------------------------------------------------------------------
1 | fetch($id);
18 | if(empty($attach)) {
19 | showmessage('portal_attachment_noexist');
20 | }
21 |
22 | if($operation == 'delete') {
23 | if(!$_G['group']['allowmanagearticle'] && $_G['uid'] != $attach['uid']) {
24 | showmessage('portal_attachment_nopermission_delete');
25 | }
26 | if($aid) {
27 | C::t('portal_article_title')->update($aid, array('pic' => ''));
28 | }
29 | C::t('portal_attachment')->delete($id);
30 | pic_delete($attach['attachment'], 'portal', $attach['thumb'], $attach['remote']);
31 | showmessage('portal_image_noexist');
32 |
33 | } elseif($operation == 'getattach') {
34 |
35 | require_once libfile('function/attachment');
36 | if($attach['isimage']) {
37 | require_once libfile('function/home');
38 | $smallimg = pic_get($attach['attachment'], 'portal', $attach['thumb'], $attach['remote']);
39 | $bigimg = pic_get($attach['attachment'], 'portal', 0, $attach['remote']);
40 | $coverstr = addslashes(serialize(array('pic'=>'portal/'.$attach['attachment'], 'thumb'=>$attach['thumb'], 'remote'=>$attach['remote'])));
41 | }
42 | $attach['filetype'] = attachtype($attach['filetype']."\t".$attach['filetype']);
43 | $attach['filesize'] = sizecount($attach['filesize']);
44 | include template('portal/portal_attachment');
45 |
46 | exit;
47 |
48 | } else {
49 | $filename = $_G['setting']['attachdir'].'/portal/'.$attach['attachment'];
50 | if(!$attach['remote'] && !is_readable($filename)) {
51 | showmessage('attachment_nonexistence');
52 | }
53 |
54 | $readmod = 2;//read local file's function: 1=fread 2=readfile 3=fpassthru 4=fpassthru+multiple
55 | $range = 0;
56 | if($readmod == 4 && !empty($_SERVER['HTTP_RANGE'])) {
57 | list($range) = explode('-',(str_replace('bytes=', '', $_SERVER['HTTP_RANGE'])));
58 | }
59 |
60 | //Begin Of Upyun Insert Code
61 | include_once DISCUZ_ROOT . 'source/plugin/upyun/function_upyun.php';
62 | upyun_attachment_download($attach, 'portal');
63 | //End Of Upyun Insert Code
64 |
65 | $filesize = $attach['filesize'];
66 | $attach['filename'] = '"'.(strtolower(CHARSET) == 'utf-8' && strexists($_SERVER['HTTP_USER_AGENT'], 'MSIE') ? urlencode($attach['filename']) : $attach['filename']).'"';
67 |
68 | dheader('Date: '.gmdate('D, d M Y H:i:s', $attach['dateline']).' GMT');
69 | dheader('Last-Modified: '.gmdate('D, d M Y H:i:s', $attach['dateline']).' GMT');
70 | dheader('Content-Encoding: none');
71 | dheader('Content-Disposition: attachment; filename='.$attach['filename']);
72 | dheader('Content-Type: '.$attach['filetype']);
73 | dheader('Content-Length: '.$filesize);
74 |
75 | if($readmod == 4) {
76 | dheader('Accept-Ranges: bytes');
77 | if(!empty($_SERVER['HTTP_RANGE'])) {
78 | $rangesize = ($filesize - $range) > 0 ? ($filesize - $range) : 0;
79 | dheader('Content-Length: '.$rangesize);
80 | dheader('HTTP/1.1 206 Partial Content');
81 | dheader('Content-Range: bytes='.$range.'-'.($filesize-1).'/'.($filesize));
82 | }
83 | }
84 |
85 | $attach['remote'] ? getremotefile($attach['attachment']) : getlocalfile($filename, $readmod, $range);
86 | }
87 | function getremotefile($file) {
88 | global $_G;
89 | @set_time_limit(0);
90 | if(!@readfile($_G['setting']['ftp']['attachurl'].'portal/'.$file)) {
91 |
92 | $ftp = new discuz_ftp();
93 | if(!($_G['setting']['ftp']['connid'] = $ftp->connect())) {
94 | return FALSE;
95 | }
96 | $tmpfile = @tempnam($_G['setting']['attachdir'], '');
97 | if($ftp->ftp_get($_G['setting']['ftp']['connid'], $tmpfile, $file, FTP_BINARY)) {
98 | @readfile($tmpfile);
99 | @unlink($tmpfile);
100 | } else {
101 | @unlink($tmpfile);
102 | return FALSE;
103 | }
104 | }
105 | return TRUE;
106 | }
107 |
108 | function getlocalfile($filename, $readmod = 2, $range = 0) {
109 | if($readmod == 1 || $readmod == 3 || $readmod == 4) {
110 | if($fp = @fopen($filename, 'rb')) {
111 | @fseek($fp, $range);
112 | if(function_exists('fpassthru') && ($readmod == 3 || $readmod == 4)) {
113 | @fpassthru($fp);
114 | } else {
115 | echo @fread($fp, filesize($filename));
116 | }
117 | }
118 | @fclose($fp);
119 | } else {
120 | @readfile($filename);
121 | }
122 | @flush();
123 | @ob_flush();
124 | }
125 |
126 | ?>
--------------------------------------------------------------------------------
/discuz_3_3/uninstall/discuz_ftp.php:
--------------------------------------------------------------------------------
1 | set_error(0);
47 | $this->config = !$config ? getglobal('setting/ftp') : $config;
48 | $this->enabled = false;
49 | if(empty($this->config['on']) || empty($this->config['host'])) {
50 | $this->set_error(FTP_ERR_CONFIG_OFF);
51 | } else {
52 | $this->func = $this->config['ssl'] && function_exists('ftp_ssl_connect') ? 'ftp_ssl_connect' : 'ftp_connect';
53 | if($this->func == 'ftp_connect' && !function_exists('ftp_connect')) {
54 | $this->set_error(FTP_ERR_SERVER_DISABLED);
55 | } else {
56 | $this->config['host'] = discuz_ftp::clear($this->config['host']);
57 | $this->config['port'] = intval($this->config['port']);
58 | $this->config['ssl'] = intval($this->config['ssl']);
59 | $this->config['username'] = discuz_ftp::clear($this->config['username']);
60 | $this->config['password'] = authcode($this->config['password'], 'DECODE', md5(getglobal('config/security/authkey')));
61 | $this->config['timeout'] = intval($this->config['timeout']);
62 | $this->enabled = true;
63 | }
64 | }
65 | }
66 |
67 | function upload($source, $target) {
68 | if($this->error()) {
69 | return 0;
70 | }
71 | $old_dir = $this->ftp_pwd();
72 | $dirname = dirname($target);
73 | $filename = basename($target);
74 | if(!$this->ftp_chdir($dirname)) {
75 | if($this->ftp_mkdir($dirname)) {
76 | $this->ftp_chmod($dirname);
77 | if(!$this->ftp_chdir($dirname)) {
78 | $this->set_error(FTP_ERR_CHDIR);
79 | }
80 | $this->ftp_put('index.htm', getglobal('setting/attachdir').'/index.htm', FTP_BINARY);
81 | } else {
82 | $this->set_error(FTP_ERR_MKDIR);
83 | }
84 | }
85 |
86 | $res = 0;
87 | if(!$this->error()) {
88 | if($fp = @fopen($source, 'rb')) {
89 | $res = $this->ftp_fput($filename, $fp, FTP_BINARY);
90 | @fclose($fp);
91 | !$res && $this->set_error(FTP_ERR_TARGET_WRITE);
92 | } else {
93 | $this->set_error(FTP_ERR_SOURCE_READ);
94 | }
95 | }
96 |
97 | $this->ftp_chdir($old_dir);
98 |
99 | return $res ? 1 : 0;
100 | }
101 |
102 | function connect() {
103 | if(!$this->enabled || empty($this->config)) {
104 | return 0;
105 | } else {
106 | return $this->ftp_connect(
107 | $this->config['host'],
108 | $this->config['username'],
109 | $this->config['password'],
110 | $this->config['attachdir'],
111 | $this->config['port'],
112 | $this->config['timeout'],
113 | $this->config['ssl'],
114 | $this->config['pasv']
115 | );
116 | }
117 |
118 | }
119 |
120 | function ftp_connect($ftphost, $username, $password, $ftppath, $ftpport = 21, $timeout = 30, $ftpssl = 0, $ftppasv = 0) {
121 | $res = 0;
122 | $fun = $this->func;
123 | if($this->connectid = $fun($ftphost, $ftpport, 20)) {
124 |
125 | $timeout && $this->set_option(FTP_TIMEOUT_SEC, $timeout);
126 | if($this->ftp_login($username, $password)) {
127 | $this->ftp_pasv($ftppasv);
128 | if($this->ftp_chdir($ftppath)) {
129 | $res = $this->connectid;
130 | } else {
131 | $this->set_error(FTP_ERR_CHDIR);
132 | }
133 | } else {
134 | $this->set_error(FTP_ERR_USER_NO_LOGGIN);
135 | }
136 |
137 | } else {
138 | $this->set_error(FTP_ERR_CONNECT_TO_SERVER);
139 | }
140 |
141 | if($res > 0) {
142 | $this->set_error();
143 | $this->enabled = 1;
144 | } else {
145 | $this->enabled = 0;
146 | $this->ftp_close();
147 | }
148 |
149 | return $res;
150 |
151 | }
152 |
153 | function set_error($code = 0) {
154 | $this->_error = $code;
155 | }
156 |
157 | function error() {
158 | return $this->_error;
159 | }
160 |
161 | function clear($str) {
162 | return str_replace(array( "\n", "\r", '..'), '', $str);
163 | }
164 |
165 |
166 | function set_option($cmd, $value) {
167 | if(function_exists('ftp_set_option')) {
168 | return @ftp_set_option($this->connectid, $cmd, $value);
169 | }
170 | }
171 |
172 | function ftp_mkdir($directory) {
173 | $directory = discuz_ftp::clear($directory);
174 | $epath = explode('/', $directory);
175 | $dir = '';$comma = '';
176 | foreach($epath as $path) {
177 | $dir .= $comma.$path;
178 | $comma = '/';
179 | $return = @ftp_mkdir($this->connectid, $dir);
180 | $this->ftp_chmod($dir);
181 | }
182 | return $return;
183 | }
184 |
185 | function ftp_rmdir($directory) {
186 | $directory = discuz_ftp::clear($directory);
187 | return @ftp_rmdir($this->connectid, $directory);
188 | }
189 |
190 | function ftp_put($remote_file, $local_file, $mode = FTP_BINARY) {
191 | $remote_file = discuz_ftp::clear($remote_file);
192 | $local_file = discuz_ftp::clear($local_file);
193 | $mode = intval($mode);
194 | return @ftp_put($this->connectid, $remote_file, $local_file, $mode);
195 | }
196 |
197 | function ftp_fput($remote_file, $sourcefp, $mode = FTP_BINARY) {
198 | $remote_file = discuz_ftp::clear($remote_file);
199 | $mode = intval($mode);
200 | return @ftp_fput($this->connectid, $remote_file, $sourcefp, $mode);
201 | }
202 |
203 | function ftp_size($remote_file) {
204 | $remote_file = discuz_ftp::clear($remote_file);
205 | return @ftp_size($this->connectid, $remote_file);
206 | }
207 |
208 | function ftp_close() {
209 | return @ftp_close($this->connectid);
210 | }
211 |
212 | function ftp_delete($path) {
213 | $path = discuz_ftp::clear($path);
214 | return @ftp_delete($this->connectid, $path);
215 | }
216 |
217 | function ftp_get($local_file, $remote_file, $mode, $resumepos = 0) {
218 | $remote_file = discuz_ftp::clear($remote_file);
219 | $local_file = discuz_ftp::clear($local_file);
220 | $mode = intval($mode);
221 | $resumepos = intval($resumepos);
222 | return @ftp_get($this->connectid, $local_file, $remote_file, $mode, $resumepos);
223 | }
224 |
225 | function ftp_login($username, $password) {
226 | $username = $this->clear($username);
227 | $password = str_replace(array("\n", "\r"), array('', ''), $password);
228 | return @ftp_login($this->connectid, $username, $password);
229 | }
230 |
231 | function ftp_pasv($pasv) {
232 | return @ftp_pasv($this->connectid, $pasv ? true : false);
233 | }
234 |
235 | function ftp_chdir($directory) {
236 | $directory = discuz_ftp::clear($directory);
237 | return @ftp_chdir($this->connectid, $directory);
238 | }
239 |
240 | function ftp_site($cmd) {
241 | $cmd = discuz_ftp::clear($cmd);
242 | return @ftp_site($this->connectid, $cmd);
243 | }
244 |
245 | function ftp_chmod($filename, $mod = 0777) {
246 | $filename = discuz_ftp::clear($filename);
247 | if(function_exists('ftp_chmod')) {
248 | return @ftp_chmod($this->connectid, $mod, $filename);
249 | } else {
250 | return @ftp_site($this->connectid, 'CHMOD '.$mod.' '.$filename);
251 | }
252 | }
253 |
254 | function ftp_pwd() {
255 | return @ftp_pwd($this->connectid);
256 | }
257 |
258 | }
--------------------------------------------------------------------------------
/discuz_3_3/uninstall/forum_image.php:
--------------------------------------------------------------------------------
1 | fetch('aid:'.$daid, $daid, array(1, -1))) {
36 | if(!$dw && !$dh && $attach['tid'] != $id) {
37 | dheader('location: '.$_G['siteurl'].'static/image/common/none.gif');
38 | }
39 | dheader('Expires: '.gmdate('D, d M Y H:i:s', TIMESTAMP + 3600).' GMT');
40 | if($attach['remote']) {
41 | $filename = $_G['setting']['ftp']['attachurl'].'forum/'.$attach['attachment'];
42 | } else {
43 | $filename = $_G['setting']['attachdir'].'forum/'.$attach['attachment'];
44 | }
45 | require_once libfile('class/image');
46 | $img = new image;
47 | if($img->Thumb($filename, $thumbfile, $w, $h, $type)) {
48 | if($nocache) {
49 | dheader('Content-Type: image');
50 | @readfile($_G['setting']['attachdir'].$thumbfile);
51 | @unlink($_G['setting']['attachdir'].$thumbfile);
52 | } else {
53 | dheader('location: '.$attachurl.$thumbfile);
54 | }
55 | } else {
56 | dheader('Content-Type: image');
57 | @readfile($filename);
58 | }
59 | }
60 |
61 | ?>
--------------------------------------------------------------------------------
/discuz_3_3/uninstall/portal_attachment.php:
--------------------------------------------------------------------------------
1 | fetch($id);
18 | if(empty($attach)) {
19 | showmessage('portal_attachment_noexist');
20 | }
21 |
22 | if($operation == 'delete') {
23 | if(!$_G['group']['allowmanagearticle'] && $_G['uid'] != $attach['uid']) {
24 | showmessage('portal_attachment_nopermission_delete');
25 | }
26 | if($aid) {
27 | C::t('portal_article_title')->update($aid, array('pic' => ''));
28 | }
29 | C::t('portal_attachment')->delete($id);
30 | pic_delete($attach['attachment'], 'portal', $attach['thumb'], $attach['remote']);
31 | showmessage('portal_image_noexist');
32 |
33 | } elseif($operation == 'getattach') {
34 |
35 | require_once libfile('function/attachment');
36 | if($attach['isimage']) {
37 | require_once libfile('function/home');
38 | $smallimg = pic_get($attach['attachment'], 'portal', $attach['thumb'], $attach['remote']);
39 | $bigimg = pic_get($attach['attachment'], 'portal', 0, $attach['remote']);
40 | $coverstr = addslashes(serialize(array('pic'=>'portal/'.$attach['attachment'], 'thumb'=>$attach['thumb'], 'remote'=>$attach['remote'])));
41 | }
42 | $attach['filetype'] = attachtype($attach['filetype']."\t".$attach['filetype']);
43 | $attach['filesize'] = sizecount($attach['filesize']);
44 | include template('portal/portal_attachment');
45 |
46 | exit;
47 |
48 | } else {
49 | $filename = $_G['setting']['attachdir'].'/portal/'.$attach['attachment'];
50 | if(!$attach['remote'] && !is_readable($filename)) {
51 | showmessage('attachment_nonexistence');
52 | }
53 |
54 | $readmod = 2;//read local file's function: 1=fread 2=readfile 3=fpassthru 4=fpassthru+multiple
55 | $range = 0;
56 | if($readmod == 4 && !empty($_SERVER['HTTP_RANGE'])) {
57 | list($range) = explode('-',(str_replace('bytes=', '', $_SERVER['HTTP_RANGE'])));
58 | }
59 |
60 | if($attach['remote'] && !$_G['setting']['ftp']['hideurl'] && $attach['isimage']) {
61 | dheader('location:'.$_G['setting']['ftp']['attachurl'].'portal/'.$attach['attachment']);
62 | }
63 |
64 | $filesize = $attach['filesize'];
65 | $attach['filename'] = '"'.(strtolower(CHARSET) == 'utf-8' && strexists($_SERVER['HTTP_USER_AGENT'], 'MSIE') ? urlencode($attach['filename']) : $attach['filename']).'"';
66 |
67 | dheader('Date: '.gmdate('D, d M Y H:i:s', $attach['dateline']).' GMT');
68 | dheader('Last-Modified: '.gmdate('D, d M Y H:i:s', $attach['dateline']).' GMT');
69 | dheader('Content-Encoding: none');
70 | dheader('Content-Disposition: attachment; filename='.$attach['filename']);
71 | dheader('Content-Type: '.$attach['filetype']);
72 | dheader('Content-Length: '.$filesize);
73 |
74 | if($readmod == 4) {
75 | dheader('Accept-Ranges: bytes');
76 | if(!empty($_SERVER['HTTP_RANGE'])) {
77 | $rangesize = ($filesize - $range) > 0 ? ($filesize - $range) : 0;
78 | dheader('Content-Length: '.$rangesize);
79 | dheader('HTTP/1.1 206 Partial Content');
80 | dheader('Content-Range: bytes='.$range.'-'.($filesize-1).'/'.($filesize));
81 | }
82 | }
83 |
84 | $attach['remote'] ? getremotefile($attach['attachment']) : getlocalfile($filename, $readmod, $range);
85 | }
86 | function getremotefile($file) {
87 | global $_G;
88 | @set_time_limit(0);
89 | if(!@readfile($_G['setting']['ftp']['attachurl'].'portal/'.$file)) {
90 |
91 | $ftp = new discuz_ftp();
92 | if(!($_G['setting']['ftp']['connid'] = $ftp->connect())) {
93 | return FALSE;
94 | }
95 | $tmpfile = @tempnam($_G['setting']['attachdir'], '');
96 | if($ftp->ftp_get($_G['setting']['ftp']['connid'], $tmpfile, $file, FTP_BINARY)) {
97 | @readfile($tmpfile);
98 | @unlink($tmpfile);
99 | } else {
100 | @unlink($tmpfile);
101 | return FALSE;
102 | }
103 | }
104 | return TRUE;
105 | }
106 |
107 | function getlocalfile($filename, $readmod = 2, $range = 0) {
108 | if($readmod == 1 || $readmod == 3 || $readmod == 4) {
109 | if($fp = @fopen($filename, 'rb')) {
110 | @fseek($fp, $range);
111 | if(function_exists('fpassthru') && ($readmod == 3 || $readmod == 4)) {
112 | @fpassthru($fp);
113 | } else {
114 | echo @fread($fp, filesize($filename));
115 | }
116 | }
117 | @fclose($fp);
118 | } else {
119 | @readfile($filename);
120 | }
121 | @flush();
122 | @ob_flush();
123 | }
124 |
125 | ?>
--------------------------------------------------------------------------------
/discuz_3_4/install/discuz_ftp.php:
--------------------------------------------------------------------------------
1 | set_error(0);
40 | loadcache('plugin');
41 | $this->upyun_config = getglobal('cache/plugin/upyun');
42 | $this->config = !$config ? getglobal('setting/ftp') : $config;
43 | $this->enabled = false;
44 | $this->config['host'] = discuz_ftp::clear($this->config['host']);
45 | $this->config['port'] = intval($this->config['port']);
46 | $this->config['ssl'] = intval($this->config['ssl']);
47 | $this->config['bucketname'] = $this->config['host'];
48 | $this->config['username'] = discuz_ftp::clear($this->config['username']);
49 | $this->config['password'] = authcode($this->config['password'], 'DECODE', md5(getglobal('config/security/authkey')));
50 | $this->config['timeout'] = intval($this->config['timeout']);
51 | $this->config['api_access'] = $this->api_access[$this->config['port']];
52 | $this->connectid = true;
53 | $this->enabled = true;
54 | }
55 |
56 | function upload($source, $target) {
57 | $file = new UpyunMultiPartFile($source);
58 | if($file->getSize() > 1024 * 1024 && $this->upyun_config['form_api_key']) {
59 | $sign = new UpyunMultipartSignature($this->upyun_config['form_api_key']);
60 | $upload = new UpyunMultipartUpload($sign);
61 | $upload->setBucketName($this->upyun_config['bucket_name']);
62 | $upload->setBlockSize($upload->getBlockSizeAdaptive($file));
63 | try {
64 | $result = $upload->upload($file, array(
65 | 'path' => '/' . ltrim($target, '/')
66 | ));
67 | return $result;
68 | } catch(Exception $e) {
69 | return 0;
70 | }
71 | } else {
72 | $fh = fopen($source, 'rb');
73 | if(!$fh) {
74 | return 0;
75 | }
76 | $upyun = new UpYun(
77 | $this->upyun_config['bucket_name'],
78 | $this->upyun_config['operator_name'],
79 | $this->upyun_config['operator_pwd']
80 | );
81 | $rsp = $upyun->writeFile('/'. ltrim($target, '/'), $fh, true);
82 | return $rsp;
83 | }
84 | }
85 |
86 | function connect() {
87 | return 1;
88 | }
89 |
90 | function set_error($code = 0) {
91 | $this->_error = $code;
92 | }
93 |
94 | function error() {
95 | return $this->_error;
96 | }
97 |
98 | function clear($str) {
99 | return str_replace(array( "\n", "\r", '..'), '', $str);
100 | }
101 |
102 | function ftp_rmdir($directory) {
103 | return 1;
104 | }
105 |
106 | function ftp_size($remote_file) {
107 | $upyun = new UpYun(
108 | $this->upyun_config['bucket_name'],
109 | $this->upyun_config['operator_name'],
110 | $this->upyun_config['operator_pwd']
111 | );
112 | $remote_file = discuz_ftp::clear($remote_file);
113 | try{
114 | $rsp = $upyun->getFileInfo('/' . ltrim($remote_file, '/'));
115 | return $rsp['x-upyun-file-size'];
116 | }
117 | catch(Exception $e){
118 | return -1;
119 | }
120 | }
121 |
122 | function ftp_close() {
123 | return 1;
124 | }
125 |
126 | function ftp_delete($path) {
127 | $upyun = new UpYun(
128 | $this->upyun_config['bucket_name'],
129 | $this->upyun_config['operator_name'],
130 | $this->upyun_config['operator_pwd']
131 | );
132 | $path = discuz_ftp::clear($path);
133 | try{
134 | $rsp = $upyun->delete('/' . ltrim($path, '/'));
135 | return $rsp;
136 | }
137 | catch(Exception $e){
138 | return 0;
139 | }
140 | }
141 |
142 | function ftp_get($local_file, $remote_file, $mode, $resumepos = 0) {
143 | $upyun = new UpYun(
144 | $this->upyun_config['bucket_name'],
145 | $this->upyun_config['operator_name'],
146 | $this->upyun_config['operator_pwd']
147 | );
148 | $remote_file = discuz_ftp::clear($remote_file);
149 | $local_file = discuz_ftp::clear($local_file);
150 | try{
151 | if($fh = fopen($local_file,'wb')){
152 | $rsp = $upyun->readFile('/'. ltrim($remote_file, '/'), $fh);
153 | fclose($fh);
154 | return $rsp;
155 | }else{
156 | return 0;
157 | }
158 | }
159 | catch(Exception $e){
160 | return 0;
161 | }
162 | }
163 |
164 | }
165 |
--------------------------------------------------------------------------------
/discuz_3_4/install/forum_image.php:
--------------------------------------------------------------------------------
1 | fetch('aid:'.$daid, $daid, array(1, -1))) {
36 | if(!$dw && !$dh && $attach['tid'] != $id) {
37 | dheader('location: '.$_G['siteurl'].'static/image/common/none.gif');
38 | }
39 | dheader('Expires: '.gmdate('D, d M Y H:i:s', TIMESTAMP + 3600).' GMT');
40 | if($attach['remote']) {
41 | $sign = upyun_gen_sign('/forum/'.$attach['attachment']);
42 | $filename = $_G['setting']['ftp']['attachurl'].'forum/'.$attach['attachment'] . '?_upt=' . $sign;
43 | } else {
44 | $filename = $_G['setting']['attachdir'].'forum/'.$attach['attachment'];
45 | }
46 | require_once libfile('class/image');
47 | $img = new image;
48 | if($img->Thumb($filename, $thumbfile, $w, $h, $type)) {
49 | if($nocache) {
50 | dheader('Content-Type: image');
51 | @readfile($_G['setting']['attachdir'].$thumbfile);
52 | @unlink($_G['setting']['attachdir'].$thumbfile);
53 | } else {
54 | dheader('location: '.$attachurl.$thumbfile);
55 | }
56 | } else {
57 | dheader('Content-Type: image');
58 | @readfile($filename);
59 | }
60 | }
61 |
62 | ?>
--------------------------------------------------------------------------------
/discuz_3_4/install/portal_attachment.php:
--------------------------------------------------------------------------------
1 | fetch($id);
18 | if(empty($attach)) {
19 | showmessage('portal_attachment_noexist');
20 | }
21 |
22 | if($operation == 'delete') {
23 | if(!$_G['group']['allowmanagearticle'] && $_G['uid'] != $attach['uid']) {
24 | showmessage('portal_attachment_nopermission_delete');
25 | }
26 | if($aid) {
27 | C::t('portal_article_title')->update($aid, array('pic' => ''));
28 | }
29 | C::t('portal_attachment')->delete($id);
30 | pic_delete($attach['attachment'], 'portal', $attach['thumb'], $attach['remote']);
31 | showmessage('portal_image_noexist');
32 |
33 | } elseif($operation == 'getattach') {
34 |
35 | require_once libfile('function/attachment');
36 | if($attach['isimage']) {
37 | require_once libfile('function/home');
38 | $smallimg = pic_get($attach['attachment'], 'portal', $attach['thumb'], $attach['remote']);
39 | $bigimg = pic_get($attach['attachment'], 'portal', 0, $attach['remote']);
40 | $coverstr = addslashes(serialize(array('pic'=>'portal/'.$attach['attachment'], 'thumb'=>$attach['thumb'], 'remote'=>$attach['remote'])));
41 | }
42 | $attach['filetype'] = attachtype($attach['filetype']."\t".$attach['filetype']);
43 | $attach['filesize'] = sizecount($attach['filesize']);
44 | include template('portal/portal_attachment');
45 |
46 | exit;
47 |
48 | } else {
49 | $filename = $_G['setting']['attachdir'].'/portal/'.$attach['attachment'];
50 | if(!$attach['remote'] && !is_readable($filename)) {
51 | showmessage('attachment_nonexistence');
52 | }
53 |
54 | $readmod = 2;//read local file's function: 1=fread 2=readfile 3=fpassthru 4=fpassthru+multiple
55 | $range = 0;
56 | if($readmod == 4 && !empty($_SERVER['HTTP_RANGE'])) {
57 | list($range) = explode('-',(str_replace('bytes=', '', $_SERVER['HTTP_RANGE'])));
58 | }
59 |
60 | //Begin Of Upyun Insert Code
61 | include_once DISCUZ_ROOT . 'source/plugin/upyun/function_upyun.php';
62 | upyun_attachment_download($attach, 'portal');
63 | //End Of Upyun Insert Code
64 |
65 | $filesize = $attach['filesize'];
66 | $attach['filename'] = '"'.(strtolower(CHARSET) == 'utf-8' && strexists($_SERVER['HTTP_USER_AGENT'], 'MSIE') ? urlencode($attach['filename']) : $attach['filename']).'"';
67 |
68 | dheader('Date: '.gmdate('D, d M Y H:i:s', $attach['dateline']).' GMT');
69 | dheader('Last-Modified: '.gmdate('D, d M Y H:i:s', $attach['dateline']).' GMT');
70 | dheader('Content-Encoding: none');
71 | dheader('Content-Disposition: attachment; filename='.$attach['filename']);
72 | dheader('Content-Type: '.$attach['filetype']);
73 | dheader('Content-Length: '.$filesize);
74 |
75 | if($readmod == 4) {
76 | dheader('Accept-Ranges: bytes');
77 | if(!empty($_SERVER['HTTP_RANGE'])) {
78 | $rangesize = ($filesize - $range) > 0 ? ($filesize - $range) : 0;
79 | dheader('Content-Length: '.$rangesize);
80 | dheader('HTTP/1.1 206 Partial Content');
81 | dheader('Content-Range: bytes='.$range.'-'.($filesize-1).'/'.($filesize));
82 | }
83 | }
84 |
85 | $attach['remote'] ? getremotefile($attach['attachment']) : getlocalfile($filename, $readmod, $range);
86 | }
87 | function getremotefile($file) {
88 | global $_G;
89 | @set_time_limit(0);
90 | if(!@readfile($_G['setting']['ftp']['attachurl'].'portal/'.$file)) {
91 |
92 | $ftp = new discuz_ftp();
93 | if(!($_G['setting']['ftp']['connid'] = $ftp->connect())) {
94 | return FALSE;
95 | }
96 | $tmpfile = @tempnam($_G['setting']['attachdir'], '');
97 | if($ftp->ftp_get($_G['setting']['ftp']['connid'], $tmpfile, $file, FTP_BINARY)) {
98 | @readfile($tmpfile);
99 | @unlink($tmpfile);
100 | } else {
101 | @unlink($tmpfile);
102 | return FALSE;
103 | }
104 | }
105 | return TRUE;
106 | }
107 |
108 | function getlocalfile($filename, $readmod = 2, $range = 0) {
109 | if($readmod == 1 || $readmod == 3 || $readmod == 4) {
110 | if($fp = @fopen($filename, 'rb')) {
111 | @fseek($fp, $range);
112 | if(function_exists('fpassthru') && ($readmod == 3 || $readmod == 4)) {
113 | @fpassthru($fp);
114 | } else {
115 | echo @fread($fp, filesize($filename));
116 | }
117 | }
118 | @fclose($fp);
119 | } else {
120 | @readfile($filename);
121 | }
122 | @flush();
123 | @ob_flush();
124 | }
125 |
126 | ?>
--------------------------------------------------------------------------------
/discuz_3_4/uninstall/discuz_ftp.php:
--------------------------------------------------------------------------------
1 | set_error(0);
47 | $this->config = !$config ? getglobal('setting/ftp') : $config;
48 | $this->enabled = false;
49 | if(empty($this->config['on']) || empty($this->config['host'])) {
50 | $this->set_error(FTP_ERR_CONFIG_OFF);
51 | } else {
52 | $this->func = $this->config['ssl'] && function_exists('ftp_ssl_connect') ? 'ftp_ssl_connect' : 'ftp_connect';
53 | if($this->func == 'ftp_connect' && !function_exists('ftp_connect')) {
54 | $this->set_error(FTP_ERR_SERVER_DISABLED);
55 | } else {
56 | $this->config['host'] = discuz_ftp::clear($this->config['host']);
57 | $this->config['port'] = intval($this->config['port']);
58 | $this->config['ssl'] = intval($this->config['ssl']);
59 | $this->config['username'] = discuz_ftp::clear($this->config['username']);
60 | $this->config['password'] = authcode($this->config['password'], 'DECODE', md5(getglobal('config/security/authkey')));
61 | $this->config['timeout'] = intval($this->config['timeout']);
62 | $this->enabled = true;
63 | }
64 | }
65 | }
66 |
67 | function upload($source, $target) {
68 | if($this->error()) {
69 | return 0;
70 | }
71 | $old_dir = $this->ftp_pwd();
72 | $dirname = dirname($target);
73 | $filename = basename($target);
74 | if(!$this->ftp_chdir($dirname)) {
75 | if($this->ftp_mkdir($dirname)) {
76 | $this->ftp_chmod($dirname);
77 | if(!$this->ftp_chdir($dirname)) {
78 | $this->set_error(FTP_ERR_CHDIR);
79 | }
80 | $this->ftp_put('index.htm', getglobal('setting/attachdir').'/index.htm', FTP_BINARY);
81 | } else {
82 | $this->set_error(FTP_ERR_MKDIR);
83 | }
84 | }
85 |
86 | $res = 0;
87 | if(!$this->error()) {
88 | if($fp = @fopen($source, 'rb')) {
89 | $res = $this->ftp_fput($filename, $fp, FTP_BINARY);
90 | @fclose($fp);
91 | !$res && $this->set_error(FTP_ERR_TARGET_WRITE);
92 | } else {
93 | $this->set_error(FTP_ERR_SOURCE_READ);
94 | }
95 | }
96 |
97 | $this->ftp_chdir($old_dir);
98 |
99 | return $res ? 1 : 0;
100 | }
101 |
102 | function connect() {
103 | if(!$this->enabled || empty($this->config)) {
104 | return 0;
105 | } else {
106 | return $this->ftp_connect(
107 | $this->config['host'],
108 | $this->config['username'],
109 | $this->config['password'],
110 | $this->config['attachdir'],
111 | $this->config['port'],
112 | $this->config['timeout'],
113 | $this->config['ssl'],
114 | $this->config['pasv']
115 | );
116 | }
117 |
118 | }
119 |
120 | function ftp_connect($ftphost, $username, $password, $ftppath, $ftpport = 21, $timeout = 30, $ftpssl = 0, $ftppasv = 0) {
121 | $res = 0;
122 | $fun = $this->func;
123 | if($this->connectid = $fun($ftphost, $ftpport, 20)) {
124 |
125 | $timeout && $this->set_option(FTP_TIMEOUT_SEC, $timeout);
126 | if($this->ftp_login($username, $password)) {
127 | $this->ftp_pasv($ftppasv);
128 | if($this->ftp_chdir($ftppath)) {
129 | $res = $this->connectid;
130 | } else {
131 | $this->set_error(FTP_ERR_CHDIR);
132 | }
133 | } else {
134 | $this->set_error(FTP_ERR_USER_NO_LOGGIN);
135 | }
136 |
137 | } else {
138 | $this->set_error(FTP_ERR_CONNECT_TO_SERVER);
139 | }
140 |
141 | if($res > 0) {
142 | $this->set_error();
143 | $this->enabled = 1;
144 | } else {
145 | $this->enabled = 0;
146 | $this->ftp_close();
147 | }
148 |
149 | return $res;
150 |
151 | }
152 |
153 | function set_error($code = 0) {
154 | $this->_error = $code;
155 | }
156 |
157 | function error() {
158 | return $this->_error;
159 | }
160 |
161 | function clear($str) {
162 | return str_replace(array( "\n", "\r", '..'), '', $str);
163 | }
164 |
165 |
166 | function set_option($cmd, $value) {
167 | if(function_exists('ftp_set_option')) {
168 | return @ftp_set_option($this->connectid, $cmd, $value);
169 | }
170 | }
171 |
172 | function ftp_mkdir($directory) {
173 | $directory = discuz_ftp::clear($directory);
174 | $epath = explode('/', $directory);
175 | $dir = '';$comma = '';
176 | foreach($epath as $path) {
177 | $dir .= $comma.$path;
178 | $comma = '/';
179 | $return = @ftp_mkdir($this->connectid, $dir);
180 | $this->ftp_chmod($dir);
181 | }
182 | return $return;
183 | }
184 |
185 | function ftp_rmdir($directory) {
186 | $directory = discuz_ftp::clear($directory);
187 | return @ftp_rmdir($this->connectid, $directory);
188 | }
189 |
190 | function ftp_put($remote_file, $local_file, $mode = FTP_BINARY) {
191 | $remote_file = discuz_ftp::clear($remote_file);
192 | $local_file = discuz_ftp::clear($local_file);
193 | $mode = intval($mode);
194 | return @ftp_put($this->connectid, $remote_file, $local_file, $mode);
195 | }
196 |
197 | function ftp_fput($remote_file, $sourcefp, $mode = FTP_BINARY) {
198 | $remote_file = discuz_ftp::clear($remote_file);
199 | $mode = intval($mode);
200 | return @ftp_fput($this->connectid, $remote_file, $sourcefp, $mode);
201 | }
202 |
203 | function ftp_size($remote_file) {
204 | $remote_file = discuz_ftp::clear($remote_file);
205 | return @ftp_size($this->connectid, $remote_file);
206 | }
207 |
208 | function ftp_close() {
209 | return @ftp_close($this->connectid);
210 | }
211 |
212 | function ftp_delete($path) {
213 | $path = discuz_ftp::clear($path);
214 | return @ftp_delete($this->connectid, $path);
215 | }
216 |
217 | function ftp_get($local_file, $remote_file, $mode, $resumepos = 0) {
218 | $remote_file = discuz_ftp::clear($remote_file);
219 | $local_file = discuz_ftp::clear($local_file);
220 | $mode = intval($mode);
221 | $resumepos = intval($resumepos);
222 | return @ftp_get($this->connectid, $local_file, $remote_file, $mode, $resumepos);
223 | }
224 |
225 | function ftp_login($username, $password) {
226 | $username = $this->clear($username);
227 | $password = str_replace(array("\n", "\r"), array('', ''), $password);
228 | return @ftp_login($this->connectid, $username, $password);
229 | }
230 |
231 | function ftp_pasv($pasv) {
232 | return @ftp_pasv($this->connectid, $pasv ? true : false);
233 | }
234 |
235 | function ftp_chdir($directory) {
236 | $directory = discuz_ftp::clear($directory);
237 | return @ftp_chdir($this->connectid, $directory);
238 | }
239 |
240 | function ftp_site($cmd) {
241 | $cmd = discuz_ftp::clear($cmd);
242 | return @ftp_site($this->connectid, $cmd);
243 | }
244 |
245 | function ftp_chmod($filename, $mod = 0777) {
246 | $filename = discuz_ftp::clear($filename);
247 | if(function_exists('ftp_chmod')) {
248 | return @ftp_chmod($this->connectid, $mod, $filename);
249 | } else {
250 | return @ftp_site($this->connectid, 'CHMOD '.$mod.' '.$filename);
251 | }
252 | }
253 |
254 | function ftp_pwd() {
255 | return @ftp_pwd($this->connectid);
256 | }
257 |
258 | }
--------------------------------------------------------------------------------
/discuz_3_4/uninstall/forum_image.php:
--------------------------------------------------------------------------------
1 | fetch('aid:'.$daid, $daid, array(1, -1))) {
36 | if(!$dw && !$dh && $attach['tid'] != $id) {
37 | dheader('location: '.$_G['siteurl'].'static/image/common/none.gif');
38 | }
39 | dheader('Expires: '.gmdate('D, d M Y H:i:s', TIMESTAMP + 3600).' GMT');
40 | if($attach['remote']) {
41 | $filename = $_G['setting']['ftp']['attachurl'].'forum/'.$attach['attachment'];
42 | } else {
43 | $filename = $_G['setting']['attachdir'].'forum/'.$attach['attachment'];
44 | }
45 | require_once libfile('class/image');
46 | $img = new image;
47 | if($img->Thumb($filename, $thumbfile, $w, $h, $type)) {
48 | if($nocache) {
49 | dheader('Content-Type: image');
50 | @readfile($_G['setting']['attachdir'].$thumbfile);
51 | @unlink($_G['setting']['attachdir'].$thumbfile);
52 | } else {
53 | dheader('location: '.$attachurl.$thumbfile);
54 | }
55 | } else {
56 | dheader('Content-Type: image');
57 | @readfile($filename);
58 | }
59 | }
60 |
61 | ?>
--------------------------------------------------------------------------------
/discuz_3_4/uninstall/portal_attachment.php:
--------------------------------------------------------------------------------
1 | fetch($id);
18 | if(empty($attach)) {
19 | showmessage('portal_attachment_noexist');
20 | }
21 |
22 | if($operation == 'delete') {
23 | if(!$_G['group']['allowmanagearticle'] && $_G['uid'] != $attach['uid']) {
24 | showmessage('portal_attachment_nopermission_delete');
25 | }
26 | if($aid) {
27 | C::t('portal_article_title')->update($aid, array('pic' => ''));
28 | }
29 | C::t('portal_attachment')->delete($id);
30 | pic_delete($attach['attachment'], 'portal', $attach['thumb'], $attach['remote']);
31 | showmessage('portal_image_noexist');
32 |
33 | } elseif($operation == 'getattach') {
34 |
35 | require_once libfile('function/attachment');
36 | if($attach['isimage']) {
37 | require_once libfile('function/home');
38 | $smallimg = pic_get($attach['attachment'], 'portal', $attach['thumb'], $attach['remote']);
39 | $bigimg = pic_get($attach['attachment'], 'portal', 0, $attach['remote']);
40 | $coverstr = addslashes(serialize(array('pic'=>'portal/'.$attach['attachment'], 'thumb'=>$attach['thumb'], 'remote'=>$attach['remote'])));
41 | }
42 | $attach['filetype'] = attachtype($attach['filetype']."\t".$attach['filetype']);
43 | $attach['filesize'] = sizecount($attach['filesize']);
44 | include template('portal/portal_attachment');
45 |
46 | exit;
47 |
48 | } else {
49 | $filename = $_G['setting']['attachdir'].'/portal/'.$attach['attachment'];
50 | if(!$attach['remote'] && !is_readable($filename)) {
51 | showmessage('attachment_nonexistence');
52 | }
53 |
54 | $readmod = 2;//read local file's function: 1=fread 2=readfile 3=fpassthru 4=fpassthru+multiple
55 | $range = 0;
56 | if($readmod == 4 && !empty($_SERVER['HTTP_RANGE'])) {
57 | list($range) = explode('-',(str_replace('bytes=', '', $_SERVER['HTTP_RANGE'])));
58 | }
59 |
60 | if($attach['remote'] && !$_G['setting']['ftp']['hideurl'] && $attach['isimage']) {
61 | dheader('location:'.$_G['setting']['ftp']['attachurl'].'portal/'.$attach['attachment']);
62 | }
63 |
64 | $filesize = $attach['filesize'];
65 | $attach['filename'] = '"'.(strtolower(CHARSET) == 'utf-8' && strexists($_SERVER['HTTP_USER_AGENT'], 'MSIE') ? urlencode($attach['filename']) : $attach['filename']).'"';
66 |
67 | dheader('Date: '.gmdate('D, d M Y H:i:s', $attach['dateline']).' GMT');
68 | dheader('Last-Modified: '.gmdate('D, d M Y H:i:s', $attach['dateline']).' GMT');
69 | dheader('Content-Encoding: none');
70 | dheader('Content-Disposition: attachment; filename='.$attach['filename']);
71 | dheader('Content-Type: '.$attach['filetype']);
72 | dheader('Content-Length: '.$filesize);
73 |
74 | if($readmod == 4) {
75 | dheader('Accept-Ranges: bytes');
76 | if(!empty($_SERVER['HTTP_RANGE'])) {
77 | $rangesize = ($filesize - $range) > 0 ? ($filesize - $range) : 0;
78 | dheader('Content-Length: '.$rangesize);
79 | dheader('HTTP/1.1 206 Partial Content');
80 | dheader('Content-Range: bytes='.$range.'-'.($filesize-1).'/'.($filesize));
81 | }
82 | }
83 |
84 | $attach['remote'] ? getremotefile($attach['attachment']) : getlocalfile($filename, $readmod, $range);
85 | }
86 | function getremotefile($file) {
87 | global $_G;
88 | @set_time_limit(0);
89 | if(!@readfile($_G['setting']['ftp']['attachurl'].'portal/'.$file)) {
90 |
91 | $ftp = new discuz_ftp();
92 | if(!($_G['setting']['ftp']['connid'] = $ftp->connect())) {
93 | return FALSE;
94 | }
95 | $tmpfile = @tempnam($_G['setting']['attachdir'], '');
96 | if($ftp->ftp_get($_G['setting']['ftp']['connid'], $tmpfile, $file, FTP_BINARY)) {
97 | @readfile($tmpfile);
98 | @unlink($tmpfile);
99 | } else {
100 | @unlink($tmpfile);
101 | return FALSE;
102 | }
103 | }
104 | return TRUE;
105 | }
106 |
107 | function getlocalfile($filename, $readmod = 2, $range = 0) {
108 | if($readmod == 1 || $readmod == 3 || $readmod == 4) {
109 | if($fp = @fopen($filename, 'rb')) {
110 | @fseek($fp, $range);
111 | if(function_exists('fpassthru') && ($readmod == 3 || $readmod == 4)) {
112 | @fpassthru($fp);
113 | } else {
114 | echo @fread($fp, filesize($filename));
115 | }
116 | }
117 | @fclose($fp);
118 | } else {
119 | @readfile($filename);
120 | }
121 | @flush();
122 | @ob_flush();
123 | }
124 |
125 | ?>
--------------------------------------------------------------------------------
/discuz_plugin_upyun_SC_GBK.xml:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/upyun/discuz-plugin/228ff7f5ea86e89534e6e97867beacfa48e44036/discuz_plugin_upyun_SC_GBK.xml
--------------------------------------------------------------------------------
/discuz_plugin_upyun_SC_UTF8.xml:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/discuz_plugin_upyun_TC_BIG5.xml:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/upyun/discuz-plugin/228ff7f5ea86e89534e6e97867beacfa48e44036/discuz_plugin_upyun_TC_BIG5.xml
--------------------------------------------------------------------------------
/discuz_plugin_upyun_TC_UTF8.xml:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/function_upyun.php:
--------------------------------------------------------------------------------
1 | 'd2343fb3bea0e16b574a1ea601a9f871',
134 | 'forum_attachment.php' => 'df9a7925d66ed5aa69e87a713d9aed9e',
135 | 'function_attachment.php' => '7fd243cd20ec44c2033401535828c6c4',
136 | 'function_home.php' => 'd3b81c420b7e98158fa2a818399969b1',
137 | 'portal_attachment.php' => 'e5fc1bbd71d087e81243f45e61219d50',
138 | 'forum_image.php' => '044aabe6823ceff3bd01b082776d5fe5',
139 | 'function_post.php' => '3c9043052af1e66010dffd9874257cd9',
140 | );
141 | break;
142 | case 'X3.1':
143 | return array(
144 | 'discuz_ftp.php' => 'd2343fb3bea0e16b574a1ea601a9f871',
145 | 'forum_attachment.php' => '207db1330d130f4425ad0bfa5b5064d5',
146 | 'function_attachment.php' => '7fd243cd20ec44c2033401535828c6c4',
147 | 'function_home.php' => 'd3b81c420b7e98158fa2a818399969b1',
148 | 'portal_attachment.php' => 'e5fc1bbd71d087e81243f45e61219d50',
149 | 'forum_image.php' => '044aabe6823ceff3bd01b082776d5fe5',
150 | 'function_post.php' => '3c9043052af1e66010dffd9874257cd9',
151 | );
152 | break;
153 | case 'X3.2':
154 | return array(
155 | 'discuz_ftp.php' => 'd2343fb3bea0e16b574a1ea601a9f871',
156 | 'forum_attachment.php' => '015002fd98d4ef2d509142d5ac97b256',
157 | 'function_attachment.php' => '7fd243cd20ec44c2033401535828c6c4',
158 | 'function_home.php' => 'd3b81c420b7e98158fa2a818399969b1',
159 | 'portal_attachment.php' => 'e5fc1bbd71d087e81243f45e61219d50',
160 | 'forum_image.php' => '044aabe6823ceff3bd01b082776d5fe5',
161 | 'function_post.php' => '3c9043052af1e66010dffd9874257cd9',
162 | );
163 | break;
164 | case 'X3.3':
165 | return array(
166 | 'discuz_ftp.php' => 'd2343fb3bea0e16b574a1ea601a9f871',
167 | 'forum_attachment.php' => '015002fd98d4ef2d509142d5ac97b256',
168 | 'forum_image.php' => '044aabe6823ceff3bd01b082776d5fe5',
169 | 'function_attachment.php' => '9d5abc171193da52e2cebcf12f17500a',
170 | 'function_home.php' => '3f4f0ced4056653bce3d976708d6858a',
171 | 'function_post.php' => '21f02c43de97c3685e774fd8b7f7ac9e',
172 | 'portal_attachment.php' => 'e5fc1bbd71d087e81243f45e61219d50',
173 | );
174 | break;
175 | case 'X3.4':
176 | return array(
177 | 'discuz_ftp.php' => 'd2343fb3bea0e16b574a1ea601a9f871',
178 | 'forum_attachment.php' => '016a8b55f747a5855ed60b0bb0ba908a',
179 | 'forum_image.php' => '044aabe6823ceff3bd01b082776d5fe5',
180 | 'function_attachment.php' => '9d5abc171193da52e2cebcf12f17500a',
181 | 'function_home.php' => '7785b5a8a332617b6f929b17f6bb7250',
182 | 'function_post.php' => '21f02c43de97c3685e774fd8b7f7ac9e',
183 | 'portal_attachment.php' => 'e5fc1bbd71d087e81243f45e61219d50',
184 | );
185 | break;
186 | default:
187 | return array();
188 | }
189 | }
190 |
191 | /**
192 | * 将换行符统一处理为 \r\n 再生成 md5
193 | * @param $path: 文件路径
194 | * @return bool|string
195 | */
196 | function upyun_md5_file($path) {
197 | $f = file_get_contents($path);
198 | if(!$f) {
199 | return false;
200 | }
201 |
202 | return md5(preg_replace("/(?realPath = realpath($path);
55 | if(!($this->realPath && file_exists($this->realPath))) {
56 | throw new Exception('upload file not exists: ' . $path);
57 | }
58 | $this->size = filesize($path);
59 | $this->md5FileHash = md5_file($this->realPath);
60 | }
61 |
62 | public function getSize()
63 | {
64 | return $this->size;
65 | }
66 |
67 | public function getMd5FileHash()
68 | {
69 | return $this->md5FileHash;
70 | }
71 |
72 | public function getHandler()
73 | {
74 | if(is_resource($this->handler) === false) {
75 | $this->handler = fopen($this->realPath, 'rb');
76 | }
77 | return $this->handler;
78 | }
79 |
80 | /**
81 | * 读取文件块
82 | * @param $currentPosition: 文件当前读取位置
83 | * @param $endPosition: 文件读取结束位置
84 | * @param int $len: 每次读取的字节数
85 | * @return string
86 | */
87 | public function readBlock($currentPosition, $endPosition, $len = 8192)
88 | {
89 | $data = '';
90 | while($currentPosition < $endPosition) {
91 | if($currentPosition + $len > $endPosition) {
92 | $len = $endPosition - $currentPosition;
93 | }
94 |
95 | fseek($this->getHandler(), $currentPosition);
96 | $data .= fread($this->getHandler(), $len);
97 | $currentPosition = $currentPosition + $len;
98 | }
99 | return $data;
100 | }
101 |
102 | public function getRealPath()
103 | {
104 | return $this->realPath;
105 | }
106 |
107 | public function __destruct()
108 | {
109 | if(is_resource($this->handler)) {
110 | fclose($this->handler);
111 | }
112 | }
113 | }
114 |
--------------------------------------------------------------------------------
/sdk/upyun_multipart_upload/Signature.php:
--------------------------------------------------------------------------------
1 | setFormApiKey($formApiKey);
52 | $this->paramsKey = array('path', 'content_type', 'content_length',
53 | 'image_width', 'image_height', 'image_frames',
54 | 'last_modified', 'signature');
55 | }
56 |
57 | public function setFormApiKey($key)
58 | {
59 | $this->formApiKey = $key;
60 | }
61 |
62 | public function setTokenSecret($key)
63 | {
64 | $this->tokenSecret = $key;
65 | }
66 |
67 | /**
68 | * 生成签名
69 | * @param $data
70 | * @param bool $isFormApiKey: 签名生成方式 e.g: true 使用表单API的key生成
71 | * @return bool|string
72 | */
73 | public function createSign($data, $isFormApiKey = true)
74 | {
75 | if(is_array($data)) {
76 | ksort($data);
77 | $string = '';
78 | foreach($data as $k => $v) {
79 | $string .= "$k$v";
80 | }
81 | $string .= $isFormApiKey ? $this->formApiKey : $this->tokenSecret;
82 | $sign = md5($string);
83 | return $sign;
84 | }
85 | return false;
86 | }
87 |
88 | /**
89 | * 获取 Policy 值
90 | * @param $metaData
91 | * @return bool|string
92 | */
93 | public function createPolicy($metaData)
94 | {
95 | if(is_array($metaData)) {
96 | $jsonStr = json_encode($metaData);
97 | return base64_encode($jsonStr);
98 | }
99 | return false;
100 | }
101 |
102 | /**
103 | * 验证回调签名
104 | * @param $data
105 | * @param bool $isFormApiKey
106 | * @return bool
107 | */
108 | protected function validateSign($data, $isFormApiKey = true)
109 | {
110 | if(! isset($data['signature'])) {
111 | return false;
112 | }
113 |
114 | $sign = $data['signature'];
115 | unset($data['signature']);
116 |
117 | return $this->createSign($data, $isFormApiKey) === $sign;
118 | }
119 |
120 | /**
121 | * 客户端同步跳转回调验证
122 | * @return bool
123 | */
124 | public function returnValidate()
125 | {
126 | $data = array();
127 | foreach($this->paramsKey as $key) {
128 | if(isset($_GET[$key])) {
129 | $data[$key] = $_GET[$key];
130 | }
131 | }
132 | return $this->validateSign($data);
133 | }
134 | /**
135 | * 异步通知回调验证
136 | * @return bool
137 | */
138 | public function notifyValidate()
139 | {
140 | $data = array();
141 | foreach($this->paramsKey as $key) {
142 | if(isset($_POST[$key])) {
143 | $data[$key] = $_GET[$key];
144 | }
145 | }
146 | return $this->validateSign($data);
147 | }
148 |
149 | /**
150 | * 服务端直接返回 json验证
151 | * @param $data: 服务端返回的待验证数据
152 | * @return bool
153 | */
154 | public function syncJsonValidate($data)
155 | {
156 | return $this->validateSign($data, true);
157 | }
158 | }
--------------------------------------------------------------------------------
/sdk/upyun_multipart_upload/Util/MultiPartPost.php:
--------------------------------------------------------------------------------
1 | $content) {
40 | if(is_array($content)) {
41 | $data .= "--" . $delimiter . "\r\n";
42 | $filename = isset($content['name']) ? $content['name'] : $name;
43 | $data .= 'Content-Disposition: form-data; name="' . $name . '"; filename="' . $filename . "\" \r\n";
44 | $type = isset($content['type']) ? $content['type'] : 'application/octet-stream';
45 | $data .= 'Content-Type: ' . $type . "\r\n\r\n";
46 | $data .= $content['data'] . "\r\n";
47 | } else {
48 | $data .= "--" . $delimiter . "\r\n";
49 | $data .= 'Content-Disposition: form-data; name="' . $name . '"';
50 | $data .= "\r\n\r\n" . $content . "\r\n";
51 | }
52 | }
53 | $data .= "--" . $delimiter . "--";
54 |
55 | $handle = curl_init($url);
56 | curl_setopt($handle, CURLOPT_POST, true);
57 | curl_setopt($handle, CURLOPT_HTTPHEADER , array(
58 | 'Content-Type: multipart/form-data; boundary=' . $delimiter,
59 | 'Content-Length: ' . strlen($data))
60 | );
61 | curl_setopt($handle, CURLOPT_RETURNTRANSFER, 1);
62 | curl_setopt($handle, CURLOPT_POSTFIELDS, $data);
63 |
64 | $times = 0;
65 | do{
66 | $result = curl_exec($handle);
67 | $times++;
68 | } while($result === false && $times < $retryTimes);
69 |
70 | curl_close($handle);
71 | return $result;
72 | }
73 | }
--------------------------------------------------------------------------------
/uninstall.php:
--------------------------------------------------------------------------------
1 |