教你如何实现帖子详情页附件隐藏,仅登录后可见

教你如何实现帖子详情页附件隐藏,仅登录后可见
此方法可以强制用户必须登录注册才可以看到上传的附件内容。
方法如下:
首先找到我们要修改的文件,路径如下
xiunobbs\model\post.func.php
PHP
到286行,有一个post_file_list_html()方法,将下面代码复制替换后清空缓存即可
// 公用的附件模板,采用函数,效率比 include 高。

function post_file_list_html($filelist, $include_delete = FALSE) {
    global $gid;
    if(empty($filelist)) return '';
    
    // hook model_post_file_list_html_start.php
    
    $s = '<fieldset class="fieldset">'."\r\n";
    $s .= '<legend>上传的附件:</legend>'."\r\n";
    $s .= '<ul class="attachlist">'."\r\n";
    if($gid === 0) {
        $s .= '    <div class="card text-center"><p></p><p class="text-center">
         <a href="<?php echo url("user-login");?><i class="icon-user"></i><b> 登录</b></a> 后查看附件!</p>
    </div>';
    }else{
        foreach ($filelist as &$attach) {
            $s .= '<li aid="'.$attach['aid'].'">'."\r\n";
            $s .= '        <a href="'.url("attach-download-$attach[aid]").'" target="_blank">'."\r\n";
            $s .= '            <i class="icon filetype '.$attach['filetype'].'"></i>'."\r\n";
            $s .= '            '.$attach['orgfilename']."\r\n";
            $s .= '        </a>'."\r\n";
            // hook model_post_file_list_html_delete_before.php
            $include_delete AND $s .= '        <a href="javascript:void(0)" class="delete ml-3"><i class="icon-remove"></i> '.lang('delete').'</a>'."\r\n";
            // hook model_post_file_list_html_delete_after.php
            $s .= '</li>'."\r\n";
        };
    }
    $s .= '</ul>'."\r\n";
    $s .= '</fieldset>'."\r\n";
    
    // hook model_post_file_list_html_end.php
    
    return $s;
}

相关文章

发表新评论