完善标签功能

This commit is contained in:
2020-04-12 11:15:24 +08:00
parent 456d63a231
commit 8bc3b1fd9b
4 changed files with 55 additions and 85 deletions

View File

@@ -25,4 +25,18 @@ class Channel extends \think\Model {
$status = [0 => '禁用', 1 => '启用'];
return isset($status[$data['status']]) ? $status[$data['status']] : '禁用';
}
public static function getChannelList($pid, $tree){
$map = [];
$map[] = ['status', '=', 1];
if ($pid !== '') {
$map[] = ['pid', '=', $pid];
}
$list = self::where($map)->order('sort asc, id desc')->column("*");
if ($tree) {
$list = (new \sent\tree\Tree())->listToTree($list);
}
return $list;
}
}

33
app/model/Document.php Normal file
View File

@@ -0,0 +1,33 @@
<?php
// +----------------------------------------------------------------------
// | OneThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
// +----------------------------------------------------------------------
namespace app\model;
use think\facade\Db;
/**
* 文档模型
*/
class Document {
public static function getDocumentList($model, $category_id, $limit = 20, $order = "id desc", $field = "*"){
$map = [];
if (!$model) {
return [];
}
//判断model是否为内容模型
$info = Model::where('name', $model)->where('status', 1)->findOrEmpty();
if ($info->isEmpty()) {
return [];
}
$list = Db::name($model)->where($map)->limit($limit)->order($order)->field($field)->select();
return $list;
}
}

View File

