uchome 开发插件 简单实例

discuz

2009-12-08 17:40


uchome 和dz 论坛是连一起的 所以在uchome里面加一个论坛的帖子调用

在主目录新建 bbs.php

<?php
include_once('./common.php');//调用核心

//是否关闭站点
checkclose();

//处理rewrite
if($_SCONFIG['allowrewrite'] && isset($_GET['rewrite'])) {
$rws = explode('-', $_GET['rewrite']);
if($rw_uid = intval($rws[0])) {
   $_GET['uid'] = $rw_uid;
} else {
   $_GET['do'] = $rws[0];
}
if(isset($rws[1])) {
   $rw_count = count($rws);
   for ($rw_i=1; $rw_i<$rw_count; $rw_i=$rw_i+2) {
    $_GET[$rws[$rw_i]] = empty($rws[$rw_i+1])?'':$rws[$rw_i+1];
   }
}
unset($_GET['rewrite']);
}

//允许动作     目前只做个简单的浏览   稍会给提供 其他功能
$dos = array('list');
//视图
$vs = array('all','me',"reply"); //三种显示模式

//获取变量
$isinvite = 0;
$uid = empty($_GET['uid'])?0:intval($_GET['uid']);
$username = empty($_GET['username'])?'':$_GET['username'];
//$domain = empty($_GET['domain'])?'':$_GET['domain'];
$do = (!empty($_GET['do']) && in_array($_GET['do'], $dos))?$_GET['do']:'list';

$view = (!empty($_GET['view']) && in_array($_GET['view'], $vs))?$_GET['view']:'me';


//是否公开

checklogin();//需要登录


//获取空间
if($uid) {
$space = getspace($uid, 'uid');
} elseif ($username) {
$space = getspace($username, 'username');
} elseif ($domain) {
$space = getspace($domain, 'domain');
} elseif ($_SGLOBAL['supe_uid']) {
$space = getspace($_SGLOBAL['supe_uid'], 'uid');
}

if($space) {

//验证空间是否被锁定
if($space['flag'] == -1) {
   showmessage('space_has_been_locked');
}

//隐私检查
if(empty($isinvite) || ($isinvite<0 && $code != space_key($space, $_GET['app']))) {
   //游客
   if(empty($_SCONFIG['networkpublic'])) {
    checklogin();//需要登录
   }
   if(!ckprivacy($do)) {
    include template('space_privacy');
    exit();
   }
}

//别人只查看自己
if(!$space['self']) {
   $_GET['view'] = 'me';
} else if(empty($space['feedfriend']) && empty($_GET['view'])) {
   $_GET['view'] = 'all';
}
if ($_GET['view'] == 'me') {
   $space['feedfriend'] = '';
}

} elseif($uid) {

//判断当前用户是否删除
$query = $_SGLOBAL['db']->query("SELECT * FROM ".tname('spacelog')." WHERE uid='$uid' AND flag='-1'");
if($value = $_SGLOBAL['db']->fetch_array($query)) {
   showmessage('the_space_has_been_closed');
}

//未开通空间
include_once(S_ROOT.'./uc_client/client.php');
if($user = uc_get_user($uid, 1)) {
   $space = array('uid' => $user[0], 'username' => $user[1], 'dateline'=>$_SGLOBAL['timestamp'], 'friends'=>array());
   $_SN[$space['uid']] = $space['username'];
}
}

//游客
if(empty($space)) {
$space = array('uid'=>0, 'username'=>'guest', 'self'=>1);
if($do == 'index') $do = 'feed';
}

//更新活动session
if($_SGLOBAL['supe_uid']) {

getmember(); //获取当前用户信息

if($_SGLOBAL['member']['flag'] == -1) {
   showmessage('space_has_been_locked');
}

//禁止访问
if(checkperm('banvisit')) {
   ckspacelog();
   showmessage('you_do_not_have_permission_to_visit');
}

updatetable('session', array('lastactivity' => $_SGLOBAL['timestamp']), array('uid'=>$_SGLOBAL['supe_uid']));
}

//计划任务
if(!empty($_SCONFIG['cronnextrun']) && $_SCONFIG['cronnextrun'] <= $_SGLOBAL['timestamp']) {
include_once S_ROOT.'./source/function_cron.php';
runcron();
}
//处理

include_once(S_ROOT."./source/bbs_{$do}.php");

?>

----------------------------------------------------------------------------------------------------
由于只提供了list 功能 所以新建source/bbs_list.php

<?php
if(!defined('IN_UCHOME')) {
exit('Access Denied');
}

$page = empty($_GET['page'])?1:intval($_GET['page']); //取页数
if($page<1) $page=1;

$all=$me=$reply=0;                                                         //控制器
$actives[me]=$actives[all]=$actives[reply]='';                    
//摘要截取
$summarylen = 270;
$list=array();
$count=0;    


if($view=="all"){                                                      //如果是显示全部帖子
$all=1;
$actives[all]="class=\"active\"";
$perpage=8;
$_SGLOBAL['db']->query("SELECT * FROM ********** LIMIT ".($page-1)*$perpage.",".$perpage);
while ($value = $_SGLOBAL['db']->fetch_array($query)) {
     $list[] = $value;
}

}
elseif($view=="me")                                               //显示自己的
{
$me=1;
$actives[me]="class=\"active\"";
$perpage=5;
$query = $_SGLOBAL['db']->query("SELECT ***** limit ".($page-1)*$perpage.",".$perpage);
while ($value = $_SGLOBAL['db']->fetch_array($query)) {
    $list[] = $value;
}
$count = $_SGLOBAL['db']->fetch_array($_SGLOBAL['db']->query("统计数量'"));
   $theurl="bbs.php?do=list&view=me";
$multi = multi($count, $perpage, $page, $theurl);
}
else{                                                      //显示回复的
$reply=1;
$actives[reply]="class=\"active\"";
$perpage=5;
$t_id=array();
$query = $_SGLOBAL['db']->query("******************** LIMIT ".($page-1)*$perpage.",".$perpage);
while ($value = $_SGLOBAL['db']->fetch_array($query)) {
   $list[] = $value;
}
//代码写的太多太垃圾 删除之......
$count = $_SGLOBAL['db']->fetch_array($_SGLOBAL['db']->query("统计"));
$theurl="bbs.php?do=list&view=reply";
$multi = multi($count, $perpage, $page, $theurl);

}

  
include_once template("bbs_list"); //调用模板 /template/default/bbs_list.htm


