Пример #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
 /**
  * 检测名称是否存储,当$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]);
 }
Пример #3
0
 /**
  * 将图集设置为公共的
  */
 public function set_public()
 {
     $this->galleryOwnerCheck($this->gallery_id, $this->user_id);
     $si = $this->getSimpleInfo($this->gallery_id);
     if (empty($si['gallery_title'])) {
         $this->throwMsg(-18);
     }
     if (empty($si['gallery_description'])) {
         $this->throwMsg(-19);
     }
     if ($si['gallery_front_cover'] < 1) {
         $this->throwMsg(-20);
     }
     if (!$this->db->has("gallery_has_tags", ['gallery_id' => $this->gallery_id])) {
         $this->throwMsg(-21);
     }
     if (!$this->db->has("gallery_has_pictures", ['gallery_id' => $this->gallery_id])) {
         $this->throwMsg(-22);
     }
     $u = ['gallery_status' => 1, 'gallery_update_time' => date("Y-m-d H:i:s")];
     $si = array_merge($si, $u);
     $d = $this->db->update("gallery", $u, ['AND' => ['id' => $this->gallery_id, 'users_id' => $this->user_id]]);
     if ($d === false) {
         Log::write(_("Gallery set public error."), Log::SQL);
         $this->throwMsg(-16);
     }
     //对于更新成功后的信息钩子
     hook()->apply('Gallery_set_public', NULL, $si);
 }
Пример #4
0
 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);
     }
 }
Пример #5
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);
     }
 }
Пример #6
0
 public function rely_role($id)
 {
     return $this->driver->has("access", ['r_id' => $id]) || $this->driver->has("admin", ['r_id' => $id]);
 }