/** * 添加一个访问计数器 * 返回当前访问次数或者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; }
/** * 检测名称是否存储,当$pid不为空时,排除$pid的那一栏 * @param string $name * @param int $pid * @return bool */ private function existsName($name, $pid = NULL) { if ($pid > 0) { return $this->db->has("posts", ['AND' => ['post_name' => $name, 'id[!]' => $pid]]); } return $this->db->has("posts", ['post_name' => $name]); }
/** * 获取用户的评论列表 * @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; }
/** * 检查上次发送时间间隔,过短则返回异常 * @param $uid */ private function checkLastSend($uid) { $get = $this->db->get("message", ['msg_datetime'], ['from_users_id' => $uid, 'ORDER' => 'id DESC']); if (isset($get['msg_datetime'])) { $t = strtotime($get['msg_datetime']); if (time() - $t < hook()->apply("Message_checkLastSend", 30)) { $this->throwMsg(-9); } } }
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 $code * @return string */ public function getMsg($code) { switch ($code) { case -1: return _("Insert gallery error sql.") . debug(implode(", ", $this->db->error()['write'])); case -2: return _("Insert failed."); case -3: return _("title not be empty"); case -4: return _("delete create a error.") . debug(implode(", ", $this->db->error()['write'])); case -5: return _("No delete any gallery"); case -6: return _("No permission on this gallery"); case -7: return _("comment status error."); case -8: return _("Gallery info update error.") . debug(implode(", ", $this->db->error()['write'])); case -9: return _("Pic list is empty"); case -10: return _("User own pic list is empty"); case -11: return _("No new pictures add"); case -12: return _("Delete gallery pictures make a sql error.") . debug(implode(", ", $this->db->error()['write'])); case -13: return _("Cancel like gallery error."); case -14: return _("Like gallery error."); case -15: return _("Gallery get previous and next page id error."); case -16: return _("Gallery set public error."); case -17: return _("Gallery set draft error."); case -18: return _("Gallery must be have a title."); case -19: return _("Gallery must be have a description"); case -20: return _("Gallery must be have a front cover."); case -21: return _("Gallery must be have a tag."); case -22: return _("Gallery must be have a picture."); } return _("Unknown error."); }
public function delete($id, $uid) { $id = +$id; $uid = +$uid; if (!$this->db->has("feed", ['AND' => ['id' => $id, 'users_id' => $uid]])) { $this->throwMsg(-1); } $status = $this->db->delete("feed", ['AND' => ['id' => $id, 'users_id' => $uid]]); if ($status === false) { Log::write(_("Delete feed error."), Log::SQL); $this->throwMsg(-2); } if ($status != 1) { $this->throwMsg(-3); } }
/** * 获取异常 * @param int $code * @return string */ public function getMsg($code) { switch (intval($code)) { case -1: Log::write(_("Delete comment error.") . implode(",", $this->db->error()['write']), Log::SQL); return _("Delete comment error."); case -2: return _("No comment had delete."); case -3: return _("Comment is not exists."); case -4: return _("Comment type id not defined."); case -5: return _("Comment top add error."); case -6: Log::write(_("Cancel comment like error.") . implode(",", $this->db->error()['write']), Log::SQL); return _("Cancel comment like error."); case -7: Log::write(_("Like comment error.") . implode(",", $this->db->error()['write']), Log::SQL); return _("Like comment error."); default: return _("Unknown error."); } }
public function rely_role($id) { return $this->driver->has("access", ['r_id' => $id]) || $this->driver->has("admin", ['r_id' => $id]); }