Files
web-discuz/source/plugin/replyfloor/attachment.inc.php
2025-06-27 21:04:18 +08:00

183 lines
7.2 KiB
PHP

<?php
/**
* This is NOT a freeware, use is subject to license terms
* 应用名称: 贴吧楼中楼回复 9.0
* 下载地址: https://addon.dismall.com/plugins/replyfloor.html
* 应用开发者: 乘凉
* 开发者QQ: 594433766
* 更新日期: 202505310549
* 授权域名: www.shitangsweet.com
* 授权码: 2025053105b89RrI3R9n
* 未经应用程序开发者/所有者的书面许可,不得进行反向工程、反向汇编、反向编译等,不得擅自复制、修改、链接、转载、汇编、发表、出版、发展与之有关的衍生产品、作品等
*/
/**
* $author: 乘凉 $
*/
if(!defined('IN_DISCUZ')) {
exit('Access Denied');
}
$setconfig = $_G['cache']['plugin'][CURMODULE];
if($_GET['operation'] == 'upload') {
if(empty($_G['uid'])) {
$_G['uid'] = intval($_POST['uid']);
if($_POST['hash'] != md5(substr(md5($_G['config']['security']['authkey']), 8).$_G['uid'])) {
exit();
} else {
if($_G['uid']) {
$_G['member'] = getuserbyuid($_G['uid']);
}
$_G['groupid'] = $_G['member']['groupid'];
loadcache('usergroup_'.$_G['member']['groupid']);
$_G['group'] = $_G['cache']['usergroup_'.$_G['member']['groupid']];
}
}
require_once libfile('class/upload', 'plugin/'.CURMODULE);
$_FILES['Filedata']['name'] = diconv(urldecode($_FILES['Filedata']['name']), 'UTF-8');
$_FILES['Filedata']['type'] = $_GET['filetype'];
$upload = new discuz_upload();
$upload->init($_FILES['Filedata'], 'replyfloor');
if(!$upload->error()) {
$upload->save();
}
if($upload->error()) {
helper_output::json(array('status'=>'0', 'message' => lang('plugin/'.CURMODULE, 'attach_uploaderror').$upload->error()));
}
$thumb = $remote = $width = 0;
list($width, $height) = @getimagesize($upload->attach['target']);
if(getglobal('setting/ftp/on')){
if(ftpcmd('upload', 'replyfloor/'.$upload->attach['attachment'])) {
@unlink($_G['setting']['attachdir'].'/replyfloor/'.$upload->attach['attachment']);
ftpcmd('close');
$remote = 1;
}
}
$insert = array(
'uid' => $_G['uid'],
'username' => $_G['username'],
'filename' => dhtmlspecialchars(censor($upload->attach['name'])),
'fileext' => $upload->fileext($upload->attach['name']),
'filesize' => $upload->attach['size'],
'attachment' => $upload->attach['attachment'],
'remote' => $remote,
'width' => $width,
'height' => $height,
'dateline' => $_G['timestamp'],
);
$aid = C::t('#'.CURMODULE.'#'.CURMODULE.'_attachment_unused')->insert($insert, true);
$fileurl = ($remote ? $_G['setting']['ftp']['attachurl'] : $_G['setting']['attachurl']) . 'replyfloor/'. $insert['attachment'];
helper_output::json(array('status'=>'1', 'aid' => $aid, 'filename' => $insert['filename'], 'attachment' => $fileurl));
}elseif($_GET['operation'] == 'wechat') {
$mid = $_GET['mid'];
if(empty($mid)) {
helper_output::json(array('status'=>'0', 'message' => lang('plugin/'.CURMODULE, 'attach_uploaderror')));
}
require_once libfile('class/wechat', 'plugin/'.CURMODULE);
$wechat_client = new replyfloor_wechat($setconfig['wechat_appid'], $setconfig['wechat_appsecret']);
if(!$setconfig['access_token']){
$wechat_client->setNoCache("AccessToken");
}
$url = $wechat_client->download($mid);
require_once libfile('class/upload', 'plugin/'.CURMODULE);
$upload = new discuz_upload();
$attach = array();
$attach['name'] = trim($_GET['name']);
$attach['name'] = $attach['name'] ? $attach['name'] : 'wximage.jpg';
$attach['extension'] = 'jpg';
$attach['attachdir'] = $upload->get_target_dir('replyfloor');
$attach['attachment'] = $attach['attachdir'].$upload->get_target_filename('replyfloor').'.'.$attach['extension'];
$attach['target'] = getglobal('setting/attachdir').'./replyfloor/'.$attach['attachment'];
file_put_contents($attach['target'], $url);
$attach['size'] = filesize($attach['target']);
$upload->attach = $attach;
$thumb = $remote = $width = 0;
list($width, $height) = @getimagesize($upload->attach['target']);
if(getglobal('setting/ftp/on')){
if(ftpcmd('upload', 'replyfloor/'.$upload->attach['attachment'])) {
@unlink($_G['setting']['attachdir'].'/replyfloor/'.$upload->attach['attachment']);
ftpcmd('close');
$remote = 1;
}
}
$insert = array(
'uid' => $_G['uid'],
'username' => $_G['username'],
'filename' => dhtmlspecialchars(censor($upload->attach['name'])),
'fileext' => $upload->fileext($upload->attach['name']),
'filesize' => $upload->attach['size'],
'attachment' => $upload->attach['attachment'],
'remote' => $remote,
'width' => $width,
'height' => $height,
'dateline' => $_G['timestamp'],
);
$aid = C::t('#'.CURMODULE.'#'.CURMODULE.'_attachment_unused')->insert($insert, true);
$fileurl = ($remote ? $_G['setting']['ftp']['attachurl'] : $_G['setting']['attachurl']) . 'replyfloor/'. $insert['attachment'];
helper_output::json(array('status'=>'1', 'aid' => $aid, 'filename' => $insert['filename'], 'attachment' => $fileurl));
}elseif($_GET['operation'] == 'delete') {
$aid = intval($_GET['aid']);
if(!$aid){
showmessage(lang('plugin/'.CURMODULE, 'attach_nonexistence'));
}
$attachment = C::t('#'.CURMODULE.'#'.CURMODULE.'_attachment_unused')->fetch_by_id($aid);
if(!$attachment){
$attachment = C::t('#'.CURMODULE.'#'.CURMODULE.'_attachment')->fetch_by_id($aid);
if(!$attachment){
showmessage(lang('plugin/'.CURMODULE, 'attach_nonexistence'));
}
require_once libfile('function/forum');
loadforum(null, $attachment['tid']);
if($attachment['uid'] != $_G['uid'] && !$_G['forum']['ismoderator']){
showmessage(lang('plugin/'.CURMODULE, 'attach_no_permission'));
}
}else{
if($attachment['uid'] != $_G['uid']){
showmessage(lang('plugin/'.CURMODULE, 'attach_no_permission'));
}
}
if($attachment['remote']) {
ftpcmd('delete', 'replyfloor/'.$attachment['attachment']);
} else {
@unlink($_G['setting']['attachdir'].'/replyfloor/'.$attachment['attachment']);
}
if($attachment['msgid']){
C::t('#'.CURMODULE.'#'.CURMODULE.'_attachment')->delete_by_id($aid);
$attachlist = C::t('#'.CURMODULE.'#'.CURMODULE.'_attachment')->fetch_all_by_msgid(array($attachment['msgid']), 'order by displayorder asc,dateline asc');
$msgattach = array();
foreach($attachlist as $value){
if(in_array($value['fileext'], array('jpg', 'jpeg', 'gif', 'png', 'bmp', 'webp'))){
$msgattach[] = ($value['remote'] ? $_G['setting']['ftp']['attachurl'] : $_G['setting']['attachurl']) . 'replyfloor/'. $value['attachment'];
}
}
C::t('#'.CURMODULE.'#'.CURMODULE.'_message')->update_by_id($attachment['msgid'], array('attachment' => implode("\t", $msgattach)));
}else{
C::t('#'.CURMODULE.'#'.CURMODULE.'_attachment_unused')->delete_by_id($aid);
}
showmessage(lang('plugin/'.CURMODULE, 'attach_deletesucceed'), dreferer());
}
?>