public function submit_post_end($event) { $points_config = $this->cache->get('points_config'); $points_values = $this->cache->get('points_values'); if ($this->config['points_enable']) { $data = $event['data']; $mode = $event['mode']; $poll = $event['poll']; $post_id = (int) $data['post_id']; $topic_id = (int) $data['topic_id']; $forum_id = (int) $data['forum_id']; $user_id = (int) $this->user->data['user_id']; // Send the user_id away to check for a bonus increment $this->functions_points->random_bonus_increment($user_id); /** * Grab our message and strip it clean. * This means removing all BBCode, * and removing text inside code and quote blocks */ $message = $this->functions_points->strip_text($data['message']); // Set default values $topic_word = $topic_char = $forum_topic = 0; $post_word = $post_char = $forum_post = 0; $difference = $total_points = $prev_points = 0; $has_attach = $per_attach = 0; $total_attachments = $points_attach = 0; $has_poll = $per_poll = $points_poll = $total_poll_options = 0; // We grab global points increment $topic_word = $points_values['points_per_topic_word']; // Points per word in a topic $topic_char = $points_values['points_per_topic_character']; // Points per character in a topic $post_word = $points_values['points_per_post_word']; // Points per word in a post (reply) $post_char = $points_values['points_per_post_character']; // Points per word in a post (reply) $has_attach = $points_values['points_per_attach']; // Points for having attachments in your post $per_attach = $points_values['points_per_attach_file']; // Points per attachment in your post $has_poll = $points_values['points_per_poll']; // Points for having a poll in your topic $per_poll = $points_values['points_per_poll_option']; // Points per poll option in your topic // We grab forum specific points increment $sql = 'SELECT forum_peredit, forum_perpost, forum_pertopic, forum_cost_topic, forum_cost_post FROM ' . FORUMS_TABLE . ' WHERE forum_id = ' . (int) $forum_id; $result = $this->db->sql_query($sql); $forum = $this->db->sql_fetchrow($result); $this->db->sql_freeresult($result); // First we check if we have to pay for new topics/post if ($mode == 'post' && $forum['forum_cost_topic'] > 0 && $this->auth->acl_get('f_pay_topic', (int) $forum_id)) { $this->functions_points->substract_points((int) $user_id, $forum['forum_cost_topic']); } else { if (($mode == 'reply' || $mode == 'quote') && $forum['forum_cost_post'] > 0 && $this->auth->acl_get('f_pay_post', (int) $forum_id)) { $this->functions_points->substract_points((int) $user_id, $forum['forum_cost_post']); } } // We grab some specific message data $sizeof_msg = sizeof(explode(' ', $message)); // Amount of words $chars_msg = utf8_strlen($message); // Amount of characters // Check if the post has attachment, if so calculate attachment points if (!empty($data['attachment_data'])) { $total_attachments = sizeof($data['attachment_data']); $points_attach = $total_attachments * $per_attach + $has_attach; } // Check if the post has a poll, if so calculate poll points if (!empty($poll['poll_options'])) { $total_poll_options = sizeof($poll['poll_options']); $points_poll = $total_poll_options * $per_poll + $has_poll; } // If it's a new topic if ($mode == 'post' && $forum['forum_pertopic'] > 0) { // We calculate the total points $words_points = $topic_word * $sizeof_msg; $chars_points = $topic_char * $chars_msg; $total_points = $words_points + $chars_points + $forum['forum_pertopic'] + $points_attach + $points_poll; // We add the total points $this->functions_points->add_points($user_id, $total_points); // Add to the user $this->functions_points->add_points_to_table($post_id, $total_points, 'topic', $total_attachments, $total_poll_options); // Add to the post table } else { if (($mode == 'reply' || $mode == 'quote') && $forum['forum_perpost'] > 0) { // We calculate the total points $words_points = $post_word * $sizeof_msg; $chars_points = $post_char * $chars_msg; $total_points = $words_points + $chars_points + $forum['forum_perpost'] + $points_attach; // We add the total points $this->functions_points->add_points($user_id, $total_points); // Add to the user $this->functions_points->add_points_to_table($post_id, $total_points, 'post', $total_attachments, 0); // Add to the post table } else { if (($mode == 'edit_topic' || $mode == 'edit_first_post') && $forum['forum_peredit'] > 0) { // We calculate the total points $words_points = $topic_word * $sizeof_msg; $chars_points = $topic_char * $chars_msg; $total_points = $words_points + $chars_points + $forum['forum_peredit'] + $points_attach + $points_poll; // We grab previously received points amount $sql = 'SELECT points_topic_received FROM ' . POSTS_TABLE . ' WHERE post_id = ' . (int) $post_id; $result = $this->db->sql_query($sql); $prev_points = $this->db->sql_fetchfield('points_topic_received'); $this->db->sql_freeresult($result); // We calculate the difference $difference = $total_points - $prev_points; // We add the difference, only if it's positive, cause we're generous :-) if ($difference > 0) { $this->functions_points->add_points($user_id, $difference); // Add to the user $this->functions_points->add_points_to_table($post_id, $total_points, 'topic', $total_attachments, $total_poll_options); // Update to the post table } else { return; // "AM I NOT MERCIFUL??" - Caesar Commodus (Gladiator [2000]) } } else { if (($mode == 'edit' || $mode == 'edit_last_post') && $forum['forum_peredit'] > 0) { // We calculate the total points $words_points = $post_word * $sizeof_msg; $chars_points = $post_char * $chars_msg; $total_points = $words_points + $chars_points + $forum_['forum_peredit'] + $points_attach; // We grab previously received points amount $sql = 'SELECT points_post_received FROM ' . POSTS_TABLE . ' WHERE post_id = ' . (int) $post_id; $result = $this->db->sql_query($sql); $prev_points = $this->db->sql_fetchfield('points_post_received'); $this->db->sql_freeresult($result); // We calculate the difference $difference = $total_points - $prev_points; // We add the difference, only if it's positive, cause we're generous :-) if ($difference > 0) { $this->functions_points->add_points($user_id, $difference); // Add to the user $this->functions_points->add_points_to_table($post_id, $total_points, 'post', $total_attachments, 0); // Update to the post table } else { return; // "AM I NOT MERCIFUL??" - Caesar Commodus (Gladiator [2000]) } } else { // We do nothing.. return; // The only thing necessary for the triumph of evil, is for good men to do nothing. - Edmund Burke } } } } } else { return; } }