Entry gets bumped if new comment is posted, how?

Discussion corner for Developers of Serendipity.
Post Reply
evanslee
Regular
Posts: 28
Joined: Tue Jul 27, 2010 3:21 pm

Entry gets bumped if new comment is posted, how?

Post by evanslee »

Hi guys,

hoping you may have some suggestions for me to try.

I hoped it would be a quick SQL statement change, but how would I change serendipity so that if someone placed a new comment on a post it would then become top of the list...

Effectively, i want comments on old post to be able to bump the entry to the top, is this possible?

thanks in advance for any guidance from the guru's,
Lee
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Entry gets bumped if new comment is posted, how?

Post by garvinhicking »

Hi!

That is possible, but you're pushing things quite into the direction of a forum then, and it might confuse visitors? (At least I would be surprised).

The best way to do that is with a simple event plugin:

Code: Select all

<?php
class serendipity_event_bumpcomment extends serendipity_event {
    var $title = 'Bump comments';

    function introspect(&$propbag) {
        global $serendipity;

        $propbag->add('name',          'Bump Comments');
        $propbag->add('description',   '');
        $propbag->add('stackable',     false);
        $propbag->add('author',        'Garvin Hicking');
        $propbag->add('version',       '1.0');
        $propbag->add('requirements',  array(
            'serendipity' => '0.8',
            'smarty'      => '2.6.7',
            'php'         => '4.1.0'
        ));
        $propbag->add('event_hooks',    array(
            'frontend_saveComment_finish' => true
        ));
    }

