让discuzX2.5加上回帖支持功能

2013年9月13日 分类: Discuz, PHP (180 个脚步)

之前一直看着别人的论坛是X3.0的,有回帖点击支持这个功能。然后现在用回X2.5有点点别扭,又不想升级到X3.0上面。

想想还是直接将X3.0的这个回帖支持功能搬过来了。

为了使得论坛能够顺利升级并兼容到X3.0,所以我们对现在的数据表保持一直。

首先打开

/source/module/forum/forum_viewthread.php

找到

if($_G['forum_thread']['stickreply'] && $page == 1 && (!$_GET['authorid'] || $_GET['authorid'] == $_G['thread']['authorid'])) {

修改成

	if($_G['page'] === 1 && $_G['forum_thread']['stickreply'] && empty($_GET['authorid'])){
 		$poststick = C::t('forum_poststick')->fetch_all_by_tid($_G['tid']);
 		foreach(C::t('forum_post')->fetch_all($posttableid, array_keys($poststick)) as $post) {
 			$post['position'] = $poststick[$post['pid']]['position'];
 			$post['avatar'] = avatar($post['authorid'], 'small');
			$post['isstick'] = true;
 			$sticklist[$post['pid']] = $post;
 		}
 		$stickcount = count($sticklist);
@@ -579,9 +579,41 @@ if($page == 1 && $ordertype == 1) {
 		unset($firstpost);
 	}

找到

upload/source/module/forum/forum_viewthread.php

找到这一行

$tagnames = $locationpids = array();

修改成下面的样子

$tagnames = $locationpids = $hotpostarr = $hotpids = array();

$_G['setting']['threadhotreplies'] = 50; //此处根据情况更改,到达数值后置顶到主题贴
$remainhots = ($_G['page'] == 1 && !$rushreply && !$hiddenreplies && !$_G['forum_thread']['special'] && !$_G['forum']['noforumrecommend'] && empty($_GET['authorid'])) ? $_G['setting']['threadhotreplies'] : 0;

if($remainhots) {
	$hotpids = array_keys(C::t('forum_hotreply_number')->fetch_all_by_tid_total($_G['tid'], 5));
	$remainhots = $remainhots - count($hotpids);
}

if($hotpids) {
	$hotposts = C::t('forum_post')->fetch_all_by_pid($posttableid, $hotpids);
	foreach($hotpids as $hotpid) {
		if($hotposts[$hotpid]) {
			$hotpostarr[$hotpid] = $hotposts[$hotpid];
			$hotpostarr[$hotpid]['hotrecommended'] = true;
		}
	}
	unset($hotposts);
}

if($hotpostarr || $sticklist) {
	$_newpostarr_first = array_shift($postarr);
	$postarr = (array)$sticklist + (array)$hotpostarr + $postarr;
	array_unshift($postarr, $_newpostarr_first);
	unset($_newpostarr_first, $sticklist);
}

 foreach($postarr as $post) {
	if(($onlyauthoradd && $post['anonymous'] == 0) || !$onlyauthoradd && !isset($postlist[$post['pid']])) {

		if(isset($hotpostarr[$post['pid']])) {
			$post['existinfirstpage'] = true;
		}

找到这一句

$seodata = array('forum' => $_G['forum']['name'], 'fup'

在前面加上

unset($hotpostarr);

在大概950行找到

if($_G['forum_pagebydesc']) {

修改成

	if(!$post['hotrecommended']) {
		if($_G['forum_pagebydesc']) {
			if($ordertype != 1) {
				$post['number'] = $_G['forum_numpost'] + $_G['forum_ppp2']--;
			} else {
				$post['number'] = $post['first'] == 1 ? 1 : ($_G['forum_numpost'] - 1) - $_G['forum_ppp2']--;
			}
		} else {
			if($ordertype != 1) {
				$post['number'] = ++$_G['forum_numpost'];
			} else {
				$post['number'] = $post['first'] == 1 ? 1 : --$_G['forum_numpost'];
				$post['number'] = $post['number'] - 1;
			}
		}
	}

	if($post['existinfirstpage']) {
		if($_G['forum_pagebydesc']) {
			$_G['forum_ppp2']--;
		} else {
			if($ordertype != 1) {
				++$_G['forum_numpost'];
			} else {
				--$_G['forum_numpost'];
			}
		}
	}

	if($post['hotrecommended']) {
		$post['number'] = -1;
	}

然后就是修改模版 打开upload/template/default/forum/viewthread_node.htm

找到

<a href="{if $post[first]}forum.php?mod=viewthread&tid=$_G[tid]$fromuid{else}forum.php?mod=redirect&goto=findpost&ptid=$_G[tid]&pid=$post[pid]$fromuid{/if}" {if $fromuid}title="{lang share_url_copy_comment}"{/if} id="postnum$post[pid]" onclick="setCopy(this.href, '{lang post_copied}');return false;">$postno[$post[number]]{$post[number]}{$postno[0]}<!--{/if}--></a>

将之修改为

<a href="{if $post[first]}forum.php?mod=viewthread&tid=$_G[tid]$fromuid{else}forum.php?mod=redirect&goto=findpost&ptid=$_G[tid]&pid=$post[pid]$fromuid{/if}" {if $fromuid}title="{lang share_url_copy_comment}"{/if} id="postnum$post[pid]" onclick="setCopy(this.href, '{lang post_copied}');return false;">
						<!--{if isset($post[isstick])}-->
							<img src ="{IMGDIR}/settop.png" title="{lang replystick}" class="vm" /> {lang from} {$post[number]}{$postnostick}
						<!--{elseif $post[number] == -1}-->
							<img src ="{IMGDIR}/settop.png" title="{lang replystick}" class="vm" /> {lang from} {lang recommend}
						<!--{else}-->
							<!--{if !empty($postno[$post[number]])}-->
								$postno[$post[number]]
							<!--{else}-->
								<em>{$post[number]}{$postno[0]}
							<!--{/if}-->
						<!--{/if}-->
					</a>

然后就完成了这次的修改

让discuzX2.5加上回帖支持功能 【声明】本文 让discuzX2.5加上回帖支持功能 为柠之漠然原创文章,转载请注明出自 枫之落叶
并保留本文有效链接:https://blog.shiniv.com/2013/09/add-reply-on-discuzx-2-5/ , 转载请保留本声明!

标签:
目前还没有任何评论.
你必须要启用 Javascript