Пример #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
 public function update($title, $name, $content, $category, $keyword, $description, $status, $allow_comment, $user_id)
 {
     if (!$this->existsCheck($this->post_id, $user_id)) {
         $this->throwMsg(-5);
     }
     $title = trim($title);
     $name = trim($name);
     $content = trim($content);
     $this->checkTitle($title);
     $this->checkName($name);
     if ($this->existsName($name, $this->post_id)) {
         $this->throwMsg(-9);
     }
     if (empty($content)) {
         $this->throwMsg(-8);
     }
     if (!in_array($category, $this->getCategory())) {
         $this->throwMsg(-10);
     }
     if ($status < 0 || $status > 1) {
         $this->throwMsg(-11);
     }
     $data = ['post_name' => $name, 'post_title' => $title, 'post_content' => $content, 'post_category' => $category, 'post_keyword' => $keyword, 'post_description' => $description, 'post_status' => $status, 'post_update_time' => date("Y-m-d H:i:s"), 'post_allow_comment' => $allow_comment > 0 ? 1 : 0];
     if ($this->db->update('posts', $data, ['id' => $this->post_id]) < 0) {
         Log::write(_("Update post error.") . Log::SQL);
         $this->throwMsg(-12);
     }
 }
Пример #3
0
 public function set_read($id, $uid)
 {
     $data = ['is_read' => 1, 'read_time' => date("Y-m-d H:i:s")];
     $rt = $this->db->update("message", $data, ['AND' => ['id' => $id, 'to_users_id' => $uid, 'is_read' => 0]]);
     if ($rt < 1) {
         $this->throwMsg(-16);
     }
 }
Пример #4
0
 /**
  * 将图集设置为草稿
  */
 public function set_draft()
 {
     $this->galleryOwnerCheck($this->gallery_id, $this->user_id);
     $d = $this->db->update("gallery", ['gallery_status' => 0, 'gallery_update_time' => date("Y-m-d H:i:s")], ['AND' => ['id' => $this->gallery_id, 'users_id' => $this->user_id]]);
     if ($d === false) {
         Log::write(_("Gallery set draft error."), Log::SQL);
         $this->throwMsg(-17);
     }
     hook()->apply('Gallery_set_draft', NULL, $this->gallery_id, $this->user_id);
 }
Пример #5
0
 public function role_edit($id, $name, $status)
 {
     return $this->driver->update("role", ['r_name' => $name, 'r_status' => $status], ['r_id' => $id]);
 }