INNER JOIN {group} g ON (g.id = f.group AND g.deleted = ?) LEFT JOIN ( SELECT m.forum, m.user FROM {interaction_forum_moderator} m INNER JOIN {usr} u ON (m.user = u.id AND u.deleted = 0) ) m ON (m.forum = f.id AND m.user = p.poster) INNER JOIN {interaction_forum_post} p3 ON (p.poster = p3.poster AND p3.deleted != 1) INNER JOIN {interaction_forum_topic} t2 ON (t2.deleted != 1 AND p3.topic = t2.id) INNER JOIN {interaction_instance} f2 ON (t2.forum = f2.id AND f2.deleted != 1 AND f2.group = f.group) WHERE p.id = ? AND p.deleted != 1 GROUP BY 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12', array(0, $postid)); if (!$post) { throw new NotFoundException(get_string('cantfindpost', 'interaction.forum', $postid)); } $membership = user_can_access_forum((int) $post->forum); $moderator = (bool) ($membership & INTERACTION_FORUM_MOD); if (!$moderator || $post->group && !group_within_edit_window($post->group)) { throw new AccessDeniedException(get_string('cantdeletepost', 'interaction.forum')); } if (!$post->parent) { throw new AccessDeniedException(get_string('cantdeletethispost', 'interaction.forum')); } define('GROUP', $post->group); define('TITLE', $post->topicsubject . ' - ' . get_string('deletepost', 'interaction.forum')); $post->ctime = relative_date(get_string('strftimerecentfullrelative', 'interaction.forum'), get_string('strftimerecentfull'), $post->ctime); $form = pieform(array('name' => 'deletepost', 'renderer' => 'div', 'autofocus' => false, 'elements' => array('title' => array('value' => get_string('deletepostsure', 'interaction.forum')), 'submit' => array('type' => 'submitcancel', 'class' => 'btn-success', 'value' => array(get_string('yes'), get_string('no')), 'goto' => get_config('wwwroot') . 'interaction/forum/topic.php?id=' . $post->topic . '&post=' . $postid), 'post' => array('type' => 'hidden', 'value' => $postid), 'topic' => array('type' => 'hidden', 'value' => $post->topic), 'parent' => array('type' => 'hidden', 'value' => $post->parent)))); function deletepost_submit(Pieform $form, $values) { global $SESSION, $USER; $objectionable = get_record_sql("SELECT fp.id\n FROM {interaction_forum_post} fp\n JOIN {objectionable} o\n ON (o.objecttype = 'forum' AND o.objectid = fp.id)\n WHERE fp.id = ?\n AND o.resolvedby IS NULL\n AND o.resolvedtime IS NULL", array($values['post']));
// if offset isn't a multiple of $topicsperpage, make it the closest smaller multiple $offset = (int) ($offset / $topicsperpage) * $topicsperpage; $forum = get_record_sql('SELECT f.title, f.description, f.id, COUNT(t.id) AS topiccount, s.forum AS subscribed, g.id AS groupid, g.name AS groupname, ic.value AS newtopicusers FROM {interaction_instance} f INNER JOIN {group} g ON (g.id = f."group" AND g.deleted = ?) LEFT JOIN {interaction_forum_topic} t ON (t.forum = f.id AND t.deleted != 1 AND t.sticky != 1) LEFT JOIN {interaction_forum_subscription_forum} s ON (s.forum = f.id AND s."user" = ?) LEFT JOIN {interaction_forum_instance_config} ic ON (f.id = ic.forum AND ic.field = \'createtopicusers\') WHERE f.id = ? AND f.deleted != 1 GROUP BY 1, 2, 3, 5, 6, 7, 8', array(0, $userid, $forumid)); define('GROUP', $forum->groupid); if (!$forum) { throw new InteractionInstanceNotFoundException(get_string('cantfindforum', 'interaction.forum', $forumid)); } $membership = user_can_access_forum((int) $forumid); $admin = (bool) ($membership & INTERACTION_FORUM_ADMIN); $moderator = (bool) ($membership & INTERACTION_FORUM_MOD); $publicgroup = get_field('group', 'public', 'id', $forum->groupid); if (!$membership && !$publicgroup) { throw new GroupAccessDeniedException(get_string('cantviewforums', 'interaction.forum')); } define('TITLE', $forum->groupname . ' - ' . $forum->title); $feedlink = get_config('wwwroot') . 'interaction/forum/atom.php?type=f&id=' . $forum->id; $moderators = get_column_sql('SELECT gm.user FROM {interaction_forum_moderator} gm INNER JOIN {usr} u ON (u.id = gm.user AND u.deleted = 0) WHERE gm.forum = ?', array($forumid)); // updates the selected topics as subscribed/closed/sticky if ($membership && isset($_POST['checked'])) { $checked = array_map('intval', array_keys($_POST['checked'])); // get type based on which button was pressed
/** * builds a post (including its children) * * @param int $postindex the index of the post * @param string $parentsubject the subject of the parent * @param array $posts the posts in the topic * * @returns string the html for the post */ function buildpost($postindex, $parentsubject, &$posts) { global $moderator, $topic, $groupadmins; $localposts = $posts; if ($posts[$postindex]->subject) { $parentsubject = $posts[$postindex]->subject; } else { $posts[$postindex]->subject = get_string('re', 'interaction.forum', $parentsubject); } $children = array(); foreach ($localposts as $index => $post) { if ($posts[$index]->parent == $posts[$postindex]->id) { $children[] = buildpost($index, $parentsubject, $posts); } } $membership = user_can_access_forum((int) $topic->forumid); $smarty = smarty_core(); $smarty->assign('post', $posts[$postindex]); $smarty->assign('groupadmins', $groupadmins); $smarty->assign('children', $children); $smarty->assign('moderator', $moderator); $smarty->assign('membership', $membership); $smarty->assign('closed', $topic->closed); return $smarty->fetch('interaction:forum:post.tpl'); }
INNER JOIN {interaction_instance} f ON (t.forum = f.id AND f.deleted != 1) INNER JOIN {group} g ON (g.id = f.group AND g.deleted = 0) INNER JOIN {interaction_forum_post} p ON (p.topic = t.id AND p.parent IS NULL) LEFT JOIN {interaction_forum_subscription_forum} sf ON (sf.forum = f.id AND sf.user = ?) LEFT JOIN {interaction_forum_subscription_topic} st ON (st.topic = t.id AND st.user = ?) WHERE t.id = ? AND t.deleted != 1', array($USER->get('id'), $USER->get('id'), $topicid)); if (!$topic) { throw new NotFoundException(get_string('cantfindtopic', 'interaction.forum', $topicid)); } define('GROUP', $topic->groupid); $group = get_record('group', 'id', $topic->groupid); $publicgroup = $group->public; $ineditwindow = group_within_edit_window($group); $feedlink = get_config('wwwroot') . 'interaction/forum/atom.php?type=t&id=' . $topic->id; $membership = user_can_access_forum((int) $topic->forumid); $moderator = $ineditwindow && (bool) ($membership & INTERACTION_FORUM_MOD); $forumconfig = get_records_assoc('interaction_forum_instance_config', 'forum', $topic->forumid, '', 'field,value'); $indentmode = isset($forumconfig['indentmode']) ? $forumconfig['indentmode']->value : 'full_indent'; $maxindentdepth = isset($forumconfig['maxindent']) ? $forumconfig['maxindent']->value : 10; if (!$membership && !get_field('group', 'public', 'id', $topic->groupid)) { $objection = param_integer('objection', 0); $errorstr = $objection ? get_string('accessdeniedobjection', 'error') : get_string('cantviewtopic', 'interaction.forum'); throw new GroupAccessDeniedException($errorstr, $objection); } $topic->canedit = ($moderator || user_can_edit_post($topic->poster, $topic->ctime)) && $ineditwindow; define('TITLE', $topic->forumtitle . ' - ' . $topic->subject); $groupadmins = group_get_admin_ids($topic->groupid); if ($membership && !$topic->forumsubscribed) { $topic->subscribe = pieform(array('name' => 'subscribe_topic', 'renderer' => 'div', 'plugintype' => 'interaction', 'pluginname' => 'forum', 'class' => 'btn-group btn-group-top', 'autofocus' => false, 'elements' => array('submit' => array('type' => 'button', 'usebuttontag' => true, 'class' => 'btn-default', 'value' => $topic->topicsubscribed ? '<span class="icon icon-times icon-lg text-danger left"></span>' . get_string('unsubscribefromtopic', 'interaction.forum') : '<span class="icon icon-star icon-lg left"></span>' . get_string('subscribetotopic', 'interaction.forum'), 'help' => false), 'topic' => array('type' => 'hidden', 'value' => $topicid), 'type' => array('type' => 'hidden', 'value' => $topic->topicsubscribed ? 'unsubscribe' : 'subscribe')))); }
function renderpost($post) { global $moderator, $topic, $groupadmins; $children = array(); if (isset($post->children) && !empty($post->children)) { foreach ($post->children as $index => $child_post) { $children[] = renderpost($child_post); } } $membership = user_can_access_forum((int) $topic->forumid); $smarty = smarty_core(); $smarty->assign('post', $post); $smarty->assign('groupadmins', $groupadmins); $smarty->assign('children', $children); $smarty->assign('moderator', $moderator); $smarty->assign('membership', $membership); $smarty->assign('closed', $topic->closed); return $smarty->fetch('interaction:forum:post.tpl'); }