1 (edited by lexazloy 2009-12-04 18:09)

Topic: [Release] Merge posts

Hi.

Search in forum but this extention dosnt exists (lazy developers! smile) 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.

Royal Crown Chinpoko Master, ^_^

Re: [Release] Merge posts

+1 query on post adding doesn't lead to a significant increase of the server load.

I think the array must contain these values:

    'seconds' => 'second/seconds/seconds',
    'minutes' => 'minute/minutes/minutes',

and so on.

Re: [Release] Merge posts

Parpalak, maybe it important for someone who optimization fan. smile

P.S. Thank you for help translate.

Royal Crown Chinpoko Master, ^_^

4 (edited by KeyDog 2009-04-17 09:56)

Re: [Release] Merge posts

very cool - just tried it. Wrote "Test 123" in reply box and it automatically merged it... but:

Database reported: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AND (fp.read_forum IS NULL OR fp.read_forum=1) AND s.topic_id=7 AND u.id!=2' at line 1 (Errno: 1064).


^^^get that

but you can see it changed post here:

http://punbb-a.keydogbb.info/viewtopic.php?pid=7#p7

any ideas what prob is?



EDIT: Anyone wanting to download the extension without pasting and creating folder:

http://www.mediafire.com/file/tzaq2dfjm … _posts.zip


EDIT 2: I see "1 month, 2 weeks and 10 hours after:" is before the Test 123 but in same font  as my background - so invisible - in admin mode I can see it light grey.

EDIT 3:
           

 $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']); 

changed the color cccccc to 333333 in second post now (above is the original extension code)

5 (edited by lexazloy 2009-04-17 10:05)

Re: [Release] Merge posts

KeyDog, i update code to version 1.1. Was bug. And rename author to "lexazloy" (name not need save file in utf8 encoding). Please reinstall extention.

KeyDog wrote:

Database reported: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AND (fp.read_forum IS NULL OR fp.read_forum=1) AND s.topic_id=7 AND u.id!=2' at line 1 (Errno: 1064).

Sorry i dont know about this bug. I try find in PunBB this SQL query but too many. Need all query in error message (need write about it to developers). Debugging in PunBB sux.

KeyDog wrote:

EDIT 2: I see "1 month, 2 weeks and 10 hours after:" is before the Test 123 but in same font  as my background - so invisible - in admin mode I can see it light grey. But that's a style issue my side not ext problem....

Sorry i dont understand. I try but translating (Google Translit) not help me. smile

upd edit 3 help me understand! smile

KeyDog wrote:

changed the color cccccc to 333333 in second post now (above is the original extension code)

#cccccc good for default theme (oxygen). I think all users use default theme, i was wrong sorry.

Royal Crown Chinpoko Master, ^_^

6 (edited by KeyDog 2009-04-17 10:13)

Re: [Release] Merge posts

ok will try the 1.1 big_smile
chrs.


EDIT: okay still get the database error....

Re: [Release] Merge posts

Writing to Parpalak about debugging SQL. I hope he make something. smile

Royal Crown Chinpoko Master, ^_^

Re: [Release] Merge posts

cool.
maybe also add this
    <description>This extension merges posts. Example: one user posting after prior own post. Both posts are automatically merged</description>

Re: [Release] Merge posts

Works fine for me.

Though the error can be related to this 'WHERE' clause: http://punbb.informer.com/trac/browser/ … .php#L2508

10 (edited by lexazloy 2009-04-17 10:26)

Re: [Release] Merge posts

KeyDog, thank you! Most better. Update code and post (was mine "englesh" now you text).

Parpalak, but why error? In extention replace only $query in function add_post() local namespace. And another $query in function replaces because every $query is new array.

Royal Crown Chinpoko Master, ^_^

Re: [Release] Merge posts

KeyDog, in what file and line is the error? This information must be also displayed.

12

Re: [Release] Merge posts

indeed sry forgot to mention

The error occurred on line 2507 in punbb-a.keydogbb.info/include/functions.php

Re: [Release] Merge posts

Ok, then I gave a correct link to the error location. Moreover, function send_subscriptions() is called inside add_post().

14 (edited by KeyDog 2009-04-17 13:41)