@@ -18,22 +18,15 @@ class Sent extends \think\template\TagLib {
protected $tags = array(
// 标签定义: attr 属性列表 close 是否闭合0 或者1 默认1 alias 标签别名 level 嵌套层次
'nav' => array('attr' => 'name,pid', 'close' => 1), //获取导航
'list' => array('attr' => 'table,where,order,limit,id,sql,field,key','level'=>3),//列表
'doc' => array('attr' => 'model,field,limit,id,field,key,name','level'=>3),
'recom' => array('attr' => 'doc_id,id'),
'link' => array('attr' => 'type,limit' , 'close' => 1),//友情链接
'prev' => array('attr' => 'id,cate' , 'close' => 1),//上一篇
'next' => array('attr' => 'id,cate' , 'close' => 1),//下一篇
);
public function tagnav($tag, $content){
$pid = isset($tag['pid']) ? 'pid=' . $tag['pid'] : '';
$pid = isset($tag['pid']) ? $tag['pid'] : '';
$tree = isset($tag['tree']) ? $tag['tree'] : 1;
$parse = $parse = '<?php ';
$parse .= '$__NAV__ = db(\'Channel\')->where("status=1")->where("'.$pid.'")->order("sort")->select();';
if($tree == 1){
$parse .= '$__NAV__ = list_to_tree($__NAV__, "id", "pid");';
}
$parse = '<?php ';
$parse .= '$__NAV__ = \\app\\model\\Channel::getChannelList('.$pid.', '.$tree.');';
$parse .= 'foreach ($__NAV__ as $key => $'.$tag['name'].') {';
$parse .= '?>';
$parse .= $content;
@@ -43,20 +36,14 @@ class Sent extends \think\template\TagLib {
public function tagdoc($tag, $content){
$model = !empty($tag['model']) ? $tag['model']:'';
$cid = !empty($tag['cid']) ? $tag['cid']:'0';
$cid = (!empty($tag['cid']) && is_integer($tag['limit'])) ? $tag['cid']:'0';
$field = empty($tag['field']) ? '*' : $tag['field'];
$limit = empty($tag['limit']) ? 20 : $tag['limit'];
$limit = (!empty($tag['limit']) && is_integer($tag['limit'])) ? $tag['limit'] : 20;
$order = empty($tag['order']) ? 'id desc' : $tag['order'];
$name = isset($tag['name']) ? $tag['name'] : 'item';
//获得当前栏目的所有子栏目
$ids = get_category_child($cid);
$ids = implode(',', $ids);
$where = "category_id IN ({$ids})";
$where .= " and status >= 1";
$parse = $parse = '<?php ';
$parse .= '$__LIST__ = M(\''.$model.'\')->where(\''.$where.'\')->field(\''.$field.'\')->limit(\''.$limit.'\')->order(\''.$order.'\')->select();';
$parse .= '$__LIST__ = \\app\\model\\Document::getDocumentList("'.$model.'", '.$cid.', '.$limit.', "'.$order.'", "'.$field.'");';
$parse .= 'foreach ($__LIST__ as $key => $'.$tag['name'].') {';
$parse .= '?>';
$parse .= $content;
@@ -64,45 +51,6 @@ class Sent extends \think\template\TagLib {
return $parse;
}
public function taglist($tag, $content){
$name = !empty($tag['name']) ? $tag['name'] : '';
$map = !empty($tag['map']) ? $tag['map'] : '';
$field = empty($tag['field']) ? '*' : $tag['field'];
$limit = empty($tag['limit']) ? 20 : $tag['limit'];
$order = empty($tag['order']) ? 'id desc' : $tag['order'];
$where[] = "status > 0";
if ($map) {
$where[] = $map;
}
$map = implode(" and ", $where);
$parse = $parse = '<?php ';
$parse .= '$__LIST__ = model(\''.$name.'\')->where(\''.$map.'\')->field(\''.$field.'\')->limit(\''.$limit.'\')->order(\''.$order.'\')->select();';
$parse .= 'foreach ($__LIST__ as $key => $'.$tag['id'].') {';
$parse .= '?>';
$parse .= $content;
$parse .= '<?php } ?>';
return $parse;
}
public function tagrecom($tag, $content){
$model = empty($tag['model']) ? '' : $tag['model'];
$field = empty($tag['field']) ? '*' : $tag['field'];
$limit = empty($tag['limit']) ? 20 : $tag['limit'];
$order = empty($tag['order']) ? 'id desc' : $tag['order'];
if (!$model) {
return '';
}
$parse = $parse = '<?php ';
$parse .= '$__LIST__ = M(\''.$model.'\')->recom(\'' .$field. '\',' .$limit. ',\'' .$order. '\');';
$parse .= 'foreach ($__LIST__ as $key => $'.$tag['id'].') {';
$parse .= '?>';
$parse .= $content;
$parse .= '<?php } ?>';
return $parse;
}
public function taglink($tag, $content){
$type = !empty($tag['type']) ? $tag['type'] : '';
$limit = !empty($tag['limit']) ? $tag['limit'] : '';
@@ -117,37 +65,11 @@ class Sent extends \think\template\TagLib {
$map = implode(" and ", $where);
$parse = $parse = '<?php ';
$parse .= '$__LIST__ = model(\'Link\')->where(\''.$map.'\')->field(\''.$field.'\')->limit(\''.$limit.'\')->order(\''.$order.'\')->select();';
$parse .= '$__LIST__ = \\app\\model\\Link::where(\''.$map.'\')->field(\''.$field.'\')->limit(\''.$limit.'\')->order(\''.$order.'\')->select();';
$parse .= 'foreach ($__LIST__ as $key => $'.$tag['name'].') {';
$parse .= '?>';
$parse .= $content;
$parse .= '<?php } ?>';
return $parse;
}
public function tagprev($tag, $content){
$id = !empty($tag['id']) ? $tag['id'] : '';
$cate = !empty($tag['cate']) ? $tag['cate'] : '';
$model = !empty($tag['model']) ? $tag['model'] : '';
$parse = '<?php ';
$parse .= '$map = "category_id=" . ' . $cate . ' . " and id>" . ' . $id . ';';
$parse .= '$prev = db(\''.$model.'\')->where($map)->order(\'id asc\')->find();if(!empty($prev)){ ?>';
$parse .= $content;
$parse .= '<?php } ?>';
return $parse;
}
public function tagnext($tag, $content){
$id = !empty($tag['id']) ? ($tag['id']) : '';
$cate = !empty($tag['cate']) ? $tag['cate'] : '';
$model = !empty($tag['model']) ? $tag['model'] : '';
$parse = '<?php ';
$parse .= '$map = "category_id=" . ' . $cate . ' . " and id<" . ' . $id . ';';
$parse .= '$next = db(\''.$model.'\')->where($map)->order(\'id desc\')->find();if(!empty($next)){ ?>';
$parse .= $content;
$parse .= '<?php } ?>';
return $parse;
}
}

View File

@@ -1,2 +1,3 @@
User-agent: *
Disallow:
Disallow: /template