12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- <?php
- namespace Content\Lib;
- use Dever;
- class Search
- {
- # 获取搜索信息
- public function getInfo()
- {
- $info = array();
- $tid = Dever::input('tid');
- if ($tid) {
- $info = Dever::db('tag/info')->find($tid);
- if (!$info) {
- Dever::alert('标签已失效或者不存在');
- }
- }
- $t = Dever::input('keyboard');
- if ($t) {
- $info['name'] = $t;
- }
- if (!$info) {
- Dever::alert('检索出现问题,请重试');
- }
- return $info;
- }
- # 获取检索的数据列表
- public function getAll()
- {
- $data = array();
- $tid = Dever::input('tid');
- if ($tid) {
- $data = Dever::load('tag/api')->getData($tid);
- if ($data) {
- foreach ($data as $k => $v) {
- $data[$k]['info'] = Dever::db($v['type'])->one($v['type_id']);
- $data[$k]['link'] = Dever::load('content/lib/common')->getInfoLink($v['type'], $v['type_id']);
- $data[$k]['cdate'] = date('Y-m-d', $data[$k]['info']['pdate']);
- $cate = Dever::db('content/cate')->one($data[$k]['info']['cate_id']);
- $data[$k]['cate_name'] = $cate['name'];
- $data[$k]['cate_link'] = Dever::load('content/lib/common')->getCateLink(1, $cate['id']);
- }
- }
- } else {
- $t = Dever::input('keyboard');
- if ($t) {
- $where['name'] = $t;
- $data = Dever::db('content/search')->getAll($where);
- foreach ($data as $k => $v) {
- if ($v['type'] == 1) {
- $v['type'] = 'content/article';
- } elseif ($v['type'] == 2) {
- $v['type'] = 'content/album';
- } elseif ($v['type'] == 3) {
- $v['type'] = 'content/video';
- }
- $data[$k]['info'] = Dever::db($v['type'])->one($v['data_id']);
- $data[$k]['link'] = Dever::load('content/lib/common')->getInfoLink($v['type'], $v['data_id']);
- $data[$k]['cdate'] = date('Y-m-d', $data[$k]['info']['pdate']);
- $cate = Dever::db('content/cate')->one($data[$k]['info']['cate_id']);
- $data[$k]['cate_name'] = $cate['name'];
- $data[$k]['cate_link'] = Dever::load('content/lib/common')->getCateLink(1, $cate['id']);
- }
- }
- }
- return $data;
- }
- }
|