News.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. namespace Content\Lib;
  3. use Dever;
  4. class News
  5. {
  6. # 获取几条数据
  7. public function getHome($type = 1, $limit = 3, $page = 'article')
  8. {
  9. $where = array();
  10. if ($type) {
  11. $where['type'] = $type;
  12. }
  13. $where['limit'] = '0,' . $limit;
  14. $data = Dever::db('content/news')->getHome($where);
  15. if ($data) {
  16. foreach ($data as $k => $v) {
  17. $data[$k] = $this->getOne($v);
  18. }
  19. }
  20. return $data;
  21. }
  22. # 获取几条数据
  23. public function getAll($type = 1, $name = '')
  24. {
  25. $where = array();
  26. if ($type && $type > 0) {
  27. $where['type'] = $type;
  28. }
  29. if($name) {
  30. $where['name'] = $name;
  31. }
  32. $data = Dever::db('content/news')->getAll($where);
  33. if ($data) {
  34. foreach ($data as $k => $v) {
  35. $data[$k] = $this->getOne($v);
  36. }
  37. }
  38. return $data;
  39. }
  40. public function getInfo($type, $id)
  41. {
  42. $where = array();
  43. if ($type) {
  44. $where['type'] = $type;
  45. }
  46. $data = Dever::db('content/news')->getOne($where);
  47. if ($data) {
  48. $data = $this->getOne($data);
  49. }
  50. return $data;
  51. }
  52. private function getOne($info)
  53. {
  54. $info['link'] = Dever::url('main/article?type='.$info['type'].'&id=' . $info['id']);
  55. $info['pdate_string'] = date('M d, Y', $info['pdate']);
  56. if ($info['author']) {
  57. $info['pdate_string'] .= ' by ' . $info['author'];
  58. }
  59. $info['pdate_s'] = date('Y/m/d', $info['pdate']);
  60. if ($info['video']) {
  61. $info['video_info'] = Dever::qqvideo($info['video'], 2);
  62. $info['video_id'] = isset($info['video_info'][1]) ? $info['video_info'][1] : 0;
  63. $info['video_link'] = isset($info['video_info'][0]) ? $info['video_info'][0] : '';
  64. }
  65. $info['sname'] = $info['name'] . '<br />' . $info['desc'];
  66. return $info;
  67. }
  68. }