日期:2014-05-17 浏览次数:20546 次
<?php
class blog extends top
{
function __construct(){
parent::__construct();
}
//获取feeds
function feeds(){
if($this->spArgs('uid')){
$uid = (int) $this->spArgs('uid');
$cond = "and b.uid = '$uid'";
}
if($this->spArgs('pagelimit')){
$pageLimit = ($this->spArgs('pagelimit') < 30) ? $this->spArgs('pagelimit') : 30 ; //自定义分页
}else{
$pageLimit = $this->yb['show_page_num'];
}
//LEFT JOIN `".DBPRE."follow` AS f ON ( b.uid = f.touid and f.uid = '$uid' )
$sql = "SELECT b. * , k.id AS likeid ,m.username,m.domain
FROM `".DBPRE."blog` AS b LEFT JOIN `".DBPRE."likes` AS k ON ( b.bid = k.bid AND k.uid ='$this->uid' )
LEFT JOIN `".DBPRE."member` as m on b.uid = m.uid where b.open = 1 $cond ORDER BY b.time desc";
$data['blog'] = spClass('db_blog')->spPager($this->spArgs('page',1),$pageLimit)->findSql($sql);
$data['page'] = spClass('db_blog')->spPager()->getPager();
unset($data['page']['all_pages']);
if(!empty($data['blog'])){
foreach($data['blog'] as &$d){
$this->foramt_feeds($d);
}
$this->api_success($data);
}else{
$this->api_success("");
}
}
//获取单个博客
function getOneBlog(){
$bid = (int) $this->spArgs('bid');
$sql = "SELECT b. * , k.id AS likeid ,m.username,m.domain
FROM `".DBPRE."blog` AS b LEFT JOIN `".DBPRE."likes` AS k ON ( b.bid = k.bid AND k.uid ='$this->uid' )
LEFT JOIN `".DBPRE."member` as m on b.uid = m.uid where b.open in (1,-2) and b.bid = '$bid'";
$data['blog'] = spClass('db_blog')->findSql($sql);
foreach($data['blog'] as &$d){
$this->foramt_feeds($d,0);
}
$this->api_success($data);
}
//获取我关注的用户feeds
function followfeeds(){
$followuid = spClass('db_follow')->getFollowUid($this->uid);
if($followuid){
$sql = "SELECT b. * , k.id AS likeid ,m.username,m.domain
FROM `".DBPRE."blog` AS b LEFT JOIN `".DBPRE."likes` AS k ON ( b.bid = k.bid AND k.uid ='$this->uid' )
LEFT JOIN `".DBPRE."member` as m on b.uid = m.uid where b.open = 1";
$sql .= " and b.uid in ($followuid) and b.open=1 ORDER BY b.time desc";
$data['blog'] = spClass('db_blog')->spPager($this->spArgs('page',1),10)->findSql($sql);
$data['page'] = spClass('db_blog')->spPager()->getPager();
foreach($data['b