其他程序,首页调用Discuz最新帖子,最新回复等

发个小程序,证明我还或者,至于他们两个,就不清楚了

前端时间,在xoops上,东至同学发了Xoops整合Ucenter的方法,然后就可以使用Discuz了,只是首页无法调取Discuz的最新帖子,最新回复等! xoops上几个网友问了下,在下就搞个小程序出来了!
以下是代码
C.php

/*
	Date:2008-11-17
	$Id: c.php   cfc4n $
	$num 变量可以自己赋值,为最新帖子数量
*/
define('CURSCRIPT', 'c');
require_once './include/common.inc.php';
require_once DISCUZ_ROOT.'./include/forum.func.php';

$num = 10; 
$thread = array();

$sql = "SELECT t.* , f.fid , f.name FROM {$tablepre}threads t , {$tablepre}forums f WHERE f.fid = t.fid ORDER BY `dateline` DESC LIMIT 0,$num";
$query = $db->query($sql);
while( $thread = $db->fetch_array($query)) {
	$thread['icon'] = ' ';
	$thread['lastposterenc'] = rawurlencode($thread['lastposter']);
	$thread['typeid'] = '';
	$thread['multipage'] = '';
	$topicposts = $thread['special'] ? $thread['replies'] : $thread['replies'] + 1;
	$thread['special'] == 3 && $thread['price'] < 0 && $thread&#91;'replies'&#93;--;
	if($thread&#91;'highlight'&#93;) {
		$string = sprintf('%02d', $thread&#91;'highlight'&#93;);
		$stylestr = sprintf('%03b', $string&#91;0&#93;);

		$thread&#91;'highlight'&#93; = ' style="';
		$thread&#91;'highlight'&#93; .= $stylestr&#91;0&#93; ? 'font-weight: bold;' : '';
		$thread&#91;'highlight'&#93; .= $stylestr&#91;1&#93; ? 'font-style: italic;' : '';
		$thread&#91;'highlight'&#93; .= $stylestr&#91;2&#93; ? 'text-decoration: underline;' : '';
		$thread&#91;'highlight'&#93; .= $string&#91;1&#93; ? 'color: '.$colorarray&#91;$string&#91;1&#93;&#93; : '';
		$thread&#91;'highlight'&#93; .= '"';
	} else {
		$thread&#91;'highlight'&#93; = '';
	}
	$thread&#91;'moved'&#93; = 0;
	if($thread&#91;'closed'&#93;) {
		$thread&#91;'new'&#93; = 0;
		if($thread&#91;'closed'&#93; > 1) {
			$thread['moved'] = $thread['tid'];
			$thread['tid'] = $thread['closed'];
			$thread['replies'] = '-';
			$thread['views'] = '-';
		}
		$thread['folder'] = 'lock';
	} else {
		$thread['folder'] = 'common';
		if($lastvisit < $thread&#91;'lastpost'&#93; && (empty($_DCOOKIE&#91;'oldtopics'&#93;) || strpos($_DCOOKIE&#91;'oldtopics'&#93;, 'D'.$thread&#91;'tid'&#93;.'D') === FALSE)) {
			$thread&#91;'new'&#93; = 1;
			$thread&#91;'folder'&#93; = 'new';
		} else {
			$thread&#91;'new'&#93; = 0;
		}
		if($thread&#91;'replies'&#93; > $thread['views']) {
			$thread['views'] = $thread['replies'];
		}
		if($thread['replies'] >= $hottopic) {
			$thread['folder'] = 'hot';
		}
	}

	$thread['dateline'] = gmdate($dateformat, $thread['dateline'] + $timeoffset * 3600);
	$thread['lastpost'] = gmdate("$dateformat $timeformat", $thread['lastpost'] + $timeoffset * 3600);

	if(in_array($thread['displayorder'], array(1, 2, 3))) {
		$thread['id'] = 'stickthread_'.$thread['tid'];
		$separatepos++;
	} elseif(in_array($thread['displayorder'], array(4, 5))) {
		$thread['id'] = 'floatthread_'.$thread['tid'];
	} else {
		$thread['id'] = 'normalthread_'.$thread['tid'];
	}

	$resulttid[] = $thread['tid'];
	$threadlist[] = $thread;
}
include template('c');
?>

C.htm

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=$charset" />
<title>$navtitle $bbname $seotitle - Powered by Discuz!</title>
$seohead
<meta name="keywords" content="{$metakeywords}$seokeywords" />
<meta name="description" content="$metadescription $bbname $seodescription - Discuz! Board" />
<meta name="generator" content="Discuz! $version" />
<meta name="author" content="Discuz! Team and Comsenz UI Team" />
<meta name="copyright" content="2001-2008 Comsenz Inc." />
<meta name="MSSmartTagsPreventParsing" content="True" />
<meta http-equiv="MSThemeCompatible" content="Yes" />
<link rel="archives" title="$bbname" href="{$boardurl}archiver/" />
$rsshead
$extrahead
<!--{if CURSCRIPT == 'viewthread'}-->
	<link rel="stylesheet" type="text/css" href="forumdata/cache/style_{STYLEID}_viewthread.css" />
	<!--{if $thread&#91;'special'&#93;}-->
		<link rel="stylesheet" type="text/css" href="forumdata/cache/style_{STYLEID}_special.css" />
	<!--{/if}-->
<!--{elseif CURSCRIPT == 'post'}-->
	<link rel="stylesheet" type="text/css" href="forumdata/cache/style_{STYLEID}_editor.css" />
<!--{/if}-->
<link rel="stylesheet" type="text/css" href="forumdata/cache/style_{STYLEID}_common.css" />
<script type="text/javascript">
	var discuz_uid = $discuz_uid;var IMGDIR = '{IMGDIR}';var attackevasive = '$attackevasive';var gid = 0;var STYLEID = '{STYLEID}';
	<!--{if in_array(CURSCRIPT, array('viewthread', 'forumdisplay'))}-->gid = parseInt('$thisgid');<!--{elseif CURSCRIPT == 'index'}-->gid = parseInt('$gid');<!--{/if}-->var fid = parseInt('$fid');var tid = parseInt('$tid');
</script>
<script type="text/javascript" src="include/javascript/common.js"></script>
</head>

<body onkeydown="if(event.keyCode==27) return false;">
<div id="append_parent"></div><div id="ajaxwaitid"></div>
<div class="wrap">



<div class="mainbox threadlist">
<table summary="forum_$fid" {if !$separatepos}id="forum_$fid"{/if} cellspacing="0" cellpadding="0">
			<thead class="category">
				<tr>
					<td class="folder">&nbsp;</td>
					<td class="icon">&nbsp;</td>
					<td class="forum">{lang forum}</td>
					<th>{lang subject}</th>
					<td class="author">{lang author}</td>
					<td class="nums">{lang replies}/{lang views}</td>
					<td class="lastpost">{lang lastpost}</td>
				</tr>
			</thead>
<!--{loop $threadlist $key $thread}-->
		<tbody id="$thread&#91;id&#93;" {if in_array($thread&#91;'displayorder'&#93;, array(4, 5))}style="display: none"{/if}>
			<tr>
				<td class="folder"><a href="viewthread.php?tid=$thread&#91;tid&#93;&amp;extra=$extra" title="{lang target_blank}" target="_blank"><img src="{IMGDIR}/folder_$thread&#91;folder&#93;.gif" /></a></td>
				<td class="icon">
				<!--{if $thread&#91;'special'&#93; == 1}-->
					<img src="{IMGDIR}/pollsmall.gif" alt="{lang thread_poll}" />
				<!--{elseif $thread&#91;'special'&#93; == 2}-->
					<img src="{IMGDIR}/tradesmall.gif" alt="{lang thread_trade}" />
				<!--{elseif $thread&#91;'special'&#93; == 3}-->
					<!--{if $thread&#91;'price'&#93; > 0}-->
						<img src="{IMGDIR}/rewardsmall.gif" alt="{lang thread_reward}" />
					<!--{elseif $thread&#91;'price'&#93; < 0}-->
						<img src="{IMGDIR}/rewardsmallend.gif" alt="{lang thread_rewardend}" />
					<!--{/if}-->
				<!--{elseif $thread&#91;'special'&#93; == 4}-->
					<img src="{IMGDIR}/activitysmall.gif" alt="{lang thread_activity}" />
				<!--{elseif $thread&#91;'special'&#93; == 5}-->
					<img src="{IMGDIR}/debatesmall.gif" alt="{lang thread_debate}" />
				<!--{elseif $thread&#91;'special'&#93; == 6}-->
					<img src="{IMGDIR}/videosmall.gif" alt="{lang thread_video}" />
				<!--{else}-->
					$thread['icon']
				<!--{/if}-->
				</td>
				<td class="forum"><a href="forumdisplay.php?fid=$thread&#91;fid&#93;">$thread[name]</a></td>
				<th class="$thread&#91;folder&#93;" {if $forum&#91;'ismoderator'&#93;} ondblclick="ajaxget('modcp.php?action=editsubject&tid=$thread&#91;tid&#93;', 'thread_$thread&#91;tid&#93;', 'specialposts');doane(event);"{/if}>
					<label>
					<!--{if $thread&#91;'rate'&#93; > 0}-->
						<img src="{IMGDIR}/agree.gif" alt="" />
					<!--{elseif $thread&#91;'rate'&#93; < 0}-->
						<img src="{IMGDIR}/disagree.gif" alt="" />
					<!--{/if}-->
					<!--{if in_array($thread&#91;'displayorder'&#93;, array(1, 2, 3))}-->
						<img src="{IMGDIR}/pin_$thread&#91;displayorder&#93;.gif" alt="$threadsticky&#91;3-$thread&#91;displayorder&#93;&#93;" />
					<!--{/if}-->
					<!--{if $thread&#91;'digest'&#93; > 0}-->
						<img src="{IMGDIR}/digest_$thread&#91;digest&#93;.gif" alt="{lang thread_digest} $thread&#91;digest&#93;" />
					<!--{/if}-->
					&nbsp;</label>
					$thread[typeid]
					<span id="thread_$thread&#91;tid&#93;"><a href="viewthread.php?tid=$thread&#91;tid&#93;&amp;extra=$extra"$thread&#91;highlight&#93;>$thread[subject]</a></span>
					<!--{if $thread&#91;'readperm'&#93;}--> - [{lang readperm} <span class="bold">$thread[readperm]</span>]<!--{/if}-->
					<!--{if $thread&#91;'price'&#93; > 0}-->
						<!--{if $thread&#91;'special'&#93; == '3'}-->
						- [{lang thread_reward}
						<!--{else}-->
						- [{lang price}
						<!--{/if}-->
						{$extcredits[$creditstrans][title]} <span class="bold">$thread[price]</span> {$extcredits[$creditstrans][unit]}]
					<!--{elseif $thread&#91;'special'&#93; == '3' && $thread&#91;'price'&#93; < 0}-->
						- [{lang reward_solved}]
					<!--{/if}-->
					<!--{if $thread&#91;'attachment'&#93;}-->
						<img src="images/attachicons/common.gif" alt="{lang attachment}" class="attach" />
					<!--{/if}-->
					<!--{if $thread&#91;multipage&#93;}-->
						<span class="threadpages">$thread[multipage]</span>
					<!--{/if}-->
					<!--{if $thread&#91;'new'&#93;}-->
						<a href="redirect.php?tid=$thread&#91;tid&#93;&amp;goto=newpost$highlight#newpost" class="new">New</a>
					<!--{/if}-->
				</th>
				<td class="author">
					<cite>
					<!--{if $thread&#91;'authorid'&#93; && $thread&#91;'author'&#93;}-->
						<a href="space.php?uid=$thread&#91;authorid&#93;">$thread[author]</a>
					<!--{else}-->
						<!--{if $forum&#91;'ismoderator'&#93;}-->
							<a href="space.php?uid=$thread&#91;authorid&#93;">{lang anonymous}</a>
						<!--{else}-->
							{lang anonymous}
						<!--{/if}-->
					<!--{/if}-->
					</cite>
					<em>$thread[dateline]</em>
				</td>
				<td class="nums"><strong>$thread[replies]</strong> / <em>$thread[views]</em></td>
				<td class="lastpost">
					<em><a href="{if $thread&#91;digest&#93; != -2}redirect.php?tid=$thread&#91;tid&#93;&amp;goto=lastpost$highlight#lastpost{else}viewthread.php?tid=$thread&#91;tid&#93;&amp;page={echo max(1, $thread&#91;pages&#93;);}{/if}">$thread[lastpost]</a></em>
					<cite>{lang forum_lastpost_by} <!--{if $thread&#91;'lastposter'&#93;}--><a href="{if $thread&#91;digest&#93; != -2}space.php?username=$thread&#91;lastposterenc&#93;{else}viewthread.php?tid=$thread&#91;tid&#93;&amp;page={echo max(1, $thread&#91;pages&#93;);}{/if}">$thread[lastposter]</a><!--{else}-->{lang anonymous}<!--{/if}--></cite>
				</td>
			</tr>
		</tbody>
	<!--{/loop}-->
</table>
</div>
</div>

使用方法
1,将c.php放到Discuz根目录下!
2,将c.htm放到templates\当前主体\下!(比如templates\default\)!
3,在xoops的相关页面(比如自定义区块中)下加入

<iframe border="0" marginwidth="1" marginheight="1" src="http://Discuz论坛地址/c.php" frameborder="0" width="850" height="435" scrolling="no"></iframe>

其中,宽高自定义!

关注微信公众号,手机阅读更方便: 程序员的阅微草堂

知识共享许可协议莿鸟栖草堂CFC4N 创作,采用 知识共享 署名-非商业性使用-相同方式共享(3.0未本地化版本)许可协议进行许可。基于http://www.cnxct.com上的作品创作。转载请注明转自:其他程序,首页调用Discuz最新帖子,最新回复等

9 thoughts on “其他程序,首页调用Discuz最新帖子,最新回复等

  1. 请教你一个问题:在使用 coolcode 插件时,我也能成功显示,但是我的文章发布后 再想修改什么地方的时候,编辑器里面的coolcode 都是打乱的,代码也打乱了。怎么办,这时候要是直接保存,coolcode就失效了! 你是这样的么?

  2. 哦 我下载了,请问有什么区别么
    支持怎么调用的?
    我的编辑器老实自动添加比如这样的标志,当然 他总是把coolcode和 直接靠近,中间什么都没有

  3. 呵呵,我都是使用 “html源代码”模式进行编辑的,你别用”可视化”的那个试试,具体什么情况,我也没懂你的意思!!

  4. 呵呵,我都是使用 "html源代码"模式进行编辑的,你别用"可视化"的那个试试,具体什么情况,我也没懂你的意思!!

  5. 呵呵,我都是使用 &quot;html源代码&quot;模式进行编辑的,你别用&quot;可视化&quot;的那个试试,具体什么情况,我也没懂你的意思!!

发表评论

电子邮件地址不会被公开。 必填项已用*标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据