?>

---------------------------------------------------------------------------------------------------------
/template/default/bbs_list.htm模板如下 PS:模板已经被该的面目全非..

<!--{template header}-->


<h2 class="title"><img src="image/app/blog.gif" />论坛</h2>
<div class="tabs_header">
<ul class="tabs">
   <li $actives[all]><a href="bbs.php?uid=$space[uid]&do=list&view=all"><span>论坛最新帖子</span></a></li>
   <li $actives[me]><a href="bbs.php?uid=$space[uid]&do=list&view=me"><span>我的帖子</span></a></li>
        <li $actives[reply]><a href="bbs.php?uid=$space[uid]&do=list&view=reply"><span>我的回帖</span></a></li>
</ul>
</div>

  
<div id="content" style="width:640px;">

<!--{if $all}-->
   <!--{if count($list)}-->
<div class="entry_list">
<ul>
   <!--{loop $list $value}-->
<li>
       <div class="avatardiv" >
      <div class="avatar48" >
                    <a href="space.php?uid=$value[authorid]"><!--{avatar($value[authorid],small)}--></a>
                    </div>
     
   </div>
       
   <div class="title" >
    <h4><a href="asdasd">$value[subject]   </a></h4>
<div>
              <!--{if $value[authorid]}--><a href="space.php?uid=$value[authorid]">{$value[author]}</a><!--{/if}-->
                   
                    &nbsp;&nbsp;&nbsp;<span class="gray"><!--{date('Y-m-d H:i',$value[dateline],1)}--></span>  
           </div>
   </div>
      
   <div class="detail image_right l_text " id="blog_article_$value[tid]" >
     $value[message]
   </div>
   <div class="gray s_clear" >
   <!--{if $value[views]}-->$value[views] 次阅读<span class="pipe">|</span><!--{/if}-->
    <!--{if $value[replies]}-->$value[replies] 个评论<!--{else}-->没有评论<!--{/if}-->
   </div>
      
</li>
   <!--{/loop}-->

</ul>
</div>

<div class="page">$multi</div>
<!--{else}-->
    <div class="c_form">还没有相关的帖子。</div>
    <!--{/if}-->
   
<!--{elseif $me}-->

    <!--{if count($list)}-->

<div class="entry_list">
   <ul>
   <!--{loop $list $value}-->
    <li>
            
       <div class="avatardiv" >
              <div class="avatar48" ><a href="space.php?uid=$value[authorid]"><!--{avatar($value[authorid],small)}--></a></div>
     
     </div>
    
     <div class="title" >
   <h4><a href="xxxxxxx/viewthread.php?tid=$value[tid]">$value[subject]</a></h4>
      <div>
     <span class="gray"><!--{date('Y-m-d H:i',$value[dateline],1)}--></span>
     </div>
   </div>
     <div class="detail image_right l_text " id="blog_article_$value[tid]">
         $value[message]
     </div>
     <div class="gray s_clear" >
    <!--{if $value[views]}-->$value[views] 次阅读<span class="pipe">|</span><!--{/if}-->
    <!--{if $value[replies]}-->$value[replies] 个评论<!--{else}-->没有评论<!--{/if}-->
     </div>
                
          
           
    </li>
   <!--{/loop}-->

   </ul>
</div>

<div class="page">$multi</div>
   <!--{else}-->
      <div class="c_form">你还没有发布过帖子。</div>
      <!--{/if}-->
        
         <!--{elseif $reply}-->
         <!--{if count($list)}-->


//由于 回帖不需要调用 主题数据 前面删除的回帖的 参考以上两个就可以了 下面的可以忽略
<div class="entry_list">
   <ul>
   <!--{loop $list $value}-->
    <li>
            
                   <div class="avatardiv" >
      <div class="avatar48" ><a href="space.php?uid=$list_title[$value[tid]][authorid]"><!--{avatar($list_title[$value[tid]][authorid],small)}--></a></div>
     
     </div>
    
     <div class="title" >
   <h4><a href="xxxxxxxxxxxxxx/viewthread.php?tid=$value[tid]">$list_title[$value[tid]][subject]</a></h4>

      <div>
     <span class="gray"><!--{date('Y-m-d H:i',$value[dateline],1)}-->【回复】</span>
     </div>
   </div>
     <div class="detail image_right l_text " id="blog_article_$value[tid]">
         $value[message]
     </div>
     <div class="gray s_clear" >
    <!--{if $list_title[$value[tid]][views]}-->$list_title[$value[tid]][views] 次阅读<span class="pipe">|</span><!--{/if}-->
    <!--{if $list_title[$value[tid]][replies]}-->$list_title[$value[tid]][replies] 个评论<!--{else}-->没有评论<!--{/if}-->
     </div>
                
         
       
           
    </li>
   <!--{/loop}-->

   </ul>
</div>

<div class="page">$multi</div>
   <!--{else}-->
      <div class="c_form">你还没有回复过帖子。</div>
      <!--{/if}-->
<!--{/if}-->

<!--{template footer}-->