/** * Clear post reputation * * @param int $post_id Post ID * @return null * @access public */ public function clear_post($post_id) { $this->user->add_lang_ext('pico/reputation', 'reputation_system'); $is_ajax = $this->request->is_ajax(); $submit = false; $post_type_id = (int) $this->reputation_manager->get_reputation_type_id('post'); $sql_array = array('SELECT' => 'r.*, p.post_subject, p.post_reputation, ut.username AS username_to', 'FROM' => array($this->reputations_table => 'r', POSTS_TABLE => 'p'), 'LEFT_JOIN' => array(array('FROM' => array(USERS_TABLE => 'ut'), 'ON' => 'r.user_id_to = ut.user_id ')), 'WHERE' => 'r.reputation_item_id = ' . $post_id . ' AND r.reputation_type_id = ' . $post_type_id . ' AND p.post_id = r.reputation_item_id'); $sql = $this->db->sql_build_query('SELECT', $sql_array); $result = $this->db->sql_query($sql); $row = $this->db->sql_fetchrow($result); $this->db->sql_freeresult($result); //We couldn't find this reputation. May be it was deleted meanwhile? if (empty($row)) { $message = $this->user->lang('RS_NO_REPUTATION'); $json_data = array('error_msg' => $message); $redirect = append_sid("{$this->root_path}index.{$this->php_ext}"); $redirect_text = 'RETURN_INDEX'; $this->reputation_manager->response($message, $json_data, $redirect, $redirect_text, $is_ajax); } $redirect = $this->helper->route('reputation_post_details_controller', array('post_id' => $post_id)); if ($this->request->is_set_post('cancel')) { redirect($redirect); } $redirect_text = 'RETURN_PAGE'; if ($this->auth->acl_gets('m_rs_moderate')) { if ($is_ajax) { $submit = true; } else { $s_hidden_fields = build_hidden_fields(array('p' => $post_id)); if (confirm_box(true)) { $submit = true; } else { confirm_box(false, $this->user->lang('RS_CLEAR_POST_CONFIRM'), $s_hidden_fields); } } } else { $message = $this->user->lang('RS_USER_CANNOT_DELETE'); $json_data = array('error_msg' => $message); $this->reputation_manager->response($message, $json_data, $redirect, $redirect_text, $is_ajax); } if ($submit) { try { $this->reputation_manager->clear_post_reputation($post_id, $row); } catch (\pico\reputation\exception\base $e) { // Catch exception trigger_error($e->get_message($this->user)); } $message = $this->user->lang('RS_CLEARED_POST'); $json_data = array('clear_post' => true, 'post_id' => $post_id, 'poster_id' => $row['user_id_to'], 'user_reputation' => $this->reputation_manager->get_user_reputation($row['user_id_to']), 'post_reputation' => 0, 'reputation_class' => 'neutral'); $this->reputation_manager->response($message, $json_data, $redirect, $redirect_text, $is_ajax); } }