News.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. $where['id'] = $id;
  48. $data = Dever::db('content/news')->getOne($where);
  49. if ($data) {
  50. $data = $this->getOne($data);
  51. }
  52. return $data;
  53. }
  54. private function getOne($info)
  55. {
  56. $info['link'] = Dever::url('main/article?type='.$info['type'].'&id=' . $info['id']);
  57. $info['pdate_string'] = date('M d, Y', $info['pdate']);
  58. if ($info['author']) {
  59. $info['pdate_string'] .= ' by ' . $info['author'];
  60. }
  61. $info['pdate_s'] = date('Y/m/d', $info['pdate']);
  62. $info['video_link'] = Dever::url('main/content.video?id=' . $info['id']);
  63. /*
  64. if ($info['video'] && strstr($info['video'], '.qq.com')) {
  65. $info['video_info'] = Dever::qqvideo($info['video'], 2);
  66. $info['video_id'] = isset($info['video_info'][1]) ? $info['video_info'][1] : 0;
  67. $info['video_link'] = isset($info['video_info'][0]) ? $info['video_info'][0] : '';
  68. } else {
  69. $info['video_info'] = '';
  70. $info['video_id'] = '';
  71. $info['video_link'] = $info['video'];
  72. }
  73. */
  74. $info['sname'] = $info['name'] . '<br />' . $info['desc'];
  75. return $info;
  76. }
  77. }