Press "Enter" to skip to content

Discuz_源码_用户组下载附件权限细分到版块的设想

需求场景:
1、希望一些用户组具有直接下载收费附件

2、希望一些用户组具有直接查看收费主题


3、搜索|发短消息|搜索|下载附件  不扣除积分

这些需求可以在用户组设置的积分设置中实现。但是这是针对于全论坛,我能否按版块继续细分权限呢?

就是控制某些用户可以在某些版块里直接下载付费附件

从页面反向分析: 我发了一篇带付费附件的文章进行测试

直接相关的就是forum_viewthread.php文件

页面模板文件层层寻找viewthread.htm viewthread_node.htm viewthread_node_body.htm

通过浏览器查看页面定位到 最终找到附件显示的元素位于viewthread_node_body.htm 83行

60                            <!--{if $post['first']}-->
83				$post[message]</td></tr></table>

可以看到附件信息是存储与 主题内容中的。

然后我去寻找 $post ,$post是变量过程中定义的变量,那么需要找到其上的列表,在viewthread.htm 320行找到了 $postlist 变量

	<!--{loop $postlist $post}-->
		<!--{if $rushreply && $_GET['checkrush'] && $post['rewardfloor'] != 1}-->
			<!--{eval continue;}-->
		<!--{/if}-->
		<div id="post_$post[pid]" {if $_G['blockedpids'] && $post['inblacklist']}style="display:none;"{/if}>
			<!--{subtemplate forum/viewthread_node}-->
		</div>
		<!--{eval $postcount++;}-->
	<!--{/loop}-->

然后回到 forum_viewthread.php文件 ,在928行发现了 其退message的处理


parseattach($_G['forum_attachpids'], $_G['forum_attachtags'], $postlist, $skipaids);

进入function_attachment.php文件 查看parseattach方法,在163行发现了其对message字段的解析处理

		foreach($attachtags as $pid => $aids) {
			if($findattach[$pid]) {
				foreach($findattach[$pid] as $aid => $find) {
					$postlist[$pid]['message'] = preg_replace($find, attachinpost($postlist[$pid]['attachments'][$aid], $postlist[$pid]), $postlist[$pid]['message'], 1);
					$postlist[$pid]['message'] = preg_replace($find, '', $postlist[$pid]['message']);
				}
			}
		}

主要方法 attachinpost , 然后我寻找到 attachinpost 方法发现其在discuzcode.htm中。

然后综合浏览器代码查看和寻找discuzcode.htm页面寻找到了附件链接位置在287行

			<!--{if !$attach['price'] || $attach['payed']}-->
				<a href="forum.php?mod=attachment{$is_archive}&aid=$aidencode" target="_blank">$attach[filename]</a>
			<!--{else}-->
				<a href="forum.php?mod=misc&action=attachpay&aid=$attach[aid]&tid=$attach[tid]" onclick="showWindow('attachpay', this.href)">$attach[filename]</a>
			<!--{/if}-->

可见是 attach[‘price’] || $attach[‘payed’] 这两个参数进行控制的,由于price是价格不便于修改,因此可以在此之前控制payed实现需求

回到function_attachement.php文件的parseattach方法,在107行找到了
$attach[‘payed’] = $_G[‘forum_attachmentdown’] || $_G[‘uid’] == $attach[‘uid’] ? 1 : 0;

可见有两种情况payed为true:
1、$_G[‘forum_attachmentdown’]为true //已经下载过
2、$_G[‘uid’] == $attach[‘uid’] //作者

那么明确了我可以修改:
$_G[‘forum_attachmentdown’]来实现目的

实际操作

实际处理过程中发现无法解决问题,这里只是在下载链接显示上得到了改变,并没有真正意义上改变流程,通过不断分析我发现还是得改变

$_G['group']['exempt']

这是一个在后台用户组编辑里设置的值,它其实是由5个开关项组成的2进制串转的十进制,然后需要在viewthread、attachment、misc三个模块中分别实用并合理处理才能实现,discuz的思路是付费附件必须先进行购买(或者拥有免费购买权限)然后才能下载

如果需要进一步解答可联系我哈QQ 664942395

发表评论