News.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. } else {
  66. $info['video_info'] = '';
  67. $info['video_id'] = '';
  68. $info['video_link'] = '';
  69. }
  70. $info['sname'] = $info['name'] . '<br />' . $info['desc'];
  71. return $info;
  72. }
  73. }