Execute an Extension at posting

Discuss PivotX 2.0.x extensions here, and view extensions that are available for download.

Execute an Extension at posting

Postby bavatar » Fri Aug 14, 2009 7:37 am

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!
bavatar
 
Posts: 8
Joined: Sun May 03, 2009 10:51 am

Re: Execute an Extension at posting

Postby hansfn » Fri Aug 14, 2009 11:14 am

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...
hansfn
Developer
 
Posts: 3282
Joined: Sun Nov 25, 2007 7:48 pm
Location: Molde, Norway

Re: Execute an Extension at posting

Postby hansfn » Fri Aug 14, 2009 11:34 am

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);
}

?>
hansfn
Developer
 
Posts: 3282
Joined: Sun Nov 25, 2007 7:48 pm
Location: Molde, Norway

Re: Execute an Extension at posting

Postby bavatar » Fri Aug 14, 2009 11:40 am

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
bavatar
 
Posts: 8
Joined: Sun May 03, 2009 10:51 am

Re: Execute an Extension at posting

Postby DiMTRX » Thu Aug 20, 2009 5:00 pm

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 ?
User avatar
DiMTRX
 
Posts: 8
Joined: Tue Aug 18, 2009 4:57 pm
Location: Netherlands

Re: Execute an Extension at posting

Postby hansfn » Thu Aug 20, 2009 7:00 pm

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, "", "");
hansfn
Developer
 
Posts: 3282
Joined: Sun Nov 25, 2007 7:48 pm
Location: Molde, Norway

Re: Execute an Extension at posting

Postby DiMTRX » Mon Aug 31, 2009 6:52 pm

Got it to work btw, thanks for the tip :)
User avatar
DiMTRX
 
Posts: 8
Joined: Tue Aug 18, 2009 4:57 pm
Location: Netherlands

Re: Execute an Extension at posting

Postby DiMTRX » Sun Oct 11, 2009 4:05 pm

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 :)
User avatar
DiMTRX
 
Posts: 8
Joined: Tue Aug 18, 2009 4:57 pm
Location: Netherlands

Re: Execute an Extension at posting

Postby hansfn » Sun Oct 11, 2009 4:31 pm

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.)
hansfn
Developer
 
Posts: 3282
Joined: Sun Nov 25, 2007 7:48 pm
Location: Molde, Norway

Re: Execute an Extension at posting

Postby DiMTRX » Sat Oct 31, 2009 8:28 pm

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 ;)
User avatar
DiMTRX
 
Posts: 8
Joined: Tue Aug 18, 2009 4:57 pm
Location: Netherlands


Return to 2.x Extensions

Who is online

Users browsing this forum: No registered users and 5 guests

cron