Page 1 of 1
Add entry then Redirect to view entry after save (how?)
Posted: Wed Jul 28, 2010 9:49 pm
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
Re: Add entry then Redirect to view entry after save (how?)
Posted: Wed Jul 28, 2010 9:58 pm
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
Re: Add entry then Redirect to view entry after save (how?)
Posted: Wed Jul 28, 2010 10:18 pm
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

Re: Add entry then Redirect to view entry after save (how?)
Posted: Thu Jul 29, 2010 12:47 pm
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
Re: Add entry then Redirect to view entry after save (how?)
Posted: Fri Jul 30, 2010 11:11 am
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;
Re: Add entry then Redirect to view entry after save (how?)
Posted: Fri Jul 30, 2010 12:40 pm
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
Re: Add entry then Redirect to view entry after save (how?)
Posted: Fri Jul 30, 2010 12:47 pm
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...
Re: Add entry then Redirect to view entry after save (how?)
Posted: Fri Jul 30, 2010 1:06 pm
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
));
Re: Add entry then Redirect to view entry after save (how?)
Posted: Fri Jul 30, 2010 2:04 pm
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
Re: Add entry then Redirect to view entry after save (how?)
Posted: Fri Jul 30, 2010 2:18 pm
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
Re: Add entry then Redirect to view entry after save (how?)
Posted: Fri Jul 30, 2010 2:36 pm
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>