Video.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. namespace Content\Lib;
  3. use Dever;
  4. class Video
  5. {
  6. # 获取文章信息
  7. public function getInfo()
  8. {
  9. $id = Dever::input('id');
  10. $data = Dever::db('content/video')->getOne($id);
  11. if (!$data) {
  12. Dever::alert('错误的视频信息');
  13. }
  14. if ($data['author_id']) {
  15. $data['author'] = Dever::db('content/author')->one($data['author_id']);
  16. }
  17. $data['cdate'] = date('Y年m月d日', $data['pdate']);
  18. $data['tag_html'] = '';
  19. if ($data['tag']) {
  20. $tag_data = Dever::load('tag/api')->tag_content($data['author_id']);
  21. if ($tag_data) {
  22. $data['tag_html'] = '标签:';
  23. foreach ($tag_data as $k => $v) {
  24. $link = Dever::url('search_list?tid=' . $v['id'], 'main');
  25. $data['tag_html'] .= '<a href="'.$link.'" target="_blank">'.$v['name'].'</a>';
  26. }
  27. }
  28. }
  29. # 获取上一篇和下一篇
  30. $where['id'] = $id;
  31. $where['cate_id'] = $data['cate_id'];
  32. $data['prev'] = Dever::db('content/video')->findPrev($where);
  33. if ($data['prev']) {
  34. $data['prev']['link'] = Dever::load('content/lib/common')->getInfoLink(3, $data['prev']['id']);
  35. $data['prev']['cdate'] = date('Y年m月d日', $data['prev']['pdate']);
  36. }
  37. $data['next'] = Dever::db('content/video')->findNext($where);
  38. if ($data['next']) {
  39. $data['next']['link'] = Dever::load('content/lib/common')->getInfoLink(3, $data['next']['id']);
  40. $data['next']['cdate'] = date('Y年m月d日', $data['next']['pdate']);
  41. }
  42. //print_r($data);die;
  43. $data['up_url'] = Dever::url('content/lib/video.addUp?id=' . $data['id']);
  44. $this->addView($id);
  45. return $data;
  46. }
  47. # 获取最新列表
  48. public function getAll()
  49. {
  50. $where = array();
  51. $cate_id = Dever::input('cid');
  52. if ($cate_id > 0) {
  53. $where['cate_id'] = $cate_id;
  54. }
  55. $data = Dever::db('content/video')->getAll($where);
  56. if ($data) {
  57. foreach ($data as $k => $v) {
  58. $data[$k]['link'] = Dever::load('content/lib/common')->getInfoLink(3, $v['id']);
  59. $data[$k]['cdate'] = date('Y-m-d', $v['pdate']);
  60. }
  61. }
  62. return $data;
  63. }
  64. # 获取相关推荐
  65. public function getRelation($info)
  66. {
  67. $where['noid'] = Dever::input('id');
  68. $data = Dever::db('content/video')->getOne($where['noid']);
  69. $where['cate_id'] = $data['cate_id'];
  70. $data = Dever::db('content/video')->getRelation($where);
  71. if ($data) {
  72. foreach ($data as $k => $v) {
  73. $data[$k]['link'] = Dever::load('content/lib/common')->getInfoLink(3, $v['id']);
  74. }
  75. }
  76. return $data;
  77. }
  78. # 增加浏览量
  79. public function addView($id)
  80. {
  81. Dever::db('content/video')->addView(array('where_id' => $id, 'set_num_view' => 1));
  82. }
  83. # 点赞
  84. public function addUp_api()
  85. {
  86. $id = Dever::input('id');
  87. Dever::db('content/video')->addUp(array('where_id' => $id, 'set_num_up' => 1));
  88. }
  89. # 获取精彩推荐
  90. public function getTop($cate_id = false)
  91. {
  92. $where = array();
  93. if ($cate_id) {
  94. $where['cate_id'] = $cate_id;
  95. }
  96. $data = Dever::db('content/video')->getTop($where);
  97. if ($data) {
  98. foreach ($data as $k => $v) {
  99. $cate = Dever::db('content/cate')->one($v['cate_id']);
  100. $data[$k]['cate_name'] = $cate['name'];
  101. $data[$k]['link'] = Dever::load('content/lib/common')->getInfoLink(3, $v['id']);
  102. $data[$k]['cdate'] = date('Y-m-d', $v['pdate']);
  103. }
  104. }
  105. return $data;
  106. }
  107. }