Пример #1
0
 /**
  * 添加一个访问计数器
  * 返回当前访问次数或者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;
 }
Пример #2
0
 /**
  * 添加一个系统提示信息给用户
  * @param string $title
  * @param string $content
  * @param string $uid
  */
 public function addNoticeMsg($title, $content, $uid)
 {
     $title = trim($title);
     $content = htmlspecialchars(trim($content), ENT_NOQUOTES);
     $uid = intval($uid);
     if (empty($title) || empty($content) || $uid < 1) {
         $this->throwMsg(-17);
     }
     $data = ['msg_title' => $title, 'msg_content' => $content, 'msg_datetime' => date("Y-m-d H:i:s"), 'from_users_id' => NULL, 'to_users_id' => $uid];
     if ($this->db->insert("message", $data) < 0) {
         Log::write(_("Add message notice error."), Log::SQL);
         $this->throwMsg(-18);
     }
 }
Пример #3
0
 /**
  * 取消或者喜欢某一评论
  * @param int $c_id
  * @param int $u_id
  */
 public function like($c_id, $u_id)
 {
     $c_id = intval($c_id);
     $u_id = intval($u_id);
     if ($this->db->has("users_like_comments", ['AND' => ['users_id' => $u_id, 'comments_id' => $c_id]])) {
         if ($this->db->delete("users_like_comments", ['AND' => ['users_id' => $u_id, 'comments_id' => $c_id]]) === false) {
             $this->throwMsg(-6);
         }
         hook()->apply('CommentManagement_unlike', NULL, $c_id, $u_id);
     } else {
         if ($this->db->insert("users_like_comments", ['users_id' => $u_id, 'comments_id' => $c_id, 'like_time' => date("Y-m-d H:i:s")]) < 0) {
             $this->throwMsg(-7);
         }
         hook()->apply('CommentManagement_like', NULL, $c_id, $u_id);
     }
 }
Пример #4
0
 /**
  * 插入标题创建新的画集
  * @param string $title
  * @param int    $user_id
  * @return int
  */
 public function add($title, $user_id)
 {
     $user_id = intval($user_id);
     $title = trim($title);
     if (empty($title)) {
         $this->throwMsg(-3);
     }
     $rt = $this->db->insert("gallery", ['users_id' => $user_id, 'gallery_title' => $title, 'gallery_create_time' => date("Y-m-d H:i:s"), 'gallery_update_time' => date("Y-m-d H:i:s")]);
     if ($rt === -1) {
         $this->throwMsg(-1);
     } else {
         if ($rt == 0) {
             $this->throwMsg(-2);
         }
     }
     return $rt;
 }
Пример #5
0
 /**
  * @param $title
  * @param $name
  * @param $users_id
  * @return array
  */
 public function create($title, $name, $users_id)
 {
     $title = trim($title);
     $name = trim($name);
     $this->checkTitle($title);
     $this->checkName($name);
     if ($this->existsName($name)) {
         $this->throwMsg(-7);
     }
     User::getUser($users_id);
     $data = ['post_title' => $title, 'post_name' => $name, 'post_time' => date("Y-m-d H:i:s"), 'post_category' => $this->getCategory(0), 'post_status' => 0, 'post_update_time' => date("Y-m-d H:i:s"), 'post_content' => '', 'users_id' => $users_id];
     $insert = $this->db->insert("posts", $data);
     if ($insert < 1) {
         Log::write(_("Insert post content error."), Log::SQL);
         $this->throwMsg(-3);
     }
     $data['id'] = $insert;
     return $data;
 }
Пример #6
0
 public function role_add($info)
 {
     return $this->driver->insert("role", $info);
 }