Re: [Release] Merge posts

smile that's nice and all. but what is solution?
replace what with what?

Re: [Release] Merge posts

Let's ask lexazloy smile
I'll be able to see later what's wrong.

Re: [Release] Merge posts

I do not know what problem. I subscribed (via second account) and postint (via first account) but no error exists.

KeyDog maybe you use some extension with "fn_send_subscriptions_qr_get_users_to_notify" hook. And this extension incompatible with merge_posts. I testing on PunBB 1.3.2 without extensions and with extesions pun_attachment, pun_pm and pun_repository.

Royal Crown Chinpoko Master, ^_^

17 (edited by KeyDog 2009-04-18 08:56)

Re: [Release] Merge posts

just tried it on another test forum where it works fine. strange. even if I uninstall the extensions that I haven't got on the 2nd working test forum I still get database error in 1st forum.

anyway: thx!

added to extension dowload page

18

Re: [Release] Merge posts

I also found the same error when merge_post is activated.

in functions.php line 2503  the code is:

'WHERE'        => 'b.username IS NULL AND COALESCE(o.logged, u.last_visit)>'.$previous_post_time.' AND (fp.read_forum IS NULL OR fp.read_forum=1) AND s.topic_id='.$post_info['topic_id'].' AND u.id!='.$post_info['poster_id']

problem occurs as when this extension is activated $previous_post_time returns nothing. so the query is like:

AND COALESCE(o.logged, u.last_visit)> AND (fp.read_forum IS NULL OR fp.read_forum=1) AND s.topic_id=10949 AND

see after >. guess there would be a timestamp.

thanks

19 (edited by guest1234 2009-05-19 14:55)

Re: [Release] Merge posts

I used the extension since it came out, but in this time I realised that another "time scheme" would be better.

Currently it is this way:
While merging, there is added something like "1 day, 3 hours, 5 minutes and 4 seconds later".

But I think it should work this way:
For example, when the post date is 03/05/2009 09:15 PM and a double post is merged there shoudl be something like this:
"On 03/07/2009 10:40 AM was added:"

I'm also fine with both ways at once ("[this time] later on [new date] was added:"), but the new date should appear at least. This would make it a lot easier to find out the time, because you don't have to calculate it yourself (especially when there are more posts merged, not only two).

Re: [Release] Merge posts

maststef, you mean need insert current date because need know when be update post? That is logical. I dont think about this.

But why in you example PM/AM for 24-hour format (09:15, after 13:15, 14:15, etc)? smile

I code replace:

$l['ago'] = l_ago((time() - $l['post']['posted']), 3, array('ago' => 'after'));

to this:

$l['ago'] = date('d/m/Y H:i:s');

Format for: DD/MM/YY HH:MM:SS

or to this:

$l['ago'] = date('m/d/Y g:i:s A');

Format for (USA format?): MM/DD/YY H:MM:SS AM (or PM)

And this alternative from dimka.linux@gmail.com Fancy Merge Posts (i not found it on forum and upload to my site).

Royal Crown Chinpoko Master, ^_^

21

Re: [Release] Merge posts

Got the same error as discussed earlier:

Database reported: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AND (fp.read_forum IS NULL OR fp.read_forum=1) AND s.topic_id=35 (Errno: 1064).

A bit of info that might (hopefully) help: it happens when the merged posts are first and second in the topic. The posts do merger just fine. The error message appears after redirect to new message view.

Any idea what the problem might be?

Re: [Release] Merge posts

Alternative extensions with many configurable options — Fancy Merge Posts

Re: [Release] Merge posts

Thanks for the info, I appreciate it.

Re: [Release] Merge posts

Hello Lexazloy,

thanks for your work.

Unfortunately I get fatal errors as soon as I make a double posting for test purposes.
(2 postings, same IP, same guest name). If I submit the second posting (which should be merged) then the following error is shown (with PunBB debug enabled):

An error was encountered
The error occurred on line 2125 in D:\Programme\Apache\htdocs\forum\include\functions.php
Database reported: SQL logic error or missing database (Errno: 1).

Double posting again works normally as soon as your extension is uninstalled.

Note: I am using SQLLite as database (it works slightly different)

Any hope to get this fixed?