Add entry then Redirect to view entry after save (how?)

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

Add entry then Redirect to view entry after save (how?)

Post by evanslee »

Currently after I enter an entry, it stays on the page that says it's saved and remains in the admin section.

How would I be able to change this without hacking the serendipity code, can redirects be done in a plugin or is this the wrong way to go?

Id like to be able to redirect to the final post after saving completes

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

Re: Add entry then Redirect to view entry after save (how?)

Post by garvinhicking »

Hi!

You could write a plugin that listens on the "backend_publish" hook for example, yes. How much do you know about the plugin API, does that information help you?

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: Add entry then Redirect to view entry after save (how?)

Post by evanslee »

I had a look a freetag plugin to try and see what was going on with backend_publish but couldnt make sense of it.

I have yet to get my head round all the hooks n the like, but im sure i will get there, then i can start publishing plugins :)
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Add entry then Redirect to view entry after save (how?)

Post by garvinhicking »

Hi!

Okay, it's not really hard, here's an example for your case:

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(
                'backend_publish' => true
            ));
        }

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

            $hooks = &$bag->get('event_hooks');
            if (isset($hooks[$event])) {
                switch($event) {
                    case 'backend_publish':
                        header('Location: http://www.google.de/');
                        exit;
                        return true;
                        break;
                }
            }
        }
    }
If you have more questions, feel free to ask :)

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: Add entry then Redirect to view entry after save (how?)

Post by evanslee »

Thanks

So, you can stack them up like this?

Code: Select all

$hooks = &$bag->get('event_hooks');
        if (isset($hooks[$event])) {
            switch($event) {
                case 'frontend_saveComment_finish':
                    serendipity_db_query("UPDATE {$serendipity['dbPrefix']}entries 
                                             SET timestamp = UNIX_TIMESTAMP(NOW())
                                           WHERE id = '" . (int)$addData['comment_id'] . "'");
                    return true;
                    break;
					
	    case 'backend_publish':
                        header('Location: http://www.google.de/');
                        exit;
                        return true;
                        break;
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Add entry then Redirect to view entry after save (how?)

Post by garvinhicking »

Hi!

Yeah, you can do that! Just remember to also add frontend_saveComment_finish at the "introspect" method to the propbag where all event hooks that the plugin wants to use need to be shown.

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: Add entry then Redirect to view entry after save (how?)

Post by evanslee »

garvinhicking wrote: Just remember to also add frontend_saveComment_finish at the "introspect" method to the propbag where all event hooks that the plugin wants to use need to be shown.

HTH,
Garvin
Now you have lost me...
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Add entry then Redirect to view entry after save (how?)

Post by garvinhicking »

Hi!

You need to change this

Code: Select all

            $propbag->add('event_hooks',    array(
                'backend_publish' => true
            ));

Code: Select all

            $propbag->add('event_hooks',    array(
                'backend_publish' => true,
                'frontend_saveComment_finish' => true
            ));
# 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: Add entry then Redirect to view entry after save (how?)

Post by evanslee »

This sort of works...

However, the redirect is only showing in the frame below:
'Serendipity is now saving your entry, creating trackbacks and performing possible XML-RPC calls. This may take a while..'

I still see the add entry form below that with my populated text... and it doesnt redirect to the main blog page
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Add entry then Redirect to view entry after save (how?)

Post by garvinhicking »

Hi!

Hm, okay. I suppose instead of a redirect you then need javascript code that accesses the parent frame and redirects there...

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: Add entry then Redirect to view entry after save (how?)

Post by evanslee »

So i can redirect the frame as per above... but to a page that contains this...

Code: Select all

<script type="text/javascript">
setTimeout('Redirect()',4000);
function Redirect()
{
  self.parent.location.href = 'http://localhost/serendipity/';
}
</script>
Post Reply