function edittopic_submit(Pieform $form, $values) { global $SESSION, $USER, $topic; $topicid = param_integer('id'); $returnto = param_alpha('returnto', 'topic'); $groupid = get_field_sql("SELECT DISTINCT i.group FROM {interaction_instance} i\n INNER JOIN {interaction_forum_topic} t ON i.id = t.forum\n WHERE t.id =?", array($topicid)); db_begin(); // check the post content actually changed // otherwise topic could have been set as sticky/closed $postchanged = $values['subject'] != $topic->subject || $values['body'] != $topic->body; if ($postchanged) { $newbody = EmbeddedImage::prepare_embedded_images($values['body'], 'topic', $topicid, $groupid); update_record('interaction_forum_post', array('subject' => $values['subject'], 'body' => PluginInteractionForum::prepare_post_body($newbody, $values['post'])), array('id' => $values['post'])); } if ($values['editrecord'] && $postchanged) { insert_record('interaction_forum_edit', (object) array('user' => $USER->get('id'), 'post' => $values['post'], 'ctime' => db_format_timestamp(time()))); } if (isset($values['sticky'])) { update_record('interaction_forum_topic', array('sticky' => isset($values['sticky']) && $values['sticky'] == 1 ? 1 : 0, 'closed' => isset($values['closed']) && $values['closed'] == 1 ? 1 : 0), array('id' => $topicid)); } db_commit(); $SESSION->add_ok_msg(get_string('edittopicsuccess', 'interaction.forum')); if ($returnto == 'view') { redirect('/interaction/forum/view.php?id=' . $topic->forum); } else { redirect('/interaction/forum/topic.php?id=' . $topicid); } }
function addpost_submit(Pieform $form, $values) { global $USER, $SESSION; require_once 'embeddedimage.php'; $parentid = param_integer('parent'); $post = (object) array('topic' => $values['topic'], 'poster' => $USER->get('id'), 'parent' => $parentid, 'subject' => $values['subject'], 'body' => $values['body'], 'ctime' => db_format_timestamp(time())); $sendnow = isset($values['sendnow']) && $values['sendnow'] ? 1 : 0; // See if the same content has been submitted in the last 5 seconds. If so, don't add this post. $oldpost = get_record_select('interaction_forum_post', 'topic = ? AND poster = ? AND parent = ? AND subject = ? AND body = ? AND ctime > ?', array($post->topic, $post->poster, $post->parent, $post->subject, $post->body, db_format_timestamp(time() - 5)), 'id'); if ($oldpost) { redirect(get_config('wwwroot') . 'interaction/forum/topic.php?id=' . $values['topic'] . '&post=' . $oldpost->id); } $postrec = new stdClass(); $postid = $postrec->id = insert_record('interaction_forum_post', $post, 'id', true); $postrec->path = get_field('interaction_forum_post', 'path', 'id', $parentid) . '/' . sprintf('%010d', $postrec->id); update_record('interaction_forum_post', $postrec); // Rewrite the post id into links in the body $groupid = get_groupid_from_postid($postid); $newbody = EmbeddedImage::prepare_embedded_images($post->body, 'post', $postid, $groupid); $newbody = PluginInteractionForum::prepare_post_body($newbody, $postid); if (!empty($newbody) && $newbody != $post->body) { set_field('interaction_forum_post', 'body', $newbody, 'id', $postid); } if ($sendnow == 0) { $delay = get_config_plugin('interaction', 'forum', 'postdelay'); } else { $delay = 0; } if (!is_null($delay) && $delay == 0) { PluginInteractionForum::interaction_forum_new_post(array($postid)); } $SESSION->add_ok_msg(get_string('addpostsuccess', 'interaction.forum')); if (is_using_probation() && $post->parent) { $parentposter = get_field('interaction_forum_post', 'poster', 'id', $post->parent); vouch_for_probationary_user($parentposter); } redirect(get_config('wwwroot') . 'interaction/forum/topic.php?id=' . $values['topic'] . '&post=' . $postid); }