Commit 9c7c3741 authored by Clare Lenihan's avatar Clare Lenihan Committed by Clare Lenihan

added date formating, comments, transaction + other minor stuff

parent 028f5659
......@@ -33,7 +33,7 @@ define('TITLE', get_string('deletepost', 'interaction.forum'));
$postid = param_integer('id');
$post = get_record_sql(
'SELECT p.subject, p.body, p.topic, p.parent, p.poster, p.ctime, t.forum, p2.subject as topicsubject, f.group, f.title as forumtitle, g.name as groupname, COUNT(p3.*)
'SELECT p.subject, p.body, p.topic, p.parent, p.poster, ' . db_format_tsfield('p.ctime', 'ctime') . ', t.forum, p2.subject AS topicsubject, f.group, f.title AS forumtitle, g.name AS groupname, COUNT(p3.*)
FROM {interaction_forum_post} p
INNER JOIN {interaction_forum_topic} t ON (p.topic = t.id AND t.deleted != 1)
INNER JOIN {interaction_forum_post} p2 ON (p2.topic = t.id AND p2.parent IS NULL)
......@@ -58,6 +58,8 @@ $admin = (bool)($membership & GROUP_MEMBERSHIP_OWNER);
$moderator = $admin || is_forum_moderator((int)$post->forum);
$post->ctime = strftime(get_string('strftimerecentfull'), $post->ctime);
if (!$moderator) {
throw new AccessDeniedException(get_string('cantdeletepost', 'interaction.forum'));
}
......
......@@ -32,7 +32,7 @@ require('group.php');
$topicid = param_integer('id');
$topic = get_record_sql(
'SELECT f."group", f.id as forumid, f.title, g.name as groupname, p.poster, p.subject, p.body, COUNT(p2.*), p.ctime, t.closed
'SELECT f."group", f.id AS forumid, f.title, g.name AS groupname, p.poster, p.subject, p.body, COUNT(p2.*), ' . db_format_tsfield('p.ctime', 'ctime') . ', t.closed
FROM {interaction_forum_topic} t
INNER JOIN {interaction_instance} f ON (f.id = t.forum AND f.deleted != 1)
INNER JOIN {group} g ON g.id = f.group
......@@ -56,6 +56,8 @@ $admin = (bool)($membership & GROUP_MEMBERSHIP_OWNER);
$moderator = $admin || is_forum_moderator((int)$topic->forumid);
$topic->ctime = strftime(get_string('strftimerecentfull'), $topic->ctime);
if (!$moderator) {
throw new AccessDeniedException(get_string('cantdeletetopic', 'interaction.forum'));
}
......@@ -88,7 +90,7 @@ $breadcrumbs = array(
require_once('pieforms/pieform.php');
$form = pieform(array(
'name' => 'deletepost',
'name' => 'deletetopic',
'autofocus' => false,
'elements' => array(
'title' => array(
......@@ -98,28 +100,24 @@ $form = pieform(array(
'type' => 'submitcancel',
'value' => array(get_string('yes'), get_string('no')),
'goto' => get_config('wwwroot') . 'interaction/forum/topic.php?id=' . $topicid,
),
'forum' => array(
'type' => 'hidden',
'value' => $topic->forumid
)
)
));
function deletepost_submit(Pieform $form, $values) {
function deletetopic_submit(Pieform $form, $values) {
global $SESSION;
$topicid = param_integer('id');
db_begin();
update_record(
'interaction_forum_topic',
array('deleted' => 1),
array('id' => $topicid)
);
$forumid = get_field_sql(
'SELECT forum
FROM interaction_forum_topic
WHERE id = ?',
array($topicid)
);
db_commit();
$SESSION->add_ok_msg(get_string('deletetopicsuccess', 'interaction.forum'));
redirect('/interaction/forum/view.php?id=' . $forumid);
redirect('/interaction/forum/view.php?id=' . $values['forum']);
}
$smarty = smarty();
......
......@@ -33,15 +33,14 @@ require('group.php');
$userid = $USER->get('id');
$postid = param_integer('id',0);
$topicid = 0;
if ($postid==0) {
$postid = param_integer('id', 0);
if ($postid == 0) { // post reply
unset($postid);
define('TITLE', get_string('postreply','interaction.forum'));
$parentid = param_integer('parent');
$parent = get_record_sql(
'SELECT p.subject, p.body, p.topic, p.parent, p.poster, t.id as topicid, t.forum, t.closed AS topicclosed, p2.subject AS topicsubject, f.group, f.title AS forumtitle, g.name AS groupname, COUNT(p3.*)
'SELECT p.subject, p.body, p.topic, p.parent, p.poster, ' . db_format_tsfield('p.ctime', 'ctime') . ', t.id AS topicid, t.forum, t.closed AS topicclosed, p2.subject AS topicsubject, f.group, f.title AS forumtitle, g.name AS groupname, COUNT(p3.*)
FROM {interaction_forum_post} p
INNER JOIN {interaction_forum_topic} t ON (p.topic = t.id AND t.deleted != 1)
INNER JOIN {interaction_forum_post} p2 ON (p2.topic = t.id AND p2.parent IS NULL)
......@@ -52,7 +51,7 @@ if ($postid==0) {
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',
GROUP BY 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13',
array($parentid)
);
......@@ -72,6 +71,7 @@ if ($postid==0) {
$topicid = $parent->topicid;
$topicsubject = $parent->topicsubject;
$parent->ctime = strftime(get_string('strftimerecentfull'), $parent->ctime);
$breadcrumbs = array(
array(
......@@ -96,11 +96,10 @@ if ($postid==0) {
)
);
}
if (isset($postid)) {
else { // edit post
define('TITLE', get_string('editpost','interaction.forum'));
$post = get_record_sql(
'SELECT p.subject, p.body, p.parent, p.topic, p.poster, p.ctime, t.forum, p2.subject AS topicsubject, f.title AS forumtitle, f.group, g.name AS groupname
'SELECT p.subject, p.body, p.parent, p.topic, p.poster, ' . db_format_tsfield('p.ctime', 'ctime') . ', t.forum, p2.subject AS topicsubject, f.title AS forumtitle, f.group, g.name AS groupname
FROM {interaction_forum_post} p
INNER JOIN {interaction_forum_topic} t ON (p.topic = t.id AND t.deleted != 1)
INNER JOIN {interaction_forum_post} p2 ON (p2.topic = t.id AND p2.parent IS NULL)
......@@ -124,9 +123,13 @@ if (isset($postid)) {
$moderator = $admin || is_forum_moderator((int)$post->forum);
if (!$moderator &&
($post->poster != $userid
|| (time() - strtotime($post->ctime)) > (30 * 60))) {
if ($post->poster == $userid && (time() - $post->ctime) < (30 * 60)) {
$post->editrecord = false;
}
else if ($moderator) {
$post->editrecord = true;
}
else {
throw new AccessDeniedException(get_string('canteditpost', 'interaction.forum'));
}
......@@ -178,8 +181,8 @@ EOF;
require_once('pieforms/pieform.php');
$editform = pieform(array(
'name' => isset($post) ? 'editpost' : 'addpost',
'method' => 'post',
'name' => 'editpost',
'successcallback' => isset($post) ? 'editpost_submit' : 'addpost_submit',
'elements' => array(
'subject' => array(
'type' => 'text',
......@@ -204,20 +207,22 @@ $editform = pieform(array(
isset($post) ? get_string('edit') : get_string('post','interaction.forum'),
get_string('cancel')
),
'goto' => get_config('wwwroot') . 'interaction/forum/topic.php?id='.$topicid
'goto' => get_config('wwwroot') . 'interaction/forum/topic.php?id='.$topicid
),
'topic' => array(
'type' => 'hidden',
'value' => $topicid
),
'editrecord' => array(
'type' => 'hidden',
'value' => isset($post) ? $post->editrecord : false
)
),
));
function editpost_submit(Pieform $form, $values) {
global $USER, $SESSION;
$postid = param_integer('id');
$topic = get_record_sql(
'SELECT topic AS id, poster, ctime AS posttime
FROM {interaction_forum_post}
WHERE id = ?',
array($postid)
);
db_begin();
update_record(
'interaction_forum_post',
......@@ -227,8 +232,7 @@ function editpost_submit(Pieform $form, $values) {
),
array('id' => $postid)
);
if ($topic->poster != $USER->get('id') ||
(time() - strtotime($topic->posttime)) > (30 * 60)) {
if ($values['editrecord']) {
insert_record(
'interaction_forum_edit',
(object)array(
......@@ -238,33 +242,27 @@ function editpost_submit(Pieform $form, $values) {
)
);
}
db_commit();
$SESSION->add_ok_msg(get_string('editpostsuccess', 'interaction.forum'));
redirect('/interaction/forum/topic.php?id='.$topic->id);
redirect('/interaction/forum/topic.php?id=' . $values['topic']);
}
function addpost_submit(Pieform $form, $values) {
global $USER, $SESSION;
$parentid = param_integer('parent');
$topic = get_record_sql(
'SELECT topic AS id
FROM {interaction_forum_post}
WHERE id = ?',
array($parentid)
);
insert_record(
'interaction_forum_post',
(object)array(
'topic' => $topic->id,
'topic' => $values['topic'],
'poster' => $USER->get('id'),
'parent' => $parentid,
'subject' => $values['subject'],
'body' => $values['body'],
'ctime' => db_format_timestamp(time())
),
'id'
)
);
$SESSION->add_ok_msg(get_string('addpostsuccess', 'interaction.forum'));
redirect('/interaction/forum/topic.php?id='.$topic->id);
redirect('/interaction/forum/topic.php?id=' . $values['topic']);
}
$smarty = smarty();
......
......@@ -31,14 +31,13 @@ safe_require('interaction', 'forum');
require_once('group.php');
$userid = $USER->get('id');
$moderator = false;
$topicid = param_integer('id',0);
if ($topicid==0) {
$topicid = param_integer('id', 0);
if ($topicid == 0) { // new topic
unset($topicid);
define('TITLE', get_string('addtopic','interaction.forum'));
$forumid = param_integer('forum');
$forum = get_record_sql(
'SELECT f.group AS group, f.title, g.name as groupname
'SELECT f.group AS group, f.title, g.name AS groupname
FROM {interaction_instance} f
INNER JOIN {group} g ON g.id = f.group
WHERE f.id = ?
......@@ -81,10 +80,10 @@ if ($topicid==0) {
);
}
if (isset($topicid)) {
define('TITLE', get_string('edittopic','interaction.forum'));
else { // edit topic
define('TITLE', get_string('edittopic','interaction.forum'));
$topic = get_record_sql(
'SELECT p.subject, p.body, p.topic AS id, t.sticky, t.closed, f.id as forumid, f.group AS group, f.title, g.name AS groupname
'SELECT p.subject, p.id AS postid, p.body, p.topic AS id, t.sticky, t.closed, f.id AS forumid, f.group AS group, f.title, g.name AS groupname
FROM {interaction_forum_post} p
INNER JOIN {interaction_forum_topic} t ON (p.topic = t.id AND t.deleted != 1)
INNER JOIN {interaction_instance} f ON (f.id = t.forum AND f.deleted != 1)
......@@ -180,6 +179,10 @@ $editform = array(
),
'goto' => get_config('wwwroot') . 'interaction/forum/' . (isset($topic) ? 'topic.php?id='.$topicid : 'view.php?id='.$forumid)
),
'post' => array(
'type' => 'hidden',
'value' => isset($topic) ? $topic->postid : false
)
),
);
......@@ -200,9 +203,7 @@ function addtopic_submit(Pieform $form, $values) {
'forum' => $forumid,
'sticky' => isset($values['sticky']) && $values['sticky'] ? 1 : 0,
'closed' => isset($values['closed']) && $values['closed'] ? 1 : 0
),
'id',
true
), 'id', true
);
insert_record(
'interaction_forum_post',
......@@ -212,8 +213,7 @@ function addtopic_submit(Pieform $form, $values) {
'subject' => $values['subject'],
'body' => $values['body'],
'ctime' => db_format_timestamp(time())
),
'id'
)
);
db_commit();
$SESSION->add_ok_msg(get_string('addtopicsuccess', 'interaction.forum'));
......@@ -223,13 +223,6 @@ function addtopic_submit(Pieform $form, $values) {
function edittopic_submit(Pieform $form, $values) {
global $SESSION, $USER;
$topicid = param_integer('id');
$post = get_record_sql(
'SELECT id
FROM {interaction_forum_post}
WHERE parent IS NULL
AND topic = ?',
array($topicid)
);
db_begin();
update_record(
'interaction_forum_post',
......@@ -237,13 +230,13 @@ function edittopic_submit(Pieform $form, $values) {
'subject' => $values['subject'],
'body' => $values['body']
),
array('id' => $post->id)
array('id' => $values['post'])
);
insert_record(
'interaction_forum_edit',
(object)array(
'user' => $USER->get('id'),
'post' => $post->id,
'post' => $values['post'],
'ctime' => db_format_timestamp(time())
)
);
......
......@@ -34,7 +34,7 @@ define('TITLE', get_string('nameplural', 'interaction.forum'));
$groupid = param_integer('group');
if (!record_exists('group', 'id', $groupid)) {
throw new GroupNotFoundException(get_string('groupnotfound', 'group', $groupid));
throw new GroupNotFoundException(get_string('groupnotfound', 'group', $groupid));
}
$groupname = get_field_sql(
......@@ -97,6 +97,10 @@ if ($forums) {
'redirect' => array(
'type' => 'hidden',
'value' => '/interaction/forum/index.php?group=' . $groupid
),
'type' => array(
'type' => 'hidden',
'value' => $forum->subscribed ? 'unsubscribe' : 'subscribe'
)
)
));
......
......@@ -65,6 +65,8 @@ $string['edittopic'] = 'Edit topic';
$string['edittopicsuccess'] = 'Topic edited successfully';
$string['forumsuccessfulsubscribe'] = 'Forum subscribed successfully';
$string['forumsuccessfulunsubscribe'] = 'Forum unsubscribed successfully';
$string['lastpost'] = 'Last post';
$string['lastposton'] = '%s on %s';
$string['moderators'] = 'Moderators';
$string['moderatorsdescription'] = 'Moderators can edit and delete topics and posts. They can also open, close, set and unset topics as sticky';
$string['name'] = 'Forum';
......@@ -74,8 +76,8 @@ $string['newforumpostin'] = 'New forum post in %s';
$string['newpost'] = 'New post: ';
$string['newtopic'] = 'New topic';
$string['noforums'] = 'There are no forums in this group';
$string['noregulartopics'] = 'There are no regular topics in this forum';
$string['nostickytopics'] = 'There are no sticky topics in this forum';
$string['notopics'] = 'There are no topics in this forum';
$string['open'] = 'Open';
$string['post'] = 'Post';
$string['postedin'] = '%s posted in %s';
$string['poster'] = 'Poster';
......@@ -91,17 +93,26 @@ $string['sticky'] = 'Sticky';
$string['stickydescription'] = 'Sticky topics are at the top of every page';
$string['stickytopics'] = 'Sticky topics';
$string['subscribe'] = 'Subscribe';
$string['subscribetoforum'] = 'Subscribe to forum';
$string['subscribetotopic'] = 'Subscribe to topic';
$string['subject'] = 'Subject';
$string['topic'] = 'Topic';
$string['topiclower'] = 'topic';
$string['topics'] = 'Topics: %s';
$string['topicslower'] = 'topics';
$string['topicclosedsuccess'] = 'Topics were closed successfully';
$string['topicstickysuccess'] = 'Topics were set as sticky successfully';
$string['topicclosedsuccess'] = 'Topics closed successfully';
$string['topicopenedsuccess'] = 'Topics opened successfully';
$string['topicstickysuccess'] = 'Topics set as sticky successfully';
$string['topicsubscribesuccess'] = 'Topics subscribed successfully';
$string['topicunstickysuccess'] = 'Topic unset as sticky successfully';
$string['topicunsubscribesuccess'] = 'Topics unsubscribed successfully';
$string['topicupdatefailed'] = 'Topics update failed';
$string['typenewpost'] = 'New post';
$string['unsticky'] = 'Unsticky';
$string['unsubscribe'] = 'Unsubscribe';
$string['unsubscribefromforum'] = 'Unsubscribe from forum';
$string['unsubscribefromtopic'] = 'Unsubscribe from topic';
$string['updatetopics'] = 'Update topics';
$string['weight'] = 'Weight';
$string['weightdescription'] = 'The weight controls the order of forums. Forums with lower weights appear above forums with higher weights';
......
......@@ -5,7 +5,7 @@ class PluginInteractionForum extends PluginInteraction {
public static function instance_config_form($group, $instance=null) {
if (isset($instance)) {
$weight = get_field_sql(
'SELECT c.value as weight
'SELECT c.value AS weight
FROM {interaction_forum_instance_config} c
WHERE c.field=\'weight\'
AND forum = ?',
......@@ -47,6 +47,7 @@ class PluginInteractionForum extends PluginInteraction {
}
public static function instance_config_save($instance, $values){
db_begin();
delete_records(
'interaction_forum_moderator',
'forum', $instance->get('id')
......@@ -74,6 +75,7 @@ class PluginInteractionForum extends PluginInteraction {
'value' => $values['weight']
)
);
db_commit();
}
public static function get_activity_types() {
......@@ -163,7 +165,7 @@ class ActivityTypeInteractionForumNewPost extends ActivityTypePlugin {
$this->users = get_records_sql_array(
'SELECT id, username, preferredname, firstname, lastname, admin, staff
FROM {usr} u
WHERE id in (' . implode(',', $this->users) . ')',
WHERE id IN (' . implode(',', $this->users) . ')',
array()
);
$post = get_record_sql(
......@@ -235,16 +237,15 @@ function is_forum_moderator($forumid, $userid=null) {
}
/**
* For a pieform with forum, redirect and subscribe elements.
* For a pieform with forum, redirect and type elements.
* forum is the forum id
* redirect is where to redirect to
* subscribe has value get_string('subscribe', 'interaction.forum') if the user should be subscribed
* get_string('unsubscribe', 'interaction.forum') if the user should be unsubscribed
* type is unsubscribe or subscribe depending on the intended action
*/
function subscribe_forum_submit(Pieform $form, $values) {
global $USER, $SESSION;
db_begin();
if ($values['submit'] == get_string('subscribe', 'interaction.forum')) {
if ($values['type'] == 'subscribe') {
db_begin();
insert_record(
'interaction_forum_subscription_forum',
(object)array(
......@@ -262,6 +263,7 @@ function subscribe_forum_submit(Pieform $form, $values) {
)',
array($values['forum'], $USER->get('id'))
);
db_commit();
$SESSION->add_ok_msg(get_string('forumsuccessfulsubscribe', 'interaction.forum'));
}
else {
......@@ -272,7 +274,6 @@ function subscribe_forum_submit(Pieform $form, $values) {
);
$SESSION->add_ok_msg(get_string('forumsuccessfulunsubscribe', 'interaction.forum'));
}
db_commit();
redirect($values['redirect']);
}
......
<span>
{foreach from=$breadcrumbs item=item name=breadcrumbs}
<a href="{$item[0]|escape}">{$item[1]|escape}</a>
{if !$smarty.foreach.breadcrumbs.last} &raquo {/if}
{if !$smarty.foreach.breadcrumbs.last} &raquo; {/if}
{/foreach}
</span>
\ No newline at end of file
......@@ -30,7 +30,7 @@
{/foreach}
</ul>
{else}
<p>{str tag=noforums section=interaction.forum}</p>
<div>{str tag=noforums section=interaction.forum}</div>
{/if}
{include file="columnleftend.tpl"}
{include file="footer.tpl"}
{if $post->subject}<h4>{$post->subject|escape}</h4>{/if}
{$post->ctime}
<h5>{$post->poster|display_name|escape}</h5>
<h5>{str tag="posts" section=interaction.forum} {$post->count|escape}</h5>
<h5><a href="{$WWWROOT}user/view.php?id={$post->poster}">{$post->poster|display_name|escape}</a></h5>
<div><img src="{$WWWROOT}thumb.php?type=profileicon&amp;maxsize=100&amp;id={$post->poster}" alt=""></div>
<h5>{str tag="posts" section=interaction.forum} {$post->count|escape}</h5>
{$post->body}
\ No newline at end of file
......@@ -7,8 +7,8 @@
{include file="interaction:forum:breadcrumbs.tpl" breadcrumbs=$breadcrumbs}
{if $moderator}
<div>
<a href="{$WWWROOT}interaction/forum/edittopic.php?id={$topic->id|escape}">{str tag="edit"}</a>
| <a href="{$WWWROOT}interaction/forum/deletetopic.php?id={$topic->id|escape}">{str tag="delete"}</a>
<a href="{$WWWROOT}interaction/forum/edittopic.php?id={$topic->id|escape}">{str tag=edittopic section=interaction.forum}</a>
| <a href="{$WWWROOT}interaction/forum/deletetopic.php?id={$topic->id|escape}">{str tag=deletetopic section=interaction.forum}</a>
</div>
{/if}
{if !$topic->forumsubscribed}{$topic->subscribe}{/if}
......
......@@ -34,7 +34,7 @@ define('TITLE', get_string('topic','interaction.forum'));
$topicid = param_integer('id');
$topic = get_record_sql(
'SELECT p.subject, f.group, g.name AS groupname, f.id AS forumid, f.title as forumtitle, t.closed, t.id, sf.forum AS forumsubscribed, st.topic AS topicsubscribed
'SELECT p.subject, t.id, f.group, g.name AS groupname, f.id AS forumid, f.title AS forumtitle, t.closed, sf.forum AS forumsubscribed, st.topic AS topicsubscribed
FROM {interaction_forum_topic} t
INNER JOIN {interaction_instance} f ON (t.forum = f.id AND f.deleted != 1)
INNER JOIN {group} g ON g.id = f.group
......@@ -74,7 +74,7 @@ $breadcrumbs = array(
$topic->forumtitle
),
array(
get_config('wwwroot') . 'interaction/forum/topic.php?id=' . $topic->id,
get_config('wwwroot') . 'interaction/forum/topic.php?id=' . $topicid,
$topic->subject
)
);
......@@ -88,84 +88,99 @@ if (!$topic->forumsubscribed) {
'elements' => array(
'submit' => array(
'type' => 'submit',
'value' => $topic->topicsubscribed ? get_string('unsubscribe', 'interaction.forum') : get_string('subscribe', 'interaction.forum')
'value' => $topic->topicsubscribed ? get_string('unsubscribefromtopic', 'interaction.forum') : get_string('subscribetotopic', 'interaction.forum')
),
'topic' => array(
'type' => 'hidden',
'value' => $topicid
),
'type' => array(
'type' => 'hidden',
'value' => $topic->topicsubscribed ? 'unsubscribe' : 'subscribe'
)
)
));
}
$posts = get_records_sql_array(
'SELECT p1.id, p1.parent, p1.poster, p1.subject, p1.body, p1.ctime, p1.deleted, COUNT(p2.*), e.ctime AS edit, e.user AS editor
'SELECT p1.id, p1.parent, p1.poster, p1.subject, p1.body, ' . db_format_tsfield('p1.ctime', 'ctime') . ', p1.deleted, COUNT(p2.*), ' . db_format_tsfield('e.ctime', 'edittime') . ', e.user AS editor
FROM {interaction_forum_post} p1
INNER JOIN {interaction_forum_post} p2
ON p1.poster = p2.poster
AND p2.deleted != 1
INNER JOIN {interaction_forum_topic} t
ON t.deleted != 1
AND p2.topic = t.id
INNER JOIN {interaction_instance} f
ON t.forum = f.id
AND f.deleted != 1
AND f.group = ?
LEFT JOIN {interaction_forum_edit} e
ON (e.post = p1.id)
INNER JOIN {interaction_forum_post} p2 ON (p1.poster = p2.poster AND p2.deleted != 1)
INNER JOIN {interaction_forum_topic} t ON (t.deleted != 1 AND p2.topic = t.id)
INNER JOIN {interaction_instance} f ON (t.forum = f.id AND f.deleted != 1 AND f.group = ?)
LEFT JOIN {interaction_forum_edit} e ON e.post = p1.id
WHERE p1.topic = ?
GROUP BY 1, 2, 3, 4, 5, 6, 7, 9, 10
ORDER BY p1.ctime',
GROUP BY 1, 2, 3, 4, 5, p1.ctime, 7, 9, 10
ORDER BY p1.ctime, p1.id',
array($topic->group, $topicid)
);
// $posts has an object for every edit to a post
// this combines all the edits into a single object for each post
// also formats the edits a bit
$count = count($posts);
for ($i = 0; $i < $count; $i++) {
$postedits = array();
if (!empty($posts[$i]->edit)) {
$postedits[] = get_string('editedon', 'interaction.forum', display_name($posts[$i]->editor), $posts[$i]->edit);
if (!empty($posts[$i]->edittime)) {
$postedits[] = get_string('editedon', 'interaction.forum', display_name($posts[$i]->editor), strftime(get_string('strftimerecentfull'), $posts[$i]->edittime));
}
$temp = $i;
while (isset($posts[$i+1]) && $posts[$i+1]->id == $posts[$temp]->id) {
while (isset($posts[$i+1]) && $posts[$i+1]->id == $posts[$temp]->id) { // while the next object is the same post
$i++;
$postedits[] = get_string('editedon', 'interaction.forum', display_name($posts[$i]->editor), $posts[$i]->edit);
$postedits[] = get_string('editedon', 'interaction.forum', display_name($posts[$i]->editor), strftime(get_string('strftimerecentfull'), $posts[$i]->edittime));
unset($posts[$i]);
}
$posts[$temp]->edit = $postedits;
}
// works out if the logged in user can edit each post
// and formats the post time
foreach ($posts as $post) {
if ($post->poster == $USER->get('id') && (time() - strtotime($post->ctime)) < (30 * 60)) {
$post->editor = true;
if ($moderator ||
($post->poster == $USER->get('id') && (time() - $post->ctime) < (30 * 60))) {
$post->canedit = true;
}
else {
$post->editor = false;