    function event_hook($event, &$bag, &$eventData, $addData = '') {
        global $serendipity;

        $hooks = &$bag->get('event_hooks');
        if (isset($hooks[$event])) {
            switch($event) {
                case 'frontend_saveComment_finish':
                    serendipity_db_query("UPDATE {$serendipity['dbPrefix']}entries 
                                             SET timestamp = NOW() 
                                           WHERE id = '" . (int)$addData['comment_id'] . "'");
                    return true;
                    break;
            }
        }
    }
}
?>
On each "frontend_saveComment_finish" event, this would set the publish date of an entry to the current time, thus pushing it to the top. That would mean, of course, you cannot preserve the original publication time of your blog entries (unless you put it inside your text).

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
evanslee
Regular
Posts: 28
Joined: Tue Jul 27, 2010 3:21 pm

Re: Entry gets bumped if new comment is posted, how?

Post by evanslee »

Thank you very much for the point in the right direction, I have tried it, and whilst it is doing something its a little unexpected.

When I add a comment to a post It is correctly modifiying the time to: Last modified on 2010-07-27 17:18, however rather than bumping it, it is sending it to the very last post, in the wrong direction.

The rest of the entries appear to remain in the correct order,
i.e new ones correctly appear at the top of page1, any ideas?

I also now get this error everytime I click an admin page link:

Warning: Cannot modify header information - headers already sent by (output started at /docs/serendipity/plugins/serendipity_event_bumpcomment/serendipity_event_bumpcomment.php:1) in /docs/serendipity/include/functions_config.inc.php on line 696

VERSION: Powered by Serendipity 1.5.3 and PHP 5.2.6



Regards,
Lee
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Entry gets bumped if new comment is posted, how?

Post by garvinhicking »

Hi!
When I add a comment to a post It is correctly modifiying the time to: Last modified on 2010-07-27 17:18, however rather than bumping it, it is sending it to the very last post, in the wrong direction.
I don't understand what you mean - the blog posting to which the comment belongs gets sent to the LAST page of your blog entries?

In that, case try to modify "NOW()" in the code to "UNIX_TIMESTAMP(NOW())" instead.

About the error: Make sure you have no character before the first <?php and no character after ?> - you seem to have a blank space or line or UTF-8 BOM inside the file you created...

HTH,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
evanslee
Regular
Posts: 28
Joined: Tue Jul 27, 2010 3:21 pm

Re: Entry gets bumped if new comment is posted, how?

Post by evanslee »

Thank you, loving your work.

You understood perfectly, and changing Now() to UNIX_TIMESTAMP(NOW()) did the trick.

Im still getting the error with the admin page though, and i checked for spaces, there were no before the <?php

Thanks again

Regards,
Lee
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Entry gets bumped if new comment is posted, how?

Post by garvinhicking »

Hi!

You could remove the last "?>" to check that. If you're using a UTF-8 text editor, make sure to save it in "UTF-8 without BOM". Or save it as ANSI/LATIN-encoding. Mostly in those cases, editors insert 2 special bytes inside a UTF-8 file that disturb PHP because they get shown...

Best regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
evanslee
Regular
Posts: 28
Joined: Tue Jul 27, 2010 3:21 pm

Re: Entry gets bumped if new comment is posted, how?

Post by evanslee »

I have replace the files in the root dir of serendipity with fresh copies, and it fixed the error, i must have changed something I shouldnt have prior to the plugin change.

Regards,
Lee
evanslee
Regular
Posts: 28
Joined: Tue Jul 27, 2010 3:21 pm

Re: Entry gets bumped if new comment is posted, how?

Post by evanslee »

A slight bug...

When i try to upload a photo using the photo blog plugin, on the add entry page... i get this...

Code: Select all

Warning: Cannot modify header information - headers already sent by (output started at /docs/serendipity/plugins/serendipity_event_bumpcomment/serendipity_event_bumpcomment.php:1) in /docs/serendipity/include/functions_config.inc.php on line 696

Warning: Cannot modify header information - headers already sent by (output started at /docs/serendipity/plugins/serendipity_event_bumpcomment/serendipity_event_bumpcomment.php:1) in /docs/serendipity/include/functions_config.inc.php on line 696

Warning: Cannot modify header information - headers already sent by (output started at /docs/serendipity/plugins/serendipity_event_bumpcomment/serendipity_event_bumpcomment.php:1) in /docs/serendipity/include/functions_config.inc.php on line 696

Warning: Cannot modify header information - headers already sent by (output started at /docs/serendipity/plugins/serendipity_event_bumpcomment/serendipity_event_bumpcomment.php:1) in /docs/serendipity/serendipity_admin_image_selector.php on line 11
It used to work, and suspect the bumpcomment plugin is conflicting in some way, any ideas?
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Entry gets bumped if new comment is posted, how?

Post by garvinhicking »

Hi!

Again, you seem to have introduced extra linefeeds/spacing inside that file... :)

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
evanslee
Regular
Posts: 28
Joined: Tue Jul 27, 2010 3:21 pm

Re: Entry gets bumped if new comment is posted, how?

Post by evanslee »

hmm, I will check again, but i have yet to modify and save the bump changes...

Last time i fixed it by replacing all the files in the root folder on serendipity, maybe i need to replace the files in the include dire too...

thanks
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Entry gets bumped if new comment is posted, how?

Post by garvinhicking »

Hi!
evanslee wrote:hmm, I will check again, but i have yet to modify and save the bump changes...

Last time i fixed it by replacing all the files in the root folder on serendipity, maybe i need to replace the files in the include dire too...

thanks
Well, the error message tells you that in the bumpcomments file there is a spacing. You should really make sure that spacing/UTF-8 thing I explicitly mentioned, this is 99% the reason :)

Why uploading the s9y files changed this, I don't know. According to the current error, it didn't?! :)

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
evanslee
Regular
Posts: 28
Joined: Tue Jul 27, 2010 3:21 pm

Re: Entry gets bumped if new comment is posted, how?

Post by evanslee »

I hear ya, but before i uploaded the files to the root dir again i was getting this error on every single page in the admin sections. Now i only get it on the photoblog upload page.

[scratches head]

will report back shortly.
Post Reply