Discuz教程网

[代码修改] Discuz X2无法删除他人附件的解决办法

[复制链接]
authicon dly 发表于 2011-5-15 17:18:55 | 显示全部楼层 |阅读模式
目前的程序中无法删除非本人上传的附件,修正后,拥有管理权限的用户则可以正常删除他人附件了。

1、找到文件 source/module/forum/forum_ajax.php 的 106 行附近,找到
  1. } elseif($_G['gp_action'] == 'deleteattach') {

  2. if($_G['gp_aids']) {
  3. foreach($_G['gp_aids'] as $aid) {
  4. $query = DB::query("SELECT uid, attachment, thumb, remote, aid FROM ".DB::table(getattachtablebyaid($aid))." WHERE aid='$aid' AND uid='$_G[uid]'");
  5. if(DB::num_rows($query)) {
  6. DB::delete(getattachtablebyaid($aid), "aid='$aid'");
  7. DB::delete('forum_attachment', "aid='$aid'");
  8. }
  9. while($attach = DB::fetch($query)) {
  10. dunlink($attach);
  11. }
  12. }
  13. }
  14. include template('common/header_ajax');
  15. echo count($_G['gp_aids']);
  16. include template('common/footer_ajax');
  17. dexit();
复制代码

修改为
  1. } elseif($_G['gp_action'] == 'deleteattach') {

  2. $count = 0;
  3. if($_G['gp_aids']) {
  4. foreach($_G['gp_aids'] as $aid) {
  5. $attach = DB::fetch_first("SELECT * FROM ".DB::table(getattachtablebyaid($aid))." WHERE aid='$aid'");
  6. if($attach && ($attach['pid'] && $attach['pid'] == $_G['gp_pid'] && $_G['uid'] == $attach['uid'] || $_G['forum']['ismoderator'] || !$attach['pid'] && $_G['uid'] == $attach['uid'])) {
  7. DB::delete(getattachtablebyaid($aid), "aid='$aid'");
  8. DB::delete('forum_attachment', "aid='$aid'");
  9. dunlink($attach);
  10. $count++;
  11. }
  12. }
  13. }
  14. include template('common/header_ajax');
  15. echo $count;
  16. include template('common/footer_ajax');
  17. dexit();
复制代码

2、找到文件 template/default/forum/post.htm 的 6 行附近,找到
  1. var pid = parseInt('$pid');
复制代码

在他下面添加一行,修改后为
  1. var pid = parseInt('$pid');
  2. var tid = parseInt('$_G[tid]');
复制代码

3、找到文件 static/js/forum_post.js 的 399 行附近,找到
  1. x.get('https://www.discuz.1314study.com/forum.php?mod=ajax&action=deleteattach&inajax=yes' + aids, function() {});
复制代码

修改为
  1. x.get('https://www.discuz.1314study.com/forum.php?mod=ajax&action=deleteattach&inajax=yes&tid=' + tid + '&pid=' + pid + aids, function() {});
复制代码






上一篇:Discuz X2上传附件后附件列表正序显示的修改
下一篇:升级到 Discuz X2 后,用 uid 或者 email 登陆,不显示安全提问或验证码,登陆失败的
authicon 皆无 发表于 2011-5-15 19:29:49 | 显示全部楼层
好辛苦才找到啊
authicon forever21 发表于 2011-5-15 20:30:03 | 显示全部楼层
不错,谢谢分享
authicon nmzc 发表于 2011-5-15 22:30:01 | 显示全部楼层
支持!好东西,拿走了!
authicon icenna 发表于 2011-5-15 22:59:46 | 显示全部楼层
谢谢,学习了
authicon nancybingling 发表于 2011-5-15 23:29:34 | 显示全部楼层
顶你一下,好贴要顶!
authicon mjz 发表于 2011-5-16 03:29:57 | 显示全部楼层
好东西要顶的。
authicon kurt226 发表于 2011-5-16 03:59:52 | 显示全部楼层
我回不回呢 考虑再三 还是不回了吧 ^_^
authicon qqoxygen 发表于 2011-5-16 04:29:46 | 显示全部楼层
这个要顶起来啊
authicon rin421 发表于 2011-5-16 05:29:37 | 显示全部楼层
有意思~顶顶 ,继续顶顶。继续顶哦
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

1314学习网 ( 浙ICP备10214163号 )

GMT+8, 2025-5-2 14:16

Powered by Discuz! X3.4

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表