Skip to content

Commit

Permalink
feat support discuz 3.4
Browse files Browse the repository at this point in the history
  • Loading branch information
sabakugaara committed Sep 13, 2017
1 parent e4a45fa commit 7b5490a
Show file tree
Hide file tree
Showing 19 changed files with 4,433 additions and 9 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,14 @@ https://techs.b0.upaiyun.com/videos/cdnpage/Discuz.html

2. 安装时提示文件已经被修改,请手动安装

由于插件需要修改以下六个系统原文件
由于插件需要修改以下七个系统原文件
* source/module/forum/forum_attachment.php
* source/module/portal/portal_attachment.php
* source/class/discuz/discuz_ftp.php
* source/function/function_attachment.php
* source/function/function_home.php
* source/function/function_post.php
* source/module/forum/forum_image.php

在安装时,插件会提前检查这个六个文件是否被修改,防止覆盖您的自定义修改。建议您将自定义修改的系统文件先备份,然后使用 Discuz 相应版本的原文件暂时代替完成安装(例如 Discuz 3.1 版本的原文件可以通过 source/plugin/upyun/discuz_3_1/uninstall/ 目录下获取。 uninstall 目录保存了各个版本的系统原文件)。文件还原后,重新安装即可。安装完成后,可以将您的自定义修改再追加到新的文件中。(如果卸载插件,该文件会被还原为 Discuz 原文件,所以卸载完成后需要重新追加本地修改)。

Expand Down
164 changes: 164 additions & 0 deletions discuz_3_4/install/discuz_ftp.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
<?php

/**
* (c) 2005 - 2099 UpYun.com, All Rights Reserved.
* If you have any problem,please connect with us: https://www.upyun.com
* $Id: discuz_ftp.php BiangBiang: [email protected]
*/

if(!defined('IN_DISCUZ')) {
exit('Access Denied');
}

include_once DISCUZ_ROOT . "source/plugin/upyun/sdk/upyun.class.php";
include_once DISCUZ_ROOT . "source/plugin/upyun/sdk/upyun_multipart_upload/Upload.php";
include_once DISCUZ_ROOT . "source/plugin/upyun/sdk/upyun_multipart_upload/Signature.php";
include_once DISCUZ_ROOT . "source/plugin/upyun/sdk/upyun_multipart_upload/File.php";


class discuz_ftp
{

var $enabled = false;
var $config = array();
var $api_access = array(UpYun::ED_AUTO, UpYun::ED_TELECOM, UpYun::ED_CNC, UpYun::ED_CTT);
var $connectid;
var $_error;
var $upyun_config = array();

function &instance($config = array()) {
static $object;
if(empty($object)) {
$object = new discuz_ftp($config);
}
return $object;
}

function __construct($config = array()) {
global $_G;
$this->set_error(0);
loadcache('plugin');
$this->upyun_config = getglobal('cache/plugin/upyun');
$this->config = !$config ? getglobal('setting/ftp') : $config;
$this->enabled = false;
$this->config['host'] = discuz_ftp::clear($this->config['host']);
$this->config['port'] = intval($this->config['port']);
$this->config['ssl'] = intval($this->config['ssl']);
$this->config['bucketname'] = $this->config['host'];
$this->config['username'] = discuz_ftp::clear($this->config['username']);
$this->config['password'] = authcode($this->config['password'], 'DECODE', md5(getglobal('config/security/authkey')));
$this->config['timeout'] = intval($this->config['timeout']);
$this->config['api_access'] = $this->api_access[$this->config['port']];
$this->connectid = true;
$this->enabled = true;
}

function upload($source, $target) {
$file = new UpyunMultiPartFile($source);
if($file->getSize() > 1024 * 1024 && $this->upyun_config['form_api_key']) {
$sign = new UpyunMultipartSignature($this->upyun_config['form_api_key']);
$upload = new UpyunMultipartUpload($sign);
$upload->setBucketName($this->upyun_config['bucket_name']);
$upload->setBlockSize($upload->getBlockSizeAdaptive($file));
try {
$result = $upload->upload($file, array(
'path' => '/' . ltrim($target, '/')
));
return $result;
} catch(Exception $e) {
return 0;
}
} else {
$fh = fopen($source, 'rb');
if(!$fh) {
return 0;
}
$upyun = new UpYun(
$this->upyun_config['bucket_name'],
$this->upyun_config['operator_name'],
$this->upyun_config['operator_pwd']
);
$rsp = $upyun->writeFile('/'. ltrim($target, '/'), $fh, true);
return $rsp;
}
}

function connect() {
return 1;
}

function set_error($code = 0) {
$this->_error = $code;
}

function error() {
return $this->_error;
}

function clear($str) {
return str_replace(array( "\n", "\r", '..'), '', $str);
}

function ftp_rmdir($directory) {
return 1;
}

function ftp_size($remote_file) {
$upyun = new UpYun(
$this->upyun_config['bucket_name'],
$this->upyun_config['operator_name'],
$this->upyun_config['operator_pwd']
);
$remote_file = discuz_ftp::clear($remote_file);
try{
$rsp = $upyun->getFileInfo('/' . ltrim($remote_file, '/'));
return $rsp['x-upyun-file-size'];
}
catch(Exception $e){
return -1;
}
}

function ftp_close() {
return 1;
}

function ftp_delete($path) {
$upyun = new UpYun(
$this->upyun_config['bucket_name'],
$this->upyun_config['operator_name'],
$this->upyun_config['operator_pwd']
);
$path = discuz_ftp::clear($path);
try{
$rsp = $upyun->delete('/' . ltrim($path, '/'));
return $rsp;
}
catch(Exception $e){
return 0;
}
}

function ftp_get($local_file, $remote_file, $mode, $resumepos = 0) {
$upyun = new UpYun(
$this->upyun_config['bucket_name'],
$this->upyun_config['operator_name'],
$this->upyun_config['operator_pwd']
);
$remote_file = discuz_ftp::clear($remote_file);
$local_file = discuz_ftp::clear($local_file);
try{
if($fh = fopen($local_file,'wb')){
$rsp = $upyun->readFile('/'. ltrim($remote_file, '/'), $fh);
fclose($fh);
return $rsp;
}else{
return 0;
}
}
catch(Exception $e){
return 0;
}
}

}
Loading

0 comments on commit 7b5490a

Please sign in to comment.