Info.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <?php
  2. namespace Community\Lib;
  3. use Dever;
  4. class Info
  5. {
  6. private function table($type)
  7. {
  8. $table = Dever::db('community/info')->config['set']['table_name'][$type];
  9. return $table;
  10. }
  11. public function getData($method = 'getAll', $uid, $cate_id = false, $type = false, $type_id = false, $total = false, $id = false)
  12. {
  13. # 获取分类下的帖子
  14. $where['cate_id'] = $cate_id;
  15. $where['type'] = $type;
  16. $where['type_id'] = $type_id;
  17. if ($id > 0) {
  18. $where['noid'] = $id;
  19. }
  20. $data['info'] = Dever::db('community/info')->$method($where);
  21. if ($total) {
  22. if ($method == 'getAll') {
  23. $data['total'] = Dever::total();
  24. } else {
  25. $data['total'] = Dever::db('community/info')->getTotal($where);
  26. }
  27. }
  28. if ($data['info']) {
  29. foreach ($data['info'] as $k => $v) {
  30. $data['info'][$k] = $this->one($uid, $v);
  31. }
  32. }
  33. return $data;
  34. }
  35. public function content($content, $id)
  36. {
  37. $content = $this->getContent($content);
  38. return '<span class=dever-emoji>'.$content.'</span>';
  39. }
  40. public function getContent($content)
  41. {
  42. if (strstr($content, '_b64')) {
  43. $content = str_replace('_b64', '', $content);
  44. $content = base64_decode($content);
  45. }
  46. return $content;
  47. }
  48. # 发表信息
  49. public function submit($uid, $cate_id, $id, $type, $pic, $content, $to_id, $to_uid)
  50. {
  51. $where['uid'] = $uid;
  52. $where['cate_id'] = $cate_id;
  53. $where['type_id'] = $id;
  54. $where['type'] = $type;
  55. $where['content'] = $content;
  56. $table = 'community/info';
  57. //$info = Dever::db($table)->one($where);
  58. $info = false;
  59. if ($pic) {
  60. $where['pic'] = $pic;
  61. }
  62. if ($to_id) {
  63. $where['to_id'] = $to_id;
  64. }
  65. if ($to_uid) {
  66. $where['to_uid'] = $to_uid;
  67. }
  68. $data_table = $this->table($type);
  69. if (!$info) {
  70. $data = Dever::db($data_table)->one($id);
  71. if (isset($data['name']) && $data['name']) {
  72. $where['type_name'] = $data['name'];
  73. }
  74. Dever::db($table)->insert($where);
  75. Dever::score($uid, 'submit_community', '发表帖子');
  76. # 更新评论数
  77. $where = array();
  78. $where['type_id'] = $id;
  79. $where['type'] = $type;
  80. $where['state'] = 1;
  81. $total = Dever::db($table)->total($where);
  82. Dever::db($data_table)->update(array('where_id' => $id, 'num_comment' => $total));
  83. }
  84. return true;
  85. }
  86. private function one($uid, $info)
  87. {
  88. $info['pic'] = explode(',', $info['pic']);
  89. $info['user'] = Dever::load('passport/api')->info($info['uid']);
  90. $info['cdate_string'] = Dever::mdate($info['cdate'], 2);
  91. # 点赞数
  92. $info['num_up'] = $info['num_up'] + 0;
  93. # 反对数
  94. $info['num_oppose'] = $info['num_oppose'] + 0;
  95. $info['is_up'] = $info['is_oppose'] = false;
  96. if ($uid) {
  97. # 是否点赞
  98. $info['is_up'] = Dever::load('community/lib/up')->get($uid, $info['id'], 20);
  99. # 是否反对
  100. $info['is_oppose'] = Dever::load('community/lib/oppose')->get($uid, $info['id'], 20);
  101. }
  102. # 评论数
  103. $info['num_comment'] = $info['num_comment'] + 0;
  104. # 获取引用的数据
  105. $info['to_user'] = array();
  106. if ($info['to_uid']) {
  107. $info['to_user'] = Dever::load('passport/api')->info($info['to_uid']);
  108. }
  109. # 获取热门的子信息
  110. $info['child'] = array();
  111. if ($info['type'] < 20) {
  112. $child = $this->getData('getHot', $uid, $info['cate_id'], 20, $info['id'], true, 1);
  113. if ($child && $child['info']) {
  114. $info['child'] = $child['info'];
  115. $info['child_total'] = $child['total'];
  116. }
  117. }
  118. # 获取最新的服务器时间
  119. $info['server_time'] = time();
  120. return $info;
  121. }
  122. }