Exemple #1
0
 // Clean up message from POST
 $message = pun_linebreaks(pun_trim($_POST['req_message']));
 if (!$message) {
     $errors[] = $lang_post['No message'];
 } else {
     if (mb_strlen($message) > 65535) {
         $errors[] = $lang_post['Too long message'];
     } else {
         if (!$pun_config['p_message_all_caps'] && mb_strtoupper($message) == $message && $pun_user['g_id'] > PUN_MOD) {
             $message = ucwords(mb_strtolower($message));
         }
     }
 }
 // MOD CONVENIENT FORUM URL BEGIN
 //if ($pun_config['o_convenient_url_enable'] == 1)
 convert_forum_url($message);
 // MOD CONVENIENT FORUM URL END
 // Validate BBCode syntax
 if ($pun_config['p_message_bbcode'] == 1 && strpos($message, '[') !== false && strpos($message, ']') !== false) {
     include_once PUN_ROOT . 'include/parser.php';
     $message = preparse_bbcode($message, $errors);
 }
 include PUN_ROOT . 'include/search_idx.php';
 $hide_smilies = isset($_POST['hide_smilies']) ? 1 : 0;
 $subscribe = isset($_POST['subscribe']) ? 1 : 0;
 // Did everything go according to plan?
 if (!$errors && !isset($_POST['preview'])) {
     // MERGE POSTS BEGIN
     $merged = false;
     if (isset($_POST['merge'])) {
         $_POST['merge'] = 1;
Exemple #2
0
 /**
  * setMessage
  *
  * @param array $args
  * @return array
  * @throws Exception
  */
 public function setMessage($args)
 {
     $message = $args['message'];
     $topicId = $args['topicId'];
     $hideSmiles = $args['hideSmiles'];
     $topicId = intval($topicId);
     if ($topicId <= 0) {
         throw new Exception($this->_lang['Bad request']);
     }
     if ($this->_pun_user['is_guest']) {
         throw new Exception($this->_lang['Bad request']);
     }
     if ($this->_pun_user['last_post'] && $_SERVER['REQUEST_TIME'] - $this->_pun_user['last_post'] < $this->_pun_user['g_post_flood']) {
         throw new Exception($this->_lang['Bad request']);
     }
     // Clean up message
     $message = pun_linebreaks(pun_trim($message));
     if (!$message) {
         throw new Exception($this->_lang['Bad request']);
     } else {
         if (mb_strlen($message) > 65535) {
             throw new Exception($this->_lang['Bad request']);
         } else {
             if (!$this->_pun_config['p_message_all_caps'] && mb_strtoupper($message) == $message && $this->_pun_user['g_id'] > PUN_MOD) {
                 $message = ucwords(mb_strtolower($message));
             }
         }
     }
     convert_forum_url($message);
     // Insert the new post
     $r = $this->_db->query('
         INSERT INTO ' . $this->_db->prefix . 'posts (
             poster, poster_id, poster_ip, message, hide_smilies, posted, topic_id
         ) VALUES (
             \'' . $this->_db->escape($this->_pun_user['username']) . '\',
             ' . $this->_pun_user['id'] . ',
             \'' . get_remote_address() . '\',
             \'' . $this->_db->escape($message) . '\',
             \'' . intval($hideSmiles) . '\',
             ' . $_SERVER['REQUEST_TIME'] . ',
             ' . $topicId . '
         )
     ');
     if (!$r) {
         throw new Exception($this->_db->error());
     }
     if (!$this->_db->affected_rows()) {
         throw new Exception($this->_lang['Bad request']);
     }
     $id = $this->_db->insert_id();
     // Count number of replies in the topic
     $result = $this->_db->query('
         SELECT COUNT(1)
         FROM ' . $this->_db->prefix . 'posts
         WHERE topic_id=' . $topicId);
     $num_replies = $this->_db->result($result, 0) - 1;
     // Update topic
     $this->_db->query('
         UPDATE ' . $this->_db->prefix . 'topics
         SET num_replies=' . $num_replies . ',
         last_post=' . $_SERVER['REQUEST_TIME'] . ',
         last_post_id=' . $id . ',
         last_poster=\'' . $this->_db->escape($this->_pun_user['username']) . '\'
         WHERE id=' . $topicId);
     //update_search_index('post', $id, $message);
     $result = $this->_db->query('
         SELECT f.id
         FROM ' . $this->_db->prefix . 'topics AS t
         INNER JOIN ' . $this->_db->prefix . 'forums AS f ON f.id=t.forum_id
         LEFT JOIN ' . $this->_db->prefix . 'forum_perms AS fp ON (fp.forum_id=f.id AND fp.group_id=' . $this->_pun_user['g_id'] . ')
         WHERE (fp.read_forum IS NULL OR fp.read_forum=1) AND t.id=' . $topicId);
     $forumId = $this->_db->result($result, 0);
     update_forum($forumId);
     generate_rss();
     return array('message' => $this->_parseMessage($message, $hideSmiles), 'poster' => $this->_pun_user['username'], 'posted' => $_SERVER['REQUEST_TIME']);
 }