blogCMS标签库源码例子
发布:smiling 来源: PHP粉丝网 添加日期:2014-12-04 11:35:54 浏览: 评论:0
最近用ThinkPHP3.1版本重写了下自己的轻博客系统,新增加了标签库功能,如果使用过织梦或是74CMS的标签,会对此比较熟悉,标签库源码如下:
- <?php
- 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(emptyempty($name)){
- $name='list';
- }
- $str=<<<str
- <?php
- ${$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(emptyempty($name)){
- $name='list';
- }
- $str=<<<str
- <?php
- ${$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(emptyempty($name)){
- $name='list';
- }
- $str=<<<str
- <?php
- ${$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(emptyempty($name)){
- $name='list';
- }
- if(emptyempty($sql)){
- echo '模板标签有误';
- exit;
- }
- if(preg_match('/update|insert|delete/',$sql)){
- echo 'sql语句包含危险操作';
- exit;
- }
- $str=<<<str
- <?php
- ${$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(emptyempty($name)){
- $name='list';
- }
- $str=<<<str
- <?php
- ${$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(emptyempty($name)){
- $name='list';
- }
- $str=<<<str
- <?php
- ${$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(emptyempty($name)){
- $name='list';
- }
- $str=<<<str
- <?php
- ${$name}=M()->query("select count(*) as num,from_unixtime(pubdate,'%Y-%m') as pdate from blog_article group by pdate order by pdate desc");//开源软件:phpfensi.com
- ?>
- str;
- return $str;
- }
- }
- ?>
Tags: blogCMS标签 blogCMS源码
推荐文章
热门文章
最新评论文章
- 写给考虑创业的年轻程序员(10)
- PHP新手上路(一)(7)
- 惹恼程序员的十件事(5)
- PHP邮件发送例子,已测试成功(5)
- 致初学者:PHP比ASP优秀的七个理由(4)
- PHP会被淘汰吗?(4)
- PHP新手上路(四)(4)
- 如何去学习PHP?(2)
- 简单入门级php分页代码(2)
- php中邮箱email 电话等格式的验证(2)