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()); } ?>