News.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. if ($type == 3) {
  34. $data = Dever::db('content/news')->getAllVideo($where);
  35. } else {
  36. $data = Dever::db('content/news')->getAll($where);
  37. }
  38. if ($data) {
  39. foreach ($data as $k => $v) {
  40. $data[$k] = $this->getOne($v);
  41. }
  42. }
  43. return $data;
  44. }
  45. public function getInfo($type, $id)
  46. {
  47. $where = array();
  48. if ($type) {
  49. $where['type'] = $type;
  50. }
  51. $where['id'] = $id;
  52. $data = Dever::db('content/news')->getOne($where);
  53. if ($data) {
  54. $data = $this->getOne($data);
  55. }
  56. return $data;
  57. }
  58. private function getOne($info)
  59. {
  60. if ($info['small_pic']) {
  61. $info['small_pic'] = str_replace('http://8.131.66.239/', 'http://www.virtualbeings.cn/', $info['small_pic']);
  62. }
  63. if ($info['content_video_pic']) {
  64. $info['content_video_pic'] = str_replace('http://8.131.66.239/', 'http://www.virtualbeings.cn/', $info['content_video_pic']);
  65. }
  66. $info['pic'] = str_replace('http://8.131.66.239/', 'http://www.virtualbeings.cn/', $info['pic']);
  67. $info['link'] = Dever::url('main/article?type='.$info['type'].'&id=' . $info['id']);
  68. $info['pdate_string'] = date('M d, Y', $info['pdate']);
  69. if ($info['author']) {
  70. $info['pdate_string'] .= ' by ' . $info['author'];
  71. }
  72. $info['pdate_s'] = date('Y/m/d', $info['pdate']);
  73. $info['video_link'] = Dever::url('main/content.video?id=' . $info['id']);
  74. /*
  75. if ($info['video'] && strstr($info['video'], '.qq.com')) {
  76. $info['video_info'] = Dever::qqvideo($info['video'], 2);
  77. $info['video_id'] = isset($info['video_info'][1]) ? $info['video_info'][1] : 0;
  78. $info['video_link'] = isset($info['video_info'][0]) ? $info['video_info'][0] : '';
  79. } else {
  80. $info['video_info'] = '';
  81. $info['video_id'] = '';
  82. $info['video_link'] = $info['video'];
  83. }
  84. */
  85. $info['sname'] = $info['name'] . '<br />' . $info['desc'];
  86. return $info;
  87. }
  88. }