News.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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) {
  27. $where['type'] = $type;
  28. }
  29. $data = Dever::db('content/news')->getAll($where);
  30. if ($data) {
  31. foreach ($data as $k => $v) {
  32. $data[$k] = $this->getOne($v);
  33. }
  34. }
  35. return $data;
  36. }
  37. private function getOne($info)
  38. {
  39. $info['link'] = Dever::url('main/article?type='.$info['type'].'&id=' . $info['id']);
  40. $info['pdate_string'] = date('M d, Y', $info['pdate']);
  41. if ($info['author']) {
  42. $info['pdate_string'] .= ' by ' . $info['author'];
  43. }
  44. $info['pdate_s'] = date('Y/m/d', $info['pdate']);
  45. if ($info['video']) {
  46. $info['video_info'] = Dever::qqvideo($info['video'], 2);
  47. $info['video_id'] = isset($info['video_info'][1]) ? $info['video_info'][1] : 0;
  48. $info['video_link'] = isset($info['video_info'][0]) ? $info['video_info'][0] : '';
  49. }
  50. $info['sname'] = $info['name'] . '<br />' . $info['desc'];
  51. return $info;
  52. }
  53. }