|
@@ -0,0 +1,109 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace Community\Lib;
|
|
|
+
|
|
|
+use Dever;
|
|
|
+
|
|
|
+class Info
|
|
|
+{
|
|
|
+ private function table($type)
|
|
|
+ {
|
|
|
+ $table = Dever::db('community/info')->config['type_name'][$type];
|
|
|
+ return $table;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public function get($id, $type, $uid = false)
|
|
|
+ {
|
|
|
+ $where['type'] = $type;
|
|
|
+ $where['type_id'] = $id;
|
|
|
+ $table = $this->table($type);
|
|
|
+ $data = Dever::db($table)->getAll($where);
|
|
|
+
|
|
|
+ if ($data) {
|
|
|
+ foreach ($data as $k => $v) {
|
|
|
+ $user = Dever::load('passport/api')->info($v['uid']);
|
|
|
+ $data[$k]['time'] = Dever::mdate($v['cdate'], 2);
|
|
|
+ $data[$k]['username'] = $user['username'];
|
|
|
+ $data[$k]['avatar'] = $user['avatar'];
|
|
|
+ $data[$k]['cdate_time'] = date('Y-m-d H:i:s', $v['cdate']);
|
|
|
+
|
|
|
+
|
|
|
+ if ($uid > 0) {
|
|
|
+ $data[$k]['up'] = Dever::load('act/lib/like')->get($uid, $v['id'], 11);
|
|
|
+ } else {
|
|
|
+ $data[$k]['up'] = 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ $data[$k]['content'] = $this->getContent($v['content']);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return $data;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public function getList($uid)
|
|
|
+ {
|
|
|
+ $where['uid'] = $uid;
|
|
|
+ $where['type'] = '1,2,3';
|
|
|
+ $info = Dever::db('community/comment')->getAll($where);
|
|
|
+
|
|
|
+ if ($info) {
|
|
|
+ foreach ($info as $k => $v) {
|
|
|
+ $info[$k]['content'] = $this->getContent($v['content']);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return $info;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function content($content, $id)
|
|
|
+ {
|
|
|
+ $content = $this->getContent($content);
|
|
|
+
|
|
|
+ return '<span class=dever-emoji>'.$content.'</span>';
|
|
|
+ }
|
|
|
+
|
|
|
+ public function getContent($content)
|
|
|
+ {
|
|
|
+ if (strstr($content, '_b64')) {
|
|
|
+ $content = str_replace('_b64', '', $content);
|
|
|
+ $content = base64_decode($content);
|
|
|
+ }
|
|
|
+
|
|
|
+ return $content;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public function submit($uid, $id, $type, $content)
|
|
|
+ {
|
|
|
+ $where['uid'] = $uid;
|
|
|
+ $where['type_id'] = $id;
|
|
|
+ $where['type'] = $type;
|
|
|
+ $where['content'] = base64_encode($content) . '_b64';
|
|
|
+ $table = $this->table($type);
|
|
|
+ $info = Dever::db($table)->one($where);
|
|
|
+ $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);
|
|
|
+ }
|
|
|
+ Dever::score($uid, 'submit_commit', '发表评论');
|
|
|
+
|
|
|
+
|
|
|
+ $where = array();
|
|
|
+ $where['data_id'] = $id;
|
|
|
+ $where['type'] = $type;
|
|
|
+ $where['state'] = 1;
|
|
|
+ $total = Dever::db($table)->total($where);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+}
|