News.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. $where['tag'] = $name;
  32. }
  33. $data = Dever::db('content/news')->getAll($where);
  34. if ($data) {
  35. foreach ($data as $k => $v) {
  36. $data[$k] = $this->getOne($v);
  37. }
  38. }
  39. return $data;
  40. }
  41. public function getInfo($type, $id)
  42. {
  43. $where = array();
  44. if ($type) {
  45. $where['type'] = $type;
  46. }
  47. $data = Dever::db('content/news')->getOne($where);
  48. if ($data) {
  49. $data = $this->getOne($data);
  50. }
  51. return $data;
  52. }
  53. private function getOne($info)
  54. {
  55. $info['link'] = Dever::url('main/article?type='.$info['type'].'&id=' . $info['id']);
  56. $info['pdate_string'] = date('M d, Y', $info['pdate']);
  57. if ($info['author']) {
  58. $info['pdate_string'] .= ' by ' . $info['author'];
  59. }
  60. $info['pdate_s'] = date('Y/m/d', $info['pdate']);
  61. if ($info['video']) {
  62. $info['video_info'] = Dever::qqvideo($info['video'], 2);
  63. $info['video_id'] = isset($info['video_info'][1]) ? $info['video_info'][1] : 0;
  64. $info['video_link'] = isset($info['video_info'][0]) ? $info['video_info'][0] : '';
  65. }
  66. $info['sname'] = $info['name'] . '<br />' . $info['desc'];
  67. return $info;
  68. }
  69. }