Album.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <?php
  2. namespace Content\Lib;
  3. use Dever;
  4. class Album
  5. {
  6. # 获取文章信息
  7. public function getInfo()
  8. {
  9. $id = Dever::input('id');
  10. $data = Dever::db('content/album')->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. $data['pic'] = explode(',', $data['pic']);
  30. $data['pic_html'] = '';
  31. if ($data['pic']) {
  32. foreach ($data['pic'] as $k => $v) {
  33. $data['pic_html'] .= '<li><a href="'.$v.'" data-fancybox="group" data-caption=""><i><img src="'.$v.'" alt=""></i></a></li>';
  34. }
  35. }
  36. $data['pic_num'] = count($data['pic']);
  37. # 获取上一篇和下一篇
  38. $where['id'] = $id;
  39. $where['cate_id'] = $data['cate_id'];
  40. $data['prev'] = Dever::db('content/album')->findPrev($where);
  41. if ($data['prev']) {
  42. $data['prev']['link'] = Dever::load('content/lib/common')->getInfoLink(2, $data['prev']['id']);
  43. $data['prev']['cdate'] = date('Y年m月d日创建', $data['prev']['pdate']);
  44. }
  45. $data['next'] = Dever::db('content/album')->findNext($where);
  46. if ($data['next']) {
  47. $data['next']['link'] = Dever::load('content/lib/common')->getInfoLink(2, $data['next']['id']);
  48. $data['next']['cdate'] = date('Y年m月d日创建', $data['next']['pdate']);
  49. }
  50. //print_r($data);die;
  51. $data['up_url'] = Dever::url('content/lib/album.addUp?id=' . $data['id']);
  52. $this->addView($id);
  53. return $data;
  54. }
  55. # 获取最新列表
  56. public function getList()
  57. {
  58. $data = Dever::db('content/album')->getList();
  59. if ($data) {
  60. foreach ($data as $k => $v) {
  61. $data[$k]['link'] = Dever::load('content/lib/common')->getInfoLink(2, $v['id']);
  62. $data[$k]['pic_num'] = count(explode(',', $v['pic']));
  63. }
  64. }
  65. return $data;
  66. }
  67. # 获取最新列表
  68. public function getAll()
  69. {
  70. $where = array();
  71. $cate_id = Dever::input('cid');
  72. if ($cate_id > 0) {
  73. $where['cate_id'] = $cate_id;
  74. }
  75. $data = Dever::db('content/album')->getAll($where);
  76. if ($data) {
  77. foreach ($data as $k => $v) {
  78. $data[$k]['link'] = Dever::load('content/lib/common')->getInfoLink(2, $v['id']);
  79. $data[$k]['cdate'] = date('Y-m-d', $v['pdate']);
  80. $data[$k]['pic_num'] = count(explode(',', $v['pic']));
  81. }
  82. }
  83. return $data;
  84. }
  85. # 获取相关推荐
  86. public function getRelation($info)
  87. {
  88. $where['noid'] = $info['id'];
  89. $where['cate_id'] = $info['cate_id'];
  90. return Dever::db('content/album')->getRelation($where);
  91. }
  92. # 增加浏览量
  93. public function addView($id)
  94. {
  95. Dever::db('content/album')->addView(array('where_id' => $id, 'set_num_view' => 1));
  96. }
  97. # 点赞
  98. public function addUp_api()
  99. {
  100. $id = Dever::input('id');
  101. Dever::db('content/album')->addUp(array('where_id' => $id, 'set_num_up' => 1));
  102. }
  103. # 获取精彩推荐
  104. public function getTop($cate_id = false)
  105. {
  106. $where = array();
  107. if ($cate_id) {
  108. $where['cate_id'] = $cate_id;
  109. }
  110. $data = Dever::db('content/album')->getTop($where);
  111. if ($data) {
  112. foreach ($data as $k => $v) {
  113. $cate = Dever::db('content/cate')->one($v['cate_id']);
  114. $data[$k]['cate_name'] = $cate['name'];
  115. $data[$k]['link'] = Dever::load('content/lib/common')->getInfoLink(2, $v['id']);
  116. $data[$k]['cdate'] = date('Y-m-d', $v['pdate']);
  117. }
  118. }
  119. return $data;
  120. }
  121. }