123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193 |
- <?php
- namespace Community\Lib;
- use Dever;
- class Info
- {
- private function table($type)
- {
- $table = Dever::db('community/info')->config['set']['table_name'][$type];
- return $table;
- }
- public function getData($method = 'getAll', $uid, $cate_id = false, $type = false, $type_id = false, $total = false, $id = false, $times = false, $day = false, $collection_id = false)
- {
- # 获取分类下的帖子
- $where['cate_id'] = $cate_id;
- $where['type'] = $type;
- $where['type_id'] = $type_id;
- if ($id > 0) {
- $where['noid'] = $id;
- }
- if ($day && $day > 0) {
- $where['day'] = $day;
- } else {
- $where['day'] = -1;
- }
- $data['info'] = Dever::db('community/info')->$method($where);
- if ($total) {
- if ($method == 'getAll') {
- $data['total'] = Dever::total();
- } else {
- $data['total'] = Dever::db('community/info')->getTotal($where);
- }
- }
- if ($data['info']) {
- foreach ($data['info'] as $k => $v) {
- $data['info'][$k] = $this->one($uid, $v, $times, $collection_id);
- }
- }
- return $data;
- }
- public function content($id)
- {
- $info = Dever::db('community/info')->one($id);
- $table = array();
- $pic = '';
- if ($info['pic']) {
- $temp = explode(',', $info['pic']);
- foreach ($temp as $k => $v) {
- $pic .= '<img src="'.$v.'" width="150" />';
- }
- }
-
- $table['内容'] = $info['content'];
- $table['图片'] = $pic;
- return Dever::table($table);
- }
- # 发表信息
- public function submit($uid, $cate_id, $id, $type, $pic, $content, $to_id, $to_uid, $day = false, $score_type = false, $score_type_id = false)
- {
- $where['uid'] = $uid;
- $where['cate_id'] = $cate_id;
- $where['type_id'] = $id;
- $where['type'] = $type;
- $where['content'] = $content;
- $table = 'community/info';
- //$info = Dever::db($table)->one($where);
- $info = false;
- if ($pic) {
- $where['pic'] = $pic;
- }
- if ($to_id) {
- $where['to_id'] = $to_id;
- }
- if ($to_uid) {
- $where['to_uid'] = $to_uid;
- }
- if ($day) {
- $where['day'] = $day;
- }
- $data_table = $this->table($type);
- if (!$info) {
- $data = Dever::db($data_table)->one($id);
- if (isset($data['name']) && $data['name']) {
- $where['type_name'] = $data['name'];
- }
-
- Dever::db($table)->insert($where);
- if ($to_uid && $to_uid != $uid) {
- Dever::score($uid, 'reply_community', '回复帖子', false, false, false, $score_type, $score_type_id);
- Dever::score($to_uid, 'reply_me_community', '被回复帖子', false, false, false, $score_type, $score_type_id);
- # 建立聊天相关信息
- Dever::load('community/lib/chat')->add($uid, $to_uid, $score_type_id, $content, $pic, $day);
- } else {
- Dever::score($uid, 'submit_community', '发表帖子', false, false, false, $score_type, $score_type_id);
- }
- # 更新评论数
- /*
- $where = array();
- $where['type_id'] = $id;
- $where['type'] = $type;
- $where['state'] = 1;
- $total = Dever::db($table)->total($where);
- echo $data_table;die;
- Dever::db($data_table)->update(array('where_id' => $id, 'num_comment' => $total));
- */
- }
- return true;
- }
- private function one($uid, $info, $times = false, $collection_id = false)
- {
- $info['pic'] = explode(',', $info['pic']);
- $info['user'] = Dever::load('user/lib/info')->get($info['uid'], $collection_id, true);
-
- $info['cdate_string'] = Dever::load('collection/lib/times')->getDate($info['day'], $info['cdate'], $times);
- # 点赞数
- $info['num_up'] = $info['num_up'] + 0;
- # 反对数
- $info['num_oppose'] = $info['num_oppose'] + 0;
- $info['is_up'] = $info['is_oppose'] = false;
- if ($uid) {
- # 是否点赞
- $info['is_up'] = Dever::load('community/lib/up')->get($uid, $info['id'], 20);
- # 是否反对
- $info['is_oppose'] = Dever::load('community/lib/oppose')->get($uid, $info['id'], 20);
- }
- # 评论数
- $info['num_comment'] = $info['num_comment'] + 0;
- # 获取引用的数据
- $info['to_user'] = array();
- if ($info['to_uid']) {
- $info['to_user'] = Dever::load('user/lib/info')->get($info['to_uid'], $collection_id, true);
- }
- # 获取热门的子信息
- $info['child'] = array();
- if ($info['type'] < 20) {
- $child = $this->getData('getHot', $uid, $info['cate_id'], 20, $info['id'], true, false, $times, $info['day'], $collection_id);
- if ($child && $child['info']) {
- $info['child'] = $child['info'];
- $info['child_total'] = $child['total'];
- }
- }
- # 获取最新的服务器时间
- $info['server_time'] = time();
- return $info;
- }
- public function getCdate(&$info, $times = false)
- {
- if ($info['day'] > 0) {
- if ($times && $times['year']) {
- $year = $times['year'];
- } else {
- $year = substr($info['day'],0,4);
- }
-
- $month = substr($info['day'],4,2);
- $day = substr($info['day'],6,2);
- $string = $year . '-' . $month . '-' . $day;
- } elseif ($times && $times['year']) {
- $string = $times['year'] . '-m-d';
- } else {
- $string = 'Y-m-d';
- }
- $info['cdate_string'] = date($string . ' H:i', $info['cdate']);
- }
- }
|