一聚教程网:一个值得你收藏的教程网站

热门教程

blogCMS标签库源码例子

时间:2022-06-25 16:25:56 编辑:袖梨 来源:一聚教程网

 代码如下 复制代码

import('TagLib');
class TagLibBlog extends TagLib {
  
   protected $tags=array(
       'blog_cate'=>array('attr'=>'typeid,reid,model,menu,order,limit,name','close'=>0),
       'blog_blog'=>array('attr'=>'id,typeid,order,limit,name','close'=>0),
       'blog_link'=>array('attr'=>'kind,order,limit,name','close'=>0),
       'blog_sql'=>array('attr'=>'sql,name','close'=>0),
       'blog_comment'=>array('attr'=>'aid,reid,order,limit,name','close'=>0),
       'blog_tag'=>array('attr'=>'order,limit,name','close'=>0),
       'blog_group'=>array('attr'=>'order,limit,name','close'=>0),
   );
  
   //获取栏目信息
   public function _blog_cate($attr){
       $attr=$this->parseXmlAttr($attr);
       extract($attr);
       $sql='where 1';
       if(isset($typeid)){
           $sql.=" and id=$typeid";
       }
       if(isset($reid)){
           $sql.=" and reid=$reid";
       }
       if(isset($model)){
           $sql.=" and model=$model";
       }
       if(isset($menu)){
           $sql.=" and menu=$menu";
       }
       if(isset($order)){
           $sql.=" order by $order";
       }
       if(isset($limit)){
           $sql.=" limit $limit";
       }
       if(empty($name)){
           $name='list';
       }
       $str=<<               ${$name}=M()->query("select id,name,reid from blog_category {$sql}");
       import('@.Class.Tool');
       ${$name}=Tool::formatMultiArray(${$name});
       ?>
str;
       return $str;
   }
  
   //获取博文列表
   public function _blog_blog($attr){
       $attr=$this->parseXmlAttr($attr);
       extract($attr);
       $sql='where 1';
       if(isset($id)){
           $sql.=" and a.id in ($id)";
       }
       if(isset($typeid)){
           import('@.Class.Tool');
           $categories=M('category')->select();
           $arr=Tool::getChildsId($categories,$typeid);
           $arrStr=implode(",",$arrStr);
           $sql.=" and a.reid in ($typeid)";
       }
       if(isset($order)){
           $sql.=" order by a.$order";
       }
       if(isset($limit)){
           $sql.=" limit $limit";
       }
       if(empty($name)){
           $name='list';
       }
       $str=<<               ${$name}=M()->query("select a.*,c.name as cname from blog_article as a left join blog_category as c on a.reid=c.id {$sql}");
       foreach(${$name} as $key=>$value){
           if($value['keywords']){
               ${$name}[$key]['tag']=explode(',',$value['keywords']);
           }
       }
       ?>
str;
       return $str;   
   }

   //友链调用标签
   public function _blog_link($attr){
       $attr=$this->parseXmlAttr($attr);
       extract($attr);
       $sql='where 1 and state=1';
       if(isset($kind)){
           $sql.=" and kind=$kind";
       }
       if(isset($order)){
           $sql.=" order by $order";
       }
       if(isset($limit)){
           $sql.=" limit $limit";
       }
       if(empty($name)){
           $name='list';
       }
       $str=<<               ${$name}=M()->query("select name,url,imgurl from blog_link {$sql}");
       ?>
str;
       return $str;
   }
  
   //万能sql调用标签
   public function _blog_sql($attr){
       $attr=$this->parseXmlAttr($attr);
       extract($attr);
       if(empty($name)){
           $name='list';
       }
       if(empty($sql)){
           echo '模板标签有误';
           exit;
       }
       if(preg_match('/update|insert|delete/',$sql)){
           echo 'sql语句包含危险操作';
           exit;
       }
       $str=<<               ${$name}=M()->query("{$sql}");
       p(${$name});
       exit;
       ?>
str;
       return $str;
   }
  
   //评论列表标签
   public function _blog_comment($attr){
       $attr=$this->parseXmlAttr($attr);
       extract($attr);
       $sql='where 1 and islock=0';
       if(isset($aid)){
           $sql.=" and aid=$aid";
       }
       if(isset($reid)){
           $sql.=" and reid=$reid";
       }
       if(isset($order)){
           $sql.=" order by $order";
       }
       if(isset($limit)){
           $sql.=" limit $limit";
       }
       if(empty($name)){
           $name='list';
       }
       $str=<<               ${$name}=M()->query("select * from blog_comment $sql");
       import('@.Class.Tool');
       ${$name}=Tool::formatOneArray(${$name});
       ?>
str;
       return $str;
   }
  
   //Tag列表标签
   public function _blog_tag($attr){
       $attr=$this->parseXmlAttr($attr);
       extract($attr);
       $sql='where 1';
       if(isset($order)){
           $sql.=" order by $order";
       }
       if(isset($limit)){
           $sql.=" limit $limit";
       }
       if(empty($name)){
           $name='list';
       }
       $str=<<               ${$name}=M()->query("select tagname,counts from blog_tag $sql");
       foreach(${$name} as $key=>$value){
           $num=floor(($value['counts']+1200)/100);
           $num=$num>30? 30:$num;
           ${$name}[$key]['size']=$num;
       }
       shuffle(${$name});
       ?>
str;
       return $str;       
   }
  
   //文档归档标签
   public function _blog_group($attr){
       $attr=$this->parseXmlAttr($attr);
       extract($attr);
       $sql='where 1';
       if(empty($name)){
           $name='list';
       }
       $str=<<               ${$name}=M()->query("select count(*) as num,from_unixtime(pubdate,'%Y-%m') as pdate from blog_article group by pdate order by pdate desc");
       ?>
str;
       return $str;       
   }
}

?>

热门栏目