public function __construct($playerUUID, $database)
 {
     $this->uuid = $playerUUID;
     // Gather additionals stats
     $query = $database->prepare("SELECT * FROM BAT_players WHERE UUID = :uuid;");
     $query->execute(array(":uuid" => $this->uuid));
     $data = $query->fetch();
     if ($data != false) {
         $this->player = $data['BAT_player'];
         $this->firstlogin = $data['firstlogin'];
         $this->lastlogin = $data['lastlogin'];
         $this->lastip = $data['lastip'];
     } else {
         die("Player not found !");
     }
     // Gather different modules stats
     $banModel = new ban_model();
     $this->banEntries = $banModel->getPlayerBans($this->uuid);
     $muteModel = new mute_model();
     $this->muteEntries = $muteModel->getPlayerMutes($this->uuid);
     $kickModel = new kick_model();
     $this->kickEntries = $kickModel->getPlayerKicks($this->uuid);
     $commentModel = new comment_model();
     $this->commentEntries = $commentModel->getPlayerComments($this->uuid);
 }
Exemplo n.º 2
0
 public static function new_action()
 {
     // 拦截
     self::method('post');
     $post_id = g_int('post_id');
     $post = post_model::get_by_id($post_id);
     self::forward_404_if($post === null, '文章不存在,无法评论');
     try {
         // 校验
         $checker = new lazy_checker(p());
         $checker->check('captcha', array('should_be' => array(setting_model::get_by_id(setting_model::id_captcha_answer)->value, '验证码不正确')));
         $checker->del('captcha');
         $checker->check_model_rules('comment');
         $comment = $checker->get_all();
         if (!visitor::has_role('member') && member_model::get_one(array('name' => $comment['author'])) !== null) {
             $checker->failed('author', '您不能使用管理员的昵称');
         }
         // 执行
         $comment['post_id'] = $post_id;
         $comment['pub_time'] = clock::get_stamp();
         comment_model::add($comment);
         post_model::inc_by_id(array('comment_count' => 1), $post_id);
         setting_model::inc_by_id(array('value' => 1), setting_model::id_comment_count);
         // 成功
         self::json_result(true, '评论成功', 0, url('post/show?id=' . $post_id));
     } catch (check_failed $e) {
         // 失败
         self::json_result(false, $e->get_reasons());
     }
 }
Exemplo n.º 3
0
 public function get_subcomments()
 {
     if (!isset($this->data['subcomments'])) {
         $this->data['subcomments'] = comment_model::get_comments(array('filters' => array('file_id' => $this->get_file_id(), 'comment_parent_id' => $this->get_id()), 'orders' => array('comment_add_datetime' => 'asc')));
     }
     return $this->data['subcomments'];
 }
Exemplo n.º 4
0
 public static function delete($comment_id)
 {
     $comment = comment_model::get_by_id($comment_id);
     if ($comment !== null) {
         comment_model::del_by_id($comment_id);
         post_model::dec_by_id(array('comment_count' => 1), $comment->post_id);
     }
 }
Exemplo n.º 5
0
 /**
  * 获取评论列表
  *
  * @access public
  * @param string type
  * @param int $page
  * @param int $num
  * @return array
  */
 public function getList()
 {
     $this->checkAccessToken();
     $this->params = $this->require_params(array('type'));
     if ($this->params['type'] == 'event') {
         $this->require_params(array('eventId'));
     }
     $this->params['page'] = F::request('page', 1);
     $this->params['num'] = F::request('num', 20);
     switch ($this->params['type']) {
         case 'event':
             $this->returnData = $this->commentModel->getListByEvent($this->params['eventId'], $this->params['page'], $this->params['num']);
             break;
         default:
             throw new Exception('未知的type类型', 100);
             break;
     }
     F::rest()->show_result($this->returnData);
 }
Exemplo n.º 6
0
 public static function run(array $context)
 {
     self::set('categories', category_model::get_all());
     self::set('tags', tag_model::get_all(array(array('refer_count' => 'DESC'), 1, 10)));
     $comments = comment_model::get_all(array(array('id' => 'DESC'), 1, 10));
     binder::bind($comments, 'belongs_to', 'post');
     self::set('comments', $comments);
     self::set('links', link_model::get_all());
     self::render();
 }
Exemplo n.º 7
0
 public static function delete_action()
 {
     // 拦截
     self::method('delete');
     self::role('member');
     self::csrf('member');
     // 校验
     // 执行
     $id = g_int('id');
     $post = post_model::get_by_id($id);
     if ($post !== null) {
         comment_model::del(array('post_id' => $id));
         category_model::dec_by_id(array('post_count' => 1), $post->category_id);
         post_model::del_by_id($id);
         publish_service::delete_tags_for_post($post);
     }
     // 成功
     self::send_json(true);
 }
Exemplo n.º 8
0
 public function get_total_comments()
 {
     if (!isset($this->data['total_comments'])) {
         $this->data['total_comments'] = comment_model::get_total_comments($this->get_id());
     }
     return $this->data['total_comments'];
 }
Exemplo n.º 9
0
 public static function add_comment($file_id = 0, $comment_parent_id = 0)
 {
     if (!($me = session_essence::get('me'))) {
         request_essence::load_request();
     }
     if ($file_id) {
         if ($file = file_model::get_file_by_id($file_id)) {
             if ($comment_parent_id > 0) {
                 if (!($comment = comment_model::get_comment_by_id($comment_parent_id))) {
                     request_essence::load_request();
                 } else {
                     if ($comment->get_file_id() != $file_id) {
                         request_essence::load_request();
                     }
                 }
             }
             $comment = new comment_object();
             $comment->set_parent_id($comment_parent_id);
             $comment->set_content(data_essence::get('post', 'comment-content', array('trim', 'striptags')));
             $comment->set_file_id($file_id);
             $comment->set_user_id($me->get_id());
             if (comment_model::add_comment($comment)) {
                 request_essence::load_request('file', 'view', array($file_id));
             } else {
                 request_essence::load_request();
             }
         } else {
             request_essence::load_request();
         }
     } else {
         request_essence::load_request();
     }
 }