Page 1 of 1

Execute an Extension at posting

PostPosted: Fri Aug 14, 2009 7:37 am
by bavatar
Dear Forum,

I want to write an OMB expansion for PivotX similar to mnw for this other blogengine. I've looked at the code of some provided extensions, but for me it looks like none of them is doing something when an article is posted.

I would be very glad if you could point me to such a file or provide me with the basic code that would allow such thing :)

TIA!

Re: Execute an Extension at posting

PostPosted: Fri Aug 14, 2009 11:14 am
by hansfn
Yes, the documentation for extension authors is non-existing - we know. Anyway, there is a hook for this - entry_edit_aftersave - which is executed after an entry is saved. (You can tell from the $entry['code'] value whether it's new or an edited entry. (There is page_edit_aftersave for pages) If your extension implements/adds that hook, you should be able to do what you want.

Wait a minute, and I'll write an example...

Re: Execute an Extension at posting

PostPosted: Fri Aug 14, 2009 11:34 am
by hansfn
And now the example - put the code in a file named for example extensions/hook_saved_entry_notification.php, update the email address in the pivotxMail call, enable the extension inside PivotX and give it a try.

Code: Select all
<?php
// - Extension: The saved entry notification hook
// - Version: 0.1
// - Author: PivotX Team
// - Email: admin@pivotx.net
// - Site: http://www.pivotx.net
// - Updatecheck: http://www.pivotx.net/update.php?ext=saved_entry_notification
// - Description: This hook will send an e-mail notification each time an entry is saved.
// - Date: 2009-08-14


$this->addHook(
    'entry_edit_aftersave',
    'callback',
    'afterSavedEntryNotification'
    );


function afterSavedEntryNotification(&$entry) {
    // Do nothing if the entry isn't published.
    if ($entry['status']!="publish") {
        return;
    }
    $text = "The entry '{$entry['title']}' was ";
    if ($entry['code']==">") {
        $text .= "created";
    } else {
        $text .= "updated";
    }
    pivotxMail('someuser@example.org', 'PivotX entry notification',$text);
}

?>

Re: Execute an Extension at posting

PostPosted: Fri Aug 14, 2009 11:40 am
by bavatar
Missing docs are not that bad when you keep answering requests that quickly ;-)

Thank you very much for the example Hans!I'll take a look at it later :-D

Re: Execute an Extension at posting

PostPosted: Thu Aug 20, 2009 5:00 pm
by DiMTRX
Anyway to get the url information as well in this mail. I modded this code so it posts the information through my bot on an IRC channel. But was wondering if I could get a click-able link along with the Post title ?

Re: Execute an Extension at posting

PostPosted: Thu Aug 20, 2009 7:00 pm
by hansfn
Well, you could have look at the function sendMailNotification in lib.php, but to keep it short - what you need is
Code: Select all
global $PIVOTX;
$link = $PIVOTX['paths']['host'] . makeFilelink($entry, "", "");

Re: Execute an Extension at posting

PostPosted: Mon Aug 31, 2009 6:52 pm
by DiMTRX
Got it to work btw, thanks for the tip :)

Re: Execute an Extension at posting

PostPosted: Sun Oct 11, 2009 4:05 pm
by DiMTRX
I got one more question about something which I find a little bit strange, when a new post is posted it doesn't show the full path of the article. While when I update a post it does show the full correct path.

[17:44] <Bot> [Blog] Entry 'Fixing Script Bug' was created. [URL] http://blog.p0wer.nl/?e= <-- should be http://blog.p0wer.nl/?e=10

and then when I update that same post with lets say an extra point or comma it does post the full path.

[18:01] <Bot> [Blog] Entry 'Fixing Script Bug' was updated. [URL] http://blog.p0wer.nl/?e=10


Anyone around which is able to help me out and has the time for it. Thanks in advance :)

Re: Execute an Extension at posting

PostPosted: Sun Oct 11, 2009 4:31 pm
by hansfn
If you use
Code: Select all
$PIVOTX['db']->entry

instead of just $entry it will work. ($entry doesn't have the code set when you post a new entry.)

Re: Execute an Extension at posting

PostPosted: Sat Oct 31, 2009 8:28 pm
by DiMTRX
hansfn wrote:If you use
Code: Select all
$PIVOTX['db']->entry

instead of just $entry it will work. ($entry doesn't have the code set when you post a new entry.)


Thanks that did the trick :) soz for the late response ;)