diff --git a/app/common/taglib/Zz.php b/app/common/taglib/Zz.php index e47d00d..c60def6 100644 --- a/app/common/taglib/Zz.php +++ b/app/common/taglib/Zz.php @@ -199,7 +199,7 @@ class Zz extends TagLib{ } /** - * tagAdvert + * tagAdvert 广告 * @param $tag * @param $content * @return string diff --git a/app/index/common.php b/app/index/common.php index ea87b63..c1e16c8 100644 --- a/app/index/common.php +++ b/app/index/common.php @@ -3,13 +3,16 @@ // +---------------------------------------------------------------------- use think\facade\Db; use think\Exception; + // 应用公共文件 /** * 中文字符截取 */ -function cn_substr($str,$len){ - return mb_substr($str,0,$len,'utf-8'); +function cn_substr($str, $len) +{ + return mb_substr($str, 0, $len, 'utf-8'); } + /** * 时间戳格式化 */ @@ -19,40 +22,45 @@ function cn_substr($str,$len){ /** * 过滤html标签 */ -function html2text($str){ +function html2text($str) +{ return strip_tags($str); } + /** * 获取文章分类的内容 * $id=文章id * $strip=true过滤html */ -function get_type_content($id,$strip=false){ - $dc=\app\common\model\DocumentCategoryContent::find($id); - if(!$dc){ +function get_type_content($id, $strip = false) +{ + $dc = \app\common\model\DocumentCategoryContent::find($id); + if (!$dc) { return ''; } - if($strip){ + if ($strip) { return html2text($dc['content']); } return $dc['content']; } + /** * 获取文章分类 */ -function get_document_category_list(){ +function get_document_category_list() +{ //缓存文章菜单 - $documentCategory=cache('DATA_DOCUMENT_CATEGORY_LIST'); - if($documentCategory===null){ - $documentCategoryList= \app\common\model\DocumentCategory::where('status',1)->order('sort asc')->select()->toArray(); + $documentCategory = cache('DATA_DOCUMENT_CATEGORY_LIST'); + if ($documentCategory === null) { + $documentCategoryList = \app\common\model\DocumentCategory::where('status', 1)->order('sort asc')->select()->toArray(); //转换,让id作为数组的键 - $documentCategory=[]; - foreach ($documentCategoryList as $key=>$item){ + $documentCategory = []; + foreach ($documentCategoryList as $key => $item) { //根据栏目类型,生成栏目url - $item['url']=curl($item); - $documentCategory[$item['id']]=$item; + $item['url'] = curl($item); + $documentCategory[$item['id']] = $item; } - cache('DATA_DOCUMENT_CATEGORY_LIST',$documentCategory); + cache('DATA_DOCUMENT_CATEGORY_LIST', $documentCategory); } return $documentCategory; } @@ -61,19 +69,19 @@ function get_document_category_list(){ /** * 获取一个文章分类 */ -function get_document_category($x,$field=false){ - if(!$x){ - throw new Exception('请指定要获取的栏目分类id!'); +function get_document_category($x, $field = false) +{ + if (!$x) { + throw new Exception('请指定要获取的栏目分类id!'); } //获取缓存的文章菜单 - $documentCategoryList=get_document_category_list(); - if(!isset($documentCategoryList[$x])){ - return false; + $documentCategoryList = get_document_category_list(); + if (!isset($documentCategoryList[$x])) { + return false; } - if($field){ + if ($field) { return $documentCategoryList[$x][$field]; - } - else{ + } else { return $documentCategoryList[$x]; } } @@ -81,26 +89,26 @@ function get_document_category($x,$field=false){ /** * 获取一个文章分类-通个分类标识 */ -function get_document_category_by_name($name,$field=false){ - if(!$name){ - throw new Exception('请指定要获取的栏目分类标识!'); +function get_document_category_by_name($name, $field = false) +{ + if (!$name) { + throw new Exception('请指定要获取的栏目分类标识!'); } //获取缓存的文章菜单 - $documentCategoryList=get_document_category_list(); - $documentCategory=false; - foreach ($documentCategoryList as $item){ - if($item['name']==$name){ - $documentCategory=$item; + $documentCategoryList = get_document_category_list(); + $documentCategory = false; + foreach ($documentCategoryList as $item) { + if ($item['name'] == $name) { + $documentCategory = $item; break; } } - if(!$documentCategory){ + if (!$documentCategory) { return false; } - if($field){ + if ($field) { return $documentCategory[$field]; - } - else{ + } else { return $documentCategory; } } @@ -108,168 +116,172 @@ function get_document_category_by_name($name,$field=false){ /** * 模板-获取文章分类 */ -function tpl_get_channel($type,$typeid,$row=100,$where='',$orderby='',$display=1){ +function tpl_get_channel($type, $typeid, $row = 100, $where = '', $orderby = '', $display = 1) +{ - switch($type){ + switch ($type) { case 'top': //获取顶级分类 - return get_document_category_by_parent(0,$row,$display); + return get_document_category_by_parent(0, $row, $display); break; case 'son': //获取子级分类 - if(!$typeid){ - throw new Exception('请指定要获取的栏目分类id!'); + if (!$typeid) { + throw new Exception('请指定要获取的栏目分类id!'); } - return get_document_category_by_parent($typeid,$row,$display); + return get_document_category_by_parent($typeid, $row, $display); break; case 'self': //获取同级分类 - if(!$typeid){ - throw new Exception('请指定要获取的栏目分类id!'); + if (!$typeid) { + throw new Exception('请指定要获取的栏目分类id!'); } - $dc=get_document_category($typeid); - if(!$dc){ + $dc = get_document_category($typeid); + if (!$dc) { return false; } - return get_document_category_by_parent($dc['pid'],$row,$display);; + return get_document_category_by_parent($dc['pid'], $row, $display);; break; case 'find': //获取所有子孙分类,此操作读取数据库,非缓存! - if(!$typeid){ - throw new Exception('请指定要获取的栏目分类id!'); + if (!$typeid) { + throw new Exception('请指定要获取的栏目分类id!'); } - $dc=get_document_category($typeid); - if(!$dc){ - throw new Exception('分类不存在或已删除!'); + $dc = get_document_category($typeid); + if (!$dc) { + throw new Exception('分类不存在或已删除!'); } - $tempArr=\app\common\model\DocumentCategory::where('id','in',$dc['child'])->where('status',1)->limit($row); - if($display){ - $tempArr=$tempArr->where('display',1); + $tempArr = \app\common\model\DocumentCategory::where('id', 'in', $dc['child'])->where('status', 1)->limit($row); + if ($display) { + $tempArr = $tempArr->where('display', 1); } - $tempArr=$tempArr->select(); - foreach ($tempArr as $key=>$item){ + $tempArr = $tempArr->select(); + foreach ($tempArr as $key => $item) { //根据栏目类型,生成栏目url - $item['url']=curl($item); - $tempArr[$key]=$item; + $item['url'] = curl($item); + $tempArr[$key] = $item; } return $tempArr; break; case 'parent': //获取父级分类 - if(!$typeid){ - throw new Exception('请指定要获取的栏目分类id!'); + if (!$typeid) { + throw new Exception('请指定要获取的栏目分类id!'); } - $dc=get_document_category($typeid); - $tempArr=array(); - $parent=get_document_category($dc['pid']); - array_push($tempArr,$parent); + $dc = get_document_category($typeid); + $tempArr = array(); + $parent = get_document_category($dc['pid']); + array_push($tempArr, $parent); return $tempArr; break; case 'root': - if(!$typeid){ - throw new Exception('请指定要获取的栏目分类id!'); + if (!$typeid) { + throw new Exception('请指定要获取的栏目分类id!'); } - $dc=get_document_category($typeid); - if($dc['pid']!=0){ + $dc = get_document_category($typeid); + if ($dc['pid'] != 0) { //获取根分类,此操作读取数据库,非缓存! - $dc=\app\common\model\DocumentCategory::where('pid',0)->where('status',1) - -> where("CONCAT(',',child,',') like '%,$typeid,%'")->limit($row); - if($display){ - $dc=$dc->where('display',1); + $dc = \app\common\model\DocumentCategory::where('pid', 0)->where('status', 1) + ->where("CONCAT(',',child,',') like '%,$typeid,%'")->limit($row); + if ($display) { + $dc = $dc->where('display', 1); } - $dc=$dc->find(); + $dc = $dc->find(); } //根据栏目类型,生成栏目url - $dc['url']=curl($dc); - $tempArr=[]; - array_push($tempArr,$dc); + $dc['url'] = curl($dc); + $tempArr = []; + array_push($tempArr, $dc); return $tempArr; break; case 'where': //根据自定义条件获取分类(where语句),此操作读取数据库,非缓存! - $tempArr=\app\common\model\DocumentCategory::where('status',1)-> where($where)->order($orderby)->limit($row); - if($display){ - $tempArr=$tempArr->where('display',1); + $tempArr = \app\common\model\DocumentCategory::where('status', 1)->where($where)->order($orderby)->limit($row); + if ($display) { + $tempArr = $tempArr->where('display', 1); } - $tempArr=$tempArr->select(); - foreach ($tempArr as $key=>$item){ + $tempArr = $tempArr->select(); + foreach ($tempArr as $key => $item) { //根据栏目类型,生成栏目url - $item['url']=curl($item); - $tempArr[$key]=$item; + $item['url'] = curl($item); + $tempArr[$key] = $item; } return $tempArr; break; case 'ids': //根据多个栏目id,逗号隔开的那种,获得栏目列表 - $tempArr=\app\common\model\DocumentCategory::where('status',1)-> where('id','in',$typeid)->order($orderby)->limit($row); - if($display){ - $tempArr=$tempArr->where('display',1); + $tempArr = \app\common\model\DocumentCategory::where('status', 1)->where('id', 'in', $typeid)->order($orderby)->limit($row); + if ($display) { + $tempArr = $tempArr->where('display', 1); } - $tempArr=$tempArr->select(); - foreach ($tempArr as $key=>$item){ + $tempArr = $tempArr->select(); + foreach ($tempArr as $key => $item) { //根据栏目类型,生成栏目url - $item['url']=curl($item); - $tempArr[$key]=$item; + $item['url'] = curl($item); + $tempArr[$key] = $item; } return $tempArr; break; - default: - $tempArr=[]; + default: + $tempArr = []; return $tempArr; - break; + break; } } + /** * 根据父级分类id获取子分类 * $pid=父级id * $row=获取多少数目 */ -function get_document_category_by_parent($pid,$row,$display=1){ - $documentCategoryList=get_document_category_list(); - $x=1; - $tempArr=array(); - foreach ($documentCategoryList as $item){ - if($x>$row){ +function get_document_category_by_parent($pid, $row, $display = 1) +{ + $documentCategoryList = get_document_category_list(); + $x = 1; + $tempArr = array(); + foreach ($documentCategoryList as $item) { + if ($x > $row) { break; } - if($item['pid']==$pid&&($display?$item['display']==1:true)){ - $x=$x+1; - array_push($tempArr,$item); + if ($item['pid'] == $pid && ($display ? $item['display'] == 1 : true)) { + $x = $x + 1; + array_push($tempArr, $item); } } return $tempArr; } + /** * 模板-获取上一篇和下一篇 * $get=上一篇|下一篇 * $cid=栏目分类id */ -function tpl_get_prenext($get,$cid=false,$none){ +function tpl_get_prenext($get, $cid = false, $none) +{ //文档id - $id=input('id'); - if(!$get){ - $get='next'; + $id = input('id'); + if (!$get) { + $get = 'next'; } - $document=\app\common\model\Document::where('display',1)->where('status',1); - $document=$get=='pre'?$document->where("id",'<',$id):$document->where("id",'>',$id); + $document = \app\common\model\Document::where('display', 1)->where('status', 1); + $document = $get == 'pre' ? $document->where("id", '<', $id) : $document->where("id", '>', $id); //如果表明在同一分类下查询 - if($cid){ - $document=$document->where("category_id",$cid); + if ($cid) { + $document = $document->where("category_id", $cid); } - $document=$document->field('id,title')->order($get=='pre'?'id desc':'id asc')->find(); - - if($document){ - $document['url']=url('article/detail?id='.$document['id'])->build(); - } - else{ - $document['id']=false; - $document['url']='javascript:void(0)'; - $document['title']=$none; + $document = $document->field('id,title')->order($get == 'pre' ? 'id desc' : 'id asc')->find(); + + if ($document) { + $document['url'] = url('article/detail?id=' . $document['id'])->build(); + } else { + $document['id'] = false; + $document['url'] = 'javascript:void(0)'; + $document['title'] = $none; } return $document; @@ -284,77 +296,76 @@ function tpl_get_prenext($get,$cid=false,$none){ * $table=文章内容扩展表名,默认article * $where=自定义条件 */ -function tpl_get_list($orderby,$pagesize,$cid,$type,$table='article',$where=false,$display=1){ +function tpl_get_list($orderby, $pagesize, $cid, $type, $table = 'article', $where = false, $display = 1) +{ - $documentListModel= (new \app\common\model\Document()) + $documentListModel = (new \app\common\model\Document()) ->alias('a') - ->join(config('database.prefix').'document_category b','a.category_id=b.id','LEFT') - ->join(config('database.prefix')."document_$table c",'a.id=c.id','LEFT') + ->join(config('database.prefix') . 'document_category b', 'a.category_id=b.id', 'LEFT') + ->join(config('database.prefix') . "document_$table c", 'a.id=c.id', 'LEFT') ->where("a.type='$table'") - ->where('a.status',1) - ->where('b.status',1) + ->where('a.status', 1) + ->where('b.status', 1) ->field('a.*,b.title as category_title,c.*'); - if($display){ - $documentListModel=$documentListModel->where('a.display',1); + if ($display) { + $documentListModel = $documentListModel->where('a.display', 1); } - //判断当前是否搜索页面 - if(request()->action()=='search'){ - $type='search'; + //判断当前是否搜索页面 + if (request()->action() == 'search') { + $type = 'search'; } - switch ($type){ + switch ($type) { case 'find': //获取栏目下文章以及所有子孙分类文章 - $dc=get_document_category($cid); - $child=$dc['child']; - if($child){ - $documentListModel=$documentListModel->where('a.category_id','in',"$cid,$child"); - } - else{ - $documentListModel=$documentListModel->where('a.category_id',$cid); + $dc = get_document_category($cid); + $child = $dc['child']; + if ($child) { + $documentListModel = $documentListModel->where('a.category_id', 'in', "$cid,$child"); + } else { + $documentListModel = $documentListModel->where('a.category_id', $cid); } break; case 'son': //获取栏目下文章 - $documentListModel=$documentListModel->where('a.category_id',$cid); + $documentListModel = $documentListModel->where('a.category_id', $cid); break; case 'search': //获取关键字搜索的文章 - $kw=input('kw'); //搜索关键词 - $tid=input('cid');//文章分类Id - if($kw){ - $documentListModel=$documentListModel->where('a.title','like',"%$kw%"); + $kw = input('kw'); //搜索关键词 + $tid = input('cid');//文章分类Id + if ($kw) { + $documentListModel = $documentListModel->where('a.title', 'like', "%$kw%"); } - if($tid){ - $documentListModel=$documentListModel->where('a.category_id',$tid); + if ($tid) { + $documentListModel = $documentListModel->where('a.category_id', $tid); } break; case 'where': //根据自定义条件获取文章(where语句) - $documentListModel=$documentListModel->where($where); + $documentListModel = $documentListModel->where($where); break; case 'tag': //读取指定tag的文章 - $documentListModel=$documentListModel->where('a.keywords','like',"%$where%"); + $documentListModel = $documentListModel->where('a.keywords', 'like', "%$where%"); break; } - $documentListModel=$documentListModel->order($orderby); + $documentListModel = $documentListModel->order($orderby); //获取当前请求的请求参数,以确定分页是否要带上这些请求参数 - $query=request()->query(); - if($query){ - $documentListModel=$documentListModel->paginate($pagesize,false,['query' => getRouteQuery()]); - } - else{ - $documentListModel=$documentListModel->paginate($pagesize); - } - $lists=[]; - foreach ($documentListModel as $key=>$item){ - //生成文章url - $item['url']=aurl($item); - $lists[$key]=$item; + $query = request()->query(); + if ($query) { + $documentListModel = $documentListModel->paginate($pagesize, false, ['query' => getRouteQuery()]); + } else { + $documentListModel = $documentListModel->paginate($pagesize); } - $re=[ - 'model'=>$documentListModel, - 'lists'=>$lists + $lists = []; + foreach ($documentListModel as $key => $item) { + //生成文章url + $item['url'] = aurl($item); + $lists[$key] = $item; + } + $re = [ + 'model' => $documentListModel, + 'lists' => $lists ]; return $re; } @@ -363,24 +374,24 @@ function tpl_get_list($orderby,$pagesize,$cid,$type,$table='article',$where=fals * 获得当前路由及参数列表 * @return mixed */ -function getRouteQuery(){ - $request=request(); - $queryArr=$request->param(); - $queryArr['s']=$request->pathinfo(); +function getRouteQuery() +{ + $request = request(); + $queryArr = $request->param(); + $queryArr['s'] = $request->pathinfo(); return $queryArr; } /** * 根据栏目类型,生成栏目url */ -function curl($item){ - if((int)$item['type']==0){ - return url('article/lists?id='.$item['id'])->build(); - } - elseif((int)$item['type']==1){ - return url('article/lists?id='.$item['id'])->build(); - } - elseif((int)$item['type']==2){ +function curl($item) +{ + if ((int)$item['type'] == 0) { + return url('article/lists?id=' . $item['id'])->build(); + } elseif ((int)$item['type'] == 1) { + return url('article/lists?id=' . $item['id'])->build(); + } elseif ((int)$item['type'] == 2) { return $item['link_str']; } } @@ -388,13 +399,13 @@ function curl($item){ /** * 生成文章url */ -function aurl($item){ +function aurl($item) +{ //根据栏目类型,生成栏目url - if($item['link_str']){ + if ($item['link_str']) { return $item['link_str']; - } - else{ - return url('article/detail?id='.$item['id'])->build(); + } else { + return url('article/detail?id=' . $item['id'])->build(); } } @@ -402,20 +413,21 @@ function aurl($item){ /** * 模板-根据指定的文章id获取文章内容 */ -function tpl_get_article($id,$table){ - $documentModel=\app\common\model\Document::alias('a') - ->join(config('database.prefix').'document_category b','a.category_id=b.id','LEFT') - ->join(config('database.prefix')."document_$table c",'a.id=c.id','LEFT') - ->where('a.status',1)->where('a.id',$id)->where("a.type='$table'") +function tpl_get_article($id, $table) +{ + $documentModel = \app\common\model\Document::alias('a') + ->join(config('database.prefix') . 'document_category b', 'a.category_id=b.id', 'LEFT') + ->join(config('database.prefix') . "document_$table c", 'a.id=c.id', 'LEFT') + ->where('a.status', 1)->where('a.id', $id)->where("a.type='$table'") ->field('a.*,b.title as category_title,c.*'); - $doc=$documentModel->find(); + $doc = $documentModel->find(); - if(!$doc){ + if (!$doc) { return false; } - $doc['url']=aurl($doc); + $doc['url'] = aurl($doc); return $doc; } @@ -430,55 +442,55 @@ function tpl_get_article($id,$table){ * $type=读取数据的方式(son:'获取栏目下文章以及所有子孙分类文章',self:'获取栏目下文章',search:'获取关键字搜索的文章',where:'根据自定义条件获取文章(where语句)') * $where=自定义条件 */ -function tpl_get_article_list($cid,$row,$orderby,$table='article',$type='son',$where=false,$display=1,$ids=''){ +function tpl_get_article_list($cid, $row, $orderby, $table = 'article', $type = 'son', $where = false, $display = 1, $ids = '') +{ - $documentListModel=\app\common\model\Document::alias('a') - ->join(config('database.prefix').'document_category b','a.category_id=b.id','LEFT') - ->join(config('database.prefix')."document_$table c",'a.id=c.id','RIGHT') - ->where("a.type='$table'")->where('a.status',1)->where('b.status',1) + $documentListModel = \app\common\model\Document::alias('a') + ->join(config('database.prefix') . 'document_category b', 'a.category_id=b.id', 'LEFT') + ->join(config('database.prefix') . "document_$table c", 'a.id=c.id', 'RIGHT') + ->where("a.type='$table'")->where('a.status', 1)->where('b.status', 1) ->limit($row) ->field('a.*,b.title as category_title,c.*'); - if($display){ - $documentListModel=$documentListModel->where('a.display',1); + if ($display) { + $documentListModel = $documentListModel->where('a.display', 1); } - switch ($type){ + switch ($type) { case 'find': //获取栏目下文章以及所有子孙分类文章 - $dc=get_document_category($cid); - $child=$dc['child']; - if($child){ - $documentListModel=$documentListModel->where('a.category_id','in',"$cid,$child"); - } - else{ - $documentListModel=$documentListModel->where('a.category_id',$cid); + $dc = get_document_category($cid); + if (!empty($dc['child'])) { + $child = $dc['child']; + $documentListModel = $documentListModel->where('a.category_id', 'in', "$cid,$child"); + } else { + $documentListModel = $documentListModel->where('a.category_id', $cid); } break; case 'son': //获取栏目下文章 - $documentListModel=$documentListModel->where('a.category_id',$cid); + $documentListModel = $documentListModel->where('a.category_id', $cid); break; case 'where': //根据自定义条件获取文章(where语句) - $documentListModel=$documentListModel->where($where); + $documentListModel = $documentListModel->where($where); break; case 'ids': //读取指定id的文章 - $documentListModel=$documentListModel->where('a.id','in',$ids); + $documentListModel = $documentListModel->where('a.id', 'in', $ids); break; case 'tag': //读取指定tag的文章 - $documentListModel=$documentListModel->where('a.keywords','like',"%$where%"); + $documentListModel = $documentListModel->where('a.keywords', 'like', "%$where%"); break; } - $documentListModel=$documentListModel->order($orderby)->select(); - $lists=[]; - foreach ($documentListModel as $key=>$item){ + $documentListModel = $documentListModel->order($orderby)->select(); + $lists = []; + foreach ($documentListModel as $key => $item) { //生成文章url - $item['url']=aurl($item); - $lists[$key]=$item; + $item['url'] = aurl($item); + $lists[$key] = $item; } return $lists; } @@ -492,26 +504,28 @@ function tpl_get_article_list($cid,$row,$orderby,$table='article',$type='son',$w * $type=读取数据的方式(son:'获取栏目下文章以及所有子孙分类文章',self:'获取栏目下文章',search:'获取关键字搜索的文章',where:'根据自定义条件获取文章(where语句)') * $where=自定义条件 */ -function tpl_get_product_list($cid,$row,$orderby,$table='article',$type='son',$where=false,$display=1){ - return tpl_get_article_list($cid,$row,$orderby,'product',$type,$where,$display); +function tpl_get_product_list($cid, $row, $orderby, $table = 'article', $type = 'son', $where = false, $display = 1) +{ + return tpl_get_article_list($cid, $row, $orderby, 'product', $type, $where, $display); } /** * 模板-友情链接 */ -function tpl_get_friend_link($type,$row){ - $flinkList=cache('DATA_FRIEND_LINK'); - if($flinkList===null){ - $flinkList= \app\common\model\FriendLink::where('status',1)->order('sort asc')->limit($row)->select(); - cache('DATA_FRIEND_LINK',$flinkList); +function tpl_get_friend_link($type, $row) +{ + $flinkList = cache('DATA_FRIEND_LINK'); + if ($flinkList === null) { + $flinkList = \app\common\model\FriendLink::where('status', 1)->order('sort asc')->limit($row)->select(); + cache('DATA_FRIEND_LINK', $flinkList); } - if($type===0){ + if ($type === 0) { return $flinkList; } - $flinkListTemp=[]; - foreach ($flinkList as $key=>$item){ - if($item['image']){ - array_push($flinkListTemp,$item); + $flinkListTemp = []; + foreach ($flinkList as $key => $item) { + if ($item['image']) { + array_push($flinkListTemp, $item); } } return $flinkListTemp; @@ -520,19 +534,20 @@ function tpl_get_friend_link($type,$row){ /** * 模板-poster */ -function tpl_get_banner($type,$row){ - $bannerList=cache('DATA_BANNER'); - if($bannerList===null){ - $bannerList=Db::name('slides')->where('status',1)->order('sort asc')->limit($row)->select(); - cache('DATA_BANNER',$bannerList); +function tpl_get_banner($type, $row) +{ + $bannerList = cache('DATA_BANNER'); + if ($bannerList === null) { + $bannerList = Db::name('slides')->where('status', 1)->order('sort asc')->limit($row)->select(); + cache('DATA_BANNER', $bannerList); } - if($type===0){ + if ($type === 0) { return $bannerList; } - $bannerListTemp=[]; - foreach ($bannerList as $key=>$item){ - if($item['image']){ - array_push($bannerListTemp,$item); + $bannerListTemp = []; + foreach ($bannerList as $key => $item) { + if ($item['image']) { + array_push($bannerListTemp, $item); } } return $bannerListTemp; @@ -549,27 +564,27 @@ function tpl_get_banner($type,$row){ * @author 李玉坤 * @date 2021-07-26 23:24 */ -function tpl_get_advert($type,$row){ - $advertList=cache('DATA_BANNER'); - if($advertList===null){ - $advertList=Db::name('advert')->where('status',1)->order('sort asc')->limit($row)->select(); - cache('DATA_ADVERT',$advertList); +function tpl_get_advert($type, $row) +{ + $advertList = cache('DATA_BANNER'); + if ($advertList === null) { + $advertList = Db::name('advert')->where('status', 1)->order('sort asc')->limit($row)->select(); + cache('DATA_ADVERT', $advertList); } - if($type===0){ + if ($type === 0) { return $advertList; } - $advertListTemp=[]; - foreach ($advertList as $key=>$item){ - if($item['image']){ - array_push($advertListTemp,$item); + $advertListTemp = []; + foreach ($advertList as $key => $item) { + if ($item['image']) { + array_push($advertListTemp, $item); } } return $advertListTemp; } -if (!function_exists('web_config')) -{ +if (!function_exists('web_config')) { /** * 获取系统配置值 * @param string $formName @@ -583,27 +598,28 @@ if (!function_exists('web_config')) function web_config(string $formName): string { $webConfig = cache('systemConfig'); - if (empty($webConfig)){ - $webConfig = Db::name('system_config')->where("status",1)->column('value', 'form_name'); - cache('systemConfig',$webConfig); + if (empty($webConfig)) { + $webConfig = Db::name('system_config')->where("status", 1)->column('value', 'form_name'); + cache('systemConfig', $webConfig); } - return $webConfig[$formName]??''; + return $webConfig[$formName] ?? ''; } } /** * 模板-文章标签 */ -function tpl_get_tags_list($tags){ - if(!$tags){ +function tpl_get_tags_list($tags) +{ + if (!$tags) { return false; } - $tagArr=explode(',',$tags); - $tagTemp=[]; - foreach ($tagArr as $item){ - $data['title']=$item; - $data['url']=url('article/tag?t='.urlencode($item)); - array_push($tagTemp,$data); + $tagArr = explode(',', $tags); + $tagTemp = []; + foreach ($tagArr as $item) { + $data['title'] = $item; + $data['url'] = url('article/tag?t=' . urlencode($item)); + array_push($tagTemp, $data); } return $tagTemp; } @@ -612,28 +628,29 @@ function tpl_get_tags_list($tags){ /** * 模板-获取页面的面包屑导航 */ -function tpl_get_position($dc,$positionList=array()){ - array_push($positionList,$dc); - if($dc['pid']==0){ - $htmlstr='首页'; - $positionListCount=count($positionList); - for ($x=$positionListCount-1;$x>=0;$x--){ - $htmlstr=$htmlstr.'>'.$positionList[$x]['title'].''; +function tpl_get_position($dc, $positionList = array()) +{ + array_push($positionList, $dc); + if ($dc['pid'] == 0) { + $htmlstr = '首页'; + $positionListCount = count($positionList); + for ($x = $positionListCount - 1; $x >= 0; $x--) { + $htmlstr = $htmlstr . '>' . $positionList[$x]['title'] . ''; } return $htmlstr; } //获取父级栏目分类 - $parentDc=get_document_category($dc['pid']); - return tpl_get_position($parentDc,$positionList); + $parentDc = get_document_category($dc['pid']); + return tpl_get_position($parentDc, $positionList); } //获取顶级栏目名 -function GetTopTypename($id=false) +function GetTopTypename($id = false) { - $id=$id?$id:input('id'); - $dc=get_document_category($id); - if((int)$dc['pid']===0){ + $id = $id ? $id : input('id'); + $dc = get_document_category($id); + if ((int)$dc['pid'] === 0) { return $dc['title']; } @@ -641,11 +658,11 @@ function GetTopTypename($id=false) } //获取顶级id -function GetTopTypeid($id=false) +function GetTopTypeid($id = false) { - $id=$id?$id:input('id'); - $dc=get_document_category($id); - if((int)$dc['pid']===0){ + $id = $id ? $id : input('id'); + $dc = get_document_category($id); + if ((int)$dc['pid'] === 0) { return $dc['id']; } @@ -653,69 +670,72 @@ function GetTopTypeid($id=false) } //获取顶级栏目图片 -function GetTopTypeimg($id=false) +function GetTopTypeimg($id = false) { - $id=$id?$id:input('id'); - $dc=get_document_category($id); - if((int)$dc['pid']===0){ + $id = $id ? $id : input('id'); + $dc = get_document_category($id); + if ((int)$dc['pid'] === 0) { return $dc['icon']; } return GetTopTypeimg($dc['pid']); } + //获取顶级栏目描述 -function GetTopDescription($id=false) +function GetTopDescription($id = false) { - $id=$id?$id:input('id'); - $dc=get_document_category($id); - if((int)$dc['pid']===0){ + $id = $id ? $id : input('id'); + $dc = get_document_category($id); + if ((int)$dc['pid'] === 0) { return $dc['description']; } return GetTopDescription($dc['pid']); } + //获取顶级英文名称 -function GetTopTypenameen($id=false) +function GetTopTypenameen($id = false) { - $id=$id?$id:input('id'); - $dc=get_document_category($id); - if((int)$dc['pid']===0){ + $id = $id ? $id : input('id'); + $dc = get_document_category($id); + if ((int)$dc['pid'] === 0) { return $dc['name']; } return GetTopTypenameen($dc['pid']); } + /** * 判断当前页面是否在此栏目下 * 主要用于菜单高亮 * $cid=栏目id,首页可不填此参数 * $curr_id=当前页面栏目id,首页可不填此参数 -*/ -function IsActiveNav($curr_cid=false,$cid=false) + */ +function IsActiveNav($curr_cid = false, $cid = false) { - if(request()->action()=='search'){ + if (request()->action() == 'search') { return false; } //首页 - if(!$curr_cid&&!$cid){ + if (!$curr_cid && !$cid) { return true; } //一般在首页中,要比对的栏目id会为false - if($cid==false){ + if ($cid == false) { return false; } //如果分类id相等,是在同一页面中 - if($cid==$curr_cid){ + if ($cid == $curr_cid) { return true; } //判断是否在同一栏目树下。 - $parent_id=cache('curr_category_patent_id'); + $parent_id = cache('curr_category_patent_id'); - $parent_id=explode(',',$parent_id); + $parent_id = explode(',', $parent_id); - if(in_array($cid,$parent_id)){ + if (in_array($cid, $parent_id)) { return true; } @@ -724,13 +744,14 @@ function IsActiveNav($curr_cid=false,$cid=false) // 查看是否为手机端的方法 //判断是手机登录还是电脑登录 -function ismobile() { +function ismobile() +{ // 如果有HTTP_X_WAP_PROFILE则一定是移动设备 if (isset ($_SERVER['HTTP_X_WAP_PROFILE'])) return true; //此条摘自TPM智能切换模板引擎,适合TPM开发 - if(isset ($_SERVER['HTTP_CLIENT']) &&'PhoneClient'==$_SERVER['HTTP_CLIENT']) + if (isset ($_SERVER['HTTP_CLIENT']) && 'PhoneClient' == $_SERVER['HTTP_CLIENT']) return true; //如果via信息含有wap则一定是移动设备,部分服务商会屏蔽该信息 if (isset ($_SERVER['HTTP_VIA'])) @@ -739,7 +760,7 @@ function ismobile() { //判断手机发送的客户端标志,兼容性有待提高 if (isset ($_SERVER['HTTP_USER_AGENT'])) { $clientkeywords = array( - 'nokia','sony','ericsson','mot','samsung','htc','sgh','lg','sharp','sie-','philips','panasonic','alcatel','lenovo','iphone','ipod','blackberry','meizu','android','netfront','symbian','ucweb','windowsce','palm','operamini','operamobi','openwave','nexusone','cldc','midp','wap','mobile' + 'nokia', 'sony', 'ericsson', 'mot', 'samsung', 'htc', 'sgh', 'lg', 'sharp', 'sie-', 'philips', 'panasonic', 'alcatel', 'lenovo', 'iphone', 'ipod', 'blackberry', 'meizu', 'android', 'netfront', 'symbian', 'ucweb', 'windowsce', 'palm', 'operamini', 'operamobi', 'openwave', 'nexusone', 'cldc', 'midp', 'wap', 'mobile' ); //从HTTP_USER_AGENT中查找手机浏览器的关键字 if (preg_match("/(" . implode('|', $clientkeywords) . ")/i", strtolower($_SERVER['HTTP_USER_AGENT']))) { diff --git a/app/index/controller/Article.php b/app/index/controller/Article.php index 250aed0..ae7411f 100644 --- a/app/index/controller/Article.php +++ b/app/index/controller/Article.php @@ -60,7 +60,7 @@ class Article extends Base if(!is_file(config('view.view_path').'category/'.$listTmp)){ $this->error('模板文件不存在!'); } - trace('列表页模板路径:'.config('view.view_path').'category/'.$listTmp,'debug'); + Log::info('列表页模板路径:'.config('view.view_path').'category/'.$listTmp); //文章兼容字段 $dc['category_id']=$dc['id']; //判断seo标题是否存在 @@ -146,29 +146,6 @@ class Article extends Base return $this->fetch('article/'.$detailTmp); } - //自定义页面,可通过参数指定模板文件。完成完全自定义的文件输出。 - //可以输出html片段,甚至可以输出JSON - //参数指定的模板文件必须位于模板文件夹下,且以content_开头,以.htm拓展名结尾 - public function content() - { - $zzField=input(); - if(!isset($zzField['tpl'])){ - $this->error('没有指定模板文件!'); - } - //将参数传递到模板页面 - $this->assign('zzField',$zzField); - //模板兼容性标签 - $this->assign('id',false); - $this->assign('cid',false); - //读取模板配置,获得模板后缀名 - $view_suffix=config('view.view_suffix'); - Log::info('详情页模板路径:'.config('view.view_path').'article/'.'content_'.$zzField['tpl'].'.'.$view_suffix); - cache('curr_category_patent_id',false); - $detailTmp = substr($detailTmp,0,strpos($detailTmp,'.')); - return $this->fetch('article/'.$detailTmp); - return $this->fetch(); - } - //文章标签页面 public function tag() { @@ -193,7 +170,8 @@ class Article extends Base //模板兼容性标签 $this->assign('id',false); $this->assign('cid',false); - return $this->fetch(); + $view_suffix=config('view.view_suffix'); + return $this->fetch('tag.'.$view_suffix); } //搜索页面 @@ -219,6 +197,10 @@ class Article extends Base //模板兼容性标签 $this->assign('id',false); $this->assign('cid',false); + $template = config('view.view_path').'article/search.html'; + if(!is_file($template)){ + $this->error('模板文件不存在!'); + } return $this->fetch(); } } \ No newline at end of file diff --git a/public/template/default/pc/article/detail.html b/public/template/default/pc/article/detail.html index 8928e92..fae4a9e 100644 --- a/public/template/default/pc/article/detail.html +++ b/public/template/default/pc/article/detail.html @@ -2,8 +2,8 @@ {$zzField['title']} - {:web_config("title")} - - + + {include file="public/head" /} @@ -528,145 +528,24 @@