Topic: [Release] Merge posts
Hi.
Search in forum but this extention dosnt exists (lazy developers! ) and i made it self.
This extension merges posts. Example: one user posting after prior own post. Both posts are automatically merged.
In extensions directory make directory with name merge_posts. In this directory make file manifest.xml with content:
<?xml version="1.0" encoding="utf-8"?>
<extension engine="1.0">
<id>merge_posts</id>
<title>Merge posts</title>
<description>This extension merges posts. Example: one user posting after prior own post. Both posts are automatically merged.</description>
<version>1.1</version>
<minversion>1.3.2</minversion>
<maxtestedon>1.3.2</maxtestedon>
<author>lexazloy</author>
<hooks>
<hook id="fn_add_post_qr_add_post"><![CDATA[
function l_plural($int, $array, $noint = false){
list($banan, $banana, $bananov) = (!is_array($array) ? explode('/', $array) : $array);
$n1 = substr($int, -1);
$n2 = substr($int, -2);
$string = $bananov;
if ($n2 >= 10 and $n2 <= 20)
$string = $bananov;
elseif ($n1 == 1)
$string = $banan;
elseif ($n1 >= 2 and $n1 <= 4)
$string = $banana;
return trim($noint ? $string : $int.' '.$string);
}
////////////////////////////////////////////////////////////////////////////////
// http://php.net/datetime/#78025
function l_ago($second, $len = 3, $plural = array()){
$plural = array_merge(array(
'separator' => ',',
'seconds' => 'second/seconds/seconds',
'minutes' => 'minute/minutes/minutes',
'hours' => 'hour/hours/hours',
'days' => 'day/days/days',
'weeks' => 'week/weeks/weeks',
'months' => 'month/months/months',
'years' => 'year/years/years',
'ago' => 'ago',
'and' => 'and'
), $plural);
$period = array(
'years' => 31556926,
'months' => 2629743,
'weeks' => 604800,
'days' => 86400,
'hours' => 3600,
'minutes' => 60,
'seconds' => 1
);
foreach ($period as $k => $v)
if ($second >= $v){
$durations = floor($second / $v);
$second -= ($durations * $v);
$array[] = l_plural($durations, $plural[$k]);
}
if (count($array) > 1){
if (count($array) == 2){
$result = $array[0].($len != 1 ? ' '.$plural['and'].' '.$array[1] : '');
} elseif (count($array) <= $len){
$end = array_pop($array);
$result = join($plural['separator'].' ', $array).' '.$plural['and'].' '.$end;
} else {
if ($len = count($result = array_slice($array, 0, $len - 1)))
$result = join($plural['separator'].' ', $result).' '.$plural['and'].' '.$array[$len];
else
$result = $array[$len];
}
} else {
$result = $array[0];
}
return trim($result.' '.$plural['ago']);
}
////////////////////////////////////////////////////////////////////////////////
$l = array();
$l['query'] = array('SELECT' => 'id, poster_id, posted', 'FROM' => 'posts', 'WHERE' => 'topic_id = '.$post_info['topic_id'], 'ORDER BY' => 'id desc', 'LIMIT' => 1);
$l['post'] = $forum_db->query_build($l['query']) or error(__FILE__, __LINE__);
$l['post'] = $forum_db->fetch_assoc($l['post']);
$l['ago'] = l_ago((time() - $l['post']['posted']), 3, array('ago' => 'after'));
$l['ago'] = sprintf('\n\n[i][color=#cccccc]%s:[/color][/i]\n\n', $l['ago']);
if ($l['edit'] = ($post_info['poster_id'] == $l['post']['poster_id']))
$query = array(
'UPDATE' => 'posts',
'WHERE' => 'id = '.$l['post']['id'],
'SET' => 'message = concat(message, "'.$l['ago'].'", "'.$forum_db->escape($post_info['message']).'")'
);
]]></hook>
<hook id="fn_add_post_qr_get_topic_reply_count"><![CDATA[
if ($l['edit'])
$new_pid = $l['post']['id'];
]]></hook>
</hooks>
</extension>
P.S. +1 query to database. But very simple and fast query.
upd: Alternative from dimkalinux Fancy Merge Posts.