本帖最后由 zuimengt 于 2009-10-31 22:02 编辑
官方发布的ucenter+uchome2+discuz7只是将discuz和uchome的用户整合到了一起,并没有实现信息的互相调用。
由于我一直用uchome做主页,用户就很少去看discuz论坛里面的帖子了,上网搜搜,都是discuz调用uchome的,没有一个uchome调用discuz的!!所以,花费了一个周末的时间,做了这个插件,实现uchome首页对discuz最新帖子及热帖的调用(不用js调,js调用对搜索引擎不友好,这种数据直接调用有非常好的seo效果),只需要修改两个文件。
第一个要修改的文件:home\source\notework.php,修改内容如下:
第109行修改为,话题显示数量减少,防止首页不整齐;
第206行,插入如下代码:- //uchome调用discuz最新主题/回复及热帖,作者:仝飞,演示网站:www.kxss.net
- //最新主题/回复
- $cachefile = S_ROOT.'./data/cache_network_diz_thread.txt';
- if(check_network_cache('dizthread')) {
- $diz_threadlist = unserialize(sreadfile($cachefile));
- } else {
- //显示数量
- $shownum = 10;
-
- $diz_threadlist = array();
- $query = $_SGLOBAL['db']->query("SELECT t.tid,t.subject,p.author,p.authorid,t.fid,f.name
- FROM `cdb_threads` t left join `cdb_forums` f on t.fid=f.fid left join `cdb_posts` p on (t.tid=p.tid AND t.lastposter=p.author AND t.lastpost=p.dateline)
- ORDER BY t.lastpost desc
- LIMIT 0,$shownum");
- //$no=1; //如果帖子序号想从1开始排序,可加入这个变量
- while ($value = $_SGLOBAL['db']->fetch_array($query)) {
- //$value['no'] = $no;
- //$no++;
- $value['shortsubject'] = getstr($value['subject'], 50);
- $diz_threadlist[] = $value;
- }
- if($_SGLOBAL['network']['thread']['cache']) {
- swritefile($cachefile, serialize($diz_threadlist));
- }
- }
- foreach($diz_threadlist as $key => $value) {
- realname_set($value['uid'], $value['username']);
- $diz_threadlist[$key] = $value;
- }
- //热帖
- $cachefile = S_ROOT.'./data/cache_network_diz_hot_thread.txt';
- if(check_network_cache('dizhotthread')) {
- $diz_hot_threadlist = unserialize(sreadfile($cachefile));
- } else {
- //显示数量
- $shownum = 12;
-
- $diz_hot_threadlist = array();
- $query = $_SGLOBAL['db']->query("SELECT subject,tid FROM `cdb_threads`
- ORDER BY (`cdb_threads`.`replies`*20+`cdb_threads`.`views`) DESC
- LIMIT 0,$shownum");
- while ($value = $_SGLOBAL['db']->fetch_array($query)) {
- //$value['tagname'] = getstr($value['tagname'], 20);
- $value['shortsubject'] = getstr($value['subject'], 26);
- $diz_hot_threadlist[] = $value;
- }
- if($_SGLOBAL['network']['thread']['cache']) {
- swritefile($cachefile, serialize($diz_hot_threadlist));
- }
- }
- foreach($diz_hot_threadlist as $key => $value) {
- realname_set($value['uid'], $value['username']);
- $diz_hot_threadlist[$key] = $value;
- }
- //结束,uchome调用discuz最新帖子/回复及热帖,作者:仝飞,演示网站:www.kxss.net
复制代码 ,OK,第一个文件修改完毕。
第二个要修改的文件:home\template\default\network.htm,这个文件要修改地方多,建议直接替覆盖掉:
第270行到298行,全部替换为如下代码:- <style>
- #hotpost .side_rbox_c{height:347px;}
- #hotpost ul{padding:10px;}
- #hotpost li{width: 100%; background: url(/home/template/default/image/dot.gif) no-repeat 0 49%; text-indent: 10px; overflow: hidden; text-overflow: ellipsis; padding:3px; }
- </style>
- <div class="nbox">
- <div class="nbox_c">
- <h2 class="ntitle"><span class="r_option"><a href="/bbs">更多帖子</a></span>开心大杂院最新主题/回复 »</h2>
- <div class="tlist">
- <table cellpadding="0" cellspacing="1">
- <tbody>
- <!--如果序号想从1开始,可将下面的$key换成$value[no]-->
- <!--{loop $diz_threadlist $key $value}-->
- <tr <!--{if $key%2==1}-->class="color_row"<!--{/if}-->>
- <td class="ttopic"><div class="ttop"><div><span>$key</span></div></div><a href="/bbs/viewthread.php?tid=$value[tid]" title="$value[subject]" target="_blank">$value[shortsubject]</a></td>
- <td class="tuser"><a href="space.php?uid=$value[authorid]" target="_blank"><!--{avatar($value[authorid],small)}--></a> <a href="space.php?uid=$value[authorid]" target="_blank">$value[author]</a></td>
- <td class="tgp"><a href="/bbs/forumdisplay.php?fid=$value[fid]" target="_blank">$value[name]</a></td>
- </tr>
- <!--{/loop}-->
- </tbody>
- </table>
- </div>
- </div>
- <div id="hotpost" class="nbox_s side_rbox side_rbox_w">
- <div class="side_rbox_c">
- <h2 class="ntitle"><span class="r_option"><a href="/bbs">更多帖子</a></span>热帖 »</h2>
- <ul>
- <!--{loop $diz_hot_threadlist $key $value}-->
- <li><a href="/bbs/viewthread.php?tid=$value[tid]" title="$value[subject]" target="_blank">$value[shortsubject]</a></li>
- <!--{/loop}-->
- </ul>
- </div>
- </div>
- </div>
复制代码 注意,上面代码中有一行<!--如果序号想从1开始,可将下面的$key换成$value[no]-->是注解,仅供开发者看的,实际应用中要删掉此句。
替换完后,接着将328(上面替换完以后的行号)到347行替换为如下代码:- <script language="javascript">
- function tfshow(v){
- if(v==1){
- document.getElementById("tfmore").innerHTML="<a href='space.php?do=thread&view=all'>更多话题</a>";
- document.getElementById("tfsort").style.display="none";
- document.getElementById('tfcontent1').style.display="";
- document.getElementById('tfcontent2').style.display="none";
- document.getElementById("tftitle1").style.color="#000";
- document.getElementById("tftitle1").style.width="100px";
- document.getElementById("tftitle2").style.color="#999";
- document.getElementById("tftitle2").style.width="50px";
- }
- if(v==2){
- document.getElementById("tfmore").innerHTML="<a href='space.php?do=event&view=recommend'>更多活动</a>";
- document.getElementById("tfsort").style.display="";
- document.getElementById('tfcontent1').style.display="none";
- document.getElementById('tfcontent2').style.display="";
- document.getElementById("tftitle1").style.color="#999";
- document.getElementById("tftitle1").style.width="50px";
- document.getElementById("tftitle2").style.color="#000";
- document.getElementById("tftitle2").style.width="100px";
- }
- return true;
- }
- </script>
- <div class="nbox">
- <div class="nbox_c">
- <h2 class="ntitle"><span class="r_option" id="tfmore"><a href="space.php?do=thread&view=all">更多话题</a></span>
- <div onmouseover="tfshow(1);" id="tftitle1" style="width:100px; float:left;color:#000;cursor:pointer">话题 » </div>
- <div onmouseover="tfshow(2);" id="tftitle2" style="width:50px; float:left; color:#999;cursor:pointer">活动 » </div>
- <span id="tfsort" style="display:none">
- <!--{loop $_SGLOBAL[eventclass] $value}-->
- <a href="space.php?do=event&view=all&type=going&classid=$value[classid]">$value[classname]</a></li>
- <!--{/loop}-->
- </span>
- </h2>
- <div class="tlist" id="tfcontent1" style="height:250px">
- <table cellpadding="0" cellspacing="1">
- <tbody>
- <!--{loop $threadlist $key $value}-->
- <tr <!--{if $key%2==1}-->class="color_row"<!--{/if}-->>
- <td class="ttopic"><div class="ttop"><div><span>$value[hot]</span></div></div><a href="space.php?uid=$value[uid]&do=thread&id=$value[tid]" target="_blank">$value[subject]</a></td>
- <td class="tuser"><a href="space.php?uid=$value[uid]" target="_blank"><!--{avatar($value[uid],small)}--></a> <a href="space.php?uid=$value[uid]" target="_blank">{$_SN[$value[uid]]}</a></td>
- <td class="tgp"><a href="space.php?do=mtag&tagid=$value[tagid]">$value[tagname]</a></td>
- </tr>
- <!--{/loop}-->
- </tbody>
- </table>
- </div>
- <ul class="elist" id="tfcontent2" style="display:none">
- <!--{loop $eventlist $value}-->
- <li>
- <h3><a href="space.php?do=event&id=$value[eventid]" target="_blank">$value[title]</a></h3>
- <p class="eimage"><a href="space.php?do=event&id=$value[eventid]" target="_blank"><img src="$value[pic]" alt=""/></a></p>
- <p><span class="gray">时间:</span> <!--{date('n-j H:i',$value[starttime])}--> - <!--{date('n-j H:i',$value[endtime])}--></p>
- <p><span class="gray">地点:</span> $value[province] $value[city] $value[location]</p>
- <p><span class="gray">发起:</span> <a href="space.php?uid=$value[uid]">{$_SN[$value[uid]]}</a></p>
- <p class="egz">$value[membernum] 人参加<span class="pipe">|</span>$value[follownum] 人关注</p>
- </li>
- <!--{/loop}-->
- </ul>
- </div>
复制代码 OK,整个修改完毕!
对于不懂代码的朋友,可以直接将我附件中的两个文件替换你们的对应文件就可以了,替换完了(注意network.htm文件中的<!--如果序号想从1开始,可将下面的$key换成$value[no]-->行请删去),别忘了把home\data\tpl_cache目录下的全部模板缓存文件清空一下,这样刷新首页就可以看到效果了。 |