Search.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. namespace Content\Lib;
  3. use Dever;
  4. class Search
  5. {
  6. # 获取搜索信息
  7. public function getInfo()
  8. {
  9. $info = array();
  10. $tid = Dever::input('tid');
  11. if ($tid) {
  12. $info = Dever::db('tag/info')->find($tid);
  13. if (!$info) {
  14. Dever::alert('标签已失效或者不存在');
  15. }
  16. }
  17. $t = Dever::input('keyboard');
  18. if ($t) {
  19. $info['name'] = $t;
  20. }
  21. if (!$info) {
  22. Dever::alert('检索出现问题,请重试');
  23. }
  24. return $info;
  25. }
  26. # 获取检索的数据列表
  27. public function getAll()
  28. {
  29. $data = array();
  30. $tid = Dever::input('tid');
  31. if ($tid) {
  32. $data = Dever::load('tag/api')->getData($tid);
  33. if ($data) {
  34. foreach ($data as $k => $v) {
  35. $data[$k]['info'] = Dever::db($v['type'])->one($v['type_id']);
  36. $data[$k]['link'] = Dever::load('content/lib/common')->getInfoLink($v['type'], $v['type_id']);
  37. $data[$k]['cdate'] = date('Y-m-d', $data[$k]['info']['pdate']);
  38. $cate = Dever::db('content/cate')->one($data[$k]['info']['cate_id']);
  39. $data[$k]['cate_name'] = $cate['name'];
  40. $data[$k]['cate_link'] = Dever::load('content/lib/common')->getCateLink(1, $cate['id']);
  41. }
  42. }
  43. } else {
  44. $t = Dever::input('keyboard');
  45. if ($t) {
  46. $where['name'] = $t;
  47. $data = Dever::db('content/search')->getAll($where);
  48. foreach ($data as $k => $v) {
  49. if ($v['type'] == 1) {
  50. $v['type'] = 'content/article';
  51. } elseif ($v['type'] == 2) {
  52. $v['type'] = 'content/album';
  53. } elseif ($v['type'] == 3) {
  54. $v['type'] = 'content/video';
  55. }
  56. $data[$k]['info'] = Dever::db($v['type'])->one($v['data_id']);
  57. $data[$k]['link'] = Dever::load('content/lib/common')->getInfoLink($v['type'], $v['data_id']);
  58. $data[$k]['cdate'] = date('Y-m-d', $data[$k]['info']['pdate']);
  59. $cate = Dever::db('content/cate')->one($data[$k]['info']['cate_id']);
  60. $data[$k]['cate_name'] = $cate['name'];
  61. $data[$k]['cate_link'] = Dever::load('content/lib/common')->getCateLink(1, $cate['id']);
  62. }
  63. }
  64. }
  65. return $data;
  66. }
  67. }