/** * 添加一个访问计数器 * 返回当前访问次数或者FALSE * @param string $type * @param int $id * @return int|false */ public function addCount($type, $id) { if (!in_array($type, $this->type_list)) { return false; } if (!$this->db->has($type, ['id' => $id])) { return false; } $count = $this->db->select($type . "_views", ['views_count'], ['AND' => [$type . "_id" => $id, 'views_date' => date("Y-m-d")], 'LIMIT' => 1]); if ($count === false) { Log::write(_("Count info get error."), Log::SQL); return false; } if (isset($count[0]['views_count'])) { $status = $this->db->update($type . "_views", ['views_count[+]' => 1], ['AND' => [$type . "_id" => $id, 'views_date' => date("Y-m-d")]]); if ($status === false) { Log::write(_("Count info update error."), Log::SQL); return false; } if ($status > 0) { return $count[0]['views_count'] + 1; } } else { $status = $this->db->insert($type . "_views", [$type . "_id" => $id, 'views_date' => date("Y-m-d"), 'views_count' => 1]); if ($status !== -1) { return 1; } else { Log::write(_("Count info insert error."), Log::SQL); } } return false; }
/** * 获取全部列表 * @param int $uid * @return FeedInterface[] */ public function getList($uid) { $uid = (int) $uid; if (!$this->getCountInfo($uid)) { return []; } $data = $this->db->select("feed", ['id', 'time', 'action', 'content'], ['users_id' => $uid, 'LIMIT' => [$this->count['number'] * ($this->count['page'] - 1), $this->count['number']], 'ORDER' => 'id DESC']); if ($data === false) { Log::write(_("Get feed list error."), Log::SQL); return []; } return Feed::getInstance()->parseList($data); }
/** * 删除一条评论, * @param int $id * @param string $type * @param int $user_id */ public function delete($id, $type, $user_id) { $id = intval($id); $type = trim($type); if (!isset($this->type_list[$type])) { $this->throwMsg(-4); } $user_id = intval($user_id); $comment = $this->db->get("comments", ['comment_parent', 'comment_parent_top'], ['AND' => ['id' => $id, 'users_id' => $user_id]]); if (empty($comment)) { $this->throwMsg(-3); } $writer = $this->db->getWriter(); $writer->pdo->beginTransaction(); $parent = intval($comment['comment_parent']); $parent_top = intval($comment['comment_parent_top']); if ($parent !== 0) { //存在上级回复,即非顶级评论,将所有指向它的评论指向它的上级 if ($writer->update("comments", ['comment_parent' => $parent], ['comment_parent' => $id]) === false) { $writer->pdo->rollBack(); $this->throwMsg(-1); } } elseif ($parent_top === 0) { //不存在上级回复,且自身为顶级回复 //取第一条回复 $top = $this->db->select('comments', ['id'], ['comment_parent_top' => $id, 'LIMIT' => 1]); if (isset($top[0])) { $top = $top[0]; if ($writer->update('comments', ['comment_parent_top' => NULL, 'comment_parent' => NULL], ['id' => $top['id']]) === false) { $writer->pdo->rollBack(); $this->throwMsg(-1); } if ($writer->update('comments', ['comment_parent' => $top['id']], ['comment_parent' => $id]) === false) { $writer->pdo->rollBack(); $this->throwMsg(-1); } if ($writer->update('comments', ['comment_parent_top' => $top['id']], ['comment_parent_top' => $id]) === false) { $writer->pdo->rollBack(); $this->throwMsg(-1); } } elseif ($top === false) { $writer->pdo->rollBack(); $this->throwMsg(-1); } } //针对无法触发DELETE触发器的计数器添加和删除操作 $this->deleteRelationTable($id, $this->type_list[$type], $writer); $rt = $this->db->delete("comments", ['AND' => ['id' => $id, 'users_id' => $user_id]]); if ($rt === false) { $writer->pdo->rollBack(); $this->throwMsg(-1); } else { if ($rt < 1) { $writer->pdo->rollBack(); $this->throwMsg(-2); } } $writer->pdo->commit(); }
/** * 获取用户的评论列表 * @param int $uid * @return array */ public function getListOfUser($uid) { //仅仅查询评论内容,评论时间,对象名称,对象地址 if (!$this->setCount(self::TYPE_Comment_user, $uid)) { return []; } $list = $this->db->select($this->table, ['[><]comments' => ['comments_id' => 'id']], [$this->table . "." . $this->type . "_id" => $this->type . "_id", $this->table . ".comments_id" => "comments_id", $this->table . ".object_users_id" => "object_users_id", $this->table . '.users_id' => 'users_id', 'comments.comment_content' => 'comment_content', 'comments.comment_time' => 'comment_time'], [$this->table . '.users_id' => $uid, 'LIMIT' => [($this->count['page'] - 1) * $this->count['number'], $this->count['number']]]); $this->getListDataParse($list); return $list; }
public function getPublicList() { if (!$this->getCountInfo(-1)) { return []; } $rt = $this->db->select("posts", ['id', 'post_title', 'post_name', 'post_time', 'post_update_time', 'post_category', 'post_status', 'post_content', 'post_comment_count'], ['post_status' => 1, 'ORDER' => 'id DESC', 'LIMIT' => [($this->count['page'] - 1) * $this->count['number'], $this->count['number']]]); if ($rt === false) { Log::write(_("Select public post list error."), Log::SQL); return []; } return $rt; }
public function getListOfUser($user_name) { $user = User::getUser($user_name); if (!is_object($user)) { return []; } if (!$this->getCountInfo($user->getId(), 'user')) { return []; } $list = $this->db->select("pictures", ['[<]gallery' => ['id' => 'gallery_front_cover'], '[>]server' => ['server_name' => 'name']], ['gallery.id' => 'gallery_id', 'gallery.users_id' => 'users_id', 'gallery.gallery_title' => 'gallery_title', 'gallery.gallery_description' => 'gallery_description', 'gallery.gallery_create_time' => 'gallery_create_time', 'gallery.gallery_update_time' => 'gallery_update_time', 'gallery.gallery_like_count' => 'gallery_like_count', 'gallery.gallery_comment_count' => 'gallery_comment_count', 'gallery.gallery_comment_status' => 'gallery_comment_status', 'gallery.gallery_front_cover' => 'gallery_front_cover', 'pictures.id' => 'pic_id', 'pictures.server_name' => 'server_name', 'server.url' => 'server_url', 'pictures.pic_name' => 'pic_name', 'pictures.pic_path' => 'pic_path', 'pictures.pic_create_time' => 'pic_create_time', 'pictures.pic_width' => 'pic_width', 'pictures.pic_height' => 'pic_height', 'pictures.pic_description' => 'pic_description', 'pictures.pic_thumbnails_path' => 'pic_thumbnails_path', 'pictures.pic_thumbnails_width' => 'pic_thumbnails_width', 'pictures.pic_thumbnails_height' => 'pic_thumbnails_height', 'pictures.pic_hd_path' => 'pic_hd_path', 'pictures.pic_hd_width' => 'pic_hd_width', 'pictures.pic_hd_height' => 'pic_hd_height', 'pictures.pic_status' => 'pic_status', 'pictures.pic_comment_count' => 'pic_comment_count', 'pictures.pic_display_path' => 'pic_display_path', 'pictures.pic_display_width' => 'pic_display_width', 'pictures.pic_display_height' => 'pic_display_height'], ['AND' => ['gallery.gallery_status' => 1, 'gallery.users_id' => $user->getId()], 'ORDER' => 'gallery.id DESC', 'LIMIT' => [$this->count['number'] * ($this->count['page'] - 1), $this->count['number']]]); $this->parseList($list); return $list; }
/** * 获取全部BUG信息 * @return array */ public function get_all_bugs() { $name = $this->top_info['name']; $now_code = isset($this->now_version['version_code']) ? $this->now_version['version_code'] : 0; $info = $this->db->select("version_control", ['version', 'version_code', 'build_version', 'bugs'], ['AND' => ['name' => $name, 'version_code[>=]' => $now_code]]); $rt = []; foreach ($info as $v) { $v['bugs'] = self::parse_info($v['bugs']); $rt[$v['version']] = $v; } ksort($rt); return $rt; }
/** * 获取图集的图片 * @param $gallery_id * @return array|bool */ public function getPictures($gallery_id) { $rt = $this->db->select("pictures", ['[><]gallery_has_pictures' => ['id' => 'pictures_id'], '[><]server' => ['server_name' => 'name']], ['gallery_has_pictures.gallery_id' => 'gallery_id', 'pictures.id' => 'pic_id', 'server.url' => 'server_url', 'pictures.pic_path' => 'pic_path', 'pictures.pic_name' => 'pic_name', 'pictures.pic_create_time' => 'pic_create_time', 'pictures.pic_width' => 'pic_width', 'pictures.pic_height' => 'pic_height', 'pictures.pic_description' => 'pic_description', 'pictures.pic_thumbnails_path' => 'pic_thumbnails_path', 'pictures.pic_thumbnails_width' => 'pic_thumbnails_width', 'pictures.pic_thumbnails_height' => 'pic_thumbnails_height', 'pictures.pic_hd_path' => 'pic_hd_path', 'pictures.pic_hd_width' => 'pic_hd_width', 'pictures.pic_hd_height' => 'pic_hd_height', 'pictures.pic_status' => 'pic_status', 'pictures.pic_comment_count' => 'pic_comment_count', 'pictures.pic_display_path' => 'pic_display_path', 'pictures.pic_display_width' => 'pic_display_width', 'pictures.pic_display_height' => 'pic_display_height'], ['AND' => ['gallery_has_pictures.gallery_id' => $gallery_id]]); // for($i = 0, $l = count($rt); $i < $l; $i++){ // if($rt[$i]['pic_thumbnails_path'] === 'thumbnail'){ // $rt[$i]['url'] = $rt[$i]['server_url'] . $rt[$i]['pic_path'] . "/thumbnail"; // } else{ // $rt[$i]['url'] = $rt[$i]['server_url'] . $rt[$i]['pic_thumbnails_path']; // } // } lib()->load('Picture'); $pic = new Picture(); $pic->parsePic($rt, false); $pic->list_add_tags($rt); return $rt; }
/** * 检测用户,根据字符串数组 * @param string[] $list * @param int $u_id * @return int[] */ private function checkUser($list, $u_id) { $list = array_flip(array_flip($list)); if (count($list) > 10) { $this->throwMsg(-5); } $ss = $this->db->select("users", ['id'], ['user_name' => $list]); $list = []; foreach ($ss as $v) { $list[] = intval($v['id']); } if (count($list) < 1) { return []; } if ($u_id !== 0) { $ss = implode(",", $list); $sql = <<<EOM SELECT `users_id`, `follow_users_id` FROM `users_follow_users` WHERE (`users_id` = {$u_id} AND `follow_users_id` in ({$ss})) OR (`users_id` in ({$ss}) AND `follow_users_id` = {$u_id}); EOM; $stmt = $this->db->getReader()->query($sql); if ($stmt === false) { Log::write(_("Get sql message users error."), Log::SQL); $this->throwMsg(-8); } $ss = $stmt->fetchAll(\PDO::FETCH_ASSOC); unset($stmt); $list = []; foreach ($ss as $v) { if (!isset($list[$v['users_id']])) { $list[$v['users_id']] = intval($v['users_id']); } if (!isset($list[$v['follow_users_id']])) { $list[$v['follow_users_id']] = intval($v['follow_users_id']); } } if (isset($list[$u_id])) { unset($list[$u_id]); } } return $list; }
public function get_curriculum_names($ids) { return $this->driver->select("info_curriculum", ['cu_id', 'cu_name'], ['cu_id' => $ids]); }